@leafer-ui/worker 1.0.0-beta.12 → 1.0.0-beta.15

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.
@@ -0,0 +1 @@
1
+ import{LeafList as t,DataHelper as e,RenderEvent as s,ChildEvent as i,WatchEvent as n,PropertyEvent as r,LeafHelper as a,BranchHelper as o,Bounds as d,LeafBoundsHelper as h,BoundsHelper as l,Debug as c,LeafLevelList as u,LayoutEvent as f,Run as _,ImageManager as g,Platform as p,AnimateEvent as w,ResizeEvent as y,Creator as m,LeaferCanvasBase as v,canvasPatch as x,LeaferImage as b,InteractionBase as B,FileHelper as R,MatrixHelper as L,ImageEvent as E,PointHelper as k,MathHelper as S,TaskProcessor as A}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{ColorConvert as O,Paint as C,Effect as M,TextConvert as T,Export as W}from"@leafer-ui/core";export*from"@leafer-ui/core";class I{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const e=new t;return this.__updatedList.list.forEach((t=>{t.leafer&&e.push(t)})),e}return this.__updatedList}constructor(s,i){this.totalTimes=0,this.config={},this.__updatedList=new t,this.target=s,i&&(this.config=e.default(i,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(s.REQUEST)}__onAttrChange(t){this.__updatedList.push(t.target),this.update()}__onChildEvent(t){t.type===i.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.push(t.parent)),this.update()}__pushChild(t){this.__updatedList.push(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,s=e.length;t<s;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new n(n.DATA,{updatedList:this.updatedList})),this.__updatedList=new t,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(r.CHANGE,this.__onAttrChange,this),t.on_([i.ADD,i.REMOVE],this.__onChildEvent,this),t.on_(n.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllWorldMatrix:D,updateAllWorldOpacity:P}=a,{pushAllChildBranch:F,pushAllParent:N}=o;const{worldBounds:Y}=h,{setByListWithHandle:U}=l;class H{constructor(e){this.updatedBounds=new d,this.beforeBounds=new d,this.afterBounds=new d,e instanceof Array&&(e=new t(e)),this.updatedList=e}setBefore(){U(this.beforeBounds,this.updatedList.list,Y)}setAfter(){U(this.afterBounds,this.updatedList.list,Y),this.updatedBounds.setByList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.pushList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllWorldMatrix:V,updateAllChange:G}=a,{pushAllBranchStack:j,updateWorldBoundsByBranchStack:q}=o,X=c.get("Layouter");class z{constructor(t,s){this.totalTimes=0,this.config={},this.__levelList=new u,this.target=t,s&&(this.config=e.default(s,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.running)return;const{target:t}=this;this.times=0;try{t.emit(f.START),this.layoutOnce(),t.emitEvent(new f(f.END,this.layoutedBlocks,this.times))}catch(t){X.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?X.warn("layouting"):this.times>3?X.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(n.REQUEST),this.totalTimes>1?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=_.start("PartLayout"),{target:s,__updatedList:i}=this,{BEFORE:n,LAYOUT:r,AFTER:a}=f,o=this.getBlocks(i);o.forEach((t=>{t.setBefore()})),s.emitEvent(new f(n,o,this.times)),i.sort(),function(t,e){let s;t.list.forEach((t=>{s=t.__layout,e.without(t)&&!s.useZoomProxy&&(s.matrixChanged?(D(t),e.push(t),t.isBranch&&F(t,e),N(t,e)):s.boundsChanged&&(e.push(t),t.isBranch&&(t.__tempNumber=0),N(t,e)))}))}(i,this.__levelList),function(t){let e,s;t.sort(!0),t.levels.forEach((i=>{e=t.levelMap[i];for(let t=0,i=e.length;t<i;t++){if(s=e[t],s.isBranch&&s.__tempNumber)for(let t=0,e=s.children.length;t<e;t++)s.children[t].isBranch||s.children[t].__updateWorldBounds();s.__updateWorldBounds()}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&P(t),t.__updateChange()}))}(i),o.forEach((t=>t.setAfter())),s.emitEvent(new f(r,o,this.times)),s.emitEvent(new f(a,o,this.times)),this.addBlocks(o),this.__levelList.reset(),this.__updatedList=null,_.end(e)}fullLayout(){const e=_.start("FullLayout"),{target:s}=this,{BEFORE:i,LAYOUT:n,AFTER:r}=f,a=this.getBlocks(new t(s));s.emitEvent(new f(i,a,this.times)),z.fullLayout(s),a.forEach((t=>{t.setAfter()})),s.emitEvent(new f(n,a,this.times)),s.emitEvent(new f(r,a,this.times)),this.addBlocks(a),_.end(e)}static fullLayout(t){if(V(t),t.isBranch){const e=[t];j(t,e),q(e)}else t.__updateWorldBounds();G(t)}createBlock(t){return new H(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(){const{target:t}=this;this.__eventIds=[t.on_(f.REQUEST,this.layout,this),t.on_(f.AGAIN,this.layoutAgain,this),t.on_(n.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.config=null)}}const Q=c.get("Renderer");class Z{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,s,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=s,i&&(this.config=e.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(f.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new d,Q.log(e.innerName,"---\x3e");try{this.emitRender(s.START),this.renderOnce(t),this.emitRender(s.END,this.totalBounds),g.clearRecycled()}catch(t){this.rendering=!1,Q.error(t)}Q.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){return this.rendering?Q.warn("rendering"):this.times>3?Q.warn("render max times"):(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new d,this.renderOptions={},t?(this.emitRender(s.BEFORE),t()):(this.requestLayout(),this.emitRender(s.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()),this.emitRender(s.RENDER,this.renderBounds,this.renderOptions),this.emitRender(s.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,void(this.waitAgain&&(this.waitAgain=!1,this.renderOnce())))}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return Q.warn("PartRender: need update attr");e.some((t=>t.includes(this.target.__world)))&&this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=_.start("PartRender"),{canvas:s}=this,i=t.getIntersect(s.bounds),n=t.includes(this.target.__world),r=(new d).copy(i);s.save(),n&&!c.showRepaint?s.clear():(i.spread(1+1/this.canvas.pixelRatio).ceil(),s.clearWorld(i,!0),s.clipWorld(i,!0)),this.__render(i,r),s.restore(),_.end(e)}fullRender(){const t=_.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds),e.restore(),_.end(t)}__render(t,e){const s=(null==t?void 0:t.includes(this.target.__world))?{}:{bounds:t};this.needFill&&this.canvas.fillWorld(t,this.config.fill),c.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,s),this.renderBounds=e||t,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),c.showHitView&&this.renderHitView(s),c.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender()}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new d;e.setByList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();p.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.changed&&this.running&&this.canvas.view&&this.render(),this.running&&this.target.emit(w.FRAME),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:s}=t.old;new d(0,0,e,s).includes(this.target.__world)&&!this.needFill&&t.samePixelRatio||(this.addBlock(this.canvas.bounds),this.target.forceUpdate("blendMode"))}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||Q.warn(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new s(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(s.REQUEST,this.update,this),t.on_(f.END,this.__onLayoutEnd,this),t.on_(s.AGAIN,this.renderAgain,this),t.on_(y.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.canvas=null,this.config=null)}}const{hitRadiusPoint:K}=l;class ${constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,s){e||(e=0),s||(s={});const i=s.through||!1,n=s.ignoreHittable||!1;this.exclude=s.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=[],this.eachFind(this.target.children,this.target.__onlyHitMask);const r=this.findList,a=this.getBestMatchLeaf(),o=n?this.getPath(a):this.getHitablePath(a);return this.clear(),i?{path:o,leaf:a,throughPath:r.length?this.getThroughPath(r):o}:{path:o,leaf:a}}getBestMatchLeaf(){const{findList:t}=this;if(t.length>1){let e;this.findList=[];const{x:s,y:i}=this.point,n={x:s,y:i,radiusX:0,radiusY:0};for(let s=0,i=t.length;s<i;s++)if(e=t[s],a.worldHittable(e)&&(this.hitChild(e,n),this.findList.length))return this.findList[0]}return t[0]}getPath(e){const s=new t;for(;e;)s.push(e),e=e.parent;return s.push(this.target),s}getHitablePath(e){const s=this.getPath(e);let i,n=new t;for(let t=s.list.length-1;t>-1&&(i=s.list[t],i.__.hittable)&&(n.unshift(i),i.__.hitChildren);t--);return n}getThroughPath(e){const s=new t,i=[];for(let t=e.length-1;t>-1;t--)i.push(this.getPath(e[t]));let n,r,a;for(let t=0,e=i.length;t<e;t++){n=i[t],r=i[t+1];for(let t=0,e=n.length;t<e&&(a=n.list[t],!r||!r.has(a));t++)s.push(a)}return s}eachFind(t,e){let s,i;const{point:n}=this;for(let r=t.length-1;r>-1;r--)s=t[r],!s.__.visible||e&&!s.__.isMask||(i=!!s.__.hitRadius||K(s.__world,n),s.isBranch?(i||s.__ignoreHitWorld)&&(this.eachFind(s.children,s.__onlyHitMask),s.isBranchLeaf&&!this.findList.length&&this.hitChild(s,n)):i&&this.hitChild(s,n))}hitChild(t,e){this.exclude&&this.exclude.has(t)||t.__hitWorld(e)&&this.findList.push(t)}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}class J{constructor(t,s){this.config={},this.innerIdList={},this.idList={},this.classNameList={},this.tagNameList={},this.target=t,s&&(this.config=e.default(s,this.config)),this.findPath=new $(t,this),this.__listenEvents()}getByPoint(t,e,s){return"node"===p.name&&this.target.emit(f.CHECK_UPDATE),this.findPath.getByPoint(t,e,s)}find(t,e){return"number"==typeof t?this.getByInnerId(t,e):t.startsWith("#")?this.getById(t.substring(1),e):t.startsWith(".")?this.getByClassName(t.substring(1),e):this.getByTagName(t,e)}getByInnerId(t,e){let s,i=this.innerIdList[t];return i||(e||(e=this.target),this.loopFind(e,(e=>e.innerId===t&&(s=e,this.innerIdList[t]=s,!0))),s)}getById(t,e){let s,i=this.idList[t];return i||(e||(e=this.target),this.loopFind(e,(e=>e.id===t&&(s=e,this.idList[t]=s,!0))),s)}getByClassName(t,e){e||(e=this.target);let s=[];return this.loopFind(e,(e=>(e.className===t&&s.push(e),!1))),s}getByTagName(t,e){e||(e=this.target);let s=[];return this.loopFind(e,(e=>(e.__tag===t&&s.push(e),!1))),s}loopFind(t,e){if(e(t))return;const{children:s}=t;for(let i=0,n=s.length;i<n;i++){if(e(t=s[i]))return;t.isBranch&&this.loopFind(t,e)}}__onRemoveChild(t){const e=t.target;this.idList[e.id]&&(this.idList[e.id]=null),this.innerIdList[e.id]&&(this.innerIdList[e.innerId]=null)}__listenEvents(){this.__eventIds=[this.target.on_(i.REMOVE,this.__onRemoveChild,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.findPath.destroy(),this.innerIdList={},this.idList={},this.classNameList={},this.tagNameList={})}}Object.assign(m,{watcher:(t,e)=>new I(t,e),layouter:(t,e)=>new z(t,e),renderer:(t,e,s)=>new Z(t,e,s),selector:(t,e)=>new J(t,e)}),p.layout=z.fullLayout;class tt extends v{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config)}__createView(){this.view=p.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:s}=this;this.view.width=t*s,this.view.height=e*s,this.clientBounds=this.bounds}}x(OffscreenCanvasRenderingContext2D.prototype),x(Path2D.prototype);const{mineType:et}=R;function st(t,e){p.origin={createCanvas:(t,e)=>new OffscreenCanvas(t,e),canvasToDataURL:(t,e,s)=>new Promise(((i,n)=>{t.convertToBlob({type:et(e),quality:s}).then((t=>{var e=new FileReader;e.onload=t=>i(t.target.result),e.onerror=t=>n(t),e.readAsDataURL(t)})).catch((t=>{n(t)}))})),canvasToBolb:(t,e,s)=>t.convertToBlob({type:et(e),quality:s}),canvasSaveAs:(t,e,s)=>new Promise((t=>t())),loadImage:t=>new Promise(((e,s)=>{!t.startsWith("data:")&&p.imageSuffix&&(t+=(t.includes("?")?"&":"?")+p.imageSuffix);let i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="blob",i.onload=()=>{createImageBitmap(i.response).then((t=>{e(t)})).catch((t=>{s(t)}))},i.onerror=t=>s(t),i.send()}))},p.canvas=m.canvas(),p.conicGradientSupport=!!p.canvas.context.createConicGradient}Object.assign(m,{canvas:(t,e)=>new tt(t,e),image:t=>new b(t),hitCanvas:(t,e)=>new tt(t,e),interaction:(t,e,s,i)=>new B(t,e,s,i)}),p.name="web",p.isWorker=!0,p.requestRender=function(t){requestAnimationFrame(t)},p.devicePixelRatio=1,p.realtimeLayout=!0;const{userAgent:it}=navigator;it.indexOf("Firefox")>-1?(p.conicGradientRotate90=!0,p.intWheelDeltaY=!0):it.indexOf("Safari")>-1&&-1===it.indexOf("Chrome")&&(p.fullImageShadow=!0),it.indexOf("Windows")>-1?(p.os="Windows",p.intWheelDeltaY=!0):it.indexOf("Mac")>-1?p.os="Mac":it.indexOf("Linux")>-1&&(p.os="Linux");const{get:nt,rotateOfOuter:rt,translate:at,scaleOfOuter:ot,scale:dt,rotate:ht}=L;const{get:lt,translate:ct}=L;function ut(t,e,s,i){let{width:n,height:r}=e;const{opacity:a,mode:o,offset:d,scale:h,rotation:l,blendMode:c}=s,u=i.width===n&&i.height===r;c&&(t.blendMode=c);const f=t.data={mode:o};switch(o){case"strench":u||(n=i.width,r=i.height),(i.x||i.y)&&(f.transform=lt(),ct(f.transform,i.x,i.y));break;case"clip":(d||h||l)&&function(t,e,s,i,n){const r=nt();at(r,e.x,e.y),s&&at(r,s.x,s.y),i&&("number"==typeof i?dt(r,i):dt(r,i.x,i.y),t.scaleX=r.a,t.scaleY=r.d),n&&ht(r,n),t.transform=r}(f,i,d,h,l);break;case"repeat":(!u||h||l)&&function(t,e,s,i,n,r){const a=nt();if(r)switch(ht(a,r),r){case 90:at(a,i,0);break;case 180:at(a,s,i);break;case 270:at(a,0,s)}at(a,e.x,e.y),n&&(ot(a,e,n),t.scaleX=t.scaleY=n),t.transform=a}(f,i,n,r,h,l);break;default:u&&!l||function(t,e,s,i,n,r){const a=nt(),o=r&&180!==r,d=s.width/(o?n:i),h=s.height/(o?i:n),l="fit"===e?Math.min(d,h):Math.max(d,h),c=s.x+(s.width-i*l)/2,u=s.y+(s.height-n*l)/2;at(a,c,u),dt(a,l),r&&rt(a,{x:s.x+s.width/2,y:s.y+s.height/2},r),t.scaleX=t.scaleY=l,t.transform=a}(f,o,i,n,r,l)}f.width=n,f.height=r,a&&(f.opacity=a)}function ft(t,e,s){if("fill"===e&&!t.__.__naturalWidth){const{__:e}=t;if(e.__naturalWidth=s.width,e.__naturalHeight=s.height,!e.__getInput("width")||!e.__getInput("height"))return t.forceUpdate("width"),!1}return!0}function _t(t,e){e.target.hasEvent(t)&&e.target.emitEvent(new E(t,e))}function gt(t,e,s,i){return new(s||(s=Promise))((function(n,r){function a(t){try{d(i.next(t))}catch(t){r(t)}}function o(t){try{d(i.throw(t))}catch(t){r(t)}}function d(t){var e;t.done?n(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(a,o)}d((i=i.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{get:pt,scale:wt,copy:yt}=L;function mt(t,e,s){let{scaleX:i,scaleY:n}=t.__world;const r=i+"-"+n;if(e.patternId===r||t.destroyed)return!1;{e.patternId=r,i=Math.abs(i),n=Math.abs(n);const{image:t,data:a}=e,o=t.isSVG?4096:Math.min(t.width,4096),d=t.isSVG?4096:Math.min(t.height,4096);let h,l,{width:c,height:u,scaleX:f,scaleY:_,opacity:g,transform:w,mode:y}=a;f&&(l=pt(),yt(l,w),wt(l,1/f,1/_),i*=f,n*=_),i*=s,n*=s,c*=i,u*=n,(c>o||u>d)&&(h=Math.max(c/o,u/d)),h&&(i/=h,n/=h,c/=h,u/=h),f&&(i/=f,n/=_),(w||1!==i||1!==n)&&(l||(l=pt(),w&&yt(l,w)),wt(l,1/i,1/n));const m=p.canvas.createPattern(t.getCanvas(c<1?1:c,u<1?1:u,g),"repeat"===y?"repeat":p.origin.noRepeat||"no-repeat");try{e.transform&&(e.transform=null),l&&(m.setTransform?m.setTransform(l):e.transform=l)}catch(t){e.transform=l}return e.style=m,!0}}function vt(t,e,s,i){const{scaleX:n,scaleY:r}=t.__world;if(s.data&&s.patternId!==n+"-"+r){if(i)if(s.image.isSVG&&"repeat"!==s.data.mode){let{width:t,height:a}=s.data;t*=n*e.pixelRatio,a*=r*e.pixelRatio,i=t>4096||a>4096}else i=!1;if(i){e.save(),e.clip();const{data:t}=s;return s.blendMode&&(e.blendMode=s.blendMode),t.opacity&&(e.opacity*=t.opacity),t.transform&&e.transform(t.transform),e.drawImage(s.image.view,0,0,t.width,t.height),e.restore(),!0}return s.style?g.patternTasker.add((()=>gt(this,void 0,void 0,(function*(){e.bounds.hit(t.__world)&&mt(t,s,e.pixelRatio)&&t.forceUpdate("surface")}))),300):mt(t,s,e.pixelRatio),!1}return!1}function xt(t,e){const s="fill"===e?t._fill:t._stroke;if(s instanceof Array){let i,n,r,a;for(let o=0,d=s.length;o<d;o++)i=s[o].image,a=i&&i.url,a&&(n||(n={}),n[a]=!0,g.recycle(i),i.loading&&(r||(r=t.__input&&t.__input[e]||[],r instanceof Array||(r=[r])),i.unload(s[o].loadId,!r.some((t=>t.url===a)))));return n}return null}function bt(t,e){let s;const{rows:i,decorationY:n,decorationHeight:r}=t.__.__textDrawData;for(let t=0,a=i.length;t<a;t++)s=i[t],s.text?e.fillText(s.text,s.x,s.y):s.data&&s.data.forEach((t=>{e.fillText(t.char,t.x,s.y)})),n&&e.fillRect(s.x,s.y+n,s.width,r)}function Bt(t,e,s){const{strokeAlign:i}=t.__,n="string"!=typeof s;switch(i){case"center":e.setStroke(n?void 0:s,t.__.strokeWidth,t.__),n?Et(t,s,e,!0):Lt(t,e);break;case"inside":Rt(t,e,s,"inside",n);break;case"outside":Rt(t,e,s,"outside",n)}}function Rt(t,e,s,i,n){const{strokeWidth:r,__font:a}=t.__,o=e.getSameCanvas(!0);o.setStroke(n?void 0:s,2*r,t.__),o.font=a,n?Et(t,s,o,!0):Lt(t,o),o.blendMode="outside"===i?"destination-out":"destination-in",bt(t,o),o.blendMode="normal",e.copyWorldToInner(o,t.__world,t.__layout.renderBounds),o.recycle()}function Lt(t,e){let s;const{rows:i,decorationY:n,decorationHeight:r}=t.__.__textDrawData;for(let t=0,a=i.length;t<a;t++)s=i[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)})),n&&e.strokeRect(s.x,s.y+n,s.width,r)}function Et(t,e,s,i){let n;for(let r=0,a=e.length;r<a;r++)n=e[r],n.image&&vt(t,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),i?Lt(t,s):s.stroke(),s.restoreBlendMode()):i?Lt(t,s):s.stroke())}const{getSpread:kt,getOuterOf:St,getByMove:At,getIntersectData:Ot}=l;const Ct={x:.5,y:0},Mt={x:.5,y:1};function Tt(t,e,s){let i;for(let n=0,r=e.length;n<r;n++)i=e[n],t.addColorStop(i.offset,O.string(i.color,s))}const{set:Wt,getAngle:It,getDistance:Dt}=k,{get:Pt,rotateOfOuter:Ft,scaleOfOuter:Nt}=L,Yt={x:.5,y:.5},Ut={x:.5,y:1},Ht={},Vt={};const{set:Gt,getAngle:jt,getDistance:qt}=k,{get:Xt,rotateOfOuter:zt,scaleOfOuter:Qt}=L,Zt={x:.5,y:.5},Kt={x:.5,y:1},$t={},Jt={};let te;function ee(t,e,s){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:i}=t.__layout;switch(e.type){case"solid":let{type:n,blendMode:r,color:a,opacity:o}=e;return{type:n,blendMode:r,style:O.string(a,o)};case"image":return function(t,e,s,i,n){const r={type:s.type},a=r.image=g.get(s),o=(n||a.loading)&&{target:t,image:a,attrName:e,attrValue:s};return a.ready?(ft(t,e,a)&&ut(r,a,s,i),n&&(_t(E.LOAD,o),_t(E.LOADED,o))):a.error?n&&(t.forceUpdate("surface"),o.error=a.error,_t(E.ERROR,o)):(n&&_t(E.LOAD,o),r.loadId=a.load((()=>{t.destroyed||(ft(t,e,a)&&(ut(r,a,s,i),t.forceUpdate("surface")),_t(E.LOADED,o))}),(e=>{t.forceUpdate("surface"),o.error=e,_t(E.ERROR,o)}))),r}(t,s,e,i,!te||!te[e.url]);case"linear":return function(t,e){let{from:s,to:i,type:n,blendMode:r,opacity:a}=t;s||(s=Ct),i||(i=Mt);const o=p.canvas.createLinearGradient(e.x+s.x*e.width,e.y+s.y*e.height,e.x+i.x*e.width,e.y+i.y*e.height);Tt(o,t.stops,a);const d={type:n,style:o};return r&&(d.blendMode=r),d}(e,i);case"radial":return function(t,e){let{from:s,to:i,type:n,opacity:r,blendMode:a,stretch:o}=t;s||(s=Yt),i||(i=Ut);const{x:d,y:h,width:l,height:c}=e;let u;Wt(Ht,d+s.x*l,h+s.y*c),Wt(Vt,d+i.x*l,h+i.y*c),(l!==c||o)&&(u=Pt(),Nt(u,Ht,l/c*(o||1),1),Ft(u,Ht,It(Ht,Vt)+90));const f=p.canvas.createRadialGradient(Ht.x,Ht.y,0,Ht.x,Ht.y,Dt(Ht,Vt));Tt(f,t.stops,r);const _={type:n,style:f,transform:u};return a&&(_.blendMode=a),_}(e,i);case"angular":return function(t,e){let{from:s,to:i,type:n,opacity:r,blendMode:a,stretch:o}=t;s||(s=Zt),i||(i=Kt);const{x:d,y:h,width:l,height:c}=e;Gt($t,d+s.x*l,h+s.y*c),Gt(Jt,d+i.x*l,h+i.y*c);const u=Xt(),f=jt($t,Jt);p.conicGradientRotate90?(Qt(u,$t,l/c*(o||1),1),zt(u,$t,f+90)):(Qt(u,$t,1,l/c*(o||1)),zt(u,$t,f));const _=p.conicGradientSupport?p.canvas.createConicGradient(0,$t.x,$t.y):p.canvas.createRadialGradient($t.x,$t.y,0,$t.x,$t.y,qt($t,Jt));Tt(_,t.stops,r);const g={type:n,style:_,transform:u};return a&&(g.blendMode=a),g}(e,i);default:return e.r?{type:"solid",style:O.string(e)}:void 0}}var se=Object.freeze({__proto__:null,compute:function(t,e){const s=[];let i,n=t.__.__input[e];n instanceof Array||(n=[n]),te=xt(t.__,e);for(let r=0,a=n.length;r<a;r++)i=ee(t,n[r],e),i&&s.push(i);t.__["_"+e]=s.length?s:void 0},drawTextStroke:Lt,fill:function(t,e,s){e.fillStyle=s,t.__.__font?bt(t,e):t.__.windingRule?e.fill(t.__.windingRule):e.fill()},fillText:bt,fills:function(t,e,s){let i;const{windingRule:n,__font:r}=t.__;for(let a=0,o=s.length;a<o;a++)i=s[a],i.image&&vt(t,e,i,!r)||i.style&&(e.fillStyle=i.style,i.transform?(e.save(),e.transform(i.transform),i.blendMode&&(e.blendMode=i.blendMode),r?bt(t,e):n?e.fill(n):e.fill(),e.restore()):i.blendMode?(e.saveBlendMode(i.blendMode),r?bt(t,e):n?e.fill(n):e.fill(),e.restoreBlendMode()):r?bt(t,e):n?e.fill(n):e.fill())},recycleImage:xt,shape:function(t,e,s){const i=e.getSameCanvas();let n,r,a,o;const{__world:d}=t;let{scaleX:h,scaleY:l}=d;if(h<0&&(h=-h),l<0&&(l=-l),e.bounds.includes(d,s.matrix))s.matrix?(h*=s.matrix.a,l*=s.matrix.d,n=a=St(d,s.matrix)):n=a=d,o=i;else{const{renderShapeSpread:i}=t.__layout,c=Ot(i?kt(e.bounds,i*h,i*l):e.bounds,d,s.matrix);r=e.bounds.getFitMatrix(c),r.a<1&&(o=e.getSameCanvas(),t.__renderShape(o,s),h*=r.a,l*=r.d),a=St(d,r),n=At(a,-r.e,-r.f),s.matrix&&r.multiply(s.matrix),s=Object.assign(Object.assign({},s),{matrix:r})}return t.__renderShape(i,s),{canvas:i,matrix:r,bounds:n,worldCanvas:o,shapeBounds:a,scaleX:h,scaleY:l}},stroke:function(t,e,s){const i=t.__,{strokeWidth:n,strokeAlign:r,__font:a}=i;if(n)if(a)Bt(t,e,s);else switch(r){case"center":e.setStroke(s,n,i),e.stroke();break;case"inside":e.save(),e.setStroke(s,2*n,i),i.windingRule?e.clip(i.windingRule):e.clip(),e.stroke(),e.restore();break;case"outside":const r=e.getSameCanvas(!0);r.setStroke(s,2*n,t.__),t.__drawRenderPath(r),r.stroke(),i.windingRule?r.clip(i.windingRule):r.clip(),r.clearWorld(t.__layout.renderBounds),e.copyWorldToInner(r,t.__world,t.__layout.renderBounds),r.recycle()}},strokeText:Bt,strokes:function(t,e,s){const i=t.__,{strokeWidth:n,strokeAlign:r,__font:a}=i;if(n)if(a)Bt(t,e,s);else switch(r){case"center":e.setStroke(void 0,n,i),Et(t,s,e);break;case"inside":e.save(),e.setStroke(void 0,2*n,i),i.windingRule?e.clip(i.windingRule):e.clip(),Et(t,s,e),e.restore();break;case"outside":const{renderBounds:r}=t.__layout,a=e.getSameCanvas(!0);t.__drawRenderPath(a),a.setStroke(void 0,2*n,t.__),Et(t,s,a),i.windingRule?a.clip(i.windingRule):a.clip(),a.clearWorld(r),e.copyWorldToInner(a,t.__world,r),a.recycle()}}});const{copy:ie,toOffsetOutBounds:ne}=l,re={},ae={};function oe(t,e,s,i){const{bounds:n,shapeBounds:r}=i;if(p.fullImageShadow){if(ie(re,t.bounds),re.x+=e.x-r.x,re.y+=e.y-r.y,s){const{matrix:t}=i;re.x-=(n.x+(t?t.e:0)+n.width/2)*(s-1),re.y-=(n.y+(t?t.f:0)+n.height/2)*(s-1),re.width*=s,re.height*=s}t.copyWorld(i.canvas,t.bounds,re)}else s&&(ie(re,e),re.x-=e.width/2*(s-1),re.y-=e.height/2*(s-1),re.width*=s,re.height*=s),t.copyWorld(i.canvas,r,s?re:e)}const{toOffsetOutBounds:de}=l,he={};var le=Object.freeze({__proto__:null,blur:function(t,e,s){const{blur:i}=t.__;s.setWorldBlur(i*t.__world.a),s.copyWorldToInner(e,t.__world,t.__layout.renderBounds),s.filter="none"},innerShadow:function(t,e,s,i){let n,r;const{__world:a,__layout:o}=t,{innerShadow:d}=t.__,{worldCanvas:h,bounds:l,shapeBounds:c,scaleX:u,scaleY:f}=s,_=e.getSameCanvas(),g=d.length-1;de(l,he),d.forEach(((i,d)=>{_.save(),_.setWorldShadow(he.offsetX+i.x*u,he.offsetY+i.y*f,i.blur*u),r=i.spread?1-2*i.spread/(o.boxBounds.width+2*(o.strokeBoxSpread||0)):0,oe(_,he,r,s),_.restore(),h?(_.copyWorld(_,l,a,"copy"),_.copyWorld(h,a,a,"source-out"),n=a):(_.copyWorld(s.canvas,c,l,"source-out"),n=l),_.fillWorld(n,i.color,"source-in"),t.__hasMirror?e.copyWorldByReset(_,n,a,i.blendMode):e.copyWorldToInner(_,n,o.renderBounds,i.blendMode),g&&d<g&&_.clear()})),_.recycle()},shadow:function(t,e,s,i){let n,r;const{__world:a,__layout:o}=t,{shadow:d}=t.__,{worldCanvas:h,bounds:l,shapeBounds:c,scaleX:u,scaleY:f}=s,_=e.getSameCanvas(),g=d.length-1;ne(l,ae),d.forEach(((i,d)=>{_.setWorldShadow(ae.offsetX+i.x*u,ae.offsetY+i.y*f,i.blur*u,i.color),r=i.spread?1+2*i.spread/(o.boxBounds.width+2*(o.strokeBoxSpread||0)):0,oe(_,ae,r,s),n=l,i.box&&(_.restore(),_.save(),h&&(_.copyWorld(_,l,a,"copy"),n=a),h?_.copyWorld(h,a,a,"destination-out"):_.copyWorld(s.canvas,c,l,"destination-out")),t.__hasMirror?e.copyWorldByReset(_,n,a,i.blendMode):e.copyWorldToInner(_,n,o.renderBounds,i.blendMode),g&&d<g&&_.clear()})),_.recycle()}});const ce=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",ue=ce+"_#~&*+\\=|≮≯≈≠=…",fe=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 _e(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const ge=_e("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),pe=_e("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),we=_e(ce),ye=_e(ue),me=_e("- —/~|┆·");var ve;!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"}(ve||(ve={}));const{Letter:xe,Single:be,Before:Be,After:Re,Symbol:Le,Break:Ee}=ve;function ke(t){return ge[t]?xe:me[t]?Ee:pe[t]?Be:we[t]?Re:ye[t]?Le:fe.test(t)?be:xe}const Se={trimRight(t){const{words:e}=t;let s,i=0,n=e.length;for(let r=n-1;r>-1&&(s=e[r].data[0]," "===s.char);r--)i++,t.width-=s.width;i&&e.splice(n-i,i)}};function Ae(t,e,s){switch(e){case"title":return s?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:Oe}=Se,{Letter:Ce,Single:Me,Before:Te,After:We,Symbol:Ie,Break:De}=ve;let Pe,Fe,Ne,Ye,Ue,He,Ve,Ge,je,qe,Xe,ze,Qe,Ze,Ke=[];function $e(t,e){Pe.data.push({char:t,width:e}),Ne+=e}function Je(){Ye+=Ne,Pe.width=Ne,Fe.words.push(Pe),Pe={data:[]},Ne=0}function ts(){ze&&(Qe.paraNumber++,Fe.paraStart=!0,ze=!1),Fe.width=Ye,Ze.width&&Oe(Fe),Ke.push(Fe),Fe={words:[]},Ye=0}const es={getDrawData(t,e){"string"!=typeof t&&(t=String(t));let s=0,i=0,{width:n,height:r,padding:a}=e;const{textDecoration:o,textOverflow:d,__font:h}=e;if(n||(n=0),a){const[t,e,o,d]=S.fourNumber(a);n&&(s=d,n-=e+d),r&&(i=t,r-=t+o)}const l={bounds:{x:s,y:i,width:n,height:r},rows:[],paraNumber:0,font:p.canvas.font=h};return function(t,e,s){Qe=t,Ke=t.rows,Ze=t.bounds;const{__letterSpacing:i,paraIndent:n,textCase:r}=s,{canvas:a}=p,{width:o,height:d}=Ze;if(o||d||i||"none"!==r){ze=!0,je=null,Ne=Ye=0,Pe={data:[]},Fe={words:[]};for(let t=0,s=e.length;t<s;t++)He=e[t],"\n"===He?(Ne&&Je(),Fe.paraEnd=!0,ts(),ze=!0):(Ge=ke(He),Ge===Ce&&"none"!==r&&(He=Ae(He,r,!Ne)),Ve=a.measureText(He).width,i&&(Ve+=i),qe=Ge===Me&&(je===Me||je===Ce)||je===Me&&Ge!==We,Xe=!(Ge!==Te&&Ge!==Me||je!==Ie&&je!==We),Ue=ze&&n?o-n:o,o&&Ye+Ne+Ve>Ue&&(Xe||(Xe=Ge===Ce&&je==We),qe||Xe||Ge===De||Ge===Te||Ge===Me||Ne+Ve>Ue?(Ne&&Je(),ts()):ts())," "===He&&!0!==ze&&Ye+Ne===0||(Ge===De?(" "===He&&Ne&&Je(),$e(He,Ve),Je()):qe||Xe?(Ne&&Je(),$e(He,Ve)):$e(He,Ve)),je=Ge);Ne&&Je(),Ye&&ts(),Ke.length>0&&(Ke[Ke.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{Qe.paraNumber++,Ke.push({x:n||0,text:t,width:a.measureText(t).width,paraStart:!0})}))}(l,t,e),function(t,e){const{rows:s,bounds:i}=t,{__lineHeight:n,__baseLine:r,textAlign:a,verticalAlign:o,paraSpacing:d,textOverflow:h}=e;let l,{x:c,y:u,width:f,height:_}=i,g=n*s.length+(d?d*(t.paraNumber-1):0),p=r;if("show"!==h&&g>_)g=Math.max(_,n),t.overflow=s.length;else switch(o){case"middle":u+=(_-g)/2;break;case"bottom":u+=_-g}p+=u;for(let r=0,o=s.length;r<o;r++){switch(l=s[r],l.x=c,a){case"center":l.x+=(f-l.width)/2;break;case"right":l.x+=f-l.width}if(l.paraStart&&d&&r>0&&(p+=d),l.y=p,p+=n,t.overflow>r&&p>g&&(l.isOverflow=!0,t.overflow=r+1),l.width<0){const t=l.words[0].data[0].width,s=l.x+l.width;s<i.x&&(i.x=s-t),-l.width>i.width&&(i.width=-l.width+e.fontSize+t)}else l.x<i.x&&(i.x=l.x),l.width>i.width&&(i.width=l.width)}i.y=u,i.height=g}(l,e),function(t,e,s,i){const{rows:n}=t,{textAlign:r,paraIndent:a,letterSpacing:o}=e;let d,h,l,c,u;n.forEach((t=>{t.words&&(l=a&&t.paraStart?a:0,h=s&&"justify"===r&&t.words.length>1?(s-t.width-l)/(t.words.length-1):0,c=o||t.isOverflow?0:h>.01?1:2,2===c?(t.text="",t.x+=l,t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))):(t.x+=l,d=t.x,t.data=[],t.words.forEach((e=>{1===c?(u={char:"",x:d},d=function(t,e,s){return t.forEach((t=>{s.char+=t.char,e+=t.width})),e}(e.data,d,u)," "!==u.char&&t.data.push(u)):d=function(t,e,s){return t.forEach((t=>{" "!==t.char&&(t.x=e,s.push(t)),e+=t.width})),e}(e.data,d,t.data),!t.paraEnd&&h&&(d+=h,t.width+=h)}))),t.words=null)}))}(l,e,n),l.overflow&&function(t,e){const{rows:s,overflow:i}=t;if(s.splice(i),"hide"!==e){"ellipsis"===e&&(e="...");const n=p.canvas.measureText(e).width,r=s[i-1];let a,o,d=r.data.length-1;const{x:h,width:l}=t.bounds,c=h+l-n;for(let t=d;t>-1&&(a=r.data[t],o=a.x+a.width,!(t===d&&o<c));t--){if(o<c&&" "!==a.char){r.data.splice(t+1),r.width-=a.width;break}r.width-=a.width}r.width+=n,r.data.push({char:e,x:o})}}(l,d),"none"!==o&&function(t,e){const{fontSize:s}=e;switch(t.decorationHeight=s/11,e.textDecoration){case"under":t.decorationY=.15*s;break;case"delete":t.decorationY=.35*-s}}(l,e),l}},ss={string(t,e){if("string"==typeof t)return t;let s=void 0===t.a?1:t.a;e&&(s*=e);const i=t.r+","+t.g+","+t.b;return 1===s?"rgb("+i+")":"rgba("+i+","+s+")"}},is={export(t,e,s){return function(t){ns||(ns=new A);return new Promise((e=>{ns.add((()=>gt(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((i=>new Promise((n=>{const{leafer:r}=t;r?r.waitViewCompleted((()=>gt(this,void 0,void 0,(function*(){let t,a,o,{canvas:d}=r,{unreal:h}=d;switch(h&&(d=d.getSameCanvas(),d.backgroundColor=r.config.fill,r.__render(d,{})),typeof s){case"object":s.quality&&(t=s.quality),s.blob&&(a=!0);break;case"number":t=s;break;case"boolean":a=s}o=e.includes(".")?yield d.saveAs(e,t):a?yield d.toBlob(e,t):yield d.toDataURL(e,t),i({data:o}),n(),h&&d.recycle()})))):(i({data:!1}),n())}))))}};let ns;Object.assign(C,se),Object.assign(M,le),Object.assign(T,es),Object.assign(O,ss),Object.assign(W,is),st();export{z as Layouter,tt as LeaferCanvas,Z as Renderer,J as Selector,I as Watcher,st as useCanvas};