leafer-ui 1.0.0-rc.22 → 1.0.0-rc.24
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/README.md +1 -1
- package/dist/web.esm.js +81 -61
- package/dist/web.esm.min.js +1 -1
- package/dist/web.js +534 -346
- package/dist/web.min.js +1 -1
- package/dist/web.module.js +532 -347
- package/dist/web.module.min.js +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Leafer UI 是基于 [Leafer](https://github.com/leaferjs/leafer) 开发的一套
|
|
|
4
4
|
|
|
5
5
|
提供了常用的 UI 绘图组件,和开箱即用的功能,方便与 Figma、Sketch 等产品进行数据交换,并为跨平台开发提供了统一、丰富的交互事件,如拖拽、旋转、缩放手势等。
|
|
6
6
|
|
|
7
|
-
1.0.0-rc.
|
|
7
|
+
1.0.0-rc.24 已发布 🎉🎉🎉,查看 [更新日志](https://leaferjs.com/ui/update/)。
|
|
8
8
|
|
|
9
9
|
目前产品已经逐步稳定,正式版即将到来,感谢所有参与的朋友们~
|
|
10
10
|
|
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, Answer, MathHelper, MatrixHelper,
|
|
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, Answer, MathHelper, MatrixHelper, 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 { InteractionHelper, InteractionBase, Cursor, HitCanvasManager, Leafer } from '@leafer-ui/core';
|
|
@@ -188,7 +188,7 @@ function useCanvas(_canvasType, _power) {
|
|
|
188
188
|
}
|
|
189
189
|
img.onload = () => { resolve(img); };
|
|
190
190
|
img.onerror = (e) => { reject(e); };
|
|
191
|
-
if (!src.startsWith('data:') && !src.startsWith('blob:')
|
|
191
|
+
if (suffix && !src.startsWith('data:') && !src.startsWith('blob:'))
|
|
192
192
|
src += (src.includes("?") ? "&" : "?") + suffix;
|
|
193
193
|
img.src = src;
|
|
194
194
|
});
|
|
@@ -678,7 +678,7 @@ class Renderer {
|
|
|
678
678
|
canvas.clear();
|
|
679
679
|
}
|
|
680
680
|
else {
|
|
681
|
-
bounds.spread(
|
|
681
|
+
bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil();
|
|
682
682
|
canvas.clearWorld(bounds, true);
|
|
683
683
|
canvas.clipWorld(bounds, true);
|
|
684
684
|
}
|
|
@@ -750,8 +750,11 @@ class Renderer {
|
|
|
750
750
|
if (!bounds.includes(this.target.__world) || this.needFill || !e.samePixelRatio) {
|
|
751
751
|
this.addBlock(this.canvas.bounds);
|
|
752
752
|
this.target.forceUpdate('surface');
|
|
753
|
+
return;
|
|
753
754
|
}
|
|
754
755
|
}
|
|
756
|
+
this.addBlock(new Bounds(0, 0, 1, 1));
|
|
757
|
+
this.changed = true;
|
|
755
758
|
}
|
|
756
759
|
__onLayoutEnd(event) {
|
|
757
760
|
if (event.data)
|
|
@@ -924,6 +927,7 @@ class Picker {
|
|
|
924
927
|
}
|
|
925
928
|
|
|
926
929
|
const { Yes, NoAndSkip, YesAndSkip } = Answer;
|
|
930
|
+
const idCondition = {}, classNameCondition = {}, tagCondition = {};
|
|
927
931
|
class Selector {
|
|
928
932
|
constructor(target, userConfig) {
|
|
929
933
|
this.config = {};
|
|
@@ -933,7 +937,8 @@ class Selector {
|
|
|
933
937
|
id: (leaf, name) => leaf.id === name ? (this.idMap[name] = leaf, 1) : 0,
|
|
934
938
|
innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.innerIdMap[innerId] = leaf, 1) : 0,
|
|
935
939
|
className: (leaf, name) => leaf.className === name ? 1 : 0,
|
|
936
|
-
tag: (leaf, name) => leaf.__tag === name ? 1 : 0
|
|
940
|
+
tag: (leaf, name) => leaf.__tag === name ? 1 : 0,
|
|
941
|
+
tags: (leaf, nameMap) => nameMap[leaf.__tag] ? 1 : 0
|
|
937
942
|
};
|
|
938
943
|
this.target = target;
|
|
939
944
|
if (userConfig)
|
|
@@ -949,12 +954,25 @@ class Selector {
|
|
|
949
954
|
case 'string':
|
|
950
955
|
switch (condition[0]) {
|
|
951
956
|
case '#':
|
|
952
|
-
|
|
953
|
-
|
|
957
|
+
idCondition.id = condition.substring(1), condition = idCondition;
|
|
958
|
+
break;
|
|
954
959
|
case '.':
|
|
955
|
-
|
|
960
|
+
classNameCondition.className = condition.substring(1), condition = classNameCondition;
|
|
961
|
+
break;
|
|
956
962
|
default:
|
|
957
|
-
|
|
963
|
+
tagCondition.tag = condition, condition = tagCondition;
|
|
964
|
+
}
|
|
965
|
+
case 'object':
|
|
966
|
+
if (condition.id !== undefined) {
|
|
967
|
+
const leaf = this.getById(condition.id, branch);
|
|
968
|
+
return one ? leaf : (leaf ? [leaf] : []);
|
|
969
|
+
}
|
|
970
|
+
else if (condition.tag) {
|
|
971
|
+
const { tag } = condition, isArray = tag instanceof Array;
|
|
972
|
+
return this.getByMethod(isArray ? this.methods.tags : this.methods.tag, branch, one, isArray ? DataHelper.toMap(tag) : tag);
|
|
973
|
+
}
|
|
974
|
+
else {
|
|
975
|
+
return this.getByMethod(this.methods.className, branch, one, condition.className);
|
|
958
976
|
}
|
|
959
977
|
case 'function':
|
|
960
978
|
return this.getByMethod(condition, branch, one, options);
|
|
@@ -1179,12 +1197,6 @@ class Interaction extends InteractionBase {
|
|
|
1179
1197
|
this.windowEvents = {};
|
|
1180
1198
|
}
|
|
1181
1199
|
}
|
|
1182
|
-
getLocal(p, updateClient) {
|
|
1183
|
-
if (updateClient)
|
|
1184
|
-
this.canvas.updateClientBounds();
|
|
1185
|
-
const { clientBounds } = this.canvas;
|
|
1186
|
-
return { x: p.clientX - clientBounds.x, y: p.clientY - clientBounds.y };
|
|
1187
|
-
}
|
|
1188
1200
|
getTouches(touches) {
|
|
1189
1201
|
const list = [];
|
|
1190
1202
|
for (let i = 0, len = touches.length; i < len; i++) {
|
|
@@ -1621,7 +1633,7 @@ function shape(ui, current, options) {
|
|
|
1621
1633
|
}
|
|
1622
1634
|
else {
|
|
1623
1635
|
const { renderShapeSpread: spread } = ui.__layout;
|
|
1624
|
-
const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, spread * scaleX, spread *
|
|
1636
|
+
const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [spread * scaleY, spread * scaleX]) : current.bounds, nowWorld);
|
|
1625
1637
|
fitMatrix = current.bounds.getFitMatrix(worldClipBounds);
|
|
1626
1638
|
let { a: fitScaleX, d: fitScaleY } = fitMatrix;
|
|
1627
1639
|
if (fitMatrix.a < 1) {
|
|
@@ -1721,10 +1733,10 @@ function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
|
1721
1733
|
rotate(transform, rotation);
|
|
1722
1734
|
data.transform = transform;
|
|
1723
1735
|
}
|
|
1724
|
-
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation,
|
|
1736
|
+
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
|
|
1725
1737
|
const transform = get$4();
|
|
1726
1738
|
if (rotation) {
|
|
1727
|
-
if (
|
|
1739
|
+
if (align === 'center') {
|
|
1728
1740
|
rotateOfOuter$2(transform, { x: width / 2, y: height / 2 }, rotation);
|
|
1729
1741
|
}
|
|
1730
1742
|
else {
|
|
@@ -1757,12 +1769,12 @@ function createData(leafPaint, image, paint, box) {
|
|
|
1757
1769
|
let { width, height } = image;
|
|
1758
1770
|
if (paint.padding)
|
|
1759
1771
|
box = tempBox.set(box).shrink(paint.padding);
|
|
1760
|
-
const { opacity, mode,
|
|
1772
|
+
const { opacity, mode, align, offset, scale, size, rotation, blendMode, repeat } = paint;
|
|
1761
1773
|
const sameBox = box.width === width && box.height === height;
|
|
1762
1774
|
if (blendMode)
|
|
1763
1775
|
leafPaint.blendMode = blendMode;
|
|
1764
1776
|
const data = leafPaint.data = { mode };
|
|
1765
|
-
const swapSize =
|
|
1777
|
+
const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
|
|
1766
1778
|
const swapWidth = swapSize ? height : width, swapHeight = swapSize ? width : height;
|
|
1767
1779
|
let x = 0, y = 0, scaleX, scaleY;
|
|
1768
1780
|
if (!mode || mode === 'cover' || mode === 'fit') {
|
|
@@ -1780,11 +1792,11 @@ function createData(leafPaint, image, paint, box) {
|
|
|
1780
1792
|
scaleX = typeof scale === 'number' ? scale : scale.x;
|
|
1781
1793
|
scaleY = typeof scale === 'number' ? scale : scale.y;
|
|
1782
1794
|
}
|
|
1783
|
-
if (
|
|
1795
|
+
if (align) {
|
|
1784
1796
|
const imageBounds = { x, y, width: swapWidth, height: swapHeight };
|
|
1785
1797
|
if (scaleX)
|
|
1786
1798
|
imageBounds.width *= scaleX, imageBounds.height *= scaleY;
|
|
1787
|
-
|
|
1799
|
+
AlignHelper.toPoint(align, imageBounds, box, tempPoint, true);
|
|
1788
1800
|
x += tempPoint.x, y += tempPoint.y;
|
|
1789
1801
|
}
|
|
1790
1802
|
if (offset)
|
|
@@ -1801,7 +1813,7 @@ function createData(leafPaint, image, paint, box) {
|
|
|
1801
1813
|
break;
|
|
1802
1814
|
case 'repeat':
|
|
1803
1815
|
if (!sameBox || scaleX || rotation)
|
|
1804
|
-
repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation,
|
|
1816
|
+
repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align);
|
|
1805
1817
|
if (!repeat)
|
|
1806
1818
|
data.repeat = 'repeat';
|
|
1807
1819
|
break;
|
|
@@ -2104,13 +2116,14 @@ const PaintImageModule = {
|
|
|
2104
2116
|
recycleImage
|
|
2105
2117
|
};
|
|
2106
2118
|
|
|
2107
|
-
const
|
|
2108
|
-
const
|
|
2119
|
+
const { toPoint: toPoint$2 } = AroundHelper;
|
|
2120
|
+
const realFrom$2 = {};
|
|
2121
|
+
const realTo$2 = {};
|
|
2109
2122
|
function linearGradient(paint, box) {
|
|
2110
2123
|
let { from, to, type, blendMode, opacity } = paint;
|
|
2111
|
-
from ||
|
|
2112
|
-
to ||
|
|
2113
|
-
const style = Platform.canvas.createLinearGradient(
|
|
2124
|
+
toPoint$2(from || 'top', box, realFrom$2);
|
|
2125
|
+
toPoint$2(to || 'bottom', box, realTo$2);
|
|
2126
|
+
const style = Platform.canvas.createLinearGradient(realFrom$2.x, realFrom$2.y, realTo$2.x, realTo$2.y);
|
|
2114
2127
|
applyStops(style, paint.stops, opacity);
|
|
2115
2128
|
const data = { type, style };
|
|
2116
2129
|
if (blendMode)
|
|
@@ -2121,23 +2134,25 @@ function applyStops(gradient, stops, opacity) {
|
|
|
2121
2134
|
let stop;
|
|
2122
2135
|
for (let i = 0, len = stops.length; i < len; i++) {
|
|
2123
2136
|
stop = stops[i];
|
|
2124
|
-
|
|
2137
|
+
if (typeof stop === 'string') {
|
|
2138
|
+
gradient.addColorStop(i / (len - 1), ColorConvert.string(stop, opacity));
|
|
2139
|
+
}
|
|
2140
|
+
else {
|
|
2141
|
+
gradient.addColorStop(stop.offset, ColorConvert.string(stop.color, opacity));
|
|
2142
|
+
}
|
|
2125
2143
|
}
|
|
2126
2144
|
}
|
|
2127
2145
|
|
|
2128
|
-
const {
|
|
2146
|
+
const { getAngle: getAngle$1, getDistance: getDistance$1 } = PointHelper;
|
|
2129
2147
|
const { get: get$1, rotateOfOuter: rotateOfOuter$1, scaleOfOuter: scaleOfOuter$1 } = MatrixHelper;
|
|
2130
|
-
const
|
|
2131
|
-
const defaultTo$1 = { x: 0.5, y: 1 };
|
|
2148
|
+
const { toPoint: toPoint$1 } = AroundHelper;
|
|
2132
2149
|
const realFrom$1 = {};
|
|
2133
2150
|
const realTo$1 = {};
|
|
2134
2151
|
function radialGradient(paint, box) {
|
|
2135
2152
|
let { from, to, type, opacity, blendMode, stretch } = paint;
|
|
2136
|
-
from ||
|
|
2137
|
-
to ||
|
|
2138
|
-
const {
|
|
2139
|
-
set$1(realFrom$1, x + from.x * width, y + from.y * height);
|
|
2140
|
-
set$1(realTo$1, x + to.x * width, y + to.y * height);
|
|
2153
|
+
toPoint$1(from || 'center', box, realFrom$1);
|
|
2154
|
+
toPoint$1(to || 'bottom', box, realTo$1);
|
|
2155
|
+
const { width, height } = box;
|
|
2141
2156
|
let transform;
|
|
2142
2157
|
if (width !== height || stretch) {
|
|
2143
2158
|
transform = get$1();
|
|
@@ -2152,19 +2167,16 @@ function radialGradient(paint, box) {
|
|
|
2152
2167
|
return data;
|
|
2153
2168
|
}
|
|
2154
2169
|
|
|
2155
|
-
const {
|
|
2170
|
+
const { getAngle, getDistance } = PointHelper;
|
|
2156
2171
|
const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
|
|
2157
|
-
const
|
|
2158
|
-
const defaultTo = { x: 0.5, y: 1 };
|
|
2172
|
+
const { toPoint } = AroundHelper;
|
|
2159
2173
|
const realFrom = {};
|
|
2160
2174
|
const realTo = {};
|
|
2161
2175
|
function conicGradient(paint, box) {
|
|
2162
2176
|
let { from, to, type, opacity, blendMode, stretch } = paint;
|
|
2163
|
-
from ||
|
|
2164
|
-
to ||
|
|
2165
|
-
const {
|
|
2166
|
-
set(realFrom, x + from.x * width, y + from.y * height);
|
|
2167
|
-
set(realTo, x + to.x * width, y + to.y * height);
|
|
2177
|
+
toPoint(from || 'center', box, realFrom);
|
|
2178
|
+
toPoint(to || 'bottom', box, realTo);
|
|
2179
|
+
const { width, height } = box;
|
|
2168
2180
|
const transform = get();
|
|
2169
2181
|
const angle = getAngle(realFrom, realTo);
|
|
2170
2182
|
if (Platform.conicGradientRotate90) {
|
|
@@ -2318,7 +2330,7 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
2318
2330
|
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
2319
2331
|
maskCanvas = contentCanvas = null;
|
|
2320
2332
|
}
|
|
2321
|
-
if (child.__.
|
|
2333
|
+
if (child.__.mask === 'path') {
|
|
2322
2334
|
if (child.opacity < 1) {
|
|
2323
2335
|
currentMask = 'opacity-path';
|
|
2324
2336
|
maskOpacity = child.opacity;
|
|
@@ -2339,7 +2351,7 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
2339
2351
|
contentCanvas = getCanvas(canvas);
|
|
2340
2352
|
child.__render(maskCanvas, options);
|
|
2341
2353
|
}
|
|
2342
|
-
if (child.__.
|
|
2354
|
+
if (child.__.mask !== 'clipping')
|
|
2343
2355
|
continue;
|
|
2344
2356
|
}
|
|
2345
2357
|
if (excludeRenderBounds(child, options))
|
|
@@ -2640,11 +2652,11 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
2640
2652
|
if (mode === WordMode) {
|
|
2641
2653
|
wordChar = { char: '', x: charX };
|
|
2642
2654
|
charX = toWordChar(word.data, charX, wordChar);
|
|
2643
|
-
if (wordChar.char !== ' ')
|
|
2655
|
+
if (row.isOverflow || wordChar.char !== ' ')
|
|
2644
2656
|
row.data.push(wordChar);
|
|
2645
2657
|
}
|
|
2646
2658
|
else {
|
|
2647
|
-
charX = toChar(word.data, charX, row.data);
|
|
2659
|
+
charX = toChar(word.data, charX, row.data, row.isOverflow);
|
|
2648
2660
|
}
|
|
2649
2661
|
if (!row.paraEnd && addWordWidth) {
|
|
2650
2662
|
charX += addWordWidth;
|
|
@@ -2671,9 +2683,9 @@ function toWordChar(data, charX, wordChar) {
|
|
|
2671
2683
|
});
|
|
2672
2684
|
return charX;
|
|
2673
2685
|
}
|
|
2674
|
-
function toChar(data, charX, rowData) {
|
|
2686
|
+
function toChar(data, charX, rowData, isOverflow) {
|
|
2675
2687
|
data.forEach(char => {
|
|
2676
|
-
if (char.char !== ' ') {
|
|
2688
|
+
if (isOverflow || char.char !== ' ') {
|
|
2677
2689
|
char.x = charX;
|
|
2678
2690
|
rowData.push(char);
|
|
2679
2691
|
}
|
|
@@ -2705,12 +2717,14 @@ function layoutText(drawData, style) {
|
|
|
2705
2717
|
for (let i = 0, len = rows.length; i < len; i++) {
|
|
2706
2718
|
row = rows[i];
|
|
2707
2719
|
row.x = x;
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2720
|
+
if (row.width < width || (row.width > width && !__clipText)) {
|
|
2721
|
+
switch (textAlign) {
|
|
2722
|
+
case 'center':
|
|
2723
|
+
row.x += (width - row.width) / 2;
|
|
2724
|
+
break;
|
|
2725
|
+
case 'right':
|
|
2726
|
+
row.x += width - row.width;
|
|
2727
|
+
}
|
|
2714
2728
|
}
|
|
2715
2729
|
if (row.paraStart && paraSpacing && i > 0)
|
|
2716
2730
|
starY += paraSpacing;
|
|
@@ -2750,11 +2764,13 @@ function clipText(drawData, style) {
|
|
|
2750
2764
|
const { rows, overflow } = drawData;
|
|
2751
2765
|
let { textOverflow } = style;
|
|
2752
2766
|
rows.splice(overflow);
|
|
2753
|
-
if (textOverflow !== '
|
|
2754
|
-
if (textOverflow === '
|
|
2767
|
+
if (textOverflow && textOverflow !== 'show') {
|
|
2768
|
+
if (textOverflow === 'hide')
|
|
2769
|
+
textOverflow = '';
|
|
2770
|
+
else if (textOverflow === 'ellipsis')
|
|
2755
2771
|
textOverflow = '...';
|
|
2756
2772
|
let char, charRight;
|
|
2757
|
-
const ellipsisWidth = Platform.canvas.measureText(textOverflow).width;
|
|
2773
|
+
const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0;
|
|
2758
2774
|
const right = style.x + style.width - ellipsisWidth;
|
|
2759
2775
|
const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
|
|
2760
2776
|
list.forEach(row => {
|
|
@@ -2922,8 +2938,12 @@ const ExportModule = {
|
|
|
2922
2938
|
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2923
2939
|
const { worldTransform, isLeafer, isFrame } = leaf;
|
|
2924
2940
|
const { slice, trim, onCanvas } = options;
|
|
2925
|
-
|
|
2926
|
-
|
|
2941
|
+
let scale = options.scale || 1;
|
|
2942
|
+
let pixelRatio = options.pixelRatio || 1;
|
|
2943
|
+
if (leaf.isApp) {
|
|
2944
|
+
scale *= pixelRatio;
|
|
2945
|
+
pixelRatio = leaf.app.pixelRatio;
|
|
2946
|
+
}
|
|
2927
2947
|
const screenshot = options.screenshot || leaf.isApp;
|
|
2928
2948
|
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
2929
2949
|
const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
|
package/dist/web.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Debug as t,LeaferCanvasBase as e,Platform as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,canvasPatch as r,Creator as a,LeaferImage as h,FileHelper as l,LeafList as d,RenderEvent as c,ChildEvent as u,WatchEvent as p,PropertyEvent as g,LeafHelper as f,BranchHelper as _,Bounds as w,LeafBoundsHelper as y,LeafLevelList as v,LayoutEvent as m,Run as x,ImageManager as b,AnimateEvent as B,BoundsHelper as E,Answer as L,MathHelper as R,MatrixHelper as M,AroundHelper as k,ImageEvent as T,PointHelper as S,Direction4 as C,TwoPointBoundsHelper as O,TaskProcessor as W,Matrix as P}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionHelper as A,InteractionBase as D,Cursor as I,HitCanvasManager as F,Leafer as Y}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as U,ColorConvert as G,PaintGradient as z,Export as N,Group as V,TextConvert as j,Paint as X,Effect as H}from"@leafer-ui/draw";const q=t.get("LeaferCanvas");class K extends e{init(){const{view:t}=this.config;t?this.__createViewFrom(t):this.__createView();const{style:e}=this.view;e.display||(e.display="block"),this.parentView=this.view.parentElement,this.parentView&&(this.parentView.style.userSelect="none"),i.syncDomFont&&!this.parentView&&(this.view.style.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;if(t.hasChildNodes()){const{style:e}=i;e.position="absolute",e.top=e.left="0px",t.style.position||(t.style.position="relative")}t.appendChild(i)}else q.error(`no id: ${t}`),this.__createView()}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;s.width=t+"px",s.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()))}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:r,width:a,height:h}=this.autoBounds.getBoundsFrom(t);if(a!==this.width||h!==this.height){const{style:t}=e,{pixelRatio:l}=this;t.marginLeft=i+"px",t.marginTop=r+"px";const d={width:a,height:h,pixelRatio:l},c={};s.copyAttrs(c,this,n),this.resize(d),void 0!==this.width&&this.resizeListener(new o(d,c))}}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()}}}r(CanvasRenderingContext2D.prototype),r(Path2D.prototype);const{mineType:Q,fileType:$}=l;function J(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(Q(e),i),canvasToBolb:(t,e,i)=>new Promise((s=>t.toBlob(s,Q(e),i))),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(Q($(e)),s);return i.origin.download(n,e)},download:(t,e)=>new Promise((i=>{let s=document.createElement("a");s.href=t,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),i()})),loadImage:t=>new Promise(((e,s)=>{const n=new Image,{suffix:o,crossOrigin:r}=i.image;r&&(n.setAttribute("crossOrigin",r),n.crossOrigin=r),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},t.startsWith("data:")||t.startsWith("blob:")||!o||(t+=(t.includes("?")?"&":"?")+o),n.src=t}))},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=a.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(a,{canvas:(t,e)=>new K(t,e),image:t=>new h(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},i.devicePixelRatio=Math.max(1,devicePixelRatio);const{userAgent:Z}=navigator;Z.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):Z.indexOf("Safari")>-1&&-1===Z.indexOf("Chrome")&&(i.fullImageShadow=!0),Z.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):Z.indexOf("Mac")>-1?i.os="Mac":Z.indexOf("Linux")>-1&&(i.os="Linux");class tt{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new d;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 d,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(c.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 p(p.DATA,{updatedList:this.updatedList})),this.__updatedList=new d,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_([u.ADD,u.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:et,updateBounds:it,updateAllWorldOpacity:st}=f,{pushAllChildBranch:nt,pushAllParent:ot}=_;const{worldBounds:rt}=y,at={x:0,y:0,width:1e5,height:1e5};class ht{constructor(t){this.updatedBounds=new w,this.beforeBounds=new w,this.afterBounds=new w,t instanceof Array&&(t=new d(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,rt)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(at):this.afterBounds.setListWithFn(t,rt),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:lt,updateAllChange:dt}=f,ct=t.get("Layouter");class ut{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new v,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(m.START),this.layoutOnce(),t.emitEvent(new m(m.END,this.layoutedBlocks,this.times))}catch(t){ct.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ct.warn("layouting"):this.times>3?ct.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=x.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:o,AFTER:r}=m,a=this.getBlocks(s);a.forEach((t=>t.setBefore())),i.emitEvent(new m(n,a,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?(et(t,!0),e.add(t),t.isBranch&&nt(t,e),ot(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),ot(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||it(s[t])}it(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&st(t),t.__updateChange()}))}(s),this.extraBlock&&a.push(this.extraBlock),a.forEach((t=>t.setAfter())),i.emitEvent(new m(o,a,this.times)),i.emitEvent(new m(r,a,this.times)),this.addBlocks(a),this.__levelList.reset(),this.__updatedList=null,x.end(e)}fullLayout(){const t=x.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=m,o=this.getBlocks(new d(e));e.emitEvent(new m(i,o,this.times)),ut.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new m(s,o,this.times)),e.emitEvent(new m(n,o,this.times)),this.addBlocks(o),x.end(t)}static fullLayout(t){lt(t,!0),t.isBranch?_.updateBounds(t):f.updateBounds(t),dt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new ht([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new ht(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_(m.REQUEST,this.layout,this),t.on_(m.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 pt=t.get("Renderer");class gt{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(m.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,pt.log(e.innerName,"---\x3e");try{this.emitRender(c.START),this.renderOnce(t),this.emitRender(c.END,this.totalBounds),b.clearRecycled()}catch(t){this.rendering=!1,pt.error(t)}pt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return pt.warn("rendering");if(this.times>3)return pt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new w,this.renderOptions={},t)this.emitRender(c.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(c.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(c.RENDER,this.renderBounds,this.renderOptions),this.emitRender(c.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 pt.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:s}=this,n=e.getIntersect(s.bounds),o=e.includes(this.target.__world),r=new w(n);s.save(),o&&!t.showRepaint?s.clear():(n.spread(1+1/this.canvas.pixelRatio).ceil(),s.clearWorld(n,!0),s.clipWorld(n,!0)),this.__render(n,o,r),s.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,s){const n=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,n),this.renderBounds=s||e,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),t.showHitView&&this.renderHitView(n),t.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 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(c.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:i}=t.old;new w(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||pt.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 c(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(c.REQUEST,this.update,this),t.on_(m.END,this.__onLayoutEnd,this),t.on_(c.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)}}const{hitRadiusPoint:ft}=E;class _t{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const s=i.through||!1,n=i.ignoreHittable||!1,o=i.target||this.target;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=new d(i.findList),i.findList||this.hitBranch(o);const{list:r}=this.findList,a=this.getBestMatchLeaf(r,i.bottomList,n),h=n?this.getPath(a):this.getHitablePath(a);return this.clear(),s?{path:h,target:a,throughPath:r.length?this.getThroughPath(r):h}:{path:h,target:a}}getBestMatchLeaf(t,e,i){if(t.length){let e;this.findList=new d;const{x:s,y:n}=this.point,o={x:s,y:n,radiusX:0,radiusY:0};for(let s=0,n=t.length;s<n;s++)if(e=t[s],(i||f.worldHittable(e))&&(this.hitChild(e,o),this.findList.length))return this.findList.list[0]}if(e)for(let t=0,i=e.length;t<i;t++)if(this.hitChild(e[t].target,this.point,e[t].proxy),this.findList.length)return this.findList.list[0];return t[0]}getPath(t){const e=new d;for(;t;)e.add(t),t=t.parent;return e.add(this.target),e}getHitablePath(t){const e=this.getPath(t&&t.hittable?t:null);let i,s=new d;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(s.addAt(i,0),i.__.hitChildren);t--);return s}getThroughPath(t){const e=new d,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let s,n,o;for(let t=0,r=i.length;t<r;t++){s=i[t],n=i[t+1];for(let t=0,i=s.length;t<i&&(o=s.list[t],!n||!n.has(o));t++)e.add(o)}return e}hitBranch(t){this.eachFind(t.children,t.__onlyHitMask)}eachFind(t,e){let i,s;const{point:n}=this;for(let o=t.length-1;o>-1;o--)i=t[o],!i.__.visible||e&&!i.__.mask||(s=!!i.__.hitRadius||ft(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&!this.findList.length&&this.hitChild(i,n)):s&&this.hitChild(i,n))}hitChild(t,e,i){this.exclude&&this.exclude.has(t)||t.__hitWorld(e)&&this.findList.add(i||t)}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}const{Yes:wt,NoAndSkip:yt,YesAndSkip:vt}=L;class mt{constructor(t,e){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.idMap[e]=t,1):0,innerId:(t,e)=>t.innerId===e?(this.innerIdMap[e]=t,1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0},this.target=t,e&&(this.config=s.default(e,this.config)),this.picker=new _t(t,this),this.__listenEvents()}getBy(t,e,i,s){switch(typeof t){case"number":const n=this.getByInnerId(t,e);return i?n:n?[n]:[];case"string":switch(t[0]){case"#":const s=this.getById(t.substring(1),e);return i?s:s?[s]:[];case".":return this.getByMethod(this.methods.className,e,i,t.substring(1));default:return this.getByMethod(this.methods.tag,e,i,t)}case"function":return this.getByMethod(t,e,i,s)}}getByPoint(t,e,s){return"node"===i.name&&this.target.emit(m.CHECK_UPDATE),this.picker.getByPoint(t,e,s)}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,e){const i=this.idMap[t];return i&&f.hasParent(i,e||this.target)?i:(this.eachFind(this.toChildren(e),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,i,s){let n,o;for(let r=0,a=t.length;r<a;r++){if(n=t[r],o=e(n,s),o===wt||o===vt){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&o<yt&&this.eachFind(n.children,e,i,s)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(u.REMOVE,this.__onRemoveChild,this),this.target.on_(g.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.picker.destroy(),this.findLeaf=null,this.innerIdMap={},this.idMap={})}}Object.assign(a,{watcher:(t,e)=>new tt(t,e),layouter:(t,e)=>new ut(t,e),renderer:(t,e,i)=>new gt(t,e,i),selector:(t,e)=>new mt(t,e)}),i.layout=ut.fullLayout;const xt={convert(t,e){const i=A.getBase(t),s=Object.assign(Object.assign({},i),{x:e.x,y:e.y,width:t.width,height:t.height,pointerType:t.pointerType,pressure:t.pressure});return"pen"===s.pointerType&&(s.tangentialPressure=t.tangentialPressure,s.tiltX=t.tiltX,s.tiltY=t.tiltY,s.twist=t.twist),s},convertMouse(t,e){const i=A.getBase(t);return Object.assign(Object.assign({},i),{x:e.x,y:e.y,width:1,height:1,pointerType:"mouse",pressure:.5})},convertTouch(t,e){const i=xt.getTouch(t),s=A.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",pressure:i.force})},getTouch:t=>t.targetTouches[0]||t.changedTouches[0]},bt={getMove(t,e){let{moveSpeed:i}=e,{deltaX:s,deltaY:n}=t;return t.shiftKey&&!s&&(s=n,n=0),s>50&&(s=Math.max(50,s/3)),n>50&&(n=Math.max(50,n/3)),{x:-s*i*2,y:-n*i*2}},getScale(t,e){let s,n=1,{zoomMode:o,zoomSpeed:r}=e;const a=t.deltaY||t.deltaX;if(o?(s="mouse"===o||!t.deltaX&&(i.intWheelDeltaY?Math.abs(a)>17:Math.ceil(a)!==a),(t.shiftKey||t.metaKey||t.ctrlKey)&&(s=!0)):s=!t.shiftKey&&(t.metaKey||t.ctrlKey),s){r=R.within(r,0,1);n=1-a/(4*(t.deltaY?e.delta.y:e.delta.x))*r,n<.5&&(n=.5),n>=1.5&&(n=1.5)}return n}},Bt={convert(t){const e=A.getBase(t);return Object.assign(Object.assign({},e),{code:t.code,key:t.key})}},{getMoveEventData:Et,getZoomEventData:Lt,getRotateEventData:Rt}=A;class Mt extends D{__listenEvents(){super.__listenEvents();const t=this.view=this.canvas.view;this.viewEvents={pointerdown:this.onPointerDown,mousedown:this.onMouseDown,touchstart:this.onTouchStart,contextmenu:this.onContextMenu,wheel:this.onWheel,gesturestart:this.onGesturestart,gesturechange:this.onGesturechange,gestureend:this.onGestureend},this.windowEvents={pointermove:this.onPointerMove,pointerup:this.onPointerUp,pointercancel:this.onPointerCancel,mousemove:this.onMouseMove,mouseup:this.onMouseUp,touchmove:this.onTouchMove,touchend:this.onTouchEnd,touchcancel:this.onTouchCancel,keydown:this.onKeyDown,keyup:this.onKeyUp,scroll:this.onScroll};const{viewEvents:e,windowEvents:i}=this;for(let i in e)e[i]=e[i].bind(this),t.addEventListener(i,e[i]);for(let t in i)i[t]=i[t].bind(this),window.addEventListener(t,i[t])}__removeListenEvents(){super.__removeListenEvents();const{viewEvents:t,windowEvents:e}=this;for(let e in t)this.view.removeEventListener(e,t[e]),this.viewEvents={};for(let t in e)window.removeEventListener(t,e[t]),this.windowEvents={}}getLocal(t,e){e&&this.canvas.updateClientBounds();const{clientBounds:i}=this.canvas;return{x:t.clientX-i.x,y:t.clientY-i.y}}getTouches(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push(t[i]);return e}preventDefaultPointer(t){const{pointer:e}=this.config;e.preventDefault&&t.preventDefault()}preventDefaultWheel(t){const{wheel:e}=this.config;e.preventDefault&&t.preventDefault()}preventWindowPointer(t){return!this.downData&&t.target!==this.view}onKeyDown(t){this.keyDown(Bt.convert(t))}onKeyUp(t){this.keyUp(Bt.convert(t))}onContextMenu(t){this.config.pointer.preventDefaultMenu&&t.preventDefault(),this.menu(xt.convert(t,this.getLocal(t)))}onScroll(){this.canvas.updateClientBounds()}onPointerDown(t){this.preventDefaultPointer(t),this.usePointer||(this.usePointer=!0),this.useMultiTouch||this.pointerDown(xt.convert(t,this.getLocal(t)))}onPointerMove(t){this.usePointer||(this.usePointer=!0),this.useMultiTouch||this.preventWindowPointer(t)||this.pointerMove(xt.convert(t,this.getLocal(t,!0)))}onPointerUp(t){this.downData&&this.preventDefaultPointer(t),this.useMultiTouch||this.preventWindowPointer(t)||this.pointerUp(xt.convert(t,this.getLocal(t)))}onPointerCancel(){this.useMultiTouch||this.pointerCancel()}onMouseDown(t){this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.pointerDown(xt.convertMouse(t,this.getLocal(t)))}onMouseMove(t){this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerMove(xt.convertMouse(t,this.getLocal(t,!0)))}onMouseUp(t){this.downData&&this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerUp(xt.convertMouse(t,this.getLocal(t)))}onMouseCancel(){this.useTouch||this.usePointer||this.pointerCancel()}onTouchStart(t){if(t.preventDefault(),this.multiTouchStart(t),this.usePointer)return;this.touchTimer&&(window.clearTimeout(this.touchTimer),this.touchTimer=0),this.useTouch=!0;const e=xt.getTouch(t);this.pointerDown(xt.convertTouch(t,this.getLocal(e,!0)))}onTouchMove(t){if(this.multiTouchMove(t),this.usePointer||this.preventWindowPointer(t))return;const e=xt.getTouch(t);this.pointerMove(xt.convertTouch(t,this.getLocal(e)))}onTouchEnd(t){if(this.multiTouchEnd(),this.usePointer||this.preventWindowPointer(t))return;this.touchTimer&&clearTimeout(this.touchTimer),this.touchTimer=setTimeout((()=>{this.useTouch=!1}),500);const e=xt.getTouch(t);this.pointerUp(xt.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.usePointer||this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>=2,this.touches=this.useMultiTouch?this.getTouches(t.touches):void 0,this.useMultiTouch&&this.pointerCancel()}multiTouchMove(t){if(this.useMultiTouch&&t.touches.length>1){const e=this.getTouches(t.touches),i=this.getKeepTouchList(this.touches,e);i.length>1&&(this.multiTouch(A.getBase(t),i),this.touches=e)}}multiTouchEnd(){this.touches=null,this.useMultiTouch=!1,this.transformEnd()}getKeepTouchList(t,e){let i;const s=[];return t.forEach((t=>{i=e.find((e=>e.identifier===t.identifier)),i&&s.push({from:this.getLocal(t),to:this.getLocal(i)})})),s}getLocalTouchs(t){return t.map((t=>this.getLocal(t)))}onWheel(t){this.preventDefaultWheel(t);const{wheel:e}=this.config,i=e.getScale?e.getScale(t,e):bt.getScale(t,e),s=this.getLocal(t),n=A.getBase(t);1!==i?this.zoom(Lt(s,i,n)):this.move(Et(s,e.getMove?e.getMove(t,e):bt.getMove(t,e),n))}onGesturestart(t){this.preventDefaultWheel(t),this.lastGestureScale=1,this.lastGestureRotation=0}onGesturechange(t){this.preventDefaultWheel(t);const e=this.getLocal(t),i=A.getBase(t),s=t.scale/this.lastGestureScale,n=t.rotation-this.lastGestureRotation;let{rotateSpeed:o}=this.config.wheel;o=R.within(o,0,1),this.zoom(Lt(e,s*s,i)),this.rotate(Rt(e,n/Math.PI*180*(o/4+.1),i)),this.lastGestureScale=t.scale,this.lastGestureRotation=t.rotation}onGestureend(t){this.preventDefaultWheel(t),this.transformEnd()}setCursor(t){super.setCursor(t);const e=[];this.eachCursor(t,e),"object"==typeof e[e.length-1]&&e.push("default"),this.canvas.view.style.cursor=e.map((t=>"object"==typeof t?`url(${t.url}) ${t.x||0} ${t.y||0}`:t)).join(",")}eachCursor(t,e,i=0){if(i++,t instanceof Array)t.forEach((t=>this.eachCursor(t,e,i)));else{const s="string"==typeof t&&I.get(t);s&&i<2?this.eachCursor(s,e,i):e.push(t)}}destroy(){this.view&&(super.destroy(),this.view=null,this.touches=null)}}function kt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,r=s.length;t<r;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 Tt(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?Ot(t,!0,e,i):Ct(e,i);break;case"inside":St("inside",t,n,e,i);break;case"outside":St("outside",t,n,e,i)}}function St(t,e,i,s,n){const{__strokeWidth:o,__font:r}=s.__,a=n.getSameCanvas(!0,!0);a.setStroke(i?void 0:e,2*o,s.__),a.font=r,i?Ot(e,!0,s,a):Ct(s,a),a.blendMode="outside"===t?"destination-out":"destination-in",kt(s,a),a.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(a,s.__nowWorld):n.copyWorldToInner(a,s.__nowWorld,s.__layout.renderBounds),a.recycle(s.__nowWorld)}function Ct(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,r=s.length;t<r;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 Ot(t,e,i,s){let n;for(let o=0,r=t.length;o<r;o++)n=t[o],n.image&&U.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?Ct(i,s):s.stroke(),s.restoreBlendMode()):e?Ct(i,s):s.stroke())}const{getSpread:Wt,getOuterOf:Pt,getByMove:At,getIntersectData:Dt}=E;let It;function Ft(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:r,opacity:a}=e;return{type:n,blendMode:o,style:G.string(r,a)};case"image":return U.image(i,t,e,s,!It||!It[e.url]);case"linear":return z.linearGradient(e,s);case"radial":return z.radialGradient(e,s);case"angular":return z.conicGradient(e,s);default:return e.r?{type:"solid",style:G.string(e)}:void 0}}const Yt={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),It=U.recycleImage(t,i);for(let i,n=0,r=o.length;n<r;n++)i=Ft(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?kt(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 r=0,a=t.length;r<a;r++)s=t[r],s.image&&U.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?kt(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?kt(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?kt(e,i):n?i.fill(n):i.fill())},fillText:kt,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:r}=s;if(n)if(r)Tt(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:r}=s;if(n)if(r)Tt(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),Ot(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),Ot(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,r=i.getSameCanvas(!0,!0);e.__drawRenderPath(r),r.setStroke(void 0,2*n,s),Ot(t,!1,e,r),s.windingRule?r.clip(s.windingRule):r.clip(),r.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(r,e.__nowWorld):i.copyWorldToInner(r,e.__nowWorld,o),r.recycle(e.__nowWorld)}},strokeText:Tt,drawTextStroke:Ct,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,r,a,h,{scaleX:l,scaleY:d}=n;if(l<0&&(l=-l),d<0&&(d=-d),e.bounds.includes(n))h=s,o=a=n;else{const{renderShapeSpread:s}=t.__layout,c=Dt(s?Wt(e.bounds,s*l,s*d):e.bounds,n);r=e.bounds.getFitMatrix(c);let{a:u,d:p}=r;if(r.a<1&&(h=e.getSameCanvas(),t.__renderShape(h,i),l*=u,d*=p),a=Pt(n,r),o=At(a,-r.e,-r.f),i.matrix){const{matrix:t}=i;r.multiply(t),u*=t.scaleX,p*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:r.withScale(u,p)})}return t.__renderShape(s,i),{canvas:s,matrix:r,bounds:o,worldCanvas:h,shapeBounds:a,scaleX:l,scaleY:d}}};let Ut={};const{get:Gt,rotateOfOuter:zt,translate:Nt,scaleOfOuter:Vt,scale:jt,rotate:Xt}=M;function Ht(t,e,i,s,n,o,r){const a=Gt();Nt(a,e.x+i,e.y+s),jt(a,n,o),r&&zt(a,{x:e.x+e.width/2,y:e.y+e.height/2},r),t.transform=a}function qt(t,e,i,s,n,o,r){const a=Gt();Nt(a,e.x+i,e.y+s),n&&jt(a,n,o),r&&Xt(a,r),t.transform=a}function Kt(t,e,i,s,n,o,r,a,h,l){const d=Gt();if(h)if("center"===l)zt(d,{x:i/2,y:s/2},h);else switch(Xt(d,h),h){case 90:Nt(d,s,0);break;case 180:Nt(d,i,s);break;case 270:Nt(d,0,i)}Ut.x=e.x+n,Ut.y=e.y+o,Nt(d,Ut.x,Ut.y),r&&Vt(d,Ut,r,a),t.transform=d}const{get:Qt,translate:$t}=M,Jt=new w,Zt={};function te(t,e,i,s){let{width:n,height:o}=e;i.padding&&(s=Jt.set(s).shrink(i.padding));const{opacity:r,mode:a,around:h,offset:l,scale:d,size:c,rotation:u,blendMode:p,repeat:g}=i,f=s.width===n&&s.height===o;p&&(t.blendMode=p);const _=t.data={mode:a},w="center"!==h&&(u||0)%180==90,y=w?o:n,v=w?n:o;let m,x,b=0,B=0;if(a&&"cover"!==a&&"fit"!==a)c?(m=("number"==typeof c?c:c.width)/n,x=("number"==typeof c?c:c.height)/o):d&&(m="number"==typeof d?d:d.x,x="number"==typeof d?d:d.y);else if(!f||u){const t=s.width/y,e=s.height/v;m=x="fit"===a?Math.min(t,e):Math.max(t,e),b+=(s.width-n*m)/2,B+=(s.height-o*x)/2}if(h){const t={x:b,y:B,width:y,height:v};m&&(t.width*=m,t.height*=x),k.toPoint(h,s,Zt,!0,t),b+=Zt.x,B+=Zt.y}switch(l&&(b+=l.x,B+=l.y),a){case"strench":f||(n=s.width,o=s.height);break;case"normal":case"clip":(b||B||m||u)&&qt(_,s,b,B,m,x,u);break;case"repeat":(!f||m||u)&&Kt(_,s,n,o,b,B,m,x,u,h),g||(_.repeat="repeat");break;default:m&&Ht(_,s,b,B,m,x,u)}_.transform||(s.x||s.y)&&(_.transform=Qt(),$t(_.transform,s.x,s.y)),m&&"strench"!==a&&(_.scaleX=m,_.scaleY=x),_.width=n,_.height=o,r&&(_.opacity=r),g&&(_.repeat="string"==typeof g?"x"===g?"repeat-x":"repeat-y":"repeat")}let ee,ie=new w;const{isSame:se}=E;function ne(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||te(n,s,i,o),!0}function oe(t,e){he(t,T.LOAD,e)}function re(t,e){he(t,T.LOADED,e)}function ae(t,e,i){e.error=i,t.forceUpdate("surface"),he(t,T.ERROR,e)}function he(t,e,i){t.hasEvent(e)&&t.emitEvent(new T(e,i))}function le(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:de,scale:ce,copy:ue}=M,{ceil:pe,abs:ge}=Math;function fe(t,e,s){let{scaleX:n,scaleY:o}=b.patternLocked?t.__world:t.__nowWorld;const r=n+"-"+o;if(e.patternId===r||t.destroyed)return!1;{n=ge(n),o=ge(o);const{image:t,data:a}=e;let h,l,{width:d,height:c,scaleX:u,scaleY:p,opacity:g,transform:f,repeat:_}=a;u&&(l=de(),ue(l,f),ce(l,1/u,1/p),n*=u,o*=p),n*=s,o*=s,d*=n,c*=o;const w=d*c;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&&(h=Math.sqrt(w/y)),h&&(n/=h,o/=h,d/=h,c/=h),u&&(n/=u,o/=p),(f||1!==n||1!==o)&&(l||(l=de(),f&&ue(l,f)),ce(l,1/n,1/o));const v=t.getCanvas(pe(d)||1,pe(c)||1,g),m=t.getPattern(v,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=m,e.patternId=r,!0}}function _e(t,e,i,s){return new(i||(i=Promise))((function(n,o){function r(t){try{h(s.next(t))}catch(t){o(t)}}function a(t){try{h(s.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:we}=Math;const ye={image:function(t,e,i,s,n){let o,r;const a=b.get(i);return ee&&i===ee.paint&&se(s,ee.boxBounds)?o=ee.leafPaint:(o={type:i.type,image:a},ee=a.use>1?{leafPaint:o,paint:i,boxBounds:ie.set(s)}:null),(n||a.loading)&&(r={image:a,attrName:e,attrValue:i}),a.ready?(ne(t,e,i,a,o,s),n&&(oe(t,r),re(t,r))):a.error?n&&ae(t,r,a.error):(le(t,!0),n&&oe(t,r),o.loadId=a.load((()=>{le(t,!1),t.destroyed||(ne(t,e,i,a,o,s)&&(a.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),re(t,r)),o.loadId=null}),(e=>{le(t,!1),ae(t,r,e),o.loadId=null}))),o},createData:te,fillOrFitMode:Ht,clipMode:qt,repeatMode:Kt,createPattern:fe,checkImage:function(t,e,s,n){const{scaleX:o,scaleY:r}=b.patternLocked?t.__world:t.__nowWorld;if(s.data&&s.patternId!==o+"-"+r){const{data:a}=s;if(n)if(a.repeat)n=!1;else{let{width:t,height:s}=a;t*=we(o)*e.pixelRatio,s*=we(r)*e.pixelRatio,a.scaleX&&(t*=a.scaleX,s*=a.scaleY),n=t*s>i.image.maxCacheSize}return n?(e.save(),e.clip(),s.blendMode&&(e.blendMode=s.blendMode),a.opacity&&(e.opacity*=a.opacity),a.transform&&e.transform(a.transform),e.drawImage(s.image.view,0,0,a.width,a.height),e.restore(),!0):(!s.style||N.running?fe(t,s,e.pixelRatio):s.patternTask||(s.patternTask=b.patternTasker.add((()=>_e(this,void 0,void 0,(function*(){s.patternTask=null,e.bounds.hit(t.__nowWorld)&&fe(t,s,e.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let s,n,o,r;for(let a=0,h=i.length;a<h;a++)s=i[a].image,r=s&&s.url,r&&(n||(n={}),n[r]=!0,b.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[a].loadId,!o.some((t=>t.url===r)))));return n}return null}},ve={x:.5,y:0},me={x:.5,y:1};function xe(t,e,i){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],t.addColorStop(s.offset,G.string(s.color,i))}const{set:be,getAngle:Be,getDistance:Ee}=S,{get:Le,rotateOfOuter:Re,scaleOfOuter:Me}=M,ke={x:.5,y:.5},Te={x:.5,y:1},Se={},Ce={};const{set:Oe,getAngle:We,getDistance:Pe}=S,{get:Ae,rotateOfOuter:De,scaleOfOuter:Ie}=M,Fe={x:.5,y:.5},Ye={x:.5,y:1},Ue={},Ge={};const ze={linearGradient:function(t,e){let{from:s,to:n,type:o,blendMode:r,opacity:a}=t;s||(s=ve),n||(n=me);const h=i.canvas.createLinearGradient(e.x+s.x*e.width,e.y+s.y*e.height,e.x+n.x*e.width,e.y+n.y*e.height);xe(h,t.stops,a);const l={type:o,style:h};return r&&(l.blendMode=r),l},radialGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;s||(s=ke),n||(n=Te);const{x:l,y:d,width:c,height:u}=e;let p;be(Se,l+s.x*c,d+s.y*u),be(Ce,l+n.x*c,d+n.y*u),(c!==u||h)&&(p=Le(),Me(p,Se,c/u*(h||1),1),Re(p,Se,Be(Se,Ce)+90));const g=i.canvas.createRadialGradient(Se.x,Se.y,0,Se.x,Se.y,Ee(Se,Ce));xe(g,t.stops,r);const f={type:o,style:g,transform:p};return a&&(f.blendMode=a),f},conicGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;s||(s=Fe),n||(n=Ye);const{x:l,y:d,width:c,height:u}=e;Oe(Ue,l+s.x*c,d+s.y*u),Oe(Ge,l+n.x*c,d+n.y*u);const p=Ae(),g=We(Ue,Ge);i.conicGradientRotate90?(Ie(p,Ue,c/u*(h||1),1),De(p,Ue,g+90)):(Ie(p,Ue,1,c/u*(h||1)),De(p,Ue,g));const f=i.conicGradientSupport?i.canvas.createConicGradient(0,Ue.x,Ue.y):i.canvas.createRadialGradient(Ue.x,Ue.y,0,Ue.x,Ue.y,Pe(Ue,Ge));xe(f,t.stops,r);const _={type:o,style:f,transform:p};return a&&(_.blendMode=a),_}},{copy:Ne,toOffsetOutBounds:Ve}=E,je={},Xe={};function He(t,e,s,n){const{bounds:o,shapeBounds:r}=n;if(i.fullImageShadow){if(Ne(je,t.bounds),je.x+=e.x-r.x,je.y+=e.y-r.y,s){const{matrix:t}=n;je.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),je.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),je.width*=s,je.height*=s}t.copyWorld(n.canvas,t.bounds,je)}else s&&(Ne(je,e),je.x-=e.width/2*(s-1),je.y-=e.height/2*(s-1),je.width*=s,je.height*=s),t.copyWorld(n.canvas,r,s?je:e)}const{toOffsetOutBounds:qe}=E,Ke={};const Qe={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:r}=t,{shadow:a}=t.__,{worldCanvas:h,bounds:l,shapeBounds:d,scaleX:c,scaleY:u}=i,p=e.getSameCanvas(),g=a.length-1;Ve(l,Xe),a.forEach(((a,f)=>{p.setWorldShadow(Xe.offsetX+a.x*c,Xe.offsetY+a.y*u,a.blur*c,a.color),n=a.spread?1+2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,He(p,Xe,n,i),s=l,a.box&&(p.restore(),p.save(),h&&(p.copyWorld(p,l,o,"copy"),s=o),h?p.copyWorld(h,o,o,"destination-out"):p.copyWorld(i.canvas,d,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(p,s,o,a.blendMode):e.copyWorldToInner(p,s,r.renderBounds,a.blendMode),g&&f<g&&p.clearWorld(s,!0)})),p.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:r}=t,{innerShadow:a}=t.__,{worldCanvas:h,bounds:l,shapeBounds:d,scaleX:c,scaleY:u}=i,p=e.getSameCanvas(),g=a.length-1;qe(l,Ke),a.forEach(((a,f)=>{p.save(),p.setWorldShadow(Ke.offsetX+a.x*c,Ke.offsetY+a.y*u,a.blur*c),n=a.spread?1-2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,He(p,Ke,n,i),p.restore(),h?(p.copyWorld(p,l,o,"copy"),p.copyWorld(h,o,o,"source-out"),s=o):(p.copyWorld(i.canvas,d,l,"source-out"),s=l),p.fillWorld(s,a.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(p,s,o,a.blendMode):e.copyWorldToInner(p,s,r.renderBounds,a.blendMode),g&&f<g&&p.clearWorld(s,!0)})),p.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:$e}=y;function Je(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),ti(t,e,i,1)}(t,i,s,n);break;case"opacity-path":ti(t,i,s,o);break;case"path":i.restore()}}function Ze(t){return t.getSameCanvas(!1,!0)}function ti(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}V.prototype.__renderMask=function(t,e){let i,s,n,o,r;const{children:a}=this;for(let h=0,l=a.length;h<l;h++)i=a[h],i.__.mask&&(r&&(Je(this,r,t,n,s,o),s=n=null),"path"===i.__.maskType?(i.opacity<1?(r="opacity-path",o=i.opacity,n||(n=Ze(t))):(r="path",t.save()),i.__clip(n||t,e)):(r="alpha",s||(s=Ze(t)),n||(n=Ze(t)),i.__render(s,e)),"clipping"!==i.__.maskType)||$e(i,e)||i.__render(n||t,e);Je(this,r,t,n,s,o)};const ei=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",ii=ei+"_#~&*+\\=|≮≯≈≠=…",si=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 ni(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const oi=ni("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ri=ni("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ai=ni(ei),hi=ni(ii),li=ni("- —/~|┆·");var di;!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"}(di||(di={}));const{Letter:ci,Single:ui,Before:pi,After:gi,Symbol:fi,Break:_i}=di;function wi(t){return oi[t]?ci:li[t]?_i:ri[t]?pi:ai[t]?gi:hi[t]?fi:si.test(t)?ui:ci}const yi={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 vi(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:mi}=yi,{Letter:xi,Single:bi,Before:Bi,After:Ei,Symbol:Li,Break:Ri}=di;let Mi,ki,Ti,Si,Ci,Oi,Wi,Pi,Ai,Di,Ii,Fi,Yi,Ui,Gi,zi,Ni=[];function Vi(t,e){Ai&&!Pi&&(Pi=Ai),Mi.data.push({char:t,width:e}),Ti+=e}function ji(){Si+=Ti,Mi.width=Ti,ki.words.push(Mi),Mi={data:[]},Ti=0}function Xi(){Ui&&(Gi.paraNumber++,ki.paraStart=!0,Ui=!1),Ai&&(ki.startCharSize=Pi,ki.endCharSize=Ai,Pi=0),ki.width=Si,zi.width&&mi(ki),Ni.push(ki),ki={words:[]},Si=0}const Hi=0,qi=1,Ki=2;const{top:Qi,right:$i,bottom:Ji,left:Zi}=C;function ts(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 es={getDrawData:function(t,e){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=e.__getInput("width")||0,r=e.__getInput("height")||0;const{textDecoration:a,__font:h,__padding:l}=e;l&&(o&&(s=l[Zi],o-=l[$i]+l[Zi]),r&&(n=l[Qi],r-=l[Qi]+l[Ji]));const d={bounds:{x:s,y:n,width:o,height:r},rows:[],paraNumber:0,font:i.canvas.font=h};return function(t,e,s){Gi=t,Ni=t.rows,zi=t.bounds;const{__letterSpacing:n,paraIndent:o,textCase:r}=s,{canvas:a}=i,{width:h,height:l}=zi;if(h||l||n||"none"!==r){const t="none"!==s.textWrap,i="break"===s.textWrap;Ui=!0,Ii=null,Pi=Wi=Ai=Ti=Si=0,Mi={data:[]},ki={words:[]};for(let s=0,l=e.length;s<l;s++)Oi=e[s],"\n"===Oi?(Ti&&ji(),ki.paraEnd=!0,Xi(),Ui=!0):(Di=wi(Oi),Di===xi&&"none"!==r&&(Oi=vi(Oi,r,!Ti)),Wi=a.measureText(Oi).width,n&&(n<0&&(Ai=Wi),Wi+=n),Fi=Di===bi&&(Ii===bi||Ii===xi)||Ii===bi&&Di!==Ei,Yi=!(Di!==Bi&&Di!==bi||Ii!==Li&&Ii!==Ei),Ci=Ui&&o?h-o:h,t&&h&&Si+Ti+Wi>Ci&&(i?(Ti&&ji(),Xi()):(Yi||(Yi=Di===xi&&Ii==Ei),Fi||Yi||Di===Ri||Di===Bi||Di===bi||Ti+Wi>Ci?(Ti&&ji(),Xi()):Xi()))," "===Oi&&!0!==Ui&&Si+Ti===0||(Di===Ri?(" "===Oi&&Ti&&ji(),Vi(Oi,Wi),ji()):Fi||Yi?(Ti&&ji(),Vi(Oi,Wi)):Vi(Oi,Wi)),Ii=Di);Ti&&ji(),Si&&Xi(),Ni.length>0&&(Ni[Ni.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{Gi.paraNumber++,Ni.push({x:o||0,text:t,width:a.measureText(t).width,paraStart:!0})}))}(d,t,e),l&&function(t,e,i,s,n){if(!s)switch(i.textAlign){case"left":ts(e,"x",t[Zi]);break;case"right":ts(e,"x",-t[$i])}if(!n)switch(i.verticalAlign){case"top":ts(e,"y",t[Qi]);break;case"bottom":ts(e,"y",-t[Ji])}}(l,d,e,o,r),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:r,__clipText:a,textAlign:h,verticalAlign:l,paraSpacing:d}=e;let c,u,p,{x:g,y:f,width:_,height:w}=s,y=n*i.length+(d?d*(t.paraNumber-1):0),v=o;if(a&&y>w)y=Math.max(w,n),t.overflow=i.length;else switch(l){case"middle":f+=(w-y)/2;break;case"bottom":f+=w-y}v+=f;for(let o=0,l=i.length;o<l;o++){switch(c=i[o],c.x=g,h){case"center":c.x+=(_-c.width)/2;break;case"right":c.x+=_-c.width}c.paraStart&&d&&o>0&&(v+=d),c.y=v,v+=n,t.overflow>o&&v>y&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,p=c.width,r<0&&(c.width<0?(p=-c.width+e.fontSize+r,u-=p,p+=e.fontSize):p-=r),u<s.x&&(s.x=u),p>s.width&&(s.width=p),a&&_&&_<p&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=f,s.height=y}(d,e),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:r,letterSpacing:a}=e;let h,l,d,c,u;n.forEach((t=>{t.words&&(d=r&&t.paraStart?r:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-d)/(t.words.length-1):0,c=a||t.isOverflow?Hi:l>.01?qi:Ki,t.isOverflow&&!a&&(t.textMode=!0),c===Ki?(t.x+=d,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=d,h=t.x,t.data=[],t.words.forEach((e=>{c===qi?(u={char:"",x:h},h=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,h,u)," "!==u.char&&t.data.push(u)):h=function(t,e,i){return t.forEach((t=>{" "!==t.char&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data),!t.paraEnd&&l&&(h+=l,t.width+=l)}))),t.words=null)}))}(d,e,o),d.overflow&&function(t,e){const{rows:s,overflow:n}=t;let{textOverflow:o}=e;if(s.splice(n),"hide"!==o){let t,r;"ellipsis"===o&&(o="...");const a=i.canvas.measureText(o).width,h=e.x+e.width-a;("none"===e.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],r=t.x+t.width,!(s===i&&r<h));s--){if(r<h&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=a,e.data.push({char:o,x:r}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(d,e),"none"!==a&&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}}(d,e),d}};const is={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:ss,addPoint:ns,toBounds:os}=O;const rs={export(t,e,s){return this.running=!0,function(t){as||(as=new W);return new Promise((e=>{as.add((()=>_e(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((n=>new Promise((o=>{const r=t=>{n(t),o(),this.running=!1};if("json"===e)return r({data:t.toJSON()});if("json"===l.fileType(e))return i.origin.download("data:text/plain;charset=utf-8,"+encodeURIComponent(JSON.stringify(t.toJSON())),e),r({data:!0});const{leafer:h}=t;h?h.waitViewCompleted((()=>_e(this,void 0,void 0,(function*(){s=l.getExportOptions(s);let i,n,o=1,d=1;const{worldTransform:c,isLeafer:u,isFrame:p}=t,{slice:g,trim:f,onCanvas:_}=s,y=s.scale||1,v=s.pixelRatio||1,m=s.screenshot||t.isApp,x=u&&m&&void 0===s.fill?t.fill:s.fill,b=l.isOpaqueImage(e)||x,B=new P;if(m)i=!0===m?u?h.canvas.bounds:t.worldRenderBounds:m;else{let e=s.relative||(u?"inner":"local");switch(o=c.scaleX,d=c.scaleY,e){case"inner":B.set(c);break;case"local":B.set(c).divide(t.localTransform),o/=t.scaleX,d/=t.scaleY;break;case"world":o=1,d=1;break;case"page":e=t.leafer;default:B.set(c).divide(t.getTransform(e));const i=e.worldTransform;o/=o/i.scaleX,d/=d/i.scaleY}i=t.getBounds("render",e)}const{x:E,y:L,width:R,height:M}=new w(i).scale(y);let k=a.canvas({width:Math.round(R),height:Math.round(M),pixelRatio:v});const T={matrix:B.scale(1/y).invert().translate(-E,-L).withScale(1/o*y,1/d*y)};if(g&&(t=h,T.bounds=k.bounds),k.save(),p&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(k,T),t.fill=e}else t.__render(k,T);if(k.restore(),f){n=function(t){const{width:e,height:i}=t.view,{data:s}=t.context.getImageData(0,0,e,i);let n,o,r,a=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(n=a%e,o=(a-n)/e,r?ns(r,n,o):ss(r={},n,o)),a++;const h=new w;return os(r,h),h.scale(1/t.pixelRatio).ceil()}(k);const t=k,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:v};k=a.canvas(s),k.copyWorld(t,n,s)}b&&k.fillWorld(k.bounds,x||"#FFFFFF","destination-over"),_&&_(k);const S="canvas"===e?k:yield k.export(e,s);r({data:S,width:k.pixelWidth,height:k.pixelHeight,renderBounds:i,trimBounds:n})})))):r({data:!1})}))))}};let as;const hs=e.prototype,ls=t.get("@leafer-ui/export");hs.export=function(t,e){const{quality:i,blob:s}=l.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):s?this.toBlob(t,i):this.toDataURL(t,i)},hs.toBlob=function(t,e){return new Promise((s=>{i.origin.canvasToBolb(this.view,t,e).then((t=>{s(t)})).catch((t=>{ls.error(t),s(null)}))}))},hs.toDataURL=function(t,e){return i.origin.canvasToDataURL(this.view,t,e)},hs.saveAs=function(t,e){return new Promise((s=>{i.origin.canvasSaveAs(this.view,t,e).then((()=>{s(!0)})).catch((t=>{ls.error(t),s(!1)}))}))},Object.assign(j,es),Object.assign(G,is),Object.assign(X,Yt),Object.assign(U,ye),Object.assign(z,ze),Object.assign(H,Qe),Object.assign(N,rs),Object.assign(a,{interaction:(t,e,i,s)=>new Mt(t,e,i,s),hitCanvas:(t,e)=>new K(t,e),hitCanvasManager:()=>new F}),J(),window.addEventListener("unload",(()=>{const{list:t}=Y;t.forEach((t=>t.destroy(!0))),t.destroy(),b.destroy()}));export{Mt as Interaction,ut as Layouter,K as LeaferCanvas,gt as Renderer,mt as Selector,tt as Watcher,J as useCanvas};
|
|
1
|
+
import{Debug as t,LeaferCanvasBase as e,Platform as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,canvasPatch as r,Creator as a,LeaferImage as h,FileHelper as l,LeafList as d,RenderEvent as c,ChildEvent as u,WatchEvent as p,PropertyEvent as f,LeafHelper as g,BranchHelper as _,Bounds as w,LeafBoundsHelper as v,LeafLevelList as y,LayoutEvent as m,Run as x,ImageManager as b,AnimateEvent as B,BoundsHelper as E,Answer as L,MathHelper as R,MatrixHelper as k,AlignHelper as M,ImageEvent as T,AroundHelper as S,PointHelper as C,Direction4 as O,TwoPointBoundsHelper as P,TaskProcessor as W,Matrix as A}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionHelper as D,InteractionBase as I,Cursor as F,HitCanvasManager as U,Leafer as Y}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as G,ColorConvert as N,PaintGradient as z,Export as V,Group as j,TextConvert as X,Paint as H,Effect as q}from"@leafer-ui/draw";const K=t.get("LeaferCanvas");class Q extends e{init(){const{view:t}=this.config;t?this.__createViewFrom(t):this.__createView();const{style:e}=this.view;e.display||(e.display="block"),this.parentView=this.view.parentElement,this.parentView&&(this.parentView.style.userSelect="none"),i.syncDomFont&&!this.parentView&&(this.view.style.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;if(t.hasChildNodes()){const{style:e}=i;e.position="absolute",e.top=e.left="0px",t.style.position||(t.style.position="relative")}t.appendChild(i)}else K.error(`no id: ${t}`),this.__createView()}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;s.width=t+"px",s.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()))}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:r,width:a,height:h}=this.autoBounds.getBoundsFrom(t);if(a!==this.width||h!==this.height){const{style:t}=e,{pixelRatio:l}=this;t.marginLeft=i+"px",t.marginTop=r+"px";const d={width:a,height:h,pixelRatio:l},c={};s.copyAttrs(c,this,n),this.resize(d),void 0!==this.width&&this.resizeListener(new o(d,c))}}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()}}}r(CanvasRenderingContext2D.prototype),r(Path2D.prototype);const{mineType:$,fileType:J}=l;function Z(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($(e),i),canvasToBolb:(t,e,i)=>new Promise((s=>t.toBlob(s,$(e),i))),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL($(J(e)),s);return i.origin.download(n,e)},download:(t,e)=>new Promise((i=>{let s=document.createElement("a");s.href=t,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),i()})),loadImage:t=>new Promise(((e,s)=>{const n=new Image,{suffix:o,crossOrigin:r}=i.image;r&&(n.setAttribute("crossOrigin",r),n.crossOrigin=r),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},!o||t.startsWith("data:")||t.startsWith("blob:")||(t+=(t.includes("?")?"&":"?")+o),n.src=t}))},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=a.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(a,{canvas:(t,e)=>new Q(t,e),image:t=>new h(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},i.devicePixelRatio=Math.max(1,devicePixelRatio);const{userAgent:tt}=navigator;tt.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):tt.indexOf("Safari")>-1&&-1===tt.indexOf("Chrome")&&(i.fullImageShadow=!0),tt.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):tt.indexOf("Mac")>-1?i.os="Mac":tt.indexOf("Linux")>-1&&(i.os="Linux");class et{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new d;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 d,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(c.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 p(p.DATA,{updatedList:this.updatedList})),this.__updatedList=new d,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_([u.ADD,u.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:it,updateBounds:st,updateAllWorldOpacity:nt}=g,{pushAllChildBranch:ot,pushAllParent:rt}=_;const{worldBounds:at}=v,ht={x:0,y:0,width:1e5,height:1e5};class lt{constructor(t){this.updatedBounds=new w,this.beforeBounds=new w,this.afterBounds=new w,t instanceof Array&&(t=new d(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,at)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(ht):this.afterBounds.setListWithFn(t,at),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:dt,updateAllChange:ct}=g,ut=t.get("Layouter");class pt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new y,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(m.START),this.layoutOnce(),t.emitEvent(new m(m.END,this.layoutedBlocks,this.times))}catch(t){ut.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ut.warn("layouting"):this.times>3?ut.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=x.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:o,AFTER:r}=m,a=this.getBlocks(s);a.forEach((t=>t.setBefore())),i.emitEvent(new m(n,a,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?(it(t,!0),e.add(t),t.isBranch&&ot(t,e),rt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),rt(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||st(s[t])}st(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&nt(t),t.__updateChange()}))}(s),this.extraBlock&&a.push(this.extraBlock),a.forEach((t=>t.setAfter())),i.emitEvent(new m(o,a,this.times)),i.emitEvent(new m(r,a,this.times)),this.addBlocks(a),this.__levelList.reset(),this.__updatedList=null,x.end(e)}fullLayout(){const t=x.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=m,o=this.getBlocks(new d(e));e.emitEvent(new m(i,o,this.times)),pt.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new m(s,o,this.times)),e.emitEvent(new m(n,o,this.times)),this.addBlocks(o),x.end(t)}static fullLayout(t){dt(t,!0),t.isBranch?_.updateBounds(t):g.updateBounds(t),ct(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new lt([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new lt(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_(m.REQUEST,this.layout,this),t.on_(m.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 ft=t.get("Renderer");class gt{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(m.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,ft.log(e.innerName,"---\x3e");try{this.emitRender(c.START),this.renderOnce(t),this.emitRender(c.END,this.totalBounds),b.clearRecycled()}catch(t){this.rendering=!1,ft.error(t)}ft.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return ft.warn("rendering");if(this.times>3)return ft.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new w,this.renderOptions={},t)this.emitRender(c.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(c.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(c.RENDER,this.renderBounds,this.renderOptions),this.emitRender(c.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 ft.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:s}=this,n=e.getIntersect(s.bounds),o=e.includes(this.target.__world),r=new w(n);s.save(),o&&!t.showRepaint?s.clear():(n.spread(10+1/this.canvas.pixelRatio).ceil(),s.clearWorld(n,!0),s.clipWorld(n,!0)),this.__render(n,o,r),s.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,s){const n=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,n),this.renderBounds=s||e,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),t.showHitView&&this.renderHitView(n),t.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 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(c.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||ft.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 c(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(c.REQUEST,this.update,this),t.on_(m.END,this.__onLayoutEnd,this),t.on_(c.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)}}const{hitRadiusPoint:_t}=E;class wt{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const s=i.through||!1,n=i.ignoreHittable||!1,o=i.target||this.target;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=new d(i.findList),i.findList||this.hitBranch(o);const{list:r}=this.findList,a=this.getBestMatchLeaf(r,i.bottomList,n),h=n?this.getPath(a):this.getHitablePath(a);return this.clear(),s?{path:h,target:a,throughPath:r.length?this.getThroughPath(r):h}:{path:h,target:a}}getBestMatchLeaf(t,e,i){if(t.length){let e;this.findList=new d;const{x:s,y:n}=this.point,o={x:s,y:n,radiusX:0,radiusY:0};for(let s=0,n=t.length;s<n;s++)if(e=t[s],(i||g.worldHittable(e))&&(this.hitChild(e,o),this.findList.length))return this.findList.list[0]}if(e)for(let t=0,i=e.length;t<i;t++)if(this.hitChild(e[t].target,this.point,e[t].proxy),this.findList.length)return this.findList.list[0];return t[0]}getPath(t){const e=new d;for(;t;)e.add(t),t=t.parent;return e.add(this.target),e}getHitablePath(t){const e=this.getPath(t&&t.hittable?t:null);let i,s=new d;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(s.addAt(i,0),i.__.hitChildren);t--);return s}getThroughPath(t){const e=new d,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let s,n,o;for(let t=0,r=i.length;t<r;t++){s=i[t],n=i[t+1];for(let t=0,i=s.length;t<i&&(o=s.list[t],!n||!n.has(o));t++)e.add(o)}return e}hitBranch(t){this.eachFind(t.children,t.__onlyHitMask)}eachFind(t,e){let i,s;const{point:n}=this;for(let o=t.length-1;o>-1;o--)i=t[o],!i.__.visible||e&&!i.__.mask||(s=!!i.__.hitRadius||_t(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&!this.findList.length&&this.hitChild(i,n)):s&&this.hitChild(i,n))}hitChild(t,e,i){this.exclude&&this.exclude.has(t)||t.__hitWorld(e)&&this.findList.add(i||t)}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}const{Yes:vt,NoAndSkip:yt,YesAndSkip:mt}=L,xt={},bt={},Bt={};class Et{constructor(t,e){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.idMap[e]=t,1):0,innerId:(t,e)=>t.innerId===e?(this.innerIdMap[e]=t,1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},this.target=t,e&&(this.config=s.default(e,this.config)),this.picker=new wt(t,this),this.__listenEvents()}getBy(t,e,i,n){switch(typeof t){case"number":const o=this.getByInnerId(t,e);return i?o:o?[o]:[];case"string":switch(t[0]){case"#":xt.id=t.substring(1),t=xt;break;case".":bt.className=t.substring(1),t=bt;break;default:Bt.tag=t,t=Bt}case"object":if(void 0!==t.id){const s=this.getById(t.id,e);return i?s:s?[s]:[]}if(t.tag){const{tag:n}=t,o=n instanceof Array;return this.getByMethod(o?this.methods.tags:this.methods.tag,e,i,o?s.toMap(n):n)}return this.getByMethod(this.methods.className,e,i,t.className);case"function":return this.getByMethod(t,e,i,n)}}getByPoint(t,e,s){return"node"===i.name&&this.target.emit(m.CHECK_UPDATE),this.picker.getByPoint(t,e,s)}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,e){const i=this.idMap[t];return i&&g.hasParent(i,e||this.target)?i:(this.eachFind(this.toChildren(e),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,i,s){let n,o;for(let r=0,a=t.length;r<a;r++){if(n=t[r],o=e(n,s),o===vt||o===mt){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&o<yt&&this.eachFind(n.children,e,i,s)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(u.REMOVE,this.__onRemoveChild,this),this.target.on_(f.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.picker.destroy(),this.findLeaf=null,this.innerIdMap={},this.idMap={})}}Object.assign(a,{watcher:(t,e)=>new et(t,e),layouter:(t,e)=>new pt(t,e),renderer:(t,e,i)=>new gt(t,e,i),selector:(t,e)=>new Et(t,e)}),i.layout=pt.fullLayout;const Lt={convert(t,e){const i=D.getBase(t),s=Object.assign(Object.assign({},i),{x:e.x,y:e.y,width:t.width,height:t.height,pointerType:t.pointerType,pressure:t.pressure});return"pen"===s.pointerType&&(s.tangentialPressure=t.tangentialPressure,s.tiltX=t.tiltX,s.tiltY=t.tiltY,s.twist=t.twist),s},convertMouse(t,e){const i=D.getBase(t);return Object.assign(Object.assign({},i),{x:e.x,y:e.y,width:1,height:1,pointerType:"mouse",pressure:.5})},convertTouch(t,e){const i=Lt.getTouch(t),s=D.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",pressure:i.force})},getTouch:t=>t.targetTouches[0]||t.changedTouches[0]},Rt={getMove(t,e){let{moveSpeed:i}=e,{deltaX:s,deltaY:n}=t;return t.shiftKey&&!s&&(s=n,n=0),s>50&&(s=Math.max(50,s/3)),n>50&&(n=Math.max(50,n/3)),{x:-s*i*2,y:-n*i*2}},getScale(t,e){let s,n=1,{zoomMode:o,zoomSpeed:r}=e;const a=t.deltaY||t.deltaX;if(o?(s="mouse"===o||!t.deltaX&&(i.intWheelDeltaY?Math.abs(a)>17:Math.ceil(a)!==a),(t.shiftKey||t.metaKey||t.ctrlKey)&&(s=!0)):s=!t.shiftKey&&(t.metaKey||t.ctrlKey),s){r=R.within(r,0,1);n=1-a/(4*(t.deltaY?e.delta.y:e.delta.x))*r,n<.5&&(n=.5),n>=1.5&&(n=1.5)}return n}},kt={convert(t){const e=D.getBase(t);return Object.assign(Object.assign({},e),{code:t.code,key:t.key})}},{getMoveEventData:Mt,getZoomEventData:Tt,getRotateEventData:St}=D;class Ct extends I{__listenEvents(){super.__listenEvents();const t=this.view=this.canvas.view;this.viewEvents={pointerdown:this.onPointerDown,mousedown:this.onMouseDown,touchstart:this.onTouchStart,contextmenu:this.onContextMenu,wheel:this.onWheel,gesturestart:this.onGesturestart,gesturechange:this.onGesturechange,gestureend:this.onGestureend},this.windowEvents={pointermove:this.onPointerMove,pointerup:this.onPointerUp,pointercancel:this.onPointerCancel,mousemove:this.onMouseMove,mouseup:this.onMouseUp,touchmove:this.onTouchMove,touchend:this.onTouchEnd,touchcancel:this.onTouchCancel,keydown:this.onKeyDown,keyup:this.onKeyUp,scroll:this.onScroll};const{viewEvents:e,windowEvents:i}=this;for(let i in e)e[i]=e[i].bind(this),t.addEventListener(i,e[i]);for(let t in i)i[t]=i[t].bind(this),window.addEventListener(t,i[t])}__removeListenEvents(){super.__removeListenEvents();const{viewEvents:t,windowEvents:e}=this;for(let e in t)this.view.removeEventListener(e,t[e]),this.viewEvents={};for(let t in e)window.removeEventListener(t,e[t]),this.windowEvents={}}getTouches(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push(t[i]);return e}preventDefaultPointer(t){const{pointer:e}=this.config;e.preventDefault&&t.preventDefault()}preventDefaultWheel(t){const{wheel:e}=this.config;e.preventDefault&&t.preventDefault()}preventWindowPointer(t){return!this.downData&&t.target!==this.view}onKeyDown(t){this.keyDown(kt.convert(t))}onKeyUp(t){this.keyUp(kt.convert(t))}onContextMenu(t){this.config.pointer.preventDefaultMenu&&t.preventDefault(),this.menu(Lt.convert(t,this.getLocal(t)))}onScroll(){this.canvas.updateClientBounds()}onPointerDown(t){this.preventDefaultPointer(t),this.usePointer||(this.usePointer=!0),this.useMultiTouch||this.pointerDown(Lt.convert(t,this.getLocal(t)))}onPointerMove(t){this.usePointer||(this.usePointer=!0),this.useMultiTouch||this.preventWindowPointer(t)||this.pointerMove(Lt.convert(t,this.getLocal(t,!0)))}onPointerUp(t){this.downData&&this.preventDefaultPointer(t),this.useMultiTouch||this.preventWindowPointer(t)||this.pointerUp(Lt.convert(t,this.getLocal(t)))}onPointerCancel(){this.useMultiTouch||this.pointerCancel()}onMouseDown(t){this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.pointerDown(Lt.convertMouse(t,this.getLocal(t)))}onMouseMove(t){this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerMove(Lt.convertMouse(t,this.getLocal(t,!0)))}onMouseUp(t){this.downData&&this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerUp(Lt.convertMouse(t,this.getLocal(t)))}onMouseCancel(){this.useTouch||this.usePointer||this.pointerCancel()}onTouchStart(t){if(t.preventDefault(),this.multiTouchStart(t),this.usePointer)return;this.touchTimer&&(window.clearTimeout(this.touchTimer),this.touchTimer=0),this.useTouch=!0;const e=Lt.getTouch(t);this.pointerDown(Lt.convertTouch(t,this.getLocal(e,!0)))}onTouchMove(t){if(this.multiTouchMove(t),this.usePointer||this.preventWindowPointer(t))return;const e=Lt.getTouch(t);this.pointerMove(Lt.convertTouch(t,this.getLocal(e)))}onTouchEnd(t){if(this.multiTouchEnd(),this.usePointer||this.preventWindowPointer(t))return;this.touchTimer&&clearTimeout(this.touchTimer),this.touchTimer=setTimeout((()=>{this.useTouch=!1}),500);const e=Lt.getTouch(t);this.pointerUp(Lt.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.usePointer||this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>=2,this.touches=this.useMultiTouch?this.getTouches(t.touches):void 0,this.useMultiTouch&&this.pointerCancel()}multiTouchMove(t){if(this.useMultiTouch&&t.touches.length>1){const e=this.getTouches(t.touches),i=this.getKeepTouchList(this.touches,e);i.length>1&&(this.multiTouch(D.getBase(t),i),this.touches=e)}}multiTouchEnd(){this.touches=null,this.useMultiTouch=!1,this.transformEnd()}getKeepTouchList(t,e){let i;const s=[];return t.forEach((t=>{i=e.find((e=>e.identifier===t.identifier)),i&&s.push({from:this.getLocal(t),to:this.getLocal(i)})})),s}getLocalTouchs(t){return t.map((t=>this.getLocal(t)))}onWheel(t){this.preventDefaultWheel(t);const{wheel:e}=this.config,i=e.getScale?e.getScale(t,e):Rt.getScale(t,e),s=this.getLocal(t),n=D.getBase(t);1!==i?this.zoom(Tt(s,i,n)):this.move(Mt(s,e.getMove?e.getMove(t,e):Rt.getMove(t,e),n))}onGesturestart(t){this.preventDefaultWheel(t),this.lastGestureScale=1,this.lastGestureRotation=0}onGesturechange(t){this.preventDefaultWheel(t);const e=this.getLocal(t),i=D.getBase(t),s=t.scale/this.lastGestureScale,n=t.rotation-this.lastGestureRotation;let{rotateSpeed:o}=this.config.wheel;o=R.within(o,0,1),this.zoom(Tt(e,s*s,i)),this.rotate(St(e,n/Math.PI*180*(o/4+.1),i)),this.lastGestureScale=t.scale,this.lastGestureRotation=t.rotation}onGestureend(t){this.preventDefaultWheel(t),this.transformEnd()}setCursor(t){super.setCursor(t);const e=[];this.eachCursor(t,e),"object"==typeof e[e.length-1]&&e.push("default"),this.canvas.view.style.cursor=e.map((t=>"object"==typeof t?`url(${t.url}) ${t.x||0} ${t.y||0}`:t)).join(",")}eachCursor(t,e,i=0){if(i++,t instanceof Array)t.forEach((t=>this.eachCursor(t,e,i)));else{const s="string"==typeof t&&F.get(t);s&&i<2?this.eachCursor(s,e,i):e.push(t)}}destroy(){this.view&&(super.destroy(),this.view=null,this.touches=null)}}function Ot(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,r=s.length;t<r;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 Pt(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?Dt(t,!0,e,i):At(e,i);break;case"inside":Wt("inside",t,n,e,i);break;case"outside":Wt("outside",t,n,e,i)}}function Wt(t,e,i,s,n){const{__strokeWidth:o,__font:r}=s.__,a=n.getSameCanvas(!0,!0);a.setStroke(i?void 0:e,2*o,s.__),a.font=r,i?Dt(e,!0,s,a):At(s,a),a.blendMode="outside"===t?"destination-out":"destination-in",Ot(s,a),a.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(a,s.__nowWorld):n.copyWorldToInner(a,s.__nowWorld,s.__layout.renderBounds),a.recycle(s.__nowWorld)}function At(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,r=s.length;t<r;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 Dt(t,e,i,s){let n;for(let o=0,r=t.length;o<r;o++)n=t[o],n.image&&G.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?At(i,s):s.stroke(),s.restoreBlendMode()):e?At(i,s):s.stroke())}const{getSpread:It,getOuterOf:Ft,getByMove:Ut,getIntersectData:Yt}=E;let Gt;function Nt(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:r,opacity:a}=e;return{type:n,blendMode:o,style:N.string(r,a)};case"image":return G.image(i,t,e,s,!Gt||!Gt[e.url]);case"linear":return z.linearGradient(e,s);case"radial":return z.radialGradient(e,s);case"angular":return z.conicGradient(e,s);default:return e.r?{type:"solid",style:N.string(e)}:void 0}}const zt={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),Gt=G.recycleImage(t,i);for(let i,n=0,r=o.length;n<r;n++)i=Nt(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 r=0,a=t.length;r<a;r++)s=t[r],s.image&&G.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:r}=s;if(n)if(r)Pt(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:r}=s;if(n)if(r)Pt(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),Dt(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),Dt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,r=i.getSameCanvas(!0,!0);e.__drawRenderPath(r),r.setStroke(void 0,2*n,s),Dt(t,!1,e,r),s.windingRule?r.clip(s.windingRule):r.clip(),r.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(r,e.__nowWorld):i.copyWorldToInner(r,e.__nowWorld,o),r.recycle(e.__nowWorld)}},strokeText:Pt,drawTextStroke:At,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,r,a,h,{scaleX:l,scaleY:d}=n;if(l<0&&(l=-l),d<0&&(d=-d),e.bounds.includes(n))h=s,o=a=n;else{const{renderShapeSpread:s}=t.__layout,c=Yt(s?It(e.bounds,l===d?s*l:[s*d,s*l]):e.bounds,n);r=e.bounds.getFitMatrix(c);let{a:u,d:p}=r;if(r.a<1&&(h=e.getSameCanvas(),t.__renderShape(h,i),l*=u,d*=p),a=Ft(n,r),o=Ut(a,-r.e,-r.f),i.matrix){const{matrix:t}=i;r.multiply(t),u*=t.scaleX,p*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:r.withScale(u,p)})}return t.__renderShape(s,i),{canvas:s,matrix:r,bounds:o,worldCanvas:h,shapeBounds:a,scaleX:l,scaleY:d}}};let Vt={};const{get:jt,rotateOfOuter:Xt,translate:Ht,scaleOfOuter:qt,scale:Kt,rotate:Qt}=k;function $t(t,e,i,s,n,o,r){const a=jt();Ht(a,e.x+i,e.y+s),Kt(a,n,o),r&&Xt(a,{x:e.x+e.width/2,y:e.y+e.height/2},r),t.transform=a}function Jt(t,e,i,s,n,o,r){const a=jt();Ht(a,e.x+i,e.y+s),n&&Kt(a,n,o),r&&Qt(a,r),t.transform=a}function Zt(t,e,i,s,n,o,r,a,h,l){const d=jt();if(h)if("center"===l)Xt(d,{x:i/2,y:s/2},h);else switch(Qt(d,h),h){case 90:Ht(d,s,0);break;case 180:Ht(d,i,s);break;case 270:Ht(d,0,i)}Vt.x=e.x+n,Vt.y=e.y+o,Ht(d,Vt.x,Vt.y),r&&qt(d,Vt,r,a),t.transform=d}const{get:te,translate:ee}=k,ie=new w,se={};function ne(t,e,i,s){let{width:n,height:o}=e;i.padding&&(s=ie.set(s).shrink(i.padding));const{opacity:r,mode:a,align:h,offset:l,scale:d,size:c,rotation:u,blendMode:p,repeat:f}=i,g=s.width===n&&s.height===o;p&&(t.blendMode=p);const _=t.data={mode:a},w="center"!==h&&(u||0)%180==90,v=w?o:n,y=w?n:o;let m,x,b=0,B=0;if(a&&"cover"!==a&&"fit"!==a)c?(m=("number"==typeof c?c:c.width)/n,x=("number"==typeof c?c:c.height)/o):d&&(m="number"==typeof d?d:d.x,x="number"==typeof d?d:d.y);else if(!g||u){const t=s.width/v,e=s.height/y;m=x="fit"===a?Math.min(t,e):Math.max(t,e),b+=(s.width-n*m)/2,B+=(s.height-o*x)/2}if(h){const t={x:b,y:B,width:v,height:y};m&&(t.width*=m,t.height*=x),M.toPoint(h,t,s,se,!0),b+=se.x,B+=se.y}switch(l&&(b+=l.x,B+=l.y),a){case"strench":g||(n=s.width,o=s.height);break;case"normal":case"clip":(b||B||m||u)&&Jt(_,s,b,B,m,x,u);break;case"repeat":(!g||m||u)&&Zt(_,s,n,o,b,B,m,x,u,h),f||(_.repeat="repeat");break;default:m&&$t(_,s,b,B,m,x,u)}_.transform||(s.x||s.y)&&(_.transform=te(),ee(_.transform,s.x,s.y)),m&&"strench"!==a&&(_.scaleX=m,_.scaleY=x),_.width=n,_.height=o,r&&(_.opacity=r),f&&(_.repeat="string"==typeof f?"x"===f?"repeat-x":"repeat-y":"repeat")}let oe,re=new w;const{isSame:ae}=E;function he(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||ne(n,s,i,o),!0}function le(t,e){ue(t,T.LOAD,e)}function de(t,e){ue(t,T.LOADED,e)}function ce(t,e,i){e.error=i,t.forceUpdate("surface"),ue(t,T.ERROR,e)}function ue(t,e,i){t.hasEvent(e)&&t.emitEvent(new T(e,i))}function pe(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:fe,scale:ge,copy:_e}=k,{ceil:we,abs:ve}=Math;function ye(t,e,s){let{scaleX:n,scaleY:o}=b.patternLocked?t.__world:t.__nowWorld;const r=n+"-"+o;if(e.patternId===r||t.destroyed)return!1;{n=ve(n),o=ve(o);const{image:t,data:a}=e;let h,l,{width:d,height:c,scaleX:u,scaleY:p,opacity:f,transform:g,repeat:_}=a;u&&(l=fe(),_e(l,g),ge(l,1/u,1/p),n*=u,o*=p),n*=s,o*=s,d*=n,c*=o;const w=d*c;if(!_&&w>i.image.maxCacheSize)return!1;let v=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;v>e&&(v=e)}w>v&&(h=Math.sqrt(w/v)),h&&(n/=h,o/=h,d/=h,c/=h),u&&(n/=u,o/=p),(g||1!==n||1!==o)&&(l||(l=fe(),g&&_e(l,g)),ge(l,1/n,1/o));const y=t.getCanvas(we(d)||1,we(c)||1,f),m=t.getPattern(y,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=m,e.patternId=r,!0}}function me(t,e,i,s){return new(i||(i=Promise))((function(n,o){function r(t){try{h(s.next(t))}catch(t){o(t)}}function a(t){try{h(s.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:xe}=Math;const be={image:function(t,e,i,s,n){let o,r;const a=b.get(i);return oe&&i===oe.paint&&ae(s,oe.boxBounds)?o=oe.leafPaint:(o={type:i.type,image:a},oe=a.use>1?{leafPaint:o,paint:i,boxBounds:re.set(s)}:null),(n||a.loading)&&(r={image:a,attrName:e,attrValue:i}),a.ready?(he(t,e,i,a,o,s),n&&(le(t,r),de(t,r))):a.error?n&&ce(t,r,a.error):(pe(t,!0),n&&le(t,r),o.loadId=a.load((()=>{pe(t,!1),t.destroyed||(he(t,e,i,a,o,s)&&(a.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),de(t,r)),o.loadId=null}),(e=>{pe(t,!1),ce(t,r,e),o.loadId=null}))),o},createData:ne,fillOrFitMode:$t,clipMode:Jt,repeatMode:Zt,createPattern:ye,checkImage:function(t,e,s,n){const{scaleX:o,scaleY:r}=b.patternLocked?t.__world:t.__nowWorld;if(s.data&&s.patternId!==o+"-"+r){const{data:a}=s;if(n)if(a.repeat)n=!1;else{let{width:t,height:s}=a;t*=xe(o)*e.pixelRatio,s*=xe(r)*e.pixelRatio,a.scaleX&&(t*=a.scaleX,s*=a.scaleY),n=t*s>i.image.maxCacheSize}return n?(e.save(),e.clip(),s.blendMode&&(e.blendMode=s.blendMode),a.opacity&&(e.opacity*=a.opacity),a.transform&&e.transform(a.transform),e.drawImage(s.image.view,0,0,a.width,a.height),e.restore(),!0):(!s.style||V.running?ye(t,s,e.pixelRatio):s.patternTask||(s.patternTask=b.patternTasker.add((()=>me(this,void 0,void 0,(function*(){s.patternTask=null,e.bounds.hit(t.__nowWorld)&&ye(t,s,e.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let s,n,o,r;for(let a=0,h=i.length;a<h;a++)s=i[a].image,r=s&&s.url,r&&(n||(n={}),n[r]=!0,b.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[a].loadId,!o.some((t=>t.url===r)))));return n}return null}},{toPoint:Be}=S,Ee={},Le={};function Re(t,e,i){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],"string"==typeof s?t.addColorStop(n/(o-1),N.string(s,i)):t.addColorStop(s.offset,N.string(s.color,i))}const{getAngle:ke,getDistance:Me}=C,{get:Te,rotateOfOuter:Se,scaleOfOuter:Ce}=k,{toPoint:Oe}=S,Pe={},We={};const{getAngle:Ae,getDistance:De}=C,{get:Ie,rotateOfOuter:Fe,scaleOfOuter:Ue}=k,{toPoint:Ye}=S,Ge={},Ne={};const ze={linearGradient:function(t,e){let{from:s,to:n,type:o,blendMode:r,opacity:a}=t;Be(s||"top",e,Ee),Be(n||"bottom",e,Le);const h=i.canvas.createLinearGradient(Ee.x,Ee.y,Le.x,Le.y);Re(h,t.stops,a);const l={type:o,style:h};return r&&(l.blendMode=r),l},radialGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;Oe(s||"center",e,Pe),Oe(n||"bottom",e,We);const{width:l,height:d}=e;let c;(l!==d||h)&&(c=Te(),Ce(c,Pe,l/d*(h||1),1),Se(c,Pe,ke(Pe,We)+90));const u=i.canvas.createRadialGradient(Pe.x,Pe.y,0,Pe.x,Pe.y,Me(Pe,We));Re(u,t.stops,r);const p={type:o,style:u,transform:c};return a&&(p.blendMode=a),p},conicGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;Ye(s||"center",e,Ge),Ye(n||"bottom",e,Ne);const{width:l,height:d}=e,c=Ie(),u=Ae(Ge,Ne);i.conicGradientRotate90?(Ue(c,Ge,l/d*(h||1),1),Fe(c,Ge,u+90)):(Ue(c,Ge,1,l/d*(h||1)),Fe(c,Ge,u));const p=i.conicGradientSupport?i.canvas.createConicGradient(0,Ge.x,Ge.y):i.canvas.createRadialGradient(Ge.x,Ge.y,0,Ge.x,Ge.y,De(Ge,Ne));Re(p,t.stops,r);const f={type:o,style:p,transform:c};return a&&(f.blendMode=a),f}},{copy:Ve,toOffsetOutBounds:je}=E,Xe={},He={};function qe(t,e,s,n){const{bounds:o,shapeBounds:r}=n;if(i.fullImageShadow){if(Ve(Xe,t.bounds),Xe.x+=e.x-r.x,Xe.y+=e.y-r.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&&(Ve(Xe,e),Xe.x-=e.width/2*(s-1),Xe.y-=e.height/2*(s-1),Xe.width*=s,Xe.height*=s),t.copyWorld(n.canvas,r,s?Xe:e)}const{toOffsetOutBounds:Ke}=E,Qe={};const $e={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:r}=t,{shadow:a}=t.__,{worldCanvas:h,bounds:l,shapeBounds:d,scaleX:c,scaleY:u}=i,p=e.getSameCanvas(),f=a.length-1;je(l,He),a.forEach(((a,g)=>{p.setWorldShadow(He.offsetX+a.x*c,He.offsetY+a.y*u,a.blur*c,a.color),n=a.spread?1+2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,qe(p,He,n,i),s=l,a.box&&(p.restore(),p.save(),h&&(p.copyWorld(p,l,o,"copy"),s=o),h?p.copyWorld(h,o,o,"destination-out"):p.copyWorld(i.canvas,d,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(p,s,o,a.blendMode):e.copyWorldToInner(p,s,r.renderBounds,a.blendMode),f&&g<f&&p.clearWorld(s,!0)})),p.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:r}=t,{innerShadow:a}=t.__,{worldCanvas:h,bounds:l,shapeBounds:d,scaleX:c,scaleY:u}=i,p=e.getSameCanvas(),f=a.length-1;Ke(l,Qe),a.forEach(((a,g)=>{p.save(),p.setWorldShadow(Qe.offsetX+a.x*c,Qe.offsetY+a.y*u,a.blur*c),n=a.spread?1-2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,qe(p,Qe,n,i),p.restore(),h?(p.copyWorld(p,l,o,"copy"),p.copyWorld(h,o,o,"source-out"),s=o):(p.copyWorld(i.canvas,d,l,"source-out"),s=l),p.fillWorld(s,a.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(p,s,o,a.blendMode):e.copyWorldToInner(p,s,r.renderBounds,a.blendMode),f&&g<f&&p.clearWorld(s,!0)})),p.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:Je}=v;function Ze(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),ei(t,e,i,1)}(t,i,s,n);break;case"opacity-path":ei(t,i,s,o);break;case"path":i.restore()}}function ti(t){return t.getSameCanvas(!1,!0)}function ei(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}j.prototype.__renderMask=function(t,e){let i,s,n,o,r;const{children:a}=this;for(let h=0,l=a.length;h<l;h++)i=a[h],i.__.mask&&(r&&(Ze(this,r,t,n,s,o),s=n=null),"path"===i.__.mask?(i.opacity<1?(r="opacity-path",o=i.opacity,n||(n=ti(t))):(r="path",t.save()),i.__clip(n||t,e)):(r="alpha",s||(s=ti(t)),n||(n=ti(t)),i.__render(s,e)),"clipping"!==i.__.mask)||Je(i,e)||i.__render(n||t,e);Ze(this,r,t,n,s,o)};const ii=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",si=ii+"_#~&*+\\=|≮≯≈≠=…",ni=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 oi(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const ri=oi("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ai=oi("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),hi=oi(ii),li=oi(si),di=oi("- —/~|┆·");var ci;!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"}(ci||(ci={}));const{Letter:ui,Single:pi,Before:fi,After:gi,Symbol:_i,Break:wi}=ci;function vi(t){return ri[t]?ui:di[t]?wi:ai[t]?fi:hi[t]?gi:li[t]?_i:ni.test(t)?pi:ui}const yi={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 mi(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:xi}=yi,{Letter:bi,Single:Bi,Before:Ei,After:Li,Symbol:Ri,Break:ki}=ci;let Mi,Ti,Si,Ci,Oi,Pi,Wi,Ai,Di,Ii,Fi,Ui,Yi,Gi,Ni,zi,Vi=[];function ji(t,e){Di&&!Ai&&(Ai=Di),Mi.data.push({char:t,width:e}),Si+=e}function Xi(){Ci+=Si,Mi.width=Si,Ti.words.push(Mi),Mi={data:[]},Si=0}function Hi(){Gi&&(Ni.paraNumber++,Ti.paraStart=!0,Gi=!1),Di&&(Ti.startCharSize=Ai,Ti.endCharSize=Di,Ai=0),Ti.width=Ci,zi.width&&xi(Ti),Vi.push(Ti),Ti={words:[]},Ci=0}const qi=0,Ki=1,Qi=2;const{top:$i,right:Ji,bottom:Zi,left:ts}=O;function es(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 is={getDrawData:function(t,e){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=e.__getInput("width")||0,r=e.__getInput("height")||0;const{textDecoration:a,__font:h,__padding:l}=e;l&&(o&&(s=l[ts],o-=l[Ji]+l[ts]),r&&(n=l[$i],r-=l[$i]+l[Zi]));const d={bounds:{x:s,y:n,width:o,height:r},rows:[],paraNumber:0,font:i.canvas.font=h};return function(t,e,s){Ni=t,Vi=t.rows,zi=t.bounds;const{__letterSpacing:n,paraIndent:o,textCase:r}=s,{canvas:a}=i,{width:h,height:l}=zi;if(h||l||n||"none"!==r){const t="none"!==s.textWrap,i="break"===s.textWrap;Gi=!0,Fi=null,Ai=Wi=Di=Si=Ci=0,Mi={data:[]},Ti={words:[]};for(let s=0,l=e.length;s<l;s++)Pi=e[s],"\n"===Pi?(Si&&Xi(),Ti.paraEnd=!0,Hi(),Gi=!0):(Ii=vi(Pi),Ii===bi&&"none"!==r&&(Pi=mi(Pi,r,!Si)),Wi=a.measureText(Pi).width,n&&(n<0&&(Di=Wi),Wi+=n),Ui=Ii===Bi&&(Fi===Bi||Fi===bi)||Fi===Bi&&Ii!==Li,Yi=!(Ii!==Ei&&Ii!==Bi||Fi!==Ri&&Fi!==Li),Oi=Gi&&o?h-o:h,t&&h&&Ci+Si+Wi>Oi&&(i?(Si&&Xi(),Hi()):(Yi||(Yi=Ii===bi&&Fi==Li),Ui||Yi||Ii===ki||Ii===Ei||Ii===Bi||Si+Wi>Oi?(Si&&Xi(),Hi()):Hi()))," "===Pi&&!0!==Gi&&Ci+Si===0||(Ii===ki?(" "===Pi&&Si&&Xi(),ji(Pi,Wi),Xi()):Ui||Yi?(Si&&Xi(),ji(Pi,Wi)):ji(Pi,Wi)),Fi=Ii);Si&&Xi(),Ci&&Hi(),Vi.length>0&&(Vi[Vi.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{Ni.paraNumber++,Vi.push({x:o||0,text:t,width:a.measureText(t).width,paraStart:!0})}))}(d,t,e),l&&function(t,e,i,s,n){if(!s)switch(i.textAlign){case"left":es(e,"x",t[ts]);break;case"right":es(e,"x",-t[Ji])}if(!n)switch(i.verticalAlign){case"top":es(e,"y",t[$i]);break;case"bottom":es(e,"y",-t[Zi])}}(l,d,e,o,r),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:r,__clipText:a,textAlign:h,verticalAlign:l,paraSpacing:d}=e;let c,u,p,{x:f,y:g,width:_,height:w}=s,v=n*i.length+(d?d*(t.paraNumber-1):0),y=o;if(a&&v>w)v=Math.max(w,n),t.overflow=i.length;else switch(l){case"middle":g+=(w-v)/2;break;case"bottom":g+=w-v}y+=g;for(let o=0,l=i.length;o<l;o++){if(c=i[o],c.x=f,c.width<_||c.width>_&&!a)switch(h){case"center":c.x+=(_-c.width)/2;break;case"right":c.x+=_-c.width}c.paraStart&&d&&o>0&&(y+=d),c.y=y,y+=n,t.overflow>o&&y>v&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,p=c.width,r<0&&(c.width<0?(p=-c.width+e.fontSize+r,u-=p,p+=e.fontSize):p-=r),u<s.x&&(s.x=u),p>s.width&&(s.width=p),a&&_&&_<p&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=g,s.height=v}(d,e),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:r,letterSpacing:a}=e;let h,l,d,c,u;n.forEach((t=>{t.words&&(d=r&&t.paraStart?r:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-d)/(t.words.length-1):0,c=a||t.isOverflow?qi:l>.01?Ki:Qi,t.isOverflow&&!a&&(t.textMode=!0),c===Qi?(t.x+=d,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=d,h=t.x,t.data=[],t.words.forEach((e=>{c===Ki?(u={char:"",x:h},h=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,h,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):h=function(t,e,i,s){return t.forEach((t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data,t.isOverflow),!t.paraEnd&&l&&(h+=l,t.width+=l)}))),t.words=null)}))}(d,e,o),d.overflow&&function(t,e){const{rows:s,overflow:n}=t;let{textOverflow:o}=e;if(s.splice(n),o&&"show"!==o){let t,r;"hide"===o?o="":"ellipsis"===o&&(o="...");const a=o?i.canvas.measureText(o).width:0,h=e.x+e.width-a;("none"===e.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],r=t.x+t.width,!(s===i&&r<h));s--){if(r<h&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=a,e.data.push({char:o,x:r}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(d,e),"none"!==a&&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}}(d,e),d}};const ss={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:ns,addPoint:os,toBounds:rs}=P;const as={export(t,e,s){return this.running=!0,function(t){hs||(hs=new W);return new Promise((e=>{hs.add((()=>me(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((n=>new Promise((o=>{const r=t=>{n(t),o(),this.running=!1};if("json"===e)return r({data:t.toJSON()});if("json"===l.fileType(e))return i.origin.download("data:text/plain;charset=utf-8,"+encodeURIComponent(JSON.stringify(t.toJSON())),e),r({data:!0});const{leafer:h}=t;h?h.waitViewCompleted((()=>me(this,void 0,void 0,(function*(){s=l.getExportOptions(s);let i,n,o=1,d=1;const{worldTransform:c,isLeafer:u,isFrame:p}=t,{slice:f,trim:g,onCanvas:_}=s;let v=s.scale||1,y=s.pixelRatio||1;t.isApp&&(v*=y,y=t.app.pixelRatio);const m=s.screenshot||t.isApp,x=u&&m&&void 0===s.fill?t.fill:s.fill,b=l.isOpaqueImage(e)||x,B=new A;if(m)i=!0===m?u?h.canvas.bounds:t.worldRenderBounds:m;else{let e=s.relative||(u?"inner":"local");switch(o=c.scaleX,d=c.scaleY,e){case"inner":B.set(c);break;case"local":B.set(c).divide(t.localTransform),o/=t.scaleX,d/=t.scaleY;break;case"world":o=1,d=1;break;case"page":e=t.leafer;default:B.set(c).divide(t.getTransform(e));const i=e.worldTransform;o/=o/i.scaleX,d/=d/i.scaleY}i=t.getBounds("render",e)}const{x:E,y:L,width:R,height:k}=new w(i).scale(v);let M=a.canvas({width:Math.round(R),height:Math.round(k),pixelRatio:y});const T={matrix:B.scale(1/v).invert().translate(-E,-L).withScale(1/o*v,1/d*v)};if(f&&(t=h,T.bounds=M.bounds),M.save(),p&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(M,T),t.fill=e}else t.__render(M,T);if(M.restore(),g){n=function(t){const{width:e,height:i}=t.view,{data:s}=t.context.getImageData(0,0,e,i);let n,o,r,a=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(n=a%e,o=(a-n)/e,r?os(r,n,o):ns(r={},n,o)),a++;const h=new w;return rs(r,h),h.scale(1/t.pixelRatio).ceil()}(M);const t=M,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:y};M=a.canvas(s),M.copyWorld(t,n,s)}b&&M.fillWorld(M.bounds,x||"#FFFFFF","destination-over"),_&&_(M);const S="canvas"===e?M:yield M.export(e,s);r({data:S,width:M.pixelWidth,height:M.pixelHeight,renderBounds:i,trimBounds:n})})))):r({data:!1})}))))}};let hs;const ls=e.prototype,ds=t.get("@leafer-ui/export");ls.export=function(t,e){const{quality:i,blob:s}=l.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):s?this.toBlob(t,i):this.toDataURL(t,i)},ls.toBlob=function(t,e){return new Promise((s=>{i.origin.canvasToBolb(this.view,t,e).then((t=>{s(t)})).catch((t=>{ds.error(t),s(null)}))}))},ls.toDataURL=function(t,e){return i.origin.canvasToDataURL(this.view,t,e)},ls.saveAs=function(t,e){return new Promise((s=>{i.origin.canvasSaveAs(this.view,t,e).then((()=>{s(!0)})).catch((t=>{ds.error(t),s(!1)}))}))},Object.assign(X,is),Object.assign(N,ss),Object.assign(H,zt),Object.assign(G,be),Object.assign(z,ze),Object.assign(q,$e),Object.assign(V,as),Object.assign(a,{interaction:(t,e,i,s)=>new Ct(t,e,i,s),hitCanvas:(t,e)=>new Q(t,e),hitCanvasManager:()=>new U}),Z(),window.addEventListener("unload",(()=>{const{list:t}=Y;t.forEach((t=>t.destroy(!0))),t.destroy(),b.destroy()}));export{Ct as Interaction,pt as Layouter,Q as LeaferCanvas,gt as Renderer,Et as Selector,et as Watcher,Z as useCanvas};
|