leafer-draw 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web.cjs +2562 -0
- package/dist/web.esm.js +77 -61
- package/dist/web.esm.min.js +1 -1
- package/dist/web.js +255 -138
- package/dist/web.min.cjs +1 -0
- package/dist/web.min.js +1 -1
- package/dist/web.module.js +255 -139
- package/dist/web.module.min.js +1 -1
- package/package.json +9 -3
package/dist/web.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Debug, LeaferCanvasBase, Platform, DataHelper, canvasSizeAttrs, ResizeEvent, canvasPatch, Creator, LeaferImage, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, BoundsHelper, MatrixHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
|
|
1
|
+
import { Debug, LeaferCanvasBase, Platform, DataHelper, canvasSizeAttrs, ResizeEvent, canvasPatch, Creator, LeaferImage, defineKey, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, BoundsHelper, MatrixHelper, MathHelper, AlignHelper, ImageEvent, AroundHelper, 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';
|
|
@@ -25,7 +25,8 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
init() {
|
|
28
|
-
const {
|
|
28
|
+
const { config } = this;
|
|
29
|
+
const view = config.view || config.canvas;
|
|
29
30
|
view ? this.__createViewFrom(view) : this.__createView();
|
|
30
31
|
const { style } = this.view;
|
|
31
32
|
style.display || (style.display = 'block');
|
|
@@ -40,7 +41,7 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
40
41
|
}
|
|
41
42
|
this.__createContext();
|
|
42
43
|
if (!this.autoLayout)
|
|
43
|
-
this.resize(
|
|
44
|
+
this.resize(config);
|
|
44
45
|
}
|
|
45
46
|
set backgroundColor(color) { this.view.style.backgroundColor = color; }
|
|
46
47
|
get backgroundColor() { return this.view.style.backgroundColor; }
|
|
@@ -96,26 +97,37 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
96
97
|
this.clientBounds = this.view.getBoundingClientRect();
|
|
97
98
|
}
|
|
98
99
|
startAutoLayout(autoBounds, listener) {
|
|
99
|
-
this.autoBounds = autoBounds;
|
|
100
100
|
this.resizeListener = listener;
|
|
101
|
-
|
|
102
|
-
this.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this.
|
|
110
|
-
|
|
101
|
+
if (autoBounds) {
|
|
102
|
+
this.autoBounds = autoBounds;
|
|
103
|
+
try {
|
|
104
|
+
this.resizeObserver = new ResizeObserver((entries) => {
|
|
105
|
+
this.updateClientBounds();
|
|
106
|
+
for (const entry of entries)
|
|
107
|
+
this.checkAutoBounds(entry.contentRect);
|
|
108
|
+
});
|
|
109
|
+
const parent = this.parentView;
|
|
110
|
+
if (parent) {
|
|
111
|
+
this.resizeObserver.observe(parent);
|
|
112
|
+
this.checkAutoBounds(parent.getBoundingClientRect());
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
this.checkAutoBounds(this.view);
|
|
116
|
+
debug$3.warn('no parent');
|
|
117
|
+
}
|
|
111
118
|
}
|
|
112
|
-
|
|
113
|
-
this.
|
|
114
|
-
debug$3.warn('no parent');
|
|
119
|
+
catch (_a) {
|
|
120
|
+
this.imitateResizeObserver();
|
|
115
121
|
}
|
|
116
122
|
}
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
else {
|
|
124
|
+
window.addEventListener('resize', () => {
|
|
125
|
+
const pixelRatio = Platform.devicePixelRatio;
|
|
126
|
+
if (this.pixelRatio !== pixelRatio) {
|
|
127
|
+
const { width, height } = this;
|
|
128
|
+
this.emitResize({ width, height, pixelRatio });
|
|
129
|
+
}
|
|
130
|
+
});
|
|
119
131
|
}
|
|
120
132
|
}
|
|
121
133
|
imitateResizeObserver() {
|
|
@@ -128,17 +140,12 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
128
140
|
checkAutoBounds(parentSize) {
|
|
129
141
|
const view = this.view;
|
|
130
142
|
const { x, y, width, height } = this.autoBounds.getBoundsFrom(parentSize);
|
|
131
|
-
|
|
143
|
+
const size = { width, height, pixelRatio: Platform.devicePixelRatio };
|
|
144
|
+
if (!this.isSameSize(size)) {
|
|
132
145
|
const { style } = view;
|
|
133
|
-
const { pixelRatio } = this;
|
|
134
146
|
style.marginLeft = x + 'px';
|
|
135
147
|
style.marginTop = y + 'px';
|
|
136
|
-
|
|
137
|
-
const oldSize = {};
|
|
138
|
-
DataHelper.copyAttrs(oldSize, this, canvasSizeAttrs);
|
|
139
|
-
this.resize(size);
|
|
140
|
-
if (this.width !== undefined)
|
|
141
|
-
this.resizeListener(new ResizeEvent(size, oldSize));
|
|
148
|
+
this.emitResize(size);
|
|
142
149
|
}
|
|
143
150
|
}
|
|
144
151
|
stopAutoLayout() {
|
|
@@ -149,6 +156,13 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
149
156
|
this.resizeObserver = null;
|
|
150
157
|
}
|
|
151
158
|
}
|
|
159
|
+
emitResize(size) {
|
|
160
|
+
const oldSize = {};
|
|
161
|
+
DataHelper.copyAttrs(oldSize, this, canvasSizeAttrs);
|
|
162
|
+
this.resize(size);
|
|
163
|
+
if (this.width !== undefined)
|
|
164
|
+
this.resizeListener(new ResizeEvent(size, oldSize));
|
|
165
|
+
}
|
|
152
166
|
unrealCanvas() {
|
|
153
167
|
if (!this.unreal && this.parentView) {
|
|
154
168
|
const view = this.view;
|
|
@@ -229,7 +243,7 @@ function useCanvas(_canvasType, _power) {
|
|
|
229
243
|
Platform.name = 'web';
|
|
230
244
|
Platform.isMobile = 'ontouchstart' in window;
|
|
231
245
|
Platform.requestRender = function (render) { window.requestAnimationFrame(render); };
|
|
232
|
-
Platform
|
|
246
|
+
defineKey(Platform, 'devicePixelRatio', { get() { return Math.max(1, devicePixelRatio); } });
|
|
233
247
|
const { userAgent } = navigator;
|
|
234
248
|
if (userAgent.indexOf("Firefox") > -1) {
|
|
235
249
|
Platform.conicGradientRotate90 = true;
|
|
@@ -726,14 +740,14 @@ class Renderer {
|
|
|
726
740
|
if (Debug.showRepaint)
|
|
727
741
|
this.canvas.strokeWorld(bounds, 'red');
|
|
728
742
|
this.target.__render(this.canvas, options);
|
|
729
|
-
this.renderBounds = realBounds || bounds;
|
|
743
|
+
this.renderBounds = realBounds = realBounds || bounds;
|
|
730
744
|
this.renderOptions = options;
|
|
731
|
-
this.totalBounds.isEmpty() ? this.totalBounds =
|
|
745
|
+
this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
|
|
732
746
|
if (Debug.showHitView)
|
|
733
747
|
this.renderHitView(options);
|
|
734
748
|
if (Debug.showBoundsView)
|
|
735
749
|
this.renderBoundsView(options);
|
|
736
|
-
this.canvas.updateRender();
|
|
750
|
+
this.canvas.updateRender(realBounds);
|
|
737
751
|
}
|
|
738
752
|
renderHitView(_options) { }
|
|
739
753
|
renderBoundsView(_options) { }
|
|
@@ -1181,10 +1195,13 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
|
|
|
1181
1195
|
const { get: get$2, translate } = MatrixHelper;
|
|
1182
1196
|
const tempBox = new Bounds();
|
|
1183
1197
|
const tempPoint = {};
|
|
1198
|
+
const tempScaleData = {};
|
|
1184
1199
|
function createData(leafPaint, image, paint, box) {
|
|
1185
|
-
const { blendMode } = paint;
|
|
1200
|
+
const { blendMode, sync } = paint;
|
|
1186
1201
|
if (blendMode)
|
|
1187
1202
|
leafPaint.blendMode = blendMode;
|
|
1203
|
+
if (sync)
|
|
1204
|
+
leafPaint.sync = sync;
|
|
1188
1205
|
leafPaint.data = getPatternData(paint, box, image);
|
|
1189
1206
|
}
|
|
1190
1207
|
function getPatternData(paint, box, image) {
|
|
@@ -1204,13 +1221,10 @@ function getPatternData(paint, box, image) {
|
|
|
1204
1221
|
x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
|
|
1205
1222
|
}
|
|
1206
1223
|
}
|
|
1207
|
-
else if (size) {
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
else if (scale) {
|
|
1212
|
-
scaleX = typeof scale === 'number' ? scale : scale.x;
|
|
1213
|
-
scaleY = typeof scale === 'number' ? scale : scale.y;
|
|
1224
|
+
else if (scale || size) {
|
|
1225
|
+
MathHelper.getScaleData(scale, size, image, tempScaleData);
|
|
1226
|
+
scaleX = tempScaleData.scaleX;
|
|
1227
|
+
scaleY = tempScaleData.scaleY;
|
|
1214
1228
|
}
|
|
1215
1229
|
if (align) {
|
|
1216
1230
|
const imageBounds = { x, y, width: swapWidth, height: swapHeight };
|
|
@@ -1447,7 +1461,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
1447
1461
|
const { abs } = Math;
|
|
1448
1462
|
function checkImage(ui, canvas, paint, allowPaint) {
|
|
1449
1463
|
const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
|
|
1450
|
-
if (!paint.data || paint.patternId === scaleX + '-' + scaleY) {
|
|
1464
|
+
if (!paint.data || (paint.patternId === scaleX + '-' + scaleY && !Export.running)) {
|
|
1451
1465
|
return false;
|
|
1452
1466
|
}
|
|
1453
1467
|
else {
|
|
@@ -1481,7 +1495,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
1481
1495
|
return true;
|
|
1482
1496
|
}
|
|
1483
1497
|
else {
|
|
1484
|
-
if (!paint.style || Export.running) {
|
|
1498
|
+
if (!paint.style || paint.sync || Export.running) {
|
|
1485
1499
|
createPattern(ui, paint, canvas.pixelRatio);
|
|
1486
1500
|
}
|
|
1487
1501
|
else {
|
|
@@ -2351,6 +2365,7 @@ const ExportModule = {
|
|
|
2351
2365
|
export(leaf, filename, options) {
|
|
2352
2366
|
this.running = true;
|
|
2353
2367
|
const fileType = FileHelper.fileType(filename);
|
|
2368
|
+
const isDownload = filename.includes('.');
|
|
2354
2369
|
options = FileHelper.getExportOptions(options);
|
|
2355
2370
|
return addTask((success) => new Promise((resolve) => {
|
|
2356
2371
|
const over = (result) => {
|
|
@@ -2360,19 +2375,13 @@ const ExportModule = {
|
|
|
2360
2375
|
};
|
|
2361
2376
|
const { toURL } = Platform;
|
|
2362
2377
|
const { download } = Platform.origin;
|
|
2363
|
-
if (
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
else if (fileType === 'json') {
|
|
2367
|
-
download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
2368
|
-
return over({ data: true });
|
|
2369
|
-
}
|
|
2370
|
-
if (filename === 'svg') {
|
|
2371
|
-
return over({ data: leaf.toSVG() });
|
|
2378
|
+
if (fileType === 'json') {
|
|
2379
|
+
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
2380
|
+
return over({ data: isDownload ? true : leaf.toJSON(options.json) });
|
|
2372
2381
|
}
|
|
2373
|
-
|
|
2374
|
-
download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2375
|
-
return over({ data: true });
|
|
2382
|
+
if (fileType === 'svg') {
|
|
2383
|
+
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2384
|
+
return over({ data: isDownload ? true : leaf.toSVG() });
|
|
2376
2385
|
}
|
|
2377
2386
|
const { leafer } = leaf;
|
|
2378
2387
|
if (leafer) {
|
|
@@ -2381,14 +2390,8 @@ const ExportModule = {
|
|
|
2381
2390
|
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2382
2391
|
const { worldTransform, isLeafer, isFrame } = leaf;
|
|
2383
2392
|
const { slice, trim, onCanvas } = options;
|
|
2384
|
-
let scale = options.scale || 1;
|
|
2385
|
-
let pixelRatio = options.pixelRatio || 1;
|
|
2386
2393
|
const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
|
|
2387
2394
|
const contextSettings = options.contextSettings || leafer.config.contextSettings;
|
|
2388
|
-
if (leaf.isApp) {
|
|
2389
|
-
scale *= pixelRatio;
|
|
2390
|
-
pixelRatio = leaf.app.pixelRatio;
|
|
2391
|
-
}
|
|
2392
2395
|
const screenshot = options.screenshot || leaf.isApp;
|
|
2393
2396
|
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
2394
2397
|
const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
|
|
@@ -2422,10 +2425,21 @@ const ExportModule = {
|
|
|
2422
2425
|
}
|
|
2423
2426
|
renderBounds = leaf.getBounds('render', relative);
|
|
2424
2427
|
}
|
|
2425
|
-
const {
|
|
2428
|
+
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
2429
|
+
MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2430
|
+
let pixelRatio = options.pixelRatio || 1;
|
|
2431
|
+
if (leaf.isApp) {
|
|
2432
|
+
scaleData.scaleX *= pixelRatio;
|
|
2433
|
+
scaleData.scaleY *= pixelRatio;
|
|
2434
|
+
pixelRatio = leaf.app.pixelRatio;
|
|
2435
|
+
}
|
|
2436
|
+
const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2437
|
+
const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
|
|
2426
2438
|
let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
|
|
2427
|
-
|
|
2439
|
+
let sliceLeaf;
|
|
2428
2440
|
if (slice) {
|
|
2441
|
+
sliceLeaf = leaf;
|
|
2442
|
+
sliceLeaf.__worldOpacity = 0;
|
|
2429
2443
|
leaf = leafer;
|
|
2430
2444
|
renderOptions.bounds = canvas.bounds;
|
|
2431
2445
|
}
|
|
@@ -2440,6 +2454,8 @@ const ExportModule = {
|
|
|
2440
2454
|
leaf.__render(canvas, renderOptions);
|
|
2441
2455
|
}
|
|
2442
2456
|
canvas.restore();
|
|
2457
|
+
if (sliceLeaf)
|
|
2458
|
+
sliceLeaf.__updateWorldOpacity();
|
|
2443
2459
|
if (trim) {
|
|
2444
2460
|
trimBounds = getTrimBounds(canvas);
|
|
2445
2461
|
const old = canvas, { width, height } = trimBounds;
|
package/dist/web.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Debug as t,LeaferCanvasBase as e,Platform as i,DataHelper as n,canvasSizeAttrs as s,ResizeEvent as o,canvasPatch as a,Creator as r,LeaferImage as d,FileHelper as l,LeafList as c,RenderEvent as h,ChildEvent as u,WatchEvent as f,PropertyEvent as p,LeafHelper as g,BranchHelper as _,Bounds as w,LeafBoundsHelper as y,LeafLevelList as m,LayoutEvent as v,Run as x,ImageManager as b,AnimateEvent as B,BoundsHelper as R,MatrixHelper as k,AlignHelper as E,ImageEvent as S,AroundHelper as L,PointHelper as A,Direction4 as O,TwoPointBoundsHelper as W,TaskProcessor as C,Matrix as T}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as M,ColorConvert as D,PaintGradient as I,Export as P,Group as F,TextConvert as V,Paint as z,Effect as U}from"@leafer-ui/draw";export*from"@leafer-ui/draw";const Y=t.get("LeaferCanvas");class N extends e{set zIndex(t){const{style:e}=this.view;e.zIndex=t,this.setAbsolute(this.view)}set childIndex(t){const{view:e,parentView:i}=this;if(e&&i){const n=i.children[t];n?(this.setAbsolute(n),i.insertBefore(e,n)):i.appendChild(n)}}init(){const{view:t}=this.config;t?this.__createViewFrom(t):this.__createView();const{style:e}=this.view;if(e.display||(e.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}i.syncDomFont&&!this.parentView&&(e.display="none",document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(this.config)}set backgroundColor(t){this.view.style.backgroundColor=t}get backgroundColor(){return this.view.style.backgroundColor}set hittable(t){this.view.style.pointerEvents=t?"auto":"none"}get hittable(){return"none"!==this.view.style.pointerEvents}__createView(){this.view=document.createElement("canvas")}__createViewFrom(t){let e="string"==typeof t?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;t.hasChildNodes()&&(this.setAbsolute(i),t.style.position||(t.style.position="relative")),t.appendChild(i)}else Y.error(`no id: ${t}`),this.__createView()}setAbsolute(t){const{style:e}=t;e.position="absolute",e.top=e.left="0px"}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:n}=this.view;n.width=t+"px",n.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.clientBounds=this.view.getBoundingClientRect()}startAutoLayout(t,e){this.autoBounds=t,this.resizeListener=e;try{this.resizeObserver=new ResizeObserver((t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)}));const t=this.parentView;t?(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect())):(this.checkAutoBounds(this.view),Y.warn("no parent"))}catch(t){this.imitateResizeObserver()}}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(t){const e=this.view,{x:i,y:a,width:r,height:d}=this.autoBounds.getBoundsFrom(t);if(r!==this.width||d!==this.height){const{style:t}=e,{pixelRatio:l}=this;t.marginLeft=i+"px",t.marginTop=a+"px";const c={width:r,height:d,pixelRatio:l},h={};n.copyAttrs(h,this,s),this.resize(c),void 0!==this.width&&this.resizeListener(new o(c,h))}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}a(CanvasRenderingContext2D.prototype),a(Path2D.prototype);const{mineType:G,fileType:j}=l;function X(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>t.toDataURL(G(e),i),canvasToBolb:(t,e,i)=>new Promise((n=>t.toBlob(n,G(e),i))),canvasSaveAs:(t,e,n)=>{const s=t.toDataURL(G(j(e)),n);return i.origin.download(s,e)},download:(t,e)=>new Promise((i=>{let n=document.createElement("a");n.href=t,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),i()})),loadImage:t=>new Promise(((e,n)=>{const s=new Image,{crossOrigin:o}=i.image;o&&(s.setAttribute("crossOrigin",o),s.crossOrigin=o),s.onload=()=>{e(s)},s.onerror=t=>{n(t)},s.src=i.image.getRealURL(t)}))},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=r.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(r,{canvas:(t,e)=>new N(t,e),image:t=>new d(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},i.devicePixelRatio=Math.max(1,devicePixelRatio);const{userAgent:q}=navigator;q.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):q.indexOf("Safari")>-1&&-1===q.indexOf("Chrome")&&(i.fullImageShadow=!0),q.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):q.indexOf("Mac")>-1?i.os="Mac":q.indexOf("Linux")>-1&&(i.os="Linux");class H{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new c;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 c,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===u.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new f(f.DATA,{updatedList:this.updatedList})),this.__updatedList=new c,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(p.CHANGE,this.__onAttrChange,this),t.on_([u.ADD,u.REMOVE],this.__onChildEvent,this),t.on_(f.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:Q,updateBounds:J,updateAllWorldOpacity:Z}=g,{pushAllChildBranch:$,pushAllParent:K}=_;const{worldBounds:tt}=y,et={x:0,y:0,width:1e5,height:1e5};class it{constructor(t){this.updatedBounds=new w,this.beforeBounds=new w,this.afterBounds=new w,t instanceof Array&&(t=new c(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,tt)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(et):this.afterBounds.setListWithFn(t,tt),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:nt,updateAllChange:st}=g,ot=t.get("Layouter");class at{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){ot.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ot.warn("layouting"):this.times>3?ot.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(f.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=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?(Q(t,!0),e.add(t),t.isBranch&&$(t,e),K(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),K(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||J(n[t])}J(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&Z(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 c(e));e.emitEvent(new v(i,o,this.times)),at.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){nt(t,!0),t.isBranch?_.updateBounds(t):g.updateBounds(t),st(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new it([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new it(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_(f.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const rt=t.get("Renderer");class dt{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 w,rt.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,rt.error(t)}rt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return rt.warn("rendering");if(this.times>3)return rt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new w,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 rt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const i=x.start("PartRender"),{canvas:n}=this,s=e.getIntersect(n.bounds),o=e.includes(this.target.__world),a=new w(s);n.save(),o&&!t.showRepaint?n.clear():(s.spread(10+1/this.canvas.pixelRatio).ceil(),n.clearWorld(s,!0),n.clipWorld(s,!0)),this.__render(s,o,a),n.restore(),x.end(i)}fullRender(){const t=x.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),x.end(t)}__render(e,i,n){const s=e.includes(this.target.__world)?{includes:i}:{bounds:e,includes:i};this.needFill&&this.canvas.fillWorld(e,this.config.fill),t.showRepaint&&this.canvas.strokeWorld(e,"red"),this.target.__render(this.canvas,s),this.renderBounds=n||e,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),t.showHitView&&this.renderHitView(s),t.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 w;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();i.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.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){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new w(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new w(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||rt.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 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.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 ct(t,e,i){const{strokeAlign:n}=e.__,s="string"!=typeof t;switch(n){case"center":i.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?ft(t,!0,e,i):ut(e,i);break;case"inside":ht("inside",t,s,e,i);break;case"outside":ht("outside",t,s,e,i)}}function ht(t,e,i,n,s){const{__strokeWidth:o,__font:a}=n.__,r=s.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,n.__),r.font=a,i?ft(e,!0,n,r):ut(n,r),r.blendMode="outside"===t?"destination-out":"destination-in",lt(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 ut(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),s&&e.strokeRect(i.x,i.y+s,i.width,o)}function ft(t,e,i,n){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&M.checkImage(i,n,s,!1)||s.style&&(n.strokeStyle=s.style,s.blendMode?(n.saveBlendMode(s.blendMode),e?ut(i,n):n.stroke(),n.restoreBlendMode()):e?ut(i,n):n.stroke())}Object.assign(r,{watcher:(t,e)=>new H(t,e),layouter:(t,e)=>new at(t,e),renderer:(t,e,i)=>new dt(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,n)=>{}}),i.layout=at.fullLayout;const{getSpread:pt,getOuterOf:gt,getByMove:_t,getIntersectData:wt}=R;let yt;function mt(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:D.string(a,r)};case"image":return M.image(i,t,e,n,!yt||!yt[e.url]);case"linear":return I.linearGradient(e,n);case"radial":return I.radialGradient(e,n);case"angular":return I.conicGradient(e,n);default:return void 0!==e.r?{type:"solid",style:D.string(e)}:void 0}}const vt={compute:function(t,e){const i=e.__,n=[];let s,o=i.__input[t];o instanceof Array||(o=[o]),yt=M.recycleImage(t,i);for(let i,s=0,a=o.length;s<a;s++)i=mt(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?lt(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?lt(e,i):s?i.fill(s):i.fill(),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),o?lt(e,i):s?i.fill(s):i.fill(),i.restoreBlendMode()):o?lt(e,i):s?i.fill(s):i.fill())},fillText:lt,stroke:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)ct(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)ct(t,e,i);else switch(o){case"center":i.setStroke(void 0,s,n),ft(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),ft(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*s,n),ft(t,!1,e,a),n.windingRule?a.clip(n.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:ct,drawTextStroke:ut,shape:function(t,e,i){const n=e.getSameCanvas(),s=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:c}=s;if(l<0&&(l=-l),c<0&&(c=-c),e.bounds.includes(s))d=n,o=r=s;else{const{renderShapeSpread:n}=t.__layout,h=wt(n?pt(e.bounds,l===c?n*l:[n*c,n*l]):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,c*=f),r=gt(s,a),o=_t(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(n,i),{canvas:n,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:c}}};let xt={};const{get:bt,rotateOfOuter:Bt,translate:Rt,scaleOfOuter:kt,scale:Et,rotate:St}=k;function Lt(t,e,i,n,s,o,a){const r=bt();Rt(r,e.x+i,e.y+n),Et(r,s,o),a&&Bt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function At(t,e,i,n,s,o,a){const r=bt();Rt(r,e.x+i,e.y+n),s&&Et(r,s,o),a&&St(r,a),t.transform=r}function Ot(t,e,i,n,s,o,a,r,d,l){const c=bt();if(d)if("center"===l)Bt(c,{x:i/2,y:n/2},d);else switch(St(c,d),d){case 90:Rt(c,n,0);break;case 180:Rt(c,i,n);break;case 270:Rt(c,0,i)}xt.x=e.x+s,xt.y=e.y+o,Rt(c,xt.x,xt.y),a&&kt(c,xt,a,r),t.transform=c}const{get:Wt,translate:Ct}=k,Tt=new w,Mt={};function Dt(t,e,i,n){const{blendMode:s}=i;s&&(t.blendMode=s),t.data=It(i,n,e)}function It(t,e,i){let{width:n,height:s}=i;t.padding&&(e=Tt.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===n&&e.height===s,p={mode:a},g="center"!==r&&(h||0)%180==90,_=g?s:n,w=g?n:s;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)c?(y=("number"==typeof c?c:c.width)/n,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/_,i=e.height/w;y=m="fit"===a?Math.min(t,i):Math.max(t,i),v+=(e.width-n*y)/2,x+=(e.height-s*m)/2}if(r){const t={x:v,y:x,width:_,height:w};y&&(t.width*=y,t.height*=m),E.toPoint(r,t,e,Mt,!0),v+=Mt.x,x+=Mt.y}switch(d&&(v+=d.x,x+=d.y),a){case"strench":f||(n=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||h)&&At(p,e,v,x,y,m,h);break;case"repeat":(!f||y||h)&&Ot(p,e,n,s,v,x,y,m,h,r),u||(p.repeat="repeat");break;default:y&&Lt(p,e,v,x,y,m,h)}return p.transform||(e.x||e.y)&&(p.transform=Wt(),Ct(p.transform,e.x,e.y)),y&&"strench"!==a&&(p.scaleX=y,p.scaleY=m),p.width=n,p.height=s,o&&(p.opacity=o),u&&(p.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),p}let Pt,Ft=new w;const{isSame:Vt}=R;function zt(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||Dt(s,n,i,o),!0}function Ut(t,e){Gt(t,S.LOAD,e)}function Yt(t,e){Gt(t,S.LOADED,e)}function Nt(t,e,i){e.error=i,t.forceUpdate("surface"),Gt(t,S.ERROR,e)}function Gt(t,e,i){t.hasEvent(e)&&t.emitEvent(new S(e,i))}function jt(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:Xt,scale:qt,copy:Ht}=k,{ceil:Qt,abs:Jt}=Math;function Zt(t,e,n){let{scaleX:s,scaleY:o}=b.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o;if(e.patternId===a||t.destroyed)return!1;{s=Jt(s),o=Jt(o);const{image:t,data:r}=e;let d,l,{width:c,height:h,scaleX:u,scaleY:f,opacity:p,transform:g,repeat:_}=r;u&&(l=Xt(),Ht(l,g),qt(l,1/u,1/f),s*=u,o*=f),s*=n,o*=n,c*=s,h*=o;const w=c*h;if(!_&&w>i.image.maxCacheSize)return!1;let y=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(s/=d,o/=d,c/=d,h/=d),u&&(s/=u,o/=f),(g||1!==s||1!==o)&&(l||(l=Xt(),g&&Ht(l,g)),qt(l,1/s,1/o));const m=t.getCanvas(Qt(c)||1,Qt(h)||1,p),v=t.getPattern(m,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=v,e.patternId=a,!0}}function $t(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:Kt}=Math;const te={image:function(t,e,i,n,s){let o,a;const r=b.get(i);return Pt&&i===Pt.paint&&Vt(n,Pt.boxBounds)?o=Pt.leafPaint:(o={type:i.type,image:r},Pt=r.use>1?{leafPaint:o,paint:i,boxBounds:Ft.set(n)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(zt(t,e,i,r,o,n),s&&(Ut(t,a),Yt(t,a))):r.error?s&&Nt(t,a,r.error):(jt(t,!0),s&&Ut(t,a),o.loadId=r.load((()=>{jt(t,!1),t.destroyed||(zt(t,e,i,r,o,n)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Yt(t,a)),o.loadId=null}),(e=>{jt(t,!1),Nt(t,a,e),o.loadId=null}))),o},checkImage:function(t,e,n,s){const{scaleX:o,scaleY:a}=b.patternLocked?t.__world:t.__nowWorld;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*=Kt(o)*e.pixelRatio,n*=Kt(a)*e.pixelRatio,r.scaleX&&(t*=r.scaleX,n*=r.scaleY),s=t*n>i.image.maxCacheSize||P.running}return s?(e.save(),e.clip(),n.blendMode&&(e.blendMode=n.blendMode),r.opacity&&(e.opacity*=r.opacity),r.transform&&e.transform(r.transform),e.drawImage(n.image.view,0,0,r.width,r.height),e.restore(),!0):(!n.style||P.running?Zt(t,n,e.pixelRatio):n.patternTask||(n.patternTask=b.patternTasker.add((()=>$t(this,void 0,void 0,(function*(){n.patternTask=null,e.bounds.hit(t.__nowWorld)&&Zt(t,n,e.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},createPattern:Zt,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let n,s,o,a;for(let r=0,d=i.length;r<d;r++)n=i[r].image,a=n&&n.url,a&&(s||(s={}),s[a]=!0,b.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),n.unload(i[r].loadId,!o.some((t=>t.url===a)))));return s}return null},createData:Dt,getPatternData:It,fillOrFitMode:Lt,clipMode:At,repeatMode:Ot},{toPoint:ee}=L,ie={},ne={};function se(t,e,i){let n;for(let s=0,o=e.length;s<o;s++)n=e[s],"string"==typeof n?t.addColorStop(s/(o-1),D.string(n,i)):t.addColorStop(n.offset,D.string(n.color,i))}const{getAngle:oe,getDistance:ae}=A,{get:re,rotateOfOuter:de,scaleOfOuter:le}=k,{toPoint:ce}=L,he={},ue={};function fe(t,e,i,n,s){let o;const{width:a,height:r}=t;if(a!==r||n){const t=oe(e,i);o=re(),s?(le(o,e,a/r*(n||1),1),de(o,e,t+90)):(le(o,e,1,a/r*(n||1)),de(o,e,t))}return o}const{getDistance:pe}=A,{toPoint:ge}=L,_e={},we={};const ye={linearGradient:function(t,e){let{from:n,to:s,type:o,blendMode:a,opacity:r}=t;ee(n||"top",e,ie),ee(s||"bottom",e,ne);const d=i.canvas.createLinearGradient(ie.x,ie.y,ne.x,ne.y);se(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,e){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;ce(n||"center",e,he),ce(s||"bottom",e,ue);const l=i.canvas.createRadialGradient(he.x,he.y,0,he.x,he.y,ae(he,ue));se(l,t.stops,a);const c={type:o,style:l},h=fe(e,he,ue,d,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(t,e){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;ge(n||"center",e,_e),ge(s||"bottom",e,we);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,_e.x,_e.y):i.canvas.createRadialGradient(_e.x,_e.y,0,_e.x,_e.y,pe(_e,we));se(l,t.stops,a);const c={type:o,style:l},h=fe(e,_e,we,d||1,i.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:fe},{copy:me,toOffsetOutBounds:ve}=R,xe={},be={};function Be(t,e,n,s){const{bounds:o,shapeBounds:a}=s;if(i.fullImageShadow){if(me(xe,t.bounds),xe.x+=e.x-a.x,xe.y+=e.y-a.y,n){const{matrix:t}=s;xe.x-=(o.x+(t?t.e:0)+o.width/2)*(n-1),xe.y-=(o.y+(t?t.f:0)+o.height/2)*(n-1),xe.width*=n,xe.height*=n}t.copyWorld(s.canvas,t.bounds,xe)}else n&&(me(xe,e),xe.x-=e.width/2*(n-1),xe.y-=e.height/2*(n-1),xe.width*=n,xe.height*=n),t.copyWorld(s.canvas,a,n?xe:e)}const{toOffsetOutBounds:Re}=R,ke={};const Ee={shadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;ve(l,be),r.forEach(((r,g)=>{f.setWorldShadow(be.offsetX+r.x*h,be.offsetY+r.y*u,r.blur*h,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Be(f,be,s,i),n=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),n=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(i.canvas,c,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),p&&g<p&&f.clearWorld(n,!0)})),f.recycle(n)},innerShadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Re(l,ke),r.forEach(((r,g)=>{f.save(),f.setWorldShadow(ke.offsetX+r.x*h,ke.offsetY+r.y*u,r.blur*h),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Be(f,ke,s,i),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),n=o):(f.copyWorld(i.canvas,c,l,"source-out"),n=l),f.fillWorld(n,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),p&&g<p&&f.clearWorld(n,!0)})),f.recycle(n)},blur:function(t,e,i){const{blur:n}=t.__;i.setWorldBlur(n*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Se}=y;function Le(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),Oe(t,e,i,1)}(t,i,n,s);break;case"opacity-path":Oe(t,i,n,o);break;case"path":i.restore()}}function Ae(t){return t.getSameCanvas(!1,!0)}function Oe(t,e,i,n){const s=t.__nowWorld;e.resetTransform(),e.opacity=n,e.copyWorld(i,s),i.recycle(s)}F.prototype.__renderMask=function(t,e){let i,n,s,o,a;const{children:r}=this;for(let d=0,l=r.length;d<l;d++)i=r[d],i.__.mask&&(a&&(Le(this,a,t,s,n,o),n=s=null),"path"===i.__.mask?(i.opacity<1?(a="opacity-path",o=i.opacity,s||(s=Ae(t))):(a="path",t.save()),i.__clip(s||t,e)):(a="alpha",n||(n=Ae(t)),s||(s=Ae(t)),i.__render(n,e)),"clipping"!==i.__.mask)||Se(i,e)||i.__render(s||t,e);Le(this,a,t,s,n,o)};const We=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Ce=We+"_#~&*+\\=|≮≯≈≠=…",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 De=Me("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ie=Me("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Pe=Me(We),Fe=Me(Ce),Ve=Me("- —/~|┆·");var ze;!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"}(ze||(ze={}));const{Letter:Ue,Single:Ye,Before:Ne,After:Ge,Symbol:je,Break:Xe}=ze;function qe(t){return De[t]?Ue:Ve[t]?Xe:Ie[t]?Ne:Pe[t]?Ge:Fe[t]?je:Te.test(t)?Ye:Ue}const He={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 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:Je}=He,{Letter:Ze,Single:$e,Before:Ke,After:ti,Symbol:ei,Break:ii}=ze;let ni,si,oi,ai,ri,di,li,ci,hi,ui,fi,pi,gi,_i,wi,yi,mi=[];function vi(t,e){hi&&!ci&&(ci=hi),ni.data.push({char:t,width:e}),oi+=e}function xi(){ai+=oi,ni.width=oi,si.words.push(ni),ni={data:[]},oi=0}function bi(){_i&&(wi.paraNumber++,si.paraStart=!0,_i=!1),hi&&(si.startCharSize=ci,si.endCharSize=hi,ci=0),si.width=ai,yi.width&&Je(si),mi.push(si),si={words:[]},ai=0}const Bi=0,Ri=1,ki=2;const{top:Ei,right:Si,bottom:Li,left:Ai}=O;function Oi(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 Wi={getDrawData:function(t,e){"string"!=typeof t&&(t=String(t));let n=0,s=0,o=e.__getInput("width")||0,a=e.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=e;l&&(o&&(n=l[Ai],o-=l[Si]+l[Ai]),a&&(s=l[Ei],a-=l[Ei]+l[Li]));const c={bounds:{x:n,y:s,width:o,height:a},rows:[],paraNumber:0,font:i.canvas.font=d};return function(t,e,n){wi=t,mi=t.rows,yi=t.bounds;const{__letterSpacing:s,paraIndent:o,textCase:a}=n,{canvas:r}=i,{width:d,height:l}=yi;if(d||l||s||"none"!==a){const t="none"!==n.textWrap,i="break"===n.textWrap;_i=!0,fi=null,ci=li=hi=oi=ai=0,ni={data:[]},si={words:[]};for(let n=0,l=e.length;n<l;n++)di=e[n],"\n"===di?(oi&&xi(),si.paraEnd=!0,bi(),_i=!0):(ui=qe(di),ui===Ze&&"none"!==a&&(di=Qe(di,a,!oi)),li=r.measureText(di).width,s&&(s<0&&(hi=li),li+=s),pi=ui===$e&&(fi===$e||fi===Ze)||fi===$e&&ui!==ti,gi=!(ui!==Ke&&ui!==$e||fi!==ei&&fi!==ti),ri=_i&&o?d-o:d,t&&d&&ai+oi+li>ri&&(i?(oi&&xi(),ai&&bi()):(gi||(gi=ui===Ze&&fi==ti),pi||gi||ui===ii||ui===Ke||ui===$e||oi+li>ri?(oi&&xi(),ai&&bi()):ai&&bi()))," "===di&&!0!==_i&&ai+oi===0||(ui===ii?(" "===di&&oi&&xi(),vi(di,li),xi()):pi||gi?(oi&&xi(),vi(di,li)):vi(di,li)),fi=ui);oi&&xi(),ai&&bi(),mi.length>0&&(mi[mi.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{wi.paraNumber++,mi.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(c,t,e),l&&function(t,e,i,n,s){if(!n)switch(i.textAlign){case"left":Oi(e,"x",t[Ai]);break;case"right":Oi(e,"x",-t[Si])}if(!s)switch(i.verticalAlign){case"top":Oi(e,"y",t[Ei]);break;case"bottom":Oi(e,"y",-t[Li])}}(l,c,e,o,a),function(t,e){const{rows:i,bounds:n}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:c}=e;let h,u,f,{x:p,y:g,width:_,height:w}=n,y=s*i.length+(c?c*(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++){if(h=i[o],h.x=p,h.width<_||h.width>_&&!r)switch(d){case"center":h.x+=(_-h.width)/2;break;case"right":h.x+=_-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<n.x&&(n.x=u),f>n.width&&(n.width=f),r&&_&&_<f&&(h.isOverflow=!0,t.overflow||(t.overflow=i.length))}n.y=g,n.height=y}(c,e),function(t,e,i,n){const{rows:s}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,l,c,h,u;s.forEach((t=>{t.words&&(c=a&&t.paraStart?a:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-c)/(t.words.length-1):0,h=r||t.isOverflow?Bi:l>.01?Ri:ki,t.isOverflow&&!r&&(t.textMode=!0),h===ki?(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===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),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,i,n){return t.forEach((t=>{(n||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(c,e,o),c.overflow&&function(t,e,n,s){if(!s)return;const{rows:o,overflow:a}=t;let{textOverflow:r}=e;if(o.splice(a),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?i.canvas.measureText(r).width:0,c=n+s-l;("none"===e.textWrap?o:[o[a-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let n=i;n>-1&&(t=e.data[n],d=t.x+t.width,!(n===i&&d<c));n--){if(d<c&&" "!==t.char){e.data.splice(n+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:r,x:d}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(c,e,n,o),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(c,e),c}};const 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:Ti,addPoint:Mi,toBounds:Di}=W;const Ii={export(t,e,n){this.running=!0;const s=l.fileType(e);return n=l.getExportOptions(n),function(t){Pi||(Pi=new C);return new Promise((e=>{Pi.add((()=>$t(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((o=>new Promise((a=>{const d=t=>{o(t),a(),this.running=!1},{toURL:c}=i,{download:h}=i.origin;if("json"===e)return d({data:t.toJSON(n.json)});if("json"===s)return h(c(JSON.stringify(t.toJSON(n.json)),"text"),e),d({data:!0});if("svg"===e)return d({data:t.toSVG()});if("svg"===s)return h(c(t.toSVG(),"svg"),e),d({data:!0});const{leafer:u}=t;u?(Fi(t),u.waitViewCompleted((()=>$t(this,void 0,void 0,(function*(){let i,s,o=1,a=1;const{worldTransform:c,isLeafer:h,isFrame:f}=t,{slice:p,trim:g,onCanvas:_}=n;let y=n.scale||1,m=n.pixelRatio||1;const v=void 0===n.smooth?u.config.smooth:n.smooth,x=n.contextSettings||u.config.contextSettings;t.isApp&&(y*=m,m=t.app.pixelRatio);const b=n.screenshot||t.isApp,B=h&&b&&void 0===n.fill?t.fill:n.fill,R=l.isOpaqueImage(e)||B,k=new T;if(b)i=!0===b?h?u.canvas.bounds:t.worldRenderBounds:b;else{let e=n.relative||(h?"inner":"local");switch(o=c.scaleX,a=c.scaleY,e){case"inner":k.set(c);break;case"local":k.set(c).divide(t.localTransform),o/=t.scaleX,a/=t.scaleY;break;case"world":o=1,a=1;break;case"page":e=t.leafer;default:k.set(c).divide(t.getTransform(e));const i=e.worldTransform;o/=o/i.scaleX,a/=a/i.scaleY}i=t.getBounds("render",e)}const{x:E,y:S,width:L,height:A}=new w(i).scale(y);let O=r.canvas({width:Math.round(L),height:Math.round(A),pixelRatio:m,smooth:v,contextSettings:x});const W={matrix:k.scale(1/y).invert().translate(-E,-S).withScale(1/o*y,1/a*y)};if(p&&(t=u,W.bounds=O.bounds),O.save(),f&&void 0!==B){const e=t.get("fill");t.fill="",t.__render(O,W),t.fill=e}else t.__render(O,W);if(O.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?Mi(a,s,o):Ti(a={},s,o)),r++;const d=new w;return Di(a,d),d.scale(1/t.pixelRatio).ceil()}(O);const t=O,{width:e,height:i}=s,n={x:0,y:0,width:e,height:i,pixelRatio:m};O=r.canvas(n),O.copyWorld(t,s,n)}R&&O.fillWorld(O.bounds,B||"#FFFFFF","destination-over"),_&&_(O);const C="canvas"===e?O:yield O.export(e,n);d({data:C,width:O.pixelWidth,height:O.pixelHeight,renderBounds:i,trimBounds:s})}))))):d({data:!1})}))))}};let Pi;function Fi(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Fi(t)))}const Vi=e.prototype,zi=t.get("@leafer-ui/export");Vi.export=function(t,e){const{quality:i,blob:n}=l.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):n?this.toBlob(t,i):this.toDataURL(t,i)},Vi.toBlob=function(t,e){return new Promise((n=>{i.origin.canvasToBolb(this.view,t,e).then((t=>{n(t)})).catch((t=>{zi.error(t),n(null)}))}))},Vi.toDataURL=function(t,e){return i.origin.canvasToDataURL(this.view,t,e)},Vi.saveAs=function(t,e){return new Promise((n=>{i.origin.canvasSaveAs(this.view,t,e).then((()=>{n(!0)})).catch((t=>{zi.error(t),n(!1)}))}))},Object.assign(V,Wi),Object.assign(D,Ci),Object.assign(z,vt),Object.assign(M,te),Object.assign(I,ye),Object.assign(U,Ee),Object.assign(P,Ii),X();export{at as Layouter,N as LeaferCanvas,dt as Renderer,H as Watcher,X as useCanvas};
|
|
1
|
+
import{Debug as t,LeaferCanvasBase as e,Platform as i,DataHelper as n,canvasSizeAttrs as s,ResizeEvent as o,canvasPatch as a,Creator as r,LeaferImage as d,defineKey as l,FileHelper as c,LeafList as h,RenderEvent as u,ChildEvent as f,WatchEvent as p,PropertyEvent as g,LeafHelper as _,BranchHelper as w,Bounds as y,LeafBoundsHelper as m,LeafLevelList as v,LayoutEvent as x,Run as b,ImageManager as B,AnimateEvent as R,BoundsHelper as k,MatrixHelper as E,MathHelper as S,AlignHelper as L,ImageEvent as A,AroundHelper as O,PointHelper as W,Direction4 as C,TwoPointBoundsHelper as T,TaskProcessor as M,Matrix as D}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as I,ColorConvert as P,PaintGradient as F,Export as z,Group as V,TextConvert as Y,Paint as U,Effect as X}from"@leafer-ui/draw";export*from"@leafer-ui/draw";const N=t.get("LeaferCanvas");class G extends e{set zIndex(t){const{style:e}=this.view;e.zIndex=t,this.setAbsolute(this.view)}set childIndex(t){const{view:e,parentView:i}=this;if(e&&i){const n=i.children[t];n?(this.setAbsolute(n),i.insertBefore(e,n)):i.appendChild(n)}}init(){const{config:t}=this,e=t.view||t.canvas;e?this.__createViewFrom(e):this.__createView();const{style:n}=this.view;if(n.display||(n.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}i.syncDomFont&&!this.parentView&&(n.display="none",document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(t)}set backgroundColor(t){this.view.style.backgroundColor=t}get backgroundColor(){return this.view.style.backgroundColor}set hittable(t){this.view.style.pointerEvents=t?"auto":"none"}get hittable(){return"none"!==this.view.style.pointerEvents}__createView(){this.view=document.createElement("canvas")}__createViewFrom(t){let e="string"==typeof t?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;t.hasChildNodes()&&(this.setAbsolute(i),t.style.position||(t.style.position="relative")),t.appendChild(i)}else N.error(`no id: ${t}`),this.__createView()}setAbsolute(t){const{style:e}=t;e.position="absolute",e.top=e.left="0px"}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:n}=this.view;n.width=t+"px",n.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.clientBounds=this.view.getBoundingClientRect()}startAutoLayout(t,e){if(this.resizeListener=e,t){this.autoBounds=t;try{this.resizeObserver=new ResizeObserver((t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)}));const t=this.parentView;t?(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect())):(this.checkAutoBounds(this.view),N.warn("no parent"))}catch(t){this.imitateResizeObserver()}}else window.addEventListener("resize",(()=>{const t=i.devicePixelRatio;if(this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}}))}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(t){const e=this.view,{x:n,y:s,width:o,height:a}=this.autoBounds.getBoundsFrom(t),r={width:o,height:a,pixelRatio:i.devicePixelRatio};if(!this.isSameSize(r)){const{style:t}=e;t.marginLeft=n+"px",t.marginTop=s+"px",this.emitResize(r)}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}emitResize(t){const e={};n.copyAttrs(e,this,s),this.resize(t),void 0!==this.width&&this.resizeListener(new o(t,e))}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}a(CanvasRenderingContext2D.prototype),a(Path2D.prototype);const{mineType:j,fileType:q}=c;function H(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>t.toDataURL(j(e),i),canvasToBolb:(t,e,i)=>new Promise((n=>t.toBlob(n,j(e),i))),canvasSaveAs:(t,e,n)=>{const s=t.toDataURL(j(q(e)),n);return i.origin.download(s,e)},download:(t,e)=>new Promise((i=>{let n=document.createElement("a");n.href=t,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),i()})),loadImage:t=>new Promise(((e,n)=>{const s=new Image,{crossOrigin:o}=i.image;o&&(s.setAttribute("crossOrigin",o),s.crossOrigin=o),s.onload=()=>{e(s)},s.onerror=t=>{n(t)},s.src=i.image.getRealURL(t)}))},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=r.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(r,{canvas:(t,e)=>new G(t,e),image:t=>new d(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},l(i,"devicePixelRatio",{get:()=>Math.max(1,devicePixelRatio)});const{userAgent:Q}=navigator;Q.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):Q.indexOf("Safari")>-1&&-1===Q.indexOf("Chrome")&&(i.fullImageShadow=!0),Q.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):Q.indexOf("Mac")>-1?i.os="Mac":Q.indexOf("Linux")>-1&&(i.os="Linux");class J{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new h;return this.__updatedList.list.forEach((e=>{e.leafer&&t.add(e)})),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new h,this.target=t,e&&(this.config=n.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(u.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===f.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new p(p.DATA,{updatedList:this.updatedList})),this.__updatedList=new h,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(g.CHANGE,this.__onAttrChange,this),t.on_([f.ADD,f.REMOVE],this.__onChildEvent,this),t.on_(p.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:Z,updateBounds:$,updateAllWorldOpacity:K}=_,{pushAllChildBranch:tt,pushAllParent:et}=w;const{worldBounds:it}=m,nt={x:0,y:0,width:1e5,height:1e5};class st{constructor(t){this.updatedBounds=new y,this.beforeBounds=new y,this.afterBounds=new y,t instanceof Array&&(t=new h(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,it)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(nt):this.afterBounds.setListWithFn(t,it),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:ot,updateAllChange:at}=_,rt=t.get("Layouter");class dt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new v,this.target=t,e&&(this.config=n.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(x.START),this.layoutOnce(),t.emitEvent(new x(x.END,this.layoutedBlocks,this.times))}catch(t){rt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?rt.warn("layouting"):this.times>3?rt.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(p.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=b.start("PartLayout"),{target:i,__updatedList:n}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=x,r=this.getBlocks(n);r.forEach((t=>t.setBefore())),i.emitEvent(new x(s,r,this.times)),this.extraBlock=null,n.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(Z(t,!0),e.add(t),t.isBranch&&tt(t,e),et(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),et(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||$(n[t])}$(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&K(t),t.__updateChange()}))}(n),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new x(o,r,this.times)),i.emitEvent(new x(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,b.end(e)}fullLayout(){const t=b.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:n,AFTER:s}=x,o=this.getBlocks(new h(e));e.emitEvent(new x(i,o,this.times)),dt.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new x(n,o,this.times)),e.emitEvent(new x(s,o,this.times)),this.addBlocks(o),b.end(t)}static fullLayout(t){ot(t,!0),t.isBranch?w.updateBounds(t):_.updateBounds(t),at(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new st([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new st(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(x.REQUEST,this.layout,this),t.on_(x.AGAIN,this.layoutAgain,this),t.on_(p.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const lt=t.get("Renderer");class ct{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=n.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(x.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new y,lt.log(e.innerName,"---\x3e");try{this.emitRender(u.START),this.renderOnce(t),this.emitRender(u.END,this.totalBounds),B.clearRecycled()}catch(t){this.rendering=!1,lt.error(t)}lt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return lt.warn("rendering");if(this.times>3)return lt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new y,this.renderOptions={},t)this.emitRender(u.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(u.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(u.RENDER,this.renderBounds,this.renderOptions),this.emitRender(u.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return lt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const i=b.start("PartRender"),{canvas:n}=this,s=e.getIntersect(n.bounds),o=e.includes(this.target.__world),a=new y(s);n.save(),o&&!t.showRepaint?n.clear():(s.spread(10+1/this.canvas.pixelRatio).ceil(),n.clearWorld(s,!0),n.clipWorld(s,!0)),this.__render(s,o,a),n.restore(),b.end(i)}fullRender(){const t=b.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),b.end(t)}__render(e,i,n){const s=e.includes(this.target.__world)?{includes:i}:{bounds:e,includes:i};this.needFill&&this.canvas.fillWorld(e,this.config.fill),t.showRepaint&&this.canvas.strokeWorld(e,"red"),this.target.__render(this.canvas,s),this.renderBounds=n=n||e,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=n:this.totalBounds.add(n),t.showHitView&&this.renderHitView(s),t.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender(n)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new y;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();i.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(R.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(u.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new y(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new y(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||lt.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new u(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.REQUEST,this.update,this),t.on_(x.END,this.__onLayoutEnd,this),t.on_(u.AGAIN,this.renderAgain,this),t.on_(o.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}function ht(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 ut(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?gt(t,!0,e,i):pt(e,i);break;case"inside":ft("inside",t,s,e,i);break;case"outside":ft("outside",t,s,e,i)}}function ft(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?gt(e,!0,n,r):pt(n,r),r.blendMode="outside"===t?"destination-out":"destination-in",ht(n,r),r.blendMode="normal",n.__worldFlipped?s.copyWorldByReset(r,n.__nowWorld):s.copyWorldToInner(r,n.__nowWorld,n.__layout.renderBounds),r.recycle(n.__nowWorld)}function pt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),s&&e.strokeRect(i.x,i.y+s,i.width,o)}function gt(t,e,i,n){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&I.checkImage(i,n,s,!1)||s.style&&(n.strokeStyle=s.style,s.blendMode?(n.saveBlendMode(s.blendMode),e?pt(i,n):n.stroke(),n.restoreBlendMode()):e?pt(i,n):n.stroke())}Object.assign(r,{watcher:(t,e)=>new J(t,e),layouter:(t,e)=>new dt(t,e),renderer:(t,e,i)=>new ct(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,n)=>{}}),i.layout=dt.fullLayout;const{getSpread:_t,getOuterOf:wt,getByMove:yt,getIntersectData:mt}=k;let vt;function xt(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:P.string(a,r)};case"image":return I.image(i,t,e,n,!vt||!vt[e.url]);case"linear":return F.linearGradient(e,n);case"radial":return F.radialGradient(e,n);case"angular":return F.conicGradient(e,n);default:return void 0!==e.r?{type:"solid",style:P.string(e)}:void 0}}const bt={compute:function(t,e){const i=e.__,n=[];let s,o=i.__input[t];o instanceof Array||(o=[o]),vt=I.recycleImage(t,i);for(let i,s=0,a=o.length;s<a;s++)i=xt(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?ht(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&&I.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?ht(e,i):s?i.fill(s):i.fill(),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),o?ht(e,i):s?i.fill(s):i.fill(),i.restoreBlendMode()):o?ht(e,i):s?i.fill(s):i.fill())},fillText:ht,stroke:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)ut(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)ut(t,e,i);else switch(o){case"center":i.setStroke(void 0,s,n),gt(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),gt(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),gt(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:ut,drawTextStroke:pt,shape:function(t,e,i){const n=e.getSameCanvas(),s=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:c}=s;if(l<0&&(l=-l),c<0&&(c=-c),e.bounds.includes(s))d=n,o=r=s;else{const{renderShapeSpread:n}=t.__layout,h=mt(n?_t(e.bounds,l===c?n*l:[n*c,n*l]):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,c*=f),r=wt(s,a),o=yt(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(n,i),{canvas:n,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:c}}};let Bt={};const{get:Rt,rotateOfOuter:kt,translate:Et,scaleOfOuter:St,scale:Lt,rotate:At}=E;function Ot(t,e,i,n,s,o,a){const r=Rt();Et(r,e.x+i,e.y+n),Lt(r,s,o),a&&kt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Wt(t,e,i,n,s,o,a){const r=Rt();Et(r,e.x+i,e.y+n),s&&Lt(r,s,o),a&&At(r,a),t.transform=r}function Ct(t,e,i,n,s,o,a,r,d,l){const c=Rt();if(d)if("center"===l)kt(c,{x:i/2,y:n/2},d);else switch(At(c,d),d){case 90:Et(c,n,0);break;case 180:Et(c,i,n);break;case 270:Et(c,0,i)}Bt.x=e.x+s,Bt.y=e.y+o,Et(c,Bt.x,Bt.y),a&&St(c,Bt,a,r),t.transform=c}const{get:Tt,translate:Mt}=E,Dt=new y,It={},Pt={};function Ft(t,e,i,n){const{blendMode:s,sync:o}=i;s&&(t.blendMode=s),o&&(t.sync=o),t.data=zt(i,n,e)}function zt(t,e,i){let{width:n,height:s}=i;t.padding&&(e=Dt.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===n&&e.height===s,p={mode:a},g="center"!==r&&(h||0)%180==90,_=g?s:n,w=g?n:s;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)(l||c)&&(S.getScaleData(l,c,i,Pt),y=Pt.scaleX,m=Pt.scaleY);else if(!f||h){const t=e.width/_,i=e.height/w;y=m="fit"===a?Math.min(t,i):Math.max(t,i),v+=(e.width-n*y)/2,x+=(e.height-s*m)/2}if(r){const t={x:v,y:x,width:_,height:w};y&&(t.width*=y,t.height*=m),L.toPoint(r,t,e,It,!0),v+=It.x,x+=It.y}switch(d&&(v+=d.x,x+=d.y),a){case"strench":f||(n=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||h)&&Wt(p,e,v,x,y,m,h);break;case"repeat":(!f||y||h)&&Ct(p,e,n,s,v,x,y,m,h,r),u||(p.repeat="repeat");break;default:y&&Ot(p,e,v,x,y,m,h)}return p.transform||(e.x||e.y)&&(p.transform=Tt(),Mt(p.transform,e.x,e.y)),y&&"strench"!==a&&(p.scaleX=y,p.scaleY=m),p.width=n,p.height=s,o&&(p.opacity=o),u&&(p.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),p}let Vt,Yt=new y;const{isSame:Ut}=k;function Xt(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||Ft(s,n,i,o),!0}function Nt(t,e){qt(t,A.LOAD,e)}function Gt(t,e){qt(t,A.LOADED,e)}function jt(t,e,i){e.error=i,t.forceUpdate("surface"),qt(t,A.ERROR,e)}function qt(t,e,i){t.hasEvent(e)&&t.emitEvent(new A(e,i))}function Ht(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:Qt,scale:Jt,copy:Zt}=E,{ceil:$t,abs:Kt}=Math;function te(t,e,n){let{scaleX:s,scaleY:o}=B.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o;if(e.patternId===a||t.destroyed)return!1;{s=Kt(s),o=Kt(o);const{image:t,data:r}=e;let d,l,{width:c,height:h,scaleX:u,scaleY:f,opacity:p,transform:g,repeat:_}=r;u&&(l=Qt(),Zt(l,g),Jt(l,1/u,1/f),s*=u,o*=f),s*=n,o*=n,c*=s,h*=o;const w=c*h;if(!_&&w>i.image.maxCacheSize)return!1;let y=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(s/=d,o/=d,c/=d,h/=d),u&&(s/=u,o/=f),(g||1!==s||1!==o)&&(l||(l=Qt(),g&&Zt(l,g)),Jt(l,1/s,1/o));const m=t.getCanvas($t(c)||1,$t(h)||1,p),v=t.getPattern(m,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=v,e.patternId=a,!0}}function ee(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:ie}=Math;const ne={image:function(t,e,i,n,s){let o,a;const r=B.get(i);return Vt&&i===Vt.paint&&Ut(n,Vt.boxBounds)?o=Vt.leafPaint:(o={type:i.type,image:r},Vt=r.use>1?{leafPaint:o,paint:i,boxBounds:Yt.set(n)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Xt(t,e,i,r,o,n),s&&(Nt(t,a),Gt(t,a))):r.error?s&&jt(t,a,r.error):(Ht(t,!0),s&&Nt(t,a),o.loadId=r.load((()=>{Ht(t,!1),t.destroyed||(Xt(t,e,i,r,o,n)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Gt(t,a)),o.loadId=null}),(e=>{Ht(t,!1),jt(t,a,e),o.loadId=null}))),o},checkImage:function(t,e,n,s){const{scaleX:o,scaleY:a}=B.patternLocked?t.__world:t.__nowWorld;if(!n.data||n.patternId===o+"-"+a&&!z.running)return!1;{const{data:r}=n;if(s)if(r.repeat)s=!1;else{let{width:t,height:n}=r;t*=ie(o)*e.pixelRatio,n*=ie(a)*e.pixelRatio,r.scaleX&&(t*=r.scaleX,n*=r.scaleY),s=t*n>i.image.maxCacheSize||z.running}return s?(e.save(),e.clip(),n.blendMode&&(e.blendMode=n.blendMode),r.opacity&&(e.opacity*=r.opacity),r.transform&&e.transform(r.transform),e.drawImage(n.image.view,0,0,r.width,r.height),e.restore(),!0):(!n.style||n.sync||z.running?te(t,n,e.pixelRatio):n.patternTask||(n.patternTask=B.patternTasker.add((()=>ee(this,void 0,void 0,(function*(){n.patternTask=null,e.bounds.hit(t.__nowWorld)&&te(t,n,e.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}},createPattern:te,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let n,s,o,a;for(let r=0,d=i.length;r<d;r++)n=i[r].image,a=n&&n.url,a&&(s||(s={}),s[a]=!0,B.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),n.unload(i[r].loadId,!o.some((t=>t.url===a)))));return s}return null},createData:Ft,getPatternData:zt,fillOrFitMode:Ot,clipMode:Wt,repeatMode:Ct},{toPoint:se}=O,oe={},ae={};function re(t,e,i){let n;for(let s=0,o=e.length;s<o;s++)n=e[s],"string"==typeof n?t.addColorStop(s/(o-1),P.string(n,i)):t.addColorStop(n.offset,P.string(n.color,i))}const{getAngle:de,getDistance:le}=W,{get:ce,rotateOfOuter:he,scaleOfOuter:ue}=E,{toPoint:fe}=O,pe={},ge={};function _e(t,e,i,n,s){let o;const{width:a,height:r}=t;if(a!==r||n){const t=de(e,i);o=ce(),s?(ue(o,e,a/r*(n||1),1),he(o,e,t+90)):(ue(o,e,1,a/r*(n||1)),he(o,e,t))}return o}const{getDistance:we}=W,{toPoint:ye}=O,me={},ve={};const xe={linearGradient:function(t,e){let{from:n,to:s,type:o,blendMode:a,opacity:r}=t;se(n||"top",e,oe),se(s||"bottom",e,ae);const d=i.canvas.createLinearGradient(oe.x,oe.y,ae.x,ae.y);re(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,e){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;fe(n||"center",e,pe),fe(s||"bottom",e,ge);const l=i.canvas.createRadialGradient(pe.x,pe.y,0,pe.x,pe.y,le(pe,ge));re(l,t.stops,a);const c={type:o,style:l},h=_e(e,pe,ge,d,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(t,e){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;ye(n||"center",e,me),ye(s||"bottom",e,ve);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,me.x,me.y):i.canvas.createRadialGradient(me.x,me.y,0,me.x,me.y,we(me,ve));re(l,t.stops,a);const c={type:o,style:l},h=_e(e,me,ve,d||1,i.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:_e},{copy:be,toOffsetOutBounds:Be}=k,Re={},ke={};function Ee(t,e,n,s){const{bounds:o,shapeBounds:a}=s;if(i.fullImageShadow){if(be(Re,t.bounds),Re.x+=e.x-a.x,Re.y+=e.y-a.y,n){const{matrix:t}=s;Re.x-=(o.x+(t?t.e:0)+o.width/2)*(n-1),Re.y-=(o.y+(t?t.f:0)+o.height/2)*(n-1),Re.width*=n,Re.height*=n}t.copyWorld(s.canvas,t.bounds,Re)}else n&&(be(Re,e),Re.x-=e.width/2*(n-1),Re.y-=e.height/2*(n-1),Re.width*=n,Re.height*=n),t.copyWorld(s.canvas,a,n?Re:e)}const{toOffsetOutBounds:Se}=k,Le={};const Ae={shadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Be(l,ke),r.forEach(((r,g)=>{f.setWorldShadow(ke.offsetX+r.x*h,ke.offsetY+r.y*u,r.blur*h,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Ee(f,ke,s,i),n=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),n=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(i.canvas,c,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),p&&g<p&&f.clearWorld(n,!0)})),f.recycle(n)},innerShadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Se(l,Le),r.forEach(((r,g)=>{f.save(),f.setWorldShadow(Le.offsetX+r.x*h,Le.offsetY+r.y*u,r.blur*h),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Ee(f,Le,s,i),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),n=o):(f.copyWorld(i.canvas,c,l,"source-out"),n=l),f.fillWorld(n,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),p&&g<p&&f.clearWorld(n,!0)})),f.recycle(n)},blur:function(t,e,i){const{blur:n}=t.__;i.setWorldBlur(n*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Oe}=m;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 Ce(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)}V.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.__.mask?(i.opacity<1?(a="opacity-path",o=i.opacity,s||(s=Ce(t))):(a="path",t.save()),i.__clip(s||t,e)):(a="alpha",n||(n=Ce(t)),s||(s=Ce(t)),i.__render(n,e)),"clipping"!==i.__.mask)||Oe(i,e)||i.__render(s||t,e);We(this,a,t,s,n,o)};const Me=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",De=Me+"_#~&*+\\=|≮≯≈≠=…",Ie=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 Pe(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Fe=Pe("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ze=Pe("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Ve=Pe(Me),Ye=Pe(De),Ue=Pe("- —/~|┆·");var Xe;!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"}(Xe||(Xe={}));const{Letter:Ne,Single:Ge,Before:je,After:qe,Symbol:He,Break:Qe}=Xe;function Je(t){return Fe[t]?Ne:Ue[t]?Qe:ze[t]?je:Ve[t]?qe:Ye[t]?He:Ie.test(t)?Ge:Ne}const Ze={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 $e(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:Ke}=Ze,{Letter:ti,Single:ei,Before:ii,After:ni,Symbol:si,Break:oi}=Xe;let ai,ri,di,li,ci,hi,ui,fi,pi,gi,_i,wi,yi,mi,vi,xi,bi=[];function Bi(t,e){pi&&!fi&&(fi=pi),ai.data.push({char:t,width:e}),di+=e}function Ri(){li+=di,ai.width=di,ri.words.push(ai),ai={data:[]},di=0}function ki(){mi&&(vi.paraNumber++,ri.paraStart=!0,mi=!1),pi&&(ri.startCharSize=fi,ri.endCharSize=pi,fi=0),ri.width=li,xi.width&&Ke(ri),bi.push(ri),ri={words:[]},li=0}const Ei=0,Si=1,Li=2;const{top:Ai,right:Oi,bottom:Wi,left:Ci}=C;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,e){"string"!=typeof t&&(t=String(t));let n=0,s=0,o=e.__getInput("width")||0,a=e.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=e;l&&(o&&(n=l[Ci],o-=l[Oi]+l[Ci]),a&&(s=l[Ai],a-=l[Ai]+l[Wi]));const c={bounds:{x:n,y:s,width:o,height:a},rows:[],paraNumber:0,font:i.canvas.font=d};return function(t,e,n){vi=t,bi=t.rows,xi=t.bounds;const{__letterSpacing:s,paraIndent:o,textCase:a}=n,{canvas:r}=i,{width:d,height:l}=xi;if(d||l||s||"none"!==a){const t="none"!==n.textWrap,i="break"===n.textWrap;mi=!0,_i=null,fi=ui=pi=di=li=0,ai={data:[]},ri={words:[]};for(let n=0,l=e.length;n<l;n++)hi=e[n],"\n"===hi?(di&&Ri(),ri.paraEnd=!0,ki(),mi=!0):(gi=Je(hi),gi===ti&&"none"!==a&&(hi=$e(hi,a,!di)),ui=r.measureText(hi).width,s&&(s<0&&(pi=ui),ui+=s),wi=gi===ei&&(_i===ei||_i===ti)||_i===ei&&gi!==ni,yi=!(gi!==ii&&gi!==ei||_i!==si&&_i!==ni),ci=mi&&o?d-o:d,t&&d&&li+di+ui>ci&&(i?(di&&Ri(),li&&ki()):(yi||(yi=gi===ti&&_i==ni),wi||yi||gi===oi||gi===ii||gi===ei||di+ui>ci?(di&&Ri(),li&&ki()):li&&ki()))," "===hi&&!0!==mi&&li+di===0||(gi===oi?(" "===hi&&di&&Ri(),Bi(hi,ui),Ri()):wi||yi?(di&&Ri(),Bi(hi,ui)):Bi(hi,ui)),_i=gi);di&&Ri(),li&&ki(),bi.length>0&&(bi[bi.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{vi.paraNumber++,bi.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(c,t,e),l&&function(t,e,i,n,s){if(!n)switch(i.textAlign){case"left":Ti(e,"x",t[Ci]);break;case"right":Ti(e,"x",-t[Oi])}if(!s)switch(i.verticalAlign){case"top":Ti(e,"y",t[Ai]);break;case"bottom":Ti(e,"y",-t[Wi])}}(l,c,e,o,a),function(t,e){const{rows:i,bounds:n}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:c}=e;let h,u,f,{x:p,y:g,width:_,height:w}=n,y=s*i.length+(c?c*(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++){if(h=i[o],h.x=p,h.width<_||h.width>_&&!r)switch(d){case"center":h.x+=(_-h.width)/2;break;case"right":h.x+=_-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<n.x&&(n.x=u),f>n.width&&(n.width=f),r&&_&&_<f&&(h.isOverflow=!0,t.overflow||(t.overflow=i.length))}n.y=g,n.height=y}(c,e),function(t,e,i,n){const{rows:s}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,l,c,h,u;s.forEach((t=>{t.words&&(c=a&&t.paraStart?a:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-c)/(t.words.length-1):0,h=r||t.isOverflow?Ei:l>.01?Si:Li,t.isOverflow&&!r&&(t.textMode=!0),h===Li?(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===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),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,i,n){return t.forEach((t=>{(n||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(c,e,o),c.overflow&&function(t,e,n,s){if(!s)return;const{rows:o,overflow:a}=t;let{textOverflow:r}=e;if(o.splice(a),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?i.canvas.measureText(r).width:0,c=n+s-l;("none"===e.textWrap?o:[o[a-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let n=i;n>-1&&(t=e.data[n],d=t.x+t.width,!(n===i&&d<c));n--){if(d<c&&" "!==t.char){e.data.splice(n+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:r,x:d}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(c,e,n,o),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(c,e),c}};const Di={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:Ii,addPoint:Pi,toBounds:Fi}=T;const zi={export(t,e,n){this.running=!0;const s=c.fileType(e),o=e.includes(".");return n=c.getExportOptions(n),function(t){Vi||(Vi=new M);return new Promise((e=>{Vi.add((()=>ee(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((a=>new Promise((d=>{const l=t=>{a(t),d(),this.running=!1},{toURL:h}=i,{download:u}=i.origin;if("json"===s)return o&&u(h(JSON.stringify(t.toJSON(n.json)),"text"),e),l({data:!!o||t.toJSON(n.json)});if("svg"===s)return o&&u(h(t.toSVG(),"svg"),e),l({data:!!o||t.toSVG()});const{leafer:f}=t;f?(Yi(t),f.waitViewCompleted((()=>ee(this,void 0,void 0,(function*(){let i,s,o=1,a=1;const{worldTransform:d,isLeafer:h,isFrame:u}=t,{slice:p,trim:g,onCanvas:_}=n,w=void 0===n.smooth?f.config.smooth:n.smooth,m=n.contextSettings||f.config.contextSettings,v=n.screenshot||t.isApp,x=h&&v&&void 0===n.fill?t.fill:n.fill,b=c.isOpaqueImage(e)||x,B=new D;if(v)i=!0===v?h?f.canvas.bounds:t.worldRenderBounds:v;else{let e=n.relative||(h?"inner":"local");switch(o=d.scaleX,a=d.scaleY,e){case"inner":B.set(d);break;case"local":B.set(d).divide(t.localTransform),o/=t.scaleX,a/=t.scaleY;break;case"world":o=1,a=1;break;case"page":e=t.leafer;default:B.set(d).divide(t.getTransform(e));const i=e.worldTransform;o/=o/i.scaleX,a/=a/i.scaleY}i=t.getBounds("render",e)}const R={scaleX:1,scaleY:1};S.getScaleData(n.scale,n.size,i,R);let k=n.pixelRatio||1;t.isApp&&(R.scaleX*=k,R.scaleY*=k,k=t.app.pixelRatio);const{x:E,y:L,width:A,height:O}=new y(i).scale(R.scaleX,R.scaleY),W={matrix:B.scale(1/R.scaleX,1/R.scaleY).invert().translate(-E,-L).withScale(1/o*R.scaleX,1/a*R.scaleY)};let C,T=r.canvas({width:Math.round(A),height:Math.round(O),pixelRatio:k,smooth:w,contextSettings:m});if(p&&(C=t,C.__worldOpacity=0,t=f,W.bounds=T.bounds),T.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(T,W),t.fill=e}else t.__render(T,W);if(T.restore(),C&&C.__updateWorldOpacity(),g){s=function(t){const{width:e,height:i}=t.view,{data:n}=t.context.getImageData(0,0,e,i);let s,o,a,r=0;for(let t=0;t<n.length;t+=4)0!==n[t+3]&&(s=r%e,o=(r-s)/e,a?Pi(a,s,o):Ii(a={},s,o)),r++;const d=new y;return Fi(a,d),d.scale(1/t.pixelRatio).ceil()}(T);const t=T,{width:e,height:i}=s,n={x:0,y:0,width:e,height:i,pixelRatio:k};T=r.canvas(n),T.copyWorld(t,s,n)}b&&T.fillWorld(T.bounds,x||"#FFFFFF","destination-over"),_&&_(T);const M="canvas"===e?T:yield T.export(e,n);l({data:M,width:T.pixelWidth,height:T.pixelHeight,renderBounds:i,trimBounds:s})}))))):l({data:!1})}))))}};let Vi;function Yi(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Yi(t)))}const Ui=e.prototype,Xi=t.get("@leafer-ui/export");Ui.export=function(t,e){const{quality:i,blob:n}=c.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):n?this.toBlob(t,i):this.toDataURL(t,i)},Ui.toBlob=function(t,e){return new Promise((n=>{i.origin.canvasToBolb(this.view,t,e).then((t=>{n(t)})).catch((t=>{Xi.error(t),n(null)}))}))},Ui.toDataURL=function(t,e){return i.origin.canvasToDataURL(this.view,t,e)},Ui.saveAs=function(t,e){return new Promise((n=>{i.origin.canvasSaveAs(this.view,t,e).then((()=>{n(!0)})).catch((t=>{Xi.error(t),n(!1)}))}))},Object.assign(Y,Mi),Object.assign(P,Di),Object.assign(U,bt),Object.assign(I,ne),Object.assign(F,xe),Object.assign(X,Ae),Object.assign(z,zi),H();export{dt as Layouter,G as LeaferCanvas,ct as Renderer,J as Watcher,H as useCanvas};
|