@leafer-draw/miniapp 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/miniapp.esm.js +64 -47
- package/dist/miniapp.esm.min.js +1 -1
- package/dist/miniapp.module.js +122 -75
- package/dist/miniapp.module.min.js +1 -1
- package/package.json +7 -7
package/dist/miniapp.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LeaferCanvasBase, Platform, canvasPatch, DataHelper, canvasSizeAttrs, ResizeEvent, Creator, LeaferImage, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, BoundsHelper, MatrixHelper, ImageEvent, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
|
|
1
|
+
import { LeaferCanvasBase, Platform, canvasPatch, DataHelper, canvasSizeAttrs, ResizeEvent, Creator, LeaferImage, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, 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';
|
|
@@ -1091,79 +1091,75 @@ const PaintModule = {
|
|
|
1091
1091
|
|
|
1092
1092
|
let origin = {};
|
|
1093
1093
|
const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
|
|
1094
|
-
function fillOrFitMode(data,
|
|
1094
|
+
function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
1095
1095
|
const transform = get$4();
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
const sh = box.height / (swap ? width : height);
|
|
1099
|
-
const scale = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
|
|
1100
|
-
const x = box.x + (box.width - width * scale) / 2;
|
|
1101
|
-
const y = box.y + (box.height - height * scale) / 2;
|
|
1102
|
-
translate$1(transform, x, y);
|
|
1103
|
-
scaleHelper(transform, scale);
|
|
1096
|
+
translate$1(transform, box.x + x, box.y + y);
|
|
1097
|
+
scaleHelper(transform, scaleX, scaleY);
|
|
1104
1098
|
if (rotation)
|
|
1105
1099
|
rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
|
|
1106
|
-
data.scaleX = data.scaleY = scale;
|
|
1107
1100
|
data.transform = transform;
|
|
1108
1101
|
}
|
|
1109
1102
|
function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
1110
1103
|
const transform = get$4();
|
|
1111
|
-
translate$1(transform, box.x, box.y);
|
|
1112
|
-
if (
|
|
1113
|
-
translate$1(transform, x, y);
|
|
1114
|
-
if (scaleX) {
|
|
1104
|
+
translate$1(transform, box.x + x, box.y + y);
|
|
1105
|
+
if (scaleX)
|
|
1115
1106
|
scaleHelper(transform, scaleX, scaleY);
|
|
1116
|
-
data.scaleX = transform.a;
|
|
1117
|
-
data.scaleY = transform.d;
|
|
1118
|
-
}
|
|
1119
1107
|
if (rotation)
|
|
1120
1108
|
rotate(transform, rotation);
|
|
1121
1109
|
data.transform = transform;
|
|
1122
1110
|
}
|
|
1123
|
-
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation) {
|
|
1111
|
+
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around) {
|
|
1124
1112
|
const transform = get$4();
|
|
1125
1113
|
if (rotation) {
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1114
|
+
if (around === 'center') {
|
|
1115
|
+
rotateOfOuter$2(transform, { x: width / 2, y: height / 2 }, rotation);
|
|
1116
|
+
}
|
|
1117
|
+
else {
|
|
1118
|
+
rotate(transform, rotation);
|
|
1119
|
+
switch (rotation) {
|
|
1120
|
+
case 90:
|
|
1121
|
+
translate$1(transform, height, 0);
|
|
1122
|
+
break;
|
|
1123
|
+
case 180:
|
|
1124
|
+
translate$1(transform, width, height);
|
|
1125
|
+
break;
|
|
1126
|
+
case 270:
|
|
1127
|
+
translate$1(transform, 0, width);
|
|
1128
|
+
break;
|
|
1129
|
+
}
|
|
1137
1130
|
}
|
|
1138
1131
|
}
|
|
1139
|
-
origin.x = box.x;
|
|
1140
|
-
origin.y = box.y;
|
|
1141
|
-
if (x || y)
|
|
1142
|
-
origin.x += x, origin.y += y;
|
|
1132
|
+
origin.x = box.x + x;
|
|
1133
|
+
origin.y = box.y + y;
|
|
1143
1134
|
translate$1(transform, origin.x, origin.y);
|
|
1144
|
-
if (scaleX)
|
|
1135
|
+
if (scaleX)
|
|
1145
1136
|
scaleOfOuter$2(transform, origin, scaleX, scaleY);
|
|
1146
|
-
data.scaleX = scaleX;
|
|
1147
|
-
data.scaleY = scaleY;
|
|
1148
|
-
}
|
|
1149
1137
|
data.transform = transform;
|
|
1150
1138
|
}
|
|
1151
1139
|
|
|
1152
1140
|
const { get: get$3, translate } = MatrixHelper;
|
|
1153
1141
|
const tempBox = new Bounds();
|
|
1142
|
+
const tempPoint = {};
|
|
1154
1143
|
function createData(leafPaint, image, paint, box) {
|
|
1155
1144
|
let { width, height } = image;
|
|
1156
1145
|
if (paint.padding)
|
|
1157
1146
|
box = tempBox.set(box).shrink(paint.padding);
|
|
1158
|
-
const { opacity, mode, offset, scale, size, rotation, blendMode, repeat } = paint;
|
|
1147
|
+
const { opacity, mode, around, offset, scale, size, rotation, blendMode, repeat } = paint;
|
|
1159
1148
|
const sameBox = box.width === width && box.height === height;
|
|
1160
1149
|
if (blendMode)
|
|
1161
1150
|
leafPaint.blendMode = blendMode;
|
|
1162
1151
|
const data = leafPaint.data = { mode };
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
if (
|
|
1152
|
+
const swapSize = around !== 'center' && (rotation || 0) % 180 === 90;
|
|
1153
|
+
const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height;
|
|
1154
|
+
let x = 0, y = 0, scaleX, scaleY;
|
|
1155
|
+
if (!mode || mode === 'cover' || mode === 'fit') {
|
|
1156
|
+
if (!sameBox || rotation) {
|
|
1157
|
+
const sw = box.width / swapWidth, sh = box.height / swapHeight;
|
|
1158
|
+
scaleX = scaleY = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh);
|
|
1159
|
+
x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
else if (size) {
|
|
1167
1163
|
scaleX = (typeof size === 'number' ? size : size.width) / width;
|
|
1168
1164
|
scaleY = (typeof size === 'number' ? size : size.height) / height;
|
|
1169
1165
|
}
|
|
@@ -1171,26 +1167,36 @@ function createData(leafPaint, image, paint, box) {
|
|
|
1171
1167
|
scaleX = typeof scale === 'number' ? scale : scale.x;
|
|
1172
1168
|
scaleY = typeof scale === 'number' ? scale : scale.y;
|
|
1173
1169
|
}
|
|
1170
|
+
if (around) {
|
|
1171
|
+
const imageBounds = { x, y, width: swapWidth, height: swapHeight };
|
|
1172
|
+
if (scaleX)
|
|
1173
|
+
imageBounds.width *= scaleX, imageBounds.height *= scaleY;
|
|
1174
|
+
AroundHelper.toPoint(around, box, tempPoint, true, imageBounds);
|
|
1175
|
+
x += tempPoint.x, y += tempPoint.y;
|
|
1176
|
+
}
|
|
1177
|
+
if (offset)
|
|
1178
|
+
x += offset.x, y += offset.y;
|
|
1174
1179
|
switch (mode) {
|
|
1175
1180
|
case 'strench':
|
|
1176
1181
|
if (!sameBox)
|
|
1177
1182
|
width = box.width, height = box.height;
|
|
1178
1183
|
break;
|
|
1184
|
+
case 'normal':
|
|
1179
1185
|
case 'clip':
|
|
1180
|
-
if (
|
|
1186
|
+
if (x || y || scaleX || rotation)
|
|
1181
1187
|
clipMode(data, box, x, y, scaleX, scaleY, rotation);
|
|
1182
1188
|
break;
|
|
1183
1189
|
case 'repeat':
|
|
1184
1190
|
if (!sameBox || scaleX || rotation)
|
|
1185
|
-
repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation);
|
|
1191
|
+
repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, around);
|
|
1186
1192
|
if (!repeat)
|
|
1187
1193
|
data.repeat = 'repeat';
|
|
1188
1194
|
break;
|
|
1189
1195
|
case 'fit':
|
|
1190
1196
|
case 'cover':
|
|
1191
1197
|
default:
|
|
1192
|
-
if (
|
|
1193
|
-
fillOrFitMode(data,
|
|
1198
|
+
if (scaleX)
|
|
1199
|
+
fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation);
|
|
1194
1200
|
}
|
|
1195
1201
|
if (!data.transform) {
|
|
1196
1202
|
if (box.x || box.y) {
|
|
@@ -1198,6 +1204,10 @@ function createData(leafPaint, image, paint, box) {
|
|
|
1198
1204
|
translate(data.transform, box.x, box.y);
|
|
1199
1205
|
}
|
|
1200
1206
|
}
|
|
1207
|
+
if (scaleX && mode !== 'strench') {
|
|
1208
|
+
data.scaleX = scaleX;
|
|
1209
|
+
data.scaleY = scaleY;
|
|
1210
|
+
}
|
|
1201
1211
|
data.width = width;
|
|
1202
1212
|
data.height = height;
|
|
1203
1213
|
if (opacity)
|
|
@@ -2285,6 +2295,13 @@ const ExportModule = {
|
|
|
2285
2295
|
resolve();
|
|
2286
2296
|
this.running = false;
|
|
2287
2297
|
};
|
|
2298
|
+
if (filename === 'json') {
|
|
2299
|
+
return over({ data: leaf.toJSON() });
|
|
2300
|
+
}
|
|
2301
|
+
else if (FileHelper.fileType(filename) === 'json') {
|
|
2302
|
+
Platform.origin.download('data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(leaf.toJSON())), filename);
|
|
2303
|
+
return over({ data: true });
|
|
2304
|
+
}
|
|
2288
2305
|
const { leafer } = leaf;
|
|
2289
2306
|
if (leafer) {
|
|
2290
2307
|
leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
|
package/dist/miniapp.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LeaferCanvasBase as t,Platform as e,canvasPatch as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,Creator as a,LeaferImage as r,FileHelper as d,LeafList as l,RenderEvent as h,ChildEvent as c,WatchEvent as u,PropertyEvent as f,LeafHelper as p,BranchHelper as _,Bounds as g,LeafBoundsHelper as w,Debug as y,LeafLevelList as m,LayoutEvent as v,Run as x,ImageManager as b,AnimateEvent as B,BoundsHelper as R,MatrixHelper as k,ImageEvent as S,PointHelper as E,Direction4 as L,TwoPointBoundsHelper as A,TaskProcessor as W,Matrix as T}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as O,ColorConvert as M,PaintGradient as C,Export as P,Group as I,TextConvert as D,Paint as F,Effect as z}from"@leafer-ui/draw";export*from"@leafer-ui/draw";class Y extends t{get allowBackgroundColor(){return!1}init(){let{view:t}=this.config;t?("string"==typeof t?("#"!==t[0]&&(t="#"+t),this.viewSelect=e.miniapp.select(t)):t.fields?this.viewSelect=t:this.initView(t),this.viewSelect&&e.miniapp.getSizeView(this.viewSelect).then((t=>{this.initView(t)}))):this.initView()}initView(t){t?this.view=t.view||t:(t={},this.__createView()),this.__createContext();const{width:e,height:s,pixelRatio:n}=this.config,o={width:e||t.width,height:s||t.height,pixelRatio:n};this.resize(o),this.context.roundRect&&(this.roundRect=function(t,e,i,s,n){this.context.roundRect(t,e,i,s,"number"==typeof n?[n]:n)}),i(this.context.__proto__)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(t){this.viewSelect&&e.miniapp.getBounds(this.viewSelect).then((e=>{this.clientBounds=e,t&&t()}))}startAutoLayout(t,i){this.resizeListener=i,this.checkSize=this.checkSize.bind(this),e.miniapp.onWindowResize(this.checkSize)}checkSize(){this.viewSelect&&setTimeout((()=>{this.updateClientBounds((()=>{const{width:t,height:e}=this.clientBounds,{pixelRatio:i}=this,a={width:t,height:e,pixelRatio:i};if(!this.isSameSize(a)){const t={};s.copyAttrs(t,this,n),this.resize(a),void 0!==this.width&&this.resizeListener(new o(a,t))}}))}),500)}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,e.miniapp.offWindowResize(this.checkSize)}}const{mineType:U,fileType:V}=d;function X(t,i){e.origin||(e.origin={createCanvas:(t,e,s)=>i.createOffscreenCanvas({type:"2d",width:t,height:e}),canvasToDataURL:(t,e,i)=>t.toDataURL(U(e),i),canvasToBolb:(t,e,i)=>t.toBuffer(e,{quality:i}),canvasSaveAs:(t,i,s)=>{let n=t.toDataURL(U(V(i)),s);return n=n.substring(n.indexOf("64,")+3),e.origin.download(n,i)},download:(t,s)=>new Promise(((n,o)=>{let a;s.includes("/")||(s=`${i.env.USER_DATA_PATH}/`+s,a=!0);const r=i.getFileSystemManager();r.writeFile({filePath:s,data:t,encoding:"base64",success(){a&&e.miniapp.saveToAlbum(s).then((()=>{r.unlink({filePath:s})})),n()},fail(t){o(t)}})})),loadImage:t=>new Promise(((i,s)=>{const n=e.canvas.view.createImage();n.onload=()=>{i(n)},n.onerror=t=>{s(t)},n.src=t})),noRepeat:"repeat-x"},e.miniapp={select:t=>i.createSelectorQuery().select(t),getBounds:t=>new Promise((e=>{t.boundingClientRect().exec((t=>{const i=t[1];e({x:i.top,y:i.left,width:i.width,height:i.height})}))})),getSizeView:t=>new Promise((e=>{t.fields({node:!0,size:!0}).exec((t=>{const i=t[0];e({view:i.node,width:i.width,height:i.height})}))})),saveToAlbum:t=>new Promise((e=>{i.getSetting({success:s=>{s.authSetting["scope.writePhotosAlbum"]?i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}}):i.authorize({scope:"scope.writePhotosAlbum",success:()=>{i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}})},fail:()=>{}})}})})),onWindowResize(t){i.onWindowResize(t)},offWindowResize(t){i.offWindowResize(t)}},e.event={stopDefault(t){},stopNow(t){},stop(t){}},e.canvas=a.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient)}Object.assign(a,{canvas:(t,e)=>new Y(t,e),image:t=>new r(t)}),e.name="miniapp",e.requestRender=function(t){e.canvas.view.requestAnimationFrame(t)},e.devicePixelRatio=wx.getSystemInfoSync().pixelRatio;class G{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new l;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 l,this.target=t,e&&(this.config=s.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(h.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===c.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new u(u.DATA,{updatedList:this.updatedList})),this.__updatedList=new l,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(f.CHANGE,this.__onAttrChange,this),t.on_([c.ADD,c.REMOVE],this.__onChildEvent,this),t.on_(u.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:N,updateBounds:j,updateAllWorldOpacity:q}=p,{pushAllChildBranch:H,pushAllParent:Q}=_;const{worldBounds:Z}=w,$={x:0,y:0,width:1e5,height:1e5};class J{constructor(t){this.updatedBounds=new g,this.beforeBounds=new g,this.afterBounds=new g,t instanceof Array&&(t=new l(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:K,updateAllChange:tt}=p,et=y.get("Layouter");class it{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new m,this.target=t,e&&(this.config=s.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(v.START),this.layoutOnce(),t.emitEvent(new v(v.END,this.layoutedBlocks,this.times))}catch(t){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(u.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=x.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:o,AFTER:a}=v,r=this.getBlocks(s);r.forEach((t=>t.setBefore())),i.emitEvent(new v(n,r,this.times)),this.extraBlock=null,s.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(N(t,!0),e.add(t),t.isBranch&&H(t,e),Q(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),Q(t,e)))}))}(s,this.__levelList),function(t){let e,i,s;t.sort(!0),t.levels.forEach((n=>{e=t.levelMap[n];for(let t=0,n=e.length;t<n;t++){if(i=e[t],i.isBranch&&i.__tempNumber){s=i.children;for(let t=0,e=s.length;t<e;t++)s[t].isBranch||j(s[t])}j(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&q(t),t.__updateChange()}))}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new v(o,r,this.times)),i.emitEvent(new v(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,x.end(e)}fullLayout(){const t=x.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=v,o=this.getBlocks(new l(e));e.emitEvent(new v(i,o,this.times)),it.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new v(s,o,this.times)),e.emitEvent(new v(n,o,this.times)),this.addBlocks(o),x.end(t)}static fullLayout(t){K(t,!0),t.isBranch?_.updateBounds(t):p.updateBounds(t),tt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new J([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new J(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(v.REQUEST,this.layout,this),t.on_(v.AGAIN,this.layoutAgain,this),t.on_(u.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const st=y.get("Renderer");class nt{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=s.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(v.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new g,st.log(e.innerName,"---\x3e");try{this.emitRender(h.START),this.renderOnce(t),this.emitRender(h.END,this.totalBounds),b.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 g,this.renderOptions={},t)this.emitRender(h.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(h.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(h.RENDER,this.renderBounds,this.renderOptions),this.emitRender(h.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=x.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=t.includes(this.target.__world),o=new g(s);i.save(),n&&!y.showRepaint?i.clear():(s.spread(1+1/this.canvas.pixelRatio).ceil(),i.clearWorld(s,!0),i.clipWorld(s,!0)),this.__render(s,n,o),i.restore(),x.end(e)}fullRender(){const t=x.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),x.end(t)}__render(t,e,i){const s=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),y.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,s),this.renderBounds=i||t,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),y.showHitView&&this.renderHitView(s),y.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender()}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new g;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(B.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(h.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:i}=t.old;new g(0,0,e,i).includes(this.target.__world)&&!this.needFill&&t.samePixelRatio||(this.addBlock(this.canvas.bounds),this.target.forceUpdate("surface"))}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||st.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new h(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(h.REQUEST,this.update,this),t.on_(v.END,this.__onLayoutEnd,this),t.on_(h.AGAIN,this.renderAgain,this),t.on_(o.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}function ot(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),n&&e.fillRect(i.x,i.y+n,i.width,o)}function at(t,e,i){const{strokeAlign:s}=e.__,n="string"!=typeof t;switch(s){case"center":i.setStroke(n?void 0:t,e.__.strokeWidth,e.__),n?lt(t,!0,e,i):dt(e,i);break;case"inside":rt("inside",t,n,e,i);break;case"outside":rt("outside",t,n,e,i)}}function rt(t,e,i,s,n){const{__strokeWidth:o,__font:a}=s.__,r=n.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,s.__),r.font=a,i?lt(e,!0,s,r):dt(s,r),r.blendMode="outside"===t?"destination-out":"destination-in",ot(s,r),r.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(r,s.__nowWorld):n.copyWorldToInner(r,s.__nowWorld,s.__layout.renderBounds),r.recycle(s.__nowWorld)}function dt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),n&&e.strokeRect(i.x,i.y+n,i.width,o)}function lt(t,e,i,s){let n;for(let o=0,a=t.length;o<a;o++)n=t[o],n.image&&O.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?dt(i,s):s.stroke(),s.restoreBlendMode()):e?dt(i,s):s.stroke())}Object.assign(a,{watcher:(t,e)=>new G(t,e),layouter:(t,e)=>new it(t,e),renderer:(t,e,i)=>new nt(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,s)=>{}}),e.layout=it.fullLayout;const{getSpread:ht,getOuterOf:ct,getByMove:ut,getIntersectData:ft}=R;let pt;function _t(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:s}=i.__layout;switch(e.type){case"solid":let{type:n,blendMode:o,color:a,opacity:r}=e;return{type:n,blendMode:o,style:M.string(a,r)};case"image":return O.image(i,t,e,s,!pt||!pt[e.url]);case"linear":return C.linearGradient(e,s);case"radial":return C.radialGradient(e,s);case"angular":return C.conicGradient(e,s);default:return e.r?{type:"solid",style:M.string(e)}:void 0}}const gt={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),pt=O.recycleImage(t,i);for(let i,n=0,a=o.length;n<a;n++)i=_t(t,o[n],e),i&&s.push(i);i["_"+t]=s.length?s:void 0,s.length&&s[0].image&&(n=s[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=n:i.__pixelStroke=n},fill:function(t,e,i){i.fillStyle=t,e.__.__font?ot(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)s=t[a],s.image&&O.checkImage(e,i,s,!o)||s.style&&(i.fillStyle=s.style,s.transform?(i.save(),i.transform(s.transform),s.blendMode&&(i.blendMode=s.blendMode),o?ot(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?ot(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?ot(e,i):n?i.fill(n):i.fill())},fillText:ot,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:a}=s;if(n)if(a)at(t,e,i);else switch(o){case"center":i.setStroke(t,n,s),i.stroke();break;case"inside":i.save(),i.setStroke(t,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*n,s),e.__drawRenderPath(o),o.stroke(),s.windingRule?o.clip(s.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:a}=s;if(n)if(a)at(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),lt(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),lt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*n,s),lt(t,!1,e,a),s.windingRule?a.clip(s.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:at,drawTextStroke:dt,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:h}=n;if(l<0&&(l=-l),h<0&&(h=-h),e.bounds.includes(n))d=s,o=r=n;else{const{renderShapeSpread:s}=t.__layout,c=ft(s?ht(e.bounds,s*l,s*h):e.bounds,n);a=e.bounds.getFitMatrix(c);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,h*=f),r=ct(n,a),o=ut(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(s,i),{canvas:s,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:h}}};let wt={};const{get:yt,rotateOfOuter:mt,translate:vt,scaleOfOuter:xt,scale:bt,rotate:Bt}=k;function Rt(t,e,i,s,n,o){const a=yt(),r=o&&180!==o,d=i.width/(r?n:s),l=i.height/(r?s:n),h="fit"===e?Math.min(d,l):Math.max(d,l),c=i.x+(i.width-s*h)/2,u=i.y+(i.height-n*h)/2;vt(a,c,u),bt(a,h),o&&mt(a,{x:i.x+i.width/2,y:i.y+i.height/2},o),t.scaleX=t.scaleY=h,t.transform=a}function kt(t,e,i,s,n,o,a){const r=yt();vt(r,e.x,e.y),(i||s)&&vt(r,i,s),n&&(bt(r,n,o),t.scaleX=r.a,t.scaleY=r.d),a&&Bt(r,a),t.transform=r}function St(t,e,i,s,n,o,a,r,d){const l=yt();if(d)switch(Bt(l,d),d){case 90:vt(l,s,0);break;case 180:vt(l,i,s);break;case 270:vt(l,0,i)}wt.x=e.x,wt.y=e.y,(n||o)&&(wt.x+=n,wt.y+=o),vt(l,wt.x,wt.y),a&&(xt(l,wt,a,r),t.scaleX=a,t.scaleY=r),t.transform=l}const{get:Et,translate:Lt}=k,At=new g;function Wt(t,e,i,s){let{width:n,height:o}=e;i.padding&&(s=At.set(s).shrink(i.padding));const{opacity:a,mode:r,offset:d,scale:l,size:h,rotation:c,blendMode:u,repeat:f}=i,p=s.width===n&&s.height===o;u&&(t.blendMode=u);const _=t.data={mode:r};let g,w,y,m;switch(d&&(g=d.x,w=d.y),h?(y=("number"==typeof h?h:h.width)/n,m=("number"==typeof h?h:h.height)/o):l&&(y="number"==typeof l?l:l.x,m="number"==typeof l?l:l.y),r){case"strench":p||(n=s.width,o=s.height);break;case"clip":(d||y||c)&&kt(_,s,g,w,y,m,c);break;case"repeat":(!p||y||c)&&St(_,s,n,o,g,w,y,m,c),f||(_.repeat="repeat");break;default:p&&!c||Rt(_,r,s,n,o,c)}_.transform||(s.x||s.y)&&(_.transform=Et(),Lt(_.transform,s.x,s.y)),_.width=n,_.height=o,a&&(_.opacity=a),f&&(_.repeat="string"==typeof f?"x"===f?"repeat-x":"repeat-y":"repeat")}let Tt,Ot=new g;const{isSame:Mt}=R;function Ct(t,e,i,s,n,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=s.width/e.pixelRatio,e.__naturalHeight=s.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return n.data||Wt(n,s,i,o),!0}function Pt(t,e){Ft(t,S.LOAD,e)}function It(t,e){Ft(t,S.LOADED,e)}function Dt(t,e,i){e.error=i,t.forceUpdate("surface"),Ft(t,S.ERROR,e)}function Ft(t,e,i){t.hasEvent(e)&&t.emitEvent(new S(e,i))}function zt(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:Yt,scale:Ut,copy:Vt}=k,{ceil:Xt,abs:Gt}=Math;function Nt(t,i,s){let{scaleX:n,scaleY:o}=b.patternLocked?t.__world:t.__nowWorld;const a=n+"-"+o;if(i.patternId===a||t.destroyed)return!1;{n=Gt(n),o=Gt(o);const{image:t,data:r}=i;let d,l,{width:h,height:c,scaleX:u,scaleY:f,opacity:p,transform:_,repeat:g}=r;u&&(l=Yt(),Vt(l,_),Ut(l,1/u,1/f),n*=u,o*=f),n*=s,o*=s,h*=n,c*=o;const w=h*c;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&&(n/=d,o/=d,h/=d,c/=d),u&&(n/=u,o/=f),(_||1!==n||1!==o)&&(l||(l=Yt(),_&&Vt(l,_)),Ut(l,1/n,1/o));const m=t.getCanvas(Xt(h)||1,Xt(c)||1,p),v=t.getPattern(m,g||e.origin.noRepeat||"no-repeat",l,i);return i.style=v,i.patternId=a,!0}}function jt(t,e,i,s){return new(i||(i=Promise))((function(n,o){function a(t){try{d(s.next(t))}catch(t){o(t)}}function r(t){try{d(s.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}d((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:qt}=Math;const Ht={image:function(t,e,i,s,n){let o,a;const r=b.get(i);return Tt&&i===Tt.paint&&Mt(s,Tt.boxBounds)?o=Tt.leafPaint:(o={type:i.type,image:r},Tt=r.use>1?{leafPaint:o,paint:i,boxBounds:Ot.set(s)}:null),(n||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Ct(t,e,i,r,o,s),n&&(Pt(t,a),It(t,a))):r.error?n&&Dt(t,a,r.error):(zt(t,!0),n&&Pt(t,a),o.loadId=r.load((()=>{zt(t,!1),t.destroyed||(Ct(t,e,i,r,o,s)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),It(t,a)),o.loadId=null}),(e=>{zt(t,!1),Dt(t,a,e),o.loadId=null}))),o},createData:Wt,fillOrFitMode:Rt,clipMode:kt,repeatMode:St,createPattern:Nt,checkImage:function(t,i,s,n){const{scaleX:o,scaleY:a}=b.patternLocked?t.__world:t.__nowWorld;if(s.data&&s.patternId!==o+"-"+a){const{data:r}=s;if(n)if(r.repeat)n=!1;else{let{width:t,height:s}=r;t*=qt(o)*i.pixelRatio,s*=qt(a)*i.pixelRatio,r.scaleX&&(t*=r.scaleX,s*=r.scaleY),n=t*s>e.image.maxCacheSize}return n?(i.save(),i.clip(),s.blendMode&&(i.blendMode=s.blendMode),r.opacity&&(i.opacity*=r.opacity),r.transform&&i.transform(r.transform),i.drawImage(s.image.view,0,0,r.width,r.height),i.restore(),!0):(!s.style||P.running?Nt(t,s,i.pixelRatio):s.patternTask||(s.patternTask=b.patternTasker.add((()=>jt(this,void 0,void 0,(function*(){s.patternTask=null,i.bounds.hit(t.__nowWorld)&&Nt(t,s,i.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let s,n,o,a;for(let r=0,d=i.length;r<d;r++)s=i[r].image,a=s&&s.url,a&&(n||(n={}),n[a]=!0,b.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[r].loadId,!o.some((t=>t.url===a)))));return n}return null}},Qt={x:.5,y:0},Zt={x:.5,y:1};function $t(t,e,i){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],t.addColorStop(s.offset,M.string(s.color,i))}const{set:Jt,getAngle:Kt,getDistance:te}=E,{get:ee,rotateOfOuter:ie,scaleOfOuter:se}=k,ne={x:.5,y:.5},oe={x:.5,y:1},ae={},re={};const{set:de,getAngle:le,getDistance:he}=E,{get:ce,rotateOfOuter:ue,scaleOfOuter:fe}=k,pe={x:.5,y:.5},_e={x:.5,y:1},ge={},we={};const ye={linearGradient:function(t,i){let{from:s,to:n,type:o,blendMode:a,opacity:r}=t;s||(s=Qt),n||(n=Zt);const d=e.canvas.createLinearGradient(i.x+s.x*i.width,i.y+s.y*i.height,i.x+n.x*i.width,i.y+n.y*i.height);$t(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,i){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:d}=t;s||(s=ne),n||(n=oe);const{x:l,y:h,width:c,height:u}=i;let f;Jt(ae,l+s.x*c,h+s.y*u),Jt(re,l+n.x*c,h+n.y*u),(c!==u||d)&&(f=ee(),se(f,ae,c/u*(d||1),1),ie(f,ae,Kt(ae,re)+90));const p=e.canvas.createRadialGradient(ae.x,ae.y,0,ae.x,ae.y,te(ae,re));$t(p,t.stops,a);const _={type:o,style:p,transform:f};return r&&(_.blendMode=r),_},conicGradient:function(t,i){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:d}=t;s||(s=pe),n||(n=_e);const{x:l,y:h,width:c,height:u}=i;de(ge,l+s.x*c,h+s.y*u),de(we,l+n.x*c,h+n.y*u);const f=ce(),p=le(ge,we);e.conicGradientRotate90?(fe(f,ge,c/u*(d||1),1),ue(f,ge,p+90)):(fe(f,ge,1,c/u*(d||1)),ue(f,ge,p));const _=e.conicGradientSupport?e.canvas.createConicGradient(0,ge.x,ge.y):e.canvas.createRadialGradient(ge.x,ge.y,0,ge.x,ge.y,he(ge,we));$t(_,t.stops,a);const g={type:o,style:_,transform:f};return r&&(g.blendMode=r),g}},{copy:me,toOffsetOutBounds:ve}=R,xe={},be={};function Be(t,i,s,n){const{bounds:o,shapeBounds:a}=n;if(e.fullImageShadow){if(me(xe,t.bounds),xe.x+=i.x-a.x,xe.y+=i.y-a.y,s){const{matrix:t}=n;xe.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),xe.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),xe.width*=s,xe.height*=s}t.copyWorld(n.canvas,t.bounds,xe)}else s&&(me(xe,i),xe.x-=i.width/2*(s-1),xe.y-=i.height/2*(s-1),xe.width*=s,xe.height*=s),t.copyWorld(n.canvas,a,s?xe:i)}const{toOffsetOutBounds:Re}=R,ke={};const Se={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;ve(l,be),r.forEach(((r,_)=>{f.setWorldShadow(be.offsetX+r.x*c,be.offsetY+r.y*u,r.blur*c,r.color),n=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Be(f,be,n,i),s=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),s=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(i.canvas,h,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,s,o,r.blendMode):e.copyWorldToInner(f,s,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(s,!0)})),f.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Re(l,ke),r.forEach(((r,_)=>{f.save(),f.setWorldShadow(ke.offsetX+r.x*c,ke.offsetY+r.y*u,r.blur*c),n=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Be(f,ke,n,i),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),s=o):(f.copyWorld(i.canvas,h,l,"source-out"),s=l),f.fillWorld(s,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,s,o,r.blendMode):e.copyWorldToInner(f,s,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(s,!0)})),f.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Ee}=w;function Le(t,e,i,s,n,o){switch(e){case"alpha":!function(t,e,i,s){const n=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,n),s.recycle(n),We(t,e,i,1)}(t,i,s,n);break;case"opacity-path":We(t,i,s,o);break;case"path":i.restore()}}function Ae(t){return t.getSameCanvas(!1,!0)}function We(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}I.prototype.__renderMask=function(t,e){let i,s,n,o,a;const{children:r}=this;for(let d=0,l=r.length;d<l;d++)i=r[d],i.__.mask&&(a&&(Le(this,a,t,n,s,o),s=n=null),"path"===i.__.maskType?(i.opacity<1?(a="opacity-path",o=i.opacity,n||(n=Ae(t))):(a="path",t.save()),i.__clip(n||t,e)):(a="alpha",s||(s=Ae(t)),n||(n=Ae(t)),i.__render(s,e)),"clipping"!==i.__.maskType)||Ee(i,e)||i.__render(n||t,e);Le(this,a,t,n,s,o)};const Te=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Oe=Te+"_#~&*+\\=|≮≯≈≠=…",Me=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 Ce(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Pe=Ce("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ie=Ce("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),De=Ce(Te),Fe=Ce(Oe),ze=Ce("- —/~|┆·");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:Ve,Before:Xe,After:Ge,Symbol:Ne,Break:je}=Ye;function qe(t){return Pe[t]?Ue:ze[t]?je:Ie[t]?Xe:De[t]?Ge:Fe[t]?Ne:Me.test(t)?Ve:Ue}const He={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let o=n-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function Qe(t,e,i){switch(e){case"title":return i?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:Ze}=He,{Letter:$e,Single:Je,Before:Ke,After:ti,Symbol:ei,Break:ii}=Ye;let si,ni,oi,ai,ri,di,li,hi,ci,ui,fi,pi,_i,gi,wi,yi,mi=[];function vi(t,e){ci&&!hi&&(hi=ci),si.data.push({char:t,width:e}),oi+=e}function xi(){ai+=oi,si.width=oi,ni.words.push(si),si={data:[]},oi=0}function bi(){gi&&(wi.paraNumber++,ni.paraStart=!0,gi=!1),ci&&(ni.startCharSize=hi,ni.endCharSize=ci,hi=0),ni.width=ai,yi.width&&Ze(ni),mi.push(ni),ni={words:[]},ai=0}const Bi=0,Ri=1,ki=2;const{top:Si,right:Ei,bottom:Li,left:Ai}=L;function Wi(t,e,i){const{bounds:s,rows:n}=t;s[e]+=i;for(let t=0;t<n.length;t++)n[t][e]+=i}const Ti={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=i.__getInput("width")||0,a=i.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=i;l&&(o&&(s=l[Ai],o-=l[Ei]+l[Ai]),a&&(n=l[Si],a-=l[Si]+l[Li]));const h={bounds:{x:s,y:n,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,i,s){wi=t,mi=t.rows,yi=t.bounds;const{__letterSpacing:n,paraIndent:o,textCase:a}=s,{canvas:r}=e,{width:d,height:l}=yi;if(d||l||n||"none"!==a){const t="none"!==s.textWrap,e="break"===s.textWrap;gi=!0,fi=null,hi=li=ci=oi=ai=0,si={data:[]},ni={words:[]};for(let s=0,l=i.length;s<l;s++)di=i[s],"\n"===di?(oi&&xi(),ni.paraEnd=!0,bi(),gi=!0):(ui=qe(di),ui===$e&&"none"!==a&&(di=Qe(di,a,!oi)),li=r.measureText(di).width,n&&(n<0&&(ci=li),li+=n),pi=ui===Je&&(fi===Je||fi===$e)||fi===Je&&ui!==ti,_i=!(ui!==Ke&&ui!==Je||fi!==ei&&fi!==ti),ri=gi&&o?d-o:d,t&&d&&ai+oi+li>ri&&(e?(oi&&xi(),bi()):(_i||(_i=ui===$e&&fi==ti),pi||_i||ui===ii||ui===Ke||ui===Je||oi+li>ri?(oi&&xi(),bi()):bi()))," "===di&&!0!==gi&&ai+oi===0||(ui===ii?(" "===di&&oi&&xi(),vi(di,li),xi()):pi||_i?(oi&&xi(),vi(di,li)):vi(di,li)),fi=ui);oi&&xi(),ai&&bi(),mi.length>0&&(mi[mi.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{wi.paraNumber++,mi.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(h,t,i),l&&function(t,e,i,s,n){if(!s)switch(i.textAlign){case"left":Wi(e,"x",t[Ai]);break;case"right":Wi(e,"x",-t[Ei])}if(!n)switch(i.verticalAlign){case"top":Wi(e,"y",t[Si]);break;case"bottom":Wi(e,"y",-t[Li])}}(l,h,i,o,a),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:h}=e;let c,u,f,{x:p,y:_,width:g,height:w}=s,y=n*i.length+(h?h*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,n),t.overflow=i.length;else switch(l){case"middle":_+=(w-y)/2;break;case"bottom":_+=w-y}m+=_;for(let o=0,l=i.length;o<l;o++){switch(c=i[o],c.x=p,d){case"center":c.x+=(g-c.width)/2;break;case"right":c.x+=g-c.width}c.paraStart&&h&&o>0&&(m+=h),c.y=m,m+=n,t.overflow>o&&m>y&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,f=c.width,a<0&&(c.width<0?(f=-c.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<s.x&&(s.x=u),f>s.width&&(s.width=f),r&&g&&g<f&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=_,s.height=y}(h,i),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,l,h,c,u;n.forEach((t=>{t.words&&(h=a&&t.paraStart?a:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-h)/(t.words.length-1):0,c=r||t.isOverflow?Bi:l>.01?Ri:ki,t.isOverflow&&!r&&(t.textMode=!0),c===ki?(t.x+=h,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=h,d=t.x,t.data=[],t.words.forEach((e=>{c===Ri?(u={char:"",x:d},d=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,d,u)," "!==u.char&&t.data.push(u)):d=function(t,e,i){return t.forEach((t=>{" "!==t.char&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(h,i,o),h.overflow&&function(t,i){const{rows:s,overflow:n}=t;let{textOverflow:o}=i;if(s.splice(n),"hide"!==o){let t,a;"ellipsis"===o&&(o="...");const r=e.canvas.measureText(o).width,d=i.x+i.width-r;("none"===i.textWrap?s:[s[n-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],a=t.x+t.width,!(s===i&&a<d));s--){if(a<d&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=r,e.data.push({char:o,x:a}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(h,i),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(h,i),h}};const Oi={string:function(t,e){if("string"==typeof t)return t;let i=void 0===t.a?1:t.a;e&&(i*=e);const s=t.r+","+t.g+","+t.b;return 1===i?"rgb("+s+")":"rgba("+s+","+i+")"}},{setPoint:Mi,addPoint:Ci,toBounds:Pi}=A;const Ii={export(t,e,i){return this.running=!0,function(t){Di||(Di=new W);return new Promise((e=>{Di.add((()=>jt(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((s=>new Promise((n=>{const o=t=>{s(t),n(),this.running=!1},{leafer:r}=t;r?r.waitViewCompleted((()=>jt(this,void 0,void 0,(function*(){i=d.getExportOptions(i);let s,n,l=1,h=1;const{worldTransform:c,isLeafer:u,isFrame:f}=t,{slice:p,trim:_,onCanvas:w}=i,y=i.scale||1,m=i.pixelRatio||1,v=i.screenshot||t.isApp,x=u&&v&&void 0===i.fill?t.fill:i.fill,b=d.isOpaqueImage(e)||x,B=new T;if(v)s=!0===v?u?r.canvas.bounds:t.worldRenderBounds:v;else{let e=i.relative||(u?"inner":"local");switch(l=c.scaleX,h=c.scaleY,e){case"inner":B.set(c);break;case"local":B.set(c).divide(t.localTransform),l/=t.scaleX,h/=t.scaleY;break;case"world":l=1,h=1;break;case"page":e=t.leafer;default:B.set(c).divide(t.getTransform(e));const i=e.worldTransform;l/=l/i.scaleX,h/=h/i.scaleY}s=t.getBounds("render",e)}const{x:R,y:k,width:S,height:E}=new g(s).scale(y);let L=a.canvas({width:Math.round(S),height:Math.round(E),pixelRatio:m});const A={matrix:B.scale(1/y).invert().translate(-R,-k).withScale(1/l*y,1/h*y)};if(p&&(t=r,A.bounds=L.bounds),L.save(),f&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(L,A),t.fill=e}else t.__render(L,A);if(L.restore(),_){n=function(t){const{width:e,height:i}=t.view,{data:s}=t.context.getImageData(0,0,e,i);let n,o,a,r=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(n=r%e,o=(r-n)/e,a?Ci(a,n,o):Mi(a={},n,o)),r++;const d=new g;return Pi(a,d),d.scale(1/t.pixelRatio).ceil()}(L);const t=L,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:m};L=a.canvas(s),L.copyWorld(t,n,s)}b&&L.fillWorld(L.bounds,x||"#FFFFFF","destination-over"),w&&w(L);const W="canvas"===e?L:yield L.export(e,i);o({data:W,width:L.pixelWidth,height:L.pixelHeight,renderBounds:s,trimBounds:n})})))):o({data:!1})}))))}};let Di;const Fi=t.prototype,zi=y.get("@leafer-ui/export");Fi.export=function(t,e){const{quality:i,blob:s}=d.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):s?this.toBlob(t,i):this.toDataURL(t,i)},Fi.toBlob=function(t,i){return new Promise((s=>{e.origin.canvasToBolb(this.view,t,i).then((t=>{s(t)})).catch((t=>{zi.error(t),s(null)}))}))},Fi.toDataURL=function(t,i){return e.origin.canvasToDataURL(this.view,t,i)},Fi.saveAs=function(t,i){return new Promise((s=>{e.origin.canvasSaveAs(this.view,t,i).then((()=>{s(!0)})).catch((t=>{zi.error(t),s(!1)}))}))},Object.assign(D,Ti),Object.assign(M,Oi),Object.assign(F,gt),Object.assign(O,Ht),Object.assign(C,ye),Object.assign(z,Se),Object.assign(P,Ii);try{X(0,wx)}catch(t){}export{it as Layouter,Y as LeaferCanvas,nt as Renderer,G as Watcher,X as useCanvas};
|
|
1
|
+
import{LeaferCanvasBase as t,Platform as e,canvasPatch as i,DataHelper as n,canvasSizeAttrs as s,ResizeEvent as o,Creator as a,LeaferImage as r,FileHelper as d,LeafList as l,RenderEvent as h,ChildEvent as c,WatchEvent as u,PropertyEvent as f,LeafHelper as p,BranchHelper as g,Bounds as _,LeafBoundsHelper as w,Debug as y,LeafLevelList as m,LayoutEvent as v,Run as x,ImageManager as b,AnimateEvent as B,BoundsHelper as R,MatrixHelper as k,AroundHelper as S,ImageEvent as E,PointHelper as L,Direction4 as A,TwoPointBoundsHelper as W,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 P,Export as I,Group as D,TextConvert as F,Paint as z,Effect as U}from"@leafer-ui/draw";export*from"@leafer-ui/draw";class N extends t{get allowBackgroundColor(){return!1}init(){let{view:t}=this.config;t?("string"==typeof t?("#"!==t[0]&&(t="#"+t),this.viewSelect=e.miniapp.select(t)):t.fields?this.viewSelect=t:this.initView(t),this.viewSelect&&e.miniapp.getSizeView(this.viewSelect).then((t=>{this.initView(t)}))):this.initView()}initView(t){t?this.view=t.view||t:(t={},this.__createView()),this.__createContext();const{width:e,height:n,pixelRatio:s}=this.config,o={width:e||t.width,height:n||t.height,pixelRatio:s};this.resize(o),this.context.roundRect&&(this.roundRect=function(t,e,i,n,s){this.context.roundRect(t,e,i,n,"number"==typeof s?[s]:s)}),i(this.context.__proto__)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(t){this.viewSelect&&e.miniapp.getBounds(this.viewSelect).then((e=>{this.clientBounds=e,t&&t()}))}startAutoLayout(t,i){this.resizeListener=i,this.checkSize=this.checkSize.bind(this),e.miniapp.onWindowResize(this.checkSize)}checkSize(){this.viewSelect&&setTimeout((()=>{this.updateClientBounds((()=>{const{width:t,height:e}=this.clientBounds,{pixelRatio:i}=this,a={width:t,height:e,pixelRatio:i};if(!this.isSameSize(a)){const t={};n.copyAttrs(t,this,s),this.resize(a),void 0!==this.width&&this.resizeListener(new o(a,t))}}))}),500)}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,e.miniapp.offWindowResize(this.checkSize)}}const{mineType:V,fileType:Y}=d;function G(t,i){e.origin||(e.origin={createCanvas:(t,e,n)=>i.createOffscreenCanvas({type:"2d",width:t,height:e}),canvasToDataURL:(t,e,i)=>t.toDataURL(V(e),i),canvasToBolb:(t,e,i)=>t.toBuffer(e,{quality:i}),canvasSaveAs:(t,i,n)=>{let s=t.toDataURL(V(Y(i)),n);return s=s.substring(s.indexOf("64,")+3),e.origin.download(s,i)},download:(t,n)=>new Promise(((s,o)=>{let a;n.includes("/")||(n=`${i.env.USER_DATA_PATH}/`+n,a=!0);const r=i.getFileSystemManager();r.writeFile({filePath:n,data:t,encoding:"base64",success(){a&&e.miniapp.saveToAlbum(n).then((()=>{r.unlink({filePath:n})})),s()},fail(t){o(t)}})})),loadImage:t=>new Promise(((i,n)=>{const s=e.canvas.view.createImage();s.onload=()=>{i(s)},s.onerror=t=>{n(t)},s.src=t})),noRepeat:"repeat-x"},e.miniapp={select:t=>i.createSelectorQuery().select(t),getBounds:t=>new Promise((e=>{t.boundingClientRect().exec((t=>{const i=t[1];e({x:i.top,y:i.left,width:i.width,height:i.height})}))})),getSizeView:t=>new Promise((e=>{t.fields({node:!0,size:!0}).exec((t=>{const i=t[0];e({view:i.node,width:i.width,height:i.height})}))})),saveToAlbum:t=>new Promise((e=>{i.getSetting({success:n=>{n.authSetting["scope.writePhotosAlbum"]?i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}}):i.authorize({scope:"scope.writePhotosAlbum",success:()=>{i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}})},fail:()=>{}})}})})),onWindowResize(t){i.onWindowResize(t)},offWindowResize(t){i.offWindowResize(t)}},e.event={stopDefault(t){},stopNow(t){},stop(t){}},e.canvas=a.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient)}Object.assign(a,{canvas:(t,e)=>new N(t,e),image:t=>new r(t)}),e.name="miniapp",e.requestRender=function(t){e.canvas.view.requestAnimationFrame(t)},e.devicePixelRatio=wx.getSystemInfoSync().pixelRatio;class X{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new l;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 l,this.target=t,e&&(this.config=n.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(h.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===c.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new u(u.DATA,{updatedList:this.updatedList})),this.__updatedList=new l,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(f.CHANGE,this.__onAttrChange,this),t.on_([c.ADD,c.REMOVE],this.__onChildEvent,this),t.on_(u.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:j,updateBounds:q,updateAllWorldOpacity:H}=p,{pushAllChildBranch:Q,pushAllParent:J}=g;const{worldBounds:Z}=w,$={x:0,y:0,width:1e5,height:1e5};class K{constructor(t){this.updatedBounds=new _,this.beforeBounds=new _,this.afterBounds=new _,t instanceof Array&&(t=new l(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}=p,it=y.get("Layouter");class nt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new m,this.target=t,e&&(this.config=n.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(v.START),this.layoutOnce(),t.emitEvent(new v(v.END,this.layoutedBlocks,this.times))}catch(t){it.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?it.warn("layouting"):this.times>3?it.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(u.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=x.start("PartLayout"),{target:i,__updatedList:n}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=v,r=this.getBlocks(n);r.forEach((t=>t.setBefore())),i.emitEvent(new v(s,r,this.times)),this.extraBlock=null,n.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(j(t,!0),e.add(t),t.isBranch&&Q(t,e),J(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),J(t,e)))}))}(n,this.__levelList),function(t){let e,i,n;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(i=e[t],i.isBranch&&i.__tempNumber){n=i.children;for(let t=0,e=n.length;t<e;t++)n[t].isBranch||q(n[t])}q(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&H(t),t.__updateChange()}))}(n),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new v(o,r,this.times)),i.emitEvent(new v(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,x.end(e)}fullLayout(){const t=x.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:n,AFTER:s}=v,o=this.getBlocks(new l(e));e.emitEvent(new v(i,o,this.times)),nt.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new v(n,o,this.times)),e.emitEvent(new v(s,o,this.times)),this.addBlocks(o),x.end(t)}static fullLayout(t){tt(t,!0),t.isBranch?g.updateBounds(t):p.updateBounds(t),et(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new K([]));e.length?i.add(t.__world):i.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_(v.REQUEST,this.layout,this),t.on_(v.AGAIN,this.layoutAgain,this),t.on_(u.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const st=y.get("Renderer");class ot{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=n.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(v.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new _,st.log(e.innerName,"---\x3e");try{this.emitRender(h.START),this.renderOnce(t),this.emitRender(h.END,this.totalBounds),b.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 _,this.renderOptions={},t)this.emitRender(h.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(h.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(h.RENDER,this.renderBounds,this.renderOptions),this.emitRender(h.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=x.start("PartRender"),{canvas:i}=this,n=t.getIntersect(i.bounds),s=t.includes(this.target.__world),o=new _(n);i.save(),s&&!y.showRepaint?i.clear():(n.spread(1+1/this.canvas.pixelRatio).ceil(),i.clearWorld(n,!0),i.clipWorld(n,!0)),this.__render(n,s,o),i.restore(),x.end(e)}fullRender(){const t=x.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),x.end(t)}__render(t,e,i){const n=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),y.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,n),this.renderBounds=i||t,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),y.showHitView&&this.renderHitView(n),y.showBoundsView&&this.renderBoundsView(n),this.canvas.updateRender()}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new _;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(B.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(h.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:i}=t.old;new _(0,0,e,i).includes(this.target.__world)&&!this.needFill&&t.samePixelRatio||(this.addBlock(this.canvas.bounds),this.target.forceUpdate("surface"))}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||st.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new h(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(h.REQUEST,this.update,this),t.on_(v.END,this.__onLayoutEnd,this),t.on_(h.AGAIN,this.renderAgain,this),t.on_(o.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}function at(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),s&&e.fillRect(i.x,i.y+s,i.width,o)}function rt(t,e,i){const{strokeAlign:n}=e.__,s="string"!=typeof t;switch(n){case"center":i.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?ht(t,!0,e,i):lt(e,i);break;case"inside":dt("inside",t,s,e,i);break;case"outside":dt("outside",t,s,e,i)}}function dt(t,e,i,n,s){const{__strokeWidth:o,__font:a}=n.__,r=s.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,n.__),r.font=a,i?ht(e,!0,n,r):lt(n,r),r.blendMode="outside"===t?"destination-out":"destination-in",at(n,r),r.blendMode="normal",n.__worldFlipped?s.copyWorldByReset(r,n.__nowWorld):s.copyWorldToInner(r,n.__nowWorld,n.__layout.renderBounds),r.recycle(n.__nowWorld)}function lt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),s&&e.strokeRect(i.x,i.y+s,i.width,o)}function ht(t,e,i,n){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&M.checkImage(i,n,s,!1)||s.style&&(n.strokeStyle=s.style,s.blendMode?(n.saveBlendMode(s.blendMode),e?lt(i,n):n.stroke(),n.restoreBlendMode()):e?lt(i,n):n.stroke())}Object.assign(a,{watcher:(t,e)=>new X(t,e),layouter:(t,e)=>new nt(t,e),renderer:(t,e,i)=>new ot(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,n)=>{}}),e.layout=nt.fullLayout;const{getSpread:ct,getOuterOf:ut,getByMove:ft,getIntersectData:pt}=R;let gt;function _t(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:n}=i.__layout;switch(e.type){case"solid":let{type:s,blendMode:o,color:a,opacity:r}=e;return{type:s,blendMode:o,style:C.string(a,r)};case"image":return M.image(i,t,e,n,!gt||!gt[e.url]);case"linear":return P.linearGradient(e,n);case"radial":return P.radialGradient(e,n);case"angular":return P.conicGradient(e,n);default:return e.r?{type:"solid",style:C.string(e)}:void 0}}const wt={compute:function(t,e){const i=e.__,n=[];let s,o=i.__input[t];o instanceof Array||(o=[o]),gt=M.recycleImage(t,i);for(let i,s=0,a=o.length;s<a;s++)i=_t(t,o[s],e),i&&n.push(i);i["_"+t]=n.length?n:void 0,n.length&&n[0].image&&(s=n[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=s:i.__pixelStroke=s},fill:function(t,e,i){i.fillStyle=t,e.__.__font?at(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let n;const{windingRule:s,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)n=t[a],n.image&&M.checkImage(e,i,n,!o)||n.style&&(i.fillStyle=n.style,n.transform?(i.save(),i.transform(n.transform),n.blendMode&&(i.blendMode=n.blendMode),o?at(e,i):s?i.fill(s):i.fill(),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),o?at(e,i):s?i.fill(s):i.fill(),i.restoreBlendMode()):o?at(e,i):s?i.fill(s):i.fill())},fillText:at,stroke:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)rt(t,e,i);else switch(o){case"center":i.setStroke(t,s,n),i.stroke();break;case"inside":i.save(),i.setStroke(t,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*s,n),e.__drawRenderPath(o),o.stroke(),n.windingRule?o.clip(n.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)rt(t,e,i);else switch(o){case"center":i.setStroke(void 0,s,n),ht(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),ht(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*s,n),ht(t,!1,e,a),n.windingRule?a.clip(n.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:rt,drawTextStroke:lt,shape:function(t,e,i){const n=e.getSameCanvas(),s=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:h}=s;if(l<0&&(l=-l),h<0&&(h=-h),e.bounds.includes(s))d=n,o=r=s;else{const{renderShapeSpread:n}=t.__layout,c=pt(n?ct(e.bounds,n*l,n*h):e.bounds,s);a=e.bounds.getFitMatrix(c);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,h*=f),r=ut(s,a),o=ft(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(n,i),{canvas:n,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:h}}};let yt={};const{get:mt,rotateOfOuter:vt,translate:xt,scaleOfOuter:bt,scale:Bt,rotate:Rt}=k;function kt(t,e,i,n,s,o,a){const r=mt();xt(r,e.x+i,e.y+n),Bt(r,s,o),a&&vt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function St(t,e,i,n,s,o,a){const r=mt();xt(r,e.x+i,e.y+n),s&&Bt(r,s,o),a&&Rt(r,a),t.transform=r}function Et(t,e,i,n,s,o,a,r,d,l){const h=mt();if(d)if("center"===l)vt(h,{x:i/2,y:n/2},d);else switch(Rt(h,d),d){case 90:xt(h,n,0);break;case 180:xt(h,i,n);break;case 270:xt(h,0,i)}yt.x=e.x+s,yt.y=e.y+o,xt(h,yt.x,yt.y),a&&bt(h,yt,a,r),t.transform=h}const{get:Lt,translate:At}=k,Wt=new _,Ot={};function Tt(t,e,i,n){let{width:s,height:o}=e;i.padding&&(n=Wt.set(n).shrink(i.padding));const{opacity:a,mode:r,around:d,offset:l,scale:h,size:c,rotation:u,blendMode:f,repeat:p}=i,g=n.width===s&&n.height===o;f&&(t.blendMode=f);const _=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)c?(v=("number"==typeof c?c:c.width)/s,x=("number"==typeof c?c:c.height)/o):h&&(v="number"==typeof h?h:h.x,x="number"==typeof h?h:h.y);else if(!g||u){const t=n.width/y,e=n.height/m;v=x="fit"===r?Math.min(t,e):Math.max(t,e),b+=(n.width-s*v)/2,B+=(n.height-o*x)/2}if(d){const t={x:b,y:B,width:y,height:m};v&&(t.width*=v,t.height*=x),S.toPoint(d,n,Ot,!0,t),b+=Ot.x,B+=Ot.y}switch(l&&(b+=l.x,B+=l.y),r){case"strench":g||(s=n.width,o=n.height);break;case"normal":case"clip":(b||B||v||u)&&St(_,n,b,B,v,x,u);break;case"repeat":(!g||v||u)&&Et(_,n,s,o,b,B,v,x,u,d),p||(_.repeat="repeat");break;default:v&&kt(_,n,b,B,v,x,u)}_.transform||(n.x||n.y)&&(_.transform=Lt(),At(_.transform,n.x,n.y)),v&&"strench"!==r&&(_.scaleX=v,_.scaleY=x),_.width=s,_.height=o,a&&(_.opacity=a),p&&(_.repeat="string"==typeof p?"x"===p?"repeat-x":"repeat-y":"repeat")}let Mt,Ct=new _;const{isSame:Pt}=R;function It(t,e,i,n,s,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=n.width/e.pixelRatio,e.__naturalHeight=n.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return s.data||Tt(s,n,i,o),!0}function Dt(t,e){Ut(t,E.LOAD,e)}function Ft(t,e){Ut(t,E.LOADED,e)}function zt(t,e,i){e.error=i,t.forceUpdate("surface"),Ut(t,E.ERROR,e)}function Ut(t,e,i){t.hasEvent(e)&&t.emitEvent(new E(e,i))}function Nt(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:Vt,scale:Yt,copy:Gt}=k,{ceil:Xt,abs:jt}=Math;function qt(t,i,n){let{scaleX:s,scaleY:o}=b.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o;if(i.patternId===a||t.destroyed)return!1;{s=jt(s),o=jt(o);const{image:t,data:r}=i;let d,l,{width:h,height:c,scaleX:u,scaleY:f,opacity:p,transform:g,repeat:_}=r;u&&(l=Vt(),Gt(l,g),Yt(l,1/u,1/f),s*=u,o*=f),s*=n,o*=n,h*=s,c*=o;const w=h*c;if(!_&&w>e.image.maxCacheSize)return!1;let y=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(s/=d,o/=d,h/=d,c/=d),u&&(s/=u,o/=f),(g||1!==s||1!==o)&&(l||(l=Vt(),g&&Gt(l,g)),Yt(l,1/s,1/o));const m=t.getCanvas(Xt(h)||1,Xt(c)||1,p),v=t.getPattern(m,_||e.origin.noRepeat||"no-repeat",l,i);return i.style=v,i.patternId=a,!0}}function Ht(t,e,i,n){return new(i||(i=Promise))((function(s,o){function a(t){try{d(n.next(t))}catch(t){o(t)}}function r(t){try{d(n.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}d((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:Qt}=Math;const Jt={image:function(t,e,i,n,s){let o,a;const r=b.get(i);return Mt&&i===Mt.paint&&Pt(n,Mt.boxBounds)?o=Mt.leafPaint:(o={type:i.type,image:r},Mt=r.use>1?{leafPaint:o,paint:i,boxBounds:Ct.set(n)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(It(t,e,i,r,o,n),s&&(Dt(t,a),Ft(t,a))):r.error?s&&zt(t,a,r.error):(Nt(t,!0),s&&Dt(t,a),o.loadId=r.load((()=>{Nt(t,!1),t.destroyed||(It(t,e,i,r,o,n)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Ft(t,a)),o.loadId=null}),(e=>{Nt(t,!1),zt(t,a,e),o.loadId=null}))),o},createData:Tt,fillOrFitMode:kt,clipMode:St,repeatMode:Et,createPattern:qt,checkImage:function(t,i,n,s){const{scaleX:o,scaleY:a}=b.patternLocked?t.__world:t.__nowWorld;if(n.data&&n.patternId!==o+"-"+a){const{data:r}=n;if(s)if(r.repeat)s=!1;else{let{width:t,height:n}=r;t*=Qt(o)*i.pixelRatio,n*=Qt(a)*i.pixelRatio,r.scaleX&&(t*=r.scaleX,n*=r.scaleY),s=t*n>e.image.maxCacheSize}return s?(i.save(),i.clip(),n.blendMode&&(i.blendMode=n.blendMode),r.opacity&&(i.opacity*=r.opacity),r.transform&&i.transform(r.transform),i.drawImage(n.image.view,0,0,r.width,r.height),i.restore(),!0):(!n.style||I.running?qt(t,n,i.pixelRatio):n.patternTask||(n.patternTask=b.patternTasker.add((()=>Ht(this,void 0,void 0,(function*(){n.patternTask=null,i.bounds.hit(t.__nowWorld)&&qt(t,n,i.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let n,s,o,a;for(let r=0,d=i.length;r<d;r++)n=i[r].image,a=n&&n.url,a&&(s||(s={}),s[a]=!0,b.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),n.unload(i[r].loadId,!o.some((t=>t.url===a)))));return s}return null}},Zt={x:.5,y:0},$t={x:.5,y:1};function Kt(t,e,i){let n;for(let s=0,o=e.length;s<o;s++)n=e[s],t.addColorStop(n.offset,C.string(n.color,i))}const{set:te,getAngle:ee,getDistance:ie}=L,{get:ne,rotateOfOuter:se,scaleOfOuter:oe}=k,ae={x:.5,y:.5},re={x:.5,y:1},de={},le={};const{set:he,getAngle:ce,getDistance:ue}=L,{get:fe,rotateOfOuter:pe,scaleOfOuter:ge}=k,_e={x:.5,y:.5},we={x:.5,y:1},ye={},me={};const ve={linearGradient:function(t,i){let{from:n,to:s,type:o,blendMode:a,opacity:r}=t;n||(n=Zt),s||(s=$t);const d=e.canvas.createLinearGradient(i.x+n.x*i.width,i.y+n.y*i.height,i.x+s.x*i.width,i.y+s.y*i.height);Kt(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,i){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;n||(n=ae),s||(s=re);const{x:l,y:h,width:c,height:u}=i;let f;te(de,l+n.x*c,h+n.y*u),te(le,l+s.x*c,h+s.y*u),(c!==u||d)&&(f=ne(),oe(f,de,c/u*(d||1),1),se(f,de,ee(de,le)+90));const p=e.canvas.createRadialGradient(de.x,de.y,0,de.x,de.y,ie(de,le));Kt(p,t.stops,a);const g={type:o,style:p,transform:f};return r&&(g.blendMode=r),g},conicGradient:function(t,i){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;n||(n=_e),s||(s=we);const{x:l,y:h,width:c,height:u}=i;he(ye,l+n.x*c,h+n.y*u),he(me,l+s.x*c,h+s.y*u);const f=fe(),p=ce(ye,me);e.conicGradientRotate90?(ge(f,ye,c/u*(d||1),1),pe(f,ye,p+90)):(ge(f,ye,1,c/u*(d||1)),pe(f,ye,p));const g=e.conicGradientSupport?e.canvas.createConicGradient(0,ye.x,ye.y):e.canvas.createRadialGradient(ye.x,ye.y,0,ye.x,ye.y,ue(ye,me));Kt(g,t.stops,a);const _={type:o,style:g,transform:f};return r&&(_.blendMode=r),_}},{copy:xe,toOffsetOutBounds:be}=R,Be={},Re={};function ke(t,i,n,s){const{bounds:o,shapeBounds:a}=s;if(e.fullImageShadow){if(xe(Be,t.bounds),Be.x+=i.x-a.x,Be.y+=i.y-a.y,n){const{matrix:t}=s;Be.x-=(o.x+(t?t.e:0)+o.width/2)*(n-1),Be.y-=(o.y+(t?t.f:0)+o.height/2)*(n-1),Be.width*=n,Be.height*=n}t.copyWorld(s.canvas,t.bounds,Be)}else n&&(xe(Be,i),Be.x-=i.width/2*(n-1),Be.y-=i.height/2*(n-1),Be.width*=n,Be.height*=n),t.copyWorld(s.canvas,a,n?Be:i)}const{toOffsetOutBounds:Se}=R,Ee={};const Le={shadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;be(l,Re),r.forEach(((r,g)=>{f.setWorldShadow(Re.offsetX+r.x*c,Re.offsetY+r.y*u,r.blur*c,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,ke(f,Re,s,i),n=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),n=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(i.canvas,h,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),p&&g<p&&f.clearWorld(n,!0)})),f.recycle(n)},innerShadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Se(l,Ee),r.forEach(((r,g)=>{f.save(),f.setWorldShadow(Ee.offsetX+r.x*c,Ee.offsetY+r.y*u,r.blur*c),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,ke(f,Ee,s,i),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),n=o):(f.copyWorld(i.canvas,h,l,"source-out"),n=l),f.fillWorld(n,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),p&&g<p&&f.clearWorld(n,!0)})),f.recycle(n)},blur:function(t,e,i){const{blur:n}=t.__;i.setWorldBlur(n*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Ae}=w;function We(t,e,i,n,s,o){switch(e){case"alpha":!function(t,e,i,n){const s=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(n,s),n.recycle(s),Te(t,e,i,1)}(t,i,n,s);break;case"opacity-path":Te(t,i,n,o);break;case"path":i.restore()}}function Oe(t){return t.getSameCanvas(!1,!0)}function Te(t,e,i,n){const s=t.__nowWorld;e.resetTransform(),e.opacity=n,e.copyWorld(i,s),i.recycle(s)}D.prototype.__renderMask=function(t,e){let i,n,s,o,a;const{children:r}=this;for(let d=0,l=r.length;d<l;d++)i=r[d],i.__.mask&&(a&&(We(this,a,t,s,n,o),n=s=null),"path"===i.__.maskType?(i.opacity<1?(a="opacity-path",o=i.opacity,s||(s=Oe(t))):(a="path",t.save()),i.__clip(s||t,e)):(a="alpha",n||(n=Oe(t)),s||(s=Oe(t)),i.__render(n,e)),"clipping"!==i.__.maskType)||Ae(i,e)||i.__render(s||t,e);We(this,a,t,s,n,o)};const Me=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Ce=Me+"_#~&*+\\=|≮≯≈≠=…",Pe=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map((([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`)).join("|"));function Ie(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const De=Ie("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Fe=Ie("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ze=Ie(Me),Ue=Ie(Ce),Ne=Ie("- —/~|┆·");var Ve;!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"}(Ve||(Ve={}));const{Letter:Ye,Single:Ge,Before:Xe,After:je,Symbol:qe,Break:He}=Ve;function Qe(t){return De[t]?Ye:Ne[t]?He:Fe[t]?Xe:ze[t]?je:Ue[t]?qe:Pe.test(t)?Ge:Ye}const Je={trimRight(t){const{words:e}=t;let i,n=0,s=e.length;for(let o=s-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)n++,t.width-=i.width;n&&e.splice(s-n,n)}};function Ze(t,e,i){switch(e){case"title":return i?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:$e}=Je,{Letter:Ke,Single:ti,Before:ei,After:ii,Symbol:ni,Break:si}=Ve;let oi,ai,ri,di,li,hi,ci,ui,fi,pi,gi,_i,wi,yi,mi,vi,xi=[];function bi(t,e){fi&&!ui&&(ui=fi),oi.data.push({char:t,width:e}),ri+=e}function Bi(){di+=ri,oi.width=ri,ai.words.push(oi),oi={data:[]},ri=0}function Ri(){yi&&(mi.paraNumber++,ai.paraStart=!0,yi=!1),fi&&(ai.startCharSize=ui,ai.endCharSize=fi,ui=0),ai.width=di,vi.width&&$e(ai),xi.push(ai),ai={words:[]},di=0}const ki=0,Si=1,Ei=2;const{top:Li,right:Ai,bottom:Wi,left:Oi}=A;function Ti(t,e,i){const{bounds:n,rows:s}=t;n[e]+=i;for(let t=0;t<s.length;t++)s[t][e]+=i}const Mi={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let n=0,s=0,o=i.__getInput("width")||0,a=i.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=i;l&&(o&&(n=l[Oi],o-=l[Ai]+l[Oi]),a&&(s=l[Li],a-=l[Li]+l[Wi]));const h={bounds:{x:n,y:s,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,i,n){mi=t,xi=t.rows,vi=t.bounds;const{__letterSpacing:s,paraIndent:o,textCase:a}=n,{canvas:r}=e,{width:d,height:l}=vi;if(d||l||s||"none"!==a){const t="none"!==n.textWrap,e="break"===n.textWrap;yi=!0,gi=null,ui=ci=fi=ri=di=0,oi={data:[]},ai={words:[]};for(let n=0,l=i.length;n<l;n++)hi=i[n],"\n"===hi?(ri&&Bi(),ai.paraEnd=!0,Ri(),yi=!0):(pi=Qe(hi),pi===Ke&&"none"!==a&&(hi=Ze(hi,a,!ri)),ci=r.measureText(hi).width,s&&(s<0&&(fi=ci),ci+=s),_i=pi===ti&&(gi===ti||gi===Ke)||gi===ti&&pi!==ii,wi=!(pi!==ei&&pi!==ti||gi!==ni&&gi!==ii),li=yi&&o?d-o:d,t&&d&&di+ri+ci>li&&(e?(ri&&Bi(),Ri()):(wi||(wi=pi===Ke&&gi==ii),_i||wi||pi===si||pi===ei||pi===ti||ri+ci>li?(ri&&Bi(),Ri()):Ri()))," "===hi&&!0!==yi&&di+ri===0||(pi===si?(" "===hi&&ri&&Bi(),bi(hi,ci),Bi()):_i||wi?(ri&&Bi(),bi(hi,ci)):bi(hi,ci)),gi=pi);ri&&Bi(),di&&Ri(),xi.length>0&&(xi[xi.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{mi.paraNumber++,xi.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(h,t,i),l&&function(t,e,i,n,s){if(!n)switch(i.textAlign){case"left":Ti(e,"x",t[Oi]);break;case"right":Ti(e,"x",-t[Ai])}if(!s)switch(i.verticalAlign){case"top":Ti(e,"y",t[Li]);break;case"bottom":Ti(e,"y",-t[Wi])}}(l,h,i,o,a),function(t,e){const{rows:i,bounds:n}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:h}=e;let c,u,f,{x:p,y:g,width:_,height:w}=n,y=s*i.length+(h?h*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,s),t.overflow=i.length;else switch(l){case"middle":g+=(w-y)/2;break;case"bottom":g+=w-y}m+=g;for(let o=0,l=i.length;o<l;o++){switch(c=i[o],c.x=p,d){case"center":c.x+=(_-c.width)/2;break;case"right":c.x+=_-c.width}c.paraStart&&h&&o>0&&(m+=h),c.y=m,m+=s,t.overflow>o&&m>y&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,f=c.width,a<0&&(c.width<0?(f=-c.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<n.x&&(n.x=u),f>n.width&&(n.width=f),r&&_&&_<f&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}n.y=g,n.height=y}(h,i),function(t,e,i,n){const{rows:s}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,l,h,c,u;s.forEach((t=>{t.words&&(h=a&&t.paraStart?a:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-h)/(t.words.length-1):0,c=r||t.isOverflow?ki:l>.01?Si:Ei,t.isOverflow&&!r&&(t.textMode=!0),c===Ei?(t.x+=h,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=h,d=t.x,t.data=[],t.words.forEach((e=>{c===Si?(u={char:"",x:d},d=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,d,u)," "!==u.char&&t.data.push(u)):d=function(t,e,i){return t.forEach((t=>{" "!==t.char&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(h,i,o),h.overflow&&function(t,i){const{rows:n,overflow:s}=t;let{textOverflow:o}=i;if(n.splice(s),"hide"!==o){let t,a;"ellipsis"===o&&(o="...");const r=e.canvas.measureText(o).width,d=i.x+i.width-r;("none"===i.textWrap?n:[n[s-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let n=i;n>-1&&(t=e.data[n],a=t.x+t.width,!(n===i&&a<d));n--){if(a<d&&" "!==t.char){e.data.splice(n+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)}}))}}(h,i),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(h,i),h}};const Ci={string:function(t,e){if("string"==typeof t)return t;let i=void 0===t.a?1:t.a;e&&(i*=e);const n=t.r+","+t.g+","+t.b;return 1===i?"rgb("+n+")":"rgba("+n+","+i+")"}},{setPoint:Pi,addPoint:Ii,toBounds:Di}=W;const Fi={export(t,i,n){return this.running=!0,function(t){zi||(zi=new O);return new Promise((e=>{zi.add((()=>Ht(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((s=>new Promise((o=>{const r=t=>{s(t),o(),this.running=!1};if("json"===i)return r({data:t.toJSON()});if("json"===d.fileType(i))return e.origin.download("data:text/plain;charset=utf-8,"+encodeURIComponent(JSON.stringify(t.toJSON())),i),r({data:!0});const{leafer:l}=t;l?l.waitViewCompleted((()=>Ht(this,void 0,void 0,(function*(){n=d.getExportOptions(n);let e,s,o=1,h=1;const{worldTransform:c,isLeafer:u,isFrame:f}=t,{slice:p,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=d.isOpaqueImage(i)||x,B=new T;if(v)e=!0===v?u?l.canvas.bounds:t.worldRenderBounds:v;else{let i=n.relative||(u?"inner":"local");switch(o=c.scaleX,h=c.scaleY,i){case"inner":B.set(c);break;case"local":B.set(c).divide(t.localTransform),o/=t.scaleX,h/=t.scaleY;break;case"world":o=1,h=1;break;case"page":i=t.leafer;default:B.set(c).divide(t.getTransform(i));const e=i.worldTransform;o/=o/e.scaleX,h/=h/e.scaleY}e=t.getBounds("render",i)}const{x:R,y:k,width:S,height:E}=new _(e).scale(y);let L=a.canvas({width:Math.round(S),height:Math.round(E),pixelRatio:m});const A={matrix:B.scale(1/y).invert().translate(-R,-k).withScale(1/o*y,1/h*y)};if(p&&(t=l,A.bounds=L.bounds),L.save(),f&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(L,A),t.fill=e}else t.__render(L,A);if(L.restore(),g){s=function(t){const{width:e,height:i}=t.view,{data:n}=t.context.getImageData(0,0,e,i);let s,o,a,r=0;for(let t=0;t<n.length;t+=4)0!==n[t+3]&&(s=r%e,o=(r-s)/e,a?Ii(a,s,o):Pi(a={},s,o)),r++;const d=new _;return Di(a,d),d.scale(1/t.pixelRatio).ceil()}(L);const t=L,{width:e,height:i}=s,n={x:0,y:0,width:e,height:i,pixelRatio:m};L=a.canvas(n),L.copyWorld(t,s,n)}b&&L.fillWorld(L.bounds,x||"#FFFFFF","destination-over"),w&&w(L);const W="canvas"===i?L:yield L.export(i,n);r({data:W,width:L.pixelWidth,height:L.pixelHeight,renderBounds:e,trimBounds:s})})))):r({data:!1})}))))}};let zi;const Ui=t.prototype,Ni=y.get("@leafer-ui/export");Ui.export=function(t,e){const{quality:i,blob:n}=d.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):n?this.toBlob(t,i):this.toDataURL(t,i)},Ui.toBlob=function(t,i){return new Promise((n=>{e.origin.canvasToBolb(this.view,t,i).then((t=>{n(t)})).catch((t=>{Ni.error(t),n(null)}))}))},Ui.toDataURL=function(t,i){return e.origin.canvasToDataURL(this.view,t,i)},Ui.saveAs=function(t,i){return new Promise((n=>{e.origin.canvasSaveAs(this.view,t,i).then((()=>{n(!0)})).catch((t=>{Ni.error(t),n(!1)}))}))},Object.assign(F,Mi),Object.assign(C,Ci),Object.assign(z,wt),Object.assign(M,Jt),Object.assign(P,ve),Object.assign(U,Le),Object.assign(I,Fi);try{G(0,wx)}catch(t){}export{nt as Layouter,N as LeaferCanvas,ot as Renderer,X as Watcher,G as useCanvas};
|