@leafer-draw/worker 1.0.0-rc.20 → 1.0.0-rc.22
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/worker.esm.js +64 -47
- package/dist/worker.esm.min.js +1 -1
- package/dist/worker.js +122 -75
- package/dist/worker.min.js +1 -1
- package/dist/worker.module.js +122 -75
- package/dist/worker.module.min.js +1 -1
- package/package.json +6 -6
package/dist/worker.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LeaferCanvasBase, Platform, canvasPatch, Creator, LeaferImage, FileHelper, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, ResizeEvent, BoundsHelper, MatrixHelper, ImageEvent, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
|
|
1
|
+
import { LeaferCanvasBase, Platform, canvasPatch, Creator, LeaferImage, FileHelper, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, ResizeEvent, BoundsHelper, MatrixHelper, AroundHelper, ImageEvent, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
|
|
2
2
|
export * from '@leafer/core';
|
|
3
3
|
export { LeaferImage } from '@leafer/core';
|
|
4
4
|
import { PaintImage, ColorConvert, PaintGradient, Export, Group, TextConvert, Paint, Effect } from '@leafer-ui/draw';
|
|
@@ -972,79 +972,75 @@ const PaintModule = {
|
|
|
972
972
|
|
|
973
973
|
let origin = {};
|
|
974
974
|
const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
|
|
975
|
-
function fillOrFitMode(data,
|
|
975
|
+
function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
976
976
|
const transform = get$4();
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
const sh = box.height / (swap ? width : height);
|
|
980
|
-
const scale = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
|
|
981
|
-
const x = box.x + (box.width - width * scale) / 2;
|
|
982
|
-
const y = box.y + (box.height - height * scale) / 2;
|
|
983
|
-
translate$1(transform, x, y);
|
|
984
|
-
scaleHelper(transform, scale);
|
|
977
|
+
translate$1(transform, box.x + x, box.y + y);
|
|
978
|
+
scaleHelper(transform, scaleX, scaleY);
|
|
985
979
|
if (rotation)
|
|
986
980
|
rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
|
|
987
|
-
data.scaleX = data.scaleY = scale;
|
|
988
981
|
data.transform = transform;
|
|
989
982
|
}
|
|
990
983
|
function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
991
984
|
const transform = get$4();
|
|
992
|
-
translate$1(transform, box.x, box.y);
|
|
993
|
-
if (
|
|
994
|
-
translate$1(transform, x, y);
|
|
995
|
-
if (scaleX) {
|
|
985
|
+
translate$1(transform, box.x + x, box.y + y);
|
|
986
|
+
if (scaleX)
|
|
996
987
|
scaleHelper(transform, scaleX, scaleY);
|
|
997
|
-
data.scaleX = transform.a;
|
|
998
|
-
data.scaleY = transform.d;
|
|
999
|
-
}
|
|
1000
988
|
if (rotation)
|
|
1001
989
|
rotate(transform, rotation);
|
|
1002
990
|
data.transform = transform;
|
|
1003
991
|
}
|
|
1004
|
-
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation) {
|
|
992
|
+
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around) {
|
|
1005
993
|
const transform = get$4();
|
|
1006
994
|
if (rotation) {
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
995
|
+
if (around === 'center') {
|
|
996
|
+
rotateOfOuter$2(transform, { x: width / 2, y: height / 2 }, rotation);
|
|
997
|
+
}
|
|
998
|
+
else {
|
|
999
|
+
rotate(transform, rotation);
|
|
1000
|
+
switch (rotation) {
|
|
1001
|
+
case 90:
|
|
1002
|
+
translate$1(transform, height, 0);
|
|
1003
|
+
break;
|
|
1004
|
+
case 180:
|
|
1005
|
+
translate$1(transform, width, height);
|
|
1006
|
+
break;
|
|
1007
|
+
case 270:
|
|
1008
|
+
translate$1(transform, 0, width);
|
|
1009
|
+
break;
|
|
1010
|
+
}
|
|
1018
1011
|
}
|
|
1019
1012
|
}
|
|
1020
|
-
origin.x = box.x;
|
|
1021
|
-
origin.y = box.y;
|
|
1022
|
-
if (x || y)
|
|
1023
|
-
origin.x += x, origin.y += y;
|
|
1013
|
+
origin.x = box.x + x;
|
|
1014
|
+
origin.y = box.y + y;
|
|
1024
1015
|
translate$1(transform, origin.x, origin.y);
|
|
1025
|
-
if (scaleX)
|
|
1016
|
+
if (scaleX)
|
|
1026
1017
|
scaleOfOuter$2(transform, origin, scaleX, scaleY);
|
|
1027
|
-
data.scaleX = scaleX;
|
|
1028
|
-
data.scaleY = scaleY;
|
|
1029
|
-
}
|
|
1030
1018
|
data.transform = transform;
|
|
1031
1019
|
}
|
|
1032
1020
|
|
|
1033
1021
|
const { get: get$3, translate } = MatrixHelper;
|
|
1034
1022
|
const tempBox = new Bounds();
|
|
1023
|
+
const tempPoint = {};
|
|
1035
1024
|
function createData(leafPaint, image, paint, box) {
|
|
1036
1025
|
let { width, height } = image;
|
|
1037
1026
|
if (paint.padding)
|
|
1038
1027
|
box = tempBox.set(box).shrink(paint.padding);
|
|
1039
|
-
const { opacity, mode, offset, scale, size, rotation, blendMode, repeat } = paint;
|
|
1028
|
+
const { opacity, mode, around, offset, scale, size, rotation, blendMode, repeat } = paint;
|
|
1040
1029
|
const sameBox = box.width === width && box.height === height;
|
|
1041
1030
|
if (blendMode)
|
|
1042
1031
|
leafPaint.blendMode = blendMode;
|
|
1043
1032
|
const data = leafPaint.data = { mode };
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
if (
|
|
1033
|
+
const swapSize = around !== 'center' && (rotation || 0) % 180 === 90;
|
|
1034
|
+
const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height;
|
|
1035
|
+
let x = 0, y = 0, scaleX, scaleY;
|
|
1036
|
+
if (!mode || mode === 'cover' || mode === 'fit') {
|
|
1037
|
+
if (!sameBox || rotation) {
|
|
1038
|
+
const sw = box.width / swapWidth, sh = box.height / swapHeight;
|
|
1039
|
+
scaleX = scaleY = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
|
|
1040
|
+
x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
else if (size) {
|
|
1048
1044
|
scaleX = (typeof size === 'number' ? size : size.width) / width;
|
|
1049
1045
|
scaleY = (typeof size === 'number' ? size : size.height) / height;
|
|
1050
1046
|
}
|
|
@@ -1052,26 +1048,36 @@ function createData(leafPaint, image, paint, box) {
|
|
|
1052
1048
|
scaleX = typeof scale === 'number' ? scale : scale.x;
|
|
1053
1049
|
scaleY = typeof scale === 'number' ? scale : scale.y;
|
|
1054
1050
|
}
|
|
1051
|
+
if (around) {
|
|
1052
|
+
const imageBounds = { x, y, width: swapWidth, height: swapHeight };
|
|
1053
|
+
if (scaleX)
|
|
1054
|
+
imageBounds.width *= scaleX, imageBounds.height *= scaleY;
|
|
1055
|
+
AroundHelper.toPoint(around, box, tempPoint, true, imageBounds);
|
|
1056
|
+
x += tempPoint.x, y += tempPoint.y;
|
|
1057
|
+
}
|
|
1058
|
+
if (offset)
|
|
1059
|
+
x += offset.x, y += offset.y;
|
|
1055
1060
|
switch (mode) {
|
|
1056
1061
|
case 'strench':
|
|
1057
1062
|
if (!sameBox)
|
|
1058
1063
|
width = box.width, height = box.height;
|
|
1059
1064
|
break;
|
|
1065
|
+
case 'normal':
|
|
1060
1066
|
case 'clip':
|
|
1061
|
-
if (
|
|
1067
|
+
if (x || y || scaleX || rotation)
|
|
1062
1068
|
clipMode(data, box, x, y, scaleX, scaleY, rotation);
|
|
1063
1069
|
break;
|
|
1064
1070
|
case 'repeat':
|
|
1065
1071
|
if (!sameBox || scaleX || rotation)
|
|
1066
|
-
repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation);
|
|
1072
|
+
repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around);
|
|
1067
1073
|
if (!repeat)
|
|
1068
1074
|
data.repeat = 'repeat';
|
|
1069
1075
|
break;
|
|
1070
1076
|
case 'fit':
|
|
1071
1077
|
case 'cover':
|
|
1072
1078
|
default:
|
|
1073
|
-
if (
|
|
1074
|
-
fillOrFitMode(data,
|
|
1079
|
+
if (scaleX)
|
|
1080
|
+
fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation);
|
|
1075
1081
|
}
|
|
1076
1082
|
if (!data.transform) {
|
|
1077
1083
|
if (box.x || box.y) {
|
|
@@ -1079,6 +1085,10 @@ function createData(leafPaint, image, paint, box) {
|
|
|
1079
1085
|
translate(data.transform, box.x, box.y);
|
|
1080
1086
|
}
|
|
1081
1087
|
}
|
|
1088
|
+
if (scaleX && mode !== 'strench') {
|
|
1089
|
+
data.scaleX = scaleX;
|
|
1090
|
+
data.scaleY = scaleY;
|
|
1091
|
+
}
|
|
1082
1092
|
data.width = width;
|
|
1083
1093
|
data.height = height;
|
|
1084
1094
|
if (opacity)
|
|
@@ -2166,6 +2176,13 @@ const ExportModule = {
|
|
|
2166
2176
|
resolve();
|
|
2167
2177
|
this.running = false;
|
|
2168
2178
|
};
|
|
2179
|
+
if (filename === 'json') {
|
|
2180
|
+
return over({ data: leaf.toJSON() });
|
|
2181
|
+
}
|
|
2182
|
+
else if (FileHelper.fileType(filename) === 'json') {
|
|
2183
|
+
Platform.origin.download('data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(leaf.toJSON())), filename);
|
|
2184
|
+
return over({ data: true });
|
|
2185
|
+
}
|
|
2169
2186
|
const { leafer } = leaf;
|
|
2170
2187
|
if (leafer) {
|
|
2171
2188
|
leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
|
package/dist/worker.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LeaferCanvasBase as t,Platform as e,canvasPatch as n,Creator as i,LeaferImage as s,FileHelper as o,LeafList as a,DataHelper as r,RenderEvent as d,ChildEvent as l,WatchEvent as c,PropertyEvent as h,LeafHelper as u,BranchHelper as f,Bounds as p,LeafBoundsHelper as _,Debug as g,LeafLevelList as w,LayoutEvent as y,Run as m,ImageManager as v,AnimateEvent as x,ResizeEvent as b,BoundsHelper as B,MatrixHelper as R,ImageEvent as k,PointHelper as E,Direction4 as S,TwoPointBoundsHelper as L,TaskProcessor as W,Matrix as A}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as O,ColorConvert as T,PaintGradient as M,Export as C,Group as D,TextConvert as I,Paint as F,Effect as P}from"@leafer-ui/draw";export*from"@leafer-ui/draw";class Y extends t{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:n}=this;this.view.width=Math.ceil(t*n),this.view.height=Math.ceil(e*n),this.clientBounds=this.bounds}}n(OffscreenCanvasRenderingContext2D.prototype),n(Path2D.prototype);const{mineType:G}=o;function U(t,n){e.origin={createCanvas:(t,e)=>new OffscreenCanvas(t,e),canvasToDataURL:(t,e,n)=>new Promise(((i,s)=>{t.convertToBlob({type:G(e),quality:n}).then((t=>{var e=new FileReader;e.onload=t=>i(t.target.result),e.onerror=t=>s(t),e.readAsDataURL(t)})).catch((t=>{s(t)}))})),canvasToBolb:(t,e,n)=>t.convertToBlob({type:G(e),quality:n}),canvasSaveAs:(t,e,n)=>new Promise((t=>t())),download(t,e){},loadImage:t=>new Promise(((n,i)=>{!t.startsWith("data:")&&e.image.suffix&&(t+=(t.includes("?")?"&":"?")+e.image.suffix);let s=new XMLHttpRequest;s.open("GET",t,!0),s.responseType="blob",s.onload=()=>{createImageBitmap(s.response).then((t=>{n(t)})).catch((t=>{i(t)}))},s.onerror=t=>i(t),s.send()}))},e.canvas=i.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient}Object.assign(i,{canvas:(t,e)=>new Y(t,e),image:t=>new s(t)}),e.name="web",e.isWorker=!0,e.requestRender=function(t){requestAnimationFrame(t)},e.devicePixelRatio=1;const{userAgent:X}=navigator;X.indexOf("Firefox")>-1?(e.conicGradientRotate90=!0,e.intWheelDeltaY=!0):X.indexOf("Safari")>-1&&-1===X.indexOf("Chrome")&&(e.fullImageShadow=!0),X.indexOf("Windows")>-1?(e.os="Windows",e.intWheelDeltaY=!0):X.indexOf("Mac")>-1?e.os="Mac":X.indexOf("Linux")>-1&&(e.os="Linux");class N{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new a;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 a,this.target=t,e&&(this.config=r.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(d.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===l.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,n=e.length;t<n;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new c(c.DATA,{updatedList:this.updatedList})),this.__updatedList=new a,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(h.CHANGE,this.__onAttrChange,this),t.on_([l.ADD,l.REMOVE],this.__onChildEvent,this),t.on_(c.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:q,updateBounds:V,updateAllWorldOpacity:j}=u,{pushAllChildBranch:z,pushAllParent:H}=f;const{worldBounds:Q}=_,Z={x:0,y:0,width:1e5,height:1e5};class ${constructor(t){this.updatedBounds=new p,this.beforeBounds=new p,this.afterBounds=new p,t instanceof Array&&(t=new a(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,Q)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(Z):this.afterBounds.setListWithFn(t,Q),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:J,updateAllChange:K}=u,tt=g.get("Layouter");class et{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new w,this.target=t,e&&(this.config=r.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(y.START),this.layoutOnce(),t.emitEvent(new y(y.END,this.layoutedBlocks,this.times))}catch(t){tt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?tt.warn("layouting"):this.times>3?tt.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(c.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=m.start("PartLayout"),{target:n,__updatedList:i}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=y,r=this.getBlocks(i);r.forEach((t=>t.setBefore())),n.emitEvent(new y(s,r,this.times)),this.extraBlock=null,i.sort(),function(t,e){let n;t.list.forEach((t=>{n=t.__layout,e.without(t)&&!n.proxyZoom&&(n.matrixChanged?(q(t,!0),e.add(t),t.isBranch&&z(t,e),H(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),H(t,e)))}))}(i,this.__levelList),function(t){let e,n,i;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(n=e[t],n.isBranch&&n.__tempNumber){i=n.children;for(let t=0,e=i.length;t<e;t++)i[t].isBranch||V(i[t])}V(n)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&j(t),t.__updateChange()}))}(i),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),n.emitEvent(new y(o,r,this.times)),n.emitEvent(new y(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,m.end(e)}fullLayout(){const t=m.start("FullLayout"),{target:e}=this,{BEFORE:n,LAYOUT:i,AFTER:s}=y,o=this.getBlocks(new a(e));e.emitEvent(new y(n,o,this.times)),et.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new y(i,o,this.times)),e.emitEvent(new y(s,o,this.times)),this.addBlocks(o),m.end(t)}static fullLayout(t){J(t,!0),t.isBranch?f.updateBounds(t):u.updateBounds(t),K(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new $([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new $(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_(y.REQUEST,this.layout,this),t.on_(y.AGAIN,this.layoutAgain,this),t.on_(c.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const nt=g.get("Renderer");class it{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,n){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,n&&(this.config=r.default(n,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(y.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new p,nt.log(e.innerName,"---\x3e");try{this.emitRender(d.START),this.renderOnce(t),this.emitRender(d.END,this.totalBounds),v.clearRecycled()}catch(t){this.rendering=!1,nt.error(t)}nt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return nt.warn("rendering");if(this.times>3)return nt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new p,this.renderOptions={},t)this.emitRender(d.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(d.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(d.RENDER,this.renderBounds,this.renderOptions),this.emitRender(d.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 nt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=m.start("PartRender"),{canvas:n}=this,i=t.getIntersect(n.bounds),s=t.includes(this.target.__world),o=new p(i);n.save(),s&&!g.showRepaint?n.clear():(i.spread(1+1/this.canvas.pixelRatio).ceil(),n.clearWorld(i,!0),n.clipWorld(i,!0)),this.__render(i,s,o),n.restore(),m.end(e)}fullRender(){const t=m.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),m.end(t)}__render(t,e,n){const i=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),g.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,i),this.renderBounds=n||t,this.renderOptions=i,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),g.showHitView&&this.renderHitView(i),g.showBoundsView&&this.renderBoundsView(i),this.canvas.updateRender()}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new p;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(x.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(d.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:n}=t.old;new p(0,0,e,n).includes(this.target.__world)&&!this.needFill&&t.samePixelRatio||(this.addBlock(this.canvas.bounds),this.target.forceUpdate("surface"))}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||nt.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,n){this.target.emitEvent(new d(t,this.times,e,n))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(d.REQUEST,this.update,this),t.on_(y.END,this.__onLayoutEnd,this),t.on_(d.AGAIN,this.renderAgain,this),t.on_(b.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 st(t,e){let n;const{rows:i,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=i.length;t<a;t++)n=i[t],n.text?e.fillText(n.text,n.x,n.y):n.data&&n.data.forEach((t=>{e.fillText(t.char,t.x,n.y)})),s&&e.fillRect(n.x,n.y+s,n.width,o)}function ot(t,e,n){const{strokeAlign:i}=e.__,s="string"!=typeof t;switch(i){case"center":n.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?dt(t,!0,e,n):rt(e,n);break;case"inside":at("inside",t,s,e,n);break;case"outside":at("outside",t,s,e,n)}}function at(t,e,n,i,s){const{__strokeWidth:o,__font:a}=i.__,r=s.getSameCanvas(!0,!0);r.setStroke(n?void 0:e,2*o,i.__),r.font=a,n?dt(e,!0,i,r):rt(i,r),r.blendMode="outside"===t?"destination-out":"destination-in",st(i,r),r.blendMode="normal",i.__worldFlipped?s.copyWorldByReset(r,i.__nowWorld):s.copyWorldToInner(r,i.__nowWorld,i.__layout.renderBounds),r.recycle(i.__nowWorld)}function rt(t,e){let n;const{rows:i,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=i.length;t<a;t++)n=i[t],n.text?e.strokeText(n.text,n.x,n.y):n.data&&n.data.forEach((t=>{e.strokeText(t.char,t.x,n.y)})),s&&e.strokeRect(n.x,n.y+s,n.width,o)}function dt(t,e,n,i){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&O.checkImage(n,i,s,!1)||s.style&&(i.strokeStyle=s.style,s.blendMode?(i.saveBlendMode(s.blendMode),e?rt(n,i):i.stroke(),i.restoreBlendMode()):e?rt(n,i):i.stroke())}Object.assign(i,{watcher:(t,e)=>new N(t,e),layouter:(t,e)=>new et(t,e),renderer:(t,e,n)=>new it(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,i)=>{}}),e.layout=et.fullLayout;const{getSpread:lt,getOuterOf:ct,getByMove:ht,getIntersectData:ut}=B;let ft;function pt(t,e,n){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:i}=n.__layout;switch(e.type){case"solid":let{type:s,blendMode:o,color:a,opacity:r}=e;return{type:s,blendMode:o,style:T.string(a,r)};case"image":return O.image(n,t,e,i,!ft||!ft[e.url]);case"linear":return M.linearGradient(e,i);case"radial":return M.radialGradient(e,i);case"angular":return M.conicGradient(e,i);default:return e.r?{type:"solid",style:T.string(e)}:void 0}}const _t={compute:function(t,e){const n=e.__,i=[];let s,o=n.__input[t];o instanceof Array||(o=[o]),ft=O.recycleImage(t,n);for(let n,s=0,a=o.length;s<a;s++)n=pt(t,o[s],e),n&&i.push(n);n["_"+t]=i.length?i:void 0,i.length&&i[0].image&&(s=i[0].image.hasOpacityPixel),"fill"===t?n.__pixelFill=s:n.__pixelStroke=s},fill:function(t,e,n){n.fillStyle=t,e.__.__font?st(e,n):e.__.windingRule?n.fill(e.__.windingRule):n.fill()},fills:function(t,e,n){let i;const{windingRule:s,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)i=t[a],i.image&&O.checkImage(e,n,i,!o)||i.style&&(n.fillStyle=i.style,i.transform?(n.save(),n.transform(i.transform),i.blendMode&&(n.blendMode=i.blendMode),o?st(e,n):s?n.fill(s):n.fill(),n.restore()):i.blendMode?(n.saveBlendMode(i.blendMode),o?st(e,n):s?n.fill(s):n.fill(),n.restoreBlendMode()):o?st(e,n):s?n.fill(s):n.fill())},fillText:st,stroke:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)ot(t,e,n);else switch(o){case"center":n.setStroke(t,s,i),n.stroke();break;case"inside":n.save(),n.setStroke(t,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),n.stroke(),n.restore();break;case"outside":const o=n.getSameCanvas(!0,!0);o.setStroke(t,2*s,i),e.__drawRenderPath(o),o.stroke(),i.windingRule?o.clip(i.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?n.copyWorldByReset(o,e.__nowWorld):n.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)ot(t,e,n);else switch(o){case"center":n.setStroke(void 0,s,i),dt(t,!1,e,n);break;case"inside":n.save(),n.setStroke(void 0,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),dt(t,!1,e,n),n.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=n.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*s,i),dt(t,!1,e,a),i.windingRule?a.clip(i.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?n.copyWorldByReset(a,e.__nowWorld):n.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:ot,drawTextStroke:rt,shape:function(t,e,n){const i=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=i,o=r=s;else{const{renderShapeSpread:i}=t.__layout,h=ut(i?lt(e.bounds,i*l,i*c):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,n),l*=u,c*=f),r=ct(s,a),o=ht(r,-a.e,-a.f),n.matrix){const{matrix:t}=n;a.multiply(t),u*=t.scaleX,f*=t.scaleY}n=Object.assign(Object.assign({},n),{matrix:a.withScale(u,f)})}return t.__renderShape(i,n),{canvas:i,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:c}}};let gt={};const{get:wt,rotateOfOuter:yt,translate:mt,scaleOfOuter:vt,scale:xt,rotate:bt}=R;function Bt(t,e,n,i,s,o){const a=wt(),r=o&&180!==o,d=n.width/(r?s:i),l=n.height/(r?i:s),c="fit"===e?Math.min(d,l):Math.max(d,l),h=n.x+(n.width-i*c)/2,u=n.y+(n.height-s*c)/2;mt(a,h,u),xt(a,c),o&&yt(a,{x:n.x+n.width/2,y:n.y+n.height/2},o),t.scaleX=t.scaleY=c,t.transform=a}function Rt(t,e,n,i,s,o,a){const r=wt();mt(r,e.x,e.y),(n||i)&&mt(r,n,i),s&&(xt(r,s,o),t.scaleX=r.a,t.scaleY=r.d),a&&bt(r,a),t.transform=r}function kt(t,e,n,i,s,o,a,r,d){const l=wt();if(d)switch(bt(l,d),d){case 90:mt(l,i,0);break;case 180:mt(l,n,i);break;case 270:mt(l,0,n)}gt.x=e.x,gt.y=e.y,(s||o)&&(gt.x+=s,gt.y+=o),mt(l,gt.x,gt.y),a&&(vt(l,gt,a,r),t.scaleX=a,t.scaleY=r),t.transform=l}const{get:Et,translate:St}=R,Lt=new p;function Wt(t,e,n,i){let{width:s,height:o}=e;n.padding&&(i=Lt.set(i).shrink(n.padding));const{opacity:a,mode:r,offset:d,scale:l,size:c,rotation:h,blendMode:u,repeat:f}=n,p=i.width===s&&i.height===o;u&&(t.blendMode=u);const _=t.data={mode:r};let g,w,y,m;switch(d&&(g=d.x,w=d.y),c?(y=("number"==typeof c?c:c.width)/s,m=("number"==typeof c?c:c.height)/o):l&&(y="number"==typeof l?l:l.x,m="number"==typeof l?l:l.y),r){case"strench":p||(s=i.width,o=i.height);break;case"clip":(d||y||h)&&Rt(_,i,g,w,y,m,h);break;case"repeat":(!p||y||h)&&kt(_,i,s,o,g,w,y,m,h),f||(_.repeat="repeat");break;default:p&&!h||Bt(_,r,i,s,o,h)}_.transform||(i.x||i.y)&&(_.transform=Et(),St(_.transform,i.x,i.y)),_.width=s,_.height=o,a&&(_.opacity=a),f&&(_.repeat="string"==typeof f?"x"===f?"repeat-x":"repeat-y":"repeat")}let At,Ot=new p;const{isSame:Tt}=B;function Mt(t,e,n,i,s,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=i.width/e.pixelRatio,e.__naturalHeight=i.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||Wt(s,i,n,o),!0}function Ct(t,e){Ft(t,k.LOAD,e)}function Dt(t,e){Ft(t,k.LOADED,e)}function It(t,e,n){e.error=n,t.forceUpdate("surface"),Ft(t,k.ERROR,e)}function Ft(t,e,n){t.hasEvent(e)&&t.emitEvent(new k(e,n))}function Pt(t,e){const{leafer:n}=t;n&&n.viewReady&&(n.renderer.ignore=e)}const{get:Yt,scale:Gt,copy:Ut}=R,{ceil:Xt,abs:Nt}=Math;function qt(t,n,i){let{scaleX:s,scaleY:o}=v.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o;if(n.patternId===a||t.destroyed)return!1;{s=Nt(s),o=Nt(o);const{image:t,data:r}=n;let d,l,{width:c,height:h,scaleX:u,scaleY:f,opacity:p,transform:_,repeat:g}=r;u&&(l=Yt(),Ut(l,_),Gt(l,1/u,1/f),s*=u,o*=f),s*=i,o*=i,c*=s,h*=o;const w=c*h;if(!g&&w>e.image.maxCacheSize)return!1;let y=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(s/=d,o/=d,c/=d,h/=d),u&&(s/=u,o/=f),(_||1!==s||1!==o)&&(l||(l=Yt(),_&&Ut(l,_)),Gt(l,1/s,1/o));const m=t.getCanvas(Xt(c)||1,Xt(h)||1,p),v=t.getPattern(m,g||e.origin.noRepeat||"no-repeat",l,n);return n.style=v,n.patternId=a,!0}}function Vt(t,e,n,i){return new(n||(n=Promise))((function(s,o){function a(t){try{d(i.next(t))}catch(t){o(t)}}function r(t){try{d(i.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,r)}d((i=i.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:jt}=Math;const zt={image:function(t,e,n,i,s){let o,a;const r=v.get(n);return At&&n===At.paint&&Tt(i,At.boxBounds)?o=At.leafPaint:(o={type:n.type,image:r},At=r.use>1?{leafPaint:o,paint:n,boxBounds:Ot.set(i)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:n}),r.ready?(Mt(t,e,n,r,o,i),s&&(Ct(t,a),Dt(t,a))):r.error?s&&It(t,a,r.error):(Pt(t,!0),s&&Ct(t,a),o.loadId=r.load((()=>{Pt(t,!1),t.destroyed||(Mt(t,e,n,r,o,i)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Dt(t,a)),o.loadId=null}),(e=>{Pt(t,!1),It(t,a,e),o.loadId=null}))),o},createData:Wt,fillOrFitMode:Bt,clipMode:Rt,repeatMode:kt,createPattern:qt,checkImage:function(t,n,i,s){const{scaleX:o,scaleY:a}=v.patternLocked?t.__world:t.__nowWorld;if(i.data&&i.patternId!==o+"-"+a){const{data:r}=i;if(s)if(r.repeat)s=!1;else{let{width:t,height:i}=r;t*=jt(o)*n.pixelRatio,i*=jt(a)*n.pixelRatio,r.scaleX&&(t*=r.scaleX,i*=r.scaleY),s=t*i>e.image.maxCacheSize}return s?(n.save(),n.clip(),i.blendMode&&(n.blendMode=i.blendMode),r.opacity&&(n.opacity*=r.opacity),r.transform&&n.transform(r.transform),n.drawImage(i.image.view,0,0,r.width,r.height),n.restore(),!0):(!i.style||C.running?qt(t,i,n.pixelRatio):i.patternTask||(i.patternTask=v.patternTasker.add((()=>Vt(this,void 0,void 0,(function*(){i.patternTask=null,n.bounds.hit(t.__nowWorld)&&qt(t,i,n.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},recycleImage:function(t,e){const n=e["_"+t];if(n instanceof Array){let i,s,o,a;for(let r=0,d=n.length;r<d;r++)i=n[r].image,a=i&&i.url,a&&(s||(s={}),s[a]=!0,v.recycle(i),i.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),i.unload(n[r].loadId,!o.some((t=>t.url===a)))));return s}return null}},Ht={x:.5,y:0},Qt={x:.5,y:1};function Zt(t,e,n){let i;for(let s=0,o=e.length;s<o;s++)i=e[s],t.addColorStop(i.offset,T.string(i.color,n))}const{set:$t,getAngle:Jt,getDistance:Kt}=E,{get:te,rotateOfOuter:ee,scaleOfOuter:ne}=R,ie={x:.5,y:.5},se={x:.5,y:1},oe={},ae={};const{set:re,getAngle:de,getDistance:le}=E,{get:ce,rotateOfOuter:he,scaleOfOuter:ue}=R,fe={x:.5,y:.5},pe={x:.5,y:1},_e={},ge={};const we={linearGradient:function(t,n){let{from:i,to:s,type:o,blendMode:a,opacity:r}=t;i||(i=Ht),s||(s=Qt);const d=e.canvas.createLinearGradient(n.x+i.x*n.width,n.y+i.y*n.height,n.x+s.x*n.width,n.y+s.y*n.height);Zt(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,n){let{from:i,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;i||(i=ie),s||(s=se);const{x:l,y:c,width:h,height:u}=n;let f;$t(oe,l+i.x*h,c+i.y*u),$t(ae,l+s.x*h,c+s.y*u),(h!==u||d)&&(f=te(),ne(f,oe,h/u*(d||1),1),ee(f,oe,Jt(oe,ae)+90));const p=e.canvas.createRadialGradient(oe.x,oe.y,0,oe.x,oe.y,Kt(oe,ae));Zt(p,t.stops,a);const _={type:o,style:p,transform:f};return r&&(_.blendMode=r),_},conicGradient:function(t,n){let{from:i,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;i||(i=fe),s||(s=pe);const{x:l,y:c,width:h,height:u}=n;re(_e,l+i.x*h,c+i.y*u),re(ge,l+s.x*h,c+s.y*u);const f=ce(),p=de(_e,ge);e.conicGradientRotate90?(ue(f,_e,h/u*(d||1),1),he(f,_e,p+90)):(ue(f,_e,1,h/u*(d||1)),he(f,_e,p));const _=e.conicGradientSupport?e.canvas.createConicGradient(0,_e.x,_e.y):e.canvas.createRadialGradient(_e.x,_e.y,0,_e.x,_e.y,le(_e,ge));Zt(_,t.stops,a);const g={type:o,style:_,transform:f};return r&&(g.blendMode=r),g}},{copy:ye,toOffsetOutBounds:me}=B,ve={},xe={};function be(t,n,i,s){const{bounds:o,shapeBounds:a}=s;if(e.fullImageShadow){if(ye(ve,t.bounds),ve.x+=n.x-a.x,ve.y+=n.y-a.y,i){const{matrix:t}=s;ve.x-=(o.x+(t?t.e:0)+o.width/2)*(i-1),ve.y-=(o.y+(t?t.f:0)+o.height/2)*(i-1),ve.width*=i,ve.height*=i}t.copyWorld(s.canvas,t.bounds,ve)}else i&&(ye(ve,n),ve.x-=n.width/2*(i-1),ve.y-=n.height/2*(i-1),ve.width*=i,ve.height*=i),t.copyWorld(s.canvas,a,i?ve:n)}const{toOffsetOutBounds:Be}=B,Re={};const ke={shadow:function(t,e,n){let i,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;me(l,xe),r.forEach(((r,_)=>{f.setWorldShadow(xe.offsetX+r.x*h,xe.offsetY+r.y*u,r.blur*h,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,be(f,xe,s,n),i=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),i=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(n.canvas,c,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,i,o,r.blendMode):e.copyWorldToInner(f,i,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(i,!0)})),f.recycle(i)},innerShadow:function(t,e,n){let i,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;Be(l,Re),r.forEach(((r,_)=>{f.save(),f.setWorldShadow(Re.offsetX+r.x*h,Re.offsetY+r.y*u,r.blur*h),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,be(f,Re,s,n),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),i=o):(f.copyWorld(n.canvas,c,l,"source-out"),i=l),f.fillWorld(i,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,i,o,r.blendMode):e.copyWorldToInner(f,i,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(i,!0)})),f.recycle(i)},blur:function(t,e,n){const{blur:i}=t.__;n.setWorldBlur(i*t.__nowWorld.a),n.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),n.filter="none"},backgroundBlur:function(t,e,n){}},{excludeRenderBounds:Ee}=_;function Se(t,e,n,i,s,o){switch(e){case"alpha":!function(t,e,n,i){const s=t.__nowWorld;n.resetTransform(),n.opacity=1,n.useMask(i,s),i.recycle(s),We(t,e,n,1)}(t,n,i,s);break;case"opacity-path":We(t,n,i,o);break;case"path":n.restore()}}function Le(t){return t.getSameCanvas(!1,!0)}function We(t,e,n,i){const s=t.__nowWorld;e.resetTransform(),e.opacity=i,e.copyWorld(n,s),n.recycle(s)}D.prototype.__renderMask=function(t,e){let n,i,s,o,a;const{children:r}=this;for(let d=0,l=r.length;d<l;d++)n=r[d],n.__.mask&&(a&&(Se(this,a,t,s,i,o),i=s=null),"path"===n.__.maskType?(n.opacity<1?(a="opacity-path",o=n.opacity,s||(s=Le(t))):(a="path",t.save()),n.__clip(s||t,e)):(a="alpha",i||(i=Le(t)),s||(s=Le(t)),n.__render(i,e)),"clipping"!==n.__.maskType)||Ee(n,e)||n.__render(s||t,e);Se(this,a,t,s,i,o)};const Ae=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Oe=Ae+"_#~&*+\\=|≮≯≈≠=…",Te=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 Me(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Ce=Me("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),De=Me("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Ie=Me(Ae),Fe=Me(Oe),Pe=Me("- —/~|┆·");var Ye;!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"}(Ye||(Ye={}));const{Letter:Ge,Single:Ue,Before:Xe,After:Ne,Symbol:qe,Break:Ve}=Ye;function je(t){return Ce[t]?Ge:Pe[t]?Ve:De[t]?Xe:Ie[t]?Ne:Fe[t]?qe:Te.test(t)?Ue:Ge}const ze={trimRight(t){const{words:e}=t;let n,i=0,s=e.length;for(let o=s-1;o>-1&&(n=e[o].data[0]," "===n.char);o--)i++,t.width-=n.width;i&&e.splice(s-i,i)}};function He(t,e,n){switch(e){case"title":return n?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:Qe}=ze,{Letter:Ze,Single:$e,Before:Je,After:Ke,Symbol:tn,Break:en}=Ye;let nn,sn,on,an,rn,dn,ln,cn,hn,un,fn,pn,_n,gn,wn,yn,mn=[];function vn(t,e){hn&&!cn&&(cn=hn),nn.data.push({char:t,width:e}),on+=e}function xn(){an+=on,nn.width=on,sn.words.push(nn),nn={data:[]},on=0}function bn(){gn&&(wn.paraNumber++,sn.paraStart=!0,gn=!1),hn&&(sn.startCharSize=cn,sn.endCharSize=hn,cn=0),sn.width=an,yn.width&&Qe(sn),mn.push(sn),sn={words:[]},an=0}const Bn=0,Rn=1,kn=2;const{top:En,right:Sn,bottom:Ln,left:Wn}=S;function An(t,e,n){const{bounds:i,rows:s}=t;i[e]+=n;for(let t=0;t<s.length;t++)s[t][e]+=n}const On={getDrawData:function(t,n){"string"!=typeof t&&(t=String(t));let i=0,s=0,o=n.__getInput("width")||0,a=n.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=n;l&&(o&&(i=l[Wn],o-=l[Sn]+l[Wn]),a&&(s=l[En],a-=l[En]+l[Ln]));const c={bounds:{x:i,y:s,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,n,i){wn=t,mn=t.rows,yn=t.bounds;const{__letterSpacing:s,paraIndent:o,textCase:a}=i,{canvas:r}=e,{width:d,height:l}=yn;if(d||l||s||"none"!==a){const t="none"!==i.textWrap,e="break"===i.textWrap;gn=!0,fn=null,cn=ln=hn=on=an=0,nn={data:[]},sn={words:[]};for(let i=0,l=n.length;i<l;i++)dn=n[i],"\n"===dn?(on&&xn(),sn.paraEnd=!0,bn(),gn=!0):(un=je(dn),un===Ze&&"none"!==a&&(dn=He(dn,a,!on)),ln=r.measureText(dn).width,s&&(s<0&&(hn=ln),ln+=s),pn=un===$e&&(fn===$e||fn===Ze)||fn===$e&&un!==Ke,_n=!(un!==Je&&un!==$e||fn!==tn&&fn!==Ke),rn=gn&&o?d-o:d,t&&d&&an+on+ln>rn&&(e?(on&&xn(),bn()):(_n||(_n=un===Ze&&fn==Ke),pn||_n||un===en||un===Je||un===$e||on+ln>rn?(on&&xn(),bn()):bn()))," "===dn&&!0!==gn&&an+on===0||(un===en?(" "===dn&&on&&xn(),vn(dn,ln),xn()):pn||_n?(on&&xn(),vn(dn,ln)):vn(dn,ln)),fn=un);on&&xn(),an&&bn(),mn.length>0&&(mn[mn.length-1].paraEnd=!0)}else n.split("\n").forEach((t=>{wn.paraNumber++,mn.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(c,t,n),l&&function(t,e,n,i,s){if(!i)switch(n.textAlign){case"left":An(e,"x",t[Wn]);break;case"right":An(e,"x",-t[Sn])}if(!s)switch(n.verticalAlign){case"top":An(e,"y",t[En]);break;case"bottom":An(e,"y",-t[Ln])}}(l,c,n,o,a),function(t,e){const{rows:n,bounds:i}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:c}=e;let h,u,f,{x:p,y:_,width:g,height:w}=i,y=s*n.length+(c?c*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,s),t.overflow=n.length;else switch(l){case"middle":_+=(w-y)/2;break;case"bottom":_+=w-y}m+=_;for(let o=0,l=n.length;o<l;o++){switch(h=n[o],h.x=p,d){case"center":h.x+=(g-h.width)/2;break;case"right":h.x+=g-h.width}h.paraStart&&c&&o>0&&(m+=c),h.y=m,m+=s,t.overflow>o&&m>y&&(h.isOverflow=!0,t.overflow=o+1),u=h.x,f=h.width,a<0&&(h.width<0?(f=-h.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<i.x&&(i.x=u),f>i.width&&(i.width=f),r&&g&&g<f&&(h.isOverflow=!0,t.overflow||(t.overflow=n.length))}i.y=_,i.height=y}(c,n),function(t,e,n,i){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=n&&"justify"===o&&t.words.length>1?(n-t.width-c)/(t.words.length-1):0,h=r||t.isOverflow?Bn:l>.01?Rn:kn,t.isOverflow&&!r&&(t.textMode=!0),h===kn?(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===Rn?(u={char:"",x:d},d=function(t,e,n){return t.forEach((t=>{n.char+=t.char,e+=t.width})),e}(e.data,d,u)," "!==u.char&&t.data.push(u)):d=function(t,e,n){return t.forEach((t=>{" "!==t.char&&(t.x=e,n.push(t)),e+=t.width})),e}(e.data,d,t.data),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(c,n,o),c.overflow&&function(t,n){const{rows:i,overflow:s}=t;let{textOverflow:o}=n;if(i.splice(s),"hide"!==o){let t,a;"ellipsis"===o&&(o="...");const r=e.canvas.measureText(o).width,d=n.x+n.width-r;("none"===n.textWrap?i:[i[s-1]]).forEach((e=>{if(e.isOverflow&&e.data){let n=e.data.length-1;for(let i=n;i>-1&&(t=e.data[i],a=t.x+t.width,!(i===n&&a<d));i--){if(a<d&&" "!==t.char){e.data.splice(i+1),e.width-=t.width;break}e.width-=t.width}e.width+=r,e.data.push({char:o,x:a}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(c,n),"none"!==r&&function(t,e){const{fontSize:n}=e;switch(t.decorationHeight=n/11,e.textDecoration){case"under":t.decorationY=.15*n;break;case"delete":t.decorationY=.35*-n}}(c,n),c}};const Tn={string:function(t,e){if("string"==typeof t)return t;let n=void 0===t.a?1:t.a;e&&(n*=e);const i=t.r+","+t.g+","+t.b;return 1===n?"rgb("+i+")":"rgba("+i+","+n+")"}},{setPoint:Mn,addPoint:Cn,toBounds:Dn}=L;const In={export(t,e,n){return this.running=!0,function(t){Fn||(Fn=new W);return new Promise((e=>{Fn.add((()=>Vt(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((s=>new Promise((a=>{const r=t=>{s(t),a(),this.running=!1},{leafer:d}=t;d?d.waitViewCompleted((()=>Vt(this,void 0,void 0,(function*(){n=o.getExportOptions(n);let s,a,l=1,c=1;const{worldTransform:h,isLeafer:u,isFrame:f}=t,{slice:_,trim:g,onCanvas:w}=n,y=n.scale||1,m=n.pixelRatio||1,v=n.screenshot||t.isApp,x=u&&v&&void 0===n.fill?t.fill:n.fill,b=o.isOpaqueImage(e)||x,B=new A;if(v)s=!0===v?u?d.canvas.bounds:t.worldRenderBounds:v;else{let e=n.relative||(u?"inner":"local");switch(l=h.scaleX,c=h.scaleY,e){case"inner":B.set(h);break;case"local":B.set(h).divide(t.localTransform),l/=t.scaleX,c/=t.scaleY;break;case"world":l=1,c=1;break;case"page":e=t.leafer;default:B.set(h).divide(t.getTransform(e));const n=e.worldTransform;l/=l/n.scaleX,c/=c/n.scaleY}s=t.getBounds("render",e)}const{x:R,y:k,width:E,height:S}=new p(s).scale(y);let L=i.canvas({width:Math.round(E),height:Math.round(S),pixelRatio:m});const W={matrix:B.scale(1/y).invert().translate(-R,-k).withScale(1/l*y,1/c*y)};if(_&&(t=d,W.bounds=L.bounds),L.save(),f&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(L,W),t.fill=e}else t.__render(L,W);if(L.restore(),g){a=function(t){const{width:e,height:n}=t.view,{data:i}=t.context.getImageData(0,0,e,n);let s,o,a,r=0;for(let t=0;t<i.length;t+=4)0!==i[t+3]&&(s=r%e,o=(r-s)/e,a?Cn(a,s,o):Mn(a={},s,o)),r++;const d=new p;return Dn(a,d),d.scale(1/t.pixelRatio).ceil()}(L);const t=L,{width:e,height:n}=a,s={x:0,y:0,width:e,height:n,pixelRatio:m};L=i.canvas(s),L.copyWorld(t,a,s)}b&&L.fillWorld(L.bounds,x||"#FFFFFF","destination-over"),w&&w(L);const O="canvas"===e?L:yield L.export(e,n);r({data:O,width:L.pixelWidth,height:L.pixelHeight,renderBounds:s,trimBounds:a})})))):r({data:!1})}))))}};let Fn;const Pn=t.prototype,Yn=g.get("@leafer-ui/export");Pn.export=function(t,e){const{quality:n,blob:i}=o.getExportOptions(e);return t.includes(".")?this.saveAs(t,n):i?this.toBlob(t,n):this.toDataURL(t,n)},Pn.toBlob=function(t,n){return new Promise((i=>{e.origin.canvasToBolb(this.view,t,n).then((t=>{i(t)})).catch((t=>{Yn.error(t),i(null)}))}))},Pn.toDataURL=function(t,n){return e.origin.canvasToDataURL(this.view,t,n)},Pn.saveAs=function(t,n){return new Promise((i=>{e.origin.canvasSaveAs(this.view,t,n).then((()=>{i(!0)})).catch((t=>{Yn.error(t),i(!1)}))}))},Object.assign(I,On),Object.assign(T,Tn),Object.assign(F,_t),Object.assign(O,zt),Object.assign(M,we),Object.assign(P,ke),Object.assign(C,In),U();export{et as Layouter,Y as LeaferCanvas,it as Renderer,N as Watcher,U as useCanvas};
|
|
1
|
+
import{LeaferCanvasBase as t,Platform as e,canvasPatch as n,Creator as i,LeaferImage as s,FileHelper as o,LeafList as a,DataHelper as r,RenderEvent as d,ChildEvent as l,WatchEvent as c,PropertyEvent as h,LeafHelper as u,BranchHelper as f,Bounds as p,LeafBoundsHelper as _,Debug as g,LeafLevelList as w,LayoutEvent as y,Run as m,ImageManager as x,AnimateEvent as v,ResizeEvent as b,BoundsHelper as B,MatrixHelper as R,AroundHelper as k,ImageEvent as E,PointHelper as S,Direction4 as L,TwoPointBoundsHelper as O,TaskProcessor as W,Matrix as A}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as T,ColorConvert as M,PaintGradient as C,Export as D,Group as I,TextConvert as F,Paint as P,Effect as Y}from"@leafer-ui/draw";export*from"@leafer-ui/draw";class U extends t{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:n}=this;this.view.width=Math.ceil(t*n),this.view.height=Math.ceil(e*n),this.clientBounds=this.bounds}}n(OffscreenCanvasRenderingContext2D.prototype),n(Path2D.prototype);const{mineType:G}=o;function N(t,n){e.origin={createCanvas:(t,e)=>new OffscreenCanvas(t,e),canvasToDataURL:(t,e,n)=>new Promise(((i,s)=>{t.convertToBlob({type:G(e),quality:n}).then((t=>{var e=new FileReader;e.onload=t=>i(t.target.result),e.onerror=t=>s(t),e.readAsDataURL(t)})).catch((t=>{s(t)}))})),canvasToBolb:(t,e,n)=>t.convertToBlob({type:G(e),quality:n}),canvasSaveAs:(t,e,n)=>new Promise((t=>t())),download(t,e){},loadImage:t=>new Promise(((n,i)=>{!t.startsWith("data:")&&e.image.suffix&&(t+=(t.includes("?")?"&":"?")+e.image.suffix);let s=new XMLHttpRequest;s.open("GET",t,!0),s.responseType="blob",s.onload=()=>{createImageBitmap(s.response).then((t=>{n(t)})).catch((t=>{i(t)}))},s.onerror=t=>i(t),s.send()}))},e.canvas=i.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient}Object.assign(i,{canvas:(t,e)=>new U(t,e),image:t=>new s(t)}),e.name="web",e.isWorker=!0,e.requestRender=function(t){requestAnimationFrame(t)},e.devicePixelRatio=1;const{userAgent:X}=navigator;X.indexOf("Firefox")>-1?(e.conicGradientRotate90=!0,e.intWheelDeltaY=!0):X.indexOf("Safari")>-1&&-1===X.indexOf("Chrome")&&(e.fullImageShadow=!0),X.indexOf("Windows")>-1?(e.os="Windows",e.intWheelDeltaY=!0):X.indexOf("Mac")>-1?e.os="Mac":X.indexOf("Linux")>-1&&(e.os="Linux");class j{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new a;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 a,this.target=t,e&&(this.config=r.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(d.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===l.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,n=e.length;t<n;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new c(c.DATA,{updatedList:this.updatedList})),this.__updatedList=new a,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(h.CHANGE,this.__onAttrChange,this),t.on_([l.ADD,l.REMOVE],this.__onChildEvent,this),t.on_(c.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:q,updateBounds:V,updateAllWorldOpacity:z}=u,{pushAllChildBranch:H,pushAllParent:Q}=f;const{worldBounds:J}=_,Z={x:0,y:0,width:1e5,height:1e5};class ${constructor(t){this.updatedBounds=new p,this.beforeBounds=new p,this.afterBounds=new p,t instanceof Array&&(t=new a(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,J)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(Z):this.afterBounds.setListWithFn(t,J),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:K,updateAllChange:tt}=u,et=g.get("Layouter");class nt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new w,this.target=t,e&&(this.config=r.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(y.START),this.layoutOnce(),t.emitEvent(new y(y.END,this.layoutedBlocks,this.times))}catch(t){et.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?et.warn("layouting"):this.times>3?et.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(c.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=m.start("PartLayout"),{target:n,__updatedList:i}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=y,r=this.getBlocks(i);r.forEach((t=>t.setBefore())),n.emitEvent(new y(s,r,this.times)),this.extraBlock=null,i.sort(),function(t,e){let n;t.list.forEach((t=>{n=t.__layout,e.without(t)&&!n.proxyZoom&&(n.matrixChanged?(q(t,!0),e.add(t),t.isBranch&&H(t,e),Q(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),Q(t,e)))}))}(i,this.__levelList),function(t){let e,n,i;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(n=e[t],n.isBranch&&n.__tempNumber){i=n.children;for(let t=0,e=i.length;t<e;t++)i[t].isBranch||V(i[t])}V(n)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&z(t),t.__updateChange()}))}(i),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),n.emitEvent(new y(o,r,this.times)),n.emitEvent(new y(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,m.end(e)}fullLayout(){const t=m.start("FullLayout"),{target:e}=this,{BEFORE:n,LAYOUT:i,AFTER:s}=y,o=this.getBlocks(new a(e));e.emitEvent(new y(n,o,this.times)),nt.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new y(i,o,this.times)),e.emitEvent(new y(s,o,this.times)),this.addBlocks(o),m.end(t)}static fullLayout(t){K(t,!0),t.isBranch?f.updateBounds(t):u.updateBounds(t),tt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new $([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new $(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_(y.REQUEST,this.layout,this),t.on_(y.AGAIN,this.layoutAgain,this),t.on_(c.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const it=g.get("Renderer");class st{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,n){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,n&&(this.config=r.default(n,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(y.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new p,it.log(e.innerName,"---\x3e");try{this.emitRender(d.START),this.renderOnce(t),this.emitRender(d.END,this.totalBounds),x.clearRecycled()}catch(t){this.rendering=!1,it.error(t)}it.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return it.warn("rendering");if(this.times>3)return it.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new p,this.renderOptions={},t)this.emitRender(d.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(d.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(d.RENDER,this.renderBounds,this.renderOptions),this.emitRender(d.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 it.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=m.start("PartRender"),{canvas:n}=this,i=t.getIntersect(n.bounds),s=t.includes(this.target.__world),o=new p(i);n.save(),s&&!g.showRepaint?n.clear():(i.spread(1+1/this.canvas.pixelRatio).ceil(),n.clearWorld(i,!0),n.clipWorld(i,!0)),this.__render(i,s,o),n.restore(),m.end(e)}fullRender(){const t=m.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),m.end(t)}__render(t,e,n){const i=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),g.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,i),this.renderBounds=n||t,this.renderOptions=i,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),g.showHitView&&this.renderHitView(i),g.showBoundsView&&this.renderBoundsView(i),this.canvas.updateRender()}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new p;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(v.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(d.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:n}=t.old;new p(0,0,e,n).includes(this.target.__world)&&!this.needFill&&t.samePixelRatio||(this.addBlock(this.canvas.bounds),this.target.forceUpdate("surface"))}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||it.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,n){this.target.emitEvent(new d(t,this.times,e,n))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(d.REQUEST,this.update,this),t.on_(y.END,this.__onLayoutEnd,this),t.on_(d.AGAIN,this.renderAgain,this),t.on_(b.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 ot(t,e){let n;const{rows:i,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=i.length;t<a;t++)n=i[t],n.text?e.fillText(n.text,n.x,n.y):n.data&&n.data.forEach((t=>{e.fillText(t.char,t.x,n.y)})),s&&e.fillRect(n.x,n.y+s,n.width,o)}function at(t,e,n){const{strokeAlign:i}=e.__,s="string"!=typeof t;switch(i){case"center":n.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?lt(t,!0,e,n):dt(e,n);break;case"inside":rt("inside",t,s,e,n);break;case"outside":rt("outside",t,s,e,n)}}function rt(t,e,n,i,s){const{__strokeWidth:o,__font:a}=i.__,r=s.getSameCanvas(!0,!0);r.setStroke(n?void 0:e,2*o,i.__),r.font=a,n?lt(e,!0,i,r):dt(i,r),r.blendMode="outside"===t?"destination-out":"destination-in",ot(i,r),r.blendMode="normal",i.__worldFlipped?s.copyWorldByReset(r,i.__nowWorld):s.copyWorldToInner(r,i.__nowWorld,i.__layout.renderBounds),r.recycle(i.__nowWorld)}function dt(t,e){let n;const{rows:i,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=i.length;t<a;t++)n=i[t],n.text?e.strokeText(n.text,n.x,n.y):n.data&&n.data.forEach((t=>{e.strokeText(t.char,t.x,n.y)})),s&&e.strokeRect(n.x,n.y+s,n.width,o)}function lt(t,e,n,i){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&T.checkImage(n,i,s,!1)||s.style&&(i.strokeStyle=s.style,s.blendMode?(i.saveBlendMode(s.blendMode),e?dt(n,i):i.stroke(),i.restoreBlendMode()):e?dt(n,i):i.stroke())}Object.assign(i,{watcher:(t,e)=>new j(t,e),layouter:(t,e)=>new nt(t,e),renderer:(t,e,n)=>new st(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,i)=>{}}),e.layout=nt.fullLayout;const{getSpread:ct,getOuterOf:ht,getByMove:ut,getIntersectData:ft}=B;let pt;function _t(t,e,n){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:i}=n.__layout;switch(e.type){case"solid":let{type:s,blendMode:o,color:a,opacity:r}=e;return{type:s,blendMode:o,style:M.string(a,r)};case"image":return T.image(n,t,e,i,!pt||!pt[e.url]);case"linear":return C.linearGradient(e,i);case"radial":return C.radialGradient(e,i);case"angular":return C.conicGradient(e,i);default:return e.r?{type:"solid",style:M.string(e)}:void 0}}const gt={compute:function(t,e){const n=e.__,i=[];let s,o=n.__input[t];o instanceof Array||(o=[o]),pt=T.recycleImage(t,n);for(let n,s=0,a=o.length;s<a;s++)n=_t(t,o[s],e),n&&i.push(n);n["_"+t]=i.length?i:void 0,i.length&&i[0].image&&(s=i[0].image.hasOpacityPixel),"fill"===t?n.__pixelFill=s:n.__pixelStroke=s},fill:function(t,e,n){n.fillStyle=t,e.__.__font?ot(e,n):e.__.windingRule?n.fill(e.__.windingRule):n.fill()},fills:function(t,e,n){let i;const{windingRule:s,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)i=t[a],i.image&&T.checkImage(e,n,i,!o)||i.style&&(n.fillStyle=i.style,i.transform?(n.save(),n.transform(i.transform),i.blendMode&&(n.blendMode=i.blendMode),o?ot(e,n):s?n.fill(s):n.fill(),n.restore()):i.blendMode?(n.saveBlendMode(i.blendMode),o?ot(e,n):s?n.fill(s):n.fill(),n.restoreBlendMode()):o?ot(e,n):s?n.fill(s):n.fill())},fillText:ot,stroke:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)at(t,e,n);else switch(o){case"center":n.setStroke(t,s,i),n.stroke();break;case"inside":n.save(),n.setStroke(t,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),n.stroke(),n.restore();break;case"outside":const o=n.getSameCanvas(!0,!0);o.setStroke(t,2*s,i),e.__drawRenderPath(o),o.stroke(),i.windingRule?o.clip(i.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?n.copyWorldByReset(o,e.__nowWorld):n.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)at(t,e,n);else switch(o){case"center":n.setStroke(void 0,s,i),lt(t,!1,e,n);break;case"inside":n.save(),n.setStroke(void 0,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),lt(t,!1,e,n),n.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=n.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*s,i),lt(t,!1,e,a),i.windingRule?a.clip(i.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?n.copyWorldByReset(a,e.__nowWorld):n.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:at,drawTextStroke:dt,shape:function(t,e,n){const i=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=i,o=r=s;else{const{renderShapeSpread:i}=t.__layout,h=ft(i?ct(e.bounds,i*l,i*c):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,n),l*=u,c*=f),r=ht(s,a),o=ut(r,-a.e,-a.f),n.matrix){const{matrix:t}=n;a.multiply(t),u*=t.scaleX,f*=t.scaleY}n=Object.assign(Object.assign({},n),{matrix:a.withScale(u,f)})}return t.__renderShape(i,n),{canvas:i,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:c}}};let wt={};const{get:yt,rotateOfOuter:mt,translate:xt,scaleOfOuter:vt,scale:bt,rotate:Bt}=R;function Rt(t,e,n,i,s,o,a){const r=yt();xt(r,e.x+n,e.y+i),bt(r,s,o),a&&mt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function kt(t,e,n,i,s,o,a){const r=yt();xt(r,e.x+n,e.y+i),s&&bt(r,s,o),a&&Bt(r,a),t.transform=r}function Et(t,e,n,i,s,o,a,r,d,l){const c=yt();if(d)if("center"===l)mt(c,{x:n/2,y:i/2},d);else switch(Bt(c,d),d){case 90:xt(c,i,0);break;case 180:xt(c,n,i);break;case 270:xt(c,0,n)}wt.x=e.x+s,wt.y=e.y+o,xt(c,wt.x,wt.y),a&&vt(c,wt,a,r),t.transform=c}const{get:St,translate:Lt}=R,Ot=new p,Wt={};function At(t,e,n,i){let{width:s,height:o}=e;n.padding&&(i=Ot.set(i).shrink(n.padding));const{opacity:a,mode:r,around:d,offset:l,scale:c,size:h,rotation:u,blendMode:f,repeat:p}=n,_=i.width===s&&i.height===o;f&&(t.blendMode=f);const g=t.data={mode:r},w="center"!==d&&(u||0)%180==90,y=w?o:s,m=w?s:o;let x,v,b=0,B=0;if(r&&"cover"!==r&&"fit"!==r)h?(x=("number"==typeof h?h:h.width)/s,v=("number"==typeof h?h:h.height)/o):c&&(x="number"==typeof c?c:c.x,v="number"==typeof c?c:c.y);else if(!_||u){const t=i.width/y,e=i.height/m;x=v="fit"===r?Math.min(t,e):Math.max(t,e),b+=(i.width-s*x)/2,B+=(i.height-o*v)/2}if(d){const t={x:b,y:B,width:y,height:m};x&&(t.width*=x,t.height*=v),k.toPoint(d,i,Wt,!0,t),b+=Wt.x,B+=Wt.y}switch(l&&(b+=l.x,B+=l.y),r){case"strench":_||(s=i.width,o=i.height);break;case"normal":case"clip":(b||B||x||u)&&kt(g,i,b,B,x,v,u);break;case"repeat":(!_||x||u)&&Et(g,i,s,o,b,B,x,v,u,d),p||(g.repeat="repeat");break;default:x&&Rt(g,i,b,B,x,v,u)}g.transform||(i.x||i.y)&&(g.transform=St(),Lt(g.transform,i.x,i.y)),x&&"strench"!==r&&(g.scaleX=x,g.scaleY=v),g.width=s,g.height=o,a&&(g.opacity=a),p&&(g.repeat="string"==typeof p?"x"===p?"repeat-x":"repeat-y":"repeat")}let Tt,Mt=new p;const{isSame:Ct}=B;function Dt(t,e,n,i,s,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=i.width/e.pixelRatio,e.__naturalHeight=i.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||At(s,i,n,o),!0}function It(t,e){Yt(t,E.LOAD,e)}function Ft(t,e){Yt(t,E.LOADED,e)}function Pt(t,e,n){e.error=n,t.forceUpdate("surface"),Yt(t,E.ERROR,e)}function Yt(t,e,n){t.hasEvent(e)&&t.emitEvent(new E(e,n))}function Ut(t,e){const{leafer:n}=t;n&&n.viewReady&&(n.renderer.ignore=e)}const{get:Gt,scale:Nt,copy:Xt}=R,{ceil:jt,abs:qt}=Math;function Vt(t,n,i){let{scaleX:s,scaleY:o}=x.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o;if(n.patternId===a||t.destroyed)return!1;{s=qt(s),o=qt(o);const{image:t,data:r}=n;let d,l,{width:c,height:h,scaleX:u,scaleY:f,opacity:p,transform:_,repeat:g}=r;u&&(l=Gt(),Xt(l,_),Nt(l,1/u,1/f),s*=u,o*=f),s*=i,o*=i,c*=s,h*=o;const w=c*h;if(!g&&w>e.image.maxCacheSize)return!1;let y=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(s/=d,o/=d,c/=d,h/=d),u&&(s/=u,o/=f),(_||1!==s||1!==o)&&(l||(l=Gt(),_&&Xt(l,_)),Nt(l,1/s,1/o));const m=t.getCanvas(jt(c)||1,jt(h)||1,p),x=t.getPattern(m,g||e.origin.noRepeat||"no-repeat",l,n);return n.style=x,n.patternId=a,!0}}function zt(t,e,n,i){return new(n||(n=Promise))((function(s,o){function a(t){try{d(i.next(t))}catch(t){o(t)}}function r(t){try{d(i.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,r)}d((i=i.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:Ht}=Math;const Qt={image:function(t,e,n,i,s){let o,a;const r=x.get(n);return Tt&&n===Tt.paint&&Ct(i,Tt.boxBounds)?o=Tt.leafPaint:(o={type:n.type,image:r},Tt=r.use>1?{leafPaint:o,paint:n,boxBounds:Mt.set(i)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:n}),r.ready?(Dt(t,e,n,r,o,i),s&&(It(t,a),Ft(t,a))):r.error?s&&Pt(t,a,r.error):(Ut(t,!0),s&&It(t,a),o.loadId=r.load((()=>{Ut(t,!1),t.destroyed||(Dt(t,e,n,r,o,i)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Ft(t,a)),o.loadId=null}),(e=>{Ut(t,!1),Pt(t,a,e),o.loadId=null}))),o},createData:At,fillOrFitMode:Rt,clipMode:kt,repeatMode:Et,createPattern:Vt,checkImage:function(t,n,i,s){const{scaleX:o,scaleY:a}=x.patternLocked?t.__world:t.__nowWorld;if(i.data&&i.patternId!==o+"-"+a){const{data:r}=i;if(s)if(r.repeat)s=!1;else{let{width:t,height:i}=r;t*=Ht(o)*n.pixelRatio,i*=Ht(a)*n.pixelRatio,r.scaleX&&(t*=r.scaleX,i*=r.scaleY),s=t*i>e.image.maxCacheSize}return s?(n.save(),n.clip(),i.blendMode&&(n.blendMode=i.blendMode),r.opacity&&(n.opacity*=r.opacity),r.transform&&n.transform(r.transform),n.drawImage(i.image.view,0,0,r.width,r.height),n.restore(),!0):(!i.style||D.running?Vt(t,i,n.pixelRatio):i.patternTask||(i.patternTask=x.patternTasker.add((()=>zt(this,void 0,void 0,(function*(){i.patternTask=null,n.bounds.hit(t.__nowWorld)&&Vt(t,i,n.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},recycleImage:function(t,e){const n=e["_"+t];if(n instanceof Array){let i,s,o,a;for(let r=0,d=n.length;r<d;r++)i=n[r].image,a=i&&i.url,a&&(s||(s={}),s[a]=!0,x.recycle(i),i.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),i.unload(n[r].loadId,!o.some((t=>t.url===a)))));return s}return null}},Jt={x:.5,y:0},Zt={x:.5,y:1};function $t(t,e,n){let i;for(let s=0,o=e.length;s<o;s++)i=e[s],t.addColorStop(i.offset,M.string(i.color,n))}const{set:Kt,getAngle:te,getDistance:ee}=S,{get:ne,rotateOfOuter:ie,scaleOfOuter:se}=R,oe={x:.5,y:.5},ae={x:.5,y:1},re={},de={};const{set:le,getAngle:ce,getDistance:he}=S,{get:ue,rotateOfOuter:fe,scaleOfOuter:pe}=R,_e={x:.5,y:.5},ge={x:.5,y:1},we={},ye={};const me={linearGradient:function(t,n){let{from:i,to:s,type:o,blendMode:a,opacity:r}=t;i||(i=Jt),s||(s=Zt);const d=e.canvas.createLinearGradient(n.x+i.x*n.width,n.y+i.y*n.height,n.x+s.x*n.width,n.y+s.y*n.height);$t(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,n){let{from:i,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;i||(i=oe),s||(s=ae);const{x:l,y:c,width:h,height:u}=n;let f;Kt(re,l+i.x*h,c+i.y*u),Kt(de,l+s.x*h,c+s.y*u),(h!==u||d)&&(f=ne(),se(f,re,h/u*(d||1),1),ie(f,re,te(re,de)+90));const p=e.canvas.createRadialGradient(re.x,re.y,0,re.x,re.y,ee(re,de));$t(p,t.stops,a);const _={type:o,style:p,transform:f};return r&&(_.blendMode=r),_},conicGradient:function(t,n){let{from:i,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;i||(i=_e),s||(s=ge);const{x:l,y:c,width:h,height:u}=n;le(we,l+i.x*h,c+i.y*u),le(ye,l+s.x*h,c+s.y*u);const f=ue(),p=ce(we,ye);e.conicGradientRotate90?(pe(f,we,h/u*(d||1),1),fe(f,we,p+90)):(pe(f,we,1,h/u*(d||1)),fe(f,we,p));const _=e.conicGradientSupport?e.canvas.createConicGradient(0,we.x,we.y):e.canvas.createRadialGradient(we.x,we.y,0,we.x,we.y,he(we,ye));$t(_,t.stops,a);const g={type:o,style:_,transform:f};return r&&(g.blendMode=r),g}},{copy:xe,toOffsetOutBounds:ve}=B,be={},Be={};function Re(t,n,i,s){const{bounds:o,shapeBounds:a}=s;if(e.fullImageShadow){if(xe(be,t.bounds),be.x+=n.x-a.x,be.y+=n.y-a.y,i){const{matrix:t}=s;be.x-=(o.x+(t?t.e:0)+o.width/2)*(i-1),be.y-=(o.y+(t?t.f:0)+o.height/2)*(i-1),be.width*=i,be.height*=i}t.copyWorld(s.canvas,t.bounds,be)}else i&&(xe(be,n),be.x-=n.width/2*(i-1),be.y-=n.height/2*(i-1),be.width*=i,be.height*=i),t.copyWorld(s.canvas,a,i?be:n)}const{toOffsetOutBounds:ke}=B,Ee={};const Se={shadow:function(t,e,n){let i,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;ve(l,Be),r.forEach(((r,_)=>{f.setWorldShadow(Be.offsetX+r.x*h,Be.offsetY+r.y*u,r.blur*h,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Re(f,Be,s,n),i=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),i=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(n.canvas,c,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,i,o,r.blendMode):e.copyWorldToInner(f,i,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(i,!0)})),f.recycle(i)},innerShadow:function(t,e,n){let i,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;ke(l,Ee),r.forEach(((r,_)=>{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,Re(f,Ee,s,n),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),i=o):(f.copyWorld(n.canvas,c,l,"source-out"),i=l),f.fillWorld(i,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,i,o,r.blendMode):e.copyWorldToInner(f,i,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(i,!0)})),f.recycle(i)},blur:function(t,e,n){const{blur:i}=t.__;n.setWorldBlur(i*t.__nowWorld.a),n.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),n.filter="none"},backgroundBlur:function(t,e,n){}},{excludeRenderBounds:Le}=_;function Oe(t,e,n,i,s,o){switch(e){case"alpha":!function(t,e,n,i){const s=t.__nowWorld;n.resetTransform(),n.opacity=1,n.useMask(i,s),i.recycle(s),Ae(t,e,n,1)}(t,n,i,s);break;case"opacity-path":Ae(t,n,i,o);break;case"path":n.restore()}}function We(t){return t.getSameCanvas(!1,!0)}function Ae(t,e,n,i){const s=t.__nowWorld;e.resetTransform(),e.opacity=i,e.copyWorld(n,s),n.recycle(s)}I.prototype.__renderMask=function(t,e){let n,i,s,o,a;const{children:r}=this;for(let d=0,l=r.length;d<l;d++)n=r[d],n.__.mask&&(a&&(Oe(this,a,t,s,i,o),i=s=null),"path"===n.__.maskType?(n.opacity<1?(a="opacity-path",o=n.opacity,s||(s=We(t))):(a="path",t.save()),n.__clip(s||t,e)):(a="alpha",i||(i=We(t)),s||(s=We(t)),n.__render(i,e)),"clipping"!==n.__.maskType)||Le(n,e)||n.__render(s||t,e);Oe(this,a,t,s,i,o)};const Te=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Me=Te+"_#~&*+\\=|≮≯≈≠=…",Ce=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 De(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Ie=De("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Fe=De("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Pe=De(Te),Ye=De(Me),Ue=De("- —/~|┆·");var Ge;!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"}(Ge||(Ge={}));const{Letter:Ne,Single:Xe,Before:je,After:qe,Symbol:Ve,Break:ze}=Ge;function He(t){return Ie[t]?Ne:Ue[t]?ze:Fe[t]?je:Pe[t]?qe:Ye[t]?Ve:Ce.test(t)?Xe:Ne}const Qe={trimRight(t){const{words:e}=t;let n,i=0,s=e.length;for(let o=s-1;o>-1&&(n=e[o].data[0]," "===n.char);o--)i++,t.width-=n.width;i&&e.splice(s-i,i)}};function Je(t,e,n){switch(e){case"title":return n?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:Ze}=Qe,{Letter:$e,Single:Ke,Before:tn,After:en,Symbol:nn,Break:sn}=Ge;let on,an,rn,dn,ln,cn,hn,un,fn,pn,_n,gn,wn,yn,mn,xn,vn=[];function bn(t,e){fn&&!un&&(un=fn),on.data.push({char:t,width:e}),rn+=e}function Bn(){dn+=rn,on.width=rn,an.words.push(on),on={data:[]},rn=0}function Rn(){yn&&(mn.paraNumber++,an.paraStart=!0,yn=!1),fn&&(an.startCharSize=un,an.endCharSize=fn,un=0),an.width=dn,xn.width&&Ze(an),vn.push(an),an={words:[]},dn=0}const kn=0,En=1,Sn=2;const{top:Ln,right:On,bottom:Wn,left:An}=L;function Tn(t,e,n){const{bounds:i,rows:s}=t;i[e]+=n;for(let t=0;t<s.length;t++)s[t][e]+=n}const Mn={getDrawData:function(t,n){"string"!=typeof t&&(t=String(t));let i=0,s=0,o=n.__getInput("width")||0,a=n.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=n;l&&(o&&(i=l[An],o-=l[On]+l[An]),a&&(s=l[Ln],a-=l[Ln]+l[Wn]));const c={bounds:{x:i,y:s,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,n,i){mn=t,vn=t.rows,xn=t.bounds;const{__letterSpacing:s,paraIndent:o,textCase:a}=i,{canvas:r}=e,{width:d,height:l}=xn;if(d||l||s||"none"!==a){const t="none"!==i.textWrap,e="break"===i.textWrap;yn=!0,_n=null,un=hn=fn=rn=dn=0,on={data:[]},an={words:[]};for(let i=0,l=n.length;i<l;i++)cn=n[i],"\n"===cn?(rn&&Bn(),an.paraEnd=!0,Rn(),yn=!0):(pn=He(cn),pn===$e&&"none"!==a&&(cn=Je(cn,a,!rn)),hn=r.measureText(cn).width,s&&(s<0&&(fn=hn),hn+=s),gn=pn===Ke&&(_n===Ke||_n===$e)||_n===Ke&&pn!==en,wn=!(pn!==tn&&pn!==Ke||_n!==nn&&_n!==en),ln=yn&&o?d-o:d,t&&d&&dn+rn+hn>ln&&(e?(rn&&Bn(),Rn()):(wn||(wn=pn===$e&&_n==en),gn||wn||pn===sn||pn===tn||pn===Ke||rn+hn>ln?(rn&&Bn(),Rn()):Rn()))," "===cn&&!0!==yn&&dn+rn===0||(pn===sn?(" "===cn&&rn&&Bn(),bn(cn,hn),Bn()):gn||wn?(rn&&Bn(),bn(cn,hn)):bn(cn,hn)),_n=pn);rn&&Bn(),dn&&Rn(),vn.length>0&&(vn[vn.length-1].paraEnd=!0)}else n.split("\n").forEach((t=>{mn.paraNumber++,vn.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(c,t,n),l&&function(t,e,n,i,s){if(!i)switch(n.textAlign){case"left":Tn(e,"x",t[An]);break;case"right":Tn(e,"x",-t[On])}if(!s)switch(n.verticalAlign){case"top":Tn(e,"y",t[Ln]);break;case"bottom":Tn(e,"y",-t[Wn])}}(l,c,n,o,a),function(t,e){const{rows:n,bounds:i}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:c}=e;let h,u,f,{x:p,y:_,width:g,height:w}=i,y=s*n.length+(c?c*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,s),t.overflow=n.length;else switch(l){case"middle":_+=(w-y)/2;break;case"bottom":_+=w-y}m+=_;for(let o=0,l=n.length;o<l;o++){switch(h=n[o],h.x=p,d){case"center":h.x+=(g-h.width)/2;break;case"right":h.x+=g-h.width}h.paraStart&&c&&o>0&&(m+=c),h.y=m,m+=s,t.overflow>o&&m>y&&(h.isOverflow=!0,t.overflow=o+1),u=h.x,f=h.width,a<0&&(h.width<0?(f=-h.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<i.x&&(i.x=u),f>i.width&&(i.width=f),r&&g&&g<f&&(h.isOverflow=!0,t.overflow||(t.overflow=n.length))}i.y=_,i.height=y}(c,n),function(t,e,n,i){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=n&&"justify"===o&&t.words.length>1?(n-t.width-c)/(t.words.length-1):0,h=r||t.isOverflow?kn:l>.01?En:Sn,t.isOverflow&&!r&&(t.textMode=!0),h===Sn?(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===En?(u={char:"",x:d},d=function(t,e,n){return t.forEach((t=>{n.char+=t.char,e+=t.width})),e}(e.data,d,u)," "!==u.char&&t.data.push(u)):d=function(t,e,n){return t.forEach((t=>{" "!==t.char&&(t.x=e,n.push(t)),e+=t.width})),e}(e.data,d,t.data),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(c,n,o),c.overflow&&function(t,n){const{rows:i,overflow:s}=t;let{textOverflow:o}=n;if(i.splice(s),"hide"!==o){let t,a;"ellipsis"===o&&(o="...");const r=e.canvas.measureText(o).width,d=n.x+n.width-r;("none"===n.textWrap?i:[i[s-1]]).forEach((e=>{if(e.isOverflow&&e.data){let n=e.data.length-1;for(let i=n;i>-1&&(t=e.data[i],a=t.x+t.width,!(i===n&&a<d));i--){if(a<d&&" "!==t.char){e.data.splice(i+1),e.width-=t.width;break}e.width-=t.width}e.width+=r,e.data.push({char:o,x:a}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(c,n),"none"!==r&&function(t,e){const{fontSize:n}=e;switch(t.decorationHeight=n/11,e.textDecoration){case"under":t.decorationY=.15*n;break;case"delete":t.decorationY=.35*-n}}(c,n),c}};const Cn={string:function(t,e){if("string"==typeof t)return t;let n=void 0===t.a?1:t.a;e&&(n*=e);const i=t.r+","+t.g+","+t.b;return 1===n?"rgb("+i+")":"rgba("+i+","+n+")"}},{setPoint:Dn,addPoint:In,toBounds:Fn}=O;const Pn={export(t,n,s){return this.running=!0,function(t){Yn||(Yn=new W);return new Promise((e=>{Yn.add((()=>zt(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((a=>new Promise((r=>{const d=t=>{a(t),r(),this.running=!1};if("json"===n)return d({data:t.toJSON()});if("json"===o.fileType(n))return e.origin.download("data:text/plain;charset=utf-8,"+encodeURIComponent(JSON.stringify(t.toJSON())),n),d({data:!0});const{leafer:l}=t;l?l.waitViewCompleted((()=>zt(this,void 0,void 0,(function*(){s=o.getExportOptions(s);let e,a,r=1,c=1;const{worldTransform:h,isLeafer:u,isFrame:f}=t,{slice:_,trim:g,onCanvas:w}=s,y=s.scale||1,m=s.pixelRatio||1,x=s.screenshot||t.isApp,v=u&&x&&void 0===s.fill?t.fill:s.fill,b=o.isOpaqueImage(n)||v,B=new A;if(x)e=!0===x?u?l.canvas.bounds:t.worldRenderBounds:x;else{let n=s.relative||(u?"inner":"local");switch(r=h.scaleX,c=h.scaleY,n){case"inner":B.set(h);break;case"local":B.set(h).divide(t.localTransform),r/=t.scaleX,c/=t.scaleY;break;case"world":r=1,c=1;break;case"page":n=t.leafer;default:B.set(h).divide(t.getTransform(n));const e=n.worldTransform;r/=r/e.scaleX,c/=c/e.scaleY}e=t.getBounds("render",n)}const{x:R,y:k,width:E,height:S}=new p(e).scale(y);let L=i.canvas({width:Math.round(E),height:Math.round(S),pixelRatio:m});const O={matrix:B.scale(1/y).invert().translate(-R,-k).withScale(1/r*y,1/c*y)};if(_&&(t=l,O.bounds=L.bounds),L.save(),f&&void 0!==v){const e=t.get("fill");t.fill="",t.__render(L,O),t.fill=e}else t.__render(L,O);if(L.restore(),g){a=function(t){const{width:e,height:n}=t.view,{data:i}=t.context.getImageData(0,0,e,n);let s,o,a,r=0;for(let t=0;t<i.length;t+=4)0!==i[t+3]&&(s=r%e,o=(r-s)/e,a?In(a,s,o):Dn(a={},s,o)),r++;const d=new p;return Fn(a,d),d.scale(1/t.pixelRatio).ceil()}(L);const t=L,{width:e,height:n}=a,s={x:0,y:0,width:e,height:n,pixelRatio:m};L=i.canvas(s),L.copyWorld(t,a,s)}b&&L.fillWorld(L.bounds,v||"#FFFFFF","destination-over"),w&&w(L);const W="canvas"===n?L:yield L.export(n,s);d({data:W,width:L.pixelWidth,height:L.pixelHeight,renderBounds:e,trimBounds:a})})))):d({data:!1})}))))}};let Yn;const Un=t.prototype,Gn=g.get("@leafer-ui/export");Un.export=function(t,e){const{quality:n,blob:i}=o.getExportOptions(e);return t.includes(".")?this.saveAs(t,n):i?this.toBlob(t,n):this.toDataURL(t,n)},Un.toBlob=function(t,n){return new Promise((i=>{e.origin.canvasToBolb(this.view,t,n).then((t=>{i(t)})).catch((t=>{Gn.error(t),i(null)}))}))},Un.toDataURL=function(t,n){return e.origin.canvasToDataURL(this.view,t,n)},Un.saveAs=function(t,n){return new Promise((i=>{e.origin.canvasSaveAs(this.view,t,n).then((()=>{i(!0)})).catch((t=>{Gn.error(t),i(!1)}))}))},Object.assign(F,Mn),Object.assign(M,Cn),Object.assign(P,gt),Object.assign(T,Qt),Object.assign(C,me),Object.assign(Y,Se),Object.assign(D,Pn),N();export{nt as Layouter,U as LeaferCanvas,st as Renderer,j as Watcher,N as useCanvas};
|