UNPKG

@leafer-in/editor

Version:
3 lines (2 loc) 46.8 kB
import{Event as t,isArray as e,defineKey as i,isNull as s,isUndefined as o,isObject as r,MatrixHelper as n,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 T,DataHelper as x,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 D,Creator as A,dataType as I}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,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n}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,o)=>{const n="_"+o;i(s,o,{get(){return this[n]},set(i){const s=this[n];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(r(e))i=e;else if(!1===e)return}a.hasDimOthers&&a.cancelDimOthers(),e(i)&&i.length>1&&i[0].locked&&i.splice(0,1),a.single&&(delete a.element.syncEventer,delete a.element.__world.ignorePixelSnap)}const n=t?N.BEFORE_SELECT:N.BEFORE_HOVER;this.hasEvent(n)&&this.emitEvent(new N(n,{editor:a,value:i,oldValue:s}))}this[n]=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}=n,{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:r,strokeWidth:n,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=n%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=n/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))}r&&(f(r)?p.stroke(r,this,t,e):p.strokes(r,this,t,e)),a&&(f(a)?p.fill(a,this,t,e):p.fills(a,this,t,e)),o.shadow&&t.restore()}}o.strokeWidth=n}}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 rt={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return nt([t],i,e),i}};function nt(t,e,i){let s,o;for(let r=0,n=t.length;r<n;r++)if(s=t[r],o=s.__,o.hittable&&o.visible&&!o.locked&&i.hit(s.__world)){if(o.editable){if(s.isBranch&&!o.hitChildren){o.hitSelf&&e.push(s);continue}if(s.isFrame){if(i.includes(s.__layout.boxBounds,s.__world)){e.push(s);continue}}else i.hit(s.__layout.boxBounds,s.__world)&&o.hitSelf&&e.push(s)}s.isBranch&&nt(s.children,e,i)}}const{findOne:at,findByBounds:ht}=rt;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:r,hover:n,hoverStyle:a}=s;this.hoverStroker.setTarget(n?e:null,Object.assign({stroke:o,strokeWidth:r},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:r}=t.getInnerPoint(this);this.bounds.set(o,r),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:r},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,r,n,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),T=a?w:k*u.width/v,x=a?y:L*u.height/b;if(O(s))c=g=Math.sqrt(s);else{r&&(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,n=(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=n,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=n,c=e,h="top-left";break;case mt:g=n,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/=T),_&&(g/=x),!n){const{worldTransform:e}=t;c<0&&(c=1/u.width/e.scaleX),g<0&&(g=1/u.height/e.scaleY)}if(vt(r||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:r}},getRotateData(t,e,i,s,o){let r,n={};switch(e){case dt:r="bottom-right";break;case gt:r="bottom-left";break;case ft:r="top-left";break;case mt:r="top-right";break;default:r="center"}return vt(o||r,t.boxBounds,n,!0),{origin:n,rotation:L.getRotation(s,t.getWorldPointByBox(n),i)}},getSkewData(t,e,i,s){let o,r,n={},a=0,h=0;switch(e){case ct:case dt:r={x:.5,y:0},o="bottom",a=1;break;case pt:case ft:r={x:.5,y:1},o="top",a=1;break;case Et:case mt:r={x:0,y:.5},o="right",h=1;break;case ut:case gt:r={x:1,y:.5},o="left",h=1}const{width:l,height:d}=t;r.x=r.x*l,r.y=r.y*d,vt(s||o,t,n,!0);const c=L.getRotation(r,n,{x:r.x+(a?i.x:0),y:r.y+(h?i.y:0)});return a?a=-c:h=c,{origin:n,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:r,flippedX:n,flippedY:a}=t;if(!i||!t.editor.editing||!t.canUse)return;if("rect"===i.name)return Tt(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:r?c:g:b?u:v?c:g;h+=45*(kt.getFlipDirection(i.direction,n,a)+1),h=2*Math.round(k.formatRotation(h,!0)/2);const{url:y,x:L,y:O}=w,T=y+h;Lt[T]?i.cursor=Lt[T]:Lt[T]=i.cursor={url:xt(y,h),x:L,y:O}}function Tt(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.canUse&&(t.rect.cursor=i?e:void 0)}function xt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class St extends T{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:r,resizeLines:n,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"}),r.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new St({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.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(...r,a,h,l,...n,...o),this.add(s)}load(){const{target:t,mergeConfig:e,single:i,rect:o,circle:r,resizePoints:n,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=n[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]||{}));r.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&&x.stintSet(t.__world,"ignorePixelSnap",d),Tt(this)}update(){const{editor:t}=this,{x:e,y:i,scaleX:s,scaleY:o,rotation:r,skewX:n,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:r,skewX:n,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:r,circle:n,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:T}=i;if(g.visible=!!v||0,o(b)&&o(w)?e.hasDimOthers&&e.cancelDimOthers():(e.setDimOthers(b),e.setBright(!!b||w),e.hasDimOthers=!0),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&&!T,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)));n.visible=g&&p&&!(!i.circle&&!i.rotatePoint),n.visible&&this.layoutCircle(),r.path&&(r.path=null),r.set(Object.assign(Object.assign({},t),{visible:!s||E})),h.visible=g&&h.children.length>0||0,h.visible&&this.layoutButtons()}else r.set(t)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,r=_t.indexOf(t||(this.buttons.children.length&&"bottom"===s?"top":"bottom"));this.setButtonPosition(this.circle,r,e||i,!!o)}layoutButtons(){const{buttons:t}=this,{buttonsDirection:e,buttonsFixed:i,buttonsMargin:s,middlePoint:o}=this.mergedConfig,{flippedX:r,flippedY:n}=this;let a=_t.indexOf(e);(a%2&&r||(a+1)%2&&n)&&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=r?-1:1,t.scaleY=n?-1:1}setButtonPosition(t,e,i,s){const o=this.resizePoints[2*e+1],r=e%2,n=e&&3!==e?1:-1,a=(i+(e%2?(s?o.width:0)+t.boxBounds.width:(s?o.height:0)+t.boxBounds.height)/2)*n;r?(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:r}=this.mergedConfig,n={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",opacity:1,width:o,height:o,cornerRadius:r,offsetX:0,offsetY:0,editConfig:Bt};return t?Object.assign(n,t):n}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:r,skewable:n,onCopy:a}=this.mergeConfig;"move"===i?(t.altKey&&a&&a()&&this.editor.single&&this.app.interaction.replaceDownTarget(this.target),s&&(this.moving=!0)):(i.includes("rotate")||this.isHoldRotateKey(t)||!o?(r&&(this.rotating=!0),"resize-rotate"===i?o&&(this.resizing=!0):"resize-line"===e.name&&(n&&(this.skewing=!0),this.rotating=!1)):"resize"===i&&o&&(this.resizing=!0),"skew"===i&&n&&(this.skewing=!0)),this.onTransformStart(t)}onDrag(t){const{transformTool:e,moving:i,resizing:s,rotating:o,skewing:r}=this;if(i)e.onMove(t);else if(s||o||r){const i=t.current;i.pointType&&(this.enterPoint=i),o&&e.onRotate(t),s&&e.onScale(t),r&&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){let e=0,i=0;switch(t.code){case"ArrowDown":i=1;break;case"ArrowUp":i=-1;break;case"ArrowLeft":e=-1;break;case"ArrowRight":e=1}if(e||i){const{keyEvent:s,arrowStep:o,arrowFastStep:r}=this.mergeConfig;if(s){const s=t.shiftKey?r:o;this.transformTool.move(e*s,i*s)}}}}onDoubleTap(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"double"!==e||i||this.openInner(t)}onLongPress(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"long"===e&&i&&this.openInner(t)}openInner(t){const{editor:e,target:i}=this;if(this.single){if(i.locked)return;if(i.isBranch&&!i.editInner){if(i.textBox){const{children:t}=i,s=t.find(t=>t.editable&&t instanceof 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,arrowStep:1,arrowFastStep:10,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 Dt(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 At=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),It=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),zt={group(t,e,i){t.sort(It);const{app:s,parent:o}=t[0];let r;r=i&&i.add?i:new m(i),o.addAt(r,o.children.indexOf(t[0])),t.sort(At);const n=new C(e.worldTransform);return n.divideParent(o.scrollWorldTransform),r.setTransform(n),r.editable=!0,r.hitChildren=!1,s.lockLayout(),t.forEach(t=>t.dropTo(r)),s.unlockLayout(),r},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach(t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.isBranchLeaf?i.push(t):t.remove()}else i.push(t)}),e.unlockLayout(),i},toTop(t){t.sort(At),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(It),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})}},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,r="s"===i[0]?(s||1)/(o||1):(s||0)-(o||0);this.canChange=!1;const n=this.__;n[i]=o,Kt(this.parent),Kt(this);const a=new C(this.__world);switch(n[i]=s,this.__layout.rotationChange(),Kt(this),this.changedTransform=new C(this.__world).divide(a),i){case"x":t.move(r,0);break;case"y":t.move(0,r);break;case"rotation":t.rotateOf(Nt,r);break;case"scaleX":t.scaleOf(Nt,r,1);break;case"scaleY":t.scaleOf(Nt,1,r);break;case"skewX":t.skewOf(Nt,r,0);break;case"skewY":t.skewOf(Nt,0,r)}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:r}=i;const n=t.type===W.END||t.type===F.END,a=f(e.draggable),h=!r||n||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)&&(r&&!a&&n?R.animateMove(this,o,O(r)?r:.3):this.move(o))}onScale(t){const{target:e,mergeConfig:i,single:s,dragStartData:o}=this.editBox;let r,{around:n,lockRatio:a,flipable:h,editSize:l}=i;t instanceof Z?(n||(n=e.getBoxPoint(t)),r=t.totalScale):r=t.getInnerTotal(e);const{direction:d}=t.current;(t.shiftKey||e.lockRatio)&&(a=!0);const c=kt.getScaleData(e,o.bounds,d,r,a,kt.getAround(n,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:r,rotateGap:n,diagonalRotateKey:a}=i,{direction:h}=t.current;let l,d;if(t instanceof Y)d=t.rotation,l=r?y.getPoint(r,e.boxBounds):e.getBoxPoint(t);else{const i=a?t.isHoldKeys(a):t.shiftKey,n=kt.getRotateData(e,h,t,s,i?null:r||e.around||e.origin||o||"center");d=s.rotation+n.rotation-e.rotation,l=n.origin}if(d=k.float(k.getGapRotation(d,n,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:r,skewY:n}=kt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),kt.getAround(s,t.altKey));(r||n)&&this.skewOf(o,r,n)}move(t,e=0){if(!this.checkTransform("moveable"))return;r(t)&&(e=t.y,t=t.x);const{target:i,mergeConfig:s,single:o,editor:n}=this.editBox,{beforeMove:a}=s;if(a){const s=a({target:i,x:t,y:e});if(r(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:n,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:r,drag:n}=t;if(!1===o({target:e,drag:n,origin:i,scaleX:s,scaleY:r}))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 r=new Jt(Jt.SCALE,t);this.editTool.onScaleWithDrag(r),this.emitEvent(r)}scaleOf(t,e,i=e,s){if(!this.checkTransform("resizeable"))return;const{target:o,mergeConfig:n,single:a,editor:h}=this.editBox,{beforeScale:l}=n;if(l){const s=l({target:o,origin:t,scaleX:e,scaleY:i});if(r(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"),r=i?new C(R.getFlipTransform(e,t)):this.getChangedTransform(()=>e.safeChange(()=>e.flip(t))),n={target:e,editor:s,worldOrigin:o,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:r};this.emitEvent(new Jt(Jt.BEFORE_SCALE,n));const a=new Jt(Jt.SCALE,n);this.doScale(a),this.emitEvent(a)}rotateOf(t,e){if(!this.checkTransform("rotateable"))return;const{target:i,mergeConfig:s,single:o,editor:r}=this.editBox,{beforeRotate:n}=s;if(n){const s=n({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:r,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:n,single:a,editor:h}=this.editBox,{beforeSkew:l}=n;if(l){const s=l({target:o,origin:t,skewX:e,skewY:i});if(r(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=x.clone(Vt);t&&(i=x.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=>x.stintSet(e,i,t))}setBright(t){this.setDimOthers(t,"bright",this.list)}cancelDimOthers(){this.setDimOthers(!1),this.setBright(!1),this.hasDimOthers=void 0}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&&Dt(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_(D.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:r,editTool:n,innerEditor:a,app:h}=this,l=Object.assign({},t);if(a?a.editConfig&&Object.assign(l,a.editConfig):n&&n.editConfig&&Object.assign(l,n.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 r.config&&Object.assign(l,r.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&&Dt(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:r}=s;o.lockLayout(),r.forEach(t=>{t.moveWorld(e,i)}),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:r}=t,{app:n,list:a}=r;n.lockLayout(),a.forEach(t=>{const n="scale"!==r.getEditSize(t);s?t.transformWorld(s,n):t.scaleOfWorld(o,e,i,n)}),n.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:r,list:n}=o;r.lockLayout(),n.forEach(t=>{const r="scale"!==o.getEditSize(t);i?t.transformWorld(i,r):t.rotateOfWorld(s,e)}),r.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:r}=t,{app:n,list:a}=r;n.lockLayout(),a.forEach(t=>{const n="scale"!==r.getEditSize(t);s?t.transformWorld(s,n):t.skewOfWorld(o,e,i,n)}),n.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:re,right:ne}=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,r=t.target,n=i===re;if(r.pathInputed){const{path:t}=r.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,n,o,this.getInnerMove(r,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,r.path=t}else if(r.points){const{points:t}=r,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,n,o,this.getInnerMove(r,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,r.points=t}else{const t=_(),{toPoint:i}=r;r.rotation=0,this.dragPoint(t,i,n,o,this.getInnerMove(r,e,s)),r.getLocalPointByInner(t,null,null,!0),r.getLocalPointByInner(i,null,null,!0),r.x=t.x,r.y=t.y,r.getInnerPointByLocal(i,null,null,!0),r.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:r,y:n}=o;i?(ae(t,r,n),s&&ae(e,-r,-n)):(s&&ae(t,-r,-n),ae(e,r,n))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=t,r=t.target;let n,a;if(r.pathInputed?n=this.getFromToByPath(r.__.path):r.points&&(n=this.getFromToByPoints(r.__.points)),n){const{from:i,to:a}=n;r.innerToWorld(i,i,!1,t),r.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===re||t===ne,s[t].visible=a,e[t].visible=!n&&a}};de=K([Wt()],de),V.add("editor","resize"),A.editor=function(t,e){const i=new ie(t);return e&&e.sky.add(e.editor=i),i},T.addAttr("textBox",!1,I),g.addAttr("editConfig",void 0,I),g.addAttr("editOuter",t=>(t.updateLayout(),t.__.__isLinePath?"LineEditTool":"EditTool"),I),g.addAttr("editInner","PathEditor",I),m.addAttr("editInner","",I),B.addAttr("editInner","TextEditor",I),g.setEditConfig=function(t){this.changeAttr("editConfig",t)},g.setEditOuter=function(t){this.changeAttr("editOuter",t)},g.setEditInner=function(t){this.changeAttr("editInner",t)};export{Ct as EditBox,kt as EditDataHelper,St as EditPoint,lt as EditSelect,rt 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}; //# sourceMappingURL=editor.esm.min.js.map