@idraw/renderer 0.4.0-beta.23 → 0.4.0-beta.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/draw/box.js +63 -12
- package/dist/esm/draw/global.d.ts +2 -0
- package/dist/esm/draw/global.js +9 -0
- package/dist/esm/draw/group.js +6 -2
- package/dist/esm/draw/image.js +43 -2
- package/dist/esm/draw/index.d.ts +1 -0
- package/dist/esm/draw/index.js +1 -0
- package/dist/esm/draw/layout.js +2 -2
- package/dist/esm/draw/path.js +2 -2
- package/dist/esm/draw/text.js +47 -13
- package/dist/esm/index.js +4 -3
- package/dist/index.global.js +174 -33
- package/dist/index.global.min.js +1 -1
- package/package.json +3 -3
package/dist/esm/draw/box.js
CHANGED
|
@@ -13,19 +13,37 @@ export function drawBox(ctx, viewElem, opts) {
|
|
|
13
13
|
const { pattern, renderContent, originElem, calcElemSize, viewScaleInfo, viewSizeInfo } = opts || {};
|
|
14
14
|
const { parentOpacity } = opts;
|
|
15
15
|
const opacity = getOpacity(originElem) * parentOpacity;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
viewScaleInfo,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
const { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = originElem.detail;
|
|
17
|
+
const mainRender = () => {
|
|
18
|
+
ctx.globalAlpha = opacity;
|
|
19
|
+
drawBoxBackground(ctx, viewElem, { pattern, viewScaleInfo, viewSizeInfo });
|
|
20
|
+
renderContent === null || renderContent === void 0 ? void 0 : renderContent();
|
|
21
|
+
drawBoxBorder(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
|
|
22
|
+
ctx.globalAlpha = parentOpacity;
|
|
23
|
+
};
|
|
24
|
+
if (clipPath) {
|
|
25
|
+
drawClipPath(ctx, viewElem, {
|
|
26
|
+
originElem,
|
|
27
|
+
calcElemSize,
|
|
28
|
+
viewScaleInfo,
|
|
29
|
+
viewSizeInfo,
|
|
30
|
+
renderContent: () => {
|
|
31
|
+
mainRender();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (typeof clipPathStrokeWidth === 'number' && clipPathStrokeWidth > 0 && clipPathStrokeColor) {
|
|
35
|
+
drawClipPathStroke(ctx, viewElem, {
|
|
36
|
+
originElem,
|
|
37
|
+
calcElemSize,
|
|
38
|
+
viewScaleInfo,
|
|
39
|
+
viewSizeInfo,
|
|
40
|
+
parentOpacity
|
|
41
|
+
});
|
|
27
42
|
}
|
|
28
|
-
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
mainRender();
|
|
46
|
+
}
|
|
29
47
|
}
|
|
30
48
|
function drawClipPath(ctx, viewElem, opts) {
|
|
31
49
|
const { renderContent, originElem, calcElemSize, viewSizeInfo } = opts;
|
|
@@ -57,6 +75,39 @@ function drawClipPath(ctx, viewElem, opts) {
|
|
|
57
75
|
renderContent === null || renderContent === void 0 ? void 0 : renderContent();
|
|
58
76
|
}
|
|
59
77
|
}
|
|
78
|
+
function drawClipPathStroke(ctx, viewElem, opts) {
|
|
79
|
+
const { renderContent, originElem, calcElemSize, viewSizeInfo, parentOpacity } = opts;
|
|
80
|
+
const totalScale = viewSizeInfo.devicePixelRatio;
|
|
81
|
+
const { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = (originElem === null || originElem === void 0 ? void 0 : originElem.detail) || {};
|
|
82
|
+
if (clipPath && calcElemSize && clipPath.commands && typeof clipPathStrokeWidth === 'number' && clipPathStrokeWidth > 0 && clipPathStrokeColor) {
|
|
83
|
+
const { x, y, w, h } = calcElemSize;
|
|
84
|
+
const { originW, originH, originX, originY } = clipPath;
|
|
85
|
+
const scaleW = w / originW;
|
|
86
|
+
const scaleH = h / originH;
|
|
87
|
+
const viewOriginX = originX * scaleW;
|
|
88
|
+
const viewOriginY = originY * scaleH;
|
|
89
|
+
const internalX = x - viewOriginX;
|
|
90
|
+
const internalY = y - viewOriginY;
|
|
91
|
+
ctx.save();
|
|
92
|
+
ctx.globalAlpha = parentOpacity;
|
|
93
|
+
ctx.translate(internalX, internalY);
|
|
94
|
+
ctx.scale(totalScale * scaleW, totalScale * scaleH);
|
|
95
|
+
const pathStr = generateSVGPath(clipPath.commands || []);
|
|
96
|
+
const path2d = new Path2D(pathStr);
|
|
97
|
+
ctx.strokeStyle = clipPathStrokeColor;
|
|
98
|
+
ctx.lineWidth = clipPathStrokeWidth;
|
|
99
|
+
ctx.stroke(path2d);
|
|
100
|
+
ctx.translate(0 - internalX, 0 - internalY);
|
|
101
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
102
|
+
rotateElement(ctx, Object.assign({}, viewElem), () => {
|
|
103
|
+
renderContent === null || renderContent === void 0 ? void 0 : renderContent();
|
|
104
|
+
});
|
|
105
|
+
ctx.restore();
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
renderContent === null || renderContent === void 0 ? void 0 : renderContent();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
60
111
|
export function drawBoxBackground(ctx, viewElem, opts) {
|
|
61
112
|
var _a, _b;
|
|
62
113
|
const { pattern, viewScaleInfo, viewSizeInfo } = opts;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function drawGlobalBackground(ctx, global, opts) {
|
|
2
|
+
if (typeof (global === null || global === void 0 ? void 0 : global.background) === 'string') {
|
|
3
|
+
const { viewSizeInfo } = opts;
|
|
4
|
+
const { width, height } = viewSizeInfo;
|
|
5
|
+
ctx.globalAlpha = 1;
|
|
6
|
+
ctx.fillStyle = global.background;
|
|
7
|
+
ctx.fillRect(0, 0, width, height);
|
|
8
|
+
}
|
|
9
|
+
}
|
package/dist/esm/draw/group.js
CHANGED
|
@@ -8,7 +8,7 @@ import { drawHTML } from './html';
|
|
|
8
8
|
import { drawBox, drawBoxShadow, getOpacity } from './box';
|
|
9
9
|
import { drawPath } from './path';
|
|
10
10
|
export function drawElement(ctx, elem, opts) {
|
|
11
|
-
var _a;
|
|
11
|
+
var _a, _b, _c;
|
|
12
12
|
if (((_a = elem === null || elem === void 0 ? void 0 : elem.operations) === null || _a === void 0 ? void 0 : _a.invisible) === true) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
@@ -17,6 +17,10 @@ export function drawElement(ctx, elem, opts) {
|
|
|
17
17
|
if ((scale < 1 && (w * scale < 1 || h * scale < 1)) || opts.parentOpacity === 0) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
+
const { overrideElementMap } = opts;
|
|
21
|
+
if ((_c = (_b = overrideElementMap === null || overrideElementMap === void 0 ? void 0 : overrideElementMap[elem.uuid]) === null || _b === void 0 ? void 0 : _b.operations) === null || _c === void 0 ? void 0 : _c.invisible) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
20
24
|
try {
|
|
21
25
|
switch (elem.type) {
|
|
22
26
|
case 'rect': {
|
|
@@ -63,7 +67,7 @@ export function drawElement(ctx, elem, opts) {
|
|
|
63
67
|
}
|
|
64
68
|
export function drawGroup(ctx, elem, opts) {
|
|
65
69
|
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
66
|
-
const { x, y, w, h, angle } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h, angle: elem.angle }, { viewScaleInfo
|
|
70
|
+
const { x, y, w, h, angle } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h, angle: elem.angle }, { viewScaleInfo }) || elem;
|
|
67
71
|
const viewElem = Object.assign(Object.assign({}, elem), { x, y, w, h, angle });
|
|
68
72
|
rotateElement(ctx, { x, y, w, h, angle }, () => {
|
|
69
73
|
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
package/dist/esm/draw/image.js
CHANGED
|
@@ -3,7 +3,7 @@ import { drawBox, drawBoxShadow, getOpacity } from './box';
|
|
|
3
3
|
export function drawImage(ctx, elem, opts) {
|
|
4
4
|
const content = opts.loader.getContent(elem);
|
|
5
5
|
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
6
|
-
const { x, y, w, h, angle } = calcViewElementSize(elem, { viewScaleInfo
|
|
6
|
+
const { x, y, w, h, angle } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
7
7
|
const viewElem = Object.assign(Object.assign({}, elem), { x, y, w, h, angle });
|
|
8
8
|
rotateElement(ctx, { x, y, w, h, angle }, () => {
|
|
9
9
|
drawBoxShadow(ctx, viewElem, {
|
|
@@ -26,6 +26,10 @@ export function drawImage(ctx, elem, opts) {
|
|
|
26
26
|
viewScaleInfo,
|
|
27
27
|
viewSizeInfo
|
|
28
28
|
});
|
|
29
|
+
const { detail } = elem;
|
|
30
|
+
const { scaleMode, originW = 0, originH = 0 } = detail;
|
|
31
|
+
const imageW = ctx.$undoPixelRatio(originW);
|
|
32
|
+
const imageH = ctx.$undoPixelRatio(originH);
|
|
29
33
|
ctx.save();
|
|
30
34
|
ctx.fillStyle = 'transparent';
|
|
31
35
|
ctx.beginPath();
|
|
@@ -37,7 +41,44 @@ export function drawImage(ctx, elem, opts) {
|
|
|
37
41
|
ctx.closePath();
|
|
38
42
|
ctx.fill();
|
|
39
43
|
ctx.clip();
|
|
40
|
-
|
|
44
|
+
if (scaleMode && originH && originW) {
|
|
45
|
+
let sx = 0;
|
|
46
|
+
let sy = 0;
|
|
47
|
+
let sWidth = imageW;
|
|
48
|
+
let sHeight = imageH;
|
|
49
|
+
const dx = x;
|
|
50
|
+
const dy = y;
|
|
51
|
+
const dWidth = w;
|
|
52
|
+
const dHeight = h;
|
|
53
|
+
if (imageW > elem.w || imageH > elem.h) {
|
|
54
|
+
if (scaleMode === 'fill') {
|
|
55
|
+
const sourceScale = Math.max(elem.w / imageW, elem.h / imageH);
|
|
56
|
+
const newImageWidth = imageW * sourceScale;
|
|
57
|
+
const newImageHeight = imageH * sourceScale;
|
|
58
|
+
sx = (newImageWidth - elem.w) / 2 / sourceScale;
|
|
59
|
+
sy = (newImageHeight - elem.h) / 2 / sourceScale;
|
|
60
|
+
sWidth = elem.w / sourceScale;
|
|
61
|
+
sHeight = elem.h / sourceScale;
|
|
62
|
+
}
|
|
63
|
+
else if (scaleMode === 'tile') {
|
|
64
|
+
sx = 0;
|
|
65
|
+
sy = 0;
|
|
66
|
+
sWidth = elem.w;
|
|
67
|
+
sHeight = elem.h;
|
|
68
|
+
}
|
|
69
|
+
else if (scaleMode === 'fit') {
|
|
70
|
+
const sourceScale = Math.min(elem.w / imageW, elem.h / imageH);
|
|
71
|
+
sx = (imageW - elem.w / sourceScale) / 2;
|
|
72
|
+
sy = (imageH - elem.h / sourceScale) / 2;
|
|
73
|
+
sWidth = elem.w / sourceScale;
|
|
74
|
+
sHeight = elem.h / sourceScale;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
ctx.drawImage(content, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
ctx.drawImage(content, x, y, w, h);
|
|
81
|
+
}
|
|
41
82
|
ctx.globalAlpha = parentOpacity;
|
|
42
83
|
ctx.restore();
|
|
43
84
|
}
|
package/dist/esm/draw/index.d.ts
CHANGED
package/dist/esm/draw/index.js
CHANGED
package/dist/esm/draw/layout.js
CHANGED
|
@@ -3,7 +3,7 @@ import { drawBoxShadow, drawBoxBackground, drawBoxBorder } from './box';
|
|
|
3
3
|
export function drawLayout(ctx, layout, opts, renderContent) {
|
|
4
4
|
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
5
5
|
const elem = Object.assign({ uuid: 'layout', type: 'group' }, layout);
|
|
6
|
-
const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo
|
|
6
|
+
const { x, y, w, h } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
7
7
|
const angle = 0;
|
|
8
8
|
const viewElem = Object.assign(Object.assign({}, elem), { x, y, w, h, angle });
|
|
9
9
|
ctx.globalAlpha = 1;
|
|
@@ -17,7 +17,7 @@ export function drawLayout(ctx, layout, opts, renderContent) {
|
|
|
17
17
|
if (layout.detail.overflow === 'hidden') {
|
|
18
18
|
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
19
19
|
const elem = Object.assign({ uuid: 'layout', type: 'group' }, layout);
|
|
20
|
-
const viewElemSize = calcViewElementSize(elem, { viewScaleInfo
|
|
20
|
+
const viewElemSize = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
21
21
|
const viewElem = Object.assign(Object.assign({}, elem), viewElemSize);
|
|
22
22
|
const { x, y, w, h, radiusList } = calcViewBoxSize(viewElem, {
|
|
23
23
|
viewScaleInfo,
|
package/dist/esm/draw/path.js
CHANGED
|
@@ -2,7 +2,7 @@ import { rotateElement, generateSVGPath, calcViewElementSize } from '@idraw/util
|
|
|
2
2
|
import { drawBox, drawBoxShadow } from './box';
|
|
3
3
|
export function drawPath(ctx, elem, opts) {
|
|
4
4
|
const { detail } = elem;
|
|
5
|
-
const { originX, originY, originW, originH } = detail;
|
|
5
|
+
const { originX, originY, originW, originH, fillRule } = detail;
|
|
6
6
|
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
7
7
|
const { x, y, w, h, angle } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
8
8
|
const scaleW = w / originW;
|
|
@@ -32,7 +32,7 @@ export function drawPath(ctx, elem, opts) {
|
|
|
32
32
|
const path2d = new Path2D(pathStr);
|
|
33
33
|
if (detail.fill) {
|
|
34
34
|
ctx.fillStyle = detail.fill;
|
|
35
|
-
ctx.fill(path2d);
|
|
35
|
+
ctx.fill(path2d, fillRule);
|
|
36
36
|
}
|
|
37
37
|
if (detail.stroke && detail.strokeWidth !== 0) {
|
|
38
38
|
ctx.strokeStyle = detail.stroke;
|
package/dist/esm/draw/text.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import { rotateElement, calcViewElementSize } from '@idraw/util';
|
|
1
|
+
import { rotateElement, calcViewElementSize, enhanceFontFamliy } from '@idraw/util';
|
|
2
2
|
import { is, isColorStr, getDefaultElementDetailConfig } from '@idraw/util';
|
|
3
3
|
import { drawBox } from './box';
|
|
4
4
|
const detailConfig = getDefaultElementDetailConfig();
|
|
5
|
+
function isTextWidthWithinErrorRange(w0, w1, scale) {
|
|
6
|
+
if (scale < 0.5) {
|
|
7
|
+
if (w0 < w1 && (w0 - w1) / w0 > -0.15) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return w0 >= w1;
|
|
12
|
+
}
|
|
5
13
|
export function drawText(ctx, elem, opts) {
|
|
6
14
|
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
7
15
|
const { x, y, w, h, angle } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
@@ -17,6 +25,9 @@ export function drawText(ctx, elem, opts) {
|
|
|
17
25
|
const detail = Object.assign(Object.assign({}, detailConfig), elem.detail);
|
|
18
26
|
const originFontSize = detail.fontSize || detailConfig.fontSize;
|
|
19
27
|
const fontSize = originFontSize * viewScaleInfo.scale;
|
|
28
|
+
if (fontSize < 2) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
20
31
|
const originLineHeight = detail.lineHeight || originFontSize;
|
|
21
32
|
const lineHeight = originLineHeight * viewScaleInfo.scale;
|
|
22
33
|
ctx.fillStyle = elem.detail.color || detailConfig.color;
|
|
@@ -24,7 +35,7 @@ export function drawText(ctx, elem, opts) {
|
|
|
24
35
|
ctx.$setFont({
|
|
25
36
|
fontWeight: detail.fontWeight,
|
|
26
37
|
fontSize: fontSize,
|
|
27
|
-
fontFamily: detail.fontFamily
|
|
38
|
+
fontFamily: enhanceFontFamliy(detail.fontFamily)
|
|
28
39
|
});
|
|
29
40
|
let detailText = detail.text.replace(/\r\n/gi, '\n');
|
|
30
41
|
if (detail.textTransform === 'lowercase') {
|
|
@@ -37,32 +48,51 @@ export function drawText(ctx, elem, opts) {
|
|
|
37
48
|
const detailTextList = detailText.split('\n');
|
|
38
49
|
const lines = [];
|
|
39
50
|
let lineNum = 0;
|
|
40
|
-
detailTextList.forEach((
|
|
51
|
+
detailTextList.forEach((itemText, idx) => {
|
|
41
52
|
if (detail.minInlineSize === 'maxContent') {
|
|
42
53
|
lines.push({
|
|
43
|
-
text:
|
|
44
|
-
width: ctx.$undoPixelRatio(ctx.measureText(
|
|
54
|
+
text: itemText,
|
|
55
|
+
width: ctx.$undoPixelRatio(ctx.measureText(itemText).width)
|
|
45
56
|
});
|
|
46
57
|
}
|
|
47
58
|
else {
|
|
48
59
|
let lineText = '';
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
let splitStr = '';
|
|
61
|
+
let tempStrList = itemText.split(splitStr);
|
|
62
|
+
if (detail.wordBreak === 'normal') {
|
|
63
|
+
const splitStr = ' ';
|
|
64
|
+
const wordList = itemText.split(splitStr);
|
|
65
|
+
tempStrList = [];
|
|
66
|
+
wordList.forEach((word, idx) => {
|
|
67
|
+
tempStrList.push(word);
|
|
68
|
+
if (idx < wordList.length - 1) {
|
|
69
|
+
tempStrList.push(splitStr);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (tempStrList.length === 1 && detail.overflow === 'visible') {
|
|
74
|
+
lines.push({
|
|
75
|
+
text: tempStrList[0],
|
|
76
|
+
width: ctx.$undoPixelRatio(ctx.measureText(tempStrList[0]).width)
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else if (tempStrList.length > 0) {
|
|
80
|
+
for (let i = 0; i < tempStrList.length; i++) {
|
|
81
|
+
if (isTextWidthWithinErrorRange(ctx.$doPixelRatio(w), ctx.measureText(lineText + tempStrList[i]).width, viewScaleInfo.scale)) {
|
|
82
|
+
lineText += tempStrList[i] || '';
|
|
53
83
|
}
|
|
54
84
|
else {
|
|
55
85
|
lines.push({
|
|
56
86
|
text: lineText,
|
|
57
87
|
width: ctx.$undoPixelRatio(ctx.measureText(lineText).width)
|
|
58
88
|
});
|
|
59
|
-
lineText =
|
|
89
|
+
lineText = tempStrList[i] || '';
|
|
60
90
|
lineNum++;
|
|
61
91
|
}
|
|
62
|
-
if ((lineNum + 1) * fontHeight > h) {
|
|
92
|
+
if ((lineNum + 1) * fontHeight > h && detail.overflow === 'hidden') {
|
|
63
93
|
break;
|
|
64
94
|
}
|
|
65
|
-
if (
|
|
95
|
+
if (tempStrList.length - 1 === i) {
|
|
66
96
|
if ((lineNum + 1) * fontHeight <= h) {
|
|
67
97
|
lines.push({
|
|
68
98
|
text: lineText,
|
|
@@ -85,6 +115,10 @@ export function drawText(ctx, elem, opts) {
|
|
|
85
115
|
}
|
|
86
116
|
});
|
|
87
117
|
let startY = 0;
|
|
118
|
+
let eachLineStartY = 0;
|
|
119
|
+
if (fontHeight > fontSize) {
|
|
120
|
+
eachLineStartY = (fontHeight - fontSize) / 2;
|
|
121
|
+
}
|
|
88
122
|
if (lines.length * fontHeight < h) {
|
|
89
123
|
if (elem.detail.verticalAlign === 'top') {
|
|
90
124
|
startY = 0;
|
|
@@ -118,7 +152,7 @@ export function drawText(ctx, elem, opts) {
|
|
|
118
152
|
else if (detail.textAlign === 'right') {
|
|
119
153
|
_x = x + (w - line.width);
|
|
120
154
|
}
|
|
121
|
-
ctx.fillText(line.text, _x, _y + fontHeight * i);
|
|
155
|
+
ctx.fillText(line.text, _x, _y + fontHeight * i + eachLineStartY);
|
|
122
156
|
});
|
|
123
157
|
}
|
|
124
158
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _Renderer_instances, _Renderer_opts, _Renderer_loader, _Renderer_hasDestroyed, _Renderer_init;
|
|
13
13
|
import { EventEmitter } from '@idraw/util';
|
|
14
|
-
import { drawElementList, drawLayout } from './draw/index';
|
|
14
|
+
import { drawElementList, drawLayout, drawGlobalBackground } from './draw/index';
|
|
15
15
|
import { Loader } from './loader';
|
|
16
16
|
export class Renderer extends EventEmitter {
|
|
17
17
|
constructor(opts) {
|
|
@@ -38,7 +38,7 @@ export class Renderer extends EventEmitter {
|
|
|
38
38
|
}
|
|
39
39
|
drawData(data, opts) {
|
|
40
40
|
const loader = __classPrivateFieldGet(this, _Renderer_loader, "f");
|
|
41
|
-
const { calculator } = __classPrivateFieldGet(this, _Renderer_opts, "f");
|
|
41
|
+
const { calculator, sharer } = __classPrivateFieldGet(this, _Renderer_opts, "f");
|
|
42
42
|
const viewContext = __classPrivateFieldGet(this, _Renderer_opts, "f").viewContext;
|
|
43
43
|
viewContext.clearRect(0, 0, viewContext.canvas.width, viewContext.canvas.height);
|
|
44
44
|
const parentElementSize = {
|
|
@@ -49,7 +49,8 @@ export class Renderer extends EventEmitter {
|
|
|
49
49
|
};
|
|
50
50
|
const drawOpts = Object.assign({ loader,
|
|
51
51
|
calculator,
|
|
52
|
-
parentElementSize, elementAssets: data.assets, parentOpacity: 1 }, opts);
|
|
52
|
+
parentElementSize, elementAssets: data.assets, parentOpacity: 1, overrideElementMap: sharer === null || sharer === void 0 ? void 0 : sharer.getActiveOverrideElemenentMap() }, opts);
|
|
53
|
+
drawGlobalBackground(viewContext, data.global, drawOpts);
|
|
53
54
|
if (data.layout) {
|
|
54
55
|
drawLayout(viewContext, data.layout, drawOpts, () => {
|
|
55
56
|
drawElementList(viewContext, data, drawOpts);
|
package/dist/index.global.js
CHANGED
|
@@ -493,6 +493,8 @@ var __privateMethod = (obj, member, method) => {
|
|
|
493
493
|
fontSize: 16,
|
|
494
494
|
fontFamily: "sans-serif",
|
|
495
495
|
fontWeight: 400,
|
|
496
|
+
minInlineSize: "auto",
|
|
497
|
+
wordBreak: "break-all",
|
|
496
498
|
overflow: "hidden"
|
|
497
499
|
};
|
|
498
500
|
return config;
|
|
@@ -548,6 +550,10 @@ var __privateMethod = (obj, member, method) => {
|
|
|
548
550
|
radiusList
|
|
549
551
|
};
|
|
550
552
|
}
|
|
553
|
+
const baseFontFamilyList = ["-apple-system", '"system-ui"', ' "Segoe UI"', " Roboto", '"Helvetica Neue"', "Arial", '"Noto Sans"', " sans-serif"];
|
|
554
|
+
function enhanceFontFamliy(fontFamily2) {
|
|
555
|
+
return [fontFamily2, ...baseFontFamilyList].join(", ");
|
|
556
|
+
}
|
|
551
557
|
function createColorStyle(ctx, color2, opts) {
|
|
552
558
|
if (typeof color2 === "string") {
|
|
553
559
|
return color2;
|
|
@@ -604,19 +610,36 @@ var __privateMethod = (obj, member, method) => {
|
|
|
604
610
|
const { pattern, renderContent, originElem, calcElemSize, viewScaleInfo, viewSizeInfo } = opts || {};
|
|
605
611
|
const { parentOpacity } = opts;
|
|
606
612
|
const opacity = getOpacity(originElem) * parentOpacity;
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
viewScaleInfo,
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
613
|
+
const { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = originElem.detail;
|
|
614
|
+
const mainRender = () => {
|
|
615
|
+
ctx.globalAlpha = opacity;
|
|
616
|
+
drawBoxBackground(ctx, viewElem, { pattern, viewScaleInfo, viewSizeInfo });
|
|
617
|
+
renderContent == null ? void 0 : renderContent();
|
|
618
|
+
drawBoxBorder(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
|
|
619
|
+
ctx.globalAlpha = parentOpacity;
|
|
620
|
+
};
|
|
621
|
+
if (clipPath) {
|
|
622
|
+
drawClipPath(ctx, viewElem, {
|
|
623
|
+
originElem,
|
|
624
|
+
calcElemSize,
|
|
625
|
+
viewScaleInfo,
|
|
626
|
+
viewSizeInfo,
|
|
627
|
+
renderContent: () => {
|
|
628
|
+
mainRender();
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
if (typeof clipPathStrokeWidth === "number" && clipPathStrokeWidth > 0 && clipPathStrokeColor) {
|
|
632
|
+
drawClipPathStroke(ctx, viewElem, {
|
|
633
|
+
originElem,
|
|
634
|
+
calcElemSize,
|
|
635
|
+
viewScaleInfo,
|
|
636
|
+
viewSizeInfo,
|
|
637
|
+
parentOpacity
|
|
638
|
+
});
|
|
618
639
|
}
|
|
619
|
-
}
|
|
640
|
+
} else {
|
|
641
|
+
mainRender();
|
|
642
|
+
}
|
|
620
643
|
}
|
|
621
644
|
function drawClipPath(ctx, viewElem, opts) {
|
|
622
645
|
const { renderContent, originElem, calcElemSize, viewSizeInfo } = opts;
|
|
@@ -647,6 +670,38 @@ var __privateMethod = (obj, member, method) => {
|
|
|
647
670
|
renderContent == null ? void 0 : renderContent();
|
|
648
671
|
}
|
|
649
672
|
}
|
|
673
|
+
function drawClipPathStroke(ctx, viewElem, opts) {
|
|
674
|
+
const { renderContent, originElem, calcElemSize, viewSizeInfo, parentOpacity } = opts;
|
|
675
|
+
const totalScale = viewSizeInfo.devicePixelRatio;
|
|
676
|
+
const { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = (originElem == null ? void 0 : originElem.detail) || {};
|
|
677
|
+
if (clipPath && calcElemSize && clipPath.commands && typeof clipPathStrokeWidth === "number" && clipPathStrokeWidth > 0 && clipPathStrokeColor) {
|
|
678
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcElemSize;
|
|
679
|
+
const { originW, originH, originX, originY } = clipPath;
|
|
680
|
+
const scaleW = w2 / originW;
|
|
681
|
+
const scaleH = h2 / originH;
|
|
682
|
+
const viewOriginX = originX * scaleW;
|
|
683
|
+
const viewOriginY = originY * scaleH;
|
|
684
|
+
const internalX = x2 - viewOriginX;
|
|
685
|
+
const internalY = y2 - viewOriginY;
|
|
686
|
+
ctx.save();
|
|
687
|
+
ctx.globalAlpha = parentOpacity;
|
|
688
|
+
ctx.translate(internalX, internalY);
|
|
689
|
+
ctx.scale(totalScale * scaleW, totalScale * scaleH);
|
|
690
|
+
const pathStr = generateSVGPath(clipPath.commands || []);
|
|
691
|
+
const path2d = new Path2D(pathStr);
|
|
692
|
+
ctx.strokeStyle = clipPathStrokeColor;
|
|
693
|
+
ctx.lineWidth = clipPathStrokeWidth;
|
|
694
|
+
ctx.stroke(path2d);
|
|
695
|
+
ctx.translate(0 - internalX, 0 - internalY);
|
|
696
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
697
|
+
rotateElement(ctx, { ...viewElem }, () => {
|
|
698
|
+
renderContent == null ? void 0 : renderContent();
|
|
699
|
+
});
|
|
700
|
+
ctx.restore();
|
|
701
|
+
} else {
|
|
702
|
+
renderContent == null ? void 0 : renderContent();
|
|
703
|
+
}
|
|
704
|
+
}
|
|
650
705
|
function drawBoxBackground(ctx, viewElem, opts) {
|
|
651
706
|
var _a, _b;
|
|
652
707
|
const { pattern, viewScaleInfo, viewSizeInfo } = opts;
|
|
@@ -952,7 +1007,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
952
1007
|
function drawImage(ctx, elem, opts) {
|
|
953
1008
|
const content = opts.loader.getContent(elem);
|
|
954
1009
|
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
955
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo
|
|
1010
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
956
1011
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
957
1012
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
958
1013
|
drawBoxShadow(ctx, viewElem, {
|
|
@@ -975,6 +1030,10 @@ var __privateMethod = (obj, member, method) => {
|
|
|
975
1030
|
viewScaleInfo,
|
|
976
1031
|
viewSizeInfo
|
|
977
1032
|
});
|
|
1033
|
+
const { detail } = elem;
|
|
1034
|
+
const { scaleMode, originW = 0, originH = 0 } = detail;
|
|
1035
|
+
const imageW = ctx.$undoPixelRatio(originW);
|
|
1036
|
+
const imageH = ctx.$undoPixelRatio(originH);
|
|
978
1037
|
ctx.save();
|
|
979
1038
|
ctx.fillStyle = "transparent";
|
|
980
1039
|
ctx.beginPath();
|
|
@@ -986,7 +1045,41 @@ var __privateMethod = (obj, member, method) => {
|
|
|
986
1045
|
ctx.closePath();
|
|
987
1046
|
ctx.fill();
|
|
988
1047
|
ctx.clip();
|
|
989
|
-
|
|
1048
|
+
if (scaleMode && originH && originW) {
|
|
1049
|
+
let sx = 0;
|
|
1050
|
+
let sy = 0;
|
|
1051
|
+
let sWidth = imageW;
|
|
1052
|
+
let sHeight = imageH;
|
|
1053
|
+
const dx = x22;
|
|
1054
|
+
const dy = y22;
|
|
1055
|
+
const dWidth = w22;
|
|
1056
|
+
const dHeight = h22;
|
|
1057
|
+
if (imageW > elem.w || imageH > elem.h) {
|
|
1058
|
+
if (scaleMode === "fill") {
|
|
1059
|
+
const sourceScale = Math.max(elem.w / imageW, elem.h / imageH);
|
|
1060
|
+
const newImageWidth = imageW * sourceScale;
|
|
1061
|
+
const newImageHeight = imageH * sourceScale;
|
|
1062
|
+
sx = (newImageWidth - elem.w) / 2 / sourceScale;
|
|
1063
|
+
sy = (newImageHeight - elem.h) / 2 / sourceScale;
|
|
1064
|
+
sWidth = elem.w / sourceScale;
|
|
1065
|
+
sHeight = elem.h / sourceScale;
|
|
1066
|
+
} else if (scaleMode === "tile") {
|
|
1067
|
+
sx = 0;
|
|
1068
|
+
sy = 0;
|
|
1069
|
+
sWidth = elem.w;
|
|
1070
|
+
sHeight = elem.h;
|
|
1071
|
+
} else if (scaleMode === "fit") {
|
|
1072
|
+
const sourceScale = Math.min(elem.w / imageW, elem.h / imageH);
|
|
1073
|
+
sx = (imageW - elem.w / sourceScale) / 2;
|
|
1074
|
+
sy = (imageH - elem.h / sourceScale) / 2;
|
|
1075
|
+
sWidth = elem.w / sourceScale;
|
|
1076
|
+
sHeight = elem.h / sourceScale;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
ctx.drawImage(content, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
|
|
1080
|
+
} else {
|
|
1081
|
+
ctx.drawImage(content, x22, y22, w22, h22);
|
|
1082
|
+
}
|
|
990
1083
|
ctx.globalAlpha = parentOpacity;
|
|
991
1084
|
ctx.restore();
|
|
992
1085
|
}
|
|
@@ -1027,6 +1120,14 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1027
1120
|
});
|
|
1028
1121
|
}
|
|
1029
1122
|
const detailConfig = getDefaultElementDetailConfig();
|
|
1123
|
+
function isTextWidthWithinErrorRange(w0, w1, scale) {
|
|
1124
|
+
if (scale < 0.5) {
|
|
1125
|
+
if (w0 < w1 && (w0 - w1) / w0 > -0.15) {
|
|
1126
|
+
return true;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
return w0 >= w1;
|
|
1130
|
+
}
|
|
1030
1131
|
function drawText(ctx, elem, opts) {
|
|
1031
1132
|
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1032
1133
|
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
@@ -1045,6 +1146,9 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1045
1146
|
};
|
|
1046
1147
|
const originFontSize = detail.fontSize || detailConfig.fontSize;
|
|
1047
1148
|
const fontSize2 = originFontSize * viewScaleInfo.scale;
|
|
1149
|
+
if (fontSize2 < 2) {
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1048
1152
|
const originLineHeight = detail.lineHeight || originFontSize;
|
|
1049
1153
|
const lineHeight2 = originLineHeight * viewScaleInfo.scale;
|
|
1050
1154
|
ctx.fillStyle = elem.detail.color || detailConfig.color;
|
|
@@ -1052,7 +1156,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1052
1156
|
ctx.$setFont({
|
|
1053
1157
|
fontWeight: detail.fontWeight,
|
|
1054
1158
|
fontSize: fontSize2,
|
|
1055
|
-
fontFamily: detail.fontFamily
|
|
1159
|
+
fontFamily: enhanceFontFamliy(detail.fontFamily)
|
|
1056
1160
|
});
|
|
1057
1161
|
let detailText = detail.text.replace(/\r\n/gi, "\n");
|
|
1058
1162
|
if (detail.textTransform === "lowercase") {
|
|
@@ -1064,30 +1168,48 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1064
1168
|
const detailTextList = detailText.split("\n");
|
|
1065
1169
|
const lines = [];
|
|
1066
1170
|
let lineNum = 0;
|
|
1067
|
-
detailTextList.forEach((
|
|
1171
|
+
detailTextList.forEach((itemText, idx) => {
|
|
1068
1172
|
if (detail.minInlineSize === "maxContent") {
|
|
1069
1173
|
lines.push({
|
|
1070
|
-
text:
|
|
1071
|
-
width: ctx.$undoPixelRatio(ctx.measureText(
|
|
1174
|
+
text: itemText,
|
|
1175
|
+
width: ctx.$undoPixelRatio(ctx.measureText(itemText).width)
|
|
1072
1176
|
});
|
|
1073
1177
|
} else {
|
|
1074
1178
|
let lineText = "";
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1179
|
+
let splitStr = "";
|
|
1180
|
+
let tempStrList = itemText.split(splitStr);
|
|
1181
|
+
if (detail.wordBreak === "normal") {
|
|
1182
|
+
const splitStr2 = " ";
|
|
1183
|
+
const wordList = itemText.split(splitStr2);
|
|
1184
|
+
tempStrList = [];
|
|
1185
|
+
wordList.forEach((word, idx2) => {
|
|
1186
|
+
tempStrList.push(word);
|
|
1187
|
+
if (idx2 < wordList.length - 1) {
|
|
1188
|
+
tempStrList.push(splitStr2);
|
|
1189
|
+
}
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
if (tempStrList.length === 1 && detail.overflow === "visible") {
|
|
1193
|
+
lines.push({
|
|
1194
|
+
text: tempStrList[0],
|
|
1195
|
+
width: ctx.$undoPixelRatio(ctx.measureText(tempStrList[0]).width)
|
|
1196
|
+
});
|
|
1197
|
+
} else if (tempStrList.length > 0) {
|
|
1198
|
+
for (let i = 0; i < tempStrList.length; i++) {
|
|
1199
|
+
if (isTextWidthWithinErrorRange(ctx.$doPixelRatio(w2), ctx.measureText(lineText + tempStrList[i]).width, viewScaleInfo.scale)) {
|
|
1200
|
+
lineText += tempStrList[i] || "";
|
|
1079
1201
|
} else {
|
|
1080
1202
|
lines.push({
|
|
1081
1203
|
text: lineText,
|
|
1082
1204
|
width: ctx.$undoPixelRatio(ctx.measureText(lineText).width)
|
|
1083
1205
|
});
|
|
1084
|
-
lineText =
|
|
1206
|
+
lineText = tempStrList[i] || "";
|
|
1085
1207
|
lineNum++;
|
|
1086
1208
|
}
|
|
1087
|
-
if ((lineNum + 1) * fontHeight > h2) {
|
|
1209
|
+
if ((lineNum + 1) * fontHeight > h2 && detail.overflow === "hidden") {
|
|
1088
1210
|
break;
|
|
1089
1211
|
}
|
|
1090
|
-
if (
|
|
1212
|
+
if (tempStrList.length - 1 === i) {
|
|
1091
1213
|
if ((lineNum + 1) * fontHeight <= h2) {
|
|
1092
1214
|
lines.push({
|
|
1093
1215
|
text: lineText,
|
|
@@ -1109,6 +1231,10 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1109
1231
|
}
|
|
1110
1232
|
});
|
|
1111
1233
|
let startY = 0;
|
|
1234
|
+
let eachLineStartY = 0;
|
|
1235
|
+
if (fontHeight > fontSize2) {
|
|
1236
|
+
eachLineStartY = (fontHeight - fontSize2) / 2;
|
|
1237
|
+
}
|
|
1112
1238
|
if (lines.length * fontHeight < h2) {
|
|
1113
1239
|
if (elem.detail.verticalAlign === "top") {
|
|
1114
1240
|
startY = 0;
|
|
@@ -1139,7 +1265,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1139
1265
|
} else if (detail.textAlign === "right") {
|
|
1140
1266
|
_x = x2 + (w2 - line.width);
|
|
1141
1267
|
}
|
|
1142
|
-
ctx.fillText(line.text, _x, _y + fontHeight * i);
|
|
1268
|
+
ctx.fillText(line.text, _x, _y + fontHeight * i + eachLineStartY);
|
|
1143
1269
|
});
|
|
1144
1270
|
}
|
|
1145
1271
|
}
|
|
@@ -1148,7 +1274,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1148
1274
|
}
|
|
1149
1275
|
function drawPath(ctx, elem, opts) {
|
|
1150
1276
|
const { detail } = elem;
|
|
1151
|
-
const { originX, originY, originW, originH } = detail;
|
|
1277
|
+
const { originX, originY, originW, originH, fillRule } = detail;
|
|
1152
1278
|
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1153
1279
|
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
1154
1280
|
const scaleW = w2 / originW;
|
|
@@ -1178,7 +1304,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1178
1304
|
const path2d = new Path2D(pathStr);
|
|
1179
1305
|
if (detail.fill) {
|
|
1180
1306
|
ctx.fillStyle = detail.fill;
|
|
1181
|
-
ctx.fill(path2d);
|
|
1307
|
+
ctx.fill(path2d, fillRule);
|
|
1182
1308
|
}
|
|
1183
1309
|
if (detail.stroke && detail.strokeWidth !== 0) {
|
|
1184
1310
|
ctx.strokeStyle = detail.stroke;
|
|
@@ -1195,7 +1321,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1195
1321
|
});
|
|
1196
1322
|
}
|
|
1197
1323
|
function drawElement(ctx, elem, opts) {
|
|
1198
|
-
var _a;
|
|
1324
|
+
var _a, _b, _c;
|
|
1199
1325
|
if (((_a = elem == null ? void 0 : elem.operations) == null ? void 0 : _a.invisible) === true) {
|
|
1200
1326
|
return;
|
|
1201
1327
|
}
|
|
@@ -1204,6 +1330,10 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1204
1330
|
if (scale < 1 && (w2 * scale < 1 || h2 * scale < 1) || opts.parentOpacity === 0) {
|
|
1205
1331
|
return;
|
|
1206
1332
|
}
|
|
1333
|
+
const { overrideElementMap } = opts;
|
|
1334
|
+
if ((_c = (_b = overrideElementMap == null ? void 0 : overrideElementMap[elem.uuid]) == null ? void 0 : _b.operations) == null ? void 0 : _c.invisible) {
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1207
1337
|
try {
|
|
1208
1338
|
switch (elem.type) {
|
|
1209
1339
|
case "rect": {
|
|
@@ -1255,7 +1385,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1255
1385
|
}
|
|
1256
1386
|
function drawGroup(ctx, elem, opts) {
|
|
1257
1387
|
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1258
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h, angle: elem.angle }, { viewScaleInfo
|
|
1388
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h, angle: elem.angle }, { viewScaleInfo }) || elem;
|
|
1259
1389
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
1260
1390
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
1261
1391
|
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
@@ -1364,7 +1494,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1364
1494
|
function drawLayout(ctx, layout, opts, renderContent) {
|
|
1365
1495
|
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1366
1496
|
const elem = { uuid: "layout", type: "group", ...layout };
|
|
1367
|
-
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo
|
|
1497
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
1368
1498
|
const angle2 = 0;
|
|
1369
1499
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
1370
1500
|
ctx.globalAlpha = 1;
|
|
@@ -1378,7 +1508,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1378
1508
|
if (layout.detail.overflow === "hidden") {
|
|
1379
1509
|
const { viewScaleInfo: viewScaleInfo2, viewSizeInfo: viewSizeInfo2 } = opts;
|
|
1380
1510
|
const elem2 = { uuid: "layout", type: "group", ...layout };
|
|
1381
|
-
const viewElemSize = calcViewElementSize(elem2, { viewScaleInfo: viewScaleInfo2
|
|
1511
|
+
const viewElemSize = calcViewElementSize(elem2, { viewScaleInfo: viewScaleInfo2 }) || elem2;
|
|
1382
1512
|
const viewElem2 = { ...elem2, ...viewElemSize };
|
|
1383
1513
|
const { x: x22, y: y22, w: w22, h: h22, radiusList } = calcViewBoxSize(viewElem2, {
|
|
1384
1514
|
viewScaleInfo: viewScaleInfo2,
|
|
@@ -1403,6 +1533,15 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1403
1533
|
drawBoxBorder(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
|
|
1404
1534
|
ctx.globalAlpha = parentOpacity;
|
|
1405
1535
|
}
|
|
1536
|
+
function drawGlobalBackground(ctx, global, opts) {
|
|
1537
|
+
if (typeof (global == null ? void 0 : global.background) === "string") {
|
|
1538
|
+
const { viewSizeInfo } = opts;
|
|
1539
|
+
const { width, height } = viewSizeInfo;
|
|
1540
|
+
ctx.globalAlpha = 1;
|
|
1541
|
+
ctx.fillStyle = global.background;
|
|
1542
|
+
ctx.fillRect(0, 0, width, height);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1406
1545
|
const supportElementTypes = ["image", "svg", "html"];
|
|
1407
1546
|
const getAssetIdFromElement = (element) => {
|
|
1408
1547
|
var _a, _b, _c;
|
|
@@ -1631,7 +1770,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1631
1770
|
}
|
|
1632
1771
|
drawData(data, opts) {
|
|
1633
1772
|
const loader = __privateGet(this, _loader);
|
|
1634
|
-
const { calculator } = __privateGet(this, _opts);
|
|
1773
|
+
const { calculator, sharer } = __privateGet(this, _opts);
|
|
1635
1774
|
const viewContext = __privateGet(this, _opts).viewContext;
|
|
1636
1775
|
viewContext.clearRect(0, 0, viewContext.canvas.width, viewContext.canvas.height);
|
|
1637
1776
|
const parentElementSize = {
|
|
@@ -1646,8 +1785,10 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1646
1785
|
parentElementSize,
|
|
1647
1786
|
elementAssets: data.assets,
|
|
1648
1787
|
parentOpacity: 1,
|
|
1788
|
+
overrideElementMap: sharer == null ? void 0 : sharer.getActiveOverrideElemenentMap(),
|
|
1649
1789
|
...opts
|
|
1650
1790
|
};
|
|
1791
|
+
drawGlobalBackground(viewContext, data.global, drawOpts);
|
|
1651
1792
|
if (data.layout) {
|
|
1652
1793
|
drawLayout(viewContext, data.layout, drawOpts, () => {
|
|
1653
1794
|
drawElementList(viewContext, data, drawOpts);
|
package/dist/index.global.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var iDrawRenderer=function(e){"use strict";var t,n,i,o,a,r,l,s,c,d,h,f,u,w,g,v,y,p,m,S,x,b,I,z=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},T=(e,t,n)=>(z(e,t,"read from private field"),n?n.call(e):t.get(e)),A=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},C=(e,t,n,i)=>(z(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),E=(e,t,n)=>(z(e,t,"access private method"),n);function k(e){return"string"==typeof e&&(/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e)||/^[a-z]{1,}$/i.test(e))}function O(e,t){if(1===t)return e;let n=1;const i=/^\#[0-9a-f]{6,6}$/i;let o=e;if(i.test(e)?n=parseInt(e.substring(5,7).replace(/^\#/,"0x")):/^\#[0-9a-f]{8,8}$/i.test(e)&&(n=parseInt(e.substring(7,9).replace(/^\#/,"0x")),o=e.substring(0,7)),n*=t,i.test(o)&&n>0&&n<1){const e=Math.max(0,Math.min(255,Math.ceil(256*n)));o=`${o.toUpperCase()}${e.toString(16).toUpperCase()}`}return o}function W(){function e(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${e()}${e()}-${e()}-${e()}-${e()}-${e()}${e()}${e()}`}function P(e){let t=0;for(let n=0;n<e.length;n++)t+=e.charCodeAt(n)*e.charCodeAt(n)*n*n;return t.toString(16).substring(0,4)}function $(e){const t=e.length,n=Math.floor(t/2),i=e.substring(0,4).padEnd(4,"0"),o=e.substring(0,4).padEnd(4,"0");return`@assets/${P(t.toString(16).padEnd(4,i))}${P(e.substring(n-4,n).padEnd(4,i)).padEnd(4,"f")}-${P(e.substring(n-8,n-4).padEnd(4,i)).padEnd(4,"f")}-${P(e.substring(n-12,n-8).padEnd(4,i)).padEnd(4,"f")}-${P(e.substring(n-16,n-12).padEnd(4,o)).padEnd(4,"f")}-${P(e.substring(n,n+4).padEnd(4,o)).padEnd(4,"f")}${P(e.substring(n+4,n+8).padEnd(4,o)).padEnd(4,"f")}${P(o.padEnd(4,i).padEnd(4,o))}`}function M(e){return(Object.prototype.toString.call(e)||"").replace(/(\[object|\])/gi,"").trim()}const D={type(e,t){const n=M(e);return!0===t?n.toLocaleLowerCase():n},array:e=>"Array"===M(e),json:e=>"Object"===M(e),function:e=>"Function"===M(e),asyncFunction:e=>"AsyncFunction"===M(e),boolean:e=>"Boolean"===M(e),string:e=>"String"===M(e),number:e=>"Number"===M(e),undefined:e=>"Undefined"===M(e),null:e=>"Null"===M(e),promise:e=>"Promise"===M(e)};var R=function(e,t,n,i){return new(n||(n=Promise))((function(o,a){function r(e){try{s(i.next(e))}catch(e){a(e)}}function l(e){try{s(i.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,l)}s((i=i.apply(e,t||[])).next())}))};const{Image:L}=window;function B(e){return new Promise(((t,n)=>{const i=new L;i.crossOrigin="anonymous",i.onload=function(){t(i)},i.onabort=n,i.onerror=n,i.src=e}))}function F(e){return R(this,void 0,void 0,(function*(){const t=yield function(e){return new Promise(((t,n)=>{const i=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),o=new FileReader;o.readAsDataURL(i),o.onload=function(e){var n;const i=null===(n=null==e?void 0:e.target)||void 0===n?void 0:n.result;t(i)},o.onerror=function(e){n(e)}}))}(e);return yield B(t)}))}function X(e,t){return R(this,void 0,void 0,(function*(){e=e.replace(/\&/gi,"&");const n=yield function(e,t){const{width:n,height:i}=t;return new Promise(((t,o)=>{const a=new Blob([`\n <svg \n xmlns="http://www.w3.org/2000/svg" \n width="${n||""}" \n height = "${i||""}">\n <foreignObject width="100%" height="100%">\n <div xmlns = "http://www.w3.org/1999/xhtml">\n ${e}\n </div>\n </foreignObject>\n </svg>\n `],{type:"image/svg+xml;charset=utf-8"}),r=new FileReader;r.readAsDataURL(a),r.onload=function(e){var n;const i=null===(n=null==e?void 0:e.target)||void 0===n?void 0:n.result;t(i)},r.onerror=function(e){o(e)}}))}(e,t);return yield B(n)}))}function Y(e){return"number"==typeof e&&(e>0||e<=0)}function j(e){return"number"==typeof e&&e>=0}function H(e){return"string"==typeof e&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${e}`)}function U(e){return"string"==typeof e&&/^(data:image\/)/.test(`${e}`)}const q={x:function(e){return Y(e)},y:function(e){return Y(e)},w:j,h:function(e){return"number"==typeof e&&e>=0},angle:function(e){return"number"==typeof e&&e>=-360&&e<=360},number:Y,numberStr:function(e){return/^(-?\d+(?:\.\d+)?)$/.test(`${e}`)},borderWidth:function(e){return j(e)},borderRadius:function(e){return Y(e)&&e>=0},color:function(e){return k(e)},imageSrc:function(e){return U(e)||H(e)},imageURL:H,imageBase64:U,svg:function(e){return"string"==typeof e&&/^(<svg[\s]{1,}|<svg>)/i.test(`${e}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${e}`.trim())},html:function(e){let t=!1;if("string"==typeof e){let n=document.createElement("div");n.innerHTML=e,n.children.length>0&&(t=!0),n=null}return t},text:function(e){return"string"==typeof e},fontSize:function(e){return Y(e)&&e>0},lineHeight:function(e){return Y(e)&&e>0},textAlign:function(e){return["center","left","right"].includes(e)},fontFamily:function(e){return"string"==typeof e&&e.length>0},fontWeight:function(e){return["bold"].includes(e)},strokeWidth:function(e){return Y(e)&&e>0}};var G,N=function(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)};class J{constructor(){G.set(this,void 0),function(e,t,n,i,o){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===i?o.call(e,n):o?o.value=n:t.set(e,n)}(this,G,new Map,"f")}on(e,t){if(N(this,G,"f").has(e)){const n=N(this,G,"f").get(e)||[];null==n||n.push(t),N(this,G,"f").set(e,n)}else N(this,G,"f").set(e,[t])}off(e,t){if(N(this,G,"f").has(e)){const n=N(this,G,"f").get(e);if(Array.isArray(n))for(let e=0;e<(null==n?void 0:n.length);e++)if(n[e]===t){n.splice(e,1);break}N(this,G,"f").set(e,n||[])}}trigger(e,t){const n=N(this,G,"f").get(e);return!!Array.isArray(n)&&(n.forEach((e=>{e(t)})),!0)}has(e){if(N(this,G,"f").has(e)){const t=N(this,G,"f").get(e);if(Array.isArray(t)&&t.length>0)return!0}return!1}destroy(){this.clear()}clear(){N(this,G,"f").clear()}}function K(e,t,n,i){const o=function(e){return e/180*Math.PI}(t||0);n&&(o>0||o<0)&&(e.translate(n.x,n.y),e.rotate(o),e.translate(-n.x,-n.y)),i(e),n&&(o>0||o<0)&&(e.translate(n.x,n.y),e.rotate(-o),e.translate(-n.x,-n.y))}function Q(e,t,n){const i={x:(o=t).x+o.w/2,y:o.y+o.h/2};var o;K(e,t.angle||0,i,(()=>{n(e)}))}function V(e,t){const{viewScaleInfo:n}=t,{x:i,y:o,w:a,h:r,angle:l}=e,{scale:s,offsetTop:c,offsetLeft:d}=n;return{x:i*s+d,y:o*s+c,w:a*s,h:r*s,angle:l}}function Z(e){let t="";return e.forEach((e=>{t+=e.type+e.params.join(" ")})),t}G=new WeakMap;const _={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function ee(e,t){const{viewScaleInfo:n}=t,{scale:i}=n;let{borderRadius:o,borderDash:a}=e.detail;const r=Array.isArray(a)&&a.length>0,{boxSizing:l=_.boxSizing,borderWidth:s}=e.detail;Array.isArray(s)&&(o=0);let{x:c,y:d,w:h,h:f}=e,u=[0,0,0,0];if("number"==typeof o){const e=o*i;u=[e,e,e,e]}else Array.isArray(o)&&4===(null==o?void 0:o.length)&&(u=[o[0]*i,o[1]*i,o[2]*i,o[3]*i]);let w=0;return"number"==typeof s&&(w=(s||0)*i),"border-box"!==l||r?"content-box"===l?(c=e.x-w/2,d=e.y-w/2,h=e.w+w,f=e.h+w):(c=e.x,d=e.y,h=e.w,f=e.h):(c=e.x+w/2,d=e.y+w/2,h=e.w-w,f=e.h-w),h=Math.max(h,1),f=Math.max(f,1),u=u.map((e=>Math.min(e,h/2,f/2))),{x:c,y:d,w:h,h:f,radiusList:u}}function te(e,t,n){if("string"==typeof t)return t;const{viewElementSize:i,viewScaleInfo:o,opacity:a=1}=n,{x:r,y:l}=i,{scale:s}=o;if("linear-gradient"===(null==t?void 0:t.type)){const{start:n,end:i,stops:o}=t,c={x:r+n.x*s,y:l+n.y*s},d={x:r+i.x*s,y:l+i.y*s},h=e.createLinearGradient(c.x,c.y,d.x,d.y);return o.forEach((e=>{h.addColorStop(e.offset,O(e.color,a))})),h}if("radial-gradient"===(null==t?void 0:t.type)){const{inner:n,outer:i,stops:o}=t,c={x:r+n.x*s,y:l+n.y*s,radius:n.radius*s},d={x:r+i.x*s,y:l+i.y*s,radius:i.radius*s},h=e.createRadialGradient(c.x,c.y,c.radius,d.x,d.y,d.radius);return o.forEach((e=>{h.addColorStop(e.offset,O(e.color,a))})),h}return"#000000"}const ne={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function ie(e){var t,n,i,o;let a=1;return void 0!==(null==(t=null==e?void 0:e.detail)?void 0:t.opacity)&&(null==(n=null==e?void 0:e.detail)?void 0:n.opacity)>=0&&(null==(i=null==e?void 0:e.detail)?void 0:i.opacity)<=1&&(a=null==(o=null==e?void 0:e.detail)?void 0:o.opacity),a}function oe(e,t,n){const{pattern:i,renderContent:o,originElem:a,calcElemSize:r,viewScaleInfo:l,viewSizeInfo:s}=n||{},{parentOpacity:c}=n,d=ie(a)*c;!function(e,t,n){const{renderContent:i,originElem:o,calcElemSize:a,viewSizeInfo:r}=n,l=r.devicePixelRatio,{clipPath:s}=(null==o?void 0:o.detail)||{};if(s&&a&&s.commands){const{x:n,y:o,w:r,h:c}=a,{originW:d,originH:h,originX:f,originY:u}=s,w=r/d,g=c/h,v=n-f*w,y=o-u*g;e.save(),e.translate(v,y),e.scale(l*w,l*g);const p=Z(s.commands||[]),m=new Path2D(p);e.clip(m),e.translate(0-v,0-y),e.setTransform(1,0,0,1,0,0),Q(e,{...t},(()=>{null==i||i()})),e.restore()}else null==i||i()}(e,t,{originElem:a,calcElemSize:r,viewScaleInfo:l,viewSizeInfo:s,renderContent:()=>{e.globalAlpha=d,ae(e,t,{pattern:i,viewScaleInfo:l,viewSizeInfo:s}),null==o||o(),re(e,t,{viewScaleInfo:l,viewSizeInfo:s}),e.globalAlpha=c}})}function ae(e,t,n){var i,o;const{pattern:a,viewScaleInfo:r,viewSizeInfo:l}=n,s=[];if(t.detail.background||a){const{x:n,y:c,w:d,h:h,radiusList:f}=ee(t,{viewScaleInfo:r,viewSizeInfo:l});if(e.beginPath(),e.moveTo(n+f[0],c),e.arcTo(n+d,c,n+d,c+h,f[1]),e.arcTo(n+d,c+h,n,c+h,f[2]),e.arcTo(n,c+h,n,c,f[3]),e.arcTo(n,c,n+d,c,f[0]),e.closePath(),"string"==typeof a)e.fillStyle=a;else if(["CanvasPattern"].includes(D.type(a)))e.fillStyle=a;else if("string"==typeof t.detail.background)e.fillStyle=t.detail.background;else if("linear-gradient"===(null==(i=t.detail.background)?void 0:i.type)){const i=te(e,t.detail.background,{viewElementSize:{x:n,y:c,w:d,h:h},viewScaleInfo:r,opacity:e.globalAlpha});e.fillStyle=i}else if("radial-gradient"===(null==(o=t.detail.background)?void 0:o.type)){const i=te(e,t.detail.background,{viewElementSize:{x:n,y:c,w:d,h:h},viewScaleInfo:r,opacity:e.globalAlpha});if(e.fillStyle=i,s&&s.length>0)for(let t=0;t<(null==s?void 0:s.length);t++){const i=s[t];"translate"===i.method?e.translate(i.args[0]+n,i.args[1]+c):"rotate"===i.method?e.rotate(...i.args):"scale"===i.method&&e.scale(...i.args)}}e.fill(),s&&s.length>0&&e.setTransform(1,0,0,1,0,0)}}function re(e,t,n){if(0===t.detail.borderWidth)return;if(!k(t.detail.borderColor))return;const{viewScaleInfo:i}=n,{scale:o}=i;let a=ne.borderColor;!0===k(t.detail.borderColor)&&(a=t.detail.borderColor);const{borderWidth:r,borderRadius:l,borderDash:s,boxSizing:c=ne.boxSizing}=t.detail;let d=0;"number"==typeof r&&(d=r||1),d*=o;let h=[0,0,0,0];if("number"==typeof l){const e=l*o;h=[e,e,e,e]}else Array.isArray(l)&&4===(null==l?void 0:l.length)&&(h=[l[0]*o,l[1]*o,l[2]*o,l[3]*o]);e.strokeStyle=a;let f=[];Array.isArray(s)&&s.length>0&&(f=s.map((e=>Math.ceil(e*o))));let u=0,w=0,g=0,v=0;if(Array.isArray(r)&&(u=(r[0]||0)*o,w=(r[1]||0)*o,g=(r[2]||0)*o,v=(r[3]||0)*o),v||w||u||g){e.lineCap="butt";let{x:n,y:i,w:o,h:a}=t;"border-box"===c?(n+=v/2,i+=u/2,o=o-v/2-w/2,a=a-u/2-g/2):"content-box"===c?(n-=v/2,i-=u/2,o=o+v/2+w/2,a=a+u/2+g/2):(n=t.x,i=t.y,o=t.w,a=t.h),u&&(e.beginPath(),e.lineWidth=u,e.moveTo(n-v/2,i),e.lineTo(n+o+w/2,i),e.closePath(),e.stroke()),w&&(e.beginPath(),e.lineWidth=w,e.moveTo(n+o,i-u/2),e.lineTo(n+o,i+a+g/2),e.closePath(),e.stroke()),g&&(e.beginPath(),e.lineWidth=g,e.moveTo(n-v/2,i+a),e.lineTo(n+o+w/2,i+a),e.closePath(),e.stroke()),v&&(e.beginPath(),e.lineWidth=v,e.moveTo(n,i-u/2),e.lineTo(n,i+a+g/2),e.closePath(),e.stroke())}else{let{x:n,y:i,w:o,h:a}=t;"border-box"===c?(n=t.x+d/2,i=t.y+d/2,o=t.w-d,a=t.h-d):"content-box"===c?(n=t.x-d/2,i=t.y-d/2,o=t.w+d,a=t.h+d):(n=t.x,i=t.y,o=t.w,a=t.h),f.length>0?e.lineCap="butt":e.lineCap="square",o=Math.max(o,1),a=Math.max(a,1),h=h.map((e=>Math.min(e,o/2,a/2))),e.setLineDash(f),e.lineWidth=d,e.beginPath(),e.moveTo(n+h[0],i),e.arcTo(n+o,i,n+o,i+a,h[1]),e.arcTo(n+o,i+a,n,i+a,h[2]),e.arcTo(n,i+a,n,i,h[3]),e.arcTo(n,i,n+o,i,h[0]),e.closePath(),e.stroke()}e.setLineDash([])}function le(e,t,n){const{detail:i}=t,{viewScaleInfo:o,renderContent:a}=n,{shadowColor:r,shadowOffsetX:l,shadowOffsetY:s,shadowBlur:c}=i;q.number(c)?(e.save(),e.shadowColor=r||ne.shadowColor,e.shadowOffsetX=(l||0)*o.scale,e.shadowOffsetY=(s||0)*o.scale,e.shadowBlur=(c||0)*o.scale,a(),e.restore()):(e.save(),e.shadowColor="transparent",e.shadowOffsetX=0,e.shadowOffsetY=0,e.shadowBlur=0,a(),e.restore())}function se(e,t,n){const{viewScaleInfo:i,viewSizeInfo:o,parentOpacity:a}=n,{x:r,y:l,w:s,h:c,angle:d}=V(t,{viewScaleInfo:i,viewSizeInfo:o})||t,h={...t,x:r,y:l,w:s,h:c,angle:d};Q(e,{x:r,y:l,w:s,h:c,angle:d},(()=>{le(e,h,{viewScaleInfo:i,viewSizeInfo:o,renderContent:()=>{oe(e,h,{originElem:t,calcElemSize:{x:r,y:l,w:s,h:c,angle:d},viewScaleInfo:i,viewSizeInfo:o,parentOpacity:a,renderContent:()=>{}})}})}))}const ce={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function de(e,t,n){var i;if(!0===(null==(i=null==t?void 0:t.operations)?void 0:i.invisible))return;const{w:o,h:a}=t,{scale:r}=n.viewScaleInfo;if(!(r<1&&(o*r<1||a*r<1)||0===n.parentOpacity))try{switch(t.type){case"rect":se(e,t,n);break;case"circle":!function(e,t,n){const{detail:i,angle:o}=t,{viewScaleInfo:a,viewSizeInfo:r,parentOpacity:l}=n,{background:s="#000000",borderColor:c="#000000",boxSizing:d,borderWidth:h=0,borderDash:f}=i;let u=0;"number"==typeof h&&h>0?u=h:Array.isArray(h)&&"number"==typeof h[0]&&h[0]>0&&(u=h[0]),u*=a.scale;const{x:w,y:g,w:v,h:y}=V({x:t.x,y:t.y,w:t.w,h:t.h},{viewScaleInfo:a})||t,p={...t,x:w,y:g,w:v,h:y,angle:o};Q(e,{x:w,y:g,w:v,h:y,angle:o},(()=>{le(e,p,{viewScaleInfo:a,viewSizeInfo:r,renderContent:()=>{let t=v/2,n=y/2;const i=w+t,o=g+n,r=t,h=n;if(u>0&&("content-box"===d||("center-line"===d?(t-=u/2,n-=u/2):(t-=u,n-=u))),t>=0&&n>=0){const d=ie(p)*l;e.globalAlpha=d,e.beginPath();const m=te(e,s,{viewElementSize:{x:w,y:g,w:v,h:y},viewScaleInfo:a,opacity:e.globalAlpha});if(e.fillStyle=m,e.circle(i,o,r,h,0,0,2*Math.PI),e.closePath(),e.fill(),e.globalAlpha=l,"number"==typeof u&&u>0){const r=u/2+t,l=u/2+n;if(e.beginPath(),f){const t=f.map((e=>e*a.scale));e.setLineDash(t)}e.strokeStyle=c,e.lineWidth=u,e.circle(i,o,r,l,0,0,2*Math.PI),e.closePath(),e.stroke(),e.setLineDash([])}}}})}))}(e,t,n);break;case"text":!function(e,t,n){const{viewScaleInfo:i,viewSizeInfo:o,parentOpacity:a}=n,{x:r,y:l,w:s,h:c,angle:d}=V(t,{viewScaleInfo:i})||t,h={...t,x:r,y:l,w:s,h:c,angle:d};Q(e,{x:r,y:l,w:s,h:c,angle:d},(()=>{oe(e,h,{originElem:t,calcElemSize:{x:r,y:l,w:s,h:c,angle:d},viewScaleInfo:i,viewSizeInfo:o,parentOpacity:a,renderContent:()=>{const n={...ce,...t.detail},o=n.fontSize||ce.fontSize,a=o*i.scale,d=(n.lineHeight||o)*i.scale;e.fillStyle=t.detail.color||ce.color,e.textBaseline="top",e.$setFont({fontWeight:n.fontWeight,fontSize:a,fontFamily:n.fontFamily});let h=n.text.replace(/\r\n/gi,"\n");"lowercase"===n.textTransform?h=h.toLowerCase():"uppercase"===n.textTransform&&(h=h.toUpperCase());const f=d,u=h.split("\n"),w=[];let g=0;u.forEach(((t,i)=>{if("maxContent"===n.minInlineSize)w.push({text:t,width:e.$undoPixelRatio(e.measureText(t).width)});else{let n="";if(t.length>0){for(let o=0;o<t.length&&(e.measureText(n+(t[o]||"")).width<=e.$doPixelRatio(s)?n+=t[o]||"":(w.push({text:n,width:e.$undoPixelRatio(e.measureText(n).width)}),n=t[o]||"",g++),!((g+1)*f>c));o++)if(t.length-1===o&&(g+1)*f<=c){w.push({text:n,width:e.$undoPixelRatio(e.measureText(n).width)}),i<u.length-1&&g++;break}}else w.push({text:"",width:0})}}));let v=0;w.length*f<c&&("top"===t.detail.verticalAlign?v=0:"bottom"===t.detail.verticalAlign?v+=c-w.length*f:v+=(c-w.length*f)/2);{const t=l+v;void 0!==n.textShadowColor&&k(n.textShadowColor)&&(e.shadowColor=n.textShadowColor),void 0!==n.textShadowOffsetX&&q.number(n.textShadowOffsetX)&&(e.shadowOffsetX=n.textShadowOffsetX),void 0!==n.textShadowOffsetY&&q.number(n.textShadowOffsetY)&&(e.shadowOffsetY=n.textShadowOffsetY),void 0!==n.textShadowBlur&&q.number(n.textShadowBlur)&&(e.shadowBlur=n.textShadowBlur),w.forEach(((i,o)=>{let a=r;"center"===n.textAlign?a=r+(s-i.width)/2:"right"===n.textAlign&&(a=r+(s-i.width)),e.fillText(i.text,a,t+f*o)}))}}})}))}(e,t,n);break;case"image":!function(e,t,n){const i=n.loader.getContent(t),{viewScaleInfo:o,viewSizeInfo:a,parentOpacity:r}=n,{x:l,y:s,w:c,h:d,angle:h}=V(t,{viewScaleInfo:o,viewSizeInfo:a})||t,f={...t,x:l,y:s,w:c,h:d,angle:h};Q(e,{x:l,y:s,w:c,h:d,angle:h},(()=>{le(e,f,{viewScaleInfo:o,viewSizeInfo:a,renderContent:()=>{oe(e,f,{originElem:t,calcElemSize:{x:l,y:s,w:c,h:d,angle:h},viewScaleInfo:o,viewSizeInfo:a,parentOpacity:r,renderContent:()=>{if(i||n.loader.isDestroyed()||n.loader.load(t,n.elementAssets||{}),"image"===t.type&&i){e.globalAlpha=ie(t)*r;const{x:n,y:l,w:s,h:c,radiusList:d}=ee(f,{viewScaleInfo:o,viewSizeInfo:a});e.save(),e.fillStyle="transparent",e.beginPath(),e.moveTo(n+d[0],l),e.arcTo(n+s,l,n+s,l+c,d[1]),e.arcTo(n+s,l+c,n,l+c,d[2]),e.arcTo(n,l+c,n,l,d[3]),e.arcTo(n,l,n+s,l,d[0]),e.closePath(),e.fill(),e.clip(),e.drawImage(i,n,l,s,c),e.globalAlpha=r,e.restore()}}})}})}))}(e,t,n);break;case"svg":!function(e,t,n){const i=n.loader.getContent(t),{viewScaleInfo:o,viewSizeInfo:a,parentOpacity:r}=n,{x:l,y:s,w:c,h:d,angle:h}=V(t,{viewScaleInfo:o,viewSizeInfo:a})||t;Q(e,{x:l,y:s,w:c,h:d,angle:h},(()=>{i||n.loader.isDestroyed()||n.loader.load(t,n.elementAssets||{}),"svg"===t.type&&i&&(e.globalAlpha=ie(t)*r,e.drawImage(i,l,s,c,d),e.globalAlpha=r)}))}(e,t,n);break;case"html":!function(e,t,n){const i=n.loader.getContent(t),{viewScaleInfo:o,viewSizeInfo:a,parentOpacity:r}=n,{x:l,y:s,w:c,h:d,angle:h}=V(t,{viewScaleInfo:o,viewSizeInfo:a})||t;Q(e,{x:l,y:s,w:c,h:d,angle:h},(()=>{i||n.loader.isDestroyed()||n.loader.load(t,n.elementAssets||{}),"html"===t.type&&i&&(e.globalAlpha=ie(t)*r,e.drawImage(i,l,s,c,d),e.globalAlpha=r)}))}(e,t,n);break;case"path":!function(e,t,n){const{detail:i}=t,{originX:o,originY:a,originW:r,originH:l}=i,{viewScaleInfo:s,viewSizeInfo:c,parentOpacity:d}=n,{x:h,y:f,w:u,h:w,angle:g}=V(t,{viewScaleInfo:s})||t,v=u/r,y=w/l,p=h-o*v,m=f-a*y,S=s.scale*c.devicePixelRatio,x={...t,x:h,y:f,w:u,h:w,angle:g};Q(e,{x:h,y:f,w:u,h:w,angle:g},(()=>{oe(e,x,{originElem:t,calcElemSize:{x:h,y:f,w:u,h:w,angle:g},viewScaleInfo:s,viewSizeInfo:c,parentOpacity:d,renderContent:()=>{le(e,x,{viewScaleInfo:s,viewSizeInfo:c,renderContent:()=>{e.save(),e.translate(p,m),e.scale(S*v/s.scale,S*y/s.scale);const t=Z(i.commands||[]),n=new Path2D(t);i.fill&&(e.fillStyle=i.fill,e.fill(n)),i.stroke&&0!==i.strokeWidth&&(e.strokeStyle=i.stroke,e.lineWidth=(i.strokeWidth||1)/c.devicePixelRatio,e.lineCap=i.strokeLineCap||"square",e.stroke(n)),e.translate(-p,-m),e.restore()}})}})}))}(e,t,n);break;case"group":{const i={...n.elementAssets||{},...t.detail.assets||{}};!function(e,t,n){const{viewScaleInfo:i,viewSizeInfo:o,parentOpacity:a}=n,{x:r,y:l,w:s,h:c,angle:d}=V({x:t.x,y:t.y,w:t.w,h:t.h,angle:t.angle},{viewScaleInfo:i,viewSizeInfo:o})||t,h={...t,x:r,y:l,w:s,h:c,angle:d};Q(e,{x:r,y:l,w:s,h:c,angle:d},(()=>{e.globalAlpha=ie(t)*a,le(e,h,{viewScaleInfo:i,viewSizeInfo:o,renderContent:()=>{oe(e,h,{originElem:t,calcElemSize:{x:r,y:l,w:s,h:c,angle:d},viewScaleInfo:i,viewSizeInfo:o,parentOpacity:a,renderContent:()=>{const{x:r,y:l,w:s,h:c,radiusList:d}=ee(h,{viewScaleInfo:i,viewSizeInfo:o});if("hidden"===t.detail.overflow&&(e.save(),e.fillStyle="transparent",e.beginPath(),e.moveTo(r+d[0],l),e.arcTo(r+s,l,r+s,l+c,d[1]),e.arcTo(r+s,l+c,r,l+c,d[2]),e.arcTo(r,l+c,r,l,d[3]),e.arcTo(r,l,r+s,l,d[0]),e.closePath(),e.fill(),e.clip()),Array.isArray(t.detail.children)){const{parentElementSize:i}=n,o={x:i.x+t.x,y:i.y+t.y,w:t.w||i.w,h:t.h||i.h,angle:t.angle},{calculator:r}=n;for(let i=0;i<t.detail.children.length;i++){let l=t.detail.children[i];if(l={...l,x:o.x+l.x,y:o.y+l.y},!0===n.forceDrawAll||(null==r?void 0:r.needRender(l)))try{de(e,l,{...n,parentOpacity:a*ie(t)})}catch(e){console.error(e)}}}"hidden"===t.detail.overflow&&e.restore()}})}}),e.globalAlpha=a}))}(e,t,{...n,elementAssets:i});break}}}catch(e){console.error(e)}}const he={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function fe(e,t,n){var i;const{elements:o=[]}=t,{parentOpacity:a}=n;for(let t=0;t<o.length;t++){const r=o[t],l={...r,detail:{...he,...null==r?void 0:r.detail}};if(!0===n.forceDrawAll||(null==(i=n.calculator)?void 0:i.needRender(l)))try{de(e,l,{...n,parentOpacity:a})}catch(e){console.error(e)}}}const ue=["image","svg","html"],we=e=>{var t,n,i;let o=null;return"image"===e.type?o=(null==(t=null==e?void 0:e.detail)?void 0:t.src)||null:"svg"===e.type?o=(null==(n=null==e?void 0:e.detail)?void 0:n.svg)||null:"html"===e.type&&(o=(null==(i=null==e?void 0:e.detail)?void 0:i.html)||null),"string"==typeof o&&o?/^@assets\/[0-9a-z]{8,8}\-[0-9a-z]{4,4}\-[0-9a-z]{4,4}\-[0-9a-z]{4,4}\-[0-9a-z]{12,12}$/.test(`${o}`)?o:$(o):$(`${W()}-${e.uuid}-${W()}-${W()}`)};class ge extends J{constructor(){super(),A(this,a),A(this,l),A(this,c),A(this,h),A(this,u),A(this,g),A(this,y),A(this,t,{}),A(this,n,{}),A(this,i,{}),A(this,o,!1),E(this,a,r).call(this,"image",(async(e,t)=>{var n;const i=(null==(n=t[e.detail.src])?void 0:n.value)||e.detail.src,o=await B(i);return{uuid:e.uuid,lastModified:Date.now(),content:o}})),E(this,a,r).call(this,"html",(async(e,t)=>{var n;const i=(null==(n=t[e.detail.html])?void 0:n.value)||e.detail.html,o=await X(i,{width:e.detail.originW||e.w,height:e.detail.originH||e.h});return{uuid:e.uuid,lastModified:Date.now(),content:o}})),E(this,a,r).call(this,"svg",(async(e,t)=>{var n;const i=(null==(n=t[e.detail.svg])?void 0:n.value)||e.detail.svg,o=await F(i);return{uuid:e.uuid,lastModified:Date.now(),content:o}}))}isDestroyed(){return T(this,o)}destroy(){C(this,o,!0),this.clear(),C(this,t,null),C(this,n,null),C(this,i,null)}load(e,t){!0!==T(this,o)&&(E(this,y,p).call(this,e)||ue.includes(e.type)&&E(this,g,v).call(this,e,t))}getContent(e){var t,n;const o=we(e);return(null==(n=null==(t=T(this,i))?void 0:t[o])?void 0:n.content)||null}getLoadItemMap(){return T(this,i)}setLoadItemMap(e){C(this,i,e)}}t=new WeakMap,n=new WeakMap,i=new WeakMap,o=new WeakMap,a=new WeakSet,r=function(e,n){T(this,t)[e]=n},l=new WeakSet,s=function(e){var t,n,i;let o=null;return"image"===e.type?o=(null==(t=null==e?void 0:e.detail)?void 0:t.src)||null:"svg"===e.type?o=(null==(n=null==e?void 0:e.detail)?void 0:n.svg)||null:"html"===e.type&&(o=(null==(i=null==e?void 0:e.detail)?void 0:i.html)||null),o},c=new WeakSet,d=function(e){return{element:e,status:"null",content:null,error:null,startTime:-1,endTime:-1,source:E(this,l,s).call(this,e)}},h=new WeakSet,f=function(e){const t=we(e.element),n=T(this,i)[t];T(this,o)||(n?n.startTime<e.startTime&&(T(this,i)[t]=e,this.trigger("load",{...e,countTime:e.endTime-e.startTime})):(T(this,i)[t]=e,this.trigger("load",{...e,countTime:e.endTime-e.startTime})))},u=new WeakSet,w=function(e){var t;const n=we(e.element),a=null==(t=T(this,i))?void 0:t[n];T(this,o)||(a?a.startTime<e.startTime&&(T(this,i)[n]=e,this.trigger("error",{...e,countTime:e.endTime-e.startTime})):(T(this,i)[n]=e,this.trigger("error",{...e,countTime:e.endTime-e.startTime})))},g=new WeakSet,v=function(e,i){const a=E(this,c,d).call(this,e),r=we(e);if(T(this,n)[r])return;T(this,n)[r]=a;const l=T(this,t)[e.type];"function"!=typeof l||T(this,o)||(a.startTime=Date.now(),l(e,i).then((e=>{T(this,o)||(a.content=e.content,a.endTime=Date.now(),a.status="load",E(this,h,f).call(this,a))})).catch((t=>{console.warn(`Load element source "${a.source}" fail`,t,e),a.endTime=Date.now(),a.status="error",a.error=t,E(this,u,w).call(this,a)})))},y=new WeakSet,p=function(e){var t;const i=we(e),o=null==(t=T(this,n))?void 0:t[i];return!(!o||"error"!==o.status||!o.source||o.source!==E(this,l,s).call(this,e))};return m=new WeakMap,S=new WeakMap,x=new WeakMap,b=new WeakSet,I=function(){const e=T(this,S);e.on("load",(e=>{this.trigger("load",e)})),e.on("error",(e=>{console.error(e)}))},e.Renderer=class extends J{constructor(e){super(),A(this,b),A(this,m,void 0),A(this,S,new ge),A(this,x,!1),C(this,m,e),E(this,b,I).call(this)}isDestroyed(){return T(this,x)}destroy(){this.clear(),C(this,m,null),T(this,S).destroy(),C(this,S,null),C(this,x,!0)}updateOptions(e){C(this,m,e)}drawData(e,t){const n=T(this,S),{calculator:i}=T(this,m),o=T(this,m).viewContext;o.clearRect(0,0,o.canvas.width,o.canvas.height);const a={loader:n,calculator:i,parentElementSize:{x:0,y:0,w:t.viewSizeInfo.width,h:t.viewSizeInfo.height},elementAssets:e.assets,parentOpacity:1,...t};e.layout?function(e,t,n,i){const{viewScaleInfo:o,viewSizeInfo:a,parentOpacity:r}=n,l={uuid:"layout",type:"group",...t},{x:s,y:c,w:d,h:h}=V(l,{viewScaleInfo:o,viewSizeInfo:a})||l,f={...l,x:s,y:c,w:d,h:h,angle:0};if(e.globalAlpha=1,le(e,f,{viewScaleInfo:o,viewSizeInfo:a,renderContent:()=>{ae(e,f,{viewScaleInfo:o,viewSizeInfo:a})}}),"hidden"===t.detail.overflow){const{viewScaleInfo:i,viewSizeInfo:o}=n,a={uuid:"layout",type:"group",...t},r=V(a,{viewScaleInfo:i,viewSizeInfo:o})||a,l={...a,...r},{x:s,y:c,w:d,h:h,radiusList:f}=ee(l,{viewScaleInfo:i,viewSizeInfo:o});e.save(),e.fillStyle="transparent",e.beginPath(),e.moveTo(s+f[0],c),e.arcTo(s+d,c,s+d,c+h,f[1]),e.arcTo(s+d,c+h,s,c+h,f[2]),e.arcTo(s,c+h,s,c,f[3]),e.arcTo(s,c,s+d,c,f[0]),e.closePath(),e.fill(),e.clip()}i(e),"hidden"===t.detail.overflow&&e.restore(),re(e,f,{viewScaleInfo:o,viewSizeInfo:a}),e.globalAlpha=r}(o,e.layout,a,(()=>{fe(o,e,a)})):fe(o,e,a)}scale(e){const{sharer:t}=T(this,m);if(!t)return;const{data:n,offsetTop:i,offsetBottom:o,offsetLeft:a,offsetRight:r,width:l,height:s,contextHeight:c,contextWidth:d,devicePixelRatio:h}=t.getActiveStoreSnapshot();n&&this.drawData(n,{viewScaleInfo:{scale:e,offsetTop:i,offsetBottom:o,offsetLeft:a,offsetRight:r},viewSizeInfo:{width:l,height:s,contextHeight:c,contextWidth:d,devicePixelRatio:h}})}setLoadItemMap(e){T(this,S).setLoadItemMap(e)}getLoadItemMap(){return T(this,S).getLoadItemMap()}getLoader(){return T(this,S)}},e.drawRect=se,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});
|
|
1
|
+
var iDrawRenderer=function(e){"use strict";var t,n,i,o,a,r,l,s,c,d,h,f,u,w,g,v,p,y,m,S,x,b,I,z=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},T=(e,t,n)=>(z(e,t,"read from private field"),n?n.call(e):t.get(e)),A=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},k=(e,t,n,i)=>(z(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),C=(e,t,n)=>(z(e,t,"access private method"),n);function E(e){return"string"==typeof e&&(/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e)||/^[a-z]{1,}$/i.test(e))}function P(e,t){if(1===t)return e;let n=1;const i=/^\#[0-9a-f]{6,6}$/i;let o=e;if(i.test(e)?n=parseInt(e.substring(5,7).replace(/^\#/,"0x")):/^\#[0-9a-f]{8,8}$/i.test(e)&&(n=parseInt(e.substring(7,9).replace(/^\#/,"0x")),o=e.substring(0,7)),n*=t,i.test(o)&&n>0&&n<1){const e=Math.max(0,Math.min(255,Math.ceil(256*n)));o=`${o.toUpperCase()}${e.toString(16).toUpperCase()}`}return o}function W(){function e(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${e()}${e()}-${e()}-${e()}-${e()}-${e()}${e()}${e()}`}function O(e){let t=0;for(let n=0;n<e.length;n++)t+=e.charCodeAt(n)*e.charCodeAt(n)*n*n;return t.toString(16).substring(0,4)}function $(e){const t=e.length,n=Math.floor(t/2),i=e.substring(0,4).padEnd(4,"0"),o=e.substring(0,4).padEnd(4,"0");return`@assets/${O(t.toString(16).padEnd(4,i))}${O(e.substring(n-4,n).padEnd(4,i)).padEnd(4,"f")}-${O(e.substring(n-8,n-4).padEnd(4,i)).padEnd(4,"f")}-${O(e.substring(n-12,n-8).padEnd(4,i)).padEnd(4,"f")}-${O(e.substring(n-16,n-12).padEnd(4,o)).padEnd(4,"f")}-${O(e.substring(n,n+4).padEnd(4,o)).padEnd(4,"f")}${O(e.substring(n+4,n+8).padEnd(4,o)).padEnd(4,"f")}${O(o.padEnd(4,i).padEnd(4,o))}`}function M(e){return(Object.prototype.toString.call(e)||"").replace(/(\[object|\])/gi,"").trim()}const R={type(e,t){const n=M(e);return!0===t?n.toLocaleLowerCase():n},array:e=>"Array"===M(e),json:e=>"Object"===M(e),function:e=>"Function"===M(e),asyncFunction:e=>"AsyncFunction"===M(e),boolean:e=>"Boolean"===M(e),string:e=>"String"===M(e),number:e=>"Number"===M(e),undefined:e=>"Undefined"===M(e),null:e=>"Null"===M(e),promise:e=>"Promise"===M(e)};var D=function(e,t,n,i){return new(n||(n=Promise))((function(o,a){function r(e){try{s(i.next(e))}catch(e){a(e)}}function l(e){try{s(i.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,l)}s((i=i.apply(e,t||[])).next())}))};const{Image:L}=window;function B(e){return new Promise(((t,n)=>{const i=new L;i.crossOrigin="anonymous",i.onload=function(){t(i)},i.onabort=n,i.onerror=n,i.src=e}))}function X(e){return D(this,void 0,void 0,(function*(){const t=yield function(e){return new Promise(((t,n)=>{const i=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),o=new FileReader;o.readAsDataURL(i),o.onload=function(e){var n;const i=null===(n=null==e?void 0:e.target)||void 0===n?void 0:n.result;t(i)},o.onerror=function(e){n(e)}}))}(e);return yield B(t)}))}function Y(e,t){return D(this,void 0,void 0,(function*(){e=e.replace(/\&/gi,"&");const n=yield function(e,t){const{width:n,height:i}=t;return new Promise(((t,o)=>{const a=new Blob([`\n <svg \n xmlns="http://www.w3.org/2000/svg" \n width="${n||""}" \n height = "${i||""}">\n <foreignObject width="100%" height="100%">\n <div xmlns = "http://www.w3.org/1999/xhtml">\n ${e}\n </div>\n </foreignObject>\n </svg>\n `],{type:"image/svg+xml;charset=utf-8"}),r=new FileReader;r.readAsDataURL(a),r.onload=function(e){var n;const i=null===(n=null==e?void 0:e.target)||void 0===n?void 0:n.result;t(i)},r.onerror=function(e){o(e)}}))}(e,t);return yield B(n)}))}function F(e){return"number"==typeof e&&(e>0||e<=0)}function j(e){return"number"==typeof e&&e>=0}function H(e){return"string"==typeof e&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${e}`)}function U(e){return"string"==typeof e&&/^(data:image\/)/.test(`${e}`)}const N={x:function(e){return F(e)},y:function(e){return F(e)},w:j,h:function(e){return"number"==typeof e&&e>=0},angle:function(e){return"number"==typeof e&&e>=-360&&e<=360},number:F,numberStr:function(e){return/^(-?\d+(?:\.\d+)?)$/.test(`${e}`)},borderWidth:function(e){return j(e)},borderRadius:function(e){return F(e)&&e>=0},color:function(e){return E(e)},imageSrc:function(e){return U(e)||H(e)},imageURL:H,imageBase64:U,svg:function(e){return"string"==typeof e&&/^(<svg[\s]{1,}|<svg>)/i.test(`${e}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${e}`.trim())},html:function(e){let t=!1;if("string"==typeof e){let n=document.createElement("div");n.innerHTML=e,n.children.length>0&&(t=!0),n=null}return t},text:function(e){return"string"==typeof e},fontSize:function(e){return F(e)&&e>0},lineHeight:function(e){return F(e)&&e>0},textAlign:function(e){return["center","left","right"].includes(e)},fontFamily:function(e){return"string"==typeof e&&e.length>0},fontWeight:function(e){return["bold"].includes(e)},strokeWidth:function(e){return F(e)&&e>0}};var q,G=function(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)};class J{constructor(){q.set(this,void 0),function(e,t,n,i,o){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===i?o.call(e,n):o?o.value=n:t.set(e,n)}(this,q,new Map,"f")}on(e,t){if(G(this,q,"f").has(e)){const n=G(this,q,"f").get(e)||[];null==n||n.push(t),G(this,q,"f").set(e,n)}else G(this,q,"f").set(e,[t])}off(e,t){if(G(this,q,"f").has(e)){const n=G(this,q,"f").get(e);if(Array.isArray(n))for(let e=0;e<(null==n?void 0:n.length);e++)if(n[e]===t){n.splice(e,1);break}G(this,q,"f").set(e,n||[])}}trigger(e,t){const n=G(this,q,"f").get(e);return!!Array.isArray(n)&&(n.forEach((e=>{e(t)})),!0)}has(e){if(G(this,q,"f").has(e)){const t=G(this,q,"f").get(e);if(Array.isArray(t)&&t.length>0)return!0}return!1}destroy(){this.clear()}clear(){G(this,q,"f").clear()}}function K(e,t,n,i){const o=function(e){return e/180*Math.PI}(t||0);n&&(o>0||o<0)&&(e.translate(n.x,n.y),e.rotate(o),e.translate(-n.x,-n.y)),i(e),n&&(o>0||o<0)&&(e.translate(n.x,n.y),e.rotate(-o),e.translate(-n.x,-n.y))}function Q(e,t,n){const i={x:(o=t).x+o.w/2,y:o.y+o.h/2};var o;K(e,t.angle||0,i,(()=>{n(e)}))}function V(e,t){const{viewScaleInfo:n}=t,{x:i,y:o,w:a,h:r,angle:l}=e,{scale:s,offsetTop:c,offsetLeft:d}=n;return{x:i*s+d,y:o*s+c,w:a*s,h:r*s,angle:l}}function Z(e){let t="";return e.forEach((e=>{t+=e.type+e.params.join(" ")})),t}q=new WeakMap;const _={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,fontFamily:"sans-serif",fontWeight:400,minInlineSize:"auto",wordBreak:"break-all",overflow:"hidden"};function ee(e,t){const{viewScaleInfo:n}=t,{scale:i}=n;let{borderRadius:o,borderDash:a}=e.detail;const r=Array.isArray(a)&&a.length>0,{boxSizing:l=_.boxSizing,borderWidth:s}=e.detail;Array.isArray(s)&&(o=0);let{x:c,y:d,w:h,h:f}=e,u=[0,0,0,0];if("number"==typeof o){const e=o*i;u=[e,e,e,e]}else Array.isArray(o)&&4===(null==o?void 0:o.length)&&(u=[o[0]*i,o[1]*i,o[2]*i,o[3]*i]);let w=0;return"number"==typeof s&&(w=(s||0)*i),"border-box"!==l||r?"content-box"===l?(c=e.x-w/2,d=e.y-w/2,h=e.w+w,f=e.h+w):(c=e.x,d=e.y,h=e.w,f=e.h):(c=e.x+w/2,d=e.y+w/2,h=e.w-w,f=e.h-w),h=Math.max(h,1),f=Math.max(f,1),u=u.map((e=>Math.min(e,h/2,f/2))),{x:c,y:d,w:h,h:f,radiusList:u}}const te=["-apple-system",'"system-ui"',' "Segoe UI"'," Roboto",'"Helvetica Neue"',"Arial",'"Noto Sans"'," sans-serif"];function ne(e,t,n){if("string"==typeof t)return t;const{viewElementSize:i,viewScaleInfo:o,opacity:a=1}=n,{x:r,y:l}=i,{scale:s}=o;if("linear-gradient"===(null==t?void 0:t.type)){const{start:n,end:i,stops:o}=t,c={x:r+n.x*s,y:l+n.y*s},d={x:r+i.x*s,y:l+i.y*s},h=e.createLinearGradient(c.x,c.y,d.x,d.y);return o.forEach((e=>{h.addColorStop(e.offset,P(e.color,a))})),h}if("radial-gradient"===(null==t?void 0:t.type)){const{inner:n,outer:i,stops:o}=t,c={x:r+n.x*s,y:l+n.y*s,radius:n.radius*s},d={x:r+i.x*s,y:l+i.y*s,radius:i.radius*s},h=e.createRadialGradient(c.x,c.y,c.radius,d.x,d.y,d.radius);return o.forEach((e=>{h.addColorStop(e.offset,P(e.color,a))})),h}return"#000000"}const ie={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,fontFamily:"sans-serif",fontWeight:400,minInlineSize:"auto",wordBreak:"break-all",overflow:"hidden"};function oe(e){var t,n,i,o;let a=1;return void 0!==(null==(t=null==e?void 0:e.detail)?void 0:t.opacity)&&(null==(n=null==e?void 0:e.detail)?void 0:n.opacity)>=0&&(null==(i=null==e?void 0:e.detail)?void 0:i.opacity)<=1&&(a=null==(o=null==e?void 0:e.detail)?void 0:o.opacity),a}function ae(e,t,n){const{pattern:i,renderContent:o,originElem:a,calcElemSize:r,viewScaleInfo:l,viewSizeInfo:s}=n||{},{parentOpacity:c}=n,d=oe(a)*c,{clipPath:h,clipPathStrokeColor:f,clipPathStrokeWidth:u}=a.detail,w=()=>{e.globalAlpha=d,re(e,t,{pattern:i,viewScaleInfo:l,viewSizeInfo:s}),null==o||o(),le(e,t,{viewScaleInfo:l,viewSizeInfo:s}),e.globalAlpha=c};h?(function(e,t,n){const{renderContent:i,originElem:o,calcElemSize:a,viewSizeInfo:r}=n,l=r.devicePixelRatio,{clipPath:s}=(null==o?void 0:o.detail)||{};if(s&&a&&s.commands){const{x:n,y:o,w:r,h:c}=a,{originW:d,originH:h,originX:f,originY:u}=s,w=r/d,g=c/h,v=n-f*w,p=o-u*g;e.save(),e.translate(v,p),e.scale(l*w,l*g);const y=Z(s.commands||[]),m=new Path2D(y);e.clip(m),e.translate(0-v,0-p),e.setTransform(1,0,0,1,0,0),Q(e,{...t},(()=>{null==i||i()})),e.restore()}else null==i||i()}(e,t,{originElem:a,calcElemSize:r,viewScaleInfo:l,viewSizeInfo:s,renderContent:()=>{w()}}),"number"==typeof u&&u>0&&f&&function(e,t,n){const{renderContent:i,originElem:o,calcElemSize:a,viewSizeInfo:r,parentOpacity:l}=n,s=r.devicePixelRatio,{clipPath:c,clipPathStrokeColor:d,clipPathStrokeWidth:h}=(null==o?void 0:o.detail)||{};if(c&&a&&c.commands&&"number"==typeof h&&h>0&&d){const{x:n,y:o,w:r,h:f}=a,{originW:u,originH:w,originX:g,originY:v}=c,p=r/u,y=f/w,m=n-g*p,S=o-v*y;e.save(),e.globalAlpha=l,e.translate(m,S),e.scale(s*p,s*y);const x=Z(c.commands||[]),b=new Path2D(x);e.strokeStyle=d,e.lineWidth=h,e.stroke(b),e.translate(0-m,0-S),e.setTransform(1,0,0,1,0,0),Q(e,{...t},(()=>{null==i||i()})),e.restore()}else null==i||i()}(e,t,{originElem:a,calcElemSize:r,viewScaleInfo:l,viewSizeInfo:s,parentOpacity:c})):w()}function re(e,t,n){var i,o;const{pattern:a,viewScaleInfo:r,viewSizeInfo:l}=n,s=[];if(t.detail.background||a){const{x:n,y:c,w:d,h:h,radiusList:f}=ee(t,{viewScaleInfo:r,viewSizeInfo:l});if(e.beginPath(),e.moveTo(n+f[0],c),e.arcTo(n+d,c,n+d,c+h,f[1]),e.arcTo(n+d,c+h,n,c+h,f[2]),e.arcTo(n,c+h,n,c,f[3]),e.arcTo(n,c,n+d,c,f[0]),e.closePath(),"string"==typeof a)e.fillStyle=a;else if(["CanvasPattern"].includes(R.type(a)))e.fillStyle=a;else if("string"==typeof t.detail.background)e.fillStyle=t.detail.background;else if("linear-gradient"===(null==(i=t.detail.background)?void 0:i.type)){const i=ne(e,t.detail.background,{viewElementSize:{x:n,y:c,w:d,h:h},viewScaleInfo:r,opacity:e.globalAlpha});e.fillStyle=i}else if("radial-gradient"===(null==(o=t.detail.background)?void 0:o.type)){const i=ne(e,t.detail.background,{viewElementSize:{x:n,y:c,w:d,h:h},viewScaleInfo:r,opacity:e.globalAlpha});if(e.fillStyle=i,s&&s.length>0)for(let t=0;t<(null==s?void 0:s.length);t++){const i=s[t];"translate"===i.method?e.translate(i.args[0]+n,i.args[1]+c):"rotate"===i.method?e.rotate(...i.args):"scale"===i.method&&e.scale(...i.args)}}e.fill(),s&&s.length>0&&e.setTransform(1,0,0,1,0,0)}}function le(e,t,n){if(0===t.detail.borderWidth)return;if(!E(t.detail.borderColor))return;const{viewScaleInfo:i}=n,{scale:o}=i;let a=ie.borderColor;!0===E(t.detail.borderColor)&&(a=t.detail.borderColor);const{borderWidth:r,borderRadius:l,borderDash:s,boxSizing:c=ie.boxSizing}=t.detail;let d=0;"number"==typeof r&&(d=r||1),d*=o;let h=[0,0,0,0];if("number"==typeof l){const e=l*o;h=[e,e,e,e]}else Array.isArray(l)&&4===(null==l?void 0:l.length)&&(h=[l[0]*o,l[1]*o,l[2]*o,l[3]*o]);e.strokeStyle=a;let f=[];Array.isArray(s)&&s.length>0&&(f=s.map((e=>Math.ceil(e*o))));let u=0,w=0,g=0,v=0;if(Array.isArray(r)&&(u=(r[0]||0)*o,w=(r[1]||0)*o,g=(r[2]||0)*o,v=(r[3]||0)*o),v||w||u||g){e.lineCap="butt";let{x:n,y:i,w:o,h:a}=t;"border-box"===c?(n+=v/2,i+=u/2,o=o-v/2-w/2,a=a-u/2-g/2):"content-box"===c?(n-=v/2,i-=u/2,o=o+v/2+w/2,a=a+u/2+g/2):(n=t.x,i=t.y,o=t.w,a=t.h),u&&(e.beginPath(),e.lineWidth=u,e.moveTo(n-v/2,i),e.lineTo(n+o+w/2,i),e.closePath(),e.stroke()),w&&(e.beginPath(),e.lineWidth=w,e.moveTo(n+o,i-u/2),e.lineTo(n+o,i+a+g/2),e.closePath(),e.stroke()),g&&(e.beginPath(),e.lineWidth=g,e.moveTo(n-v/2,i+a),e.lineTo(n+o+w/2,i+a),e.closePath(),e.stroke()),v&&(e.beginPath(),e.lineWidth=v,e.moveTo(n,i-u/2),e.lineTo(n,i+a+g/2),e.closePath(),e.stroke())}else{let{x:n,y:i,w:o,h:a}=t;"border-box"===c?(n=t.x+d/2,i=t.y+d/2,o=t.w-d,a=t.h-d):"content-box"===c?(n=t.x-d/2,i=t.y-d/2,o=t.w+d,a=t.h+d):(n=t.x,i=t.y,o=t.w,a=t.h),f.length>0?e.lineCap="butt":e.lineCap="square",o=Math.max(o,1),a=Math.max(a,1),h=h.map((e=>Math.min(e,o/2,a/2))),e.setLineDash(f),e.lineWidth=d,e.beginPath(),e.moveTo(n+h[0],i),e.arcTo(n+o,i,n+o,i+a,h[1]),e.arcTo(n+o,i+a,n,i+a,h[2]),e.arcTo(n,i+a,n,i,h[3]),e.arcTo(n,i,n+o,i,h[0]),e.closePath(),e.stroke()}e.setLineDash([])}function se(e,t,n){const{detail:i}=t,{viewScaleInfo:o,renderContent:a}=n,{shadowColor:r,shadowOffsetX:l,shadowOffsetY:s,shadowBlur:c}=i;N.number(c)?(e.save(),e.shadowColor=r||ie.shadowColor,e.shadowOffsetX=(l||0)*o.scale,e.shadowOffsetY=(s||0)*o.scale,e.shadowBlur=(c||0)*o.scale,a(),e.restore()):(e.save(),e.shadowColor="transparent",e.shadowOffsetX=0,e.shadowOffsetY=0,e.shadowBlur=0,a(),e.restore())}function ce(e,t,n){const{viewScaleInfo:i,viewSizeInfo:o,parentOpacity:a}=n,{x:r,y:l,w:s,h:c,angle:d}=V(t,{viewScaleInfo:i,viewSizeInfo:o})||t,h={...t,x:r,y:l,w:s,h:c,angle:d};Q(e,{x:r,y:l,w:s,h:c,angle:d},(()=>{se(e,h,{viewScaleInfo:i,viewSizeInfo:o,renderContent:()=>{ae(e,h,{originElem:t,calcElemSize:{x:r,y:l,w:s,h:c,angle:d},viewScaleInfo:i,viewSizeInfo:o,parentOpacity:a,renderContent:()=>{}})}})}))}const de={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,fontFamily:"sans-serif",fontWeight:400,minInlineSize:"auto",wordBreak:"break-all",overflow:"hidden"};function he(e,t,n){var i,o,a;if(!0===(null==(i=null==t?void 0:t.operations)?void 0:i.invisible))return;const{w:r,h:l}=t,{scale:s}=n.viewScaleInfo;if(s<1&&(r*s<1||l*s<1)||0===n.parentOpacity)return;const{overrideElementMap:c}=n;if(!(null==(a=null==(o=null==c?void 0:c[t.uuid])?void 0:o.operations)?void 0:a.invisible))try{switch(t.type){case"rect":ce(e,t,n);break;case"circle":!function(e,t,n){const{detail:i,angle:o}=t,{viewScaleInfo:a,viewSizeInfo:r,parentOpacity:l}=n,{background:s="#000000",borderColor:c="#000000",boxSizing:d,borderWidth:h=0,borderDash:f}=i;let u=0;"number"==typeof h&&h>0?u=h:Array.isArray(h)&&"number"==typeof h[0]&&h[0]>0&&(u=h[0]),u*=a.scale;const{x:w,y:g,w:v,h:p}=V({x:t.x,y:t.y,w:t.w,h:t.h},{viewScaleInfo:a})||t,y={...t,x:w,y:g,w:v,h:p,angle:o};Q(e,{x:w,y:g,w:v,h:p,angle:o},(()=>{se(e,y,{viewScaleInfo:a,viewSizeInfo:r,renderContent:()=>{let t=v/2,n=p/2;const i=w+t,o=g+n,r=t,h=n;if(u>0&&("content-box"===d||("center-line"===d?(t-=u/2,n-=u/2):(t-=u,n-=u))),t>=0&&n>=0){const d=oe(y)*l;e.globalAlpha=d,e.beginPath();const m=ne(e,s,{viewElementSize:{x:w,y:g,w:v,h:p},viewScaleInfo:a,opacity:e.globalAlpha});if(e.fillStyle=m,e.circle(i,o,r,h,0,0,2*Math.PI),e.closePath(),e.fill(),e.globalAlpha=l,"number"==typeof u&&u>0){const r=u/2+t,l=u/2+n;if(e.beginPath(),f){const t=f.map((e=>e*a.scale));e.setLineDash(t)}e.strokeStyle=c,e.lineWidth=u,e.circle(i,o,r,l,0,0,2*Math.PI),e.closePath(),e.stroke(),e.setLineDash([])}}}})}))}(e,t,n);break;case"text":!function(e,t,n){const{viewScaleInfo:i,viewSizeInfo:o,parentOpacity:a}=n,{x:r,y:l,w:s,h:c,angle:d}=V(t,{viewScaleInfo:i})||t,h={...t,x:r,y:l,w:s,h:c,angle:d};Q(e,{x:r,y:l,w:s,h:c,angle:d},(()=>{ae(e,h,{originElem:t,calcElemSize:{x:r,y:l,w:s,h:c,angle:d},viewScaleInfo:i,viewSizeInfo:o,parentOpacity:a,renderContent:()=>{const n={...de,...t.detail},o=n.fontSize||de.fontSize,a=o*i.scale;if(a<2)return;const d=(n.lineHeight||o)*i.scale;var h;e.fillStyle=t.detail.color||de.color,e.textBaseline="top",e.$setFont({fontWeight:n.fontWeight,fontSize:a,fontFamily:(h=n.fontFamily,[h,...te].join(", "))});let f=n.text.replace(/\r\n/gi,"\n");"lowercase"===n.textTransform?f=f.toLowerCase():"uppercase"===n.textTransform&&(f=f.toUpperCase());const u=d,w=f.split("\n"),g=[];let v=0;w.forEach(((t,o)=>{if("maxContent"===n.minInlineSize)g.push({text:t,width:e.$undoPixelRatio(e.measureText(t).width)});else{let l="",d="",h=t.split(d);if("normal"===n.wordBreak){const e=" ",n=t.split(e);h=[],n.forEach(((t,i)=>{h.push(t),i<n.length-1&&h.push(e)}))}if(1===h.length&&"visible"===n.overflow)g.push({text:h[0],width:e.$undoPixelRatio(e.measureText(h[0]).width)});else if(h.length>0){for(let t=0;t<h.length&&(a=e.$doPixelRatio(s),r=e.measureText(l+h[t]).width,i.scale<.5&&a<r&&(a-r)/a>-.15||a>=r?l+=h[t]||"":(g.push({text:l,width:e.$undoPixelRatio(e.measureText(l).width)}),l=h[t]||"",v++),!((v+1)*u>c&&"hidden"===n.overflow));t++)if(h.length-1===t&&(v+1)*u<=c){g.push({text:l,width:e.$undoPixelRatio(e.measureText(l).width)}),o<w.length-1&&v++;break}}else g.push({text:"",width:0})}var a,r}));let p=0,y=0;u>a&&(y=(u-a)/2),g.length*u<c&&("top"===t.detail.verticalAlign?p=0:"bottom"===t.detail.verticalAlign?p+=c-g.length*u:p+=(c-g.length*u)/2);{const t=l+p;void 0!==n.textShadowColor&&E(n.textShadowColor)&&(e.shadowColor=n.textShadowColor),void 0!==n.textShadowOffsetX&&N.number(n.textShadowOffsetX)&&(e.shadowOffsetX=n.textShadowOffsetX),void 0!==n.textShadowOffsetY&&N.number(n.textShadowOffsetY)&&(e.shadowOffsetY=n.textShadowOffsetY),void 0!==n.textShadowBlur&&N.number(n.textShadowBlur)&&(e.shadowBlur=n.textShadowBlur),g.forEach(((i,o)=>{let a=r;"center"===n.textAlign?a=r+(s-i.width)/2:"right"===n.textAlign&&(a=r+(s-i.width)),e.fillText(i.text,a,t+u*o+y)}))}}})}))}(e,t,n);break;case"image":!function(e,t,n){const i=n.loader.getContent(t),{viewScaleInfo:o,viewSizeInfo:a,parentOpacity:r}=n,{x:l,y:s,w:c,h:d,angle:h}=V(t,{viewScaleInfo:o})||t,f={...t,x:l,y:s,w:c,h:d,angle:h};Q(e,{x:l,y:s,w:c,h:d,angle:h},(()=>{se(e,f,{viewScaleInfo:o,viewSizeInfo:a,renderContent:()=>{ae(e,f,{originElem:t,calcElemSize:{x:l,y:s,w:c,h:d,angle:h},viewScaleInfo:o,viewSizeInfo:a,parentOpacity:r,renderContent:()=>{if(i||n.loader.isDestroyed()||n.loader.load(t,n.elementAssets||{}),"image"===t.type&&i){e.globalAlpha=oe(t)*r;const{x:n,y:l,w:s,h:c,radiusList:d}=ee(f,{viewScaleInfo:o,viewSizeInfo:a}),{detail:h}=t,{scaleMode:u,originW:w=0,originH:g=0}=h,v=e.$undoPixelRatio(w),p=e.$undoPixelRatio(g);if(e.save(),e.fillStyle="transparent",e.beginPath(),e.moveTo(n+d[0],l),e.arcTo(n+s,l,n+s,l+c,d[1]),e.arcTo(n+s,l+c,n,l+c,d[2]),e.arcTo(n,l+c,n,l,d[3]),e.arcTo(n,l,n+s,l,d[0]),e.closePath(),e.fill(),e.clip(),u&&g&&w){let o=0,a=0,r=v,d=p;const h=n,f=l,w=s,g=c;if(v>t.w||p>t.h)if("fill"===u){const e=Math.max(t.w/v,t.h/p),n=p*e;o=(v*e-t.w)/2/e,a=(n-t.h)/2/e,r=t.w/e,d=t.h/e}else if("tile"===u)o=0,a=0,r=t.w,d=t.h;else if("fit"===u){const e=Math.min(t.w/v,t.h/p);o=(v-t.w/e)/2,a=(p-t.h/e)/2,r=t.w/e,d=t.h/e}e.drawImage(i,o,a,r,d,h,f,w,g)}else e.drawImage(i,n,l,s,c);e.globalAlpha=r,e.restore()}}})}})}))}(e,t,n);break;case"svg":!function(e,t,n){const i=n.loader.getContent(t),{viewScaleInfo:o,viewSizeInfo:a,parentOpacity:r}=n,{x:l,y:s,w:c,h:d,angle:h}=V(t,{viewScaleInfo:o,viewSizeInfo:a})||t;Q(e,{x:l,y:s,w:c,h:d,angle:h},(()=>{i||n.loader.isDestroyed()||n.loader.load(t,n.elementAssets||{}),"svg"===t.type&&i&&(e.globalAlpha=oe(t)*r,e.drawImage(i,l,s,c,d),e.globalAlpha=r)}))}(e,t,n);break;case"html":!function(e,t,n){const i=n.loader.getContent(t),{viewScaleInfo:o,viewSizeInfo:a,parentOpacity:r}=n,{x:l,y:s,w:c,h:d,angle:h}=V(t,{viewScaleInfo:o,viewSizeInfo:a})||t;Q(e,{x:l,y:s,w:c,h:d,angle:h},(()=>{i||n.loader.isDestroyed()||n.loader.load(t,n.elementAssets||{}),"html"===t.type&&i&&(e.globalAlpha=oe(t)*r,e.drawImage(i,l,s,c,d),e.globalAlpha=r)}))}(e,t,n);break;case"path":!function(e,t,n){const{detail:i}=t,{originX:o,originY:a,originW:r,originH:l,fillRule:s}=i,{viewScaleInfo:c,viewSizeInfo:d,parentOpacity:h}=n,{x:f,y:u,w:w,h:g,angle:v}=V(t,{viewScaleInfo:c})||t,p=w/r,y=g/l,m=f-o*p,S=u-a*y,x=c.scale*d.devicePixelRatio,b={...t,x:f,y:u,w:w,h:g,angle:v};Q(e,{x:f,y:u,w:w,h:g,angle:v},(()=>{ae(e,b,{originElem:t,calcElemSize:{x:f,y:u,w:w,h:g,angle:v},viewScaleInfo:c,viewSizeInfo:d,parentOpacity:h,renderContent:()=>{se(e,b,{viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{e.save(),e.translate(m,S),e.scale(x*p/c.scale,x*y/c.scale);const t=Z(i.commands||[]),n=new Path2D(t);i.fill&&(e.fillStyle=i.fill,e.fill(n,s)),i.stroke&&0!==i.strokeWidth&&(e.strokeStyle=i.stroke,e.lineWidth=(i.strokeWidth||1)/d.devicePixelRatio,e.lineCap=i.strokeLineCap||"square",e.stroke(n)),e.translate(-m,-S),e.restore()}})}})}))}(e,t,n);break;case"group":{const i={...n.elementAssets||{},...t.detail.assets||{}};!function(e,t,n){const{viewScaleInfo:i,viewSizeInfo:o,parentOpacity:a}=n,{x:r,y:l,w:s,h:c,angle:d}=V({x:t.x,y:t.y,w:t.w,h:t.h,angle:t.angle},{viewScaleInfo:i})||t,h={...t,x:r,y:l,w:s,h:c,angle:d};Q(e,{x:r,y:l,w:s,h:c,angle:d},(()=>{e.globalAlpha=oe(t)*a,se(e,h,{viewScaleInfo:i,viewSizeInfo:o,renderContent:()=>{ae(e,h,{originElem:t,calcElemSize:{x:r,y:l,w:s,h:c,angle:d},viewScaleInfo:i,viewSizeInfo:o,parentOpacity:a,renderContent:()=>{const{x:r,y:l,w:s,h:c,radiusList:d}=ee(h,{viewScaleInfo:i,viewSizeInfo:o});if("hidden"===t.detail.overflow&&(e.save(),e.fillStyle="transparent",e.beginPath(),e.moveTo(r+d[0],l),e.arcTo(r+s,l,r+s,l+c,d[1]),e.arcTo(r+s,l+c,r,l+c,d[2]),e.arcTo(r,l+c,r,l,d[3]),e.arcTo(r,l,r+s,l,d[0]),e.closePath(),e.fill(),e.clip()),Array.isArray(t.detail.children)){const{parentElementSize:i}=n,o={x:i.x+t.x,y:i.y+t.y,w:t.w||i.w,h:t.h||i.h,angle:t.angle},{calculator:r}=n;for(let i=0;i<t.detail.children.length;i++){let l=t.detail.children[i];if(l={...l,x:o.x+l.x,y:o.y+l.y},!0===n.forceDrawAll||(null==r?void 0:r.needRender(l)))try{he(e,l,{...n,parentOpacity:a*oe(t)})}catch(e){console.error(e)}}}"hidden"===t.detail.overflow&&e.restore()}})}}),e.globalAlpha=a}))}(e,t,{...n,elementAssets:i});break}}}catch(e){console.error(e)}}const fe={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,fontFamily:"sans-serif",fontWeight:400,minInlineSize:"auto",wordBreak:"break-all",overflow:"hidden"};function ue(e,t,n){var i;const{elements:o=[]}=t,{parentOpacity:a}=n;for(let t=0;t<o.length;t++){const r=o[t],l={...r,detail:{...fe,...null==r?void 0:r.detail}};if(!0===n.forceDrawAll||(null==(i=n.calculator)?void 0:i.needRender(l)))try{he(e,l,{...n,parentOpacity:a})}catch(e){console.error(e)}}}const we=["image","svg","html"],ge=e=>{var t,n,i;let o=null;return"image"===e.type?o=(null==(t=null==e?void 0:e.detail)?void 0:t.src)||null:"svg"===e.type?o=(null==(n=null==e?void 0:e.detail)?void 0:n.svg)||null:"html"===e.type&&(o=(null==(i=null==e?void 0:e.detail)?void 0:i.html)||null),"string"==typeof o&&o?/^@assets\/[0-9a-z]{8,8}\-[0-9a-z]{4,4}\-[0-9a-z]{4,4}\-[0-9a-z]{4,4}\-[0-9a-z]{12,12}$/.test(`${o}`)?o:$(o):$(`${W()}-${e.uuid}-${W()}-${W()}`)};class ve extends J{constructor(){super(),A(this,a),A(this,l),A(this,c),A(this,h),A(this,u),A(this,g),A(this,p),A(this,t,{}),A(this,n,{}),A(this,i,{}),A(this,o,!1),C(this,a,r).call(this,"image",(async(e,t)=>{var n;const i=(null==(n=t[e.detail.src])?void 0:n.value)||e.detail.src,o=await B(i);return{uuid:e.uuid,lastModified:Date.now(),content:o}})),C(this,a,r).call(this,"html",(async(e,t)=>{var n;const i=(null==(n=t[e.detail.html])?void 0:n.value)||e.detail.html,o=await Y(i,{width:e.detail.originW||e.w,height:e.detail.originH||e.h});return{uuid:e.uuid,lastModified:Date.now(),content:o}})),C(this,a,r).call(this,"svg",(async(e,t)=>{var n;const i=(null==(n=t[e.detail.svg])?void 0:n.value)||e.detail.svg,o=await X(i);return{uuid:e.uuid,lastModified:Date.now(),content:o}}))}isDestroyed(){return T(this,o)}destroy(){k(this,o,!0),this.clear(),k(this,t,null),k(this,n,null),k(this,i,null)}load(e,t){!0!==T(this,o)&&(C(this,p,y).call(this,e)||we.includes(e.type)&&C(this,g,v).call(this,e,t))}getContent(e){var t,n;const o=ge(e);return(null==(n=null==(t=T(this,i))?void 0:t[o])?void 0:n.content)||null}getLoadItemMap(){return T(this,i)}setLoadItemMap(e){k(this,i,e)}}t=new WeakMap,n=new WeakMap,i=new WeakMap,o=new WeakMap,a=new WeakSet,r=function(e,n){T(this,t)[e]=n},l=new WeakSet,s=function(e){var t,n,i;let o=null;return"image"===e.type?o=(null==(t=null==e?void 0:e.detail)?void 0:t.src)||null:"svg"===e.type?o=(null==(n=null==e?void 0:e.detail)?void 0:n.svg)||null:"html"===e.type&&(o=(null==(i=null==e?void 0:e.detail)?void 0:i.html)||null),o},c=new WeakSet,d=function(e){return{element:e,status:"null",content:null,error:null,startTime:-1,endTime:-1,source:C(this,l,s).call(this,e)}},h=new WeakSet,f=function(e){const t=ge(e.element),n=T(this,i)[t];T(this,o)||(n?n.startTime<e.startTime&&(T(this,i)[t]=e,this.trigger("load",{...e,countTime:e.endTime-e.startTime})):(T(this,i)[t]=e,this.trigger("load",{...e,countTime:e.endTime-e.startTime})))},u=new WeakSet,w=function(e){var t;const n=ge(e.element),a=null==(t=T(this,i))?void 0:t[n];T(this,o)||(a?a.startTime<e.startTime&&(T(this,i)[n]=e,this.trigger("error",{...e,countTime:e.endTime-e.startTime})):(T(this,i)[n]=e,this.trigger("error",{...e,countTime:e.endTime-e.startTime})))},g=new WeakSet,v=function(e,i){const a=C(this,c,d).call(this,e),r=ge(e);if(T(this,n)[r])return;T(this,n)[r]=a;const l=T(this,t)[e.type];"function"!=typeof l||T(this,o)||(a.startTime=Date.now(),l(e,i).then((e=>{T(this,o)||(a.content=e.content,a.endTime=Date.now(),a.status="load",C(this,h,f).call(this,a))})).catch((t=>{console.warn(`Load element source "${a.source}" fail`,t,e),a.endTime=Date.now(),a.status="error",a.error=t,C(this,u,w).call(this,a)})))},p=new WeakSet,y=function(e){var t;const i=ge(e),o=null==(t=T(this,n))?void 0:t[i];return!(!o||"error"!==o.status||!o.source||o.source!==C(this,l,s).call(this,e))};return m=new WeakMap,S=new WeakMap,x=new WeakMap,b=new WeakSet,I=function(){const e=T(this,S);e.on("load",(e=>{this.trigger("load",e)})),e.on("error",(e=>{console.error(e)}))},e.Renderer=class extends J{constructor(e){super(),A(this,b),A(this,m,void 0),A(this,S,new ve),A(this,x,!1),k(this,m,e),C(this,b,I).call(this)}isDestroyed(){return T(this,x)}destroy(){this.clear(),k(this,m,null),T(this,S).destroy(),k(this,S,null),k(this,x,!0)}updateOptions(e){k(this,m,e)}drawData(e,t){const n=T(this,S),{calculator:i,sharer:o}=T(this,m),a=T(this,m).viewContext;a.clearRect(0,0,a.canvas.width,a.canvas.height);const r={loader:n,calculator:i,parentElementSize:{x:0,y:0,w:t.viewSizeInfo.width,h:t.viewSizeInfo.height},elementAssets:e.assets,parentOpacity:1,overrideElementMap:null==o?void 0:o.getActiveOverrideElemenentMap(),...t};!function(e,t,n){if("string"==typeof(null==t?void 0:t.background)){const{viewSizeInfo:i}=n,{width:o,height:a}=i;e.globalAlpha=1,e.fillStyle=t.background,e.fillRect(0,0,o,a)}}(a,e.global,r),e.layout?function(e,t,n,i){const{viewScaleInfo:o,viewSizeInfo:a,parentOpacity:r}=n,l={uuid:"layout",type:"group",...t},{x:s,y:c,w:d,h:h}=V(l,{viewScaleInfo:o})||l,f={...l,x:s,y:c,w:d,h:h,angle:0};if(e.globalAlpha=1,se(e,f,{viewScaleInfo:o,viewSizeInfo:a,renderContent:()=>{re(e,f,{viewScaleInfo:o,viewSizeInfo:a})}}),"hidden"===t.detail.overflow){const{viewScaleInfo:i,viewSizeInfo:o}=n,a={uuid:"layout",type:"group",...t},r=V(a,{viewScaleInfo:i})||a,l={...a,...r},{x:s,y:c,w:d,h:h,radiusList:f}=ee(l,{viewScaleInfo:i,viewSizeInfo:o});e.save(),e.fillStyle="transparent",e.beginPath(),e.moveTo(s+f[0],c),e.arcTo(s+d,c,s+d,c+h,f[1]),e.arcTo(s+d,c+h,s,c+h,f[2]),e.arcTo(s,c+h,s,c,f[3]),e.arcTo(s,c,s+d,c,f[0]),e.closePath(),e.fill(),e.clip()}i(e),"hidden"===t.detail.overflow&&e.restore(),le(e,f,{viewScaleInfo:o,viewSizeInfo:a}),e.globalAlpha=r}(a,e.layout,r,(()=>{ue(a,e,r)})):ue(a,e,r)}scale(e){const{sharer:t}=T(this,m);if(!t)return;const{data:n,offsetTop:i,offsetBottom:o,offsetLeft:a,offsetRight:r,width:l,height:s,contextHeight:c,contextWidth:d,devicePixelRatio:h}=t.getActiveStoreSnapshot();n&&this.drawData(n,{viewScaleInfo:{scale:e,offsetTop:i,offsetBottom:o,offsetLeft:a,offsetRight:r},viewSizeInfo:{width:l,height:s,contextHeight:c,contextWidth:d,devicePixelRatio:h}})}setLoadItemMap(e){T(this,S).setLoadItemMap(e)}getLoadItemMap(){return T(this,S).getLoadItemMap()}getLoader(){return T(this,S)}},e.drawRect=ce,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idraw/renderer",
|
|
3
|
-
"version": "0.4.0-beta.
|
|
3
|
+
"version": "0.4.0-beta.25",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"author": "chenshenhai",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@idraw/types": "^0.4.0-beta.
|
|
24
|
+
"@idraw/types": "^0.4.0-beta.25"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@idraw/util": "^0.4.0-beta.
|
|
28
|
+
"@idraw/util": "^0.4.0-beta.25"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public",
|