@idraw/renderer 0.4.0-alpha.5 → 0.4.0-alpha.7
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 +5 -0
- package/dist/esm/draw/group.js +56 -39
- package/dist/esm/draw/image.js +1 -0
- package/dist/index.global.js +94 -43
- package/dist/index.global.min.js +1 -1
- package/package.json +3 -3
package/dist/esm/draw/box.js
CHANGED
|
@@ -247,6 +247,11 @@ function drawBoxBorder(ctx, viewElem, opts) {
|
|
|
247
247
|
else {
|
|
248
248
|
ctx.lineCap = 'square';
|
|
249
249
|
}
|
|
250
|
+
w = Math.max(w, 1);
|
|
251
|
+
h = Math.max(h, 1);
|
|
252
|
+
radiusList = radiusList.map((r) => {
|
|
253
|
+
return Math.min(r, w / 2, h / 2);
|
|
254
|
+
});
|
|
250
255
|
ctx.setLineDash(viewBorderDash);
|
|
251
256
|
ctx.lineWidth = bw;
|
|
252
257
|
ctx.beginPath();
|
package/dist/esm/draw/group.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { rotateElement } from '@idraw/util';
|
|
1
|
+
import { rotateElement, calcViewBoxSize } from '@idraw/util';
|
|
2
2
|
import { drawCircle } from './circle';
|
|
3
3
|
import { drawRect } from './rect';
|
|
4
4
|
import { drawImage } from './image';
|
|
5
5
|
import { drawText } from './text';
|
|
6
6
|
import { drawSVG } from './svg';
|
|
7
7
|
import { drawHTML } from './html';
|
|
8
|
-
import { drawBox } from './box';
|
|
8
|
+
import { drawBox, drawBoxShadow } from './box';
|
|
9
9
|
import { drawPath } from './path';
|
|
10
10
|
export function drawElement(ctx, elem, opts) {
|
|
11
11
|
var _a;
|
|
@@ -43,7 +43,8 @@ export function drawElement(ctx, elem, opts) {
|
|
|
43
43
|
break;
|
|
44
44
|
}
|
|
45
45
|
case 'group': {
|
|
46
|
-
|
|
46
|
+
const assets = Object.assign(Object.assign({}, (opts.elementAssets || {})), (elem.detail.assets || {}));
|
|
47
|
+
drawGroup(ctx, elem, Object.assign(Object.assign({}, opts), { elementAssets: assets }));
|
|
47
48
|
break;
|
|
48
49
|
}
|
|
49
50
|
default: {
|
|
@@ -60,50 +61,66 @@ export function drawGroup(ctx, elem, opts) {
|
|
|
60
61
|
const { x, y, w, h, angle } = calculator.elementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h, angle: elem.angle }, viewScaleInfo, viewSizeInfo);
|
|
61
62
|
const viewElem = Object.assign(Object.assign({}, elem), { x, y, w, h, angle });
|
|
62
63
|
rotateElement(ctx, { x, y, w, h, angle }, () => {
|
|
63
|
-
|
|
64
|
-
originElem: elem,
|
|
65
|
-
calcElemSize: { x, y, w, h, angle },
|
|
64
|
+
drawBoxShadow(ctx, viewElem, {
|
|
66
65
|
viewScaleInfo,
|
|
67
66
|
viewSizeInfo,
|
|
68
67
|
renderContent: () => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const { calculator } = opts;
|
|
79
|
-
if (elem.detail.overflow === 'hidden') {
|
|
80
|
-
ctx.save();
|
|
81
|
-
ctx.beginPath();
|
|
82
|
-
ctx.moveTo(x, y);
|
|
83
|
-
ctx.lineTo(x + w, y);
|
|
84
|
-
ctx.lineTo(x + w, y + h);
|
|
85
|
-
ctx.lineTo(x, y + h);
|
|
86
|
-
ctx.closePath();
|
|
87
|
-
ctx.clip();
|
|
88
|
-
}
|
|
89
|
-
for (let i = 0; i < elem.detail.children.length; i++) {
|
|
90
|
-
let child = elem.detail.children[i];
|
|
91
|
-
child = Object.assign(Object.assign({}, child), {
|
|
92
|
-
x: newParentSize.x + child.x,
|
|
93
|
-
y: newParentSize.y + child.y
|
|
68
|
+
drawBox(ctx, viewElem, {
|
|
69
|
+
originElem: elem,
|
|
70
|
+
calcElemSize: { x, y, w, h, angle },
|
|
71
|
+
viewScaleInfo,
|
|
72
|
+
viewSizeInfo,
|
|
73
|
+
renderContent: () => {
|
|
74
|
+
const { x, y, w, h, radiusList } = calcViewBoxSize(viewElem, {
|
|
75
|
+
viewScaleInfo,
|
|
76
|
+
viewSizeInfo
|
|
94
77
|
});
|
|
95
|
-
if (
|
|
96
|
-
|
|
78
|
+
if (elem.detail.overflow === 'hidden') {
|
|
79
|
+
ctx.save();
|
|
80
|
+
ctx.fillStyle = 'transparent';
|
|
81
|
+
ctx.beginPath();
|
|
82
|
+
ctx.moveTo(x + radiusList[0], y);
|
|
83
|
+
ctx.arcTo(x + w, y, x + w, y + h, radiusList[1]);
|
|
84
|
+
ctx.arcTo(x + w, y + h, x, y + h, radiusList[2]);
|
|
85
|
+
ctx.arcTo(x, y + h, x, y, radiusList[3]);
|
|
86
|
+
ctx.arcTo(x, y, x + w, y, radiusList[0]);
|
|
87
|
+
ctx.closePath();
|
|
88
|
+
ctx.fill();
|
|
89
|
+
ctx.clip();
|
|
97
90
|
}
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
if (Array.isArray(elem.detail.children)) {
|
|
92
|
+
const { parentElementSize: parentSize } = opts;
|
|
93
|
+
const newParentSize = {
|
|
94
|
+
x: parentSize.x + elem.x,
|
|
95
|
+
y: parentSize.y + elem.y,
|
|
96
|
+
w: elem.w || parentSize.w,
|
|
97
|
+
h: elem.h || parentSize.h,
|
|
98
|
+
angle: elem.angle
|
|
99
|
+
};
|
|
100
|
+
const { calculator } = opts;
|
|
101
|
+
for (let i = 0; i < elem.detail.children.length; i++) {
|
|
102
|
+
let child = elem.detail.children[i];
|
|
103
|
+
child = Object.assign(Object.assign({}, child), {
|
|
104
|
+
x: newParentSize.x + child.x,
|
|
105
|
+
y: newParentSize.y + child.y
|
|
106
|
+
});
|
|
107
|
+
if (!calculator.isElementInView(child, opts.viewScaleInfo, opts.viewSizeInfo)) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
drawElement(ctx, child, Object.assign({}, opts));
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
console.error(err);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
100
117
|
}
|
|
101
|
-
|
|
102
|
-
|
|
118
|
+
if (elem.detail.overflow === 'hidden') {
|
|
119
|
+
ctx.globalAlpha = 1;
|
|
120
|
+
ctx.restore();
|
|
103
121
|
}
|
|
104
122
|
}
|
|
105
|
-
|
|
106
|
-
}
|
|
123
|
+
});
|
|
107
124
|
}
|
|
108
125
|
});
|
|
109
126
|
});
|
package/dist/esm/draw/image.js
CHANGED
package/dist/index.global.js
CHANGED
|
@@ -294,6 +294,22 @@ var iDrawRenderer = function(exports) {
|
|
|
294
294
|
fontWeight,
|
|
295
295
|
strokeWidth
|
|
296
296
|
};
|
|
297
|
+
(function(receiver, state, value, kind, f) {
|
|
298
|
+
if (kind === "m")
|
|
299
|
+
throw new TypeError("Private method is not writable");
|
|
300
|
+
if (kind === "a" && !f)
|
|
301
|
+
throw new TypeError("Private accessor was defined without a setter");
|
|
302
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
303
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
304
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
305
|
+
});
|
|
306
|
+
(function(receiver, state, kind, f) {
|
|
307
|
+
if (kind === "a" && !f)
|
|
308
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
309
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
310
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
311
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
312
|
+
});
|
|
297
313
|
class EventEmitter {
|
|
298
314
|
constructor() {
|
|
299
315
|
this._listeners = /* @__PURE__ */ new Map();
|
|
@@ -381,7 +397,7 @@ var iDrawRenderer = function(exports) {
|
|
|
381
397
|
}
|
|
382
398
|
function getDefaultElementDetailConfig() {
|
|
383
399
|
const config = {
|
|
384
|
-
boxSizing: "
|
|
400
|
+
boxSizing: "border-box",
|
|
385
401
|
borderWidth: 0,
|
|
386
402
|
borderColor: "#000000",
|
|
387
403
|
shadowColor: "#000000",
|
|
@@ -397,7 +413,8 @@ var iDrawRenderer = function(exports) {
|
|
|
397
413
|
fontSize: 16,
|
|
398
414
|
lineHeight: 20,
|
|
399
415
|
fontFamily: "sans-serif",
|
|
400
|
-
fontWeight: 400
|
|
416
|
+
fontWeight: 400,
|
|
417
|
+
overflow: "hidden"
|
|
401
418
|
};
|
|
402
419
|
return config;
|
|
403
420
|
}
|
|
@@ -419,7 +436,7 @@ var iDrawRenderer = function(exports) {
|
|
|
419
436
|
}
|
|
420
437
|
let bw = 0;
|
|
421
438
|
if (typeof borderWidth2 === "number") {
|
|
422
|
-
bw = (borderWidth2 ||
|
|
439
|
+
bw = (borderWidth2 || 0) * scale;
|
|
423
440
|
}
|
|
424
441
|
if (boxSizing === "border-box") {
|
|
425
442
|
x2 = viewElem.x + bw / 2;
|
|
@@ -437,6 +454,11 @@ var iDrawRenderer = function(exports) {
|
|
|
437
454
|
w2 = viewElem.w;
|
|
438
455
|
h2 = viewElem.h;
|
|
439
456
|
}
|
|
457
|
+
w2 = Math.max(w2, 1);
|
|
458
|
+
h2 = Math.max(h2, 1);
|
|
459
|
+
radiusList = radiusList.map((r) => {
|
|
460
|
+
return Math.min(r, w2 / 2, h2 / 2);
|
|
461
|
+
});
|
|
440
462
|
return {
|
|
441
463
|
x: x2,
|
|
442
464
|
y: y2,
|
|
@@ -716,6 +738,11 @@ var iDrawRenderer = function(exports) {
|
|
|
716
738
|
} else {
|
|
717
739
|
ctx.lineCap = "square";
|
|
718
740
|
}
|
|
741
|
+
w2 = Math.max(w2, 1);
|
|
742
|
+
h2 = Math.max(h2, 1);
|
|
743
|
+
radiusList = radiusList.map((r) => {
|
|
744
|
+
return Math.min(r, w2 / 2, h2 / 2);
|
|
745
|
+
});
|
|
719
746
|
ctx.setLineDash(viewBorderDash);
|
|
720
747
|
ctx.lineWidth = bw;
|
|
721
748
|
ctx.beginPath();
|
|
@@ -840,6 +867,7 @@ var iDrawRenderer = function(exports) {
|
|
|
840
867
|
viewSizeInfo
|
|
841
868
|
});
|
|
842
869
|
ctx.save();
|
|
870
|
+
ctx.fillStyle = "transparent";
|
|
843
871
|
ctx.beginPath();
|
|
844
872
|
ctx.moveTo(x22 + radiusList[0], y22);
|
|
845
873
|
ctx.arcTo(x22 + w22, y22, x22 + w22, y22 + h22, radiusList[1]);
|
|
@@ -1079,7 +1107,14 @@ var iDrawRenderer = function(exports) {
|
|
|
1079
1107
|
break;
|
|
1080
1108
|
}
|
|
1081
1109
|
case "group": {
|
|
1082
|
-
|
|
1110
|
+
const assets = {
|
|
1111
|
+
...opts.elementAssets || {},
|
|
1112
|
+
...elem.detail.assets || {}
|
|
1113
|
+
};
|
|
1114
|
+
drawGroup(ctx, elem, {
|
|
1115
|
+
...opts,
|
|
1116
|
+
elementAssets: assets
|
|
1117
|
+
});
|
|
1083
1118
|
break;
|
|
1084
1119
|
}
|
|
1085
1120
|
default: {
|
|
@@ -1095,52 +1130,68 @@ var iDrawRenderer = function(exports) {
|
|
|
1095
1130
|
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calculator.elementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h, angle: elem.angle }, viewScaleInfo, viewSizeInfo);
|
|
1096
1131
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
1097
1132
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
1098
|
-
|
|
1099
|
-
originElem: elem,
|
|
1100
|
-
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1133
|
+
drawBoxShadow(ctx, viewElem, {
|
|
1101
1134
|
viewScaleInfo,
|
|
1102
1135
|
viewSizeInfo,
|
|
1103
1136
|
renderContent: () => {
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1137
|
+
drawBox(ctx, viewElem, {
|
|
1138
|
+
originElem: elem,
|
|
1139
|
+
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1140
|
+
viewScaleInfo,
|
|
1141
|
+
viewSizeInfo,
|
|
1142
|
+
renderContent: () => {
|
|
1143
|
+
const { x: x22, y: y22, w: w22, h: h22, radiusList } = calcViewBoxSize(viewElem, {
|
|
1144
|
+
viewScaleInfo,
|
|
1145
|
+
viewSizeInfo
|
|
1146
|
+
});
|
|
1147
|
+
if (elem.detail.overflow === "hidden") {
|
|
1148
|
+
ctx.save();
|
|
1149
|
+
ctx.fillStyle = "transparent";
|
|
1150
|
+
ctx.beginPath();
|
|
1151
|
+
ctx.moveTo(x22 + radiusList[0], y22);
|
|
1152
|
+
ctx.arcTo(x22 + w22, y22, x22 + w22, y22 + h22, radiusList[1]);
|
|
1153
|
+
ctx.arcTo(x22 + w22, y22 + h22, x22, y22 + h22, radiusList[2]);
|
|
1154
|
+
ctx.arcTo(x22, y22 + h22, x22, y22, radiusList[3]);
|
|
1155
|
+
ctx.arcTo(x22, y22, x22 + w22, y22, radiusList[0]);
|
|
1156
|
+
ctx.closePath();
|
|
1157
|
+
ctx.fill();
|
|
1158
|
+
ctx.clip();
|
|
1159
|
+
}
|
|
1160
|
+
if (Array.isArray(elem.detail.children)) {
|
|
1161
|
+
const { parentElementSize: parentSize } = opts;
|
|
1162
|
+
const newParentSize = {
|
|
1163
|
+
x: parentSize.x + elem.x,
|
|
1164
|
+
y: parentSize.y + elem.y,
|
|
1165
|
+
w: elem.w || parentSize.w,
|
|
1166
|
+
h: elem.h || parentSize.h,
|
|
1167
|
+
angle: elem.angle
|
|
1168
|
+
};
|
|
1169
|
+
const { calculator: calculator2 } = opts;
|
|
1170
|
+
for (let i = 0; i < elem.detail.children.length; i++) {
|
|
1171
|
+
let child = elem.detail.children[i];
|
|
1172
|
+
child = {
|
|
1173
|
+
...child,
|
|
1174
|
+
...{
|
|
1175
|
+
x: newParentSize.x + child.x,
|
|
1176
|
+
y: newParentSize.y + child.y
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
if (!calculator2.isElementInView(child, opts.viewScaleInfo, opts.viewSizeInfo)) {
|
|
1180
|
+
continue;
|
|
1181
|
+
}
|
|
1182
|
+
try {
|
|
1183
|
+
drawElement(ctx, child, { ...opts });
|
|
1184
|
+
} catch (err) {
|
|
1185
|
+
console.error(err);
|
|
1186
|
+
}
|
|
1131
1187
|
}
|
|
1132
|
-
};
|
|
1133
|
-
if (!calculator2.isElementInView(child, opts.viewScaleInfo, opts.viewSizeInfo)) {
|
|
1134
|
-
continue;
|
|
1135
1188
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
console.error(err);
|
|
1189
|
+
if (elem.detail.overflow === "hidden") {
|
|
1190
|
+
ctx.globalAlpha = 1;
|
|
1191
|
+
ctx.restore();
|
|
1140
1192
|
}
|
|
1141
1193
|
}
|
|
1142
|
-
|
|
1143
|
-
}
|
|
1194
|
+
});
|
|
1144
1195
|
}
|
|
1145
1196
|
});
|
|
1146
1197
|
});
|
package/dist/index.global.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var iDrawRenderer=function(e){"use strict";function t(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 n(e,t){if(1===t)return e;let n=1;const o=/^\#[0-9a-f]{6,6}$/i;let i=e;if(o.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")),i=e.substring(0,7)),n*=t,o.test(i)&&n>0&&n<1){const e=Math.max(0,Math.min(255,Math.ceil(256*n)));i=`${i.toUpperCase()}${e.toString(16).toUpperCase()}`}return i}function o(){function e(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${e()}${e()}-${e()}-${e()}-${e()}-${e()}${e()}${e()}`}function i(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 l(e){const t=e.length,n=Math.floor(t/2),o=e.substring(0,4).padEnd(4,"0"),l=e.substring(0,4).padEnd(4,"0");return`@assets/${i(t.toString(16).padEnd(4,o))}${i(e.substring(n-4,n).padEnd(4,o)).padEnd(4,"f")}-${i(e.substring(n-8,n-4).padEnd(4,o)).padEnd(4,"f")}-${i(e.substring(n-12,n-8).padEnd(4,o)).padEnd(4,"f")}-${i(e.substring(n-16,n-12).padEnd(4,l)).padEnd(4,"f")}-${i(e.substring(n,n+4).padEnd(4,l)).padEnd(4,"f")}${i(e.substring(n+4,n+8).padEnd(4,l)).padEnd(4,"f")}${i(l.padEnd(4,o).padEnd(4,l))}`}function r(e){return(Object.prototype.toString.call(e)||"").replace(/(\[object|\])/gi,"").trim()}const a={type(e,t){const n=r(e);return!0===t?n.toLocaleLowerCase():n},array:e=>"Array"===r(e),json:e=>"Object"===r(e),function:e=>"Function"===r(e),asyncFunction:e=>"AsyncFunction"===r(e),string:e=>"String"===r(e),number:e=>"Number"===r(e),undefined:e=>"Undefined"===r(e),null:e=>"Null"===r(e),promise:e=>"Promise"===r(e)};var s=function(e,t,n,o){return new(n||(n=Promise))((function(i,l){function r(e){try{s(o.next(e))}catch(e){l(e)}}function a(e){try{s(o.throw(e))}catch(e){l(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}s((o=o.apply(e,t||[])).next())}))};const{Image:c}=window;function d(e){return new Promise(((t,n)=>{const o=new c;o.crossOrigin="anonymous",o.onload=function(){t(o)},o.onabort=n,o.onerror=n,o.src=e}))}function h(e){return s(this,void 0,void 0,(function*(){const t=yield function(e){return new Promise(((t,n)=>{const o=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),i=new FileReader;i.readAsDataURL(o),i.onload=function(e){var n;const o=null===(n=null==e?void 0:e.target)||void 0===n?void 0:n.result;t(o)},i.onerror=function(e){n(e)}}))}(e);return yield d(t)}))}function u(e,t){return s(this,void 0,void 0,(function*(){e=e.replace(/\&/gi,"&");const n=yield function(e,t){const{width:n,height:o}=t;return new Promise(((t,i)=>{const l=new Blob([`\n <svg \n xmlns="http://www.w3.org/2000/svg" \n width="${n||""}" \n height = "${o||""}">\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(l),r.onload=function(e){var n;const o=null===(n=null==e?void 0:e.target)||void 0===n?void 0:n.result;t(o)},r.onerror=function(e){i(e)}}))}(e,t);return yield d(n)}))}function f(e){return"number"==typeof e&&(e>0||e<=0)}function g(e){return"number"==typeof e&&e>=0}function w(e){return"string"==typeof e&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${e}`)}function v(e){return"string"==typeof e&&/^(data:image\/)/.test(`${e}`)}const y={x:function(e){return f(e)},y:function(e){return f(e)},w:g,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 g(e)},borderRadius:function(e){return f(e)&&e>=0},color:function(e){return t(e)},imageSrc:function(e){return v(e)||w(e)},imageURL:w,imageBase64:v,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}};class m{constructor(){this._listeners=new Map}on(e,t){if(this._listeners.has(e)){const n=this._listeners.get(e)||[];null==n||n.push(t),this._listeners.set(e,n)}else this._listeners.set(e,[t])}off(e,t){if(this._listeners.has(e)){const n=this._listeners.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}this._listeners.set(e,n||[])}}trigger(e,t){const n=this._listeners.get(e);return!!Array.isArray(n)&&(n.forEach((e=>{e(t)})),!0)}has(e){if(this._listeners.has(e)){const t=this._listeners.get(e);if(Array.isArray(t)&&t.length>0)return!0}return!1}}function p(e,t,n,o){const i=function(e){return e/180*Math.PI}(t||0);n&&(i>0||i<0)&&(e.translate(n.x,n.y),e.rotate(i),e.translate(-n.x,-n.y)),o(e),n&&(i>0||i<0)&&(e.translate(n.x,n.y),e.rotate(-i),e.translate(-n.x,-n.y))}function x(e,t,n){const o={x:(i=t).x+i.w/2,y:i.y+i.h/2};var i;p(e,t.angle||0,o,(()=>{n(e)}))}function S(e){let t="";return e.forEach((e=>{t+=e.type+e.params.join(" ")})),t}const b={boxSizing:"center-line",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,lineHeight:20,fontFamily:"sans-serif",fontWeight:400};function I(e,t){const{viewScaleInfo:n}=t,{scale:o}=n;let{borderRadius:i,boxSizing:l=b.boxSizing,borderWidth:r}=e.detail;"number"!=typeof r&&(i=0);let{x:a,y:s,w:c,h:d}=e,h=[0,0,0,0];if("number"==typeof i){const e=i*o;h=[e,e,e,e]}else Array.isArray(i)&&4===(null==i?void 0:i.length)&&(h=[i[0]*o,i[1]*o,i[2]*o,i[3]*o]);let u=0;return"number"==typeof r&&(u=(r||1)*o),"border-box"===l?(a=e.x+u/2,s=e.y+u/2,c=e.w-u,d=e.h-u):"content-box"===l?(a=e.x-u/2,s=e.y-u/2,c=e.w+u,d=e.h+u):(a=e.x,s=e.y,c=e.w,d=e.h),{x:a,y:s,w:c,h:d,radiusList:h}}function z(e,t,o){if("string"==typeof t)return t;const{viewElementSize:i,viewScaleInfo:l,opacity:r=1}=o,{x:a,y:s}=i,{scale:c}=l;if("linear-gradient"===(null==t?void 0:t.type)){const{start:o,end:i,stops:l}=t,d={x:a+o.x*c,y:s+o.y*c},h={x:a+i.x*c,y:s+i.y*c},u=e.createLinearGradient(d.x,d.y,h.x,h.y);return l.forEach((e=>{u.addColorStop(e.offset,n(e.color,r))})),u}if("radial-gradient"===(null==t?void 0:t.type)){const{inner:o,outer:i,stops:l}=t,d={x:a+o.x*c,y:s+o.y*c,radius:o.radius*c},h={x:a+i.x*c,y:s+i.y*c,radius:i.radius*c},u=e.createRadialGradient(d.x,d.y,d.radius,h.x,h.y,h.radius);return l.forEach((e=>{u.addColorStop(e.offset,n(e.color,r))})),u}return"#000000"}const A={boxSizing:"center-line",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,lineHeight:20,fontFamily:"sans-serif",fontWeight:400};function T(e,n,o){const{pattern:i,renderContent:l,originElem:r,calcElemSize:s,viewScaleInfo:c,viewSizeInfo:d}=o||{};!function(e,t,n){const{renderContent:o,originElem:i,calcElemSize:l,viewScaleInfo:r,viewSizeInfo:a}=n,s=r.scale*a.devicePixelRatio,{clipPath:c}=(null==i?void 0:i.detail)||{};if(c&&l&&c.commands){const{x:n,y:i,w:r,h:a}=l,{originW:d,originH:h,originX:u,originY:f}=c,g=r/d,w=a/h;let v=n-u*g,y=i-f*w;e.save(),e.translate(v,y),e.scale(s*g,s*w);const m=S(c.commands||[]),p=new Path2D(m);e.clip(p),e.translate(0-v,0-y),e.setTransform(1,0,0,1,0,0),x(e,{...t},(()=>{null==o||o()})),e.restore()}else null==o||o()}(e,n,{originElem:r,calcElemSize:s,viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{var o,r;void 0!==(null==(o=null==n?void 0:n.detail)?void 0:o.opacity)&&(null==(r=null==n?void 0:n.detail)?void 0:r.opacity)>=0?e.globalAlpha=n.detail.opacity:e.globalAlpha=1,function(e,t,n){var o,i;const{pattern:l,viewScaleInfo:r,viewSizeInfo:s}=n;let c=[];if(t.detail,t.detail.background||l){const{x:n,y:d,w:h,h:u,radiusList:f}=I(t,{viewScaleInfo:r,viewSizeInfo:s});if(e.beginPath(),e.moveTo(n+f[0],d),e.arcTo(n+h,d,n+h,d+u,f[1]),e.arcTo(n+h,d+u,n,d+u,f[2]),e.arcTo(n,d+u,n,d,f[3]),e.arcTo(n,d,n+h,d,f[0]),e.closePath(),"string"==typeof l)e.fillStyle=l;else if(["CanvasPattern"].includes(a.type(l)))e.fillStyle=l;else if("string"==typeof t.detail.background)e.fillStyle=t.detail.background;else if("linear-gradient"===(null==(o=t.detail.background)?void 0:o.type)){const o=z(e,t.detail.background,{viewElementSize:{x:n,y:d,w:h,h:u},viewScaleInfo:r,opacity:e.globalAlpha});e.fillStyle=o}else if("radial-gradient"===(null==(i=t.detail.background)?void 0:i.type)){const o=z(e,t.detail.background,{viewElementSize:{x:n,y:d,w:h,h:u},viewScaleInfo:r,opacity:e.globalAlpha});if(e.fillStyle=o,c&&c.length>0)for(let t=0;t<(null==c?void 0:c.length);t++){const o=c[t];"translate"===o.method?e.translate(o.args[0]+n,o.args[1]+d):"rotate"===o.method?e.rotate(...o.args):"scale"===o.method&&e.scale(...o.args)}}e.fill(),c&&c.length>0&&e.setTransform(1,0,0,1,0,0)}}(e,n,{pattern:i,viewScaleInfo:c,viewSizeInfo:d}),null==l||l(),function(e,n,o){var i,l;if(0===n.detail.borderWidth)return;if(!t(n.detail.borderColor))return;void 0!==(null==(i=null==n?void 0:n.detail)?void 0:i.opacity)&&(null==(l=null==n?void 0:n.detail)?void 0:l.opacity)>=0?e.globalAlpha=n.detail.opacity:e.globalAlpha=1;const{viewScaleInfo:r}=o,{scale:a}=r;let s=A.borderColor;!0===t(n.detail.borderColor)&&(s=n.detail.borderColor);const{borderWidth:c,borderRadius:d,borderDash:h,boxSizing:u=A.boxSizing}=n.detail;let f=0;"number"==typeof c&&(f=c||1);f*=a;let g=[0,0,0,0];if("number"==typeof d){const e=d*a;g=[e,e,e,e]}else Array.isArray(d)&&4===(null==d?void 0:d.length)&&(g=[d[0]*a,d[1]*a,d[2]*a,d[3]*a]);e.strokeStyle=s;let w=[];Array.isArray(h)&&h.length>0&&(w=h.map((e=>Math.ceil(e*a))));let v=0,y=0,m=0,p=0;Array.isArray(c)&&(v=(c[0]||0)*a,y=(c[1]||0)*a,m=(c[2]||0)*a,p=(c[3]||0)*a);if(p||y||v||m){e.lineCap="butt";let{x:t,y:o,w:i,h:l}=n;"border-box"===u?(t+=p/2,o+=v/2,i=i-p/2-y/2,l=l-v/2-m/2):"content-box"===u?(t-=p/2,o-=v/2,i=i+p/2+y/2,l=l+v/2+m/2):(t=n.x,o=n.y,i=n.w,l=n.h),v&&(e.beginPath(),e.lineWidth=v,e.moveTo(t-p/2,o),e.lineTo(t+i+y/2,o),e.closePath(),e.stroke()),y&&(e.beginPath(),e.lineWidth=y,e.moveTo(t+i,o-v/2),e.lineTo(t+i,o+l+m/2),e.closePath(),e.stroke()),m&&(e.beginPath(),e.lineWidth=m,e.moveTo(t-p/2,o+l),e.lineTo(t+i+y/2,o+l),e.closePath(),e.stroke()),p&&(e.beginPath(),e.lineWidth=p,e.moveTo(t,o-v/2),e.lineTo(t,o+l+m/2),e.closePath(),e.stroke())}else{let{x:t,y:o,w:i,h:l}=n;"border-box"===u?(t=n.x+f/2,o=n.y+f/2,i=n.w-f,l=n.h-f):"content-box"===u?(t=n.x-f/2,o=n.y-f/2,i=n.w+f,l=n.h+f):(t=n.x,o=n.y,i=n.w,l=n.h),w.length>0?e.lineCap="butt":e.lineCap="square",e.setLineDash(w),e.lineWidth=f,e.beginPath(),e.moveTo(t+g[0],o),e.arcTo(t+i,o,t+i,o+l,g[1]),e.arcTo(t+i,o+l,t,o+l,g[2]),e.arcTo(t,o+l,t,o,g[3]),e.arcTo(t,o,t+i,o,g[0]),e.closePath(),e.stroke(),e.globalAlpha=1}e.setLineDash([])}(e,n,{viewScaleInfo:c,viewSizeInfo:d}),e.globalAlpha=1}})}function E(e,t,n){const{detail:o}=t,{viewScaleInfo:i,renderContent:l}=n,{shadowColor:r,shadowOffsetX:a,shadowOffsetY:s,shadowBlur:c}=o;y.number(c)?(e.save(),e.shadowColor=r||A.shadowColor,e.shadowOffsetX=(a||0)*i.scale,e.shadowOffsetY=(s||0)*i.scale,e.shadowBlur=(c||0)*i.scale,l(),e.restore()):l()}const C={boxSizing:"center-line",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,lineHeight:20,fontFamily:"sans-serif",fontWeight:400};function _(e,n,o){var i;if(!0!==(null==(i=null==n?void 0:n.operations)?void 0:i.invisible))try{switch(n.type){case"rect":!function(e,t,n){const{calculator:o,viewScaleInfo:i,viewSizeInfo:l}=n;let{x:r,y:a,w:s,h:c,angle:d}=o.elementSize(t,i,l);const h={...t,x:r,y:a,w:s,h:c,angle:d};x(e,{x:r,y:a,w:s,h:c,angle:d},(()=>{E(e,h,{viewScaleInfo:i,viewSizeInfo:l,renderContent:()=>{T(e,h,{originElem:t,calcElemSize:{x:r,y:a,w:s,h:c,angle:d},viewScaleInfo:i,viewSizeInfo:l,renderContent:()=>{}})}})}))}(e,n,o);break;case"circle":!function(e,t,n){const{detail:o,angle:i}=t,{background:l="#000000",borderColor:r="#000000",borderWidth:a=0}=o,{calculator:s,viewScaleInfo:c,viewSizeInfo:d}=n,{x:h,y:u,w:f,h:g}=s.elementSize({x:t.x,y:t.y,w:t.w,h:t.h},c,d),w={...t,x:h,y:u,w:f,h:g,angle:i};x(e,{x:h,y:u,w:f,h:g,angle:i},(()=>{E(e,w,{viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{var n,o;const i=f/2,s=g/2,d=h+i,w=u+s;if(void 0!==(null==(n=null==t?void 0:t.detail)?void 0:n.opacity)&&(null==(o=null==t?void 0:t.detail)?void 0:o.opacity)>=0?e.globalAlpha=t.detail.opacity:e.globalAlpha=1,"number"==typeof a&&a>0){const t=a/2+i,n=a/2+s;e.beginPath(),e.strokeStyle=r,e.lineWidth=a,e.circle(d,w,t,n,0,0,2*Math.PI),e.closePath(),e.stroke()}e.beginPath();const v=z(e,l,{viewElementSize:{x:h,y:u,w:f,h:g},viewScaleInfo:c,opacity:e.globalAlpha});e.fillStyle=v,e.circle(d,w,i,s,0,0,2*Math.PI),e.closePath(),e.fill(),e.globalAlpha=1}})}))}(e,n,o);break;case"text":!function(e,n,o){const{calculator:i,viewScaleInfo:l,viewSizeInfo:r}=o,{x:a,y:s,w:c,h:d,angle:h}=i.elementSize(n,l,r),u={...n,x:a,y:s,w:c,h:d,angle:h};x(e,{x:a,y:s,w:c,h:d,angle:h},(()=>{T(e,u,{originElem:n,calcElemSize:{x:a,y:s,w:c,h:d,angle:h},viewScaleInfo:l,viewSizeInfo:r,renderContent:()=>{const o={...C,...n.detail},i=(o.fontSize||C.fontSize)*l.scale,r=o.lineHeight?o.lineHeight*l.scale:i;e.fillStyle=n.detail.color||C.color,e.textBaseline="top",e.$setFont({fontWeight:o.fontWeight,fontSize:i,fontFamily:o.fontFamily});const h=o.text.replace(/\r\n/gi,"\n"),u=r,f=h.split("\n"),g=[];let w=0;f.forEach(((t,n)=>{let o="";if(t.length>0){for(let i=0;i<t.length&&(e.measureText(o+(t[i]||"")).width<e.$doPixelRatio(c)?o+=t[i]||"":(g.push({text:o,width:e.$undoPixelRatio(e.measureText(o).width)}),o=t[i]||"",w++),!((w+1)*u>d));i++)if(t.length-1===i&&(w+1)*u<d){g.push({text:o,width:e.$undoPixelRatio(e.measureText(o).width)}),n<f.length-1&&w++;break}}else g.push({text:"",width:0})}));let v=0;g.length*u<d&&("top"===n.detail.verticalAlign?v=0:"bottom"===n.detail.verticalAlign?v+=d-g.length*u:v+=(d-g.length*u)/2);{const n=s+v;void 0!==o.textShadowColor&&t(o.textShadowColor)&&(e.shadowColor=o.textShadowColor),void 0!==o.textShadowOffsetX&&y.number(o.textShadowOffsetX)&&(e.shadowOffsetX=o.textShadowOffsetX),void 0!==o.textShadowOffsetY&&y.number(o.textShadowOffsetY)&&(e.shadowOffsetY=o.textShadowOffsetY),void 0!==o.textShadowBlur&&y.number(o.textShadowBlur)&&(e.shadowBlur=o.textShadowBlur),g.forEach(((t,i)=>{let l=a;"center"===o.textAlign?l=a+(c-t.width)/2:"right"===o.textAlign&&(l=a+(c-t.width)),e.fillText(t.text,l,n+u*i)}))}}})}))}(e,n,o);break;case"image":!function(e,t,n){const o=n.loader.getContent(t),{calculator:i,viewScaleInfo:l,viewSizeInfo:r}=n,{x:a,y:s,w:c,h:d,angle:h}=i.elementSize(t,l,r),u={...t,x:a,y:s,w:c,h:d,angle:h};x(e,{x:a,y:s,w:c,h:d,angle:h},(()=>{E(e,u,{viewScaleInfo:l,viewSizeInfo:r,renderContent:()=>{T(e,u,{originElem:t,calcElemSize:{x:a,y:s,w:c,h:d,angle:h},viewScaleInfo:l,viewSizeInfo:r,renderContent:()=>{if(o||n.loader.load(t,n.elementAssets||{}),"image"===t.type&&o){const{opacity:n}=t.detail;e.globalAlpha=n||1;const{x:i,y:a,w:s,h:c,radiusList:d}=I(u,{viewScaleInfo:l,viewSizeInfo:r});e.save(),e.beginPath(),e.moveTo(i+d[0],a),e.arcTo(i+s,a,i+s,a+c,d[1]),e.arcTo(i+s,a+c,i,a+c,d[2]),e.arcTo(i,a+c,i,a,d[3]),e.arcTo(i,a,i+s,a,d[0]),e.closePath(),e.fill(),e.clip(),e.drawImage(o,i,a,s,c),e.globalAlpha=1,e.restore()}}})}})}))}(e,n,o);break;case"svg":!function(e,t,n){const o=n.loader.getContent(t),{calculator:i,viewScaleInfo:l,viewSizeInfo:r}=n,{x:a,y:s,w:c,h:d,angle:h}=i.elementSize(t,l,r);x(e,{x:a,y:s,w:c,h:d,angle:h},(()=>{if(o||n.loader.load(t,n.elementAssets||{}),"svg"===t.type&&o){const{opacity:n}=t.detail;e.globalAlpha=n||1,e.drawImage(o,a,s,c,d),e.globalAlpha=1}}))}(e,n,o);break;case"html":!function(e,t,n){const o=n.loader.getContent(t),{calculator:i,viewScaleInfo:l,viewSizeInfo:r}=n,{x:a,y:s,w:c,h:d,angle:h}=i.elementSize(t,l,r);x(e,{x:a,y:s,w:c,h:d,angle:h},(()=>{if(o||n.loader.load(t,n.elementAssets||{}),"html"===t.type&&o){const{opacity:n}=t.detail;e.globalAlpha=n||1,e.drawImage(o,a,s,c,d),e.globalAlpha=1}}))}(e,n,o);break;case"path":!function(e,t,n){const{detail:o}=t,{originX:i,originY:l,originW:r,originH:a}=o,{calculator:s,viewScaleInfo:c,viewSizeInfo:d}=n,{x:h,y:u,w:f,h:g,angle:w}=s.elementSize(t,c,d),v=f/r,y=g/a,m=h-i*v,p=u-l*y,b=c.scale*d.devicePixelRatio,I={...t,x:h,y:u,w:f,h:g,angle:w};x(e,{x:h,y:u,w:f,h:g,angle:w},(()=>{T(e,I,{originElem:t,calcElemSize:{x:h,y:u,w:f,h:g,angle:w},viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{E(e,I,{viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{e.save(),e.translate(m,p),e.scale(b*v/c.scale,b*y/c.scale);const t=S(o.commands||[]),n=new Path2D(t);o.fill&&(e.fillStyle=o.fill,e.fill(n)),o.stroke&&0!==o.strokeWidth&&(e.strokeStyle=o.stroke,e.lineWidth=(o.strokeWidth||1)/d.devicePixelRatio,e.lineCap=o.strokeLineCap||"square",e.stroke(n)),e.translate(-m,-p),e.restore()}})}})}))}(e,n,o);break;case"group":!function(e,t,n){const{calculator:o,viewScaleInfo:i,viewSizeInfo:l}=n,{x:r,y:a,w:s,h:c,angle:d}=o.elementSize({x:t.x,y:t.y,w:t.w,h:t.h,angle:t.angle},i,l),h={...t,x:r,y:a,w:s,h:c,angle:d};x(e,{x:r,y:a,w:s,h:c,angle:d},(()=>{T(e,h,{originElem:t,calcElemSize:{x:r,y:a,w:s,h:c,angle:d},viewScaleInfo:i,viewSizeInfo:l,renderContent:()=>{if(Array.isArray(t.detail.children)){const{parentElementSize:o}=n,i={x:o.x+t.x,y:o.y+t.y,w:t.w||o.w,h:t.h||o.h,angle:t.angle},{calculator:l}=n;"hidden"===t.detail.overflow&&(e.save(),e.beginPath(),e.moveTo(r,a),e.lineTo(r+s,a),e.lineTo(r+s,a+c),e.lineTo(r,a+c),e.closePath(),e.clip());for(let o=0;o<t.detail.children.length;o++){let r=t.detail.children[o];if(r={...r,x:i.x+r.x,y:i.y+r.y},l.isElementInView(r,n.viewScaleInfo,n.viewSizeInfo))try{_(e,r,{...n})}catch(e){console.error(e)}}e.restore()}}})}))}(e,n,o)}}catch(e){console.error(e)}}const $={boxSizing:"center-line",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,lineHeight:20,fontFamily:"sans-serif",fontWeight:400};const P=["image","svg","html"],L=e=>{var t,n,i;let r=null;return"image"===e.type?r=(null==(t=null==e?void 0:e.detail)?void 0:t.src)||null:"svg"===e.type?r=(null==(n=null==e?void 0:e.detail)?void 0:n.svg)||null:"html"===e.type&&(r=(null==(i=null==e?void 0:e.detail)?void 0:i.html)||null),"string"==typeof r&&r?/^@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(`${r}`)?r:l(r):l(`${o()}-${e.uuid}-${o()}-${o()}`)};class k extends m{constructor(){super(),this._loadFuncMap={},this._currentLoadItemMap={},this._storageLoadItemMap={},this._registerLoadFunc("image",(async(e,t)=>{var n;const o=(null==(n=t[e.detail.src])?void 0:n.value)||e.detail.src,i=await d(o);return{uuid:e.uuid,lastModified:Date.now(),content:i}})),this._registerLoadFunc("html",(async(e,t)=>{var n;const o=(null==(n=t[e.detail.html])?void 0:n.value)||e.detail.html,i=await u(o,{width:e.detail.width||e.w,height:e.detail.height||e.h});return{uuid:e.uuid,lastModified:Date.now(),content:i}})),this._registerLoadFunc("svg",(async(e,t)=>{var n;const o=(null==(n=t[e.detail.svg])?void 0:n.value)||e.detail.svg,i=await h(o);return{uuid:e.uuid,lastModified:Date.now(),content:i}}))}_registerLoadFunc(e,t){this._loadFuncMap[e]=t}_getLoadElementSource(e){var t,n,o;let i=null;return"image"===e.type?i=(null==(t=null==e?void 0:e.detail)?void 0:t.src)||null:"svg"===e.type?i=(null==(n=null==e?void 0:e.detail)?void 0:n.svg)||null:"html"===e.type&&(i=(null==(o=null==e?void 0:e.detail)?void 0:o.html)||null),i}_createLoadItem(e){return{element:e,status:"null",content:null,error:null,startTime:-1,endTime:-1,source:this._getLoadElementSource(e)}}_emitLoad(e){const t=L(e.element),n=this._storageLoadItemMap[t];n?n.startTime<e.startTime&&(this._storageLoadItemMap[t]=e,this.trigger("load",{...e,countTime:e.endTime-e.startTime})):(this._storageLoadItemMap[t]=e,this.trigger("load",{...e,countTime:e.endTime-e.startTime}))}_emitError(e){const t=L(e.element),n=this._storageLoadItemMap[t];n?n.startTime<e.startTime&&(this._storageLoadItemMap[t]=e,this.trigger("error",{...e,countTime:e.endTime-e.startTime})):(this._storageLoadItemMap[t]=e,this.trigger("error",{...e,countTime:e.endTime-e.startTime}))}_loadResource(e,t){const n=this._createLoadItem(e),o=L(e);this._currentLoadItemMap[o]=n;const i=this._loadFuncMap[e.type];"function"==typeof i&&(n.startTime=Date.now(),i(e,t).then((e=>{n.content=e.content,n.endTime=Date.now(),n.status="load",this._emitLoad(n)})).catch((t=>{console.warn(`Load element source "${n.source}" fail`,t,e),n.endTime=Date.now(),n.status="error",n.error=t,this._emitError(n)})))}_isExistingErrorStorage(e){var t;const n=L(e),o=null==(t=this._currentLoadItemMap)?void 0:t[n];return!(!o||"error"!==o.status||!o.source||o.source!==this._getLoadElementSource(e))}load(e,t){this._isExistingErrorStorage(e)||P.includes(e.type)&&this._loadResource(e,t)}getContent(e){var t,n;const o=L(e);return(null==(n=null==(t=this._storageLoadItemMap)?void 0:t[o])?void 0:n.content)||null}}return e.Renderer=class extends m{constructor(e){super(),this._loader=new k,this._opts=e,this._init()}_init(){const{_loader:e}=this;e.on("load",(e=>{this.trigger("load",e)})),e.on("error",(()=>{}))}updateOptions(e){this._opts=e}drawData(e,t){const{_loader:n}=this,{calculator:o}=this._opts,{viewContext:i}=this._opts.viewContent;i.clearRect(0,0,i.canvas.width,i.canvas.height);!function(e,t,n){const{elements:o=[]}=t;for(let t=0;t<o.length;t++){const i=o[t],l={...i,detail:{...$,...null==i?void 0:i.detail}};if(n.calculator.isElementInView(l,n.viewScaleInfo,n.viewSizeInfo))try{_(e,l,n)}catch(e){console.error(e)}}}(i,e,{loader:n,calculator:o,parentElementSize:{x:0,y:0,w:t.viewSizeInfo.width,h:t.viewSizeInfo.height},elementAssets:e.assets,...t})}scale(e){const{sharer:t}=this._opts,{data:n,offsetTop:o,offsetBottom:i,offsetLeft:l,offsetRight:r,width:a,height:s,contextHeight:c,contextWidth:d,devicePixelRatio:h}=t.getActiveStoreSnapshot();n&&this.drawData(n,{viewScaleInfo:{scale:e,offsetTop:o,offsetBottom:i,offsetLeft:l,offsetRight:r},viewSizeInfo:{width:a,height:s,contextHeight:c,contextWidth:d,devicePixelRatio:h}})}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});
|
|
1
|
+
var iDrawRenderer=function(e){"use strict";function t(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 n(e,t){if(1===t)return e;let n=1;const o=/^\#[0-9a-f]{6,6}$/i;let i=e;if(o.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")),i=e.substring(0,7)),n*=t,o.test(i)&&n>0&&n<1){const e=Math.max(0,Math.min(255,Math.ceil(256*n)));i=`${i.toUpperCase()}${e.toString(16).toUpperCase()}`}return i}function o(){function e(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${e()}${e()}-${e()}-${e()}-${e()}-${e()}${e()}${e()}`}function i(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 a(e){const t=e.length,n=Math.floor(t/2),o=e.substring(0,4).padEnd(4,"0"),a=e.substring(0,4).padEnd(4,"0");return`@assets/${i(t.toString(16).padEnd(4,o))}${i(e.substring(n-4,n).padEnd(4,o)).padEnd(4,"f")}-${i(e.substring(n-8,n-4).padEnd(4,o)).padEnd(4,"f")}-${i(e.substring(n-12,n-8).padEnd(4,o)).padEnd(4,"f")}-${i(e.substring(n-16,n-12).padEnd(4,a)).padEnd(4,"f")}-${i(e.substring(n,n+4).padEnd(4,a)).padEnd(4,"f")}${i(e.substring(n+4,n+8).padEnd(4,a)).padEnd(4,"f")}${i(a.padEnd(4,o).padEnd(4,a))}`}function r(e){return(Object.prototype.toString.call(e)||"").replace(/(\[object|\])/gi,"").trim()}const l={type(e,t){const n=r(e);return!0===t?n.toLocaleLowerCase():n},array:e=>"Array"===r(e),json:e=>"Object"===r(e),function:e=>"Function"===r(e),asyncFunction:e=>"AsyncFunction"===r(e),string:e=>"String"===r(e),number:e=>"Number"===r(e),undefined:e=>"Undefined"===r(e),null:e=>"Null"===r(e),promise:e=>"Promise"===r(e)};var s=function(e,t,n,o){return new(n||(n=Promise))((function(i,a){function r(e){try{s(o.next(e))}catch(e){a(e)}}function l(e){try{s(o.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,l)}s((o=o.apply(e,t||[])).next())}))};const{Image:c}=window;function d(e){return new Promise(((t,n)=>{const o=new c;o.crossOrigin="anonymous",o.onload=function(){t(o)},o.onabort=n,o.onerror=n,o.src=e}))}function h(e){return s(this,void 0,void 0,(function*(){const t=yield function(e){return new Promise(((t,n)=>{const o=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),i=new FileReader;i.readAsDataURL(o),i.onload=function(e){var n;const o=null===(n=null==e?void 0:e.target)||void 0===n?void 0:n.result;t(o)},i.onerror=function(e){n(e)}}))}(e);return yield d(t)}))}function u(e,t){return s(this,void 0,void 0,(function*(){e=e.replace(/\&/gi,"&");const n=yield function(e,t){const{width:n,height:o}=t;return new Promise(((t,i)=>{const a=new Blob([`\n <svg \n xmlns="http://www.w3.org/2000/svg" \n width="${n||""}" \n height = "${o||""}">\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 o=null===(n=null==e?void 0:e.target)||void 0===n?void 0:n.result;t(o)},r.onerror=function(e){i(e)}}))}(e,t);return yield d(n)}))}function f(e){return"number"==typeof e&&(e>0||e<=0)}function g(e){return"number"==typeof e&&e>=0}function w(e){return"string"==typeof e&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${e}`)}function v(e){return"string"==typeof e&&/^(data:image\/)/.test(`${e}`)}const y={x:function(e){return f(e)},y:function(e){return f(e)},w:g,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 g(e)},borderRadius:function(e){return f(e)&&e>=0},color:function(e){return t(e)},imageSrc:function(e){return v(e)||w(e)},imageURL:w,imageBase64:v,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}};class m{constructor(){this._listeners=new Map}on(e,t){if(this._listeners.has(e)){const n=this._listeners.get(e)||[];null==n||n.push(t),this._listeners.set(e,n)}else this._listeners.set(e,[t])}off(e,t){if(this._listeners.has(e)){const n=this._listeners.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}this._listeners.set(e,n||[])}}trigger(e,t){const n=this._listeners.get(e);return!!Array.isArray(n)&&(n.forEach((e=>{e(t)})),!0)}has(e){if(this._listeners.has(e)){const t=this._listeners.get(e);if(Array.isArray(t)&&t.length>0)return!0}return!1}}function p(e,t,n,o){const i=function(e){return e/180*Math.PI}(t||0);n&&(i>0||i<0)&&(e.translate(n.x,n.y),e.rotate(i),e.translate(-n.x,-n.y)),o(e),n&&(i>0||i<0)&&(e.translate(n.x,n.y),e.rotate(-i),e.translate(-n.x,-n.y))}function x(e,t,n){const o={x:(i=t).x+i.w/2,y:i.y+i.h/2};var i;p(e,t.angle||0,o,(()=>{n(e)}))}function S(e){let t="";return e.forEach((e=>{t+=e.type+e.params.join(" ")})),t}const b={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,lineHeight:20,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function I(e,t){const{viewScaleInfo:n}=t,{scale:o}=n;let{borderRadius:i,boxSizing:a=b.boxSizing,borderWidth:r}=e.detail;"number"!=typeof r&&(i=0);let{x:l,y:s,w:c,h:d}=e,h=[0,0,0,0];if("number"==typeof i){const e=i*o;h=[e,e,e,e]}else Array.isArray(i)&&4===(null==i?void 0:i.length)&&(h=[i[0]*o,i[1]*o,i[2]*o,i[3]*o]);let u=0;return"number"==typeof r&&(u=(r||0)*o),"border-box"===a?(l=e.x+u/2,s=e.y+u/2,c=e.w-u,d=e.h-u):"content-box"===a?(l=e.x-u/2,s=e.y-u/2,c=e.w+u,d=e.h+u):(l=e.x,s=e.y,c=e.w,d=e.h),c=Math.max(c,1),d=Math.max(d,1),h=h.map((e=>Math.min(e,c/2,d/2))),{x:l,y:s,w:c,h:d,radiusList:h}}function z(e,t,o){if("string"==typeof t)return t;const{viewElementSize:i,viewScaleInfo:a,opacity:r=1}=o,{x:l,y:s}=i,{scale:c}=a;if("linear-gradient"===(null==t?void 0:t.type)){const{start:o,end:i,stops:a}=t,d={x:l+o.x*c,y:s+o.y*c},h={x:l+i.x*c,y:s+i.y*c},u=e.createLinearGradient(d.x,d.y,h.x,h.y);return a.forEach((e=>{u.addColorStop(e.offset,n(e.color,r))})),u}if("radial-gradient"===(null==t?void 0:t.type)){const{inner:o,outer:i,stops:a}=t,d={x:l+o.x*c,y:s+o.y*c,radius:o.radius*c},h={x:l+i.x*c,y:s+i.y*c,radius:i.radius*c},u=e.createRadialGradient(d.x,d.y,d.radius,h.x,h.y,h.radius);return a.forEach((e=>{u.addColorStop(e.offset,n(e.color,r))})),u}return"#000000"}const A={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,lineHeight:20,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function T(e,n,o){const{pattern:i,renderContent:a,originElem:r,calcElemSize:s,viewScaleInfo:c,viewSizeInfo:d}=o||{};!function(e,t,n){const{renderContent:o,originElem:i,calcElemSize:a,viewScaleInfo:r,viewSizeInfo:l}=n,s=r.scale*l.devicePixelRatio,{clipPath:c}=(null==i?void 0:i.detail)||{};if(c&&a&&c.commands){const{x:n,y:i,w:r,h:l}=a,{originW:d,originH:h,originX:u,originY:f}=c,g=r/d,w=l/h;let v=n-u*g,y=i-f*w;e.save(),e.translate(v,y),e.scale(s*g,s*w);const m=S(c.commands||[]),p=new Path2D(m);e.clip(p),e.translate(0-v,0-y),e.setTransform(1,0,0,1,0,0),x(e,{...t},(()=>{null==o||o()})),e.restore()}else null==o||o()}(e,n,{originElem:r,calcElemSize:s,viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{var o,r;void 0!==(null==(o=null==n?void 0:n.detail)?void 0:o.opacity)&&(null==(r=null==n?void 0:n.detail)?void 0:r.opacity)>=0?e.globalAlpha=n.detail.opacity:e.globalAlpha=1,function(e,t,n){var o,i;const{pattern:a,viewScaleInfo:r,viewSizeInfo:s}=n;let c=[];if(t.detail,t.detail.background||a){const{x:n,y:d,w:h,h:u,radiusList:f}=I(t,{viewScaleInfo:r,viewSizeInfo:s});if(e.beginPath(),e.moveTo(n+f[0],d),e.arcTo(n+h,d,n+h,d+u,f[1]),e.arcTo(n+h,d+u,n,d+u,f[2]),e.arcTo(n,d+u,n,d,f[3]),e.arcTo(n,d,n+h,d,f[0]),e.closePath(),"string"==typeof a)e.fillStyle=a;else if(["CanvasPattern"].includes(l.type(a)))e.fillStyle=a;else if("string"==typeof t.detail.background)e.fillStyle=t.detail.background;else if("linear-gradient"===(null==(o=t.detail.background)?void 0:o.type)){const o=z(e,t.detail.background,{viewElementSize:{x:n,y:d,w:h,h:u},viewScaleInfo:r,opacity:e.globalAlpha});e.fillStyle=o}else if("radial-gradient"===(null==(i=t.detail.background)?void 0:i.type)){const o=z(e,t.detail.background,{viewElementSize:{x:n,y:d,w:h,h:u},viewScaleInfo:r,opacity:e.globalAlpha});if(e.fillStyle=o,c&&c.length>0)for(let t=0;t<(null==c?void 0:c.length);t++){const o=c[t];"translate"===o.method?e.translate(o.args[0]+n,o.args[1]+d):"rotate"===o.method?e.rotate(...o.args):"scale"===o.method&&e.scale(...o.args)}}e.fill(),c&&c.length>0&&e.setTransform(1,0,0,1,0,0)}}(e,n,{pattern:i,viewScaleInfo:c,viewSizeInfo:d}),null==a||a(),function(e,n,o){var i,a;if(0===n.detail.borderWidth)return;if(!t(n.detail.borderColor))return;void 0!==(null==(i=null==n?void 0:n.detail)?void 0:i.opacity)&&(null==(a=null==n?void 0:n.detail)?void 0:a.opacity)>=0?e.globalAlpha=n.detail.opacity:e.globalAlpha=1;const{viewScaleInfo:r}=o,{scale:l}=r;let s=A.borderColor;!0===t(n.detail.borderColor)&&(s=n.detail.borderColor);const{borderWidth:c,borderRadius:d,borderDash:h,boxSizing:u=A.boxSizing}=n.detail;let f=0;"number"==typeof c&&(f=c||1);f*=l;let g=[0,0,0,0];if("number"==typeof d){const e=d*l;g=[e,e,e,e]}else Array.isArray(d)&&4===(null==d?void 0:d.length)&&(g=[d[0]*l,d[1]*l,d[2]*l,d[3]*l]);e.strokeStyle=s;let w=[];Array.isArray(h)&&h.length>0&&(w=h.map((e=>Math.ceil(e*l))));let v=0,y=0,m=0,p=0;Array.isArray(c)&&(v=(c[0]||0)*l,y=(c[1]||0)*l,m=(c[2]||0)*l,p=(c[3]||0)*l);if(p||y||v||m){e.lineCap="butt";let{x:t,y:o,w:i,h:a}=n;"border-box"===u?(t+=p/2,o+=v/2,i=i-p/2-y/2,a=a-v/2-m/2):"content-box"===u?(t-=p/2,o-=v/2,i=i+p/2+y/2,a=a+v/2+m/2):(t=n.x,o=n.y,i=n.w,a=n.h),v&&(e.beginPath(),e.lineWidth=v,e.moveTo(t-p/2,o),e.lineTo(t+i+y/2,o),e.closePath(),e.stroke()),y&&(e.beginPath(),e.lineWidth=y,e.moveTo(t+i,o-v/2),e.lineTo(t+i,o+a+m/2),e.closePath(),e.stroke()),m&&(e.beginPath(),e.lineWidth=m,e.moveTo(t-p/2,o+a),e.lineTo(t+i+y/2,o+a),e.closePath(),e.stroke()),p&&(e.beginPath(),e.lineWidth=p,e.moveTo(t,o-v/2),e.lineTo(t,o+a+m/2),e.closePath(),e.stroke())}else{let{x:t,y:o,w:i,h:a}=n;"border-box"===u?(t=n.x+f/2,o=n.y+f/2,i=n.w-f,a=n.h-f):"content-box"===u?(t=n.x-f/2,o=n.y-f/2,i=n.w+f,a=n.h+f):(t=n.x,o=n.y,i=n.w,a=n.h),w.length>0?e.lineCap="butt":e.lineCap="square",i=Math.max(i,1),a=Math.max(a,1),g=g.map((e=>Math.min(e,i/2,a/2))),e.setLineDash(w),e.lineWidth=f,e.beginPath(),e.moveTo(t+g[0],o),e.arcTo(t+i,o,t+i,o+a,g[1]),e.arcTo(t+i,o+a,t,o+a,g[2]),e.arcTo(t,o+a,t,o,g[3]),e.arcTo(t,o,t+i,o,g[0]),e.closePath(),e.stroke(),e.globalAlpha=1}e.setLineDash([])}(e,n,{viewScaleInfo:c,viewSizeInfo:d}),e.globalAlpha=1}})}function E(e,t,n){const{detail:o}=t,{viewScaleInfo:i,renderContent:a}=n,{shadowColor:r,shadowOffsetX:l,shadowOffsetY:s,shadowBlur:c}=o;y.number(c)?(e.save(),e.shadowColor=r||A.shadowColor,e.shadowOffsetX=(l||0)*i.scale,e.shadowOffsetY=(s||0)*i.scale,e.shadowBlur=(c||0)*i.scale,a(),e.restore()):a()}const C={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,lineHeight:20,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};function _(e,n,o){var i;if(!0!==(null==(i=null==n?void 0:n.operations)?void 0:i.invisible))try{switch(n.type){case"rect":!function(e,t,n){const{calculator:o,viewScaleInfo:i,viewSizeInfo:a}=n;let{x:r,y:l,w:s,h:c,angle:d}=o.elementSize(t,i,a);const h={...t,x:r,y:l,w:s,h:c,angle:d};x(e,{x:r,y:l,w:s,h:c,angle:d},(()=>{E(e,h,{viewScaleInfo:i,viewSizeInfo:a,renderContent:()=>{T(e,h,{originElem:t,calcElemSize:{x:r,y:l,w:s,h:c,angle:d},viewScaleInfo:i,viewSizeInfo:a,renderContent:()=>{}})}})}))}(e,n,o);break;case"circle":!function(e,t,n){const{detail:o,angle:i}=t,{background:a="#000000",borderColor:r="#000000",borderWidth:l=0}=o,{calculator:s,viewScaleInfo:c,viewSizeInfo:d}=n,{x:h,y:u,w:f,h:g}=s.elementSize({x:t.x,y:t.y,w:t.w,h:t.h},c,d),w={...t,x:h,y:u,w:f,h:g,angle:i};x(e,{x:h,y:u,w:f,h:g,angle:i},(()=>{E(e,w,{viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{var n,o;const i=f/2,s=g/2,d=h+i,w=u+s;if(void 0!==(null==(n=null==t?void 0:t.detail)?void 0:n.opacity)&&(null==(o=null==t?void 0:t.detail)?void 0:o.opacity)>=0?e.globalAlpha=t.detail.opacity:e.globalAlpha=1,"number"==typeof l&&l>0){const t=l/2+i,n=l/2+s;e.beginPath(),e.strokeStyle=r,e.lineWidth=l,e.circle(d,w,t,n,0,0,2*Math.PI),e.closePath(),e.stroke()}e.beginPath();const v=z(e,a,{viewElementSize:{x:h,y:u,w:f,h:g},viewScaleInfo:c,opacity:e.globalAlpha});e.fillStyle=v,e.circle(d,w,i,s,0,0,2*Math.PI),e.closePath(),e.fill(),e.globalAlpha=1}})}))}(e,n,o);break;case"text":!function(e,n,o){const{calculator:i,viewScaleInfo:a,viewSizeInfo:r}=o,{x:l,y:s,w:c,h:d,angle:h}=i.elementSize(n,a,r),u={...n,x:l,y:s,w:c,h:d,angle:h};x(e,{x:l,y:s,w:c,h:d,angle:h},(()=>{T(e,u,{originElem:n,calcElemSize:{x:l,y:s,w:c,h:d,angle:h},viewScaleInfo:a,viewSizeInfo:r,renderContent:()=>{const o={...C,...n.detail},i=(o.fontSize||C.fontSize)*a.scale,r=o.lineHeight?o.lineHeight*a.scale:i;e.fillStyle=n.detail.color||C.color,e.textBaseline="top",e.$setFont({fontWeight:o.fontWeight,fontSize:i,fontFamily:o.fontFamily});const h=o.text.replace(/\r\n/gi,"\n"),u=r,f=h.split("\n"),g=[];let w=0;f.forEach(((t,n)=>{let o="";if(t.length>0){for(let i=0;i<t.length&&(e.measureText(o+(t[i]||"")).width<e.$doPixelRatio(c)?o+=t[i]||"":(g.push({text:o,width:e.$undoPixelRatio(e.measureText(o).width)}),o=t[i]||"",w++),!((w+1)*u>d));i++)if(t.length-1===i&&(w+1)*u<d){g.push({text:o,width:e.$undoPixelRatio(e.measureText(o).width)}),n<f.length-1&&w++;break}}else g.push({text:"",width:0})}));let v=0;g.length*u<d&&("top"===n.detail.verticalAlign?v=0:"bottom"===n.detail.verticalAlign?v+=d-g.length*u:v+=(d-g.length*u)/2);{const n=s+v;void 0!==o.textShadowColor&&t(o.textShadowColor)&&(e.shadowColor=o.textShadowColor),void 0!==o.textShadowOffsetX&&y.number(o.textShadowOffsetX)&&(e.shadowOffsetX=o.textShadowOffsetX),void 0!==o.textShadowOffsetY&&y.number(o.textShadowOffsetY)&&(e.shadowOffsetY=o.textShadowOffsetY),void 0!==o.textShadowBlur&&y.number(o.textShadowBlur)&&(e.shadowBlur=o.textShadowBlur),g.forEach(((t,i)=>{let a=l;"center"===o.textAlign?a=l+(c-t.width)/2:"right"===o.textAlign&&(a=l+(c-t.width)),e.fillText(t.text,a,n+u*i)}))}}})}))}(e,n,o);break;case"image":!function(e,t,n){const o=n.loader.getContent(t),{calculator:i,viewScaleInfo:a,viewSizeInfo:r}=n,{x:l,y:s,w:c,h:d,angle:h}=i.elementSize(t,a,r),u={...t,x:l,y:s,w:c,h:d,angle:h};x(e,{x:l,y:s,w:c,h:d,angle:h},(()=>{E(e,u,{viewScaleInfo:a,viewSizeInfo:r,renderContent:()=>{T(e,u,{originElem:t,calcElemSize:{x:l,y:s,w:c,h:d,angle:h},viewScaleInfo:a,viewSizeInfo:r,renderContent:()=>{if(o||n.loader.load(t,n.elementAssets||{}),"image"===t.type&&o){const{opacity:n}=t.detail;e.globalAlpha=n||1;const{x:i,y:l,w:s,h:c,radiusList:d}=I(u,{viewScaleInfo:a,viewSizeInfo:r});e.save(),e.fillStyle="transparent",e.beginPath(),e.moveTo(i+d[0],l),e.arcTo(i+s,l,i+s,l+c,d[1]),e.arcTo(i+s,l+c,i,l+c,d[2]),e.arcTo(i,l+c,i,l,d[3]),e.arcTo(i,l,i+s,l,d[0]),e.closePath(),e.fill(),e.clip(),e.drawImage(o,i,l,s,c),e.globalAlpha=1,e.restore()}}})}})}))}(e,n,o);break;case"svg":!function(e,t,n){const o=n.loader.getContent(t),{calculator:i,viewScaleInfo:a,viewSizeInfo:r}=n,{x:l,y:s,w:c,h:d,angle:h}=i.elementSize(t,a,r);x(e,{x:l,y:s,w:c,h:d,angle:h},(()=>{if(o||n.loader.load(t,n.elementAssets||{}),"svg"===t.type&&o){const{opacity:n}=t.detail;e.globalAlpha=n||1,e.drawImage(o,l,s,c,d),e.globalAlpha=1}}))}(e,n,o);break;case"html":!function(e,t,n){const o=n.loader.getContent(t),{calculator:i,viewScaleInfo:a,viewSizeInfo:r}=n,{x:l,y:s,w:c,h:d,angle:h}=i.elementSize(t,a,r);x(e,{x:l,y:s,w:c,h:d,angle:h},(()=>{if(o||n.loader.load(t,n.elementAssets||{}),"html"===t.type&&o){const{opacity:n}=t.detail;e.globalAlpha=n||1,e.drawImage(o,l,s,c,d),e.globalAlpha=1}}))}(e,n,o);break;case"path":!function(e,t,n){const{detail:o}=t,{originX:i,originY:a,originW:r,originH:l}=o,{calculator:s,viewScaleInfo:c,viewSizeInfo:d}=n,{x:h,y:u,w:f,h:g,angle:w}=s.elementSize(t,c,d),v=f/r,y=g/l,m=h-i*v,p=u-a*y,b=c.scale*d.devicePixelRatio,I={...t,x:h,y:u,w:f,h:g,angle:w};x(e,{x:h,y:u,w:f,h:g,angle:w},(()=>{T(e,I,{originElem:t,calcElemSize:{x:h,y:u,w:f,h:g,angle:w},viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{E(e,I,{viewScaleInfo:c,viewSizeInfo:d,renderContent:()=>{e.save(),e.translate(m,p),e.scale(b*v/c.scale,b*y/c.scale);const t=S(o.commands||[]),n=new Path2D(t);o.fill&&(e.fillStyle=o.fill,e.fill(n)),o.stroke&&0!==o.strokeWidth&&(e.strokeStyle=o.stroke,e.lineWidth=(o.strokeWidth||1)/d.devicePixelRatio,e.lineCap=o.strokeLineCap||"square",e.stroke(n)),e.translate(-m,-p),e.restore()}})}})}))}(e,n,o);break;case"group":{const t={...o.elementAssets||{},...n.detail.assets||{}};!function(e,t,n){const{calculator:o,viewScaleInfo:i,viewSizeInfo:a}=n,{x:r,y:l,w:s,h:c,angle:d}=o.elementSize({x:t.x,y:t.y,w:t.w,h:t.h,angle:t.angle},i,a),h={...t,x:r,y:l,w:s,h:c,angle:d};x(e,{x:r,y:l,w:s,h:c,angle:d},(()=>{E(e,h,{viewScaleInfo:i,viewSizeInfo:a,renderContent:()=>{T(e,h,{originElem:t,calcElemSize:{x:r,y:l,w:s,h:c,angle:d},viewScaleInfo:i,viewSizeInfo:a,renderContent:()=>{const{x:o,y:r,w:l,h:s,radiusList:c}=I(h,{viewScaleInfo:i,viewSizeInfo:a});if("hidden"===t.detail.overflow&&(e.save(),e.fillStyle="transparent",e.beginPath(),e.moveTo(o+c[0],r),e.arcTo(o+l,r,o+l,r+s,c[1]),e.arcTo(o+l,r+s,o,r+s,c[2]),e.arcTo(o,r+s,o,r,c[3]),e.arcTo(o,r,o+l,r,c[0]),e.closePath(),e.fill(),e.clip()),Array.isArray(t.detail.children)){const{parentElementSize:o}=n,i={x:o.x+t.x,y:o.y+t.y,w:t.w||o.w,h:t.h||o.h,angle:t.angle},{calculator:a}=n;for(let o=0;o<t.detail.children.length;o++){let r=t.detail.children[o];if(r={...r,x:i.x+r.x,y:i.y+r.y},a.isElementInView(r,n.viewScaleInfo,n.viewSizeInfo))try{_(e,r,{...n})}catch(e){console.error(e)}}}"hidden"===t.detail.overflow&&(e.globalAlpha=1,e.restore())}})}})}))}(e,n,{...o,elementAssets:t});break}}}catch(e){console.error(e)}}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,lineHeight:20,fontFamily:"sans-serif",fontWeight:400,overflow:"hidden"};const P=["image","svg","html"],L=e=>{var t,n,i;let r=null;return"image"===e.type?r=(null==(t=null==e?void 0:e.detail)?void 0:t.src)||null:"svg"===e.type?r=(null==(n=null==e?void 0:e.detail)?void 0:n.svg)||null:"html"===e.type&&(r=(null==(i=null==e?void 0:e.detail)?void 0:i.html)||null),"string"==typeof r&&r?/^@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(`${r}`)?r:a(r):a(`${o()}-${e.uuid}-${o()}-${o()}`)};class M extends m{constructor(){super(),this._loadFuncMap={},this._currentLoadItemMap={},this._storageLoadItemMap={},this._registerLoadFunc("image",(async(e,t)=>{var n;const o=(null==(n=t[e.detail.src])?void 0:n.value)||e.detail.src,i=await d(o);return{uuid:e.uuid,lastModified:Date.now(),content:i}})),this._registerLoadFunc("html",(async(e,t)=>{var n;const o=(null==(n=t[e.detail.html])?void 0:n.value)||e.detail.html,i=await u(o,{width:e.detail.width||e.w,height:e.detail.height||e.h});return{uuid:e.uuid,lastModified:Date.now(),content:i}})),this._registerLoadFunc("svg",(async(e,t)=>{var n;const o=(null==(n=t[e.detail.svg])?void 0:n.value)||e.detail.svg,i=await h(o);return{uuid:e.uuid,lastModified:Date.now(),content:i}}))}_registerLoadFunc(e,t){this._loadFuncMap[e]=t}_getLoadElementSource(e){var t,n,o;let i=null;return"image"===e.type?i=(null==(t=null==e?void 0:e.detail)?void 0:t.src)||null:"svg"===e.type?i=(null==(n=null==e?void 0:e.detail)?void 0:n.svg)||null:"html"===e.type&&(i=(null==(o=null==e?void 0:e.detail)?void 0:o.html)||null),i}_createLoadItem(e){return{element:e,status:"null",content:null,error:null,startTime:-1,endTime:-1,source:this._getLoadElementSource(e)}}_emitLoad(e){const t=L(e.element),n=this._storageLoadItemMap[t];n?n.startTime<e.startTime&&(this._storageLoadItemMap[t]=e,this.trigger("load",{...e,countTime:e.endTime-e.startTime})):(this._storageLoadItemMap[t]=e,this.trigger("load",{...e,countTime:e.endTime-e.startTime}))}_emitError(e){const t=L(e.element),n=this._storageLoadItemMap[t];n?n.startTime<e.startTime&&(this._storageLoadItemMap[t]=e,this.trigger("error",{...e,countTime:e.endTime-e.startTime})):(this._storageLoadItemMap[t]=e,this.trigger("error",{...e,countTime:e.endTime-e.startTime}))}_loadResource(e,t){const n=this._createLoadItem(e),o=L(e);this._currentLoadItemMap[o]=n;const i=this._loadFuncMap[e.type];"function"==typeof i&&(n.startTime=Date.now(),i(e,t).then((e=>{n.content=e.content,n.endTime=Date.now(),n.status="load",this._emitLoad(n)})).catch((t=>{console.warn(`Load element source "${n.source}" fail`,t,e),n.endTime=Date.now(),n.status="error",n.error=t,this._emitError(n)})))}_isExistingErrorStorage(e){var t;const n=L(e),o=null==(t=this._currentLoadItemMap)?void 0:t[n];return!(!o||"error"!==o.status||!o.source||o.source!==this._getLoadElementSource(e))}load(e,t){this._isExistingErrorStorage(e)||P.includes(e.type)&&this._loadResource(e,t)}getContent(e){var t,n;const o=L(e);return(null==(n=null==(t=this._storageLoadItemMap)?void 0:t[o])?void 0:n.content)||null}}return e.Renderer=class extends m{constructor(e){super(),this._loader=new M,this._opts=e,this._init()}_init(){const{_loader:e}=this;e.on("load",(e=>{this.trigger("load",e)})),e.on("error",(()=>{}))}updateOptions(e){this._opts=e}drawData(e,t){const{_loader:n}=this,{calculator:o}=this._opts,{viewContext:i}=this._opts.viewContent;i.clearRect(0,0,i.canvas.width,i.canvas.height);!function(e,t,n){const{elements:o=[]}=t;for(let t=0;t<o.length;t++){const i=o[t],a={...i,detail:{...$,...null==i?void 0:i.detail}};if(n.calculator.isElementInView(a,n.viewScaleInfo,n.viewSizeInfo))try{_(e,a,n)}catch(e){console.error(e)}}}(i,e,{loader:n,calculator:o,parentElementSize:{x:0,y:0,w:t.viewSizeInfo.width,h:t.viewSizeInfo.height},elementAssets:e.assets,...t})}scale(e){const{sharer:t}=this._opts,{data:n,offsetTop:o,offsetBottom:i,offsetLeft:a,offsetRight:r,width:l,height:s,contextHeight:c,contextWidth:d,devicePixelRatio:h}=t.getActiveStoreSnapshot();n&&this.drawData(n,{viewScaleInfo:{scale:e,offsetTop:o,offsetBottom:i,offsetLeft:a,offsetRight:r},viewSizeInfo:{width:l,height:s,contextHeight:c,contextWidth:d,devicePixelRatio:h}})}},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-alpha.
|
|
3
|
+
"version": "0.4.0-alpha.7",
|
|
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-alpha.
|
|
24
|
+
"@idraw/types": "^0.4.0-alpha.7"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@idraw/util": "^0.4.0-alpha.
|
|
28
|
+
"@idraw/util": "^0.4.0-alpha.7"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public",
|