UNPKG

@leafer-in/editor

Version:
3 lines (2 loc) 47.6 kB
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.editor=function(t,e,i){"use strict";function s(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 o(t){return t?e.isArray(t)?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class r extends e.Event{get list(){return o(this.value)}get oldList(){return o(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}function n(t){return(i,s)=>{const o="_"+s;e.defineKey(i,s,{get(){return this[o]},set(i){const n=this[o];if(n!==i){const a=this;if(a.config){const t="target"===s;if(t){const{beforeSelect:t}=a.config;if(t){const s=t({target:i});if(e.isObject(s))i=s;else if(!1===s)return}a.hasDimOthers&&a.cancelDimOthers(),e.isArray(i)&&i.length>1&&i[0].locked&&i.splice(0,1),a.single&&(delete a.element.syncEventer,delete a.element.__world.ignorePixelSnap)}const o=t?r.BEFORE_SELECT:r.BEFORE_HOVER;this.hasEvent(o)&&this.emitEvent(new r(o,{editor:a,value:i,oldValue:n}))}this[o]=i,t(this,n)}}})}}r.BEFORE_SELECT="editor.before_select",r.SELECT="editor.select",r.AFTER_SELECT="editor.after_select",r.BEFORE_HOVER="editor.before_hover",r.HOVER="editor.hover";const{abs:a}=Math,{copy:h}=e.MatrixHelper,{setListWithFn:l}=e.BoundsHelper,{worldBounds:d}=e.LeafBoundsHelper,c=e.getMatrixData(),g=e.getBoundsData();class u extends e.UI{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?(l(g,e,d),t&&this.set(t),this.set(g),this.visible=!0):this.visible=0}__draw(t,i){const{list:s}=this;if(s.length){let o;const r=this.__,{stroke:n,strokeWidth:l,fill:d}=r,{bounds:g}=i;for(let u=0;u<s.length;u++){o=s[u];const{worldTransform:f,worldRenderBounds:p}=o;if(p.width&&p.height&&(!g||g.hit(p,i.matrix))){const s=a(f.scaleX),g=a(f.scaleY);if(h(c,f),c.half=l%2,t.setWorld(c,i.matrix),t.beginPath(),"path"===this.strokePathType||o.__.__useArrow?o.__drawPath(t):o.__.__pathForRender?o.__drawRenderPath(t):o.__drawPathByBox(t),r.strokeWidth=l/Math.max(s,g),r.shadow){const i=r.shadow[0],{scaleX:s,scaleY:o}=this.getRenderScaleData(!0,i.scaleFixed);t.save(),t.setWorldShadow(i.x*s,i.y*o,i.blur*s,e.ColorConvert.string(i.color))}n&&(e.isString(n)?e.Paint.stroke(n,this,t,i):e.Paint.strokes(n,this,t,i)),d&&(e.isString(d)?e.Paint.fill(d,this,t,i):e.Paint.fills(d,this,t,i)),r.shadow&&t.restore()}}r.strokeWidth=l}}destroy(){this.target=null,super.destroy()}}s([n(function(t){const i=t.target;t.list=i?e.isArray(i)?i:[i]:[]})],u.prototype,"target",void 0),s([e.surfaceType("render-path")],u.prototype,"strokePathType",void 0);class f extends e.Group{constructor(t){super(t),this.strokeArea=new e.Rect({strokeAlign:"center"}),this.fillArea=new e.Rect,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 p={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return E([t],i,e),i}};function E(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&&E(s.children,e,i)}}const{findOne:m,findByBounds:v}=p;class b extends e.Group{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 u,this.targetStroker=new u,this.bounds=new e.Bounds,this.selectArea=new f,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:i}=this,s=t.getInnerTotal(this),o=this.bounds.clone().unsign(),r=new e.LeafList(v(i.app,o));if(this.bounds.width=s.x,this.bounds.height=s.y,this.selectArea.setBounds(o.get()),r.length){const t=[];this.originList.forEach(e=>{r.has(e)||t.push(e)}),r.forEach(e=>{this.originList.has(e)||t.push(e)}),(t.length!==i.list.length||i.list.some((e,i)=>e!==t[i]))&&(i.target=t)}else i.target=this.originList.list}}}onDragEnd(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)&&!m(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const i={exclude:new e.LeafList(this.editor.editBox.rect)};return m(t.target.leafer.interaction.findPath(t,i))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):m(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_([[r.HOVER,this.onHover,this],[r.SELECT,this.onSelect,this]]),e.on_([[i.PointerEvent.MOVE,this.onPointerMove,this],[i.PointerEvent.BEFORE_DOWN,this.onBeforeDown,this],[i.PointerEvent.TAP,this.onTap,this],[i.DragEvent.START,this.onDragStart,this,!0],[i.DragEvent.DRAG,this.onDrag,this],[i.DragEvent.END,this.onDragEnd,this],[i.MoveEvent.MOVE,this.onAutoMove,this],[[i.ZoomEvent.ZOOM,i.MoveEvent.MOVE],()=>{this.editor.hoverTarget=null}]])]})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:y,top:w,topRight:L,right:k,bottomRight:T,bottom:O,bottomLeft:S,left:x}=e.Direction9,{toPoint:_}=e.AroundHelper,{within:M,sign:B}=e.MathHelper,{abs:C}=Math,R={getScaleData(t,s,o,r,n,a,h,l){let d,c,g={},u=1,f=1;const{boxBounds:p,widthRange:E,heightRange:m,dragBounds:v,worldBoxBounds:b}=t,{width:R,height:P}=s,H=t.scaleX/s.scaleX,D=t.scaleY/s.scaleY,A=B(H),I=B(D),V=l?H:A*p.width/R,z=l?D:I*p.height/P;if(e.isNumber(r))u=f=Math.sqrt(r);else{a&&(r.x*=2,r.y*=2),r.x*=l?H:A,r.y*=l?D:I;const t=(-r.y+P)/P,e=(r.x+R)/R,i=(r.y+P)/P,s=(-r.x+R)/R;switch(o){case w:f=t,d="bottom";break;case k:u=e,d="left";break;case O:f=i,d="top";break;case x:u=s,d="right";break;case y:f=t,u=s,d="bottom-right";break;case L:f=t,u=e,d="bottom-left";break;case T:f=i,u=e,d="top-left";break;case S:f=i,u=s,d="top-right"}if(n)if("corner"===n&&o%2)n=!1;else switch(o){case w:case O:u=f;break;case x:case k:f=u;break;default:c=Math.sqrt(C(u*f)),u=B(u)*c,f=B(f)*c}}const F=1!==u,Z=1!==f;if(F&&(u/=V),Z&&(f/=z),!h){const{worldTransform:e}=t;u<0&&(u=1/p.width/e.scaleX),f<0&&(f=1/p.height/e.scaleY)}if(_(a||d,p,g,!0),v){const e={x:u,y:f};i.DragBoundsHelper.limitScaleOf(t,g,e,n),u=e.x,f=e.y}if(F&&E){const e=p.width*t.scaleX;u=M(e*u,E)/e}if(Z&&m){const e=p.height*t.scaleY;f=M(e*f,m)/e}return F&&C(u*b.width)<1&&(u=B(u)/b.width),Z&&C(f*b.height)<1&&(f=B(f)/b.height),n&&u!==f&&(c=Math.min(C(u),C(f)),u=B(u)*c,f=B(f)*c),isFinite(u)||(u=1),isFinite(f)||(f=1),{origin:g,scaleX:u,scaleY:f,direction:o,lockRatio:n,around:a}},getRotateData(t,i,s,o,r){let n,a={};switch(i){case y:n="bottom-right";break;case L:n="bottom-left";break;case T:n="top-left";break;case S:n="top-right";break;default:n="center"}return _(r||n,t.boxBounds,a,!0),{origin:a,rotation:e.PointHelper.getRotation(o,t.getWorldPointByBox(a),s)}},getSkewData(t,i,s,o){let r,n,a={},h=0,l=0;switch(i){case w:case y:n={x:.5,y:0},r="bottom",h=1;break;case O:case T:n={x:.5,y:1},r="top",h=1;break;case x:case S:n={x:0,y:.5},r="right",l=1;break;case k:case L:n={x:1,y:.5},r="left",l=1}const{width:d,height:c}=t;n.x=n.x*d,n.y=n.y*c,_(o||r,t,a,!0);const g=e.PointHelper.getRotation(n,a,{x:n.x+(h?s.x:0),y:n.y+(l?s.y:0)});return h?h=-g:l=g,{origin:a,skewX:h,skewY:l}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case x:t=k;break;case y:t=L;break;case S:t=T;break;case k:t=x;break;case L:t=y;break;case T:t=S}if(i)switch(t){case w:t=O;break;case y:t=S;break;case L:t=T;break;case O:t=w;break;case S:t=y;break;case T:t=L}return t}},P={};function H(t,i){const{enterPoint:s,dragging:o,skewing:r,resizing:n,flippedX:a,flippedY:h}=t;if(!s||!t.editor.editing||!t.canUse)return;if("rect"===s.name)return D(t);if("circle"===s.name)return;let{rotation:l}=t;const{pointType:d}=s,{moveCursor:c,resizeCursor:g,rotateCursor:u,skewCursor:f,moveable:p,resizeable:E,rotateable:m,skewable:v}=t.mergeConfig;if("move"===d)return s.cursor=c,void(p||(s.visible=!1));if("button"===d)return void(s.cursor||(s.cursor="pointer"));let b=d.includes("resize");b&&m&&(t.isHoldRotateKey(i)||!E)&&(b=!1);const y=v&&!b&&("resize-line"===s.name||"skew"===d),w=o?r?f:n?g:u:y?f:b?g:u;l+=45*(R.getFlipDirection(s.direction,a,h)+1),l=2*Math.round(e.MathHelper.formatRotation(l,!0)/2);const{url:L,x:k,y:T}=w,O=L+l;P[O]?s.cursor=P[O]:P[O]=s.cursor={url:A(L,l),x:k,y:T}}function D(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.canUse&&(t.rect.cursor=i?e:void 0)}function A(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class I extends e.Box{constructor(t){super(t),this.useFastShadow=!0}}const V=["top","right","bottom","left"],z=void 0;class F extends e.Group{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:i,rotateable:s}=this.mergeConfig;return e.isString(t)||e.isString(i)||e.isString(s)}get canDragLimitAnimate(){return this.moving&&this.mergeConfig.dragLimitAnimate&&this.target.dragBounds}constructor(t){super(),this.view=new e.Group,this.rect=new I({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new I({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new e.Group({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 I({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),r.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new I({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),n.push(e),this.listenPointEvents(e,"resize",s)),i=new I({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:i,single:s,rect:o,circle:r,resizePoints:n,resizeLines:a}=this,{stroke:h,strokeWidth:l,ignorePixelSnap:d}=i,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(i.circle||i.rotatePoint||c[0])),o.set(Object.assign({stroke:h,strokeWidth:l,opacity:1,editConfig:z},i.rect||{}));const p=e.isNull(i.rectThrough)?s:i.rectThrough;o.hittable=!p,p&&(t.syncEventer=o,this.app.interaction.bottomList=[{target:o,proxy:t}]),s&&e.DataHelper.stintSet(t.__world,"ignorePixelSnap",d),D(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:i,mergeConfig:s,single:o,rect:r,circle:n,buttons:a,resizePoints:h,rotatePoints:l,resizeLines:d}=this,{editMask:c}=i,{middlePoint:g,resizeable:u,rotateable:f,hideOnSmall:p,editBox:E,mask:m,dimOthers:v,bright:b,spread:y,hideRotatePoints:w,hideResizeLines:L}=s;if(c.visible=!!m||0,e.isUndefined(v)&&e.isUndefined(b)?i.hasDimOthers&&i.cancelDimOthers():(i.setDimOthers(v),i.setBright(!!v||b),i.hasDimOthers=!0),y&&e.BoundsHelper.spread(t,y),this.view.worldOpacity){const{width:i,height:c}=t,m=e.isNumber(p)?p:10,v=E&&!(p&&i<m&&c<m);let b,y,k,T={};for(let s=0;s<8;s++)e.AroundHelper.toPoint(e.AroundHelper.directionData[s],t,T),y=h[s],b=l[s],y.set(T),b.set(T),y.visible=v&&!(!u&&!f),b.visible=v&&f&&u&&!w,s%2&&(k=d[(s-1)/2],k.set(T),k.visible=y.visible&&!L,y.visible&&(y.visible=!!g),b.visible&&(b.visible=!!g),(s+1)/2%2?(k.width=i+k.height,p&&2*y.width>i&&(y.visible=!1)):(k.width=c+k.height,p&&2*y.width>c&&(y.visible=!1)));n.visible=v&&f&&!(!s.circle&&!s.rotatePoint),n.visible&&this.layoutCircle(),r.path&&(r.path=null),r.set(Object.assign(Object.assign({},t),{visible:!o||E})),a.visible=v&&a.children.length>0||0,a.visible&&this.layoutButtons()}else r.set(t)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,r=V.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=V.indexOf(e);(a%2&&r||(a+1)%2&&n)&&i&&(a=(a+2)%4);const h=i?R.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:z};return t?Object.assign(n,t):n}getPointsStyle(){const{point:t}=this.mergedConfig;return e.isArray(t)?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.mergedConfig;return e.isArray(t)?t:t?[t]:this.getPointsStyle()}getResizeLinesStyle(){const{resizeLine:t}=this.mergedConfig;return e.isArray(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)}H(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&&(e.ResizeEvent.resizingKeys=this.editor.leafList.keys);const{dragStartData:i,target:s}=this;i.x=t.x,i.y=t.y,i.totalOffset=e.getPointData(),i.point={x:s.x,y:s.y},i.bounds=Object.assign({},s.getLayoutBounds("box","local")),i.rotation=s.rotation}onTransformEnd(t){this.canDragLimitAnimate&&(t instanceof i.DragEvent||t instanceof i.MoveEvent)&&this.transformTool.onMove(t),this.resizing&&(e.ResizeEvent.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(),e.isString(this.mergedConfig.moveable)))switch(this.gesturing=this.moving=!0,t.type){case i.MoveEvent.START:this.onTransformStart(t);break;case i.MoveEvent.END:this.onTransformEnd(t);break;default:this.transformTool.onMove(t)}}onScale(t){if(this.canGesture&&(t.stop(),e.isString(this.mergedConfig.resizeable)))switch(this.gesturing=this.resizing=!0,t.type){case i.ZoomEvent.START:this.onTransformStart(t);break;case i.ZoomEvent.END:this.onTransformEnd(t);break;default:this.transformTool.onScale(t)}}onRotate(t){if(this.canGesture&&(t.stop(),e.isString(this.mergedConfig.rotateable)))switch(this.gesturing=this.rotating=!0,t.type){case i.ZoomEvent.START:this.onTransformStart(t);break;case i.ZoomEvent.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){H(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:i,target:s}=this;if(this.single){if(s.locked)return;if(s.isBranch&&!s.editInner){if(s.textBox){const{children:t}=s,o=t.find(t=>t.editable&&t instanceof e.Text)||t.find(t=>t instanceof e.Text);if(o)return i.openInnerEditor(o)}i.openGroup(s),i.target=i.selector.findDeepOne(t)}else i.openInnerEditor()}}listenPointEvents(t,e,s){t.direction=s,t.pointType=e,this.__eventIds.push(t.on_([[i.DragEvent.START,this.onDragStart,this],[i.DragEvent.DRAG,this.onDrag,this],[i.DragEvent.END,this.onDragEnd,this],[i.PointerEvent.ENTER,e=>{this.enterPoint=t,H(this,e)}],[i.PointerEvent.LEAVE,()=>{this.enterPoint=null}]]))}__listenEvents(){const{rect:t,editor:e,__eventIds:s}=this;s.push(t.on_([[i.PointerEvent.DOUBLE_TAP,this.onDoubleTap,this],[i.PointerEvent.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer(()=>{s.push(e.app.on_([[[i.KeyEvent.HOLD,i.KeyEvent.UP],this.onKey,this],[i.KeyEvent.DOWN,this.onArrow,this],[[i.MoveEvent.START,i.MoveEvent.BEFORE_MOVE,i.MoveEvent.END],this.onMove,this,!0],[[i.ZoomEvent.START,i.ZoomEvent.BEFORE_ZOOM,i.ZoomEvent.END],this.onScale,this,!0],[[i.RotateEvent.START,i.RotateEvent.BEFORE_ROTATE,i.RotateEvent.END],this.onRotate,this,!0]]))})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Z={x:0,y:0,width:1e5,height:1e5};class W extends e.UI{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,Z),Object.assign(this.__world,Z)}__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 G='\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"/>',U={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${G}\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${G}\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${G}\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},N=new e.Bounds;function X(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange(()=>{N.setListWithFn(i,t=>t.getBounds("box","page")),0===N.width&&(N.width=.1),0===N.height&&(N.height=.1),e.reset(N.get())}),s.add(e)}const Y=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),K=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),j={group(t,i,s){t.sort(K);const{app:o,parent:r}=t[0];let n;n=s&&s.add?s:new e.Group(s),r.addAt(n,r.children.indexOf(t[0])),t.sort(Y);const a=new e.Matrix(i.worldTransform);return a.divideParent(r.scrollWorldTransform),n.setTransform(a),n.editable=!0,n.hitChildren=!1,o.lockLayout(),t.forEach(t=>t.dropTo(n)),o.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(Y),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(K),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})}},$=e.Debug.get("EditToolCreator");function q(){return t=>{Q.register(t)}}const J=q,Q={list:{},register(t){const{tag:e}=t.prototype;tt[e]&&$.repeat(e),tt[e]=t},get:(t,e)=>new tt[t](e)},{list:tt}=Q;class et extends r{constructor(t,e){super(t,e)}}et.BEFORE_OPEN="innerEditor.before_open",et.OPEN="innerEditor.open",et.BEFORE_CLOSE="innerEditor.before_close",et.CLOSE="innerEditor.close";class it extends r{constructor(t,e){super(t,e)}}it.BEFORE_GROUP="editor.before_group",it.GROUP="editor.group",it.BEFORE_UNGROUP="editor.before_ungroup",it.UNGROUP="editor.ungroup",it.BEFORE_OPEN="editor.before_open_group",it.OPEN="editor.open_group",it.BEFORE_CLOSE="editor.before_close_group",it.CLOSE="editor.close_group";const{updateMatrix:st}=e.LeafHelper,ot={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},rt="top-left";class nt extends e.Rect{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.skipJSON=!0,this.on(e.PropertyEvent.CHANGE,i=>{if(this.checkChange&&ot[i.attrName]){const{attrName:s,newValue:o,oldValue:r}=i,n="s"===s[0]?(o||1)/(r||1):(o||0)-(r||0);this.canChange=!1;const a=this.__;a[s]=r,st(this.parent),st(this);const h=new e.Matrix(this.__world);switch(a[s]=o,this.__layout.rotationChange(),st(this),this.changedTransform=new e.Matrix(this.__world).divide(h),s){case"x":t.move(n,0);break;case"y":t.move(0,n);break;case"rotation":t.rotateOf(rt,n);break;case"scaleX":t.scaleOf(rt,n,1);break;case"scaleY":t.scaleOf(rt,1,n);break;case"skewX":t.skewOf(rt,n,0);break;case"skewY":t.skewOf(rt,0,n)}this.canChange=!0}})}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class at extends r{constructor(t,e){super(t,e)}}at.BEFORE_MOVE="editor.before_move",at.MOVE="editor.move";class ht extends r{constructor(t,e){super(t,e)}}ht.BEFORE_SCALE="editor.before_scale",ht.SCALE="editor.scale";class lt extends r{constructor(t,e){super(t,e)}}lt.BEFORE_ROTATE="editor.before_rotate",lt.ROTATE="editor.rotate";class dt extends r{constructor(t,e){super(t,e)}}dt.BEFORE_SKEW="editor.before_skew",dt.SKEW="editor.skew";class ct{onMove(t){const{target:s,mergeConfig:o,dragStartData:r}=this.editBox;let n,{dragLimitAnimate:a}=o;const h=t.type===i.MoveEvent.END||t.type===i.DragEvent.END,l=e.isString(s.draggable),d=!a||h||l,c={x:t.totalX,y:t.totalY};t instanceof i.MoveEvent&&e.PointHelper.move(c,s.getWorldPointByLocal(r.totalOffset,null,!0)),t.shiftKey&&(Math.abs(c.x)>Math.abs(c.y)?c.y=0:c.x=0),n=i.DragEvent.getValidMove(s,r.point,c,d),(n.x||n.y)&&(a&&!l&&h?e.LeafHelper.animateMove(this,n,e.isNumber(a)?a:.3):this.move(n))}onScale(t){const{target:s,mergeConfig:o,single:r,dragStartData:n}=this.editBox;let a,{around:h,lockRatio:l,flipable:d,editSize:c}=o;t instanceof i.ZoomEvent?(h||(h=s.getBoxPoint(t)),a=t.totalScale):a=t.getInnerTotal(s);const{direction:g}=t.current;(t.shiftKey||s.lockRatio)&&(l=!0);const u=R.getScaleData(s,n.bounds,g,a,l,R.getAround(h,t.altKey),d,!r||"scale"===c),f=s.x,p=s.y;t instanceof i.DragEvent&&this.editTool&&this.editTool.onScaleWithDrag?(u.drag=t,this.scaleWithDrag(u)):this.scaleOf(u.origin,u.scaleX,u.scaleY),e.PointHelper.move(n.totalOffset,s.x-f,s.y-p)}onRotate(t){const{target:s,mergeConfig:o,dragStartData:r}=this.editBox,{around:n,rotateAround:a,rotateGap:h,diagonalRotateKey:l}=o,{direction:d}=t.current;let c,g;if(t instanceof i.RotateEvent)g=t.rotation,c=a?e.AroundHelper.getPoint(a,s.boxBounds):s.getBoxPoint(t);else{const e=l?t.isHoldKeys(l):t.shiftKey,i=R.getRotateData(s,d,t,r,e?null:a||s.around||s.origin||n||"center");g=r.rotation+i.rotation-s.rotation,c=i.origin}if(g=e.MathHelper.float(e.MathHelper.getGapRotation(g,h,s.rotation),2),!g)return;const u=s.x,f=s.y;this.rotateOf(c,g),e.PointHelper.move(r.totalOffset,s.x-u,s.y-f)}onSkew(t){const{target:e,mergeConfig:i}=this.editBox,{around:s}=i,{origin:o,skewX:r,skewY:n}=R.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),R.getAround(s,t.altKey));(r||n)&&this.skewOf(o,r,n)}move(t,i=0){if(!this.checkTransform("moveable"))return;e.isObject(t)&&(i=t.y,t=t.x);const{target:s,mergeConfig:o,single:r,editor:n}=this.editBox,{beforeMove:a}=o;if(a){const o=a({target:s,x:t,y:i});if(e.isObject(o))t=o.x,i=o.y;else if(!1===o)return}const h=s.getWorldPointByLocal({x:t,y:i},null,!0);r||s.safeChange(()=>s.move(t,i));const l={target:s,editor:n,moveX:h.x,moveY:h.y};this.emitEvent(new at(at.BEFORE_MOVE,l));const d=new at(at.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 ht(ht.BEFORE_SCALE,t));const r=new ht(ht.SCALE,t);this.editTool.onScaleWithDrag(r),this.emitEvent(r)}scaleOf(t,i,s=i,o){if(!this.checkTransform("resizeable"))return;const{target:r,mergeConfig:n,single:a,editor:h}=this.editBox,{beforeScale:l}=n;if(l){const o=l({target:r,origin:t,scaleX:i,scaleY:s});if(e.isObject(o))i=o.scaleX,s=o.scaleY;else if(!1===o)return}const d=this.getWorldOrigin(t),c=!a&&this.getChangedTransform(()=>r.safeChange(()=>r.scaleOf(t,i,s))),g={target:r,editor:h,worldOrigin:d,scaleX:i,scaleY:s,transform:c};this.emitEvent(new ht(ht.BEFORE_SCALE,g));const u=new ht(ht.SCALE,g);this.doScale(u),this.emitEvent(u)}flip(t){if(!this.checkTransform("resizeable"))return;const{target:i,single:s,editor:o}=this.editBox,r=this.getWorldOrigin("center"),n=s?new e.Matrix(e.LeafHelper.getFlipTransform(i,t)):this.getChangedTransform(()=>i.safeChange(()=>i.flip(t))),a={target:i,editor:o,worldOrigin:r,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:n};this.emitEvent(new ht(ht.BEFORE_SCALE,a));const h=new ht(ht.SCALE,a);this.doScale(h),this.emitEvent(h)}rotateOf(t,i){if(!this.checkTransform("rotateable"))return;const{target:s,mergeConfig:o,single:r,editor:n}=this.editBox,{beforeRotate:a}=o;if(a){const o=a({target:s,origin:t,rotation:i});if(e.isNumber(o))i=o;else if(!1===o)return}const h=this.getWorldOrigin(t),l=!r&&this.getChangedTransform(()=>s.safeChange(()=>s.rotateOf(t,i))),d={target:s,editor:n,worldOrigin:h,rotation:i,transform:l};this.emitEvent(new lt(lt.BEFORE_ROTATE,d));const c=new lt(lt.ROTATE,d);this.doRotate(c),this.emitEvent(c)}skewOf(t,i,s=0,o){if(!this.checkTransform("skewable"))return;const{target:r,mergeConfig:n,single:a,editor:h}=this.editBox,{beforeSkew:l}=n;if(l){const o=l({target:r,origin:t,skewX:i,skewY:s});if(e.isObject(o))i=o.skewX,s=o.skewY;else if(!1===o)return}const d=this.getWorldOrigin(t),c=!a&&this.getChangedTransform(()=>r.safeChange(()=>r.skewOf(t,i,s))),g={target:r,editor:h,worldOrigin:d,skewX:i,skewY:s,transform:c};this.emitEvent(new dt(dt.BEFORE_SKEW,g));const u=new dt(dt.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:i}=this.editBox;return i.getWorldPoint(e.LeafHelper.getInnerOrigin(i,t))}getChangedTransform(t){const{target:i,single:s}=this.editBox;if(!s&&!i.canChange)return i.changedTransform;const o=new e.Matrix(i.worldTransform);return t(),new e.Matrix(i.worldTransform).divide(o)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}t.Editor=class extends e.Group{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,i){super(i),this.leafList=new e.LeafList,this.openedGroupList=new e.LeafList,this.simulateTarget=new nt(this),this.editBox=new F(this),this.editToolList={},this.selector=new b(this),this.editMask=new W(this),this.targetEventIds=[];let s=e.DataHelper.clone(U);t&&(s=e.DataHelper.default(t,s)),this.mergedConfig=this.config=s,this.addMany(this.editMask,this.selector,this.editBox),e.Plugin.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.isArray(t)?t:[t]:[i]}s[0]&&s[0][i]!==(t||!1)&&s.forEach(s=>e.DataHelper.stintSet(s,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&&X(this),this.update()}getEditTool(t){return this.editToolList[t]=this.editToolList[t]||Q.get(t,this)}updateEditTool(){if(this.unloadEditTool(),this.editing){const t=this.element;let i=t.editOuter||"EditTool";const{beforeEditOuter:s}=this.mergeConfig;if(s){const o=s({target:t,name:i});if(e.isString(o))i=o;else if(!1===o)return}if(Q.list[i]){const t=this.editTool=this.getEditTool(i);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(it.BEFORE_GROUP),this.target=j.group(this.list,this.element,t),this.emitGroupEvent(it.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach(t=>t.isBranch&&this.emitGroupEvent(it.BEFORE_UNGROUP,t)),this.target=j.ungroup(t),t.forEach(t=>t.isBranch&&this.emitGroupEvent(it.UNGROUP,t))),this.list}openGroup(t){this.emitGroupEvent(it.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(it.OPEN,t)}closeGroup(t){this.emitGroupEvent(it.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(it.CLOSE,t)}checkOpenedGroups(){const t=this.openedGroupList;if(t.length){let{list:i}=t;this.editing&&(i=[],t.forEach(t=>this.list.every(i=>!e.LeafHelper.hasParent(i,t))&&i.push(t))),i.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 it(t,{editTarget:e});this.emitEvent(i),e&&e.emitEvent(i)}getInnerEditor(t){return this.editToolList[t]=this.editToolList[t]||Q.get(t,this)}openInnerEditor(t,i,s){let o;if(e.isString(i)?o=i:s||(s=i),t&&s&&(this.target=t),this.single){t||(t=this.element),o||(o=t.editInner);const{beforeEditInner:i}=this.mergeConfig;if(i){const s=i({target:t,name:o});if(e.isString(s))o=s;else if(!1===s)return}Q.list[o]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.getInnerEditor(o),this.innerEditor.editTarget=t,this.emitInnerEvent(et.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(et.OPEN))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(et.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(et.CLOSE),t||this.updateEditTool(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new et(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&&(j.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(j.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:i,targetLeafer:s,editMask:o}=this;this.targetEventIds=[i.on_(e.RenderEvent.START,this.onRenderStart,this),s&&s.on_(e.PropertyEvent.SCROLL,this.onChildScroll,this),t.on_(e.RenderEvent.CHILD_START,this.onAppRenderStart,this),t.on_(e.LeaferEvent.UPDATE_MODE,t=>{t.mode&&"normal"!==t.mode&&this.cancel()})],o.visible&&o.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())}},s([(t,i)=>{e.defineKey(t,i,{get(){const{config:t,element:i,dragPoint:s,editBox:o,editTool:r,innerEditor:n,app:a}=this,h=Object.assign({},t);if(n?n.editConfig&&Object.assign(h,n.editConfig):r&&r.editConfig&&Object.assign(h,r.editConfig),i&&i.editConfig){let{editConfig:t}=i;(t.hover||t.hoverStyle)&&(t=Object.assign({},t),delete t.hover,delete t.hoverStyle),Object.assign(h,t)}return o.config&&Object.assign(h,o.config),s&&(s.editConfig&&Object.assign(h,s.editConfig),"font-size"===h.editSize&&(h.lockRatio=!0),"resize-rotate"===s.pointType&&(h.around||(h.around="center"),e.isNull(h.lockRatio)&&(h.lockRatio=!0))),e.isUndefined(h.dragLimitAnimate)&&(h.dragLimitAnimate=a&&a.config.pointer.dragLimitAnimate),this.mergedConfig=h}})}],t.Editor.prototype,"mergeConfig",void 0),s([n(function(t,i){const{target:s}=t;s?(t.leafList=s instanceof e.LeafList?s:new e.LeafList(s),t.multiple&&X(t)):(t.simulateTarget.remove(),t.leafList.reset()),t.closeInnerEditor(!0),t.unloadEditTool();const o={editor:t,value:s,oldValue:i};t.emitEvent(new r(r.SELECT,o)),t.checkOpenedGroups(),t.editing?t.waitLeafer(()=>{t.updateEditTool(),t.listenTargetEvents()}):(t.updateEditTool(),t.removeTargetEvents()),t.emitEvent(new r(r.AFTER_SELECT,o))})],t.Editor.prototype,"target",void 0),s([n(function(t,e){t.emitEvent(new r(r.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))})],t.Editor.prototype,"hoverTarget",void 0),t.Editor=s([i.useModule(ct,["editBox","editTool","emitEvent"])],t.Editor);class gt{static registerInnerEditor(){Q.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 e.Group,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)}}t.EditTool=class extends gt{static registerEditTool(){Q.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()}},t.EditTool=s([q()],t.EditTool);const{left:ut,right:ft}=e.Direction9,{move:pt,copy:Et,toNumberPoints:mt}=e.PointHelper;return t.LineEditTool=class extends t.EditTool{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:i,direction:s,lockRatio:o,around:r}=t,n=t.target,a=s===ut;if(n.pathInputed){const{path:t}=n.__,{from:e,to:s}=this.getFromToByPath(t);this.dragPoint(e,s,a,r,this.getInnerMove(n,i,o)),t[1]=e.x,t[2]=e.y,t[4]=s.x,t[5]=s.y,n.path=t}else if(n.points){const{points:t}=n,{from:e,to:s}=this.getFromToByPoints(t);this.dragPoint(e,s,a,r,this.getInnerMove(n,i,o)),t[0]=e.x,t[1]=e.y,t[2]=s.x,t[3]=s.y,n.points=t}else{const t=e.getPointData(),{toPoint:s}=n;n.rotation=0,this.dragPoint(t,s,a,r,this.getInnerMove(n,i,o)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(s,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(s,null,null,!0),n.toPoint=s}}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=mt(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?(pt(t,r,n),s&&pt(e,-r,-n)):(s&&pt(t,-r,-n),pt(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),Et(s[7],i),Et(e[7],i),Et(s[3],a),Et(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===ut||t===ft,s[t].visible=a,e[t].visible=!n&&a}},t.LineEditTool=s([q()],t.LineEditTool),e.Plugin.add("editor","resize"),e.Creator.editor=function(e,i){const s=new t.Editor(e);return i&&i.sky.add(i.editor=s),s},e.Box.addAttr("textBox",!1,e.dataType),e.UI.addAttr("editConfig",void 0,e.dataType),e.UI.addAttr("editOuter",t=>(t.updateLayout(),t.__.__isLinePath?"LineEditTool":"EditTool"),e.dataType),e.UI.addAttr("editInner","PathEditor",e.dataType),e.Group.addAttr("editInner","",e.dataType),e.Text.addAttr("editInner","TextEditor",e.dataType),e.UI.setEditConfig=function(t){this.changeAttr("editConfig",t)},e.UI.setEditOuter=function(t){this.changeAttr("editOuter",t)},e.UI.setEditInner=function(t){this.changeAttr("editInner",t)},t.EditBox=F,t.EditDataHelper=R,t.EditPoint=I,t.EditSelect=b,t.EditSelectHelper=p,t.EditToolCreator=Q,t.EditorEvent=r,t.EditorGroupEvent=it,t.EditorHelper=j,t.EditorMoveEvent=at,t.EditorRotateEvent=lt,t.EditorScaleEvent=ht,t.EditorSkewEvent=dt,t.InnerEditor=gt,t.InnerEditorEvent=et,t.SelectArea=f,t.Stroker=u,t.TransformTool=ct,t.registerEditTool=q,t.registerInnerEditor=J,t}({},LeaferUI,LeaferUI); //# sourceMappingURL=editor.min.js.map