@leafer-in/editor 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- this.LeaferIN=this.LeaferIN||{},this.LeaferIN.editor=function(t,e,i){"use strict";function o(t,e,i,o){var s,n=arguments.length,r=n<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,o);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(n<3?s(r):n>3?s(e,i,r):s(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function s(t){return t?t instanceof Array?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class n extends e.Event{get list(){return s(this.value)}get oldList(){return s(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}function r(t){return(i,o)=>{const s="_"+o;e.defineKey(i,o,{get(){return this[s]},set(e){const i=this[s];if(i!==e){if(this.config){const t="target"===o;if(t){e instanceof Array&&e.length>1&&e[0].locked&&e.splice(0,1);const{beforeSelect:t}=this.config;if(t){const i=t({target:e});if("object"==typeof i)e=i;else if(!1===i)return}}const s=t?n.BEFORE_SELECT:n.BEFORE_HOVER;this.hasEvent(s)&&this.emitEvent(new n(s,{editor:this,value:e,oldValue:i}))}this[s]=e,t(this,i)}}})}}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:a}=Math,{copy:h,scale:l}=e.MatrixHelper,{setListWithFn:d}=e.BoundsHelper,{worldBounds:c}=e.LeafBoundsHelper,g=e.getMatrixData(),u=e.getBoundsData();class f extends e.UI{constructor(){super(),this.list=[],this.visible=0,this.hittable=!1,this.strokeAlign="center"}setTarget(t,e){this.set(e),this.target=t,this.update()}update(){const{list:t}=this;t.length?(d(u,t,c),this.set(u),this.visible=!0):this.visible=0}__draw(t,i){const{list:o}=this;if(o.length){let s;const n=this.__,{stroke:r,strokeWidth:d,fill:c}=n,{bounds:u}=i;for(let f=0;f<o.length;f++){s=o[f];const{worldTransform:p,worldRenderBounds:E}=s;if(E.width&&E.height&&(!u||u.hit(E,i.matrix))){const o=a(p.scaleX),u=a(p.scaleY);if(h(g,p),g.half=d%2,o!==u){l(g,1/o,1/u),t.setWorld(g,i.matrix),t.beginPath(),n.strokeWidth=d;const{x:e,y:r,width:a,height:h}=s.__layout.boxBounds;t.rect(e*o,r*u,a*o,h*u)}else t.setWorld(g,i.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),n.strokeWidth=d/a(p.scaleX);r&&("string"==typeof r?e.Paint.stroke(r,this,t):e.Paint.strokes(r,this,t)),c&&("string"==typeof c?e.Paint.fill(c,this,t):e.Paint.fills(c,this,t))}}n.strokeWidth=d}}destroy(){this.target=null,super.destroy()}}o([r((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[]}))],f.prototype,"target",void 0);class p 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:o,strokeWidth:s}=t;this.visible=i,this.strokeArea.reset(Object.assign({stroke:o,strokeWidth:s},e||{})),this.fillArea.reset({visible:!e,fill:o,opacity:.2})}setBounds(t){this.strokeArea.set(t),this.fillArea.set(t)}}const E={findOne:t=>t.list.find((t=>t.editable)),findByBounds(t,e){const i=[];return v([t],i,e),i}};function v(t,e,i){let o,s;for(let n=0,r=t.length;n<r;n++)if(o=t[n],s=o.__,s.hittable&&s.visible&&!s.locked&&i.hit(o.__world)){if(s.editable){if(o.isBranch&&!s.hitChildren){s.hitSelf&&e.push(o);continue}if(o.isFrame){if(i.includes(o.__layout.boxBounds,o.__world)){e.push(o);continue}}else i.hit(o.__layout.boxBounds,o.__world)&&s.hitSelf&&e.push(o)}o.isBranch&&v(o.children,e,i)}}const{findOne:m,findByBounds:b}=E;class w extends e.Group{get dragging(){return!!this.originList}get running(){const{editor:t}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new f,this.targetStroker=new f,this.bounds=new e.Bounds,this.selectArea=new p,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:o,hoverStyle:s}=t.mergeConfig;this.hoverStroker.setTarget(o?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},s||{}))}}onSelect(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:o,selectedStyle:s}=t;this.targetStroker.setTarget(e,Object.assign({stroke:i,strokeWidth:Math.max(1,o/2)},s||{})),this.hoverStroker.target=null}}update(){this.hoverStroker.update(),this.targetStroker.update()}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.interaction.canHover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){if(t.multiTouch)return;const{select:e}=this.editor.mergeConfig;"press"===e&&(this.app.config.mobile?this.waitSelect=()=>this.checkAndSelect(t):this.checkAndSelect(t))}onTap(t){if(t.multiTouch)return;const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i?this.checkAndSelect(t):this.waitSelect&&this.waitSelect(),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(!t.multiTouch&&(this.waitSelect&&this.waitSelect(),this.allowDrag(t))){const{editor:e}=this,{stroke:i,area:o}=e.mergeConfig,{x:s,y:n}=t.getInnerPoint(this);this.bounds.set(s,n),this.selectArea.setStyle({visible:!0,stroke:i,x:s,y:n},o),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,o=t.getInnerTotal(this),s=this.bounds.clone().unsign(),n=new e.LeafList(b(i.app,s));if(this.bounds.width=o.x,this.bounds.height=o.y,this.selectArea.setBounds(s.get()),n.length){const t=[];this.originList.forEach((e=>{n.has(e)||t.push(e)})),n.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)||t.shiftKey&&!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&&(t.shiftKey||i)}__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_([[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:L,top:y,topRight:k,right:x,bottomRight:T,bottom:O,bottomLeft:_,left:S}=e.Direction9,{toPoint:M}=e.AroundHelper,{within:B}=e.MathHelper,C={getScaleData(t,i,o,s,n,r,a,h){let l,d={},c=1,g=1;const{boxBounds:u,widthRange:f,heightRange:p,dragBounds:E,worldBoxBounds:v}=t,{width:m,height:b}=i;r&&(s.x*=2,s.y*=2);const w=t.scaleX/i.scaleX,C=t.scaleY/i.scaleY,P=w<0?-1:1,R=C<0?-1:1,H=h?w:P*u.width/m,I=h?C:R*u.height/b;s.x*=h?w:P,s.y*=h?C:R;const V=(-s.y+b)/b,D=(s.x+m)/m,A=(s.y+b)/b,F=(-s.x+m)/m;switch(o){case y:g=V,l="bottom";break;case x:c=D,l="left";break;case O:g=A,l="top";break;case S:c=F,l="right";break;case L:g=V,c=F,l="bottom-right";break;case k:g=V,c=D,l="bottom-left";break;case T:g=A,c=D,l="top-left";break;case _:g=A,c=F,l="top-right"}if(n)if("corner"===n&&o%2)n=!1;else{let t;switch(o){case y:case O:t=g;break;case S:case x:t=c;break;default:t=Math.sqrt(Math.abs(c*g))}c=c<0?-t:t,g=g<0?-t:t}const Z=1!==c,z=1!==g;if(Z&&(c/=H),z&&(g/=I),!a){const{worldTransform:e}=t;c<0&&(c=1/u.width/e.scaleX),g<0&&(g=1/u.height/e.scaleY)}if(M(r||l,u,d,!0),E){const i="parent"===E?t.parent.boxBounds:E,o=new e.Bounds(t.__localBoxBounds);if(o.scaleOf(t.getLocalPointByInner(d),c,g),!e.BoundsHelper.includes(i,o)){const t=o.getIntersect(i),e=t.width/o.width,s=t.height/o.height;Z&&(c*=e),z&&(g*=s)}}if(Z&&f){const e=u.width*t.scaleX;c=B(e*c,f)/e}if(z&&p){const e=u.height*t.scaleY;g=B(e*g,p)/e}return Z&&Math.abs(c*v.width)<1&&(c=(c<0?-1:1)/v.width),z&&Math.abs(g*v.height)<1&&(g=(g<0?-1:1)/v.height),n&&c!==g&&(g=c=Math.min(c,g)),{origin:d,scaleX:c,scaleY:g,direction:o,lockRatio:n,around:r}},getRotateData(t,i,o,s,n){let r,a={};switch(i){case L:r="bottom-right";break;case k:r="bottom-left";break;case T:r="top-left";break;case _:r="top-right";break;default:r="center"}return M(n||r,t.boxBounds,a,!0),{origin:a,rotation:e.PointHelper.getRotation(s,t.getWorldPointByBox(a),o)}},getSkewData(t,i,o,s){let n,r,a={},h=0,l=0;switch(i){case y:case L:r={x:.5,y:0},n="bottom",h=1;break;case O:case T:r={x:.5,y:1},n="top",h=1;break;case S:case _:r={x:0,y:.5},n="right",l=1;break;case x:case k:r={x:1,y:.5},n="left",l=1}const{width:d,height:c}=t;r.x=r.x*d,r.y=r.y*c,M(s||n,t,a,!0);const g=e.PointHelper.getRotation(r,a,{x:r.x+(h?o.x:0),y:r.y+(l?o.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 S:t=x;break;case L:t=k;break;case _:t=T;break;case x:t=S;break;case k:t=L;break;case T:t=_}if(i)switch(t){case y:t=O;break;case L:t=_;break;case k:t=T;break;case O:t=y;break;case _:t=L;break;case T:t=k}return t}},P={};function R(t,i){const{enterPoint:o}=t;if(!o||!t.editor.editing||!t.visible)return;if("circle"===o.name)return;if("button"===o.pointType)return void(o.cursor||(o.cursor="pointer"));let{rotation:s,flippedX:n,flippedY:r}=t;const{pointType:a}=o,{resizeCursor:h,rotateCursor:l,skewCursor:d,resizeable:c,rotateable:g,skewable:u}=t.mergeConfig;let f=a.includes("resize");f&&g&&(i.metaKey||i.ctrlKey||!c)&&(f=!1);const p=u&&!f&&("resize-line"===o.name||"skew"===a)?d:f?h:l;s+=45*(C.getFlipDirection(o.direction,n,r)+1),s=2*Math.round(e.MathHelper.formatRotation(s,!0)/2);const{url:E,x:v,y:m}=p,b=E+s;P[b]?o.cursor=P[b]:P[b]=o.cursor={url:I(E,s),x:v,y:m}}function H(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.rect.cursor=i?e:void 0}function I(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class V extends e.Box{constructor(t){super(t),this.useFastShadow=!0}}const D=["top","right","bottom","left"],A=void 0;class F extends e.Group{get mergeConfig(){const{config:t}=this,{mergeConfig:e}=this.editor;return this.mergedConfig=t?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}constructor(t){super(),this.view=new e.Group,this.rect=new e.Box({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new V({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:o,resizePoints:s,rotatePoints:n,resizeLines:r,rect:a,circle:h,buttons:l}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let o=0;o<8;o++)t=new V({name:"rotate-point",around:d[o],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",o),o%2&&(e=new V({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",o)),i=new V({name:"resize-point",hitRadius:5}),s.push(i),this.listenPointEvents(i,"resize",o);this.listenPointEvents(h,"rotate",2),o.addMany(...n,a,h,l,...r,...s),this.add(o)}load(){const{target:t,mergeConfig:e,single:i,rect:o,circle:s,resizePoints:n}=this,{stroke:r,strokeWidth:a}=e,h=this.getPointsStyle(),l=this.getMiddlePointsStyle();let d;for(let t=0;t<8;t++)d=n[t],d.set(this.getPointStyle(t%2?l[(t-1)/2%l.length]:h[t/2%h.length])),t%2||(d.rotation=t/2*90);s.set(this.getPointStyle(e.circle||e.rotatePoint||h[0])),o.set(Object.assign({stroke:r,strokeWidth:a,editConfig:A},e.rect||{}));const c=i&&this.transformTool.editTool;o.hittable=!c,o.syncEventer=c&&this.editor,c&&(t.syncEventer=o,this.app.interaction.bottomList=[{target:o,proxy:t}]),H(this)}update(){const{editor:t}=this,{x:e,y:i,scaleX:o,scaleY:s,rotation:n,skewX:r,skewY:a,width:h,height:l}=this.target.getLayoutBounds("box",t,!0);this.set({x:e,y:i,scaleX:o,scaleY:s,rotation:n,skewX:r,skewY:a}),this.updateBounds({x:0,y:0,width:h,height:l})}updateBounds(t){const{editMask:i}=this.editor,{mergeConfig:o,single:s,rect:n,circle:r,buttons:a,resizePoints:h,rotatePoints:l,resizeLines:d}=this,{middlePoint:c,resizeable:g,rotateable:u,hideOnSmall:f,editBox:p,mask:E}=o;if(this.visible=!this.target.locked,i.visible=!!E||0,this.view.worldOpacity){const{width:i,height:E}=t,v="number"==typeof f?f:10,m=p&&!(f&&i<v&&E<v);let b,w,L,y={};for(let s=0;s<8;s++)e.AroundHelper.toPoint(e.AroundHelper.directionData[s],t,y),w=h[s],b=l[s],L=d[Math.floor(s/2)],w.set(y),b.set(y),L.set(y),w.visible=L.visible=m&&!(!g&&!u),b.visible=m&&u&&g&&!o.rotatePoint,s%2&&(w.visible=b.visible=m&&!!c,(s+1)/2%2?(L.width=i,f&&2*w.width>i&&(w.visible=!1)):(L.height=E,w.rotation=90,f&&2*w.width>E&&(w.visible=!1)));r.visible=m&&u&&!(!o.circle&&!o.rotatePoint),r.visible&&this.layoutCircle(),n.path&&(n.path=null),n.set(Object.assign(Object.assign({},t),{visible:!s||p})),a.visible=m&&a.children.length>0||0,a.visible&&this.layoutButtons()}else n.set(t)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:o,middlePoint:s}=this.mergedConfig,n=D.indexOf(t||(this.buttons.children.length&&"bottom"===o?"top":"bottom"));this.setButtonPosition(this.circle,n,e||i,!!s)}layoutButtons(){const{buttons:t}=this,{buttonsDirection:e,buttonsFixed:i,buttonsMargin:o,middlePoint:s}=this.mergedConfig,{flippedX:n,flippedY:r}=this;let a=D.indexOf(e);(a%2&&n||(a+1)%2&&r)&&i&&(a=(a+2)%4);const h=i?C.getRotateDirection(a,this.flippedOne?this.rotation:-this.rotation,4):a;this.setButtonPosition(t,h,o,!!s),i&&(t.rotation=90*(h-a)),t.scaleX=n?-1:1,t.scaleY=r?-1:1}setButtonPosition(t,e,i,o){const s=this.resizePoints[2*e+1],n=e%2,r=e&&3!==e?1:-1,a=(i+(e%2?(o?s.width:0)+t.boxBounds.width:(o?s.height:0)+t.boxBounds.height)/2)*r;n?(t.x=s.x+a,t.y=s.y):(t.x=s.x,t.y=s.y+a)}unload(){this.visible=!1}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:o,pointSize:s,pointRadius:n}=this.mergedConfig,r={fill:o,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:s,height:s,cornerRadius:n,offsetX:0,offsetY:0,editConfig:A};return t?Object.assign(r,t):r}getPointsStyle(){const{point:t}=this.mergedConfig;return t instanceof Array?t:[t]}getMiddlePointsStyle(){const{middlePoint:t}=this.mergedConfig;return t instanceof Array?t:t?[t]:this.getPointsStyle()}onSelect(t){1===t.oldList.length&&(t.oldList[0].syncEventer=null,this.app&&(this.app.interaction.bottomList=null))}onDragStart(t){this.dragging=!0;const i=this.dragPoint=t.current,{pointType:o}=i,{editor:s,dragStartData:n}=this,{target:r}=this;"rect"===i.name&&(this.moving=!0,s.opacity=this.mergeConfig.hideOnMove?0:1),n.x=t.x,n.y=t.y,n.point={x:r.x,y:r.y},n.bounds=Object.assign({},r.getLayoutBounds("box","local")),n.rotation=r.rotation,o&&o.includes("resize")&&(e.ResizeEvent.resizingKeys=s.leafList.keys)}onDragEnd(t){this.dragging=!1,this.dragPoint=null,this.moving=!1;const{name:i,pointType:o}=t.current;"rect"===i&&(this.editor.opacity=1),o&&o.includes("resize")&&(e.ResizeEvent.resizingKeys=null)}onDrag(t){const{transformTool:e}=this,i=t.current;if("rect"===i.name)e.onMove(t),H(this);else{const{pointType:o}=this.enterPoint=i;o.includes("rotate")||t.metaKey||t.ctrlKey||!this.mergeConfig.resizeable?(e.onRotate(t),"resize-rotate"===o&&e.onScale(t)):"resize"===o&&e.onScale(t),"skew"===o&&e.onSkew(t),R(this,t)}}onKey(t){R(this,t)}onArrow(t){const{editor:e}=this;if(e.editing&&this.mergeConfig.keyEvent){let i=0,o=0;const s=t.shiftKey?10:1;switch(t.code){case"ArrowDown":o=s;break;case"ArrowUp":o=-s;break;case"ArrowLeft":i=-s;break;case"ArrowRight":i=s}(i||o)&&e.move(i,o)}}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:o}=this;if(this.single){if(o.locked)return;if(o.isBranch&&!o.editInner){if(o.textBox){const{children:t}=o,s=t.find((t=>t.editable&&t instanceof e.Text))||t.find((t=>t instanceof e.Text));if(s)return i.openInnerEditor(s)}i.openGroup(o),i.target=i.selector.findDeepOne(t)}else i.openInnerEditor()}}listenPointEvents(t,e,o){t.direction=o,t.pointType=e;const s=[[i.DragEvent.START,this.onDragStart,this],[i.DragEvent.DRAG,this.onDrag,this],[i.DragEvent.END,this.onDragEnd,this],[i.PointerEvent.LEAVE,()=>{this.enterPoint=null}]];"circle"!==t.name&&s.push([i.PointerEvent.ENTER,e=>{this.enterPoint=t,R(this,e)}]),this.__eventIds.push(t.on_(s))}__listenEvents(){const{rect:t,editor:e,__eventIds:o}=this;o.push(e.on_(n.SELECT,this.onSelect,this),t.on_([[i.DragEvent.START,this.onDragStart,this],[i.DragEvent.DRAG,this.onDrag,this],[i.DragEvent.END,this.onDragEnd,this],[i.PointerEvent.ENTER,()=>H(this)],[i.PointerEvent.DOUBLE_TAP,this.onDoubleTap,this],[i.PointerEvent.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer((()=>{o.push(e.app.on_([[[i.KeyEvent.HOLD,i.KeyEvent.UP],this.onKey,this],[i.KeyEvent.DOWN,this.onArrow,this]]))}))}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const Z={x:0,y:0,width:1e5,height:1e5};class z 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:o}=i.mergedConfig;if(o&&i.editing){if(t.fillWorld(t.bounds,!0===o?"rgba(0,0,0,0.8)":o),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:o}=i;o&&o.textBox&&o.__renderShape(t,e)})),t.restoreBlendMode()}}destroy(){this.editor=null,super.destroy()}}const W='\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"/>',G={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${W}\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${W}\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${W}\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},U=new e.Bounds;function X(t){const{simulateTarget:e,list:i}=t,{zoomLayer:o}=i[0].leafer;e.safeChange((()=>{U.setListWithFn(i,(t=>t.getBounds("box","page"))),0===U.width&&(U.width=.1),0===U.height&&(U.height=.1),e.reset(U.get())})),o.add(e)}const Y=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),j=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),N={group(t,i,o){t.sort(j);const{app:s,parent:n}=t[0];let r;r=o&&o.add?o:new e.Group(o),n.addAt(r,n.children.indexOf(t[0])),t.sort(Y);const a=new e.Matrix(i.worldTransform);return a.divideParent(n.worldTransform),r.setTransform(a),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:o}=t;for(;o.length;)i.push(o[0]),o[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(j),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},K=e.Debug.get("EditToolCreator");function $(){return t=>{J.register(t)}}const q=$,J={list:{},register(t){const{tag:e}=t.prototype;Q[e]&&K.repeat(e),Q[e]=t},get:(t,e)=>new Q[t](e)},{list:Q}=J;class tt extends n{constructor(t,e){super(t,e)}}tt.BEFORE_OPEN="innerEditor.before_open",tt.OPEN="innerEditor.open",tt.BEFORE_CLOSE="innerEditor.before_close",tt.CLOSE="innerEditor.close";class et extends n{constructor(t,e){super(t,e)}}et.BEFORE_GROUP="editor.before_group",et.GROUP="editor.group",et.BEFORE_UNGROUP="editor.before_ungroup",et.UNGROUP="editor.ungroup",et.BEFORE_OPEN="editor.before_open_group",et.OPEN="editor.open_group",et.BEFORE_CLOSE="editor.before_close_group",et.CLOSE="editor.close_group";const{updateMatrix:it}=e.LeafHelper,ot={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},st="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.on(e.PropertyEvent.CHANGE,(i=>{if(this.checkChange&&ot[i.attrName]){const{attrName:o,newValue:s,oldValue:n}=i,r="s"===o[0]?(s||1)/(n||1):(s||0)-(n||0);this.canChange=!1;const a=this.__;a[o]=n,it(this.parent),it(this);const h=new e.Matrix(this.__world);switch(a[o]=s,this.__layout.rotationChange(),it(this),this.changedTransform=new e.Matrix(this.__world).divide(h),o){case"x":t.move(r,0);break;case"y":t.move(0,r);break;case"rotation":t.rotateOf(st,r);break;case"scaleX":t.scaleOf(st,r,1);break;case"scaleY":t.scaleOf(st,1,r);break;case"skewX":t.skewOf(st,r,0);break;case"skewY":t.skewOf(st,0,r)}this.canChange=!0}}))}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class rt extends n{constructor(t,e){super(t,e)}}rt.BEFORE_MOVE="editor.before_move",rt.MOVE="editor.move";class at extends n{constructor(t,e){super(t,e)}}at.BEFORE_SCALE="editor.before_scale",at.SCALE="editor.scale";class ht extends n{constructor(t,e){super(t,e)}}ht.BEFORE_ROTATE="editor.before_rotate",ht.ROTATE="editor.rotate";class lt extends n{constructor(t,e){super(t,e)}}lt.BEFORE_SKEW="editor.before_skew",lt.SKEW="editor.skew";class dt{onMove(t){const{target:e,mergeConfig:o,dragStartData:s}=this.editBox;if(t instanceof i.MoveEvent){if("drag"!==t.moveType){const{moveable:i,resizeable:s}=o,n=t.getLocalMove(e);"move"===i?(t.stop(),this.move(n.x,n.y)):"zoom"===s&&t.stop()}}else{const o={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(o.x)>Math.abs(o.y)?o.y=0:o.x=0),this.move(i.DragEvent.getValidMove(e,s.point,o))}}onScale(t){const{target:e,mergeConfig:o,single:s,dragStartData:n}=this.editBox;let{around:r,lockRatio:a,resizeable:h,flipable:l,editSize:d}=o;if(t instanceof i.ZoomEvent)"zoom"===h&&(t.stop(),this.scaleOf(e.getBoxPoint(t),t.scale,t.scale));else{const{direction:i}=t.current;(t.shiftKey||e.lockRatio)&&(a=!0);const o=C.getScaleData(e,n.bounds,i,t.getInnerTotal(e),a,C.getAround(r,t.altKey),l,!s||"scale"===d);this.editTool&&this.editTool.onScaleWithDrag?(o.drag=t,this.scaleWithDrag(o)):this.scaleOf(o.origin,o.scaleX,o.scaleY)}}onRotate(t){const{target:o,mergeConfig:s,dragStartData:n}=this.editBox,{skewable:r,rotateable:a,around:h,rotateGap:l}=s,{direction:d,name:c}=t.current;if(r&&"resize-line"===c)return this.onSkew(t);let g,u;if(t instanceof i.RotateEvent){if("rotate"!==a)return;t.stop(),u=t.rotation,g=o.getBoxPoint(t),o.scaleX*o.scaleY<0&&(u=-u)}else{const e=C.getRotateData(o,d,t,n,t.shiftKey?null:o.around||o.origin||h||"center");u=e.rotation,g=e.origin}o.scaleX*o.scaleY<0&&(u=-u),t instanceof i.DragEvent&&(u=n.rotation+u-o.rotation),u=e.MathHelper.float(e.MathHelper.getGapRotation(u,l,o.rotation),2),u&&this.rotateOf(g,u)}onSkew(t){const{target:e,mergeConfig:i}=this.editBox,{around:o}=i,{origin:s,skewX:n,skewY:r}=C.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),C.getAround(o,t.altKey));(n||r)&&this.skewOf(s,n,r)}move(t,e=0){if(!this.checkTransform("moveable"))return;"object"==typeof t&&(e=t.y,t=t.x);const{target:i,mergeConfig:o,single:s,editor:n}=this.editBox,{beforeMove:r}=o;if(r){const o=r({target:i,x:t,y:e});if("object"==typeof o)t=o.x,e=o.y;else if(!1===o)return}const a=i.getWorldPointByLocal({x:t,y:e},null,!0);s||i.safeChange((()=>i.move(t,e)));const h={target:i,editor:n,moveX:a.x,moveY:a.y};this.emitEvent(new rt(rt.BEFORE_MOVE,h));const l=new rt(rt.MOVE,h);this.doMove(l),this.emitEvent(l)}scaleWithDrag(t){if(!this.checkTransform("resizeable"))return;const{target:e,mergeConfig:i,editor:o}=this.editBox,{beforeScale:s}=i;if(s){const{origin:i,scaleX:o,scaleY:n,drag:r}=t;if(!1===s({target:e,drag:r,origin:i,scaleX:o,scaleY:n}))return}t=Object.assign(Object.assign({},t),{target:e,editor:o,worldOrigin:e.getWorldPoint(t.origin)}),this.emitEvent(new at(at.BEFORE_SCALE,t));const n=new at(at.SCALE,t);this.editTool.onScaleWithDrag(n),this.emitEvent(n)}scaleOf(t,e,i=e,o){if(!this.checkTransform("resizeable"))return;const{target:s,mergeConfig:n,single:r,editor:a}=this.editBox,{beforeScale:h}=n;if(h){const o=h({target:s,origin:t,scaleX:e,scaleY:i});if("object"==typeof o)e=o.scaleX,i=o.scaleY;else if(!1===o)return}const l=this.getWorldOrigin(t),d=!r&&this.getChangedTransform((()=>s.safeChange((()=>s.scaleOf(t,e,i))))),c={target:s,editor:a,worldOrigin:l,scaleX:e,scaleY:i,transform:d};this.emitEvent(new at(at.BEFORE_SCALE,c));const g=new at(at.SCALE,c);this.doScale(g),this.emitEvent(g)}flip(t){if(!this.checkTransform("resizeable"))return;const{target:i,single:o,editor:s}=this.editBox,n=this.getWorldOrigin("center"),r=o?new e.Matrix(e.LeafHelper.getFlipTransform(i,t)):this.getChangedTransform((()=>i.safeChange((()=>i.flip(t))))),a={target:i,editor:s,worldOrigin:n,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:r};this.emitEvent(new at(at.BEFORE_SCALE,a));const h=new at(at.SCALE,a);this.doScale(h),this.emitEvent(h)}rotateOf(t,e){if(!this.checkTransform("rotateable"))return;const{target:i,mergeConfig:o,single:s,editor:n}=this.editBox,{beforeRotate:r}=o;if(r){const o=r({target:i,origin:t,rotation:e});if("number"==typeof o)e=o;else if(!1===o)return}const a=this.getWorldOrigin(t),h=!s&&this.getChangedTransform((()=>i.safeChange((()=>i.rotateOf(t,e))))),l={target:i,editor:n,worldOrigin:a,rotation:e,transform:h};this.emitEvent(new ht(ht.BEFORE_ROTATE,l));const d=new ht(ht.ROTATE,l);this.doRotate(d),this.emitEvent(d)}skewOf(t,e,i=0,o){if(!this.checkTransform("skewable"))return;const{target:s,mergeConfig:n,single:r,editor:a}=this.editBox,{beforeSkew:h}=n;if(h){const o=h({target:s,origin:t,skewX:e,skewY:i});if("object"==typeof o)e=o.skewX,i=o.skewY;else if(!1===o)return}const l=this.getWorldOrigin(t),d=!r&&this.getChangedTransform((()=>s.safeChange((()=>s.skewOf(t,e,i))))),c={target:s,editor:a,worldOrigin:l,skewX:e,skewY:i,transform:d};this.emitEvent(new lt(lt.BEFORE_SKEW,c));const g=new lt(lt.SKEW,c);this.doSkew(g),this.emitEvent(g)}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:o}=this.editBox;if(!o&&!i.canChange)return i.changedTransform;const s=new e.Matrix(i.worldTransform);return t(),new e.Matrix(i.worldTransform).divide(s)}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 dragging(){return this.editBox.dragging}get moving(){return this.editBox.moving}get dragPoint(){return this.editBox.dragPoint}get element(){return this.multiple?this.simulateTarget:this.list[0]}get buttons(){return this.editBox.buttons}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 w(this),this.editMask=new z(this),this.targetEventIds=[];let o=e.DataHelper.clone(G);t&&(o=e.DataHelper.default(t,o)),this.mergedConfig=this.config=o,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)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){if(this.editing){if(!this.element.parent)return this.cancel();this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update()}}updateEditBox(){this.multiple&&X(this),this.update()}updateEditTool(){let t=this.editTool;if(t&&(this.editBox.unload(),t.unload(),this.editTool=null),this.editing){const e=this.element.editOuter||"EditTool";t=this.editTool=this.editToolList[e]=this.editToolList[e]||J.get(e,this),this.editBox.load(),t.load(),this.update()}}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,o){}flip(t){}rotateOf(t,e){}skewOf(t,e,i=0,o){}checkTransform(t){}getWorldOrigin(t){}getChangedTransform(t){}group(t){return this.multiple&&(this.emitGroupEvent(et.BEFORE_GROUP),this.target=N.group(this.list,this.element,t),this.emitGroupEvent(et.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach((t=>t.isBranch&&this.emitGroupEvent(et.BEFORE_UNGROUP,t))),this.target=N.ungroup(t),t.forEach((t=>t.isBranch&&this.emitGroupEvent(et.UNGROUP,t)))),this.list}openGroup(t){this.emitGroupEvent(et.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(et.OPEN,t)}closeGroup(t){this.emitGroupEvent(et.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(et.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 et(t,{editTarget:e});this.emitEvent(i),e&&e.emitEvent(i)}openInnerEditor(t,e){if(t&&e&&(this.target=t),this.single){const e=t||this.element,i=e.editInner;i&&J.list[i]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[i]||J.get(i,this),this.innerEditor.editTarget=e,this.emitInnerEvent(tt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(tt.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(tt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(tt.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,o=new tt(t,{editTarget:i,innerEditor:e});this.emitEvent(o),i.emitEvent(o)}lock(){this.list.forEach((t=>t.locked=!0)),this.update()}unlock(){this.list.forEach((t=>t.locked=!1)),this.update()}toTop(){this.list.length&&(N.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(N.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()}listenTargetEvents(){if(!this.targetEventIds.length){const{app:t,leafer:o,editMask:s}=this;this.targetEventIds=[o.on_(e.RenderEvent.START,this.onRenderStart,this),t.on_([[e.RenderEvent.CHILD_START,this.onAppRenderStart,this],[i.MoveEvent.BEFORE_MOVE,this.onMove,this,!0],[i.ZoomEvent.BEFORE_ZOOM,this.onScale,this,!0],[i.RotateEvent.BEFORE_ROTATE,this.onRotate,this,!0]])],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())}},o([(t,i)=>{e.defineKey(t,i,{get(){const{config:t,element:i,dragPoint:o}=this,s=Object.assign({},t);return i&&i.editConfig&&Object.assign(s,i.editConfig),o&&(o.editConfig&&Object.assign(s,o.editConfig),"font-size"===s.editSize&&(s.lockRatio=!0),"resize-rotate"===o.pointType&&(s.around||(s.around="center"),e.isNull(s.lockRatio)&&(s.lockRatio=!0))),this.mergedConfig=s}})}],t.Editor.prototype,"mergeConfig",void 0),o([r((function(t,e){t.emitEvent(new n(n.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],t.Editor.prototype,"hoverTarget",void 0),o([r((function(t,i){const{target:o}=t;o?(t.leafList=o instanceof e.LeafList?o:new e.LeafList(o),t.multiple&&X(t)):(t.simulateTarget.remove(),t.leafList.reset()),t.closeInnerEditor();const s={editor:t,value:o,oldValue:i};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))}))],t.Editor.prototype,"target",void 0),t.Editor=o([i.useModule(dt,["editBox","editTool","emitEvent"])],t.Editor);class ct{static registerInnerEditor(){J.register(this)}get tag(){return"InnerEditor"}get mode(){return"focus"}get editBox(){return this.editor.editBox}constructor(t){this.eventIds=[],this.editor=t,this.create()}onCreate(){}create(){this.view=new 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 ct{static registerEditTool(){J.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:o}=t,{app:s,list:n}=o;s.lockLayout(),n.forEach((t=>{t.moveWorld(e,i)})),s.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:o,worldOrigin:s,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);o?t.transformWorld(o,r):t.scaleOfWorld(s,e,i,r)})),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:o,editor:s}=t,{app:n,list:r}=s;n.lockLayout(),r.forEach((t=>{const n="scale"!==s.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(o,e)})),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:o,worldOrigin:s,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach((t=>{const r="scale"!==n.getEditSize(t);o?t.transformWorld(o,r):t.skewOfWorld(s,e,i,r)})),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){this.editBox.update(),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}},t.EditTool=o([$()],t.EditTool);const{left:gt,right:ut}=e.Direction9,{move:ft,copy:pt,toNumberPoints:Et}=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:o,lockRatio:s,around:n}=t,r=t.target,a=o===gt;if(r.pathInputed){const{path:t}=r.__,{from:e,to:o}=this.getFromToByPath(t);this.dragPoint(e,o,a,n,this.getInnerMove(r,i,s)),t[1]=e.x,t[2]=e.y,t[4]=o.x,t[5]=o.y,r.path=t}else if(r.points){const{points:t}=r,{from:e,to:o}=this.getFromToByPoints(t);this.dragPoint(e,o,a,n,this.getInnerMove(r,i,s)),t[0]=e.x,t[1]=e.y,t[2]=o.x,t[3]=o.y,r.points=t}else{const t=e.getPointData(),{toPoint:o}=r;r.rotation=0,this.dragPoint(t,o,a,n,this.getInnerMove(r,i,s)),r.getLocalPointByInner(t,null,null,!0),r.getLocalPointByInner(o,null,null,!0),r.x=t.x,r.y=t.y,r.getInnerPointByLocal(o,null,null,!0),r.toPoint=o}}getInnerMove(t,e,i){const o=e.getInnerMove(t);return i&&(Math.abs(o.x)>Math.abs(o.y)?o.y=0:o.x=0),o}getFromToByPath(t){return{from:{x:t[1],y:t[2]},to:{x:t[4],y:t[5]}}}getFromToByPoints(t){const e=Et(t);return{from:{x:e[0],y:e[1]},to:{x:e[2],y:e[3]}}}dragPoint(t,e,i,o,s){const{x:n,y:r}=s;i?(ft(t,n,r),o&&ft(e,-n,-r)):(o&&ft(t,-n,-r),ft(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:o,rect:s}=t,n=this.editor.element;let r,a;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:a}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(a,a,!1,t),s.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),pt(o[7],i),pt(e[7],i),pt(o[3],a),pt(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===gt||t===ut,o[t].visible=a,e[t].visible=!r&&a}},t.LineEditTool=o([$()],t.LineEditTool),e.Plugin.add("editor","resize"),e.Creator.editor=function(e,i){const o=new t.Editor(e);return i&&i.sky.add(i.editor=o),o},e.Box.addAttr("textBox",!1,e.dataType),e.UI.addAttr("editConfig",void 0,e.dataType),e.UI.addAttr("editOuter",(t=>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=C,t.EditPoint=V,t.EditSelect=w,t.EditSelectHelper=E,t.EditToolCreator=J,t.EditorEvent=n,t.EditorGroupEvent=et,t.EditorHelper=N,t.EditorMoveEvent=rt,t.EditorRotateEvent=ht,t.EditorScaleEvent=at,t.EditorSkewEvent=lt,t.InnerEditor=ct,t.InnerEditorEvent=tt,t.SelectArea=p,t.Stroker=f,t.TransformTool=dt,t.registerEditTool=$,t.registerInnerEditor=q,t}({},LeaferUI,LeaferUI);
1
+ this.LeaferIN=this.LeaferIN||{},this.LeaferIN.editor=function(t,e,i){"use strict";function s(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);return n>3&&r&&Object.defineProperty(e,i,r),r}function o(t){return t?e.isArray(t)?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class n 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 r(t){return(i,s)=>{const o="_"+s;e.defineKey(i,s,{get(){return this[o]},set(i){const r=this[o];if(r!==i){if(this.config){const t="target"===s;if(t){e.isArray(i)&&i.length>1&&i[0].locked&&i.splice(0,1),this.single&&(this.element.syncEventer=null);const{beforeSelect:t}=this.config;if(t){const s=t({target:i});if(e.isObject(s))i=s;else if(!1===s)return}}const o=t?n.BEFORE_SELECT:n.BEFORE_HOVER;this.hasEvent(o)&&this.emitEvent(new n(o,{editor:this,value:i,oldValue:r}))}this[o]=i,t(this,r)}}})}}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:a}=Math,{copy:h,scale:l}=e.MatrixHelper,{setListWithFn:d}=e.BoundsHelper,{worldBounds:c}=e.LeafBoundsHelper,g=e.getMatrixData(),u=e.getBoundsData();class f 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?(d(u,e,c),t&&this.set(t),this.set(u),this.visible=!0):this.visible=0}__draw(t,i){const{list:s}=this;if(s.length){let o;const n=this.__,{stroke:r,strokeWidth:d,fill:c}=n,{bounds:u}=i;for(let f=0;f<s.length;f++){o=s[f];const{worldTransform:p,worldRenderBounds:E}=o;if(E.width&&E.height&&(!u||u.hit(E,i.matrix))){const s=a(p.scaleX),u=a(p.scaleY);if(h(g,p),g.half=d%2,s!==u){l(g,1/s,1/u),t.setWorld(g,i.matrix),t.beginPath(),n.strokeWidth=d;const{x:e,y:r,width:a,height:h}=o.__layout.boxBounds;t.rect(e*s,r*u,a*s,h*u)}else t.setWorld(g,i.matrix),t.beginPath(),o.__.__useArrow?o.__drawPath(t):o.__.__pathForRender?o.__drawRenderPath(t):o.__drawPathByBox(t),n.strokeWidth=d/a(p.scaleX);r&&(e.isString(r)?e.Paint.stroke(r,this,t):e.Paint.strokes(r,this,t)),c&&(e.isString(c)?e.Paint.fill(c,this,t):e.Paint.fills(c,this,t))}}n.strokeWidth=d}}destroy(){this.target=null,super.destroy()}}s([r(function(t){const i=t.target;t.list=i?e.isArray(i)?i:[i]:[]})],f.prototype,"target",void 0);class p 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 E={findOne:t=>t.list.find(t=>t.editable),findByBounds(t,e){const i=[];return v([t],i,e),i}};function v(t,e,i){let s,o;for(let n=0,r=t.length;n<r;n++)if(s=t[n],o=s.__,o.hittable&&o.visible&&!o.locked&&i.hit(s.__world)){if(o.editable){if(s.isBranch&&!o.hitChildren){o.hitSelf&&e.push(s);continue}if(s.isFrame){if(i.includes(s.__layout.boxBounds,s.__world)){e.push(s);continue}}else i.hit(s.__layout.boxBounds,s.__world)&&o.hitSelf&&e.push(s)}s.isBranch&&v(s.children,e,i)}}const{findOne:m,findByBounds:b}=E;class w extends e.Group{get dragging(){return!!this.originList}get running(){const{editor:t}=this;return this.hittable&&t.visible&&t.hittable&&t.mergeConfig.selector}get isMoveMode(){return this.app&&this.app.interaction.moveMode}constructor(t){super(),this.hoverStroker=new f,this.targetStroker=new f,this.bounds=new e.Bounds,this.selectArea=new p,this.__eventIds=[],this.editor=t,this.addMany(this.targetStroker,this.hoverStroker,this.selectArea),this.__listenEvents()}onHover(){const{editor:t}=this;if(!this.running||this.dragging||t.dragging)this.hoverStroker.target=null;else{const{stroke:e,strokeWidth:i,hover:s,hoverStyle:o}=t.mergeConfig;this.hoverStroker.setTarget(s?this.editor.hoverTarget:null,Object.assign({stroke:e,strokeWidth:i},o||{}))}}onSelect(){this.running&&(this.targetStroker.setTarget(this.editor.list),this.hoverStroker.target=null)}update(){this.hoverStroker.update();const{stroke:t,strokeWidth:e,selectedStyle:i}=this.editor.mergedConfig;this.targetStroker.update(Object.assign({stroke:t,strokeWidth:e&&Math.max(1,e/2)},i||{}))}onPointerMove(t){const{app:e,editor:i}=this;if(this.running&&!this.isMoveMode&&e.interaction.canHover&&!e.interaction.dragging){const e=this.findUI(t);i.hoverTarget=i.hasItem(e)?null:e}this.isMoveMode&&(i.hoverTarget=null)}onBeforeDown(t){if(t.multiTouch)return;const{select:e}=this.editor.mergeConfig;"press"===e&&(this.app.config.mobile?this.waitSelect=()=>this.checkAndSelect(t):this.checkAndSelect(t))}onTap(t){if(t.multiTouch)return;const{editor:e}=this,{select:i}=e.mergeConfig;"tap"===i?this.checkAndSelect(t):this.waitSelect&&this.waitSelect(),this.needRemoveItem?e.removeItem(this.needRemoveItem):this.isMoveMode&&(e.target=null)}checkAndSelect(t){if(this.needRemoveItem=null,this.allowSelect(t)){const{editor:e}=this,i=this.findUI(t);i?this.isMultipleSelect(t)?e.hasItem(i)?this.needRemoveItem=i:e.addItem(i):e.target=i:this.allow(t.target)&&(this.isHoldMultipleSelectKey(t)||(e.target=null))}}onDragStart(t){if(!t.multiTouch&&(this.waitSelect&&this.waitSelect(),this.allowDrag(t))){const{editor:e}=this,{stroke:i,area:s}=e.mergeConfig,{x:o,y:n}=t.getInnerPoint(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(!t.multiTouch){if(this.editor.dragging)return this.onDragEnd(t);if(this.dragging){const{editor:i}=this,s=t.getInnerTotal(this),o=this.bounds.clone().unsign(),n=new e.LeafList(b(i.app,o));if(this.bounds.width=s.x,this.bounds.height=s.y,this.selectArea.setBounds(o.get()),n.length){const t=[];this.originList.forEach(e=>{n.has(e)||t.push(e)}),n.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_([[n.HOVER,this.onHover,this],[n.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:L,top:y,topRight:k,right:x,bottomRight:T,bottom:O,bottomLeft:S,left:_}=e.Direction9,{toPoint:B}=e.AroundHelper,{within:M}=e.MathHelper,C={getScaleData(t,i,s,o,n,r,a,h){let l,d={},c=1,g=1;const{boxBounds:u,widthRange:f,heightRange:p,dragBounds:E,worldBoxBounds:v}=t,{width:m,height:b}=i;r&&(o.x*=2,o.y*=2);const w=t.scaleX/i.scaleX,C=t.scaleY/i.scaleY,R=w<0?-1:1,P=C<0?-1:1,H=h?w:R*u.width/m,D=h?C:P*u.height/b;o.x*=h?w:R,o.y*=h?C:P;const I=(-o.y+b)/b,V=(o.x+m)/m,A=(o.y+b)/b,z=(-o.x+m)/m;switch(s){case y:g=I,l="bottom";break;case x:c=V,l="left";break;case O:g=A,l="top";break;case _:c=z,l="right";break;case L:g=I,c=z,l="bottom-right";break;case k:g=I,c=V,l="bottom-left";break;case T:g=A,c=V,l="top-left";break;case S:g=A,c=z,l="top-right"}if(n)if("corner"===n&&s%2)n=!1;else{let t;switch(s){case y:case O:t=g;break;case _:case x:t=c;break;default:t=Math.sqrt(Math.abs(c*g))}c=c<0?-t:t,g=g<0?-t:t}const F=1!==c,Z=1!==g;if(F&&(c/=H),Z&&(g/=D),!a){const{worldTransform:e}=t;c<0&&(c=1/u.width/e.scaleX),g<0&&(g=1/u.height/e.scaleY)}if(B(r||l,u,d,!0),E){const i="parent"===E?t.parent.boxBounds:E,s=new e.Bounds(t.__localBoxBounds);if(e.BoundsHelper.includes(new e.Bounds(i).spread(.1),s)&&(s.scaleOf(t.getLocalPointByInner(d),c,g),!e.BoundsHelper.includes(i,s))){const t=s.getIntersect(i),e=t.width/s.width,o=t.height/s.height;F&&(c*=e),Z&&(g*=o)}}if(F&&f){const e=u.width*t.scaleX;c=M(e*c,f)/e}if(Z&&p){const e=u.height*t.scaleY;g=M(e*g,p)/e}return F&&Math.abs(c*v.width)<1&&(c=(c<0?-1:1)/v.width),Z&&Math.abs(g*v.height)<1&&(g=(g<0?-1:1)/v.height),n&&c!==g&&(g=c=Math.min(c,g)),{origin:d,scaleX:c,scaleY:g,direction:s,lockRatio:n,around:r}},getRotateData(t,i,s,o,n){let r,a={};switch(i){case L:r="bottom-right";break;case k:r="bottom-left";break;case T:r="top-left";break;case S:r="top-right";break;default:r="center"}return B(n||r,t.boxBounds,a,!0),{origin:a,rotation:e.PointHelper.getRotation(o,t.getWorldPointByBox(a),s)}},getSkewData(t,i,s,o){let n,r,a={},h=0,l=0;switch(i){case y:case L:r={x:.5,y:0},n="bottom",h=1;break;case O:case T:r={x:.5,y:1},n="top",h=1;break;case _:case S:r={x:0,y:.5},n="right",l=1;break;case x:case k:r={x:1,y:.5},n="left",l=1}const{width:d,height:c}=t;r.x=r.x*d,r.y=r.y*c,B(o||n,t,a,!0);const g=e.PointHelper.getRotation(r,a,{x:r.x+(h?s.x:0),y:r.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 _:t=x;break;case L:t=k;break;case S:t=T;break;case x:t=_;break;case k:t=L;break;case T:t=S}if(i)switch(t){case y:t=O;break;case L:t=S;break;case k:t=T;break;case O:t=y;break;case S:t=L;break;case T:t=k}return t}},R={};function P(t,i){const{enterPoint:s,dragging:o,skewing:n,resizing:r,flippedX:a,flippedY:h}=t;if(!s||!t.editor.editing||!t.canUse)return;if("circle"===s.name)return;if("button"===s.pointType)return void(s.cursor||(s.cursor="pointer"));let{rotation:l}=t;const{pointType:d}=s,{resizeCursor:c,rotateCursor:g,skewCursor:u,resizeable:f,rotateable:p,skewable:E}=t.mergeConfig;let v=d.includes("resize");v&&p&&(t.isHoldRotateKey(i)||!f)&&(v=!1);const m=E&&!v&&("resize-line"===s.name||"skew"===d),b=o?n?u:r?c:g:m?u:v?c:g;l+=45*(C.getFlipDirection(s.direction,a,h)+1),l=2*Math.round(e.MathHelper.formatRotation(l,!0)/2);const{url:w,x:L,y:y}=b,k=w+l;R[k]?s.cursor=R[k]:R[k]=s.cursor={url:D(w,l),x:L,y:y}}function H(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.canUse&&(t.rect.cursor=i?e:void 0)}function D(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"],A=void 0;class z 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.visible&&this.view.visible}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)}constructor(t){super(),this.view=new e.Group,this.rect=new e.Box({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:n,resizeLines:r,rect:a,circle:h,buttons:l}=this,d=["bottom-right","bottom","bottom-left","left","top-left","top","top-right","right"];for(let s=0;s<8;s++)t=new I({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new I({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.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),s.addMany(...n,a,h,l,...r,...o),this.add(s)}load(){const{target:t,mergeConfig:e,single:i,rect:s,circle:o,resizePoints:n}=this,{stroke:r,strokeWidth:a}=e,h=this.getPointsStyle(),l=this.getMiddlePointsStyle();let d;this.visible=!t.locked;for(let t=0;t<8;t++)d=n[t],d.set(this.getPointStyle(t%2?l[(t-1)/2%l.length]:h[t/2%h.length])),d.rotation=(t-(t%2?1:0))/2*90;o.set(this.getPointStyle(e.circle||e.rotatePoint||h[0])),s.set(Object.assign({stroke:r,strokeWidth:a,editConfig:A},e.rect||{}));const c=i&&this.transformTool.editTool;s.hittable=!c,s.syncEventer=c&&this.editor,c&&(t.syncEventer=s,this.app.interaction.bottomList=[{target:s,proxy:t}]),H(this)}update(){const{editor:t}=this,{x:e,y:i,scaleX:s,scaleY:o,rotation:n,skewX:r,skewY:a,width:h,height:l}=this.target.getLayoutBounds("box",t,!0);this.visible=!this.target.locked,this.set({x:e,y:i,scaleX:s,scaleY:o,rotation:n,skewX:r,skewY:a}),this.updateBounds({x:0,y:0,width:h,height:l})}unload(){this.visible=!1,this.app&&(this.rect.syncEventer=this.app.interaction.bottomList=null)}updateBounds(t){const{editMask:i}=this.editor,{mergeConfig:s,single:o,rect:n,circle:r,buttons:a,resizePoints:h,rotatePoints:l,resizeLines:d}=this,{middlePoint:c,resizeable:g,rotateable:u,hideOnSmall:f,editBox:p,mask:E,spread:v,hideRotatePoints:m,hideResizeLines:b}=s;if(i.visible=!!E||0,v&&e.BoundsHelper.spread(t,v),this.view.worldOpacity){const{width:i,height:E}=t,v=e.isNumber(f)?f:10,w=p&&!(f&&i<v&&E<v);let L,y,k,x={};for(let s=0;s<8;s++)e.AroundHelper.toPoint(e.AroundHelper.directionData[s],t,x),y=h[s],L=l[s],y.set(x),L.set(x),y.visible=w&&!(!g&&!u),L.visible=w&&u&&g&&!m,s%2&&(k=d[(s-1)/2],k.set(x),k.visible=y.visible&&!b,y.visible=L.visible=w&&!!c,(s+1)/2%2?(k.width=i,f&&2*y.width>i&&(y.visible=!1)):(k.height=E,f&&2*y.width>E&&(y.visible=!1)));r.visible=w&&u&&!(!s.circle&&!s.rotatePoint),r.visible&&this.layoutCircle(),n.path&&(n.path=null),n.set(Object.assign(Object.assign({},t),{visible:!o||p})),a.visible=w&&a.children.length>0||0,a.visible&&this.layoutButtons()}else n.set(t)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,n=V.indexOf(t||(this.buttons.children.length&&"bottom"===s?"top":"bottom"));this.setButtonPosition(this.circle,n,e||i,!!o)}layoutButtons(){const{buttons:t}=this,{buttonsDirection:e,buttonsFixed:i,buttonsMargin:s,middlePoint:o}=this.mergedConfig,{flippedX:n,flippedY:r}=this;let a=V.indexOf(e);(a%2&&n||(a+1)%2&&r)&&i&&(a=(a+2)%4);const h=i?C.getRotateDirection(a,this.flippedOne?this.rotation:-this.rotation,4):a;this.setButtonPosition(t,h,s,!!o),i&&(t.rotation=90*(h-a)),t.scaleX=n?-1:1,t.scaleY=r?-1:1}setButtonPosition(t,e,i,s){const o=this.resizePoints[2*e+1],n=e%2,r=e&&3!==e?1:-1,a=(i+(e%2?(s?o.width:0)+t.boxBounds.width:(s?o.height:0)+t.boxBounds.height)/2)*r;n?(t.x=o.x+a,t.y=o.y):(t.x=o.x,t.y=o.y+a)}getPointStyle(t){const{stroke:e,strokeWidth:i,pointFill:s,pointSize:o,pointRadius:n}=this.mergedConfig,r={fill:s,stroke:e,strokeWidth:i,around:"center",strokeAlign:"center",width:o,height:o,cornerRadius:n,offsetX:0,offsetY:0,editConfig:A};return t?Object.assign(r,t):r}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()}onDragStart(t){this.dragging=!0;const i=this.dragPoint=t.current,{pointType:s}=i,{editor:o,dragStartData:n}=this,{target:r}=this,{moveable:a,resizeable:h,rotateable:l,skewable:d,hideOnMove:c}=this.mergeConfig;"rect"===i.name?(a&&(this.moving=!0),o.opacity=c?0:1):(s.includes("rotate")||this.isHoldRotateKey(t)||!h?(l&&(this.rotating=!0),"resize-rotate"===s?h&&(this.resizing=!0):"resize-line"===i.name&&(d&&(this.skewing=!0),this.rotating=!1)):"resize"===s&&h&&(this.resizing=!0),"skew"===s&&d&&(this.skewing=!0)),n.x=t.x,n.y=t.y,n.point={x:r.x,y:r.y},n.bounds=Object.assign({},r.getLayoutBounds("box","local")),n.rotation=r.rotation,s&&s.includes("resize")&&(e.ResizeEvent.resizingKeys=o.leafList.keys)}onDragEnd(t){this.mergeConfig.dragLimitAnimate&&this.moving&&this.transformTool.onMove(t),this.dragPoint=null,this.resetDoing();const{name:i,pointType:s}=t.current;"rect"===i&&(this.editor.opacity=1),s&&s.includes("resize")&&(e.ResizeEvent.resizingKeys=null)}onDrag(t){const{transformTool:e,moving:i,resizing:s,rotating:o,skewing:n}=this;if(i)e.onMove(t),H(this);else if(s||o||n){const i=t.current;i.pointType&&(this.enterPoint=i),o&&e.onRotate(t),s&&e.onScale(t),n&&e.onSkew(t),P(this,t)}}resetDoing(){this.canUse&&(this.dragging=this.gesturing=this.moving=this.resizing=this.rotating=this.skewing=!1)}onMove(t){this.canGesture&&"drag"!==t.moveType&&(t.stop(),e.isString(this.mergeConfig.moveable)&&(this.gesturing=this.moving=!0,this.transformTool.onMove(t)))}onScale(t){this.canGesture&&(t.stop(),e.isString(this.mergeConfig.resizeable)&&(this.gesturing=this.resizing=!0,this.transformTool.onScale(t)))}onRotate(t){this.canGesture&&(t.stop(),e.isString(this.mergeConfig.rotateable)&&(this.gesturing=this.rotating=!0,this.transformTool.onRotate(t)))}isHoldRotateKey(t){const{rotateKey:e}=this.mergedConfig;return e?t.isHoldKeys(e):t.metaKey||t.ctrlKey}onKey(t){P(this,t)}onArrow(t){const{editor:e,transformTool:i}=this;if(this.canUse&&e.editing&&this.mergeConfig.keyEvent){let e=0,s=0;const o=t.shiftKey?10:1;switch(t.code){case"ArrowDown":s=o;break;case"ArrowUp":s=-o;break;case"ArrowLeft":e=-o;break;case"ArrowRight":e=o}(e||s)&&i.move(e,s)}}onDoubleTap(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"double"!==e||i||this.openInner(t)}onLongPress(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"long"===e&&i&&this.openInner(t)}openInner(t){const{editor: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;const o=[[i.DragEvent.START,this.onDragStart,this],[i.DragEvent.DRAG,this.onDrag,this],[i.DragEvent.END,this.onDragEnd,this],[i.PointerEvent.LEAVE,()=>{this.enterPoint=null}]];"circle"!==t.name&&o.push([i.PointerEvent.ENTER,e=>{this.enterPoint=t,P(this,e)}]),this.__eventIds.push(t.on_(o))}__listenEvents(){const{rect:t,editor:e,__eventIds:s}=this;s.push(t.on_([[i.DragEvent.START,this.onDragStart,this],[i.DragEvent.DRAG,this.onDrag,this],[i.DragEvent.END,this.onDragEnd,this],[i.PointerEvent.ENTER,()=>H(this)],[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.BEFORE_MOVE,this.onMove,this,!0],[i.ZoomEvent.BEFORE_ZOOM,this.onScale,this,!0],[i.RotateEvent.BEFORE_ROTATE,this.onRotate,this,!0],[i.MoveEvent.END,this.resetDoing,this],[i.ZoomEvent.END,this.resetDoing,this],[i.RotateEvent.END,this.resetDoing,this]]))})}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const F={x:0,y:0,width:1e5,height:1e5};class Z extends e.UI{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,F),Object.assign(this.__world,F)}__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"/>',W={editSize:"size",keyEvent:!0,stroke:"#836DFF",strokeWidth:2,pointFill:"#FFFFFF",pointSize:10,pointRadius:16,rotateGap:45,buttonsDirection:"bottom",buttonsMargin:12,hideOnSmall:!0,moveCursor:"move",resizeCursor:{url:`\n<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">\n<g filter="url(#f)">\n<g transform="rotate({{rotation}},12,12)">\n<path d="M7.5 8.0H8.5V5.9L6.8 7.2L7.5 8.0ZM3 11.4L2.3 10.6L1.3 11.4L2.3 12.2L3 11.4ZM7.5 10.4H6.5V11.4H7.5V10.4ZM16.5 10.4V11.4H17.5V10.4H16.5ZM16.5 8.0L17.1 7.2L15.5 5.9V8.0H16.5ZM21 11.4L21.6 12.2L22.6 11.4L21.6 10.6L21 11.4ZM16.5 14.9H15.5V16.9L17.1 15.7L16.5 14.9ZM16.5 12.4H17.5V11.4H16.5V12.4ZM7.5 12.4V11.4H6.5V12.4H7.5ZM7.5 14.9L6.8 15.7L8.5 16.9V14.9H7.5ZM6.8 7.2L2.3 10.6L3.6 12.2L8.1 8.7L6.8 7.2ZM8.5 10.4V8.0H6.5V10.4H8.5ZM16.5 9.4H7.5V11.4H16.5V9.4ZM17.5 10.4V8.0H15.5V10.4H17.5ZM15.8 8.7L20.3 12.2L21.6 10.6L17.1 7.2L15.8 8.7ZM20.3 10.6L15.8 14.1L17.1 15.7L21.6 12.2L20.3 10.6ZM17.5 14.9V12.4H15.5V14.9H17.5ZM7.5 13.4H16.5V11.4H7.5V13.4ZM8.5 14.9V12.4H6.5V14.9H8.5ZM2.3 12.2L6.8 15.7L8.1 14.1L3.6 10.6L2.3 12.2Z" fill="white"/>\n<path fill-rule="evenodd" d="M3 11.4L7.5 8.0V10.4H16.5V8.0L21 11.4L16.5 14.9V12.4H7.5V14.9L3 11.4Z" fill="black"/>\n</g>\n</g>\n<defs>\n<filter id="f" x="-1.6" y="3.9" width="27.2" height="16.9" filterUnits="userSpaceOnUse">\n${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},U=new e.Bounds;function X(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange(()=>{U.setListWithFn(i,t=>t.getBounds("box","page")),0===U.width&&(U.width=.1),0===U.height&&(U.height=.1),e.reset(U.get())}),s.add(e)}const Y=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),N=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),K={group(t,i,s){t.sort(N);const{app:o,parent:n}=t[0];let r;r=s&&s.add?s:new e.Group(s),n.addAt(r,n.children.indexOf(t[0])),t.sort(Y);const a=new e.Matrix(i.worldTransform);return a.divideParent(n.worldTransform),r.setTransform(a),r.editable=!0,r.hitChildren=!1,o.lockLayout(),t.forEach(t=>t.dropTo(r)),o.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(Y),t.forEach(t=>{t.parent&&t.parent.add(t)})},toBottom(t){t.sort(N),t.forEach(t=>{t.parent&&t.parent.addAt(t,0)})}},j=e.Debug.get("EditToolCreator");function $(){return t=>{J.register(t)}}const q=$,J={list:{},register(t){const{tag:e}=t.prototype;Q[e]&&j.repeat(e),Q[e]=t},get:(t,e)=>new Q[t](e)},{list:Q}=J;class tt extends n{constructor(t,e){super(t,e)}}tt.BEFORE_OPEN="innerEditor.before_open",tt.OPEN="innerEditor.open",tt.BEFORE_CLOSE="innerEditor.before_close",tt.CLOSE="innerEditor.close";class et extends n{constructor(t,e){super(t,e)}}et.BEFORE_GROUP="editor.before_group",et.GROUP="editor.group",et.BEFORE_UNGROUP="editor.before_ungroup",et.UNGROUP="editor.ungroup",et.BEFORE_OPEN="editor.before_open_group",et.OPEN="editor.open_group",et.BEFORE_CLOSE="editor.before_close_group",et.CLOSE="editor.close_group";const{updateMatrix:it}=e.LeafHelper,st={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},ot="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.on(e.PropertyEvent.CHANGE,i=>{if(this.checkChange&&st[i.attrName]){const{attrName:s,newValue:o,oldValue:n}=i,r="s"===s[0]?(o||1)/(n||1):(o||0)-(n||0);this.canChange=!1;const a=this.__;a[s]=n,it(this.parent),it(this);const h=new e.Matrix(this.__world);switch(a[s]=o,this.__layout.rotationChange(),it(this),this.changedTransform=new e.Matrix(this.__world).divide(h),s){case"x":t.move(r,0);break;case"y":t.move(0,r);break;case"rotation":t.rotateOf(ot,r);break;case"scaleX":t.scaleOf(ot,r,1);break;case"scaleY":t.scaleOf(ot,1,r);break;case"skewX":t.skewOf(ot,r,0);break;case"skewY":t.skewOf(ot,0,r)}this.canChange=!0}})}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class rt extends n{constructor(t,e){super(t,e)}}rt.BEFORE_MOVE="editor.before_move",rt.MOVE="editor.move";class at extends n{constructor(t,e){super(t,e)}}at.BEFORE_SCALE="editor.before_scale",at.SCALE="editor.scale";class ht extends n{constructor(t,e){super(t,e)}}ht.BEFORE_ROTATE="editor.before_rotate",ht.ROTATE="editor.rotate";class lt extends n{constructor(t,e){super(t,e)}}lt.BEFORE_SKEW="editor.before_skew",lt.SKEW="editor.skew";class dt{onMove(t){const{target:s,mergeConfig:o,dragStartData:n,app:r}=this.editBox;let a,{dragLimitAnimate:h}=o;e.isUndefined(h)&&(h=r&&r.config.pointer.dragLimitAnimate);const l=t.type===i.DragEvent.END||t.type===i.DragEvent.END,d=!h||l;if(t instanceof i.MoveEvent)a=t.getLocalMove(s),d&&i.DragEvent.limitMove(s,a);else{const e={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(e.x)>Math.abs(e.y)?e.y=0:e.x=0),a=i.DragEvent.getValidMove(s,n.point,e,d)}h&&l?e.LeafHelper.animateMove(this,a,e.isNumber(h)?h:.3):this.move(a)}onScale(t){const{target:e,mergeConfig:s,single:o,dragStartData:n}=this.editBox;let{around:r,lockRatio:a,flipable:h,editSize:l}=s;if(t instanceof i.ZoomEvent)this.scaleOf(e.getBoxPoint(t),t.scale,t.scale);else{const{direction:i}=t.current;(t.shiftKey||e.lockRatio)&&(a=!0);const s=C.getScaleData(e,n.bounds,i,t.getInnerTotal(e),a,C.getAround(r,t.altKey),h,!o||"scale"===l);this.editTool&&this.editTool.onScaleWithDrag?(s.drag=t,this.scaleWithDrag(s)):this.scaleOf(s.origin,s.scaleX,s.scaleY)}}onRotate(t){const{target:s,mergeConfig:o,dragStartData:n}=this.editBox,{around:r,rotateAround:a,rotateGap:h}=o,{direction:l}=t.current;let d,c;if(t instanceof i.RotateEvent)c=t.rotation,d=a?e.AroundHelper.getPoint(a,s.boxBounds):s.getBoxPoint(t);else{const e=C.getRotateData(s,l,t,n,t.shiftKey?null:a||s.around||s.origin||r||"center");c=n.rotation+e.rotation-s.rotation,d=e.origin}c=e.MathHelper.float(e.MathHelper.getGapRotation(c,h,s.rotation),2),c&&this.rotateOf(d,c)}onSkew(t){const{target:e,mergeConfig:i}=this.editBox,{around:s}=i,{origin:o,skewX:n,skewY:r}=C.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),C.getAround(s,t.altKey));(n||r)&&this.skewOf(o,n,r)}move(t,i=0){if(!this.checkTransform("moveable"))return;e.isObject(t)&&(i=t.y,t=t.x);const{target:s,mergeConfig:o,single:n,editor:r}=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);n||s.safeChange(()=>s.move(t,i));const l={target:s,editor:r,moveX:h.x,moveY:h.y};this.emitEvent(new rt(rt.BEFORE_MOVE,l));const d=new rt(rt.MOVE,l);this.doMove(d),this.emitEvent(d)}scaleWithDrag(t){if(!this.checkTransform("resizeable"))return;const{target:e,mergeConfig:i,editor:s}=this.editBox,{beforeScale:o}=i;if(o){const{origin:i,scaleX:s,scaleY:n,drag:r}=t;if(!1===o({target:e,drag:r,origin:i,scaleX:s,scaleY:n}))return}t=Object.assign(Object.assign({},t),{target:e,editor:s,worldOrigin:e.getWorldPoint(t.origin)}),this.emitEvent(new at(at.BEFORE_SCALE,t));const n=new at(at.SCALE,t);this.editTool.onScaleWithDrag(n),this.emitEvent(n)}scaleOf(t,i,s=i,o){if(!this.checkTransform("resizeable"))return;const{target:n,mergeConfig:r,single:a,editor:h}=this.editBox,{beforeScale:l}=r;if(l){const o=l({target:n,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(()=>n.safeChange(()=>n.scaleOf(t,i,s))),g={target:n,editor:h,worldOrigin:d,scaleX:i,scaleY:s,transform:c};this.emitEvent(new at(at.BEFORE_SCALE,g));const u=new at(at.SCALE,g);this.doScale(u),this.emitEvent(u)}flip(t){if(!this.checkTransform("resizeable"))return;const{target:i,single:s,editor:o}=this.editBox,n=this.getWorldOrigin("center"),r=s?new e.Matrix(e.LeafHelper.getFlipTransform(i,t)):this.getChangedTransform(()=>i.safeChange(()=>i.flip(t))),a={target:i,editor:o,worldOrigin:n,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:r};this.emitEvent(new at(at.BEFORE_SCALE,a));const h=new at(at.SCALE,a);this.doScale(h),this.emitEvent(h)}rotateOf(t,i){if(!this.checkTransform("rotateable"))return;const{target:s,mergeConfig:o,single:n,editor:r}=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=!n&&this.getChangedTransform(()=>s.safeChange(()=>s.rotateOf(t,i))),d={target:s,editor:r,worldOrigin:h,rotation:i,transform:l};this.emitEvent(new ht(ht.BEFORE_ROTATE,d));const c=new ht(ht.ROTATE,d);this.doRotate(c),this.emitEvent(c)}skewOf(t,i,s=0,o){if(!this.checkTransform("skewable"))return;const{target:n,mergeConfig:r,single:a,editor:h}=this.editBox,{beforeSkew:l}=r;if(l){const o=l({target:n,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(()=>n.safeChange(()=>n.skewOf(t,i,s))),g={target:n,editor:h,worldOrigin:d,skewX:i,skewY:s,transform:c};this.emitEvent(new lt(lt.BEFORE_SKEW,g));const u=new lt(lt.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}constructor(t,i){super(i),this.leafList=new e.LeafList,this.openedGroupList=new e.LeafList,this.simulateTarget=new nt(this),this.editBox=new z(this),this.editToolList={},this.selector=new w(this),this.editMask=new Z(this),this.targetEventIds=[];let s=e.DataHelper.clone(W);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)}addItem(t){this.hasItem(t)||t.locked||(this.leafList.add(t),this.target=this.leafList.list)}removeItem(t){this.hasItem(t)&&(this.leafList.remove(t),this.target=this.leafList.list)}shiftItem(t){this.hasItem(t)?this.removeItem(t):this.addItem(t)}update(){if(this.editing){if(!this.element.parent)return this.cancel();this.innerEditing&&this.innerEditor.update(),this.editTool.update(),this.selector.update()}}updateEditBox(){this.multiple&&X(this),this.update()}updateEditTool(){if(this.unloadEditTool(),this.editing){const t=this.element.editOuter||"EditTool",e=this.editTool=this.editToolList[t]=this.editToolList[t]||J.get(t,this);this.editBox.load(),e.load(),this.update()}}unloadEditTool(){let t=this.editTool;t&&(this.editBox.unload(),t.unload(),this.editTool=null)}getEditSize(t){return this.mergeConfig.editSize}onMove(t){}onScale(t){}onRotate(t){}onSkew(t){}move(t,e=0){}scaleWithDrag(t){}scaleOf(t,e,i=e,s){}flip(t){}rotateOf(t,e){}skewOf(t,e,i=0,s){}checkTransform(t){}getWorldOrigin(t){}getChangedTransform(t){}group(t){return this.multiple&&(this.emitGroupEvent(et.BEFORE_GROUP),this.target=K.group(this.list,this.element,t),this.emitGroupEvent(et.GROUP,this.target)),this.target}ungroup(){const{list:t}=this;return t.length&&(t.forEach(t=>t.isBranch&&this.emitGroupEvent(et.BEFORE_UNGROUP,t)),this.target=K.ungroup(t),t.forEach(t=>t.isBranch&&this.emitGroupEvent(et.UNGROUP,t))),this.list}openGroup(t){this.emitGroupEvent(et.BEFORE_OPEN,t),this.openedGroupList.add(t),t.hitChildren=!0,this.emitGroupEvent(et.OPEN,t)}closeGroup(t){this.emitGroupEvent(et.BEFORE_CLOSE,t),this.openedGroupList.remove(t),t.hitChildren=!1,this.emitGroupEvent(et.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 et(t,{editTarget:e});e&&e.syncEventer||this.emitEvent(i),e&&e.emitEvent(i)}openInnerEditor(t,i,s){let o;if(e.isString(i)?o=i:s||(s=i),t&&s&&(this.target=t),this.single){const e=t||this.element;o||(o=e.editInner),o&&J.list[o]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[o]=this.editToolList[o]||J.get(o,this),this.innerEditor.editTarget=e,this.emitInnerEvent(tt.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(tt.OPEN),console.log("hello"))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(tt.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(tt.CLOSE),t||this.updateEditTool(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new tt(t,{editTarget:i,innerEditor:e});i.syncEventer||this.emitEvent(s),i.emitEvent(s)}lock(){this.list.forEach(t=>t.locked=!0),this.update()}unlock(){this.list.forEach(t=>t.locked=!1),this.update()}toTop(){this.list.length&&(K.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(K.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()}listenTargetEvents(){if(!this.targetEventIds.length){const{app:t,leafer:i,editMask:s}=this;this.targetEventIds=[i.on_(e.RenderEvent.START,this.onRenderStart,this),t.on_(e.RenderEvent.CHILD_START,this.onAppRenderStart,this)],s.visible&&s.forceRender()}}removeTargetEvents(){const{targetEventIds:t,editMask:e}=this;t.length&&(this.off_(t),e.visible&&e.forceRender())}destroy(){this.destroyed||(this.target=this.hoverTarget=null,Object.values(this.editToolList).forEach(t=>t.destroy()),this.simulateTarget.destroy(),this.editToolList={},this.simulateTarget=this.editTool=this.innerEditor=null,super.destroy())}},s([(t,i)=>{e.defineKey(t,i,{get(){const{config:t,element:i,dragPoint:s,editBox:o}=this,n=Object.assign({},t);return i&&i.editConfig&&Object.assign(n,i.editConfig),o.config&&Object.assign(n,o.config),s&&(s.editConfig&&Object.assign(n,s.editConfig),"font-size"===n.editSize&&(n.lockRatio=!0),"resize-rotate"===s.pointType&&(n.around||(n.around="center"),e.isNull(n.lockRatio)&&(n.lockRatio=!0))),this.mergedConfig=n}})}],t.Editor.prototype,"mergeConfig",void 0),s([r(function(t,e){t.emitEvent(new n(n.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))})],t.Editor.prototype,"hoverTarget",void 0),s([r(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 n(n.SELECT,o)),t.checkOpenedGroups(),t.editing?t.waitLeafer(()=>{t.updateEditTool(),t.listenTargetEvents()}):(t.updateEditTool(),t.removeTargetEvents()),t.emitEvent(new n(n.AFTER_SELECT,o))})],t.Editor.prototype,"target",void 0),t.Editor=s([i.useModule(dt,["editBox","editTool","emitEvent"])],t.Editor);class ct{static registerInnerEditor(){J.register(this)}get tag(){return"InnerEditor"}get mode(){return"focus"}get editBox(){return this.editor.editBox}constructor(t){this.eventIds=[],this.editor=t,this.create()}onCreate(){}create(){this.view=new 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 ct{static registerEditTool(){J.register(this)}get tag(){return"EditTool"}onMove(t){const{moveX:e,moveY:i,editor:s}=t,{app:o,list:n}=s;o.lockLayout(),n.forEach(t=>{t.moveWorld(e,i)}),o.unlockLayout()}onScale(t){const{scaleX:e,scaleY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach(t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.scaleOfWorld(o,e,i,r)}),r.unlockLayout()}onRotate(t){const{rotation:e,transform:i,worldOrigin:s,editor:o}=t,{app:n,list:r}=o;n.lockLayout(),r.forEach(t=>{const n="scale"!==o.getEditSize(t);i?t.transformWorld(i,n):t.rotateOfWorld(s,e)}),n.unlockLayout()}onSkew(t){const{skewX:e,skewY:i,transform:s,worldOrigin:o,editor:n}=t,{app:r,list:a}=n;r.lockLayout(),a.forEach(t=>{const r="scale"!==n.getEditSize(t);s?t.transformWorld(s,r):t.skewOfWorld(o,e,i,r)}),r.unlockLayout()}load(){this.editBox.view.visible=!0,this.onLoad()}update(){this.editBox.update(),this.onUpdate()}unload(){this.editBox.view.visible=!1,this.onUnload()}},t.EditTool=s([$()],t.EditTool);const{left:gt,right:ut}=e.Direction9,{move:ft,copy:pt,toNumberPoints:Et}=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:n}=t,r=t.target,a=s===gt;if(r.pathInputed){const{path:t}=r.__,{from:e,to:s}=this.getFromToByPath(t);this.dragPoint(e,s,a,n,this.getInnerMove(r,i,o)),t[1]=e.x,t[2]=e.y,t[4]=s.x,t[5]=s.y,r.path=t}else if(r.points){const{points:t}=r,{from:e,to:s}=this.getFromToByPoints(t);this.dragPoint(e,s,a,n,this.getInnerMove(r,i,o)),t[0]=e.x,t[1]=e.y,t[2]=s.x,t[3]=s.y,r.points=t}else{const t=e.getPointData(),{toPoint:s}=r;r.rotation=0,this.dragPoint(t,s,a,n,this.getInnerMove(r,i,o)),r.getLocalPointByInner(t,null,null,!0),r.getLocalPointByInner(s,null,null,!0),r.x=t.x,r.y=t.y,r.getInnerPointByLocal(s,null,null,!0),r.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=Et(t);return{from:{x:e[0],y:e[1]},to:{x:e[2],y:e[3]}}}dragPoint(t,e,i,s,o){const{x:n,y:r}=o;i?(ft(t,n,r),s&&ft(e,-n,-r)):(s&&ft(t,-n,-r),ft(e,n,r))}onSkew(t){}onUpdate(){const{editBox:t}=this,{rotatePoints:e,resizeLines:i,resizePoints:s,rect:o}=t,n=this.editor.element;let r,a;if(n.pathInputed?r=this.getFromToByPath(n.__.path):n.points&&(r=this.getFromToByPoints(n.__.points)),r){const{from:i,to:a}=r;n.innerToWorld(i,i,!1,t),n.innerToWorld(a,a,!1,t),o.pen.clearPath().moveTo(i.x,i.y).lineTo(a.x,a.y),pt(s[7],i),pt(e[7],i),pt(s[3],a),pt(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===gt||t===ut,s[t].visible=a,e[t].visible=!r&&a}},t.LineEditTool=s([$()],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=z,t.EditDataHelper=C,t.EditPoint=I,t.EditSelect=w,t.EditSelectHelper=E,t.EditToolCreator=J,t.EditorEvent=n,t.EditorGroupEvent=et,t.EditorHelper=K,t.EditorMoveEvent=rt,t.EditorRotateEvent=ht,t.EditorScaleEvent=at,t.EditorSkewEvent=lt,t.InnerEditor=ct,t.InnerEditorEvent=tt,t.SelectArea=p,t.Stroker=f,t.TransformTool=dt,t.registerEditTool=$,t.registerInnerEditor=q,t}({},LeaferUI,LeaferUI);
2
2
  //# sourceMappingURL=editor.min.js.map