@leafer-ui/miniapp 1.0.0-beta.9 → 1.0.0-rc.11

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{LeaferCanvasBase as t,Platform as e,canvasPatch as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,Creator as a,LeaferImage as r,FileHelper as h,LeafList as d,RenderEvent as l,ChildEvent as c,WatchEvent as u,PropertyEvent as g,LeafHelper as f,BranchHelper as p,Bounds as _,LeafBoundsHelper as w,Debug as y,LeafLevelList as m,LayoutEvent as v,Run as x,ImageManager as b,AnimateEvent as B,BoundsHelper as R,Answer as k,MatrixHelper as E,ImageEvent as S,PointHelper as L,Direction4 as T,TwoPointBoundsHelper as M,TaskProcessor as A,Matrix as C}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionHelper as W,InteractionBase as O,HitCanvasManager as I,Platform as P}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as F,ColorConvert as D,PaintGradient as z,Export as V,Group as Y,TextConvert as N,Paint as H,Effect as U}from"@leafer-ui/draw";class X extends t{get allowBackgroundColor(){return!1}init(){let{view:t}=this.config;t?("string"==typeof t?("#"!==t[0]&&(t="#"+t),this.viewSelect=e.miniapp.select(t)):t.fields?this.viewSelect=t:this.initView(t),this.viewSelect&&e.miniapp.getSizeView(this.viewSelect).then((t=>{this.initView(t)}))):this.initView()}initView(t){t?this.view=t.view||t:(t={},this.__createView()),this.__createContext();const{width:e,height:s,pixelRatio:n}=this.config,o={width:e||t.width,height:s||t.height,pixelRatio:n};this.resize(o),this.context.roundRect&&(this.roundRect=function(t,e,i,s,n){this.context.roundRect(t,e,i,s,"number"==typeof n?[n]:n)}),i(this.context.__proto__)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(t){this.viewSelect&&e.miniapp.getBounds(this.viewSelect).then((e=>{this.clientBounds=e,t&&t()}))}startAutoLayout(t,i){this.resizeListener=i,this.checkSize=this.checkSize.bind(this),e.miniapp.onWindowResize(this.checkSize)}checkSize(){this.viewSelect&&setTimeout((()=>{this.updateClientBounds((()=>{const{width:t,height:e}=this.clientBounds,{pixelRatio:i}=this,a={width:t,height:e,pixelRatio:i};if(!this.isSameSize(a)){const t={};s.copyAttrs(t,this,n),this.resize(a),void 0!==this.width&&this.resizeListener(new o(a,t))}}))}),500)}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,e.miniapp.offWindowResize(this.checkSize)}}const{mineType:G,fileType:j}=h;function q(t,i){e.origin||(e.origin={createCanvas:(t,e,s)=>i.createOffscreenCanvas({type:"2d",width:t,height:e}),canvasToDataURL:(t,e,i)=>t.toDataURL(G(e),i),canvasToBolb:(t,e,i)=>t.toBuffer(e,{quality:i}),canvasSaveAs:(t,s,n)=>new Promise(((o,a)=>{let r,h=t.toDataURL(G(j(s)),n);h=h.substring(h.indexOf("64,")+3),s.includes("/")||(s=`${i.env.USER_DATA_PATH}/`+s,r=!0);const d=i.getFileSystemManager();d.writeFile({filePath:s,data:h,encoding:"base64",success(){r&&e.miniapp.saveToAlbum(s).then((()=>{d.unlink({filePath:s})})),o()},fail(t){a(t)}})})),loadImage:t=>new Promise(((i,s)=>{const n=e.canvas.view.createImage();n.onload=()=>{i(n)},n.onerror=t=>{s(t)},n.src=t})),noRepeat:"repeat-x"},e.miniapp={select:t=>i.createSelectorQuery().select(t),getBounds:t=>new Promise((e=>{t.boundingClientRect().exec((t=>{const i=t[1];e({x:i.top,y:i.left,width:i.width,height:i.height})}))})),getSizeView:t=>new Promise((e=>{t.fields({node:!0,size:!0}).exec((t=>{const i=t[0];e({view:i.node,width:i.width,height:i.height})}))})),saveToAlbum:t=>new Promise((e=>{i.getSetting({success:s=>{s.authSetting["scope.writePhotosAlbum"]?i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}}):i.authorize({scope:"scope.writePhotosAlbum",success:()=>{i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}})},fail:()=>{}})}})})),onWindowResize(t){i.onWindowResize(t)},offWindowResize(t){i.offWindowResize(t)}},e.event={stopDefault(t){},stopNow(t){},stop(t){}},e.canvas=a.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient)}Object.assign(a,{canvas:(t,e)=>new X(t,e),image:t=>new r(t)}),e.name="miniapp",e.requestRender=function(t){e.canvas.view.requestAnimationFrame(t)},e.devicePixelRatio=wx.getSystemInfoSync().pixelRatio;class Q{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new d;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 d,this.target=t,e&&(this.config=s.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(l.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===c.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 u(u.DATA,{updatedList:this.updatedList})),this.__updatedList=new d,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(g.CHANGE,this.__onAttrChange,this),t.on_([c.ADD,c.REMOVE],this.__onChildEvent,this),t.on_(u.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:K,updateBounds:Z,updateAllWorldOpacity:$}=f,{pushAllChildBranch:J,pushAllParent:tt}=p;const{worldBounds:et}=w,it={x:0,y:0,width:1e5,height:1e5};class st{constructor(t){this.updatedBounds=new _,this.beforeBounds=new _,this.afterBounds=new _,t instanceof Array&&(t=new d(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,et)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(it):this.afterBounds.setListWithFn(t,et),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:nt,updateAllChange:ot}=f,at=y.get("Layouter");class rt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new m,this.target=t,e&&(this.config=s.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.running)return;const{target:t}=this;this.times=0;try{t.emit(v.START),this.layoutOnce(),t.emitEvent(new v(v.END,this.layoutedBlocks,this.times))}catch(t){at.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?at.warn("layouting"):this.times>3?at.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(u.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=x.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:o,AFTER:a}=v,r=this.getBlocks(s);r.forEach((t=>t.setBefore())),i.emitEvent(new v(n,r,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?(K(t,!0),e.add(t),t.isBranch&&J(t,e),tt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),tt(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||Z(s[t])}Z(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&$(t),t.__updateChange()}))}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new v(o,r,this.times)),i.emitEvent(new v(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,x.end(e)}fullLayout(){const t=x.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=v,o=this.getBlocks(new d(e));e.emitEvent(new v(i,o,this.times)),rt.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new v(s,o,this.times)),e.emitEvent(new v(n,o,this.times)),this.addBlocks(o),x.end(t)}static fullLayout(t){nt(t,!0),t.isBranch?p.updateBounds(t):f.updateBounds(t),ot(t)}addExtra(t){const e=this.extraBlock||(this.extraBlock=new st([]));e.updatedList.add(t),e.beforeBounds.add(t.__world)}createBlock(t){return new st(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_(v.REQUEST,this.layout,this),t.on_(v.AGAIN,this.layoutAgain,this),t.on_(u.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const ht=y.get("Renderer");class dt{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,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=s.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(v.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new _,ht.log(e.innerName,"---\x3e");try{this.emitRender(l.START),this.renderOnce(t),this.emitRender(l.END,this.totalBounds),b.clearRecycled()}catch(t){this.rendering=!1,ht.error(t)}ht.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){return this.rendering?ht.warn("rendering"):this.times>3?ht.warn("render max times"):(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new _,this.renderOptions={},t?(this.emitRender(l.BEFORE),t()):(this.requestLayout(),this.emitRender(l.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()),this.emitRender(l.RENDER,this.renderBounds,this.renderOptions),this.emitRender(l.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 ht.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=x.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=t.includes(this.target.__world),o=new _(s);i.save(),n&&!y.showRepaint?i.clear():(s.spread(1+1/this.canvas.pixelRatio).ceil(),i.clearWorld(s,!0),i.clipWorld(s,!0)),this.__render(s,n,o),i.restore(),x.end(e)}fullRender(){const t=x.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),x.end(t)}__render(t,e,i){const s=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),y.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,s),this.renderBounds=i||t,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),y.showHitView&&this.renderHitView(s),y.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 _;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(B.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(l.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:i}=t.old;new _(0,0,e,i).includes(this.target.__world)&&!this.needFill&&t.samePixelRatio||(this.addBlock(this.canvas.bounds),this.target.forceUpdate("surface"))}}__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||ht.tip(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 l(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(l.REQUEST,this.update,this),t.on_(v.END,this.__onLayoutEnd,this),t.on_(l.AGAIN,this.renderAgain,this),t.on_(o.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:lt}=R;class ct{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const s=i.through||!1,n=i.ignoreHittable||!1,o=i.target||this.target;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=i.findList||[],i.findList||this.eachFind(o.children,o.__onlyHitMask);const a=this.findList,r=this.getBestMatchLeaf(),h=n?this.getPath(r):this.getHitablePath(r);return this.clear(),s?{path:h,target:r,throughPath:a.length?this.getThroughPath(a):h}:{path:h,target:r}}getBestMatchLeaf(){const{findList:t}=this;if(t.length>1){let e;this.findList=[];const{x:i,y:s}=this.point,n={x:i,y:s,radiusX:0,radiusY:0};for(let i=0,s=t.length;i<s;i++)if(e=t[i],f.worldHittable(e)&&(this.hitChild(e,n),this.findList.length))return this.findList[0]}return t[0]}getPath(t){const e=new d;for(;t;)e.add(t),t=t.parent;return e.add(this.target),e}getHitablePath(t){const e=this.getPath(t);let i,s=new d;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(s.addAt(i,0),i.__.hitChildren);t--);return s}getThroughPath(t){const e=new d,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let s,n,o;for(let t=0,a=i.length;t<a;t++){s=i[t],n=i[t+1];for(let t=0,i=s.length;t<i&&(o=s.list[t],!n||!n.has(o));t++)e.add(o)}return e}eachFind(t,e){let i,s;const{point:n}=this;for(let o=t.length-1;o>-1;o--)i=t[o],!i.__.visible||e&&!i.__.mask||(s=!!i.__.hitRadius||lt(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&!this.findList.length&&this.hitChild(i,n)):s&&this.hitChild(i,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()}}const{Yes:ut,NoAndSkip:gt,YesAndSkip:ft}=k;class pt{constructor(t,e){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.idMap[e]=t,1):0,innerId:(t,e)=>t.innerId===e?(this.innerIdMap[e]=t,1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0},this.target=t,e&&(this.config=s.default(e,this.config)),this.picker=new ct(t,this),this.__listenEvents()}getBy(t,e,i,s){switch(typeof t){case"number":const n=this.getByInnerId(t,e);return i?n:n?[n]:[];case"string":switch(t[0]){case"#":const s=this.getById(t.substring(1),e);return i?s:s?[s]:[];case".":return this.getByMethod(this.methods.className,e,i,t.substring(1));default:return this.getByMethod(this.methods.tag,e,i,t)}case"function":return this.getByMethod(t,e,i,s)}}getByPoint(t,i,s){return"node"===e.name&&this.target.emit(v.CHECK_UPDATE),this.picker.getByPoint(t,i,s)}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,e){const i=this.idMap[t];return i&&f.hasParent(i,e||this.target)?i:(this.eachFind(this.toChildren(e),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,i,s){let n,o;for(let a=0,r=t.length;a<r;a++){if(n=t[a],o=e(n,s),o===ut||o===ft){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&o<gt&&this.eachFind(n.children,e,i,s)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(c.REMOVE,this.__onRemoveChild,this),this.target.on_(g.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.picker.destroy(),this.findLeaf=null,this.innerIdMap={},this.idMap={})}}Object.assign(a,{watcher:(t,e)=>new Q(t,e),layouter:(t,e)=>new rt(t,e),renderer:(t,e,i)=>new dt(t,e,i),selector:(t,e)=>new pt(t,e)}),e.layout=rt.fullLayout;const _t={convertTouch(t,e){const i=_t.getTouch(t),s=W.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",pressure:i.force||1})},getTouch:t=>t.touches[0]||t.changedTouches[0]};class wt extends O{__listenEvents(){super.__listenEvents(),this.config.eventer&&(this.config.eventer.receiveEvent=this.receive.bind(this))}receive(t){switch(t.type){case"touchstart":this.onTouchStart(t);break;case"touchmove":this.onTouchMove(t);break;case"touchend":this.onTouchEnd(t);break;case"touchcancel":this.onTouchCancel()}}getLocal(t,e){if(e&&this.canvas.updateClientBounds(),void 0!==t.x)return{x:t.x,y:t.y};{const{clientBounds:e}=this.canvas;return{x:t.clientX-e.x,y:t.clientY-e.y}}}getTouches(t){return t}onTouchStart(t){this.multiTouchStart(t);const e=_t.getTouch(t);this.pointerDown(_t.convertTouch(t,this.getLocal(e,!0)))}onTouchMove(t){if(this.multiTouchMove(t),this.useMultiTouch)return;const e=_t.getTouch(t);this.pointerMove(_t.convertTouch(t,this.getLocal(e)))}onTouchEnd(t){this.multiTouchEnd();const e=_t.getTouch(t);this.pointerUp(_t.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>=2,this.touches=this.useMultiTouch?this.getTouches(t.touches):void 0,this.useMultiTouch&&this.pointerCancel()}multiTouchMove(t){if(this.useMultiTouch&&t.touches.length>1){const e=this.getTouches(t.touches),i=this.getKeepTouchList(this.touches,e);i.length>1&&(this.multiTouch(W.getBase(t),i),this.touches=e)}}multiTouchEnd(){this.touches=null,this.useMultiTouch=!1,this.transformEnd()}getKeepTouchList(t,e){let i;const s=[];return t.forEach((t=>{i=e.find((e=>e.identifier===t.identifier)),i&&s.push({from:this.getLocal(t),to:this.getLocal(i)})})),s}getLocalTouchs(t){return t.map((t=>this.getLocal(t)))}destroy(){super.destroy(),this.touches=null}}function yt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),n&&e.fillRect(i.x,i.y+n,i.width,o)}function mt(t,e,i){const{strokeAlign:s}=e.__,n="string"!=typeof t;switch(s){case"center":i.setStroke(n?void 0:t,e.__.strokeWidth,e.__),n?bt(t,!0,e,i):xt(e,i);break;case"inside":vt("inside",t,n,e,i);break;case"outside":vt("outside",t,n,e,i)}}function vt(t,e,i,s,n){const{__strokeWidth:o,__font:a}=s.__,r=n.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,s.__),r.font=a,i?bt(e,!0,s,r):xt(s,r),r.blendMode="outside"===t?"destination-out":"destination-in",yt(s,r),r.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(r,s.__nowWorld):n.copyWorldToInner(r,s.__nowWorld,s.__layout.renderBounds),r.recycle(s.__nowWorld)}function xt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),n&&e.strokeRect(i.x,i.y+n,i.width,o)}function bt(t,e,i,s){let n;for(let o=0,a=t.length;o<a;o++)n=t[o],n.image&&F.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?xt(i,s):s.stroke(),s.restoreBlendMode()):e?xt(i,s):s.stroke())}const{getSpread:Bt,getOuterOf:Rt,getByMove:kt,getIntersectData:Et}=R;let St;function Lt(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:s}=i.__layout;switch(e.type){case"solid":let{type:n,blendMode:o,color:a,opacity:r}=e;return{type:n,blendMode:o,style:D.string(a,r)};case"image":return F.image(i,t,e,s,!St||!St[e.url]);case"linear":return z.linearGradient(e,s);case"radial":return z.radialGradient(e,s);case"angular":return z.conicGradient(e,s);default:return e.r?{type:"solid",style:D.string(e)}:void 0}}const Tt={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),St=F.recycleImage(t,i);for(let i,n=0,a=o.length;n<a;n++)i=Lt(t,o[n],e),i&&s.push(i);i["_"+t]=s.length?s:void 0,s.length&&s[0].image&&(n=s[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=n:i.__pixelStroke=n},fill:function(t,e,i){i.fillStyle=t,e.__.__font?yt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)s=t[a],s.image&&F.checkImage(e,i,s,!o)||s.style&&(i.fillStyle=s.style,s.transform?(i.save(),i.transform(s.transform),s.blendMode&&(i.blendMode=s.blendMode),o?yt(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?yt(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?yt(e,i):n?i.fill(n):i.fill())},fillText:yt,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:a}=s;if(n)if(a)mt(t,e,i);else switch(o){case"center":i.setStroke(t,n,s),i.stroke();break;case"inside":i.save(),i.setStroke(t,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*n,s),e.__drawRenderPath(o),o.stroke(),s.windingRule?o.clip(s.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:a}=s;if(n)if(a)mt(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),bt(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),bt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*n,s),bt(t,!1,e,a),s.windingRule?a.clip(s.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:mt,drawTextStroke:xt,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,a,r,h,{scaleX:d,scaleY:l}=n;if(d<0&&(d=-d),l<0&&(l=-l),e.bounds.includes(n))h=s,o=r=n;else{const{renderShapeSpread:s}=t.__layout,c=Et(s?Bt(e.bounds,s*d,s*l):e.bounds,n);a=e.bounds.getFitMatrix(c);let{a:u,d:g}=a;if(a.a<1&&(h=e.getSameCanvas(),t.__renderShape(h,i),d*=u,l*=g),r=Rt(n,a),o=kt(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,g*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,g)})}return t.__renderShape(s,i),{canvas:s,matrix:a,bounds:o,worldCanvas:h,shapeBounds:r,scaleX:d,scaleY:l}}};let Mt={};const{get:At,rotateOfOuter:Ct,translate:Wt,scaleOfOuter:Ot,scale:It,rotate:Pt}=E;function Ft(t,e,i,s,n,o){const a=At(),r=o&&180!==o,h=i.width/(r?n:s),d=i.height/(r?s:n),l="fit"===e?Math.min(h,d):Math.max(h,d),c=i.x+(i.width-s*l)/2,u=i.y+(i.height-n*l)/2;Wt(a,c,u),It(a,l),o&&Ct(a,{x:i.x+i.width/2,y:i.y+i.height/2},o),t.scaleX=t.scaleY=l,t.transform=a}function Dt(t,e,i,s,n,o,a){const r=At();Wt(r,e.x,e.y),(i||s)&&Wt(r,i,s),n&&(It(r,n,o),t.scaleX=r.a,t.scaleY=r.d),a&&Pt(r,a),t.transform=r}function zt(t,e,i,s,n,o,a,r,h){const d=At();if(h)switch(Pt(d,h),h){case 90:Wt(d,s,0);break;case 180:Wt(d,i,s);break;case 270:Wt(d,0,i)}Mt.x=e.x,Mt.y=e.y,(n||o)&&(Mt.x+=n,Mt.y+=o),Wt(d,Mt.x,Mt.y),a&&(Ot(d,Mt,a,r),t.scaleX=a,t.scaleY=r),t.transform=d}const{get:Vt,translate:Yt}=E;function Nt(t,e,i,s){let{width:n,height:o}=e;const{opacity:a,mode:r,offset:h,scale:d,size:l,rotation:c,blendMode:u,repeat:g}=i,f=s.width===n&&s.height===o;u&&(t.blendMode=u);const p=t.data={mode:r};let _,w,y,m;switch(h&&(_=h.x,w=h.y),l?(y=("number"==typeof l?l:l.width)/n,m=("number"==typeof l?l:l.height)/o):d&&(y="number"==typeof d?d:d.x,m="number"==typeof d?d:d.y),r){case"strench":f||(n=s.width,o=s.height),(s.x||s.y)&&(p.transform=Vt(),Yt(p.transform,s.x,s.y));break;case"clip":(h||y||c)&&Dt(p,s,_,w,y,m,c);break;case"repeat":(!f||y||c)&&zt(p,s,n,o,_,w,y,m,c),g||(p.repeat="repeat");break;default:f&&!c||Ft(p,r,s,n,o,c)}p.width=n,p.height=o,a&&(p.opacity=a),g&&(p.repeat="string"==typeof g?"x"===g?"repeat-x":"repeat-y":"repeat")}let Ht,Ut=new _;const{isSame:Xt}=R;function Gt(t,e,i,s,n,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=s.width,e.__naturalHeight=s.height,e.__autoWidth||e.__autoHeight)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return n.data||Nt(n,s,i,o),!0}function jt(t,e){Kt(t,S.LOAD,e)}function qt(t,e){Kt(t,S.LOADED,e)}function Qt(t,e,i){e.error=i,t.forceUpdate("surface"),Kt(t,S.ERROR,e)}function Kt(t,e,i){t.hasEvent(e)&&t.emitEvent(new S(e,i))}const{get:Zt,scale:$t,copy:Jt}=E,{round:te,abs:ee}=Math;function ie(t,i,s){let{scaleX:n,scaleY:o}=t.__world;const a=n+"-"+o;if(i.patternId===a||t.destroyed)return!1;{n=ee(n),o=ee(o);const{image:t,data:r}=i;let h,d,{width:l,height:c,scaleX:u,scaleY:g,opacity:f,transform:p,repeat:_}=r;u&&(d=Zt(),Jt(d,p),$t(d,1/u,1/g),n*=u,o*=g),n*=s,o*=s,l*=n,c*=o;const w=l*c;if(!_&&w>e.image.maxCacheSize)return!1;let y=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(h=Math.sqrt(w/y)),h&&(n/=h,o/=h,l/=h,c/=h),u&&(n/=u,o/=g),(p||1!==n||1!==o)&&(d||(d=Zt(),p&&Jt(d,p)),$t(d,1/n,1/o));const m=t.getCanvas(l<1?1:te(l),c<1?1:te(c),f),v=t.getPattern(m,_||e.origin.noRepeat||"no-repeat",d,i);return i.style=v,i.patternId=a,!0}}function se(t,e,i,s){return new(i||(i=Promise))((function(n,o){function a(t){try{h(s.next(t))}catch(t){o(t)}}function r(t){try{h(s.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:ne}=Math;const oe={image:function(t,e,i,s,n){let o,a;const r=b.get(i);return Ht&&i===Ht.paint&&Xt(s,Ht.boxBounds)?o=Ht.leafPaint:(o={type:i.type},o.image=r,Ht=r.use>1?{leafPaint:o,paint:i,boxBounds:Ut.set(s)}:null),(n||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Gt(t,e,i,r,o,s),n&&(jt(t,a),qt(t,a))):r.error?n&&Qt(t,a,r.error):(n&&jt(t,a),o.loadId=r.load((()=>{t.destroyed||(Gt(t,e,i,r,o,s)&&t.forceUpdate("surface"),qt(t,a)),o.loadId=null}),(e=>{Qt(t,a,e),o.loadId=null}))),o},createData:Nt,fillOrFitMode:Ft,clipMode:Dt,repeatMode:zt,createPattern:ie,checkImage:function(t,i,s,n){const{scaleX:o,scaleY:a}=t.__world;if(s.data&&s.patternId!==o+"-"+a){const{data:r}=s;if(n)if(r.repeat)n=!1;else{let{width:t,height:s}=r;t*=ne(o)*i.pixelRatio,s*=ne(a)*i.pixelRatio,r.scaleX&&(t*=r.scaleX,s*=r.scaleY),n=t*s>e.image.maxCacheSize}return n?(i.save(),i.clip(),s.blendMode&&(i.blendMode=s.blendMode),r.opacity&&(i.opacity*=r.opacity),r.transform&&i.transform(r.transform),i.drawImage(s.image.view,0,0,r.width,r.height),i.restore(),!0):(!s.style||V.running?ie(t,s,i.pixelRatio):s.patternTask||(s.patternTask=b.patternTasker.add((()=>se(this,void 0,void 0,(function*(){s.patternTask=null,i.bounds.hit(t.__world)&&ie(t,s,i.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let s,n,o,a;for(let r=0,h=i.length;r<h;r++)s=i[r].image,a=s&&s.url,a&&(n||(n={}),n[a]=!0,b.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[r].loadId,!o.some((t=>t.url===a)))));return n}return null}},ae={x:.5,y:0},re={x:.5,y:1};function he(t,e,i){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],t.addColorStop(s.offset,D.string(s.color,i))}const{set:de,getAngle:le,getDistance:ce}=L,{get:ue,rotateOfOuter:ge,scaleOfOuter:fe}=E,pe={x:.5,y:.5},_e={x:.5,y:1},we={},ye={};const{set:me,getAngle:ve,getDistance:xe}=L,{get:be,rotateOfOuter:Be,scaleOfOuter:Re}=E,ke={x:.5,y:.5},Ee={x:.5,y:1},Se={},Le={};const Te={linearGradient:function(t,i){let{from:s,to:n,type:o,blendMode:a,opacity:r}=t;s||(s=ae),n||(n=re);const h=e.canvas.createLinearGradient(i.x+s.x*i.width,i.y+s.y*i.height,i.x+n.x*i.width,i.y+n.y*i.height);he(h,t.stops,r);const d={type:o,style:h};return a&&(d.blendMode=a),d},radialGradient:function(t,i){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:h}=t;s||(s=pe),n||(n=_e);const{x:d,y:l,width:c,height:u}=i;let g;de(we,d+s.x*c,l+s.y*u),de(ye,d+n.x*c,l+n.y*u),(c!==u||h)&&(g=ue(),fe(g,we,c/u*(h||1),1),ge(g,we,le(we,ye)+90));const f=e.canvas.createRadialGradient(we.x,we.y,0,we.x,we.y,ce(we,ye));he(f,t.stops,a);const p={type:o,style:f,transform:g};return r&&(p.blendMode=r),p},conicGradient:function(t,i){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:h}=t;s||(s=ke),n||(n=Ee);const{x:d,y:l,width:c,height:u}=i;me(Se,d+s.x*c,l+s.y*u),me(Le,d+n.x*c,l+n.y*u);const g=be(),f=ve(Se,Le);e.conicGradientRotate90?(Re(g,Se,c/u*(h||1),1),Be(g,Se,f+90)):(Re(g,Se,1,c/u*(h||1)),Be(g,Se,f));const p=e.conicGradientSupport?e.canvas.createConicGradient(0,Se.x,Se.y):e.canvas.createRadialGradient(Se.x,Se.y,0,Se.x,Se.y,xe(Se,Le));he(p,t.stops,a);const _={type:o,style:p,transform:g};return r&&(_.blendMode=r),_}},{copy:Me,toOffsetOutBounds:Ae}=R,Ce={},We={};function Oe(t,i,s,n){const{bounds:o,shapeBounds:a}=n;if(e.fullImageShadow){if(Me(Ce,t.bounds),Ce.x+=i.x-a.x,Ce.y+=i.y-a.y,s){const{matrix:t}=n;Ce.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),Ce.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),Ce.width*=s,Ce.height*=s}t.copyWorld(n.canvas,t.bounds,Ce)}else s&&(Me(Ce,i),Ce.x-=i.width/2*(s-1),Ce.y-=i.height/2*(s-1),Ce.width*=s,Ce.height*=s),t.copyWorld(n.canvas,a,s?Ce:i)}const{toOffsetOutBounds:Ie}=R,Pe={};const Fe={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:h,bounds:d,shapeBounds:l,scaleX:c,scaleY:u}=i,g=e.getSameCanvas(),f=r.length-1;Ae(d,We),r.forEach(((r,p)=>{g.setWorldShadow(We.offsetX+r.x*c,We.offsetY+r.y*u,r.blur*c,r.color),n=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Oe(g,We,n,i),s=d,r.box&&(g.restore(),g.save(),h&&(g.copyWorld(g,d,o,"copy"),s=o),h?g.copyWorld(h,o,o,"destination-out"):g.copyWorld(i.canvas,l,d,"destination-out")),t.__worldFlipped?e.copyWorldByReset(g,s,o,r.blendMode):e.copyWorldToInner(g,s,a.renderBounds,r.blendMode),f&&p<f&&g.clearWorld(s,!0)})),g.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:h,bounds:d,shapeBounds:l,scaleX:c,scaleY:u}=i,g=e.getSameCanvas(),f=r.length-1;Ie(d,Pe),r.forEach(((r,p)=>{g.save(),g.setWorldShadow(Pe.offsetX+r.x*c,Pe.offsetY+r.y*u,r.blur*c),n=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Oe(g,Pe,n,i),g.restore(),h?(g.copyWorld(g,d,o,"copy"),g.copyWorld(h,o,o,"source-out"),s=o):(g.copyWorld(i.canvas,l,d,"source-out"),s=d),g.fillWorld(s,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(g,s,o,r.blendMode):e.copyWorldToInner(g,s,a.renderBounds,r.blendMode),f&&p<f&&g.clearWorld(s,!0)})),g.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__world.a),i.copyWorldToInner(e,t.__world,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:De}=w;function ze(t,e,i,s,n,o){switch(e){case"alpha":!function(t,e,i,s){const n=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,n),s.recycle(n),Ye(t,e,i,1)}(t,i,s,n);break;case"opacity-path":Ye(t,i,s,o);break;case"path":i.restore()}}function Ve(t){return t.getSameCanvas(!1,!0)}function Ye(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}Y.prototype.__renderMask=function(t,e){let i,s,n,o,a;const{children:r}=this;for(let h=0,d=r.length;h<d;h++)i=r[h],i.__.mask&&(a&&(ze(this,a,t,n,s,o),s=n=null),"path"===i.__.maskType?(i.opacity<1?(a="opacity-path",o=i.opacity,n||(n=Ve(t))):(a="path",t.save()),i.__clip(n||t,e)):(a="alpha",s||(s=Ve(t)),n||(n=Ve(t)),i.__render(s,e)),"clipping"!==i.__.maskType)||De(i,e)||i.__render(n||t,e);ze(this,a,t,n,s,o)};const Ne=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",He=Ne+"_#~&*+\\=|≮≯≈≠=…",Ue=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 Xe(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Ge=Xe("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),je=Xe("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),qe=Xe(Ne),Qe=Xe(He),Ke=Xe("- —/~|┆·");var Ze;!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"}(Ze||(Ze={}));const{Letter:$e,Single:Je,Before:ti,After:ei,Symbol:ii,Break:si}=Ze;function ni(t){return Ge[t]?$e:Ke[t]?si:je[t]?ti:qe[t]?ei:Qe[t]?ii:Ue.test(t)?Je:$e}const oi={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let o=n-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function ai(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:ri}=oi,{Letter:hi,Single:di,Before:li,After:ci,Symbol:ui,Break:gi}=Ze;let fi,pi,_i,wi,yi,mi,vi,xi,bi,Bi,Ri,ki,Ei,Si,Li,Ti,Mi=[];function Ai(t,e){bi&&!xi&&(xi=bi),fi.data.push({char:t,width:e}),_i+=e}function Ci(){wi+=_i,fi.width=_i,pi.words.push(fi),fi={data:[]},_i=0}function Wi(){Si&&(Li.paraNumber++,pi.paraStart=!0,Si=!1),bi&&(pi.startCharSize=xi,pi.endCharSize=bi,xi=0),pi.width=wi,Ti.width&&ri(pi),Mi.push(pi),pi={words:[]},wi=0}const Oi=0,Ii=1,Pi=2;const{top:Fi,right:Di,bottom:zi,left:Vi}=T;function Yi(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 Ni={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=i.__getInput("width")||0,a=i.__getInput("height")||0;const{textDecoration:r,__font:h,__padding:d}=i;d&&(o&&(s=d[Vi],o-=d[Di]+d[Vi]),a&&(n=d[Fi],a-=d[Fi]+d[zi]));const l={bounds:{x:s,y:n,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=h};return function(t,i,s){Li=t,Mi=t.rows,Ti=t.bounds;const{__letterSpacing:n,paraIndent:o,textCase:a}=s,{canvas:r}=e,{width:h,height:d}=Ti;if(h||d||n||"none"!==a){const t="none"!==s.textWrap,e="break"===s.textWrap;Si=!0,Ri=null,xi=vi=bi=_i=wi=0,fi={data:[]},pi={words:[]};for(let s=0,d=i.length;s<d;s++)mi=i[s],"\n"===mi?(_i&&Ci(),pi.paraEnd=!0,Wi(),Si=!0):(Bi=ni(mi),Bi===hi&&"none"!==a&&(mi=ai(mi,a,!_i)),vi=r.measureText(mi).width,n&&(n<0&&(bi=vi),vi+=n),ki=Bi===di&&(Ri===di||Ri===hi)||Ri===di&&Bi!==ci,Ei=!(Bi!==li&&Bi!==di||Ri!==ui&&Ri!==ci),yi=Si&&o?h-o:h,t&&h&&wi+_i+vi>yi&&(e?(_i&&Ci(),Wi()):(Ei||(Ei=Bi===hi&&Ri==ci),ki||Ei||Bi===gi||Bi===li||Bi===di||_i+vi>yi?(_i&&Ci(),Wi()):Wi()))," "===mi&&!0!==Si&&wi+_i===0||(Bi===gi?(" "===mi&&_i&&Ci(),Ai(mi,vi),Ci()):ki||Ei?(_i&&Ci(),Ai(mi,vi)):Ai(mi,vi)),Ri=Bi);_i&&Ci(),wi&&Wi(),Mi.length>0&&(Mi[Mi.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{Li.paraNumber++,Mi.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(l,t,i),d&&function(t,e,i,s,n){if(!s)switch(i.textAlign){case"left":Yi(e,"x",t[Vi]);break;case"right":Yi(e,"x",-t[Di])}if(!n)switch(i.verticalAlign){case"top":Yi(e,"y",t[Fi]);break;case"bottom":Yi(e,"y",-t[zi])}}(d,l,i,o,a),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:h,verticalAlign:d,paraSpacing:l}=e;let c,u,g,{x:f,y:p,width:_,height:w}=s,y=n*i.length+(l?l*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,n),t.overflow=i.length;else switch(d){case"middle":p+=(w-y)/2;break;case"bottom":p+=w-y}m+=p;for(let o=0,d=i.length;o<d;o++){switch(c=i[o],c.x=f,h){case"center":c.x+=(_-c.width)/2;break;case"right":c.x+=_-c.width}c.paraStart&&l&&o>0&&(m+=l),c.y=m,m+=n,t.overflow>o&&m>y&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,g=c.width,a<0&&(c.width<0?(g=-c.width+e.fontSize+a,u-=g,g+=e.fontSize):g-=a),u<s.x&&(s.x=u),g>s.width&&(s.width=g),r&&_&&_<g&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=y}(l,i),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let h,d,l,c,u;n.forEach((t=>{t.words&&(l=a&&t.paraStart?a:0,d=i&&"justify"===o&&t.words.length>1?(i-t.width-l)/(t.words.length-1):0,c=r||t.isOverflow?Oi:d>.01?Ii:Pi,t.isOverflow&&!r&&(t.textMode=!0),c===Pi?(t.x+=l,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=l,h=t.x,t.data=[],t.words.forEach((e=>{c===Ii?(u={char:"",x:h},h=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,h,u)," "!==u.char&&t.data.push(u)):h=function(t,e,i){return t.forEach((t=>{" "!==t.char&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data),!t.paraEnd&&d&&(h+=d,t.width+=d)}))),t.words=null)}))}(l,i,o),l.overflow&&function(t,i){const{rows:s,overflow:n}=t;let{textOverflow:o}=i;if(s.splice(n),"hide"!==o){let t,a;"ellipsis"===o&&(o="...");const r=e.canvas.measureText(o).width,h=i.x+i.width-r;("none"===i.textWrap?s:[s[n-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],a=t.x+t.width,!(s===i&&a<h));s--){if(a<h&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=r,e.data.push({char:o,x:a}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(l,i),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(l,i),l}};const Hi={string:function(t,e){if("string"==typeof t)return t;let i=void 0===t.a?1:t.a;e&&(i*=e);const s=t.r+","+t.g+","+t.b;return 1===i?"rgb("+s+")":"rgba("+s+","+i+")"}},{setPoint:Ui,addPoint:Xi,toBounds:Gi}=M;const ji={export(t,e,i){return this.running=!0,function(t){qi||(qi=new A);return new Promise((e=>{qi.add((()=>se(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((s=>new Promise((n=>{const o=t=>{s(t),n(),this.running=!1},{leafer:r}=t;r?r.waitViewCompleted((()=>se(this,void 0,void 0,(function*(){let s,n,d=1,l=1;i=h.getExportOptions(i);const{scale:c,slice:u,trim:g}=i,f=i.pixelRatio||1,p=i.screenshot||t.isApp,w=void 0===i.fill?t.isLeafer&&p?t.fill:"":i.fill,y=h.isOpaqueImage(e)||w,m=new C;if(p)s=!0===p?t.isLeafer?r.canvas.bounds:t.worldRenderBounds:p;else{const{localTransform:e,__world:i}=t;m.set(i).divide(e).invert(),d=1/(i.scaleX/t.scaleX),l=1/(i.scaleY/t.scaleY),s=t.getBounds("render","local")}let{x:v,y:x,width:b,height:B}=s;c&&(m.scale(c),b*=c,B*=c,d*=c,l*=c);let R=a.canvas({width:Math.ceil(b),height:Math.ceil(b),pixelRatio:f});const k={matrix:m.translate(-v,-x).withScale(d,l)};if(u&&(t=r,k.bounds=R.bounds),R.save(),t.__render(R,k),R.restore(),g){n=function(t){const{width:e,height:i}=t.view,{data:s}=t.context.getImageData(0,0,e,i);let n,o,a,r=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(n=r%e,o=(r-n)/e,a?Xi(a,n,o):Ui(a={},n,o)),r++;const h=new _;return Gi(a,h),h.scale(1/t.pixelRatio).ceil()}(R);const t=R,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:f};R=a.canvas(s),R.copyWorld(t,n,s)}y&&R.fillWorld(R.bounds,w||"#FFFFFF","destination-over");const E="canvas"===e?R:yield R.export(e,i);o({data:E,width:R.pixelWidth,height:R.pixelHeight,renderBounds:s,trimBounds:n})})))):o({data:!1})}))))}};let qi;Object.assign(N,Ni),Object.assign(D,Hi),Object.assign(H,Tt),Object.assign(F,oe),Object.assign(z,Te),Object.assign(U,Fe),Object.assign(V,ji),Object.assign(a,{interaction:(t,e,i,s)=>new wt(t,e,i,s),hitCanvas:(t,e)=>new X(t,e),hitCanvasManager:()=>new I});try{q(0,wx)}catch(t){}X.prototype.__createContext=function(){if(this.viewSelect){const t=P.origin.createCanvas(1,1),e=this.view.getContext("2d");this.testView=this.view,this.testContext=e,this.view=t}this.context=this.view.getContext("2d"),this.__bindContext()},X.prototype.updateRender=function(){if(this.testView){let t=this.context.createPattern(this.view,P.origin.noRepeat);this.testContext.clearRect(0,0,this.view.width,this.view.height),this.testContext.fillStyle=t,this.testContext.fillRect(0,0,this.view.width,this.view.height),this.testContext.fillStyle=t=null}},X.prototype.updateViewSize=function(){const{width:t,height:e,pixelRatio:i,view:s,testView:n}=this;s.width=t*i,s.height=e*i,n&&(n.width=s.width,n.height=s.height)};export{wt as Interaction,rt as Layouter,X as LeaferCanvas,dt as Renderer,pt as Selector,Q as Watcher,q as useCanvas};