leafer-draw 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web.cjs +13 -13
- package/dist/web.esm.js +13 -13
- package/dist/web.esm.min.js +1 -1
- package/dist/web.js +64 -39
- package/dist/web.min.cjs +1 -1
- package/dist/web.min.js +1 -1
- package/dist/web.module.js +64 -39
- package/dist/web.module.min.js +1 -1
- package/package.json +2 -2
package/dist/web.cjs
CHANGED
|
@@ -643,7 +643,8 @@ class Renderer {
|
|
|
643
643
|
this.totalBounds = new core.Bounds();
|
|
644
644
|
debug$1.log(target.innerName, '--->');
|
|
645
645
|
try {
|
|
646
|
-
target.
|
|
646
|
+
if (!target.isApp)
|
|
647
|
+
target.app.emit(core.RenderEvent.CHILD_START, target);
|
|
647
648
|
this.emitRender(core.RenderEvent.START);
|
|
648
649
|
this.renderOnce(callback);
|
|
649
650
|
this.emitRender(core.RenderEvent.END, this.totalBounds);
|
|
@@ -1752,16 +1753,16 @@ const EffectModule = {
|
|
|
1752
1753
|
|
|
1753
1754
|
const { excludeRenderBounds } = core.LeafBoundsHelper;
|
|
1754
1755
|
draw.Group.prototype.__renderMask = function (canvas, options) {
|
|
1755
|
-
let child, maskCanvas, contentCanvas, maskOpacity, currentMask;
|
|
1756
|
+
let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
|
|
1756
1757
|
const { children } = this;
|
|
1757
1758
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
1758
|
-
child = children[i];
|
|
1759
|
-
if (
|
|
1759
|
+
child = children[i], mask = child.__.mask;
|
|
1760
|
+
if (mask) {
|
|
1760
1761
|
if (currentMask) {
|
|
1761
1762
|
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
1762
1763
|
maskCanvas = contentCanvas = null;
|
|
1763
1764
|
}
|
|
1764
|
-
if (
|
|
1765
|
+
if (mask === 'path' || mask === 'clipping-path') {
|
|
1765
1766
|
if (child.opacity < 1) {
|
|
1766
1767
|
currentMask = 'opacity-path';
|
|
1767
1768
|
maskOpacity = child.opacity;
|
|
@@ -1775,14 +1776,14 @@ draw.Group.prototype.__renderMask = function (canvas, options) {
|
|
|
1775
1776
|
child.__clip(contentCanvas || canvas, options);
|
|
1776
1777
|
}
|
|
1777
1778
|
else {
|
|
1778
|
-
currentMask = 'alpha';
|
|
1779
|
+
currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
|
|
1779
1780
|
if (!maskCanvas)
|
|
1780
1781
|
maskCanvas = getCanvas(canvas);
|
|
1781
1782
|
if (!contentCanvas)
|
|
1782
1783
|
contentCanvas = getCanvas(canvas);
|
|
1783
1784
|
child.__render(maskCanvas, options);
|
|
1784
1785
|
}
|
|
1785
|
-
if (
|
|
1786
|
+
if (!(mask === 'clipping' || mask === 'clipping-path'))
|
|
1786
1787
|
continue;
|
|
1787
1788
|
}
|
|
1788
1789
|
if (excludeRenderBounds(child, options))
|
|
@@ -1793,6 +1794,8 @@ draw.Group.prototype.__renderMask = function (canvas, options) {
|
|
|
1793
1794
|
};
|
|
1794
1795
|
function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
|
|
1795
1796
|
switch (maskMode) {
|
|
1797
|
+
case 'grayscale':
|
|
1798
|
+
maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
|
|
1796
1799
|
case 'alpha':
|
|
1797
1800
|
usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
|
|
1798
1801
|
break;
|
|
@@ -2497,15 +2500,12 @@ const canvas = core.LeaferCanvasBase.prototype;
|
|
|
2497
2500
|
const debug = core.Debug.get('@leafer-ui/export');
|
|
2498
2501
|
canvas.export = function (filename, options) {
|
|
2499
2502
|
const { quality, blob } = core.FileHelper.getExportOptions(options);
|
|
2500
|
-
if (filename.includes('.'))
|
|
2503
|
+
if (filename.includes('.'))
|
|
2501
2504
|
return this.saveAs(filename, quality);
|
|
2502
|
-
|
|
2503
|
-
else if (blob) {
|
|
2505
|
+
else if (blob)
|
|
2504
2506
|
return this.toBlob(filename, quality);
|
|
2505
|
-
|
|
2506
|
-
else {
|
|
2507
|
+
else
|
|
2507
2508
|
return this.toDataURL(filename, quality);
|
|
2508
|
-
}
|
|
2509
2509
|
};
|
|
2510
2510
|
canvas.toBlob = function (type, quality) {
|
|
2511
2511
|
return new Promise((resolve) => {
|
package/dist/web.esm.js
CHANGED
|
@@ -644,7 +644,8 @@ class Renderer {
|
|
|
644
644
|
this.totalBounds = new Bounds();
|
|
645
645
|
debug$1.log(target.innerName, '--->');
|
|
646
646
|
try {
|
|
647
|
-
target.
|
|
647
|
+
if (!target.isApp)
|
|
648
|
+
target.app.emit(RenderEvent.CHILD_START, target);
|
|
648
649
|
this.emitRender(RenderEvent.START);
|
|
649
650
|
this.renderOnce(callback);
|
|
650
651
|
this.emitRender(RenderEvent.END, this.totalBounds);
|
|
@@ -1753,16 +1754,16 @@ const EffectModule = {
|
|
|
1753
1754
|
|
|
1754
1755
|
const { excludeRenderBounds } = LeafBoundsHelper;
|
|
1755
1756
|
Group.prototype.__renderMask = function (canvas, options) {
|
|
1756
|
-
let child, maskCanvas, contentCanvas, maskOpacity, currentMask;
|
|
1757
|
+
let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
|
|
1757
1758
|
const { children } = this;
|
|
1758
1759
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
1759
|
-
child = children[i];
|
|
1760
|
-
if (
|
|
1760
|
+
child = children[i], mask = child.__.mask;
|
|
1761
|
+
if (mask) {
|
|
1761
1762
|
if (currentMask) {
|
|
1762
1763
|
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
1763
1764
|
maskCanvas = contentCanvas = null;
|
|
1764
1765
|
}
|
|
1765
|
-
if (
|
|
1766
|
+
if (mask === 'path' || mask === 'clipping-path') {
|
|
1766
1767
|
if (child.opacity < 1) {
|
|
1767
1768
|
currentMask = 'opacity-path';
|
|
1768
1769
|
maskOpacity = child.opacity;
|
|
@@ -1776,14 +1777,14 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
1776
1777
|
child.__clip(contentCanvas || canvas, options);
|
|
1777
1778
|
}
|
|
1778
1779
|
else {
|
|
1779
|
-
currentMask = 'alpha';
|
|
1780
|
+
currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
|
|
1780
1781
|
if (!maskCanvas)
|
|
1781
1782
|
maskCanvas = getCanvas(canvas);
|
|
1782
1783
|
if (!contentCanvas)
|
|
1783
1784
|
contentCanvas = getCanvas(canvas);
|
|
1784
1785
|
child.__render(maskCanvas, options);
|
|
1785
1786
|
}
|
|
1786
|
-
if (
|
|
1787
|
+
if (!(mask === 'clipping' || mask === 'clipping-path'))
|
|
1787
1788
|
continue;
|
|
1788
1789
|
}
|
|
1789
1790
|
if (excludeRenderBounds(child, options))
|
|
@@ -1794,6 +1795,8 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
1794
1795
|
};
|
|
1795
1796
|
function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
|
|
1796
1797
|
switch (maskMode) {
|
|
1798
|
+
case 'grayscale':
|
|
1799
|
+
maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
|
|
1797
1800
|
case 'alpha':
|
|
1798
1801
|
usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
|
|
1799
1802
|
break;
|
|
@@ -2498,15 +2501,12 @@ const canvas = LeaferCanvasBase.prototype;
|
|
|
2498
2501
|
const debug = Debug.get('@leafer-ui/export');
|
|
2499
2502
|
canvas.export = function (filename, options) {
|
|
2500
2503
|
const { quality, blob } = FileHelper.getExportOptions(options);
|
|
2501
|
-
if (filename.includes('.'))
|
|
2504
|
+
if (filename.includes('.'))
|
|
2502
2505
|
return this.saveAs(filename, quality);
|
|
2503
|
-
|
|
2504
|
-
else if (blob) {
|
|
2506
|
+
else if (blob)
|
|
2505
2507
|
return this.toBlob(filename, quality);
|
|
2506
|
-
|
|
2507
|
-
else {
|
|
2508
|
+
else
|
|
2508
2509
|
return this.toDataURL(filename, quality);
|
|
2509
|
-
}
|
|
2510
2510
|
};
|
|
2511
2511
|
canvas.toBlob = function (type, quality) {
|
|
2512
2512
|
return new Promise((resolve) => {
|
package/dist/web.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Debug as t,LeaferCanvasBase as e,Platform as i,DataHelper as n,canvasSizeAttrs as s,ResizeEvent as o,canvasPatch as a,Creator as r,LeaferImage as d,defineKey as l,FileHelper as c,LeafList as h,RenderEvent as u,ChildEvent as f,WatchEvent as p,PropertyEvent as g,LeafHelper as _,BranchHelper as w,Bounds as y,LeafBoundsHelper as m,LeafLevelList as v,LayoutEvent as x,Run as b,ImageManager as B,BoundsHelper as R,MatrixHelper as k,MathHelper as S,AlignHelper as E,ImageEvent as L,AroundHelper as A,PointHelper as O,Direction4 as W,TwoPointBoundsHelper as C,TaskProcessor as T,Matrix as M}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as D,ColorConvert as I,PaintGradient as P,Export as z,Group as F,TextConvert as V,Paint as Y,Effect as U}from"@leafer-ui/draw";export*from"@leafer-ui/draw";const X=t.get("LeaferCanvas");class N 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 n=i.children[t];n?(this.setAbsolute(n),i.insertBefore(e,n)):i.appendChild(n)}}init(){const{config:t}=this,e=t.view||t.canvas;e?this.__createViewFrom(e):this.__createView();const{style:n}=this.view;if(n.display||(n.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}i.syncDomFont&&!this.parentView&&(n.display="none",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="string"==typeof 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 X.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:n}=this.view;n.width=t+"px",n.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.clientBounds=this.view.getBoundingClientRect()}startAutoLayout(t,e){if(this.resizeListener=e,t){this.autoBounds=t;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),X.warn("no parent"))}catch(t){this.imitateResizeObserver()}}else window.addEventListener("resize",(()=>{const t=i.devicePixelRatio;if(this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}}))}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(t){const e=this.view,{x:n,y:s,width:o,height:a}=this.autoBounds.getBoundsFrom(t),r={width:o,height:a,pixelRatio:i.devicePixelRatio};if(!this.isSameSize(r)){const{style:t}=e;t.marginLeft=n+"px",t.marginTop=s+"px",this.emitResize(r)}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}emitResize(t){const e={};n.copyAttrs(e,this,s),this.resize(t),this.resizeListener&&void 0!==this.width&&this.resizeListener(new o(t,e))}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}a(CanvasRenderingContext2D.prototype),a(Path2D.prototype);const{mineType:G,fileType:j}=c;function q(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>t.toDataURL(G(e),i),canvasToBolb:(t,e,i)=>new Promise((n=>t.toBlob(n,G(e),i))),canvasSaveAs:(t,e,n)=>{const s=t.toDataURL(G(j(e)),n);return i.origin.download(s,e)},download:(t,e)=>new Promise((i=>{let n=document.createElement("a");n.href=t,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),i()})),loadImage:t=>new Promise(((e,n)=>{const s=new Image,{crossOrigin:o}=i.image;o&&(s.setAttribute("crossOrigin",o),s.crossOrigin=o),s.onload=()=>{e(s)},s.onerror=t=>{n(t)},s.src=i.image.getRealURL(t)}))},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=r.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(r,{canvas:(t,e)=>new N(t,e),image:t=>new d(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},l(i,"devicePixelRatio",{get:()=>Math.max(1,devicePixelRatio)});const{userAgent:H}=navigator;H.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):H.indexOf("Safari")>-1&&-1===H.indexOf("Chrome")&&(i.fullImageShadow=!0),H.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):H.indexOf("Mac")>-1?i.os="Mac":H.indexOf("Linux")>-1&&(i.os="Linux");class Q{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new h;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 h,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(u.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===f.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 p(p.DATA,{updatedList:this.updatedList})),this.__updatedList=new h,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_([f.ADD,f.REMOVE],this.__onChildEvent,this),t.on_(p.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:J,updateBounds:Z,updateAllWorldOpacity:$}=_,{pushAllChildBranch:K,pushAllParent:tt}=w;const{worldBounds:et}=m,it={x:0,y:0,width:1e5,height:1e5};class nt{constructor(t){this.updatedBounds=new y,this.beforeBounds=new y,this.afterBounds=new y,t instanceof Array&&(t=new h(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:st,updateAllChange:ot}=_,at=t.get("Layouter");class rt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new v,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.running)return;const{target:t}=this;this.times=0;try{t.emit(x.START),this.layoutOnce(),t.emitEvent(new x(x.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(p.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=b.start("PartLayout"),{target:i,__updatedList:n}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=x,r=this.getBlocks(n);r.forEach((t=>t.setBefore())),i.emitEvent(new x(s,r,this.times)),this.extraBlock=null,n.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(J(t,!0),e.add(t),t.isBranch&&K(t,e),tt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),tt(t,e)))}))}(n,this.__levelList),function(t){let e,i,n;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(i=e[t],i.isBranch&&i.__tempNumber){n=i.children;for(let t=0,e=n.length;t<e;t++)n[t].isBranch||Z(n[t])}Z(i)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&$(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(n),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new x(o,r,this.times)),i.emitEvent(new x(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,b.end(e)}fullLayout(){const t=b.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:n,AFTER:s}=x,o=this.getBlocks(new h(e));e.emitEvent(new x(i,o,this.times)),rt.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new x(n,o,this.times)),e.emitEvent(new x(s,o,this.times)),this.addBlocks(o),b.end(t)}static fullLayout(t){st(t,!0),t.isBranch?w.updateBounds(t):_.updateBounds(t),ot(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new nt([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new nt(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_(x.REQUEST,this.layout,this),t.on_(x.AGAIN,this.layoutAgain,this),t.on_(p.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const dt=t.get("Renderer");class lt{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=n.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(x.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new y,dt.log(e.innerName,"---\x3e");try{e.app.emit(u.CHILD_START,e),this.emitRender(u.START),this.renderOnce(t),this.emitRender(u.END,this.totalBounds),B.clearRecycled()}catch(t){this.rendering=!1,dt.error(t)}dt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return dt.warn("rendering");if(this.times>3)return dt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new y,this.renderOptions={},t)this.emitRender(u.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(u.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(u.RENDER,this.renderBounds,this.renderOptions),this.emitRender(u.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;if(!e)return dt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const i=b.start("PartRender"),{canvas:n}=this,s=e.getIntersect(n.bounds),o=e.includes(this.target.__world),a=new y(s);n.save(),o&&!t.showRepaint?n.clear():(s.spread(10+1/this.canvas.pixelRatio).ceil(),n.clearWorld(s,!0),n.clipWorld(s,!0)),this.__render(s,o,a),n.restore(),b.end(i)}fullRender(){const t=b.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),b.end(t)}__render(e,i,n){const s=e.includes(this.target.__world)?{includes:i}:{bounds:e,includes:i};this.needFill&&this.canvas.fillWorld(e,this.config.fill),t.showRepaint&&this.canvas.strokeWorld(e,"red"),this.target.__render(this.canvas,s),this.renderBounds=n=n||e,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=n:this.totalBounds.add(n),t.showHitView&&this.renderHitView(s),t.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender(n)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new y;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();i.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.changed&&this.canvas.view&&this.render(),this.target.emit(u.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new y(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 y(0,0,1,1)),this.changed=!0}}__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||dt.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 u(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.REQUEST,this.update,this),t.on_(x.END,this.__onLayoutEnd,this),t.on_(u.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=this.canvas=this.config=null)}}function ct(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[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)})),s&&e.fillRect(i.x,i.y+s,i.width,o)}function ht(t,e,i){const{strokeAlign:n}=e.__,s="string"!=typeof t;switch(n){case"center":i.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?pt(t,!0,e,i):ft(e,i);break;case"inside":ut("inside",t,s,e,i);break;case"outside":ut("outside",t,s,e,i)}}function ut(t,e,i,n,s){const{__strokeWidth:o,__font:a}=n.__,r=s.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,n.__),r.font=a,i?pt(e,!0,n,r):ft(n,r),r.blendMode="outside"===t?"destination-out":"destination-in",ct(n,r),r.blendMode="normal",n.__worldFlipped?s.copyWorldByReset(r,n.__nowWorld):s.copyWorldToInner(r,n.__nowWorld,n.__layout.renderBounds),r.recycle(n.__nowWorld)}function ft(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[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)})),s&&e.strokeRect(i.x,i.y+s,i.width,o)}function pt(t,e,i,n){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&D.checkImage(i,n,s,!1)||s.style&&(n.strokeStyle=s.style,s.blendMode?(n.saveBlendMode(s.blendMode),e?ft(i,n):n.stroke(),n.restoreBlendMode()):e?ft(i,n):n.stroke())}Object.assign(r,{watcher:(t,e)=>new Q(t,e),layouter:(t,e)=>new rt(t,e),renderer:(t,e,i)=>new lt(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,n)=>{}}),i.layout=rt.fullLayout;const{getSpread:gt,getOuterOf:_t,getByMove:wt,getIntersectData:yt}=R;let mt;function vt(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:n}=i.__layout;switch(e.type){case"solid":let{type:s,blendMode:o,color:a,opacity:r}=e;return{type:s,blendMode:o,style:I.string(a,r)};case"image":return D.image(i,t,e,n,!mt||!mt[e.url]);case"linear":return P.linearGradient(e,n);case"radial":return P.radialGradient(e,n);case"angular":return P.conicGradient(e,n);default:return void 0!==e.r?{type:"solid",style:I.string(e)}:void 0}}const xt={compute:function(t,e){const i=e.__,n=[];let s,o=i.__input[t];o instanceof Array||(o=[o]),mt=D.recycleImage(t,i);for(let i,s=0,a=o.length;s<a;s++)i=vt(t,o[s],e),i&&n.push(i);i["_"+t]=n.length?n:void 0,n.length&&n[0].image&&(s=n[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=s:i.__pixelStroke=s},fill:function(t,e,i){i.fillStyle=t,e.__.__font?ct(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let n;const{windingRule:s,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)n=t[a],n.image&&D.checkImage(e,i,n,!o)||n.style&&(i.fillStyle=n.style,n.transform?(i.save(),i.transform(n.transform),n.blendMode&&(i.blendMode=n.blendMode),o?ct(e,i):s?i.fill(s):i.fill(),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),o?ct(e,i):s?i.fill(s):i.fill(),i.restoreBlendMode()):o?ct(e,i):s?i.fill(s):i.fill())},fillText:ct,stroke:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)ht(t,e,i);else switch(o){case"center":i.setStroke(t,s,n),i.stroke();break;case"inside":i.save(),i.setStroke(t,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*s,n),e.__drawRenderPath(o),o.stroke(),n.windingRule?o.clip(n.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 n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)ht(t,e,i);else switch(o){case"center":i.setStroke(void 0,s,n),pt(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),pt(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*s,n),pt(t,!1,e,a),n.windingRule?a.clip(n.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:ht,drawTextStroke:ft,shape:function(t,e,i){const n=e.getSameCanvas(),s=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:c}=s;if(l<0&&(l=-l),c<0&&(c=-c),e.bounds.includes(s))d=n,o=r=s;else{const{renderShapeSpread:n}=t.__layout,h=yt(n?gt(e.bounds,l===c?n*l:[n*c,n*l]):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,c*=f),r=_t(s,a),o=wt(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(n,i),{canvas:n,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:c}}};let bt={};const{get:Bt,rotateOfOuter:Rt,translate:kt,scaleOfOuter:St,scale:Et,rotate:Lt}=k;function At(t,e,i,n,s,o,a){const r=Bt();kt(r,e.x+i,e.y+n),Et(r,s,o),a&&Rt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Ot(t,e,i,n,s,o,a){const r=Bt();kt(r,e.x+i,e.y+n),s&&Et(r,s,o),a&&Lt(r,a),t.transform=r}function Wt(t,e,i,n,s,o,a,r,d,l){const c=Bt();if(d)if("center"===l)Rt(c,{x:i/2,y:n/2},d);else switch(Lt(c,d),d){case 90:kt(c,n,0);break;case 180:kt(c,i,n);break;case 270:kt(c,0,i)}bt.x=e.x+s,bt.y=e.y+o,kt(c,bt.x,bt.y),a&&St(c,bt,a,r),t.transform=c}const{get:Ct,translate:Tt}=k,Mt=new y,Dt={},It={};function Pt(t,e,i,n){const{blendMode:s,sync:o}=i;s&&(t.blendMode=s),o&&(t.sync=o),t.data=zt(i,n,e)}function zt(t,e,i){let{width:n,height:s}=i;t.padding&&(e=Mt.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{opacity:o,mode:a,align:r,offset:d,scale:l,size:c,rotation:h,repeat:u}=t,f=e.width===n&&e.height===s,p={mode:a},g="center"!==r&&(h||0)%180==90,_=g?s:n,w=g?n:s;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)(l||c)&&(S.getScaleData(l,c,i,It),y=It.scaleX,m=It.scaleY);else if(!f||h){const t=e.width/_,i=e.height/w;y=m="fit"===a?Math.min(t,i):Math.max(t,i),v+=(e.width-n*y)/2,x+=(e.height-s*m)/2}if(r){const t={x:v,y:x,width:_,height:w};y&&(t.width*=y,t.height*=m),E.toPoint(r,t,e,Dt,!0),v+=Dt.x,x+=Dt.y}switch(d&&(v+=d.x,x+=d.y),a){case"stretch":f||(n=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||h)&&Ot(p,e,v,x,y,m,h);break;case"repeat":(!f||y||h)&&Wt(p,e,n,s,v,x,y,m,h,r),u||(p.repeat="repeat");break;default:y&&At(p,e,v,x,y,m,h)}return p.transform||(e.x||e.y)&&(p.transform=Ct(),Tt(p.transform,e.x,e.y)),y&&"stretch"!==a&&(p.scaleX=y,p.scaleY=m),p.width=n,p.height=s,o&&(p.opacity=o),u&&(p.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),p}let Ft,Vt=new y;const{isSame:Yt}=R;function Ut(t,e,i,n,s,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=n.width/e.pixelRatio,e.__naturalHeight=n.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return s.data||Pt(s,n,i,o),!0}function Xt(t,e){jt(t,L.LOAD,e)}function Nt(t,e){jt(t,L.LOADED,e)}function Gt(t,e,i){e.error=i,t.forceUpdate("surface"),jt(t,L.ERROR,e)}function jt(t,e,i){t.hasEvent(e)&&t.emitEvent(new L(e,i))}function qt(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:Ht,scale:Qt,copy:Jt}=k,{ceil:Zt,abs:$t}=Math;function Kt(t,e,n){let{scaleX:s,scaleY:o}=B.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o+"-"+n;if(e.patternId===a||t.destroyed)return!1;{s=$t(s),o=$t(o);const{image:t,data:r}=e;let d,l,{width:c,height:h,scaleX:u,scaleY:f,opacity:p,transform:g,repeat:_}=r;u&&(l=Ht(),Jt(l,g),Qt(l,1/u,1/f),s*=u,o*=f),s*=n,o*=n,c*=s,h*=o;const w=c*h;if(!_&&w>i.image.maxCacheSize)return!1;let y=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(s/=d,o/=d,c/=d,h/=d),u&&(s/=u,o/=f),(g||1!==s||1!==o)&&(l||(l=Ht(),g&&Jt(l,g)),Qt(l,1/s,1/o));const m=t.getCanvas(Zt(c)||1,Zt(h)||1,p),v=t.getPattern(m,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=v,e.patternId=a,!0}}function te(t,e,i,n){return new(i||(i=Promise))((function(s,o){function a(t){try{d(n.next(t))}catch(t){o(t)}}function r(t){try{d(n.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}d((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:ee}=Math;const ie={image:function(t,e,i,n,s){let o,a;const r=B.get(i);return Ft&&i===Ft.paint&&Yt(n,Ft.boxBounds)?o=Ft.leafPaint:(o={type:i.type,image:r},Ft=r.use>1?{leafPaint:o,paint:i,boxBounds:Vt.set(n)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Ut(t,e,i,r,o,n),s&&(Xt(t,a),Nt(t,a))):r.error?s&&Gt(t,a,r.error):(s&&(qt(t,!0),Xt(t,a)),o.loadId=r.load((()=>{qt(t,!1),t.destroyed||(Ut(t,e,i,r,o,n)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Nt(t,a)),o.loadId=null}),(e=>{qt(t,!1),Gt(t,a,e),o.loadId=null}))),o},checkImage:function(t,e,n,s){const{scaleX:o,scaleY:a}=B.patternLocked?t.__world:t.__nowWorld,{pixelRatio:r}=e;if(!n.data||n.patternId===o+"-"+a+"-"+r&&!z.running)return!1;{const{data:d}=n;if(s)if(d.repeat)s=!1;else{let{width:t,height:e}=d;t*=ee(o)*r,e*=ee(a)*r,d.scaleX&&(t*=d.scaleX,e*=d.scaleY),s=t*e>i.image.maxCacheSize||z.running}return s?(e.save(),t.windingRule?e.clip(t.windingRule):e.clip(),n.blendMode&&(e.blendMode=n.blendMode),d.opacity&&(e.opacity*=d.opacity),d.transform&&e.transform(d.transform),e.drawImage(n.image.view,0,0,d.width,d.height),e.restore(),!0):(!n.style||n.sync||z.running?Kt(t,n,r):n.patternTask||(n.patternTask=B.patternTasker.add((()=>te(this,void 0,void 0,(function*(){n.patternTask=null,e.bounds.hit(t.__nowWorld)&&Kt(t,n,r),t.forceUpdate("surface")}))),300)),!1)}},createPattern:Kt,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let n,s,o,a;for(let r=0,d=i.length;r<d;r++)n=i[r].image,a=n&&n.url,a&&(s||(s={}),s[a]=!0,B.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),n.unload(i[r].loadId,!o.some((t=>t.url===a)))));return s}return null},createData:Pt,getPatternData:zt,fillOrFitMode:At,clipMode:Ot,repeatMode:Wt},{toPoint:ne}=A,se={},oe={};function ae(t,e,i){if(e){let n;for(let s=0,o=e.length;s<o;s++)n=e[s],"string"==typeof n?t.addColorStop(s/(o-1),I.string(n,i)):t.addColorStop(n.offset,I.string(n.color,i))}}const{getAngle:re,getDistance:de}=O,{get:le,rotateOfOuter:ce,scaleOfOuter:he}=k,{toPoint:ue}=A,fe={},pe={};function ge(t,e,i,n,s){let o;const{width:a,height:r}=t;if(a!==r||n){const t=re(e,i);o=le(),s?(he(o,e,a/r*(n||1),1),ce(o,e,t+90)):(he(o,e,1,a/r*(n||1)),ce(o,e,t))}return o}const{getDistance:_e}=O,{toPoint:we}=A,ye={},me={};const ve={linearGradient:function(t,e){let{from:n,to:s,type:o,blendMode:a,opacity:r}=t;ne(n||"top",e,se),ne(s||"bottom",e,oe);const d=i.canvas.createLinearGradient(se.x,se.y,oe.x,oe.y);ae(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,e){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;ue(n||"center",e,fe),ue(s||"bottom",e,pe);const l=i.canvas.createRadialGradient(fe.x,fe.y,0,fe.x,fe.y,de(fe,pe));ae(l,t.stops,a);const c={type:o,style:l},h=ge(e,fe,pe,d,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(t,e){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;we(n||"center",e,ye),we(s||"bottom",e,me);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,ye.x,ye.y):i.canvas.createRadialGradient(ye.x,ye.y,0,ye.x,ye.y,_e(ye,me));ae(l,t.stops,a);const c={type:o,style:l},h=ge(e,ye,me,d||1,i.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:ge},{copy:xe,toOffsetOutBounds:be}=R,Be={},Re={};function ke(t,e,n,s){const{bounds:o,shapeBounds:a}=s;if(i.fullImageShadow){if(xe(Be,t.bounds),Be.x+=e.x-a.x,Be.y+=e.y-a.y,n){const{matrix:t}=s;Be.x-=(o.x+(t?t.e:0)+o.width/2)*(n-1),Be.y-=(o.y+(t?t.f:0)+o.height/2)*(n-1),Be.width*=n,Be.height*=n}t.copyWorld(s.canvas,t.bounds,Be)}else n&&(xe(Be,e),Be.x-=e.width/2*(n-1),Be.y-=e.height/2*(n-1),Be.width*=n,Be.height*=n),t.copyWorld(s.canvas,a,n?Be:e)}const{toOffsetOutBounds:Se}=R,Ee={};const Le={shadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;be(l,Re),r.forEach(((r,g)=>{f.setWorldShadow(Re.offsetX+r.x*h,Re.offsetY+r.y*u,r.blur*h,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,ke(f,Re,s,i),n=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),n=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(i.canvas,c,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),p&&g<p&&f.clearWorld(n,!0)})),f.recycle(n)},innerShadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Se(l,Ee),r.forEach(((r,g)=>{f.save(),f.setWorldShadow(Ee.offsetX+r.x*h,Ee.offsetY+r.y*u,r.blur*h),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,ke(f,Ee,s,i),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),n=o):(f.copyWorld(i.canvas,c,l,"source-out"),n=l),f.fillWorld(n,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),p&&g<p&&f.clearWorld(n,!0)})),f.recycle(n)},blur:function(t,e,i){const{blur:n}=t.__;i.setWorldBlur(n*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Ae}=m;function Oe(t,e,i,n,s,o){switch(e){case"alpha":!function(t,e,i,n){const s=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(n,s),n.recycle(s),Ce(t,e,i,1)}(t,i,n,s);break;case"opacity-path":Ce(t,i,n,o);break;case"path":i.restore()}}function We(t){return t.getSameCanvas(!1,!0)}function Ce(t,e,i,n){const s=t.__nowWorld;e.resetTransform(),e.opacity=n,e.copyWorld(i,s),i.recycle(s)}F.prototype.__renderMask=function(t,e){let i,n,s,o,a;const{children:r}=this;for(let d=0,l=r.length;d<l;d++)i=r[d],i.__.mask&&(a&&(Oe(this,a,t,s,n,o),n=s=null),"path"===i.__.mask?(i.opacity<1?(a="opacity-path",o=i.opacity,s||(s=We(t))):(a="path",t.save()),i.__clip(s||t,e)):(a="alpha",n||(n=We(t)),s||(s=We(t)),i.__render(n,e)),"clipping"!==i.__.mask)||Ae(i,e)||i.__render(s||t,e);Oe(this,a,t,s,n,o)};const Te=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Me=Te+"_#~&*+\\=|≮≯≈≠=…",De=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 Ie(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Pe=Ie("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ze=Ie("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Fe=Ie(Te),Ve=Ie(Me),Ye=Ie("- —/~|┆·");var Ue;!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"}(Ue||(Ue={}));const{Letter:Xe,Single:Ne,Before:Ge,After:je,Symbol:qe,Break:He}=Ue;function Qe(t){return Pe[t]?Xe:Ye[t]?He:ze[t]?Ge:Fe[t]?je:Ve[t]?qe:De.test(t)?Ne:Xe}const Je={trimRight(t){const{words:e}=t;let i,n=0,s=e.length;for(let o=s-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)n++,t.width-=i.width;n&&e.splice(s-n,n)}};function Ze(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:$e}=Je,{Letter:Ke,Single:ti,Before:ei,After:ii,Symbol:ni,Break:si}=Ue;let oi,ai,ri,di,li,ci,hi,ui,fi,pi,gi,_i,wi,yi,mi,vi,xi,bi=[];function Bi(t,e){fi&&!ui&&(ui=fi),oi.data.push({char:t,width:e}),ri+=e}function Ri(){di+=ri,oi.width=ri,ai.words.push(oi),oi={data:[]},ri=0}function ki(){yi&&(mi.paraNumber++,ai.paraStart=!0,yi=!1),fi&&(ai.startCharSize=ui,ai.endCharSize=fi,ui=0),ai.width=di,vi.width?$e(ai):xi&&Si(),bi.push(ai),ai={words:[]},di=0}function Si(){di>(mi.maxWidth||0)&&(mi.maxWidth=di)}const Ei=0,Li=1,Ai=2;const{top:Oi,right:Wi,bottom:Ci,left:Ti}=W;function Mi(t,e,i){const{bounds:n,rows:s}=t;n[e]+=i;for(let t=0;t<s.length;t++)s[t][e]+=i}const Di={getDrawData:function(t,e){"string"!=typeof t&&(t=String(t));let n=0,s=0,o=e.__getInput("width")||0,a=e.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=e;l&&(o?(n=l[Ti],o-=l[Wi]+l[Ti]):e.autoSizeAlign||(n=l[Ti]),a?(s=l[Oi],a-=l[Oi]+l[Ci]):e.autoSizeAlign||(s=l[Oi]));const c={bounds:{x:n,y:s,width:o,height:a},rows:[],paraNumber:0,font:i.canvas.font=d};return function(t,e,n){mi=t,bi=t.rows,vi=t.bounds,xi=!vi.width&&!n.autoSizeAlign;const{__letterSpacing:s,paraIndent:o,textCase:a}=n,{canvas:r}=i,{width:d,height:l}=vi;if(d||l||s||"none"!==a){const t="none"!==n.textWrap,i="break"===n.textWrap;yi=!0,gi=null,ui=hi=fi=ri=di=0,oi={data:[]},ai={words:[]};for(let n=0,l=e.length;n<l;n++)ci=e[n],"\n"===ci?(ri&&Ri(),ai.paraEnd=!0,ki(),yi=!0):(pi=Qe(ci),pi===Ke&&"none"!==a&&(ci=Ze(ci,a,!ri)),hi=r.measureText(ci).width,s&&(s<0&&(fi=hi),hi+=s),_i=pi===ti&&(gi===ti||gi===Ke)||gi===ti&&pi!==ii,wi=!(pi!==ei&&pi!==ti||gi!==ni&&gi!==ii),li=yi&&o?d-o:d,t&&d&&di+ri+hi>li&&(i?(ri&&Ri(),di&&ki()):(wi||(wi=pi===Ke&&gi==ii),_i||wi||pi===si||pi===ei||pi===ti||ri+hi>li?(ri&&Ri(),di&&ki()):di&&ki()))," "===ci&&!0!==yi&&di+ri===0||(pi===si?(" "===ci&&ri&&Ri(),Bi(ci,hi),Ri()):_i||wi?(ri&&Ri(),Bi(ci,hi)):Bi(ci,hi)),gi=pi);ri&&Ri(),di&&ki(),bi.length>0&&(bi[bi.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{mi.paraNumber++,di=r.measureText(t).width,bi.push({x:o||0,text:t,width:di,paraStart:!0}),xi&&Si()}))}(c,t,e),l&&function(t,e,i,n,s){if(!n&&i.autoSizeAlign)switch(i.textAlign){case"left":Mi(e,"x",t[Ti]);break;case"right":Mi(e,"x",-t[Wi])}if(!s&&i.autoSizeAlign)switch(i.verticalAlign){case"top":Mi(e,"y",t[Oi]);break;case"bottom":Mi(e,"y",-t[Ci])}}(l,c,e,o,a),function(t,e){const{rows:i,bounds:n}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:c,autoSizeAlign:h}=e;let{x:u,y:f,width:p,height:g}=n,_=s*i.length+(c?c*(t.paraNumber-1):0),w=o;if(r&&_>g)_=Math.max(g,s),t.overflow=i.length;else if(g||h)switch(l){case"middle":f+=(g-_)/2;break;case"bottom":f+=g-_}w+=f;let y,m,v,x=p||h?p:t.maxWidth;for(let o=0,l=i.length;o<l;o++){if(y=i[o],y.x=u,y.width<p||y.width>p&&!r)switch(d){case"center":y.x+=(x-y.width)/2;break;case"right":y.x+=x-y.width}y.paraStart&&c&&o>0&&(w+=c),y.y=w,w+=s,t.overflow>o&&w>_&&(y.isOverflow=!0,t.overflow=o+1),m=y.x,v=y.width,a<0&&(y.width<0?(v=-y.width+e.fontSize+a,m-=v,v+=e.fontSize):v-=a),m<n.x&&(n.x=m),v>n.width&&(n.width=v),r&&p&&p<v&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}n.y=f,n.height=_}(c,e),function(t,e,i,n){const{rows:s}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,l,c,h,u;s.forEach((t=>{t.words&&(c=a&&t.paraStart?a:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-c)/(t.words.length-1):0,h=r||t.isOverflow?Ei:l>.01?Li:Ai,t.isOverflow&&!r&&(t.textMode=!0),h===Ai?(t.x+=c,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=c,d=t.x,t.data=[],t.words.forEach((e=>{h===Li?(u={char:"",x:d},d=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,d,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,i,n){return t.forEach((t=>{(n||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(c,e,o),c.overflow&&function(t,e,n,s){if(!s)return;const{rows:o,overflow:a}=t;let{textOverflow:r}=e;if(o.splice(a),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?i.canvas.measureText(r).width:0,c=n+s-l;("none"===e.textWrap?o:[o[a-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let n=i;n>-1&&(t=e.data[n],d=t.x+t.width,!(n===i&&d<c));n--){if(d<c&&" "!==t.char){e.data.splice(n+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:r,x:d}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(c,e,n,o),"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}}(c,e),c}};const Ii={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!I.object)return t;t=I.object(t)}let n=void 0===t.a?1:t.a;i&&(n*=e);const s=t.r+","+t.g+","+t.b;return 1===n?"rgb("+s+")":"rgba("+s+","+n+")"}},{setPoint:Pi,addPoint:zi,toBounds:Fi}=C;const Vi={export(t,e,n){this.running=!0;const s=c.fileType(e),o=e.includes(".");return n=c.getExportOptions(n),function(t){Yi||(Yi=new T);return new Promise((e=>{Yi.add((()=>te(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((a=>new Promise((d=>{const l=t=>{a(t),d(),this.running=!1},{toURL:h}=i,{download:u}=i.origin;if("json"===s)return o&&u(h(JSON.stringify(t.toJSON(n.json)),"text"),e),l({data:!!o||t.toJSON(n.json)});if("svg"===s)return o&&u(h(t.toSVG(),"svg"),e),l({data:!!o||t.toSVG()});const{leafer:f}=t;f?(Ui(t),f.waitViewCompleted((()=>te(this,void 0,void 0,(function*(){let i,s,o=1,a=1;const{worldTransform:d,isLeafer:h,isFrame:u}=t,{slice:p,trim:g,onCanvas:_}=n,w=void 0===n.smooth?f.config.smooth:n.smooth,m=n.contextSettings||f.config.contextSettings,v=n.screenshot||t.isApp,x=h&&v&&void 0===n.fill?t.fill:n.fill,b=c.isOpaqueImage(e)||x,B=new M;if(v)i=!0===v?h?f.canvas.bounds:t.worldRenderBounds:v;else{let e=n.relative||(h?"inner":"local");switch(o=d.scaleX,a=d.scaleY,e){case"inner":B.set(d);break;case"local":B.set(d).divide(t.localTransform),o/=t.scaleX,a/=t.scaleY;break;case"world":o=1,a=1;break;case"page":e=t.leafer;default:B.set(d).divide(t.getTransform(e));const i=e.worldTransform;o/=o/i.scaleX,a/=a/i.scaleY}i=t.getBounds("render",e)}const R={scaleX:1,scaleY:1};S.getScaleData(n.scale,n.size,i,R);let k=n.pixelRatio||1;t.isApp&&(R.scaleX*=k,R.scaleY*=k,k=t.app.pixelRatio);const{x:E,y:L,width:A,height:O}=new y(i).scale(R.scaleX,R.scaleY),W={matrix:B.scale(1/R.scaleX,1/R.scaleY).invert().translate(-E,-L).withScale(1/o*R.scaleX,1/a*R.scaleY)};let C,T=r.canvas({width:Math.round(A),height:Math.round(O),pixelRatio:k,smooth:w,contextSettings:m});if(p&&(C=t,C.__worldOpacity=0,t=f,W.bounds=T.bounds),T.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(T,W),t.fill=e}else t.__render(T,W);if(T.restore(),C&&C.__updateWorldOpacity(),g){s=function(t){const{width:e,height:i}=t.view,{data:n}=t.context.getImageData(0,0,e,i);let s,o,a,r=0;for(let t=0;t<n.length;t+=4)0!==n[t+3]&&(s=r%e,o=(r-s)/e,a?zi(a,s,o):Pi(a={},s,o)),r++;const d=new y;return Fi(a,d),d.scale(1/t.pixelRatio).ceil()}(T);const t=T,{width:e,height:i}=s,n={x:0,y:0,width:e,height:i,pixelRatio:k};T=r.canvas(n),T.copyWorld(t,s,n)}b&&T.fillWorld(T.bounds,x||"#FFFFFF","destination-over"),_&&_(T);const D="canvas"===e?T:yield T.export(e,n);l({data:D,width:T.pixelWidth,height:T.pixelHeight,renderBounds:i,trimBounds:s})}))))):l({data:!1})}))))}};let Yi;function Ui(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Ui(t)))}const Xi=e.prototype,Ni=t.get("@leafer-ui/export");Xi.export=function(t,e){const{quality:i,blob:n}=c.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):n?this.toBlob(t,i):this.toDataURL(t,i)},Xi.toBlob=function(t,e){return new Promise((n=>{i.origin.canvasToBolb(this.view,t,e).then((t=>{n(t)})).catch((t=>{Ni.error(t),n(null)}))}))},Xi.toDataURL=function(t,e){return i.origin.canvasToDataURL(this.view,t,e)},Xi.saveAs=function(t,e){return new Promise((n=>{i.origin.canvasSaveAs(this.view,t,e).then((()=>{n(!0)})).catch((t=>{Ni.error(t),n(!1)}))}))},Object.assign(V,Di),Object.assign(I,Ii),Object.assign(Y,xt),Object.assign(D,ie),Object.assign(P,ve),Object.assign(U,Le),Object.assign(z,Vi),q();export{rt as Layouter,N as LeaferCanvas,lt as Renderer,Q as Watcher,q as useCanvas};
|
|
1
|
+
import{Debug as t,LeaferCanvasBase as e,Platform as i,DataHelper as n,canvasSizeAttrs as s,ResizeEvent as o,canvasPatch as a,Creator as r,LeaferImage as d,defineKey as l,FileHelper as c,LeafList as h,RenderEvent as u,ChildEvent as p,WatchEvent as f,PropertyEvent as g,LeafHelper as _,BranchHelper as w,Bounds as y,LeafBoundsHelper as m,LeafLevelList as v,LayoutEvent as x,Run as b,ImageManager as B,BoundsHelper as R,MatrixHelper as k,MathHelper as S,AlignHelper as E,ImageEvent as L,AroundHelper as A,PointHelper as O,Direction4 as W,TwoPointBoundsHelper as C,TaskProcessor as T,Matrix as M}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as D,ColorConvert as I,PaintGradient as P,Export as z,Group as F,TextConvert as V,Paint as Y,Effect as U}from"@leafer-ui/draw";export*from"@leafer-ui/draw";const X=t.get("LeaferCanvas");class G 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 n=i.children[t];n?(this.setAbsolute(n),i.insertBefore(e,n)):i.appendChild(n)}}init(){const{config:t}=this,e=t.view||t.canvas;e?this.__createViewFrom(e):this.__createView();const{style:n}=this.view;if(n.display||(n.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}i.syncDomFont&&!this.parentView&&(n.display="none",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="string"==typeof 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 X.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:n}=this.view;n.width=t+"px",n.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.clientBounds=this.view.getBoundingClientRect()}startAutoLayout(t,e){if(this.resizeListener=e,t){this.autoBounds=t;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),X.warn("no parent"))}catch(t){this.imitateResizeObserver()}}else window.addEventListener("resize",(()=>{const t=i.devicePixelRatio;if(this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}}))}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(t){const e=this.view,{x:n,y:s,width:o,height:a}=this.autoBounds.getBoundsFrom(t),r={width:o,height:a,pixelRatio:i.devicePixelRatio};if(!this.isSameSize(r)){const{style:t}=e;t.marginLeft=n+"px",t.marginTop=s+"px",this.emitResize(r)}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}emitResize(t){const e={};n.copyAttrs(e,this,s),this.resize(t),this.resizeListener&&void 0!==this.width&&this.resizeListener(new o(t,e))}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}a(CanvasRenderingContext2D.prototype),a(Path2D.prototype);const{mineType:N,fileType:j}=c;function q(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>t.toDataURL(N(e),i),canvasToBolb:(t,e,i)=>new Promise((n=>t.toBlob(n,N(e),i))),canvasSaveAs:(t,e,n)=>{const s=t.toDataURL(N(j(e)),n);return i.origin.download(s,e)},download:(t,e)=>new Promise((i=>{let n=document.createElement("a");n.href=t,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),i()})),loadImage:t=>new Promise(((e,n)=>{const s=new Image,{crossOrigin:o}=i.image;o&&(s.setAttribute("crossOrigin",o),s.crossOrigin=o),s.onload=()=>{e(s)},s.onerror=t=>{n(t)},s.src=i.image.getRealURL(t)}))},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=r.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(r,{canvas:(t,e)=>new G(t,e),image:t=>new d(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},l(i,"devicePixelRatio",{get:()=>Math.max(1,devicePixelRatio)});const{userAgent:H}=navigator;H.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):H.indexOf("Safari")>-1&&-1===H.indexOf("Chrome")&&(i.fullImageShadow=!0),H.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):H.indexOf("Mac")>-1?i.os="Mac":H.indexOf("Linux")>-1&&(i.os="Linux");class Q{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new h;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 h,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(u.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===p.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 f(f.DATA,{updatedList:this.updatedList})),this.__updatedList=new h,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_([p.ADD,p.REMOVE],this.__onChildEvent,this),t.on_(f.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:J,updateBounds:Z,updateAllWorldOpacity:$}=_,{pushAllChildBranch:K,pushAllParent:tt}=w;const{worldBounds:et}=m,it={x:0,y:0,width:1e5,height:1e5};class nt{constructor(t){this.updatedBounds=new y,this.beforeBounds=new y,this.afterBounds=new y,t instanceof Array&&(t=new h(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:st,updateAllChange:ot}=_,at=t.get("Layouter");class rt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new v,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.running)return;const{target:t}=this;this.times=0;try{t.emit(x.START),this.layoutOnce(),t.emitEvent(new x(x.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(f.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=b.start("PartLayout"),{target:i,__updatedList:n}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=x,r=this.getBlocks(n);r.forEach((t=>t.setBefore())),i.emitEvent(new x(s,r,this.times)),this.extraBlock=null,n.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(J(t,!0),e.add(t),t.isBranch&&K(t,e),tt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),tt(t,e)))}))}(n,this.__levelList),function(t){let e,i,n;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(i=e[t],i.isBranch&&i.__tempNumber){n=i.children;for(let t=0,e=n.length;t<e;t++)n[t].isBranch||Z(n[t])}Z(i)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&$(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(n),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new x(o,r,this.times)),i.emitEvent(new x(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,b.end(e)}fullLayout(){const t=b.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:n,AFTER:s}=x,o=this.getBlocks(new h(e));e.emitEvent(new x(i,o,this.times)),rt.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new x(n,o,this.times)),e.emitEvent(new x(s,o,this.times)),this.addBlocks(o),b.end(t)}static fullLayout(t){st(t,!0),t.isBranch?w.updateBounds(t):_.updateBounds(t),ot(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new nt([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new nt(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_(x.REQUEST,this.layout,this),t.on_(x.AGAIN,this.layoutAgain,this),t.on_(f.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const dt=t.get("Renderer");class lt{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=n.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(x.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new y,dt.log(e.innerName,"---\x3e");try{e.isApp||e.app.emit(u.CHILD_START,e),this.emitRender(u.START),this.renderOnce(t),this.emitRender(u.END,this.totalBounds),B.clearRecycled()}catch(t){this.rendering=!1,dt.error(t)}dt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return dt.warn("rendering");if(this.times>3)return dt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new y,this.renderOptions={},t)this.emitRender(u.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(u.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(u.RENDER,this.renderBounds,this.renderOptions),this.emitRender(u.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;if(!e)return dt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const i=b.start("PartRender"),{canvas:n}=this,s=e.getIntersect(n.bounds),o=e.includes(this.target.__world),a=new y(s);n.save(),o&&!t.showRepaint?n.clear():(s.spread(10+1/this.canvas.pixelRatio).ceil(),n.clearWorld(s,!0),n.clipWorld(s,!0)),this.__render(s,o,a),n.restore(),b.end(i)}fullRender(){const t=b.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),b.end(t)}__render(e,i,n){const s=e.includes(this.target.__world)?{includes:i}:{bounds:e,includes:i};this.needFill&&this.canvas.fillWorld(e,this.config.fill),t.showRepaint&&this.canvas.strokeWorld(e,"red"),this.target.__render(this.canvas,s),this.renderBounds=n=n||e,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=n:this.totalBounds.add(n),t.showHitView&&this.renderHitView(s),t.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender(n)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new y;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();i.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.changed&&this.canvas.view&&this.render(),this.target.emit(u.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new y(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 y(0,0,1,1)),this.changed=!0}}__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||dt.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 u(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.REQUEST,this.update,this),t.on_(x.END,this.__onLayoutEnd,this),t.on_(u.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=this.canvas=this.config=null)}}function ct(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[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)})),s&&e.fillRect(i.x,i.y+s,i.width,o)}function ht(t,e,i){const{strokeAlign:n}=e.__,s="string"!=typeof t;switch(n){case"center":i.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?ft(t,!0,e,i):pt(e,i);break;case"inside":ut("inside",t,s,e,i);break;case"outside":ut("outside",t,s,e,i)}}function ut(t,e,i,n,s){const{__strokeWidth:o,__font:a}=n.__,r=s.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,n.__),r.font=a,i?ft(e,!0,n,r):pt(n,r),r.blendMode="outside"===t?"destination-out":"destination-in",ct(n,r),r.blendMode="normal",n.__worldFlipped?s.copyWorldByReset(r,n.__nowWorld):s.copyWorldToInner(r,n.__nowWorld,n.__layout.renderBounds),r.recycle(n.__nowWorld)}function pt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[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)})),s&&e.strokeRect(i.x,i.y+s,i.width,o)}function ft(t,e,i,n){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&D.checkImage(i,n,s,!1)||s.style&&(n.strokeStyle=s.style,s.blendMode?(n.saveBlendMode(s.blendMode),e?pt(i,n):n.stroke(),n.restoreBlendMode()):e?pt(i,n):n.stroke())}Object.assign(r,{watcher:(t,e)=>new Q(t,e),layouter:(t,e)=>new rt(t,e),renderer:(t,e,i)=>new lt(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,n)=>{}}),i.layout=rt.fullLayout;const{getSpread:gt,getOuterOf:_t,getByMove:wt,getIntersectData:yt}=R;let mt;function vt(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:n}=i.__layout;switch(e.type){case"solid":let{type:s,blendMode:o,color:a,opacity:r}=e;return{type:s,blendMode:o,style:I.string(a,r)};case"image":return D.image(i,t,e,n,!mt||!mt[e.url]);case"linear":return P.linearGradient(e,n);case"radial":return P.radialGradient(e,n);case"angular":return P.conicGradient(e,n);default:return void 0!==e.r?{type:"solid",style:I.string(e)}:void 0}}const xt={compute:function(t,e){const i=e.__,n=[];let s,o=i.__input[t];o instanceof Array||(o=[o]),mt=D.recycleImage(t,i);for(let i,s=0,a=o.length;s<a;s++)i=vt(t,o[s],e),i&&n.push(i);i["_"+t]=n.length?n:void 0,n.length&&n[0].image&&(s=n[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=s:i.__pixelStroke=s},fill:function(t,e,i){i.fillStyle=t,e.__.__font?ct(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let n;const{windingRule:s,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)n=t[a],n.image&&D.checkImage(e,i,n,!o)||n.style&&(i.fillStyle=n.style,n.transform?(i.save(),i.transform(n.transform),n.blendMode&&(i.blendMode=n.blendMode),o?ct(e,i):s?i.fill(s):i.fill(),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),o?ct(e,i):s?i.fill(s):i.fill(),i.restoreBlendMode()):o?ct(e,i):s?i.fill(s):i.fill())},fillText:ct,stroke:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)ht(t,e,i);else switch(o){case"center":i.setStroke(t,s,n),i.stroke();break;case"inside":i.save(),i.setStroke(t,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*s,n),e.__drawRenderPath(o),o.stroke(),n.windingRule?o.clip(n.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 n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)ht(t,e,i);else switch(o){case"center":i.setStroke(void 0,s,n),ft(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),ft(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*s,n),ft(t,!1,e,a),n.windingRule?a.clip(n.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:ht,drawTextStroke:pt,shape:function(t,e,i){const n=e.getSameCanvas(),s=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:c}=s;if(l<0&&(l=-l),c<0&&(c=-c),e.bounds.includes(s))d=n,o=r=s;else{const{renderShapeSpread:n}=t.__layout,h=yt(n?gt(e.bounds,l===c?n*l:[n*c,n*l]):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:p}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,c*=p),r=_t(s,a),o=wt(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,p*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,p)})}return t.__renderShape(n,i),{canvas:n,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:c}}};let bt={};const{get:Bt,rotateOfOuter:Rt,translate:kt,scaleOfOuter:St,scale:Et,rotate:Lt}=k;function At(t,e,i,n,s,o,a){const r=Bt();kt(r,e.x+i,e.y+n),Et(r,s,o),a&&Rt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Ot(t,e,i,n,s,o,a){const r=Bt();kt(r,e.x+i,e.y+n),s&&Et(r,s,o),a&&Lt(r,a),t.transform=r}function Wt(t,e,i,n,s,o,a,r,d,l){const c=Bt();if(d)if("center"===l)Rt(c,{x:i/2,y:n/2},d);else switch(Lt(c,d),d){case 90:kt(c,n,0);break;case 180:kt(c,i,n);break;case 270:kt(c,0,i)}bt.x=e.x+s,bt.y=e.y+o,kt(c,bt.x,bt.y),a&&St(c,bt,a,r),t.transform=c}const{get:Ct,translate:Tt}=k,Mt=new y,Dt={},It={};function Pt(t,e,i,n){const{blendMode:s,sync:o}=i;s&&(t.blendMode=s),o&&(t.sync=o),t.data=zt(i,n,e)}function zt(t,e,i){let{width:n,height:s}=i;t.padding&&(e=Mt.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{opacity:o,mode:a,align:r,offset:d,scale:l,size:c,rotation:h,repeat:u}=t,p=e.width===n&&e.height===s,f={mode:a},g="center"!==r&&(h||0)%180==90,_=g?s:n,w=g?n:s;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)(l||c)&&(S.getScaleData(l,c,i,It),y=It.scaleX,m=It.scaleY);else if(!p||h){const t=e.width/_,i=e.height/w;y=m="fit"===a?Math.min(t,i):Math.max(t,i),v+=(e.width-n*y)/2,x+=(e.height-s*m)/2}if(r){const t={x:v,y:x,width:_,height:w};y&&(t.width*=y,t.height*=m),E.toPoint(r,t,e,Dt,!0),v+=Dt.x,x+=Dt.y}switch(d&&(v+=d.x,x+=d.y),a){case"stretch":p||(n=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||h)&&Ot(f,e,v,x,y,m,h);break;case"repeat":(!p||y||h)&&Wt(f,e,n,s,v,x,y,m,h,r),u||(f.repeat="repeat");break;default:y&&At(f,e,v,x,y,m,h)}return f.transform||(e.x||e.y)&&(f.transform=Ct(),Tt(f.transform,e.x,e.y)),y&&"stretch"!==a&&(f.scaleX=y,f.scaleY=m),f.width=n,f.height=s,o&&(f.opacity=o),u&&(f.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),f}let Ft,Vt=new y;const{isSame:Yt}=R;function Ut(t,e,i,n,s,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=n.width/e.pixelRatio,e.__naturalHeight=n.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return s.data||Pt(s,n,i,o),!0}function Xt(t,e){jt(t,L.LOAD,e)}function Gt(t,e){jt(t,L.LOADED,e)}function Nt(t,e,i){e.error=i,t.forceUpdate("surface"),jt(t,L.ERROR,e)}function jt(t,e,i){t.hasEvent(e)&&t.emitEvent(new L(e,i))}function qt(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:Ht,scale:Qt,copy:Jt}=k,{ceil:Zt,abs:$t}=Math;function Kt(t,e,n){let{scaleX:s,scaleY:o}=B.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o+"-"+n;if(e.patternId===a||t.destroyed)return!1;{s=$t(s),o=$t(o);const{image:t,data:r}=e;let d,l,{width:c,height:h,scaleX:u,scaleY:p,opacity:f,transform:g,repeat:_}=r;u&&(l=Ht(),Jt(l,g),Qt(l,1/u,1/p),s*=u,o*=p),s*=n,o*=n,c*=s,h*=o;const w=c*h;if(!_&&w>i.image.maxCacheSize)return!1;let y=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(s/=d,o/=d,c/=d,h/=d),u&&(s/=u,o/=p),(g||1!==s||1!==o)&&(l||(l=Ht(),g&&Jt(l,g)),Qt(l,1/s,1/o));const m=t.getCanvas(Zt(c)||1,Zt(h)||1,f),v=t.getPattern(m,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=v,e.patternId=a,!0}}function te(t,e,i,n){return new(i||(i=Promise))((function(s,o){function a(t){try{d(n.next(t))}catch(t){o(t)}}function r(t){try{d(n.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}d((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:ee}=Math;const ie={image:function(t,e,i,n,s){let o,a;const r=B.get(i);return Ft&&i===Ft.paint&&Yt(n,Ft.boxBounds)?o=Ft.leafPaint:(o={type:i.type,image:r},Ft=r.use>1?{leafPaint:o,paint:i,boxBounds:Vt.set(n)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Ut(t,e,i,r,o,n),s&&(Xt(t,a),Gt(t,a))):r.error?s&&Nt(t,a,r.error):(s&&(qt(t,!0),Xt(t,a)),o.loadId=r.load((()=>{qt(t,!1),t.destroyed||(Ut(t,e,i,r,o,n)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Gt(t,a)),o.loadId=null}),(e=>{qt(t,!1),Nt(t,a,e),o.loadId=null}))),o},checkImage:function(t,e,n,s){const{scaleX:o,scaleY:a}=B.patternLocked?t.__world:t.__nowWorld,{pixelRatio:r}=e;if(!n.data||n.patternId===o+"-"+a+"-"+r&&!z.running)return!1;{const{data:d}=n;if(s)if(d.repeat)s=!1;else{let{width:t,height:e}=d;t*=ee(o)*r,e*=ee(a)*r,d.scaleX&&(t*=d.scaleX,e*=d.scaleY),s=t*e>i.image.maxCacheSize||z.running}return s?(e.save(),t.windingRule?e.clip(t.windingRule):e.clip(),n.blendMode&&(e.blendMode=n.blendMode),d.opacity&&(e.opacity*=d.opacity),d.transform&&e.transform(d.transform),e.drawImage(n.image.view,0,0,d.width,d.height),e.restore(),!0):(!n.style||n.sync||z.running?Kt(t,n,r):n.patternTask||(n.patternTask=B.patternTasker.add((()=>te(this,void 0,void 0,(function*(){n.patternTask=null,e.bounds.hit(t.__nowWorld)&&Kt(t,n,r),t.forceUpdate("surface")}))),300)),!1)}},createPattern:Kt,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let n,s,o,a;for(let r=0,d=i.length;r<d;r++)n=i[r].image,a=n&&n.url,a&&(s||(s={}),s[a]=!0,B.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),n.unload(i[r].loadId,!o.some((t=>t.url===a)))));return s}return null},createData:Pt,getPatternData:zt,fillOrFitMode:At,clipMode:Ot,repeatMode:Wt},{toPoint:ne}=A,se={},oe={};function ae(t,e,i){if(e){let n;for(let s=0,o=e.length;s<o;s++)n=e[s],"string"==typeof n?t.addColorStop(s/(o-1),I.string(n,i)):t.addColorStop(n.offset,I.string(n.color,i))}}const{getAngle:re,getDistance:de}=O,{get:le,rotateOfOuter:ce,scaleOfOuter:he}=k,{toPoint:ue}=A,pe={},fe={};function ge(t,e,i,n,s){let o;const{width:a,height:r}=t;if(a!==r||n){const t=re(e,i);o=le(),s?(he(o,e,a/r*(n||1),1),ce(o,e,t+90)):(he(o,e,1,a/r*(n||1)),ce(o,e,t))}return o}const{getDistance:_e}=O,{toPoint:we}=A,ye={},me={};const ve={linearGradient:function(t,e){let{from:n,to:s,type:o,blendMode:a,opacity:r}=t;ne(n||"top",e,se),ne(s||"bottom",e,oe);const d=i.canvas.createLinearGradient(se.x,se.y,oe.x,oe.y);ae(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,e){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;ue(n||"center",e,pe),ue(s||"bottom",e,fe);const l=i.canvas.createRadialGradient(pe.x,pe.y,0,pe.x,pe.y,de(pe,fe));ae(l,t.stops,a);const c={type:o,style:l},h=ge(e,pe,fe,d,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(t,e){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;we(n||"center",e,ye),we(s||"bottom",e,me);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,ye.x,ye.y):i.canvas.createRadialGradient(ye.x,ye.y,0,ye.x,ye.y,_e(ye,me));ae(l,t.stops,a);const c={type:o,style:l},h=ge(e,ye,me,d||1,i.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:ge},{copy:xe,toOffsetOutBounds:be}=R,Be={},Re={};function ke(t,e,n,s){const{bounds:o,shapeBounds:a}=s;if(i.fullImageShadow){if(xe(Be,t.bounds),Be.x+=e.x-a.x,Be.y+=e.y-a.y,n){const{matrix:t}=s;Be.x-=(o.x+(t?t.e:0)+o.width/2)*(n-1),Be.y-=(o.y+(t?t.f:0)+o.height/2)*(n-1),Be.width*=n,Be.height*=n}t.copyWorld(s.canvas,t.bounds,Be)}else n&&(xe(Be,e),Be.x-=e.width/2*(n-1),Be.y-=e.height/2*(n-1),Be.width*=n,Be.height*=n),t.copyWorld(s.canvas,a,n?Be:e)}const{toOffsetOutBounds:Se}=R,Ee={};const Le={shadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=i,p=e.getSameCanvas(),f=r.length-1;be(l,Re),r.forEach(((r,g)=>{p.setWorldShadow(Re.offsetX+r.x*h,Re.offsetY+r.y*u,r.blur*h,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,ke(p,Re,s,i),n=l,r.box&&(p.restore(),p.save(),d&&(p.copyWorld(p,l,o,"copy"),n=o),d?p.copyWorld(d,o,o,"destination-out"):p.copyWorld(i.canvas,c,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(p,n,o,r.blendMode):e.copyWorldToInner(p,n,a.renderBounds,r.blendMode),f&&g<f&&p.clearWorld(n,!0)})),p.recycle(n)},innerShadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=i,p=e.getSameCanvas(),f=r.length-1;Se(l,Ee),r.forEach(((r,g)=>{p.save(),p.setWorldShadow(Ee.offsetX+r.x*h,Ee.offsetY+r.y*u,r.blur*h),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,ke(p,Ee,s,i),p.restore(),d?(p.copyWorld(p,l,o,"copy"),p.copyWorld(d,o,o,"source-out"),n=o):(p.copyWorld(i.canvas,c,l,"source-out"),n=l),p.fillWorld(n,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(p,n,o,r.blendMode):e.copyWorldToInner(p,n,a.renderBounds,r.blendMode),f&&g<f&&p.clearWorld(n,!0)})),p.recycle(n)},blur:function(t,e,i){const{blur:n}=t.__;i.setWorldBlur(n*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Ae}=m;function Oe(t,e,i,n,s,o){switch(e){case"grayscale":s.useGrayscaleAlpha(t.__nowWorld);case"alpha":!function(t,e,i,n){const s=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(n,s),n.recycle(s),Ce(t,e,i,1)}(t,i,n,s);break;case"opacity-path":Ce(t,i,n,o);break;case"path":i.restore()}}function We(t){return t.getSameCanvas(!1,!0)}function Ce(t,e,i,n){const s=t.__nowWorld;e.resetTransform(),e.opacity=n,e.copyWorld(i,s),i.recycle(s)}F.prototype.__renderMask=function(t,e){let i,n,s,o,a,r;const{children:d}=this;for(let l=0,c=d.length;l<c;l++)i=d[l],r=i.__.mask,r&&(a&&(Oe(this,a,t,s,n,o),n=s=null),"path"===r||"clipping-path"===r?(i.opacity<1?(a="opacity-path",o=i.opacity,s||(s=We(t))):(a="path",t.save()),i.__clip(s||t,e)):(a="grayscale"===r?"grayscale":"alpha",n||(n=We(t)),s||(s=We(t)),i.__render(n,e)),"clipping"!==r&&"clipping-path"!==r)||Ae(i,e)||i.__render(s||t,e);Oe(this,a,t,s,n,o)};const Te=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Me=Te+"_#~&*+\\=|≮≯≈≠=…",De=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 Ie(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Pe=Ie("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ze=Ie("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Fe=Ie(Te),Ve=Ie(Me),Ye=Ie("- —/~|┆·");var Ue;!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"}(Ue||(Ue={}));const{Letter:Xe,Single:Ge,Before:Ne,After:je,Symbol:qe,Break:He}=Ue;function Qe(t){return Pe[t]?Xe:Ye[t]?He:ze[t]?Ne:Fe[t]?je:Ve[t]?qe:De.test(t)?Ge:Xe}const Je={trimRight(t){const{words:e}=t;let i,n=0,s=e.length;for(let o=s-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)n++,t.width-=i.width;n&&e.splice(s-n,n)}};function Ze(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:$e}=Je,{Letter:Ke,Single:ti,Before:ei,After:ii,Symbol:ni,Break:si}=Ue;let oi,ai,ri,di,li,ci,hi,ui,pi,fi,gi,_i,wi,yi,mi,vi,xi,bi=[];function Bi(t,e){pi&&!ui&&(ui=pi),oi.data.push({char:t,width:e}),ri+=e}function Ri(){di+=ri,oi.width=ri,ai.words.push(oi),oi={data:[]},ri=0}function ki(){yi&&(mi.paraNumber++,ai.paraStart=!0,yi=!1),pi&&(ai.startCharSize=ui,ai.endCharSize=pi,ui=0),ai.width=di,vi.width?$e(ai):xi&&Si(),bi.push(ai),ai={words:[]},di=0}function Si(){di>(mi.maxWidth||0)&&(mi.maxWidth=di)}const Ei=0,Li=1,Ai=2;const{top:Oi,right:Wi,bottom:Ci,left:Ti}=W;function Mi(t,e,i){const{bounds:n,rows:s}=t;n[e]+=i;for(let t=0;t<s.length;t++)s[t][e]+=i}const Di={getDrawData:function(t,e){"string"!=typeof t&&(t=String(t));let n=0,s=0,o=e.__getInput("width")||0,a=e.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=e;l&&(o?(n=l[Ti],o-=l[Wi]+l[Ti]):e.autoSizeAlign||(n=l[Ti]),a?(s=l[Oi],a-=l[Oi]+l[Ci]):e.autoSizeAlign||(s=l[Oi]));const c={bounds:{x:n,y:s,width:o,height:a},rows:[],paraNumber:0,font:i.canvas.font=d};return function(t,e,n){mi=t,bi=t.rows,vi=t.bounds,xi=!vi.width&&!n.autoSizeAlign;const{__letterSpacing:s,paraIndent:o,textCase:a}=n,{canvas:r}=i,{width:d,height:l}=vi;if(d||l||s||"none"!==a){const t="none"!==n.textWrap,i="break"===n.textWrap;yi=!0,gi=null,ui=hi=pi=ri=di=0,oi={data:[]},ai={words:[]};for(let n=0,l=e.length;n<l;n++)ci=e[n],"\n"===ci?(ri&&Ri(),ai.paraEnd=!0,ki(),yi=!0):(fi=Qe(ci),fi===Ke&&"none"!==a&&(ci=Ze(ci,a,!ri)),hi=r.measureText(ci).width,s&&(s<0&&(pi=hi),hi+=s),_i=fi===ti&&(gi===ti||gi===Ke)||gi===ti&&fi!==ii,wi=!(fi!==ei&&fi!==ti||gi!==ni&&gi!==ii),li=yi&&o?d-o:d,t&&d&&di+ri+hi>li&&(i?(ri&&Ri(),di&&ki()):(wi||(wi=fi===Ke&&gi==ii),_i||wi||fi===si||fi===ei||fi===ti||ri+hi>li?(ri&&Ri(),di&&ki()):di&&ki()))," "===ci&&!0!==yi&&di+ri===0||(fi===si?(" "===ci&&ri&&Ri(),Bi(ci,hi),Ri()):_i||wi?(ri&&Ri(),Bi(ci,hi)):Bi(ci,hi)),gi=fi);ri&&Ri(),di&&ki(),bi.length>0&&(bi[bi.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{mi.paraNumber++,di=r.measureText(t).width,bi.push({x:o||0,text:t,width:di,paraStart:!0}),xi&&Si()}))}(c,t,e),l&&function(t,e,i,n,s){if(!n&&i.autoSizeAlign)switch(i.textAlign){case"left":Mi(e,"x",t[Ti]);break;case"right":Mi(e,"x",-t[Wi])}if(!s&&i.autoSizeAlign)switch(i.verticalAlign){case"top":Mi(e,"y",t[Oi]);break;case"bottom":Mi(e,"y",-t[Ci])}}(l,c,e,o,a),function(t,e){const{rows:i,bounds:n}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:c,autoSizeAlign:h}=e;let{x:u,y:p,width:f,height:g}=n,_=s*i.length+(c?c*(t.paraNumber-1):0),w=o;if(r&&_>g)_=Math.max(g,s),t.overflow=i.length;else if(g||h)switch(l){case"middle":p+=(g-_)/2;break;case"bottom":p+=g-_}w+=p;let y,m,v,x=f||h?f:t.maxWidth;for(let o=0,l=i.length;o<l;o++){if(y=i[o],y.x=u,y.width<f||y.width>f&&!r)switch(d){case"center":y.x+=(x-y.width)/2;break;case"right":y.x+=x-y.width}y.paraStart&&c&&o>0&&(w+=c),y.y=w,w+=s,t.overflow>o&&w>_&&(y.isOverflow=!0,t.overflow=o+1),m=y.x,v=y.width,a<0&&(y.width<0?(v=-y.width+e.fontSize+a,m-=v,v+=e.fontSize):v-=a),m<n.x&&(n.x=m),v>n.width&&(n.width=v),r&&f&&f<v&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}n.y=p,n.height=_}(c,e),function(t,e,i,n){const{rows:s}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,l,c,h,u;s.forEach((t=>{t.words&&(c=a&&t.paraStart?a:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-c)/(t.words.length-1):0,h=r||t.isOverflow?Ei:l>.01?Li:Ai,t.isOverflow&&!r&&(t.textMode=!0),h===Ai?(t.x+=c,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=c,d=t.x,t.data=[],t.words.forEach((e=>{h===Li?(u={char:"",x:d},d=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,d,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,i,n){return t.forEach((t=>{(n||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(c,e,o),c.overflow&&function(t,e,n,s){if(!s)return;const{rows:o,overflow:a}=t;let{textOverflow:r}=e;if(o.splice(a),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?i.canvas.measureText(r).width:0,c=n+s-l;("none"===e.textWrap?o:[o[a-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let n=i;n>-1&&(t=e.data[n],d=t.x+t.width,!(n===i&&d<c));n--){if(d<c&&" "!==t.char){e.data.splice(n+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:r,x:d}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(c,e,n,o),"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}}(c,e),c}};const Ii={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!I.object)return t;t=I.object(t)}let n=void 0===t.a?1:t.a;i&&(n*=e);const s=t.r+","+t.g+","+t.b;return 1===n?"rgb("+s+")":"rgba("+s+","+n+")"}},{setPoint:Pi,addPoint:zi,toBounds:Fi}=C;const Vi={export(t,e,n){this.running=!0;const s=c.fileType(e),o=e.includes(".");return n=c.getExportOptions(n),function(t){Yi||(Yi=new T);return new Promise((e=>{Yi.add((()=>te(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((a=>new Promise((d=>{const l=t=>{a(t),d(),this.running=!1},{toURL:h}=i,{download:u}=i.origin;if("json"===s)return o&&u(h(JSON.stringify(t.toJSON(n.json)),"text"),e),l({data:!!o||t.toJSON(n.json)});if("svg"===s)return o&&u(h(t.toSVG(),"svg"),e),l({data:!!o||t.toSVG()});const{leafer:p}=t;p?(Ui(t),p.waitViewCompleted((()=>te(this,void 0,void 0,(function*(){let i,s,o=1,a=1;const{worldTransform:d,isLeafer:h,isFrame:u}=t,{slice:f,trim:g,onCanvas:_}=n,w=void 0===n.smooth?p.config.smooth:n.smooth,m=n.contextSettings||p.config.contextSettings,v=n.screenshot||t.isApp,x=h&&v&&void 0===n.fill?t.fill:n.fill,b=c.isOpaqueImage(e)||x,B=new M;if(v)i=!0===v?h?p.canvas.bounds:t.worldRenderBounds:v;else{let e=n.relative||(h?"inner":"local");switch(o=d.scaleX,a=d.scaleY,e){case"inner":B.set(d);break;case"local":B.set(d).divide(t.localTransform),o/=t.scaleX,a/=t.scaleY;break;case"world":o=1,a=1;break;case"page":e=t.leafer;default:B.set(d).divide(t.getTransform(e));const i=e.worldTransform;o/=o/i.scaleX,a/=a/i.scaleY}i=t.getBounds("render",e)}const R={scaleX:1,scaleY:1};S.getScaleData(n.scale,n.size,i,R);let k=n.pixelRatio||1;t.isApp&&(R.scaleX*=k,R.scaleY*=k,k=t.app.pixelRatio);const{x:E,y:L,width:A,height:O}=new y(i).scale(R.scaleX,R.scaleY),W={matrix:B.scale(1/R.scaleX,1/R.scaleY).invert().translate(-E,-L).withScale(1/o*R.scaleX,1/a*R.scaleY)};let C,T=r.canvas({width:Math.round(A),height:Math.round(O),pixelRatio:k,smooth:w,contextSettings:m});if(f&&(C=t,C.__worldOpacity=0,t=p,W.bounds=T.bounds),T.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(T,W),t.fill=e}else t.__render(T,W);if(T.restore(),C&&C.__updateWorldOpacity(),g){s=function(t){const{width:e,height:i}=t.view,{data:n}=t.context.getImageData(0,0,e,i);let s,o,a,r=0;for(let t=0;t<n.length;t+=4)0!==n[t+3]&&(s=r%e,o=(r-s)/e,a?zi(a,s,o):Pi(a={},s,o)),r++;const d=new y;return Fi(a,d),d.scale(1/t.pixelRatio).ceil()}(T);const t=T,{width:e,height:i}=s,n={x:0,y:0,width:e,height:i,pixelRatio:k};T=r.canvas(n),T.copyWorld(t,s,n)}b&&T.fillWorld(T.bounds,x||"#FFFFFF","destination-over"),_&&_(T);const D="canvas"===e?T:yield T.export(e,n);l({data:D,width:T.pixelWidth,height:T.pixelHeight,renderBounds:i,trimBounds:s})}))))):l({data:!1})}))))}};let Yi;function Ui(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Ui(t)))}const Xi=e.prototype,Gi=t.get("@leafer-ui/export");Xi.export=function(t,e){const{quality:i,blob:n}=c.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):n?this.toBlob(t,i):this.toDataURL(t,i)},Xi.toBlob=function(t,e){return new Promise((n=>{i.origin.canvasToBolb(this.view,t,e).then((t=>{n(t)})).catch((t=>{Gi.error(t),n(null)}))}))},Xi.toDataURL=function(t,e){return i.origin.canvasToDataURL(this.view,t,e)},Xi.saveAs=function(t,e){return new Promise((n=>{i.origin.canvasSaveAs(this.view,t,e).then((()=>{n(!0)})).catch((t=>{Gi.error(t),n(!1)}))}))},Object.assign(V,Di),Object.assign(I,Ii),Object.assign(Y,xt),Object.assign(D,ie),Object.assign(P,ve),Object.assign(U,Le),Object.assign(z,Vi),q();export{rt as Layouter,G as LeaferCanvas,lt as Renderer,Q as Watcher,q as useCanvas};
|
package/dist/web.js
CHANGED
|
@@ -1414,14 +1414,13 @@ var LeaferUI = (function (exports) {
|
|
|
1414
1414
|
list: {},
|
|
1415
1415
|
register(UI) {
|
|
1416
1416
|
const { __tag: tag } = UI.prototype;
|
|
1417
|
-
if (list$1[tag])
|
|
1417
|
+
if (list$1[tag])
|
|
1418
1418
|
debug$d.repeat(tag);
|
|
1419
|
-
|
|
1420
|
-
else {
|
|
1421
|
-
list$1[tag] = UI;
|
|
1422
|
-
}
|
|
1419
|
+
list$1[tag] = UI;
|
|
1423
1420
|
},
|
|
1424
1421
|
get(tag, data, x, y, width, height) {
|
|
1422
|
+
if (!list$1[tag])
|
|
1423
|
+
debug$d.error('not register ' + tag);
|
|
1425
1424
|
const ui = new list$1[tag](data);
|
|
1426
1425
|
if (x !== undefined) {
|
|
1427
1426
|
ui.x = x;
|
|
@@ -1445,7 +1444,7 @@ var LeaferUI = (function (exports) {
|
|
|
1445
1444
|
Object.keys(Event).forEach(key => {
|
|
1446
1445
|
name = Event[key];
|
|
1447
1446
|
if (typeof name === 'string')
|
|
1448
|
-
nameList[name]
|
|
1447
|
+
nameList[name] && debug$c.repeat(name), nameList[name] = Event;
|
|
1449
1448
|
});
|
|
1450
1449
|
},
|
|
1451
1450
|
changeName(oldName, newName) {
|
|
@@ -1647,7 +1646,7 @@ var LeaferUI = (function (exports) {
|
|
|
1647
1646
|
const t = this;
|
|
1648
1647
|
if (t.blendMode === 'pass-through') {
|
|
1649
1648
|
const leaf = this.__leaf;
|
|
1650
|
-
if ((t.opacity < 1 && leaf.isBranch) || leaf.__hasEraser || t.eraser) {
|
|
1649
|
+
if ((t.opacity < 1 && (leaf.isBranch || t.__hasMultiPaint)) || leaf.__hasEraser || t.eraser) {
|
|
1651
1650
|
t.__single = true;
|
|
1652
1651
|
}
|
|
1653
1652
|
else if (t.__single) {
|
|
@@ -2045,8 +2044,9 @@ var LeaferUI = (function (exports) {
|
|
|
2045
2044
|
takeCanvas = this.getSameCanvas();
|
|
2046
2045
|
takeCanvas.copyWorld(this);
|
|
2047
2046
|
}
|
|
2048
|
-
|
|
2049
|
-
|
|
2047
|
+
const s = this.size;
|
|
2048
|
+
DataHelper.copyAttrs(s, size, canvasSizeAttrs);
|
|
2049
|
+
canvasSizeAttrs.forEach(key => s[key] || (s[key] = 1));
|
|
2050
2050
|
this.bounds = new Bounds(0, 0, this.width, this.height);
|
|
2051
2051
|
if (this.context && !this.unreal) {
|
|
2052
2052
|
this.updateViewSize();
|
|
@@ -2160,6 +2160,17 @@ var LeaferUI = (function (exports) {
|
|
|
2160
2160
|
if (!onlyResetTransform)
|
|
2161
2161
|
this.useWorldTransform();
|
|
2162
2162
|
}
|
|
2163
|
+
useGrayscaleAlpha(bounds) {
|
|
2164
|
+
this.setTempBounds(bounds, true, true);
|
|
2165
|
+
let alpha, pixel;
|
|
2166
|
+
const { context } = this, imageData = context.getImageData(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height), { data } = imageData;
|
|
2167
|
+
for (let i = 0, len = data.length; i < len; i += 4) {
|
|
2168
|
+
pixel = data[i] * 0.299 + data[i + 1] * 0.587 + data[i + 2] * 0.114;
|
|
2169
|
+
if (alpha = data[i + 3])
|
|
2170
|
+
data[i + 3] = alpha === 255 ? pixel : alpha * (pixel / 255);
|
|
2171
|
+
}
|
|
2172
|
+
context.putImageData(imageData, tempBounds$1.x, tempBounds$1.y);
|
|
2173
|
+
}
|
|
2163
2174
|
useMask(maskCanvas, fromBounds, toBounds) {
|
|
2164
2175
|
this.copyWorld(maskCanvas, fromBounds, toBounds, 'destination-in');
|
|
2165
2176
|
}
|
|
@@ -2170,7 +2181,7 @@ var LeaferUI = (function (exports) {
|
|
|
2170
2181
|
if (blendMode)
|
|
2171
2182
|
this.blendMode = blendMode;
|
|
2172
2183
|
this.fillStyle = color;
|
|
2173
|
-
|
|
2184
|
+
this.setTempBounds(bounds);
|
|
2174
2185
|
this.fillRect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
|
|
2175
2186
|
if (blendMode)
|
|
2176
2187
|
this.blendMode = 'source-over';
|
|
@@ -2179,22 +2190,18 @@ var LeaferUI = (function (exports) {
|
|
|
2179
2190
|
if (blendMode)
|
|
2180
2191
|
this.blendMode = blendMode;
|
|
2181
2192
|
this.strokeStyle = color;
|
|
2182
|
-
|
|
2193
|
+
this.setTempBounds(bounds);
|
|
2183
2194
|
this.strokeRect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
|
|
2184
2195
|
if (blendMode)
|
|
2185
2196
|
this.blendMode = 'source-over';
|
|
2186
2197
|
}
|
|
2187
2198
|
clearWorld(bounds, ceilPixel) {
|
|
2188
|
-
|
|
2189
|
-
if (ceilPixel)
|
|
2190
|
-
tempBounds$1.ceil();
|
|
2199
|
+
this.setTempBounds(bounds, ceilPixel);
|
|
2191
2200
|
this.clearRect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
|
|
2192
2201
|
}
|
|
2193
2202
|
clipWorld(bounds, ceilPixel) {
|
|
2194
2203
|
this.beginPath();
|
|
2195
|
-
|
|
2196
|
-
if (ceilPixel)
|
|
2197
|
-
tempBounds$1.ceil();
|
|
2204
|
+
this.setTempBounds(bounds, ceilPixel);
|
|
2198
2205
|
this.rect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
|
|
2199
2206
|
this.clip();
|
|
2200
2207
|
}
|
|
@@ -2202,6 +2209,14 @@ var LeaferUI = (function (exports) {
|
|
|
2202
2209
|
const { pixelRatio } = this;
|
|
2203
2210
|
this.clearRect(0, 0, this.width * pixelRatio + 2, this.height * pixelRatio + 2);
|
|
2204
2211
|
}
|
|
2212
|
+
setTempBounds(bounds, ceil, intersect) {
|
|
2213
|
+
tempBounds$1.set(bounds);
|
|
2214
|
+
if (intersect)
|
|
2215
|
+
tempBounds$1.intersect(this.bounds);
|
|
2216
|
+
tempBounds$1.scale(this.pixelRatio);
|
|
2217
|
+
if (ceil)
|
|
2218
|
+
tempBounds$1.ceil();
|
|
2219
|
+
}
|
|
2205
2220
|
isSameSize(size) {
|
|
2206
2221
|
return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
|
|
2207
2222
|
}
|
|
@@ -5215,13 +5230,14 @@ var LeaferUI = (function (exports) {
|
|
|
5215
5230
|
this.__.__checkSingle();
|
|
5216
5231
|
},
|
|
5217
5232
|
__render(canvas, options) {
|
|
5233
|
+
this.__nowWorld = this.__getNowWorld(options);
|
|
5218
5234
|
if (this.__worldOpacity) {
|
|
5219
5235
|
if (this.__.__single) {
|
|
5220
5236
|
if (this.__.eraser === 'path')
|
|
5221
5237
|
return this.__renderEraser(canvas, options);
|
|
5222
5238
|
const tempCanvas = canvas.getSameCanvas(false, true);
|
|
5223
5239
|
this.__renderBranch(tempCanvas, options);
|
|
5224
|
-
const nowWorld = this.
|
|
5240
|
+
const nowWorld = this.__nowWorld;
|
|
5225
5241
|
canvas.opacity = this.__.opacity;
|
|
5226
5242
|
canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, this.__.__blendMode, true);
|
|
5227
5243
|
tempCanvas.recycle(nowWorld);
|
|
@@ -5962,7 +5978,7 @@ var LeaferUI = (function (exports) {
|
|
|
5962
5978
|
}
|
|
5963
5979
|
}
|
|
5964
5980
|
|
|
5965
|
-
const version = "1.0.
|
|
5981
|
+
const version = "1.0.10";
|
|
5966
5982
|
|
|
5967
5983
|
const debug$5 = Debug.get('LeaferCanvas');
|
|
5968
5984
|
class LeaferCanvas extends LeaferCanvasBase {
|
|
@@ -6604,7 +6620,8 @@ var LeaferUI = (function (exports) {
|
|
|
6604
6620
|
this.totalBounds = new Bounds();
|
|
6605
6621
|
debug$3.log(target.innerName, '--->');
|
|
6606
6622
|
try {
|
|
6607
|
-
target.
|
|
6623
|
+
if (!target.isApp)
|
|
6624
|
+
target.app.emit(RenderEvent.CHILD_START, target);
|
|
6608
6625
|
this.emitRender(RenderEvent.START);
|
|
6609
6626
|
this.renderOnce(callback);
|
|
6610
6627
|
this.emitRender(RenderEvent.END, this.totalBounds);
|
|
@@ -6885,6 +6902,12 @@ var LeaferUI = (function (exports) {
|
|
|
6885
6902
|
return strokeWidth;
|
|
6886
6903
|
}
|
|
6887
6904
|
get __hasStroke() { return this.stroke && this.strokeWidth; }
|
|
6905
|
+
get __hasMultiPaint() {
|
|
6906
|
+
const t = this;
|
|
6907
|
+
if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
|
|
6908
|
+
return true;
|
|
6909
|
+
return t.fill && this.__hasStroke;
|
|
6910
|
+
}
|
|
6888
6911
|
get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
|
|
6889
6912
|
get __autoWidth() { return !this._width; }
|
|
6890
6913
|
get __autoHeight() { return !this._height; }
|
|
@@ -7254,9 +7277,8 @@ var LeaferUI = (function (exports) {
|
|
|
7254
7277
|
canvas.strokeRect(half, half, width, height);
|
|
7255
7278
|
canvas.restore();
|
|
7256
7279
|
}
|
|
7257
|
-
else
|
|
7280
|
+
else
|
|
7258
7281
|
canvas.strokeRect(half, half, width, height);
|
|
7259
|
-
}
|
|
7260
7282
|
break;
|
|
7261
7283
|
case 'outside':
|
|
7262
7284
|
canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth);
|
|
@@ -7481,6 +7503,15 @@ var LeaferUI = (function (exports) {
|
|
|
7481
7503
|
__decorate([
|
|
7482
7504
|
boundsType(0)
|
|
7483
7505
|
], exports.UI.prototype, "padding", void 0);
|
|
7506
|
+
__decorate([
|
|
7507
|
+
boundsType(false)
|
|
7508
|
+
], exports.UI.prototype, "lockRatio", void 0);
|
|
7509
|
+
__decorate([
|
|
7510
|
+
boundsType()
|
|
7511
|
+
], exports.UI.prototype, "widthRange", void 0);
|
|
7512
|
+
__decorate([
|
|
7513
|
+
boundsType()
|
|
7514
|
+
], exports.UI.prototype, "heightRange", void 0);
|
|
7484
7515
|
__decorate([
|
|
7485
7516
|
dataType(false)
|
|
7486
7517
|
], exports.UI.prototype, "draggable", void 0);
|
|
@@ -7772,8 +7803,6 @@ var LeaferUI = (function (exports) {
|
|
|
7772
7803
|
__onResize(event) {
|
|
7773
7804
|
this.emitEvent(event);
|
|
7774
7805
|
DataHelper.copyAttrs(this.__, event, canvasSizeAttrs);
|
|
7775
|
-
if (!event.width || !event.height)
|
|
7776
|
-
debug$1.warn('w = 0 or h = 0');
|
|
7777
7806
|
setTimeout(() => { if (this.canvasManager)
|
|
7778
7807
|
this.canvasManager.clearRecycled(); }, 0);
|
|
7779
7808
|
}
|
|
@@ -8098,9 +8127,6 @@ var LeaferUI = (function (exports) {
|
|
|
8098
8127
|
__decorate([
|
|
8099
8128
|
dataType(false)
|
|
8100
8129
|
], exports.Box.prototype, "resizeChildren", void 0);
|
|
8101
|
-
__decorate([
|
|
8102
|
-
dataType(false)
|
|
8103
|
-
], exports.Box.prototype, "textBox", void 0);
|
|
8104
8130
|
__decorate([
|
|
8105
8131
|
affectRenderBoundsType('show')
|
|
8106
8132
|
], exports.Box.prototype, "overflow", void 0);
|
|
@@ -9562,16 +9588,16 @@ var LeaferUI = (function (exports) {
|
|
|
9562
9588
|
|
|
9563
9589
|
const { excludeRenderBounds } = LeafBoundsHelper;
|
|
9564
9590
|
exports.Group.prototype.__renderMask = function (canvas, options) {
|
|
9565
|
-
let child, maskCanvas, contentCanvas, maskOpacity, currentMask;
|
|
9591
|
+
let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
|
|
9566
9592
|
const { children } = this;
|
|
9567
9593
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
9568
|
-
child = children[i];
|
|
9569
|
-
if (
|
|
9594
|
+
child = children[i], mask = child.__.mask;
|
|
9595
|
+
if (mask) {
|
|
9570
9596
|
if (currentMask) {
|
|
9571
9597
|
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
9572
9598
|
maskCanvas = contentCanvas = null;
|
|
9573
9599
|
}
|
|
9574
|
-
if (
|
|
9600
|
+
if (mask === 'path' || mask === 'clipping-path') {
|
|
9575
9601
|
if (child.opacity < 1) {
|
|
9576
9602
|
currentMask = 'opacity-path';
|
|
9577
9603
|
maskOpacity = child.opacity;
|
|
@@ -9585,14 +9611,14 @@ var LeaferUI = (function (exports) {
|
|
|
9585
9611
|
child.__clip(contentCanvas || canvas, options);
|
|
9586
9612
|
}
|
|
9587
9613
|
else {
|
|
9588
|
-
currentMask = 'alpha';
|
|
9614
|
+
currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
|
|
9589
9615
|
if (!maskCanvas)
|
|
9590
9616
|
maskCanvas = getCanvas(canvas);
|
|
9591
9617
|
if (!contentCanvas)
|
|
9592
9618
|
contentCanvas = getCanvas(canvas);
|
|
9593
9619
|
child.__render(maskCanvas, options);
|
|
9594
9620
|
}
|
|
9595
|
-
if (
|
|
9621
|
+
if (!(mask === 'clipping' || mask === 'clipping-path'))
|
|
9596
9622
|
continue;
|
|
9597
9623
|
}
|
|
9598
9624
|
if (excludeRenderBounds(child, options))
|
|
@@ -9603,6 +9629,8 @@ var LeaferUI = (function (exports) {
|
|
|
9603
9629
|
};
|
|
9604
9630
|
function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
|
|
9605
9631
|
switch (maskMode) {
|
|
9632
|
+
case 'grayscale':
|
|
9633
|
+
maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
|
|
9606
9634
|
case 'alpha':
|
|
9607
9635
|
usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
|
|
9608
9636
|
break;
|
|
@@ -10307,15 +10335,12 @@ var LeaferUI = (function (exports) {
|
|
|
10307
10335
|
const debug = Debug.get('@leafer-ui/export');
|
|
10308
10336
|
canvas.export = function (filename, options) {
|
|
10309
10337
|
const { quality, blob } = FileHelper.getExportOptions(options);
|
|
10310
|
-
if (filename.includes('.'))
|
|
10338
|
+
if (filename.includes('.'))
|
|
10311
10339
|
return this.saveAs(filename, quality);
|
|
10312
|
-
|
|
10313
|
-
else if (blob) {
|
|
10340
|
+
else if (blob)
|
|
10314
10341
|
return this.toBlob(filename, quality);
|
|
10315
|
-
|
|
10316
|
-
else {
|
|
10342
|
+
else
|
|
10317
10343
|
return this.toDataURL(filename, quality);
|
|
10318
|
-
}
|
|
10319
10344
|
};
|
|
10320
10345
|
canvas.toBlob = function (type, quality) {
|
|
10321
10346
|
return new Promise((resolve) => {
|