@leafer-in/editor 1.7.0 → 1.8.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.
- package/dist/editor.cjs +164 -111
- package/dist/editor.esm.js +164 -111
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +164 -111
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.cjs.map +1 -1
- package/dist/editor.min.js +1 -1
- package/dist/editor.min.js.map +1 -1
- package/package.json +6 -6
- package/src/Editor.ts +31 -23
- package/src/decorator/data.ts +4 -2
- package/src/display/EditBox.ts +103 -45
- package/src/display/EditSelect.ts +4 -4
- package/src/display/Stroker.ts +4 -3
- package/src/editor/cursor.ts +9 -6
- package/src/editor/target.ts +2 -1
- package/src/helper/EditDataHelper.ts +12 -8
- package/src/index.ts +1 -1
- package/src/tool/TransformTool.ts +12 -24
- package/types/index.d.ts +40 -26
package/dist/editor.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Event as t,defineKey as e,isNull as i,MatrixHelper as s,BoundsHelper as o,LeafBoundsHelper as n,getMatrixData as r,getBoundsData as a,UI as h,Paint as l,Group as d,Rect as c,Bounds as g,LeafList as u,Direction9 as f,AroundHelper as p,MathHelper as m,PointHelper as E,Box as v,ResizeEvent as b,Text as w,Matrix as y,Debug as L,LeafHelper as k,PropertyEvent as O,DataHelper as x,Plugin as _,RenderEvent as T,getPointData as S,Creator as B,dataType as M}from"@leafer-ui/draw";import{PointerEvent as C,DragEvent as R,MoveEvent as P,ZoomEvent as V,KeyEvent as H,RotateEvent as I,useModule as A}from"@leafer-ui/core";import"@leafer-in/resize";function D(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 F(t){return t?t instanceof Array?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class z extends t{get list(){return F(this.value)}get oldList(){return F(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}function Z(t){return(i,s)=>{const o="_"+s;e(i,s,{get(){return this[o]},set(e){const i=this[o];if(i!==e){if(this.config){const t="target"===s;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 o=t?z.BEFORE_SELECT:z.BEFORE_HOVER;this.hasEvent(o)&&this.emitEvent(new z(o,{editor:this,value:e,oldValue:i}))}this[o]=e,t(this,i)}}})}}z.BEFORE_SELECT="editor.before_select",z.SELECT="editor.select",z.AFTER_SELECT="editor.after_select",z.BEFORE_HOVER="editor.before_hover",z.HOVER="editor.hover";const{abs:W}=Math,{copy:X,scale:Y}=s,{setListWithFn:G}=o,{worldBounds:U}=n,j=r(),N=a();class K extends h{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?(G(N,t,U),this.set(N),this.visible=!0):this.visible=0}__draw(t,e){const{list:i}=this;if(i.length){let s;const o=this.__,{stroke:n,strokeWidth:r,fill:a}=o,{bounds:h}=e;for(let d=0;d<i.length;d++){s=i[d];const{worldTransform:c,worldRenderBounds:g}=s;if(g.width&&g.height&&(!h||h.hit(g,e.matrix))){const i=W(c.scaleX),h=W(c.scaleY);if(X(j,c),j.half=r%2,i!==h){Y(j,1/i,1/h),t.setWorld(j,e.matrix),t.beginPath(),o.strokeWidth=r;const{x:n,y:a,width:l,height:d}=s.__layout.boxBounds;t.rect(n*i,a*h,l*i,d*h)}else t.setWorld(j,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),o.strokeWidth=r/W(c.scaleX);n&&("string"==typeof n?l.stroke(n,this,t):l.strokes(n,this,t)),a&&("string"==typeof a?l.fill(a,this,t):l.fills(a,this,t))}}o.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}D([Z((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[]}))],K.prototype,"target",void 0);class $ extends d{constructor(t){super(t),this.strokeArea=new c({strokeAlign:"center"}),this.fillArea=new c,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 q={findOne:t=>t.list.find((t=>t.editable)),findByBounds(t,e){const i=[];return J([t],i,e),i}};function J(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&&J(s.children,e,i)}}const{findOne:Q,findByBounds:tt}=q;class et extends d{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 K,this.targetStroker=new K,this.bounds=new g,this.selectArea=new $,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(){if(this.running){const{mergeConfig:t,list:e}=this.editor,{stroke:i,strokeWidth:s,selectedStyle:o}=t;this.targetStroker.setTarget(e,Object.assign({stroke:i,strokeWidth:Math.max(1,s/2)},o||{})),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:s}=e.mergeConfig,{x:o,y:n}=t.getInnerPoint(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(!t.multiTouch){if(this.editor.dragging)return this.onDragEnd(t);if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new u(tt(e.app,s));if(this.bounds.width=i.x,this.bounds.height=i.y,this.selectArea.setBounds(s.get()),o.length){const t=[];this.originList.forEach((e=>{o.has(e)||t.push(e)})),o.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list}}}onDragEnd(t){t.multiTouch||this.dragging&&(this.originList=null,this.selectArea.visible=0)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){const{boxSelect:e,multipleSelect:i}=this.editor.mergeConfig;return!(!(this.running&&i&&e)||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!Q(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new u(this.editor.editBox.rect)};return Q(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):Q(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_([[z.HOVER,this.onHover,this],[z.SELECT,this.onSelect,this]]),e.on_([[C.MOVE,this.onPointerMove,this],[C.BEFORE_DOWN,this.onBeforeDown,this],[C.TAP,this.onTap,this],[R.START,this.onDragStart,this,!0],[R.DRAG,this.onDrag,this],[R.END,this.onDragEnd,this],[P.MOVE,this.onAutoMove,this],[[V.ZOOM,P.MOVE],()=>{this.editor.hoverTarget=null}]])]}))}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:it,top:st,topRight:ot,right:nt,bottomRight:rt,bottom:at,bottomLeft:ht,left:lt}=f,{toPoint:dt}=p,{within:ct}=m,gt={getScaleData(t,e,i,s,n,r,a,h){let l,d={},c=1,u=1;const{boxBounds:f,widthRange:p,heightRange:m,dragBounds:E,worldBoxBounds:v}=t,{width:b,height:w}=e;r&&(s.x*=2,s.y*=2);const y=t.scaleX/e.scaleX,L=t.scaleY/e.scaleY,k=y<0?-1:1,O=L<0?-1:1,x=h?y:k*f.width/b,_=h?L:O*f.height/w;s.x*=h?y:k,s.y*=h?L:O;const T=(-s.y+w)/w,S=(s.x+b)/b,B=(s.y+w)/w,M=(-s.x+b)/b;switch(i){case st:u=T,l="bottom";break;case nt:c=S,l="left";break;case at:u=B,l="top";break;case lt:c=M,l="right";break;case it:u=T,c=M,l="bottom-right";break;case ot:u=T,c=S,l="bottom-left";break;case rt:u=B,c=S,l="top-left";break;case ht:u=B,c=M,l="top-right"}if(n)if("corner"===n&&i%2)n=!1;else{let t;switch(i){case st:case at:t=u;break;case lt:case nt:t=c;break;default:t=Math.sqrt(Math.abs(c*u))}c=c<0?-t:t,u=u<0?-t:t}const C=1!==c,R=1!==u;if(C&&(c/=x),R&&(u/=_),!a){const{worldTransform:e}=t;c<0&&(c=1/f.width/e.scaleX),u<0&&(u=1/f.height/e.scaleY)}if(dt(r||l,f,d,!0),E){const e="parent"===E?t.parent.boxBounds:E,i=new g(t.__localBoxBounds);if(i.scaleOf(t.getLocalPointByInner(d),c,u),!o.includes(e,i)){const t=i.getIntersect(e),s=t.width/i.width,o=t.height/i.height;C&&(c*=s),R&&(u*=o)}}if(C&&p){const e=f.width*t.scaleX;c=ct(e*c,p)/e}if(R&&m){const e=f.height*t.scaleY;u=ct(e*u,m)/e}return C&&Math.abs(c*v.width)<1&&(c=(c<0?-1:1)/v.width),R&&Math.abs(u*v.height)<1&&(u=(u<0?-1:1)/v.height),n&&c!==u&&(u=c=Math.min(c,u)),{origin:d,scaleX:c,scaleY:u,direction:i,lockRatio:n,around:r}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case it:n="bottom-right";break;case ot:n="bottom-left";break;case rt:n="top-left";break;case ht:n="top-right";break;default:n="center"}return dt(o||n,t.boxBounds,r,!0),{origin:r,rotation:E.getRotation(s,t.getWorldPointByBox(r),i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,h=0;switch(e){case st:case it:n={x:.5,y:0},o="bottom",a=1;break;case at:case rt:n={x:.5,y:1},o="top",a=1;break;case lt:case ht:n={x:0,y:.5},o="right",h=1;break;case nt:case ot:n={x:1,y:.5},o="left",h=1}const{width:l,height:d}=t;n.x=n.x*l,n.y=n.y*d,dt(s||o,t,r,!0);const c=E.getRotation(n,r,{x:n.x+(a?i.x:0),y:n.y+(h?i.y:0)});return a?a=-c:h=c,{origin:r,skewX:a,skewY:h}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case lt:t=nt;break;case it:t=ot;break;case ht:t=rt;break;case nt:t=lt;break;case ot:t=it;break;case rt:t=ht}if(i)switch(t){case st:t=at;break;case it:t=ht;break;case ot:t=rt;break;case at:t=st;break;case ht:t=it;break;case rt:t=ot}return t}},ut={};function ft(t,e){const{enterPoint:i}=t;if(!i||!t.editor.editing||!t.visible)return;if("circle"===i.name)return;if("button"===i.pointType)return void(i.cursor||(i.cursor="pointer"));let{rotation:s,flippedX:o,flippedY:n}=t;const{pointType:r}=i,{resizeCursor:a,rotateCursor:h,skewCursor:l,resizeable:d,rotateable:c,skewable:g}=t.mergeConfig;let u=r.includes("resize");u&&c&&(e.metaKey||e.ctrlKey||!d)&&(u=!1);const f=g&&!u&&("resize-line"===i.name||"skew"===r)?l:u?a:h;s+=45*(gt.getFlipDirection(i.direction,o,n)+1),s=2*Math.round(m.formatRotation(s,!0)/2);const{url:p,x:E,y:v}=f,b=p+s;ut[b]?i.cursor=ut[b]:ut[b]=i.cursor={url:mt(p,s),x:E,y:v}}function pt(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.rect.cursor=i?e:void 0}function mt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Et extends v{constructor(t){super(t),this.useFastShadow=!0}}const vt=["top","right","bottom","left"],bt=void 0;class wt extends d{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 d,this.rect=new v({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Et({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new d({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 Et({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Et({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new Et({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;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);o.set(this.getPointStyle(e.circle||e.rotatePoint||h[0])),s.set(Object.assign({stroke:r,strokeWidth:a,editConfig:bt},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}]),pt(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.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})}updateBounds(t){const{editMask:e}=this.editor,{mergeConfig:i,single:s,rect:o,circle:n,buttons:r,resizePoints:a,rotatePoints:h,resizeLines:l}=this,{middlePoint:d,resizeable:c,rotateable:g,hideOnSmall:u,editBox:f,mask:m}=i;if(this.visible=!this.target.locked,e.visible=!!m||0,this.view.worldOpacity){const{width:e,height:m}=t,E="number"==typeof u?u:10,v=f&&!(u&&e<E&&m<E);let b,w,y,L={};for(let s=0;s<8;s++)p.toPoint(p.directionData[s],t,L),w=a[s],b=h[s],y=l[Math.floor(s/2)],w.set(L),b.set(L),y.set(L),w.visible=y.visible=v&&!(!c&&!g),b.visible=v&&g&&c&&!i.rotatePoint,s%2&&(w.visible=b.visible=v&&!!d,(s+1)/2%2?(y.width=e,u&&2*w.width>e&&(w.visible=!1)):(y.height=m,w.rotation=90,u&&2*w.width>m&&(w.visible=!1)));n.visible=v&&g&&!(!i.circle&&!i.rotatePoint),n.visible&&this.layoutCircle(),o.path&&(o.path=null),o.set(Object.assign(Object.assign({},t),{visible:!s||f})),r.visible=v&&r.children.length>0||0,r.visible&&this.layoutButtons()}else o.set(t)}layoutCircle(){const{circleDirection:t,circleMargin:e,buttonsMargin:i,buttonsDirection:s,middlePoint:o}=this.mergedConfig,n=vt.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=vt.indexOf(e);(a%2&&n||(a+1)%2&&r)&&i&&(a=(a+2)%4);const h=i?gt.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)}unload(){this.visible=!1}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:bt};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 e=this.dragPoint=t.current,{pointType:i}=e,{editor:s,dragStartData:o}=this,{target:n}=this;"rect"===e.name&&(this.moving=!0,s.opacity=this.mergeConfig.hideOnMove?0:1),o.x=t.x,o.y=t.y,o.point={x:n.x,y:n.y},o.bounds=Object.assign({},n.getLayoutBounds("box","local")),o.rotation=n.rotation,i&&i.includes("resize")&&(b.resizingKeys=s.leafList.keys)}onDragEnd(t){this.dragging=!1,this.dragPoint=null,this.moving=!1;const{name:e,pointType:i}=t.current;"rect"===e&&(this.editor.opacity=1),i&&i.includes("resize")&&(b.resizingKeys=null)}onDrag(t){const{transformTool:e}=this,i=t.current;if("rect"===i.name)e.onMove(t),pt(this);else{const{pointType:s}=this.enterPoint=i;s.includes("rotate")||t.metaKey||t.ctrlKey||!this.mergeConfig.resizeable?(e.onRotate(t),"resize-rotate"===s&&e.onScale(t)):"resize"===s&&e.onScale(t),"skew"===s&&e.onSkew(t),ft(this,t)}}onKey(t){ft(this,t)}onArrow(t){const{editor:e}=this;if(e.editing&&this.mergeConfig.keyEvent){let i=0,s=0;const o=t.shiftKey?10:1;switch(t.code){case"ArrowDown":s=o;break;case"ArrowUp":s=-o;break;case"ArrowLeft":i=-o;break;case"ArrowRight":i=o}(i||s)&&e.move(i,s)}}onDoubleTap(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"double"!==e||i||this.openInner(t)}onLongPress(t){const{openInner:e,preventEditInner:i}=this.mergeConfig;"long"===e&&i&&this.openInner(t)}openInner(t){const{editor:e,target:i}=this;if(this.single){if(i.locked)return;if(i.isBranch&&!i.editInner){if(i.textBox){const{children:t}=i,s=t.find((t=>t.editable&&t instanceof w))||t.find((t=>t instanceof w));if(s)return e.openInnerEditor(s)}e.openGroup(i),e.target=e.selector.findDeepOne(t)}else e.openInnerEditor()}}listenPointEvents(t,e,i){t.direction=i,t.pointType=e;const s=[[R.START,this.onDragStart,this],[R.DRAG,this.onDrag,this],[R.END,this.onDragEnd,this],[C.LEAVE,()=>{this.enterPoint=null}]];"circle"!==t.name&&s.push([C.ENTER,e=>{this.enterPoint=t,ft(this,e)}]),this.__eventIds.push(t.on_(s))}__listenEvents(){const{rect:t,editor:e,__eventIds:i}=this;i.push(e.on_(z.SELECT,this.onSelect,this),t.on_([[R.START,this.onDragStart,this],[R.DRAG,this.onDrag,this],[R.END,this.onDragEnd,this],[C.ENTER,()=>pt(this)],[C.DOUBLE_TAP,this.onDoubleTap,this],[C.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer((()=>{i.push(e.app.on_([[[H.HOLD,H.UP],this.onKey,this],[H.DOWN,this.onArrow,this]]))}))}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const yt={x:0,y:0,width:1e5,height:1e5};class Lt extends h{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,yt),Object.assign(this.__world,yt)}__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 kt='\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"/>',Ot={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${kt}\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${kt}\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${kt}\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},xt=new g;function _t(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange((()=>{xt.setListWithFn(i,(t=>t.getBounds("box","page"))),0===xt.width&&(xt.width=.1),0===xt.height&&(xt.height=.1),e.reset(xt.get())})),s.add(e)}const Tt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),St=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Bt={group(t,e,i){t.sort(St);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new d(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(Tt);const r=new y(e.worldTransform);return r.divideParent(o.worldTransform),n.setTransform(r),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.isBranchLeaf?i.push(t):t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(Tt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(St),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},Mt=L.get("EditToolCreator");function Ct(){return t=>{Pt.register(t)}}const Rt=Ct,Pt={list:{},register(t){const{tag:e}=t.prototype;Vt[e]&&Mt.repeat(e),Vt[e]=t},get:(t,e)=>new Vt[t](e)},{list:Vt}=Pt;class Ht extends z{constructor(t,e){super(t,e)}}Ht.BEFORE_OPEN="innerEditor.before_open",Ht.OPEN="innerEditor.open",Ht.BEFORE_CLOSE="innerEditor.before_close",Ht.CLOSE="innerEditor.close";class It extends z{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:At}=k,Dt={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},Ft="top-left";class zt extends c{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.on(O.CHANGE,(e=>{if(this.checkChange&&Dt[e.attrName]){const{attrName:i,newValue:s,oldValue:o}=e,n="s"===i[0]?(s||1)/(o||1):(s||0)-(o||0);this.canChange=!1;const r=this.__;r[i]=o,At(this.parent),At(this);const a=new y(this.__world);switch(r[i]=s,this.__layout.rotationChange(),At(this),this.changedTransform=new y(this.__world).divide(a),i){case"x":t.move(n,0);break;case"y":t.move(0,n);break;case"rotation":t.rotateOf(Ft,n);break;case"scaleX":t.scaleOf(Ft,n,1);break;case"scaleY":t.scaleOf(Ft,1,n);break;case"skewX":t.skewOf(Ft,n,0);break;case"skewY":t.skewOf(Ft,0,n)}this.canChange=!0}}))}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class Zt extends z{constructor(t,e){super(t,e)}}Zt.BEFORE_MOVE="editor.before_move",Zt.MOVE="editor.move";class Wt extends z{constructor(t,e){super(t,e)}}Wt.BEFORE_SCALE="editor.before_scale",Wt.SCALE="editor.scale";class Xt extends z{constructor(t,e){super(t,e)}}Xt.BEFORE_ROTATE="editor.before_rotate",Xt.ROTATE="editor.rotate";class Yt extends z{constructor(t,e){super(t,e)}}Yt.BEFORE_SKEW="editor.before_skew",Yt.SKEW="editor.skew";class Gt{onMove(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox;if(t instanceof P){if("drag"!==t.moveType){const{moveable:s,resizeable:o}=i,n=t.getLocalMove(e);"move"===s?(t.stop(),this.move(n.x,n.y)):"zoom"===o&&t.stop()}}else{const i={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(i.x)>Math.abs(i.y)?i.y=0:i.x=0),this.move(R.getValidMove(e,s.point,i))}}onScale(t){const{target:e,mergeConfig:i,single:s,dragStartData:o}=this.editBox;let{around:n,lockRatio:r,resizeable:a,flipable:h,editSize:l}=i;if(t instanceof V)"zoom"===a&&(t.stop(),this.scaleOf(e.getBoxPoint(t),t.scale,t.scale));else{const{direction:i}=t.current;(t.shiftKey||e.lockRatio)&&(r=!0);const a=gt.getScaleData(e,o.bounds,i,t.getInnerTotal(e),r,gt.getAround(n,t.altKey),h,!s||"scale"===l);this.editTool&&this.editTool.onScaleWithDrag?(a.drag=t,this.scaleWithDrag(a)):this.scaleOf(a.origin,a.scaleX,a.scaleY)}}onRotate(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox,{skewable:o,rotateable:n,around:r,rotateGap:a}=i,{direction:h,name:l}=t.current;if(o&&"resize-line"===l)return this.onSkew(t);let d,c;if(t instanceof I){if("rotate"!==n)return;t.stop(),c=t.rotation,d=e.getBoxPoint(t),e.scaleX*e.scaleY<0&&(c=-c)}else{const i=gt.getRotateData(e,h,t,s,t.shiftKey?null:e.around||e.origin||r||"center");c=i.rotation,d=i.origin}e.scaleX*e.scaleY<0&&(c=-c),t instanceof R&&(c=s.rotation+c-e.rotation),c=m.float(m.getGapRotation(c,a,e.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}=gt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),gt.getAround(s,t.altKey));(n||r)&&this.skewOf(o,n,r)}move(t,e=0){if(!this.checkTransform("moveable"))return;"object"==typeof t&&(e=t.y,t=t.x);const{target:i,mergeConfig:s,single:o,editor:n}=this.editBox,{beforeMove:r}=s;if(r){const s=r({target:i,x:t,y:e});if("object"==typeof s)t=s.x,e=s.y;else if(!1===s)return}const a=i.getWorldPointByLocal({x:t,y:e},null,!0);o||i.safeChange((()=>i.move(t,e)));const h={target:i,editor:n,moveX:a.x,moveY:a.y};this.emitEvent(new Zt(Zt.BEFORE_MOVE,h));const l=new Zt(Zt.MOVE,h);this.doMove(l),this.emitEvent(l)}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 Wt(Wt.BEFORE_SCALE,t));const n=new Wt(Wt.SCALE,t);this.editTool.onScaleWithDrag(n),this.emitEvent(n)}scaleOf(t,e,i=e,s){if(!this.checkTransform("resizeable"))return;const{target:o,mergeConfig:n,single:r,editor:a}=this.editBox,{beforeScale:h}=n;if(h){const s=h({target:o,origin:t,scaleX:e,scaleY:i});if("object"==typeof s)e=s.scaleX,i=s.scaleY;else if(!1===s)return}const l=this.getWorldOrigin(t),d=!r&&this.getChangedTransform((()=>o.safeChange((()=>o.scaleOf(t,e,i))))),c={target:o,editor:a,worldOrigin:l,scaleX:e,scaleY:i,transform:d};this.emitEvent(new Wt(Wt.BEFORE_SCALE,c));const g=new Wt(Wt.SCALE,c);this.doScale(g),this.emitEvent(g)}flip(t){if(!this.checkTransform("resizeable"))return;const{target:e,single:i,editor:s}=this.editBox,o=this.getWorldOrigin("center"),n=i?new y(k.getFlipTransform(e,t)):this.getChangedTransform((()=>e.safeChange((()=>e.flip(t))))),r={target:e,editor:s,worldOrigin:o,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:n};this.emitEvent(new Wt(Wt.BEFORE_SCALE,r));const a=new Wt(Wt.SCALE,r);this.doScale(a),this.emitEvent(a)}rotateOf(t,e){if(!this.checkTransform("rotateable"))return;const{target:i,mergeConfig:s,single:o,editor:n}=this.editBox,{beforeRotate:r}=s;if(r){const s=r({target:i,origin:t,rotation:e});if("number"==typeof s)e=s;else if(!1===s)return}const a=this.getWorldOrigin(t),h=!o&&this.getChangedTransform((()=>i.safeChange((()=>i.rotateOf(t,e))))),l={target:i,editor:n,worldOrigin:a,rotation:e,transform:h};this.emitEvent(new Xt(Xt.BEFORE_ROTATE,l));const d=new Xt(Xt.ROTATE,l);this.doRotate(d),this.emitEvent(d)}skewOf(t,e,i=0,s){if(!this.checkTransform("skewable"))return;const{target:o,mergeConfig:n,single:r,editor:a}=this.editBox,{beforeSkew:h}=n;if(h){const s=h({target:o,origin:t,skewX:e,skewY:i});if("object"==typeof s)e=s.skewX,i=s.skewY;else if(!1===s)return}const l=this.getWorldOrigin(t),d=!r&&this.getChangedTransform((()=>o.safeChange((()=>o.skewOf(t,e,i))))),c={target:o,editor:a,worldOrigin:l,skewX:e,skewY:i,transform:d};this.emitEvent(new Yt(Yt.BEFORE_SKEW,c));const g=new Yt(Yt.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:e}=this.editBox;return e.getWorldPoint(k.getInnerOrigin(e,t))}getChangedTransform(t){const{target:e,single:i}=this.editBox;if(!i&&!e.canChange)return e.changedTransform;const s=new y(e.worldTransform);return t(),new y(e.worldTransform).divide(s)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}let Ut=class extends d{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,e){super(e),this.leafList=new u,this.openedGroupList=new u,this.simulateTarget=new zt(this),this.editBox=new wt(this),this.editToolList={},this.selector=new et(this),this.editMask=new Lt(this),this.targetEventIds=[];let i=x.clone(Ot);t&&(i=x.default(t,i)),this.mergedConfig=this.config=i,this.addMany(this.editMask,this.selector,this.editBox),_.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&&_t(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]||Pt.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,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=Bt.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=Bt.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:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!k.hasParent(e,t)))&&e.push(t)))),e.forEach((t=>this.closeGroup(t)))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new It(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&&Pt.list[i]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[i]||Pt.get(i,this),this.innerEditor.editTarget=e,this.emitInnerEvent(Ht.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Ht.OPEN))}}closeInnerEditor(){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Ht.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Ht.CLOSE),this.editTool.load(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Ht(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&&(Bt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Bt.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:e,editMask:i}=this;this.targetEventIds=[e.on_(T.START,this.onRenderStart,this),t.on_([[T.CHILD_START,this.onAppRenderStart,this],[P.BEFORE_MOVE,this.onMove,this,!0],[V.BEFORE_ZOOM,this.onScale,this,!0],[I.BEFORE_ROTATE,this.onRotate,this,!0]])],i.visible&&i.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())}};D([(t,s)=>{e(t,s,{get(){const{config:t,element:e,dragPoint:s}=this,o=Object.assign({},t);return e&&e.editConfig&&Object.assign(o,e.editConfig),s&&(s.editConfig&&Object.assign(o,s.editConfig),"font-size"===o.editSize&&(o.lockRatio=!0),"resize-rotate"===s.pointType&&(o.around||(o.around="center"),i(o.lockRatio)&&(o.lockRatio=!0))),this.mergedConfig=o}})}],Ut.prototype,"mergeConfig",void 0),D([Z((function(t,e){t.emitEvent(new z(z.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Ut.prototype,"hoverTarget",void 0),D([Z((function(t,e){const{target:i}=t;i?(t.leafList=i instanceof u?i:new u(i),t.multiple&&_t(t)):(t.simulateTarget.remove(),t.leafList.reset()),t.closeInnerEditor();const s={editor:t,value:i,oldValue:e};t.emitEvent(new z(z.SELECT,s)),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.updateEditTool(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents()),t.emitEvent(new z(z.AFTER_SELECT,s))}))],Ut.prototype,"target",void 0),Ut=D([A(Gt,["editBox","editTool","emitEvent"])],Ut);class jt{static registerInnerEditor(){Pt.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 d,this.onCreate()}onLoad(){}load(){const{editor:t}=this;t&&(t.app&&"focus"===this.mode&&(t.selector.hittable=t.app.tree.hitChildren=!1),this.onLoad())}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){const{editor:t}=this;t&&(t.app&&"focus"===this.mode&&(t.selector.hittable=t.app.tree.hitChildren=!0),this.onUnload())}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}let Nt=class extends jt{static registerEditTool(){Pt.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()}};Nt=D([Ct()],Nt);const{left:Kt,right:$t}=f,{move:qt,copy:Jt,toNumberPoints:Qt}=E;let te=class extends Nt{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=i===Kt;if(n.pathInputed){const{path:t}=n.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,n.points=t}else{const t=S(),{toPoint:i}=n;n.rotation=0,this.dragPoint(t,i,r,o,this.getInnerMove(n,e,s)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(i,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(i,null,null,!0),n.toPoint=i}}getInnerMove(t,e,i){const s=e.getInnerMove(t);return i&&(Math.abs(s.x)>Math.abs(s.y)?s.y=0:s.x=0),s}getFromToByPath(t){return{from:{x:t[1],y:t[2]},to:{x:t[4],y:t[5]}}}getFromToByPoints(t){const e=Qt(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?(qt(t,n,r),s&&qt(e,-n,-r)):(s&&qt(t,-n,-r),qt(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),Jt(s[7],i),Jt(e[7],i),Jt(s[3],a),Jt(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===Kt||t===$t,s[t].visible=a,e[t].visible=!r&&a}};te=D([Ct()],te),_.add("editor","resize"),B.editor=function(t,e){const i=new Ut(t);return e&&e.sky.add(e.editor=i),i},v.addAttr("textBox",!1,M),h.addAttr("editConfig",void 0,M),h.addAttr("editOuter",(t=>t.__.__isLinePath?"LineEditTool":"EditTool"),M),h.addAttr("editInner","PathEditor",M),d.addAttr("editInner","",M),w.addAttr("editInner","TextEditor",M),h.setEditConfig=function(t){this.changeAttr("editConfig",t)},h.setEditOuter=function(t){this.changeAttr("editOuter",t)},h.setEditInner=function(t){this.changeAttr("editInner",t)};export{wt as EditBox,gt as EditDataHelper,Et as EditPoint,et as EditSelect,q as EditSelectHelper,Nt as EditTool,Pt as EditToolCreator,Ut as Editor,z as EditorEvent,It as EditorGroupEvent,Bt as EditorHelper,Zt as EditorMoveEvent,Xt as EditorRotateEvent,Wt as EditorScaleEvent,Yt as EditorSkewEvent,jt as InnerEditor,Ht as InnerEditorEvent,te as LineEditTool,$ as SelectArea,K as Stroker,Gt as TransformTool,Ct as registerEditTool,Rt as registerInnerEditor};
|
|
1
|
+
import{Event as t,defineKey as e,isNull as i,MatrixHelper as s,BoundsHelper as o,LeafBoundsHelper as n,getMatrixData as r,getBoundsData as a,UI as h,Paint as l,Group as d,Rect as c,Bounds as g,LeafList as u,Direction9 as f,AroundHelper as p,MathHelper as m,PointHelper as E,Box as v,ResizeEvent as b,Text as w,Matrix as y,Debug as k,LeafHelper as L,PropertyEvent as x,DataHelper as O,Plugin as _,RenderEvent as T,getPointData as S,Creator as B,dataType as M}from"@leafer-ui/draw";import{PointerEvent as C,DragEvent as R,MoveEvent as P,ZoomEvent as V,KeyEvent as H,RotateEvent as I,useModule as A}from"@leafer-ui/core";import"@leafer-in/resize";function D(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 z(t){return t?t instanceof Array?t:[t]:[]}"function"==typeof SuppressedError&&SuppressedError;class F extends t{get list(){return z(this.value)}get oldList(){return z(this.oldValue)}constructor(t,e){super(t),e&&Object.assign(this,e)}}function Z(t){return(i,s)=>{const o="_"+s;e(i,s,{get(){return this[o]},set(e){const i=this[o];if(i!==e){if(this.config){const t="target"===s;if(t){e instanceof Array&&e.length>1&&e[0].locked&&e.splice(0,1),this.single&&(this.element.syncEventer=null);const{beforeSelect:t}=this.config;if(t){const i=t({target:e});if("object"==typeof i)e=i;else if(!1===i)return}}const o=t?F.BEFORE_SELECT:F.BEFORE_HOVER;this.hasEvent(o)&&this.emitEvent(new F(o,{editor:this,value:e,oldValue:i}))}this[o]=e,t(this,i)}}})}}F.BEFORE_SELECT="editor.before_select",F.SELECT="editor.select",F.AFTER_SELECT="editor.after_select",F.BEFORE_HOVER="editor.before_hover",F.HOVER="editor.hover";const{abs:W}=Math,{copy:G,scale:X}=s,{setListWithFn:Y}=o,{worldBounds:U}=n,j=r(),N=a();class K extends h{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?(Y(N,e,U),t&&this.set(t),this.set(N),this.visible=!0):this.visible=0}__draw(t,e){const{list:i}=this;if(i.length){let s;const o=this.__,{stroke:n,strokeWidth:r,fill:a}=o,{bounds:h}=e;for(let d=0;d<i.length;d++){s=i[d];const{worldTransform:c,worldRenderBounds:g}=s;if(g.width&&g.height&&(!h||h.hit(g,e.matrix))){const i=W(c.scaleX),h=W(c.scaleY);if(G(j,c),j.half=r%2,i!==h){X(j,1/i,1/h),t.setWorld(j,e.matrix),t.beginPath(),o.strokeWidth=r;const{x:n,y:a,width:l,height:d}=s.__layout.boxBounds;t.rect(n*i,a*h,l*i,d*h)}else t.setWorld(j,e.matrix),t.beginPath(),s.__.__useArrow?s.__drawPath(t):s.__.__pathForRender?s.__drawRenderPath(t):s.__drawPathByBox(t),o.strokeWidth=r/W(c.scaleX);n&&("string"==typeof n?l.stroke(n,this,t):l.strokes(n,this,t)),a&&("string"==typeof a?l.fill(a,this,t):l.fills(a,this,t))}}o.strokeWidth=r}}destroy(){this.target=null,super.destroy()}}D([Z((function(t){const e=t.target;t.list=e?e instanceof Array?e:[e]:[]}))],K.prototype,"target",void 0);class $ extends d{constructor(t){super(t),this.strokeArea=new c({strokeAlign:"center"}),this.fillArea=new c,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 q={findOne:t=>t.list.find((t=>t.editable)),findByBounds(t,e){const i=[];return J([t],i,e),i}};function J(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&&J(s.children,e,i)}}const{findOne:Q,findByBounds:tt}=q;class et extends d{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 K,this.targetStroker=new K,this.bounds=new g,this.selectArea=new $,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)&&(t.shiftKey||(e.target=null))}}onDragStart(t){if(!t.multiTouch&&(this.waitSelect&&this.waitSelect(),this.allowDrag(t))){const{editor:e}=this,{stroke:i,area:s}=e.mergeConfig,{x:o,y:n}=t.getInnerPoint(this);this.bounds.set(o,n),this.selectArea.setStyle({visible:!0,stroke:i,x:o,y:n},s),this.selectArea.setBounds(this.bounds.get()),this.originList=e.leafList.clone()}}onDrag(t){if(!t.multiTouch){if(this.editor.dragging)return this.onDragEnd(t);if(this.dragging){const{editor:e}=this,i=t.getInnerTotal(this),s=this.bounds.clone().unsign(),o=new u(tt(e.app,s));if(this.bounds.width=i.x,this.bounds.height=i.y,this.selectArea.setBounds(s.get()),o.length){const t=[];this.originList.forEach((e=>{o.has(e)||t.push(e)})),o.forEach((e=>{this.originList.has(e)||t.push(e)})),(t.length!==e.list.length||e.list.some(((e,i)=>e!==t[i])))&&(e.target=t)}else e.target=this.originList.list}}}onDragEnd(t){t.multiTouch||this.dragging&&(this.originList=null,this.selectArea.visible=0)}onAutoMove(t){if(this.dragging){const{x:e,y:i}=t.getLocalMove(this);this.bounds.x+=e,this.bounds.y+=i}}allow(t){return t.leafer!==this.editor.leafer}allowDrag(t){const{boxSelect:e,multipleSelect:i}=this.editor.mergeConfig;return!(!(this.running&&i&&e)||t.target.draggable)&&(!this.editor.editing&&this.allow(t.target)||t.shiftKey&&!Q(t.path))}allowSelect(t){return this.running&&!this.isMoveMode&&!t.middle}findDeepOne(t){const e={exclude:new u(this.editor.editBox.rect)};return Q(t.target.leafer.interaction.findPath(t,e))}findUI(t){return this.isMultipleSelect(t)?this.findDeepOne(t):Q(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_([[F.HOVER,this.onHover,this],[F.SELECT,this.onSelect,this]]),e.on_([[C.MOVE,this.onPointerMove,this],[C.BEFORE_DOWN,this.onBeforeDown,this],[C.TAP,this.onTap,this],[R.START,this.onDragStart,this,!0],[R.DRAG,this.onDrag,this],[R.END,this.onDragEnd,this],[P.MOVE,this.onAutoMove,this],[[V.ZOOM,P.MOVE],()=>{this.editor.hoverTarget=null}]])]}))}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=this.originList=this.needRemoveItem=null,this.__removeListenEvents(),super.destroy()}}const{topLeft:it,top:st,topRight:ot,right:nt,bottomRight:rt,bottom:at,bottomLeft:ht,left:lt}=f,{toPoint:dt}=p,{within:ct}=m,gt={getScaleData(t,e,i,s,n,r,a,h){let l,d={},c=1,u=1;const{boxBounds:f,widthRange:p,heightRange:m,dragBounds:E,worldBoxBounds:v}=t,{width:b,height:w}=e;r&&(s.x*=2,s.y*=2);const y=t.scaleX/e.scaleX,k=t.scaleY/e.scaleY,L=y<0?-1:1,x=k<0?-1:1,O=h?y:L*f.width/b,_=h?k:x*f.height/w;s.x*=h?y:L,s.y*=h?k:x;const T=(-s.y+w)/w,S=(s.x+b)/b,B=(s.y+w)/w,M=(-s.x+b)/b;switch(i){case st:u=T,l="bottom";break;case nt:c=S,l="left";break;case at:u=B,l="top";break;case lt:c=M,l="right";break;case it:u=T,c=M,l="bottom-right";break;case ot:u=T,c=S,l="bottom-left";break;case rt:u=B,c=S,l="top-left";break;case ht:u=B,c=M,l="top-right"}if(n)if("corner"===n&&i%2)n=!1;else{let t;switch(i){case st:case at:t=u;break;case lt:case nt:t=c;break;default:t=Math.sqrt(Math.abs(c*u))}c=c<0?-t:t,u=u<0?-t:t}const C=1!==c,R=1!==u;if(C&&(c/=O),R&&(u/=_),!a){const{worldTransform:e}=t;c<0&&(c=1/f.width/e.scaleX),u<0&&(u=1/f.height/e.scaleY)}if(dt(r||l,f,d,!0),E){const e="parent"===E?t.parent.boxBounds:E,i=new g(t.__localBoxBounds);if(o.includes(new g(e).spread(.1),i)&&(i.scaleOf(t.getLocalPointByInner(d),c,u),!o.includes(e,i))){const t=i.getIntersect(e),s=t.width/i.width,o=t.height/i.height;C&&(c*=s),R&&(u*=o)}}if(C&&p){const e=f.width*t.scaleX;c=ct(e*c,p)/e}if(R&&m){const e=f.height*t.scaleY;u=ct(e*u,m)/e}return C&&Math.abs(c*v.width)<1&&(c=(c<0?-1:1)/v.width),R&&Math.abs(u*v.height)<1&&(u=(u<0?-1:1)/v.height),n&&c!==u&&(u=c=Math.min(c,u)),{origin:d,scaleX:c,scaleY:u,direction:i,lockRatio:n,around:r}},getRotateData(t,e,i,s,o){let n,r={};switch(e){case it:n="bottom-right";break;case ot:n="bottom-left";break;case rt:n="top-left";break;case ht:n="top-right";break;default:n="center"}return dt(o||n,t.boxBounds,r,!0),{origin:r,rotation:E.getRotation(s,t.getWorldPointByBox(r),i)}},getSkewData(t,e,i,s){let o,n,r={},a=0,h=0;switch(e){case st:case it:n={x:.5,y:0},o="bottom",a=1;break;case at:case rt:n={x:.5,y:1},o="top",a=1;break;case lt:case ht:n={x:0,y:.5},o="right",h=1;break;case nt:case ot:n={x:1,y:.5},o="left",h=1}const{width:l,height:d}=t;n.x=n.x*l,n.y=n.y*d,dt(s||o,t,r,!0);const c=E.getRotation(n,r,{x:n.x+(a?i.x:0),y:n.y+(h?i.y:0)});return a?a=-c:h=c,{origin:r,skewX:a,skewY:h}},getAround:(t,e)=>e&&!t?"center":t,getRotateDirection:(t,e,i=8)=>((t=(t+Math.round(e/(360/i)))%i)<0&&(t+=i),t),getFlipDirection(t,e,i){if(e)switch(t){case lt:t=nt;break;case it:t=ot;break;case ht:t=rt;break;case nt:t=lt;break;case ot:t=it;break;case rt:t=ht}if(i)switch(t){case st:t=at;break;case it:t=ht;break;case ot:t=rt;break;case at:t=st;break;case ht:t=it;break;case rt:t=ot}return t}},ut={};function ft(t,e){const{enterPoint:i,dragging:s,skewing:o,resizing:n,flippedX:r,flippedY:a}=t;if(!i||!t.editor.editing||!t.canUse)return;if("circle"===i.name)return;if("button"===i.pointType)return void(i.cursor||(i.cursor="pointer"));let{rotation:h}=t;const{pointType:l}=i,{resizeCursor:d,rotateCursor:c,skewCursor:g,resizeable:u,rotateable:f,skewable:p}=t.mergeConfig;let E=l.includes("resize");E&&f&&(e.metaKey||e.ctrlKey||!u)&&(E=!1);const v=p&&!E&&("resize-line"===i.name||"skew"===l),b=s?o?g:n?d:c:v?g:E?d:c;h+=45*(gt.getFlipDirection(i.direction,r,a)+1),h=2*Math.round(m.formatRotation(h,!0)/2);const{url:w,x:y,y:k}=b,L=w+h;ut[L]?i.cursor=ut[L]:ut[L]=i.cursor={url:mt(w,h),x:y,y:k}}function pt(t){const{moveCursor:e,moveable:i}=t.mergeConfig;t.canUse&&(t.rect.cursor=i?e:void 0)}function mt(t,e){return'"data:image/svg+xml,'+encodeURIComponent(t.replace("{{rotation}}",e.toString()))+'"'}class Et extends v{constructor(t){super(t),this.useFastShadow=!0}}const vt=["top","right","bottom","left"],bt=void 0;class wt extends d{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:e,rotateable:i}=this.mergeConfig;return"string"==typeof t||"string"==typeof e||"string"==typeof i}constructor(t){super(),this.view=new d,this.rect=new v({name:"rect",hitFill:"all",hitStroke:"none",strokeAlign:"center",hitRadius:5}),this.circle=new Et({name:"circle",strokeAlign:"center",around:"center",cursor:"crosshair",hitRadius:5}),this.buttons=new d({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 Et({name:"rotate-point",around:d[s],width:15,height:15,hitFill:"all"}),n.push(t),this.listenPointEvents(t,"rotate",s),s%2&&(e=new Et({name:"resize-line",around:"center",width:10,height:10,hitFill:"all"}),r.push(e),this.listenPointEvents(e,"resize",s)),i=new Et({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;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:bt},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}]),pt(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.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:e}=this.editor,{mergeConfig:i,single:s,rect:n,circle:r,buttons:a,resizePoints:h,rotatePoints:l,resizeLines:d}=this,{middlePoint:c,resizeable:g,rotateable:u,hideOnSmall:f,editBox:m,mask:E,spread:v}=i;if(this.visible=!this.target.locked,e.visible=!!E||0,v&&o.spread(t,v),this.view.worldOpacity){const{width:e,height:o}=t,E="number"==typeof f?f:10,v=m&&!(f&&e<E&&o<E);let b,w,y,k={};for(let s=0;s<8;s++)p.toPoint(p.directionData[s],t,k),w=h[s],b=l[s],y=d[Math.floor(s/2)],w.set(k),b.set(k),y.set(k),w.visible=y.visible=v&&!(!g&&!u),b.visible=v&&u&&g&&!i.rotatePoint,s%2&&(w.visible=b.visible=v&&!!c,(s+1)/2%2?(y.width=e,f&&2*w.width>e&&(w.visible=!1)):(y.height=o,f&&2*w.width>o&&(w.visible=!1)));r.visible=v&&u&&!(!i.circle&&!i.rotatePoint),r.visible&&this.layoutCircle(),n.path&&(n.path=null),n.set(Object.assign(Object.assign({},t),{visible:!s||m})),a.visible=v&&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=vt.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=vt.indexOf(e);(a%2&&n||(a+1)%2&&r)&&i&&(a=(a+2)%4);const h=i?gt.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:bt};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()}onDragStart(t){this.dragging=!0;const e=this.dragPoint=t.current,{pointType:i}=e,{editor:s,dragStartData:o}=this,{target:n}=this,{moveable:r,resizeable:a,rotateable:h,skewable:l,hideOnMove:d}=this.mergeConfig;"rect"===e.name?(r&&(this.moving=!0),s.opacity=d?0:1):(i.includes("rotate")||t.metaKey||t.ctrlKey||!a?(h&&(this.rotating=!0),"resize-rotate"===i?a&&(this.resizing=!0):"resize-line"===e.name&&(l&&(this.skewing=!0),this.rotating=!1)):"resize"===i&&a&&(this.resizing=!0),"skew"===i&&l&&(this.skewing=!0)),o.x=t.x,o.y=t.y,o.point={x:n.x,y:n.y},o.bounds=Object.assign({},n.getLayoutBounds("box","local")),o.rotation=n.rotation,i&&i.includes("resize")&&(b.resizingKeys=s.leafList.keys)}onDragEnd(t){this.dragPoint=null,this.resetDoing();const{name:e,pointType:i}=t.current;"rect"===e&&(this.editor.opacity=1),i&&i.includes("resize")&&(b.resizingKeys=null)}onDrag(t){const{transformTool:e,moving:i,resizing:s,rotating:o,skewing:n}=this;if(i)e.onMove(t),pt(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),ft(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(),"string"==typeof this.mergeConfig.moveable&&(this.gesturing=this.moving=!0,this.transformTool.onMove(t)))}onScale(t){this.canGesture&&(t.stop(),"string"==typeof this.mergeConfig.resizeable&&(this.gesturing=this.resizing=!0,this.transformTool.onScale(t)))}onRotate(t){this.canGesture&&(t.stop(),"string"==typeof this.mergeConfig.rotateable&&(this.gesturing=this.rotating=!0,this.transformTool.onRotate(t)))}onKey(t){ft(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:e,target:i}=this;if(this.single){if(i.locked)return;if(i.isBranch&&!i.editInner){if(i.textBox){const{children:t}=i,s=t.find((t=>t.editable&&t instanceof w))||t.find((t=>t instanceof w));if(s)return e.openInnerEditor(s)}e.openGroup(i),e.target=e.selector.findDeepOne(t)}else e.openInnerEditor()}}listenPointEvents(t,e,i){t.direction=i,t.pointType=e;const s=[[R.START,this.onDragStart,this],[R.DRAG,this.onDrag,this],[R.END,this.onDragEnd,this],[C.LEAVE,()=>{this.enterPoint=null}]];"circle"!==t.name&&s.push([C.ENTER,e=>{this.enterPoint=t,ft(this,e)}]),this.__eventIds.push(t.on_(s))}__listenEvents(){const{rect:t,editor:e,__eventIds:i}=this;i.push(t.on_([[R.START,this.onDragStart,this],[R.DRAG,this.onDrag,this],[R.END,this.onDragEnd,this],[C.ENTER,()=>pt(this)],[C.DOUBLE_TAP,this.onDoubleTap,this],[C.LONG_PRESS,this.onLongPress,this]])),this.waitLeafer((()=>{i.push(e.app.on_([[[H.HOLD,H.UP],this.onKey,this],[H.DOWN,this.onArrow,this],[P.BEFORE_MOVE,this.onMove,this,!0],[V.BEFORE_ZOOM,this.onScale,this,!0],[I.BEFORE_ROTATE,this.onRotate,this,!0],[P.END,this.resetDoing,this],[V.END,this.resetDoing,this],[I.END,this.resetDoing,this]]))}))}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.editor=null,this.__removeListenEvents(),super.destroy()}}const yt={x:0,y:0,width:1e5,height:1e5};class kt extends h{constructor(t){super(),this.editor=t,this.hittable=!1,this.visible=0}__updateWorldBounds(){Object.assign(this.__local,yt),Object.assign(this.__world,yt)}__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 Lt='\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"/>',xt={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${Lt}\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${Lt}\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${Lt}\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},Ot=new g;function _t(t){const{simulateTarget:e,list:i}=t,{zoomLayer:s}=i[0].leafer;e.safeChange((()=>{Ot.setListWithFn(i,(t=>t.getBounds("box","page"))),0===Ot.width&&(Ot.width=.1),0===Ot.height&&(Ot.height=.1),e.reset(Ot.get())})),s.add(e)}const Tt=(t,e)=>t.parent.children.indexOf(t)-e.parent.children.indexOf(e),St=(t,e)=>e.parent.children.indexOf(e)-t.parent.children.indexOf(t),Bt={group(t,e,i){t.sort(St);const{app:s,parent:o}=t[0];let n;n=i&&i.add?i:new d(i),o.addAt(n,o.children.indexOf(t[0])),t.sort(Tt);const r=new y(e.worldTransform);return r.divideParent(o.worldTransform),n.setTransform(r),n.editable=!0,n.hitChildren=!1,s.lockLayout(),t.forEach((t=>t.dropTo(n))),s.unlockLayout(),n},ungroup(t){const{app:e}=t[0],i=[];return e.lockLayout(),t.forEach((t=>{if(t.isBranch){const{parent:e,children:s}=t;for(;s.length;)i.push(s[0]),s[0].dropTo(e,e.children.indexOf(t));t.isBranchLeaf?i.push(t):t.remove()}else i.push(t)})),e.unlockLayout(),i},toTop(t){t.sort(Tt),t.forEach((t=>{t.parent&&t.parent.add(t)}))},toBottom(t){t.sort(St),t.forEach((t=>{t.parent&&t.parent.addAt(t,0)}))}},Mt=k.get("EditToolCreator");function Ct(){return t=>{Pt.register(t)}}const Rt=Ct,Pt={list:{},register(t){const{tag:e}=t.prototype;Vt[e]&&Mt.repeat(e),Vt[e]=t},get:(t,e)=>new Vt[t](e)},{list:Vt}=Pt;class Ht extends F{constructor(t,e){super(t,e)}}Ht.BEFORE_OPEN="innerEditor.before_open",Ht.OPEN="innerEditor.open",Ht.BEFORE_CLOSE="innerEditor.before_close",Ht.CLOSE="innerEditor.close";class It extends F{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:At}=L,Dt={x:1,y:1,scaleX:1,scaleY:1,rotation:1,skewX:1,skewY:1},zt="top-left";class Ft extends c{get __tag(){return"SimulateElement"}constructor(t){super(),this.checkChange=!0,this.canChange=!0,this.visible=this.hittable=!1,this.on(x.CHANGE,(e=>{if(this.checkChange&&Dt[e.attrName]){const{attrName:i,newValue:s,oldValue:o}=e,n="s"===i[0]?(s||1)/(o||1):(s||0)-(o||0);this.canChange=!1;const r=this.__;r[i]=o,At(this.parent),At(this);const a=new y(this.__world);switch(r[i]=s,this.__layout.rotationChange(),At(this),this.changedTransform=new y(this.__world).divide(a),i){case"x":t.move(n,0);break;case"y":t.move(0,n);break;case"rotation":t.rotateOf(zt,n);break;case"scaleX":t.scaleOf(zt,n,1);break;case"scaleY":t.scaleOf(zt,1,n);break;case"skewX":t.skewOf(zt,n,0);break;case"skewY":t.skewOf(zt,0,n)}this.canChange=!0}}))}safeChange(t){this.canChange&&(this.checkChange=!1,t(),this.checkChange=!0)}}class Zt extends F{constructor(t,e){super(t,e)}}Zt.BEFORE_MOVE="editor.before_move",Zt.MOVE="editor.move";class Wt extends F{constructor(t,e){super(t,e)}}Wt.BEFORE_SCALE="editor.before_scale",Wt.SCALE="editor.scale";class Gt extends F{constructor(t,e){super(t,e)}}Gt.BEFORE_ROTATE="editor.before_rotate",Gt.ROTATE="editor.rotate";class Xt extends F{constructor(t,e){super(t,e)}}Xt.BEFORE_SKEW="editor.before_skew",Xt.SKEW="editor.skew";class Yt{onMove(t){const{target:e,dragStartData:i}=this.editBox;if(t instanceof P){const i=t.getLocalMove(e);this.move(i.x,i.y)}else{const s={x:t.totalX,y:t.totalY};t.shiftKey&&(Math.abs(s.x)>Math.abs(s.y)?s.y=0:s.x=0),this.move(R.getValidMove(e,i.point,s))}}onScale(t){const{target:e,mergeConfig:i,single:s,dragStartData:o}=this.editBox;let{around:n,lockRatio:r,flipable:a,editSize:h}=i;if(t instanceof V)this.scaleOf(e.getBoxPoint(t),t.scale,t.scale);else{const{direction:i}=t.current;(t.shiftKey||e.lockRatio)&&(r=!0);const l=gt.getScaleData(e,o.bounds,i,t.getInnerTotal(e),r,gt.getAround(n,t.altKey),a,!s||"scale"===h);this.editTool&&this.editTool.onScaleWithDrag?(l.drag=t,this.scaleWithDrag(l)):this.scaleOf(l.origin,l.scaleX,l.scaleY)}}onRotate(t){const{target:e,mergeConfig:i,dragStartData:s}=this.editBox,{around:o,rotateAround:n,rotateGap:r}=i,{direction:a}=t.current;let h,l;if(t instanceof I)l=t.rotation,h=n?p.getPoint(n,e.boxBounds):e.getBoxPoint(t);else{const i=gt.getRotateData(e,a,t,s,t.shiftKey?null:n||e.around||e.origin||o||"center");l=s.rotation+i.rotation-e.rotation,h=i.origin}l=m.float(m.getGapRotation(l,r,e.rotation),2),l&&this.rotateOf(h,l)}onSkew(t){const{target:e,mergeConfig:i}=this.editBox,{around:s}=i,{origin:o,skewX:n,skewY:r}=gt.getSkewData(e.boxBounds,t.current.direction,t.getInnerMove(e),gt.getAround(s,t.altKey));(n||r)&&this.skewOf(o,n,r)}move(t,e=0){if(!this.checkTransform("moveable"))return;"object"==typeof t&&(e=t.y,t=t.x);const{target:i,mergeConfig:s,single:o,editor:n}=this.editBox,{beforeMove:r}=s;if(r){const s=r({target:i,x:t,y:e});if("object"==typeof s)t=s.x,e=s.y;else if(!1===s)return}const a=i.getWorldPointByLocal({x:t,y:e},null,!0);o||i.safeChange((()=>i.move(t,e)));const h={target:i,editor:n,moveX:a.x,moveY:a.y};this.emitEvent(new Zt(Zt.BEFORE_MOVE,h));const l=new Zt(Zt.MOVE,h);this.doMove(l),this.emitEvent(l)}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 Wt(Wt.BEFORE_SCALE,t));const n=new Wt(Wt.SCALE,t);this.editTool.onScaleWithDrag(n),this.emitEvent(n)}scaleOf(t,e,i=e,s){if(!this.checkTransform("resizeable"))return;const{target:o,mergeConfig:n,single:r,editor:a}=this.editBox,{beforeScale:h}=n;if(h){const s=h({target:o,origin:t,scaleX:e,scaleY:i});if("object"==typeof s)e=s.scaleX,i=s.scaleY;else if(!1===s)return}const l=this.getWorldOrigin(t),d=!r&&this.getChangedTransform((()=>o.safeChange((()=>o.scaleOf(t,e,i))))),c={target:o,editor:a,worldOrigin:l,scaleX:e,scaleY:i,transform:d};this.emitEvent(new Wt(Wt.BEFORE_SCALE,c));const g=new Wt(Wt.SCALE,c);this.doScale(g),this.emitEvent(g)}flip(t){if(!this.checkTransform("resizeable"))return;const{target:e,single:i,editor:s}=this.editBox,o=this.getWorldOrigin("center"),n=i?new y(L.getFlipTransform(e,t)):this.getChangedTransform((()=>e.safeChange((()=>e.flip(t))))),r={target:e,editor:s,worldOrigin:o,scaleX:"x"===t?-1:1,scaleY:"y"===t?-1:1,transform:n};this.emitEvent(new Wt(Wt.BEFORE_SCALE,r));const a=new Wt(Wt.SCALE,r);this.doScale(a),this.emitEvent(a)}rotateOf(t,e){if(!this.checkTransform("rotateable"))return;const{target:i,mergeConfig:s,single:o,editor:n}=this.editBox,{beforeRotate:r}=s;if(r){const s=r({target:i,origin:t,rotation:e});if("number"==typeof s)e=s;else if(!1===s)return}const a=this.getWorldOrigin(t),h=!o&&this.getChangedTransform((()=>i.safeChange((()=>i.rotateOf(t,e))))),l={target:i,editor:n,worldOrigin:a,rotation:e,transform:h};this.emitEvent(new Gt(Gt.BEFORE_ROTATE,l));const d=new Gt(Gt.ROTATE,l);this.doRotate(d),this.emitEvent(d)}skewOf(t,e,i=0,s){if(!this.checkTransform("skewable"))return;const{target:o,mergeConfig:n,single:r,editor:a}=this.editBox,{beforeSkew:h}=n;if(h){const s=h({target:o,origin:t,skewX:e,skewY:i});if("object"==typeof s)e=s.skewX,i=s.skewY;else if(!1===s)return}const l=this.getWorldOrigin(t),d=!r&&this.getChangedTransform((()=>o.safeChange((()=>o.skewOf(t,e,i))))),c={target:o,editor:a,worldOrigin:l,skewX:e,skewY:i,transform:d};this.emitEvent(new Xt(Xt.BEFORE_SKEW,c));const g=new Xt(Xt.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:e}=this.editBox;return e.getWorldPoint(L.getInnerOrigin(e,t))}getChangedTransform(t){const{target:e,single:i}=this.editBox;if(!i&&!e.canChange)return e.changedTransform;const s=new y(e.worldTransform);return t(),new y(e.worldTransform).divide(s)}emitEvent(t,e){this.editBox.editor.emitEvent(t,e)}}let Ut=class extends d{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,e){super(e),this.leafList=new u,this.openedGroupList=new u,this.simulateTarget=new Ft(this),this.editBox=new wt(this),this.editToolList={},this.selector=new et(this),this.editMask=new kt(this),this.targetEventIds=[];let i=O.clone(xt);t&&(i=O.default(t,i)),this.mergedConfig=this.config=i,this.addMany(this.editMask,this.selector,this.editBox),_.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&&_t(this),this.update()}updateEditTool(){if(this.unloadEditTool(),this.editing){const t=this.element.editOuter||"EditTool",e=this.editTool=this.editToolList[t]=this.editToolList[t]||Pt.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(It.BEFORE_GROUP),this.target=Bt.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=Bt.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:e}=t;this.editing&&(e=[],t.forEach((t=>this.list.every((e=>!L.hasParent(e,t)))&&e.push(t)))),e.forEach((t=>this.closeGroup(t)))}this.editing&&!this.selector.dragging&&this.checkDeepSelect()}checkDeepSelect(){let t,{list:e}=this;for(let i=0;i<e.length;i++)for(t=e[i].parent;t&&!t.hitChildren;)this.openGroup(t),t=t.parent}emitGroupEvent(t,e){const i=new It(t,{editTarget:e});this.emitEvent(i),e&&e.emitEvent(i)}openInnerEditor(t,e,i){let s;if("string"==typeof e?s=e:i||(i=e),t&&i&&(this.target=t),this.single){const e=t||this.element;s||(s=e.editInner),s&&Pt.list[s]&&(this.editTool.unload(),this.innerEditing=!0,this.innerEditor=this.editToolList[s]=this.editToolList[s]||Pt.get(s,this),this.innerEditor.editTarget=e,this.emitInnerEvent(Ht.BEFORE_OPEN),this.innerEditor.load(),this.emitInnerEvent(Ht.OPEN))}}closeInnerEditor(t){this.innerEditing&&(this.innerEditing=!1,this.emitInnerEvent(Ht.BEFORE_CLOSE),this.innerEditor.unload(),this.emitInnerEvent(Ht.CLOSE),t||this.updateEditTool(),this.innerEditor=null)}emitInnerEvent(t){const{innerEditor:e}=this,{editTarget:i}=e,s=new Ht(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&&(Bt.toTop(this.list),this.leafList.update())}toBottom(){this.list.length&&(Bt.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:e,editMask:i}=this;this.targetEventIds=[e.on_(T.START,this.onRenderStart,this),t.on_(T.CHILD_START,this.onAppRenderStart,this)],i.visible&&i.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())}};D([(t,s)=>{e(t,s,{get(){const{config:t,element:e,dragPoint:s,editBox:o}=this,n=Object.assign({},t);return e&&e.editConfig&&Object.assign(n,e.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"),i(n.lockRatio)&&(n.lockRatio=!0))),this.mergedConfig=n}})}],Ut.prototype,"mergeConfig",void 0),D([Z((function(t,e){t.emitEvent(new F(F.HOVER,{editor:t,value:t.hoverTarget,oldValue:e}))}))],Ut.prototype,"hoverTarget",void 0),D([Z((function(t,e){const{target:i}=t;i?(t.leafList=i instanceof u?i:new u(i),t.multiple&&_t(t)):(t.simulateTarget.remove(),t.leafList.reset()),t.closeInnerEditor(!0),t.unloadEditTool();const s={editor:t,value:i,oldValue:e};t.emitEvent(new F(F.SELECT,s)),t.checkOpenedGroups(),t.editing?t.waitLeafer((()=>{t.updateEditTool(),t.listenTargetEvents()})):(t.updateEditTool(),t.removeTargetEvents()),t.emitEvent(new F(F.AFTER_SELECT,s))}))],Ut.prototype,"target",void 0),Ut=D([A(Yt,["editBox","editTool","emitEvent"])],Ut);class jt{static registerInnerEditor(){Pt.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 d,this.onCreate()}onLoad(){}load(){const{editor:t}=this;t&&(t.app&&"focus"===this.mode&&(t.selector.hittable=t.app.tree.hitChildren=!1),this.onLoad())}onUpdate(){}update(){this.onUpdate()}onUnload(){}unload(){const{editor:t}=this;t&&(t.app&&"focus"===this.mode&&(t.selector.hittable=t.app.tree.hitChildren=!0),this.onUnload())}onDestroy(){}destroy(){this.onDestroy(),this.editor&&(this.view&&this.view.destroy(),this.eventIds&&this.editor.off_(this.eventIds),this.editor=this.view=this.eventIds=null)}}let Nt=class extends jt{static registerEditTool(){Pt.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()}};Nt=D([Ct()],Nt);const{left:Kt,right:$t}=f,{move:qt,copy:Jt,toNumberPoints:Qt}=E;let te=class extends Nt{constructor(){super(...arguments),this.scaleOfEvent=!0}get tag(){return"LineEditTool"}onScaleWithDrag(t){const{drag:e,direction:i,lockRatio:s,around:o}=t,n=t.target,r=i===Kt;if(n.pathInputed){const{path:t}=n.__,{from:i,to:a}=this.getFromToByPath(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[1]=i.x,t[2]=i.y,t[4]=a.x,t[5]=a.y,n.path=t}else if(n.points){const{points:t}=n,{from:i,to:a}=this.getFromToByPoints(t);this.dragPoint(i,a,r,o,this.getInnerMove(n,e,s)),t[0]=i.x,t[1]=i.y,t[2]=a.x,t[3]=a.y,n.points=t}else{const t=S(),{toPoint:i}=n;n.rotation=0,this.dragPoint(t,i,r,o,this.getInnerMove(n,e,s)),n.getLocalPointByInner(t,null,null,!0),n.getLocalPointByInner(i,null,null,!0),n.x=t.x,n.y=t.y,n.getInnerPointByLocal(i,null,null,!0),n.toPoint=i}}getInnerMove(t,e,i){const s=e.getInnerMove(t);return i&&(Math.abs(s.x)>Math.abs(s.y)?s.y=0:s.x=0),s}getFromToByPath(t){return{from:{x:t[1],y:t[2]},to:{x:t[4],y:t[5]}}}getFromToByPoints(t){const e=Qt(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?(qt(t,n,r),s&&qt(e,-n,-r)):(s&&qt(t,-n,-r),qt(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),Jt(s[7],i),Jt(e[7],i),Jt(s[3],a),Jt(e[3],a)}for(let t=0;t<8;t++)t<4&&(i[t].visible=!1),a=t===Kt||t===$t,s[t].visible=a,e[t].visible=!r&&a}};te=D([Ct()],te),_.add("editor","resize"),B.editor=function(t,e){const i=new Ut(t);return e&&e.sky.add(e.editor=i),i},v.addAttr("textBox",!1,M),h.addAttr("editConfig",void 0,M),h.addAttr("editOuter",(t=>(t.updateLayout(),t.__.__isLinePath?"LineEditTool":"EditTool")),M),h.addAttr("editInner","PathEditor",M),d.addAttr("editInner","",M),w.addAttr("editInner","TextEditor",M),h.setEditConfig=function(t){this.changeAttr("editConfig",t)},h.setEditOuter=function(t){this.changeAttr("editOuter",t)},h.setEditInner=function(t){this.changeAttr("editInner",t)};export{wt as EditBox,gt as EditDataHelper,Et as EditPoint,et as EditSelect,q as EditSelectHelper,Nt as EditTool,Pt as EditToolCreator,Ut as Editor,F as EditorEvent,It as EditorGroupEvent,Bt as EditorHelper,Zt as EditorMoveEvent,Gt as EditorRotateEvent,Wt as EditorScaleEvent,Xt as EditorSkewEvent,jt as InnerEditor,Ht as InnerEditorEvent,te as LineEditTool,$ as SelectArea,K as Stroker,Yt as TransformTool,Ct as registerEditTool,Rt as registerInnerEditor};
|
|
2
2
|
//# sourceMappingURL=editor.esm.min.js.map
|