@leafer-in/editor 1.9.2 → 1.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editor.cjs +28 -9
- package/dist/editor.esm.js +28 -9
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +28 -9
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.cjs.map +1 -1
- package/dist/editor.min.js +1 -1
- package/dist/editor.min.js.map +1 -1
- package/package.json +6 -6
- package/src/Editor.ts +28 -9
package/dist/editor.cjs
CHANGED
|
@@ -1945,11 +1945,22 @@ exports.Editor = class Editor extends draw.Group {
|
|
|
1945
1945
|
updateEditTool() {
|
|
1946
1946
|
this.unloadEditTool();
|
|
1947
1947
|
if (this.editing) {
|
|
1948
|
-
const
|
|
1949
|
-
|
|
1950
|
-
this.
|
|
1951
|
-
|
|
1952
|
-
|
|
1948
|
+
const target = this.element;
|
|
1949
|
+
let name = target.editOuter || "EditTool";
|
|
1950
|
+
const {beforeEditOuter: beforeEditOuter} = this.mergeConfig;
|
|
1951
|
+
if (beforeEditOuter) {
|
|
1952
|
+
const check = beforeEditOuter({
|
|
1953
|
+
target: target,
|
|
1954
|
+
name: name
|
|
1955
|
+
});
|
|
1956
|
+
if (draw.isString(check)) name = check; else if (check === false) return;
|
|
1957
|
+
}
|
|
1958
|
+
if (EditToolCreator.list[name]) {
|
|
1959
|
+
const tool = this.editTool = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
|
|
1960
|
+
this.editBox.load();
|
|
1961
|
+
tool.load();
|
|
1962
|
+
this.update();
|
|
1963
|
+
}
|
|
1953
1964
|
}
|
|
1954
1965
|
}
|
|
1955
1966
|
unloadEditTool() {
|
|
@@ -2042,13 +2053,21 @@ exports.Editor = class Editor extends draw.Group {
|
|
|
2042
2053
|
if (draw.isString(nameOrSelect)) name = nameOrSelect; else if (!select) select = nameOrSelect;
|
|
2043
2054
|
if (target && select) this.target = target;
|
|
2044
2055
|
if (this.single) {
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2056
|
+
if (!target) target = this.element;
|
|
2057
|
+
if (!name) name = target.editInner;
|
|
2058
|
+
const {beforeEditInner: beforeEditInner} = this.mergeConfig;
|
|
2059
|
+
if (beforeEditInner) {
|
|
2060
|
+
const check = beforeEditInner({
|
|
2061
|
+
target: target,
|
|
2062
|
+
name: name
|
|
2063
|
+
});
|
|
2064
|
+
if (draw.isString(check)) name = check; else if (check === false) return;
|
|
2065
|
+
}
|
|
2066
|
+
if (EditToolCreator.list[name]) {
|
|
2048
2067
|
this.editTool.unload();
|
|
2049
2068
|
this.innerEditing = true;
|
|
2050
2069
|
this.innerEditor = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
|
|
2051
|
-
this.innerEditor.editTarget =
|
|
2070
|
+
this.innerEditor.editTarget = target;
|
|
2052
2071
|
this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN);
|
|
2053
2072
|
this.innerEditor.load();
|
|
2054
2073
|
this.emitInnerEvent(InnerEditorEvent.OPEN);
|
package/dist/editor.esm.js
CHANGED
|
@@ -1943,11 +1943,22 @@ let Editor = class Editor extends Group {
|
|
|
1943
1943
|
updateEditTool() {
|
|
1944
1944
|
this.unloadEditTool();
|
|
1945
1945
|
if (this.editing) {
|
|
1946
|
-
const
|
|
1947
|
-
|
|
1948
|
-
this.
|
|
1949
|
-
|
|
1950
|
-
|
|
1946
|
+
const target = this.element;
|
|
1947
|
+
let name = target.editOuter || "EditTool";
|
|
1948
|
+
const {beforeEditOuter: beforeEditOuter} = this.mergeConfig;
|
|
1949
|
+
if (beforeEditOuter) {
|
|
1950
|
+
const check = beforeEditOuter({
|
|
1951
|
+
target: target,
|
|
1952
|
+
name: name
|
|
1953
|
+
});
|
|
1954
|
+
if (isString(check)) name = check; else if (check === false) return;
|
|
1955
|
+
}
|
|
1956
|
+
if (EditToolCreator.list[name]) {
|
|
1957
|
+
const tool = this.editTool = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
|
|
1958
|
+
this.editBox.load();
|
|
1959
|
+
tool.load();
|
|
1960
|
+
this.update();
|
|
1961
|
+
}
|
|
1951
1962
|
}
|
|
1952
1963
|
}
|
|
1953
1964
|
unloadEditTool() {
|
|
@@ -2040,13 +2051,21 @@ let Editor = class Editor extends Group {
|
|
|
2040
2051
|
if (isString(nameOrSelect)) name = nameOrSelect; else if (!select) select = nameOrSelect;
|
|
2041
2052
|
if (target && select) this.target = target;
|
|
2042
2053
|
if (this.single) {
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2054
|
+
if (!target) target = this.element;
|
|
2055
|
+
if (!name) name = target.editInner;
|
|
2056
|
+
const {beforeEditInner: beforeEditInner} = this.mergeConfig;
|
|
2057
|
+
if (beforeEditInner) {
|
|
2058
|
+
const check = beforeEditInner({
|
|
2059
|
+
target: target,
|
|
2060
|
+
name: name
|
|
2061
|
+
});
|
|
2062
|
+
if (isString(check)) name = check; else if (check === false) return;
|
|
2063
|
+
}
|
|
2064
|
+
if (EditToolCreator.list[name]) {
|
|
2046
2065
|
this.editTool.unload();
|
|
2047
2066
|
this.innerEditing = true;
|
|
2048
2067
|
this.innerEditor = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
|
|
2049
|
-
this.innerEditor.editTarget =
|
|
2068
|
+
this.innerEditor.editTarget = target;
|
|
2050
2069
|
this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN);
|
|
2051
2070
|
this.innerEditor.load();
|
|
2052
2071
|
this.emitInnerEvent(InnerEditorEvent.OPEN);
|
package/dist/editor.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Event as t,isArray as e,defineKey as i,isNull as s,isObject as o,MatrixHelper as n,BoundsHelper as r,LeafBoundsHelper as a,getMatrixData as h,getBoundsData as l,UI as d,isString as c,Paint as g,Group as u,Rect as f,Bounds as p,LeafList as m,Direction9 as E,AroundHelper as v,MathHelper as b,PointHelper as w,Box as k,isNumber as L,ResizeEvent as y,Text as x,Matrix as O,Debug as _,LeafHelper as T,PropertyEvent as S,isUndefined as B,DataHelper as M,Plugin as C,RenderEvent as R,getPointData as P,Creator as V,dataType as H}from"@leafer-ui/draw";import{PointerEvent as I,DragEvent as D,MoveEvent as A,ZoomEvent as z,KeyEvent as F,RotateEvent as W,useModule as Z}from"@leafer-ui/core";import"@leafer-in/resize";function G(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?e(t)?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class Y extends t{get list(){return X(this.value)}get oldList(){return X(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}function U(t){return(s,n)=>{const r="_"+n;i(s,n,{get(){return this[r]},set(i){const s=this[r];if(s!==i){if(this.config){const t="target"===n;if(t){e(i)&&i.length>1&&i[0].locked&&i.splice(0,1),this.single&&(this.element.syncEventer=null);const{beforeSelect:t}=this.config;if(t){const e=t({target:i});if(o(e))i=e;else if(!1===e)return}}const r=t?Y.BEFORE_SELECT:Y.BEFORE_HOVER;this.hasEvent(r)&&this.emitEvent(new Y(r,{editor:this,value:i,oldValue:s}))}this[r]=i,t(this,s)}}})}}Y.BEFORE_SELECT="editor.before_select",Y.SELECT="editor.select",Y.AFTER_SELECT="editor.after_select",Y.BEFORE_HOVER="editor.before_hover",Y.HOVER="editor.hover";const{abs:N}=Math,{copy:K,scale:j}=n,{setListWithFn:$}=r,{worldBounds:q}=a,J=h(),Q=l();class tt extends d{constructor(){super(),this.list=[],this.visible=0,this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){e&&this.set(e),this.target=t,this.update()}update(t){const{list:e}=this;e.length?($(Q,e,q),t&&this.set(t),this.set(Q),this.visible=!0):this.visible=0}__draw(t,e){const{list:i}=this;if(i.length){let s;const o=this.__,{stroke:n,strokeWidth:r,fill:a}=o,{bounds:h}=e;for(let l=0;l<i.length;l++){s=i[l];const{worldTransform:d,worldRenderBounds:u}=s;if(u.width&&u.height&&(!h||h.hit(u,e.matrix))){const i=N(d.scaleX),h=N(d.scaleY);if(K(J,d),J.half=r%2,i!==h){j(J,1/i,1/h),t.setWorld(J,e.matrix),t.beginPath(),o.strokeWidth=r;const{x:n,y:a,width:l,height:d}=s.__layout.boxBounds;t.rect(n*i,a*h,l*i,d*h)}else t.setWorld(J,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),o.strokeWidth=r/N(d.scaleX);n&&(c(n)?g.stroke(n,this,t):g.strokes(n,this,t)),a&&(c(a)?g.fill(a,this,t):g.fills(a,this,t))}}o.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}G([U(function(t){const i=t.target;t.list=i?e(i)?i:[i]:[]})],tt.prototype,"target",void 0);class et extends u{constructor(t){super(t),this.strokeArea=new f({strokeAlign:"center"}),this.fillArea=new f,this.visible=0,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 it={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return st([t],i,e),i}};function st(t,e,i){let s,o;for(let n=0,r=t.length;n<r;n++)if(s=t[n],o=s.__,o.hittable&&o.visible&&!o.locked&&i.hit(s.__world)){if(o.editable){if(s.isBranch&&!o.hitChildren){o.hitSelf&&e.push(s);continue}if(s.isFrame){if(i.includes(s.__layout.boxBounds,s.__world)){e.push(s);continue}}else i.hit(s.__layout.boxBounds,s.__world)&&o.hitSelf&&e.push(s)}s.isBranch&&st(s.children,e,i)}}const{findOne:ot,findByBounds:nt}=it;class rt extends u{get dragging(){return!!this.originList}get running(){const{editor:t}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new tt,this.targetStroker=new tt,this.bounds=new p,this.selectArea=new et,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:s,hoverStyle:o}=t.mergeConfig;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},o||{}))}}onSelect(){this.running&&(this.targetStroker.setTarget(this.editor.list),this.hoverStroker.target=null)}update(){this.hoverStroker.update();const{stroke:t,strokeWidth:e,selectedStyle:i}=this.editor.mergedConfig;this.targetStroker.update(Object.assign({stroke:t,strokeWidth:e&&Math.max(1,e/2)},i||{}))}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.interaction.canHover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){if(t.multiTouch)return;const{select:e}=this.editor.mergeConfig;"press"===e&&(this.app.config.mobile?this.waitSelect=()=>this.checkAndSelect(t):this.checkAndSelect(t))}onTap(t){if(t.multiTouch)return;const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i?this.checkAndSelect(t):this.waitSelect&&this.waitSelect(),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(this.isHoldMultipleSelectKey(t)||(e.target=null))}}onDragStart(t){if(!t.multiTouch&&(this.waitSelect&&this.waitSelect(),this.allowDrag(t))){const{editor:e}=this,{stroke:i,area:s}=e.mergeConfig,{x:o,y:n}=t.getInnerPoint(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(!t.multiTouch){if(this.editor.dragging)return this.onDragEnd(t);if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new m(nt(e.app,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(t){t.multiTouch||this.dragging&&(this.originList=null,this.selectArea.visible=0)}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){const{boxSelect:e,multipleSelect:i}=this.editor.mergeConfig;return!(!(this.running&&i&&e)||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||this.isHoldMultipleSelectKey(t)&&!ot(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new m(this.editor.editBox.rect)};return ot(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):ot(t.path)}isMultipleSelect(t){const{multipleSelect:e,continuousSelect:i}=this.editor.mergeConfig;return e&&(this.isHoldMultipleSelectKey(t)||i)}isHoldMultipleSelectKey(t){const{multipleSelectKey:e}=this.editor.mergedConfig;return e?t.isHoldKeys(e):t.shiftKey}__listenEvents(){const{editor:t}=this;t.waitLeafer(()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_([[Y.HOVER,this.onHover,this],[Y.SELECT,this.onSelect,this]]),e.on_([[I.MOVE,this.onPointerMove,this],[I.BEFORE_DOWN,this.onBeforeDown,this],[I.TAP,this.onTap,this],[D.START,this.onDragStart,this,!0],[D.DRAG,this.onDrag,this],[D.END,this.onDragEnd,this],[A.MOVE,this.onAutoMove,this],[[z.ZOOM,A.MOVE],()=>{this.editor.hoverTarget=null}]])]})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:at,top:ht,topRight:lt,right:dt,bottomRight:ct,bottom:gt,bottomLeft:ut,left:ft}=E,{toPoint:pt}=v,{within:mt}=b,Et={getScaleData(t,e,i,s,o,n,a,h){let l,d={},c=1,g=1;const{boxBounds:u,widthRange:f,heightRange:m,dragBounds:E,worldBoxBounds:v}=t,{width:b,height:w}=e;n&&(s.x*=2,s.y*=2);const k=t.scaleX/e.scaleX,L=t.scaleY/e.scaleY,y=k<0?-1:1,x=L<0?-1:1,O=h?k:y*u.width/b,_=h?L:x*u.height/w;s.x*=h?k:y,s.y*=h?L:x;const T=(-s.y+w)/w,S=(s.x+b)/b,B=(s.y+w)/w,M=(-s.x+b)/b;switch(i){case ht:g=T,l="bottom";break;case dt:c=S,l="left";break;case gt:g=B,l="top";break;case ft:c=M,l="right";break;case at:g=T,c=M,l="bottom-right";break;case lt:g=T,c=S,l="bottom-left";break;case ct:g=B,c=S,l="top-left";break;case ut:g=B,c=M,l="top-right"}if(o)if("corner"===o&&i%2)o=!1;else{let t;switch(i){case ht:case gt:t=g;break;case ft:case dt:t=c;break;default:t=Math.sqrt(Math.abs(c*g))}c=c<0?-t:t,g=g<0?-t:t}const C=1!==c,R=1!==g;if(C&&(c/=O),R&&(g/=_),!a){const{worldTransform:e}=t;c<0&&(c=1/u.width/e.scaleX),g<0&&(g=1/u.height/e.scaleY)}if(pt(n||l,u,d,!0),E){const e="parent"===E?t.parent.boxBounds:E,i=new p(t.__localBoxBounds);if(r.includes(new p(e).spread(.1),i)&&(i.scaleOf(t.getLocalPointByInner(d),c,g),!r.includes(e,i))){const t=i.getIntersect(e),s=t.width/i.width,o=t.height/i.height;C&&(c*=s),R&&(g*=o)}}if(C&&f){const e=u.width*t.scaleX;c=mt(e*c,f)/e}if(R&&m){const e=u.height*t.scaleY;g=mt(e*g,m)/e}return C&&Math.abs(c*v.width)<1&&(c=(c<0?-1:1)/v.width),R&&Math.abs(g*v.height)<1&&(g=(g<0?-1:1)/v.height),o&&c!==g&&(g=c=Math.min(c,g)),{origin:d,scaleX:c,scaleY:g,direction:i,lockRatio:o,around:n}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case at:n="bottom-right";break;case lt:n="bottom-left";break;case ct:n="top-left";break;case ut:n="top-right";break;default:n="center"}return pt(o||n,t.boxBounds,r,!0),{origin:r,rotation:w.getRotation(s,t.getWorldPointByBox(r),i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,h=0;switch(e){case ht:case at:n={x:.5,y:0},o="bottom",a=1;break;case gt:case ct:n={x:.5,y:1},o="top",a=1;break;case ft:case ut:n={x:0,y:.5},o="right",h=1;break;case dt:case lt:n={x:1,y:.5},o="left",h=1}const{width:l,height:d}=t;n.x=n.x*l,n.y=n.y*d,pt(s||o,t,r,!0);const c=w.getRotation(n,r,{x:n.x+(a?i.x:0),y:n.y+(h?i.y:0)});return a?a=-c:h=c,{origin:r,skewX:a,skewY:h}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case ft:t=dt;break;case at:t=lt;break;case ut:t=ct;break;case dt:t=ft;break;case lt:t=at;break;case ct:t=ut}if(i)switch(t){case ht:t=gt;break;case at:t=ut;break;case lt:t=ct;break;case gt:t=ht;break;case ut:t=at;break;case ct:t=lt}return t}},vt={};function bt(t,e){const{enterPoint:i,dragging:s,skewing:o,resizing:n,flippedX:r,flippedY:a}=t;if(!i||!t.editor.editing||!t.canUse)return;if("circle"===i.name)return;if("button"===i.pointType)return void(i.cursor||(i.cursor="pointer"));let{rotation:h}=t;const{pointType:l}=i,{resizeCursor:d,rotateCursor:c,skewCursor:g,resizeable:u,rotateable:f,skewable:p}=t.mergeConfig;let m=l.includes("resize");m&&f&&(t.isHoldRotateKey(e)||!u)&&(m=!1);const E=p&&!m&&("resize-line"===i.name||"skew"===l),v=s?o?g:n?d:c:E?g:m?d:c;h+=45*(Et.getFlipDirection(i.direction,r,a)+1),h=2*Math.round(b.formatRotation(h,!0)/2);const{url:w,x:k,y:L}=v,y=w+h;vt[y]?i.cursor=vt[y]:vt[y]=i.cursor={url:kt(w,h),x:k,y:L}}function wt(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.canUse&&(t.rect.cursor=i?e:void 0)}function kt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Lt extends k{constructor(t){super(t),this.useFastShadow=!0}}const yt=["top","right","bottom","left"],xt=void 0;class Ot extends u{get mergeConfig(){const{config:t}=this,{mergeConfig:e,editBox:i}=this.editor;return this.mergedConfig=t&&i!==this?Object.assign(Object.assign({},e),t):e}get target(){return this._target||this.editor.element}set target(t){this._target=t}get single(){return!!this._target||this.editor.single}get transformTool(){return this._transformTool||this.editor}set transformTool(t){this._transformTool=t}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}get canUse(){return this.visible&&this.view.visible}get canGesture(){if(!this.canUse)return!1;const{moveable:t,resizeable:e,rotateable:i}=this.mergeConfig;return c(t)||c(e)||c(i)}constructor(t){super(),this.view=new u,this.rect=new k({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Lt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new u({around:"center",hitSelf:!1,visible:0}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.dragStartData={},this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:a,circle:h,buttons:l}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let s=0;s<8;s++)t=new Lt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Lt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new Lt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);this.listenPointEvents(h,"rotate",2),s.addMany(...n,a,h,l,...r,...o),this.add(s)}load(){const{target:t,mergeConfig:e,single:i,rect:s,circle:o,resizePoints:n}=this,{stroke:r,strokeWidth:a}=e,h=this.getPointsStyle(),l=this.getMiddlePointsStyle();let d;this.visible=!t.locked;for(let t=0;t<8;t++)d=n[t],d.set(this.getPointStyle(t%2?l[(t-1)/2%l.length]:h[t/2%h.length])),d.rotation=(t-(t%2?1:0))/2*90;o.set(this.getPointStyle(e.circle||e.rotatePoint||h[0])),s.set(Object.assign({stroke:r,strokeWidth:a,editConfig:xt},e.rect||{}));const c=i&&this.transformTool.editTool;s.hittable=!c,s.syncEventer=c&&this.editor,c&&(t.syncEventer=s,this.app.interaction.bottomList=[{target:s,proxy:t}]),wt(this)}update(){const{editor:t}=this,{x:e,y:i,scaleX:s,scaleY:o,rotation:n,skewX:r,skewY:a,width:h,height:l}=this.target.getLayoutBounds("box",t,!0);this.visible=!this.target.locked,this.set({x:e,y:i,scaleX:s,scaleY:o,rotation:n,skewX:r,skewY:a}),this.updateBounds({x:0,y:0,width:h,height:l})}unload(){this.visible=!1,this.app&&(this.rect.syncEventer=this.app.interaction.bottomList=null)}updateBounds(t){const{editMask:e}=this.editor,{mergeConfig:i,single:s,rect:o,circle:n,buttons:a,resizePoints:h,rotatePoints:l,resizeLines:d}=this,{middlePoint:c,resizeable:g,rotateable:u,hideOnSmall:f,editBox:p,mask:m,spread:E,hideRotatePoints:b,hideResizeLines:w}=i;if(e.visible=!!m||0,E&&r.spread(t,E),this.view.worldOpacity){const{width:e,height:r}=t,m=L(f)?f:10,E=p&&!(f&&e<m&&r<m);let k,y,x,O={};for(let i=0;i<8;i++)v.toPoint(v.directionData[i],t,O),y=h[i],k=l[i],y.set(O),k.set(O),y.visible=E&&!(!g&&!u),k.visible=E&&u&&g&&!b,i%2&&(x=d[(i-1)/2],x.set(O),x.visible=y.visible&&!w,y.visible=k.visible=E&&!!c,(i+1)/2%2?(x.width=e,f&&2*y.width>e&&(y.visible=!1)):(x.height=r,f&&2*y.width>r&&(y.visible=!1)));n.visible=E&&u&&!(!i.circle&&!i.rotatePoint),n.visible&&this.layoutCircle(),o.path&&(o.path=null),o.set(Object.assign(Object.assign({},t),{visible:!s||p})),a.visible=E&&a.children.length>0||0,a.visible&&this.layoutButtons()}else o.set(t)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,n=yt.indexOf(t||(this.buttons.children.length&&"bottom"===s?"top":"bottom"));this.setButtonPosition(this.circle,n,e||i,!!o)}layoutButtons(){const{buttons:t}=this,{buttonsDirection:e,buttonsFixed:i,buttonsMargin:s,middlePoint:o}=this.mergedConfig,{flippedX:n,flippedY:r}=this;let a=yt.indexOf(e);(a%2&&n||(a+1)%2&&r)&&i&&(a=(a+2)%4);const h=i?Et.getRotateDirection(a,this.flippedOne?this.rotation:-this.rotation,4):a;this.setButtonPosition(t,h,s,!!o),i&&(t.rotation=90*(h-a)),t.scaleX=n?-1:1,t.scaleY=r?-1:1}setButtonPosition(t,e,i,s){const o=this.resizePoints[2*e+1],n=e%2,r=e&&3!==e?1:-1,a=(i+(e%2?(s?o.width:0)+t.boxBounds.width:(s?o.height:0)+t.boxBounds.height)/2)*r;n?(t.x=o.x+a,t.y=o.y):(t.x=o.x,t.y=o.y+a)}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.mergedConfig,r={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:o,height:o,cornerRadius:n,offsetX:0,offsetY:0,editConfig:xt};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.mergedConfig;return e(t)?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.mergedConfig;return e(t)?t:t?[t]:this.getPointsStyle()}onDragStart(t){this.dragging=!0;const e=this.dragPoint=t.current,{pointType:i}=e,{editor:s,dragStartData:o}=this,{target:n}=this,{moveable:r,resizeable:a,rotateable:h,skewable:l,hideOnMove:d}=this.mergeConfig;"rect"===e.name?(r&&(this.moving=!0),s.opacity=d?0:1):(i.includes("rotate")||this.isHoldRotateKey(t)||!a?(h&&(this.rotating=!0),"resize-rotate"===i?a&&(this.resizing=!0):"resize-line"===e.name&&(l&&(this.skewing=!0),this.rotating=!1)):"resize"===i&&a&&(this.resizing=!0),"skew"===i&&l&&(this.skewing=!0)),o.x=t.x,o.y=t.y,o.point={x:n.x,y:n.y},o.bounds=Object.assign({},n.getLayoutBounds("box","local")),o.rotation=n.rotation,i&&i.includes("resize")&&(y.resizingKeys=s.leafList.keys)}onDragEnd(t){this.moving&&this.transformTool.onMove(t),this.dragPoint=null,this.resetDoing();const{name:e,pointType:i}=t.current;"rect"===e&&(this.editor.opacity=1),i&&i.includes("resize")&&(y.resizingKeys=null)}onDrag(t){const{transformTool:e,moving:i,resizing:s,rotating:o,skewing:n}=this;if(i)e.onMove(t),wt(this);else if(s||o||n){const i=t.current;i.pointType&&(this.enterPoint=i),o&&e.onRotate(t),s&&e.onScale(t),n&&e.onSkew(t),bt(this,t)}}resetDoing(){this.canUse&&(this.dragging=this.gesturing=this.moving=this.resizing=this.rotating=this.skewing=!1)}onMove(t){this.canGesture&&"drag"!==t.moveType&&(t.stop(),c(this.mergeConfig.moveable)&&(this.gesturing=this.moving=!0,this.transformTool.onMove(t)))}onMoveEnd(t){this.moving&&this.transformTool.onMove(t),this.resetDoing()}onScale(t){this.canGesture&&(t.stop(),c(this.mergeConfig.resizeable)&&(this.gesturing=this.resizing=!0,this.transformTool.onScale(t)))}onRotate(t){this.canGesture&&(t.stop(),c(this.mergeConfig.rotateable)&&(this.gesturing=this.rotating=!0,this.transformTool.onRotate(t)))}isHoldRotateKey(t){const{rotateKey:e}=this.mergedConfig;return e?t.isHoldKeys(e):t.metaKey||t.ctrlKey}onKey(t){bt(this,t)}onArrow(t){const{editor:e,transformTool:i}=this;if(this.canUse&&e.editing&&this.mergeConfig.keyEvent){let e=0,s=0;const o=t.shiftKey?10:1;switch(t.code){case"ArrowDown":s=o;break;case"ArrowUp":s=-o;break;case"ArrowLeft":e=-o;break;case"ArrowRight":e=o}(e||s)&&i.move(e,s)}}onDoubleTap(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"double"!==e||i||this.openInner(t)}onLongPress(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"long"===e&&i&&this.openInner(t)}openInner(t){const{editor:e,target:i}=this;if(this.single){if(i.locked)return;if(i.isBranch&&!i.editInner){if(i.textBox){const{children:t}=i,s=t.find(t=>t.editable&&t instanceof x)||t.find(t=>t instanceof x);if(s)return e.openInnerEditor(s)}e.openGroup(i),e.target=e.selector.findDeepOne(t)}else e.openInnerEditor()}}listenPointEvents(t,e,i){t.direction=i,t.pointType=e;const s=[[D.START,this.onDragStart,this],[D.DRAG,this.onDrag,this],[D.END,this.onDragEnd,this],[I.LEAVE,()=>{this.enterPoint=null}]];"circle"!==t.name&&s.push([I.ENTER,e=>{this.enterPoint=t,bt(this,e)}]),this.__eventIds.push(t.on_(s))}__listenEvents(){const{rect:t,editor:e,__eventIds:i}=this;i.push(t.on_([[D.START,this.onDragStart,this],[D.DRAG,this.onDrag,this],[D.END,this.onDragEnd,this],[I.ENTER,()=>wt(this)],[I.DOUBLE_TAP,this.onDoubleTap,this],[I.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer(()=>{i.push(e.app.on_([[[F.HOLD,F.UP],this.onKey,this],[F.DOWN,this.onArrow,this],[A.BEFORE_MOVE,this.onMove,this,!0],[z.BEFORE_ZOOM,this.onScale,this,!0],[W.BEFORE_ROTATE,this.onRotate,this,!0],[A.END,this.onMoveEnd,this],[z.END,this.resetDoing,this],[W.END,this.resetDoing,this]]))})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const _t={x:0,y:0,width:1e5,height:1e5};class Tt extends d{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,_t),Object.assign(this.__world,_t)}__draw(t,e){const{editor:i}=this,{mask:s}=i.mergedConfig;if(s&&i.editing){if(t.fillWorld(t.bounds,!0===s?"rgba(0,0,0,0.8)":s),e.bounds&&!e.bounds.hit(i.editBox.rect.__world,e.matrix))return;t.saveBlendMode("destination-out"),e=Object.assign(Object.assign({},e),{shape:!0}),i.list.forEach(i=>{i.__render(t,e);const{parent:s}=i;s&&s.textBox&&s.__renderShape(t,e)}),t.restoreBlendMode()}}destroy(){this.editor=null,super.destroy()}}const St='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',Bt={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${St}\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${St}\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${St}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,editBox:!0,hover:!0,select:"press",openInner:"double",multipleSelect:!0,boxSelect:!0,moveable:!0,resizeable:!0,flipable:!0,rotateable:!0,skewable:!0},Mt=new p;function Ct(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange(()=>{Mt.setListWithFn(i,t=>t.getBounds("box","page")),0===Mt.width&&(Mt.width=.1),0===Mt.height&&(Mt.height=.1),e.reset(Mt.get())}),s.add(e)}const Rt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Pt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Vt={group(t,e,i){t.sort(Pt);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(Rt);const r=new O(e.worldTransform);return r.divideParent(o.scrollWorldTransform),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.isBranchLeaf?i.push(t):t.remove()}else i.push(t)}),e.unlockLayout(),i},toTop(t){t.sort(Rt),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(Pt),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})}},Ht=_.get("EditToolCreator");function It(){return t=>{At.register(t)}}const Dt=It,At={list:{},register(t){const{tag:e}=t.prototype;zt[e]&&Ht.repeat(e),zt[e]=t},get:(t,e)=>new zt[t](e)},{list:zt}=At;class Ft extends Y{constructor(t,e){super(t,e)}}Ft.BEFORE_OPEN="innerEditor.before_open",Ft.OPEN="innerEditor.open",Ft.BEFORE_CLOSE="innerEditor.before_close",Ft.CLOSE="innerEditor.close";class Wt extends Y{constructor(t,e){super(t,e)}}Wt.BEFORE_GROUP="editor.before_group",Wt.GROUP="editor.group",Wt.BEFORE_UNGROUP="editor.before_ungroup",Wt.UNGROUP="editor.ungroup",Wt.BEFORE_OPEN="editor.before_open_group",Wt.OPEN="editor.open_group",Wt.BEFORE_CLOSE="editor.before_close_group",Wt.CLOSE="editor.close_group";const{updateMatrix:Zt}=T,Gt={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},Xt="top-left";class Yt extends f{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.on(S.CHANGE,e=>{if(this.checkChange&&Gt[e.attrName]){const{attrName:i,newValue:s,oldValue:o}=e,n="s"===i[0]?(s||1)/(o||1):(s||0)-(o||0);this.canChange=!1;const r=this.__;r[i]=o,Zt(this.parent),Zt(this);const a=new O(this.__world);switch(r[i]=s,this.__layout.rotationChange(),Zt(this),this.changedTransform=new O(this.__world).divide(a),i){case"x":t.move(n,0);break;case"y":t.move(0,n);break;case"rotation":t.rotateOf(Xt,n);break;case"scaleX":t.scaleOf(Xt,n,1);break;case"scaleY":t.scaleOf(Xt,1,n);break;case"skewX":t.skewOf(Xt,n,0);break;case"skewY":t.skewOf(Xt,0,n)}this.canChange=!0}})}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class Ut extends Y{constructor(t,e){super(t,e)}}Ut.BEFORE_MOVE="editor.before_move",Ut.MOVE="editor.move";class Nt extends Y{constructor(t,e){super(t,e)}}Nt.BEFORE_SCALE="editor.before_scale",Nt.SCALE="editor.scale";class Kt extends Y{constructor(t,e){super(t,e)}}Kt.BEFORE_ROTATE="editor.before_rotate",Kt.ROTATE="editor.rotate";class jt extends Y{constructor(t,e){super(t,e)}}jt.BEFORE_SKEW="editor.before_skew",jt.SKEW="editor.skew";class $t{onMove(t){const{target:e,mergeConfig:i,dragStartData:s,app:o}=this.editBox;let n,{dragLimitAnimate:r}=i;B(r)&&(r=o&&o.config.pointer.dragLimitAnimate);const a=t.type===A.END||t.type===D.END,h=c(e.draggable),l=!r||a||h;if(t instanceof A)n=t.getLocalMove(e),l&&D.limitMove(e,n);else{const i={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(i.x)>Math.abs(i.y)?i.y=0:i.x=0),n=D.getValidMove(e,s.point,i,l)}(n.x||n.y)&&(r&&!h&&a?T.animateMove(this,n,L(r)?r:.3):this.move(n))}onScale(t){const{target:e,mergeConfig:i,single:s,dragStartData:o}=this.editBox;let{around:n,lockRatio:r,flipable:a,editSize:h}=i;if(t instanceof z)this.scaleOf(e.getBoxPoint(t),t.scale,t.scale);else{const{direction:i}=t.current;(t.shiftKey||e.lockRatio)&&(r=!0);const l=Et.getScaleData(e,o.bounds,i,t.getInnerTotal(e),r,Et.getAround(n,t.altKey),a,!s||"scale"===h);this.editTool&&this.editTool.onScaleWithDrag?(l.drag=t,this.scaleWithDrag(l)):this.scaleOf(l.origin,l.scaleX,l.scaleY)}}onRotate(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox,{around:o,rotateAround:n,rotateGap:r}=i,{direction:a}=t.current;let h,l;if(t instanceof W)l=t.rotation,h=n?v.getPoint(n,e.boxBounds):e.getBoxPoint(t);else{const i=Et.getRotateData(e,a,t,s,t.shiftKey?null:n||e.around||e.origin||o||"center");l=s.rotation+i.rotation-e.rotation,h=i.origin}l=b.float(b.getGapRotation(l,r,e.rotation),2),l&&this.rotateOf(h,l)}onSkew(t){const{target:e,mergeConfig:i}=this.editBox,{around:s}=i,{origin:o,skewX:n,skewY:r}=Et.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Et.getAround(s,t.altKey));(n||r)&&this.skewOf(o,n,r)}move(t,e=0){if(!this.checkTransform("moveable"))return;o(t)&&(e=t.y,t=t.x);const{target:i,mergeConfig:s,single:n,editor:r}=this.editBox,{beforeMove:a}=s;if(a){const s=a({target:i,x:t,y:e});if(o(s))t=s.x,e=s.y;else if(!1===s)return}const h=i.getWorldPointByLocal({x:t,y:e},null,!0);n||i.safeChange(()=>i.move(t,e));const l={target:i,editor:r,moveX:h.x,moveY:h.y};this.emitEvent(new Ut(Ut.BEFORE_MOVE,l));const d=new Ut(Ut.MOVE,l);this.doMove(d),this.emitEvent(d)}scaleWithDrag(t){if(!this.checkTransform("resizeable"))return;const{target:e,mergeConfig:i,editor:s}=this.editBox,{beforeScale:o}=i;if(o){const{origin:i,scaleX:s,scaleY:n,drag:r}=t;if(!1===o({target:e,drag:r,origin:i,scaleX:s,scaleY:n}))return}t=Object.assign(Object.assign({},t),{target:e,editor:s,worldOrigin:e.getWorldPoint(t.origin)}),this.emitEvent(new Nt(Nt.BEFORE_SCALE,t));const n=new Nt(Nt.SCALE,t);this.editTool.onScaleWithDrag(n),this.emitEvent(n)}scaleOf(t,e,i=e,s){if(!this.checkTransform("resizeable"))return;const{target:n,mergeConfig:r,single:a,editor:h}=this.editBox,{beforeScale:l}=r;if(l){const s=l({target:n,origin:t,scaleX:e,scaleY:i});if(o(s))e=s.scaleX,i=s.scaleY;else if(!1===s)return}const d=this.getWorldOrigin(t),c=!a&&this.getChangedTransform(()=>n.safeChange(()=>n.scaleOf(t,e,i))),g={target:n,editor:h,worldOrigin:d,scaleX:e,scaleY:i,transform:c};this.emitEvent(new Nt(Nt.BEFORE_SCALE,g));const u=new Nt(Nt.SCALE,g);this.doScale(u),this.emitEvent(u)}flip(t){if(!this.checkTransform("resizeable"))return;const{target:e,single:i,editor:s}=this.editBox,o=this.getWorldOrigin("center"),n=i?new O(T.getFlipTransform(e,t)):this.getChangedTransform(()=>e.safeChange(()=>e.flip(t))),r={target:e,editor:s,worldOrigin:o,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:n};this.emitEvent(new Nt(Nt.BEFORE_SCALE,r));const a=new Nt(Nt.SCALE,r);this.doScale(a),this.emitEvent(a)}rotateOf(t,e){if(!this.checkTransform("rotateable"))return;const{target:i,mergeConfig:s,single:o,editor:n}=this.editBox,{beforeRotate:r}=s;if(r){const s=r({target:i,origin:t,rotation:e});if(L(s))e=s;else if(!1===s)return}const a=this.getWorldOrigin(t),h=!o&&this.getChangedTransform(()=>i.safeChange(()=>i.rotateOf(t,e))),l={target:i,editor:n,worldOrigin:a,rotation:e,transform:h};this.emitEvent(new Kt(Kt.BEFORE_ROTATE,l));const d=new Kt(Kt.ROTATE,l);this.doRotate(d),this.emitEvent(d)}skewOf(t,e,i=0,s){if(!this.checkTransform("skewable"))return;const{target:n,mergeConfig:r,single:a,editor:h}=this.editBox,{beforeSkew:l}=r;if(l){const s=l({target:n,origin:t,skewX:e,skewY:i});if(o(s))e=s.skewX,i=s.skewY;else if(!1===s)return}const d=this.getWorldOrigin(t),c=!a&&this.getChangedTransform(()=>n.safeChange(()=>n.skewOf(t,e,i))),g={target:n,editor:h,worldOrigin:d,skewX:e,skewY:i,transform:c};this.emitEvent(new jt(jt.BEFORE_SKEW,g));const u=new jt(jt.SKEW,g);this.doSkew(u),this.emitEvent(u)}doMove(t){this.editTool.onMove(t)}doScale(t){this.editTool.onScale(t)}doRotate(t){this.editTool.onRotate(t)}doSkew(t){this.editTool.onSkew(t)}checkTransform(t){const{target:e,mergeConfig:i}=this.editBox;return e&&!e.locked&&i[t]}getWorldOrigin(t){const{target:e}=this.editBox;return e.getWorldPoint(T.getInnerOrigin(e,t))}getChangedTransform(t){const{target:e,single:i}=this.editBox;if(!i&&!e.canChange)return e.changedTransform;const s=new O(e.worldTransform);return t(),new O(e.worldTransform).divide(s)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}let qt=class extends u{get list(){return this.leafList.list}get dragHoverExclude(){return[this.editBox.rect]}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragPoint(){return this.editBox.dragPoint}get dragging(){return this.editBox.dragging}get gesturing(){return this.editBox.gesturing}get moving(){return this.editBox.moving}get resizing(){return this.editBox.resizing}get rotating(){return this.editBox.rotating}get skewing(){return this.editBox.skewing}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}get targetLeafer(){const t=this.list[0];return t&&t.leafer}constructor(t,e){super(e),this.leafList=new m,this.openedGroupList=new m,this.simulateTarget=new Yt(this),this.editBox=new Ot(this),this.editToolList={},this.selector=new rt(this),this.editMask=new Tt(this),this.targetEventIds=[];let i=M.clone(Bt);t&&(i=M.default(t,i)),this.mergedConfig=this.config=i,this.addMany(this.editMask,this.selector,this.editBox),C.has("resize")||(this.config.editSize="scale")}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){if(this.editing){if(!this.element.parent)return this.cancel();this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update()}}updateEditBox(){this.multiple&&Ct(this),this.update()}updateEditTool(){if(this.unloadEditTool(),this.editing){const t=this.element.editOuter||"EditTool",e=this.editTool=this.editToolList[t]=this.editToolList[t]||At.get(t,this);this.editBox.load(),e.load(),this.update()}}unloadEditTool(){let t=this.editTool;t&&(this.editBox.unload(),t.unload(),this.editTool=null)}getEditSize(t){return this.mergeConfig.editSize}onMove(t){}onScale(t){}onRotate(t){}onSkew(t){}move(t,e=0){}scaleWithDrag(t){}scaleOf(t,e,i=e,s){}flip(t){}rotateOf(t,e){}skewOf(t,e,i=0,s){}checkTransform(t){}getWorldOrigin(t){}getChangedTransform(t){}group(t){return this.multiple&&(this.emitGroupEvent(Wt.BEFORE_GROUP),this.target=Vt.group(this.list,this.element,t),this.emitGroupEvent(Wt.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach(t=>t.isBranch&&this.emitGroupEvent(Wt.BEFORE_UNGROUP,t)),this.target=Vt.ungroup(t),t.forEach(t=>t.isBranch&&this.emitGroupEvent(Wt.UNGROUP,t))),this.list}openGroup(t){this.emitGroupEvent(Wt.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Wt.OPEN,t)}closeGroup(t){this.emitGroupEvent(Wt.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Wt.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach(t=>this.list.every(e=>!T.hasParent(e,t))&&e.push(t))),e.forEach(t=>this.closeGroup(t))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new Wt(t,{editTarget:e});e&&e.syncEventer||this.emitEvent(i),e&&e.emitEvent(i)}openInnerEditor(t,e,i){let s;if(c(e)?s=e:i||(i=e),t&&i&&(this.target=t),this.single){const e=t||this.element;s||(s=e.editInner),s&&At.list[s]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[s]=this.editToolList[s]||At.get(s,this),this.innerEditor.editTarget=e,this.emitInnerEvent(Ft.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Ft.OPEN))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Ft.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Ft.CLOSE),t||this.updateEditTool(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Ft(t,{editTarget:i,innerEditor:e});i.syncEventer||this.emitEvent(s),i.emitEvent(s)}lock(){this.list.forEach(t=>t.locked=!0),this.update()}unlock(){this.list.forEach(t=>t.locked=!1),this.update()}toTop(){this.list.length&&(Vt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Vt.toBottom(this.list),this.leafList.update())}onAppRenderStart(t){(this.targetChanged=t.children.some(t=>t!==this.leafer&&t.renderer.changed))&&this.editBox.forceRender()}onRenderStart(){this.targetChanged&&this.update()}onChildScroll(){this.multiple&&this.updateEditBox()}listenTargetEvents(){if(!this.targetEventIds.length){const{app:t,leafer:e,targetLeafer:i,editMask:s}=this;this.targetEventIds=[e.on_(R.START,this.onRenderStart,this),i&&i.on_(S.SCROLL,this.onChildScroll,this),t.on_(R.CHILD_START,this.onAppRenderStart,this)],s.visible&&s.forceRender()}}removeTargetEvents(){const{targetEventIds:t,editMask:e}=this;t.length&&(this.off_(t),e.visible&&e.forceRender())}destroy(){this.destroyed||(this.target=this.hoverTarget=null,Object.values(this.editToolList).forEach(t=>t.destroy()),this.simulateTarget.destroy(),this.editToolList={},this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}};G([(t,e)=>{i(t,e,{get(){const{config:t,element:e,dragPoint:i,editBox:o}=this,n=Object.assign({},t);return e&&e.editConfig&&Object.assign(n,e.editConfig),o.config&&Object.assign(n,o.config),i&&(i.editConfig&&Object.assign(n,i.editConfig),"font-size"===n.editSize&&(n.lockRatio=!0),"resize-rotate"===i.pointType&&(n.around||(n.around="center"),s(n.lockRatio)&&(n.lockRatio=!0))),this.mergedConfig=n}})}],qt.prototype,"mergeConfig",void 0),G([U(function(t,e){t.emitEvent(new Y(Y.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))})],qt.prototype,"hoverTarget",void 0),G([U(function(t,e){const{target:i}=t;i?(t.leafList=i instanceof m?i:new m(i),t.multiple&&Ct(t)):(t.simulateTarget.remove(),t.leafList.reset()),t.closeInnerEditor(!0),t.unloadEditTool();const s={editor:t,value:i,oldValue:e};t.emitEvent(new Y(Y.SELECT,s)),t.checkOpenedGroups(),t.editing?t.waitLeafer(()=>{t.updateEditTool(),t.listenTargetEvents()}):(t.updateEditTool(),t.removeTargetEvents()),t.emitEvent(new Y(Y.AFTER_SELECT,s))})],qt.prototype,"target",void 0),qt=G([Z($t,["editBox","editTool","emitEvent"])],qt);class Jt{static registerInnerEditor(){At.register(this)}get tag(){return"InnerEditor"}get mode(){return"focus"}get editBox(){return this.editor.editBox}constructor(t){this.eventIds=[],this.editor=t,this.create()}onCreate(){}create(){this.view=new u,this.onCreate()}onLoad(){}load(){const{editor:t}=this;t&&(t.app&&"focus"===this.mode&&(t.selector.hittable=t.app.tree.hitChildren=!1),this.onLoad())}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){const{editor:t}=this;t&&(t.app&&"focus"===this.mode&&(t.selector.hittable=t.app.tree.hitChildren=!0),this.onUnload())}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}let Qt=class extends Jt{static registerEditTool(){At.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach(t=>{t.moveWorld(e,i)}),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach(t=>{const r="scale"!==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="scale"!==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="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)}),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){this.editBox.update(),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};Qt=G([It()],Qt);const{left:te,right:ee}=E,{move:ie,copy:se,toNumberPoints:oe}=w;let ne=class extends Qt{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=i===te;if(n.pathInputed){const{path:t}=n.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,n.points=t}else{const t=P(),{toPoint:i}=n;n.rotation=0,this.dragPoint(t,i,r,o,this.getInnerMove(n,e,s)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(i,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(i,null,null,!0),n.toPoint=i}}getInnerMove(t,e,i){const s=e.getInnerMove(t);return i&&(Math.abs(s.x)>Math.abs(s.y)?s.y=0:s.x=0),s}getFromToByPath(t){return{from:{x:t[1],y:t[2]},to:{x:t[4],y:t[5]}}}getFromToByPoints(t){const e=oe(t);return{from:{x:e[0],y:e[1]},to:{x:e[2],y:e[3]}}}dragPoint(t,e,i,s,o){const{x:n,y:r}=o;i?(ie(t,n,r),s&&ie(e,-n,-r)):(s&&ie(t,-n,-r),ie(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=t,n=this.editor.element;let r,a;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:a}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(a,a,!1,t),o.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),se(s[7],i),se(e[7],i),se(s[3],a),se(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===te||t===ee,s[t].visible=a,e[t].visible=!r&&a}};ne=G([It()],ne),C.add("editor","resize"),V.editor=function(t,e){const i=new qt(t);return e&&e.sky.add(e.editor=i),i},k.addAttr("textBox",!1,H),d.addAttr("editConfig",void 0,H),d.addAttr("editOuter",t=>(t.updateLayout(),t.__.__isLinePath?"LineEditTool":"EditTool"),H),d.addAttr("editInner","PathEditor",H),u.addAttr("editInner","",H),x.addAttr("editInner","TextEditor",H),d.setEditConfig=function(t){this.changeAttr("editConfig",t)},d.setEditOuter=function(t){this.changeAttr("editOuter",t)},d.setEditInner=function(t){this.changeAttr("editInner",t)};export{Ot as EditBox,Et as EditDataHelper,Lt as EditPoint,rt as EditSelect,it as EditSelectHelper,Qt as EditTool,At as EditToolCreator,qt as Editor,Y as EditorEvent,Wt as EditorGroupEvent,Vt as EditorHelper,Ut as EditorMoveEvent,Kt as EditorRotateEvent,Nt as EditorScaleEvent,jt as EditorSkewEvent,Jt as InnerEditor,Ft as InnerEditorEvent,ne as LineEditTool,et as SelectArea,tt as Stroker,$t as TransformTool,It as registerEditTool,Dt as registerInnerEditor};
|
|
1
|
+
import{Event as t,isArray as e,defineKey as i,isNull as s,isObject as o,MatrixHelper as n,BoundsHelper as r,LeafBoundsHelper as a,getMatrixData as h,getBoundsData as l,UI as d,isString as c,Paint as g,Group as u,Rect as f,Bounds as p,LeafList as m,Direction9 as E,AroundHelper as v,MathHelper as b,PointHelper as w,Box as k,isNumber as L,ResizeEvent as y,Text as x,Matrix as O,Debug as _,LeafHelper as T,PropertyEvent as S,isUndefined as B,DataHelper as M,Plugin as C,RenderEvent as R,getPointData as P,Creator as V,dataType as H}from"@leafer-ui/draw";import{PointerEvent as I,DragEvent as D,MoveEvent as A,ZoomEvent as z,KeyEvent as F,RotateEvent as W,useModule as Z}from"@leafer-ui/core";import"@leafer-in/resize";function G(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?e(t)?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class Y extends t{get list(){return X(this.value)}get oldList(){return X(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}function U(t){return(s,n)=>{const r="_"+n;i(s,n,{get(){return this[r]},set(i){const s=this[r];if(s!==i){if(this.config){const t="target"===n;if(t){e(i)&&i.length>1&&i[0].locked&&i.splice(0,1),this.single&&(this.element.syncEventer=null);const{beforeSelect:t}=this.config;if(t){const e=t({target:i});if(o(e))i=e;else if(!1===e)return}}const r=t?Y.BEFORE_SELECT:Y.BEFORE_HOVER;this.hasEvent(r)&&this.emitEvent(new Y(r,{editor:this,value:i,oldValue:s}))}this[r]=i,t(this,s)}}})}}Y.BEFORE_SELECT="editor.before_select",Y.SELECT="editor.select",Y.AFTER_SELECT="editor.after_select",Y.BEFORE_HOVER="editor.before_hover",Y.HOVER="editor.hover";const{abs:N}=Math,{copy:K,scale:j}=n,{setListWithFn:$}=r,{worldBounds:q}=a,J=h(),Q=l();class tt extends d{constructor(){super(),this.list=[],this.visible=0,this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){e&&this.set(e),this.target=t,this.update()}update(t){const{list:e}=this;e.length?($(Q,e,q),t&&this.set(t),this.set(Q),this.visible=!0):this.visible=0}__draw(t,e){const{list:i}=this;if(i.length){let s;const o=this.__,{stroke:n,strokeWidth:r,fill:a}=o,{bounds:h}=e;for(let l=0;l<i.length;l++){s=i[l];const{worldTransform:d,worldRenderBounds:u}=s;if(u.width&&u.height&&(!h||h.hit(u,e.matrix))){const i=N(d.scaleX),h=N(d.scaleY);if(K(J,d),J.half=r%2,i!==h){j(J,1/i,1/h),t.setWorld(J,e.matrix),t.beginPath(),o.strokeWidth=r;const{x:n,y:a,width:l,height:d}=s.__layout.boxBounds;t.rect(n*i,a*h,l*i,d*h)}else t.setWorld(J,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),o.strokeWidth=r/N(d.scaleX);n&&(c(n)?g.stroke(n,this,t):g.strokes(n,this,t)),a&&(c(a)?g.fill(a,this,t):g.fills(a,this,t))}}o.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}G([U(function(t){const i=t.target;t.list=i?e(i)?i:[i]:[]})],tt.prototype,"target",void 0);class et extends u{constructor(t){super(t),this.strokeArea=new f({strokeAlign:"center"}),this.fillArea=new f,this.visible=0,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 it={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return st([t],i,e),i}};function st(t,e,i){let s,o;for(let n=0,r=t.length;n<r;n++)if(s=t[n],o=s.__,o.hittable&&o.visible&&!o.locked&&i.hit(s.__world)){if(o.editable){if(s.isBranch&&!o.hitChildren){o.hitSelf&&e.push(s);continue}if(s.isFrame){if(i.includes(s.__layout.boxBounds,s.__world)){e.push(s);continue}}else i.hit(s.__layout.boxBounds,s.__world)&&o.hitSelf&&e.push(s)}s.isBranch&&st(s.children,e,i)}}const{findOne:ot,findByBounds:nt}=it;class rt extends u{get dragging(){return!!this.originList}get running(){const{editor:t}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new tt,this.targetStroker=new tt,this.bounds=new p,this.selectArea=new et,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:s,hoverStyle:o}=t.mergeConfig;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},o||{}))}}onSelect(){this.running&&(this.targetStroker.setTarget(this.editor.list),this.hoverStroker.target=null)}update(){this.hoverStroker.update();const{stroke:t,strokeWidth:e,selectedStyle:i}=this.editor.mergedConfig;this.targetStroker.update(Object.assign({stroke:t,strokeWidth:e&&Math.max(1,e/2)},i||{}))}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.interaction.canHover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){if(t.multiTouch)return;const{select:e}=this.editor.mergeConfig;"press"===e&&(this.app.config.mobile?this.waitSelect=()=>this.checkAndSelect(t):this.checkAndSelect(t))}onTap(t){if(t.multiTouch)return;const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i?this.checkAndSelect(t):this.waitSelect&&this.waitSelect(),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(this.isHoldMultipleSelectKey(t)||(e.target=null))}}onDragStart(t){if(!t.multiTouch&&(this.waitSelect&&this.waitSelect(),this.allowDrag(t))){const{editor:e}=this,{stroke:i,area:s}=e.mergeConfig,{x:o,y:n}=t.getInnerPoint(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(!t.multiTouch){if(this.editor.dragging)return this.onDragEnd(t);if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new m(nt(e.app,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(t){t.multiTouch||this.dragging&&(this.originList=null,this.selectArea.visible=0)}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){const{boxSelect:e,multipleSelect:i}=this.editor.mergeConfig;return!(!(this.running&&i&&e)||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||this.isHoldMultipleSelectKey(t)&&!ot(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new m(this.editor.editBox.rect)};return ot(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):ot(t.path)}isMultipleSelect(t){const{multipleSelect:e,continuousSelect:i}=this.editor.mergeConfig;return e&&(this.isHoldMultipleSelectKey(t)||i)}isHoldMultipleSelectKey(t){const{multipleSelectKey:e}=this.editor.mergedConfig;return e?t.isHoldKeys(e):t.shiftKey}__listenEvents(){const{editor:t}=this;t.waitLeafer(()=>{const{app:e}=t;e.selector.proxy=t,this.__eventIds=[t.on_([[Y.HOVER,this.onHover,this],[Y.SELECT,this.onSelect,this]]),e.on_([[I.MOVE,this.onPointerMove,this],[I.BEFORE_DOWN,this.onBeforeDown,this],[I.TAP,this.onTap,this],[D.START,this.onDragStart,this,!0],[D.DRAG,this.onDrag,this],[D.END,this.onDragEnd,this],[A.MOVE,this.onAutoMove,this],[[z.ZOOM,A.MOVE],()=>{this.editor.hoverTarget=null}]])]})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:at,top:ht,topRight:lt,right:dt,bottomRight:ct,bottom:gt,bottomLeft:ut,left:ft}=E,{toPoint:pt}=v,{within:mt}=b,Et={getScaleData(t,e,i,s,o,n,a,h){let l,d={},c=1,g=1;const{boxBounds:u,widthRange:f,heightRange:m,dragBounds:E,worldBoxBounds:v}=t,{width:b,height:w}=e;n&&(s.x*=2,s.y*=2);const k=t.scaleX/e.scaleX,L=t.scaleY/e.scaleY,y=k<0?-1:1,x=L<0?-1:1,O=h?k:y*u.width/b,_=h?L:x*u.height/w;s.x*=h?k:y,s.y*=h?L:x;const T=(-s.y+w)/w,S=(s.x+b)/b,B=(s.y+w)/w,M=(-s.x+b)/b;switch(i){case ht:g=T,l="bottom";break;case dt:c=S,l="left";break;case gt:g=B,l="top";break;case ft:c=M,l="right";break;case at:g=T,c=M,l="bottom-right";break;case lt:g=T,c=S,l="bottom-left";break;case ct:g=B,c=S,l="top-left";break;case ut:g=B,c=M,l="top-right"}if(o)if("corner"===o&&i%2)o=!1;else{let t;switch(i){case ht:case gt:t=g;break;case ft:case dt:t=c;break;default:t=Math.sqrt(Math.abs(c*g))}c=c<0?-t:t,g=g<0?-t:t}const C=1!==c,R=1!==g;if(C&&(c/=O),R&&(g/=_),!a){const{worldTransform:e}=t;c<0&&(c=1/u.width/e.scaleX),g<0&&(g=1/u.height/e.scaleY)}if(pt(n||l,u,d,!0),E){const e="parent"===E?t.parent.boxBounds:E,i=new p(t.__localBoxBounds);if(r.includes(new p(e).spread(.1),i)&&(i.scaleOf(t.getLocalPointByInner(d),c,g),!r.includes(e,i))){const t=i.getIntersect(e),s=t.width/i.width,o=t.height/i.height;C&&(c*=s),R&&(g*=o)}}if(C&&f){const e=u.width*t.scaleX;c=mt(e*c,f)/e}if(R&&m){const e=u.height*t.scaleY;g=mt(e*g,m)/e}return C&&Math.abs(c*v.width)<1&&(c=(c<0?-1:1)/v.width),R&&Math.abs(g*v.height)<1&&(g=(g<0?-1:1)/v.height),o&&c!==g&&(g=c=Math.min(c,g)),{origin:d,scaleX:c,scaleY:g,direction:i,lockRatio:o,around:n}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case at:n="bottom-right";break;case lt:n="bottom-left";break;case ct:n="top-left";break;case ut:n="top-right";break;default:n="center"}return pt(o||n,t.boxBounds,r,!0),{origin:r,rotation:w.getRotation(s,t.getWorldPointByBox(r),i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,h=0;switch(e){case ht:case at:n={x:.5,y:0},o="bottom",a=1;break;case gt:case ct:n={x:.5,y:1},o="top",a=1;break;case ft:case ut:n={x:0,y:.5},o="right",h=1;break;case dt:case lt:n={x:1,y:.5},o="left",h=1}const{width:l,height:d}=t;n.x=n.x*l,n.y=n.y*d,pt(s||o,t,r,!0);const c=w.getRotation(n,r,{x:n.x+(a?i.x:0),y:n.y+(h?i.y:0)});return a?a=-c:h=c,{origin:r,skewX:a,skewY:h}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case ft:t=dt;break;case at:t=lt;break;case ut:t=ct;break;case dt:t=ft;break;case lt:t=at;break;case ct:t=ut}if(i)switch(t){case ht:t=gt;break;case at:t=ut;break;case lt:t=ct;break;case gt:t=ht;break;case ut:t=at;break;case ct:t=lt}return t}},vt={};function bt(t,e){const{enterPoint:i,dragging:s,skewing:o,resizing:n,flippedX:r,flippedY:a}=t;if(!i||!t.editor.editing||!t.canUse)return;if("circle"===i.name)return;if("button"===i.pointType)return void(i.cursor||(i.cursor="pointer"));let{rotation:h}=t;const{pointType:l}=i,{resizeCursor:d,rotateCursor:c,skewCursor:g,resizeable:u,rotateable:f,skewable:p}=t.mergeConfig;let m=l.includes("resize");m&&f&&(t.isHoldRotateKey(e)||!u)&&(m=!1);const E=p&&!m&&("resize-line"===i.name||"skew"===l),v=s?o?g:n?d:c:E?g:m?d:c;h+=45*(Et.getFlipDirection(i.direction,r,a)+1),h=2*Math.round(b.formatRotation(h,!0)/2);const{url:w,x:k,y:L}=v,y=w+h;vt[y]?i.cursor=vt[y]:vt[y]=i.cursor={url:kt(w,h),x:k,y:L}}function wt(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.canUse&&(t.rect.cursor=i?e:void 0)}function kt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Lt extends k{constructor(t){super(t),this.useFastShadow=!0}}const yt=["top","right","bottom","left"],xt=void 0;class Ot extends u{get mergeConfig(){const{config:t}=this,{mergeConfig:e,editBox:i}=this.editor;return this.mergedConfig=t&&i!==this?Object.assign(Object.assign({},e),t):e}get target(){return this._target||this.editor.element}set target(t){this._target=t}get single(){return!!this._target||this.editor.single}get transformTool(){return this._transformTool||this.editor}set transformTool(t){this._transformTool=t}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}get canUse(){return this.visible&&this.view.visible}get canGesture(){if(!this.canUse)return!1;const{moveable:t,resizeable:e,rotateable:i}=this.mergeConfig;return c(t)||c(e)||c(i)}constructor(t){super(),this.view=new u,this.rect=new k({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Lt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new u({around:"center",hitSelf:!1,visible:0}),this.resizePoints=[],this.rotatePoints=[],this.resizeLines=[],this.dragStartData={},this.__eventIds=[],this.editor=t,this.visible=!1,this.create(),this.__listenEvents()}create(){let t,e,i;const{view:s,resizePoints:o,rotatePoints:n,resizeLines:r,rect:a,circle:h,buttons:l}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let s=0;s<8;s++)t=new Lt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Lt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new Lt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);this.listenPointEvents(h,"rotate",2),s.addMany(...n,a,h,l,...r,...o),this.add(s)}load(){const{target:t,mergeConfig:e,single:i,rect:s,circle:o,resizePoints:n}=this,{stroke:r,strokeWidth:a}=e,h=this.getPointsStyle(),l=this.getMiddlePointsStyle();let d;this.visible=!t.locked;for(let t=0;t<8;t++)d=n[t],d.set(this.getPointStyle(t%2?l[(t-1)/2%l.length]:h[t/2%h.length])),d.rotation=(t-(t%2?1:0))/2*90;o.set(this.getPointStyle(e.circle||e.rotatePoint||h[0])),s.set(Object.assign({stroke:r,strokeWidth:a,editConfig:xt},e.rect||{}));const c=i&&this.transformTool.editTool;s.hittable=!c,s.syncEventer=c&&this.editor,c&&(t.syncEventer=s,this.app.interaction.bottomList=[{target:s,proxy:t}]),wt(this)}update(){const{editor:t}=this,{x:e,y:i,scaleX:s,scaleY:o,rotation:n,skewX:r,skewY:a,width:h,height:l}=this.target.getLayoutBounds("box",t,!0);this.visible=!this.target.locked,this.set({x:e,y:i,scaleX:s,scaleY:o,rotation:n,skewX:r,skewY:a}),this.updateBounds({x:0,y:0,width:h,height:l})}unload(){this.visible=!1,this.app&&(this.rect.syncEventer=this.app.interaction.bottomList=null)}updateBounds(t){const{editMask:e}=this.editor,{mergeConfig:i,single:s,rect:o,circle:n,buttons:a,resizePoints:h,rotatePoints:l,resizeLines:d}=this,{middlePoint:c,resizeable:g,rotateable:u,hideOnSmall:f,editBox:p,mask:m,spread:E,hideRotatePoints:b,hideResizeLines:w}=i;if(e.visible=!!m||0,E&&r.spread(t,E),this.view.worldOpacity){const{width:e,height:r}=t,m=L(f)?f:10,E=p&&!(f&&e<m&&r<m);let k,y,x,O={};for(let i=0;i<8;i++)v.toPoint(v.directionData[i],t,O),y=h[i],k=l[i],y.set(O),k.set(O),y.visible=E&&!(!g&&!u),k.visible=E&&u&&g&&!b,i%2&&(x=d[(i-1)/2],x.set(O),x.visible=y.visible&&!w,y.visible=k.visible=E&&!!c,(i+1)/2%2?(x.width=e,f&&2*y.width>e&&(y.visible=!1)):(x.height=r,f&&2*y.width>r&&(y.visible=!1)));n.visible=E&&u&&!(!i.circle&&!i.rotatePoint),n.visible&&this.layoutCircle(),o.path&&(o.path=null),o.set(Object.assign(Object.assign({},t),{visible:!s||p})),a.visible=E&&a.children.length>0||0,a.visible&&this.layoutButtons()}else o.set(t)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,n=yt.indexOf(t||(this.buttons.children.length&&"bottom"===s?"top":"bottom"));this.setButtonPosition(this.circle,n,e||i,!!o)}layoutButtons(){const{buttons:t}=this,{buttonsDirection:e,buttonsFixed:i,buttonsMargin:s,middlePoint:o}=this.mergedConfig,{flippedX:n,flippedY:r}=this;let a=yt.indexOf(e);(a%2&&n||(a+1)%2&&r)&&i&&(a=(a+2)%4);const h=i?Et.getRotateDirection(a,this.flippedOne?this.rotation:-this.rotation,4):a;this.setButtonPosition(t,h,s,!!o),i&&(t.rotation=90*(h-a)),t.scaleX=n?-1:1,t.scaleY=r?-1:1}setButtonPosition(t,e,i,s){const o=this.resizePoints[2*e+1],n=e%2,r=e&&3!==e?1:-1,a=(i+(e%2?(s?o.width:0)+t.boxBounds.width:(s?o.height:0)+t.boxBounds.height)/2)*r;n?(t.x=o.x+a,t.y=o.y):(t.x=o.x,t.y=o.y+a)}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.mergedConfig,r={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:o,height:o,cornerRadius:n,offsetX:0,offsetY:0,editConfig:xt};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.mergedConfig;return e(t)?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.mergedConfig;return e(t)?t:t?[t]:this.getPointsStyle()}onDragStart(t){this.dragging=!0;const e=this.dragPoint=t.current,{pointType:i}=e,{editor:s,dragStartData:o}=this,{target:n}=this,{moveable:r,resizeable:a,rotateable:h,skewable:l,hideOnMove:d}=this.mergeConfig;"rect"===e.name?(r&&(this.moving=!0),s.opacity=d?0:1):(i.includes("rotate")||this.isHoldRotateKey(t)||!a?(h&&(this.rotating=!0),"resize-rotate"===i?a&&(this.resizing=!0):"resize-line"===e.name&&(l&&(this.skewing=!0),this.rotating=!1)):"resize"===i&&a&&(this.resizing=!0),"skew"===i&&l&&(this.skewing=!0)),o.x=t.x,o.y=t.y,o.point={x:n.x,y:n.y},o.bounds=Object.assign({},n.getLayoutBounds("box","local")),o.rotation=n.rotation,i&&i.includes("resize")&&(y.resizingKeys=s.leafList.keys)}onDragEnd(t){this.moving&&this.transformTool.onMove(t),this.dragPoint=null,this.resetDoing();const{name:e,pointType:i}=t.current;"rect"===e&&(this.editor.opacity=1),i&&i.includes("resize")&&(y.resizingKeys=null)}onDrag(t){const{transformTool:e,moving:i,resizing:s,rotating:o,skewing:n}=this;if(i)e.onMove(t),wt(this);else if(s||o||n){const i=t.current;i.pointType&&(this.enterPoint=i),o&&e.onRotate(t),s&&e.onScale(t),n&&e.onSkew(t),bt(this,t)}}resetDoing(){this.canUse&&(this.dragging=this.gesturing=this.moving=this.resizing=this.rotating=this.skewing=!1)}onMove(t){this.canGesture&&"drag"!==t.moveType&&(t.stop(),c(this.mergeConfig.moveable)&&(this.gesturing=this.moving=!0,this.transformTool.onMove(t)))}onMoveEnd(t){this.moving&&this.transformTool.onMove(t),this.resetDoing()}onScale(t){this.canGesture&&(t.stop(),c(this.mergeConfig.resizeable)&&(this.gesturing=this.resizing=!0,this.transformTool.onScale(t)))}onRotate(t){this.canGesture&&(t.stop(),c(this.mergeConfig.rotateable)&&(this.gesturing=this.rotating=!0,this.transformTool.onRotate(t)))}isHoldRotateKey(t){const{rotateKey:e}=this.mergedConfig;return e?t.isHoldKeys(e):t.metaKey||t.ctrlKey}onKey(t){bt(this,t)}onArrow(t){const{editor:e,transformTool:i}=this;if(this.canUse&&e.editing&&this.mergeConfig.keyEvent){let e=0,s=0;const o=t.shiftKey?10:1;switch(t.code){case"ArrowDown":s=o;break;case"ArrowUp":s=-o;break;case"ArrowLeft":e=-o;break;case"ArrowRight":e=o}(e||s)&&i.move(e,s)}}onDoubleTap(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"double"!==e||i||this.openInner(t)}onLongPress(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"long"===e&&i&&this.openInner(t)}openInner(t){const{editor:e,target:i}=this;if(this.single){if(i.locked)return;if(i.isBranch&&!i.editInner){if(i.textBox){const{children:t}=i,s=t.find(t=>t.editable&&t instanceof x)||t.find(t=>t instanceof x);if(s)return e.openInnerEditor(s)}e.openGroup(i),e.target=e.selector.findDeepOne(t)}else e.openInnerEditor()}}listenPointEvents(t,e,i){t.direction=i,t.pointType=e;const s=[[D.START,this.onDragStart,this],[D.DRAG,this.onDrag,this],[D.END,this.onDragEnd,this],[I.LEAVE,()=>{this.enterPoint=null}]];"circle"!==t.name&&s.push([I.ENTER,e=>{this.enterPoint=t,bt(this,e)}]),this.__eventIds.push(t.on_(s))}__listenEvents(){const{rect:t,editor:e,__eventIds:i}=this;i.push(t.on_([[D.START,this.onDragStart,this],[D.DRAG,this.onDrag,this],[D.END,this.onDragEnd,this],[I.ENTER,()=>wt(this)],[I.DOUBLE_TAP,this.onDoubleTap,this],[I.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer(()=>{i.push(e.app.on_([[[F.HOLD,F.UP],this.onKey,this],[F.DOWN,this.onArrow,this],[A.BEFORE_MOVE,this.onMove,this,!0],[z.BEFORE_ZOOM,this.onScale,this,!0],[W.BEFORE_ROTATE,this.onRotate,this,!0],[A.END,this.onMoveEnd,this],[z.END,this.resetDoing,this],[W.END,this.resetDoing,this]]))})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const _t={x:0,y:0,width:1e5,height:1e5};class Tt extends d{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,_t),Object.assign(this.__world,_t)}__draw(t,e){const{editor:i}=this,{mask:s}=i.mergedConfig;if(s&&i.editing){if(t.fillWorld(t.bounds,!0===s?"rgba(0,0,0,0.8)":s),e.bounds&&!e.bounds.hit(i.editBox.rect.__world,e.matrix))return;t.saveBlendMode("destination-out"),e=Object.assign(Object.assign({},e),{shape:!0}),i.list.forEach(i=>{i.__render(t,e);const{parent:s}=i;s&&s.textBox&&s.__renderShape(t,e)}),t.restoreBlendMode()}}destroy(){this.editor=null,super.destroy()}}const St='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',Bt={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${St}\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${St}\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${St}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,editBox:!0,hover:!0,select:"press",openInner:"double",multipleSelect:!0,boxSelect:!0,moveable:!0,resizeable:!0,flipable:!0,rotateable:!0,skewable:!0},Mt=new p;function Ct(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange(()=>{Mt.setListWithFn(i,t=>t.getBounds("box","page")),0===Mt.width&&(Mt.width=.1),0===Mt.height&&(Mt.height=.1),e.reset(Mt.get())}),s.add(e)}const Rt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Pt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Vt={group(t,e,i){t.sort(Pt);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(Rt);const r=new O(e.worldTransform);return r.divideParent(o.scrollWorldTransform),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.isBranchLeaf?i.push(t):t.remove()}else i.push(t)}),e.unlockLayout(),i},toTop(t){t.sort(Rt),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(Pt),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})}},Ht=_.get("EditToolCreator");function It(){return t=>{At.register(t)}}const Dt=It,At={list:{},register(t){const{tag:e}=t.prototype;zt[e]&&Ht.repeat(e),zt[e]=t},get:(t,e)=>new zt[t](e)},{list:zt}=At;class Ft extends Y{constructor(t,e){super(t,e)}}Ft.BEFORE_OPEN="innerEditor.before_open",Ft.OPEN="innerEditor.open",Ft.BEFORE_CLOSE="innerEditor.before_close",Ft.CLOSE="innerEditor.close";class Wt extends Y{constructor(t,e){super(t,e)}}Wt.BEFORE_GROUP="editor.before_group",Wt.GROUP="editor.group",Wt.BEFORE_UNGROUP="editor.before_ungroup",Wt.UNGROUP="editor.ungroup",Wt.BEFORE_OPEN="editor.before_open_group",Wt.OPEN="editor.open_group",Wt.BEFORE_CLOSE="editor.before_close_group",Wt.CLOSE="editor.close_group";const{updateMatrix:Zt}=T,Gt={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},Xt="top-left";class Yt extends f{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.on(S.CHANGE,e=>{if(this.checkChange&&Gt[e.attrName]){const{attrName:i,newValue:s,oldValue:o}=e,n="s"===i[0]?(s||1)/(o||1):(s||0)-(o||0);this.canChange=!1;const r=this.__;r[i]=o,Zt(this.parent),Zt(this);const a=new O(this.__world);switch(r[i]=s,this.__layout.rotationChange(),Zt(this),this.changedTransform=new O(this.__world).divide(a),i){case"x":t.move(n,0);break;case"y":t.move(0,n);break;case"rotation":t.rotateOf(Xt,n);break;case"scaleX":t.scaleOf(Xt,n,1);break;case"scaleY":t.scaleOf(Xt,1,n);break;case"skewX":t.skewOf(Xt,n,0);break;case"skewY":t.skewOf(Xt,0,n)}this.canChange=!0}})}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class Ut extends Y{constructor(t,e){super(t,e)}}Ut.BEFORE_MOVE="editor.before_move",Ut.MOVE="editor.move";class Nt extends Y{constructor(t,e){super(t,e)}}Nt.BEFORE_SCALE="editor.before_scale",Nt.SCALE="editor.scale";class Kt extends Y{constructor(t,e){super(t,e)}}Kt.BEFORE_ROTATE="editor.before_rotate",Kt.ROTATE="editor.rotate";class jt extends Y{constructor(t,e){super(t,e)}}jt.BEFORE_SKEW="editor.before_skew",jt.SKEW="editor.skew";class $t{onMove(t){const{target:e,mergeConfig:i,dragStartData:s,app:o}=this.editBox;let n,{dragLimitAnimate:r}=i;B(r)&&(r=o&&o.config.pointer.dragLimitAnimate);const a=t.type===A.END||t.type===D.END,h=c(e.draggable),l=!r||a||h;if(t instanceof A)n=t.getLocalMove(e),l&&D.limitMove(e,n);else{const i={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(i.x)>Math.abs(i.y)?i.y=0:i.x=0),n=D.getValidMove(e,s.point,i,l)}(n.x||n.y)&&(r&&!h&&a?T.animateMove(this,n,L(r)?r:.3):this.move(n))}onScale(t){const{target:e,mergeConfig:i,single:s,dragStartData:o}=this.editBox;let{around:n,lockRatio:r,flipable:a,editSize:h}=i;if(t instanceof z)this.scaleOf(e.getBoxPoint(t),t.scale,t.scale);else{const{direction:i}=t.current;(t.shiftKey||e.lockRatio)&&(r=!0);const l=Et.getScaleData(e,o.bounds,i,t.getInnerTotal(e),r,Et.getAround(n,t.altKey),a,!s||"scale"===h);this.editTool&&this.editTool.onScaleWithDrag?(l.drag=t,this.scaleWithDrag(l)):this.scaleOf(l.origin,l.scaleX,l.scaleY)}}onRotate(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox,{around:o,rotateAround:n,rotateGap:r}=i,{direction:a}=t.current;let h,l;if(t instanceof W)l=t.rotation,h=n?v.getPoint(n,e.boxBounds):e.getBoxPoint(t);else{const i=Et.getRotateData(e,a,t,s,t.shiftKey?null:n||e.around||e.origin||o||"center");l=s.rotation+i.rotation-e.rotation,h=i.origin}l=b.float(b.getGapRotation(l,r,e.rotation),2),l&&this.rotateOf(h,l)}onSkew(t){const{target:e,mergeConfig:i}=this.editBox,{around:s}=i,{origin:o,skewX:n,skewY:r}=Et.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),Et.getAround(s,t.altKey));(n||r)&&this.skewOf(o,n,r)}move(t,e=0){if(!this.checkTransform("moveable"))return;o(t)&&(e=t.y,t=t.x);const{target:i,mergeConfig:s,single:n,editor:r}=this.editBox,{beforeMove:a}=s;if(a){const s=a({target:i,x:t,y:e});if(o(s))t=s.x,e=s.y;else if(!1===s)return}const h=i.getWorldPointByLocal({x:t,y:e},null,!0);n||i.safeChange(()=>i.move(t,e));const l={target:i,editor:r,moveX:h.x,moveY:h.y};this.emitEvent(new Ut(Ut.BEFORE_MOVE,l));const d=new Ut(Ut.MOVE,l);this.doMove(d),this.emitEvent(d)}scaleWithDrag(t){if(!this.checkTransform("resizeable"))return;const{target:e,mergeConfig:i,editor:s}=this.editBox,{beforeScale:o}=i;if(o){const{origin:i,scaleX:s,scaleY:n,drag:r}=t;if(!1===o({target:e,drag:r,origin:i,scaleX:s,scaleY:n}))return}t=Object.assign(Object.assign({},t),{target:e,editor:s,worldOrigin:e.getWorldPoint(t.origin)}),this.emitEvent(new Nt(Nt.BEFORE_SCALE,t));const n=new Nt(Nt.SCALE,t);this.editTool.onScaleWithDrag(n),this.emitEvent(n)}scaleOf(t,e,i=e,s){if(!this.checkTransform("resizeable"))return;const{target:n,mergeConfig:r,single:a,editor:h}=this.editBox,{beforeScale:l}=r;if(l){const s=l({target:n,origin:t,scaleX:e,scaleY:i});if(o(s))e=s.scaleX,i=s.scaleY;else if(!1===s)return}const d=this.getWorldOrigin(t),c=!a&&this.getChangedTransform(()=>n.safeChange(()=>n.scaleOf(t,e,i))),g={target:n,editor:h,worldOrigin:d,scaleX:e,scaleY:i,transform:c};this.emitEvent(new Nt(Nt.BEFORE_SCALE,g));const u=new Nt(Nt.SCALE,g);this.doScale(u),this.emitEvent(u)}flip(t){if(!this.checkTransform("resizeable"))return;const{target:e,single:i,editor:s}=this.editBox,o=this.getWorldOrigin("center"),n=i?new O(T.getFlipTransform(e,t)):this.getChangedTransform(()=>e.safeChange(()=>e.flip(t))),r={target:e,editor:s,worldOrigin:o,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:n};this.emitEvent(new Nt(Nt.BEFORE_SCALE,r));const a=new Nt(Nt.SCALE,r);this.doScale(a),this.emitEvent(a)}rotateOf(t,e){if(!this.checkTransform("rotateable"))return;const{target:i,mergeConfig:s,single:o,editor:n}=this.editBox,{beforeRotate:r}=s;if(r){const s=r({target:i,origin:t,rotation:e});if(L(s))e=s;else if(!1===s)return}const a=this.getWorldOrigin(t),h=!o&&this.getChangedTransform(()=>i.safeChange(()=>i.rotateOf(t,e))),l={target:i,editor:n,worldOrigin:a,rotation:e,transform:h};this.emitEvent(new Kt(Kt.BEFORE_ROTATE,l));const d=new Kt(Kt.ROTATE,l);this.doRotate(d),this.emitEvent(d)}skewOf(t,e,i=0,s){if(!this.checkTransform("skewable"))return;const{target:n,mergeConfig:r,single:a,editor:h}=this.editBox,{beforeSkew:l}=r;if(l){const s=l({target:n,origin:t,skewX:e,skewY:i});if(o(s))e=s.skewX,i=s.skewY;else if(!1===s)return}const d=this.getWorldOrigin(t),c=!a&&this.getChangedTransform(()=>n.safeChange(()=>n.skewOf(t,e,i))),g={target:n,editor:h,worldOrigin:d,skewX:e,skewY:i,transform:c};this.emitEvent(new jt(jt.BEFORE_SKEW,g));const u=new jt(jt.SKEW,g);this.doSkew(u),this.emitEvent(u)}doMove(t){this.editTool.onMove(t)}doScale(t){this.editTool.onScale(t)}doRotate(t){this.editTool.onRotate(t)}doSkew(t){this.editTool.onSkew(t)}checkTransform(t){const{target:e,mergeConfig:i}=this.editBox;return e&&!e.locked&&i[t]}getWorldOrigin(t){const{target:e}=this.editBox;return e.getWorldPoint(T.getInnerOrigin(e,t))}getChangedTransform(t){const{target:e,single:i}=this.editBox;if(!i&&!e.canChange)return e.changedTransform;const s=new O(e.worldTransform);return t(),new O(e.worldTransform).divide(s)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}let qt=class extends u{get list(){return this.leafList.list}get dragHoverExclude(){return[this.editBox.rect]}get editing(){return!!this.list.length}get groupOpening(){return!!this.openedGroupList.length}get multiple(){return this.list.length>1}get single(){return 1===this.list.length}get dragPoint(){return this.editBox.dragPoint}get dragging(){return this.editBox.dragging}get gesturing(){return this.editBox.gesturing}get moving(){return this.editBox.moving}get resizing(){return this.editBox.resizing}get rotating(){return this.editBox.rotating}get skewing(){return this.editBox.skewing}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}get targetLeafer(){const t=this.list[0];return t&&t.leafer}constructor(t,e){super(e),this.leafList=new m,this.openedGroupList=new m,this.simulateTarget=new Yt(this),this.editBox=new Ot(this),this.editToolList={},this.selector=new rt(this),this.editMask=new Tt(this),this.targetEventIds=[];let i=M.clone(Bt);t&&(i=M.default(t,i)),this.mergedConfig=this.config=i,this.addMany(this.editMask,this.selector,this.editBox),C.has("resize")||(this.config.editSize="scale")}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){if(this.editing){if(!this.element.parent)return this.cancel();this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update()}}updateEditBox(){this.multiple&&Ct(this),this.update()}updateEditTool(){if(this.unloadEditTool(),this.editing){const t=this.element;let e=t.editOuter||"EditTool";const{beforeEditOuter:i}=this.mergeConfig;if(i){const s=i({target:t,name:e});if(c(s))e=s;else if(!1===s)return}if(At.list[e]){const t=this.editTool=this.editToolList[e]=this.editToolList[e]||At.get(e,this);this.editBox.load(),t.load(),this.update()}}}unloadEditTool(){let t=this.editTool;t&&(this.editBox.unload(),t.unload(),this.editTool=null)}getEditSize(t){return this.mergeConfig.editSize}onMove(t){}onScale(t){}onRotate(t){}onSkew(t){}move(t,e=0){}scaleWithDrag(t){}scaleOf(t,e,i=e,s){}flip(t){}rotateOf(t,e){}skewOf(t,e,i=0,s){}checkTransform(t){}getWorldOrigin(t){}getChangedTransform(t){}group(t){return this.multiple&&(this.emitGroupEvent(Wt.BEFORE_GROUP),this.target=Vt.group(this.list,this.element,t),this.emitGroupEvent(Wt.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach(t=>t.isBranch&&this.emitGroupEvent(Wt.BEFORE_UNGROUP,t)),this.target=Vt.ungroup(t),t.forEach(t=>t.isBranch&&this.emitGroupEvent(Wt.UNGROUP,t))),this.list}openGroup(t){this.emitGroupEvent(Wt.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Wt.OPEN,t)}closeGroup(t){this.emitGroupEvent(Wt.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Wt.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach(t=>this.list.every(e=>!T.hasParent(e,t))&&e.push(t))),e.forEach(t=>this.closeGroup(t))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new Wt(t,{editTarget:e});e&&e.syncEventer||this.emitEvent(i),e&&e.emitEvent(i)}openInnerEditor(t,e,i){let s;if(c(e)?s=e:i||(i=e),t&&i&&(this.target=t),this.single){t||(t=this.element),s||(s=t.editInner);const{beforeEditInner:e}=this.mergeConfig;if(e){const i=e({target:t,name:s});if(c(i))s=i;else if(!1===i)return}At.list[s]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[s]=this.editToolList[s]||At.get(s,this),this.innerEditor.editTarget=t,this.emitInnerEvent(Ft.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Ft.OPEN))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Ft.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Ft.CLOSE),t||this.updateEditTool(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Ft(t,{editTarget:i,innerEditor:e});i.syncEventer||this.emitEvent(s),i.emitEvent(s)}lock(){this.list.forEach(t=>t.locked=!0),this.update()}unlock(){this.list.forEach(t=>t.locked=!1),this.update()}toTop(){this.list.length&&(Vt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Vt.toBottom(this.list),this.leafList.update())}onAppRenderStart(t){(this.targetChanged=t.children.some(t=>t!==this.leafer&&t.renderer.changed))&&this.editBox.forceRender()}onRenderStart(){this.targetChanged&&this.update()}onChildScroll(){this.multiple&&this.updateEditBox()}listenTargetEvents(){if(!this.targetEventIds.length){const{app:t,leafer:e,targetLeafer:i,editMask:s}=this;this.targetEventIds=[e.on_(R.START,this.onRenderStart,this),i&&i.on_(S.SCROLL,this.onChildScroll,this),t.on_(R.CHILD_START,this.onAppRenderStart,this)],s.visible&&s.forceRender()}}removeTargetEvents(){const{targetEventIds:t,editMask:e}=this;t.length&&(this.off_(t),e.visible&&e.forceRender())}destroy(){this.destroyed||(this.target=this.hoverTarget=null,Object.values(this.editToolList).forEach(t=>t.destroy()),this.simulateTarget.destroy(),this.editToolList={},this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}};G([(t,e)=>{i(t,e,{get(){const{config:t,element:e,dragPoint:i,editBox:o}=this,n=Object.assign({},t);return e&&e.editConfig&&Object.assign(n,e.editConfig),o.config&&Object.assign(n,o.config),i&&(i.editConfig&&Object.assign(n,i.editConfig),"font-size"===n.editSize&&(n.lockRatio=!0),"resize-rotate"===i.pointType&&(n.around||(n.around="center"),s(n.lockRatio)&&(n.lockRatio=!0))),this.mergedConfig=n}})}],qt.prototype,"mergeConfig",void 0),G([U(function(t,e){t.emitEvent(new Y(Y.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))})],qt.prototype,"hoverTarget",void 0),G([U(function(t,e){const{target:i}=t;i?(t.leafList=i instanceof m?i:new m(i),t.multiple&&Ct(t)):(t.simulateTarget.remove(),t.leafList.reset()),t.closeInnerEditor(!0),t.unloadEditTool();const s={editor:t,value:i,oldValue:e};t.emitEvent(new Y(Y.SELECT,s)),t.checkOpenedGroups(),t.editing?t.waitLeafer(()=>{t.updateEditTool(),t.listenTargetEvents()}):(t.updateEditTool(),t.removeTargetEvents()),t.emitEvent(new Y(Y.AFTER_SELECT,s))})],qt.prototype,"target",void 0),qt=G([Z($t,["editBox","editTool","emitEvent"])],qt);class Jt{static registerInnerEditor(){At.register(this)}get tag(){return"InnerEditor"}get mode(){return"focus"}get editBox(){return this.editor.editBox}constructor(t){this.eventIds=[],this.editor=t,this.create()}onCreate(){}create(){this.view=new u,this.onCreate()}onLoad(){}load(){const{editor:t}=this;t&&(t.app&&"focus"===this.mode&&(t.selector.hittable=t.app.tree.hitChildren=!1),this.onLoad())}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){const{editor:t}=this;t&&(t.app&&"focus"===this.mode&&(t.selector.hittable=t.app.tree.hitChildren=!0),this.onUnload())}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}let Qt=class extends Jt{static registerEditTool(){At.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach(t=>{t.moveWorld(e,i)}),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach(t=>{const r="scale"!==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="scale"!==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="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)}),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){this.editBox.update(),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}};Qt=G([It()],Qt);const{left:te,right:ee}=E,{move:ie,copy:se,toNumberPoints:oe}=w;let ne=class extends Qt{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=i===te;if(n.pathInputed){const{path:t}=n.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,n.points=t}else{const t=P(),{toPoint:i}=n;n.rotation=0,this.dragPoint(t,i,r,o,this.getInnerMove(n,e,s)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(i,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(i,null,null,!0),n.toPoint=i}}getInnerMove(t,e,i){const s=e.getInnerMove(t);return i&&(Math.abs(s.x)>Math.abs(s.y)?s.y=0:s.x=0),s}getFromToByPath(t){return{from:{x:t[1],y:t[2]},to:{x:t[4],y:t[5]}}}getFromToByPoints(t){const e=oe(t);return{from:{x:e[0],y:e[1]},to:{x:e[2],y:e[3]}}}dragPoint(t,e,i,s,o){const{x:n,y:r}=o;i?(ie(t,n,r),s&&ie(e,-n,-r)):(s&&ie(t,-n,-r),ie(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=t,n=this.editor.element;let r,a;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:a}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(a,a,!1,t),o.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),se(s[7],i),se(e[7],i),se(s[3],a),se(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===te||t===ee,s[t].visible=a,e[t].visible=!r&&a}};ne=G([It()],ne),C.add("editor","resize"),V.editor=function(t,e){const i=new qt(t);return e&&e.sky.add(e.editor=i),i},k.addAttr("textBox",!1,H),d.addAttr("editConfig",void 0,H),d.addAttr("editOuter",t=>(t.updateLayout(),t.__.__isLinePath?"LineEditTool":"EditTool"),H),d.addAttr("editInner","PathEditor",H),u.addAttr("editInner","",H),x.addAttr("editInner","TextEditor",H),d.setEditConfig=function(t){this.changeAttr("editConfig",t)},d.setEditOuter=function(t){this.changeAttr("editOuter",t)},d.setEditInner=function(t){this.changeAttr("editInner",t)};export{Ot as EditBox,Et as EditDataHelper,Lt as EditPoint,rt as EditSelect,it as EditSelectHelper,Qt as EditTool,At as EditToolCreator,qt as Editor,Y as EditorEvent,Wt as EditorGroupEvent,Vt as EditorHelper,Ut as EditorMoveEvent,Kt as EditorRotateEvent,Nt as EditorScaleEvent,jt as EditorSkewEvent,Jt as InnerEditor,Ft as InnerEditorEvent,ne as LineEditTool,et as SelectArea,tt as Stroker,$t as TransformTool,It as registerEditTool,Dt as registerInnerEditor};
|
|
2
2
|
//# sourceMappingURL=editor.esm.min.js.map
|