@leafer-in/editor 1.12.1 → 1.12.2
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 +11 -4
- package/dist/editor.esm.js +12 -5
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +10 -4
- 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/display/EditSelect.ts +2 -2
- package/src/display/Stroker.ts +14 -6
- package/src/tool/TransformTool.ts +1 -1
- package/types/index.d.ts +4 -3
package/dist/editor.cjs
CHANGED
|
@@ -165,7 +165,11 @@ class Stroker extends draw.UI {
|
|
|
165
165
|
matrix.half = strokeWidth % 2;
|
|
166
166
|
canvas.setWorld(matrix, options.matrix);
|
|
167
167
|
canvas.beginPath();
|
|
168
|
-
if (
|
|
168
|
+
if (this.strokePathType === "path") {
|
|
169
|
+
leaf.__drawPath(canvas);
|
|
170
|
+
} else {
|
|
171
|
+
if (leaf.__.__useArrow) leaf.__drawPath(canvas); else leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
|
|
172
|
+
}
|
|
169
173
|
data.strokeWidth = strokeWidth / Math.max(aScaleX, aScaleY);
|
|
170
174
|
if (stroke) draw.isString(stroke) ? draw.Paint.stroke(stroke, this, canvas, options) : draw.Paint.strokes(stroke, this, canvas, options);
|
|
171
175
|
if (fill) draw.isString(fill) ? draw.Paint.fill(fill, this, canvas, options) : draw.Paint.fills(fill, this, canvas, options);
|
|
@@ -182,6 +186,8 @@ class Stroker extends draw.UI {
|
|
|
182
186
|
|
|
183
187
|
__decorate([ targetAttr(onTarget$1) ], Stroker.prototype, "target", void 0);
|
|
184
188
|
|
|
189
|
+
__decorate([ draw.surfaceType("render-path") ], Stroker.prototype, "strokePathType", void 0);
|
|
190
|
+
|
|
185
191
|
function onTarget$1(stroker) {
|
|
186
192
|
const value = stroker.target;
|
|
187
193
|
stroker.list = value ? draw.isArray(value) ? value : [ value ] : [];
|
|
@@ -296,10 +302,11 @@ class EditSelect extends draw.Group {
|
|
|
296
302
|
}
|
|
297
303
|
update() {
|
|
298
304
|
this.hoverStroker.update();
|
|
299
|
-
const {stroke: stroke, strokeWidth: strokeWidth, selectedStyle: selectedStyle} = this.editor.mergedConfig;
|
|
305
|
+
const {stroke: stroke, strokeWidth: strokeWidth, selectedPathType: selectedPathType, selectedStyle: selectedStyle} = this.editor.mergedConfig;
|
|
300
306
|
this.targetStroker.update(Object.assign({
|
|
301
307
|
stroke: stroke,
|
|
302
|
-
strokeWidth: strokeWidth && Math.max(1, strokeWidth / 2)
|
|
308
|
+
strokeWidth: strokeWidth && Math.max(1, strokeWidth / 2),
|
|
309
|
+
strokePathType: selectedPathType
|
|
303
310
|
}, selectedStyle || {}));
|
|
304
311
|
}
|
|
305
312
|
onPointerMove(e) {
|
|
@@ -1684,7 +1691,7 @@ class TransformTool {
|
|
|
1684
1691
|
const {target: target, mergeConfig: mergeConfig, single: single, dragStartData: dragStartData} = this.editBox;
|
|
1685
1692
|
let {around: around, lockRatio: lockRatio, flipable: flipable, editSize: editSize} = mergeConfig, totalMove;
|
|
1686
1693
|
if (e instanceof core.ZoomEvent) {
|
|
1687
|
-
around = target.getBoxPoint(e);
|
|
1694
|
+
if (!around) around = target.getBoxPoint(e);
|
|
1688
1695
|
totalMove = e.totalScale;
|
|
1689
1696
|
} else {
|
|
1690
1697
|
totalMove = e.getInnerTotal(target);
|
package/dist/editor.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Event, isArray, defineKey, isNull, isUndefined, isObject, MatrixHelper, BoundsHelper, LeafBoundsHelper, getMatrixData, getBoundsData, UI, isString, Paint, Group, Rect, Bounds, LeafList, Direction9, AroundHelper, MathHelper, PointHelper, isNumber, Box, DataHelper, ResizeEvent, getPointData, Text, Matrix, Debug, LeafHelper, PropertyEvent, Plugin, RenderEvent, LeaferEvent, Creator, dataType } from "@leafer-ui/draw";
|
|
1
|
+
import { Event, isArray, defineKey, isNull, isUndefined, isObject, MatrixHelper, BoundsHelper, LeafBoundsHelper, getMatrixData, getBoundsData, surfaceType, UI, isString, Paint, Group, Rect, Bounds, LeafList, Direction9, AroundHelper, MathHelper, PointHelper, isNumber, Box, DataHelper, ResizeEvent, getPointData, Text, Matrix, Debug, LeafHelper, PropertyEvent, Plugin, RenderEvent, LeaferEvent, Creator, dataType } from "@leafer-ui/draw";
|
|
2
2
|
|
|
3
3
|
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, DragBoundsHelper, KeyEvent, RotateEvent, useModule } from "@leafer-ui/core";
|
|
4
4
|
|
|
@@ -163,7 +163,11 @@ class Stroker extends UI {
|
|
|
163
163
|
matrix.half = strokeWidth % 2;
|
|
164
164
|
canvas.setWorld(matrix, options.matrix);
|
|
165
165
|
canvas.beginPath();
|
|
166
|
-
if (
|
|
166
|
+
if (this.strokePathType === "path") {
|
|
167
|
+
leaf.__drawPath(canvas);
|
|
168
|
+
} else {
|
|
169
|
+
if (leaf.__.__useArrow) leaf.__drawPath(canvas); else leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas);
|
|
170
|
+
}
|
|
167
171
|
data.strokeWidth = strokeWidth / Math.max(aScaleX, aScaleY);
|
|
168
172
|
if (stroke) isString(stroke) ? Paint.stroke(stroke, this, canvas, options) : Paint.strokes(stroke, this, canvas, options);
|
|
169
173
|
if (fill) isString(fill) ? Paint.fill(fill, this, canvas, options) : Paint.fills(fill, this, canvas, options);
|
|
@@ -180,6 +184,8 @@ class Stroker extends UI {
|
|
|
180
184
|
|
|
181
185
|
__decorate([ targetAttr(onTarget$1) ], Stroker.prototype, "target", void 0);
|
|
182
186
|
|
|
187
|
+
__decorate([ surfaceType("render-path") ], Stroker.prototype, "strokePathType", void 0);
|
|
188
|
+
|
|
183
189
|
function onTarget$1(stroker) {
|
|
184
190
|
const value = stroker.target;
|
|
185
191
|
stroker.list = value ? isArray(value) ? value : [ value ] : [];
|
|
@@ -294,10 +300,11 @@ class EditSelect extends Group {
|
|
|
294
300
|
}
|
|
295
301
|
update() {
|
|
296
302
|
this.hoverStroker.update();
|
|
297
|
-
const {stroke: stroke, strokeWidth: strokeWidth, selectedStyle: selectedStyle} = this.editor.mergedConfig;
|
|
303
|
+
const {stroke: stroke, strokeWidth: strokeWidth, selectedPathType: selectedPathType, selectedStyle: selectedStyle} = this.editor.mergedConfig;
|
|
298
304
|
this.targetStroker.update(Object.assign({
|
|
299
305
|
stroke: stroke,
|
|
300
|
-
strokeWidth: strokeWidth && Math.max(1, strokeWidth / 2)
|
|
306
|
+
strokeWidth: strokeWidth && Math.max(1, strokeWidth / 2),
|
|
307
|
+
strokePathType: selectedPathType
|
|
301
308
|
}, selectedStyle || {}));
|
|
302
309
|
}
|
|
303
310
|
onPointerMove(e) {
|
|
@@ -1682,7 +1689,7 @@ class TransformTool {
|
|
|
1682
1689
|
const {target: target, mergeConfig: mergeConfig, single: single, dragStartData: dragStartData} = this.editBox;
|
|
1683
1690
|
let {around: around, lockRatio: lockRatio, flipable: flipable, editSize: editSize} = mergeConfig, totalMove;
|
|
1684
1691
|
if (e instanceof ZoomEvent) {
|
|
1685
|
-
around = target.getBoxPoint(e);
|
|
1692
|
+
if (!around) around = target.getBoxPoint(e);
|
|
1686
1693
|
totalMove = e.totalScale;
|
|
1687
1694
|
} else {
|
|
1688
1695
|
totalMove = e.getInnerTotal(target);
|
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,isUndefined as o,isObject as n,MatrixHelper as r,BoundsHelper as a,LeafBoundsHelper as h,getMatrixData as l,getBoundsData as d,UI as c,isString as g,Paint as u,Group as f,Rect as p,Bounds as m,LeafList as E,Direction9 as v,AroundHelper as b,MathHelper as w,PointHelper as L,isNumber as y,Box as k,DataHelper as O,ResizeEvent as x,getPointData as T,Text as S,Matrix as _,Debug as B,LeafHelper as C,PropertyEvent as M,Plugin as R,RenderEvent as P,LeaferEvent as V,Creator as H,dataType as A}from"@leafer-ui/draw";import{PointerEvent as I,DragEvent as D,MoveEvent as z,ZoomEvent as F,DragBoundsHelper as Z,KeyEvent as W,RotateEvent as G,useModule as X}from"@leafer-ui/core";import"@leafer-in/resize";function Y(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 U(t){return t?e(t)?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class K extends t{get list(){return U(this.value)}get oldList(){return U(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}function N(t){return(s,o)=>{const r="_"+o;i(s,o,{get(){return this[r]},set(i){const s=this[r];if(s!==i){const a=this;if(a.config){const t="target"===o;if(t){const{beforeSelect:t}=a.config;if(t){const e=t({target:i});if(n(e))i=e;else if(!1===e)return}a.setDimOthers(!1),a.setBright(!1),e(i)&&i.length>1&&i[0].locked&&i.splice(0,1),a.single&&(delete a.element.syncEventer,delete a.element.__world.ignorePixelSnap)}const r=t?K.BEFORE_SELECT:K.BEFORE_HOVER;this.hasEvent(r)&&this.emitEvent(new K(r,{editor:a,value:i,oldValue:s}))}this[r]=i,t(this,s)}}})}}K.BEFORE_SELECT="editor.before_select",K.SELECT="editor.select",K.AFTER_SELECT="editor.after_select",K.BEFORE_HOVER="editor.before_hover",K.HOVER="editor.hover";const{abs:j}=Math,{copy:$}=r,{setListWithFn:q}=a,{worldBounds:J}=h,Q=l(),tt=d();class et extends c{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(tt,e,J),t&&this.set(t),this.set(tt),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:c}=s;if(c.width&&c.height&&(!h||h.hit(c,e.matrix))){const i=j(d.scaleX),h=j(d.scaleY);$(Q,d),Q.half=r%2,t.setWorld(Q,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),o.strokeWidth=r/Math.max(i,h),n&&(g(n)?u.stroke(n,this,t,e):u.strokes(n,this,t,e)),a&&(g(a)?u.fill(a,this,t,e):u.fills(a,this,t,e))}}o.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}Y([N(function(t){const i=t.target;t.list=i?e(i)?i:[i]:[]})],et.prototype,"target",void 0);class it extends f{constructor(t){super(t),this.strokeArea=new p({strokeAlign:"center"}),this.fillArea=new p,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 st={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return ot([t],i,e),i}};function ot(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&&ot(s.children,e,i)}}const{findOne:nt,findByBounds:rt}=st;class at extends f{get dragging(){return!!this.originList}get running(){const{editor:t,app:e}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector&&e&&"normal"===e.mode}get isMoveMode(){const{app:t}=this;return t&&t.interaction.moveMode}constructor(t){super(),this.hoverStroker=new et,this.targetStroker=new et,this.bounds=new m,this.selectArea=new it,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{hoverTarget:e,mergeConfig:i}=t,s=Object.assign({},i);e&&e.editConfig&&Object.assign(s,e.editConfig);const{stroke:o,strokeWidth:n,hover:r,hoverStyle:a}=s;this.hoverStroker.setTarget(r?e:null,Object.assign({stroke:o,strokeWidth:n},a||{}))}}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,selectKeep:s}=e.mergeConfig;"tap"===i?this.checkAndSelect(t):this.waitSelect&&this.waitSelect(),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(s||(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)||this.editor.mergedConfig.selectKeep||(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 E(rt(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)&&!nt(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new E(this.editor.editBox.rect)};return nt(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):nt(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_([[K.HOVER,this.onHover,this],[K.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],[z.MOVE,this.onAutoMove,this],[[F.ZOOM,z.MOVE],()=>{this.editor.hoverTarget=null}]])]})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:ht,top:lt,topRight:dt,right:ct,bottomRight:gt,bottom:ut,bottomLeft:ft,left:pt}=v,{toPoint:mt}=b,{within:Et,sign:vt}=w,{abs:bt}=Math,wt={getScaleData(t,e,i,s,o,n,r,a){let h,l,d={},c=1,g=1;const{boxBounds:u,widthRange:f,heightRange:p,dragBounds:m,worldBoxBounds:E}=t,{width:v,height:b}=e,w=t.scaleX/e.scaleX,L=t.scaleY/e.scaleY,k=vt(w),O=vt(L),x=a?w:k*u.width/v,T=a?L:O*u.height/b;if(y(s))c=g=Math.sqrt(s);else{n&&(s.x*=2,s.y*=2),s.x*=a?w:k,s.y*=a?L:O;const t=(-s.y+b)/b,e=(s.x+v)/v,r=(s.y+b)/b,d=(-s.x+v)/v;switch(i){case lt:g=t,h="bottom";break;case ct:c=e,h="left";break;case ut:g=r,h="top";break;case pt:c=d,h="right";break;case ht:g=t,c=d,h="bottom-right";break;case dt:g=t,c=e,h="bottom-left";break;case gt:g=r,c=e,h="top-left";break;case ft:g=r,c=d,h="top-right"}if(o)if("corner"===o&&i%2)o=!1;else switch(i){case lt:case ut:c=g;break;case pt:case ct:g=c;break;default:l=Math.sqrt(bt(c*g)),c=vt(c)*l,g=vt(g)*l}}const S=1!==c,_=1!==g;if(S&&(c/=x),_&&(g/=T),!r){const{worldTransform:e}=t;c<0&&(c=1/u.width/e.scaleX),g<0&&(g=1/u.height/e.scaleY)}if(mt(n||h,u,d,!0),m){const e={x:c,y:g};Z.limitScaleOf(t,d,e,o),c=e.x,g=e.y}if(S&&f){const e=u.width*t.scaleX;c=Et(e*c,f)/e}if(_&&p){const e=u.height*t.scaleY;g=Et(e*g,p)/e}return S&&bt(c*E.width)<1&&(c=vt(c)/E.width),_&&bt(g*E.height)<1&&(g=vt(g)/E.height),o&&c!==g&&(l=Math.min(bt(c),bt(g)),c=vt(c)*l,g=vt(g)*l),isFinite(c)||(c=1),isFinite(g)||(g=1),{origin:d,scaleX:c,scaleY:g,direction:i,lockRatio:o,around:n}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case ht:n="bottom-right";break;case dt:n="bottom-left";break;case gt:n="top-left";break;case ft:n="top-right";break;default:n="center"}return mt(o||n,t.boxBounds,r,!0),{origin:r,rotation:L.getRotation(s,t.getWorldPointByBox(r),i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,h=0;switch(e){case lt:case ht:n={x:.5,y:0},o="bottom",a=1;break;case ut:case gt:n={x:.5,y:1},o="top",a=1;break;case pt:case ft:n={x:0,y:.5},o="right",h=1;break;case ct:case dt: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,mt(s||o,t,r,!0);const c=L.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 pt:t=ct;break;case ht:t=dt;break;case ft:t=gt;break;case ct:t=pt;break;case dt:t=ht;break;case gt:t=ft}if(i)switch(t){case lt:t=ut;break;case ht:t=ft;break;case dt:t=gt;break;case ut:t=lt;break;case ft:t=ht;break;case gt:t=dt}return t}},Lt={};function yt(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("rect"===i.name)return kt(t);if("circle"===i.name)return;let{rotation:h}=t;const{pointType:l}=i,{moveCursor:d,resizeCursor:c,rotateCursor:g,skewCursor:u,moveable:f,resizeable:p,rotateable:m,skewable:E}=t.mergeConfig;if("move"===l)return i.cursor=d,void(f||(i.visible=!1));if("button"===l)return void(i.cursor||(i.cursor="pointer"));let v=l.includes("resize");v&&m&&(t.isHoldRotateKey(e)||!p)&&(v=!1);const b=E&&!v&&("resize-line"===i.name||"skew"===l),L=s?o?u:n?c:g:b?u:v?c:g;h+=45*(wt.getFlipDirection(i.direction,r,a)+1),h=2*Math.round(w.formatRotation(h,!0)/2);const{url:y,x:k,y:O}=L,x=y+h;Lt[x]?i.cursor=Lt[x]:Lt[x]=i.cursor={url:Ot(y,h),x:k,y:O}}function kt(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.canUse&&(t.rect.cursor=i?e:void 0)}function Ot(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class xt extends k{constructor(t){super(t),this.useFastShadow=!0}}const Tt=["top","right","bottom","left"],St=void 0;class _t extends f{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.app&&this.editor.editing}get canGesture(){if(!this.canUse)return!1;const{moveable:t,resizeable:e,rotateable:i}=this.mergeConfig;return g(t)||g(e)||g(i)}get canDragLimitAnimate(){return this.moving&&this.mergeConfig.dragLimitAnimate&&this.target.dragBounds}constructor(t){super(),this.view=new f,this.rect=new xt({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new xt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new f({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 xt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new xt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new xt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);this.listenPointEvents(h,"rotate",2),this.listenPointEvents(a,"move",8),s.addMany(...n,a,h,l,...r,...o),this.add(s)}load(){const{target:t,mergeConfig:e,single:i,rect:o,circle:n,resizePoints:r,resizeLines:a}=this,{stroke:h,strokeWidth:l,ignorePixelSnap:d}=e,c=this.getPointsStyle(),g=this.getMiddlePointsStyle(),u=this.getResizeLinesStyle();let f;this.visible=!t.locked;for(let t=0;t<8;t++)f=r[t],f.set(this.getPointStyle(t%2?g[(t-1)/2%g.length]:c[t/2%c.length])),f.rotation=(t-(t%2?1:0))/2*90,t%2&&a[(t-1)/2].set(Object.assign({pointType:"resize",rotation:(t-1)/2*90},u[(t-1)/2%u.length]||{}));n.set(this.getPointStyle(e.circle||e.rotatePoint||c[0])),o.set(Object.assign({stroke:h,strokeWidth:l,opacity:1,editConfig:St},e.rect||{}));const p=s(e.rectThrough)?i:e.rectThrough;o.hittable=!p,p&&(t.syncEventer=o,this.app.interaction.bottomList=[{target:o,proxy:t}]),i&&O.stintSet(t.__world,"ignorePixelSnap",d),kt(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{editor:e,mergeConfig:i,single:s,rect:o,circle:n,buttons:r,resizePoints:h,rotatePoints:l,resizeLines:d}=this,{editMask:c}=e,{middlePoint:g,resizeable:u,rotateable:f,hideOnSmall:p,editBox:m,mask:E,dimOthers:v,bright:w,spread:L,hideRotatePoints:k,hideResizeLines:O}=i;if(c.visible=!!E||0,e.setDimOthers(v),e.setBright(!!v||w),L&&a.spread(t,L),this.view.worldOpacity){const{width:e,height:a}=t,c=y(p)?p:10,E=m&&!(p&&e<c&&a<c);let v,w,L,x={};for(let i=0;i<8;i++)b.toPoint(b.directionData[i],t,x),w=h[i],v=l[i],w.set(x),v.set(x),w.visible=E&&!(!u&&!f),v.visible=E&&f&&u&&!k,i%2&&(L=d[(i-1)/2],L.set(x),L.visible=w.visible&&!O,w.visible=v.visible=E&&!!g,(i+1)/2%2?(L.width=e+L.height,p&&2*w.width>e&&(w.visible=!1)):(L.width=a+L.height,p&&2*w.width>a&&(w.visible=!1)));n.visible=E&&f&&!(!i.circle&&!i.rotatePoint),n.visible&&this.layoutCircle(),o.path&&(o.path=null),o.set(Object.assign(Object.assign({},t),{visible:!s||m})),r.visible=E&&r.children.length>0||0,r.visible&&this.layoutButtons()}else o.set(t)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,n=Tt.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=Tt.indexOf(e);(a%2&&n||(a+1)%2&&r)&&i&&(a=(a+2)%4);const h=i?wt.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",opacity:1,width:o,height:o,cornerRadius:n,offsetX:0,offsetY:0,editConfig:St};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()}getResizeLinesStyle(){const{resizeLine:t}=this.mergedConfig;return e(t)?t:[t]}onDragStart(t){this.dragging=!0;const e=this.dragPoint=t.current,{pointType:i}=e,{moveable:s,resizeable:o,rotateable:n,skewable:r}=this.mergeConfig;"move"===i?s&&(this.moving=!0):(i.includes("rotate")||this.isHoldRotateKey(t)||!o?(n&&(this.rotating=!0),"resize-rotate"===i?o&&(this.resizing=!0):"resize-line"===e.name&&(r&&(this.skewing=!0),this.rotating=!1)):"resize"===i&&o&&(this.resizing=!0),"skew"===i&&r&&(this.skewing=!0)),this.onTransformStart(t)}onDrag(t){const{transformTool:e,moving:i,resizing:s,rotating:o,skewing:n}=this;if(i)e.onMove(t);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)}yt(this,t)}onDragEnd(t){this.onTransformEnd(t),this.dragPoint=null}onTransformStart(t){(this.moving||this.gesturing)&&(this.editor.opacity=this.mergedConfig.hideOnMove?0:1),this.resizing&&(x.resizingKeys=this.editor.leafList.keys);const{dragStartData:e,target:i}=this;e.x=t.x,e.y=t.y,e.totalOffset=T(),e.point={x:i.x,y:i.y},e.bounds=Object.assign({},i.getLayoutBounds("box","local")),e.rotation=i.rotation}onTransformEnd(t){this.canDragLimitAnimate&&(t instanceof D||t instanceof z)&&this.transformTool.onMove(t),this.resizing&&(x.resizingKeys=null),this.dragging=this.gesturing=this.moving=this.resizing=this.rotating=this.skewing=!1,this.editor.opacity=1,this.editor.update()}onMove(t){if(this.canGesture&&"drag"!==t.moveType&&(t.stop(),g(this.mergedConfig.moveable)))switch(this.gesturing=this.moving=!0,t.type){case z.START:this.onTransformStart(t);break;case z.END:this.onTransformEnd(t);break;default:this.transformTool.onMove(t)}}onScale(t){if(this.canGesture&&(t.stop(),g(this.mergedConfig.resizeable)))switch(this.gesturing=this.resizing=!0,t.type){case F.START:this.onTransformStart(t);break;case F.END:this.onTransformEnd(t);break;default:this.transformTool.onScale(t)}}onRotate(t){if(this.canGesture&&(t.stop(),g(this.mergedConfig.rotateable)))switch(this.gesturing=this.rotating=!0,t.type){case F.START:this.onTransformStart(t);break;case F.END:this.onTransformEnd(t);break;default:this.transformTool.onRotate(t)}}isHoldRotateKey(t){const{rotateKey:e}=this.mergedConfig;return e?t.isHoldKeys(e):t.metaKey||t.ctrlKey}onKey(t){yt(this,t)}onArrow(t){if(this.canUse&&this.mergeConfig.keyEvent){let e=0,i=0;const s=t.shiftKey?10:1;switch(t.code){case"ArrowDown":i=s;break;case"ArrowUp":i=-s;break;case"ArrowLeft":e=-s;break;case"ArrowRight":e=s}(e||i)&&this.transformTool.move(e,i)}}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 S)||t.find(t=>t instanceof S);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,this.__eventIds.push(t.on_([[D.START,this.onDragStart,this],[D.DRAG,this.onDrag,this],[D.END,this.onDragEnd,this],[I.ENTER,e=>{this.enterPoint=t,yt(this,e)}],[I.LEAVE,()=>{this.enterPoint=null}]]))}__listenEvents(){const{rect:t,editor:e,__eventIds:i}=this;i.push(t.on_([[I.DOUBLE_TAP,this.onDoubleTap,this],[I.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer(()=>{i.push(e.app.on_([[[W.HOLD,W.UP],this.onKey,this],[W.DOWN,this.onArrow,this],[[z.START,z.BEFORE_MOVE,z.END],this.onMove,this,!0],[[F.START,F.BEFORE_ZOOM,F.END],this.onScale,this,!0],[[G.START,G.BEFORE_ROTATE,G.END],this.onRotate,this,!0]]))})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Bt={x:0,y:0,width:1e5,height:1e5};class Ct extends c{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,Bt),Object.assign(this.__world,Bt)}__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 Mt='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',Rt={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${Mt}\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${Mt}\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${Mt}\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},Pt=new m;function Vt(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange(()=>{Pt.setListWithFn(i,t=>t.getBounds("box","page")),0===Pt.width&&(Pt.width=.1),0===Pt.height&&(Pt.height=.1),e.reset(Pt.get())}),s.add(e)}const Ht=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),At=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),It={group(t,e,i){t.sort(At);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new f(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(Ht);const r=new _(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(Ht),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(At),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})}},Dt=B.get("EditToolCreator");function zt(){return t=>{Zt.register(t)}}const Ft=zt,Zt={list:{},register(t){const{tag:e}=t.prototype;Wt[e]&&Dt.repeat(e),Wt[e]=t},get:(t,e)=>new Wt[t](e)},{list:Wt}=Zt;class Gt extends K{constructor(t,e){super(t,e)}}Gt.BEFORE_OPEN="innerEditor.before_open",Gt.OPEN="innerEditor.open",Gt.BEFORE_CLOSE="innerEditor.before_close",Gt.CLOSE="innerEditor.close";class Xt extends K{constructor(t,e){super(t,e)}}Xt.BEFORE_GROUP="editor.before_group",Xt.GROUP="editor.group",Xt.BEFORE_UNGROUP="editor.before_ungroup",Xt.UNGROUP="editor.ungroup",Xt.BEFORE_OPEN="editor.before_open_group",Xt.OPEN="editor.open_group",Xt.BEFORE_CLOSE="editor.before_close_group",Xt.CLOSE="editor.close_group";const{updateMatrix:Yt}=C,Ut={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},Kt="top-left";class Nt extends p{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.on(M.CHANGE,e=>{if(this.checkChange&&Ut[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,Yt(this.parent),Yt(this);const a=new _(this.__world);switch(r[i]=s,this.__layout.rotationChange(),Yt(this),this.changedTransform=new _(this.__world).divide(a),i){case"x":t.move(n,0);break;case"y":t.move(0,n);break;case"rotation":t.rotateOf(Kt,n);break;case"scaleX":t.scaleOf(Kt,n,1);break;case"scaleY":t.scaleOf(Kt,1,n);break;case"skewX":t.skewOf(Kt,n,0);break;case"skewY":t.skewOf(Kt,0,n)}this.canChange=!0}})}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class jt extends K{constructor(t,e){super(t,e)}}jt.BEFORE_MOVE="editor.before_move",jt.MOVE="editor.move";class $t extends K{constructor(t,e){super(t,e)}}$t.BEFORE_SCALE="editor.before_scale",$t.SCALE="editor.scale";class qt extends K{constructor(t,e){super(t,e)}}qt.BEFORE_ROTATE="editor.before_rotate",qt.ROTATE="editor.rotate";class Jt extends K{constructor(t,e){super(t,e)}}Jt.BEFORE_SKEW="editor.before_skew",Jt.SKEW="editor.skew";class Qt{onMove(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox;let o,{dragLimitAnimate:n}=i;const r=t.type===z.END||t.type===D.END,a=g(e.draggable),h=!n||r||a,l={x:t.totalX,y:t.totalY};t instanceof z&&L.move(l,e.getWorldPointByLocal(s.totalOffset,null,!0)),t.shiftKey&&(Math.abs(l.x)>Math.abs(l.y)?l.y=0:l.x=0),o=D.getValidMove(e,s.point,l,h),(o.x||o.y)&&(n&&!a&&r?C.animateMove(this,o,y(n)?n:.3):this.move(o))}onScale(t){const{target:e,mergeConfig:i,single:s,dragStartData:o}=this.editBox;let n,{around:r,lockRatio:a,flipable:h,editSize:l}=i;t instanceof F?(r=e.getBoxPoint(t),n=t.totalScale):n=t.getInnerTotal(e);const{direction:d}=t.current;(t.shiftKey||e.lockRatio)&&(a=!0);const c=wt.getScaleData(e,o.bounds,d,n,a,wt.getAround(r,t.altKey),h,!s||"scale"===l),g=e.x,u=e.y;t instanceof D&&this.editTool&&this.editTool.onScaleWithDrag?(c.drag=t,this.scaleWithDrag(c)):this.scaleOf(c.origin,c.scaleX,c.scaleY),L.move(o.totalOffset,e.x-g,e.y-u)}onRotate(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox,{around:o,rotateAround:n,rotateGap:r,diagonalRotateKey:a}=i,{direction:h}=t.current;let l,d;if(t instanceof G)d=t.rotation,l=n?b.getPoint(n,e.boxBounds):e.getBoxPoint(t);else{const i=a?t.isHoldKeys(a):t.shiftKey,r=wt.getRotateData(e,h,t,s,i?null:n||e.around||e.origin||o||"center");d=s.rotation+r.rotation-e.rotation,l=r.origin}if(d=w.float(w.getGapRotation(d,r,e.rotation),2),!d)return;const c=e.x,g=e.y;this.rotateOf(l,d),L.move(s.totalOffset,e.x-c,e.y-g)}onSkew(t){const{target:e,mergeConfig:i}=this.editBox,{around:s}=i,{origin:o,skewX:n,skewY:r}=wt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),wt.getAround(s,t.altKey));(n||r)&&this.skewOf(o,n,r)}move(t,e=0){if(!this.checkTransform("moveable"))return;n(t)&&(e=t.y,t=t.x);const{target:i,mergeConfig:s,single:o,editor:r}=this.editBox,{beforeMove:a}=s;if(a){const s=a({target:i,x:t,y:e});if(n(s))t=s.x,e=s.y;else if(!1===s)return}const h=i.getWorldPointByLocal({x:t,y:e},null,!0);o||i.safeChange(()=>i.move(t,e));const l={target:i,editor:r,moveX:h.x,moveY:h.y};this.emitEvent(new jt(jt.BEFORE_MOVE,l));const d=new jt(jt.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 $t($t.BEFORE_SCALE,t));const n=new $t($t.SCALE,t);this.editTool.onScaleWithDrag(n),this.emitEvent(n)}scaleOf(t,e,i=e,s){if(!this.checkTransform("resizeable"))return;const{target:o,mergeConfig:r,single:a,editor:h}=this.editBox,{beforeScale:l}=r;if(l){const s=l({target:o,origin:t,scaleX:e,scaleY:i});if(n(s))e=s.scaleX,i=s.scaleY;else if(!1===s)return}const d=this.getWorldOrigin(t),c=!a&&this.getChangedTransform(()=>o.safeChange(()=>o.scaleOf(t,e,i))),g={target:o,editor:h,worldOrigin:d,scaleX:e,scaleY:i,transform:c};this.emitEvent(new $t($t.BEFORE_SCALE,g));const u=new $t($t.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 _(C.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 $t($t.BEFORE_SCALE,r));const a=new $t($t.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(y(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 qt(qt.BEFORE_ROTATE,l));const d=new qt(qt.ROTATE,l);this.doRotate(d),this.emitEvent(d)}skewOf(t,e,i=0,s){if(!this.checkTransform("skewable"))return;const{target:o,mergeConfig:r,single:a,editor:h}=this.editBox,{beforeSkew:l}=r;if(l){const s=l({target:o,origin:t,skewX:e,skewY:i});if(n(s))e=s.skewX,i=s.skewY;else if(!1===s)return}const d=this.getWorldOrigin(t),c=!a&&this.getChangedTransform(()=>o.safeChange(()=>o.skewOf(t,e,i))),g={target:o,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(C.getInnerOrigin(e,t))}getChangedTransform(t){const{target:e,single:i}=this.editBox;if(!i&&!e.canChange)return e.changedTransform;const s=new _(e.worldTransform);return t(),new _(e.worldTransform).divide(s)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}let te=class extends f{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 E,this.openedGroupList=new E,this.simulateTarget=new Nt(this),this.editBox=new _t(this),this.editToolList={},this.selector=new at(this),this.editMask=new Ct(this),this.targetEventIds=[];let i=O.clone(Rt);t&&(i=O.default(t,i)),this.mergedConfig=this.config=i,this.addMany(this.editMask,this.selector,this.editBox),R.has("resize")||(this.config.editSize="scale")}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}getItem(t){return this.list[t||0]}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)}setDimOthers(t,i="dim",s){if(!s){const{dimTarget:t,targetLeafer:i}=this;s=t?e(t)?t:[t]:[i]}s[0]&&s[0][i]!==(t||!1)&&s.forEach(e=>O.stintSet(e,i,t))}setBright(t){this.setDimOthers(t,"bright",this.list)}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&&Vt(this),this.update()}getEditTool(t){return this.editToolList[t]=this.editToolList[t]||Zt.get(t,this)}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(g(s))e=s;else if(!1===s)return}if(Zt.list[e]){const t=this.editTool=this.getEditTool(e);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(Xt.BEFORE_GROUP),this.target=It.group(this.list,this.element,t),this.emitGroupEvent(Xt.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach(t=>t.isBranch&&this.emitGroupEvent(Xt.BEFORE_UNGROUP,t)),this.target=It.ungroup(t),t.forEach(t=>t.isBranch&&this.emitGroupEvent(Xt.UNGROUP,t))),this.list}openGroup(t){this.emitGroupEvent(Xt.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Xt.OPEN,t)}closeGroup(t){this.emitGroupEvent(Xt.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Xt.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach(t=>this.list.every(e=>!C.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 Xt(t,{editTarget:e});this.emitEvent(i),e&&e.emitEvent(i)}getInnerEditor(t){return this.editToolList[t]=this.editToolList[t]||Zt.get(t,this)}openInnerEditor(t,e,i){let s;if(g(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(g(i))s=i;else if(!1===i)return}Zt.list[s]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.getInnerEditor(s),this.innerEditor.editTarget=t,this.emitInnerEvent(Gt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Gt.OPEN))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Gt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Gt.CLOSE),t||this.updateEditTool(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Gt(t,{editTarget:i,innerEditor:e});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&&(It.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(It.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_(P.START,this.onRenderStart,this),i&&i.on_(M.SCROLL,this.onChildScroll,this),t.on_(P.CHILD_START,this.onAppRenderStart,this),t.on_(V.UPDATE_MODE,t=>{t.mode&&"normal"!==t.mode&&this.cancel()})],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())}};Y([(t,e)=>{i(t,e,{get(){const{config:t,element:e,dragPoint:i,editBox:n,app:r}=this,a=Object.assign({},t);if(e&&e.editConfig){let{editConfig:t}=e;(t.hover||t.hoverStyle)&&(t=Object.assign({},t),delete t.hover,delete t.hoverStyle),Object.assign(a,t)}return n.config&&Object.assign(a,n.config),i&&(i.editConfig&&Object.assign(a,i.editConfig),"font-size"===a.editSize&&(a.lockRatio=!0),"resize-rotate"===i.pointType&&(a.around||(a.around="center"),s(a.lockRatio)&&(a.lockRatio=!0))),o(a.dragLimitAnimate)&&(a.dragLimitAnimate=r&&r.config.pointer.dragLimitAnimate),this.mergedConfig=a}})}],te.prototype,"mergeConfig",void 0),Y([N(function(t,e){const{target:i}=t;i?(t.leafList=i instanceof E?i:new E(i),t.multiple&&Vt(t)):(t.simulateTarget.remove(),t.leafList.reset()),t.closeInnerEditor(!0),t.unloadEditTool();const s={editor:t,value:i,oldValue:e};t.emitEvent(new K(K.SELECT,s)),t.checkOpenedGroups(),t.editing?t.waitLeafer(()=>{t.updateEditTool(),t.listenTargetEvents()}):(t.updateEditTool(),t.removeTargetEvents()),t.emitEvent(new K(K.AFTER_SELECT,s))})],te.prototype,"target",void 0),Y([N(function(t,e){t.emitEvent(new K(K.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))})],te.prototype,"hoverTarget",void 0),te=Y([X(Qt,["editBox","editTool","emitEvent"])],te);class ee{static registerInnerEditor(){Zt.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 f,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 ie=class extends ee{static registerEditTool(){Zt.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()}};ie=Y([zt()],ie);const{left:se,right:oe}=v,{move:ne,copy:re,toNumberPoints:ae}=L;let he=class extends ie{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===se;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=T(),{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=ae(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?(ne(t,n,r),s&&ne(e,-n,-r)):(s&&ne(t,-n,-r),ne(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),re(s[7],i),re(e[7],i),re(s[3],a),re(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===se||t===oe,s[t].visible=a,e[t].visible=!r&&a}};he=Y([zt()],he),R.add("editor","resize"),H.editor=function(t,e){const i=new te(t);return e&&e.sky.add(e.editor=i),i},k.addAttr("textBox",!1,A),c.addAttr("editConfig",void 0,A),c.addAttr("editOuter",t=>(t.updateLayout(),t.__.__isLinePath?"LineEditTool":"EditTool"),A),c.addAttr("editInner","PathEditor",A),f.addAttr("editInner","",A),S.addAttr("editInner","TextEditor",A),c.setEditConfig=function(t){this.changeAttr("editConfig",t)},c.setEditOuter=function(t){this.changeAttr("editOuter",t)},c.setEditInner=function(t){this.changeAttr("editInner",t)};export{_t as EditBox,wt as EditDataHelper,xt as EditPoint,at as EditSelect,st as EditSelectHelper,ie as EditTool,Zt as EditToolCreator,te as Editor,K as EditorEvent,Xt as EditorGroupEvent,It as EditorHelper,jt as EditorMoveEvent,qt as EditorRotateEvent,$t as EditorScaleEvent,Jt as EditorSkewEvent,ee as InnerEditor,Gt as InnerEditorEvent,he as LineEditTool,it as SelectArea,et as Stroker,Qt as TransformTool,zt as registerEditTool,Ft as registerInnerEditor};
|
|
1
|
+
import{Event as t,isArray as e,defineKey as i,isNull as s,isUndefined as o,isObject as n,MatrixHelper as r,BoundsHelper as a,LeafBoundsHelper as h,getMatrixData as l,getBoundsData as d,surfaceType as c,UI as g,isString as u,Paint as f,Group as p,Rect as m,Bounds as E,LeafList as v,Direction9 as b,AroundHelper as w,MathHelper as y,PointHelper as L,isNumber as k,Box as O,DataHelper as T,ResizeEvent as x,getPointData as S,Text as _,Matrix as B,Debug as C,LeafHelper as M,PropertyEvent as R,Plugin as P,RenderEvent as V,LeaferEvent as H,Creator as A,dataType as I}from"@leafer-ui/draw";import{PointerEvent as D,DragEvent as z,MoveEvent as F,ZoomEvent as Z,DragBoundsHelper as W,KeyEvent as G,RotateEvent as X,useModule as Y}from"@leafer-ui/core";import"@leafer-in/resize";function U(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 K(t){return t?e(t)?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class N extends t{get list(){return K(this.value)}get oldList(){return K(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}function j(t){return(s,o)=>{const r="_"+o;i(s,o,{get(){return this[r]},set(i){const s=this[r];if(s!==i){const a=this;if(a.config){const t="target"===o;if(t){const{beforeSelect:t}=a.config;if(t){const e=t({target:i});if(n(e))i=e;else if(!1===e)return}a.setDimOthers(!1),a.setBright(!1),e(i)&&i.length>1&&i[0].locked&&i.splice(0,1),a.single&&(delete a.element.syncEventer,delete a.element.__world.ignorePixelSnap)}const r=t?N.BEFORE_SELECT:N.BEFORE_HOVER;this.hasEvent(r)&&this.emitEvent(new N(r,{editor:a,value:i,oldValue:s}))}this[r]=i,t(this,s)}}})}}N.BEFORE_SELECT="editor.before_select",N.SELECT="editor.select",N.AFTER_SELECT="editor.after_select",N.BEFORE_HOVER="editor.before_hover",N.HOVER="editor.hover";const{abs:$}=Math,{copy:q}=r,{setListWithFn:J}=a,{worldBounds:Q}=h,tt=l(),et=d();class it extends g{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?(J(et,e,Q),t&&this.set(t),this.set(et),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:c}=s;if(c.width&&c.height&&(!h||h.hit(c,e.matrix))){const i=$(d.scaleX),h=$(d.scaleY);q(tt,d),tt.half=r%2,t.setWorld(tt,e.matrix),t.beginPath(),"path"===this.strokePathType||s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),o.strokeWidth=r/Math.max(i,h),n&&(u(n)?f.stroke(n,this,t,e):f.strokes(n,this,t,e)),a&&(u(a)?f.fill(a,this,t,e):f.fills(a,this,t,e))}}o.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}U([j(function(t){const i=t.target;t.list=i?e(i)?i:[i]:[]})],it.prototype,"target",void 0),U([c("render-path")],it.prototype,"strokePathType",void 0);class st extends p{constructor(t){super(t),this.strokeArea=new m({strokeAlign:"center"}),this.fillArea=new m,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 ot={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return nt([t],i,e),i}};function nt(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&&nt(s.children,e,i)}}const{findOne:rt,findByBounds:at}=ot;class ht extends p{get dragging(){return!!this.originList}get running(){const{editor:t,app:e}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector&&e&&"normal"===e.mode}get isMoveMode(){const{app:t}=this;return t&&t.interaction.moveMode}constructor(t){super(),this.hoverStroker=new it,this.targetStroker=new it,this.bounds=new E,this.selectArea=new st,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{hoverTarget:e,mergeConfig:i}=t,s=Object.assign({},i);e&&e.editConfig&&Object.assign(s,e.editConfig);const{stroke:o,strokeWidth:n,hover:r,hoverStyle:a}=s;this.hoverStroker.setTarget(r?e:null,Object.assign({stroke:o,strokeWidth:n},a||{}))}}onSelect(){this.running&&(this.targetStroker.setTarget(this.editor.list),this.hoverStroker.target=null)}update(){this.hoverStroker.update();const{stroke:t,strokeWidth:e,selectedPathType:i,selectedStyle:s}=this.editor.mergedConfig;this.targetStroker.update(Object.assign({stroke:t,strokeWidth:e&&Math.max(1,e/2),strokePathType:i},s||{}))}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,selectKeep:s}=e.mergeConfig;"tap"===i?this.checkAndSelect(t):this.waitSelect&&this.waitSelect(),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(s||(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)||this.editor.mergedConfig.selectKeep||(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 v(at(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)&&!rt(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new v(this.editor.editBox.rect)};return rt(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):rt(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_([[N.HOVER,this.onHover,this],[N.SELECT,this.onSelect,this]]),e.on_([[D.MOVE,this.onPointerMove,this],[D.BEFORE_DOWN,this.onBeforeDown,this],[D.TAP,this.onTap,this],[z.START,this.onDragStart,this,!0],[z.DRAG,this.onDrag,this],[z.END,this.onDragEnd,this],[F.MOVE,this.onAutoMove,this],[[Z.ZOOM,F.MOVE],()=>{this.editor.hoverTarget=null}]])]})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:lt,top:dt,topRight:ct,right:gt,bottomRight:ut,bottom:ft,bottomLeft:pt,left:mt}=b,{toPoint:Et}=w,{within:vt,sign:bt}=y,{abs:wt}=Math,yt={getScaleData(t,e,i,s,o,n,r,a){let h,l,d={},c=1,g=1;const{boxBounds:u,widthRange:f,heightRange:p,dragBounds:m,worldBoxBounds:E}=t,{width:v,height:b}=e,w=t.scaleX/e.scaleX,y=t.scaleY/e.scaleY,L=bt(w),O=bt(y),T=a?w:L*u.width/v,x=a?y:O*u.height/b;if(k(s))c=g=Math.sqrt(s);else{n&&(s.x*=2,s.y*=2),s.x*=a?w:L,s.y*=a?y:O;const t=(-s.y+b)/b,e=(s.x+v)/v,r=(s.y+b)/b,d=(-s.x+v)/v;switch(i){case dt:g=t,h="bottom";break;case gt:c=e,h="left";break;case ft:g=r,h="top";break;case mt:c=d,h="right";break;case lt:g=t,c=d,h="bottom-right";break;case ct:g=t,c=e,h="bottom-left";break;case ut:g=r,c=e,h="top-left";break;case pt:g=r,c=d,h="top-right"}if(o)if("corner"===o&&i%2)o=!1;else switch(i){case dt:case ft:c=g;break;case mt:case gt:g=c;break;default:l=Math.sqrt(wt(c*g)),c=bt(c)*l,g=bt(g)*l}}const S=1!==c,_=1!==g;if(S&&(c/=T),_&&(g/=x),!r){const{worldTransform:e}=t;c<0&&(c=1/u.width/e.scaleX),g<0&&(g=1/u.height/e.scaleY)}if(Et(n||h,u,d,!0),m){const e={x:c,y:g};W.limitScaleOf(t,d,e,o),c=e.x,g=e.y}if(S&&f){const e=u.width*t.scaleX;c=vt(e*c,f)/e}if(_&&p){const e=u.height*t.scaleY;g=vt(e*g,p)/e}return S&&wt(c*E.width)<1&&(c=bt(c)/E.width),_&&wt(g*E.height)<1&&(g=bt(g)/E.height),o&&c!==g&&(l=Math.min(wt(c),wt(g)),c=bt(c)*l,g=bt(g)*l),isFinite(c)||(c=1),isFinite(g)||(g=1),{origin:d,scaleX:c,scaleY:g,direction:i,lockRatio:o,around:n}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case lt:n="bottom-right";break;case ct:n="bottom-left";break;case ut:n="top-left";break;case pt:n="top-right";break;default:n="center"}return Et(o||n,t.boxBounds,r,!0),{origin:r,rotation:L.getRotation(s,t.getWorldPointByBox(r),i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,h=0;switch(e){case dt:case lt:n={x:.5,y:0},o="bottom",a=1;break;case ft:case ut:n={x:.5,y:1},o="top",a=1;break;case mt:case pt:n={x:0,y:.5},o="right",h=1;break;case gt:case ct: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,Et(s||o,t,r,!0);const c=L.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 mt:t=gt;break;case lt:t=ct;break;case pt:t=ut;break;case gt:t=mt;break;case ct:t=lt;break;case ut:t=pt}if(i)switch(t){case dt:t=ft;break;case lt:t=pt;break;case ct:t=ut;break;case ft:t=dt;break;case pt:t=lt;break;case ut:t=ct}return t}},Lt={};function kt(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("rect"===i.name)return Ot(t);if("circle"===i.name)return;let{rotation:h}=t;const{pointType:l}=i,{moveCursor:d,resizeCursor:c,rotateCursor:g,skewCursor:u,moveable:f,resizeable:p,rotateable:m,skewable:E}=t.mergeConfig;if("move"===l)return i.cursor=d,void(f||(i.visible=!1));if("button"===l)return void(i.cursor||(i.cursor="pointer"));let v=l.includes("resize");v&&m&&(t.isHoldRotateKey(e)||!p)&&(v=!1);const b=E&&!v&&("resize-line"===i.name||"skew"===l),w=s?o?u:n?c:g:b?u:v?c:g;h+=45*(yt.getFlipDirection(i.direction,r,a)+1),h=2*Math.round(y.formatRotation(h,!0)/2);const{url:L,x:k,y:O}=w,T=L+h;Lt[T]?i.cursor=Lt[T]:Lt[T]=i.cursor={url:Tt(L,h),x:k,y:O}}function Ot(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.canUse&&(t.rect.cursor=i?e:void 0)}function Tt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class xt extends O{constructor(t){super(t),this.useFastShadow=!0}}const St=["top","right","bottom","left"],_t=void 0;class Bt extends p{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.app&&this.editor.editing}get canGesture(){if(!this.canUse)return!1;const{moveable:t,resizeable:e,rotateable:i}=this.mergeConfig;return u(t)||u(e)||u(i)}get canDragLimitAnimate(){return this.moving&&this.mergeConfig.dragLimitAnimate&&this.target.dragBounds}constructor(t){super(),this.view=new p,this.rect=new xt({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new xt({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new p({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 xt({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new xt({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new xt({name:"resize-point",hitRadius:5}),o.push(i),this.listenPointEvents(i,"resize",s);this.listenPointEvents(h,"rotate",2),this.listenPointEvents(a,"move",8),s.addMany(...n,a,h,l,...r,...o),this.add(s)}load(){const{target:t,mergeConfig:e,single:i,rect:o,circle:n,resizePoints:r,resizeLines:a}=this,{stroke:h,strokeWidth:l,ignorePixelSnap:d}=e,c=this.getPointsStyle(),g=this.getMiddlePointsStyle(),u=this.getResizeLinesStyle();let f;this.visible=!t.locked;for(let t=0;t<8;t++)f=r[t],f.set(this.getPointStyle(t%2?g[(t-1)/2%g.length]:c[t/2%c.length])),f.rotation=(t-(t%2?1:0))/2*90,t%2&&a[(t-1)/2].set(Object.assign({pointType:"resize",rotation:(t-1)/2*90},u[(t-1)/2%u.length]||{}));n.set(this.getPointStyle(e.circle||e.rotatePoint||c[0])),o.set(Object.assign({stroke:h,strokeWidth:l,opacity:1,editConfig:_t},e.rect||{}));const p=s(e.rectThrough)?i:e.rectThrough;o.hittable=!p,p&&(t.syncEventer=o,this.app.interaction.bottomList=[{target:o,proxy:t}]),i&&T.stintSet(t.__world,"ignorePixelSnap",d),Ot(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{editor:e,mergeConfig:i,single:s,rect:o,circle:n,buttons:r,resizePoints:h,rotatePoints:l,resizeLines:d}=this,{editMask:c}=e,{middlePoint:g,resizeable:u,rotateable:f,hideOnSmall:p,editBox:m,mask:E,dimOthers:v,bright:b,spread:y,hideRotatePoints:L,hideResizeLines:O}=i;if(c.visible=!!E||0,e.setDimOthers(v),e.setBright(!!v||b),y&&a.spread(t,y),this.view.worldOpacity){const{width:e,height:a}=t,c=k(p)?p:10,E=m&&!(p&&e<c&&a<c);let v,b,y,T={};for(let i=0;i<8;i++)w.toPoint(w.directionData[i],t,T),b=h[i],v=l[i],b.set(T),v.set(T),b.visible=E&&!(!u&&!f),v.visible=E&&f&&u&&!L,i%2&&(y=d[(i-1)/2],y.set(T),y.visible=b.visible&&!O,b.visible=v.visible=E&&!!g,(i+1)/2%2?(y.width=e+y.height,p&&2*b.width>e&&(b.visible=!1)):(y.width=a+y.height,p&&2*b.width>a&&(b.visible=!1)));n.visible=E&&f&&!(!i.circle&&!i.rotatePoint),n.visible&&this.layoutCircle(),o.path&&(o.path=null),o.set(Object.assign(Object.assign({},t),{visible:!s||m})),r.visible=E&&r.children.length>0||0,r.visible&&this.layoutButtons()}else o.set(t)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,n=St.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=St.indexOf(e);(a%2&&n||(a+1)%2&&r)&&i&&(a=(a+2)%4);const h=i?yt.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",opacity:1,width:o,height:o,cornerRadius:n,offsetX:0,offsetY:0,editConfig:_t};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()}getResizeLinesStyle(){const{resizeLine:t}=this.mergedConfig;return e(t)?t:[t]}onDragStart(t){this.dragging=!0;const e=this.dragPoint=t.current,{pointType:i}=e,{moveable:s,resizeable:o,rotateable:n,skewable:r}=this.mergeConfig;"move"===i?s&&(this.moving=!0):(i.includes("rotate")||this.isHoldRotateKey(t)||!o?(n&&(this.rotating=!0),"resize-rotate"===i?o&&(this.resizing=!0):"resize-line"===e.name&&(r&&(this.skewing=!0),this.rotating=!1)):"resize"===i&&o&&(this.resizing=!0),"skew"===i&&r&&(this.skewing=!0)),this.onTransformStart(t)}onDrag(t){const{transformTool:e,moving:i,resizing:s,rotating:o,skewing:n}=this;if(i)e.onMove(t);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)}kt(this,t)}onDragEnd(t){this.onTransformEnd(t),this.dragPoint=null}onTransformStart(t){(this.moving||this.gesturing)&&(this.editor.opacity=this.mergedConfig.hideOnMove?0:1),this.resizing&&(x.resizingKeys=this.editor.leafList.keys);const{dragStartData:e,target:i}=this;e.x=t.x,e.y=t.y,e.totalOffset=S(),e.point={x:i.x,y:i.y},e.bounds=Object.assign({},i.getLayoutBounds("box","local")),e.rotation=i.rotation}onTransformEnd(t){this.canDragLimitAnimate&&(t instanceof z||t instanceof F)&&this.transformTool.onMove(t),this.resizing&&(x.resizingKeys=null),this.dragging=this.gesturing=this.moving=this.resizing=this.rotating=this.skewing=!1,this.editor.opacity=1,this.editor.update()}onMove(t){if(this.canGesture&&"drag"!==t.moveType&&(t.stop(),u(this.mergedConfig.moveable)))switch(this.gesturing=this.moving=!0,t.type){case F.START:this.onTransformStart(t);break;case F.END:this.onTransformEnd(t);break;default:this.transformTool.onMove(t)}}onScale(t){if(this.canGesture&&(t.stop(),u(this.mergedConfig.resizeable)))switch(this.gesturing=this.resizing=!0,t.type){case Z.START:this.onTransformStart(t);break;case Z.END:this.onTransformEnd(t);break;default:this.transformTool.onScale(t)}}onRotate(t){if(this.canGesture&&(t.stop(),u(this.mergedConfig.rotateable)))switch(this.gesturing=this.rotating=!0,t.type){case Z.START:this.onTransformStart(t);break;case Z.END:this.onTransformEnd(t);break;default:this.transformTool.onRotate(t)}}isHoldRotateKey(t){const{rotateKey:e}=this.mergedConfig;return e?t.isHoldKeys(e):t.metaKey||t.ctrlKey}onKey(t){kt(this,t)}onArrow(t){if(this.canUse&&this.mergeConfig.keyEvent){let e=0,i=0;const s=t.shiftKey?10:1;switch(t.code){case"ArrowDown":i=s;break;case"ArrowUp":i=-s;break;case"ArrowLeft":e=-s;break;case"ArrowRight":e=s}(e||i)&&this.transformTool.move(e,i)}}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 _)||t.find(t=>t instanceof _);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,this.__eventIds.push(t.on_([[z.START,this.onDragStart,this],[z.DRAG,this.onDrag,this],[z.END,this.onDragEnd,this],[D.ENTER,e=>{this.enterPoint=t,kt(this,e)}],[D.LEAVE,()=>{this.enterPoint=null}]]))}__listenEvents(){const{rect:t,editor:e,__eventIds:i}=this;i.push(t.on_([[D.DOUBLE_TAP,this.onDoubleTap,this],[D.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer(()=>{i.push(e.app.on_([[[G.HOLD,G.UP],this.onKey,this],[G.DOWN,this.onArrow,this],[[F.START,F.BEFORE_MOVE,F.END],this.onMove,this,!0],[[Z.START,Z.BEFORE_ZOOM,Z.END],this.onScale,this,!0],[[X.START,X.BEFORE_ROTATE,X.END],this.onRotate,this,!0]]))})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Ct={x:0,y:0,width:1e5,height:1e5};class Mt extends g{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,Ct),Object.assign(this.__world,Ct)}__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 Rt='\n<feOffset dy="1"/>\n<feGaussianBlur stdDeviation="1.5"/>\n<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2 0"/>\n<feBlend mode="normal" in="SourceGraphic" result="shape"/>',Pt={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${Rt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},rotateCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(135,12,12),rotate({{rotation}},12,12)">\n<path d="M20.4 8H21.4L20.8 7.1L17.3 2.6L17 2.1L16.6 2.6L13.1 7.1L12.5 8H13.5H15.4C14.9 11.8 11.8 14.9 8 15.4V13.5V12.5L7.1 13.1L2.6 16.6L2.1 17L2.6 17.3L7.1 20.8L8 21.4V20.4V18.4C13.5 17.9 17.9 13.5 18.4 8H20.4Z" stroke="white"/>\n<path fill-rule="evenodd" d="M17 3L20.4 7.5H17.9C17.7 13.1 13.1 17.7 7.5 17.9V20.4L3 17L7.5 13.5V15.9C12.0 15.7 15.7 12.0 15.9 7.5H13.5L17 3Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="-0.6" width="27.1" height="27.1" filterUnits="userSpaceOnUse">\n${Rt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},skewCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate(90,12,12),rotate({{rotation}},12,12)">\n<path d="M21 10.4L21 11.4L23.8 11.4L21.6 9.6L21 10.4ZM17 10.4V11.4L17 11.4L17 10.4ZM15.5 6L16.1 5.2L14.5 3.9V6H15.5ZM15.5 8.4V9.4H16.5V8.4H15.5ZM6 8.4V7.4H5V8.4H6ZM6 10.4H5V11.4H6V10.4ZM7 14.4V13.4L7 13.4L7 14.4ZM3 14.4L3 13.4L0.1 13.4L2.3 15.2L3 14.4ZM8.5 18.9L7.8 19.7L9.5 21.0V18.9H8.5ZM8.5 16.4V15.4H7.5V16.4H8.5ZM19 16.4V17.4H20V16.4H19ZM19 14.4H20V13.4H19V14.4ZM21 9.4L17 9.4L17 11.4L21 11.4L21 9.4ZM14.8 6.7L20.3 11.2L21.6 9.6L16.1 5.2L14.8 6.7ZM16.5 8.4V6H14.5V8.4H16.5ZM6 9.4H15.5V7.4H6V9.4ZM7 10.4V8.4H5V10.4H7ZM15.5 9.4H6V11.4H15.5V9.4ZM17 9.4H15.5V11.4H17V9.4ZM7 15.4H8.5V13.4H7V15.4ZM3 15.4L7 15.4L7 13.4L3 13.4L3 15.4ZM9.1 18.1L3.6 13.6L2.3 15.2L7.8 19.7L9.1 18.1ZM7.5 16.4V18.9H9.5V16.4H7.5ZM19 15.4H8.5V17.4H19V15.4ZM18 14.4V16.4H20V14.4H18ZM8.5 15.4H19V13.4H8.5V15.4Z" fill="white"/>\n<path fill-rule="evenodd" d="M17 10.4L21 10.4L15.5 6V8.4H6V10.4H15.5H17ZM8.5 14.4H7L3 14.4L8.5 18.9V16.4H19V14.4H8.5Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter x="-2.8" y="1.9" width="29.6" height="23.1" filterUnits="userSpaceOnUse" >\n${Rt}\n</filter>\n</defs>\n</svg>\n`,x:12,y:12},selector:!0,editBox:!0,hover:!0,select:"press",openInner:"double",multipleSelect:!0,boxSelect:!0,moveable:!0,resizeable:!0,flipable:!0,rotateable:!0,skewable:!0},Vt=new E;function Ht(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange(()=>{Vt.setListWithFn(i,t=>t.getBounds("box","page")),0===Vt.width&&(Vt.width=.1),0===Vt.height&&(Vt.height=.1),e.reset(Vt.get())}),s.add(e)}const At=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),It=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Dt={group(t,e,i){t.sort(It);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new p(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(At);const r=new B(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(At),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(It),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})}},zt=C.get("EditToolCreator");function Ft(){return t=>{Wt.register(t)}}const Zt=Ft,Wt={list:{},register(t){const{tag:e}=t.prototype;Gt[e]&&zt.repeat(e),Gt[e]=t},get:(t,e)=>new Gt[t](e)},{list:Gt}=Wt;class Xt extends N{constructor(t,e){super(t,e)}}Xt.BEFORE_OPEN="innerEditor.before_open",Xt.OPEN="innerEditor.open",Xt.BEFORE_CLOSE="innerEditor.before_close",Xt.CLOSE="innerEditor.close";class Yt extends N{constructor(t,e){super(t,e)}}Yt.BEFORE_GROUP="editor.before_group",Yt.GROUP="editor.group",Yt.BEFORE_UNGROUP="editor.before_ungroup",Yt.UNGROUP="editor.ungroup",Yt.BEFORE_OPEN="editor.before_open_group",Yt.OPEN="editor.open_group",Yt.BEFORE_CLOSE="editor.before_close_group",Yt.CLOSE="editor.close_group";const{updateMatrix:Ut}=M,Kt={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},Nt="top-left";class jt extends m{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.on(R.CHANGE,e=>{if(this.checkChange&&Kt[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,Ut(this.parent),Ut(this);const a=new B(this.__world);switch(r[i]=s,this.__layout.rotationChange(),Ut(this),this.changedTransform=new B(this.__world).divide(a),i){case"x":t.move(n,0);break;case"y":t.move(0,n);break;case"rotation":t.rotateOf(Nt,n);break;case"scaleX":t.scaleOf(Nt,n,1);break;case"scaleY":t.scaleOf(Nt,1,n);break;case"skewX":t.skewOf(Nt,n,0);break;case"skewY":t.skewOf(Nt,0,n)}this.canChange=!0}})}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class $t extends N{constructor(t,e){super(t,e)}}$t.BEFORE_MOVE="editor.before_move",$t.MOVE="editor.move";class qt extends N{constructor(t,e){super(t,e)}}qt.BEFORE_SCALE="editor.before_scale",qt.SCALE="editor.scale";class Jt extends N{constructor(t,e){super(t,e)}}Jt.BEFORE_ROTATE="editor.before_rotate",Jt.ROTATE="editor.rotate";class Qt extends N{constructor(t,e){super(t,e)}}Qt.BEFORE_SKEW="editor.before_skew",Qt.SKEW="editor.skew";class te{onMove(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox;let o,{dragLimitAnimate:n}=i;const r=t.type===F.END||t.type===z.END,a=u(e.draggable),h=!n||r||a,l={x:t.totalX,y:t.totalY};t instanceof F&&L.move(l,e.getWorldPointByLocal(s.totalOffset,null,!0)),t.shiftKey&&(Math.abs(l.x)>Math.abs(l.y)?l.y=0:l.x=0),o=z.getValidMove(e,s.point,l,h),(o.x||o.y)&&(n&&!a&&r?M.animateMove(this,o,k(n)?n:.3):this.move(o))}onScale(t){const{target:e,mergeConfig:i,single:s,dragStartData:o}=this.editBox;let n,{around:r,lockRatio:a,flipable:h,editSize:l}=i;t instanceof Z?(r||(r=e.getBoxPoint(t)),n=t.totalScale):n=t.getInnerTotal(e);const{direction:d}=t.current;(t.shiftKey||e.lockRatio)&&(a=!0);const c=yt.getScaleData(e,o.bounds,d,n,a,yt.getAround(r,t.altKey),h,!s||"scale"===l),g=e.x,u=e.y;t instanceof z&&this.editTool&&this.editTool.onScaleWithDrag?(c.drag=t,this.scaleWithDrag(c)):this.scaleOf(c.origin,c.scaleX,c.scaleY),L.move(o.totalOffset,e.x-g,e.y-u)}onRotate(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox,{around:o,rotateAround:n,rotateGap:r,diagonalRotateKey:a}=i,{direction:h}=t.current;let l,d;if(t instanceof X)d=t.rotation,l=n?w.getPoint(n,e.boxBounds):e.getBoxPoint(t);else{const i=a?t.isHoldKeys(a):t.shiftKey,r=yt.getRotateData(e,h,t,s,i?null:n||e.around||e.origin||o||"center");d=s.rotation+r.rotation-e.rotation,l=r.origin}if(d=y.float(y.getGapRotation(d,r,e.rotation),2),!d)return;const c=e.x,g=e.y;this.rotateOf(l,d),L.move(s.totalOffset,e.x-c,e.y-g)}onSkew(t){const{target:e,mergeConfig:i}=this.editBox,{around:s}=i,{origin:o,skewX:n,skewY:r}=yt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),yt.getAround(s,t.altKey));(n||r)&&this.skewOf(o,n,r)}move(t,e=0){if(!this.checkTransform("moveable"))return;n(t)&&(e=t.y,t=t.x);const{target:i,mergeConfig:s,single:o,editor:r}=this.editBox,{beforeMove:a}=s;if(a){const s=a({target:i,x:t,y:e});if(n(s))t=s.x,e=s.y;else if(!1===s)return}const h=i.getWorldPointByLocal({x:t,y:e},null,!0);o||i.safeChange(()=>i.move(t,e));const l={target:i,editor:r,moveX:h.x,moveY:h.y};this.emitEvent(new $t($t.BEFORE_MOVE,l));const d=new $t($t.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 qt(qt.BEFORE_SCALE,t));const n=new qt(qt.SCALE,t);this.editTool.onScaleWithDrag(n),this.emitEvent(n)}scaleOf(t,e,i=e,s){if(!this.checkTransform("resizeable"))return;const{target:o,mergeConfig:r,single:a,editor:h}=this.editBox,{beforeScale:l}=r;if(l){const s=l({target:o,origin:t,scaleX:e,scaleY:i});if(n(s))e=s.scaleX,i=s.scaleY;else if(!1===s)return}const d=this.getWorldOrigin(t),c=!a&&this.getChangedTransform(()=>o.safeChange(()=>o.scaleOf(t,e,i))),g={target:o,editor:h,worldOrigin:d,scaleX:e,scaleY:i,transform:c};this.emitEvent(new qt(qt.BEFORE_SCALE,g));const u=new qt(qt.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 B(M.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 qt(qt.BEFORE_SCALE,r));const a=new qt(qt.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(k(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 Jt(Jt.BEFORE_ROTATE,l));const d=new Jt(Jt.ROTATE,l);this.doRotate(d),this.emitEvent(d)}skewOf(t,e,i=0,s){if(!this.checkTransform("skewable"))return;const{target:o,mergeConfig:r,single:a,editor:h}=this.editBox,{beforeSkew:l}=r;if(l){const s=l({target:o,origin:t,skewX:e,skewY:i});if(n(s))e=s.skewX,i=s.skewY;else if(!1===s)return}const d=this.getWorldOrigin(t),c=!a&&this.getChangedTransform(()=>o.safeChange(()=>o.skewOf(t,e,i))),g={target:o,editor:h,worldOrigin:d,skewX:e,skewY:i,transform:c};this.emitEvent(new Qt(Qt.BEFORE_SKEW,g));const u=new Qt(Qt.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(M.getInnerOrigin(e,t))}getChangedTransform(t){const{target:e,single:i}=this.editBox;if(!i&&!e.canChange)return e.changedTransform;const s=new B(e.worldTransform);return t(),new B(e.worldTransform).divide(s)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}let ee=class extends p{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 v,this.openedGroupList=new v,this.simulateTarget=new jt(this),this.editBox=new Bt(this),this.editToolList={},this.selector=new ht(this),this.editMask=new Mt(this),this.targetEventIds=[];let i=T.clone(Pt);t&&(i=T.default(t,i)),this.mergedConfig=this.config=i,this.addMany(this.editMask,this.selector,this.editBox),P.has("resize")||(this.config.editSize="scale")}select(t){this.target=t}cancel(){this.target=null}hasItem(t){return this.leafList.has(t)}getItem(t){return this.list[t||0]}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)}setDimOthers(t,i="dim",s){if(!s){const{dimTarget:t,targetLeafer:i}=this;s=t?e(t)?t:[t]:[i]}s[0]&&s[0][i]!==(t||!1)&&s.forEach(e=>T.stintSet(e,i,t))}setBright(t){this.setDimOthers(t,"bright",this.list)}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&&Ht(this),this.update()}getEditTool(t){return this.editToolList[t]=this.editToolList[t]||Wt.get(t,this)}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(u(s))e=s;else if(!1===s)return}if(Wt.list[e]){const t=this.editTool=this.getEditTool(e);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(Yt.BEFORE_GROUP),this.target=Dt.group(this.list,this.element,t),this.emitGroupEvent(Yt.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach(t=>t.isBranch&&this.emitGroupEvent(Yt.BEFORE_UNGROUP,t)),this.target=Dt.ungroup(t),t.forEach(t=>t.isBranch&&this.emitGroupEvent(Yt.UNGROUP,t))),this.list}openGroup(t){this.emitGroupEvent(Yt.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Yt.OPEN,t)}closeGroup(t){this.emitGroupEvent(Yt.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Yt.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach(t=>this.list.every(e=>!M.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 Yt(t,{editTarget:e});this.emitEvent(i),e&&e.emitEvent(i)}getInnerEditor(t){return this.editToolList[t]=this.editToolList[t]||Wt.get(t,this)}openInnerEditor(t,e,i){let s;if(u(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(u(i))s=i;else if(!1===i)return}Wt.list[s]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.getInnerEditor(s),this.innerEditor.editTarget=t,this.emitInnerEvent(Xt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Xt.OPEN))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Xt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Xt.CLOSE),t||this.updateEditTool(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Xt(t,{editTarget:i,innerEditor:e});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&&(Dt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Dt.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_(V.START,this.onRenderStart,this),i&&i.on_(R.SCROLL,this.onChildScroll,this),t.on_(V.CHILD_START,this.onAppRenderStart,this),t.on_(H.UPDATE_MODE,t=>{t.mode&&"normal"!==t.mode&&this.cancel()})],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())}};U([(t,e)=>{i(t,e,{get(){const{config:t,element:e,dragPoint:i,editBox:n,app:r}=this,a=Object.assign({},t);if(e&&e.editConfig){let{editConfig:t}=e;(t.hover||t.hoverStyle)&&(t=Object.assign({},t),delete t.hover,delete t.hoverStyle),Object.assign(a,t)}return n.config&&Object.assign(a,n.config),i&&(i.editConfig&&Object.assign(a,i.editConfig),"font-size"===a.editSize&&(a.lockRatio=!0),"resize-rotate"===i.pointType&&(a.around||(a.around="center"),s(a.lockRatio)&&(a.lockRatio=!0))),o(a.dragLimitAnimate)&&(a.dragLimitAnimate=r&&r.config.pointer.dragLimitAnimate),this.mergedConfig=a}})}],ee.prototype,"mergeConfig",void 0),U([j(function(t,e){const{target:i}=t;i?(t.leafList=i instanceof v?i:new v(i),t.multiple&&Ht(t)):(t.simulateTarget.remove(),t.leafList.reset()),t.closeInnerEditor(!0),t.unloadEditTool();const s={editor:t,value:i,oldValue:e};t.emitEvent(new N(N.SELECT,s)),t.checkOpenedGroups(),t.editing?t.waitLeafer(()=>{t.updateEditTool(),t.listenTargetEvents()}):(t.updateEditTool(),t.removeTargetEvents()),t.emitEvent(new N(N.AFTER_SELECT,s))})],ee.prototype,"target",void 0),U([j(function(t,e){t.emitEvent(new N(N.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))})],ee.prototype,"hoverTarget",void 0),ee=U([Y(te,["editBox","editTool","emitEvent"])],ee);class ie{static registerInnerEditor(){Wt.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 p,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 se=class extends ie{static registerEditTool(){Wt.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()}};se=U([Ft()],se);const{left:oe,right:ne}=b,{move:re,copy:ae,toNumberPoints:he}=L;let le=class extends se{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===oe;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=S(),{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=he(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?(re(t,n,r),s&&re(e,-n,-r)):(s&&re(t,-n,-r),re(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),ae(s[7],i),ae(e[7],i),ae(s[3],a),ae(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===oe||t===ne,s[t].visible=a,e[t].visible=!r&&a}};le=U([Ft()],le),P.add("editor","resize"),A.editor=function(t,e){const i=new ee(t);return e&&e.sky.add(e.editor=i),i},O.addAttr("textBox",!1,I),g.addAttr("editConfig",void 0,I),g.addAttr("editOuter",t=>(t.updateLayout(),t.__.__isLinePath?"LineEditTool":"EditTool"),I),g.addAttr("editInner","PathEditor",I),p.addAttr("editInner","",I),_.addAttr("editInner","TextEditor",I),g.setEditConfig=function(t){this.changeAttr("editConfig",t)},g.setEditOuter=function(t){this.changeAttr("editOuter",t)},g.setEditInner=function(t){this.changeAttr("editInner",t)};export{Bt as EditBox,yt as EditDataHelper,xt as EditPoint,ht as EditSelect,ot as EditSelectHelper,se as EditTool,Wt as EditToolCreator,ee as Editor,N as EditorEvent,Yt as EditorGroupEvent,Dt as EditorHelper,$t as EditorMoveEvent,Jt as EditorRotateEvent,qt as EditorScaleEvent,Qt as EditorSkewEvent,ie as InnerEditor,Xt as InnerEditorEvent,le as LineEditTool,st as SelectArea,it as Stroker,te as TransformTool,Ft as registerEditTool,Zt as registerInnerEditor};
|
|
2
2
|
//# sourceMappingURL=editor.esm.min.js.map
|