@leafer-in/editor 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/editor.cjs CHANGED
@@ -65,8 +65,11 @@ function targetAttr(fn) {
65
65
  });
66
66
  if (draw.isObject(check)) value = check; else if (check === false) return;
67
67
  }
68
- t.setDimOthers(false);
69
- t.setBright(false);
68
+ const {dimOthers: dimOthers, bright: bright} = t.editBox.mergedConfig || t.config;
69
+ if (!draw.isUndefined(dimOthers) || !draw.isUndefined(bright)) {
70
+ t.setDimOthers(false);
71
+ t.setBright(false);
72
+ }
70
73
  if (draw.isArray(value) && value.length > 1 && value[0].locked) value.splice(0, 1);
71
74
  if (t.single) {
72
75
  delete t.element.syncEventer;
@@ -91,7 +94,8 @@ function mergeConfigAttr() {
91
94
  return (target, key) => {
92
95
  draw.defineKey(target, key, {
93
96
  get() {
94
- const {config: config, element: element, dragPoint: dragPoint, editBox: editBox, app: app} = this, mergeConfig = Object.assign({}, config);
97
+ const {config: config, element: element, dragPoint: dragPoint, editBox: editBox, editTool: editTool, innerEditor: innerEditor, app: app} = this, mergeConfig = Object.assign({}, config);
98
+ if (innerEditor) innerEditor.editConfig && Object.assign(mergeConfig, innerEditor.editConfig); else if (editTool) editTool.editConfig && Object.assign(mergeConfig, editTool.editConfig);
95
99
  if (element && element.editConfig) {
96
100
  let {editConfig: editConfig} = element;
97
101
  if (editConfig.hover || editConfig.hoverStyle) {
@@ -994,8 +998,10 @@ class EditBox extends draw.Group {
994
998
  const {editMask: editMask} = editor;
995
999
  const {middlePoint: middlePoint, resizeable: resizeable, rotateable: rotateable, hideOnSmall: hideOnSmall, editBox: editBox, mask: mask, dimOthers: dimOthers, bright: bright, spread: spread, hideRotatePoints: hideRotatePoints, hideResizeLines: hideResizeLines} = mergeConfig;
996
1000
  editMask.visible = mask ? true : 0;
997
- editor.setDimOthers(dimOthers);
998
- editor.setBright(!!dimOthers || bright);
1001
+ if (!draw.isUndefined(dimOthers) || !draw.isUndefined(bright)) {
1002
+ editor.setDimOthers(dimOthers);
1003
+ editor.setBright(!!dimOthers || bright);
1004
+ }
999
1005
  if (spread) draw.BoundsHelper.spread(bounds, spread);
1000
1006
  if (this.view.worldOpacity) {
1001
1007
  const {width: width, height: height} = bounds;
@@ -1014,7 +1020,8 @@ class EditBox extends draw.Group {
1014
1020
  resizeL = resizeLines[(i - 1) / 2];
1015
1021
  resizeL.set(point);
1016
1022
  resizeL.visible = resizeP.visible && !hideResizeLines;
1017
- resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
1023
+ if (resizeP.visible) resizeP.visible = !!middlePoint;
1024
+ if (rotateP.visible) rotateP.visible = !!middlePoint;
1018
1025
  if ((i + 1) / 2 % 2) {
1019
1026
  resizeL.width = width + resizeL.height;
1020
1027
  if (hideOnSmall && resizeP.width * 2 > width) resizeP.visible = false;
@@ -63,8 +63,11 @@ function targetAttr(fn) {
63
63
  });
64
64
  if (isObject(check)) value = check; else if (check === false) return;
65
65
  }
66
- t.setDimOthers(false);
67
- t.setBright(false);
66
+ const {dimOthers: dimOthers, bright: bright} = t.editBox.mergedConfig || t.config;
67
+ if (!isUndefined(dimOthers) || !isUndefined(bright)) {
68
+ t.setDimOthers(false);
69
+ t.setBright(false);
70
+ }
68
71
  if (isArray(value) && value.length > 1 && value[0].locked) value.splice(0, 1);
69
72
  if (t.single) {
70
73
  delete t.element.syncEventer;
@@ -89,7 +92,8 @@ function mergeConfigAttr() {
89
92
  return (target, key) => {
90
93
  defineKey(target, key, {
91
94
  get() {
92
- const {config: config, element: element, dragPoint: dragPoint, editBox: editBox, app: app} = this, mergeConfig = Object.assign({}, config);
95
+ const {config: config, element: element, dragPoint: dragPoint, editBox: editBox, editTool: editTool, innerEditor: innerEditor, app: app} = this, mergeConfig = Object.assign({}, config);
96
+ if (innerEditor) innerEditor.editConfig && Object.assign(mergeConfig, innerEditor.editConfig); else if (editTool) editTool.editConfig && Object.assign(mergeConfig, editTool.editConfig);
93
97
  if (element && element.editConfig) {
94
98
  let {editConfig: editConfig} = element;
95
99
  if (editConfig.hover || editConfig.hoverStyle) {
@@ -992,8 +996,10 @@ class EditBox extends Group {
992
996
  const {editMask: editMask} = editor;
993
997
  const {middlePoint: middlePoint, resizeable: resizeable, rotateable: rotateable, hideOnSmall: hideOnSmall, editBox: editBox, mask: mask, dimOthers: dimOthers, bright: bright, spread: spread, hideRotatePoints: hideRotatePoints, hideResizeLines: hideResizeLines} = mergeConfig;
994
998
  editMask.visible = mask ? true : 0;
995
- editor.setDimOthers(dimOthers);
996
- editor.setBright(!!dimOthers || bright);
999
+ if (!isUndefined(dimOthers) || !isUndefined(bright)) {
1000
+ editor.setDimOthers(dimOthers);
1001
+ editor.setBright(!!dimOthers || bright);
1002
+ }
997
1003
  if (spread) BoundsHelper.spread(bounds, spread);
998
1004
  if (this.view.worldOpacity) {
999
1005
  const {width: width, height: height} = bounds;
@@ -1012,7 +1018,8 @@ class EditBox extends Group {
1012
1018
  resizeL = resizeLines[(i - 1) / 2];
1013
1019
  resizeL.set(point);
1014
1020
  resizeL.visible = resizeP.visible && !hideResizeLines;
1015
- resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
1021
+ if (resizeP.visible) resizeP.visible = !!middlePoint;
1022
+ if (rotateP.visible) rotateP.visible = !!middlePoint;
1016
1023
  if ((i + 1) / 2 % 2) {
1017
1024
  resizeL.width = width + resizeL.height;
1018
1025
  if (hideOnSmall && resizeP.width * 2 > width) resizeP.visible = false;
@@ -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,surfaceType as c,UI as g,ColorConvert as u,isString as f,Paint as p,Group as m,Rect as E,Bounds as v,LeafList as b,Direction9 as w,AroundHelper as y,MathHelper as k,PointHelper as L,isNumber as x,Box as O,DataHelper as T,ResizeEvent as S,getPointData as _,Text as B,Matrix as C,Debug as M,LeafHelper as R,PropertyEvent as P,Plugin as V,RenderEvent as H,LeaferEvent as A,Creator as I,dataType as D}from"@leafer-ui/draw";import{PointerEvent as z,DragEvent as F,MoveEvent as W,ZoomEvent as Z,DragBoundsHelper as G,KeyEvent as X,RotateEvent as Y,useModule as U}from"@leafer-ui/core";import"@leafer-in/resize";function K(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function N(t){return t?e(t)?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class j extends t{get list(){return N(this.value)}get oldList(){return N(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}function $(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?j.BEFORE_SELECT:j.BEFORE_HOVER;this.hasEvent(r)&&this.emitEvent(new j(r,{editor:a,value:i,oldValue:s}))}this[r]=i,t(this,s)}}})}}j.BEFORE_SELECT="editor.before_select",j.SELECT="editor.select",j.AFTER_SELECT="editor.after_select",j.BEFORE_HOVER="editor.before_hover",j.HOVER="editor.hover";const{abs:q}=Math,{copy:J}=r,{setListWithFn:Q}=a,{worldBounds:tt}=h,et=l(),it=d();class st 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?(Q(it,e,tt),t&&this.set(t),this.set(it),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=q(d.scaleX),h=q(d.scaleY);if(J(et,d),et.half=r%2,t.setWorld(et,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),o.shadow){const e=o.shadow[0],{scaleX:i,scaleY:s}=this.getRenderScaleData(!0,e.scaleFixed);t.save(),t.setWorldShadow(e.x*i,e.y*s,e.blur*i,u.string(e.color))}n&&(f(n)?p.stroke(n,this,t,e):p.strokes(n,this,t,e)),a&&(f(a)?p.fill(a,this,t,e):p.fills(a,this,t,e)),o.shadow&&t.restore()}}o.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}K([$(function(t){const i=t.target;t.list=i?e(i)?i:[i]:[]})],st.prototype,"target",void 0),K([c("render-path")],st.prototype,"strokePathType",void 0);class ot extends m{constructor(t){super(t),this.strokeArea=new E({strokeAlign:"center"}),this.fillArea=new E,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 nt={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return rt([t],i,e),i}};function rt(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&&rt(s.children,e,i)}}const{findOne:at,findByBounds:ht}=nt;class lt extends m{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 st,this.targetStroker=new st,this.bounds=new v,this.selectArea=new ot,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,t.path.needUpdate=!0):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 b(ht(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)&&!at(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new b(this.editor.editBox.rect)};return at(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):at(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_([[j.HOVER,this.onHover,this],[j.SELECT,this.onSelect,this]]),e.on_([[z.MOVE,this.onPointerMove,this],[z.BEFORE_DOWN,this.onBeforeDown,this],[z.TAP,this.onTap,this],[F.START,this.onDragStart,this,!0],[F.DRAG,this.onDrag,this],[F.END,this.onDragEnd,this],[W.MOVE,this.onAutoMove,this],[[Z.ZOOM,W.MOVE],()=>{this.editor.hoverTarget=null}]])]})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:dt,top:ct,topRight:gt,right:ut,bottomRight:ft,bottom:pt,bottomLeft:mt,left:Et}=w,{toPoint:vt}=y,{within:bt,sign:wt}=k,{abs:yt}=Math,kt={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,k=wt(w),L=wt(y),O=a?w:k*u.width/v,T=a?y:L*u.height/b;if(x(s))c=g=Math.sqrt(s);else{n&&(s.x*=2,s.y*=2),s.x*=a?w:k,s.y*=a?y:L;const t=(-s.y+b)/b,e=(s.x+v)/v,r=(s.y+b)/b,d=(-s.x+v)/v;switch(i){case ct:g=t,h="bottom";break;case ut:c=e,h="left";break;case pt:g=r,h="top";break;case Et:c=d,h="right";break;case dt:g=t,c=d,h="bottom-right";break;case gt:g=t,c=e,h="bottom-left";break;case ft:g=r,c=e,h="top-left";break;case mt:g=r,c=d,h="top-right"}if(o)if("corner"===o&&i%2)o=!1;else switch(i){case ct:case pt:c=g;break;case Et:case ut:g=c;break;default:l=Math.sqrt(yt(c*g)),c=wt(c)*l,g=wt(g)*l}}const S=1!==c,_=1!==g;if(S&&(c/=O),_&&(g/=T),!r){const{worldTransform:e}=t;c<0&&(c=1/u.width/e.scaleX),g<0&&(g=1/u.height/e.scaleY)}if(vt(n||h,u,d,!0),m){const e={x:c,y:g};G.limitScaleOf(t,d,e,o),c=e.x,g=e.y}if(S&&f){const e=u.width*t.scaleX;c=bt(e*c,f)/e}if(_&&p){const e=u.height*t.scaleY;g=bt(e*g,p)/e}return S&&yt(c*E.width)<1&&(c=wt(c)/E.width),_&&yt(g*E.height)<1&&(g=wt(g)/E.height),o&&c!==g&&(l=Math.min(yt(c),yt(g)),c=wt(c)*l,g=wt(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 dt:n="bottom-right";break;case gt:n="bottom-left";break;case ft:n="top-left";break;case mt:n="top-right";break;default:n="center"}return vt(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 ct:case dt:n={x:.5,y:0},o="bottom",a=1;break;case pt:case ft:n={x:.5,y:1},o="top",a=1;break;case Et:case mt:n={x:0,y:.5},o="right",h=1;break;case ut:case gt: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,vt(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 Et:t=ut;break;case dt:t=gt;break;case mt:t=ft;break;case ut:t=Et;break;case gt:t=dt;break;case ft:t=mt}if(i)switch(t){case ct:t=pt;break;case dt:t=mt;break;case gt:t=ft;break;case pt:t=ct;break;case mt:t=dt;break;case ft:t=gt}return t}},Lt={};function xt(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*(kt.getFlipDirection(i.direction,r,a)+1),h=2*Math.round(k.formatRotation(h,!0)/2);const{url:y,x:L,y:x}=w,O=y+h;Lt[O]?i.cursor=Lt[O]:Lt[O]=i.cursor={url:Tt(y,h),x:L,y:x}}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 St extends O{constructor(t){super(t),this.useFastShadow=!0}}const _t=["top","right","bottom","left"],Bt=void 0;class Ct extends m{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 f(t)||f(e)||f(i)}get canDragLimitAnimate(){return this.moving&&this.mergeConfig.dragLimitAnimate&&this.target.dragBounds}constructor(t){super(),this.view=new m,this.rect=new St({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new St({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new m({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 St({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new St({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new St({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:Bt},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:w,hideRotatePoints:k,hideResizeLines:L}=i;if(c.visible=!!E||0,e.setDimOthers(v),e.setBright(!!v||b),w&&a.spread(t,w),this.view.worldOpacity){const{width:e,height:a}=t,c=x(p)?p:10,E=m&&!(p&&e<c&&a<c);let v,b,w,O={};for(let i=0;i<8;i++)y.toPoint(y.directionData[i],t,O),b=h[i],v=l[i],b.set(O),v.set(O),b.visible=E&&!(!u&&!f),v.visible=E&&f&&u&&!k,i%2&&(w=d[(i-1)/2],w.set(O),w.visible=b.visible&&!L,b.visible=v.visible=E&&!!g,(i+1)/2%2?(w.width=e+w.height,p&&2*b.width>e&&(b.visible=!1)):(w.width=a+w.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=_t.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=_t.indexOf(e);(a%2&&n||(a+1)%2&&r)&&i&&(a=(a+2)%4);const h=i?kt.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:Bt};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)}xt(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&&(S.resizingKeys=this.editor.leafList.keys);const{dragStartData:e,target:i}=this;e.x=t.x,e.y=t.y,e.totalOffset=_(),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 F||t instanceof W)&&this.transformTool.onMove(t),this.resizing&&(S.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(),f(this.mergedConfig.moveable)))switch(this.gesturing=this.moving=!0,t.type){case W.START:this.onTransformStart(t);break;case W.END:this.onTransformEnd(t);break;default:this.transformTool.onMove(t)}}onScale(t){if(this.canGesture&&(t.stop(),f(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(),f(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){xt(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 B)||t.find(t=>t instanceof B);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_([[F.START,this.onDragStart,this],[F.DRAG,this.onDrag,this],[F.END,this.onDragEnd,this],[z.ENTER,e=>{this.enterPoint=t,xt(this,e)}],[z.LEAVE,()=>{this.enterPoint=null}]]))}__listenEvents(){const{rect:t,editor:e,__eventIds:i}=this;i.push(t.on_([[z.DOUBLE_TAP,this.onDoubleTap,this],[z.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer(()=>{i.push(e.app.on_([[[X.HOLD,X.UP],this.onKey,this],[X.DOWN,this.onArrow,this],[[W.START,W.BEFORE_MOVE,W.END],this.onMove,this,!0],[[Z.START,Z.BEFORE_ZOOM,Z.END],this.onScale,this,!0],[[Y.START,Y.BEFORE_ROTATE,Y.END],this.onRotate,this,!0]]))})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Mt={x:0,y:0,width:1e5,height:1e5};class Rt extends g{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,Mt),Object.assign(this.__world,Mt)}__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 Pt='\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"/>',Vt={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${Pt}\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${Pt}\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${Pt}\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},Ht=new v;function At(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange(()=>{Ht.setListWithFn(i,t=>t.getBounds("box","page")),0===Ht.width&&(Ht.width=.1),0===Ht.height&&(Ht.height=.1),e.reset(Ht.get())}),s.add(e)}const It=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Dt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),zt={group(t,e,i){t.sort(Dt);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new m(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(It);const r=new C(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(It),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(Dt),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})}},Ft=M.get("EditToolCreator");function Wt(){return t=>{Gt.register(t)}}const Zt=Wt,Gt={list:{},register(t){const{tag:e}=t.prototype;Xt[e]&&Ft.repeat(e),Xt[e]=t},get:(t,e)=>new Xt[t](e)},{list:Xt}=Gt;class Yt extends j{constructor(t,e){super(t,e)}}Yt.BEFORE_OPEN="innerEditor.before_open",Yt.OPEN="innerEditor.open",Yt.BEFORE_CLOSE="innerEditor.before_close",Yt.CLOSE="innerEditor.close";class Ut extends j{constructor(t,e){super(t,e)}}Ut.BEFORE_GROUP="editor.before_group",Ut.GROUP="editor.group",Ut.BEFORE_UNGROUP="editor.before_ungroup",Ut.UNGROUP="editor.ungroup",Ut.BEFORE_OPEN="editor.before_open_group",Ut.OPEN="editor.open_group",Ut.BEFORE_CLOSE="editor.before_close_group",Ut.CLOSE="editor.close_group";const{updateMatrix:Kt}=R,Nt={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},jt="top-left";class $t extends E{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.skipJSON=!0,this.on(P.CHANGE,e=>{if(this.checkChange&&Nt[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,Kt(this.parent),Kt(this);const a=new C(this.__world);switch(r[i]=s,this.__layout.rotationChange(),Kt(this),this.changedTransform=new C(this.__world).divide(a),i){case"x":t.move(n,0);break;case"y":t.move(0,n);break;case"rotation":t.rotateOf(jt,n);break;case"scaleX":t.scaleOf(jt,n,1);break;case"scaleY":t.scaleOf(jt,1,n);break;case"skewX":t.skewOf(jt,n,0);break;case"skewY":t.skewOf(jt,0,n)}this.canChange=!0}})}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class qt extends j{constructor(t,e){super(t,e)}}qt.BEFORE_MOVE="editor.before_move",qt.MOVE="editor.move";class Jt extends j{constructor(t,e){super(t,e)}}Jt.BEFORE_SCALE="editor.before_scale",Jt.SCALE="editor.scale";class Qt extends j{constructor(t,e){super(t,e)}}Qt.BEFORE_ROTATE="editor.before_rotate",Qt.ROTATE="editor.rotate";class te extends j{constructor(t,e){super(t,e)}}te.BEFORE_SKEW="editor.before_skew",te.SKEW="editor.skew";class ee{onMove(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox;let o,{dragLimitAnimate:n}=i;const r=t.type===W.END||t.type===F.END,a=f(e.draggable),h=!n||r||a,l={x:t.totalX,y:t.totalY};t instanceof W&&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=F.getValidMove(e,s.point,l,h),(o.x||o.y)&&(n&&!a&&r?R.animateMove(this,o,x(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=kt.getScaleData(e,o.bounds,d,n,a,kt.getAround(r,t.altKey),h,!s||"scale"===l),g=e.x,u=e.y;t instanceof F&&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 Y)d=t.rotation,l=n?y.getPoint(n,e.boxBounds):e.getBoxPoint(t);else{const i=a?t.isHoldKeys(a):t.shiftKey,r=kt.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=k.float(k.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}=kt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),kt.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 qt(qt.BEFORE_MOVE,l));const d=new qt(qt.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 Jt(Jt.BEFORE_SCALE,t));const n=new Jt(Jt.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 Jt(Jt.BEFORE_SCALE,g));const u=new Jt(Jt.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(R.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 Jt(Jt.BEFORE_SCALE,r));const a=new Jt(Jt.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(x(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 te(te.BEFORE_SKEW,g));const u=new te(te.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(R.getInnerOrigin(e,t))}getChangedTransform(t){const{target:e,single:i}=this.editBox;if(!i&&!e.canChange)return e.changedTransform;const s=new C(e.worldTransform);return t(),new C(e.worldTransform).divide(s)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}let ie=class extends m{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 b,this.openedGroupList=new b,this.simulateTarget=new $t(this),this.editBox=new Ct(this),this.editToolList={},this.selector=new lt(this),this.editMask=new Rt(this),this.targetEventIds=[];let i=T.clone(Vt);t&&(i=T.default(t,i)),this.mergedConfig=this.config=i,this.addMany(this.editMask,this.selector,this.editBox),V.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&&At(this),this.update()}getEditTool(t){return this.editToolList[t]=this.editToolList[t]||Gt.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(f(s))e=s;else if(!1===s)return}if(Gt.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(Ut.BEFORE_GROUP),this.target=zt.group(this.list,this.element,t),this.emitGroupEvent(Ut.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach(t=>t.isBranch&&this.emitGroupEvent(Ut.BEFORE_UNGROUP,t)),this.target=zt.ungroup(t),t.forEach(t=>t.isBranch&&this.emitGroupEvent(Ut.UNGROUP,t))),this.list}openGroup(t){this.emitGroupEvent(Ut.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Ut.OPEN,t)}closeGroup(t){this.emitGroupEvent(Ut.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Ut.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach(t=>this.list.every(e=>!R.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 Ut(t,{editTarget:e});this.emitEvent(i),e&&e.emitEvent(i)}getInnerEditor(t){return this.editToolList[t]=this.editToolList[t]||Gt.get(t,this)}openInnerEditor(t,e,i){let s;if(f(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(f(i))s=i;else if(!1===i)return}Gt.list[s]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.getInnerEditor(s),this.innerEditor.editTarget=t,this.emitInnerEvent(Yt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Yt.OPEN))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Yt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Yt.CLOSE),t||this.updateEditTool(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Yt(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&&(zt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(zt.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_(H.START,this.onRenderStart,this),i&&i.on_(P.SCROLL,this.onChildScroll,this),t.on_(H.CHILD_START,this.onAppRenderStart,this),t.on_(A.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())}};K([(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}})}],ie.prototype,"mergeConfig",void 0),K([$(function(t,e){const{target:i}=t;i?(t.leafList=i instanceof b?i:new b(i),t.multiple&&At(t)):(t.simulateTarget.remove(),t.leafList.reset()),t.closeInnerEditor(!0),t.unloadEditTool();const s={editor:t,value:i,oldValue:e};t.emitEvent(new j(j.SELECT,s)),t.checkOpenedGroups(),t.editing?t.waitLeafer(()=>{t.updateEditTool(),t.listenTargetEvents()}):(t.updateEditTool(),t.removeTargetEvents()),t.emitEvent(new j(j.AFTER_SELECT,s))})],ie.prototype,"target",void 0),K([$(function(t,e){t.emitEvent(new j(j.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))})],ie.prototype,"hoverTarget",void 0),ie=K([U(ee,["editBox","editTool","emitEvent"])],ie);class se{static registerInnerEditor(){Gt.register(this)}get tag(){return"InnerEditor"}get mode(){return"focus"}get editBox(){return this._editBox||this.editor.editBox}set editBox(t){this._editBox=t}constructor(t){this.eventIds=[],this.editor=t,this.create()}onCreate(){}create(){this.view=new m,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 oe=class extends se{static registerEditTool(){Gt.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()}};oe=K([Wt()],oe);const{left:ne,right:re}=w,{move:ae,copy:he,toNumberPoints:le}=L;let de=class extends oe{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===ne;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=_(),{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=le(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?(ae(t,n,r),s&&ae(e,-n,-r)):(s&&ae(t,-n,-r),ae(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=t,n=t.target;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),he(s[7],i),he(e[7],i),he(s[3],a),he(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===ne||t===re,s[t].visible=a,e[t].visible=!r&&a}};de=K([Wt()],de),V.add("editor","resize"),I.editor=function(t,e){const i=new ie(t);return e&&e.sky.add(e.editor=i),i},O.addAttr("textBox",!1,D),g.addAttr("editConfig",void 0,D),g.addAttr("editOuter",t=>(t.updateLayout(),t.__.__isLinePath?"LineEditTool":"EditTool"),D),g.addAttr("editInner","PathEditor",D),m.addAttr("editInner","",D),B.addAttr("editInner","TextEditor",D),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{Ct as EditBox,kt as EditDataHelper,St as EditPoint,lt as EditSelect,nt as EditSelectHelper,oe as EditTool,Gt as EditToolCreator,ie as Editor,j as EditorEvent,Ut as EditorGroupEvent,zt as EditorHelper,qt as EditorMoveEvent,Qt as EditorRotateEvent,Jt as EditorScaleEvent,te as EditorSkewEvent,se as InnerEditor,Yt as InnerEditorEvent,de as LineEditTool,ot as SelectArea,st as Stroker,ee as TransformTool,Wt as registerEditTool,Zt 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,ColorConvert as u,isString as f,Paint as p,Group as m,Rect as E,Bounds as v,LeafList as b,Direction9 as w,AroundHelper as y,MathHelper as k,PointHelper as L,isNumber as O,Box as x,DataHelper as T,ResizeEvent as S,getPointData as _,Text as B,Matrix as C,Debug as M,LeafHelper as R,PropertyEvent as P,Plugin as V,RenderEvent as H,LeaferEvent as A,Creator as I,dataType as D}from"@leafer-ui/draw";import{PointerEvent as z,DragEvent as F,MoveEvent as W,ZoomEvent as Z,DragBoundsHelper as G,KeyEvent as X,RotateEvent as Y,useModule as U}from"@leafer-ui/core";import"@leafer-in/resize";function K(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function j(t){return t?e(t)?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class N extends t{get list(){return j(this.value)}get oldList(){return j(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}function $(t){return(s,r)=>{const a="_"+r;i(s,r,{get(){return this[a]},set(i){const s=this[a];if(s!==i){const h=this;if(h.config){const t="target"===r;if(t){const{beforeSelect:t}=h.config;if(t){const e=t({target:i});if(n(e))i=e;else if(!1===e)return}const{dimOthers:s,bright:r}=h.editBox.mergedConfig||h.config;o(s)&&o(r)||(h.setDimOthers(!1),h.setBright(!1)),e(i)&&i.length>1&&i[0].locked&&i.splice(0,1),h.single&&(delete h.element.syncEventer,delete h.element.__world.ignorePixelSnap)}const a=t?N.BEFORE_SELECT:N.BEFORE_HOVER;this.hasEvent(a)&&this.emitEvent(new N(a,{editor:h,value:i,oldValue:s}))}this[a]=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:q}=Math,{copy:J}=r,{setListWithFn:Q}=a,{worldBounds:tt}=h,et=l(),it=d();class st 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?(Q(it,e,tt),t&&this.set(t),this.set(it),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=q(d.scaleX),h=q(d.scaleY);if(J(et,d),et.half=r%2,t.setWorld(et,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),o.shadow){const e=o.shadow[0],{scaleX:i,scaleY:s}=this.getRenderScaleData(!0,e.scaleFixed);t.save(),t.setWorldShadow(e.x*i,e.y*s,e.blur*i,u.string(e.color))}n&&(f(n)?p.stroke(n,this,t,e):p.strokes(n,this,t,e)),a&&(f(a)?p.fill(a,this,t,e):p.fills(a,this,t,e)),o.shadow&&t.restore()}}o.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}K([$(function(t){const i=t.target;t.list=i?e(i)?i:[i]:[]})],st.prototype,"target",void 0),K([c("render-path")],st.prototype,"strokePathType",void 0);class ot extends m{constructor(t){super(t),this.strokeArea=new E({strokeAlign:"center"}),this.fillArea=new E,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 nt={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return rt([t],i,e),i}};function rt(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&&rt(s.children,e,i)}}const{findOne:at,findByBounds:ht}=nt;class lt extends m{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 st,this.targetStroker=new st,this.bounds=new v,this.selectArea=new ot,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,t.path.needUpdate=!0):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 b(ht(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)&&!at(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new b(this.editor.editBox.rect)};return at(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):at(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_([[z.MOVE,this.onPointerMove,this],[z.BEFORE_DOWN,this.onBeforeDown,this],[z.TAP,this.onTap,this],[F.START,this.onDragStart,this,!0],[F.DRAG,this.onDrag,this],[F.END,this.onDragEnd,this],[W.MOVE,this.onAutoMove,this],[[Z.ZOOM,W.MOVE],()=>{this.editor.hoverTarget=null}]])]})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:dt,top:ct,topRight:gt,right:ut,bottomRight:ft,bottom:pt,bottomLeft:mt,left:Et}=w,{toPoint:vt}=y,{within:bt,sign:wt}=k,{abs:yt}=Math,kt={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,k=wt(w),L=wt(y),x=a?w:k*u.width/v,T=a?y:L*u.height/b;if(O(s))c=g=Math.sqrt(s);else{n&&(s.x*=2,s.y*=2),s.x*=a?w:k,s.y*=a?y:L;const t=(-s.y+b)/b,e=(s.x+v)/v,r=(s.y+b)/b,d=(-s.x+v)/v;switch(i){case ct:g=t,h="bottom";break;case ut:c=e,h="left";break;case pt:g=r,h="top";break;case Et:c=d,h="right";break;case dt:g=t,c=d,h="bottom-right";break;case gt:g=t,c=e,h="bottom-left";break;case ft:g=r,c=e,h="top-left";break;case mt:g=r,c=d,h="top-right"}if(o)if("corner"===o&&i%2)o=!1;else switch(i){case ct:case pt:c=g;break;case Et:case ut:g=c;break;default:l=Math.sqrt(yt(c*g)),c=wt(c)*l,g=wt(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(vt(n||h,u,d,!0),m){const e={x:c,y:g};G.limitScaleOf(t,d,e,o),c=e.x,g=e.y}if(S&&f){const e=u.width*t.scaleX;c=bt(e*c,f)/e}if(_&&p){const e=u.height*t.scaleY;g=bt(e*g,p)/e}return S&&yt(c*E.width)<1&&(c=wt(c)/E.width),_&&yt(g*E.height)<1&&(g=wt(g)/E.height),o&&c!==g&&(l=Math.min(yt(c),yt(g)),c=wt(c)*l,g=wt(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 dt:n="bottom-right";break;case gt:n="bottom-left";break;case ft:n="top-left";break;case mt:n="top-right";break;default:n="center"}return vt(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 ct:case dt:n={x:.5,y:0},o="bottom",a=1;break;case pt:case ft:n={x:.5,y:1},o="top",a=1;break;case Et:case mt:n={x:0,y:.5},o="right",h=1;break;case ut:case gt: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,vt(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 Et:t=ut;break;case dt:t=gt;break;case mt:t=ft;break;case ut:t=Et;break;case gt:t=dt;break;case ft:t=mt}if(i)switch(t){case ct:t=pt;break;case dt:t=mt;break;case gt:t=ft;break;case pt:t=ct;break;case mt:t=dt;break;case ft:t=gt}return t}},Lt={};function Ot(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 xt(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*(kt.getFlipDirection(i.direction,r,a)+1),h=2*Math.round(k.formatRotation(h,!0)/2);const{url:y,x:L,y:O}=w,x=y+h;Lt[x]?i.cursor=Lt[x]:Lt[x]=i.cursor={url:Tt(y,h),x:L,y:O}}function xt(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 St extends x{constructor(t){super(t),this.useFastShadow=!0}}const _t=["top","right","bottom","left"],Bt=void 0;class Ct extends m{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 f(t)||f(e)||f(i)}get canDragLimitAnimate(){return this.moving&&this.mergeConfig.dragLimitAnimate&&this.target.dragBounds}constructor(t){super(),this.view=new m,this.rect=new St({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new St({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new m({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 St({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new St({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new St({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:Bt},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),xt(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:n,circle:r,buttons:h,resizePoints:l,rotatePoints:d,resizeLines:c}=this,{editMask:g}=e,{middlePoint:u,resizeable:f,rotateable:p,hideOnSmall:m,editBox:E,mask:v,dimOthers:b,bright:w,spread:k,hideRotatePoints:L,hideResizeLines:x}=i;if(g.visible=!!v||0,o(b)&&o(w)||(e.setDimOthers(b),e.setBright(!!b||w)),k&&a.spread(t,k),this.view.worldOpacity){const{width:e,height:o}=t,a=O(m)?m:10,g=E&&!(m&&e<a&&o<a);let v,b,w,k={};for(let i=0;i<8;i++)y.toPoint(y.directionData[i],t,k),b=l[i],v=d[i],b.set(k),v.set(k),b.visible=g&&!(!f&&!p),v.visible=g&&p&&f&&!L,i%2&&(w=c[(i-1)/2],w.set(k),w.visible=b.visible&&!x,b.visible&&(b.visible=!!u),v.visible&&(v.visible=!!u),(i+1)/2%2?(w.width=e+w.height,m&&2*b.width>e&&(b.visible=!1)):(w.width=o+w.height,m&&2*b.width>o&&(b.visible=!1)));r.visible=g&&p&&!(!i.circle&&!i.rotatePoint),r.visible&&this.layoutCircle(),n.path&&(n.path=null),n.set(Object.assign(Object.assign({},t),{visible:!s||E})),h.visible=g&&h.children.length>0||0,h.visible&&this.layoutButtons()}else n.set(t)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,n=_t.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=_t.indexOf(e);(a%2&&n||(a+1)%2&&r)&&i&&(a=(a+2)%4);const h=i?kt.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:Bt};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)}Ot(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&&(S.resizingKeys=this.editor.leafList.keys);const{dragStartData:e,target:i}=this;e.x=t.x,e.y=t.y,e.totalOffset=_(),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 F||t instanceof W)&&this.transformTool.onMove(t),this.resizing&&(S.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(),f(this.mergedConfig.moveable)))switch(this.gesturing=this.moving=!0,t.type){case W.START:this.onTransformStart(t);break;case W.END:this.onTransformEnd(t);break;default:this.transformTool.onMove(t)}}onScale(t){if(this.canGesture&&(t.stop(),f(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(),f(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){Ot(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 B)||t.find(t=>t instanceof B);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_([[F.START,this.onDragStart,this],[F.DRAG,this.onDrag,this],[F.END,this.onDragEnd,this],[z.ENTER,e=>{this.enterPoint=t,Ot(this,e)}],[z.LEAVE,()=>{this.enterPoint=null}]]))}__listenEvents(){const{rect:t,editor:e,__eventIds:i}=this;i.push(t.on_([[z.DOUBLE_TAP,this.onDoubleTap,this],[z.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer(()=>{i.push(e.app.on_([[[X.HOLD,X.UP],this.onKey,this],[X.DOWN,this.onArrow,this],[[W.START,W.BEFORE_MOVE,W.END],this.onMove,this,!0],[[Z.START,Z.BEFORE_ZOOM,Z.END],this.onScale,this,!0],[[Y.START,Y.BEFORE_ROTATE,Y.END],this.onRotate,this,!0]]))})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Mt={x:0,y:0,width:1e5,height:1e5};class Rt extends g{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,Mt),Object.assign(this.__world,Mt)}__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 Pt='\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"/>',Vt={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${Pt}\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${Pt}\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${Pt}\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},Ht=new v;function At(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange(()=>{Ht.setListWithFn(i,t=>t.getBounds("box","page")),0===Ht.width&&(Ht.width=.1),0===Ht.height&&(Ht.height=.1),e.reset(Ht.get())}),s.add(e)}const It=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),Dt=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),zt={group(t,e,i){t.sort(Dt);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new m(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(It);const r=new C(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(It),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(Dt),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})}},Ft=M.get("EditToolCreator");function Wt(){return t=>{Gt.register(t)}}const Zt=Wt,Gt={list:{},register(t){const{tag:e}=t.prototype;Xt[e]&&Ft.repeat(e),Xt[e]=t},get:(t,e)=>new Xt[t](e)},{list:Xt}=Gt;class Yt extends N{constructor(t,e){super(t,e)}}Yt.BEFORE_OPEN="innerEditor.before_open",Yt.OPEN="innerEditor.open",Yt.BEFORE_CLOSE="innerEditor.before_close",Yt.CLOSE="innerEditor.close";class Ut extends N{constructor(t,e){super(t,e)}}Ut.BEFORE_GROUP="editor.before_group",Ut.GROUP="editor.group",Ut.BEFORE_UNGROUP="editor.before_ungroup",Ut.UNGROUP="editor.ungroup",Ut.BEFORE_OPEN="editor.before_open_group",Ut.OPEN="editor.open_group",Ut.BEFORE_CLOSE="editor.before_close_group",Ut.CLOSE="editor.close_group";const{updateMatrix:Kt}=R,jt={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},Nt="top-left";class $t extends E{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.skipJSON=!0,this.on(P.CHANGE,e=>{if(this.checkChange&&jt[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,Kt(this.parent),Kt(this);const a=new C(this.__world);switch(r[i]=s,this.__layout.rotationChange(),Kt(this),this.changedTransform=new C(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 qt extends N{constructor(t,e){super(t,e)}}qt.BEFORE_MOVE="editor.before_move",qt.MOVE="editor.move";class Jt extends N{constructor(t,e){super(t,e)}}Jt.BEFORE_SCALE="editor.before_scale",Jt.SCALE="editor.scale";class Qt extends N{constructor(t,e){super(t,e)}}Qt.BEFORE_ROTATE="editor.before_rotate",Qt.ROTATE="editor.rotate";class te extends N{constructor(t,e){super(t,e)}}te.BEFORE_SKEW="editor.before_skew",te.SKEW="editor.skew";class ee{onMove(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox;let o,{dragLimitAnimate:n}=i;const r=t.type===W.END||t.type===F.END,a=f(e.draggable),h=!n||r||a,l={x:t.totalX,y:t.totalY};t instanceof W&&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=F.getValidMove(e,s.point,l,h),(o.x||o.y)&&(n&&!a&&r?R.animateMove(this,o,O(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=kt.getScaleData(e,o.bounds,d,n,a,kt.getAround(r,t.altKey),h,!s||"scale"===l),g=e.x,u=e.y;t instanceof F&&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 Y)d=t.rotation,l=n?y.getPoint(n,e.boxBounds):e.getBoxPoint(t);else{const i=a?t.isHoldKeys(a):t.shiftKey,r=kt.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=k.float(k.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}=kt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),kt.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 qt(qt.BEFORE_MOVE,l));const d=new qt(qt.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 Jt(Jt.BEFORE_SCALE,t));const n=new Jt(Jt.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 Jt(Jt.BEFORE_SCALE,g));const u=new Jt(Jt.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(R.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 Jt(Jt.BEFORE_SCALE,r));const a=new Jt(Jt.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(O(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 te(te.BEFORE_SKEW,g));const u=new te(te.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(R.getInnerOrigin(e,t))}getChangedTransform(t){const{target:e,single:i}=this.editBox;if(!i&&!e.canChange)return e.changedTransform;const s=new C(e.worldTransform);return t(),new C(e.worldTransform).divide(s)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}let ie=class extends m{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 b,this.openedGroupList=new b,this.simulateTarget=new $t(this),this.editBox=new Ct(this),this.editToolList={},this.selector=new lt(this),this.editMask=new Rt(this),this.targetEventIds=[];let i=T.clone(Vt);t&&(i=T.default(t,i)),this.mergedConfig=this.config=i,this.addMany(this.editMask,this.selector,this.editBox),V.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&&At(this),this.update()}getEditTool(t){return this.editToolList[t]=this.editToolList[t]||Gt.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(f(s))e=s;else if(!1===s)return}if(Gt.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(Ut.BEFORE_GROUP),this.target=zt.group(this.list,this.element,t),this.emitGroupEvent(Ut.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach(t=>t.isBranch&&this.emitGroupEvent(Ut.BEFORE_UNGROUP,t)),this.target=zt.ungroup(t),t.forEach(t=>t.isBranch&&this.emitGroupEvent(Ut.UNGROUP,t))),this.list}openGroup(t){this.emitGroupEvent(Ut.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(Ut.OPEN,t)}closeGroup(t){this.emitGroupEvent(Ut.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(Ut.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:e}=t;this.editing&&(e=[],t.forEach(t=>this.list.every(e=>!R.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 Ut(t,{editTarget:e});this.emitEvent(i),e&&e.emitEvent(i)}getInnerEditor(t){return this.editToolList[t]=this.editToolList[t]||Gt.get(t,this)}openInnerEditor(t,e,i){let s;if(f(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(f(i))s=i;else if(!1===i)return}Gt.list[s]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.getInnerEditor(s),this.innerEditor.editTarget=t,this.emitInnerEvent(Yt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Yt.OPEN))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Yt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Yt.CLOSE),t||this.updateEditTool(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Yt(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&&(zt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(zt.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_(H.START,this.onRenderStart,this),i&&i.on_(P.SCROLL,this.onChildScroll,this),t.on_(H.CHILD_START,this.onAppRenderStart,this),t.on_(A.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())}};K([(t,e)=>{i(t,e,{get(){const{config:t,element:e,dragPoint:i,editBox:n,editTool:r,innerEditor:a,app:h}=this,l=Object.assign({},t);if(a?a.editConfig&&Object.assign(l,a.editConfig):r&&r.editConfig&&Object.assign(l,r.editConfig),e&&e.editConfig){let{editConfig:t}=e;(t.hover||t.hoverStyle)&&(t=Object.assign({},t),delete t.hover,delete t.hoverStyle),Object.assign(l,t)}return n.config&&Object.assign(l,n.config),i&&(i.editConfig&&Object.assign(l,i.editConfig),"font-size"===l.editSize&&(l.lockRatio=!0),"resize-rotate"===i.pointType&&(l.around||(l.around="center"),s(l.lockRatio)&&(l.lockRatio=!0))),o(l.dragLimitAnimate)&&(l.dragLimitAnimate=h&&h.config.pointer.dragLimitAnimate),this.mergedConfig=l}})}],ie.prototype,"mergeConfig",void 0),K([$(function(t,e){const{target:i}=t;i?(t.leafList=i instanceof b?i:new b(i),t.multiple&&At(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))})],ie.prototype,"target",void 0),K([$(function(t,e){t.emitEvent(new N(N.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))})],ie.prototype,"hoverTarget",void 0),ie=K([U(ee,["editBox","editTool","emitEvent"])],ie);class se{static registerInnerEditor(){Gt.register(this)}get tag(){return"InnerEditor"}get mode(){return"focus"}get editBox(){return this._editBox||this.editor.editBox}set editBox(t){this._editBox=t}constructor(t){this.eventIds=[],this.editor=t,this.create()}onCreate(){}create(){this.view=new m,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 oe=class extends se{static registerEditTool(){Gt.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()}};oe=K([Wt()],oe);const{left:ne,right:re}=w,{move:ae,copy:he,toNumberPoints:le}=L;let de=class extends oe{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===ne;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=_(),{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=le(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?(ae(t,n,r),s&&ae(e,-n,-r)):(s&&ae(t,-n,-r),ae(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=t,n=t.target;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),he(s[7],i),he(e[7],i),he(s[3],a),he(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===ne||t===re,s[t].visible=a,e[t].visible=!r&&a}};de=K([Wt()],de),V.add("editor","resize"),I.editor=function(t,e){const i=new ie(t);return e&&e.sky.add(e.editor=i),i},x.addAttr("textBox",!1,D),g.addAttr("editConfig",void 0,D),g.addAttr("editOuter",t=>(t.updateLayout(),t.__.__isLinePath?"LineEditTool":"EditTool"),D),g.addAttr("editInner","PathEditor",D),m.addAttr("editInner","",D),B.addAttr("editInner","TextEditor",D),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{Ct as EditBox,kt as EditDataHelper,St as EditPoint,lt as EditSelect,nt as EditSelectHelper,oe as EditTool,Gt as EditToolCreator,ie as Editor,N as EditorEvent,Ut as EditorGroupEvent,zt as EditorHelper,qt as EditorMoveEvent,Qt as EditorRotateEvent,Jt as EditorScaleEvent,te as EditorSkewEvent,se as InnerEditor,Yt as InnerEditorEvent,de as LineEditTool,ot as SelectArea,st as Stroker,ee as TransformTool,Wt as registerEditTool,Zt as registerInnerEditor};
2
2
  //# sourceMappingURL=editor.esm.min.js.map