@leafer-in/editor 1.0.0-rc.20 → 1.0.0-rc.21
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 +13 -13
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.js +42 -42
- package/dist/editor.min.js +1 -1
- package/package.json +5 -7
- package/src/Editor.ts +2 -1
- package/src/decorator/data.ts +1 -1
- package/src/display/EditBox.ts +2 -1
- package/src/display/EditPoint.ts +1 -1
- package/src/display/EditSelect.ts +2 -1
- package/src/display/SelectArea.ts +1 -1
- package/src/display/Stroker.ts +1 -1
- package/src/editor/cursor.ts +1 -1
- package/src/editor/simulate.ts +1 -1
- package/src/editor/target.ts +1 -1
- package/src/event/EditorEvent.ts +1 -1
- package/src/helper/EditDataHelper.ts +1 -1
- package/src/helper/EditSelectHelper.ts +1 -1
- package/src/helper/EditorHelper.ts +1 -1
- package/src/tool/LineEditTool.ts +1 -1
- package/src/tool/index.ts +1 -1
- package/types/index.d.ts +2 -1
package/dist/editor.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PathCommandMap, Leaf, Path, Line, Polygon, MatrixHelper, Group, Box } from '@leafer-ui/draw';
|
|
2
|
-
import {
|
|
1
|
+
import { PathCommandMap, Leaf, Path, Line, Polygon, MatrixHelper, Group, Box, Event, defineKey, UI, Paint, Rect, Answer, Bounds, LeafList, PointHelper, AroundHelper, MathHelper, getPointData, Matrix, DataHelper, RenderEvent } from '@leafer-ui/draw';
|
|
2
|
+
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent, Creator } from '@leafer-ui/core';
|
|
3
3
|
|
|
4
4
|
const { M, L, C, Q, Z, N, D, X, G, F, O, P, U } = PathCommandMap;
|
|
5
5
|
const PathScaler = {
|
|
@@ -235,9 +235,9 @@ function targetAttr(fn) {
|
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
const matrix = MatrixHelper
|
|
238
|
+
const matrix = MatrixHelper.get();
|
|
239
239
|
const { abs } = Math;
|
|
240
|
-
const { copy, scale } = MatrixHelper
|
|
240
|
+
const { copy, scale } = MatrixHelper;
|
|
241
241
|
class Stroker extends UI {
|
|
242
242
|
constructor() {
|
|
243
243
|
super();
|
|
@@ -304,7 +304,7 @@ function onTarget$1(stroker) {
|
|
|
304
304
|
stroker.forceUpdate();
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
-
class SelectArea extends Group
|
|
307
|
+
class SelectArea extends Group {
|
|
308
308
|
constructor(data) {
|
|
309
309
|
super(data);
|
|
310
310
|
this.strokeArea = new Rect({ strokeAlign: 'center' });
|
|
@@ -352,7 +352,7 @@ const EditSelectHelper = {
|
|
|
352
352
|
};
|
|
353
353
|
|
|
354
354
|
const { findOne } = EditSelectHelper;
|
|
355
|
-
class EditSelect extends Group
|
|
355
|
+
class EditSelect extends Group {
|
|
356
356
|
get dragging() { return !!this.originList; }
|
|
357
357
|
get running() { return this.editor.hittable && this.editor.config.selector; }
|
|
358
358
|
get isMoveMode() { return this.app && this.app.interaction.moveMode; }
|
|
@@ -764,20 +764,20 @@ function toDataURL(svg, rotation) {
|
|
|
764
764
|
return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"';
|
|
765
765
|
}
|
|
766
766
|
|
|
767
|
-
class EditPoint extends Box
|
|
767
|
+
class EditPoint extends Box {
|
|
768
768
|
}
|
|
769
769
|
|
|
770
770
|
const fourDirection = ['top', 'right', 'bottom', 'left'];
|
|
771
|
-
class EditBox extends Group
|
|
771
|
+
class EditBox extends Group {
|
|
772
772
|
get flipped() { return this.flippedX || this.flippedY; }
|
|
773
773
|
get flippedX() { return this.scaleX < 0; }
|
|
774
774
|
get flippedY() { return this.scaleY < 0; }
|
|
775
775
|
get flippedOne() { return this.scaleX * this.scaleY < 0; }
|
|
776
776
|
constructor(editor) {
|
|
777
777
|
super();
|
|
778
|
-
this.rect = new Box
|
|
778
|
+
this.rect = new Box({ name: 'rect', hitFill: 'all', hitStroke: 'none', strokeAlign: 'center', hitRadius: 5 });
|
|
779
779
|
this.circle = new EditPoint({ name: 'circle', strokeAlign: 'center', around: 'center', cursor: 'crosshair', hitRadius: 5 });
|
|
780
|
-
this.buttons = new Group
|
|
780
|
+
this.buttons = new Group({ around: 'center', hitSelf: false });
|
|
781
781
|
this.resizePoints = [];
|
|
782
782
|
this.rotatePoints = [];
|
|
783
783
|
this.resizeLines = [];
|
|
@@ -1185,7 +1185,7 @@ class LineEditTool extends EditTool {
|
|
|
1185
1185
|
function getEditTool(list) {
|
|
1186
1186
|
if (list.length === 1) {
|
|
1187
1187
|
const leaf = list[0];
|
|
1188
|
-
if (leaf instanceof Line
|
|
1188
|
+
if (leaf instanceof Line && !leaf.points) {
|
|
1189
1189
|
return new LineEditTool();
|
|
1190
1190
|
}
|
|
1191
1191
|
else {
|
|
@@ -1243,7 +1243,7 @@ const EditorHelper = {
|
|
|
1243
1243
|
group = userGroup;
|
|
1244
1244
|
}
|
|
1245
1245
|
else {
|
|
1246
|
-
group = new Group
|
|
1246
|
+
group = new Group(userGroup);
|
|
1247
1247
|
}
|
|
1248
1248
|
parent.addAt(group, parent.children.indexOf(list[0]));
|
|
1249
1249
|
list.sort(order);
|
|
@@ -1293,7 +1293,7 @@ const EditorHelper = {
|
|
|
1293
1293
|
}
|
|
1294
1294
|
};
|
|
1295
1295
|
|
|
1296
|
-
class Editor extends Group
|
|
1296
|
+
class Editor extends Group {
|
|
1297
1297
|
get list() { return this.leafList.list; }
|
|
1298
1298
|
get hasTarget() { return !!this.list.length; }
|
|
1299
1299
|
get multiple() { return this.list.length > 1; }
|
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 l,defineKey as h,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 v,MoveEvent as k,ZoomEvent as _,PointHelper as m,AroundHelper as b,MathHelper as x,Box as M,getPointData as E,Line as S,Matrix as V,DataHelper as H,RotateEvent as T,RenderEvent as O,KeyEvent as P,Creator as D}from"@leafer-ui/core";const{M:R,L:A,C:Z,Q:B,Z:z,N:W,D:I,X:X,G:Y,F:C,O:F,P:K,U:U}=t,j={scale(t,e,i){if(!t)return;let s,o=0,n=t.length;for(;o<n;)switch(s=t[o],s){case R:case A:G(t,e,i,o,1),o+=3;break;case Z:G(t,e,i,o,3),o+=7;break;case B:G(t,e,i,o,2),o+=5;break;case z:o+=1;break;case W:G(t,e,i,o,2),o+=5;break;case I:G(t,e,i,o,2),o+=9;break;case X:G(t,e,i,o,2),o+=6;break;case Y:G(t,e,i,o,2),o+=9;break;case C:G(t,e,i,o,2),o+=5;break;case F:t[o]=Y,t.splice(o+4,0,t[o+3],0),G(t,e,i,o,2),o+=9,n+=2;break;case K:t[o]=C,t.splice(o+4,0,t[o+3]),G(t,e,i,o,2),o+=5,n+=1;break;case U:G(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:G}=j;function N(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){N(this,t,e)},i.prototype.__scaleResize=function(t,e){j.scale(this.__.path,t,e),this.path=this.__.path},s.prototype.__scaleResize=function(t,e){if(this.points)j.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?(j.scalePoints(this.__.points,t,e),this.points=this.__.points):N(this,t,e)};const $=n.get();function Q(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)$.a=e,$.d=i,s[t].transform($,!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 J(t){return t?t instanceof Array?t:[t]:[]}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):N(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class tt extends l{get list(){return J(this.value)}get oldList(){return J(this.oldValue)}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;h(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:lt,scale:ht}=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){lt(rt,s.__world),ht(rt,1/o,1/r),t.setWorld(rt,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:a,y:l,width:h,height:c}=s.__layout.boxBounds;t.rect(a*o,l*r,h*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()}}q([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){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=t.shiftKey?this.findDeepOne(t):wt(t.path);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.config;"press"===e&&this.checkAndSelect(t,!0)}onTap(t){const{editor:e}=this,{select:i,continuousSelect:s}=e.config;if("tap"===i&&this.checkAndSelect(t),!this.running||!t.shiftKey&&!s||t.middle||this.lastDownLeaf)this.isMoveMode&&(e.target=null);else{const i=this.findDeepOne(t);i?e.shiftItem(i):!t.shiftKey&&s&&(e.target=null)}this.lastDownLeaf=null}checkAndSelect(t,e){if(this.running&&!this.isMoveMode&&!t.middle){const{editor:i}=this,s=this.lastDownLeaf=wt(t.path);s?(t.shiftKey||i.config.continuousSelect?i.shiftItem(s):i.target=s,e&&(i.updateLayout(),s.locked||this.app.interaction.updateDownData(t,{findList:[i.editBox.rect]},i.config.dualEvent))):this.allow(t.target)&&(t.shiftKey||(i.target=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}}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_(v.START,this.onDragStart,this),e.on_(v.DRAG,this.onDrag,this),e.on_(v.END,this.onDragEnd,this),e.on_(k.MOVE,this.onAutoMove,this),e.on_([_.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 vt;!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"}(vt||(vt={}));const{topLeft:kt,top:_t,topRight:mt,right:bt,bottomRight:xt,bottom:Mt,bottomLeft:Et,left:St}=vt,{toPoint:Vt}=b,Ht={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 c=(-i.y+h)/h,d=(i.x+l)/l,g=(i.y+h)/h,u=(-i.x+l)/l;switch(e){case _t:a=c,n={x:.5,y:1};break;case bt:r=d,n={x:0,y:.5};break;case Mt:a=g,n={x:.5,y:0};break;case St:r=u,n={x:1,y:.5};break;case kt:a=c,r=u,n={x:1,y:1};break;case mt: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}}if(s){"corner"===s&&e%2||(1!==a?r=a:a=r)}return Vt(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 mt: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 Vt(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 _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 St: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:c,height:d}=t;n.x=l+n.x*c,n.y=h+n.y*d,Vt(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 St:t=bt;break;case kt:t=mt;break;case Et:t=xt;break;case bt:t=St;break;case mt:t=kt;break;case xt:t=Et}if(i)switch(t){case _t:t=Mt;break;case kt:t=Et;break;case mt:t=xt;break;case Mt:t=_t;break;case Et:t=kt;break;case xt:t=mt}return t}},Tt={};function Ot(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.hasTarget||!i.visible)return;if("circle"===s.name)return;let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:l,rotateable:h,skewable:c}=t.config,{pointType:d}=s,{flippedX:g,flippedY:u}=i;let f="resize"===d;f&&h&&(e.metaKey||e.ctrlKey||!l)&&(f=!1);const p=c&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(Ht.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(x.formatRotation(o,!0)/2);const{url:y,x:w,y:L}=p,v=y+o;Tt[v]?s.cursor=Tt[v]:Tt[v]=s.cursor={url:Dt(y,o),x:w,y:L}}function Pt(t){t.editBox.rect.cursor=t.config.moveCursor}function Dt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Rt extends M{}const At=["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 M({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Rt({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: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 Rt({name:"rotate-point",around:h[r],width:15,height:15,hitFill:"all"}),o.push(t),this.listenPointEvents(t,"rotate",r),r%2&&(e=new Rt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",r)),i=new Rt({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:i}=this.editor,{width:s,height:o}=t,{rect:n,circle:r,resizePoints:a,rotatePoints:l,resizeLines:h}=this,{middlePoint:c,resizeable:d,rotateable:g,stroke:u,strokeWidth:f,hideOnSmall:p}=e,y=this.getPointsStyle(),w=this.getMiddlePointsStyle(),L="number"==typeof p?p:10,v=!(p&&s<L&&o<L);this.visible=i[0]&&!i[0].locked;let k,_,m,x,M={};for(let i=0;i<8;i++)b.toPoint(b.directionData[i],t,M),k=this.getPointStyle(i%2?w[(i-1)/2%w.length]:y[i/2%y.length]),m=a[i],_=l[i],x=h[Math.floor(i/2)],m.set(k),m.set(M),_.set(M),x.set(M),m.visible=x.visible=v&&(d||g),_.visible=v&&g&&d&&!e.rotatePoint,i%2?(m.visible=_.visible=v&&!!c,(i+1)/2%2?(x.width=s,m.width>s-30&&(m.visible=!1)):(x.height=o,m.rotation=90,m.width>o-30&&(m.visible=!1))):m.rotation=i/2*90;r.visible=v&&g&&!!e.rotatePoint,r.set(this.getPointStyle(e.rotatePoint||y[0])),n.set(Object.assign({stroke:u,strokeWidth:f},e.rect||{})),n.set(Object.assign(Object.assign({},t),{visible:!0})),n.hittable=e.moveable,this.buttons.visible=v,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=At.indexOf(i);(l%2&&r||(l+1)%2&&a)&&s&&(l=(l+2)%4);const h=s?Ht.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l,c=e[2*h+1],d=h%2,g=h&&3!==h?1:-1,u=(o+(l%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*(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):e.onScale(t),Ot(e,t)}onArrow(t){if(this.editor.hasTarget&&this.editor.config.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}(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_(v.START,this.onDragStart,this),t.on_(v.DRAG,this.onDrag,this),t.on_(v.END,this.onDragEnd,this),t.on_(L.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(L.ENTER,(e=>{this.enterPoint=t,Ot(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(tt.SELECT,(()=>{this.visible=e.hasTarget})),t.on_(v.START,this.onDragStart,this),t.on_(v.DRAG,e.onMove,e),t.on_(v.END,this.onDragEnd,this),t.on_(L.ENTER,(()=>Pt(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 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"/>',zt={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${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,select:"press",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};class Wt{constructor(){this.tag="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()}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:c,height:d}=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:c,height:d})}}Wt.list=[];const{left:It,right:Xt}=vt;class Yt extends Wt{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:l,y:h}=e.getInnerMove(n);s&&(Math.abs(l)>Math.abs(h)?h=0:l=0),i===It?(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){}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===It||t===Xt}}const Ct=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Ft=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Kt={group(t,e,i){t.sort(Ft);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(Ct);const r=new V(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(Ct),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(Ft),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}};class Ut 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=zt,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.hasTarget&&(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 S&&!e.points?new Yt:new Wt}return new Wt}(this.list)}getEditSize(t){let{editSize:e}=this.config;return"auto"===e?t.editSize:e}onMove(t){const e=t.getLocalMove(this.element),{lockMove:i}=this.config;"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(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,l;if(t instanceof T)l=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");l=s.rotation,a=s.origin}l=x.getGapRotation(l,s,r.rotation),l&&(r.scaleX*r.scaleY<0&&(l=-l),this.rotateOf(a,x.float(l,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){if(!this.config.moveable)return;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 V(o.worldTransform);o.scaleOf(t,e,i),r=new V(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 V(i.worldTransform);i.rotateOf(t,e),o=new V(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 V(o.worldTransform);o.skewOf(t,e,i),r=new V(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=Kt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=Kt.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&&(Kt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Kt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(O.START,this.update,this),t.on_([P.HOLD,P.UP],(t=>{Ot(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(),this.target=this.hoverTarget=this.simulateTarget=null,super.destroy())}}q([nt((function(t,e){t.emitEvent(new tt(tt.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Ut.prototype,"hoverTarget",void 0),q([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:l,scaleY:h,e:c,f:d}=a.__world;e.reset({x:(s-c)/l,y:(o-d)/h,width:n/l,height:r/h})}(t),Pt(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):t.removeTargetEvents()}))],Ut.prototype,"target",void 0),D.editor=function(t){return new Ut(t)};export{Zt as EditBox,Ht as EditDataHelper,Rt as EditPoint,Lt as EditSelect,yt as EditSelectHelper,Wt as EditTool,Ut as Editor,tt as EditorEvent,Kt as EditorHelper,et as EditorMoveEvent,st as EditorRotateEvent,it as EditorScaleEvent,ot as EditorSkewEvent,Yt 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,Event as l,defineKey as h,UI as c,Paint as d,Rect as g,Answer as u,Bounds as f,LeafList as p,PointHelper as y,AroundHelper as w,MathHelper as L,getPointData as v,Matrix as k,DataHelper as _,RenderEvent as m}from"@leafer-ui/draw";import{PointerEvent as b,DragEvent as x,MoveEvent as M,ZoomEvent as E,RotateEvent as S,KeyEvent as V,Creator as T}from"@leafer-ui/core";const{M:H,L:O,C:P,Q:D,Z:R,N:A,D:Z,X:B,G:z,F:W,O:I,P:X,U:Y}=t,C={scale(t,e,i){if(!t)return;let s,o=0,n=t.length;for(;o<n;)switch(s=t[o],s){case H:case O:F(t,e,i,o,1),o+=3;break;case P:F(t,e,i,o,3),o+=7;break;case D:F(t,e,i,o,2),o+=5;break;case R:o+=1;break;case A:F(t,e,i,o,2),o+=5;break;case Z:F(t,e,i,o,2),o+=9;break;case B:F(t,e,i,o,2),o+=6;break;case z:F(t,e,i,o,2),o+=9;break;case W:F(t,e,i,o,2),o+=5;break;case I:t[o]=z,t.splice(o+4,0,t[o+3],0),F(t,e,i,o,2),o+=9,n+=2;break;case X:t[o]=W,t.splice(o+4,0,t[o+3]),F(t,e,i,o,2),o+=5,n+=1;break;case Y:F(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:F}=C;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){C.scale(this.__.path,t,e),this.path=this.__.path},s.prototype.__scaleResize=function(t,e){if(this.points)C.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?(C.scalePoints(this.__.points,t,e),this.points=this.__.points):K(this,t,e)};const U=n.get();function j(t,e,i){const{children:s}=t;for(let t=0;t<s.length;t++)U.a=e,U.d=i,s[t].transform(U,!0)}function N(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 G(t){return t?t instanceof Array?t:[t]:[]}r.prototype.__scaleResize=function(t,e){j(this,t,e)},a.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?j(this,t,e):K(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class $ extends l{get list(){return G(this.value)}get oldList(){return G(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}$.SELECT="editor.select",$.HOVER="editor.hover";class Q extends ${constructor(t,e){super(t,e)}}Q.MOVE="editor.move";class q extends ${constructor(t,e){super(t,e)}}q.SCALE="editor.scale";class J extends ${constructor(t,e){super(t,e)}}J.ROTATE="editor.rotate";class tt extends ${constructor(t,e){super(t,e)}}function et(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))}})}}tt.SKEW="editor.skew";const it=n.get(),{abs:st}=Math,{copy:ot,scale:nt}=n;class rt extends c{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=st(s.__world.scaleX),r=st(s.__world.scaleY);if(o!==r){ot(it,s.__world),nt(it,1/o,1/r),t.setWorld(it,e.matrix),t.beginPath(),this.__.strokeWidth=n;const{x:a,y:l,width:h,height:c}=s.__layout.boxBounds;t.rect(a*o,l*r,h*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/st(s.__world.scaleX)),"string"==typeof o?d.stroke(o,this,t):d.strokes(o,this,t)}this.__.strokeWidth=n}}destroy(){this.target=null,super.destroy()}}N([et((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],rt.prototype,"target",void 0);class at 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:lt,Yes:ht,NoAndSkip:ct,YesAndSkip:dt}=u,gt={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?dt:ct;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?dt:lt;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return ht}return lt}return t.isBranch?ct:lt}},{findOne:ut}=gt;class ft extends r{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 rt,this.targetStroker=new rt,this.bounds=new f,this.selectArea=new at,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){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=t.shiftKey?this.findDeepOne(t):ut(t.path);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.config;"press"===e&&this.checkAndSelect(t,!0)}onTap(t){const{editor:e}=this,{select:i,continuousSelect:s}=e.config;if("tap"===i&&this.checkAndSelect(t),!this.running||!t.shiftKey&&!s||t.middle||this.lastDownLeaf)this.isMoveMode&&(e.target=null);else{const i=this.findDeepOne(t);i?e.shiftItem(i):!t.shiftKey&&s&&(e.target=null)}this.lastDownLeaf=null}checkAndSelect(t,e){if(this.running&&!this.isMoveMode&&!t.middle){const{editor:i}=this,s=this.lastDownLeaf=ut(t.path);s?(t.shiftKey||i.config.continuousSelect?i.shiftItem(s):i.target=s,e&&(i.updateLayout(),s.locked||this.app.interaction.updateDownData(t,{findList:[i.editBox.rect]},i.config.dualEvent))):this.allow(t.target)&&(t.shiftKey||(i.target=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 p(e.app.find(gt.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.editor.config.boxSelect||t.target.draggable)&&(!this.editor.hasTarget&&this.allow(t.target)||t.shiftKey&&!ut(t.path))}findDeepOne(t){const e={exclude:new p(this.editor.editBox.rect)};return ut(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_(b.MOVE,this.onPointerMove,this),e.on_(b.BEFORE_DOWN,this.onBeforeDown,this),e.on_(b.TAP,this.onTap,this),e.on_(x.START,this.onDragStart,this),e.on_(x.DRAG,this.onDrag,this),e.on_(x.END,this.onDragEnd,this),e.on_(M.MOVE,this.onAutoMove,this),e.on_([E.ZOOM,M.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 pt;!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"}(pt||(pt={}));const{topLeft:yt,top:wt,topRight:Lt,right:vt,bottomRight:kt,bottom:_t,bottomLeft:mt,left:bt}=pt,{toPoint:xt}=w,Mt={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 c=(-i.y+h)/h,d=(i.x+l)/l,g=(i.y+h)/h,u=(-i.x+l)/l;switch(e){case wt:a=c,n={x:.5,y:1};break;case vt:r=d,n={x:0,y:.5};break;case _t:a=g,n={x:.5,y:0};break;case bt:r=u,n={x:1,y:.5};break;case yt:a=c,r=u,n={x:1,y:1};break;case Lt:a=c,r=d,n={x:0,y:1};break;case kt:a=g,r=d,n={x:0,y:0};break;case mt:a=g,r=u,n={x:1,y:0}}if(s){"corner"===s&&e%2||(1!==a?r=a:a=r)}return xt(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 yt:n={x:1,y:1};break;case Lt:n={x:0,y:1};break;case kt:n={x:0,y:0};break;case mt:n={x:1,y:0};break;default:n={x:.5,y:.5}}return xt(o||n,t,n),{origin:n,rotation:y.getRotation(s,n,i)}},getSkewData(t,e,i,s){let o,n,r=0,a=0;switch(e){case wt:n={x:.5,y:0},o={x:.5,y:1},r=1;break;case _t:n={x:.5,y:1},o={x:.5,y:0},r=1;break;case bt:n={x:0,y:.5},o={x:1,y:.5},a=1;break;case vt:n={x:1,y:.5},o={x:0,y:.5},a=1}const{x:l,y:h,width:c,height:d}=t;n.x=l+n.x*c,n.y=h+n.y*d,xt(s||o,t,o);const g=y.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 bt:t=vt;break;case yt:t=Lt;break;case mt:t=kt;break;case vt:t=bt;break;case Lt:t=yt;break;case kt:t=mt}if(i)switch(t){case wt:t=_t;break;case yt:t=mt;break;case Lt:t=kt;break;case _t:t=wt;break;case mt:t=yt;break;case kt:t=Lt}return t}},Et={};function St(t,e){const{editBox:i}=t,s=i.enterPoint;if(!s||!t.hasTarget||!i.visible)return;if("circle"===s.name)return;let{rotation:o}=i;const{resizeCursor:n,rotateCursor:r,skewCursor:a,resizeable:l,rotateable:h,skewable:c}=t.config,{pointType:d}=s,{flippedX:g,flippedY:u}=i;let f="resize"===d;f&&h&&(e.metaKey||e.ctrlKey||!l)&&(f=!1);const p=c&&!f&&"resize-line"===s.name?a:f?n:r;o+=45*(Mt.getFlipDirection(s.direction,g,u)+1),o=2*Math.round(L.formatRotation(o,!0)/2);const{url:y,x:w,y:v}=p,k=y+o;Et[k]?s.cursor=Et[k]:Et[k]=s.cursor={url:Tt(y,o),x:w,y:v}}function Vt(t){t.editBox.rect.cursor=t.config.moveCursor}function Tt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Ht extends a{}const Ot=["top","right","bottom","left"];class Pt 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.rect=new a({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Ht({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{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 Ht({name:"rotate-point",around:h[r],width:15,height:15,hitFill:"all"}),o.push(t),this.listenPointEvents(t,"rotate",r),r%2&&(e=new Ht({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",r)),i=new Ht({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:i}=this.editor,{width:s,height:o}=t,{rect:n,circle:r,resizePoints:a,rotatePoints:l,resizeLines:h}=this,{middlePoint:c,resizeable:d,rotateable:g,stroke:u,strokeWidth:f,hideOnSmall:p}=e,y=this.getPointsStyle(),L=this.getMiddlePointsStyle(),v="number"==typeof p?p:10,k=!(p&&s<v&&o<v);this.visible=i[0]&&!i[0].locked;let _,m,b,x,M={};for(let i=0;i<8;i++)w.toPoint(w.directionData[i],t,M),_=this.getPointStyle(i%2?L[(i-1)/2%L.length]:y[i/2%y.length]),b=a[i],m=l[i],x=h[Math.floor(i/2)],b.set(_),b.set(M),m.set(M),x.set(M),b.visible=x.visible=k&&(d||g),m.visible=k&&g&&d&&!e.rotatePoint,i%2?(b.visible=m.visible=k&&!!c,(i+1)/2%2?(x.width=s,b.width>s-30&&(b.visible=!1)):(x.height=o,b.rotation=90,b.width>o-30&&(b.visible=!1))):b.rotation=i/2*90;r.visible=k&&g&&!!e.rotatePoint,r.set(this.getPointStyle(e.rotatePoint||y[0])),n.set(Object.assign({stroke:u,strokeWidth:f},e.rect||{})),n.set(Object.assign(Object.assign({},t),{visible:!0})),n.hittable=e.moveable,this.buttons.visible=k,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=Ot.indexOf(i);(l%2&&r||(l+1)%2&&a)&&s&&(l=(l+2)%4);const h=s?Mt.getRotateDirection(l,this.flippedOne?this.rotation:-this.rotation,4):l,c=e[2*h+1],d=h%2,g=h&&3!==h?1:-1,u=(o+(l%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*(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):e.onScale(t),St(e,t)}onArrow(t){if(this.editor.hasTarget&&this.editor.config.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}(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_(x.START,this.onDragStart,this),t.on_(x.DRAG,this.onDrag,this),t.on_(x.END,this.onDragEnd,this),t.on_(b.LEAVE,(()=>this.enterPoint=null)),"circle"!==t.name&&t.on_(b.ENTER,(e=>{this.enterPoint=t,St(s,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_($.SELECT,(()=>{this.visible=e.hasTarget})),t.on_(x.START,this.onDragStart,this),t.on_(x.DRAG,e.onMove,e),t.on_(x.END,this.onDragEnd,this),t.on_(b.ENTER,(()=>Vt(e))),t.on_(b.DOUBLE_CLICK,this.onDoubleClick,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",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};class At{constructor(){this.tag="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()}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:c,height:d}=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:c,height:d})}}At.list=[];const{left:Zt,right:Bt}=pt;class zt extends At{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=v(),{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===Zt?(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){}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===Zt||t===Bt}}const Wt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),It=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Xt={group(t,e,i){t.sort(It);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(Wt);const a=new k(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(Wt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(It),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}};class Yt extends r{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=Rt,this.leafList=new p,this.simulateTarget=new g({visible:!1}),this.editBox=new Pt(this),this.selector=new ft(this),this.targetEventIds=[],t&&(this.config=_.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.hasTarget&&(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 s&&!e.points?new zt:new At}return new At}(this.list)}getEditSize(t){let{editSize:e}=this.config;return"auto"===e?t.editSize:e}onMove(t){const e=t.getLocalMove(this.element),{lockMove:i}=this.config;"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(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=Mt.getScaleData(e.boxBounds,i,t.getInnerMove(e),o,Mt.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,l;if(t instanceof S)l=t.rotation,a=r.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},s=Mt.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.config,{origin:s,skewX:o,skewY:n}=Mt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Mt.getAround(i,t.altKey));(o||n)&&this.skewOf(s,o,n)}move(t,e){if(!this.config.moveable)return;const{element:i}=this,s=i.getWorldPointByLocal({x:t,y:e},null,!0),o=new Q(Q.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 q(q.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 k(o.worldTransform);o.scaleOf(t,e,i),r=new k(o.worldTransform).divide(s)}const a=new q(q.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 k(i.worldTransform);i.rotateOf(t,e),o=new k(i.worldTransform).divide(s)}const n=new J(J.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 k(o.worldTransform);o.skewOf(t,e,i),r=new k(o.worldTransform).divide(s)}const a=new tt(tt.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=Xt.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=Xt.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&&(Xt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Xt.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(m.START,this.update,this),t.on_([V.HOLD,V.UP],(t=>{St(this,t)})),t.on_(V.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())}}N([et((function(t,e){t.emitEvent(new $($.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Yt.prototype,"hoverTarget",void 0),N([et((function(t,e){const{target:i}=t;i?t.leafList=i instanceof p?i:new p(i):t.leafList.reset(),t.emitEvent(new $($.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 f).setListWithFn(i.list,(t=>t.worldBoxBounds)),a=e.parent=i.list[0].leafer.zoomLayer,{scaleX:l,scaleY:h,e:c,f:d}=a.__world;e.reset({x:(s-c)/l,y:(o-d)/h,width:n/l,height:r/h})}(t),Vt(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):t.removeTargetEvents()}))],Yt.prototype,"target",void 0),T.editor=function(t){return new Yt(t)};export{Pt as EditBox,Mt as EditDataHelper,Ht as EditPoint,ft as EditSelect,gt as EditSelectHelper,At as EditTool,Yt as Editor,$ as EditorEvent,Xt as EditorHelper,Q as EditorMoveEvent,J as EditorRotateEvent,q as EditorScaleEvent,tt as EditorSkewEvent,zt as LineEditTool,at as SelectArea,rt as Stroker};
|
package/dist/editor.js
CHANGED
|
@@ -182,7 +182,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
182
182
|
function toList(value) {
|
|
183
183
|
return value ? (value instanceof Array ? value : [value]) : [];
|
|
184
184
|
}
|
|
185
|
-
class EditorEvent extends
|
|
185
|
+
class EditorEvent extends draw.Event {
|
|
186
186
|
get list() { return toList(this.value); }
|
|
187
187
|
get oldList() { return toList(this.oldValue); }
|
|
188
188
|
constructor(type, data) {
|
|
@@ -225,7 +225,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
225
225
|
function targetAttr(fn) {
|
|
226
226
|
return (target, key) => {
|
|
227
227
|
const privateKey = '_' + key;
|
|
228
|
-
|
|
228
|
+
draw.defineKey(target, key, {
|
|
229
229
|
get() { return this[privateKey]; },
|
|
230
230
|
set(value) {
|
|
231
231
|
const old = this[privateKey];
|
|
@@ -236,10 +236,10 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
236
236
|
};
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
const matrix =
|
|
239
|
+
const matrix = draw.MatrixHelper.get();
|
|
240
240
|
const { abs } = Math;
|
|
241
|
-
const { copy, scale } =
|
|
242
|
-
class Stroker extends
|
|
241
|
+
const { copy, scale } = draw.MatrixHelper;
|
|
242
|
+
class Stroker extends draw.UI {
|
|
243
243
|
constructor() {
|
|
244
244
|
super();
|
|
245
245
|
this.list = [];
|
|
@@ -285,7 +285,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
285
285
|
}
|
|
286
286
|
this.__.strokeWidth = strokeWidth / abs(leaf.__world.scaleX);
|
|
287
287
|
}
|
|
288
|
-
typeof stroke === 'string' ?
|
|
288
|
+
typeof stroke === 'string' ? draw.Paint.stroke(stroke, this, canvas) : draw.Paint.strokes(stroke, this, canvas);
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
this.__.strokeWidth = strokeWidth;
|
|
@@ -305,11 +305,11 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
305
305
|
stroker.forceUpdate();
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
class SelectArea extends
|
|
308
|
+
class SelectArea extends draw.Group {
|
|
309
309
|
constructor(data) {
|
|
310
310
|
super(data);
|
|
311
|
-
this.strokeArea = new
|
|
312
|
-
this.fillArea = new
|
|
311
|
+
this.strokeArea = new draw.Rect({ strokeAlign: 'center' });
|
|
312
|
+
this.fillArea = new draw.Rect();
|
|
313
313
|
this.visible = this.hittable = false;
|
|
314
314
|
this.addMany(this.fillArea, this.strokeArea);
|
|
315
315
|
}
|
|
@@ -325,7 +325,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
-
const { No, Yes, NoAndSkip, YesAndSkip } =
|
|
328
|
+
const { No, Yes, NoAndSkip, YesAndSkip } = draw.Answer;
|
|
329
329
|
const EditSelectHelper = {
|
|
330
330
|
findOne(path) {
|
|
331
331
|
return path.list.find((leaf) => leaf.editable);
|
|
@@ -353,7 +353,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
353
353
|
};
|
|
354
354
|
|
|
355
355
|
const { findOne } = EditSelectHelper;
|
|
356
|
-
class EditSelect extends
|
|
356
|
+
class EditSelect extends draw.Group {
|
|
357
357
|
get dragging() { return !!this.originList; }
|
|
358
358
|
get running() { return this.editor.hittable && this.editor.config.selector; }
|
|
359
359
|
get isMoveMode() { return this.app && this.app.interaction.moveMode; }
|
|
@@ -361,7 +361,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
361
361
|
super();
|
|
362
362
|
this.hoverStroker = new Stroker();
|
|
363
363
|
this.targetStroker = new Stroker();
|
|
364
|
-
this.bounds = new
|
|
364
|
+
this.bounds = new draw.Bounds();
|
|
365
365
|
this.selectArea = new SelectArea();
|
|
366
366
|
this.__eventIds = [];
|
|
367
367
|
this.editor = editor;
|
|
@@ -465,7 +465,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
465
465
|
const { editor } = this;
|
|
466
466
|
const total = e.getInnerTotal(this);
|
|
467
467
|
const dragBounds = this.bounds.clone().unsign();
|
|
468
|
-
const list = new
|
|
468
|
+
const list = new draw.LeafList(editor.app.find(EditSelectHelper.findBounds, dragBounds));
|
|
469
469
|
this.bounds.width = total.x;
|
|
470
470
|
this.bounds.height = total.y;
|
|
471
471
|
this.selectArea.setBounds(dragBounds.get());
|
|
@@ -507,7 +507,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
509
|
findDeepOne(e) {
|
|
510
|
-
const options = { exclude: new
|
|
510
|
+
const options = { exclude: new draw.LeafList(this.editor.editBox.rect) };
|
|
511
511
|
return findOne(e.target.leafer.interaction.findPath(e, options));
|
|
512
512
|
}
|
|
513
513
|
__listenEvents() {
|
|
@@ -555,7 +555,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
555
555
|
})(IDirection8 || (IDirection8 = {}));
|
|
556
556
|
|
|
557
557
|
const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft, left: left$1 } = IDirection8;
|
|
558
|
-
const { toPoint } =
|
|
558
|
+
const { toPoint } = draw.AroundHelper;
|
|
559
559
|
const EditDataHelper = {
|
|
560
560
|
getScaleData(bounds, direction, pointMove, lockRatio, around) {
|
|
561
561
|
let origin, scaleX = 1, scaleY = 1;
|
|
@@ -640,7 +640,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
640
640
|
origin = { x: 0.5, y: 0.5 };
|
|
641
641
|
}
|
|
642
642
|
toPoint(around || origin, bounds, origin);
|
|
643
|
-
return { origin, rotation:
|
|
643
|
+
return { origin, rotation: draw.PointHelper.getRotation(last, origin, current) };
|
|
644
644
|
},
|
|
645
645
|
getSkewData(bounds, direction, move, around) {
|
|
646
646
|
let origin, skewX = 0, skewY = 0;
|
|
@@ -670,7 +670,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
670
670
|
last.x = x + last.x * width;
|
|
671
671
|
last.y = y + last.y * height;
|
|
672
672
|
toPoint(around || origin, bounds, origin);
|
|
673
|
-
const rotation =
|
|
673
|
+
const rotation = draw.PointHelper.getRotation(last, origin, { x: last.x + (skewX ? move.x : 0), y: last.y + (skewY ? move.y : 0) });
|
|
674
674
|
skewX ? skewX = -rotation : skewY = rotation;
|
|
675
675
|
return { origin, skewX, skewY };
|
|
676
676
|
},
|
|
@@ -748,7 +748,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
748
748
|
const showSkew = skewable && !showResize && point.name === 'resize-line';
|
|
749
749
|
const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor);
|
|
750
750
|
rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45;
|
|
751
|
-
rotation = Math.round(
|
|
751
|
+
rotation = Math.round(draw.MathHelper.formatRotation(rotation, true) / 2) * 2;
|
|
752
752
|
const { url, x, y } = cursor;
|
|
753
753
|
const key = url + rotation;
|
|
754
754
|
if (cacheCursors[key]) {
|
|
@@ -765,20 +765,20 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
765
765
|
return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"';
|
|
766
766
|
}
|
|
767
767
|
|
|
768
|
-
class EditPoint extends
|
|
768
|
+
class EditPoint extends draw.Box {
|
|
769
769
|
}
|
|
770
770
|
|
|
771
771
|
const fourDirection = ['top', 'right', 'bottom', 'left'];
|
|
772
|
-
class EditBox extends
|
|
772
|
+
class EditBox extends draw.Group {
|
|
773
773
|
get flipped() { return this.flippedX || this.flippedY; }
|
|
774
774
|
get flippedX() { return this.scaleX < 0; }
|
|
775
775
|
get flippedY() { return this.scaleY < 0; }
|
|
776
776
|
get flippedOne() { return this.scaleX * this.scaleY < 0; }
|
|
777
777
|
constructor(editor) {
|
|
778
778
|
super();
|
|
779
|
-
this.rect = new
|
|
779
|
+
this.rect = new draw.Box({ name: 'rect', hitFill: 'all', hitStroke: 'none', strokeAlign: 'center', hitRadius: 5 });
|
|
780
780
|
this.circle = new EditPoint({ name: 'circle', strokeAlign: 'center', around: 'center', cursor: 'crosshair', hitRadius: 5 });
|
|
781
|
-
this.buttons = new
|
|
781
|
+
this.buttons = new draw.Group({ around: 'center', hitSelf: false });
|
|
782
782
|
this.resizePoints = [];
|
|
783
783
|
this.rotatePoints = [];
|
|
784
784
|
this.resizeLines = [];
|
|
@@ -821,7 +821,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
|
|
|
821
821
|
this.visible = list[0] && !list[0].locked;
|
|
822
822
|
let point = {}, style, rotateP, resizeP, resizeL;
|
|
823
823
|
for (let i = 0; i < 8; i++) {
|
|
824
|
-
|
|
824
|
+
draw.AroundHelper.toPoint(draw.AroundHelper.directionData[i], bounds, point);
|
|
825
825
|
style = this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]);
|
|
826
826
|
resizeP = resizePoints[i], rotateP = rotatePoints[i], resizeL = resizeLines[Math.floor(i / 2)];
|
|
827
827
|
resizeP.set(style);
|
|
@@ -1135,7 +1135,7 @@ ${filterStyle}
|
|
|
1135
1135
|
onScaleWithDrag(e) {
|
|
1136
1136
|
const { drag, direction, lockRatio, around } = e;
|
|
1137
1137
|
const target = e.target;
|
|
1138
|
-
const fromPoint =
|
|
1138
|
+
const fromPoint = draw.getPointData();
|
|
1139
1139
|
const { toPoint } = target;
|
|
1140
1140
|
target.rotation = 0;
|
|
1141
1141
|
let { x, y } = drag.getInnerMove(target);
|
|
@@ -1186,7 +1186,7 @@ ${filterStyle}
|
|
|
1186
1186
|
function getEditTool(list) {
|
|
1187
1187
|
if (list.length === 1) {
|
|
1188
1188
|
const leaf = list[0];
|
|
1189
|
-
if (leaf instanceof
|
|
1189
|
+
if (leaf instanceof draw.Line && !leaf.points) {
|
|
1190
1190
|
return new LineEditTool();
|
|
1191
1191
|
}
|
|
1192
1192
|
else {
|
|
@@ -1200,7 +1200,7 @@ ${filterStyle}
|
|
|
1200
1200
|
|
|
1201
1201
|
function simulate(editor) {
|
|
1202
1202
|
const { simulateTarget, leafList: targetList } = editor;
|
|
1203
|
-
const { x, y, width, height } = new
|
|
1203
|
+
const { x, y, width, height } = new draw.Bounds().setListWithFn(targetList.list, (leaf) => leaf.worldBoxBounds);
|
|
1204
1204
|
const parent = simulateTarget.parent = targetList.list[0].leafer.zoomLayer;
|
|
1205
1205
|
const { scaleX, scaleY, e: worldX, f: worldY } = parent.__world;
|
|
1206
1206
|
simulateTarget.reset({ x: (x - worldX) / scaleX, y: (y - worldY) / scaleY, width: width / scaleX, height: height / scaleY });
|
|
@@ -1209,7 +1209,7 @@ ${filterStyle}
|
|
|
1209
1209
|
function onTarget(editor, oldValue) {
|
|
1210
1210
|
const { target } = editor;
|
|
1211
1211
|
if (target) {
|
|
1212
|
-
editor.leafList = target instanceof
|
|
1212
|
+
editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target instanceof Array ? target : target);
|
|
1213
1213
|
}
|
|
1214
1214
|
else {
|
|
1215
1215
|
editor.leafList.reset();
|
|
@@ -1244,11 +1244,11 @@ ${filterStyle}
|
|
|
1244
1244
|
group = userGroup;
|
|
1245
1245
|
}
|
|
1246
1246
|
else {
|
|
1247
|
-
group = new
|
|
1247
|
+
group = new draw.Group(userGroup);
|
|
1248
1248
|
}
|
|
1249
1249
|
parent.addAt(group, parent.children.indexOf(list[0]));
|
|
1250
1250
|
list.sort(order);
|
|
1251
|
-
const matrx = new
|
|
1251
|
+
const matrx = new draw.Matrix(element.worldTransform);
|
|
1252
1252
|
matrx.divideParent(parent.worldTransform);
|
|
1253
1253
|
group.setTransform(matrx);
|
|
1254
1254
|
group.editable = true;
|
|
@@ -1294,7 +1294,7 @@ ${filterStyle}
|
|
|
1294
1294
|
}
|
|
1295
1295
|
};
|
|
1296
1296
|
|
|
1297
|
-
class Editor extends
|
|
1297
|
+
class Editor extends draw.Group {
|
|
1298
1298
|
get list() { return this.leafList.list; }
|
|
1299
1299
|
get hasTarget() { return !!this.list.length; }
|
|
1300
1300
|
get multiple() { return this.list.length > 1; }
|
|
@@ -1305,13 +1305,13 @@ ${filterStyle}
|
|
|
1305
1305
|
constructor(userConfig, data) {
|
|
1306
1306
|
super(data);
|
|
1307
1307
|
this.config = config;
|
|
1308
|
-
this.leafList = new
|
|
1309
|
-
this.simulateTarget = new
|
|
1308
|
+
this.leafList = new draw.LeafList();
|
|
1309
|
+
this.simulateTarget = new draw.Rect({ visible: false });
|
|
1310
1310
|
this.editBox = new EditBox(this);
|
|
1311
1311
|
this.selector = new EditSelect(this);
|
|
1312
1312
|
this.targetEventIds = [];
|
|
1313
1313
|
if (userConfig)
|
|
1314
|
-
this.config =
|
|
1314
|
+
this.config = draw.DataHelper.default(userConfig, this.config);
|
|
1315
1315
|
this.addMany(this.selector, this.editBox);
|
|
1316
1316
|
}
|
|
1317
1317
|
hasItem(item) {
|
|
@@ -1388,12 +1388,12 @@ ${filterStyle}
|
|
|
1388
1388
|
rotation = data.rotation;
|
|
1389
1389
|
origin = data.origin;
|
|
1390
1390
|
}
|
|
1391
|
-
rotation =
|
|
1391
|
+
rotation = draw.MathHelper.getGapRotation(rotation, rotateGap, element.rotation);
|
|
1392
1392
|
if (!rotation)
|
|
1393
1393
|
return;
|
|
1394
1394
|
if (element.scaleX * element.scaleY < 0)
|
|
1395
1395
|
rotation = -rotation;
|
|
1396
|
-
this.rotateOf(origin,
|
|
1396
|
+
this.rotateOf(origin, draw.MathHelper.float(rotation, 2));
|
|
1397
1397
|
}
|
|
1398
1398
|
onSkew(e) {
|
|
1399
1399
|
const { element } = this;
|
|
@@ -1426,9 +1426,9 @@ ${filterStyle}
|
|
|
1426
1426
|
const worldOrigin = element.getWorldPoint(origin);
|
|
1427
1427
|
let transform;
|
|
1428
1428
|
if (this.multiple) {
|
|
1429
|
-
const oldMatrix = new
|
|
1429
|
+
const oldMatrix = new draw.Matrix(element.worldTransform);
|
|
1430
1430
|
element.scaleOf(origin, scaleX, scaleY);
|
|
1431
|
-
transform = new
|
|
1431
|
+
transform = new draw.Matrix(element.worldTransform).divide(oldMatrix);
|
|
1432
1432
|
}
|
|
1433
1433
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX, scaleY, transform });
|
|
1434
1434
|
this.editTool.onScale(event);
|
|
@@ -1439,9 +1439,9 @@ ${filterStyle}
|
|
|
1439
1439
|
const worldOrigin = element.getWorldPoint(origin);
|
|
1440
1440
|
let transform;
|
|
1441
1441
|
if (this.multiple) {
|
|
1442
|
-
const oldMatrix = new
|
|
1442
|
+
const oldMatrix = new draw.Matrix(element.worldTransform);
|
|
1443
1443
|
element.rotateOf(origin, rotation);
|
|
1444
|
-
transform = new
|
|
1444
|
+
transform = new draw.Matrix(element.worldTransform).divide(oldMatrix);
|
|
1445
1445
|
}
|
|
1446
1446
|
const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, { target: element, editor: this, worldOrigin, rotation, transform });
|
|
1447
1447
|
this.editTool.onRotate(event);
|
|
@@ -1452,9 +1452,9 @@ ${filterStyle}
|
|
|
1452
1452
|
const worldOrigin = element.getWorldPoint(origin);
|
|
1453
1453
|
let transform;
|
|
1454
1454
|
if (this.multiple) {
|
|
1455
|
-
const oldMatrix = new
|
|
1455
|
+
const oldMatrix = new draw.Matrix(element.worldTransform);
|
|
1456
1456
|
element.skewOf(origin, skewX, skewY);
|
|
1457
|
-
transform = new
|
|
1457
|
+
transform = new draw.Matrix(element.worldTransform).divide(oldMatrix);
|
|
1458
1458
|
}
|
|
1459
1459
|
const event = new EditorSkewEvent(EditorSkewEvent.SKEW, {
|
|
1460
1460
|
target: element, editor: this, skewX, skewY, transform, worldOrigin
|
|
@@ -1496,7 +1496,7 @@ ${filterStyle}
|
|
|
1496
1496
|
if (!this.targetEventIds.length) {
|
|
1497
1497
|
const { leafer } = this.list[0];
|
|
1498
1498
|
this.targetEventIds = [
|
|
1499
|
-
leafer.on_(
|
|
1499
|
+
leafer.on_(draw.RenderEvent.START, this.update, this),
|
|
1500
1500
|
leafer.on_([core.KeyEvent.HOLD, core.KeyEvent.UP], (e) => { updateCursor(this, e); }),
|
|
1501
1501
|
leafer.on_(core.KeyEvent.DOWN, this.editBox.onArrow, this.editBox)
|
|
1502
1502
|
];
|
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:c,G:d,F:g,O:u,P:f,U:p}=e.PathCommandMap,v={scale(t,e,i){if(!t)return;let v,L=0,w=t.length;for(;L<w;)switch(v=t[L],v){case s:case o:y(t,e,i,L,1),L+=3;break;case n:y(t,e,i,L,3),L+=7;break;case r:y(t,e,i,L,2),L+=5;break;case a:L+=1;break;case l:y(t,e,i,L,2),L+=5;break;case h:y(t,e,i,L,2),L+=9;break;case c:y(t,e,i,L,2),L+=6;break;case d:y(t,e,i,L,2),L+=9;break;case g:y(t,e,i,L,2),L+=5;break;case u:t[L]=d,t.splice(L+4,0,t[L+3],0),y(t,e,i,L,2),L+=9,w+=2;break;case f:t[L]=g,t.splice(L+4,0,t[L+3]),y(t,e,i,L,2),L+=5,w+=1;break;case p:y(t,e,i,L,2),L+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:y}=v;function L(t,e,i){1!==e&&(t.width*=e),1!==i&&(t.height*=i)}e.Leaf.prototype.scaleResize=function(t,e=t,i){const s=this;i?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},e.Leaf.prototype.__scaleResize=function(t,e){L(this,t,e)},e.Path.prototype.__scaleResize=function(t,e){v.scale(this.__.path,t,e),this.path=this.__.path},e.Line.prototype.__scaleResize=function(t,e){if(this.points)v.scalePoints(this.__.points,t,e),this.points=this.__.points;else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},e.Polygon.prototype.__scaleResize=function(t,e){this.points?(v.scalePoints(this.__.points,t,e),this.points=this.__.points):L(this,t,e)};const 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 _(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 x(t){return t?t instanceof Array?t:[t]:[]}e.Group.prototype.__scaleResize=function(t,e){k(this,t,e)},e.Box.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?k(this,t,e):L(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class m extends i.Event{get list(){return x(this.value)}get oldList(){return x(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}m.SELECT="editor.select",m.HOVER="editor.hover";class b extends m{constructor(t,e){super(t,e)}}b.MOVE="editor.move";class E extends m{constructor(t,e){super(t,e)}}E.SCALE="editor.scale";class M extends m{constructor(t,e){super(t,e)}}M.ROTATE="editor.rotate";class S extends m{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))}})}}S.SKEW="editor.skew";const V=i.MatrixHelper.get(),{abs:P}=Math,{copy:T,scale:D}=i.MatrixHelper;class O 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=P(o.__world.scaleX),n=P(o.__world.scaleY);if(i!==n){T(V,o.__world),D(V,1/i,1/n),t.setWorld(V,e.matrix),t.beginPath(),this.__.strokeWidth=r;const{x:a,y:l,width:h,height:c}=o.__layout.boxBounds;t.rect(a*i,l*n,h*i,c*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/P(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()}}_([H((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],O.prototype,"target",void 0);class R 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:A,Yes:B,NoAndSkip:Z,YesAndSkip:z}=i.Answer,I={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?z:Z;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?z:A;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return B}return A}return t.isBranch?Z:A}},{findOne:W}=I;class C 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 O,this.targetStroker=new O,this.bounds=new i.Bounds,this.selectArea=new R,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){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=t.shiftKey?this.findDeepOne(t):W(t.path);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.config;"press"===e&&this.checkAndSelect(t,!0)}onTap(t){const{editor:e}=this,{select:i,continuousSelect:s}=e.config;if("tap"===i&&this.checkAndSelect(t),!this.running||!t.shiftKey&&!s||t.middle||this.lastDownLeaf)this.isMoveMode&&(e.target=null);else{const i=this.findDeepOne(t);i?e.shiftItem(i):!t.shiftKey&&s&&(e.target=null)}this.lastDownLeaf=null}checkAndSelect(t,e){if(this.running&&!this.isMoveMode&&!t.middle){const{editor:i}=this,s=this.lastDownLeaf=W(t.path);s?(t.shiftKey||i.config.continuousSelect?i.shiftItem(s):i.target=s,e&&(i.updateLayout(),s.locked||this.app.interaction.updateDownData(t,{findList:[i.editBox.rect]},i.config.dualEvent))):this.allow(t.target)&&(t.shiftKey||(i.target=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(I.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}}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&&!W(t.path))}findDeepOne(t){const e={exclude:new i.LeafList(this.editor.editBox.rect)};return W(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_(m.HOVER,this.onHover,this),t.on_(m.SELECT,this.onSelect,this),e.on_(i.PointerEvent.MOVE,this.onPointerMove,this),e.on_(i.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this),e.on_(i.PointerEvent.TAP,this.onTap,this),e.on_(i.DragEvent.START,this.onDragStart,this),e.on_(i.DragEvent.DRAG,this.onDrag,this),e.on_(i.DragEvent.END,this.onDragEnd,this),e.on_(i.MoveEvent.MOVE,this.onAutoMove,this),e.on_([i.ZoomEvent.ZOOM,i.MoveEvent.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.lastDownLeaf=null,this.__removeListenEvents(),super.destroy()}}var X;!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"}(X||(X={}));const{topLeft:Y,top:K,topRight:F,right:G,bottomRight:U,bottom:N,bottomLeft:j,left:$}=X,{toPoint:Q}=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 c=(-i.y+h)/h,d=(i.x+l)/l,g=(i.y+h)/h,u=(-i.x+l)/l;switch(e){case K:a=c,n={x:.5,y:1};break;case G:r=d,n={x:0,y:.5};break;case N:a=g,n={x:.5,y:0};break;case $:r=u,n={x:1,y:.5};break;case Y:a=c,r=u,n={x:1,y:1};break;case F:a=c,r=d,n={x:0,y:1};break;case U:a=g,r=d,n={x:0,y:0};break;case j:a=g,r=u,n={x:1,y:0}}if(s){"corner"===s&&e%2||(1!==a?r=a:a=r)}return Q(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 Y:r={x:1,y:1};break;case F:r={x:0,y:1};break;case U:r={x:0,y:0};break;case j:r={x:1,y:0};break;default:r={x:.5,y:.5}}return Q(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 K:r={x:.5,y:0},n={x:.5,y:1},a=1;break;case N:r={x:.5,y:1},n={x:.5,y:0},a=1;break;case $:r={x:0,y:.5},n={x:1,y:.5},l=1;break;case G:r={x:1,y:.5},n={x:0,y:.5},l=1}const{x:h,y:c,width:d,height:g}=t;r.x=h+r.x*d,r.y=c+r.y*g,Q(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 $:t=G;break;case Y:t=F;break;case j:t=U;break;case G:t=$;break;case F:t=Y;break;case U:t=j}if(i)switch(t){case K:t=N;break;case Y:t=j;break;case F:t=U;break;case N:t=K;break;case j:t=Y;break;case U:t=F}return t}},J={};function tt(t,e){const{editBox:s}=t,o=s.enterPoint;if(!o||!t.hasTarget||!s.visible)return;if("circle"===o.name)return;let{rotation:n}=s;const{resizeCursor:r,rotateCursor:a,skewCursor:l,resizeable:h,rotateable:c,skewable:d}=t.config,{pointType:g}=o,{flippedX:u,flippedY:f}=s;let p="resize"===g;p&&c&&(e.metaKey||e.ctrlKey||!h)&&(p=!1);const v=d&&!p&&"resize-line"===o.name?l:p?r:a;n+=45*(q.getFlipDirection(o.direction,u,f)+1),n=2*Math.round(i.MathHelper.formatRotation(n,!0)/2);const{url:y,x:L,y:w}=v,k=y+n;J[k]?o.cursor=J[k]:J[k]=o.cursor={url:it(y,n),x:L,y:w}}function et(t){t.editBox.rect.cursor=t.config.moveCursor}function it(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class st extends i.Box{}const ot=["top","right","bottom","left"];class nt 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 st({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 st({name:"rotate-point",around:h[r],width:15,height:15,hitFill:"all"}),o.push(t),this.listenPointEvents(t,"rotate",r),r%2&&(e=new st({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",r)),i=new st({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:c}=this,{middlePoint:d,resizeable:g,rotateable:u,stroke:f,strokeWidth:p,hideOnSmall:v}=e,y=this.getPointsStyle(),L=this.getMiddlePointsStyle(),w="number"==typeof v?v:10,k=!(v&&o<w&&n<w);this.visible=s[0]&&!s[0].locked;let _,x,m,b,E={};for(let s=0;s<8;s++)i.AroundHelper.toPoint(i.AroundHelper.directionData[s],t,E),_=this.getPointStyle(s%2?L[(s-1)/2%L.length]:y[s/2%y.length]),m=l[s],x=h[s],b=c[Math.floor(s/2)],m.set(_),m.set(E),x.set(E),b.set(E),m.visible=b.visible=k&&(g||u),x.visible=k&&u&&g&&!e.rotatePoint,s%2?(m.visible=x.visible=k&&!!d,(s+1)/2%2?(b.width=o,m.width>o-30&&(m.visible=!1)):(b.height=n,m.rotation=90,m.width>n-30&&(m.visible=!1))):m.rotation=s/2*90;a.visible=k&&u&&!!e.rotatePoint,a.set(this.getPointStyle(e.rotatePoint||y[0])),r.set(Object.assign({stroke:f,strokeWidth:p},e.rect||{})),r.set(Object.assign(Object.assign({},t),{visible:!0})),r.hittable=e.moveable,this.buttons.visible=k,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=ot.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,c=e[2*h+1],d=h%2,g=h&&3!==h?1:-1,u=(o+(l%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*(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):e.onScale(t),tt(e,t)}onArrow(t){if(this.editor.hasTarget&&this.editor.config.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}(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,tt(o,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(m.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,(()=>et(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 rt='\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",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${rt}\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${rt}\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${rt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};class lt{constructor(){this.tag="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()}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:c,height:d}=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:c,height:d})}}lt.list=[];const{left:ht,right:ct}=X;class dt extends lt{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:c}=e.getInnerMove(r);o&&(Math.abs(h)>Math.abs(c)?c=0:h=0),s===ht?(a.x+=h,a.y+=c,n&&(l.x-=h,l.y-=c)):(n&&(a.x-=h,a.y-=c),l.x+=h,l.y+=c),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===ht||t===ct}}const gt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),ut=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),ft={group(t,e,s){t.sort(ut);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(gt);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(gt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(ut),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}};class pt 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=at,this.leafList=new i.LeafList,this.simulateTarget=new i.Rect({visible:!1}),this.editBox=new nt(this),this.selector=new C(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.hasTarget&&(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 dt:new lt}return new lt}(this.list)}getEditSize(t){let{editSize:e}=this.config;return"auto"===e?t.editSize:e}onMove(t){const e=t.getLocalMove(this.element),{lockMove:i}=this.config;"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(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){if(!this.config.moveable)return;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 E(E.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 E(E.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 M(M.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 S(S.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=ft.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=ft.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&&(ft.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(ft.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=>{tt(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 _([H((function(t,e){t.emitEvent(new m(m.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],pt.prototype,"hoverTarget",void 0),_([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 m(m.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:c,e:d,f:g}=l.__world;e.reset({x:(o-d)/h,y:(n-g)/c,width:r/h,height:a/c})}(t),et(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):t.removeTargetEvents()}))],pt.prototype,"target",void 0),i.Creator.editor=function(t){return new pt(t)},t.EditBox=nt,t.EditDataHelper=q,t.EditPoint=st,t.EditSelect=C,t.EditSelectHelper=I,t.EditTool=lt,t.Editor=pt,t.EditorEvent=m,t.EditorHelper=ft,t.EditorMoveEvent=b,t.EditorRotateEvent=M,t.EditorScaleEvent=E,t.EditorSkewEvent=S,t.LineEditTool=dt,t.SelectArea=R,t.Stroker=O,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:c,G:d,F:g,O:u,P:f,U:p}=e.PathCommandMap,v={scale(t,e,i){if(!t)return;let v,L=0,w=t.length;for(;L<w;)switch(v=t[L],v){case s:case o:y(t,e,i,L,1),L+=3;break;case n:y(t,e,i,L,3),L+=7;break;case r:y(t,e,i,L,2),L+=5;break;case a:L+=1;break;case l:y(t,e,i,L,2),L+=5;break;case h:y(t,e,i,L,2),L+=9;break;case c:y(t,e,i,L,2),L+=6;break;case d:y(t,e,i,L,2),L+=9;break;case g:y(t,e,i,L,2),L+=5;break;case u:t[L]=d,t.splice(L+4,0,t[L+3],0),y(t,e,i,L,2),L+=9,w+=2;break;case f:t[L]=g,t.splice(L+4,0,t[L+3]),y(t,e,i,L,2),L+=5,w+=1;break;case p:y(t,e,i,L,2),L+=6}},scalePoints(t,e,i,s,o){for(let n=o?s+1:0,r=o?n+2*o:t.length;n<r;n+=2)t[n]*=e,t[n+1]*=i}},{scalePoints:y}=v;function L(t,e,i){1!==e&&(t.width*=e),1!==i&&(t.height*=i)}e.Leaf.prototype.scaleResize=function(t,e=t,i){const s=this;i?(s.scaleX*=t,s.scaleY*=e):(t<0&&(s.scaleX*=-1,t=-t),e<0&&(s.scaleY*=-1,e=-e),this.__scaleResize(t,e))},e.Leaf.prototype.__scaleResize=function(t,e){L(this,t,e)},e.Path.prototype.__scaleResize=function(t,e){v.scale(this.__.path,t,e),this.path=this.__.path},e.Line.prototype.__scaleResize=function(t,e){if(this.points)v.scalePoints(this.__.points,t,e),this.points=this.__.points;else{const i=this.toPoint;i.x*=t,i.y*=e,this.toPoint=i}},e.Polygon.prototype.__scaleResize=function(t,e){this.points?(v.scalePoints(this.__.points,t,e),this.points=this.__.points):L(this,t,e)};const 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 _(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 x(t){return t?t instanceof Array?t:[t]:[]}e.Group.prototype.__scaleResize=function(t,e){k(this,t,e)},e.Box.prototype.__scaleResize=function(t,e){this.__.__autoSize&&this.children.length?k(this,t,e):L(this,t,e)},"function"==typeof SuppressedError&&SuppressedError;class m extends e.Event{get list(){return x(this.value)}get oldList(){return x(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}m.SELECT="editor.select",m.HOVER="editor.hover";class b extends m{constructor(t,e){super(t,e)}}b.MOVE="editor.move";class E extends m{constructor(t,e){super(t,e)}}E.SCALE="editor.scale";class M extends m{constructor(t,e){super(t,e)}}M.ROTATE="editor.rotate";class S extends m{constructor(t,e){super(t,e)}}function H(t){return(i,s)=>{const o="_"+s;e.defineKey(i,s,{get(){return this[o]},set(e){const i=this[o];i!==e&&(this[o]=e,t(this,i))}})}}S.SKEW="editor.skew";const V=e.MatrixHelper.get(),{abs:P}=Math,{copy:T,scale:D}=e.MatrixHelper;class O extends e.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,i){const{list:s}=this;if(s.length){let o;const{stroke:n,strokeWidth:r}=this.__,{bounds:a}=i;for(let l=0;l<s.length;l++)if(o=s[l],a&&a.hit(o.__world,i.matrix)){let s;if("scale"===o.__.editSize){const e=P(o.__world.scaleX),n=P(o.__world.scaleY);if(e!==n){T(V,o.__world),D(V,1/e,1/n),t.setWorld(V,i.matrix),t.beginPath(),this.__.strokeWidth=r;const{x:a,y:l,width:h,height:c}=o.__layout.boxBounds;t.rect(a*e,l*n,h*e,c*n),s=!0}}s||(t.setWorld(o.__world,i.matrix),t.beginPath(),o.__.__useArrow?o.__drawPath(t):o.__.__pathForRender?o.__drawRenderPath(t):o.__drawPathByBox(t),this.__.strokeWidth=r/P(o.__world.scaleX)),"string"==typeof n?e.Paint.stroke(n,this,t):e.Paint.strokes(n,this,t)}this.__.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}_([H((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[],t.forceUpdate()}))],O.prototype,"target",void 0);class R extends e.Group{constructor(t){super(t),this.strokeArea=new e.Rect({strokeAlign:"center"}),this.fillArea=new e.Rect,this.visible=this.hittable=!1,this.addMany(this.fillArea,this.strokeArea)}setStyle(t,e){const{visible:i,stroke:s,strokeWidth:o}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:s,strokeWidth:o},e||{})),this.fillArea.reset({visible:!e,fill:s,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const{No:A,Yes:B,NoAndSkip:Z,YesAndSkip:z}=e.Answer,I={findOne:t=>t.list.find((t=>t.editable)),findBounds(t,e){if(t.__.hittable&&t.__.visible&&!t.__.locked&&e.hit(t.__world)){if(t.__.editable){if(t.isBranch&&!t.__.hitChildren)return t.__.hitSelf?z:Z;if(t.isFrame)return e.includes(t.__layout.boxBounds,t.__world)?z:A;if(e.hit(t.__layout.boxBounds,t.__world)&&t.__.hitSelf)return B}return A}return t.isBranch?Z:A}},{findOne:W}=I;class C extends e.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 O,this.targetStroker=new O,this.bounds=new e.Bounds,this.selectArea=new R,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){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.config.pointer.hover&&!e.interaction.dragging){const e=t.shiftKey?this.findDeepOne(t):W(t.path);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){const{select:e}=this.editor.config;"press"===e&&this.checkAndSelect(t,!0)}onTap(t){const{editor:e}=this,{select:i,continuousSelect:s}=e.config;if("tap"===i&&this.checkAndSelect(t),!this.running||!t.shiftKey&&!s||t.middle||this.lastDownLeaf)this.isMoveMode&&(e.target=null);else{const i=this.findDeepOne(t);i?e.shiftItem(i):!t.shiftKey&&s&&(e.target=null)}this.lastDownLeaf=null}checkAndSelect(t,e){if(this.running&&!this.isMoveMode&&!t.middle){const{editor:i}=this,s=this.lastDownLeaf=W(t.path);s?(t.shiftKey||i.config.continuousSelect?i.shiftItem(s):i.target=s,e&&(i.updateLayout(),s.locked||this.app.interaction.updateDownData(t,{findList:[i.editBox.rect]},i.config.dualEvent))):this.allow(t.target)&&(t.shiftKey||(i.target=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:i}=this,s=t.getInnerTotal(this),o=this.bounds.clone().unsign(),n=new e.LeafList(i.app.find(I.findBounds,o));if(this.bounds.width=s.x,this.bounds.height=s.y,this.selectArea.setBounds(o.get()),n.length){const t=[];this.originList.forEach((e=>{n.has(e)||t.push(e)})),n.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==i.list.length||i.list.some(((e,i)=>e!==t[i])))&&(i.target=t)}else i.target=this.originList.list}}onDragEnd(){this.dragging&&(this.originList=null,this.selectArea.visible=!1)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){return!(!this.editor.config.boxSelect||t.target.draggable)&&(!this.editor.hasTarget&&this.allow(t.target)||t.shiftKey&&!W(t.path))}findDeepOne(t){const i={exclude:new e.LeafList(this.editor.editBox.rect)};return W(t.target.leafer.interaction.findPath(t,i))}__listenEvents(){const{editor:t}=this;t.waitLeafer((()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_(m.HOVER,this.onHover,this),t.on_(m.SELECT,this.onSelect,this),e.on_(i.PointerEvent.MOVE,this.onPointerMove,this),e.on_(i.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this),e.on_(i.PointerEvent.TAP,this.onTap,this),e.on_(i.DragEvent.START,this.onDragStart,this),e.on_(i.DragEvent.DRAG,this.onDrag,this),e.on_(i.DragEvent.END,this.onDragEnd,this),e.on_(i.MoveEvent.MOVE,this.onAutoMove,this),e.on_([i.ZoomEvent.ZOOM,i.MoveEvent.MOVE],(()=>{this.editor.hoverTarget=null}))]}))}__removeListenEvents(){this.__eventIds&&(this.off_(this.__eventIds),this.__eventIds.length=0)}destroy(){this.editor=this.originList=this.lastDownLeaf=null,this.__removeListenEvents(),super.destroy()}}var X;!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"}(X||(X={}));const{topLeft:Y,top:K,topRight:F,right:G,bottomRight:U,bottom:N,bottomLeft:j,left:$}=X,{toPoint:Q}=e.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 c=(-i.y+h)/h,d=(i.x+l)/l,g=(i.y+h)/h,u=(-i.x+l)/l;switch(e){case K:a=c,n={x:.5,y:1};break;case G:r=d,n={x:0,y:.5};break;case N:a=g,n={x:.5,y:0};break;case $:r=u,n={x:1,y:.5};break;case Y:a=c,r=u,n={x:1,y:1};break;case F:a=c,r=d,n={x:0,y:1};break;case U:a=g,r=d,n={x:0,y:0};break;case j:a=g,r=u,n={x:1,y:0}}if(s){"corner"===s&&e%2||(1!==a?r=a:a=r)}return Q(o||n,t,n),{origin:n,scaleX:r,scaleY:a,direction:e,lockRatio:s,around:o}},getRotateData(t,i,s,o,n){let r;switch(i){case Y:r={x:1,y:1};break;case F:r={x:0,y:1};break;case U:r={x:0,y:0};break;case j:r={x:1,y:0};break;default:r={x:.5,y:.5}}return Q(n||r,t,r),{origin:r,rotation:e.PointHelper.getRotation(o,r,s)}},getSkewData(t,i,s,o){let n,r,a=0,l=0;switch(i){case K:r={x:.5,y:0},n={x:.5,y:1},a=1;break;case N:r={x:.5,y:1},n={x:.5,y:0},a=1;break;case $:r={x:0,y:.5},n={x:1,y:.5},l=1;break;case G:r={x:1,y:.5},n={x:0,y:.5},l=1}const{x:h,y:c,width:d,height:g}=t;r.x=h+r.x*d,r.y=c+r.y*g,Q(o||n,t,n);const u=e.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 $:t=G;break;case Y:t=F;break;case j:t=U;break;case G:t=$;break;case F:t=Y;break;case U:t=j}if(i)switch(t){case K:t=N;break;case Y:t=j;break;case F:t=U;break;case N:t=K;break;case j:t=Y;break;case U:t=F}return t}},J={};function tt(t,i){const{editBox:s}=t,o=s.enterPoint;if(!o||!t.hasTarget||!s.visible)return;if("circle"===o.name)return;let{rotation:n}=s;const{resizeCursor:r,rotateCursor:a,skewCursor:l,resizeable:h,rotateable:c,skewable:d}=t.config,{pointType:g}=o,{flippedX:u,flippedY:f}=s;let p="resize"===g;p&&c&&(i.metaKey||i.ctrlKey||!h)&&(p=!1);const v=d&&!p&&"resize-line"===o.name?l:p?r:a;n+=45*(q.getFlipDirection(o.direction,u,f)+1),n=2*Math.round(e.MathHelper.formatRotation(n,!0)/2);const{url:y,x:L,y:w}=v,k=y+n;J[k]?o.cursor=J[k]:J[k]=o.cursor={url:it(y,n),x:L,y:w}}function et(t){t.editBox.rect.cursor=t.config.moveCursor}function it(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class st extends e.Box{}const ot=["top","right","bottom","left"];class nt extends e.Group{get flipped(){return this.flippedX||this.flippedY}get flippedX(){return this.scaleX<0}get flippedY(){return this.scaleY<0}get flippedOne(){return this.scaleX*this.scaleY<0}constructor(t){super(),this.rect=new e.Box({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new st({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new e.Group({around:"center",hitSelf:!1}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{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 st({name:"rotate-point",around:h[r],width:15,height:15,hitFill:"all"}),o.push(t),this.listenPointEvents(t,"rotate",r),r%2&&(e=new st({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",r)),i=new st({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:i,list:s}=this.editor,{width:o,height:n}=t,{rect:r,circle:a,resizePoints:l,rotatePoints:h,resizeLines:c}=this,{middlePoint:d,resizeable:g,rotateable:u,stroke:f,strokeWidth:p,hideOnSmall:v}=i,y=this.getPointsStyle(),L=this.getMiddlePointsStyle(),w="number"==typeof v?v:10,k=!(v&&o<w&&n<w);this.visible=s[0]&&!s[0].locked;let _,x,m,b,E={};for(let s=0;s<8;s++)e.AroundHelper.toPoint(e.AroundHelper.directionData[s],t,E),_=this.getPointStyle(s%2?L[(s-1)/2%L.length]:y[s/2%y.length]),m=l[s],x=h[s],b=c[Math.floor(s/2)],m.set(_),m.set(E),x.set(E),b.set(E),m.visible=b.visible=k&&(g||u),x.visible=k&&u&&g&&!i.rotatePoint,s%2?(m.visible=x.visible=k&&!!d,(s+1)/2%2?(b.width=o,m.width>o-30&&(m.visible=!1)):(b.height=n,m.rotation=90,m.width>n-30&&(m.visible=!1))):m.rotation=s/2*90;a.visible=k&&u&&!!i.rotatePoint,a.set(this.getPointStyle(i.rotatePoint||y[0])),r.set(Object.assign({stroke:f,strokeWidth:p},i.rect||{})),r.set(Object.assign(Object.assign({},t),{visible:!0})),r.hittable=i.moveable,this.buttons.visible=k,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=ot.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,c=e[2*h+1],d=h%2,g=h&&3!==h?1:-1,u=(o+(l%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*(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):e.onScale(t),tt(e,t)}onArrow(t){if(this.editor.hasTarget&&this.editor.config.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}(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,tt(o,e)}))}__listenEvents(){const{rect:t,editor:e}=this;this.__eventIds=[e.on_(m.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,(()=>et(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 rt='\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",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${rt}\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${rt}\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${rt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,hover:!0,select:"press",boxSelect:!0,moveable:!0,resizeable:!0,rotateable:!0,skewable:!0};class lt{constructor(){this.tag="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()}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:c,height:d}=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:c,height:d})}}lt.list=[];const{left:ht,right:ct}=X;class dt extends lt{constructor(){super(...arguments),this.tag="LineEditTool",this.scaleOfEvent=!0}onScaleWithDrag(t){const{drag:i,direction:s,lockRatio:o,around:n}=t,r=t.target,a=e.getPointData(),{toPoint:l}=r;r.rotation=0;let{x:h,y:c}=i.getInnerMove(r);o&&(Math.abs(h)>Math.abs(c)?c=0:h=0),s===ht?(a.x+=h,a.y+=c,n&&(l.x-=h,l.y-=c)):(n&&(a.x-=h,a.y-=c),l.x+=h,l.y+=c),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===ht||t===ct}}const gt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),ut=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),ft={group(t,i,s){t.sort(ut);const{app:o,parent:n}=t[0];let r;r=s&&s.add?s:new e.Group(s),n.addAt(r,n.children.indexOf(t[0])),t.sort(gt);const a=new e.Matrix(i.worldTransform);return a.divideParent(n.worldTransform),r.setTransform(a),r.editable=!0,r.hitChildren=!1,o.lockLayout(),t.forEach((t=>t.dropTo(r))),o.unlockLayout(),r},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(gt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(ut),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}};class pt extends e.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,i){super(i),this.config=at,this.leafList=new e.LeafList,this.simulateTarget=new e.Rect({visible:!1}),this.editBox=new nt(this),this.selector=new C(this),this.targetEventIds=[],t&&(this.config=e.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.hasTarget&&(this.editTool&&this.editTool.update(this),this.selector.update())}updateEditTool(){this.editTool=function(t){if(1===t.length){const i=t[0];return i instanceof e.Line&&!i.points?new dt:new lt}return new lt}(this.list)}getEditSize(t){let{editSize:e}=this.config;return"auto"===e?t.editSize:e}onMove(t){const e=t.getLocalMove(this.element),{lockMove:i}=this.config;"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(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:s,around:o,rotateGap:n}=this.config,{direction:r,name:a}=t.current;if(s&&"resize-line"===a)return this.onSkew(t);const{element:l}=this;let h,c;if(t instanceof i.RotateEvent)c=t.rotation,h=l.getInnerPoint(t);else{const e={x:t.x-t.moveX,y:t.y-t.moveY},i=q.getRotateData(l.boxBounds,r,t.getInner(l),l.getInnerPoint(e),t.shiftKey?null:o||"center");c=i.rotation,h=i.origin}c=e.MathHelper.getGapRotation(c,n,l.rotation),c&&(l.scaleX*l.scaleY<0&&(c=-c),this.rotateOf(h,e.MathHelper.float(c,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){if(!this.config.moveable)return;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 E(E.SCALE,Object.assign(Object.assign({},t),{target:e,editor:this,worldOrigin:i}));this.editTool.onScaleWithDrag(s),this.emitEvent(s)}scaleOf(t,i,s=i,o){const{element:n}=this,r=n.getWorldPoint(t);let a;if(this.multiple){const o=new e.Matrix(n.worldTransform);n.scaleOf(t,i,s),a=new e.Matrix(n.worldTransform).divide(o)}const l=new E(E.SCALE,{target:n,editor:this,worldOrigin:r,scaleX:i,scaleY:s,transform:a});this.editTool.onScale(l),this.emitEvent(l)}rotateOf(t,i){const{element:s}=this,o=s.getWorldPoint(t);let n;if(this.multiple){const o=new e.Matrix(s.worldTransform);s.rotateOf(t,i),n=new e.Matrix(s.worldTransform).divide(o)}const r=new M(M.ROTATE,{target:s,editor:this,worldOrigin:o,rotation:i,transform:n});this.editTool.onRotate(r),this.emitEvent(r)}skewOf(t,i,s=0,o){const{element:n}=this,r=n.getWorldPoint(t);let a;if(this.multiple){const o=new e.Matrix(n.worldTransform);n.skewOf(t,i,s),a=new e.Matrix(n.worldTransform).divide(o)}const l=new S(S.SKEW,{target:n,editor:this,skewX:i,skewY:s,transform:a,worldOrigin:r});this.editTool.onSkew(l),this.emitEvent(l)}group(t){return this.multiple&&(this.target=ft.group(this.list,this.element,t)),this.target}ungroup(){return this.list.length&&(this.target=ft.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&&(ft.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(ft.toBottom(this.list),this.leafList.update())}listenTargetEvents(){if(!this.targetEventIds.length){const{leafer:t}=this.list[0];this.targetEventIds=[t.on_(e.RenderEvent.START,this.update,this),t.on_([i.KeyEvent.HOLD,i.KeyEvent.UP],(t=>{tt(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 _([H((function(t,e){t.emitEvent(new m(m.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],pt.prototype,"hoverTarget",void 0),_([H((function(t,i){const{target:s}=t;s?t.leafList=s instanceof e.LeafList?s:new e.LeafList(s):t.leafList.reset(),t.emitEvent(new m(m.SELECT,{editor:t,value:s,oldValue:i})),t.hasTarget?t.waitLeafer((()=>{t.multiple&&function(t){const{simulateTarget:i,leafList:s}=t,{x:o,y:n,width:r,height:a}=(new e.Bounds).setListWithFn(s.list,(t=>t.worldBoxBounds)),l=i.parent=s.list[0].leafer.zoomLayer,{scaleX:h,scaleY:c,e:d,f:g}=l.__world;i.reset({x:(o-d)/h,y:(n-g)/c,width:r/h,height:a/c})}(t),et(t),t.updateEditTool(),t.update(),t.listenTargetEvents()})):t.removeTargetEvents()}))],pt.prototype,"target",void 0),i.Creator.editor=function(t){return new pt(t)},t.EditBox=nt,t.EditDataHelper=q,t.EditPoint=st,t.EditSelect=C,t.EditSelectHelper=I,t.EditTool=lt,t.Editor=pt,t.EditorEvent=m,t.EditorHelper=ft,t.EditorMoveEvent=b,t.EditorRotateEvent=M,t.EditorScaleEvent=E,t.EditorSkewEvent=S,t.LineEditTool=dt,t.SelectArea=R,t.Stroker=O,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.21",
|
|
4
4
|
"description": "@leafer-in/editor",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,11 +28,9 @@
|
|
|
28
28
|
"leaferjs"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@leafer-ui/core": "1.0.0-rc.
|
|
32
|
-
"@leafer-ui/scale": "1.0.0-rc.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"@leafer-ui/interface": "1.0.0-rc.20",
|
|
36
|
-
"@leafer-in/interface": "1.0.0-rc.20"
|
|
31
|
+
"@leafer-ui/core": "1.0.0-rc.21",
|
|
32
|
+
"@leafer-ui/scale": "1.0.0-rc.21",
|
|
33
|
+
"@leafer-ui/interface": "1.0.0-rc.21",
|
|
34
|
+
"@leafer-in/interface": "1.0.0-rc.21"
|
|
37
35
|
}
|
|
38
36
|
}
|
package/src/Editor.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IGroupInputData, IUI, IEventListenerId, IPointData, ILeafList, IEditSize, IGroup } from '@leafer-ui/interface'
|
|
2
|
-
import { Group, Rect,
|
|
2
|
+
import { Group, Rect, DataHelper, MathHelper, LeafList, Matrix, RenderEvent } from '@leafer-ui/draw'
|
|
3
|
+
import { DragEvent, RotateEvent, KeyEvent } from '@leafer-ui/core'
|
|
3
4
|
|
|
4
5
|
import { IEditBox, IEditPoint, IEditor, IEditorConfig, IEditTool, IEditorScaleEvent } from '@leafer-in/interface'
|
|
5
6
|
|
package/src/decorator/data.ts
CHANGED
package/src/display/EditBox.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IRect, IAround, IEventListenerId, IBoundsData, IRectInputData, IPointData, IKeyEvent, IGroup, IBox } from '@leafer-ui/interface'
|
|
2
|
-
import { Group,
|
|
2
|
+
import { Group, Box, AroundHelper } from '@leafer-ui/draw'
|
|
3
|
+
import { DragEvent, PointerEvent } from '@leafer-ui/core'
|
|
3
4
|
|
|
4
5
|
import { IEditBox, IEditor, IDirection8, IEditPoint, IEditPointType } from '@leafer-in/interface'
|
|
5
6
|
|
package/src/display/EditPoint.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IBounds, ILeaf, ILeafList, IUI, IEventListenerId } from '@leafer-ui/interface'
|
|
2
|
-
import { Bounds,
|
|
2
|
+
import { Bounds, LeafList, Group } from '@leafer-ui/draw'
|
|
3
|
+
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent } from '@leafer-ui/core'
|
|
3
4
|
|
|
4
5
|
import { IEditSelect, IEditor, ISelectArea, IStroker } from '@leafer-in/interface'
|
|
5
6
|
|
package/src/display/Stroker.ts
CHANGED
package/src/editor/cursor.ts
CHANGED
package/src/editor/simulate.ts
CHANGED
package/src/editor/target.ts
CHANGED
package/src/event/EditorEvent.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IBoundsData, IPointData, IAround } from '@leafer-ui/interface'
|
|
2
|
-
import { AroundHelper, PointHelper } from '@leafer-ui/
|
|
2
|
+
import { AroundHelper, PointHelper } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
import { IEditorScaleEvent, IDirection8, IEditorSkewEvent, IEditorRotateEvent } from '@leafer-in/interface'
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IGroup, IGroupInputData, ILeaf, IUI } from '@leafer-ui/interface'
|
|
2
|
-
import { Group, Matrix } from '@leafer-ui/
|
|
2
|
+
import { Group, Matrix } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
const order = (a: ILeaf, b: ILeaf) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b)
|
package/src/tool/LineEditTool.ts
CHANGED
package/src/tool/index.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from '@leafer-ui/scale';
|
|
2
2
|
import { IBounds, ILeafList, IUI, IEventListenerId, ILeaf, IGroup, IGroupInputData, IEditSize, IPointData, IBox, IBoundsData, IRectInputData, IKeyEvent, IRect, ILeaferCanvas, IRenderOptions, IMatrixData, IDragEvent, IAround } from '@leafer-ui/interface';
|
|
3
|
-
import { Group,
|
|
3
|
+
import { Group, Box, UI, Event, Answer } from '@leafer-ui/draw';
|
|
4
|
+
import { PointerEvent, DragEvent, MoveEvent, RotateEvent } from '@leafer-ui/core';
|
|
4
5
|
import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditBox, IEditTool, IEditorScaleEvent, IEditPoint, IEditPointType, IDirection8, IEditorEvent, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent } from '@leafer-in/interface';
|
|
5
6
|
|
|
6
7
|
declare class EditSelect extends Group implements IEditSelect {
|