@leafer-draw/worker 1.0.0-rc.25 → 1.0.0-rc.27
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 +69 -48
- package/dist/worker.esm.min.js +1 -1
- package/dist/worker.js +146 -71
- package/dist/worker.min.js +1 -1
- package/dist/worker.module.js +146 -71
- package/dist/worker.module.min.js +1 -1
- package/package.json +6 -6
package/dist/worker.esm.js
CHANGED
|
@@ -957,7 +957,7 @@ function getLeafPaint(attrName, paint, ui) {
|
|
|
957
957
|
case 'angular':
|
|
958
958
|
return PaintGradient.conicGradient(paint, boxBounds);
|
|
959
959
|
default:
|
|
960
|
-
return paint.r ? { type: 'solid', style: ColorConvert.string(paint) } : undefined;
|
|
960
|
+
return paint.r !== undefined ? { type: 'solid', style: ColorConvert.string(paint) } : undefined;
|
|
961
961
|
}
|
|
962
962
|
}
|
|
963
963
|
|
|
@@ -974,17 +974,17 @@ const PaintModule = {
|
|
|
974
974
|
};
|
|
975
975
|
|
|
976
976
|
let origin = {};
|
|
977
|
-
const { get: get$
|
|
977
|
+
const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate } = MatrixHelper;
|
|
978
978
|
function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
979
|
-
const transform = get$
|
|
979
|
+
const transform = get$3();
|
|
980
980
|
translate$1(transform, box.x + x, box.y + y);
|
|
981
981
|
scaleHelper(transform, scaleX, scaleY);
|
|
982
982
|
if (rotation)
|
|
983
|
-
rotateOfOuter$
|
|
983
|
+
rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
|
|
984
984
|
data.transform = transform;
|
|
985
985
|
}
|
|
986
986
|
function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
987
|
-
const transform = get$
|
|
987
|
+
const transform = get$3();
|
|
988
988
|
translate$1(transform, box.x + x, box.y + y);
|
|
989
989
|
if (scaleX)
|
|
990
990
|
scaleHelper(transform, scaleX, scaleY);
|
|
@@ -993,10 +993,10 @@ function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
|
993
993
|
data.transform = transform;
|
|
994
994
|
}
|
|
995
995
|
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
|
|
996
|
-
const transform = get$
|
|
996
|
+
const transform = get$3();
|
|
997
997
|
if (rotation) {
|
|
998
998
|
if (align === 'center') {
|
|
999
|
-
rotateOfOuter$
|
|
999
|
+
rotateOfOuter$1(transform, { x: width / 2, y: height / 2 }, rotation);
|
|
1000
1000
|
}
|
|
1001
1001
|
else {
|
|
1002
1002
|
rotate(transform, rotation);
|
|
@@ -1017,22 +1017,26 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
|
|
|
1017
1017
|
origin.y = box.y + y;
|
|
1018
1018
|
translate$1(transform, origin.x, origin.y);
|
|
1019
1019
|
if (scaleX)
|
|
1020
|
-
scaleOfOuter$
|
|
1020
|
+
scaleOfOuter$1(transform, origin, scaleX, scaleY);
|
|
1021
1021
|
data.transform = transform;
|
|
1022
1022
|
}
|
|
1023
1023
|
|
|
1024
|
-
const { get: get$
|
|
1024
|
+
const { get: get$2, translate } = MatrixHelper;
|
|
1025
1025
|
const tempBox = new Bounds();
|
|
1026
1026
|
const tempPoint = {};
|
|
1027
1027
|
function createData(leafPaint, image, paint, box) {
|
|
1028
|
+
const { blendMode } = paint;
|
|
1029
|
+
if (blendMode)
|
|
1030
|
+
leafPaint.blendMode = blendMode;
|
|
1031
|
+
leafPaint.data = getPatternData(paint, box, image);
|
|
1032
|
+
}
|
|
1033
|
+
function getPatternData(paint, box, image) {
|
|
1028
1034
|
let { width, height } = image;
|
|
1029
1035
|
if (paint.padding)
|
|
1030
1036
|
box = tempBox.set(box).shrink(paint.padding);
|
|
1031
|
-
const { opacity, mode, align, offset, scale, size, rotation,
|
|
1037
|
+
const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
|
|
1032
1038
|
const sameBox = box.width === width && box.height === height;
|
|
1033
|
-
|
|
1034
|
-
leafPaint.blendMode = blendMode;
|
|
1035
|
-
const data = leafPaint.data = { mode };
|
|
1039
|
+
const data = { mode };
|
|
1036
1040
|
const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
|
|
1037
1041
|
const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height;
|
|
1038
1042
|
let x = 0, y = 0, scaleX, scaleY;
|
|
@@ -1084,7 +1088,7 @@ function createData(leafPaint, image, paint, box) {
|
|
|
1084
1088
|
}
|
|
1085
1089
|
if (!data.transform) {
|
|
1086
1090
|
if (box.x || box.y) {
|
|
1087
|
-
data.transform = get$
|
|
1091
|
+
data.transform = get$2();
|
|
1088
1092
|
translate(data.transform, box.x, box.y);
|
|
1089
1093
|
}
|
|
1090
1094
|
}
|
|
@@ -1098,6 +1102,7 @@ function createData(leafPaint, image, paint, box) {
|
|
|
1098
1102
|
data.opacity = opacity;
|
|
1099
1103
|
if (repeat)
|
|
1100
1104
|
data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
|
|
1105
|
+
return data;
|
|
1101
1106
|
}
|
|
1102
1107
|
|
|
1103
1108
|
let cache, box = new Bounds();
|
|
@@ -1187,7 +1192,7 @@ function ignoreRender(ui, value) {
|
|
|
1187
1192
|
leafer.renderer.ignore = value;
|
|
1188
1193
|
}
|
|
1189
1194
|
|
|
1190
|
-
const { get: get$
|
|
1195
|
+
const { get: get$1, scale, copy: copy$1 } = MatrixHelper;
|
|
1191
1196
|
const { ceil, abs: abs$1 } = Math;
|
|
1192
1197
|
function createPattern(ui, paint, pixelRatio) {
|
|
1193
1198
|
let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
|
|
@@ -1198,7 +1203,7 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1198
1203
|
const { image, data } = paint;
|
|
1199
1204
|
let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, repeat } = data;
|
|
1200
1205
|
if (sx) {
|
|
1201
|
-
imageMatrix = get$
|
|
1206
|
+
imageMatrix = get$1();
|
|
1202
1207
|
copy$1(imageMatrix, transform);
|
|
1203
1208
|
scale(imageMatrix, 1 / sx, 1 / sy);
|
|
1204
1209
|
scaleX *= sx;
|
|
@@ -1233,7 +1238,7 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1233
1238
|
}
|
|
1234
1239
|
if (transform || scaleX !== 1 || scaleY !== 1) {
|
|
1235
1240
|
if (!imageMatrix) {
|
|
1236
|
-
imageMatrix = get$
|
|
1241
|
+
imageMatrix = get$1();
|
|
1237
1242
|
if (transform)
|
|
1238
1243
|
copy$1(imageMatrix, transform);
|
|
1239
1244
|
}
|
|
@@ -1366,13 +1371,14 @@ function recycleImage(attrName, data) {
|
|
|
1366
1371
|
|
|
1367
1372
|
const PaintImageModule = {
|
|
1368
1373
|
image,
|
|
1374
|
+
checkImage,
|
|
1375
|
+
createPattern,
|
|
1376
|
+
recycleImage,
|
|
1369
1377
|
createData,
|
|
1378
|
+
getPatternData,
|
|
1370
1379
|
fillOrFitMode,
|
|
1371
1380
|
clipMode,
|
|
1372
|
-
repeatMode
|
|
1373
|
-
createPattern,
|
|
1374
|
-
checkImage,
|
|
1375
|
-
recycleImage
|
|
1381
|
+
repeatMode
|
|
1376
1382
|
};
|
|
1377
1383
|
|
|
1378
1384
|
const { toPoint: toPoint$2 } = AroundHelper;
|
|
@@ -1402,8 +1408,8 @@ function applyStops(gradient, stops, opacity) {
|
|
|
1402
1408
|
}
|
|
1403
1409
|
}
|
|
1404
1410
|
|
|
1405
|
-
const { getAngle
|
|
1406
|
-
const { get
|
|
1411
|
+
const { getAngle, getDistance: getDistance$1 } = PointHelper;
|
|
1412
|
+
const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
|
|
1407
1413
|
const { toPoint: toPoint$1 } = AroundHelper;
|
|
1408
1414
|
const realFrom$1 = {};
|
|
1409
1415
|
const realTo$1 = {};
|
|
@@ -1411,23 +1417,35 @@ function radialGradient(paint, box) {
|
|
|
1411
1417
|
let { from, to, type, opacity, blendMode, stretch } = paint;
|
|
1412
1418
|
toPoint$1(from || 'center', box, realFrom$1);
|
|
1413
1419
|
toPoint$1(to || 'bottom', box, realTo$1);
|
|
1414
|
-
const { width, height } = box;
|
|
1415
|
-
let transform;
|
|
1416
|
-
if (width !== height || stretch) {
|
|
1417
|
-
transform = get$1();
|
|
1418
|
-
scaleOfOuter$1(transform, realFrom$1, width / height * (stretch || 1), 1);
|
|
1419
|
-
rotateOfOuter$1(transform, realFrom$1, getAngle$1(realFrom$1, realTo$1) + 90);
|
|
1420
|
-
}
|
|
1421
1420
|
const style = Platform.canvas.createRadialGradient(realFrom$1.x, realFrom$1.y, 0, realFrom$1.x, realFrom$1.y, getDistance$1(realFrom$1, realTo$1));
|
|
1422
1421
|
applyStops(style, paint.stops, opacity);
|
|
1423
|
-
const data = { type, style
|
|
1422
|
+
const data = { type, style };
|
|
1423
|
+
const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
|
|
1424
|
+
if (transform)
|
|
1425
|
+
data.transform = transform;
|
|
1424
1426
|
if (blendMode)
|
|
1425
1427
|
data.blendMode = blendMode;
|
|
1426
1428
|
return data;
|
|
1427
1429
|
}
|
|
1430
|
+
function getTransform(box, from, to, stretch, rotate90) {
|
|
1431
|
+
let transform;
|
|
1432
|
+
const { width, height } = box;
|
|
1433
|
+
if (width !== height || stretch) {
|
|
1434
|
+
const angle = getAngle(from, to);
|
|
1435
|
+
transform = get();
|
|
1436
|
+
if (rotate90) {
|
|
1437
|
+
scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
|
|
1438
|
+
rotateOfOuter(transform, from, angle + 90);
|
|
1439
|
+
}
|
|
1440
|
+
else {
|
|
1441
|
+
scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
|
|
1442
|
+
rotateOfOuter(transform, from, angle);
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
return transform;
|
|
1446
|
+
}
|
|
1428
1447
|
|
|
1429
|
-
const {
|
|
1430
|
-
const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
|
|
1448
|
+
const { getDistance } = PointHelper;
|
|
1431
1449
|
const { toPoint } = AroundHelper;
|
|
1432
1450
|
const realFrom = {};
|
|
1433
1451
|
const realTo = {};
|
|
@@ -1435,20 +1453,12 @@ function conicGradient(paint, box) {
|
|
|
1435
1453
|
let { from, to, type, opacity, blendMode, stretch } = paint;
|
|
1436
1454
|
toPoint(from || 'center', box, realFrom);
|
|
1437
1455
|
toPoint(to || 'bottom', box, realTo);
|
|
1438
|
-
const { width, height } = box;
|
|
1439
|
-
const transform = get();
|
|
1440
|
-
const angle = getAngle(realFrom, realTo);
|
|
1441
|
-
if (Platform.conicGradientRotate90) {
|
|
1442
|
-
scaleOfOuter(transform, realFrom, width / height * (stretch || 1), 1);
|
|
1443
|
-
rotateOfOuter(transform, realFrom, angle + 90);
|
|
1444
|
-
}
|
|
1445
|
-
else {
|
|
1446
|
-
scaleOfOuter(transform, realFrom, 1, width / height * (stretch || 1));
|
|
1447
|
-
rotateOfOuter(transform, realFrom, angle);
|
|
1448
|
-
}
|
|
1449
1456
|
const style = Platform.conicGradientSupport ? Platform.canvas.createConicGradient(0, realFrom.x, realFrom.y) : Platform.canvas.createRadialGradient(realFrom.x, realFrom.y, 0, realFrom.x, realFrom.y, getDistance(realFrom, realTo));
|
|
1450
1457
|
applyStops(style, paint.stops, opacity);
|
|
1451
|
-
const data = { type, style
|
|
1458
|
+
const data = { type, style };
|
|
1459
|
+
const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90);
|
|
1460
|
+
if (transform)
|
|
1461
|
+
data.transform = transform;
|
|
1452
1462
|
if (blendMode)
|
|
1453
1463
|
data.blendMode = blendMode;
|
|
1454
1464
|
return data;
|
|
@@ -1457,7 +1467,8 @@ function conicGradient(paint, box) {
|
|
|
1457
1467
|
const PaintGradientModule = {
|
|
1458
1468
|
linearGradient,
|
|
1459
1469
|
radialGradient,
|
|
1460
|
-
conicGradient
|
|
1470
|
+
conicGradient,
|
|
1471
|
+
getTransform
|
|
1461
1472
|
};
|
|
1462
1473
|
|
|
1463
1474
|
const { copy, toOffsetOutBounds: toOffsetOutBounds$1 } = BoundsHelper;
|
|
@@ -2183,11 +2194,21 @@ const ExportModule = {
|
|
|
2183
2194
|
resolve();
|
|
2184
2195
|
this.running = false;
|
|
2185
2196
|
};
|
|
2197
|
+
const { toURL } = Platform;
|
|
2198
|
+
const { download } = Platform.origin;
|
|
2199
|
+
const fileType = FileHelper.fileType(filename);
|
|
2186
2200
|
if (filename === 'json') {
|
|
2187
2201
|
return over({ data: leaf.toJSON() });
|
|
2188
2202
|
}
|
|
2189
|
-
else if (
|
|
2190
|
-
|
|
2203
|
+
else if (fileType === 'json') {
|
|
2204
|
+
download(toURL(JSON.stringify(leaf.toJSON()), 'text'), filename);
|
|
2205
|
+
return over({ data: true });
|
|
2206
|
+
}
|
|
2207
|
+
if (filename === 'svg') {
|
|
2208
|
+
return over({ data: leaf.toSVG() });
|
|
2209
|
+
}
|
|
2210
|
+
else if (fileType === 'svg') {
|
|
2211
|
+
download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2191
2212
|
return over({ data: true });
|
|
2192
2213
|
}
|
|
2193
2214
|
const { leafer } = leaf;
|
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,AlignHelper as k,ImageEvent as E,AroundHelper as S,PointHelper as L,Direction4 as O,TwoPointBoundsHelper as A,TaskProcessor as W,Matrix as T}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as M,ColorConvert as C,PaintGradient as D,Export as I,Group as P,TextConvert as F,Paint as Y,Effect as U}from"@leafer-ui/draw";export*from"@leafer-ui/draw";class G 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:N}=o;function X(t,n){e.origin={createCanvas:(t,e)=>new OffscreenCanvas(t,e),canvasToDataURL:(t,e,n)=>new Promise(((i,s)=>{t.convertToBlob({type:N(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:N(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 G(t,e),image:t=>new s(t)}),e.name="web",e.isWorker=!0,e.requestRender=function(t){requestAnimationFrame(t)},e.devicePixelRatio=1;const{userAgent:j}=navigator;j.indexOf("Firefox")>-1?(e.conicGradientRotate90=!0,e.intWheelDeltaY=!0):j.indexOf("Safari")>-1&&-1===j.indexOf("Chrome")&&(e.fullImageShadow=!0),j.indexOf("Windows")>-1?(e.os="Windows",e.intWheelDeltaY=!0):j.indexOf("Mac")>-1?e.os="Mac":j.indexOf("Linux")>-1&&(e.os="Linux");class q{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:V,updateBounds:z,updateAllWorldOpacity:H}=u,{pushAllChildBranch:Q,pushAllParent:J}=f;const{worldBounds:Z}=_,$={x:0,y:0,width:1e5,height:1e5};class K{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,Z)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set($):this.afterBounds.setListWithFn(t,Z),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:tt,updateAllChange:et}=u,nt=g.get("Layouter");class it{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){nt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?nt.warn("layouting"):this.times>3?nt.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?(V(t,!0),e.add(t),t.isBranch&&Q(t,e),J(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),J(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||z(i[t])}z(n)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&H(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)),it.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){tt(t,!0),t.isBranch?f.updateBounds(t):u.updateBounds(t),et(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new K([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new K(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 st=g.get("Renderer");class ot{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,st.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,st.error(t)}st.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return st.warn("rendering");if(this.times>3)return st.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 st.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(10+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){if(t.bigger||!t.samePixelRatio){const{width:e,height:n}=t.old;if(!new p(0,0,e,n).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new p(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||st.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 at(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 rt(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?ct(t,!0,e,n):lt(e,n);break;case"inside":dt("inside",t,s,e,n);break;case"outside":dt("outside",t,s,e,n)}}function dt(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?ct(e,!0,i,r):lt(i,r),r.blendMode="outside"===t?"destination-out":"destination-in",at(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 lt(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 ct(t,e,n,i){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&M.checkImage(n,i,s,!1)||s.style&&(i.strokeStyle=s.style,s.blendMode?(i.saveBlendMode(s.blendMode),e?lt(n,i):i.stroke(),i.restoreBlendMode()):e?lt(n,i):i.stroke())}Object.assign(i,{watcher:(t,e)=>new q(t,e),layouter:(t,e)=>new it(t,e),renderer:(t,e,n)=>new ot(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,i)=>{}}),e.layout=it.fullLayout;const{getSpread:ht,getOuterOf:ut,getByMove:ft,getIntersectData:pt}=B;let _t;function gt(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:C.string(a,r)};case"image":return M.image(n,t,e,i,!_t||!_t[e.url]);case"linear":return D.linearGradient(e,i);case"radial":return D.radialGradient(e,i);case"angular":return D.conicGradient(e,i);default:return e.r?{type:"solid",style:C.string(e)}:void 0}}const wt={compute:function(t,e){const n=e.__,i=[];let s,o=n.__input[t];o instanceof Array||(o=[o]),_t=M.recycleImage(t,n);for(let n,s=0,a=o.length;s<a;s++)n=gt(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?at(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&&M.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?at(e,n):s?n.fill(s):n.fill(),n.restore()):i.blendMode?(n.saveBlendMode(i.blendMode),o?at(e,n):s?n.fill(s):n.fill(),n.restoreBlendMode()):o?at(e,n):s?n.fill(s):n.fill())},fillText:at,stroke:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)rt(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)rt(t,e,n);else switch(o){case"center":n.setStroke(void 0,s,i),ct(t,!1,e,n);break;case"inside":n.save(),n.setStroke(void 0,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),ct(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),ct(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:rt,drawTextStroke:lt,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=pt(i?ht(e.bounds,l===c?i*l:[i*c,i*l]):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,n),l*=u,c*=f),r=ut(s,a),o=ft(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 yt={};const{get:mt,rotateOfOuter:vt,translate:xt,scaleOfOuter:bt,scale:Bt,rotate:Rt}=R;function kt(t,e,n,i,s,o,a){const r=mt();xt(r,e.x+n,e.y+i),Bt(r,s,o),a&&vt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Et(t,e,n,i,s,o,a){const r=mt();xt(r,e.x+n,e.y+i),s&&Bt(r,s,o),a&&Rt(r,a),t.transform=r}function St(t,e,n,i,s,o,a,r,d,l){const c=mt();if(d)if("center"===l)vt(c,{x:n/2,y:i/2},d);else switch(Rt(c,d),d){case 90:xt(c,i,0);break;case 180:xt(c,n,i);break;case 270:xt(c,0,n)}yt.x=e.x+s,yt.y=e.y+o,xt(c,yt.x,yt.y),a&&bt(c,yt,a,r),t.transform=c}const{get:Lt,translate:Ot}=R,At=new p,Wt={};function Tt(t,e,n,i){let{width:s,height:o}=e;n.padding&&(i=At.set(i).shrink(n.padding));const{opacity:a,mode:r,align: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 v,x,b=0,B=0;if(r&&"cover"!==r&&"fit"!==r)h?(v=("number"==typeof h?h:h.width)/s,x=("number"==typeof h?h:h.height)/o):c&&(v="number"==typeof c?c:c.x,x="number"==typeof c?c:c.y);else if(!_||u){const t=i.width/y,e=i.height/m;v=x="fit"===r?Math.min(t,e):Math.max(t,e),b+=(i.width-s*v)/2,B+=(i.height-o*x)/2}if(d){const t={x:b,y:B,width:y,height:m};v&&(t.width*=v,t.height*=x),k.toPoint(d,t,i,Wt,!0),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||v||u)&&Et(g,i,b,B,v,x,u);break;case"repeat":(!_||v||u)&&St(g,i,s,o,b,B,v,x,u,d),p||(g.repeat="repeat");break;default:v&&kt(g,i,b,B,v,x,u)}g.transform||(i.x||i.y)&&(g.transform=Lt(),Ot(g.transform,i.x,i.y)),v&&"strench"!==r&&(g.scaleX=v,g.scaleY=x),g.width=s,g.height=o,a&&(g.opacity=a),p&&(g.repeat="string"==typeof p?"x"===p?"repeat-x":"repeat-y":"repeat")}let Mt,Ct=new p;const{isSame:Dt}=B;function It(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||Tt(s,i,n,o),!0}function Pt(t,e){Ut(t,E.LOAD,e)}function Ft(t,e){Ut(t,E.LOADED,e)}function Yt(t,e,n){e.error=n,t.forceUpdate("surface"),Ut(t,E.ERROR,e)}function Ut(t,e,n){t.hasEvent(e)&&t.emitEvent(new E(e,n))}function Gt(t,e){const{leafer:n}=t;n&&n.viewReady&&(n.renderer.ignore=e)}const{get:Nt,scale:Xt,copy:jt}=R,{ceil:qt,abs:Vt}=Math;function zt(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=Vt(s),o=Vt(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=Nt(),jt(l,_),Xt(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=Nt(),_&&jt(l,_)),Xt(l,1/s,1/o));const m=t.getCanvas(qt(c)||1,qt(h)||1,p),v=t.getPattern(m,g||e.origin.noRepeat||"no-repeat",l,n);return n.style=v,n.patternId=a,!0}}function Ht(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:Qt}=Math;const Jt={image:function(t,e,n,i,s){let o,a;const r=v.get(n);return Mt&&n===Mt.paint&&Dt(i,Mt.boxBounds)?o=Mt.leafPaint:(o={type:n.type,image:r},Mt=r.use>1?{leafPaint:o,paint:n,boxBounds:Ct.set(i)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:n}),r.ready?(It(t,e,n,r,o,i),s&&(Pt(t,a),Ft(t,a))):r.error?s&&Yt(t,a,r.error):(Gt(t,!0),s&&Pt(t,a),o.loadId=r.load((()=>{Gt(t,!1),t.destroyed||(It(t,e,n,r,o,i)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Ft(t,a)),o.loadId=null}),(e=>{Gt(t,!1),Yt(t,a,e),o.loadId=null}))),o},createData:Tt,fillOrFitMode:kt,clipMode:Et,repeatMode:St,createPattern:zt,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*=Qt(o)*n.pixelRatio,i*=Qt(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||I.running?zt(t,i,n.pixelRatio):i.patternTask||(i.patternTask=v.patternTasker.add((()=>Ht(this,void 0,void 0,(function*(){i.patternTask=null,n.bounds.hit(t.__nowWorld)&&zt(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}},{toPoint:Zt}=S,$t={},Kt={};function te(t,e,n){let i;for(let s=0,o=e.length;s<o;s++)i=e[s],"string"==typeof i?t.addColorStop(s/(o-1),C.string(i,n)):t.addColorStop(i.offset,C.string(i.color,n))}const{getAngle:ee,getDistance:ne}=L,{get:ie,rotateOfOuter:se,scaleOfOuter:oe}=R,{toPoint:ae}=S,re={},de={};const{getAngle:le,getDistance:ce}=L,{get:he,rotateOfOuter:ue,scaleOfOuter:fe}=R,{toPoint:pe}=S,_e={},ge={};const we={linearGradient:function(t,n){let{from:i,to:s,type:o,blendMode:a,opacity:r}=t;Zt(i||"top",n,$t),Zt(s||"bottom",n,Kt);const d=e.canvas.createLinearGradient($t.x,$t.y,Kt.x,Kt.y);te(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;ae(i||"center",n,re),ae(s||"bottom",n,de);const{width:l,height:c}=n;let h;(l!==c||d)&&(h=ie(),oe(h,re,l/c*(d||1),1),se(h,re,ee(re,de)+90));const u=e.canvas.createRadialGradient(re.x,re.y,0,re.x,re.y,ne(re,de));te(u,t.stops,a);const f={type:o,style:u,transform:h};return r&&(f.blendMode=r),f},conicGradient:function(t,n){let{from:i,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;pe(i||"center",n,_e),pe(s||"bottom",n,ge);const{width:l,height:c}=n,h=he(),u=le(_e,ge);e.conicGradientRotate90?(fe(h,_e,l/c*(d||1),1),ue(h,_e,u+90)):(fe(h,_e,1,l/c*(d||1)),ue(h,_e,u));const f=e.conicGradientSupport?e.canvas.createConicGradient(0,_e.x,_e.y):e.canvas.createRadialGradient(_e.x,_e.y,0,_e.x,_e.y,ce(_e,ge));te(f,t.stops,a);const p={type:o,style:f,transform:h};return r&&(p.blendMode=r),p}},{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),Oe(t,e,n,1)}(t,n,i,s);break;case"opacity-path":Oe(t,n,i,o);break;case"path":n.restore()}}function Le(t){return t.getSameCanvas(!1,!0)}function Oe(t,e,n,i){const s=t.__nowWorld;e.resetTransform(),e.opacity=i,e.copyWorld(n,s),n.recycle(s)}P.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.__.mask?(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.__.mask)||Ee(n,e)||n.__render(s||t,e);Se(this,a,t,s,i,o)};const Ae=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",We=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),Pe=Me(We),Fe=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:Ue,Single:Ge,Before:Ne,After:Xe,Symbol:je,Break:qe}=Ye;function Ve(t){return Ce[t]?Ue:Fe[t]?qe:De[t]?Ne:Ie[t]?Xe:Pe[t]?je:Te.test(t)?Ge:Ue}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:Je,Single:Ze,Before:$e,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:On}=O;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 Wn={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[On],o-=l[Sn]+l[On]),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=Ve(dn),un===Je&&"none"!==a&&(dn=He(dn,a,!on)),ln=r.measureText(dn).width,s&&(s<0&&(hn=ln),ln+=s),pn=un===Ze&&(fn===Ze||fn===Je)||fn===Ze&&un!==Ke,_n=!(un!==$e&&un!==Ze||fn!==tn&&fn!==Ke),rn=gn&&o?d-o:d,t&&d&&an+on+ln>rn&&(e?(on&&xn(),bn()):(_n||(_n=un===Je&&fn==Ke),pn||_n||un===en||un===$e||un===Ze||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[On]);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++){if(h=n[o],h.x=p,h.width<g||h.width>g&&!r)switch(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),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,n,i){return t.forEach((t=>{(i||" "!==t.char)&&(t.x=e,n.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(c,n,o),c.overflow&&function(t,n){const{rows:i,overflow:s}=t;let{textOverflow:o}=n;if(i.splice(s),o&&"show"!==o){let t,a;"hide"===o?o="":"ellipsis"===o&&(o="...");const r=o?e.canvas.measureText(o).width:0,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}=A;const In={export(t,n,s){return this.running=!0,function(t){Pn||(Pn=new W);return new Promise((e=>{Pn.add((()=>Ht(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((()=>Ht(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;let y=s.scale||1,m=s.pixelRatio||1;t.isApp&&(y*=m,m=t.app.pixelRatio);const v=s.screenshot||t.isApp,x=u&&v&&void 0===s.fill?t.fill:s.fill,b=o.isOpaqueImage(n)||x,B=new T;if(v)e=!0===v?u?l.canvas.bounds:t.worldRenderBounds:v;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!==x){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?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 A="canvas"===n?L:yield L.export(n,s);d({data:A,width:L.pixelWidth,height:L.pixelHeight,renderBounds:e,trimBounds:a})})))):d({data:!1})}))))}};let Pn;const Fn=t.prototype,Yn=g.get("@leafer-ui/export");Fn.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)},Fn.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)}))}))},Fn.toDataURL=function(t,n){return e.origin.canvasToDataURL(this.view,t,n)},Fn.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(F,Wn),Object.assign(C,Tn),Object.assign(Y,wt),Object.assign(M,Jt),Object.assign(D,we),Object.assign(U,ke),Object.assign(I,In),X();export{it as Layouter,G as LeaferCanvas,ot as Renderer,q as Watcher,X 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 v,AnimateEvent as x,ResizeEvent as b,BoundsHelper as B,MatrixHelper as R,AlignHelper as k,ImageEvent as E,AroundHelper as S,PointHelper as L,Direction4 as W,TwoPointBoundsHelper as A,TaskProcessor as O,Matrix as T}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as M,ColorConvert as C,PaintGradient as D,Export as I,Group as P,TextConvert as F,Paint as Y,Effect as G}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:N}=o;function X(t,n){e.origin={createCanvas:(t,e)=>new OffscreenCanvas(t,e),canvasToDataURL:(t,e,n)=>new Promise(((i,s)=>{t.convertToBlob({type:N(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:N(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:V}=navigator;V.indexOf("Firefox")>-1?(e.conicGradientRotate90=!0,e.intWheelDeltaY=!0):V.indexOf("Safari")>-1&&-1===V.indexOf("Chrome")&&(e.fullImageShadow=!0),V.indexOf("Windows")>-1?(e.os="Windows",e.intWheelDeltaY=!0):V.indexOf("Mac")>-1?e.os="Mac":V.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:z,updateAllWorldOpacity:H}=u,{pushAllChildBranch:Q,pushAllParent:J}=f;const{worldBounds:Z}=_,$={x:0,y:0,width:1e5,height:1e5};class K{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,Z)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set($):this.afterBounds.setListWithFn(t,Z),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:tt,updateAllChange:et}=u,nt=g.get("Layouter");class it{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){nt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?nt.warn("layouting"):this.times>3?nt.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&&Q(t,e),J(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),J(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||z(i[t])}z(n)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&H(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)),it.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){tt(t,!0),t.isBranch?f.updateBounds(t):u.updateBounds(t),et(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new K([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new K(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 st=g.get("Renderer");class ot{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,st.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,st.error(t)}st.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return st.warn("rendering");if(this.times>3)return st.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 st.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(10+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){if(t.bigger||!t.samePixelRatio){const{width:e,height:n}=t.old;if(!new p(0,0,e,n).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new p(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||st.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 at(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 rt(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?ct(t,!0,e,n):lt(e,n);break;case"inside":dt("inside",t,s,e,n);break;case"outside":dt("outside",t,s,e,n)}}function dt(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?ct(e,!0,i,r):lt(i,r),r.blendMode="outside"===t?"destination-out":"destination-in",at(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 lt(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 ct(t,e,n,i){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&M.checkImage(n,i,s,!1)||s.style&&(i.strokeStyle=s.style,s.blendMode?(i.saveBlendMode(s.blendMode),e?lt(n,i):i.stroke(),i.restoreBlendMode()):e?lt(n,i):i.stroke())}Object.assign(i,{watcher:(t,e)=>new j(t,e),layouter:(t,e)=>new it(t,e),renderer:(t,e,n)=>new ot(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,i)=>{}}),e.layout=it.fullLayout;const{getSpread:ht,getOuterOf:ut,getByMove:ft,getIntersectData:pt}=B;let _t;function gt(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:C.string(a,r)};case"image":return M.image(n,t,e,i,!_t||!_t[e.url]);case"linear":return D.linearGradient(e,i);case"radial":return D.radialGradient(e,i);case"angular":return D.conicGradient(e,i);default:return void 0!==e.r?{type:"solid",style:C.string(e)}:void 0}}const wt={compute:function(t,e){const n=e.__,i=[];let s,o=n.__input[t];o instanceof Array||(o=[o]),_t=M.recycleImage(t,n);for(let n,s=0,a=o.length;s<a;s++)n=gt(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?at(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&&M.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?at(e,n):s?n.fill(s):n.fill(),n.restore()):i.blendMode?(n.saveBlendMode(i.blendMode),o?at(e,n):s?n.fill(s):n.fill(),n.restoreBlendMode()):o?at(e,n):s?n.fill(s):n.fill())},fillText:at,stroke:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)rt(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)rt(t,e,n);else switch(o){case"center":n.setStroke(void 0,s,i),ct(t,!1,e,n);break;case"inside":n.save(),n.setStroke(void 0,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),ct(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),ct(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:rt,drawTextStroke:lt,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=pt(i?ht(e.bounds,l===c?i*l:[i*c,i*l]):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,n),l*=u,c*=f),r=ut(s,a),o=ft(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 yt={};const{get:mt,rotateOfOuter:vt,translate:xt,scaleOfOuter:bt,scale:Bt,rotate:Rt}=R;function kt(t,e,n,i,s,o,a){const r=mt();xt(r,e.x+n,e.y+i),Bt(r,s,o),a&&vt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Et(t,e,n,i,s,o,a){const r=mt();xt(r,e.x+n,e.y+i),s&&Bt(r,s,o),a&&Rt(r,a),t.transform=r}function St(t,e,n,i,s,o,a,r,d,l){const c=mt();if(d)if("center"===l)vt(c,{x:n/2,y:i/2},d);else switch(Rt(c,d),d){case 90:xt(c,i,0);break;case 180:xt(c,n,i);break;case 270:xt(c,0,n)}yt.x=e.x+s,yt.y=e.y+o,xt(c,yt.x,yt.y),a&&bt(c,yt,a,r),t.transform=c}const{get:Lt,translate:Wt}=R,At=new p,Ot={};function Tt(t,e,n,i){const{blendMode:s}=n;s&&(t.blendMode=s),t.data=Mt(n,i,e)}function Mt(t,e,n){let{width:i,height:s}=n;t.padding&&(e=At.set(e).shrink(t.padding));const{opacity:o,mode:a,align:r,offset:d,scale:l,size:c,rotation:h,repeat:u}=t,f=e.width===i&&e.height===s,p={mode:a},_="center"!==r&&(h||0)%180==90,g=_?s:i,w=_?i:s;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)c?(y=("number"==typeof c?c:c.width)/i,m=("number"==typeof c?c:c.height)/s):l&&(y="number"==typeof l?l:l.x,m="number"==typeof l?l:l.y);else if(!f||h){const t=e.width/g,n=e.height/w;y=m="fit"===a?Math.min(t,n):Math.max(t,n),v+=(e.width-i*y)/2,x+=(e.height-s*m)/2}if(r){const t={x:v,y:x,width:g,height:w};y&&(t.width*=y,t.height*=m),k.toPoint(r,t,e,Ot,!0),v+=Ot.x,x+=Ot.y}switch(d&&(v+=d.x,x+=d.y),a){case"strench":f||(i=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||h)&&Et(p,e,v,x,y,m,h);break;case"repeat":(!f||y||h)&&St(p,e,i,s,v,x,y,m,h,r),u||(p.repeat="repeat");break;default:y&&kt(p,e,v,x,y,m,h)}return p.transform||(e.x||e.y)&&(p.transform=Lt(),Wt(p.transform,e.x,e.y)),y&&"strench"!==a&&(p.scaleX=y,p.scaleY=m),p.width=i,p.height=s,o&&(p.opacity=o),u&&(p.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),p}let Ct,Dt=new p;const{isSame:It}=B;function Pt(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||Tt(s,i,n,o),!0}function Ft(t,e){Ut(t,E.LOAD,e)}function Yt(t,e){Ut(t,E.LOADED,e)}function Gt(t,e,n){e.error=n,t.forceUpdate("surface"),Ut(t,E.ERROR,e)}function Ut(t,e,n){t.hasEvent(e)&&t.emitEvent(new E(e,n))}function Nt(t,e){const{leafer:n}=t;n&&n.viewReady&&(n.renderer.ignore=e)}const{get:Xt,scale:Vt,copy:jt}=R,{ceil:qt,abs:zt}=Math;function Ht(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=zt(s),o=zt(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=Xt(),jt(l,_),Vt(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=Xt(),_&&jt(l,_)),Vt(l,1/s,1/o));const m=t.getCanvas(qt(c)||1,qt(h)||1,p),v=t.getPattern(m,g||e.origin.noRepeat||"no-repeat",l,n);return n.style=v,n.patternId=a,!0}}function Qt(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 Ct&&n===Ct.paint&&It(i,Ct.boxBounds)?o=Ct.leafPaint:(o={type:n.type,image:r},Ct=r.use>1?{leafPaint:o,paint:n,boxBounds:Dt.set(i)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:n}),r.ready?(Pt(t,e,n,r,o,i),s&&(Ft(t,a),Yt(t,a))):r.error?s&&Gt(t,a,r.error):(Nt(t,!0),s&&Ft(t,a),o.loadId=r.load((()=>{Nt(t,!1),t.destroyed||(Pt(t,e,n,r,o,i)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Yt(t,a)),o.loadId=null}),(e=>{Nt(t,!1),Gt(t,a,e),o.loadId=null}))),o},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||I.running?Ht(t,i,n.pixelRatio):i.patternTask||(i.patternTask=v.patternTasker.add((()=>Qt(this,void 0,void 0,(function*(){i.patternTask=null,n.bounds.hit(t.__nowWorld)&&Ht(t,i,n.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},createPattern:Ht,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},createData:Tt,getPatternData:Mt,fillOrFitMode:kt,clipMode:Et,repeatMode:St},{toPoint:$t}=S,Kt={},te={};function ee(t,e,n){let i;for(let s=0,o=e.length;s<o;s++)i=e[s],"string"==typeof i?t.addColorStop(s/(o-1),C.string(i,n)):t.addColorStop(i.offset,C.string(i.color,n))}const{getAngle:ne,getDistance:ie}=L,{get:se,rotateOfOuter:oe,scaleOfOuter:ae}=R,{toPoint:re}=S,de={},le={};function ce(t,e,n,i,s){let o;const{width:a,height:r}=t;if(a!==r||i){const t=ne(e,n);o=se(),s?(ae(o,e,a/r*(i||1),1),oe(o,e,t+90)):(ae(o,e,1,a/r*(i||1)),oe(o,e,t))}return o}const{getDistance:he}=L,{toPoint:ue}=S,fe={},pe={};const _e={linearGradient:function(t,n){let{from:i,to:s,type:o,blendMode:a,opacity:r}=t;$t(i||"top",n,Kt),$t(s||"bottom",n,te);const d=e.canvas.createLinearGradient(Kt.x,Kt.y,te.x,te.y);ee(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;re(i||"center",n,de),re(s||"bottom",n,le);const l=e.canvas.createRadialGradient(de.x,de.y,0,de.x,de.y,ie(de,le));ee(l,t.stops,a);const c={type:o,style:l},h=ce(n,de,le,d,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(t,n){let{from:i,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;ue(i||"center",n,fe),ue(s||"bottom",n,pe);const l=e.conicGradientSupport?e.canvas.createConicGradient(0,fe.x,fe.y):e.canvas.createRadialGradient(fe.x,fe.y,0,fe.x,fe.y,he(fe,pe));ee(l,t.stops,a);const c={type:o,style:l},h=ce(n,fe,pe,d||1,e.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:ce},{copy:ge,toOffsetOutBounds:we}=B,ye={},me={};function ve(t,n,i,s){const{bounds:o,shapeBounds:a}=s;if(e.fullImageShadow){if(ge(ye,t.bounds),ye.x+=n.x-a.x,ye.y+=n.y-a.y,i){const{matrix:t}=s;ye.x-=(o.x+(t?t.e:0)+o.width/2)*(i-1),ye.y-=(o.y+(t?t.f:0)+o.height/2)*(i-1),ye.width*=i,ye.height*=i}t.copyWorld(s.canvas,t.bounds,ye)}else i&&(ge(ye,n),ye.x-=n.width/2*(i-1),ye.y-=n.height/2*(i-1),ye.width*=i,ye.height*=i),t.copyWorld(s.canvas,a,i?ye:n)}const{toOffsetOutBounds:xe}=B,be={};const Be={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;we(l,me),r.forEach(((r,_)=>{f.setWorldShadow(me.offsetX+r.x*h,me.offsetY+r.y*u,r.blur*h,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,ve(f,me,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;xe(l,be),r.forEach(((r,_)=>{f.save(),f.setWorldShadow(be.offsetX+r.x*h,be.offsetY+r.y*u,r.blur*h),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,ve(f,be,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:Re}=_;function ke(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),Se(t,e,n,1)}(t,n,i,s);break;case"opacity-path":Se(t,n,i,o);break;case"path":n.restore()}}function Ee(t){return t.getSameCanvas(!1,!0)}function Se(t,e,n,i){const s=t.__nowWorld;e.resetTransform(),e.opacity=i,e.copyWorld(n,s),n.recycle(s)}P.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&&(ke(this,a,t,s,i,o),i=s=null),"path"===n.__.mask?(n.opacity<1?(a="opacity-path",o=n.opacity,s||(s=Ee(t))):(a="path",t.save()),n.__clip(s||t,e)):(a="alpha",i||(i=Ee(t)),s||(s=Ee(t)),n.__render(i,e)),"clipping"!==n.__.mask)||Re(n,e)||n.__render(s||t,e);ke(this,a,t,s,i,o)};const Le=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",We=Le+"_#~&*+\\=|≮≯≈≠=…",Ae=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 Oe(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Te=Oe("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Me=Oe("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Ce=Oe(Le),De=Oe(We),Ie=Oe("- —/~|┆·");var Pe;!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"}(Pe||(Pe={}));const{Letter:Fe,Single:Ye,Before:Ge,After:Ue,Symbol:Ne,Break:Xe}=Pe;function Ve(t){return Te[t]?Fe:Ie[t]?Xe:Me[t]?Ge:Ce[t]?Ue:De[t]?Ne:Ae.test(t)?Ye:Fe}const je={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 qe(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}=je,{Letter:He,Single:Qe,Before:Je,After:Ze,Symbol:$e,Break:Ke}=Pe;let tn,en,nn,sn,on,an,rn,dn,ln,cn,hn,un,fn,pn,_n,gn,wn=[];function yn(t,e){ln&&!dn&&(dn=ln),tn.data.push({char:t,width:e}),nn+=e}function mn(){sn+=nn,tn.width=nn,en.words.push(tn),tn={data:[]},nn=0}function vn(){pn&&(_n.paraNumber++,en.paraStart=!0,pn=!1),ln&&(en.startCharSize=dn,en.endCharSize=ln,dn=0),en.width=sn,gn.width&&ze(en),wn.push(en),en={words:[]},sn=0}const xn=0,bn=1,Bn=2;const{top:Rn,right:kn,bottom:En,left:Sn}=W;function Ln(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 Wn={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[Sn],o-=l[kn]+l[Sn]),a&&(s=l[Rn],a-=l[Rn]+l[En]));const c={bounds:{x:i,y:s,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,n,i){_n=t,wn=t.rows,gn=t.bounds;const{__letterSpacing:s,paraIndent:o,textCase:a}=i,{canvas:r}=e,{width:d,height:l}=gn;if(d||l||s||"none"!==a){const t="none"!==i.textWrap,e="break"===i.textWrap;pn=!0,hn=null,dn=rn=ln=nn=sn=0,tn={data:[]},en={words:[]};for(let i=0,l=n.length;i<l;i++)an=n[i],"\n"===an?(nn&&mn(),en.paraEnd=!0,vn(),pn=!0):(cn=Ve(an),cn===He&&"none"!==a&&(an=qe(an,a,!nn)),rn=r.measureText(an).width,s&&(s<0&&(ln=rn),rn+=s),un=cn===Qe&&(hn===Qe||hn===He)||hn===Qe&&cn!==Ze,fn=!(cn!==Je&&cn!==Qe||hn!==$e&&hn!==Ze),on=pn&&o?d-o:d,t&&d&&sn+nn+rn>on&&(e?(nn&&mn(),vn()):(fn||(fn=cn===He&&hn==Ze),un||fn||cn===Ke||cn===Je||cn===Qe||nn+rn>on?(nn&&mn(),vn()):vn()))," "===an&&!0!==pn&&sn+nn===0||(cn===Ke?(" "===an&&nn&&mn(),yn(an,rn),mn()):un||fn?(nn&&mn(),yn(an,rn)):yn(an,rn)),hn=cn);nn&&mn(),sn&&vn(),wn.length>0&&(wn[wn.length-1].paraEnd=!0)}else n.split("\n").forEach((t=>{_n.paraNumber++,wn.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":Ln(e,"x",t[Sn]);break;case"right":Ln(e,"x",-t[kn])}if(!s)switch(n.verticalAlign){case"top":Ln(e,"y",t[Rn]);break;case"bottom":Ln(e,"y",-t[En])}}(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++){if(h=n[o],h.x=p,h.width<g||h.width>g&&!r)switch(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?xn:l>.01?bn:Bn,t.isOverflow&&!r&&(t.textMode=!0),h===Bn?(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===bn?(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),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,n,i){return t.forEach((t=>{(i||" "!==t.char)&&(t.x=e,n.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(c,n,o),c.overflow&&function(t,n){const{rows:i,overflow:s}=t;let{textOverflow:o}=n;if(i.splice(s),o&&"show"!==o){let t,a;"hide"===o?o="":"ellipsis"===o&&(o="...");const r=o?e.canvas.measureText(o).width:0,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 An={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:On,addPoint:Tn,toBounds:Mn}=A;const Cn={export(t,n,s){return this.running=!0,function(t){Dn||(Dn=new O);return new Promise((e=>{Dn.add((()=>Qt(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},{toURL:l}=e,{download:c}=e.origin,h=o.fileType(n);if("json"===n)return d({data:t.toJSON()});if("json"===h)return c(l(JSON.stringify(t.toJSON()),"text"),n),d({data:!0});if("svg"===n)return d({data:t.toSVG()});if("svg"===h)return c(l(t.toSVG(),"svg"),n),d({data:!0});const{leafer:u}=t;u?u.waitViewCompleted((()=>Qt(this,void 0,void 0,(function*(){s=o.getExportOptions(s);let e,a,r=1,l=1;const{worldTransform:c,isLeafer:h,isFrame:f}=t,{slice:_,trim:g,onCanvas:w}=s;let y=s.scale||1,m=s.pixelRatio||1;t.isApp&&(y*=m,m=t.app.pixelRatio);const v=s.screenshot||t.isApp,x=h&&v&&void 0===s.fill?t.fill:s.fill,b=o.isOpaqueImage(n)||x,B=new T;if(v)e=!0===v?h?u.canvas.bounds:t.worldRenderBounds:v;else{let n=s.relative||(h?"inner":"local");switch(r=c.scaleX,l=c.scaleY,n){case"inner":B.set(c);break;case"local":B.set(c).divide(t.localTransform),r/=t.scaleX,l/=t.scaleY;break;case"world":r=1,l=1;break;case"page":n=t.leafer;default:B.set(c).divide(t.getTransform(n));const e=n.worldTransform;r/=r/e.scaleX,l/=l/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 W={matrix:B.scale(1/y).invert().translate(-R,-k).withScale(1/r*y,1/l*y)};if(_&&(t=u,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?Tn(a,s,o):On(a={},s,o)),r++;const d=new p;return Mn(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 A="canvas"===n?L:yield L.export(n,s);d({data:A,width:L.pixelWidth,height:L.pixelHeight,renderBounds:e,trimBounds:a})})))):d({data:!1})}))))}};let Dn;const In=t.prototype,Pn=g.get("@leafer-ui/export");In.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)},In.toBlob=function(t,n){return new Promise((i=>{e.origin.canvasToBolb(this.view,t,n).then((t=>{i(t)})).catch((t=>{Pn.error(t),i(null)}))}))},In.toDataURL=function(t,n){return e.origin.canvasToDataURL(this.view,t,n)},In.saveAs=function(t,n){return new Promise((i=>{e.origin.canvasSaveAs(this.view,t,n).then((()=>{i(!0)})).catch((t=>{Pn.error(t),i(!1)}))}))},Object.assign(F,Wn),Object.assign(C,An),Object.assign(Y,wt),Object.assign(M,Zt),Object.assign(D,_e),Object.assign(G,Be),Object.assign(I,Cn),X();export{it as Layouter,U as LeaferCanvas,ot as Renderer,j as Watcher,X as useCanvas};
|