leafer-draw 1.9.5 → 1.9.6
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 +16 -5
- package/dist/web.esm.js +17 -6
- package/dist/web.esm.min.js +1 -1
- package/dist/web.esm.min.js.map +1 -1
- package/dist/web.js +128 -89
- package/dist/web.min.cjs +1 -1
- package/dist/web.min.cjs.map +1 -1
- package/dist/web.min.js +1 -1
- package/dist/web.min.js.map +1 -1
- package/dist/web.module.js +143 -102
- package/dist/web.module.min.js +1 -1
- package/dist/web.module.min.js.map +1 -1
- package/package.json +3 -3
package/dist/web.cjs
CHANGED
|
@@ -1809,12 +1809,18 @@ function shadow(ui, current, shape) {
|
|
|
1809
1809
|
}
|
|
1810
1810
|
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
|
|
1811
1811
|
}
|
|
1812
|
-
core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1812
|
+
if (draw.Effect.isTransformShadow(item)) draw.Effect.renderTransformShadow(ui, current, other, copyBounds, item); else core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1813
1813
|
if (end && index < end) other.clearWorld(copyBounds);
|
|
1814
1814
|
});
|
|
1815
1815
|
other.recycle(copyBounds);
|
|
1816
1816
|
}
|
|
1817
1817
|
|
|
1818
|
+
function getShadowSpread(_ui, shadow) {
|
|
1819
|
+
let width = 0;
|
|
1820
|
+
shadow.forEach(item => width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5));
|
|
1821
|
+
return width;
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1818
1824
|
function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
1819
1825
|
const {bounds: bounds, shapeBounds: shapeBounds} = shape;
|
|
1820
1826
|
if (core.Platform.fullImageShadow) {
|
|
@@ -1892,7 +1898,11 @@ const EffectModule = {
|
|
|
1892
1898
|
shadow: shadow,
|
|
1893
1899
|
innerShadow: innerShadow,
|
|
1894
1900
|
blur: blur,
|
|
1895
|
-
backgroundBlur: backgroundBlur
|
|
1901
|
+
backgroundBlur: backgroundBlur,
|
|
1902
|
+
getShadowSpread: getShadowSpread,
|
|
1903
|
+
isTransformShadow(_shadow) {
|
|
1904
|
+
return undefined;
|
|
1905
|
+
}
|
|
1896
1906
|
};
|
|
1897
1907
|
|
|
1898
1908
|
const {excludeRenderBounds: excludeRenderBounds} = core.LeafBoundsHelper;
|
|
@@ -2400,16 +2410,17 @@ function toTextChar(row) {
|
|
|
2400
2410
|
}
|
|
2401
2411
|
|
|
2402
2412
|
function decorationText(drawData, style) {
|
|
2403
|
-
let type;
|
|
2413
|
+
let type, offset = 0;
|
|
2404
2414
|
const {fontSize: fontSize, textDecoration: textDecoration} = style;
|
|
2405
2415
|
drawData.decorationHeight = fontSize / 11;
|
|
2406
2416
|
if (core.isObject(textDecoration)) {
|
|
2407
2417
|
type = textDecoration.type;
|
|
2408
2418
|
if (textDecoration.color) drawData.decorationColor = draw.ColorConvert.string(textDecoration.color);
|
|
2419
|
+
if (textDecoration.offset) offset = Math.min(fontSize * .3, Math.max(textDecoration.offset, -fontSize * .15));
|
|
2409
2420
|
} else type = textDecoration;
|
|
2410
2421
|
switch (type) {
|
|
2411
2422
|
case "under":
|
|
2412
|
-
drawData.decorationY = [ fontSize * .15 ];
|
|
2423
|
+
drawData.decorationY = [ fontSize * .15 + offset ];
|
|
2413
2424
|
break;
|
|
2414
2425
|
|
|
2415
2426
|
case "delete":
|
|
@@ -2417,7 +2428,7 @@ function decorationText(drawData, style) {
|
|
|
2417
2428
|
break;
|
|
2418
2429
|
|
|
2419
2430
|
case "under-delete":
|
|
2420
|
-
drawData.decorationY = [ fontSize * .15, -fontSize * .35 ];
|
|
2431
|
+
drawData.decorationY = [ fontSize * .15 + offset, -fontSize * .35 ];
|
|
2421
2432
|
}
|
|
2422
2433
|
}
|
|
2423
2434
|
|
package/dist/web.esm.js
CHANGED
|
@@ -4,7 +4,7 @@ export * from "@leafer/core";
|
|
|
4
4
|
|
|
5
5
|
export { LeaferImage } from "@leafer/core";
|
|
6
6
|
|
|
7
|
-
import { PaintImage, Paint, ColorConvert, PaintGradient, Export, Group, TextConvert
|
|
7
|
+
import { PaintImage, Paint, ColorConvert, PaintGradient, Export, Effect, Group, TextConvert } from "@leafer-ui/draw";
|
|
8
8
|
|
|
9
9
|
export * from "@leafer-ui/draw";
|
|
10
10
|
|
|
@@ -1813,12 +1813,18 @@ function shadow(ui, current, shape) {
|
|
|
1813
1813
|
}
|
|
1814
1814
|
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
|
|
1815
1815
|
}
|
|
1816
|
-
LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1816
|
+
if (Effect.isTransformShadow(item)) Effect.renderTransformShadow(ui, current, other, copyBounds, item); else LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1817
1817
|
if (end && index < end) other.clearWorld(copyBounds);
|
|
1818
1818
|
});
|
|
1819
1819
|
other.recycle(copyBounds);
|
|
1820
1820
|
}
|
|
1821
1821
|
|
|
1822
|
+
function getShadowSpread(_ui, shadow) {
|
|
1823
|
+
let width = 0;
|
|
1824
|
+
shadow.forEach(item => width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5));
|
|
1825
|
+
return width;
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1822
1828
|
function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
1823
1829
|
const {bounds: bounds, shapeBounds: shapeBounds} = shape;
|
|
1824
1830
|
if (Platform.fullImageShadow) {
|
|
@@ -1896,7 +1902,11 @@ const EffectModule = {
|
|
|
1896
1902
|
shadow: shadow,
|
|
1897
1903
|
innerShadow: innerShadow,
|
|
1898
1904
|
blur: blur,
|
|
1899
|
-
backgroundBlur: backgroundBlur
|
|
1905
|
+
backgroundBlur: backgroundBlur,
|
|
1906
|
+
getShadowSpread: getShadowSpread,
|
|
1907
|
+
isTransformShadow(_shadow) {
|
|
1908
|
+
return undefined;
|
|
1909
|
+
}
|
|
1900
1910
|
};
|
|
1901
1911
|
|
|
1902
1912
|
const {excludeRenderBounds: excludeRenderBounds} = LeafBoundsHelper;
|
|
@@ -2404,16 +2414,17 @@ function toTextChar(row) {
|
|
|
2404
2414
|
}
|
|
2405
2415
|
|
|
2406
2416
|
function decorationText(drawData, style) {
|
|
2407
|
-
let type;
|
|
2417
|
+
let type, offset = 0;
|
|
2408
2418
|
const {fontSize: fontSize, textDecoration: textDecoration} = style;
|
|
2409
2419
|
drawData.decorationHeight = fontSize / 11;
|
|
2410
2420
|
if (isObject(textDecoration)) {
|
|
2411
2421
|
type = textDecoration.type;
|
|
2412
2422
|
if (textDecoration.color) drawData.decorationColor = ColorConvert.string(textDecoration.color);
|
|
2423
|
+
if (textDecoration.offset) offset = Math.min(fontSize * .3, Math.max(textDecoration.offset, -fontSize * .15));
|
|
2413
2424
|
} else type = textDecoration;
|
|
2414
2425
|
switch (type) {
|
|
2415
2426
|
case "under":
|
|
2416
|
-
drawData.decorationY = [ fontSize * .15 ];
|
|
2427
|
+
drawData.decorationY = [ fontSize * .15 + offset ];
|
|
2417
2428
|
break;
|
|
2418
2429
|
|
|
2419
2430
|
case "delete":
|
|
@@ -2421,7 +2432,7 @@ function decorationText(drawData, style) {
|
|
|
2421
2432
|
break;
|
|
2422
2433
|
|
|
2423
2434
|
case "under-delete":
|
|
2424
|
-
drawData.decorationY = [ fontSize * .15, -fontSize * .35 ];
|
|
2435
|
+
drawData.decorationY = [ fontSize * .15 + offset, -fontSize * .35 ];
|
|
2425
2436
|
}
|
|
2426
2437
|
}
|
|
2427
2438
|
|
package/dist/web.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Debug as t,LeaferCanvasBase as e,Platform as i,isString as s,isUndefined as n,DataHelper as a,canvasSizeAttrs as o,ResizeEvent as r,canvasPatch as l,FileHelper as d,Creator as h,LeaferImage as c,defineKey as u,LeafList as f,RenderEvent as p,ChildEvent as g,WatchEvent as _,PropertyEvent as w,LeafHelper as m,BranchHelper as y,LeafBoundsHelper as v,Bounds as x,isArray as b,LeafLevelList as k,LayoutEvent as S,Run as B,ImageManager as R,isObject as E,BoundsHelper as L,Matrix as A,getMatrixData as C,MatrixHelper as O,MathHelper as T,AlignHelper as W,PointHelper as D,ImageEvent as P,AroundHelper as M,Direction4 as I,isNumber as z}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as F,Paint as U,ColorConvert as V,PaintGradient as Y,Export as G,Group as N,TextConvert as X,Effect as q}from"@leafer-ui/draw";export*from"@leafer-ui/draw";const j=t.get("LeaferCanvas");class H extends e{set zIndex(t){const{style:e}=this.view;e.zIndex=t,this.setAbsolute(this.view)}set childIndex(t){const{view:e,parentView:i}=this;if(e&&i){const s=i.children[t];s?(this.setAbsolute(s),i.insertBefore(e,s)):i.appendChild(s)}}init(){const{config:t}=this,e=t.view||t.canvas;e?this.__createViewFrom(e):this.__createView();const{style:s}=this.view;if(s.display||(s.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}i.syncDomFont&&!this.parentView&&(s.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=s(t)?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;t.hasChildNodes()&&(this.setAbsolute(i),t.style.position||(t.style.position="relative")),t.appendChild(i)}else j.error(`no id: ${t}`),this.__createView()}setAbsolute(t){const{style:e}=t;e.position="absolute",e.top=e.left="0px"}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;if(this.unreal){const{config:t,autoWidthStr:e,autoHeightStr:i}=this;t.width?(n(e)&&(this.autoWidthStr=s.width||""),s.width=t.width+"px"):n(e)||(s.width=e),t.height?(n(i)&&(this.autoHeightStr=s.height||""),s.height=t.height+"px"):n(i)||(s.height=i)}else s.width=t+"px",s.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.view.parentElement&&(this.clientBounds=this.view.getBoundingClientRect())}startAutoLayout(t,e){if(this.resizeListener=e,t){if(this.autoBounds=t,this.resizeObserver)return;try{this.resizeObserver=new ResizeObserver(t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)});const t=this.parentView;t?(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect())):(this.checkAutoBounds(this.view),j.warn("no parent"))}catch(t){this.imitateResizeObserver()}this.stopListenPixelRatio()}else this.listenPixelRatio(),this.unreal&&this.updateViewSize()}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}listenPixelRatio(){this.windowListener||window.addEventListener("resize",this.windowListener=()=>{const t=i.devicePixelRatio;if(!this.config.pixelRatio&&this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}})}stopListenPixelRatio(){this.windowListener&&(window.removeEventListener("resize",this.windowListener),this.windowListener=null)}checkAutoBounds(t){const e=this.view,{x:s,y:n,width:a,height:o}=this.autoBounds.getBoundsFrom(t),r={width:a,height:o,pixelRatio:this.config.pixelRatio?this.pixelRatio:i.devicePixelRatio};if(!this.isSameSize(r)){const{style:t}=e;t.marginLeft=s+"px",t.marginTop=n+"px",this.emitResize(r)}}stopAutoLayout(){this.autoLayout=!1,this.resizeObserver&&this.resizeObserver.disconnect(),this.resizeListener=this.resizeObserver=null}emitResize(t){const e={};a.copyAttrs(e,this,o),this.resize(t),this.resizeListener&&!n(this.width)&&this.resizeListener(new r(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.stopListenPixelRatio(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}l(CanvasRenderingContext2D.prototype),l(Path2D.prototype);const{mineType:Q,fileType:Z}=d;function $(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>{const s=Q(e),n=t.toDataURL(s,i);return"image/bmp"===s?n.replace("image/png;","image/bmp;"):n},canvasToBolb:(t,e,i)=>new Promise(s=>t.toBlob(s,Q(e),i)),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(Q(Z(e)),s);return i.origin.download(n,e)},download:(t,e)=>new Promise(i=>{let s=document.createElement("a");s.href=t,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),i()}),loadImage:t=>new Promise((e,s)=>{const n=new i.origin.Image,{crossOrigin:a}=i.image;a&&(n.setAttribute("crossOrigin",a),n.crossOrigin=a),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},n.src=i.image.getRealURL(t)}),Image:Image,PointerEvent:PointerEvent,DragEvent:DragEvent},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=h.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(h,{canvas:(t,e)=>new H(t,e),image:t=>new c(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},u(i,"devicePixelRatio",{get:()=>devicePixelRatio});const{userAgent:J}=navigator;J.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):(/iPhone|iPad|iPod/.test(navigator.userAgent)||/Macintosh/.test(navigator.userAgent)&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent))&&(i.fullImageShadow=!0),J.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):J.indexOf("Mac")>-1?i.os="Mac":J.indexOf("Linux")>-1&&(i.os="Linux");class K{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new f;return this.__updatedList.list.forEach(e=>{e.leafer&&t.add(e)}),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new f,this.target=t,e&&(this.config=a.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(p.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===g.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new _(_.DATA,{updatedList:this.updatedList})),this.__updatedList=new f,this.totalTimes++,this.changed=this.hasVisible=this.hasRemove=this.hasAdd=!1}__listenEvents(){this.__eventIds=[this.target.on_([[w.CHANGE,this.__onAttrChange,this],[[g.ADD,g.REMOVE],this.__onChildEvent,this],[_.REQUEST,this.__onRquestData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.__updatedList=null)}}const{updateAllMatrix:tt,updateBounds:et,updateChange:it}=m,{pushAllChildBranch:st,pushAllParent:nt}=y;const{worldBounds:at}=v;class ot{constructor(t){this.updatedBounds=new x,this.beforeBounds=new x,this.afterBounds=new x,b(t)&&(t=new f(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,at)}setAfter(){this.afterBounds.setListWithFn(this.updatedList.list,at),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:rt,updateAllChange:lt}=m,dt=t.get("Layouter");class ht{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new k,this.target=t,e&&(this.config=a.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(this.layouting||!this.running)return;const{target:t}=this;this.times=0;try{t.emit(S.START),this.layoutOnce(),t.emitEvent(new S(S.END,this.layoutedBlocks,this.times))}catch(t){dt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?dt.warn("layouting"):this.times>3?dt.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(_.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:s}=this,{BEFORE:n,LAYOUT:a,AFTER:o}=S,r=this.getBlocks(s);r.forEach(t=>t.setBefore()),i.emitEvent(new S(n,r,this.times)),this.extraBlock=null,s.sort(),function(t,e){let i;t.list.forEach(t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(tt(t,!0),e.add(t),t.isBranch&&st(t,e),nt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),nt(t,e)))})}(s,this.__levelList),function(t){let e,i,s;t.sort(!0),t.levels.forEach(n=>{e=t.levelMap[n];for(let t=0,n=e.length;t<n;t++){if(i=e[t],i.isBranch&&i.__tempNumber){s=i.children;for(let t=0,e=s.length;t<e;t++)s[t].isBranch||et(s[t])}et(i)}})}(this.__levelList),function(t){t.list.forEach(it)}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach(t=>t.setAfter()),i.emitEvent(new S(a,r,this.times)),i.emitEvent(new S(o,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:s,AFTER:n}=S,a=this.getBlocks(new f(e));e.emitEvent(new S(i,a,this.times)),ht.fullLayout(e),a.forEach(t=>{t.setAfter()}),e.emitEvent(new S(s,a,this.times)),e.emitEvent(new S(n,a,this.times)),this.addBlocks(a),B.end(t)}static fullLayout(t){rt(t,!0),t.isBranch?y.updateBounds(t):m.updateBounds(t),lt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new ot([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new ot(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){this.__eventIds=[this.target.on_([[S.REQUEST,this.layout,this],[S.AGAIN,this.layoutAgain,this],[_.DATA,this.__onReceiveWatchData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const ct=t.get("Renderer");class ut{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:120},this.target=t,this.canvas=e,i&&(this.config=a.default(i,this.config)),this.__listenEvents()}start(){this.running=!0,this.update(!1)}stop(){this.running=!1}update(t=!0){this.changed||(this.changed=t),this.__requestRender()}requestLayout(){this.target.emit(S.REQUEST)}checkRender(){if(this.running){const{target:t}=this;t.isApp&&(t.emit(p.CHILD_START,t),t.children.forEach(t=>{t.renderer.FPS=this.FPS,t.renderer.checkRender()}),t.emit(p.CHILD_END,t)),this.changed&&this.canvas.view&&this.render(),this.target.emit(p.NEXT)}}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new x,ct.log(e.innerName,"---\x3e");try{this.emitRender(p.START),this.renderOnce(t),this.emitRender(p.END,this.totalBounds),R.clearRecycled()}catch(t){this.rendering=!1,ct.error(t)}ct.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return ct.warn("rendering");if(this.times>3)return ct.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new x,this.renderOptions={},t)this.emitRender(p.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(p.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(p.RENDER,this.renderBounds,this.renderOptions),this.emitRender(p.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;e&&(this.mergeBlocks(),e.forEach(e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=B.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=new x(s);i.save(),s.spread(ut.clipSpread).ceil(),i.clearWorld(s),i.clipWorld(s),this.__render(s,n),i.restore(),B.end(e)}fullRender(){const t=B.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds),e.restore(),B.end(t)}__render(e,i){const{canvas:s}=this,n=e.includes(this.target.__world),a=n?{includes:n}:{bounds:e,includes:n};this.needFill&&s.fillWorld(e,this.config.fill),t.showRepaint&&t.drawRepaint(s,e),this.target.__render(s,a),this.renderBounds=i=i||e,this.renderOptions=a,this.totalBounds.isEmpty()?this.totalBounds=i:this.totalBounds.add(i),s.updateRender(i)}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new x;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=this.target;if(this.requestTime||!t)return;if(t.parentApp)return t.parentApp.requestRender(!1);const e=this.requestTime=Date.now(),s=()=>{const t=1e3/(Date.now()-e),{maxFPS:n}=this.config;if(n&&t>n-.5)return i.requestRender(s);this.FPS=Math.min(120,Math.ceil(t)),this.requestTime=0,this.checkRender()};i.requestRender(s)}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new x(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new x(0,0,1,1)),this.update()}}__onLayoutEnd(t){t.data&&t.data.map(t=>{let e;t.updatedList&&t.updatedList.list.some(t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||ct.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 p(t,this.times,e,i))}__listenEvents(){this.__eventIds=[this.target.on_([[p.REQUEST,this.update,this],[S.END,this.__onLayoutEnd,this],[p.AGAIN,this.renderAgain,this],[r.RESIZE,this.__onResize,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.config={},this.target=this.canvas=null)}}function ft(t,e){const i=t.__,{rows:s,decorationY:n}=i.__textDrawData;let a;i.__isPlacehold&&i.placeholderColor&&(e.fillStyle=i.placeholderColor);for(let t=0,i=s.length;t<i;t++)a=s[t],a.text?e.fillText(a.text,a.x,a.y):a.data&&a.data.forEach(t=>{e.fillText(t.char,t.x,a.y)});if(n){const{decorationColor:t,decorationHeight:a}=i.__textDrawData;t&&(e.fillStyle=t),s.forEach(t=>n.forEach(i=>e.fillRect(t.x,t.y+i,t.width,a)))}}function pt(t,e){t.__.__font?ft(t,e):t.__.windingRule?e.fill(t.__.windingRule):e.fill()}function gt(t,e,i){switch(e.__.strokeAlign){case"center":_t(t,1,e,i);break;case"inside":wt(t,"inside",e,i);break;case"outside":e.__.__fillAfterStroke?_t(t,2,e,i):wt(t,"outside",e,i)}}function _t(t,e,i,s){const n=i.__;E(t)?yt(t,e,!0,i,s):(s.setStroke(t,n.__strokeWidth*e,n),mt(i,s))}function wt(t,e,i,s){const n=s.getSameCanvas(!0,!0);n.font=i.__.__font,_t(t,2,i,n),n.blendMode="outside"===e?"destination-out":"destination-in",ft(i,n),n.blendMode="normal",m.copyCanvasByWorld(i,s,n),n.recycle(i.__nowWorld)}function mt(t,e){let i,s=t.__.__textDrawData;const{rows:n,decorationY:a}=s;for(let t=0,s=n.length;t<s;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)});if(a){const{decorationHeight:t}=s;n.forEach(i=>a.forEach(s=>e.strokeRect(i.x,i.y+s,i.width,t)))}}function yt(t,e,i,s,n){let a;const o=s.__,{__hasMultiStrokeStyle:r}=o;r||n.setStroke(void 0,o.__strokeWidth*e,o);for(let l=0,d=t.length;l<d;l++)if(a=t[l],(!a.image||!F.checkImage(s,n,a,!1))&&a.style){if(r){const{strokeStyle:t}=a;t?n.setStroke(a.style,o.__getRealStrokeWidth(t)*e,o,t):n.setStroke(a.style,o.__strokeWidth*e,o)}else n.strokeStyle=a.style;a.blendMode?(n.saveBlendMode(a.blendMode),i?mt(s,n):n.stroke(),n.restoreBlendMode()):i?mt(s,n):n.stroke()}}function vt(t,e,i){const s=e.__;if(s.__strokeWidth)if(s.__font)gt(t,e,i);else switch(s.strokeAlign){case"center":xt(t,1,e,i);break;case"inside":!function(t,e,i){i.save(),i.clipUI(e),xt(t,2,e,i),i.restore()}(t,e,i);break;case"outside":!function(t,e,i){const s=e.__;if(s.__fillAfterStroke)xt(t,2,e,i);else{const{renderBounds:n}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),xt(t,2,e,a),a.clipUI(s),a.clearWorld(n),m.copyCanvasByWorld(e,i,a),a.recycle(e.__nowWorld)}}(t,e,i)}}function xt(t,e,i,s){const n=i.__;E(t)?yt(t,e,!1,i,s):(s.setStroke(t,n.__strokeWidth*e,n),s.stroke()),n.__useArrow&&U.strokeArrow(t,i,s)}ut.clipSpread=10,Object.assign(h,{watcher:(t,e)=>new K(t,e),layouter:(t,e)=>new ht(t,e),renderer:(t,e,i)=>new ut(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,s)=>{}}),i.layout=ht.fullLayout;const{getSpread:bt,getOuterOf:kt,getByMove:St,getIntersectData:Bt}=L;let Rt;const{stintSet:Et}=a,{hasTransparent:Lt}=V;function At(t,e,i){if(!E(e)||!1===e.visible||0===e.opacity)return;let a;const{boxBounds:o}=i.__layout;switch(e.type){case"image":a=F.image(i,t,e,o,!Rt||!Rt[e.url]);break;case"linear":a=Y.linearGradient(e,o);break;case"radial":a=Y.radialGradient(e,o);break;case"angular":a=Y.conicGradient(e,o);break;case"solid":const{type:s,color:r,opacity:l}=e;a={type:s,style:V.string(r,l)};break;default:n(e.r)||(a={type:"solid",style:V.string(e)})}if(a){if(s(a.style)&&Lt(a.style)&&(a.isTransparent=!0),e.style){if(0===e.style.strokeWidth)return;a.strokeStyle=e.style}e.editing&&(a.editing=e.editing),e.blendMode&&(a.blendMode=e.blendMode)}return a}const Ct={compute:function(t,e){const i=e.__,s=[];let n,a,o,r=i.__input[t];b(r)||(r=[r]),Rt=F.recycleImage(t,i);for(let i,n=0,a=r.length;n<a;n++)(i=At(t,r[n],e))&&(s.push(i),i.strokeStyle&&(o||(o=1),i.strokeStyle.strokeWidth&&(o=Math.max(o,i.strokeStyle.strokeWidth))));i["_"+t]=s.length?s:void 0,s.length&&s.every(t=>t.isTransparent)&&(s.some(t=>t.image)&&(n=!0),a=!0),"fill"===t?(Et(i,"__isAlphaPixelFill",n),Et(i,"__isTransparentFill",a)):(Et(i,"__isAlphaPixelStroke",n),Et(i,"__isTransparentStroke",a),Et(i,"__hasMultiStrokeStyle",o))},fill:function(t,e,i){i.fillStyle=t,pt(e,i)},fills:function(t,e,i){let s;for(let n=0,a=t.length;n<a;n++){if(s=t[n],s.image){if(F.checkImage(e,i,s,!e.__.__font))continue;if(!s.style){!n&&s.image.isPlacehold&&e.drawImagePlaceholder(i,s.image);continue}}if(i.fillStyle=s.style,s.transform||s.scaleFixed){if(i.save(),s.transform&&i.transform(s.transform),s.scaleFixed){const{scaleX:t,scaleY:n}=e.getRenderScaleData(!0);(!0===s.scaleFixed||"zoom-in"===s.scaleFixed&&t>1&&n>1)&&i.scale(1/t,1/n)}s.blendMode&&(i.blendMode=s.blendMode),pt(e,i),i.restore()}else s.blendMode?(i.saveBlendMode(s.blendMode),pt(e,i),i.restoreBlendMode()):pt(e,i)}},fillPathOrText:pt,fillText:ft,stroke:vt,strokes:function(t,e,i){vt(t,e,i)},strokeText:gt,drawTextStroke:mt,shape:function(t,e,s){const n=e.getSameCanvas(),a=t.__nowWorld,o=e.bounds;let r,l,d,h,c,{scaleX:u,scaleY:f}=t.getRenderScaleData(!0);if(o.includes(a))c=n,r=h=a;else{const{renderShapeSpread:n}=t.__layout;let p;if(i.fullImageShadow)p=a;else{const t=n?bt(o,u===f?n*u:[n*f,n*u]):o;p=Bt(t,a)}d=o.getFitMatrix(p);let{a:g,d:_}=d;d.a<1&&(c=e.getSameCanvas(),t.__renderShape(c,s),u*=g,f*=_),h=kt(a,d),r=St(h,-d.e,-d.f);const w=s.matrix;w?(l=new A(d),l.multiply(w),g*=w.scaleX,_*=w.scaleY):l=d,l.withScale(g,_),s=Object.assign(Object.assign({},s),{matrix:l})}return t.__renderShape(n,s),{canvas:n,matrix:l,fitMatrix:d,bounds:r,worldCanvas:c,shapeBounds:h,scaleX:u,scaleY:f}}};let Ot={},Tt=C();const{get:Wt,rotateOfOuter:Dt,translate:Pt,scaleOfOuter:Mt,multiplyParent:It,scale:zt,rotate:Ft,skew:Ut}=O;function Vt(t,e,i,s,n,a,o){const r=Wt();Pt(r,e.x+i,e.y+s),zt(r,n,a),o&&Dt(r,{x:e.x+e.width/2,y:e.y+e.height/2},o),t.transform=r}function Yt(t,e,i,s,n,a,o,r,l){const d=Wt();Nt(d,e,i,s,n,a,o,r),l&&(Tt.a=e.width/l.width,Tt.d=e.height/l.height,It(d,Tt)),t.transform=d}function Gt(t,e,i,s,n,a,o,r,l,d,h,c){const u=Wt();if(c)Nt(u,e,n,a,o,r,l,d);else{if(l)if("center"===h)Dt(u,{x:i/2,y:s/2},l);else switch(Ft(u,l),l){case 90:Pt(u,s,0);break;case 180:Pt(u,i,s);break;case 270:Pt(u,0,i)}Ot.x=e.x+n,Ot.y=e.y+a,Pt(u,Ot.x,Ot.y),o&&Mt(u,Ot,o,r)}t.transform=u}function Nt(t,e,i,s,n,a,o,r){o&&Ft(t,o),r&&Ut(t,r.x,r.y),n&&zt(t,n,a),Pt(t,e.x+i,e.y+s)}const{get:Xt,translate:qt}=O,jt=new x,Ht={},Qt={};function Zt(t,e,i,s){const{changeful:n,sync:a,scaleFixed:o}=i;n&&(t.changeful=n),a&&(t.sync=a),o&&(t.scaleFixed=o),t.data=$t(i,s,e)}function $t(t,e,i){t.padding&&(e=jt.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");let{width:n,height:a}=i;const{opacity:o,mode:r,align:l,offset:d,scale:h,size:c,rotation:u,skew:f,clipSize:p,repeat:g,gap:_,filters:w}=t,m=e.width===n&&e.height===a,y={mode:r},v="center"!==l&&(u||0)%180==90;let x,b;switch(L.set(Qt,0,0,v?a:n,v?n:a),r&&"cover"!==r&&"fit"!==r?((h||c)&&(T.getScaleData(h,c,i,Ht),x=Ht.scaleX,b=Ht.scaleY),(l||_||g)&&(x&&L.scale(Qt,x,b,!0),l&&W.toPoint(l,Qt,e,Qt,!0,!0))):m&&!u||(x=b=L.getFitScale(e,Qt,"fit"!==r),L.put(e,i,l,x,!1,Qt),L.scale(Qt,x,b,!0)),d&&D.move(Qt,d),r){case"stretch":m||(n=e.width,a=e.height);break;case"normal":case"clip":(Qt.x||Qt.y||x||p||u||f)&&Yt(y,e,Qt.x,Qt.y,x,b,u,f,t.clipSize);break;case"repeat":(!m||x||u||f)&&Gt(y,e,n,a,Qt.x,Qt.y,x,b,u,f,l,t.freeTransform),g||(y.repeat="repeat");const i=E(g);(_||i)&&(y.gap=function(t,e,i,s,n){let a,o;E(t)?(a=t.x,o=t.y):a=o=t;return{x:Jt(a,i,n.width,e&&e.x),y:Jt(o,s,n.height,e&&e.y)}}(_,i&&g,Qt.width,Qt.height,e));break;default:x&&Vt(y,e,Qt.x,Qt.y,x,b,u)}return y.transform||(e.x||e.y)&&(y.transform=Xt(),qt(y.transform,e.x,e.y)),x&&"stretch"!==r&&(y.scaleX=x,y.scaleY=b),y.width=n,y.height=a,o&&(y.opacity=o),w&&(y.filters=w),g&&(y.repeat=s(g)?"x"===g?"repeat-x":"repeat-y":"repeat"),y}function Jt(t,e,i,n){const a=s(t)||n?(n?i-n*e:i%e)/((n||Math.floor(i/e))-1):t;return"auto"===t&&a<0?0:a}let Kt,te=new x;const{isSame:ee}=L;function ie(t,e,i,s,n,a){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=s.width/e.pixelRatio,e.__naturalHeight=s.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return n.data||Zt(n,s,i,a),!0}function se(t,e){oe(t,P.LOAD,e)}function ne(t,e){oe(t,P.LOADED,e)}function ae(t,e,i){e.error=i,t.forceUpdate("surface"),oe(t,P.ERROR,e)}function oe(t,e,i){t.hasEvent(e)&&t.emitEvent(new P(e,i))}function re(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:le,scale:de,copy:he}=O,{floor:ce,ceil:ue,max:fe,abs:pe}=Math;function ge(t,e,s){let{scaleX:n,scaleY:a}=t.getRenderScaleData(!0,e.scaleFixed);const o=n+"-"+a+"-"+s;if(e.patternId===o||t.destroyed)return!1;{const{image:r,data:l}=e;let d,h,{width:c,height:u,scaleX:f,scaleY:p,transform:g,repeat:_,gap:w}=l;n*=s,a*=s,f&&(f=pe(f),p=pe(p),h=le(),he(h,g),de(h,1/f,1/p),n*=f,a*=p),c*=n,u*=a;const m=c*u;if(!_&&m>i.image.maxCacheSize)return!1;let y=i.image.maxPatternSize;if(r.isSVG){const t=c/r.width;t>1&&(d=t/ue(t))}else{const t=r.width*r.height;y>t&&(y=t)}m>y&&(d=Math.sqrt(m/y)),d&&(n/=d,a/=d,c/=d,u/=d),f&&(n/=f,a/=p);const v=w&&w.x*n,x=w&&w.y*a;if(g||1!==n||1!==a){const t=c+(v||0),e=u+(x||0);n/=t/fe(ce(t),1),a/=e/fe(ce(e),1),h||(h=le(),g&&he(h,g)),de(h,1/n,1/a)}const b=r.getCanvas(c,u,l.opacity,l.filters,v,x,t.leafer&&t.leafer.config.smooth),k=r.getPattern(b,_||i.origin.noRepeat||"no-repeat",h,e);return e.style=k,e.patternId=o,!0}}function _e(t,e,i,s){return new(i||(i=Promise))(function(n,a){function o(t){try{l(s.next(t))}catch(t){a(t)}}function r(t){try{l(s.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(o,r)}l((s=s.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const we={image:function(t,e,i,s,n){let a,o;const r=R.get(i);return Kt&&i===Kt.paint&&ee(s,Kt.boxBounds)?a=Kt.leafPaint:(a={type:i.type,image:r},r.hasAlphaPixel&&(a.isTransparent=!0),Kt=r.use>1?{leafPaint:a,paint:i,boxBounds:te.set(s)}:null),(n||r.loading)&&(o={image:r,attrName:e,attrValue:i}),r.ready?(ie(t,e,i,r,a,s),n&&(se(t,o),ne(t,o))):r.error?n&&ae(t,o,r.error):(n&&(re(t,!0),se(t,o)),a.loadId=r.load(()=>{re(t,!1),t.destroyed||(ie(t,e,i,r,a,s)&&(r.hasAlphaPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),ne(t,o)),a.loadId=void 0},e=>{re(t,!1),ae(t,o,e),a.loadId=void 0}),t.placeholderColor&&(t.placeholderDelay?setTimeout(()=>{r.ready||(r.isPlacehold=!0,t.forceUpdate("surface"))},t.placeholderDelay):r.isPlacehold=!0)),a},checkImage:function(t,e,s,n){const{scaleX:a,scaleY:o}=t.getRenderScaleData(!0,s.scaleFixed),{pixelRatio:l}=e,{data:d}=s;if(!d||s.patternId===a+"-"+o+"-"+l&&!G.running)return!1;if(n)if(d.repeat)n=!1;else if(!(s.changeful||"miniapp"===i.name&&r.isResizing(t)||G.running)){let{width:t,height:e}=d;t*=a*l,e*=o*l,d.scaleX&&(t*=d.scaleX,e*=d.scaleY),n=t*e>i.image.maxCacheSize}return n?(t.__.__isFastShadow&&(e.fillStyle=s.style||"#000",e.fill()),function(t,e,i,s){e.save(),e.clipUI(t),i.blendMode&&(e.blendMode=i.blendMode);s.opacity&&(e.opacity*=s.opacity);s.transform&&e.transform(s.transform);e.drawImage(i.image.getFull(s.filters),0,0,s.width,s.height),e.restore()}(t,e,s,d),!0):(!s.style||s.sync||G.running?ge(t,s,l):s.patternTask||(s.patternTask=R.patternTasker.add(()=>_e(this,void 0,void 0,function*(){s.patternTask=null,e.bounds.hit(t.__nowWorld)&&ge(t,s,l),t.forceUpdate("surface")}),300)),!1)},createPattern:ge,recycleImage:function(t,e){const i=e["_"+t];if(b(i)){let s,n,a,o,r;for(let l=0,d=i.length;l<d;l++)s=i[l],n=s.image,r=n&&n.url,r&&(a||(a={}),a[r]=!0,R.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],b(o)||(o=[o])),n.unload(i[l].loadId,!o.some(t=>t.url===r))));return a}return null},createData:Zt,getPatternData:$t,fillOrFitMode:Vt,clipMode:Yt,repeatMode:Gt},{toPoint:me}=M,{hasTransparent:ye}=V,ve={},xe={};function be(t,e,i,n){if(i){let a,o,r,l;for(let t=0,d=i.length;t<d;t++)a=i[t],s(a)?(r=t/(d-1),o=V.string(a,n)):(r=a.offset,o=V.string(a.color,n)),e.addColorStop(r,o),!l&&ye(o)&&(l=!0);l&&(t.isTransparent=!0)}}const{getAngle:ke,getDistance:Se}=D,{get:Be,rotateOfOuter:Re,scaleOfOuter:Ee}=O,{toPoint:Le}=M,Ae={},Ce={};function Oe(t,e,i,s,n){let a;const{width:o,height:r}=t;if(o!==r||s){const t=ke(e,i);a=Be(),n?(Ee(a,e,o/r*(s||1),1),Re(a,e,t+90)):(Ee(a,e,1,o/r*(s||1)),Re(a,e,t))}return a}const{getDistance:Te}=D,{toPoint:We}=M,De={},Pe={};const Me={linearGradient:function(t,e){let{from:s,to:n,type:a,opacity:o}=t;me(s||"top",e,ve),me(n||"bottom",e,xe);const r=i.canvas.createLinearGradient(ve.x,ve.y,xe.x,xe.y),l={type:a,style:r};return be(l,r,t.stops,o),l},radialGradient:function(t,e){let{from:s,to:n,type:a,opacity:o,stretch:r}=t;Le(s||"center",e,Ae),Le(n||"bottom",e,Ce);const l=i.canvas.createRadialGradient(Ae.x,Ae.y,0,Ae.x,Ae.y,Se(Ae,Ce)),d={type:a,style:l};be(d,l,t.stops,o);const h=Oe(e,Ae,Ce,r,!0);return h&&(d.transform=h),d},conicGradient:function(t,e){let{from:s,to:n,type:a,opacity:o,stretch:r}=t;We(s||"center",e,De),We(n||"bottom",e,Pe);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,De.x,De.y):i.canvas.createRadialGradient(De.x,De.y,0,De.x,De.y,Te(De,Pe)),d={type:a,style:l};be(d,l,t.stops,o);const h=Oe(e,De,Pe,r||1,i.conicGradientRotate90);return h&&(d.transform=h),d},getTransform:Oe},{copy:Ie,toOffsetOutBounds:ze}=L,Fe={},Ue={};function Ve(t,e,s,n){const{bounds:a,shapeBounds:o}=n;if(i.fullImageShadow){if(Ie(Fe,t.bounds),Fe.x+=e.x-o.x,Fe.y+=e.y-o.y,s){const{fitMatrix:t}=n;Fe.x-=(a.x+(t?t.e:0)+a.width/2)*(s-1),Fe.y-=(a.y+(t?t.f:0)+a.height/2)*(s-1),Fe.width*=s,Fe.height*=s}t.copyWorld(n.canvas,t.bounds,Fe)}else s&&(Ie(Fe,e),Fe.x-=e.width/2*(s-1),Fe.y-=e.height/2*(s-1),Fe.width*=s,Fe.height*=s),t.copyWorld(n.canvas,o,s?Fe:e)}const{toOffsetOutBounds:Ye}=L,Ge={};const Ne={shadow:function(t,e,i){let s,n;const{__nowWorld:a,__layout:o}=t,{shadow:r}=t.__,{worldCanvas:l,bounds:d,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;ze(d,Ue),r.forEach((r,g)=>{let _=1;if(r.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.setWorldShadow(Ue.offsetX+r.x*c*_,Ue.offsetY+r.y*u*_,r.blur*c*_,V.string(r.color)),n=r.spread?1+2*r.spread/(o.boxBounds.width+2*(o.strokeBoxSpread||0))*_:0,Ve(f,Ue,n,i),s=d,r.box&&(f.restore(),f.save(),l&&(f.copyWorld(f,d,a,"copy"),s=a),l?f.copyWorld(l,a,a,"destination-out"):f.copyWorld(i.canvas,h,d,"destination-out")),m.copyCanvasByWorld(t,e,f,s,r.blendMode),p&&g<p&&f.clearWorld(s)}),f.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:a,__layout:o}=t,{innerShadow:r}=t.__,{worldCanvas:l,bounds:d,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Ye(d,Ge),r.forEach((r,g)=>{let _=1;if(r.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.save(),f.setWorldShadow(Ge.offsetX+r.x*c*_,Ge.offsetY+r.y*u*_,r.blur*c*_),n=r.spread?1-2*r.spread/(o.boxBounds.width+2*(o.strokeBoxSpread||0))*_:0,Ve(f,Ge,n,i),f.restore(),l?(f.copyWorld(f,d,a,"copy"),f.copyWorld(l,a,a,"source-out"),s=a):(f.copyWorld(i.canvas,h,d,"source-out"),s=d),f.fillWorld(s,V.string(r.color),"source-in"),m.copyCanvasByWorld(t,e,f,s,r.blendMode),p&&g<p&&f.clearWorld(s)}),f.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Xe}=v;let qe;function je(t,e,i,s,n,a,o,r){switch(e){case"grayscale":qe||(qe=!0,n.useGrayscaleAlpha(t.__nowWorld));case"alpha":!function(t,e,i,s,n,a){const o=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,o),a&&s.recycle(o);Qe(t,e,i,1,n,a)}(t,i,s,n,o,r);break;case"opacity-path":Qe(t,i,s,a,o,r);break;case"path":r&&i.restore()}}function He(t){return t.getSameCanvas(!1,!0)}function Qe(t,e,i,s,n,a){const o=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,o,void 0,n),a?i.recycle(o):i.clearWorld(o)}N.prototype.__renderMask=function(t,e){let i,s,n,a,o,r;const{children:l}=this;for(let d=0,h=l.length;d<h;d++){if(i=l[d],r=i.__.mask,r){o&&(je(this,o,t,n,s,a,void 0,!0),s=n=null),a=i.__.opacity,qe=!1,"path"===r||"clipping-path"===r?(a<1?(o="opacity-path",n||(n=He(t))):(o="path",t.save()),i.__clip(n||t,e)):(o="grayscale"===r?"grayscale":"alpha",s||(s=He(t)),n||(n=He(t)),i.__render(s,e)),"clipping"!==r&&"clipping-path"!==r||Xe(i,e)||i.__render(t,e);continue}const h=1===a&&i.__.__blendMode;h&&je(this,o,t,n,s,a,void 0,!1),Xe(i,e)||i.__render(n||t,e),h&&je(this,o,t,n,s,a,h,!1)}je(this,o,t,n,s,a,void 0,!0)};const Ze=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",$e=Ze+"_#~&*+\\=|≮≯≈≠=…",Je=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 Ke(t){const e={};return t.split("").forEach(t=>e[t]=!0),e}const ti=Ke("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ei=Ke("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ii=Ke(Ze),si=Ke($e),ni=Ke("- —/~|┆·");var ai;!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"}(ai||(ai={}));const{Letter:oi,Single:ri,Before:li,After:di,Symbol:hi,Break:ci}=ai;function ui(t){return ti[t]?oi:ni[t]?ci:ei[t]?li:ii[t]?di:si[t]?hi:Je.test(t)?ri:oi}const fi={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let a=n-1;a>-1&&(i=e[a].data[0]," "===i.char);a--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function pi(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:gi}=fi,{Letter:_i,Single:wi,Before:mi,After:yi,Symbol:vi,Break:xi}=ai;let bi,ki,Si,Bi,Ri,Ei,Li,Ai,Ci,Oi,Ti,Wi,Di,Pi,Mi,Ii,zi,Fi=[];function Ui(t,e){Ci&&!Ai&&(Ai=Ci),bi.data.push({char:t,width:e}),Si+=e}function Vi(){Bi+=Si,bi.width=Si,ki.words.push(bi),bi={data:[]},Si=0}function Yi(){Pi&&(Mi.paraNumber++,ki.paraStart=!0,Pi=!1),Ci&&(ki.startCharSize=Ai,ki.endCharSize=Ci,Ai=0),ki.width=Bi,Ii.width?gi(ki):zi&&Gi(),Fi.push(ki),ki={words:[]},Bi=0}function Gi(){Bi>(Mi.maxWidth||0)&&(Mi.maxWidth=Bi)}const{top:Ni,right:Xi,bottom:qi,left:ji}=I;function Hi(t,e,i){const{bounds:s,rows:n}=t;s[e]+=i;for(let t=0;t<n.length;t++)n[t][e]+=i}const Qi={getDrawData:function(t,e){s(t)||(t=String(t));let n=0,a=0,o=e.__getInput("width")||0,r=e.__getInput("height")||0;const{textDecoration:l,__font:d,__padding:h}=e;h&&(o?(n=h[ji],o-=h[Xi]+h[ji]):e.autoSizeAlign||(n=h[ji]),r?(a=h[Ni],r-=h[Ni]+h[qi]):e.autoSizeAlign||(a=h[Ni]));const c={bounds:{x:n,y:a,width:o,height:r},rows:[],paraNumber:0,font:i.canvas.font=d};return function(t,e,s){Mi=t,Fi=t.rows,Ii=t.bounds,zi=!Ii.width&&!s.autoSizeAlign;const{__letterSpacing:n,paraIndent:a,textCase:o}=s,{canvas:r}=i,{width:l,height:d}=Ii;if(l||d||n||"none"!==o){const t="none"!==s.textWrap,i="break"===s.textWrap;Pi=!0,Ti=null,Ai=Li=Ci=Si=Bi=0,bi={data:[]},ki={words:[]},n&&(e=[...e]);for(let s=0,d=e.length;s<d;s++)Ei=e[s],"\n"===Ei?(Si&&Vi(),ki.paraEnd=!0,Yi(),Pi=!0):(Oi=ui(Ei),Oi===_i&&"none"!==o&&(Ei=pi(Ei,o,!Si)),Li=r.measureText(Ei).width,n&&(n<0&&(Ci=Li),Li+=n),Wi=Oi===wi&&(Ti===wi||Ti===_i)||Ti===wi&&Oi!==yi,Di=!(Oi!==mi&&Oi!==wi||Ti!==vi&&Ti!==yi),Ri=Pi&&a?l-a:l,t&&l&&Bi+Si+Li>Ri&&(i?(Si&&Vi(),Bi&&Yi()):(Di||(Di=Oi===_i&&Ti==yi),Wi||Di||Oi===xi||Oi===mi||Oi===wi||Si+Li>Ri?(Si&&Vi(),Bi&&Yi()):Bi&&Yi()))," "===Ei&&!0!==Pi&&Bi+Si===0||(Oi===xi?(" "===Ei&&Si&&Vi(),Ui(Ei,Li),Vi()):Wi||Di?(Si&&Vi(),Ui(Ei,Li)):Ui(Ei,Li)),Ti=Oi);Si&&Vi(),Bi&&Yi(),Fi.length>0&&(Fi[Fi.length-1].paraEnd=!0)}else e.split("\n").forEach(t=>{Mi.paraNumber++,Bi=r.measureText(t).width,Fi.push({x:a||0,text:t,width:Bi,paraStart:!0}),zi&&Gi()})}(c,t,e),h&&function(t,e,i,s,n){if(!s&&i.autoSizeAlign)switch(i.textAlign){case"left":Hi(e,"x",t[ji]);break;case"right":Hi(e,"x",-t[Xi])}if(!n&&i.autoSizeAlign)switch(i.verticalAlign){case"top":Hi(e,"y",t[Ni]);break;case"bottom":Hi(e,"y",-t[qi])}}(h,c,e,o,r),function(t,e){const{rows:i,bounds:s}=t,n=i.length,{__lineHeight:a,__baseLine:o,__letterSpacing:r,__clipText:l,textAlign:d,verticalAlign:h,paraSpacing:c,autoSizeAlign:u}=e;let{x:f,y:p,width:g,height:_}=s,w=a*n+(c?c*(t.paraNumber-1):0),m=o;if(l&&w>_)w=Math.max(_,a),n>1&&(t.overflow=n);else if(_||u)switch(h){case"middle":p+=(_-w)/2;break;case"bottom":p+=_-w}m+=p;let y,v,x,b=g||u?g:t.maxWidth;for(let o=0,h=n;o<h;o++){if(y=i[o],y.x=f,y.width<g||y.width>g&&!l)switch(d){case"center":y.x+=(b-y.width)/2;break;case"right":y.x+=b-y.width}y.paraStart&&c&&o>0&&(m+=c),y.y=m,m+=a,t.overflow>o&&m>w&&(y.isOverflow=!0,t.overflow=o+1),v=y.x,x=y.width,r<0&&(y.width<0?(x=-y.width+e.fontSize+r,v-=x,x+=e.fontSize):x-=r),v<s.x&&(s.x=v),x>s.width&&(s.width=x),l&&g&&g<x&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=w}(c,e),function(t,e,i){const{rows:s}=t,{textAlign:n,paraIndent:a,letterSpacing:o}=e;let r,l,d,h,c,u;s.forEach(t=>{t.words&&(d=a&&t.paraStart?a:0,u=t.words.length,l=i&&("justify"===n||"both"===n)&&u>1?(i-t.width-d)/(u-1):0,h=o||t.isOverflow?0:l>.01?1:2,t.isOverflow&&!o&&(t.textMode=!0),2===h?(t.x+=d,function(t){t.text="",t.words.forEach(e=>{e.data.forEach(e=>{t.text+=e.char})})}(t)):(t.x+=d,r=t.x,t.data=[],t.words.forEach((e,i)=>{1===h?(c={char:"",x:r},r=function(t,e,i){return t.forEach(t=>{i.char+=t.char,e+=t.width}),e}(e.data,r,c),(t.isOverflow||" "!==c.char)&&t.data.push(c)):r=function(t,e,i,s){return t.forEach(t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width}),e}(e.data,r,t.data,t.isOverflow),!l||t.paraEnd&&"both"!==n||i===u-1||(r+=l,t.width+=l)})),t.words=null)})}(c,e,o),c.overflow&&function(t,e,s,n){if(!n)return;const{rows:a,overflow:o}=t;let{textOverflow:r}=e;if(a.splice(o),r&&"show"!==r){let t,l;"hide"===r?r="":"ellipsis"===r&&(r="...");const d=r?i.canvas.measureText(r).width:0,h=s+n-d;("none"===e.textWrap?a:[a[o-1]]).forEach(e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],l=t.x+t.width,!(s===i&&l<h));s--){if(l<h&&" "!==t.char||!s){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=d,e.data.push({char:r,x:l}),e.textMode&&function(t){t.text="",t.data.forEach(e=>{t.text+=e.char}),t.data=null}(e)}})}}(c,e,n,o),"none"!==l&&function(t,e){let i;const{fontSize:s,textDecoration:n}=e;switch(t.decorationHeight=s/11,E(n)?(i=n.type,n.color&&(t.decorationColor=V.string(n.color))):i=n,i){case"under":t.decorationY=[.15*s];break;case"delete":t.decorationY=[.35*-s];break;case"under-delete":t.decorationY=[.15*s,.35*-s]}}(c,e),c}};const Zi={string:function(t,e){const i=z(e)&&e<1;if(s(t)){if(!i||!V.object)return t;t=V.object(t)}let a=n(t.a)?1:t.a;i&&(a*=e);const o=t.r+","+t.g+","+t.b;return 1===a?"rgb("+o+")":"rgba("+o+","+a+")"}};Object.assign(X,Qi),Object.assign(V,Zi),Object.assign(U,Ct),Object.assign(F,we),Object.assign(Y,Me),Object.assign(q,Ne),$();export{ht as Layouter,H as LeaferCanvas,ut as Renderer,K as Watcher,$ as useCanvas};
|
|
1
|
+
import{Debug as t,LeaferCanvasBase as e,Platform as i,isString as s,isUndefined as n,DataHelper as a,canvasSizeAttrs as o,ResizeEvent as r,canvasPatch as l,FileHelper as h,Creator as d,LeaferImage as c,defineKey as u,LeafList as f,RenderEvent as p,ChildEvent as g,WatchEvent as _,PropertyEvent as w,LeafHelper as m,BranchHelper as y,LeafBoundsHelper as v,Bounds as x,isArray as b,LeafLevelList as S,LayoutEvent as k,Run as B,ImageManager as R,isObject as E,BoundsHelper as L,Matrix as A,getMatrixData as C,MatrixHelper as O,MathHelper as T,AlignHelper as W,PointHelper as M,ImageEvent as D,AroundHelper as P,Direction4 as I,isNumber as z}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as F,Paint as U,ColorConvert as V,PaintGradient as Y,Export as G,Effect as N,Group as X,TextConvert as q}from"@leafer-ui/draw";export*from"@leafer-ui/draw";const j=t.get("LeaferCanvas");class H extends e{set zIndex(t){const{style:e}=this.view;e.zIndex=t,this.setAbsolute(this.view)}set childIndex(t){const{view:e,parentView:i}=this;if(e&&i){const s=i.children[t];s?(this.setAbsolute(s),i.insertBefore(e,s)):i.appendChild(s)}}init(){const{config:t}=this,e=t.view||t.canvas;e?this.__createViewFrom(e):this.__createView();const{style:s}=this.view;if(s.display||(s.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}i.syncDomFont&&!this.parentView&&(s.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=s(t)?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;t.hasChildNodes()&&(this.setAbsolute(i),t.style.position||(t.style.position="relative")),t.appendChild(i)}else j.error(`no id: ${t}`),this.__createView()}setAbsolute(t){const{style:e}=t;e.position="absolute",e.top=e.left="0px"}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;if(this.unreal){const{config:t,autoWidthStr:e,autoHeightStr:i}=this;t.width?(n(e)&&(this.autoWidthStr=s.width||""),s.width=t.width+"px"):n(e)||(s.width=e),t.height?(n(i)&&(this.autoHeightStr=s.height||""),s.height=t.height+"px"):n(i)||(s.height=i)}else s.width=t+"px",s.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.view.parentElement&&(this.clientBounds=this.view.getBoundingClientRect())}startAutoLayout(t,e){if(this.resizeListener=e,t){if(this.autoBounds=t,this.resizeObserver)return;try{this.resizeObserver=new ResizeObserver(t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)});const t=this.parentView;t?(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect())):(this.checkAutoBounds(this.view),j.warn("no parent"))}catch(t){this.imitateResizeObserver()}this.stopListenPixelRatio()}else this.listenPixelRatio(),this.unreal&&this.updateViewSize()}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}listenPixelRatio(){this.windowListener||window.addEventListener("resize",this.windowListener=()=>{const t=i.devicePixelRatio;if(!this.config.pixelRatio&&this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}})}stopListenPixelRatio(){this.windowListener&&(window.removeEventListener("resize",this.windowListener),this.windowListener=null)}checkAutoBounds(t){const e=this.view,{x:s,y:n,width:a,height:o}=this.autoBounds.getBoundsFrom(t),r={width:a,height:o,pixelRatio:this.config.pixelRatio?this.pixelRatio:i.devicePixelRatio};if(!this.isSameSize(r)){const{style:t}=e;t.marginLeft=s+"px",t.marginTop=n+"px",this.emitResize(r)}}stopAutoLayout(){this.autoLayout=!1,this.resizeObserver&&this.resizeObserver.disconnect(),this.resizeListener=this.resizeObserver=null}emitResize(t){const e={};a.copyAttrs(e,this,o),this.resize(t),this.resizeListener&&!n(this.width)&&this.resizeListener(new r(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.stopListenPixelRatio(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}l(CanvasRenderingContext2D.prototype),l(Path2D.prototype);const{mineType:Q,fileType:Z}=h;function $(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>{const s=Q(e),n=t.toDataURL(s,i);return"image/bmp"===s?n.replace("image/png;","image/bmp;"):n},canvasToBolb:(t,e,i)=>new Promise(s=>t.toBlob(s,Q(e),i)),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(Q(Z(e)),s);return i.origin.download(n,e)},download:(t,e)=>new Promise(i=>{let s=document.createElement("a");s.href=t,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),i()}),loadImage:t=>new Promise((e,s)=>{const n=new i.origin.Image,{crossOrigin:a}=i.image;a&&(n.setAttribute("crossOrigin",a),n.crossOrigin=a),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},n.src=i.image.getRealURL(t)}),Image:Image,PointerEvent:PointerEvent,DragEvent:DragEvent},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=d.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(d,{canvas:(t,e)=>new H(t,e),image:t=>new c(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},u(i,"devicePixelRatio",{get:()=>devicePixelRatio});const{userAgent:J}=navigator;J.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):(/iPhone|iPad|iPod/.test(navigator.userAgent)||/Macintosh/.test(navigator.userAgent)&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent))&&(i.fullImageShadow=!0),J.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):J.indexOf("Mac")>-1?i.os="Mac":J.indexOf("Linux")>-1&&(i.os="Linux");class K{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new f;return this.__updatedList.list.forEach(e=>{e.leafer&&t.add(e)}),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new f,this.target=t,e&&(this.config=a.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(p.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===g.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new _(_.DATA,{updatedList:this.updatedList})),this.__updatedList=new f,this.totalTimes++,this.changed=this.hasVisible=this.hasRemove=this.hasAdd=!1}__listenEvents(){this.__eventIds=[this.target.on_([[w.CHANGE,this.__onAttrChange,this],[[g.ADD,g.REMOVE],this.__onChildEvent,this],[_.REQUEST,this.__onRquestData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.__updatedList=null)}}const{updateAllMatrix:tt,updateBounds:et,updateChange:it}=m,{pushAllChildBranch:st,pushAllParent:nt}=y;const{worldBounds:at}=v;class ot{constructor(t){this.updatedBounds=new x,this.beforeBounds=new x,this.afterBounds=new x,b(t)&&(t=new f(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,at)}setAfter(){this.afterBounds.setListWithFn(this.updatedList.list,at),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:rt,updateAllChange:lt}=m,ht=t.get("Layouter");class dt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new S,this.target=t,e&&(this.config=a.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(this.layouting||!this.running)return;const{target:t}=this;this.times=0;try{t.emit(k.START),this.layoutOnce(),t.emitEvent(new k(k.END,this.layoutedBlocks,this.times))}catch(t){ht.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ht.warn("layouting"):this.times>3?ht.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(_.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:s}=this,{BEFORE:n,LAYOUT:a,AFTER:o}=k,r=this.getBlocks(s);r.forEach(t=>t.setBefore()),i.emitEvent(new k(n,r,this.times)),this.extraBlock=null,s.sort(),function(t,e){let i;t.list.forEach(t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(tt(t,!0),e.add(t),t.isBranch&&st(t,e),nt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),nt(t,e)))})}(s,this.__levelList),function(t){let e,i,s;t.sort(!0),t.levels.forEach(n=>{e=t.levelMap[n];for(let t=0,n=e.length;t<n;t++){if(i=e[t],i.isBranch&&i.__tempNumber){s=i.children;for(let t=0,e=s.length;t<e;t++)s[t].isBranch||et(s[t])}et(i)}})}(this.__levelList),function(t){t.list.forEach(it)}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach(t=>t.setAfter()),i.emitEvent(new k(a,r,this.times)),i.emitEvent(new k(o,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:s,AFTER:n}=k,a=this.getBlocks(new f(e));e.emitEvent(new k(i,a,this.times)),dt.fullLayout(e),a.forEach(t=>{t.setAfter()}),e.emitEvent(new k(s,a,this.times)),e.emitEvent(new k(n,a,this.times)),this.addBlocks(a),B.end(t)}static fullLayout(t){rt(t,!0),t.isBranch?y.updateBounds(t):m.updateBounds(t),lt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new ot([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new ot(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){this.__eventIds=[this.target.on_([[k.REQUEST,this.layout,this],[k.AGAIN,this.layoutAgain,this],[_.DATA,this.__onReceiveWatchData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const ct=t.get("Renderer");class ut{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:120},this.target=t,this.canvas=e,i&&(this.config=a.default(i,this.config)),this.__listenEvents()}start(){this.running=!0,this.update(!1)}stop(){this.running=!1}update(t=!0){this.changed||(this.changed=t),this.__requestRender()}requestLayout(){this.target.emit(k.REQUEST)}checkRender(){if(this.running){const{target:t}=this;t.isApp&&(t.emit(p.CHILD_START,t),t.children.forEach(t=>{t.renderer.FPS=this.FPS,t.renderer.checkRender()}),t.emit(p.CHILD_END,t)),this.changed&&this.canvas.view&&this.render(),this.target.emit(p.NEXT)}}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new x,ct.log(e.innerName,"---\x3e");try{this.emitRender(p.START),this.renderOnce(t),this.emitRender(p.END,this.totalBounds),R.clearRecycled()}catch(t){this.rendering=!1,ct.error(t)}ct.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return ct.warn("rendering");if(this.times>3)return ct.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new x,this.renderOptions={},t)this.emitRender(p.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(p.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(p.RENDER,this.renderBounds,this.renderOptions),this.emitRender(p.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;e&&(this.mergeBlocks(),e.forEach(e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=B.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=new x(s);i.save(),s.spread(ut.clipSpread).ceil(),i.clearWorld(s),i.clipWorld(s),this.__render(s,n),i.restore(),B.end(e)}fullRender(){const t=B.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds),e.restore(),B.end(t)}__render(e,i){const{canvas:s}=this,n=e.includes(this.target.__world),a=n?{includes:n}:{bounds:e,includes:n};this.needFill&&s.fillWorld(e,this.config.fill),t.showRepaint&&t.drawRepaint(s,e),this.target.__render(s,a),this.renderBounds=i=i||e,this.renderOptions=a,this.totalBounds.isEmpty()?this.totalBounds=i:this.totalBounds.add(i),s.updateRender(i)}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new x;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=this.target;if(this.requestTime||!t)return;if(t.parentApp)return t.parentApp.requestRender(!1);const e=this.requestTime=Date.now(),s=()=>{const t=1e3/(Date.now()-e),{maxFPS:n}=this.config;if(n&&t>n-.5)return i.requestRender(s);this.FPS=Math.min(120,Math.ceil(t)),this.requestTime=0,this.checkRender()};i.requestRender(s)}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new x(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new x(0,0,1,1)),this.update()}}__onLayoutEnd(t){t.data&&t.data.map(t=>{let e;t.updatedList&&t.updatedList.list.some(t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||ct.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 p(t,this.times,e,i))}__listenEvents(){this.__eventIds=[this.target.on_([[p.REQUEST,this.update,this],[k.END,this.__onLayoutEnd,this],[p.AGAIN,this.renderAgain,this],[r.RESIZE,this.__onResize,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.config={},this.target=this.canvas=null)}}function ft(t,e){const i=t.__,{rows:s,decorationY:n}=i.__textDrawData;let a;i.__isPlacehold&&i.placeholderColor&&(e.fillStyle=i.placeholderColor);for(let t=0,i=s.length;t<i;t++)a=s[t],a.text?e.fillText(a.text,a.x,a.y):a.data&&a.data.forEach(t=>{e.fillText(t.char,t.x,a.y)});if(n){const{decorationColor:t,decorationHeight:a}=i.__textDrawData;t&&(e.fillStyle=t),s.forEach(t=>n.forEach(i=>e.fillRect(t.x,t.y+i,t.width,a)))}}function pt(t,e){t.__.__font?ft(t,e):t.__.windingRule?e.fill(t.__.windingRule):e.fill()}function gt(t,e,i){switch(e.__.strokeAlign){case"center":_t(t,1,e,i);break;case"inside":wt(t,"inside",e,i);break;case"outside":e.__.__fillAfterStroke?_t(t,2,e,i):wt(t,"outside",e,i)}}function _t(t,e,i,s){const n=i.__;E(t)?yt(t,e,!0,i,s):(s.setStroke(t,n.__strokeWidth*e,n),mt(i,s))}function wt(t,e,i,s){const n=s.getSameCanvas(!0,!0);n.font=i.__.__font,_t(t,2,i,n),n.blendMode="outside"===e?"destination-out":"destination-in",ft(i,n),n.blendMode="normal",m.copyCanvasByWorld(i,s,n),n.recycle(i.__nowWorld)}function mt(t,e){let i,s=t.__.__textDrawData;const{rows:n,decorationY:a}=s;for(let t=0,s=n.length;t<s;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)});if(a){const{decorationHeight:t}=s;n.forEach(i=>a.forEach(s=>e.strokeRect(i.x,i.y+s,i.width,t)))}}function yt(t,e,i,s,n){let a;const o=s.__,{__hasMultiStrokeStyle:r}=o;r||n.setStroke(void 0,o.__strokeWidth*e,o);for(let l=0,h=t.length;l<h;l++)if(a=t[l],(!a.image||!F.checkImage(s,n,a,!1))&&a.style){if(r){const{strokeStyle:t}=a;t?n.setStroke(a.style,o.__getRealStrokeWidth(t)*e,o,t):n.setStroke(a.style,o.__strokeWidth*e,o)}else n.strokeStyle=a.style;a.blendMode?(n.saveBlendMode(a.blendMode),i?mt(s,n):n.stroke(),n.restoreBlendMode()):i?mt(s,n):n.stroke()}}function vt(t,e,i){const s=e.__;if(s.__strokeWidth)if(s.__font)gt(t,e,i);else switch(s.strokeAlign){case"center":xt(t,1,e,i);break;case"inside":!function(t,e,i){i.save(),i.clipUI(e),xt(t,2,e,i),i.restore()}(t,e,i);break;case"outside":!function(t,e,i){const s=e.__;if(s.__fillAfterStroke)xt(t,2,e,i);else{const{renderBounds:n}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),xt(t,2,e,a),a.clipUI(s),a.clearWorld(n),m.copyCanvasByWorld(e,i,a),a.recycle(e.__nowWorld)}}(t,e,i)}}function xt(t,e,i,s){const n=i.__;E(t)?yt(t,e,!1,i,s):(s.setStroke(t,n.__strokeWidth*e,n),s.stroke()),n.__useArrow&&U.strokeArrow(t,i,s)}ut.clipSpread=10,Object.assign(d,{watcher:(t,e)=>new K(t,e),layouter:(t,e)=>new dt(t,e),renderer:(t,e,i)=>new ut(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,s)=>{}}),i.layout=dt.fullLayout;const{getSpread:bt,getOuterOf:St,getByMove:kt,getIntersectData:Bt}=L;let Rt;const{stintSet:Et}=a,{hasTransparent:Lt}=V;function At(t,e,i){if(!E(e)||!1===e.visible||0===e.opacity)return;let a;const{boxBounds:o}=i.__layout;switch(e.type){case"image":a=F.image(i,t,e,o,!Rt||!Rt[e.url]);break;case"linear":a=Y.linearGradient(e,o);break;case"radial":a=Y.radialGradient(e,o);break;case"angular":a=Y.conicGradient(e,o);break;case"solid":const{type:s,color:r,opacity:l}=e;a={type:s,style:V.string(r,l)};break;default:n(e.r)||(a={type:"solid",style:V.string(e)})}if(a){if(s(a.style)&&Lt(a.style)&&(a.isTransparent=!0),e.style){if(0===e.style.strokeWidth)return;a.strokeStyle=e.style}e.editing&&(a.editing=e.editing),e.blendMode&&(a.blendMode=e.blendMode)}return a}const Ct={compute:function(t,e){const i=e.__,s=[];let n,a,o,r=i.__input[t];b(r)||(r=[r]),Rt=F.recycleImage(t,i);for(let i,n=0,a=r.length;n<a;n++)(i=At(t,r[n],e))&&(s.push(i),i.strokeStyle&&(o||(o=1),i.strokeStyle.strokeWidth&&(o=Math.max(o,i.strokeStyle.strokeWidth))));i["_"+t]=s.length?s:void 0,s.length&&s.every(t=>t.isTransparent)&&(s.some(t=>t.image)&&(n=!0),a=!0),"fill"===t?(Et(i,"__isAlphaPixelFill",n),Et(i,"__isTransparentFill",a)):(Et(i,"__isAlphaPixelStroke",n),Et(i,"__isTransparentStroke",a),Et(i,"__hasMultiStrokeStyle",o))},fill:function(t,e,i){i.fillStyle=t,pt(e,i)},fills:function(t,e,i){let s;for(let n=0,a=t.length;n<a;n++){if(s=t[n],s.image){if(F.checkImage(e,i,s,!e.__.__font))continue;if(!s.style){!n&&s.image.isPlacehold&&e.drawImagePlaceholder(i,s.image);continue}}if(i.fillStyle=s.style,s.transform||s.scaleFixed){if(i.save(),s.transform&&i.transform(s.transform),s.scaleFixed){const{scaleX:t,scaleY:n}=e.getRenderScaleData(!0);(!0===s.scaleFixed||"zoom-in"===s.scaleFixed&&t>1&&n>1)&&i.scale(1/t,1/n)}s.blendMode&&(i.blendMode=s.blendMode),pt(e,i),i.restore()}else s.blendMode?(i.saveBlendMode(s.blendMode),pt(e,i),i.restoreBlendMode()):pt(e,i)}},fillPathOrText:pt,fillText:ft,stroke:vt,strokes:function(t,e,i){vt(t,e,i)},strokeText:gt,drawTextStroke:mt,shape:function(t,e,s){const n=e.getSameCanvas(),a=t.__nowWorld,o=e.bounds;let r,l,h,d,c,{scaleX:u,scaleY:f}=t.getRenderScaleData(!0);if(o.includes(a))c=n,r=d=a;else{const{renderShapeSpread:n}=t.__layout;let p;if(i.fullImageShadow)p=a;else{const t=n?bt(o,u===f?n*u:[n*f,n*u]):o;p=Bt(t,a)}h=o.getFitMatrix(p);let{a:g,d:_}=h;h.a<1&&(c=e.getSameCanvas(),t.__renderShape(c,s),u*=g,f*=_),d=St(a,h),r=kt(d,-h.e,-h.f);const w=s.matrix;w?(l=new A(h),l.multiply(w),g*=w.scaleX,_*=w.scaleY):l=h,l.withScale(g,_),s=Object.assign(Object.assign({},s),{matrix:l})}return t.__renderShape(n,s),{canvas:n,matrix:l,fitMatrix:h,bounds:r,worldCanvas:c,shapeBounds:d,scaleX:u,scaleY:f}}};let Ot={},Tt=C();const{get:Wt,rotateOfOuter:Mt,translate:Dt,scaleOfOuter:Pt,multiplyParent:It,scale:zt,rotate:Ft,skew:Ut}=O;function Vt(t,e,i,s,n,a,o){const r=Wt();Dt(r,e.x+i,e.y+s),zt(r,n,a),o&&Mt(r,{x:e.x+e.width/2,y:e.y+e.height/2},o),t.transform=r}function Yt(t,e,i,s,n,a,o,r,l){const h=Wt();Nt(h,e,i,s,n,a,o,r),l&&(Tt.a=e.width/l.width,Tt.d=e.height/l.height,It(h,Tt)),t.transform=h}function Gt(t,e,i,s,n,a,o,r,l,h,d,c){const u=Wt();if(c)Nt(u,e,n,a,o,r,l,h);else{if(l)if("center"===d)Mt(u,{x:i/2,y:s/2},l);else switch(Ft(u,l),l){case 90:Dt(u,s,0);break;case 180:Dt(u,i,s);break;case 270:Dt(u,0,i)}Ot.x=e.x+n,Ot.y=e.y+a,Dt(u,Ot.x,Ot.y),o&&Pt(u,Ot,o,r)}t.transform=u}function Nt(t,e,i,s,n,a,o,r){o&&Ft(t,o),r&&Ut(t,r.x,r.y),n&&zt(t,n,a),Dt(t,e.x+i,e.y+s)}const{get:Xt,translate:qt}=O,jt=new x,Ht={},Qt={};function Zt(t,e,i,s){const{changeful:n,sync:a,scaleFixed:o}=i;n&&(t.changeful=n),a&&(t.sync=a),o&&(t.scaleFixed=o),t.data=$t(i,s,e)}function $t(t,e,i){t.padding&&(e=jt.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");let{width:n,height:a}=i;const{opacity:o,mode:r,align:l,offset:h,scale:d,size:c,rotation:u,skew:f,clipSize:p,repeat:g,gap:_,filters:w}=t,m=e.width===n&&e.height===a,y={mode:r},v="center"!==l&&(u||0)%180==90;let x,b;switch(L.set(Qt,0,0,v?a:n,v?n:a),r&&"cover"!==r&&"fit"!==r?((d||c)&&(T.getScaleData(d,c,i,Ht),x=Ht.scaleX,b=Ht.scaleY),(l||_||g)&&(x&&L.scale(Qt,x,b,!0),l&&W.toPoint(l,Qt,e,Qt,!0,!0))):m&&!u||(x=b=L.getFitScale(e,Qt,"fit"!==r),L.put(e,i,l,x,!1,Qt),L.scale(Qt,x,b,!0)),h&&M.move(Qt,h),r){case"stretch":m||(n=e.width,a=e.height);break;case"normal":case"clip":(Qt.x||Qt.y||x||p||u||f)&&Yt(y,e,Qt.x,Qt.y,x,b,u,f,t.clipSize);break;case"repeat":(!m||x||u||f)&&Gt(y,e,n,a,Qt.x,Qt.y,x,b,u,f,l,t.freeTransform),g||(y.repeat="repeat");const i=E(g);(_||i)&&(y.gap=function(t,e,i,s,n){let a,o;E(t)?(a=t.x,o=t.y):a=o=t;return{x:Jt(a,i,n.width,e&&e.x),y:Jt(o,s,n.height,e&&e.y)}}(_,i&&g,Qt.width,Qt.height,e));break;default:x&&Vt(y,e,Qt.x,Qt.y,x,b,u)}return y.transform||(e.x||e.y)&&(y.transform=Xt(),qt(y.transform,e.x,e.y)),x&&"stretch"!==r&&(y.scaleX=x,y.scaleY=b),y.width=n,y.height=a,o&&(y.opacity=o),w&&(y.filters=w),g&&(y.repeat=s(g)?"x"===g?"repeat-x":"repeat-y":"repeat"),y}function Jt(t,e,i,n){const a=s(t)||n?(n?i-n*e:i%e)/((n||Math.floor(i/e))-1):t;return"auto"===t&&a<0?0:a}let Kt,te=new x;const{isSame:ee}=L;function ie(t,e,i,s,n,a){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=s.width/e.pixelRatio,e.__naturalHeight=s.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return n.data||Zt(n,s,i,a),!0}function se(t,e){oe(t,D.LOAD,e)}function ne(t,e){oe(t,D.LOADED,e)}function ae(t,e,i){e.error=i,t.forceUpdate("surface"),oe(t,D.ERROR,e)}function oe(t,e,i){t.hasEvent(e)&&t.emitEvent(new D(e,i))}function re(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:le,scale:he,copy:de}=O,{floor:ce,ceil:ue,max:fe,abs:pe}=Math;function ge(t,e,s){let{scaleX:n,scaleY:a}=t.getRenderScaleData(!0,e.scaleFixed);const o=n+"-"+a+"-"+s;if(e.patternId===o||t.destroyed)return!1;{const{image:r,data:l}=e;let h,d,{width:c,height:u,scaleX:f,scaleY:p,transform:g,repeat:_,gap:w}=l;n*=s,a*=s,f&&(f=pe(f),p=pe(p),d=le(),de(d,g),he(d,1/f,1/p),n*=f,a*=p),c*=n,u*=a;const m=c*u;if(!_&&m>i.image.maxCacheSize)return!1;let y=i.image.maxPatternSize;if(r.isSVG){const t=c/r.width;t>1&&(h=t/ue(t))}else{const t=r.width*r.height;y>t&&(y=t)}m>y&&(h=Math.sqrt(m/y)),h&&(n/=h,a/=h,c/=h,u/=h),f&&(n/=f,a/=p);const v=w&&w.x*n,x=w&&w.y*a;if(g||1!==n||1!==a){const t=c+(v||0),e=u+(x||0);n/=t/fe(ce(t),1),a/=e/fe(ce(e),1),d||(d=le(),g&&de(d,g)),he(d,1/n,1/a)}const b=r.getCanvas(c,u,l.opacity,l.filters,v,x,t.leafer&&t.leafer.config.smooth),S=r.getPattern(b,_||i.origin.noRepeat||"no-repeat",d,e);return e.style=S,e.patternId=o,!0}}function _e(t,e,i,s){return new(i||(i=Promise))(function(n,a){function o(t){try{l(s.next(t))}catch(t){a(t)}}function r(t){try{l(s.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(o,r)}l((s=s.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const we={image:function(t,e,i,s,n){let a,o;const r=R.get(i);return Kt&&i===Kt.paint&&ee(s,Kt.boxBounds)?a=Kt.leafPaint:(a={type:i.type,image:r},r.hasAlphaPixel&&(a.isTransparent=!0),Kt=r.use>1?{leafPaint:a,paint:i,boxBounds:te.set(s)}:null),(n||r.loading)&&(o={image:r,attrName:e,attrValue:i}),r.ready?(ie(t,e,i,r,a,s),n&&(se(t,o),ne(t,o))):r.error?n&&ae(t,o,r.error):(n&&(re(t,!0),se(t,o)),a.loadId=r.load(()=>{re(t,!1),t.destroyed||(ie(t,e,i,r,a,s)&&(r.hasAlphaPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),ne(t,o)),a.loadId=void 0},e=>{re(t,!1),ae(t,o,e),a.loadId=void 0}),t.placeholderColor&&(t.placeholderDelay?setTimeout(()=>{r.ready||(r.isPlacehold=!0,t.forceUpdate("surface"))},t.placeholderDelay):r.isPlacehold=!0)),a},checkImage:function(t,e,s,n){const{scaleX:a,scaleY:o}=t.getRenderScaleData(!0,s.scaleFixed),{pixelRatio:l}=e,{data:h}=s;if(!h||s.patternId===a+"-"+o+"-"+l&&!G.running)return!1;if(n)if(h.repeat)n=!1;else if(!(s.changeful||"miniapp"===i.name&&r.isResizing(t)||G.running)){let{width:t,height:e}=h;t*=a*l,e*=o*l,h.scaleX&&(t*=h.scaleX,e*=h.scaleY),n=t*e>i.image.maxCacheSize}return n?(t.__.__isFastShadow&&(e.fillStyle=s.style||"#000",e.fill()),function(t,e,i,s){e.save(),e.clipUI(t),i.blendMode&&(e.blendMode=i.blendMode);s.opacity&&(e.opacity*=s.opacity);s.transform&&e.transform(s.transform);e.drawImage(i.image.getFull(s.filters),0,0,s.width,s.height),e.restore()}(t,e,s,h),!0):(!s.style||s.sync||G.running?ge(t,s,l):s.patternTask||(s.patternTask=R.patternTasker.add(()=>_e(this,void 0,void 0,function*(){s.patternTask=null,e.bounds.hit(t.__nowWorld)&&ge(t,s,l),t.forceUpdate("surface")}),300)),!1)},createPattern:ge,recycleImage:function(t,e){const i=e["_"+t];if(b(i)){let s,n,a,o,r;for(let l=0,h=i.length;l<h;l++)s=i[l],n=s.image,r=n&&n.url,r&&(a||(a={}),a[r]=!0,R.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],b(o)||(o=[o])),n.unload(i[l].loadId,!o.some(t=>t.url===r))));return a}return null},createData:Zt,getPatternData:$t,fillOrFitMode:Vt,clipMode:Yt,repeatMode:Gt},{toPoint:me}=P,{hasTransparent:ye}=V,ve={},xe={};function be(t,e,i,n){if(i){let a,o,r,l;for(let t=0,h=i.length;t<h;t++)a=i[t],s(a)?(r=t/(h-1),o=V.string(a,n)):(r=a.offset,o=V.string(a.color,n)),e.addColorStop(r,o),!l&&ye(o)&&(l=!0);l&&(t.isTransparent=!0)}}const{getAngle:Se,getDistance:ke}=M,{get:Be,rotateOfOuter:Re,scaleOfOuter:Ee}=O,{toPoint:Le}=P,Ae={},Ce={};function Oe(t,e,i,s,n){let a;const{width:o,height:r}=t;if(o!==r||s){const t=Se(e,i);a=Be(),n?(Ee(a,e,o/r*(s||1),1),Re(a,e,t+90)):(Ee(a,e,1,o/r*(s||1)),Re(a,e,t))}return a}const{getDistance:Te}=M,{toPoint:We}=P,Me={},De={};const Pe={linearGradient:function(t,e){let{from:s,to:n,type:a,opacity:o}=t;me(s||"top",e,ve),me(n||"bottom",e,xe);const r=i.canvas.createLinearGradient(ve.x,ve.y,xe.x,xe.y),l={type:a,style:r};return be(l,r,t.stops,o),l},radialGradient:function(t,e){let{from:s,to:n,type:a,opacity:o,stretch:r}=t;Le(s||"center",e,Ae),Le(n||"bottom",e,Ce);const l=i.canvas.createRadialGradient(Ae.x,Ae.y,0,Ae.x,Ae.y,ke(Ae,Ce)),h={type:a,style:l};be(h,l,t.stops,o);const d=Oe(e,Ae,Ce,r,!0);return d&&(h.transform=d),h},conicGradient:function(t,e){let{from:s,to:n,type:a,opacity:o,stretch:r}=t;We(s||"center",e,Me),We(n||"bottom",e,De);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,Me.x,Me.y):i.canvas.createRadialGradient(Me.x,Me.y,0,Me.x,Me.y,Te(Me,De)),h={type:a,style:l};be(h,l,t.stops,o);const d=Oe(e,Me,De,r||1,i.conicGradientRotate90);return d&&(h.transform=d),h},getTransform:Oe},{copy:Ie,toOffsetOutBounds:ze}=L,Fe={},Ue={};function Ve(t,e,s,n){const{bounds:a,shapeBounds:o}=n;if(i.fullImageShadow){if(Ie(Fe,t.bounds),Fe.x+=e.x-o.x,Fe.y+=e.y-o.y,s){const{fitMatrix:t}=n;Fe.x-=(a.x+(t?t.e:0)+a.width/2)*(s-1),Fe.y-=(a.y+(t?t.f:0)+a.height/2)*(s-1),Fe.width*=s,Fe.height*=s}t.copyWorld(n.canvas,t.bounds,Fe)}else s&&(Ie(Fe,e),Fe.x-=e.width/2*(s-1),Fe.y-=e.height/2*(s-1),Fe.width*=s,Fe.height*=s),t.copyWorld(n.canvas,o,s?Fe:e)}const{toOffsetOutBounds:Ye}=L,Ge={};const Ne={shadow:function(t,e,i){let s,n;const{__nowWorld:a,__layout:o}=t,{shadow:r}=t.__,{worldCanvas:l,bounds:h,shapeBounds:d,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;ze(h,Ue),r.forEach((r,g)=>{let _=1;if(r.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.setWorldShadow(Ue.offsetX+r.x*c*_,Ue.offsetY+r.y*u*_,r.blur*c*_,V.string(r.color)),n=r.spread?1+2*r.spread/(o.boxBounds.width+2*(o.strokeBoxSpread||0))*_:0,Ve(f,Ue,n,i),s=h,r.box&&(f.restore(),f.save(),l&&(f.copyWorld(f,h,a,"copy"),s=a),l?f.copyWorld(l,a,a,"destination-out"):f.copyWorld(i.canvas,d,h,"destination-out")),N.isTransformShadow(r)?N.renderTransformShadow(t,e,f,s,r):m.copyCanvasByWorld(t,e,f,s,r.blendMode),p&&g<p&&f.clearWorld(s)}),f.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:a,__layout:o}=t,{innerShadow:r}=t.__,{worldCanvas:l,bounds:h,shapeBounds:d,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Ye(h,Ge),r.forEach((r,g)=>{let _=1;if(r.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.save(),f.setWorldShadow(Ge.offsetX+r.x*c*_,Ge.offsetY+r.y*u*_,r.blur*c*_),n=r.spread?1-2*r.spread/(o.boxBounds.width+2*(o.strokeBoxSpread||0))*_:0,Ve(f,Ge,n,i),f.restore(),l?(f.copyWorld(f,h,a,"copy"),f.copyWorld(l,a,a,"source-out"),s=a):(f.copyWorld(i.canvas,d,h,"source-out"),s=h),f.fillWorld(s,V.string(r.color),"source-in"),m.copyCanvasByWorld(t,e,f,s,r.blendMode),p&&g<p&&f.clearWorld(s)}),f.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){},getShadowSpread:function(t,e){let i=0;return e.forEach(t=>i=Math.max(i,Math.max(Math.abs(t.y),Math.abs(t.x))+(t.spread>0?t.spread:0)+1.5*t.blur)),i},isTransformShadow(t){}},{excludeRenderBounds:Xe}=v;let qe;function je(t,e,i,s,n,a,o,r){switch(e){case"grayscale":qe||(qe=!0,n.useGrayscaleAlpha(t.__nowWorld));case"alpha":!function(t,e,i,s,n,a){const o=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,o),a&&s.recycle(o);Qe(t,e,i,1,n,a)}(t,i,s,n,o,r);break;case"opacity-path":Qe(t,i,s,a,o,r);break;case"path":r&&i.restore()}}function He(t){return t.getSameCanvas(!1,!0)}function Qe(t,e,i,s,n,a){const o=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,o,void 0,n),a?i.recycle(o):i.clearWorld(o)}X.prototype.__renderMask=function(t,e){let i,s,n,a,o,r;const{children:l}=this;for(let h=0,d=l.length;h<d;h++){if(i=l[h],r=i.__.mask,r){o&&(je(this,o,t,n,s,a,void 0,!0),s=n=null),a=i.__.opacity,qe=!1,"path"===r||"clipping-path"===r?(a<1?(o="opacity-path",n||(n=He(t))):(o="path",t.save()),i.__clip(n||t,e)):(o="grayscale"===r?"grayscale":"alpha",s||(s=He(t)),n||(n=He(t)),i.__render(s,e)),"clipping"!==r&&"clipping-path"!==r||Xe(i,e)||i.__render(t,e);continue}const d=1===a&&i.__.__blendMode;d&&je(this,o,t,n,s,a,void 0,!1),Xe(i,e)||i.__render(n||t,e),d&&je(this,o,t,n,s,a,d,!1)}je(this,o,t,n,s,a,void 0,!0)};const Ze=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",$e=Ze+"_#~&*+\\=|≮≯≈≠=…",Je=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 Ke(t){const e={};return t.split("").forEach(t=>e[t]=!0),e}const ti=Ke("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ei=Ke("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ii=Ke(Ze),si=Ke($e),ni=Ke("- —/~|┆·");var ai;!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"}(ai||(ai={}));const{Letter:oi,Single:ri,Before:li,After:hi,Symbol:di,Break:ci}=ai;function ui(t){return ti[t]?oi:ni[t]?ci:ei[t]?li:ii[t]?hi:si[t]?di:Je.test(t)?ri:oi}const fi={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let a=n-1;a>-1&&(i=e[a].data[0]," "===i.char);a--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function pi(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:gi}=fi,{Letter:_i,Single:wi,Before:mi,After:yi,Symbol:vi,Break:xi}=ai;let bi,Si,ki,Bi,Ri,Ei,Li,Ai,Ci,Oi,Ti,Wi,Mi,Di,Pi,Ii,zi,Fi=[];function Ui(t,e){Ci&&!Ai&&(Ai=Ci),bi.data.push({char:t,width:e}),ki+=e}function Vi(){Bi+=ki,bi.width=ki,Si.words.push(bi),bi={data:[]},ki=0}function Yi(){Di&&(Pi.paraNumber++,Si.paraStart=!0,Di=!1),Ci&&(Si.startCharSize=Ai,Si.endCharSize=Ci,Ai=0),Si.width=Bi,Ii.width?gi(Si):zi&&Gi(),Fi.push(Si),Si={words:[]},Bi=0}function Gi(){Bi>(Pi.maxWidth||0)&&(Pi.maxWidth=Bi)}const{top:Ni,right:Xi,bottom:qi,left:ji}=I;function Hi(t,e,i){const{bounds:s,rows:n}=t;s[e]+=i;for(let t=0;t<n.length;t++)n[t][e]+=i}const Qi={getDrawData:function(t,e){s(t)||(t=String(t));let n=0,a=0,o=e.__getInput("width")||0,r=e.__getInput("height")||0;const{textDecoration:l,__font:h,__padding:d}=e;d&&(o?(n=d[ji],o-=d[Xi]+d[ji]):e.autoSizeAlign||(n=d[ji]),r?(a=d[Ni],r-=d[Ni]+d[qi]):e.autoSizeAlign||(a=d[Ni]));const c={bounds:{x:n,y:a,width:o,height:r},rows:[],paraNumber:0,font:i.canvas.font=h};return function(t,e,s){Pi=t,Fi=t.rows,Ii=t.bounds,zi=!Ii.width&&!s.autoSizeAlign;const{__letterSpacing:n,paraIndent:a,textCase:o}=s,{canvas:r}=i,{width:l,height:h}=Ii;if(l||h||n||"none"!==o){const t="none"!==s.textWrap,i="break"===s.textWrap;Di=!0,Ti=null,Ai=Li=Ci=ki=Bi=0,bi={data:[]},Si={words:[]},n&&(e=[...e]);for(let s=0,h=e.length;s<h;s++)Ei=e[s],"\n"===Ei?(ki&&Vi(),Si.paraEnd=!0,Yi(),Di=!0):(Oi=ui(Ei),Oi===_i&&"none"!==o&&(Ei=pi(Ei,o,!ki)),Li=r.measureText(Ei).width,n&&(n<0&&(Ci=Li),Li+=n),Wi=Oi===wi&&(Ti===wi||Ti===_i)||Ti===wi&&Oi!==yi,Mi=!(Oi!==mi&&Oi!==wi||Ti!==vi&&Ti!==yi),Ri=Di&&a?l-a:l,t&&l&&Bi+ki+Li>Ri&&(i?(ki&&Vi(),Bi&&Yi()):(Mi||(Mi=Oi===_i&&Ti==yi),Wi||Mi||Oi===xi||Oi===mi||Oi===wi||ki+Li>Ri?(ki&&Vi(),Bi&&Yi()):Bi&&Yi()))," "===Ei&&!0!==Di&&Bi+ki===0||(Oi===xi?(" "===Ei&&ki&&Vi(),Ui(Ei,Li),Vi()):Wi||Mi?(ki&&Vi(),Ui(Ei,Li)):Ui(Ei,Li)),Ti=Oi);ki&&Vi(),Bi&&Yi(),Fi.length>0&&(Fi[Fi.length-1].paraEnd=!0)}else e.split("\n").forEach(t=>{Pi.paraNumber++,Bi=r.measureText(t).width,Fi.push({x:a||0,text:t,width:Bi,paraStart:!0}),zi&&Gi()})}(c,t,e),d&&function(t,e,i,s,n){if(!s&&i.autoSizeAlign)switch(i.textAlign){case"left":Hi(e,"x",t[ji]);break;case"right":Hi(e,"x",-t[Xi])}if(!n&&i.autoSizeAlign)switch(i.verticalAlign){case"top":Hi(e,"y",t[Ni]);break;case"bottom":Hi(e,"y",-t[qi])}}(d,c,e,o,r),function(t,e){const{rows:i,bounds:s}=t,n=i.length,{__lineHeight:a,__baseLine:o,__letterSpacing:r,__clipText:l,textAlign:h,verticalAlign:d,paraSpacing:c,autoSizeAlign:u}=e;let{x:f,y:p,width:g,height:_}=s,w=a*n+(c?c*(t.paraNumber-1):0),m=o;if(l&&w>_)w=Math.max(_,a),n>1&&(t.overflow=n);else if(_||u)switch(d){case"middle":p+=(_-w)/2;break;case"bottom":p+=_-w}m+=p;let y,v,x,b=g||u?g:t.maxWidth;for(let o=0,d=n;o<d;o++){if(y=i[o],y.x=f,y.width<g||y.width>g&&!l)switch(h){case"center":y.x+=(b-y.width)/2;break;case"right":y.x+=b-y.width}y.paraStart&&c&&o>0&&(m+=c),y.y=m,m+=a,t.overflow>o&&m>w&&(y.isOverflow=!0,t.overflow=o+1),v=y.x,x=y.width,r<0&&(y.width<0?(x=-y.width+e.fontSize+r,v-=x,x+=e.fontSize):x-=r),v<s.x&&(s.x=v),x>s.width&&(s.width=x),l&&g&&g<x&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=w}(c,e),function(t,e,i){const{rows:s}=t,{textAlign:n,paraIndent:a,letterSpacing:o}=e;let r,l,h,d,c,u;s.forEach(t=>{t.words&&(h=a&&t.paraStart?a:0,u=t.words.length,l=i&&("justify"===n||"both"===n)&&u>1?(i-t.width-h)/(u-1):0,d=o||t.isOverflow?0:l>.01?1:2,t.isOverflow&&!o&&(t.textMode=!0),2===d?(t.x+=h,function(t){t.text="",t.words.forEach(e=>{e.data.forEach(e=>{t.text+=e.char})})}(t)):(t.x+=h,r=t.x,t.data=[],t.words.forEach((e,i)=>{1===d?(c={char:"",x:r},r=function(t,e,i){return t.forEach(t=>{i.char+=t.char,e+=t.width}),e}(e.data,r,c),(t.isOverflow||" "!==c.char)&&t.data.push(c)):r=function(t,e,i,s){return t.forEach(t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width}),e}(e.data,r,t.data,t.isOverflow),!l||t.paraEnd&&"both"!==n||i===u-1||(r+=l,t.width+=l)})),t.words=null)})}(c,e,o),c.overflow&&function(t,e,s,n){if(!n)return;const{rows:a,overflow:o}=t;let{textOverflow:r}=e;if(a.splice(o),r&&"show"!==r){let t,l;"hide"===r?r="":"ellipsis"===r&&(r="...");const h=r?i.canvas.measureText(r).width:0,d=s+n-h;("none"===e.textWrap?a:[a[o-1]]).forEach(e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],l=t.x+t.width,!(s===i&&l<d));s--){if(l<d&&" "!==t.char||!s){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=h,e.data.push({char:r,x:l}),e.textMode&&function(t){t.text="",t.data.forEach(e=>{t.text+=e.char}),t.data=null}(e)}})}}(c,e,n,o),"none"!==l&&function(t,e){let i,s=0;const{fontSize:n,textDecoration:a}=e;switch(t.decorationHeight=n/11,E(a)?(i=a.type,a.color&&(t.decorationColor=V.string(a.color)),a.offset&&(s=Math.min(.3*n,Math.max(a.offset,.15*-n)))):i=a,i){case"under":t.decorationY=[.15*n+s];break;case"delete":t.decorationY=[.35*-n];break;case"under-delete":t.decorationY=[.15*n+s,.35*-n]}}(c,e),c}};const Zi={string:function(t,e){const i=z(e)&&e<1;if(s(t)){if(!i||!V.object)return t;t=V.object(t)}let a=n(t.a)?1:t.a;i&&(a*=e);const o=t.r+","+t.g+","+t.b;return 1===a?"rgb("+o+")":"rgba("+o+","+a+")"}};Object.assign(q,Qi),Object.assign(V,Zi),Object.assign(U,Ct),Object.assign(F,we),Object.assign(Y,Pe),Object.assign(N,Ne),$();export{dt as Layouter,H as LeaferCanvas,ut as Renderer,K as Watcher,$ as useCanvas};
|
|
2
2
|
//# sourceMappingURL=web.esm.min.js.map
|