@leafer-ui/draw 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.
@@ -1,2 +1,2 @@
1
- import{defineKey as t,decorateLeafAttr as e,attr as i,Plugin as s,PathConvert as o,DataHelper as r,Debug as a,LeafData as n,canvasSizeAttrs as _,UICreator as h,dataProcessor as d,dataType as p,surfaceType as l,opacityType as u,visibleType as c,sortType as y,maskType as g,eraserType as v,positionType as f,boundsType as w,scaleType as x,rotationType as m,autoLayoutType as S,naturalBoundsType as R,pathInputType as k,pathType as b,hitType as B,strokeType as A,cursorType as C,rewrite as P,Leaf as F,useModule as E,rewriteAble as I,MathHelper as W,pen as T,PathCorner as D,PathDrawer as z,registerUI as L,Branch as M,LeafList as O,Resource as N,getBoundsData as V,Creator as j,CanvasManager as Y,WaitHelper as U,LeaferEvent as X,Bounds as H,ResizeEvent as q,AutoBounds as G,Run as J,LayoutEvent as $,RenderEvent as K,WatchEvent as Q,ImageManager as Z,BoundsHelper as tt,affectRenderBoundsType as et,PathCommandDataHelper as it,Platform as st,PointHelper as ot,PathBounds as rt,affectStrokeBoundsType as at,getPointData as nt,LeaferImage as _t,ImageEvent as ht,Matrix as dt,PathCreator as pt}from"@leafer/core";export*from"@leafer/core";function lt(t,e,i,s){var o,r=arguments.length,a=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,s);else for(var n=t.length-1;n>=0;n--)(o=t[n])&&(a=(r<3?o(a):r>3?o(e,i,a):o(e,i))||a);return r>3&&a&&Object.defineProperty(e,i,a),a}function ut(t){return e(t,(t=>i({set(e){this.__setAttr(t,e),e&&(this.__.__useEffect=!0),this.__layout.renderChanged||this.__layout.renderChange()}})))}function ct(t){return e(t,(t=>i({set(e){this.__setAttr(t,e),this.__layout.boxChanged||this.__layout.boxChange(),this.__updateSize()}})))}function yt(){return(e,i)=>{const s="_"+i;t(e,i,{set(t){this.isLeafer&&(this[s]=t)},get(){return this.isApp?this.tree.zoomLayer:this.isLeafer?this[s]||this:this.leafer&&this.leafer.zoomLayer}})}}"function"==typeof SuppressedError&&SuppressedError;const gt={},vt={hasTransparent:function(t){if(!t||7===t.length||4===t.length)return!1;if("transparent"===t)return!0;const e=t[0];if("#"===e)switch(t.length){case 5:return"f"!==t[4]&&"F"!==t[4];case 9:return"f"!==t[7]&&"F"!==t[7]||"f"!==t[8]&&"F"!==t[8]}else if(("r"===e||"h"===e)&&"a"===t[3]){const e=t.lastIndexOf(",");if(e>-1)return parseFloat(t.slice(e+1))<1}return!1}},ft={number:(t,e)=>"object"==typeof t?"percent"===t.type?t.value*e:t.value:t},wt={},xt={},mt={},St={},Rt={},kt={apply(){s.need("filter")}},bt={},Bt={setStyleName:()=>s.need("state"),set:()=>s.need("state")},At={list:{},register(t,e){At.list[t]=e},get:t=>At.list[t]},{parse:Ct,objectToCanvasData:Pt}=o,{stintSet:Ft}=r,{hasTransparent:Et}=vt,It={},Wt=a.get("UIData");class Tt extends n{get scale(){const{scaleX:t,scaleY:e}=this;return t!==e?{x:t,y:e}:t}get __strokeWidth(){const{strokeWidth:t,strokeWidthFixed:e}=this;if(e){const e=this.__leaf;let{scaleX:i}=e.__nowWorld||e.__world;return i<0&&(i=-i),i>1?t/i:t}return t}get __hasMultiPaint(){const t=this;return t.fill&&this.__useStroke||t.__isFills&&t.fill.length>1||t.__isStrokes&&t.stroke.length>1||t.__useEffect}get __clipAfterFill(){const t=this;return t.cornerRadius||t.innerShadow||t.__pathInputed}get __hasSurface(){return this.fill||this.stroke}get __autoWidth(){return!this._width}get __autoHeight(){return!this._height}get __autoSide(){return!this._width||!this._height}get __autoSize(){return!this._width&&!this._height}setVisible(t){this._visible=t;const{leafer:e}=this.__leaf;e&&(e.watcher.hasVisible=!0)}setWidth(t){t<0?(this._width=-t,this.__leaf.scaleX*=-1,Wt.warn("width < 0, instead -scaleX ",this)):this._width=t}setHeight(t){t<0?(this._height=-t,this.__leaf.scaleY*=-1,Wt.warn("height < 0, instead -scaleY",this)):this._height=t}setFill(t){this.__naturalWidth&&this.__removeNaturalSize(),"string"!=typeof t&&t?"object"==typeof t&&this.__setPaint("fill",t):(Ft(this,"__isTransparentFill",Et(t)),this.__isFills&&this.__removePaint("fill",!0),this._fill=t)}setStroke(t){"string"!=typeof t&&t?"object"==typeof t&&this.__setPaint("stroke",t):(Ft(this,"__isTransparentStroke",Et(t)),this.__isStrokes&&this.__removePaint("stroke",!0),this._stroke=t)}setPath(t){const e="string"==typeof t;e||t&&"object"==typeof t[0]?(this.__setInput("path",t),this._path=e?Ct(t):Pt(t)):(this.__input&&this.__removeInput("path"),this._path=t)}setShadow(t){Dt(this,"shadow",t)}setInnerShadow(t){Dt(this,"innerShadow",t)}setFilter(t){Dt(this,"filter",t)}__computePaint(){const{fill:t,stroke:e}=this.__input;t&&xt.compute("fill",this.__leaf),e&&xt.compute("stroke",this.__leaf),this.__needComputePaint=void 0}__setPaint(t,e){this.__setInput(t,e);const i=this.__leaf.__layout;i.boxChanged||i.boxChange(),e instanceof Array&&!e.length?this.__removePaint(t):"fill"===t?(this.__isFills=!0,this._fill||(this._fill=It)):(this.__isStrokes=!0,this._stroke||(this._stroke=It))}__removePaint(t,e){e&&this.__removeInput(t),mt.recycleImage(t,this),"fill"===t?(Ft(this,"__isAlphaPixelFill",void 0),this._fill=this.__isFills=void 0):(Ft(this,"__isAlphaPixelStroke",void 0),this._stroke=this.__isStrokes=void 0)}}function Dt(t,e,i){t.__setInput(e,i),i instanceof Array?(i.some((t=>!1===t.visible))&&(i=i.filter((t=>!1!==t.visible))),i.length||(i=void 0)):i=i&&!1!==i.visible?[i]:void 0,t["_"+e]=i}class zt extends Tt{}class Lt extends zt{get __boxStroke(){return!this.__pathInputed}get __drawAfterFill(){const t=this;return"hide"===t.overflow&&(t.__clipAfterFill||t.innerShadow)&&t.__leaf.children.length}get __clipAfterFill(){return this.__leaf.isOverflow||super.__clipAfterFill}}class Mt extends zt{__getInputData(t,e){const i=super.__getInputData(t,e);return _.forEach((t=>delete i[t])),i}}class Ot extends Lt{}class Nt extends Tt{}class Vt extends Tt{get __boxStroke(){return!this.__pathInputed}}class jt extends Tt{get __boxStroke(){return!this.__pathInputed}}class Yt extends Tt{}class Ut extends Tt{}class Xt extends Tt{get __pathInputed(){return 2}}class Ht extends zt{}const qt={thin:100,"extra-light":200,light:300,normal:400,medium:500,"semi-bold":600,bold:700,"extra-bold":800,black:900};class Gt extends Tt{get __useNaturalRatio(){return!1}setFontWeight(t){"string"==typeof t?(this.__setInput("fontWeight",t),t=qt[t]||400):this.__input&&this.__removeInput("fontWeight"),this._fontWeight=t}setBoxStyle(t){let e=this.__leaf,i=e.__box;if(t){const{boxStyle:s}=this;if(i)for(let t in s)i[t]=void 0;else i=e.__box=h.get("Rect",0);const o=e.__layout,r=i.__layout;s||(i.parent=e,i.__world=e.__world,r.boxBounds=o.boxBounds),i.set(t),r.strokeChanged&&o.strokeChange(),r.renderChanged&&o.renderChange(),i.__updateChange()}else i&&(e.__box=i.parent=null,i.destroy());this._boxStyle=t}}class Jt extends Vt{setUrl(t){this.__setImageFill(t),this._url=t}__setImageFill(t){this.fill=t?{type:"image",mode:"stretch",url:t}:void 0}__getData(){const t=super.__getData();return delete t.fill,t}__getInputData(t,e){const i=super.__getInputData(t,e);return delete i.fill,i}}class $t extends Vt{get __isCanvas(){return!0}get __drawAfterFill(){return!0}__getInputData(t,e){const i=super.__getInputData(t,e);return i.url=this.__leaf.canvas.toDataURL("image/png"),i}}const Kt={__updateStrokeSpread(){let t=0,e=0;const i=this.__,{strokeAlign:s,strokeWidth:o}=i,r=this.__box;if((i.stroke||"all"===i.hitStroke)&&o&&"inside"!==s&&(e=t="center"===s?o/2:o,!i.__boxStroke)){const e=i.__isLinePath?0:10*t,s="none"===i.strokeCap?0:o;t+=Math.max(e,s)}return i.__useArrow&&(t+=5*o),r&&(t=Math.max(r.__layout.strokeSpread=r.__updateStrokeSpread(),t),e=r.__layout.strokeBoxSpread),this.__layout.strokeBoxSpread=e,t},__updateRenderSpread(){let t=0;const{shadow:e,innerShadow:i,blur:s,backgroundBlur:o,filter:r}=this.__;e&&e.forEach((e=>t=Math.max(t,Math.max(Math.abs(e.y),Math.abs(e.x))+(e.spread>0?e.spread:0)+1.5*e.blur))),s&&(t=Math.max(t,s)),r&&(t+=kt.getSpread(r));let a=t=Math.ceil(t);return i&&i.forEach((t=>a=Math.max(a,Math.max(Math.abs(t.y),Math.abs(t.x))+(t.spread<0?-t.spread:0)+1.5*t.blur))),o&&(a=Math.max(a,o)),this.__layout.renderShapeSpread=a,t+=this.__layout.strokeSpread||0,this.__box?Math.max(this.__box.__updateRenderSpread(),t):t}},{stintSet:Qt}=r,Zt={__updateChange(){const t=this.__;if(t.__useStroke){const e=t.__useStroke=!(!t.stroke||!t.strokeWidth);Qt(this.__world,"half",e&&"center"===t.strokeAlign&&t.strokeWidth%2),Qt(t,"__fillAfterStroke",e&&"outside"===t.strokeAlign&&t.fill&&!t.__isTransparentFill)}if(t.__useEffect){const{shadow:e,fill:i,stroke:s}=t,o=t.innerShadow||t.blur||t.backgroundBlur||t.filter;Qt(t,"__isFastShadow",e&&!o&&e.length<2&&!e[0].spread&&!(e[0].box&&t.__isTransparentFill)&&i&&!(i instanceof Array&&i.length>1)&&(this.useFastShadow||!s||s&&"inside"===t.strokeAlign)),t.__useEffect=!(!e&&!o)}t.__checkSingle(),Qt(t,"__complex",t.__isFills||t.__isStrokes||t.cornerRadius||t.__useEffect)},__drawFast(t,e){te(this,t,e)},__draw(t,e,i){const s=this.__;if(s.__complex){s.__needComputePaint&&s.__computePaint();const{fill:o,stroke:r,__drawAfterFill:a,__fillAfterStroke:n,__isFastShadow:_}=s;if(this.__drawRenderPath(t),s.__useEffect&&!_){const _=xt.shape(this,t,e);this.__nowWorld=this.__getNowWorld(e);const{shadow:h,innerShadow:d,filter:p}=s;h&&Rt.shadow(this,t,_),n&&(s.__isStrokes?xt.strokes(r,this,t):xt.stroke(r,this,t)),o&&(s.__isFills?xt.fills(o,this,t):xt.fill(o,this,t)),a&&this.__drawAfterFill(t,e),d&&Rt.innerShadow(this,t,_),r&&!n&&(s.__isStrokes?xt.strokes(r,this,t):xt.stroke(r,this,t)),p&&kt.apply(p,this,this.__nowWorld,t,i,_),_.worldCanvas&&_.worldCanvas.recycle(),_.canvas.recycle()}else{if(n&&(s.__isStrokes?xt.strokes(r,this,t):xt.stroke(r,this,t)),_){const e=s.shadow[0],{scaleX:i,scaleY:o}=this.__nowWorld;t.save(),t.setWorldShadow(e.x*i,e.y*o,e.blur*i,vt.string(e.color))}o&&(s.__isFills?xt.fills(o,this,t):xt.fill(o,this,t)),_&&t.restore(),a&&this.__drawAfterFill(t,e),r&&!n&&(s.__isStrokes?xt.strokes(r,this,t):xt.stroke(r,this,t))}}else s.__pathInputed?te(this,t,e):this.__drawFast(t,e)},__drawShape(t,e){this.__drawRenderPath(t);const i=this.__,{fill:s,stroke:o}=i;s&&!e.ignoreFill&&(i.__isAlphaPixelFill?xt.fills(s,this,t):xt.fill("#000000",this,t)),i.__isCanvas&&this.__drawAfterFill(t,e),o&&!e.ignoreStroke&&(i.__isAlphaPixelStroke?xt.strokes(o,this,t):xt.stroke("#000000",this,t))},__drawAfterFill(t,e){this.__.__clipAfterFill?(t.save(),t.clipUI(this),this.__drawContent(t,e),t.restore()):this.__drawContent(t,e)}};function te(t,e,i){const{fill:s,stroke:o,__drawAfterFill:r,__fillAfterStroke:a}=t.__;t.__drawRenderPath(e),a&&xt.stroke(o,t,e),s&&xt.fill(s,t,e),r&&t.__drawAfterFill(e,i),o&&!a&&xt.stroke(o,t,e)}const ee={__drawFast(t,e){let{x:i,y:s,width:o,height:r}=this.__layout.boxBounds;const{fill:a,stroke:n,__drawAfterFill:_}=this.__;if(a&&(t.fillStyle=a,t.fillRect(i,s,o,r)),_&&this.__drawAfterFill(t,e),n){const{strokeAlign:a,__strokeWidth:_}=this.__;if(!_)return;t.setStroke(n,_,this.__);const h=_/2;switch(a){case"center":t.strokeRect(0,0,o,r);break;case"inside":o-=_,r-=_,o<0||r<0?(t.save(),this.__clip(t,e),t.strokeRect(i+h,s+h,o,r),t.restore()):t.strokeRect(i+h,s+h,o,r);break;case"outside":t.strokeRect(i-h,s-h,o+_,r+_)}}}};var ie;let se=ie=class extends F{get app(){return this.leafer&&this.leafer.app}get isFrame(){return!1}set scale(t){W.assignScale(this,t)}get scale(){return this.__.scale}get pen(){const{path:t}=this.__;return T.set(this.path=t||[]),t||this.__drawPathByBox(T),T}constructor(t){super(t)}reset(t){}set(t,e){t&&(e?"temp"===e?(this.lockNormalStyle=!0,Object.assign(this,t),this.lockNormalStyle=!1):this.animate(t,e):Object.assign(this,t))}get(t){return"string"==typeof t?this.__.__getInput(t):this.__.__getInputData(t)}createProxyData(){}find(t,e){return s.need("find")}findTag(t){return this.find({tag:t})}findOne(t,e){return s.need("find")}findId(t){return this.findOne({id:t})}getPath(t,e){this.__layout.update();let i=e?this.__.__pathForRender:this.__.path;return i||(T.set(i=[]),this.__drawPathByBox(T)),t?o.toCanvasData(i,!0):i}getPathString(t,e,i){return o.stringify(this.getPath(t,e),i)}load(){this.__.__computePaint()}__onUpdateSize(){if(this.__.__input){const t=this.__;!t.lazy||this.__inLazyBounds||bt.running?t.__computePaint():t.__needComputePaint=!0}}__updateRenderPath(){const t=this.__;t.path?(t.__pathForRender=t.cornerRadius?D.smooth(t.path,t.cornerRadius,t.cornerSmoothing):t.path,t.__useArrow&&wt.addArrows(this,!t.cornerRadius)):t.__pathForRender&&(t.__pathForRender=void 0)}__drawRenderPath(t){t.beginPath(),this.__drawPathByData(t,this.__.__pathForRender)}__drawPath(t){t.beginPath(),this.__drawPathByData(t,this.__.path)}__drawPathByData(t,e){e?z.drawPathByData(t,e):this.__drawPathByBox(t)}__drawPathByBox(t){const{x:e,y:i,width:s,height:o}=this.__layout.boxBounds;if(this.__.cornerRadius){const{cornerRadius:r}=this.__;t.roundRect(e,i,s,o,"number"==typeof r?[r]:r)}else t.rect(e,i,s,o)}drawImagePlaceholder(t,e){xt.fill(this.__.placeholderColor,this,t)}animate(t,e,i,o){return s.need("animate")}killAnimate(t,e){}export(t,e){return s.need("export")}syncExport(t,e){return s.need("export")}clone(t){const e=r.clone(this.toJSON());return t&&Object.assign(e,t),ie.one(e)}static one(t,e,i,s,o){return h.get(t.tag||this.prototype.__tag,t,e,i,s,o)}static registerUI(){L()(this)}static registerData(t){d(t)(this.prototype)}static setEditConfig(t){}static setEditOuter(t){}static setEditInner(t){}destroy(){this.fill=this.stroke=null,this.__animate&&this.killAnimate(),super.destroy()}};lt([d(Tt)],se.prototype,"__",void 0),lt([yt()],se.prototype,"zoomLayer",void 0),lt([p("")],se.prototype,"id",void 0),lt([p("")],se.prototype,"name",void 0),lt([p("")],se.prototype,"className",void 0),lt([l("pass-through")],se.prototype,"blendMode",void 0),lt([u(1)],se.prototype,"opacity",void 0),lt([c(!0)],se.prototype,"visible",void 0),lt([l(!1)],se.prototype,"locked",void 0),lt([l(!1)],se.prototype,"dim",void 0),lt([l(!1)],se.prototype,"dimskip",void 0),lt([y(0)],se.prototype,"zIndex",void 0),lt([g(!1)],se.prototype,"mask",void 0),lt([v(!1)],se.prototype,"eraser",void 0),lt([f(0,!0)],se.prototype,"x",void 0),lt([f(0,!0)],se.prototype,"y",void 0),lt([w(100,!0)],se.prototype,"width",void 0),lt([w(100,!0)],se.prototype,"height",void 0),lt([x(1,!0)],se.prototype,"scaleX",void 0),lt([x(1,!0)],se.prototype,"scaleY",void 0),lt([m(0,!0)],se.prototype,"rotation",void 0),lt([m(0,!0)],se.prototype,"skewX",void 0),lt([m(0,!0)],se.prototype,"skewY",void 0),lt([f(0,!0)],se.prototype,"offsetX",void 0),lt([f(0,!0)],se.prototype,"offsetY",void 0),lt([f(0,!0)],se.prototype,"scrollX",void 0),lt([f(0,!0)],se.prototype,"scrollY",void 0),lt([S()],se.prototype,"origin",void 0),lt([S()],se.prototype,"around",void 0),lt([p(!1)],se.prototype,"lazy",void 0),lt([R(1)],se.prototype,"pixelRatio",void 0),lt([k()],se.prototype,"path",void 0),lt([b()],se.prototype,"windingRule",void 0),lt([b(!0)],se.prototype,"closed",void 0),lt([w(0)],se.prototype,"padding",void 0),lt([w(!1)],se.prototype,"lockRatio",void 0),lt([w()],se.prototype,"widthRange",void 0),lt([w()],se.prototype,"heightRange",void 0),lt([p(!1)],se.prototype,"draggable",void 0),lt([p()],se.prototype,"dragBounds",void 0),lt([p(!1)],se.prototype,"editable",void 0),lt([B(!0)],se.prototype,"hittable",void 0),lt([B("path")],se.prototype,"hitFill",void 0),lt([A("path")],se.prototype,"hitStroke",void 0),lt([B(!1)],se.prototype,"hitBox",void 0),lt([B(!0)],se.prototype,"hitChildren",void 0),lt([B(!0)],se.prototype,"hitSelf",void 0),lt([B()],se.prototype,"hitRadius",void 0),lt([C("")],se.prototype,"cursor",void 0),lt([l()],se.prototype,"fill",void 0),lt([A(void 0,!0)],se.prototype,"stroke",void 0),lt([A("inside")],se.prototype,"strokeAlign",void 0),lt([A(1,!0)],se.prototype,"strokeWidth",void 0),lt([A(!1)],se.prototype,"strokeWidthFixed",void 0),lt([A("none")],se.prototype,"strokeCap",void 0),lt([A("miter")],se.prototype,"strokeJoin",void 0),lt([A()],se.prototype,"dashPattern",void 0),lt([A(0)],se.prototype,"dashOffset",void 0),lt([A(10)],se.prototype,"miterLimit",void 0),lt([b(0)],se.prototype,"cornerRadius",void 0),lt([b()],se.prototype,"cornerSmoothing",void 0),lt([ut()],se.prototype,"shadow",void 0),lt([ut()],se.prototype,"innerShadow",void 0),lt([ut()],se.prototype,"blur",void 0),lt([ut()],se.prototype,"backgroundBlur",void 0),lt([ut()],se.prototype,"grayscale",void 0),lt([ut()],se.prototype,"filter",void 0),lt([l()],se.prototype,"placeholderColor",void 0),lt([p(100)],se.prototype,"placeholderDelay",void 0),lt([p({})],se.prototype,"data",void 0),lt([P(F.prototype.reset)],se.prototype,"reset",null),se=ie=lt([E(Kt),E(Zt),I()],se);let oe=class extends se{get __tag(){return"Group"}get isBranch(){return!0}constructor(t){super(t)}reset(t){this.__setBranch(),super.reset(t)}__setBranch(){this.children||(this.children=[])}set(t,e){if(t)if(t.children){const{children:i}=t;delete t.children,this.children?this.clear():this.__setBranch(),super.set(t,e),i.forEach((t=>this.add(t))),t.children=i}else super.set(t,e)}toJSON(t){const e=super.toJSON(t);return e.children=this.children.map((e=>e.toJSON(t))),e}pick(t,e){}addAt(t,e){this.add(t,e)}addAfter(t,e){this.add(t,this.children.indexOf(e)+1)}addBefore(t,e){this.add(t,this.children.indexOf(e))}add(t,e){}addMany(...t){}remove(t,e){}removeAll(t){}clear(){}};var re;lt([d(zt)],oe.prototype,"__",void 0),lt([w(0)],oe.prototype,"width",void 0),lt([w(0)],oe.prototype,"height",void 0),oe=lt([E(M),L()],oe);const ae=a.get("Leafer");let ne=re=class extends oe{get __tag(){return"Leafer"}get isApp(){return!1}get app(){return this.parent||this}get isLeafer(){return!0}get imageReady(){return this.viewReady&&N.isComplete}get layoutLocked(){return!this.layouter.running}get FPS(){return this.renderer?this.renderer.FPS:60}get cursorPoint(){return this.interaction&&this.interaction.hoverData||{x:this.width/2,y:this.height/2}}get clientBounds(){return this.canvas&&this.canvas.getClientBounds(!0)||V()}constructor(t,e){super(e),this.config={start:!0,hittable:!0,smooth:!0,lazySpeard:100},this.leafs=0,this.__eventIds=[],this.__controllers=[],this.__readyWait=[],this.__viewReadyWait=[],this.__viewCompletedWait=[],this.__nextRenderWait=[],this.userConfig=t,t&&(t.view||t.width)&&this.init(t),re.list.add(this)}init(t,e){if(this.canvas)return;let i;const{config:s}=this;this.__setLeafer(this),e&&(this.parentApp=e,this.__bindApp(e),i=e.running),t&&(this.parent=e,this.initType(t.type),this.parent=void 0,r.assign(s,t));const o=this.canvas=j.canvas(s);this.__controllers.push(this.renderer=j.renderer(this,o,s),this.watcher=j.watcher(this,s),this.layouter=j.layouter(this,s)),this.isApp&&this.__setApp(),this.__checkAutoLayout(s,e),this.view=o.view,e||(this.selector=j.selector(this),this.interaction=j.interaction(this,o,this.selector,s),this.interaction&&(this.__controllers.unshift(this.interaction),this.hitCanvasManager=j.hitCanvasManager()),this.canvasManager=new Y,i=s.start),this.hittable=s.hittable,this.fill=s.fill,this.canvasManager.add(o),this.__listenEvents(),i&&(this.__startTimer=setTimeout(this.start.bind(this))),U.run(this.__initWait),this.onInit()}onInit(){}initType(t){}set(t,e){this.waitInit((()=>{super.set(t,e)}))}start(){clearTimeout(this.__startTimer),!this.running&&this.canvas&&(this.running=!0,this.ready?this.emitLeafer(X.RESTART):this.emitLeafer(X.START),this.__controllers.forEach((t=>t.start())),this.isApp||this.renderer.render())}stop(){clearTimeout(this.__startTimer),this.running&&this.canvas&&(this.__controllers.forEach((t=>t.stop())),this.running=!1,this.emitLeafer(X.STOP))}unlockLayout(){this.layouter.start(),this.updateLayout()}lockLayout(){this.updateLayout(),this.layouter.stop()}resize(t){const e=r.copyAttrs({},t,_);Object.keys(e).forEach((t=>this[t]=e[t]))}forceRender(t,e){const{renderer:i}=this;i&&(i.addBlock(t?new H(t):this.canvas.bounds),this.viewReady&&(e?i.render():i.update()))}requestRender(t=!1){this.renderer&&this.renderer.update(t)}updateCursor(t){const e=this.interaction;e&&(t?e.setCursor(t):e.updateCursor())}updateLazyBounds(){this.lazyBounds=this.canvas.bounds.clone().spread(this.config.lazySpeard)}__doResize(t){const{canvas:e}=this;if(!e||e.isSameSize(t))return;const i=r.copyAttrs({},this.canvas,_);e.resize(t),this.updateLazyBounds(),this.__onResize(new q(t,i))}__onResize(t){this.emitEvent(t),r.copyAttrs(this.__,t,_),setTimeout((()=>{this.canvasManager&&this.canvasManager.clearRecycled()}),0)}__setApp(){}__bindApp(t){this.selector=t.selector,this.interaction=t.interaction,this.canvasManager=t.canvasManager,this.hitCanvasManager=t.hitCanvasManager}__setLeafer(t){this.leafer=t,this.__level=1}__checkAutoLayout(t,e){e||(t.width&&t.height||(this.autoLayout=new G(t)),this.canvas.startAutoLayout(this.autoLayout,this.__onResize.bind(this)))}__setAttr(t,e){return this.canvas&&(_.includes(t)?this.__changeCanvasSize(t,e):"fill"===t?this.__changeFill(e):"hittable"===t?this.parent||(this.canvas.hittable=e):"zIndex"===t&&(this.canvas.zIndex=e,setTimeout((()=>this.parent&&this.parent.__updateSortChildren())))),super.__setAttr(t,e)}__getAttr(t){return this.canvas&&_.includes(t)?this.canvas[t]:super.__getAttr(t)}__changeCanvasSize(t,e){const i=r.copyAttrs({},this.canvas,_);i[t]=this.config[t]=e,e&&this.canvas.stopAutoLayout(),this.__doResize(i)}__changeFill(t){this.config.fill=t,this.canvas.allowBackgroundColor?this.canvas.backgroundColor=t:this.forceRender()}__onCreated(){this.created=!0}__onReady(){this.ready=!0,this.emitLeafer(X.BEFORE_READY),this.emitLeafer(X.READY),this.emitLeafer(X.AFTER_READY),U.run(this.__readyWait)}__onViewReady(){this.viewReady||(this.viewReady=!0,this.emitLeafer(X.VIEW_READY),U.run(this.__viewReadyWait))}__onLayoutEnd(){const{grow:t,width:e,height:i}=this.config;if(t){let{width:s,height:o,pixelRatio:r}=this;const a="box"===t?this.worldBoxBounds:this.__world;e||(s=Math.max(1,a.x+a.width)),i||(o=Math.max(1,a.y+a.height)),this.__doResize({width:s,height:o,pixelRatio:r})}this.ready||this.__onReady()}__onNextRender(){if(this.viewReady){U.run(this.__nextRenderWait);const{imageReady:t}=this;t&&!this.viewCompleted&&this.__checkViewCompleted(),t||(this.viewCompleted=!1,this.requestRender())}else this.requestRender()}__checkViewCompleted(t=!0){this.nextRender((()=>{this.imageReady&&(t&&this.emitLeafer(X.VIEW_COMPLETED),U.run(this.__viewCompletedWait),this.viewCompleted=!0)}))}__onWatchData(){this.watcher.childrenChanged&&this.interaction&&this.nextRender((()=>this.interaction.updateCursor()))}waitInit(t,e){e&&(t=t.bind(e)),this.__initWait||(this.__initWait=[]),this.canvas?t():this.__initWait.push(t)}waitReady(t,e){e&&(t=t.bind(e)),this.ready?t():this.__readyWait.push(t)}waitViewReady(t,e){e&&(t=t.bind(e)),this.viewReady?t():this.__viewReadyWait.push(t)}waitViewCompleted(t,e){e&&(t=t.bind(e)),this.__viewCompletedWait.push(t),this.viewCompleted?this.__checkViewCompleted(!1):this.running||this.start()}nextRender(t,e,i){e&&(t=t.bind(e));const s=this.__nextRenderWait;if(i){for(let e=0;e<s.length;e++)if(s[e]===t){s.splice(e,1);break}}else s.push(t);this.requestRender()}zoom(t,e,i,o){return s.need("view")}getValidMove(t,e){return{x:t,y:e}}getValidScale(t){return t}getWorldPointByClient(t,e){return this.interaction&&this.interaction.getLocal(t,e)}getPagePointByClient(t,e){return this.getPagePoint(this.getWorldPointByClient(t,e))}getClientPointByWorld(t){const{x:e,y:i}=this.clientBounds;return{x:e+t.x,y:i+t.y}}updateClientBounds(){this.canvas&&this.canvas.updateClientBounds()}receiveEvent(t){}emitLeafer(t){this.emitEvent(new X(t,this))}__listenEvents(){const t=J.start("FirstCreate "+this.innerName);this.once([[X.START,()=>J.end(t)],[$.START,this.updateLazyBounds,this],[K.START,this.__onCreated,this],[K.END,this.__onViewReady,this]]),this.__eventIds.push(this.on_([[Q.DATA,this.__onWatchData,this],[$.END,this.__onLayoutEnd,this],[K.NEXT,this.__onNextRender,this]]))}__removeListenEvents(){this.off_(this.__eventIds)}destroy(t){const e=()=>{if(!this.destroyed){re.list.remove(this);try{this.stop(),this.emitLeafer(X.END),this.__removeListenEvents(),this.__controllers.forEach((t=>!(this.parent&&t===this.interaction)&&t.destroy())),this.__controllers.length=0,this.parent||(this.selector&&this.selector.destroy(),this.hitCanvasManager&&this.hitCanvasManager.destroy(),this.canvasManager.destroy()),this.canvas.destroy(),this.config.view=this.view=this.parentApp=null,this.userConfig&&(this.userConfig.view=null),super.destroy(),setTimeout((()=>{Z.clearRecycled()}),100)}catch(t){ae.error(t)}}};t?e():setTimeout(e)}};ne.list=new O,lt([d(Mt)],ne.prototype,"__",void 0),lt([w()],ne.prototype,"pixelRatio",void 0),ne=re=lt([L()],ne);let _e=class extends se{get __tag(){return"Rect"}constructor(t){super(t)}};lt([d(Vt)],_e.prototype,"__",void 0),_e=lt([E(ee),I(),L()],_e);const{copy:he,add:de,includes:pe}=tt,le=_e.prototype,ue=oe.prototype,ce={};let ye=class extends oe{get __tag(){return"Box"}get isBranchLeaf(){return!0}constructor(t){super(t),this.__layout.renderChanged||this.__layout.renderChange()}__updateStrokeSpread(){return 0}__updateRectRenderSpread(){return 0}__updateRenderSpread(){return this.__updateRectRenderSpread()||-1}__updateRectBoxBounds(){}__updateBoxBounds(t){const e=this.__;if(this.children.length&&!this.pathInputed)if(e.__autoSide){e.__hasSurface&&this.__extraUpdate(),super.__updateBoxBounds();const{boxBounds:t}=this.__layout;e.__autoSize||(e.__autoWidth?(t.width+=t.x,t.x=0,t.height=e.height,t.y=0):(t.height+=t.y,t.y=0,t.width=e.width,t.x=0)),this.__updateNaturalSize()}else this.__updateRectBoxBounds();else this.__updateRectBoxBounds()}__updateStrokeBounds(){}__updateRenderBounds(){let t;const{renderBounds:e}=this.__layout;this.children.length?(super.__updateRenderBounds(),he(ce,e),this.__updateRectRenderBounds(),t=!pe(e,ce),t&&"hide"!==this.__.overflow&&de(e,ce)):this.__updateRectRenderBounds(),r.stintSet(this,"isOverflow",t)}__updateRectRenderBounds(){}__updateRectChange(){}__updateChange(){super.__updateChange(),this.__updateRectChange()}__renderRect(t,e){}__renderGroup(t,e){}__render(t,e){this.__.__drawAfterFill?this.__renderRect(t,e):(this.__renderRect(t,e),this.children.length&&this.__renderGroup(t,e))}__drawContent(t,e){this.__renderGroup(t,e),this.__.__useStroke&&(t.setWorld(this.__nowWorld),this.__drawRenderPath(t))}};lt([d(Lt)],ye.prototype,"__",void 0),lt([w(100)],ye.prototype,"width",void 0),lt([w(100)],ye.prototype,"height",void 0),lt([p(!1)],ye.prototype,"resizeChildren",void 0),lt([et("show")],ye.prototype,"overflow",void 0),lt([P(le.__updateStrokeSpread)],ye.prototype,"__updateStrokeSpread",null),lt([P(le.__updateRenderSpread)],ye.prototype,"__updateRectRenderSpread",null),lt([P(le.__updateBoxBounds)],ye.prototype,"__updateRectBoxBounds",null),lt([P(le.__updateStrokeBounds)],ye.prototype,"__updateStrokeBounds",null),lt([P(le.__updateRenderBounds)],ye.prototype,"__updateRectRenderBounds",null),lt([P(le.__updateChange)],ye.prototype,"__updateRectChange",null),lt([P(le.__render)],ye.prototype,"__renderRect",null),lt([P(ue.__render)],ye.prototype,"__renderGroup",null),ye=lt([I(),L()],ye);let ge=class extends ye{get __tag(){return"Frame"}get isFrame(){return!0}constructor(t){super(t)}};lt([d(Ot)],ge.prototype,"__",void 0),lt([l("#FFFFFF")],ge.prototype,"fill",void 0),lt([et("hide")],ge.prototype,"overflow",void 0),ge=lt([L()],ge);const{moveTo:ve,closePath:fe,ellipse:we}=it;let xe=class extends se{get __tag(){return"Ellipse"}constructor(t){super(t)}__updatePath(){const{width:t,height:e,innerRadius:i,startAngle:s,endAngle:o}=this.__,r=t/2,a=e/2,n=this.__.path=[];i?(s||o?(i<1&&we(n,r,a,r*i,a*i,0,s,o,!1),we(n,r,a,r,a,0,o,s,!0),i<1&&fe(n)):(i<1&&(we(n,r,a,r*i,a*i),ve(n,t,a)),we(n,r,a,r,a,0,360,0,!0)),st.ellipseToCurve&&(this.__.path=this.getPath(!0))):s||o?(ve(n,r,a),we(n,r,a,r,a,0,s,o,!1),fe(n)):we(n,r,a,r,a)}};lt([d(jt)],xe.prototype,"__",void 0),lt([b(0)],xe.prototype,"innerRadius",void 0),lt([b(0)],xe.prototype,"startAngle",void 0),lt([b(0)],xe.prototype,"endAngle",void 0),xe=lt([L()],xe);const{moveTo:me,lineTo:Se,drawPoints:Re}=it,{rotate:ke,getAngle:be,getDistance:Be,defaultPoint:Ae}=ot,{toBounds:Ce}=rt;let Pe=class extends se{get __tag(){return"Line"}get toPoint(){const{width:t,rotation:e}=this.__,i=nt();return t&&(i.x=t),e&&ke(i,e),i}set toPoint(t){this.width=Be(Ae,t),this.rotation=be(Ae,t),this.height&&(this.height=0)}constructor(t){super(t)}__updatePath(){const t=this.__,e=t.path=[];t.points?Re(e,t.points,!1,t.closed):(me(e,0,0),Se(e,this.width,0))}__updateRenderPath(){const t=this.__;!this.pathInputed&&t.points&&t.curve?(Re(t.__pathForRender=[],t.points,t.curve,t.closed),t.__useArrow&&wt.addArrows(this,!1)):super.__updateRenderPath()}__updateBoxBounds(){this.points?Ce(this.__.__pathForRender,this.__layout.boxBounds):super.__updateBoxBounds()}};lt([d(Nt)],Pe.prototype,"__",void 0),lt([at("center")],Pe.prototype,"strokeAlign",void 0),lt([w(0)],Pe.prototype,"height",void 0),lt([b()],Pe.prototype,"points",void 0),lt([b(0)],Pe.prototype,"curve",void 0),lt([b(!1)],Pe.prototype,"closed",void 0),Pe=lt([L()],Pe);const{sin:Fe,cos:Ee,PI:Ie}=Math,{moveTo:We,lineTo:Te,closePath:De,drawPoints:ze}=it,Le=Pe.prototype;let Me=class extends se{get __tag(){return"Polygon"}constructor(t){super(t)}__updatePath(){const t=this.__.path=[];if(this.__.points)ze(t,this.__.points,!1,!0);else{const{width:e,height:i,sides:s}=this.__,o=e/2,r=i/2;We(t,o,0);for(let e=1;e<s;e++)Te(t,o+o*Fe(2*e*Ie/s),r-r*Ee(2*e*Ie/s));De(t)}}__updateRenderPath(){}__updateBoxBounds(){}};lt([d(Yt)],Me.prototype,"__",void 0),lt([b(3)],Me.prototype,"sides",void 0),lt([b()],Me.prototype,"points",void 0),lt([b(0)],Me.prototype,"curve",void 0),lt([P(Le.__updateRenderPath)],Me.prototype,"__updateRenderPath",null),lt([P(Le.__updateBoxBounds)],Me.prototype,"__updateBoxBounds",null),Me=lt([I(),L()],Me);const{sin:Oe,cos:Ne,PI:Ve}=Math,{moveTo:je,lineTo:Ye,closePath:Ue}=it;let Xe=class extends se{get __tag(){return"Star"}constructor(t){super(t)}__updatePath(){const{width:t,height:e,corners:i,innerRadius:s}=this.__,o=t/2,r=e/2,a=this.__.path=[];je(a,o,0);for(let t=1;t<2*i;t++)Ye(a,o+(t%2==0?o:o*s)*Oe(t*Ve/i),r-(t%2==0?r:r*s)*Ne(t*Ve/i));Ue(a)}};lt([d(Ut)],Xe.prototype,"__",void 0),lt([b(5)],Xe.prototype,"corners",void 0),lt([b(.382)],Xe.prototype,"innerRadius",void 0),Xe=lt([L()],Xe);let He=class extends _e{get __tag(){return"Image"}get ready(){const{image:t}=this;return t&&t.ready}get image(){const{fill:t}=this.__;return t instanceof Array&&t[0].image}constructor(t){super(t)}};lt([d(Jt)],He.prototype,"__",void 0),lt([w("")],He.prototype,"url",void 0),He=lt([L()],He);const qe=He;let Ge=class extends _e{get __tag(){return"Canvas"}get context(){return this.canvas.context}get ready(){return!this.url}constructor(t){super(t),this.canvas=j.canvas(this.__),t&&t.url&&this.drawImage(t.url)}drawImage(t){new _t({url:t}).load((t=>{this.context.drawImage(t.view,0,0),this.url=void 0,this.paint(),this.emitEvent(new ht(ht.LOADED,{image:t}))}))}draw(t,e,i,s){const o=new dt(t.worldTransform).invert(),r=new dt;e&&r.translate(e.x,e.y),i&&("number"==typeof i?r.scale(i):r.scale(i.x,i.y)),s&&r.rotate(s),o.multiplyParent(r),t.__render(this.canvas,{matrix:o.withScale()}),this.paint()}paint(){this.forceRender()}__drawContent(t,e){const{width:i,height:s}=this.__,{view:o}=this.canvas;t.drawImage(o,0,0,o.width,o.height,0,0,i,s)}__updateSize(){const{canvas:t}=this;if(t){const{smooth:e,safeResize:i}=this.__;t.resize(this.__,i),t.smooth!==e&&(t.smooth=e)}}destroy(){this.canvas&&(this.canvas.destroy(),this.canvas=null),super.destroy()}};lt([d($t)],Ge.prototype,"__",void 0),lt([ct(100)],Ge.prototype,"width",void 0),lt([ct(100)],Ge.prototype,"height",void 0),lt([ct(1)],Ge.prototype,"pixelRatio",void 0),lt([ct(!0)],Ge.prototype,"smooth",void 0),lt([p(!1)],Ge.prototype,"safeResize",void 0),lt([ct()],Ge.prototype,"contextSettings",void 0),Ge=lt([L()],Ge);const{copyAndSpread:Je,includes:$e,spread:Ke,setList:Qe}=tt;let Ze=class extends se{get __tag(){return"Text"}get textDrawData(){return this.updateLayout(),this.__.__textDrawData}constructor(t){super(t)}__updateTextDrawData(){const t=this.__,{lineHeight:e,letterSpacing:i,fontFamily:s,fontSize:o,fontWeight:r,italic:a,textCase:n,textOverflow:_,padding:h}=t;t.__lineHeight=ft.number(e,o),t.__letterSpacing=ft.number(i,o),t.__padding=h?W.fourNumber(h):void 0,t.__baseLine=t.__lineHeight-(t.__lineHeight-.7*o)/2,t.__font=`${a?"italic ":""}${"small-caps"===n?"small-caps ":""}${"normal"!==r?r+" ":""}${o}px ${s}`,t.__clipText="show"!==_&&!t.__autoSize,t.__textDrawData=gt.getDrawData((t.__isPlacehold=t.placeholder&&""===t.text)?t.placeholder:t.text,this.__)}__updateBoxBounds(){const t=this.__,e=this.__layout,{fontSize:i,italic:s,padding:o,__autoWidth:a,__autoHeight:n}=t;this.__updateTextDrawData();const{bounds:_}=t.__textDrawData,h=e.boxBounds;if(e.contentBounds=_,t.__lineHeight<i&&Ke(_,i/2),a||n){if(h.x=a?_.x:0,h.y=n?_.y:0,h.width=a?_.width:t.width,h.height=n?_.height:t.height,o){const[e,i,s,o]=t.__padding;a&&(h.x-=o,h.width+=i+o),n&&(h.y-=e,h.height+=s+e)}this.__updateNaturalSize()}else super.__updateBoxBounds();s&&(h.width+=.16*i),r.stintSet(this,"isOverflow",!$e(h,_)),this.isOverflow?(Qe(t.__textBoxBounds={},[h,_]),e.renderChanged=!0):t.__textBoxBounds=h}__onUpdateSize(){this.__box&&this.__box.__onUpdateSize(),super.__onUpdateSize()}__updateRenderSpread(){let t=super.__updateRenderSpread();return t||(t=this.isOverflow?1:0),t}__updateRenderBounds(){const{renderBounds:t,renderSpread:e}=this.__layout;Je(t,this.__.__textBoxBounds,e),this.__box&&(this.__box.__layout.renderBounds=t)}__drawRenderPath(t){t.font=this.__.__font}__draw(t,e,i){const s=this.__box;s&&(s.__nowWorld=this.__nowWorld,s.__draw(t,e,i)),this.textEditing&&!e.exporting||super.__draw(t,e,i)}__drawShape(t,e){e.shape&&this.__box&&this.__box.__drawShape(t,e),super.__drawShape(t,e)}destroy(){this.boxStyle&&(this.boxStyle=null),super.destroy()}};lt([d(Gt)],Ze.prototype,"__",void 0),lt([w(0)],Ze.prototype,"width",void 0),lt([w(0)],Ze.prototype,"height",void 0),lt([l()],Ze.prototype,"boxStyle",void 0),lt([p(!1)],Ze.prototype,"resizeFontSize",void 0),lt([l("#000000")],Ze.prototype,"fill",void 0),lt([at("outside")],Ze.prototype,"strokeAlign",void 0),lt([B("all")],Ze.prototype,"hitFill",void 0),lt([w("")],Ze.prototype,"text",void 0),lt([w("")],Ze.prototype,"placeholder",void 0),lt([w("caption")],Ze.prototype,"fontFamily",void 0),lt([w(12)],Ze.prototype,"fontSize",void 0),lt([w("normal")],Ze.prototype,"fontWeight",void 0),lt([w(!1)],Ze.prototype,"italic",void 0),lt([w("none")],Ze.prototype,"textCase",void 0),lt([w("none")],Ze.prototype,"textDecoration",void 0),lt([w(0)],Ze.prototype,"letterSpacing",void 0),lt([w({type:"percent",value:1.5})],Ze.prototype,"lineHeight",void 0),lt([w(0)],Ze.prototype,"paraIndent",void 0),lt([w(0)],Ze.prototype,"paraSpacing",void 0),lt([w("x")],Ze.prototype,"writingMode",void 0),lt([w("left")],Ze.prototype,"textAlign",void 0),lt([w("top")],Ze.prototype,"verticalAlign",void 0),lt([w(!0)],Ze.prototype,"autoSizeAlign",void 0),lt([w("normal")],Ze.prototype,"textWrap",void 0),lt([w("show")],Ze.prototype,"textOverflow",void 0),lt([l(!1)],Ze.prototype,"textEditing",void 0),Ze=lt([L()],Ze);let ti=class extends se{get __tag(){return"Path"}constructor(t){super(t)}};lt([d(Xt)],ti.prototype,"__",void 0),lt([at("center")],ti.prototype,"strokeAlign",void 0),ti=lt([L()],ti);let ei=class extends oe{get __tag(){return"Pen"}constructor(t){super(t)}setStyle(t){const e=this.pathElement=new ti(t);return this.pathStyle=t,this.__path=e.path||(e.path=[]),this.add(e),this}beginPath(){return this}moveTo(t,e){return this}lineTo(t,e){return this}bezierCurveTo(t,e,i,s,o,r){return this}quadraticCurveTo(t,e,i,s){return this}closePath(){return this}rect(t,e,i,s){return this}roundRect(t,e,i,s,o){return this}ellipse(t,e,i,s,o,r,a,n){return this}arc(t,e,i,s,o,r){return this}arcTo(t,e,i,s,o){return this}drawEllipse(t,e,i,s,o,r,a,n){return this}drawArc(t,e,i,s,o,r){return this}drawPoints(t,e,i){return this}clearPath(){return this}paint(){this.pathElement.__layout.boxChanged||this.pathElement.forceUpdate("path")}};lt([d(Ht)],ei.prototype,"__",void 0),lt([(e,i)=>{t(e,i,{get(){return this.__path}})}],ei.prototype,"path",void 0),ei=lt([E(pt,["set","path","paint"]),L()],ei);export{ye as Box,Lt as BoxData,Ge as Canvas,$t as CanvasData,vt as ColorConvert,Rt as Effect,xe as Ellipse,jt as EllipseData,bt as Export,kt as Filter,ge as Frame,Ot as FrameData,oe as Group,zt as GroupData,He as Image,Jt as ImageData,ne as Leafer,Mt as LeaferData,Pe as Line,Nt as LineData,qe as MyImage,xt as Paint,St as PaintGradient,mt as PaintImage,ti as Path,wt as PathArrow,Xt as PathData,ei as Pen,Ht as PenData,Me as Polygon,Yt as PolygonData,_e as Rect,Vt as RectData,ee as RectRender,Xe as Star,Ut as StarData,Bt as State,Ze as Text,gt as TextConvert,Gt as TextData,At as Transition,se as UI,Kt as UIBounds,Tt as UIData,Zt as UIRender,ft as UnitConvert,ut as effectType,ct as resizeType,yt as zoomLayerType};
1
+ import{defineKey as t,decorateLeafAttr as e,attr as i,createDescriptor as s,Plugin as o,PathConvert as r,DataHelper as a,Debug as n,LeafData as _,canvasSizeAttrs as h,UICreator as d,dataProcessor as p,dataType as l,surfaceType as u,opacityType as c,visibleType as y,sortType as g,maskType as v,eraserType as f,positionType as w,boundsType as x,scaleType as S,rotationType as m,autoLayoutType as R,naturalBoundsType as k,affectRenderBoundsType as b,pathInputType as B,pathType as A,hitType as C,strokeType as P,cursorType as F,rewrite as W,Leaf as E,useModule as I,rewriteAble as T,MathHelper as D,pen as z,PathCorner as L,PathDrawer as M,registerUI as O,Branch as N,LeafList as Y,Resource as V,getBoundsData as j,Creator as H,CanvasManager as U,WaitHelper as X,LeaferEvent as J,Bounds as q,ResizeEvent as G,AutoBounds as $,Run as K,LayoutEvent as Q,RenderEvent as Z,WatchEvent as tt,ImageManager as et,BoundsHelper as it,PathCommandDataHelper as st,Platform as ot,PointHelper as rt,PathBounds as at,affectStrokeBoundsType as nt,getPointData as _t,LeaferImage as ht,ImageEvent as dt,Matrix as pt,PathCreator as lt}from"@leafer/core";export*from"@leafer/core";function ut(t,e,i,s){var o,r=arguments.length,a=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,s);else for(var n=t.length-1;n>=0;n--)(o=t[n])&&(a=(r<3?o(a):r>3?o(e,i,a):o(e,i))||a);return r>3&&a&&Object.defineProperty(e,i,a),a}function ct(t){return e(t,(t=>i({set(e){this.__setAttr(t,e),e&&(this.__.__useEffect=!0),this.__layout.renderChanged||this.__layout.renderChange()}})))}function yt(t){return e(t,(t=>i({set(e){this.__setAttr(t,e),this.__layout.boxChanged||this.__layout.boxChange(),this.__updateSize()}})))}function gt(){return(e,i)=>{const s="_"+i;t(e,i,{set(t){this.isLeafer&&(this[s]=t)},get(){return this.isApp?this.tree.zoomLayer:this.isLeafer?this[s]||this:this.leafer&&this.leafer.zoomLayer}})}}function vt(e){return(i,o)=>{t(i,o,s(o,e))}}"function"==typeof SuppressedError&&SuppressedError;const ft={},wt={hasTransparent:function(t){if(!t||7===t.length||4===t.length)return!1;if("transparent"===t)return!0;const e=t[0];if("#"===e)switch(t.length){case 5:return"f"!==t[4]&&"F"!==t[4];case 9:return"f"!==t[7]&&"F"!==t[7]||"f"!==t[8]&&"F"!==t[8]}else if(("r"===e||"h"===e)&&"a"===t[3]){const e=t.lastIndexOf(",");if(e>-1)return parseFloat(t.slice(e+1))<1}return!1}},xt={number:(t,e)=>"object"==typeof t?"percent"===t.type?t.value*e:t.value:t},St={},mt={},Rt={},kt={},bt={},Bt={apply(){o.need("filter")}},At={},Ct={setStyleName:()=>o.need("state"),set:()=>o.need("state")},Pt={list:{},register(t,e){Pt.list[t]=e},get:t=>Pt.list[t]},{parse:Ft,objectToCanvasData:Wt}=r,{stintSet:Et}=a,{hasTransparent:It}=wt,Tt={},Dt=n.get("UIData");class zt extends _{get scale(){const{scaleX:t,scaleY:e}=this;return t!==e?{x:t,y:e}:t}get __strokeWidth(){return this.__getRealStrokeWidth()}get __maxStrokeWidth(){const t=this;return t.__hasMultiStrokeStyle?Math.max(t.__hasMultiStrokeStyle,t.strokeWidth):t.strokeWidth}get __hasMultiPaint(){const t=this;return t.fill&&this.__useStroke||t.__isFills&&t.fill.length>1||t.__isStrokes&&t.stroke.length>1||t.__useEffect}get __clipAfterFill(){const t=this;return t.cornerRadius||t.innerShadow||t.__pathInputed}get __hasSurface(){return this.fill||this.stroke}get __autoWidth(){return!this._width}get __autoHeight(){return!this._height}get __autoSide(){return!this._width||!this._height}get __autoSize(){return!this._width&&!this._height}setVisible(t){this._visible=t;const{leafer:e}=this.__leaf;e&&(e.watcher.hasVisible=!0)}setWidth(t){t<0?(this._width=-t,this.__leaf.scaleX*=-1,Dt.warn("width < 0, instead -scaleX ",this)):this._width=t}setHeight(t){t<0?(this._height=-t,this.__leaf.scaleY*=-1,Dt.warn("height < 0, instead -scaleY",this)):this._height=t}setFill(t){this.__naturalWidth&&this.__removeNaturalSize(),"string"!=typeof t&&t?"object"==typeof t&&this.__setPaint("fill",t):(Et(this,"__isTransparentFill",It(t)),this.__isFills&&this.__removePaint("fill",!0),this._fill=t)}setStroke(t){"string"!=typeof t&&t?"object"==typeof t&&this.__setPaint("stroke",t):(Et(this,"__isTransparentStroke",It(t)),this.__isStrokes&&this.__removePaint("stroke",!0),this._stroke=t)}setPath(t){const e="string"==typeof t;e||t&&"object"==typeof t[0]?(this.__setInput("path",t),this._path=e?Ft(t):Wt(t)):(this.__input&&this.__removeInput("path"),this._path=t)}setShadow(t){Lt(this,"shadow",t)}setInnerShadow(t){Lt(this,"innerShadow",t)}setFilter(t){Lt(this,"filter",t)}__computePaint(){const{fill:t,stroke:e}=this.__input;t&&mt.compute("fill",this.__leaf),e&&mt.compute("stroke",this.__leaf),this.__needComputePaint=void 0}__getRealStrokeWidth(t){let{strokeWidth:e,strokeWidthFixed:i}=this;if(t&&(t.strokeWidth&&(e=t.strokeWidth),void 0!==t.strokeWidthFixed&&(i=t.strokeWidthFixed)),i){const t=this.__leaf.getClampRenderScale();return t>1?e/t:e}return e}__setPaint(t,e){this.__setInput(t,e);const i=this.__leaf.__layout;i.boxChanged||i.boxChange(),e instanceof Array&&!e.length?this.__removePaint(t):"fill"===t?(this.__isFills=!0,this._fill||(this._fill=Tt)):(this.__isStrokes=!0,this._stroke||(this._stroke=Tt))}__removePaint(t,e){e&&this.__removeInput(t),Rt.recycleImage(t,this),"fill"===t?(Et(this,"__isAlphaPixelFill",void 0),this._fill=this.__isFills=void 0):(Et(this,"__isAlphaPixelStroke",void 0),Et(this,"__hasMultiStrokeStyle",void 0),this._stroke=this.__isStrokes=void 0)}}function Lt(t,e,i){t.__setInput(e,i),i instanceof Array?(i.some((t=>!1===t.visible))&&(i=i.filter((t=>!1!==t.visible))),i.length||(i=void 0)):i=i&&!1!==i.visible?[i]:void 0,t["_"+e]=i}class Mt extends zt{}class Ot extends Mt{get __boxStroke(){return!this.__pathInputed}get __drawAfterFill(){return this.__single||this.__clipAfterFill}get __clipAfterFill(){const t=this;return"hide"===t.overflow&&t.__leaf.children.length&&(t.__leaf.isOverflow||super.__clipAfterFill)}}class Nt extends Mt{__getInputData(t,e){const i=super.__getInputData(t,e);return h.forEach((t=>delete i[t])),i}}class Yt extends Ot{}class Vt extends zt{}class jt extends zt{get __boxStroke(){return!this.__pathInputed}}class Ht extends zt{get __boxStroke(){return!this.__pathInputed}}class Ut extends zt{}class Xt extends zt{}class Jt extends zt{get __pathInputed(){return 2}}class qt extends Mt{}const Gt={thin:100,"extra-light":200,light:300,normal:400,medium:500,"semi-bold":600,bold:700,"extra-bold":800,black:900};class $t extends zt{get __useNaturalRatio(){return!1}setFontWeight(t){"string"==typeof t?(this.__setInput("fontWeight",t),t=Gt[t]||400):this.__input&&this.__removeInput("fontWeight"),this._fontWeight=t}setBoxStyle(t){let e=this.__leaf,i=e.__box;if(t){const{boxStyle:s}=this;if(i)for(let t in s)i[t]=void 0;else i=e.__box=d.get("Rect",0);const o=e.__layout,r=i.__layout;s||(i.parent=e,i.__world=e.__world,r.boxBounds=o.boxBounds),i.set(t),r.strokeChanged&&o.strokeChange(),r.renderChanged&&o.renderChange(),i.__updateChange()}else i&&(e.__box=i.parent=null,i.destroy());this._boxStyle=t}}class Kt extends jt{setUrl(t){this.__setImageFill(t),this._url=t}__setImageFill(t){this.fill=t?{type:"image",mode:"stretch",url:t}:void 0}__getData(){const t=super.__getData();return delete t.fill,t}__getInputData(t,e){const i=super.__getInputData(t,e);return delete i.fill,i}}class Qt extends jt{get __isCanvas(){return!0}get __drawAfterFill(){return!0}__getInputData(t,e){const i=super.__getInputData(t,e);return i.url=this.__leaf.canvas.toDataURL("image/png"),i}}const Zt={__updateStrokeSpread(){let t=0,e=0;const i=this.__,{strokeAlign:s,__maxStrokeWidth:o}=i,r=this.__box;if((i.stroke||"all"===i.hitStroke)&&o&&"inside"!==s&&(e=t="center"===s?o/2:o,!i.__boxStroke)){const e=i.__isLinePath?0:10*t,s="none"===i.strokeCap?0:o;t+=Math.max(e,s)}return i.__useArrow&&(t+=5*o),r&&(t=Math.max(r.__layout.strokeSpread=r.__updateStrokeSpread(),t),e=r.__layout.strokeBoxSpread),this.__layout.strokeBoxSpread=e,t},__updateRenderSpread(){let t=0;const{shadow:e,innerShadow:i,blur:s,backgroundBlur:o,filter:r,renderSpread:a}=this.__;e&&e.forEach((e=>t=Math.max(t,Math.max(Math.abs(e.y),Math.abs(e.x))+(e.spread>0?e.spread:0)+1.5*e.blur))),s&&(t=Math.max(t,s)),r&&(t+=Bt.getSpread(r)),a&&(t+=a);let n=t=Math.ceil(t);return i&&i.forEach((t=>n=Math.max(n,Math.max(Math.abs(t.y),Math.abs(t.x))+(t.spread<0?-t.spread:0)+1.5*t.blur))),o&&(n=Math.max(n,o)),this.__layout.renderShapeSpread=n,t+=this.__layout.strokeSpread||0,this.__box?Math.max(this.__box.__updateRenderSpread(),t):t}},{stintSet:te}=a,ee={__updateChange(){const t=this.__;if(t.__useStroke){const e=t.__useStroke=!(!t.stroke||!t.strokeWidth);te(this.__world,"half",e&&"center"===t.strokeAlign&&t.strokeWidth%2),te(t,"__fillAfterStroke",e&&"outside"===t.strokeAlign&&t.fill&&!t.__isTransparentFill)}if(t.__useEffect){const{shadow:e,fill:i,stroke:s}=t,o=t.innerShadow||t.blur||t.backgroundBlur||t.filter;te(t,"__isFastShadow",e&&!o&&e.length<2&&!e[0].spread&&i&&!t.__isTransparentFill&&!(i instanceof Array&&i.length>1)&&(this.useFastShadow||!s||s&&"inside"===t.strokeAlign)),t.__useEffect=!(!e&&!o)}t.__checkSingle(),te(t,"__complex",t.__isFills||t.__isStrokes||t.cornerRadius||t.__useEffect)},__drawFast(t,e){ie(this,t,e)},__draw(t,e,i){const s=this.__;if(s.__complex){s.__needComputePaint&&s.__computePaint();const{fill:o,stroke:r,__drawAfterFill:a,__fillAfterStroke:n,__isFastShadow:_}=s;if(this.__drawRenderPath(t),s.__useEffect&&!_){const _=mt.shape(this,t,e);this.__nowWorld=this.__getNowWorld(e);const{shadow:h,innerShadow:d,filter:p}=s;h&&bt.shadow(this,t,_),n&&(s.__isStrokes?mt.strokes(r,this,t):mt.stroke(r,this,t)),o&&(s.__isFills?mt.fills(o,this,t):mt.fill(o,this,t)),a&&this.__drawAfterFill(t,e),d&&bt.innerShadow(this,t,_),r&&!n&&(s.__isStrokes?mt.strokes(r,this,t):mt.stroke(r,this,t)),p&&Bt.apply(p,this,this.__nowWorld,t,i,_),_.worldCanvas&&_.worldCanvas.recycle(),_.canvas.recycle()}else{if(n&&(s.__isStrokes?mt.strokes(r,this,t):mt.stroke(r,this,t)),_){const e=s.shadow[0],{scaleX:i,scaleY:o}=this.__nowWorld;t.save(),t.setWorldShadow(e.x*i,e.y*o,e.blur*i,wt.string(e.color))}o&&(s.__isFills?mt.fills(o,this,t):mt.fill(o,this,t)),_&&t.restore(),a&&this.__drawAfterFill(t,e),r&&!n&&(s.__isStrokes?mt.strokes(r,this,t):mt.stroke(r,this,t))}}else s.__pathInputed?ie(this,t,e):this.__drawFast(t,e)},__drawShape(t,e){this.__drawRenderPath(t);const i=this.__,{fill:s,stroke:o}=i;s&&!e.ignoreFill&&(i.__isAlphaPixelFill?mt.fills(s,this,t):mt.fill("#000000",this,t)),i.__isCanvas&&this.__drawAfterFill(t,e),o&&!e.ignoreStroke&&(i.__isAlphaPixelStroke?mt.strokes(o,this,t):mt.stroke("#000000",this,t))},__drawAfterFill(t,e){this.__.__clipAfterFill?(t.save(),t.clipUI(this),this.__drawContent(t,e),t.restore()):this.__drawContent(t,e)}};function ie(t,e,i){const{fill:s,stroke:o,__drawAfterFill:r,__fillAfterStroke:a}=t.__;t.__drawRenderPath(e),a&&mt.stroke(o,t,e),s&&mt.fill(s,t,e),r&&t.__drawAfterFill(e,i),o&&!a&&mt.stroke(o,t,e)}const se={__drawFast(t,e){let{x:i,y:s,width:o,height:r}=this.__layout.boxBounds;const{fill:a,stroke:n,__drawAfterFill:_}=this.__;if(a&&(t.fillStyle=a,t.fillRect(i,s,o,r)),_&&this.__drawAfterFill(t,e),n){const{strokeAlign:a,__strokeWidth:_}=this.__;if(!_)return;t.setStroke(n,_,this.__);const h=_/2;switch(a){case"center":t.strokeRect(0,0,o,r);break;case"inside":o-=_,r-=_,o<0||r<0?(t.save(),this.__clip(t,e),t.strokeRect(i+h,s+h,o,r),t.restore()):t.strokeRect(i+h,s+h,o,r);break;case"outside":t.strokeRect(i-h,s-h,o+_,r+_)}}}};var oe;let re=oe=class extends E{get app(){return this.leafer&&this.leafer.app}get isFrame(){return!1}set scale(t){D.assignScale(this,t)}get scale(){return this.__.scale}get isAutoWidth(){const t=this.__;return t.__autoWidth||t.autoWidth}get isAutoHeight(){const t=this.__;return t.__autoHeight||t.autoHeight}get pen(){const{path:t}=this.__;return z.set(this.path=t||[]),t||this.__drawPathByBox(z),z}constructor(t){super(t)}reset(t){}set(t,e){t&&(e?"temp"===e?(this.lockNormalStyle=!0,Object.assign(this,t),this.lockNormalStyle=!1):this.animate(t,e):Object.assign(this,t))}get(t){return"string"==typeof t?this.__.__getInput(t):this.__.__getInputData(t)}createProxyData(){}find(t,e){return o.need("find")}findTag(t){return this.find({tag:t})}findOne(t,e){return o.need("find")}findId(t){return this.findOne({id:t})}getPath(t,e){this.__layout.update();let i=e?this.__.__pathForRender:this.__.path;return i||(z.set(i=[]),this.__drawPathByBox(z)),t?r.toCanvasData(i,!0):i}getPathString(t,e,i){return r.stringify(this.getPath(t,e),i)}load(){this.__.__computePaint()}__onUpdateSize(){if(this.__.__input){const t=this.__;!t.lazy||this.__inLazyBounds||At.running?t.__computePaint():t.__needComputePaint=!0}}__updateRenderPath(){const t=this.__;t.path?(t.__pathForRender=t.cornerRadius?L.smooth(t.path,t.cornerRadius,t.cornerSmoothing):t.path,t.__useArrow&&St.addArrows(this,!t.cornerRadius)):t.__pathForRender&&(t.__pathForRender=void 0)}__drawRenderPath(t){t.beginPath(),this.__drawPathByData(t,this.__.__pathForRender)}__drawPath(t){t.beginPath(),this.__drawPathByData(t,this.__.path)}__drawPathByData(t,e){e?M.drawPathByData(t,e):this.__drawPathByBox(t)}__drawPathByBox(t){const{x:e,y:i,width:s,height:o}=this.__layout.boxBounds;if(this.__.cornerRadius){const{cornerRadius:r}=this.__;t.roundRect(e,i,s,o,"number"==typeof r?[r]:r)}else t.rect(e,i,s,o)}drawImagePlaceholder(t,e){mt.fill(this.__.placeholderColor,this,t)}animate(t,e,i,s){return o.need("animate")}killAnimate(t,e){}export(t,e){return o.need("export")}syncExport(t,e){return o.need("export")}clone(t){const e=a.clone(this.toJSON());return t&&Object.assign(e,t),oe.one(e)}static one(t,e,i,s,o){return d.get(t.tag||this.prototype.__tag,t,e,i,s,o)}static registerUI(){O()(this)}static registerData(t){p(t)(this.prototype)}static setEditConfig(t){}static setEditOuter(t){}static setEditInner(t){}destroy(){this.fill=this.stroke=null,this.__animate&&this.killAnimate(),super.destroy()}};ut([p(zt)],re.prototype,"__",void 0),ut([gt()],re.prototype,"zoomLayer",void 0),ut([l("")],re.prototype,"id",void 0),ut([l("")],re.prototype,"name",void 0),ut([l("")],re.prototype,"className",void 0),ut([u("pass-through")],re.prototype,"blendMode",void 0),ut([c(1)],re.prototype,"opacity",void 0),ut([y(!0)],re.prototype,"visible",void 0),ut([u(!1)],re.prototype,"locked",void 0),ut([u(!1)],re.prototype,"dim",void 0),ut([u(!1)],re.prototype,"dimskip",void 0),ut([g(0)],re.prototype,"zIndex",void 0),ut([v(!1)],re.prototype,"mask",void 0),ut([f(!1)],re.prototype,"eraser",void 0),ut([w(0,!0)],re.prototype,"x",void 0),ut([w(0,!0)],re.prototype,"y",void 0),ut([x(100,!0)],re.prototype,"width",void 0),ut([x(100,!0)],re.prototype,"height",void 0),ut([S(1,!0)],re.prototype,"scaleX",void 0),ut([S(1,!0)],re.prototype,"scaleY",void 0),ut([m(0,!0)],re.prototype,"rotation",void 0),ut([m(0,!0)],re.prototype,"skewX",void 0),ut([m(0,!0)],re.prototype,"skewY",void 0),ut([w(0,!0)],re.prototype,"offsetX",void 0),ut([w(0,!0)],re.prototype,"offsetY",void 0),ut([w(0,!0)],re.prototype,"scrollX",void 0),ut([w(0,!0)],re.prototype,"scrollY",void 0),ut([R()],re.prototype,"origin",void 0),ut([R()],re.prototype,"around",void 0),ut([l(!1)],re.prototype,"lazy",void 0),ut([k(1)],re.prototype,"pixelRatio",void 0),ut([b(0)],re.prototype,"renderSpread",void 0),ut([B()],re.prototype,"path",void 0),ut([A()],re.prototype,"windingRule",void 0),ut([A(!0)],re.prototype,"closed",void 0),ut([x(0)],re.prototype,"padding",void 0),ut([x(!1)],re.prototype,"lockRatio",void 0),ut([x()],re.prototype,"widthRange",void 0),ut([x()],re.prototype,"heightRange",void 0),ut([l(!1)],re.prototype,"draggable",void 0),ut([l()],re.prototype,"dragBounds",void 0),ut([l(!1)],re.prototype,"editable",void 0),ut([C(!0)],re.prototype,"hittable",void 0),ut([C("path")],re.prototype,"hitFill",void 0),ut([P("path")],re.prototype,"hitStroke",void 0),ut([C(!1)],re.prototype,"hitBox",void 0),ut([C(!0)],re.prototype,"hitChildren",void 0),ut([C(!0)],re.prototype,"hitSelf",void 0),ut([C()],re.prototype,"hitRadius",void 0),ut([F("")],re.prototype,"cursor",void 0),ut([u()],re.prototype,"fill",void 0),ut([P(void 0,!0)],re.prototype,"stroke",void 0),ut([P("inside")],re.prototype,"strokeAlign",void 0),ut([P(1,!0)],re.prototype,"strokeWidth",void 0),ut([P(!1)],re.prototype,"strokeWidthFixed",void 0),ut([P("none")],re.prototype,"strokeCap",void 0),ut([P("miter")],re.prototype,"strokeJoin",void 0),ut([P()],re.prototype,"dashPattern",void 0),ut([P(0)],re.prototype,"dashOffset",void 0),ut([P(10)],re.prototype,"miterLimit",void 0),ut([A(0)],re.prototype,"cornerRadius",void 0),ut([A()],re.prototype,"cornerSmoothing",void 0),ut([ct()],re.prototype,"shadow",void 0),ut([ct()],re.prototype,"innerShadow",void 0),ut([ct()],re.prototype,"blur",void 0),ut([ct()],re.prototype,"backgroundBlur",void 0),ut([ct()],re.prototype,"grayscale",void 0),ut([ct()],re.prototype,"filter",void 0),ut([u()],re.prototype,"placeholderColor",void 0),ut([l(100)],re.prototype,"placeholderDelay",void 0),ut([l({})],re.prototype,"data",void 0),ut([W(E.prototype.reset)],re.prototype,"reset",null),re=oe=ut([I(Zt),I(ee),T()],re);let ae=class extends re{get __tag(){return"Group"}get isBranch(){return!0}constructor(t){super(t)}reset(t){this.__setBranch(),super.reset(t)}__setBranch(){this.children||(this.children=[])}set(t,e){if(t)if(t.children){const{children:i}=t;delete t.children,this.children?this.clear():this.__setBranch(),super.set(t,e),i.forEach((t=>this.add(t))),t.children=i}else super.set(t,e)}toJSON(t){const e=super.toJSON(t);return this.childlessJSON||(e.children=this.children.map((e=>e.toJSON(t)))),e}pick(t,e){}addAt(t,e){this.add(t,e)}addAfter(t,e){this.add(t,this.children.indexOf(e)+1)}addBefore(t,e){this.add(t,this.children.indexOf(e))}add(t,e){}addMany(...t){}remove(t,e){}removeAll(t){}clear(){}};var ne;ut([p(Mt)],ae.prototype,"__",void 0),ut([x(0)],ae.prototype,"width",void 0),ut([x(0)],ae.prototype,"height",void 0),ae=ut([I(N),O()],ae);const _e=n.get("Leafer");let he=ne=class extends ae{get __tag(){return"Leafer"}get isApp(){return!1}get app(){return this.parent||this}get isLeafer(){return!0}get imageReady(){return this.viewReady&&V.isComplete}get layoutLocked(){return!this.layouter.running}get FPS(){return this.renderer?this.renderer.FPS:60}get cursorPoint(){return this.interaction&&this.interaction.hoverData||{x:this.width/2,y:this.height/2}}get clientBounds(){return this.canvas&&this.canvas.getClientBounds(!0)||j()}constructor(t,e){super(e),this.config={start:!0,hittable:!0,smooth:!0,lazySpeard:100},this.leafs=0,this.__eventIds=[],this.__controllers=[],this.__readyWait=[],this.__viewReadyWait=[],this.__viewCompletedWait=[],this.__nextRenderWait=[],this.userConfig=t,t&&(t.view||t.width)&&this.init(t),ne.list.add(this)}init(t,e){if(this.canvas)return;let i;const{config:s}=this;this.__setLeafer(this),e&&(this.parentApp=e,this.__bindApp(e),i=e.running),t&&(this.parent=e,this.initType(t.type),this.parent=void 0,a.assign(s,t));const o=this.canvas=H.canvas(s);this.__controllers.push(this.renderer=H.renderer(this,o,s),this.watcher=H.watcher(this,s),this.layouter=H.layouter(this,s)),this.isApp&&this.__setApp(),this.__checkAutoLayout(s,e),this.view=o.view,e||(this.selector=H.selector(this),this.interaction=H.interaction(this,o,this.selector,s),this.interaction&&(this.__controllers.unshift(this.interaction),this.hitCanvasManager=H.hitCanvasManager()),this.canvasManager=new U,i=s.start),this.hittable=s.hittable,this.fill=s.fill,this.canvasManager.add(o),this.__listenEvents(),i&&(this.__startTimer=setTimeout(this.start.bind(this))),X.run(this.__initWait),this.onInit()}onInit(){}initType(t){}set(t,e){this.waitInit((()=>{super.set(t,e)}))}start(){clearTimeout(this.__startTimer),!this.running&&this.canvas&&(this.running=!0,this.ready?this.emitLeafer(J.RESTART):this.emitLeafer(J.START),this.__controllers.forEach((t=>t.start())),this.isApp||this.renderer.render())}stop(){clearTimeout(this.__startTimer),this.running&&this.canvas&&(this.__controllers.forEach((t=>t.stop())),this.running=!1,this.emitLeafer(J.STOP))}unlockLayout(){this.layouter.start(),this.updateLayout()}lockLayout(){this.updateLayout(),this.layouter.stop()}resize(t){const e=a.copyAttrs({},t,h);Object.keys(e).forEach((t=>this[t]=e[t]))}forceRender(t,e){const{renderer:i}=this;i&&(i.addBlock(t?new q(t):this.canvas.bounds),this.viewReady&&(e?i.render():i.update()))}requestRender(t=!1){this.renderer&&this.renderer.update(t)}updateCursor(t){const e=this.interaction;e&&(t?e.setCursor(t):e.updateCursor())}updateLazyBounds(){this.lazyBounds=this.canvas.bounds.clone().spread(this.config.lazySpeard)}__doResize(t){const{canvas:e}=this;if(!e||e.isSameSize(t))return;const i=a.copyAttrs({},this.canvas,h);e.resize(t),this.updateLazyBounds(),this.__onResize(new G(t,i))}__onResize(t){this.emitEvent(t),a.copyAttrs(this.__,t,h),setTimeout((()=>{this.canvasManager&&this.canvasManager.clearRecycled()}),0)}__setApp(){}__bindApp(t){this.selector=t.selector,this.interaction=t.interaction,this.canvasManager=t.canvasManager,this.hitCanvasManager=t.hitCanvasManager}__setLeafer(t){this.leafer=t,this.__level=1}__checkAutoLayout(t,e){e||(t.width&&t.height||(this.autoLayout=new $(t)),this.canvas.startAutoLayout(this.autoLayout,this.__onResize.bind(this)))}__setAttr(t,e){return this.canvas&&(h.includes(t)?this.__changeCanvasSize(t,e):"fill"===t?this.__changeFill(e):"hittable"===t?this.parent||(this.canvas.hittable=e):"zIndex"===t&&(this.canvas.zIndex=e,setTimeout((()=>this.parent&&this.parent.__updateSortChildren())))),super.__setAttr(t,e)}__getAttr(t){return this.canvas&&h.includes(t)?this.canvas[t]:super.__getAttr(t)}__changeCanvasSize(t,e){const i=a.copyAttrs({},this.canvas,h);i[t]=this.config[t]=e,e&&this.canvas.stopAutoLayout(),this.__doResize(i)}__changeFill(t){this.config.fill=t,this.canvas.allowBackgroundColor?this.canvas.backgroundColor=t:this.forceRender()}__onCreated(){this.created=!0}__onReady(){this.ready=!0,this.emitLeafer(J.BEFORE_READY),this.emitLeafer(J.READY),this.emitLeafer(J.AFTER_READY),X.run(this.__readyWait)}__onViewReady(){this.viewReady||(this.viewReady=!0,this.emitLeafer(J.VIEW_READY),X.run(this.__viewReadyWait))}__onLayoutEnd(){const{grow:t,width:e,height:i}=this.config;if(t){let{width:s,height:o,pixelRatio:r}=this;const a="box"===t?this.worldBoxBounds:this.__world;e||(s=Math.max(1,a.x+a.width)),i||(o=Math.max(1,a.y+a.height)),this.__doResize({width:s,height:o,pixelRatio:r})}this.ready||this.__onReady()}__onNextRender(){if(this.viewReady){X.run(this.__nextRenderWait);const{imageReady:t}=this;t&&!this.viewCompleted&&this.__checkViewCompleted(),t||(this.viewCompleted=!1,this.requestRender())}else this.requestRender()}__checkViewCompleted(t=!0){this.nextRender((()=>{this.imageReady&&(t&&this.emitLeafer(J.VIEW_COMPLETED),X.run(this.__viewCompletedWait),this.viewCompleted=!0)}))}__onWatchData(){this.watcher.childrenChanged&&this.interaction&&this.nextRender((()=>this.interaction.updateCursor()))}waitInit(t,e){e&&(t=t.bind(e)),this.__initWait||(this.__initWait=[]),this.canvas?t():this.__initWait.push(t)}waitReady(t,e){e&&(t=t.bind(e)),this.ready?t():this.__readyWait.push(t)}waitViewReady(t,e){e&&(t=t.bind(e)),this.viewReady?t():this.__viewReadyWait.push(t)}waitViewCompleted(t,e){e&&(t=t.bind(e)),this.__viewCompletedWait.push(t),this.viewCompleted?this.__checkViewCompleted(!1):this.running||this.start()}nextRender(t,e,i){e&&(t=t.bind(e));const s=this.__nextRenderWait;if(i){for(let e=0;e<s.length;e++)if(s[e]===t){s.splice(e,1);break}}else s.push(t);this.requestRender()}zoom(t,e,i,s){return o.need("view")}getValidMove(t,e){return{x:t,y:e}}getValidScale(t){return t}getWorldPointByClient(t,e){return this.interaction&&this.interaction.getLocal(t,e)}getPagePointByClient(t,e){return this.getPagePoint(this.getWorldPointByClient(t,e))}getClientPointByWorld(t){const{x:e,y:i}=this.clientBounds;return{x:e+t.x,y:i+t.y}}updateClientBounds(){this.canvas&&this.canvas.updateClientBounds()}receiveEvent(t){}emitLeafer(t){this.emitEvent(new J(t,this))}__listenEvents(){const t=K.start("FirstCreate "+this.innerName);this.once([[J.START,()=>K.end(t)],[Q.START,this.updateLazyBounds,this],[Z.START,this.__onCreated,this],[Z.END,this.__onViewReady,this]]),this.__eventIds.push(this.on_([[tt.DATA,this.__onWatchData,this],[Q.END,this.__onLayoutEnd,this],[Z.NEXT,this.__onNextRender,this]]))}__removeListenEvents(){this.off_(this.__eventIds)}destroy(t){const e=()=>{if(!this.destroyed){ne.list.remove(this);try{this.stop(),this.emitLeafer(J.END),this.__removeListenEvents(),this.__controllers.forEach((t=>!(this.parent&&t===this.interaction)&&t.destroy())),this.__controllers.length=0,this.parent||(this.selector&&this.selector.destroy(),this.hitCanvasManager&&this.hitCanvasManager.destroy(),this.canvasManager.destroy()),this.canvas.destroy(),this.config.view=this.view=this.parentApp=null,this.userConfig&&(this.userConfig.view=null),super.destroy(),setTimeout((()=>{et.clearRecycled()}),100)}catch(t){_e.error(t)}}};t?e():setTimeout(e)}};he.list=new Y,ut([p(Nt)],he.prototype,"__",void 0),ut([x()],he.prototype,"pixelRatio",void 0),he=ne=ut([O()],he);let de=class extends re{get __tag(){return"Rect"}constructor(t){super(t)}};ut([p(jt)],de.prototype,"__",void 0),de=ut([I(se),T(),O()],de);const{copy:pe,add:le,includes:ue}=it,ce=de.prototype,ye=ae.prototype,ge={};let ve=class extends ae{get __tag(){return"Box"}get isBranchLeaf(){return!0}constructor(t){super(t),this.__layout.renderChanged||this.__layout.renderChange()}__updateStrokeSpread(){return 0}__updateRectRenderSpread(){return 0}__updateRenderSpread(){return this.__updateRectRenderSpread()||-1}__updateRectBoxBounds(){}__updateBoxBounds(t){if(this.children.length&&!this.pathInputed){const t=this.__;if(t.__autoSide){t.__hasSurface&&this.__extraUpdate(),super.__updateBoxBounds();const{boxBounds:e}=this.__layout;t.__autoSize||(t.__autoWidth?(e.width+=e.x,e.x=0,e.height=t.height,e.y=0):(e.height+=e.y,e.y=0,e.width=t.width,e.x=0)),this.__updateNaturalSize()}else this.__updateRectBoxBounds()}else this.__updateRectBoxBounds()}__updateStrokeBounds(){}__updateRenderBounds(){let t;if(this.children.length){const e=this.__,{renderBounds:i,boxBounds:s}=this.__layout;super.__updateRenderBounds(),pe(ge,i),this.__updateRectRenderBounds(),(e.scrollY||e.scrollX)&&(ge.x+=e.scrollX,ge.y+=e.scrollY),t=!ue(s,ge),t&&"hide"!==e.overflow&&le(i,ge)}else this.__updateRectRenderBounds();a.stintSet(this,"isOverflow",t),this.__updateScrollBar()}__updateRectRenderBounds(){}__updateScrollBar(){}__updateRectChange(){}__updateChange(){super.__updateChange(),this.__updateRectChange()}__renderRect(t,e){}__renderGroup(t,e){}__render(t,e){this.__.__drawAfterFill?this.__renderRect(t,e):(this.__renderRect(t,e),this.children.length&&this.__renderGroup(t,e)),this.scrollBar&&this.scrollBar.__render(t,e)}__drawContent(t,e){this.__renderGroup(t,e),(this.__.__useStroke||this.__.__useEffect)&&(t.setWorld(this.__nowWorld),this.__drawRenderPath(t))}};ut([p(Ot)],ve.prototype,"__",void 0),ut([x(100)],ve.prototype,"width",void 0),ut([x(100)],ve.prototype,"height",void 0),ut([l(!1)],ve.prototype,"resizeChildren",void 0),ut([b("show")],ve.prototype,"overflow",void 0),ut([W(ce.__updateStrokeSpread)],ve.prototype,"__updateStrokeSpread",null),ut([W(ce.__updateRenderSpread)],ve.prototype,"__updateRectRenderSpread",null),ut([W(ce.__updateBoxBounds)],ve.prototype,"__updateRectBoxBounds",null),ut([W(ce.__updateStrokeBounds)],ve.prototype,"__updateStrokeBounds",null),ut([W(ce.__updateRenderBounds)],ve.prototype,"__updateRectRenderBounds",null),ut([W(ce.__updateChange)],ve.prototype,"__updateRectChange",null),ut([W(ce.__render)],ve.prototype,"__renderRect",null),ut([W(ye.__render)],ve.prototype,"__renderGroup",null),ve=ut([T(),O()],ve);let fe=class extends ve{get __tag(){return"Frame"}get isFrame(){return!0}constructor(t){super(t)}};ut([p(Yt)],fe.prototype,"__",void 0),ut([u("#FFFFFF")],fe.prototype,"fill",void 0),ut([b("hide")],fe.prototype,"overflow",void 0),fe=ut([O()],fe);const{moveTo:we,closePath:xe,ellipse:Se}=st;let me=class extends re{get __tag(){return"Ellipse"}constructor(t){super(t)}__updatePath(){const{width:t,height:e,innerRadius:i,startAngle:s,endAngle:o}=this.__,r=t/2,a=e/2,n=this.__.path=[];i?(s||o?(i<1&&Se(n,r,a,r*i,a*i,0,s,o,!1),Se(n,r,a,r,a,0,o,s,!0),i<1&&xe(n)):(i<1&&(Se(n,r,a,r*i,a*i),we(n,t,a)),Se(n,r,a,r,a,0,360,0,!0)),ot.ellipseToCurve&&(this.__.path=this.getPath(!0))):s||o?(we(n,r,a),Se(n,r,a,r,a,0,s,o,!1),xe(n)):Se(n,r,a,r,a)}};ut([p(Ht)],me.prototype,"__",void 0),ut([A(0)],me.prototype,"innerRadius",void 0),ut([A(0)],me.prototype,"startAngle",void 0),ut([A(0)],me.prototype,"endAngle",void 0),me=ut([O()],me);const{moveTo:Re,lineTo:ke,drawPoints:be}=st,{rotate:Be,getAngle:Ae,getDistance:Ce,defaultPoint:Pe}=rt,{toBounds:Fe}=at;let We=class extends re{get __tag(){return"Line"}get toPoint(){const{width:t,rotation:e}=this.__,i=_t();return t&&(i.x=t),e&&Be(i,e),i}set toPoint(t){this.width=Ce(Pe,t),this.rotation=Ae(Pe,t),this.height&&(this.height=0)}constructor(t){super(t)}__updatePath(){const t=this.__,e=t.path=[];t.points?be(e,t.points,!1,t.closed):(Re(e,0,0),ke(e,this.width,0))}__updateRenderPath(){const t=this.__;!this.pathInputed&&t.points&&t.curve?(be(t.__pathForRender=[],t.points,t.curve,t.closed),t.__useArrow&&St.addArrows(this,!1)):super.__updateRenderPath()}__updateBoxBounds(){this.points?Fe(this.__.__pathForRender,this.__layout.boxBounds):super.__updateBoxBounds()}};ut([p(Vt)],We.prototype,"__",void 0),ut([nt("center")],We.prototype,"strokeAlign",void 0),ut([x(0)],We.prototype,"height",void 0),ut([A()],We.prototype,"points",void 0),ut([A(0)],We.prototype,"curve",void 0),ut([A(!1)],We.prototype,"closed",void 0),We=ut([O()],We);const{sin:Ee,cos:Ie,PI:Te}=Math,{moveTo:De,lineTo:ze,closePath:Le,drawPoints:Me}=st,Oe=We.prototype;let Ne=class extends re{get __tag(){return"Polygon"}constructor(t){super(t)}__updatePath(){const t=this.__.path=[];if(this.__.points)Me(t,this.__.points,!1,!0);else{const{width:e,height:i,sides:s}=this.__,o=e/2,r=i/2;De(t,o,0);for(let e=1;e<s;e++)ze(t,o+o*Ee(2*e*Te/s),r-r*Ie(2*e*Te/s));Le(t)}}__updateRenderPath(){}__updateBoxBounds(){}};ut([p(Ut)],Ne.prototype,"__",void 0),ut([A(3)],Ne.prototype,"sides",void 0),ut([A()],Ne.prototype,"points",void 0),ut([A(0)],Ne.prototype,"curve",void 0),ut([W(Oe.__updateRenderPath)],Ne.prototype,"__updateRenderPath",null),ut([W(Oe.__updateBoxBounds)],Ne.prototype,"__updateBoxBounds",null),Ne=ut([T(),O()],Ne);const{sin:Ye,cos:Ve,PI:je}=Math,{moveTo:He,lineTo:Ue,closePath:Xe}=st;let Je=class extends re{get __tag(){return"Star"}constructor(t){super(t)}__updatePath(){const{width:t,height:e,corners:i,innerRadius:s}=this.__,o=t/2,r=e/2,a=this.__.path=[];He(a,o,0);for(let t=1;t<2*i;t++)Ue(a,o+(t%2==0?o:o*s)*Ye(t*je/i),r-(t%2==0?r:r*s)*Ve(t*je/i));Xe(a)}};ut([p(Xt)],Je.prototype,"__",void 0),ut([A(5)],Je.prototype,"corners",void 0),ut([A(.382)],Je.prototype,"innerRadius",void 0),Je=ut([O()],Je);let qe=class extends de{get __tag(){return"Image"}get ready(){const{image:t}=this;return t&&t.ready}get image(){const{fill:t}=this.__;return t instanceof Array&&t[0].image}constructor(t){super(t)}};ut([p(Kt)],qe.prototype,"__",void 0),ut([x("")],qe.prototype,"url",void 0),qe=ut([O()],qe);const Ge=qe;let $e=class extends de{get __tag(){return"Canvas"}get context(){return this.canvas.context}get ready(){return!this.url}constructor(t){super(t),this.canvas=H.canvas(this.__),t&&t.url&&this.drawImage(t.url)}drawImage(t){new ht({url:t}).load((t=>{this.context.drawImage(t.view,0,0),this.url=void 0,this.paint(),this.emitEvent(new dt(dt.LOADED,{image:t}))}))}draw(t,e,i,s){const o=new pt(t.worldTransform).invert(),r=new pt;e&&r.translate(e.x,e.y),i&&("number"==typeof i?r.scale(i):r.scale(i.x,i.y)),s&&r.rotate(s),o.multiplyParent(r),t.__render(this.canvas,{matrix:o.withScale()}),this.paint()}paint(){this.forceRender()}__drawContent(t,e){const{width:i,height:s}=this.__,{view:o}=this.canvas;t.drawImage(o,0,0,o.width,o.height,0,0,i,s)}__updateSize(){const{canvas:t}=this;if(t){const{smooth:e,safeResize:i}=this.__;t.resize(this.__,i),t.smooth!==e&&(t.smooth=e)}}destroy(){this.canvas&&(this.canvas.destroy(),this.canvas=null),super.destroy()}};ut([p(Qt)],$e.prototype,"__",void 0),ut([yt(100)],$e.prototype,"width",void 0),ut([yt(100)],$e.prototype,"height",void 0),ut([yt(1)],$e.prototype,"pixelRatio",void 0),ut([yt(!0)],$e.prototype,"smooth",void 0),ut([l(!1)],$e.prototype,"safeResize",void 0),ut([yt()],$e.prototype,"contextSettings",void 0),$e=ut([O()],$e);const{copyAndSpread:Ke,includes:Qe,spread:Ze,setList:ti}=it;let ei=class extends re{get __tag(){return"Text"}get textDrawData(){return this.updateLayout(),this.__.__textDrawData}constructor(t){super(t)}__updateTextDrawData(){const t=this.__,{lineHeight:e,letterSpacing:i,fontFamily:s,fontSize:o,fontWeight:r,italic:a,textCase:n,textOverflow:_,padding:h}=t;t.__lineHeight=xt.number(e,o),t.__letterSpacing=xt.number(i,o),t.__padding=h?D.fourNumber(h):void 0,t.__baseLine=t.__lineHeight-(t.__lineHeight-.7*o)/2,t.__font=`${a?"italic ":""}${"small-caps"===n?"small-caps ":""}${"normal"!==r?r+" ":""}${o}px ${s}`,t.__clipText="show"!==_&&!t.__autoSize,t.__textDrawData=ft.getDrawData((t.__isPlacehold=t.placeholder&&""===t.text)?t.placeholder:t.text,this.__)}__updateBoxBounds(){const t=this.__,e=this.__layout,{fontSize:i,italic:s,padding:o,__autoWidth:r,__autoHeight:n}=t;this.__updateTextDrawData();const{bounds:_}=t.__textDrawData,h=e.boxBounds;if(e.contentBounds=_,t.__lineHeight<i&&Ze(_,i/2),r||n){if(h.x=r?_.x:0,h.y=n?_.y:0,h.width=r?_.width:t.width,h.height=n?_.height:t.height,o){const[e,i,s,o]=t.__padding;r&&(h.x-=o,h.width+=i+o),n&&(h.y-=e,h.height+=s+e)}this.__updateNaturalSize()}else super.__updateBoxBounds();s&&(h.width+=.16*i),a.stintSet(this,"isOverflow",!Qe(h,_)),this.isOverflow?(ti(t.__textBoxBounds={},[h,_]),e.renderChanged=!0):t.__textBoxBounds=h}__onUpdateSize(){this.__box&&this.__box.__onUpdateSize(),super.__onUpdateSize()}__updateRenderSpread(){let t=super.__updateRenderSpread();return t||(t=this.isOverflow?1:0),t}__updateRenderBounds(){const{renderBounds:t,renderSpread:e}=this.__layout;Ke(t,this.__.__textBoxBounds,e),this.__box&&(this.__box.__layout.renderBounds=t)}__drawRenderPath(t){t.font=this.__.__font}__draw(t,e,i){const s=this.__box;s&&(s.__nowWorld=this.__nowWorld,s.__draw(t,e,i)),this.textEditing&&!e.exporting||super.__draw(t,e,i)}__drawShape(t,e){e.shape&&this.__box&&this.__box.__drawShape(t,e),super.__drawShape(t,e)}destroy(){this.boxStyle&&(this.boxStyle=null),super.destroy()}};ut([p($t)],ei.prototype,"__",void 0),ut([x(0)],ei.prototype,"width",void 0),ut([x(0)],ei.prototype,"height",void 0),ut([u()],ei.prototype,"boxStyle",void 0),ut([l(!1)],ei.prototype,"resizeFontSize",void 0),ut([u("#000000")],ei.prototype,"fill",void 0),ut([nt("outside")],ei.prototype,"strokeAlign",void 0),ut([C("all")],ei.prototype,"hitFill",void 0),ut([x("")],ei.prototype,"text",void 0),ut([x("")],ei.prototype,"placeholder",void 0),ut([x("caption")],ei.prototype,"fontFamily",void 0),ut([x(12)],ei.prototype,"fontSize",void 0),ut([x("normal")],ei.prototype,"fontWeight",void 0),ut([x(!1)],ei.prototype,"italic",void 0),ut([x("none")],ei.prototype,"textCase",void 0),ut([x("none")],ei.prototype,"textDecoration",void 0),ut([x(0)],ei.prototype,"letterSpacing",void 0),ut([x({type:"percent",value:1.5})],ei.prototype,"lineHeight",void 0),ut([x(0)],ei.prototype,"paraIndent",void 0),ut([x(0)],ei.prototype,"paraSpacing",void 0),ut([x("x")],ei.prototype,"writingMode",void 0),ut([x("left")],ei.prototype,"textAlign",void 0),ut([x("top")],ei.prototype,"verticalAlign",void 0),ut([x(!0)],ei.prototype,"autoSizeAlign",void 0),ut([x("normal")],ei.prototype,"textWrap",void 0),ut([x("show")],ei.prototype,"textOverflow",void 0),ut([u(!1)],ei.prototype,"textEditing",void 0),ei=ut([O()],ei);let ii=class extends re{get __tag(){return"Path"}constructor(t){super(t)}};ut([p(Jt)],ii.prototype,"__",void 0),ut([nt("center")],ii.prototype,"strokeAlign",void 0),ii=ut([O()],ii);let si=class extends ae{get __tag(){return"Pen"}constructor(t){super(t)}setStyle(t){const e=this.pathElement=new ii(t);return this.pathStyle=t,this.__path=e.path||(e.path=[]),this.add(e),this}beginPath(){return this}moveTo(t,e){return this}lineTo(t,e){return this}bezierCurveTo(t,e,i,s,o,r){return this}quadraticCurveTo(t,e,i,s){return this}closePath(){return this}rect(t,e,i,s){return this}roundRect(t,e,i,s,o){return this}ellipse(t,e,i,s,o,r,a,n){return this}arc(t,e,i,s,o,r){return this}arcTo(t,e,i,s,o){return this}drawEllipse(t,e,i,s,o,r,a,n){return this}drawArc(t,e,i,s,o,r){return this}drawPoints(t,e,i){return this}clearPath(){return this}paint(){this.pathElement.__layout.boxChanged||this.pathElement.forceUpdate("path")}};ut([p(qt)],si.prototype,"__",void 0),ut([(e,i)=>{t(e,i,{get(){return this.__path}})}],si.prototype,"path",void 0),si=ut([I(lt,["set","path","paint"]),O()],si);export{ve as Box,Ot as BoxData,$e as Canvas,Qt as CanvasData,wt as ColorConvert,bt as Effect,me as Ellipse,Ht as EllipseData,At as Export,Bt as Filter,fe as Frame,Yt as FrameData,ae as Group,Mt as GroupData,qe as Image,Kt as ImageData,he as Leafer,Nt as LeaferData,We as Line,Vt as LineData,Ge as MyImage,mt as Paint,kt as PaintGradient,Rt as PaintImage,ii as Path,St as PathArrow,Jt as PathData,si as Pen,qt as PenData,Ne as Polygon,Ut as PolygonData,de as Rect,jt as RectData,se as RectRender,Je as Star,Xt as StarData,Ct as State,ei as Text,ft as TextConvert,$t as TextData,Pt as Transition,re as UI,Zt as UIBounds,zt as UIData,ee as UIRender,xt as UnitConvert,vt as createAttr,ct as effectType,yt as resizeType,gt as zoomLayerType};
2
2
  //# sourceMappingURL=draw.esm.min.js.map