UNPKG

leafer-draw

Version:

**leafer-draw** 是 [leafer-ui](https://github.com/leaferjs/leafer-ui) 的轻量版,体积小巧,移除了交互功能,仅提供绘制元素的功能,适用于绘制海报、插图、图表、动画等场景,或作为框架的底层绘制库。

3 lines (2 loc) 41.9 kB
import{Debug as t,LeaferCanvasBase as e,Platform as i,isString as s,DataHelper as n,canvasSizeAttrs as a,isUndefined as r,ResizeEvent as o,canvasPatch as l,Creator as d,LeaferImage as c,defineKey as h,FileHelper as u,LeafList as f,RenderEvent as p,ChildEvent as g,WatchEvent as _,PropertyEvent as w,LeafHelper as m,BranchHelper as y,LeafBoundsHelper as v,Bounds as x,isArray as b,LeafLevelList as S,LayoutEvent as k,Run as B,ImageManager as R,isObject as E,BoundsHelper as L,FourNumberHelper as A,Matrix as T,ImageEvent as P,MatrixHelper as C,MathHelper as O,AlignHelper as D,PointHelper as M,isNumber as W,getMatrixData as I,AroundHelper as F,OneRadian as z,Direction4 as Y}from"@leafer/core";export*from"@leafer/core";export{LeaferFilm,LeaferImage,LeaferVideo}from"@leafer/core";import{Paint as V,PaintImage as U,ColorConvert as X,PaintGradient as N,Effect as G,Group as q,TextConvert as j}from"@leafer-ui/draw";export*from"@leafer-ui/draw";var H;function Q(t,e,i,s){return new(i||(i=Promise))(function(n,a){function r(t){try{l(s.next(t))}catch(t){a(t)}}function o(t){try{l(s.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(r,o)}l((s=s.apply(t,e||[])).next())})}!function(t){t[t.none=1]="none",t[t.free=2]="free",t[t.mirrorAngle=3]="mirrorAngle",t[t.mirror=4]="mirror"}(H||(H={})),"function"==typeof SuppressedError&&SuppressedError;const $=t.get("LeaferCanvas");class Z extends e{set zIndex(t){const{style:e}=this.view;e.zIndex=t,this.setAbsolute(this.view)}set childIndex(t){const{view:e,parentView:i}=this;if(e&&i){const s=i.children[t];s?(this.setAbsolute(s),i.insertBefore(e,s)):i.appendChild(s)}}init(){const{config:t}=this,e=t.view||t.canvas;e?this.__createViewFrom(e):this.__createView();const{style:s}=this.view;if(s.display||(s.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none",this.view.classList.add("leafer-canvas-view")}i.syncDomFont&&!this.parentView&&(s.display="none",document.body&&document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(t)}set backgroundColor(t){this.view.style.backgroundColor=t}get backgroundColor(){return this.view.style.backgroundColor}set hittable(t){this.view.style.pointerEvents=t?"auto":"none"}get hittable(){return"none"!==this.view.style.pointerEvents}__createView(){this.view=document.createElement("canvas")}__createViewFrom(t){let e=s(t)?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;t.hasChildNodes()&&(this.setAbsolute(i),t.style.position||(t.style.position="relative")),t.appendChild(i)}else $.error(`no id: ${t}`),this.__createView()}setAbsolute(t){const{style:e}=t;e.position="absolute",e.top=e.left="0px"}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;s.width=t+"px",s.height=e+"px",this.unreal||(this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i))}updateClientBounds(){this.view.parentElement&&(this.clientBounds=this.view.getBoundingClientRect())}startAutoLayout(t,e){if(this.resizeListener=e,t){if(this.autoBounds=t,this.resizeObserver)return;try{this.resizeObserver=new ResizeObserver(t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)});const t=this.parentView;t?(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect())):(this.checkAutoBounds(this.view),$.warn("no parent"))}catch(t){this.imitateResizeObserver()}this.stopListenPixelRatio()}else this.listenPixelRatio(),this.unreal&&this.updateViewSize()}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}listenPixelRatio(){this.windowListener||window.addEventListener("resize",this.windowListener=()=>{const t=i.devicePixelRatio;if(!this.config.pixelRatio&&this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}})}stopListenPixelRatio(){this.windowListener&&(window.removeEventListener("resize",this.windowListener),this.windowListener=null)}checkAutoBounds(t){const e=this.view,{x:s,y:n,width:a,height:r}=this.autoBounds.getBoundsFrom(t),o={width:a,height:r,pixelRatio:this.config.pixelRatio?this.pixelRatio:i.devicePixelRatio};if(!this.isSameSize(o)){const{style:t}=e;t.marginLeft=s+"px",t.marginTop=n+"px",this.emitResize(o)}}stopAutoLayout(){this.autoLayout=!1,this.resizeObserver&&this.resizeObserver.disconnect(),this.resizeListener=this.resizeObserver=null}emitResize(t){const e={};n.copyAttrs(e,this,a),this.resize(t),this.resizeListener&&!r(this.width)&&this.resizeListener(new o(t,e))}unrealCanvas(){if(!this.unreal&&this.parentView){let t=this.view;t&&t.remove(),t=this.view=document.createElement("div"),this.parentView.appendChild(this.view),t.classList.add("leafer-app-view"),this.unreal=!0}}destroy(){const{view:t}=this;t&&(this.stopAutoLayout(),this.stopListenPixelRatio(),t.parentElement&&t.remove(),super.destroy())}}function J(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>{const s=u.mimeType(e),n=t.toDataURL(s,i);return"image/bmp"===s?n.replace("image/png;","image/bmp;"):n},canvasToBolb:(t,e,i)=>new Promise(s=>t.toBlob(s,u.mimeType(e),i)),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(u.mimeType(u.fileType(e)),s);return i.origin.download(n,e)},download(t,e){return Q(this,void 0,void 0,function*(){let i=document.createElement("a");i.href=t,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i)})},loadImage:(t,e,s)=>new Promise((s,n)=>{const a=new i.origin.Image;e&&(a.setAttribute("crossOrigin",e),a.crossOrigin=e),a.onload=()=>{s(a)},a.onerror=t=>{n(t)},a.src=i.image.getRealURL(t)}),loadContent(t){return Q(this,arguments,void 0,function*(t,e="text"){const i=yield fetch(t);if(!i.ok)throw new Error(`${i.status}`);return yield i[e]()})},Image:Image,PointerEvent:PointerEvent,DragEvent:DragEvent},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=d.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}l(CanvasRenderingContext2D.prototype),l(Path2D.prototype),Object.assign(d,{canvas:(t,e)=>new Z(t,e),image:t=>new c(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},h(i,"devicePixelRatio",{get:()=>devicePixelRatio});const{userAgent:K}=navigator;K.indexOf("Firefox")>-1?(i.intWheelDeltaY=!0,i.syncDomFont=!0):(/iPhone|iPad|iPod/.test(navigator.userAgent)||/Macintosh/.test(navigator.userAgent)&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent))&&(i.fullImageShadow=!0),K.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):K.indexOf("Mac")>-1?i.os="Mac":K.indexOf("Linux")>-1&&(i.os="Linux");class tt{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove&&this.config.usePartLayout){const t=new f;return this.__updatedList.list.forEach(e=>{e.leafer&&t.add(e)}),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new f,this.target=t,e&&(this.config=n.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(p.REQUEST)}__onAttrChange(t){this.config.usePartLayout&&this.__updatedList.add(t.target),this.update()}__onChildEvent(t){this.config.usePartLayout&&(t.type===g.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent))),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new _(_.DATA,{updatedList:this.updatedList})),this.__updatedList=new f,this.totalTimes++,this.changed=this.hasVisible=this.hasRemove=this.hasAdd=!1}__listenEvents(){this.__eventIds=[this.target.on_([[w.CHANGE,this.__onAttrChange,this],[[g.ADD,g.REMOVE],this.__onChildEvent,this],[_.REQUEST,this.__onRquestData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.__updatedList=null)}}const{updateAllMatrix:et,updateBounds:it,updateChange:st}=m,{pushAllChildBranch:nt,pushAllParent:at}=y;const{worldBounds:rt}=v;class ot{constructor(t){this.updatedBounds=new x,this.beforeBounds=new x,this.afterBounds=new x,b(t)&&(t=new f(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,rt)}setAfter(){this.afterBounds.setListWithFn(this.updatedList.list,rt),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:lt,updateAllChange:dt}=m,ct=t.get("Layouter");class ht{constructor(t,e){this.totalTimes=0,this.config={usePartLayout:!0},this.__levelList=new S,this.target=t,e&&(this.config=n.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(this.layouting||!this.running)return;const{target:t}=this;this.times=0;try{t.emit(k.START),this.layoutOnce(),t.emitEvent(new k(k.END,this.layoutedBlocks,this.times))}catch(t){ct.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ct.warn("layouting"):this.times>3?ct.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(_.REQUEST),this.totalTimes>1&&this.config.usePartLayout?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=B.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:a,AFTER:r}=k,o=this.getBlocks(s);o.forEach(t=>t.setBefore()),i.emitEvent(new k(n,o,this.times)),this.extraBlock=null,s.sort(),function(t,e){let i;t.list.forEach(t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(et(t,!0),e.add(t),t.isBranch&&nt(t,e),at(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),at(t,e)))})}(s,this.__levelList),function(t){let e,i,s;t.sort(!0),t.levels.forEach(n=>{e=t.levelMap[n];for(let t=0,n=e.length;t<n;t++){if(i=e[t],i.isBranch&&i.__tempNumber){s=i.children;for(let t=0,e=s.length;t<e;t++)s[t].isBranch||it(s[t])}it(i)}})}(this.__levelList),function(t){t.list.forEach(st)}(s),this.extraBlock&&o.push(this.extraBlock),o.forEach(t=>t.setAfter()),i.emitEvent(new k(a,o,this.times)),i.emitEvent(new k(r,o,this.times)),this.addBlocks(o),this.__levelList.reset(),this.__updatedList=null,B.end(e)}fullLayout(){const t=B.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=k,a=this.getBlocks(new f(e));e.emitEvent(new k(i,a,this.times)),ht.fullLayout(e),a.forEach(t=>{t.setAfter()}),e.emitEvent(new k(s,a,this.times)),e.emitEvent(new k(n,a,this.times)),this.addBlocks(a),B.end(t)}static fullLayout(t){lt(t,!0),t.isBranch?y.updateBounds(t):m.updateBounds(t),dt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new ot([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new ot(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){this.__eventIds=[this.target.on_([[k.REQUEST,this.layout,this],[k.AGAIN,this.layoutAgain,this],[_.DATA,this.__onReceiveWatchData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const ut=t.get("Renderer");class ft{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,ceilPartPixel:!0,maxFPS:120},this.frames=[],this.target=t,this.canvas=e,i&&(this.config=n.default(i,this.config)),this.__listenEvents()}start(){this.running=!0,this.update(!1)}stop(){this.running=!1}update(t=!0){this.changed||(this.changed=t),this.requestTime||this.__requestRender()}requestLayout(){this.target.emit(k.REQUEST)}checkRender(){if(this.running){const{target:t}=this;t.isApp&&(t.emit(p.CHILD_START,t),t.children.forEach(t=>{t.renderer.FPS=this.FPS,t.renderer.checkRender()}),t.emit(p.CHILD_END,t)),this.changed&&this.canvas.view&&this.render(),this.target.emit(p.NEXT)}}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new x,ut.log(e.innerName,"---\x3e");try{this.emitRender(p.START),this.renderOnce(t),this.emitRender(p.END,this.totalBounds),R.clearRecycled()}catch(t){this.rendering=!1,ut.error(t)}ut.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return ut.warn("rendering");if(this.times>3)return ut.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new x,this.renderOptions={},t)this.emitRender(p.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(p.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(p.RENDER,this.renderBounds,this.renderOptions),this.emitRender(p.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;e&&(this.mergeBlocks(),e.forEach(e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=B.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=new x(s);i.save(),s.spread(ft.clipSpread).ceil();const{ceilPartPixel:a}=this.config;i.clipWorld(s,a),i.clearWorld(s,a),this.__render(s,n),i.restore(),B.end(e)}fullRender(){const t=B.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds),e.restore(),B.end(t)}__render(e,s){const{canvas:n,target:a}=this,r=e.includes(a.__world),o=r?{includes:r}:{bounds:e,includes:r};this.needFill&&n.fillWorld(e,this.config.fill),t.showRepaint&&t.drawRepaint(n,e),this.config.useCellRender&&(o.cellList=this.getCellList()),i.render(a,n,o),this.renderBounds=s=s||e,this.renderOptions=o,this.totalBounds.isEmpty()?this.totalBounds=s:this.totalBounds.add(s),n.updateRender(s)}getCellList(){}addBlock(t,e){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new x;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=this.target;if(this.requestTime||!t)return;if(t.parentApp)return t.parentApp.requestRender(!1);this.requestTime=this.frameTime||Date.now();const e=()=>{const t=1e3/((this.frameTime=Date.now())-this.requestTime),{maxFPS:s}=this.config;if(s&&t>s)return i.requestRender(e);const{frames:n}=this;n.length>30&&n.shift(),n.push(t),this.FPS=Math.round(n.reduce((t,e)=>t+e,0)/n.length),this.requestTime=0,this.checkRender()};i.requestRender(e)}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new x(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new x(0,0,1,1)),this.update()}}__onLayoutEnd(t){t.data&&t.data.map(t=>{let e;const{updatedList:i}=t;i&&i.list.some(t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||ut.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e)),this.addBlock(e?this.canvas.bounds:t.updatedBounds,i)})}emitRender(t,e,i){this.target.emitEvent(new p(t,this.times,e,i))}__listenEvents(){this.__eventIds=[this.target.on_([[p.REQUEST,this.update,this],[k.END,this.__onLayoutEnd,this],[p.AGAIN,this.renderAgain,this],[o.RESIZE,this.__onResize,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.config={},this.target=this.canvas=null)}}function pt(t,e,i){t.__.__font?V.fillText(t,e,i):t.__.windingRule?e.fill(t.__.windingRule):e.fill()}function gt(t,e,i,s,n){const a=i.__;E(t)?V.drawStrokesStyle(t,e,!1,i,s,n):(s.setStroke(t,a.__strokeWidth*e,a),s.stroke()),a.__useArrow&&V.strokeArrow(t,i,s,n)}function _t(t,e,i,s,n){const a=i.__;E(t)?V.drawStrokesStyle(t,e,!0,i,s,n):(s.setStroke(t,a.__strokeWidth*e,a),V.drawTextStroke(i,s,n))}function wt(t,e,i,s,n){const a=s.getSameCanvas(!0,!0);a.font=i.__.__font,_t(t,2,i,a,n),a.blendMode="outside"===e?"destination-out":"destination-in",V.fillText(i,a,n),a.blendMode="normal",m.copyCanvasByWorld(i,s,a),a.recycle(i.__nowWorld)}ft.clipSpread=10,Object.assign(d,{watcher:(t,e)=>new tt(t,e),layouter:(t,e)=>new ht(t,e),renderer:(t,e,i)=>new ft(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,s)=>{}}),i.layout=ht.fullLayout,i.render=function(t,e,i){const s=Object.assign(Object.assign({},i),{topRendering:!0});i.topList=new f,t.__render(e,i),i.topList.length&&i.topList.forEach(t=>t.__render(e,s))};const{getSpread:mt,copyAndSpread:yt,toOuterOf:vt,getOuterOf:xt,getByMove:bt,move:St,getIntersectData:kt}=L,Bt={};let Rt;const{stintSet:Et}=n,{hasTransparent:Lt}=X;function At(t,e,i){if(!E(e)||!1===e.visible||0===e.opacity)return;let n;const{boxBounds:a}=i.__layout,{type:o}=e;switch(o){case"image":case"film":case"video":if(!e.url)return;n=U.image(i,t,e,a,!Rt||!Rt[e.url]),"image"!==o&&U[o](n);break;case"linear":n=N.linearGradient(e,a);break;case"radial":n=N.radialGradient(e,a);break;case"angular":n=N.conicGradient(e,a);break;case"solid":const{color:s,opacity:l}=e;n={type:o,style:X.string(s,l)};break;default:r(e.r)||(n={type:"solid",style:X.string(e)})}if(n&&(n.originPaint=e,s(n.style)&&Lt(n.style)&&(n.isTransparent=!0),e.style)){if(0===e.style.strokeWidth)return;n.strokeStyle=e.style}return n}const Tt={compute:function(t,e){const i=e.__,s=[];let n,a,r,o=i.__input[t];b(o)||(o=[o]),Rt=U.recycleImage(t,i);for(let i,n=0,a=o.length;n<a;n++)(i=At(t,o[n],e))&&(s.push(i),i.strokeStyle&&(r||(r=1),i.strokeStyle.strokeWidth&&(r=Math.max(r,i.strokeStyle.strokeWidth))));s.length?(i["_"+t]=s,s.every(t=>t.isTransparent)&&(s.some(t=>t.image)&&(n=!0),a=!0),"fill"===t?(Et(i,"__isAlphaPixelFill",n),Et(i,"__isTransparentFill",a)):(Et(i,"__isAlphaPixelStroke",n),Et(i,"__isTransparentStroke",a),Et(i,"__hasMultiStrokeStyle",r))):(i.__removePaint(t,!1),i["_"+t]="")},fill:function(t,e,i,s){i.fillStyle=t,pt(e,i,s)},fills:function(t,e,i,s){let n,a,r;for(let o=0,l=t.length;o<l;o++){if(n=t[o],a=n.originPaint,n.image){if(r?r++:r=1,U.checkImage(n,!e.__.__font,e,i,s))continue;if(!n.style){1===r&&n.image.isPlacehold&&e.drawImagePlaceholder(n,i,s);continue}}if(i.fillStyle=n.style,n.transform||a.scaleFixed){if(i.save(),n.transform&&i.transform(n.transform),a.scaleFixed){const{scaleX:t,scaleY:s}=e.getRenderScaleData(!0,a.scaleFixed,!1);1!==t&&i.scale(t,s)}a.blendMode&&(i.blendMode=a.blendMode),pt(e,i,s),i.restore()}else a.blendMode?(i.saveBlendMode(a.blendMode),pt(e,i,s),i.restoreBlendMode()):pt(e,i,s)}},fillPathOrText:pt,fillText:function(t,e,i){const s=t.__,{rows:n,decorationY:a}=s.__textDrawData;let r;s.__isPlacehold&&s.placeholderColor&&(e.fillStyle=s.placeholderColor);for(let t=0,i=n.length;t<i;t++)r=n[t],r.text?e.fillText(r.text,r.x,r.y):r.data&&r.data.forEach(t=>{e.fillText(t.char,t.x,r.y)});if(a){const{decorationColor:t,decorationHeight:i}=s.__textDrawData;t&&(e.fillStyle=t),n.forEach(t=>a.forEach(s=>e.fillRect(t.x,t.y+s,t.width,i)))}},stroke:function(t,e,i,s){const n=e.__;if(n.__strokeWidth)if(n.__font)V.strokeText(t,e,i,s);else if(n.__pathForStroke)V.fillStroke(t,e,i,s);else switch(n.strokeAlign){case"center":gt(t,1,e,i,s);break;case"inside":!function(t,e,i,s){i.save(),i.clipUI(e),gt(t,2,e,i,s),i.restore()}(t,e,i,s);break;case"outside":!function(t,e,i,s){const n=e.__;if(n.__fillAfterStroke)gt(t,2,e,i,s);else{const{renderBounds:a}=e.__layout,r=i.getSameCanvas(!0,!0);e.__drawRenderPath(r),gt(t,2,e,r,s),r.clipUI(n),r.clearWorld(a),m.copyCanvasByWorld(e,i,r),r.recycle(e.__nowWorld)}}(t,e,i,s)}},strokes:function(t,e,i,s){V.stroke(t,e,i,s)},strokeText:function(t,e,i,s){switch(e.__.strokeAlign){case"center":_t(t,1,e,i,s);break;case"inside":wt(t,"inside",e,i,s);break;case"outside":e.__.__fillAfterStroke?_t(t,2,e,i,s):wt(t,"outside",e,i,s)}},drawTextStroke:function(t,e,i){let s,n=t.__.__textDrawData;const{rows:a,decorationY:r}=n;for(let t=0,i=a.length;t<i;t++)s=a[t],s.text?e.strokeText(s.text,s.x,s.y):s.data&&s.data.forEach(t=>{e.strokeText(t.char,t.x,s.y)});if(r){const{decorationHeight:t}=n;a.forEach(i=>r.forEach(s=>e.strokeRect(i.x,i.y+s,i.width,t)))}},drawStrokesStyle:function(t,e,i,s,n,a){let r;const o=s.__,{__hasMultiStrokeStyle:l}=o;l||n.setStroke(void 0,o.__strokeWidth*e,o);for(let d=0,c=t.length;d<c;d++)if(r=t[d],(!r.image||!U.checkImage(r,!1,s,n,a))&&r.style){if(l){const{strokeStyle:t}=r;t?n.setStroke(r.style,o.__getRealStrokeWidth(t)*e,o,t):n.setStroke(r.style,o.__strokeWidth*e,o)}else n.strokeStyle=r.style;r.originPaint.blendMode?(n.saveBlendMode(r.originPaint.blendMode),i?V.drawTextStroke(s,n,a):n.stroke(),n.restoreBlendMode()):i?V.drawTextStroke(s,n,a):n.stroke()}},shape:function(t,e,s){const n=e.getSameCanvas(),a=e.bounds,r=t.__nowWorld,o=t.__layout,l=t.__nowWorldShapeBounds||(t.__nowWorldShapeBounds={});let d,c,h,u,f,p;vt(o.strokeSpread?(yt(Bt,o.boxBounds,o.strokeSpread),Bt):o.boxBounds,r,l);let{scaleX:g,scaleY:_}=t.getRenderScaleData(!0);if(a.includes(l))p=n,d=f=l,c=r;else{let n;if(i.fullImageShadow)n=l;else{const t=o.renderShapeSpread?mt(a,A.swapAndScale(o.renderShapeSpread,g,_)):a;n=kt(t,l)}u=a.getFitMatrix(n);let{a:w,d:m}=u;u.a<1&&(p=e.getSameCanvas(),t.__renderShape(p,s),g*=w,_*=m),f=xt(l,u),d=bt(f,-u.e,-u.f),c=xt(r,u),St(c,-u.e,-u.f);const y=s.matrix;y?(h=new T(u),h.multiply(y),w*=y.scaleX,m*=y.scaleY):h=u,h.withScale(w,m),s=Object.assign(Object.assign({},s),{matrix:h})}return t.__renderShape(n,s),{canvas:n,matrix:h,fitMatrix:u,bounds:d,renderBounds:c,worldCanvas:p,shapeBounds:f,scaleX:g,scaleY:_}}};let Pt,Ct=new x;const{isSame:Ot}=L;function Dt(t,e,i,s,n,a){let r=!0;const o=t.__;if("fill"!==e||o.__naturalWidth||(o.__naturalWidth=s.width/o.pixelRatio,o.__naturalHeight=s.height/o.pixelRatio,o.__autoSide&&(t.forceUpdate("width"),m.updateBounds(t),t.__proxyData&&(t.setProxyAttr("width",o.width),t.setProxyAttr("height",o.height)),r=!1)),"brush"===i.mode&&U.brush(n,t),!n.data){U.createData(n,s,i,a);const{transform:t}=n.data,{opacity:e}=i,r=(t&&!t.onlyScale||o.path||o.cornerRadius)&&!n.brush;(r||e&&e<1||i.blendMode)&&(n.complex=!r||2)}return i.filter&&U.applyFilter(n,s,i.filter,t),r}function Mt(t,e){Ft(t,P.LOAD,e)}function Wt(t,e){Ft(t,P.LOADED,e)}function It(t,e,i){e.error=i,t.forceUpdate("surface"),Ft(t,P.ERROR,e)}function Ft(t,e,i){t.hasEvent(e)&&t.emitEvent(new P(e,i))}function zt(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:Yt,translate:Vt}=C,Ut=new x,Xt={},Nt={};function Gt(t,e,i,n){const a=s(t)||n?(n?i-n*e:i%e)/((n||Math.floor(i/e))-1):t;return"auto"===t&&a<0?0:a}let qt={},jt=I();const{get:Ht,set:Qt,rotateOfOuter:$t,translate:Zt,scaleOfOuter:Jt,multiplyParent:Kt,scale:te,rotate:ee,skew:ie}=C;function se(t,e,i,s,n,a,r,o){r&&ee(t,r),o&&ie(t,o.x,o.y),n&&te(t,n,a),Zt(t,e.x+i,e.y+s)}const{get:ne,scale:ae,copy:re}=C,{getFloorScale:oe}=O,{abs:le}=Math;const de={image:function(t,e,i,s,n){let a,r;const o=R.get(i,i.type);return Pt&&i===Pt.paint&&Ot(s,Pt.boxBounds)?a=Pt.leafPaint:(a={type:i.type,image:o},o.hasAlphaPixel&&(a.isTransparent=!0),Pt=o.use>1?{leafPaint:a,paint:i,boxBounds:Ct.set(s)}:null),(n||o.loading)&&(r={image:o,attrName:e,attrValue:i}),o.ready?(Dt(t,e,i,o,a,s),n&&(Mt(t,r),Wt(t,r))):o.error?n&&It(t,r,o.error):(n&&(zt(t,!0),Mt(t,r)),a.loadId=o.load(()=>{zt(t,!1),t.destroyed||(Dt(t,e,i,o,a,s)&&(o.hasAlphaPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Wt(t,r)),a.loadId=void 0},e=>{zt(t,!1),It(t,r,e),a.loadId=void 0},i.lod&&o.getThumbSize(i.lod)),t.placeholderColor&&(t.placeholderDelay?setTimeout(()=>{o.ready||(o.isPlacehold=!0,t.forceUpdate("surface"))},t.placeholderDelay):o.isPlacehold=!0)),a},checkImage:function(t,e,s,n,a){const{scaleX:r,scaleY:o}=U.getImageRenderScaleData(t,s,n,a),l=t.film?t.nowIndex:r+"-"+o,{image:d,brush:c,data:h,originPaint:u}=t,{exporting:f,snapshot:p}=a;if(!h||t.patternId===l&&!f||p){if(!c||!t.style)return!1}else if(e&&(h.repeat?e=!1:u.changeful||t.film||"miniapp"===i.name||f||(e=i.image.isLarge(d,r,o)||d.width*r>8096||d.height*o>8096)),e)s.__.__isFastShadow&&(n.fillStyle=t.style||"#000",n.fill());else if(!t.style||u.sync||f?U.createPattern(t,s,n,a):U.createPatternTask(t,s,n,a),!c||!t.style)return!1;return U.drawImage(t,r,o,s,n,a),!0},drawImage:function(t,e,i,s,n,a){const{data:r,image:o,brush:l,complex:d}=t;let{width:c,height:h}=o,u=l||o;if(d){const{blendMode:a,opacity:o}=t.originPaint,{transform:l}=r;n.save(),2===d&&n.clipUI(s),a&&(n.blendMode=a),o&&(n.opacity*=o),l&&n.transform(l),u.render(n,0,0,c,h,s,t,e,i),n.restore()}else r.scaleX&&(c*=r.scaleX,h*=r.scaleY),u.render(n,0,0,c,h,s,t,e,i)},getImageRenderScaleData:function(t,e,i,s){const n=e.getRenderScaleData(!0,t.originPaint.scaleFixed),{data:a}=t;if(t.brush&&U.addBrushScale(n,t,e),i){const{pixelRatio:t}=i;n.scaleX*=t,n.scaleY*=t}return a&&a.scaleX&&(n.scaleX*=Math.abs(a.scaleX),n.scaleY*=Math.abs(a.scaleY)),n},recycleImage:function(t,e){const i=e["_"+t];if(b(i)){let s,n,a,r,o;const l=e.__leaf;for(let d=0,c=i.length;d<c;d++)s=i[d],n=s.image,o=n&&n.url,o&&(a||(a={}),a[o]=!0,R.recyclePaint(s),s.brush&&U.recycleBrush(s,l),e.__willDestroy&&n.parent&&U.recycleFilter(n,l),n.loading&&(r||(r=e.__input&&e.__input[t]||[],b(r)||(r=[r])),n.unload(i[d].loadId,!r.some(t=>t.url===o))));return a}return null},createPatternTask:function(t,e,i,s){t.patternTask||(t.patternTask=R.patternTasker.add(()=>Q(this,void 0,void 0,function*(){U.createPattern(t,e,i,s),e.forceUpdate("surface")}),0,()=>(t.patternTask=null,i.bounds.hit(e.__nowWorld))))},createPattern:function(t,e,s,n){let{scaleX:a,scaleY:r}=U.getImageRenderScaleData(t,e,s,n),o=t.film?t.nowIndex:a+"-"+r;if(t.patternId!==o&&!e.destroyed&&(!i.image.isLarge(t.image,a,r)||t.data.repeat)){const{image:l,brush:d,data:c}=t,{opacity:h}=t.originPaint,{transform:u,gap:f}=c,p=U.getPatternFixScale(t,a,r);let g,_,w,{width:m,height:y}=l;if(p&&(a*=p,r*=p),m*=a,y*=r,f&&(_=f.x*a/le(c.scaleX||1),w=f.y*r/le(c.scaleY||1),d)){const i=U.getBrushScale(t,e);_/=i,w/=i}(u||1!==a||1!==r)&&(a*=oe(m+(_||0)),r*=oe(y+(w||0)),g=ne(),u&&re(g,u),ae(g,1/a,1/r));const v=l.getCanvas(m,y,h,void 0,_,w,e.leafer&&e.leafer.config.smooth,c.interlace);d?(t.style=v,U.cacheBrush(t,e,s,n)):t.style=l.getPattern(v,c.repeat||i.origin.noRepeat||"no-repeat",g,t),t.patternId=o}},getPatternFixScale:function(t,e,s){const{image:n}=t;let a,r=i.image.maxPatternSize,o=n.width*n.height;return n.isSVG?e>1&&(a=Math.ceil(e)/e):r>o&&(r=o),(o*=e*s)>r&&(a=Math.sqrt(r/o)),a},createData:function(t,e,i,s){t.data=U.getPatternData(i,s,e)},getPatternData:function(t,e,i){t.padding&&(e=Ut.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{width:n,height:a}=i,{mode:r,align:o,offset:l,scale:d,size:c,rotation:h,skew:u,clipSize:f,repeat:p,gap:g,interlace:_}=t,w=e.width===n&&e.height===a,m={mode:r},y="center"!==o&&(h||0)%180==90;let v,x;switch(L.set(Nt,0,0,y?a:n,y?n:a),r&&"cover"!==r&&"fit"!==r?((d||c)&&(O.getScaleData(d,c,i,Xt),v=Xt.scaleX,x=Xt.scaleY),(o||g||p)&&(v&&L.scale(Nt,v,x,!0),o&&D.toPoint(o,Nt,e,Nt,!0,!0))):w&&!h||(v=x=L.getFitScale(e,Nt,"fit"!==r),L.put(e,i,o,v,!1,Nt),L.scale(Nt,v,x,!0)),l&&M.move(Nt,l),r){case"stretch":w?v&&(v=x=void 0):(v=e.width/n,x=e.height/a,U.stretchMode(m,e,v,x));break;case"normal":case"clip":if(Nt.x||Nt.y||v||f||h||u){let t,i;f&&(t=e.width/f.width,i=e.height/f.height),U.clipMode(m,e,Nt.x,Nt.y,v,x,h,u,t,i),t&&(v=v?v*t:t,x=x?x*i:i)}break;case"repeat":case"brush":(!w||v||h||u)&&U.repeatMode(m,e,n,a,Nt.x,Nt.y,v,x,h,u,o,t.freeTransform),p||(m.repeat="repeat");const i=E(p);(g||i)&&(m.gap=function(t,e,i,s,n){let a,r;E(t)?(a=t.x,r=t.y):a=r=t;return{x:Gt(a,i,n.width,e&&e.x),y:Gt(r,s,n.height,e&&e.y)}}(g,i&&p,Nt.width,Nt.height,e));break;default:v&&U.fillOrFitMode(m,e,Nt.x,Nt.y,v,x,h)}return m.transform||(e.x||e.y)&&Vt(m.transform=Yt(),e.x,e.y),v&&(m.scaleX=v,m.scaleY=x),p&&(m.repeat=s(p)?"x"===p?"repeat-x":"repeat-y":"repeat"),_&&(m.interlace=W(_)||"percent"===_.type?{type:"x",offset:_}:_),m},stretchMode:function(t,e,i,s){const n=Ht(),{x:a,y:r}=e;a||r?Zt(n,a,r):i>0&&s>0&&(n.onlyScale=!0),te(n,i,s),t.transform=n},fillOrFitMode:function(t,e,i,s,n,a,r){const o=Ht();Zt(o,e.x+i,e.y+s),te(o,n,a),r&&$t(o,{x:e.x+e.width/2,y:e.y+e.height/2},r),t.transform=o},clipMode:function(t,e,i,s,n,a,r,o,l,d){const c=Ht();se(c,e,i,s,n,a,r,o),l&&(r||o?(Qt(jt),Jt(jt,e,l,d),Kt(c,jt)):Jt(c,e,l,d)),t.transform=c},repeatMode:function(t,e,i,s,n,a,r,o,l,d,c,h){const u=Ht();if(h)se(u,e,n,a,r,o,l,d);else{if(l)if("center"===c)$t(u,{x:i/2,y:s/2},l);else switch(ee(u,l),l){case 90:Zt(u,s,0);break;case 180:Zt(u,i,s);break;case 270:Zt(u,0,i)}qt.x=e.x+n,qt.y=e.y+a,Zt(u,qt.x,qt.y),r&&Jt(u,qt,r,o)}t.transform=u}},{toPoint:ce}=F,{hasTransparent:he}=X,ue={},fe={};function pe(t,e,i,n){if(i){let a,r,o,l;for(let t=0,d=i.length;t<d;t++)a=i[t],s(a)?(o=t/(d-1),r=X.string(a,n)):(o=a.offset,r=X.string(a.color,n)),e.addColorStop(o,r),!l&&he(r)&&(l=!0);l&&(t.isTransparent=!0)}}const{getAngle:ge,getDistance:_e}=M,{get:we,rotateOfOuter:me,scaleOfOuter:ye}=C,{toPoint:ve}=F,xe={},be={};function Se(t,e,i,s,n){let a;const{width:r,height:o}=t;if(r!==o||s){const t=ge(e,i);a=we(),n?(ye(a,e,r/o*(s||1),1),me(a,e,t+90)):(ye(a,e,1,r/o*(s||1)),me(a,e,t))}return a}const{getDistance:ke}=M,{toPoint:Be}=F,Re={},Ee={};const Le={linearGradient:function(t,e){let{from:s,to:n,type:a,opacity:r}=t;ce(s||"top",e,ue),ce(n||"bottom",e,fe);const o=i.canvas.createLinearGradient(ue.x,ue.y,fe.x,fe.y),l={type:a,style:o};return pe(l,o,t.stops,r),l},radialGradient:function(t,e){let{from:s,to:n,type:a,opacity:r,stretch:o}=t;ve(s||"center",e,xe),ve(n||"bottom",e,be);const l=i.canvas.createRadialGradient(xe.x,xe.y,0,xe.x,xe.y,_e(xe,be)),d={type:a,style:l};pe(d,l,t.stops,r);const c=Se(e,xe,be,o,!0);return c&&(d.transform=c),d},conicGradient:function(t,e){let{from:s,to:n,type:a,opacity:r,rotation:o,stretch:l}=t;Be(s||"center",e,Re),Be(n||"bottom",e,Ee);const d=i.conicGradientSupport?i.canvas.createConicGradient(o?o*z:0,Re.x,Re.y):i.canvas.createRadialGradient(Re.x,Re.y,0,Re.x,Re.y,ke(Re,Ee)),c={type:a,style:d};pe(c,d,t.stops,r);const h=Se(e,Re,Ee,l||1,i.conicGradientRotate90);return h&&(c.transform=h),c},getTransform:Se},{copy:Ae,move:Te,toOffsetOutBounds:Pe}=L,{max:Ce,abs:Oe}=Math,De={},Me=new T,We={};function Ie(t,e){let i,s,n,a,r=0,o=0,l=0,d=0;return e.forEach(t=>{i=t.x||0,s=t.y||0,a=1.5*(t.blur||0),n=Oe(t.spread||0),r=Ce(r,n+a-s),o=Ce(o,n+a+i),l=Ce(l,n+a+s),d=Ce(d,n+a-i)}),r===o&&o===l&&l===d?r:[r,o,l,d]}function Fe(t,e,s){const{shapeBounds:n}=s;let a,r;i.fullImageShadow?(Ae(De,t.bounds),Te(De,e.x-n.x,e.y-n.y),a=t.bounds,r=De):(a=n,r=e),t.copyWorld(s.canvas,a,r)}const{toOffsetOutBounds:ze}=L,Ye={};const Ve=Ie;const Ue={shadow:function(t,e,i){let s,n;const{__nowWorld:a}=t,{shadow:r}=t.__,{worldCanvas:o,bounds:l,renderBounds:d,shapeBounds:c,scaleX:h,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Pe(l,We,d),r.forEach((r,g)=>{let _=1;if(r.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.setWorldShadow(We.offsetX+(r.x||0)*h*_,We.offsetY+(r.y||0)*u*_,(r.blur||0)*h*_,X.string(r.color)),n=G.getShadowTransform(t,f,i,r,We,_),n&&f.setTransform(n),Fe(f,We,i),n&&f.resetTransform(),s=d,r.box&&(f.restore(),f.save(),o&&(f.copyWorld(f,d,a,"copy"),s=a),o?f.copyWorld(o,a,a,"destination-out"):f.copyWorld(i.canvas,c,l,"destination-out")),m.copyCanvasByWorld(t,e,f,s,r.blendMode),p&&g<p&&f.clearWorld(s)}),f.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:a}=t,{innerShadow:r}=t.__,{worldCanvas:o,bounds:l,renderBounds:d,shapeBounds:c,scaleX:h,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;ze(l,Ye,d),r.forEach((r,g)=>{let _=1;if(r.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.save(),f.setWorldShadow(Ye.offsetX+(r.x||0)*h*_,Ye.offsetY+(r.y||0)*u*_,(r.blur||0)*h*_),n=G.getShadowTransform(t,f,i,r,Ye,_,!0),n&&f.setTransform(n),Fe(f,Ye,i),f.restore(),o?(f.copyWorld(f,d,a,"copy"),f.copyWorld(o,a,a,"source-out"),s=a):(f.copyWorld(i.canvas,c,l,"source-out"),s=d),f.fillWorld(s,X.string(r.color),"source-in"),m.copyCanvasByWorld(t,e,f,s,r.blendMode),p&&g<p&&f.clearWorld(s)}),f.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){},getShadowRenderSpread:Ie,getShadowTransform:function(t,e,i,s,n,a,r){if(s.spread){const i=2*s.spread*a*(r?-1:1),{width:o,height:l}=t.__layout.strokeBounds;return Me.set().scaleOfOuter({x:(n.x+n.width/2)*e.pixelRatio,y:(n.y+n.height/2)*e.pixelRatio},1+i/o,1+i/l),Me}},isTransformShadow(t){},getInnerShadowSpread:Ve},{excludeRenderBounds:Xe}=v;let Ne;function Ge(t,e,i,s,n,a,r,o){switch(e){case"grayscale":Ne||(Ne=!0,n.useGrayscaleAlpha(t.__nowWorld));case"alpha":!function(t,e,i,s,n,a){const r=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,r),a&&s.recycle(r);je(t,e,i,1,n,a)}(t,i,s,n,r,o);break;case"opacity-path":je(t,i,s,a,r,o);break;case"path":o&&i.restore()}}function qe(t){return t.getSameCanvas(!1,!0)}function je(t,e,i,s,n,a){const r=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,r,void 0,n),a?i.recycle(r):i.clearWorld(r)}q.prototype.__renderMask=function(t,e){let i,s,n,a,r,o;const{children:l}=this;for(let d=0,c=l.length;d<c;d++){if(i=l[d],o=i.__.mask,o){r&&(Ge(this,r,t,n,s,a,void 0,!0),s=n=null),"clipping"!==o&&"clipping-path"!==o||Xe(i,e)||i.__render(t,e),a=i.__.opacity,Ne=!1,"path"===o||"clipping-path"===o?(a<1?(r="opacity-path",n||(n=qe(t))):(r="path",t.save()),i.__clip(n||t,e)):(r="grayscale"===o?"grayscale":"alpha",s||(s=qe(t)),n||(n=qe(t)),i.__render(s,e));continue}const c=1===a&&i.__.__blendMode;c&&Ge(this,r,t,n,s,a,void 0,!1),Xe(i,e)||i.__render(n||t,e),c&&Ge(this,r,t,n,s,a,c,!1)}Ge(this,r,t,n,s,a,void 0,!0)};const He=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Qe=He+"_#~&*+\\=|≮≯≈≠=…",$e=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map(([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`).join("|"));function Ze(t){const e={};return t.split("").forEach(t=>e[t]=!0),e}const Je=Ze("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ke=Ze("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ti=Ze(He),ei=Ze(Qe),ii=Ze("- —/~|┆·");var si;!function(t){t[t.Letter=0]="Letter",t[t.Single=1]="Single",t[t.Before=2]="Before",t[t.After=3]="After",t[t.Symbol=4]="Symbol",t[t.Break=5]="Break"}(si||(si={}));const{Letter:ni,Single:ai,Before:ri,After:oi,Symbol:li,Break:di}=si;function ci(t){return Je[t]?ni:ii[t]?di:Ke[t]?ri:ti[t]?oi:ei[t]?li:$e.test(t)?ai:ni}const hi={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let a=n-1;a>-1&&(i=e[a].data[0]," "===i.char);a--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function ui(t,e,i){switch(e){case"title":return i?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:fi}=hi,{Letter:pi,Single:gi,Before:_i,After:wi,Symbol:mi,Break:yi}=si;let vi,xi,bi,Si,ki,Bi,Ri,Ei,Li,Ai,Ti,Pi,Ci,Oi,Di,Mi,Wi,Ii=[];function Fi(t,e){Li&&!Ei&&(Ei=Li),vi.data.push({char:t,width:e}),bi+=e}function zi(){Si+=bi,vi.width=bi,xi.words.push(vi),vi={data:[]},bi=0}function Yi(){Oi&&(Di.paraNumber++,xi.paraStart=!0,Oi=!1),Li&&(xi.startCharSize=Ei,xi.endCharSize=Li,Ei=0),xi.width=Si,Mi.width?fi(xi):Wi&&Vi(),Ii.push(xi),xi={words:[]},Si=0}function Vi(){Si>(Di.maxWidth||0)&&(Di.maxWidth=Si)}const{top:Ui,right:Xi,bottom:Ni,left:Gi}=Y;function qi(t,e,i){const{bounds:s,rows:n}=t;s[e]+=i;for(let t=0;t<n.length;t++)n[t][e]+=i}const ji={getDrawData:function(t,e){s(t)||(t=String(t));let n=0,a=0,r=e.__getInput("width")||0,o=e.__getInput("height")||0;const{__padding:l}=e;l&&(r?(n=l[Gi],r-=l[Xi]+l[Gi],!r&&(r=.01)):e.autoSizeAlign||(n=l[Gi]),o?(a=l[Ui],o-=l[Ui]+l[Ni],!o&&(o=.01)):e.autoSizeAlign||(a=l[Ui]));const d={bounds:{x:n,y:a,width:r,height:o},rows:[],paraNumber:0,font:i.canvas.font=e.__font};return function(t,e,s){Di=t,Ii=t.rows,Mi=t.bounds,Wi=!Mi.width&&!s.autoSizeAlign;const{__letterSpacing:n,paraIndent:a,textCase:r}=s,{canvas:o}=i,{width:l}=Mi;if(s.__isCharMode){const t="none"!==s.textWrap,i="break"===s.textWrap;Oi=!0,Ti=null,Ei=Ri=Li=bi=Si=0,vi={data:[]},xi={words:[]};for(let s=0,d=(e=[...e]).length;s<d;s++)Bi=e[s],"\n"===Bi?(bi&&zi(),xi.paraEnd=!0,Yi(),Oi=!0):(Ai=ci(Bi),Ai===pi&&"none"!==r&&(Bi=ui(Bi,r,!bi)),Ri=o.measureText(Bi).width,n&&(n<0&&(Li=Ri),Ri+=n),Pi=Ai===gi&&(Ti===gi||Ti===pi)||Ti===gi&&Ai!==wi,Ci=!(Ai!==_i&&Ai!==gi||Ti!==mi&&Ti!==wi),ki=Oi&&a?l-a:l,t&&l&&Si+bi+Ri>ki&&(i?(bi&&zi(),Si&&Yi()):(Ci||(Ci=Ai===pi&&Ti==wi),Pi||Ci||Ai===yi||Ai===_i||Ai===gi||bi+Ri>ki?(bi&&zi(),Si&&Yi()):Si&&Yi()))," "===Bi&&!0!==Oi&&Si+bi===0||(Ai===yi?(" "===Bi&&bi&&zi(),Fi(Bi,Ri),zi()):Pi||Ci?(bi&&zi(),Fi(Bi,Ri)):Fi(Bi,Ri)),Ti=Ai);bi&&zi(),Si&&Yi(),Ii.length>0&&(Ii[Ii.length-1].paraEnd=!0)}else e.split("\n").forEach(t=>{Di.paraNumber++,Si=o.measureText(t).width,Ii.push({x:a||0,text:t,width:Si,paraStart:!0}),Wi&&Vi()})}(d,t,e),l&&function(t,e,i,s,n){if(!s&&i.autoSizeAlign)switch(i.textAlign){case"left":qi(e,"x",t[Gi]);break;case"right":qi(e,"x",-t[Xi])}if(!n&&i.autoSizeAlign)switch(i.verticalAlign){case"top":qi(e,"y",t[Ui]);break;case"bottom":qi(e,"y",-t[Ni])}}(l,d,e,r,o),function(t,e){const{rows:i,bounds:s}=t,n=i.length,{__lineHeight:a,__baseLine:r,__letterSpacing:o,__clipText:l,textAlign:d,verticalAlign:c,paraSpacing:h,autoSizeAlign:u}=e;let{x:f,y:p,width:g,height:_}=s,w=a*n+(h?h*(t.paraNumber-1):0),m=r;if(l&&w>_)w=Math.max(e.__autoHeight?w:_,a),n>1&&(t.overflow=n);else if(_||u)switch(c){case"middle":p+=(_-w)/2;break;case"bottom":p+=_-w}m+=p;let y,v,x,b=g||u?g:t.maxWidth;for(let r=0,c=n;r<c;r++){if(y=i[r],y.x=f,y.width<g||y.width>g&&!l)switch(d){case"center":y.x+=(b-y.width)/2;break;case"right":y.x+=b-y.width}y.paraStart&&h&&r>0&&(m+=h),y.y=m,m+=a,t.overflow>r&&m>w&&(y.isOverflow=!0,t.overflow=r+1),v=y.x,x=y.width,o<0&&(y.width<0?(x=-y.width+e.fontSize+o,v-=x,x+=e.fontSize):x-=o),v<s.x&&(s.x=v),x>s.width&&(s.width=x),l&&g&&g<x&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=w}(d,e),e.__isCharMode&&function(t,e,i){const{rows:s}=t,{textAlign:n,paraIndent:a,__letterSpacing:r}=e,o=i&&n.includes("both"),l=o||i&&n.includes("justify"),d=l&&n.includes("letter");let c,h,u,f,p,g,_,w,m,y;s.forEach(t=>{t.words&&(p=a&&t.paraStart?a:0,w=t.words.length,l&&(y=!t.paraEnd||o,h=i-t.width-p,d?f=h/(t.words.reduce((t,e)=>t+e.data.length,0)-1):u=w>1?h/(w-1):0),g=r||t.isOverflow||d?0:u?1:2,t.isOverflow&&!r&&(t.textMode=!0),2===g?(t.x+=p,function(t){t.text="",t.words.forEach(e=>{e.data.forEach(e=>{t.text+=e.char})})}(t)):(t.x+=p,c=t.x,t.data=[],t.words.forEach((e,i)=>{1===g?(_={char:"",x:c},c=function(t,e,i){return t.forEach(t=>{i.char+=t.char,e+=t.width}),e}(e.data,c,_),(t.isOverflow||" "!==_.char)&&t.data.push(_)):c=function(t,e,i,s,n){return t.forEach(t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width,n&&(e+=n)}),e}(e.data,c,t.data,t.isOverflow,y&&f),y&&(m=i===w-1,u?m||(c+=u,t.width+=u):f&&(t.width+=f*(e.data.length-(m?1:0))))})),t.words=null)})}(d,e,r),d.overflow&&function(t,e,s,n){const{rows:a,overflow:r}=t;let{textOverflow:o}=e;if(r&&a.splice(r),n&&o&&"show"!==o){let t,l;"hide"===o?o="":"ellipsis"===o&&(o="...");const d=o?i.canvas.measureText(o).width:0,c=s+n-d;("none"===e.textWrap?a:[a[r-1]]).forEach(e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],l=t.x+t.width,!(s===i&&l<c));s--){if(l<c&&" "!==t.char||!s){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=d,e.data.push({char:o,x:l}),e.textMode&&function(t){t.text="",t.data.forEach(e=>{t.text+=e.char}),t.data=null}(e)}})}}(d,e,n,r),"none"!==e.textDecoration&&function(t,e){let i,s=0;const{fontSize:n,textDecoration:a}=e;switch(t.decorationHeight=n/11,E(a)?(i=a.type,a.color&&(t.decorationColor=X.string(a.color)),a.offset&&(s=Math.min(.3*n,Math.max(a.offset,.15*-n)))):i=a,i){case"under":t.decorationY=[.15*n+s];break;case"delete":t.decorationY=[.35*-n];break;case"under-delete":t.decorationY=[.15*n+s,.35*-n]}}(d,e),d}};const Hi={string:function(t,e){if(!t)return"#000";const i=W(e)&&e<1;if(s(t)){if(!i||!X.object)return t;t=X.object(t)}let n=r(t.a)?1:t.a;i&&(n*=e);const a=t.r+","+t.g+","+t.b;return 1===n?"rgb("+a+")":"rgba("+a+","+n+")"}};Object.assign(j,ji),Object.assign(X,Hi),Object.assign(V,Tt),Object.assign(U,de),Object.assign(N,Le),Object.assign(G,Ue),J();export{ht as Layouter,Z as LeaferCanvas,H as PathNodeHandleType,ft as Renderer,tt as Watcher,J as useCanvas}; //# sourceMappingURL=web.esm.min.js.map