@idraw/core 0.4.0-alpha.3 → 0.4.0-alpha.5
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/index.d.ts +5 -6
- package/dist/esm/index.js +38 -16
- package/dist/esm/middleware/ruler/index.d.ts +3 -0
- package/dist/esm/middleware/ruler/index.js +44 -0
- package/dist/esm/middleware/ruler/util.d.ts +33 -0
- package/dist/esm/middleware/ruler/util.js +187 -0
- package/dist/esm/middleware/scaler/index.d.ts +3 -2
- package/dist/esm/middleware/scaler/index.js +10 -1
- package/dist/esm/middleware/scroller/util.js +63 -56
- package/dist/esm/middleware/selector/draw-wrapper.js +0 -4
- package/dist/esm/middleware/selector/index.d.ts +1 -0
- package/dist/esm/middleware/selector/index.js +12 -3
- package/dist/esm/middleware/text-editor/index.d.ts +3 -0
- package/dist/esm/middleware/text-editor/index.js +132 -0
- package/dist/index.global.js +975 -272
- package/dist/index.global.min.js +1 -1
- package/package.json +8 -7
package/dist/index.global.js
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
var iDrawCore = function(exports) {
|
|
2
|
-
"use strict";
|
|
2
|
+
"use strict";var __accessCheck = (obj, member, msg) => {
|
|
3
|
+
if (!member.has(obj))
|
|
4
|
+
throw TypeError("Cannot " + msg);
|
|
5
|
+
};
|
|
6
|
+
var __privateGet = (obj, member, getter) => {
|
|
7
|
+
__accessCheck(obj, member, "read from private field");
|
|
8
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
9
|
+
};
|
|
10
|
+
var __privateAdd = (obj, member, value) => {
|
|
11
|
+
if (member.has(obj))
|
|
12
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
13
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
14
|
+
};
|
|
15
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
16
|
+
__accessCheck(obj, member, "write to private field");
|
|
17
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
18
|
+
return value;
|
|
19
|
+
};
|
|
20
|
+
var __privateMethod = (obj, member, method) => {
|
|
21
|
+
__accessCheck(obj, member, "access private method");
|
|
22
|
+
return method;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
var _board, _container, _initContainer, initContainer_fn;
|
|
3
26
|
function throttle(fn, timeout) {
|
|
4
27
|
let timer = -1;
|
|
5
28
|
return function(...args) {
|
|
@@ -15,12 +38,58 @@ var iDrawCore = function(exports) {
|
|
|
15
38
|
function isColorStr(color2) {
|
|
16
39
|
return typeof color2 === "string" && (/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color2) || /^[a-z]{1,}$/i.test(color2));
|
|
17
40
|
}
|
|
41
|
+
function mergeHexColorAlpha(hex, alpha) {
|
|
42
|
+
if (alpha === 1) {
|
|
43
|
+
return hex;
|
|
44
|
+
}
|
|
45
|
+
let hexAlpha = 1;
|
|
46
|
+
const regHex1 = /^\#[0-9a-f]{6,6}$/i;
|
|
47
|
+
const regHex2 = /^\#[0-9a-f]{8,8}$/i;
|
|
48
|
+
let result = hex;
|
|
49
|
+
if (regHex1.test(hex)) {
|
|
50
|
+
hexAlpha = parseInt(hex.substring(5, 7).replace(/^\#/, "0x"));
|
|
51
|
+
} else if (regHex2.test(hex)) {
|
|
52
|
+
hexAlpha = parseInt(hex.substring(7, 9).replace(/^\#/, "0x"));
|
|
53
|
+
result = hex.substring(0, 7);
|
|
54
|
+
}
|
|
55
|
+
hexAlpha = hexAlpha * alpha;
|
|
56
|
+
if (regHex1.test(result) && hexAlpha > 0 && hexAlpha < 1) {
|
|
57
|
+
const aHexNum = Math.max(0, Math.min(255, Math.ceil(hexAlpha * 256)));
|
|
58
|
+
result = `${result.toUpperCase()}${aHexNum.toString(16).toUpperCase()}`;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
18
62
|
function createUUID() {
|
|
19
63
|
function _createStr() {
|
|
20
64
|
return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
|
|
21
65
|
}
|
|
22
66
|
return `${_createStr()}${_createStr()}-${_createStr()}-${_createStr()}-${_createStr()}-${_createStr()}${_createStr()}${_createStr()}`;
|
|
23
67
|
}
|
|
68
|
+
function limitHexStr(str) {
|
|
69
|
+
let count = 0;
|
|
70
|
+
for (let i = 0; i < str.length; i++) {
|
|
71
|
+
count += str.charCodeAt(i) * str.charCodeAt(i) * i * i;
|
|
72
|
+
}
|
|
73
|
+
return count.toString(16).substring(0, 4);
|
|
74
|
+
}
|
|
75
|
+
function createAssetId(assetStr) {
|
|
76
|
+
const len = assetStr.length;
|
|
77
|
+
const mid = Math.floor(len / 2);
|
|
78
|
+
const start4 = assetStr.substring(0, 4).padEnd(4, "0");
|
|
79
|
+
const end4 = assetStr.substring(0, 4).padEnd(4, "0");
|
|
80
|
+
const str1 = limitHexStr(len.toString(16).padEnd(4, start4));
|
|
81
|
+
const str2 = limitHexStr(assetStr.substring(mid - 4, mid).padEnd(4, start4)).padEnd(4, "f");
|
|
82
|
+
const str3 = limitHexStr(assetStr.substring(mid - 8, mid - 4).padEnd(4, start4)).padEnd(4, "f");
|
|
83
|
+
const str4 = limitHexStr(assetStr.substring(mid - 12, mid - 8).padEnd(4, start4)).padEnd(4, "f");
|
|
84
|
+
const str5 = limitHexStr(assetStr.substring(mid - 16, mid - 12).padEnd(4, end4)).padEnd(4, "f");
|
|
85
|
+
const str6 = limitHexStr(assetStr.substring(mid, mid + 4).padEnd(4, end4)).padEnd(4, "f");
|
|
86
|
+
const str7 = limitHexStr(assetStr.substring(mid + 4, mid + 8).padEnd(4, end4)).padEnd(4, "f");
|
|
87
|
+
const str8 = limitHexStr(end4.padEnd(4, start4).padEnd(4, end4));
|
|
88
|
+
return `@assets/${str1}${str2}-${str3}-${str4}-${str5}-${str6}${str7}${str8}`;
|
|
89
|
+
}
|
|
90
|
+
function isAssetId(id) {
|
|
91
|
+
return /^@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(`${id}`);
|
|
92
|
+
}
|
|
24
93
|
function deepClone(target) {
|
|
25
94
|
function _clone(t) {
|
|
26
95
|
const type = is$1(t);
|
|
@@ -132,7 +201,7 @@ var iDrawCore = function(exports) {
|
|
|
132
201
|
};
|
|
133
202
|
});
|
|
134
203
|
}
|
|
135
|
-
var __awaiter$1 =
|
|
204
|
+
var __awaiter$1 = function(thisArg, _arguments, P, generator) {
|
|
136
205
|
function adopt(value) {
|
|
137
206
|
return value instanceof P ? value : new P(function(resolve) {
|
|
138
207
|
resolve(value);
|
|
@@ -244,7 +313,7 @@ var iDrawCore = function(exports) {
|
|
|
244
313
|
function text(value) {
|
|
245
314
|
return typeof value === "string";
|
|
246
315
|
}
|
|
247
|
-
function fontSize(value) {
|
|
316
|
+
function fontSize$1(value) {
|
|
248
317
|
return number(value) && value > 0;
|
|
249
318
|
}
|
|
250
319
|
function lineHeight(value) {
|
|
@@ -256,10 +325,10 @@ var iDrawCore = function(exports) {
|
|
|
256
325
|
function textAlign(value) {
|
|
257
326
|
return ["center", "left", "right"].includes(value);
|
|
258
327
|
}
|
|
259
|
-
function fontFamily(value) {
|
|
328
|
+
function fontFamily$1(value) {
|
|
260
329
|
return typeof value === "string" && value.length > 0;
|
|
261
330
|
}
|
|
262
|
-
function fontWeight(value) {
|
|
331
|
+
function fontWeight$1(value) {
|
|
263
332
|
return ["bold"].includes(value);
|
|
264
333
|
}
|
|
265
334
|
function numberStr(value) {
|
|
@@ -282,11 +351,11 @@ var iDrawCore = function(exports) {
|
|
|
282
351
|
svg,
|
|
283
352
|
html,
|
|
284
353
|
text,
|
|
285
|
-
fontSize,
|
|
354
|
+
fontSize: fontSize$1,
|
|
286
355
|
lineHeight,
|
|
287
356
|
textAlign,
|
|
288
|
-
fontFamily,
|
|
289
|
-
fontWeight,
|
|
357
|
+
fontFamily: fontFamily$1,
|
|
358
|
+
fontWeight: fontWeight$1,
|
|
290
359
|
strokeWidth
|
|
291
360
|
};
|
|
292
361
|
class Context2D {
|
|
@@ -430,7 +499,8 @@ var iDrawCore = function(exports) {
|
|
|
430
499
|
return this._ctx.getLineDash();
|
|
431
500
|
}
|
|
432
501
|
setLineDash(nums) {
|
|
433
|
-
|
|
502
|
+
const dash = nums.map((n) => this.$doPixelRatio(n));
|
|
503
|
+
return this._ctx.setLineDash(dash);
|
|
434
504
|
}
|
|
435
505
|
stroke(path) {
|
|
436
506
|
return path ? this._ctx.stroke(path) : this._ctx.stroke();
|
|
@@ -532,8 +602,10 @@ var iDrawCore = function(exports) {
|
|
|
532
602
|
};
|
|
533
603
|
const viewContext = createContext2D(ctxOpts);
|
|
534
604
|
const helperContext = createContext2D(ctxOpts);
|
|
605
|
+
const underContext = createContext2D(ctxOpts);
|
|
535
606
|
const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
|
|
536
607
|
const content = {
|
|
608
|
+
underContext,
|
|
537
609
|
viewContext,
|
|
538
610
|
helperContext,
|
|
539
611
|
boardContext
|
|
@@ -644,9 +716,8 @@ var iDrawCore = function(exports) {
|
|
|
644
716
|
function parseAngleToRadian(angle2) {
|
|
645
717
|
return angle2 / 180 * Math.PI;
|
|
646
718
|
}
|
|
647
|
-
function
|
|
648
|
-
const
|
|
649
|
-
const radian = parseAngleToRadian(elemSize.angle || 0);
|
|
719
|
+
function rotateByCenter(ctx, angle2, center, callback) {
|
|
720
|
+
const radian = parseAngleToRadian(angle2 || 0);
|
|
650
721
|
if (center && (radian > 0 || radian < 0)) {
|
|
651
722
|
ctx.translate(center.x, center.y);
|
|
652
723
|
ctx.rotate(radian);
|
|
@@ -659,6 +730,12 @@ var iDrawCore = function(exports) {
|
|
|
659
730
|
ctx.translate(-center.x, -center.y);
|
|
660
731
|
}
|
|
661
732
|
}
|
|
733
|
+
function rotateElement(ctx, elemSize, callback) {
|
|
734
|
+
const center = calcElementCenter(elemSize);
|
|
735
|
+
rotateByCenter(ctx, elemSize.angle || 0, center, () => {
|
|
736
|
+
callback(ctx);
|
|
737
|
+
});
|
|
738
|
+
}
|
|
662
739
|
function calcElementCenter(elem) {
|
|
663
740
|
const p = {
|
|
664
741
|
x: elem.x + elem.w / 2,
|
|
@@ -1221,54 +1298,58 @@ var iDrawCore = function(exports) {
|
|
|
1221
1298
|
const topRightCenter = vertexes[1];
|
|
1222
1299
|
const bottomRightCenter = vertexes[2];
|
|
1223
1300
|
const bottomLeftCenter = vertexes[3];
|
|
1224
|
-
const topSize = createControllerElementSizeFromCenter(topCenter, { size: ctrlSize, angle: totalAngle });
|
|
1225
|
-
const rightSize = createControllerElementSizeFromCenter(rightCenter, { size: ctrlSize, angle: totalAngle });
|
|
1226
|
-
const bottomSize = createControllerElementSizeFromCenter(bottomCenter, { size: ctrlSize, angle: totalAngle });
|
|
1227
|
-
const leftSize = createControllerElementSizeFromCenter(leftCenter, { size: ctrlSize, angle: totalAngle });
|
|
1228
1301
|
const topLeftSize = createControllerElementSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: totalAngle });
|
|
1229
1302
|
const topRightSize = createControllerElementSizeFromCenter(topRightCenter, { size: ctrlSize, angle: totalAngle });
|
|
1230
1303
|
const bottomLeftSize = createControllerElementSizeFromCenter(bottomLeftCenter, { size: ctrlSize, angle: totalAngle });
|
|
1231
1304
|
const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, { size: ctrlSize, angle: totalAngle });
|
|
1305
|
+
const topLeftVertexes = calcElementVertexes(topLeftSize);
|
|
1306
|
+
const topRightVertexes = calcElementVertexes(topRightSize);
|
|
1307
|
+
const bottomLeftVertexes = calcElementVertexes(bottomLeftSize);
|
|
1308
|
+
const bottomRightVertexes = calcElementVertexes(bottomRightSize);
|
|
1309
|
+
const topVertexes = [topLeftVertexes[1], topRightVertexes[0], topRightVertexes[3], topLeftVertexes[2]];
|
|
1310
|
+
const rightVertexes = [topRightVertexes[3], topRightVertexes[2], bottomRightVertexes[1], bottomRightVertexes[0]];
|
|
1311
|
+
const bottomVertexes = [bottomLeftVertexes[1], bottomRightVertexes[0], bottomRightVertexes[3], bottomLeftVertexes[2]];
|
|
1312
|
+
const leftVertexes = [topLeftVertexes[3], topLeftVertexes[2], bottomLeftVertexes[1], bottomLeftVertexes[0]];
|
|
1232
1313
|
const sizeController = {
|
|
1233
1314
|
elementWrapper: vertexes,
|
|
1234
1315
|
left: {
|
|
1235
1316
|
type: "left",
|
|
1236
|
-
vertexes:
|
|
1317
|
+
vertexes: leftVertexes,
|
|
1237
1318
|
center: leftCenter
|
|
1238
1319
|
},
|
|
1239
1320
|
right: {
|
|
1240
1321
|
type: "right",
|
|
1241
|
-
vertexes:
|
|
1322
|
+
vertexes: rightVertexes,
|
|
1242
1323
|
center: rightCenter
|
|
1243
1324
|
},
|
|
1244
1325
|
top: {
|
|
1245
1326
|
type: "top",
|
|
1246
|
-
vertexes:
|
|
1327
|
+
vertexes: topVertexes,
|
|
1247
1328
|
center: topCenter
|
|
1248
1329
|
},
|
|
1249
1330
|
bottom: {
|
|
1250
1331
|
type: "bottom",
|
|
1251
|
-
vertexes:
|
|
1332
|
+
vertexes: bottomVertexes,
|
|
1252
1333
|
center: bottomCenter
|
|
1253
1334
|
},
|
|
1254
1335
|
topLeft: {
|
|
1255
1336
|
type: "top-left",
|
|
1256
|
-
vertexes:
|
|
1337
|
+
vertexes: topLeftVertexes,
|
|
1257
1338
|
center: topLeftCenter
|
|
1258
1339
|
},
|
|
1259
1340
|
topRight: {
|
|
1260
1341
|
type: "top-right",
|
|
1261
|
-
vertexes:
|
|
1342
|
+
vertexes: topRightVertexes,
|
|
1262
1343
|
center: topRightCenter
|
|
1263
1344
|
},
|
|
1264
1345
|
bottomLeft: {
|
|
1265
1346
|
type: "bottom-left",
|
|
1266
|
-
vertexes:
|
|
1347
|
+
vertexes: bottomLeftVertexes,
|
|
1267
1348
|
center: bottomLeftCenter
|
|
1268
1349
|
},
|
|
1269
1350
|
bottomRight: {
|
|
1270
1351
|
type: "bottom-right",
|
|
1271
|
-
vertexes:
|
|
1352
|
+
vertexes: bottomRightVertexes,
|
|
1272
1353
|
center: bottomRightCenter
|
|
1273
1354
|
}
|
|
1274
1355
|
};
|
|
@@ -1281,40 +1362,124 @@ var iDrawCore = function(exports) {
|
|
|
1281
1362
|
});
|
|
1282
1363
|
return path;
|
|
1283
1364
|
}
|
|
1284
|
-
function
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
const a = w2 / 2;
|
|
1291
|
-
const b = h2 / 2;
|
|
1292
|
-
const centerX = x2 + a;
|
|
1293
|
-
const centerY = y2 + b;
|
|
1294
|
-
if (borderWidth2 && borderWidth2 > 0) {
|
|
1295
|
-
const ba = borderWidth2 / 2 + a;
|
|
1296
|
-
const bb = borderWidth2 / 2 + b;
|
|
1297
|
-
ctx.beginPath();
|
|
1298
|
-
ctx.strokeStyle = borderColor;
|
|
1299
|
-
ctx.lineWidth = borderWidth2;
|
|
1300
|
-
ctx.circle(centerX, centerY, ba, bb, 0, 0, 2 * Math.PI);
|
|
1301
|
-
ctx.closePath();
|
|
1302
|
-
ctx.stroke();
|
|
1303
|
-
}
|
|
1304
|
-
ctx.beginPath();
|
|
1305
|
-
ctx.fillStyle = background;
|
|
1306
|
-
ctx.circle(centerX, centerY, a, b, 0, 0, 2 * Math.PI);
|
|
1307
|
-
ctx.closePath();
|
|
1308
|
-
ctx.fill();
|
|
1309
|
-
});
|
|
1365
|
+
function formatNumber(num, opts) {
|
|
1366
|
+
let decimalPlaces = 2;
|
|
1367
|
+
if (typeof (opts === null || opts === void 0 ? void 0 : opts.decimalPlaces) !== "undefined" && (opts === null || opts === void 0 ? void 0 : opts.decimalPlaces) >= 0) {
|
|
1368
|
+
decimalPlaces = opts.decimalPlaces;
|
|
1369
|
+
}
|
|
1370
|
+
return parseFloat(num.toFixed(decimalPlaces));
|
|
1310
1371
|
}
|
|
1311
|
-
function
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1372
|
+
function getDefaultElementDetailConfig() {
|
|
1373
|
+
const config = {
|
|
1374
|
+
boxSizing: "center-line",
|
|
1375
|
+
borderWidth: 0,
|
|
1376
|
+
borderColor: "#000000",
|
|
1377
|
+
shadowColor: "#000000",
|
|
1378
|
+
borderRadius: 0,
|
|
1379
|
+
borderDash: [],
|
|
1380
|
+
shadowOffsetX: 0,
|
|
1381
|
+
shadowOffsetY: 0,
|
|
1382
|
+
shadowBlur: 0,
|
|
1383
|
+
opacity: 1,
|
|
1384
|
+
color: "#000000",
|
|
1385
|
+
textAlign: "left",
|
|
1386
|
+
verticalAlign: "top",
|
|
1387
|
+
fontSize: 16,
|
|
1388
|
+
lineHeight: 20,
|
|
1389
|
+
fontFamily: "sans-serif",
|
|
1390
|
+
fontWeight: 400
|
|
1391
|
+
};
|
|
1392
|
+
return config;
|
|
1393
|
+
}
|
|
1394
|
+
const defaultElemConfig$1 = getDefaultElementDetailConfig();
|
|
1395
|
+
function calcViewBoxSize(viewElem, opts) {
|
|
1396
|
+
const { viewScaleInfo } = opts;
|
|
1397
|
+
const { scale } = viewScaleInfo;
|
|
1398
|
+
let { borderRadius: borderRadius2, boxSizing = defaultElemConfig$1.boxSizing, borderWidth: borderWidth2 } = viewElem.detail;
|
|
1399
|
+
if (typeof borderWidth2 !== "number") {
|
|
1400
|
+
borderRadius2 = 0;
|
|
1401
|
+
}
|
|
1402
|
+
let { x: x2, y: y2, w: w2, h: h2 } = viewElem;
|
|
1403
|
+
let radiusList = [0, 0, 0, 0];
|
|
1404
|
+
if (typeof borderRadius2 === "number") {
|
|
1405
|
+
const br = borderRadius2 * scale;
|
|
1406
|
+
radiusList = [br, br, br, br];
|
|
1407
|
+
} else if (Array.isArray(borderRadius2) && (borderRadius2 === null || borderRadius2 === void 0 ? void 0 : borderRadius2.length) === 4) {
|
|
1408
|
+
radiusList = [borderRadius2[0] * scale, borderRadius2[1] * scale, borderRadius2[2] * scale, borderRadius2[3] * scale];
|
|
1409
|
+
}
|
|
1410
|
+
let bw = 0;
|
|
1411
|
+
if (typeof borderWidth2 === "number") {
|
|
1412
|
+
bw = (borderWidth2 || 1) * scale;
|
|
1413
|
+
}
|
|
1414
|
+
if (boxSizing === "border-box") {
|
|
1415
|
+
x2 = viewElem.x + bw / 2;
|
|
1416
|
+
y2 = viewElem.y + bw / 2;
|
|
1417
|
+
w2 = viewElem.w - bw;
|
|
1418
|
+
h2 = viewElem.h - bw;
|
|
1419
|
+
} else if (boxSizing === "content-box") {
|
|
1420
|
+
x2 = viewElem.x - bw / 2;
|
|
1421
|
+
y2 = viewElem.y - bw / 2;
|
|
1422
|
+
w2 = viewElem.w + bw;
|
|
1423
|
+
h2 = viewElem.h + bw;
|
|
1315
1424
|
} else {
|
|
1316
|
-
|
|
1425
|
+
x2 = viewElem.x;
|
|
1426
|
+
y2 = viewElem.y;
|
|
1427
|
+
w2 = viewElem.w;
|
|
1428
|
+
h2 = viewElem.h;
|
|
1317
1429
|
}
|
|
1430
|
+
return {
|
|
1431
|
+
x: x2,
|
|
1432
|
+
y: y2,
|
|
1433
|
+
w: w2,
|
|
1434
|
+
h: h2,
|
|
1435
|
+
radiusList
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
function createColorStyle(ctx, color2, opts) {
|
|
1439
|
+
if (typeof color2 === "string") {
|
|
1440
|
+
return color2;
|
|
1441
|
+
}
|
|
1442
|
+
const { viewElementSize, viewScaleInfo, opacity = 1 } = opts;
|
|
1443
|
+
const { x: x2, y: y2 } = viewElementSize;
|
|
1444
|
+
const { scale } = viewScaleInfo;
|
|
1445
|
+
if ((color2 === null || color2 === void 0 ? void 0 : color2.type) === "linear-gradient") {
|
|
1446
|
+
const { start, end, stops } = color2;
|
|
1447
|
+
const viewStart = {
|
|
1448
|
+
x: x2 + start.x * scale,
|
|
1449
|
+
y: y2 + start.y * scale
|
|
1450
|
+
};
|
|
1451
|
+
const viewEnd = {
|
|
1452
|
+
x: x2 + end.x * scale,
|
|
1453
|
+
y: y2 + end.y * scale
|
|
1454
|
+
};
|
|
1455
|
+
const linearGradient = ctx.createLinearGradient(viewStart.x, viewStart.y, viewEnd.x, viewEnd.y);
|
|
1456
|
+
stops.forEach((stop) => {
|
|
1457
|
+
linearGradient.addColorStop(stop.offset, mergeHexColorAlpha(stop.color, opacity));
|
|
1458
|
+
});
|
|
1459
|
+
return linearGradient;
|
|
1460
|
+
}
|
|
1461
|
+
if ((color2 === null || color2 === void 0 ? void 0 : color2.type) === "radial-gradient") {
|
|
1462
|
+
const { inner, outer, stops } = color2;
|
|
1463
|
+
const viewInner = {
|
|
1464
|
+
x: x2 + inner.x * scale,
|
|
1465
|
+
y: y2 + inner.y * scale,
|
|
1466
|
+
radius: inner.radius * scale
|
|
1467
|
+
};
|
|
1468
|
+
const viewOuter = {
|
|
1469
|
+
x: x2 + outer.x * scale,
|
|
1470
|
+
y: y2 + outer.y * scale,
|
|
1471
|
+
radius: outer.radius * scale
|
|
1472
|
+
};
|
|
1473
|
+
const radialGradient = ctx.createRadialGradient(viewInner.x, viewInner.y, viewInner.radius, viewOuter.x, viewOuter.y, viewOuter.radius);
|
|
1474
|
+
stops.forEach((stop) => {
|
|
1475
|
+
radialGradient.addColorStop(stop.offset, mergeHexColorAlpha(stop.color, opacity));
|
|
1476
|
+
});
|
|
1477
|
+
return radialGradient;
|
|
1478
|
+
}
|
|
1479
|
+
return "#000000";
|
|
1480
|
+
}
|
|
1481
|
+
const defaultElemConfig = getDefaultElementDetailConfig();
|
|
1482
|
+
function drawBox(ctx, viewElem, opts) {
|
|
1318
1483
|
const { pattern, renderContent, originElem, calcElemSize, viewScaleInfo, viewSizeInfo } = opts || {};
|
|
1319
1484
|
drawClipPath(ctx, viewElem, {
|
|
1320
1485
|
originElem,
|
|
@@ -1322,12 +1487,18 @@ var iDrawCore = function(exports) {
|
|
|
1322
1487
|
viewScaleInfo,
|
|
1323
1488
|
viewSizeInfo,
|
|
1324
1489
|
renderContent: () => {
|
|
1325
|
-
|
|
1490
|
+
var _a, _b;
|
|
1491
|
+
if (((_a = viewElem === null || viewElem === void 0 ? void 0 : viewElem.detail) === null || _a === void 0 ? void 0 : _a.opacity) !== void 0 && ((_b = viewElem === null || viewElem === void 0 ? void 0 : viewElem.detail) === null || _b === void 0 ? void 0 : _b.opacity) >= 0) {
|
|
1492
|
+
ctx.globalAlpha = viewElem.detail.opacity;
|
|
1493
|
+
} else {
|
|
1494
|
+
ctx.globalAlpha = 1;
|
|
1495
|
+
}
|
|
1326
1496
|
drawBoxBackground(ctx, viewElem, { pattern, viewScaleInfo, viewSizeInfo });
|
|
1327
1497
|
renderContent === null || renderContent === void 0 ? void 0 : renderContent();
|
|
1498
|
+
drawBoxBorder(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
|
|
1499
|
+
ctx.globalAlpha = 1;
|
|
1328
1500
|
}
|
|
1329
1501
|
});
|
|
1330
|
-
ctx.globalAlpha = 1;
|
|
1331
1502
|
}
|
|
1332
1503
|
function drawClipPath(ctx, viewElem, opts) {
|
|
1333
1504
|
const { renderContent, originElem, calcElemSize, viewScaleInfo, viewSizeInfo } = opts;
|
|
@@ -1360,21 +1531,20 @@ var iDrawCore = function(exports) {
|
|
|
1360
1531
|
}
|
|
1361
1532
|
function drawBoxBackground(ctx, viewElem, opts) {
|
|
1362
1533
|
var _a, _b;
|
|
1363
|
-
const { pattern, viewScaleInfo } = opts;
|
|
1534
|
+
const { pattern, viewScaleInfo, viewSizeInfo } = opts;
|
|
1364
1535
|
let transform = [];
|
|
1536
|
+
viewElem.detail;
|
|
1365
1537
|
if (viewElem.detail.background || pattern) {
|
|
1366
|
-
const { x: x2, y: y2, w: w2, h: h2 } = viewElem
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
r = 0;
|
|
1371
|
-
}
|
|
1538
|
+
const { x: x2, y: y2, w: w2, h: h2, radiusList } = calcViewBoxSize(viewElem, {
|
|
1539
|
+
viewScaleInfo,
|
|
1540
|
+
viewSizeInfo
|
|
1541
|
+
});
|
|
1372
1542
|
ctx.beginPath();
|
|
1373
|
-
ctx.moveTo(x2 +
|
|
1374
|
-
ctx.arcTo(x2 + w2, y2, x2 + w2, y2 + h2,
|
|
1375
|
-
ctx.arcTo(x2 + w2, y2 + h2, x2, y2 + h2,
|
|
1376
|
-
ctx.arcTo(x2, y2 + h2, x2, y2,
|
|
1377
|
-
ctx.arcTo(x2, y2, x2 + w2, y2,
|
|
1543
|
+
ctx.moveTo(x2 + radiusList[0], y2);
|
|
1544
|
+
ctx.arcTo(x2 + w2, y2, x2 + w2, y2 + h2, radiusList[1]);
|
|
1545
|
+
ctx.arcTo(x2 + w2, y2 + h2, x2, y2 + h2, radiusList[2]);
|
|
1546
|
+
ctx.arcTo(x2, y2 + h2, x2, y2, radiusList[3]);
|
|
1547
|
+
ctx.arcTo(x2, y2, x2 + w2, y2, radiusList[0]);
|
|
1378
1548
|
ctx.closePath();
|
|
1379
1549
|
if (typeof pattern === "string") {
|
|
1380
1550
|
ctx.fillStyle = pattern;
|
|
@@ -1382,39 +1552,20 @@ var iDrawCore = function(exports) {
|
|
|
1382
1552
|
ctx.fillStyle = pattern;
|
|
1383
1553
|
} else if (typeof viewElem.detail.background === "string") {
|
|
1384
1554
|
ctx.fillStyle = viewElem.detail.background;
|
|
1385
|
-
} else if (((_a = viewElem.detail.background) === null || _a === void 0 ? void 0 : _a.type) === "
|
|
1386
|
-
const
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
};
|
|
1391
|
-
const viewEnd = {
|
|
1392
|
-
x: end.x + x2,
|
|
1393
|
-
y: end.y + y2
|
|
1394
|
-
};
|
|
1395
|
-
const linearGradient = ctx.createLinearGradient(viewStart.x, viewStart.y, viewEnd.x, viewEnd.y);
|
|
1396
|
-
stops.forEach((stop) => {
|
|
1397
|
-
linearGradient.addColorStop(stop.offset, stop.color);
|
|
1555
|
+
} else if (((_a = viewElem.detail.background) === null || _a === void 0 ? void 0 : _a.type) === "linear-gradient") {
|
|
1556
|
+
const colorStyle = createColorStyle(ctx, viewElem.detail.background, {
|
|
1557
|
+
viewElementSize: { x: x2, y: y2, w: w2, h: h2 },
|
|
1558
|
+
viewScaleInfo,
|
|
1559
|
+
opacity: ctx.globalAlpha
|
|
1398
1560
|
});
|
|
1399
|
-
ctx.fillStyle =
|
|
1400
|
-
} else if (((_b = viewElem.detail.background) === null || _b === void 0 ? void 0 : _b.type) === "
|
|
1401
|
-
const
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
y: inner.y,
|
|
1406
|
-
radius: inner.radius * viewScaleInfo.scale
|
|
1407
|
-
};
|
|
1408
|
-
const viewOuter = {
|
|
1409
|
-
x: outer.x,
|
|
1410
|
-
y: outer.y,
|
|
1411
|
-
radius: outer.radius * viewScaleInfo.scale
|
|
1412
|
-
};
|
|
1413
|
-
const radialGradient = ctx.createRadialGradient(viewInner.x, viewInner.y, viewInner.radius, viewOuter.x, viewOuter.y, viewOuter.radius);
|
|
1414
|
-
stops.forEach((stop) => {
|
|
1415
|
-
radialGradient.addColorStop(stop.offset, stop.color);
|
|
1561
|
+
ctx.fillStyle = colorStyle;
|
|
1562
|
+
} else if (((_b = viewElem.detail.background) === null || _b === void 0 ? void 0 : _b.type) === "radial-gradient") {
|
|
1563
|
+
const colorStyle = createColorStyle(ctx, viewElem.detail.background, {
|
|
1564
|
+
viewElementSize: { x: x2, y: y2, w: w2, h: h2 },
|
|
1565
|
+
viewScaleInfo,
|
|
1566
|
+
opacity: ctx.globalAlpha
|
|
1416
1567
|
});
|
|
1417
|
-
ctx.fillStyle =
|
|
1568
|
+
ctx.fillStyle = colorStyle;
|
|
1418
1569
|
if (transform && transform.length > 0) {
|
|
1419
1570
|
for (let i = 0; i < (transform === null || transform === void 0 ? void 0 : transform.length); i++) {
|
|
1420
1571
|
const action = transform[i];
|
|
@@ -1435,95 +1586,139 @@ var iDrawCore = function(exports) {
|
|
|
1435
1586
|
}
|
|
1436
1587
|
}
|
|
1437
1588
|
function drawBoxBorder(ctx, viewElem, opts) {
|
|
1589
|
+
var _a, _b;
|
|
1590
|
+
if (viewElem.detail.borderWidth === 0) {
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1438
1593
|
if (!isColorStr(viewElem.detail.borderColor)) {
|
|
1439
1594
|
return;
|
|
1440
1595
|
}
|
|
1596
|
+
if (((_a = viewElem === null || viewElem === void 0 ? void 0 : viewElem.detail) === null || _a === void 0 ? void 0 : _a.opacity) !== void 0 && ((_b = viewElem === null || viewElem === void 0 ? void 0 : viewElem.detail) === null || _b === void 0 ? void 0 : _b.opacity) >= 0) {
|
|
1597
|
+
ctx.globalAlpha = viewElem.detail.opacity;
|
|
1598
|
+
} else {
|
|
1599
|
+
ctx.globalAlpha = 1;
|
|
1600
|
+
}
|
|
1441
1601
|
const { viewScaleInfo } = opts;
|
|
1442
|
-
|
|
1602
|
+
const { scale } = viewScaleInfo;
|
|
1603
|
+
let borderColor2 = defaultElemConfig.borderColor;
|
|
1443
1604
|
if (isColorStr(viewElem.detail.borderColor) === true) {
|
|
1444
|
-
|
|
1605
|
+
borderColor2 = viewElem.detail.borderColor;
|
|
1445
1606
|
}
|
|
1446
|
-
const { borderWidth: borderWidth2, borderRadius: borderRadius2, borderDash } = viewElem.detail;
|
|
1607
|
+
const { borderWidth: borderWidth2, borderRadius: borderRadius2, borderDash, boxSizing = defaultElemConfig.boxSizing } = viewElem.detail;
|
|
1447
1608
|
let bw = 0;
|
|
1448
1609
|
if (typeof borderWidth2 === "number") {
|
|
1449
1610
|
bw = borderWidth2 || 1;
|
|
1450
1611
|
}
|
|
1451
|
-
bw = bw *
|
|
1452
|
-
let
|
|
1453
|
-
|
|
1454
|
-
|
|
1612
|
+
bw = bw * scale;
|
|
1613
|
+
let radiusList = [0, 0, 0, 0];
|
|
1614
|
+
if (typeof borderRadius2 === "number") {
|
|
1615
|
+
const br = borderRadius2 * scale;
|
|
1616
|
+
radiusList = [br, br, br, br];
|
|
1617
|
+
} else if (Array.isArray(borderRadius2) && (borderRadius2 === null || borderRadius2 === void 0 ? void 0 : borderRadius2.length) === 4) {
|
|
1618
|
+
radiusList = [borderRadius2[0] * scale, borderRadius2[1] * scale, borderRadius2[2] * scale, borderRadius2[3] * scale];
|
|
1619
|
+
}
|
|
1620
|
+
ctx.strokeStyle = borderColor2;
|
|
1621
|
+
let viewBorderDash = [];
|
|
1622
|
+
if (Array.isArray(borderDash) && borderDash.length > 0) {
|
|
1623
|
+
viewBorderDash = borderDash.map((num) => Math.ceil(num * scale));
|
|
1624
|
+
}
|
|
1455
1625
|
let borderTop = 0;
|
|
1456
1626
|
let borderRight = 0;
|
|
1457
1627
|
let borderBottom = 0;
|
|
1458
1628
|
let borderLeft = 0;
|
|
1459
1629
|
if (Array.isArray(borderWidth2)) {
|
|
1460
|
-
borderTop = borderWidth2[0] || 0;
|
|
1461
|
-
borderRight = borderWidth2[1] || 0;
|
|
1462
|
-
borderBottom = borderWidth2[2] || 0;
|
|
1463
|
-
borderLeft = borderWidth2[3] || 0;
|
|
1630
|
+
borderTop = (borderWidth2[0] || 0) * scale;
|
|
1631
|
+
borderRight = (borderWidth2[1] || 0) * scale;
|
|
1632
|
+
borderBottom = (borderWidth2[2] || 0) * scale;
|
|
1633
|
+
borderLeft = (borderWidth2[3] || 0) * scale;
|
|
1464
1634
|
}
|
|
1465
1635
|
if (borderLeft || borderRight || borderTop || borderBottom) {
|
|
1466
|
-
|
|
1467
|
-
|
|
1636
|
+
ctx.lineCap = "butt";
|
|
1637
|
+
let { x: x2, y: y2, w: w2, h: h2 } = viewElem;
|
|
1638
|
+
if (boxSizing === "border-box") {
|
|
1639
|
+
x2 = x2 + borderLeft / 2;
|
|
1640
|
+
y2 = y2 + borderTop / 2;
|
|
1641
|
+
w2 = w2 - borderLeft / 2 - borderRight / 2;
|
|
1642
|
+
h2 = h2 - borderTop / 2 - borderBottom / 2;
|
|
1643
|
+
} else if (boxSizing === "content-box") {
|
|
1644
|
+
x2 = x2 - borderLeft / 2;
|
|
1645
|
+
y2 = y2 - borderTop / 2;
|
|
1646
|
+
w2 = w2 + borderLeft / 2 + borderRight / 2;
|
|
1647
|
+
h2 = h2 + borderTop / 2 + borderBottom / 2;
|
|
1648
|
+
} else {
|
|
1649
|
+
x2 = viewElem.x;
|
|
1650
|
+
y2 = viewElem.y;
|
|
1651
|
+
w2 = viewElem.w;
|
|
1652
|
+
h2 = viewElem.h;
|
|
1653
|
+
}
|
|
1654
|
+
if (borderTop) {
|
|
1468
1655
|
ctx.beginPath();
|
|
1469
|
-
ctx.lineWidth =
|
|
1470
|
-
ctx.moveTo(x2, y2);
|
|
1471
|
-
ctx.lineTo(x2
|
|
1656
|
+
ctx.lineWidth = borderTop;
|
|
1657
|
+
ctx.moveTo(x2 - borderLeft / 2, y2);
|
|
1658
|
+
ctx.lineTo(x2 + w2 + borderRight / 2, y2);
|
|
1472
1659
|
ctx.closePath();
|
|
1473
1660
|
ctx.stroke();
|
|
1474
1661
|
}
|
|
1475
1662
|
if (borderRight) {
|
|
1476
1663
|
ctx.beginPath();
|
|
1477
|
-
ctx.lineWidth = borderRight
|
|
1478
|
-
ctx.moveTo(x2 + w2, y2);
|
|
1479
|
-
ctx.lineTo(x2 + w2, y2 + h2);
|
|
1664
|
+
ctx.lineWidth = borderRight;
|
|
1665
|
+
ctx.moveTo(x2 + w2, y2 - borderTop / 2);
|
|
1666
|
+
ctx.lineTo(x2 + w2, y2 + h2 + borderBottom / 2);
|
|
1480
1667
|
ctx.closePath();
|
|
1481
1668
|
ctx.stroke();
|
|
1482
1669
|
}
|
|
1483
|
-
if (
|
|
1670
|
+
if (borderBottom) {
|
|
1484
1671
|
ctx.beginPath();
|
|
1485
|
-
ctx.lineWidth =
|
|
1486
|
-
ctx.moveTo(x2, y2);
|
|
1487
|
-
ctx.lineTo(x2 + w2, y2);
|
|
1672
|
+
ctx.lineWidth = borderBottom;
|
|
1673
|
+
ctx.moveTo(x2 - borderLeft / 2, y2 + h2);
|
|
1674
|
+
ctx.lineTo(x2 + w2 + borderRight / 2, y2 + h2);
|
|
1488
1675
|
ctx.closePath();
|
|
1489
1676
|
ctx.stroke();
|
|
1490
1677
|
}
|
|
1491
|
-
if (
|
|
1678
|
+
if (borderLeft) {
|
|
1492
1679
|
ctx.beginPath();
|
|
1493
|
-
ctx.lineWidth =
|
|
1494
|
-
ctx.moveTo(x2, y2
|
|
1495
|
-
ctx.lineTo(x2
|
|
1680
|
+
ctx.lineWidth = borderLeft;
|
|
1681
|
+
ctx.moveTo(x2, y2 - borderTop / 2);
|
|
1682
|
+
ctx.lineTo(x2, y2 + h2 + borderBottom / 2);
|
|
1496
1683
|
ctx.closePath();
|
|
1497
1684
|
ctx.stroke();
|
|
1498
1685
|
}
|
|
1499
1686
|
} else {
|
|
1500
1687
|
let { x: x2, y: y2, w: w2, h: h2 } = viewElem;
|
|
1501
|
-
const { boxSizing } = viewElem.detail;
|
|
1502
1688
|
if (boxSizing === "border-box") {
|
|
1689
|
+
x2 = viewElem.x + bw / 2;
|
|
1690
|
+
y2 = viewElem.y + bw / 2;
|
|
1691
|
+
w2 = viewElem.w - bw;
|
|
1692
|
+
h2 = viewElem.h - bw;
|
|
1693
|
+
} else if (boxSizing === "content-box") {
|
|
1694
|
+
x2 = viewElem.x - bw / 2;
|
|
1695
|
+
y2 = viewElem.y - bw / 2;
|
|
1696
|
+
w2 = viewElem.w + bw;
|
|
1697
|
+
h2 = viewElem.h + bw;
|
|
1698
|
+
} else {
|
|
1503
1699
|
x2 = viewElem.x;
|
|
1504
1700
|
y2 = viewElem.y;
|
|
1505
1701
|
w2 = viewElem.w;
|
|
1506
1702
|
h2 = viewElem.h;
|
|
1507
|
-
} else {
|
|
1508
|
-
x2 = viewElem.x - bw;
|
|
1509
|
-
y2 = viewElem.y - bw;
|
|
1510
|
-
w2 = viewElem.w + bw * 2;
|
|
1511
|
-
h2 = viewElem.h + bw * 2;
|
|
1512
1703
|
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1704
|
+
if (viewBorderDash.length > 0) {
|
|
1705
|
+
ctx.lineCap = "butt";
|
|
1706
|
+
} else {
|
|
1707
|
+
ctx.lineCap = "square";
|
|
1516
1708
|
}
|
|
1517
|
-
ctx.
|
|
1709
|
+
ctx.setLineDash(viewBorderDash);
|
|
1518
1710
|
ctx.lineWidth = bw;
|
|
1519
|
-
ctx.
|
|
1520
|
-
ctx.
|
|
1521
|
-
ctx.arcTo(x2 + w2, y2 +
|
|
1522
|
-
ctx.arcTo(x2, y2 + h2, x2, y2,
|
|
1523
|
-
ctx.arcTo(x2, y2
|
|
1711
|
+
ctx.beginPath();
|
|
1712
|
+
ctx.moveTo(x2 + radiusList[0], y2);
|
|
1713
|
+
ctx.arcTo(x2 + w2, y2, x2 + w2, y2 + h2, radiusList[1]);
|
|
1714
|
+
ctx.arcTo(x2 + w2, y2 + h2, x2, y2 + h2, radiusList[2]);
|
|
1715
|
+
ctx.arcTo(x2, y2 + h2, x2, y2, radiusList[3]);
|
|
1716
|
+
ctx.arcTo(x2, y2, x2 + w2, y2, radiusList[0]);
|
|
1524
1717
|
ctx.closePath();
|
|
1525
1718
|
ctx.stroke();
|
|
1719
|
+
ctx.globalAlpha = 1;
|
|
1526
1720
|
}
|
|
1721
|
+
ctx.setLineDash([]);
|
|
1527
1722
|
}
|
|
1528
1723
|
function drawBoxShadow(ctx, viewElem, opts) {
|
|
1529
1724
|
const { detail } = viewElem;
|
|
@@ -1531,7 +1726,7 @@ var iDrawCore = function(exports) {
|
|
|
1531
1726
|
const { shadowColor, shadowOffsetX, shadowOffsetY, shadowBlur } = detail;
|
|
1532
1727
|
if (is.number(shadowBlur)) {
|
|
1533
1728
|
ctx.save();
|
|
1534
|
-
ctx.shadowColor = shadowColor ||
|
|
1729
|
+
ctx.shadowColor = shadowColor || defaultElemConfig.shadowColor;
|
|
1535
1730
|
ctx.shadowOffsetX = (shadowOffsetX || 0) * viewScaleInfo.scale;
|
|
1536
1731
|
ctx.shadowOffsetY = (shadowOffsetY || 0) * viewScaleInfo.scale;
|
|
1537
1732
|
ctx.shadowBlur = (shadowBlur || 0) * viewScaleInfo.scale;
|
|
@@ -1541,6 +1736,52 @@ var iDrawCore = function(exports) {
|
|
|
1541
1736
|
renderContent();
|
|
1542
1737
|
}
|
|
1543
1738
|
}
|
|
1739
|
+
function drawCircle(ctx, elem, opts) {
|
|
1740
|
+
const { detail, angle: angle2 } = elem;
|
|
1741
|
+
const { background: background2 = "#000000", borderColor: borderColor2 = "#000000", borderWidth: borderWidth2 = 0 } = detail;
|
|
1742
|
+
const { calculator, viewScaleInfo, viewSizeInfo } = opts;
|
|
1743
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calculator.elementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h }, viewScaleInfo, viewSizeInfo);
|
|
1744
|
+
const viewElem = Object.assign(Object.assign({}, elem), { x: x2, y: y2, w: w2, h: h2, angle: angle2 });
|
|
1745
|
+
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
1746
|
+
drawBoxShadow(ctx, viewElem, {
|
|
1747
|
+
viewScaleInfo,
|
|
1748
|
+
viewSizeInfo,
|
|
1749
|
+
renderContent: () => {
|
|
1750
|
+
var _a, _b;
|
|
1751
|
+
const a = w2 / 2;
|
|
1752
|
+
const b = h2 / 2;
|
|
1753
|
+
const centerX = x2 + a;
|
|
1754
|
+
const centerY = y2 + b;
|
|
1755
|
+
if (((_a = elem === null || elem === void 0 ? void 0 : elem.detail) === null || _a === void 0 ? void 0 : _a.opacity) !== void 0 && ((_b = elem === null || elem === void 0 ? void 0 : elem.detail) === null || _b === void 0 ? void 0 : _b.opacity) >= 0) {
|
|
1756
|
+
ctx.globalAlpha = elem.detail.opacity;
|
|
1757
|
+
} else {
|
|
1758
|
+
ctx.globalAlpha = 1;
|
|
1759
|
+
}
|
|
1760
|
+
if (typeof borderWidth2 === "number" && borderWidth2 > 0) {
|
|
1761
|
+
const ba = borderWidth2 / 2 + a;
|
|
1762
|
+
const bb = borderWidth2 / 2 + b;
|
|
1763
|
+
ctx.beginPath();
|
|
1764
|
+
ctx.strokeStyle = borderColor2;
|
|
1765
|
+
ctx.lineWidth = borderWidth2;
|
|
1766
|
+
ctx.circle(centerX, centerY, ba, bb, 0, 0, 2 * Math.PI);
|
|
1767
|
+
ctx.closePath();
|
|
1768
|
+
ctx.stroke();
|
|
1769
|
+
}
|
|
1770
|
+
ctx.beginPath();
|
|
1771
|
+
const fillStyle = createColorStyle(ctx, background2, {
|
|
1772
|
+
viewElementSize: { x: x2, y: y2, w: w2, h: h2 },
|
|
1773
|
+
viewScaleInfo,
|
|
1774
|
+
opacity: ctx.globalAlpha
|
|
1775
|
+
});
|
|
1776
|
+
ctx.fillStyle = fillStyle;
|
|
1777
|
+
ctx.circle(centerX, centerY, a, b, 0, 0, 2 * Math.PI);
|
|
1778
|
+
ctx.closePath();
|
|
1779
|
+
ctx.fill();
|
|
1780
|
+
ctx.globalAlpha = 1;
|
|
1781
|
+
}
|
|
1782
|
+
});
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1544
1785
|
function drawRect(ctx, elem, opts) {
|
|
1545
1786
|
const { calculator, viewScaleInfo, viewSizeInfo } = opts;
|
|
1546
1787
|
let { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calculator.elementSize(elem, viewScaleInfo, viewSizeInfo);
|
|
@@ -1563,20 +1804,53 @@ var iDrawCore = function(exports) {
|
|
|
1563
1804
|
});
|
|
1564
1805
|
}
|
|
1565
1806
|
function drawImage(ctx, elem, opts) {
|
|
1566
|
-
const content = opts.loader.getContent(elem
|
|
1807
|
+
const content = opts.loader.getContent(elem);
|
|
1567
1808
|
const { calculator, viewScaleInfo, viewSizeInfo } = opts;
|
|
1568
1809
|
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calculator.elementSize(elem, viewScaleInfo, viewSizeInfo);
|
|
1810
|
+
const viewElem = Object.assign(Object.assign({}, elem), { x: x2, y: y2, w: w2, h: h2, angle: angle2 });
|
|
1569
1811
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1812
|
+
drawBoxShadow(ctx, viewElem, {
|
|
1813
|
+
viewScaleInfo,
|
|
1814
|
+
viewSizeInfo,
|
|
1815
|
+
renderContent: () => {
|
|
1816
|
+
drawBox(ctx, viewElem, {
|
|
1817
|
+
originElem: elem,
|
|
1818
|
+
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1819
|
+
viewScaleInfo,
|
|
1820
|
+
viewSizeInfo,
|
|
1821
|
+
renderContent: () => {
|
|
1822
|
+
if (!content) {
|
|
1823
|
+
opts.loader.load(elem, opts.elementAssets || {});
|
|
1824
|
+
}
|
|
1825
|
+
if (elem.type === "image" && content) {
|
|
1826
|
+
const { opacity } = elem.detail;
|
|
1827
|
+
ctx.globalAlpha = opacity ? opacity : 1;
|
|
1828
|
+
const { x: x3, y: y3, w: w3, h: h3, radiusList } = calcViewBoxSize(viewElem, {
|
|
1829
|
+
viewScaleInfo,
|
|
1830
|
+
viewSizeInfo
|
|
1831
|
+
});
|
|
1832
|
+
ctx.save();
|
|
1833
|
+
ctx.beginPath();
|
|
1834
|
+
ctx.moveTo(x3 + radiusList[0], y3);
|
|
1835
|
+
ctx.arcTo(x3 + w3, y3, x3 + w3, y3 + h3, radiusList[1]);
|
|
1836
|
+
ctx.arcTo(x3 + w3, y3 + h3, x3, y3 + h3, radiusList[2]);
|
|
1837
|
+
ctx.arcTo(x3, y3 + h3, x3, y3, radiusList[3]);
|
|
1838
|
+
ctx.arcTo(x3, y3, x3 + w3, y3, radiusList[0]);
|
|
1839
|
+
ctx.closePath();
|
|
1840
|
+
ctx.fill();
|
|
1841
|
+
ctx.clip();
|
|
1842
|
+
ctx.drawImage(content, x3, y3, w3, h3);
|
|
1843
|
+
ctx.globalAlpha = 1;
|
|
1844
|
+
ctx.restore();
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
});
|
|
1576
1850
|
});
|
|
1577
1851
|
}
|
|
1578
1852
|
function drawSVG(ctx, elem, opts) {
|
|
1579
|
-
const content = opts.loader.getContent(elem
|
|
1853
|
+
const content = opts.loader.getContent(elem);
|
|
1580
1854
|
const { calculator, viewScaleInfo, viewSizeInfo } = opts;
|
|
1581
1855
|
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calculator.elementSize(elem, viewScaleInfo, viewSizeInfo);
|
|
1582
1856
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
@@ -1584,23 +1858,30 @@ var iDrawCore = function(exports) {
|
|
|
1584
1858
|
opts.loader.load(elem, opts.elementAssets || {});
|
|
1585
1859
|
}
|
|
1586
1860
|
if (elem.type === "svg" && content) {
|
|
1861
|
+
const { opacity } = elem.detail;
|
|
1862
|
+
ctx.globalAlpha = opacity ? opacity : 1;
|
|
1587
1863
|
ctx.drawImage(content, x2, y2, w2, h2);
|
|
1864
|
+
ctx.globalAlpha = 1;
|
|
1588
1865
|
}
|
|
1589
1866
|
});
|
|
1590
1867
|
}
|
|
1591
1868
|
function drawHTML(ctx, elem, opts) {
|
|
1592
|
-
const content = opts.loader.getContent(elem
|
|
1869
|
+
const content = opts.loader.getContent(elem);
|
|
1593
1870
|
const { calculator, viewScaleInfo, viewSizeInfo } = opts;
|
|
1594
1871
|
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calculator.elementSize(elem, viewScaleInfo, viewSizeInfo);
|
|
1595
1872
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
1596
1873
|
if (!content) {
|
|
1597
|
-
opts.loader.load(elem);
|
|
1874
|
+
opts.loader.load(elem, opts.elementAssets || {});
|
|
1598
1875
|
}
|
|
1599
1876
|
if (elem.type === "html" && content) {
|
|
1877
|
+
const { opacity } = elem.detail;
|
|
1878
|
+
ctx.globalAlpha = opacity ? opacity : 1;
|
|
1600
1879
|
ctx.drawImage(content, x2, y2, w2, h2);
|
|
1880
|
+
ctx.globalAlpha = 1;
|
|
1601
1881
|
}
|
|
1602
1882
|
});
|
|
1603
1883
|
}
|
|
1884
|
+
const detailConfig = getDefaultElementDetailConfig();
|
|
1604
1885
|
function drawText(ctx, elem, opts) {
|
|
1605
1886
|
const { calculator, viewScaleInfo, viewSizeInfo } = opts;
|
|
1606
1887
|
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calculator.elementSize(elem, viewScaleInfo, viewSizeInfo);
|
|
@@ -1612,14 +1893,10 @@ var iDrawCore = function(exports) {
|
|
|
1612
1893
|
viewScaleInfo,
|
|
1613
1894
|
viewSizeInfo,
|
|
1614
1895
|
renderContent: () => {
|
|
1615
|
-
const detail = Object.assign({
|
|
1616
|
-
|
|
1617
|
-
fontFamily: "sans-serif",
|
|
1618
|
-
textAlign: "center"
|
|
1619
|
-
}, elem.detail);
|
|
1620
|
-
const fontSize2 = detail.fontSize * viewScaleInfo.scale;
|
|
1896
|
+
const detail = Object.assign(Object.assign({}, detailConfig), elem.detail);
|
|
1897
|
+
const fontSize2 = (detail.fontSize || detailConfig.fontSize) * viewScaleInfo.scale;
|
|
1621
1898
|
const lineHeight2 = detail.lineHeight ? detail.lineHeight * viewScaleInfo.scale : fontSize2;
|
|
1622
|
-
ctx.fillStyle = elem.detail.color;
|
|
1899
|
+
ctx.fillStyle = elem.detail.color || detailConfig.color;
|
|
1623
1900
|
ctx.textBaseline = "top";
|
|
1624
1901
|
ctx.$setFont({
|
|
1625
1902
|
fontWeight: detail.fontWeight,
|
|
@@ -1852,10 +2129,14 @@ var iDrawCore = function(exports) {
|
|
|
1852
2129
|
});
|
|
1853
2130
|
});
|
|
1854
2131
|
}
|
|
2132
|
+
const defaultDetail = getDefaultElementDetailConfig();
|
|
1855
2133
|
function drawElementList(ctx, data, opts) {
|
|
1856
2134
|
const { elements = [] } = data;
|
|
1857
2135
|
for (let i = 0; i < elements.length; i++) {
|
|
1858
|
-
const
|
|
2136
|
+
const element = elements[i];
|
|
2137
|
+
const elem = Object.assign(Object.assign({}, element), {
|
|
2138
|
+
detail: Object.assign(Object.assign({}, defaultDetail), element === null || element === void 0 ? void 0 : element.detail)
|
|
2139
|
+
});
|
|
1859
2140
|
if (!opts.calculator.isElementInView(elem, opts.viewScaleInfo, opts.viewSizeInfo)) {
|
|
1860
2141
|
continue;
|
|
1861
2142
|
}
|
|
@@ -1866,7 +2147,7 @@ var iDrawCore = function(exports) {
|
|
|
1866
2147
|
}
|
|
1867
2148
|
}
|
|
1868
2149
|
}
|
|
1869
|
-
var __awaiter =
|
|
2150
|
+
var __awaiter = function(thisArg, _arguments, P, generator) {
|
|
1870
2151
|
function adopt(value) {
|
|
1871
2152
|
return value instanceof P ? value : new P(function(resolve) {
|
|
1872
2153
|
resolve(value);
|
|
@@ -1894,6 +2175,24 @@ var iDrawCore = function(exports) {
|
|
|
1894
2175
|
});
|
|
1895
2176
|
};
|
|
1896
2177
|
const supportElementTypes = ["image", "svg", "html"];
|
|
2178
|
+
const getAssetIdFromElement = (element) => {
|
|
2179
|
+
var _a, _b, _c;
|
|
2180
|
+
let source = null;
|
|
2181
|
+
if (element.type === "image") {
|
|
2182
|
+
source = ((_a = element === null || element === void 0 ? void 0 : element.detail) === null || _a === void 0 ? void 0 : _a.src) || null;
|
|
2183
|
+
} else if (element.type === "svg") {
|
|
2184
|
+
source = ((_b = element === null || element === void 0 ? void 0 : element.detail) === null || _b === void 0 ? void 0 : _b.svg) || null;
|
|
2185
|
+
} else if (element.type === "html") {
|
|
2186
|
+
source = ((_c = element === null || element === void 0 ? void 0 : element.detail) === null || _c === void 0 ? void 0 : _c.html) || null;
|
|
2187
|
+
}
|
|
2188
|
+
if (typeof source === "string" && source) {
|
|
2189
|
+
if (isAssetId(source)) {
|
|
2190
|
+
return source;
|
|
2191
|
+
}
|
|
2192
|
+
return createAssetId(source);
|
|
2193
|
+
}
|
|
2194
|
+
return createAssetId(`${createUUID()}-${element.uuid}-${createUUID()}-${createUUID()}`);
|
|
2195
|
+
};
|
|
1897
2196
|
class Loader extends EventEmitter {
|
|
1898
2197
|
constructor() {
|
|
1899
2198
|
super();
|
|
@@ -1961,34 +2260,35 @@ var iDrawCore = function(exports) {
|
|
|
1961
2260
|
};
|
|
1962
2261
|
}
|
|
1963
2262
|
_emitLoad(item) {
|
|
1964
|
-
const
|
|
1965
|
-
const storageItem = this._storageLoadItemMap[
|
|
2263
|
+
const assetId = getAssetIdFromElement(item.element);
|
|
2264
|
+
const storageItem = this._storageLoadItemMap[assetId];
|
|
1966
2265
|
if (storageItem) {
|
|
1967
2266
|
if (storageItem.startTime < item.startTime) {
|
|
1968
|
-
this._storageLoadItemMap[
|
|
2267
|
+
this._storageLoadItemMap[assetId] = item;
|
|
1969
2268
|
this.trigger("load", Object.assign(Object.assign({}, item), { countTime: item.endTime - item.startTime }));
|
|
1970
2269
|
}
|
|
1971
2270
|
} else {
|
|
1972
|
-
this._storageLoadItemMap[
|
|
2271
|
+
this._storageLoadItemMap[assetId] = item;
|
|
1973
2272
|
this.trigger("load", Object.assign(Object.assign({}, item), { countTime: item.endTime - item.startTime }));
|
|
1974
2273
|
}
|
|
1975
2274
|
}
|
|
1976
2275
|
_emitError(item) {
|
|
1977
|
-
const
|
|
1978
|
-
const storageItem = this._storageLoadItemMap[
|
|
2276
|
+
const assetId = getAssetIdFromElement(item.element);
|
|
2277
|
+
const storageItem = this._storageLoadItemMap[assetId];
|
|
1979
2278
|
if (storageItem) {
|
|
1980
2279
|
if (storageItem.startTime < item.startTime) {
|
|
1981
|
-
this._storageLoadItemMap[
|
|
2280
|
+
this._storageLoadItemMap[assetId] = item;
|
|
1982
2281
|
this.trigger("error", Object.assign(Object.assign({}, item), { countTime: item.endTime - item.startTime }));
|
|
1983
2282
|
}
|
|
1984
2283
|
} else {
|
|
1985
|
-
this._storageLoadItemMap[
|
|
2284
|
+
this._storageLoadItemMap[assetId] = item;
|
|
1986
2285
|
this.trigger("error", Object.assign(Object.assign({}, item), { countTime: item.endTime - item.startTime }));
|
|
1987
2286
|
}
|
|
1988
2287
|
}
|
|
1989
2288
|
_loadResource(element, assets) {
|
|
1990
2289
|
const item = this._createLoadItem(element);
|
|
1991
|
-
|
|
2290
|
+
const assetId = getAssetIdFromElement(element);
|
|
2291
|
+
this._currentLoadItemMap[assetId] = item;
|
|
1992
2292
|
const loadFunc = this._loadFuncMap[element.type];
|
|
1993
2293
|
if (typeof loadFunc === "function") {
|
|
1994
2294
|
item.startTime = Date.now();
|
|
@@ -2008,7 +2308,8 @@ var iDrawCore = function(exports) {
|
|
|
2008
2308
|
}
|
|
2009
2309
|
_isExistingErrorStorage(element) {
|
|
2010
2310
|
var _a;
|
|
2011
|
-
const
|
|
2311
|
+
const assetId = getAssetIdFromElement(element);
|
|
2312
|
+
const existItem = (_a = this._currentLoadItemMap) === null || _a === void 0 ? void 0 : _a[assetId];
|
|
2012
2313
|
if (existItem && existItem.status === "error" && existItem.source && existItem.source === this._getLoadElementSource(element)) {
|
|
2013
2314
|
return true;
|
|
2014
2315
|
}
|
|
@@ -2019,13 +2320,13 @@ var iDrawCore = function(exports) {
|
|
|
2019
2320
|
return;
|
|
2020
2321
|
}
|
|
2021
2322
|
if (supportElementTypes.includes(element.type)) {
|
|
2022
|
-
|
|
2023
|
-
this._loadResource(elem, assets);
|
|
2323
|
+
this._loadResource(element, assets);
|
|
2024
2324
|
}
|
|
2025
2325
|
}
|
|
2026
|
-
getContent(
|
|
2326
|
+
getContent(element) {
|
|
2027
2327
|
var _a, _b;
|
|
2028
|
-
|
|
2328
|
+
const assetId = getAssetIdFromElement(element);
|
|
2329
|
+
return ((_b = (_a = this._storageLoadItemMap) === null || _a === void 0 ? void 0 : _a[assetId]) === null || _b === void 0 ? void 0 : _b.content) || null;
|
|
2029
2330
|
}
|
|
2030
2331
|
}
|
|
2031
2332
|
class Renderer extends EventEmitter {
|
|
@@ -2357,7 +2658,7 @@ var iDrawCore = function(exports) {
|
|
|
2357
2658
|
const { renderer, viewContent, beforeDrawFrame, afterDrawFrame } = this._opts;
|
|
2358
2659
|
if (snapshot) {
|
|
2359
2660
|
const { scale, offsetTop, offsetBottom, offsetLeft, offsetRight, width, height, contextHeight, contextWidth, devicePixelRatio } = snapshot.activeStore;
|
|
2360
|
-
const { viewContext, helperContext, boardContext } = viewContent;
|
|
2661
|
+
const { underContext, viewContext, helperContext, boardContext } = viewContent;
|
|
2361
2662
|
if (snapshot === null || snapshot === void 0 ? void 0 : snapshot.activeStore.data) {
|
|
2362
2663
|
renderer.drawData(snapshot.activeStore.data, {
|
|
2363
2664
|
viewScaleInfo: {
|
|
@@ -2378,8 +2679,10 @@ var iDrawCore = function(exports) {
|
|
|
2378
2679
|
}
|
|
2379
2680
|
beforeDrawFrame({ snapshot });
|
|
2380
2681
|
boardContext.clearRect(0, 0, width, height);
|
|
2682
|
+
boardContext.drawImage(underContext.canvas, 0, 0, width, height);
|
|
2381
2683
|
boardContext.drawImage(viewContext.canvas, 0, 0, width, height);
|
|
2382
2684
|
boardContext.drawImage(helperContext.canvas, 0, 0, width, height);
|
|
2685
|
+
underContext.clearRect(0, 0, width, height);
|
|
2383
2686
|
viewContext.clearRect(0, 0, width, height);
|
|
2384
2687
|
helperContext.clearRect(0, 0, width, height);
|
|
2385
2688
|
afterDrawFrame({ snapshot });
|
|
@@ -2435,11 +2738,13 @@ var iDrawCore = function(exports) {
|
|
|
2435
2738
|
const originViewSize = sharer.getActiveViewSizeInfo();
|
|
2436
2739
|
const newViewSize = Object.assign(Object.assign({}, originViewSize), viewSize);
|
|
2437
2740
|
const { width, height, devicePixelRatio } = newViewSize;
|
|
2438
|
-
const { boardContext, helperContext, viewContext } = this._opts.viewContent;
|
|
2741
|
+
const { underContext, boardContext, helperContext, viewContext } = this._opts.viewContent;
|
|
2439
2742
|
boardContext.canvas.width = width * devicePixelRatio;
|
|
2440
2743
|
boardContext.canvas.height = height * devicePixelRatio;
|
|
2441
2744
|
boardContext.canvas.style.width = `${width}px`;
|
|
2442
2745
|
boardContext.canvas.style.height = `${height}px`;
|
|
2746
|
+
underContext.canvas.width = width * devicePixelRatio;
|
|
2747
|
+
underContext.canvas.height = height * devicePixelRatio;
|
|
2443
2748
|
helperContext.canvas.width = width * devicePixelRatio;
|
|
2444
2749
|
helperContext.canvas.height = height * devicePixelRatio;
|
|
2445
2750
|
viewContext.canvas.width = width * devicePixelRatio;
|
|
@@ -2668,6 +2973,9 @@ var iDrawCore = function(exports) {
|
|
|
2668
2973
|
getSharer() {
|
|
2669
2974
|
return this._sharer;
|
|
2670
2975
|
}
|
|
2976
|
+
getViewer() {
|
|
2977
|
+
return this._viewer;
|
|
2978
|
+
}
|
|
2671
2979
|
setData(data) {
|
|
2672
2980
|
const sharer = this._sharer;
|
|
2673
2981
|
this._sharer.setActiveStorage("data", data);
|
|
@@ -2687,9 +2995,9 @@ var iDrawCore = function(exports) {
|
|
|
2687
2995
|
return data;
|
|
2688
2996
|
}
|
|
2689
2997
|
use(middleware) {
|
|
2690
|
-
const { viewContent } = this._opts;
|
|
2998
|
+
const { viewContent, container } = this._opts;
|
|
2691
2999
|
const { _sharer: sharer, _viewer: viewer, _calculator: calculator, _eventHub: eventHub } = this;
|
|
2692
|
-
const obj = middleware({ viewContent, sharer, viewer, calculator, eventHub });
|
|
3000
|
+
const obj = middleware({ viewContent, sharer, viewer, calculator, eventHub, container });
|
|
2693
3001
|
this._middlewares.push(middleware);
|
|
2694
3002
|
this._activeMiddlewareObjs.push(obj);
|
|
2695
3003
|
}
|
|
@@ -2717,7 +3025,8 @@ var iDrawCore = function(exports) {
|
|
|
2717
3025
|
}
|
|
2718
3026
|
clear() {
|
|
2719
3027
|
const { viewContent } = this._opts;
|
|
2720
|
-
const { helperContext, viewContext, boardContext } = viewContent;
|
|
3028
|
+
const { underContext, helperContext, viewContext, boardContext } = viewContent;
|
|
3029
|
+
underContext.clearRect(0, 0, underContext.canvas.width, underContext.canvas.height);
|
|
2721
3030
|
helperContext.clearRect(0, 0, helperContext.canvas.width, helperContext.canvas.height);
|
|
2722
3031
|
viewContext.clearRect(0, 0, viewContext.canvas.width, viewContext.canvas.height);
|
|
2723
3032
|
boardContext.clearRect(0, 0, boardContext.canvas.width, boardContext.canvas.height);
|
|
@@ -2852,11 +3161,11 @@ var iDrawCore = function(exports) {
|
|
|
2852
3161
|
const resizeControllerBorderWidth = 2;
|
|
2853
3162
|
const wrapperColor = "#1973ba";
|
|
2854
3163
|
function drawVertexes(ctx, vertexes, opts) {
|
|
2855
|
-
const { borderColor, borderWidth: borderWidth2, background, lineDash } = opts;
|
|
3164
|
+
const { borderColor: borderColor2, borderWidth: borderWidth2, background: background2, lineDash } = opts;
|
|
2856
3165
|
ctx.setLineDash([]);
|
|
2857
3166
|
ctx.lineWidth = borderWidth2;
|
|
2858
|
-
ctx.strokeStyle =
|
|
2859
|
-
ctx.fillStyle =
|
|
3167
|
+
ctx.strokeStyle = borderColor2;
|
|
3168
|
+
ctx.fillStyle = background2;
|
|
2860
3169
|
ctx.setLineDash(lineDash);
|
|
2861
3170
|
ctx.beginPath();
|
|
2862
3171
|
ctx.moveTo(vertexes[0].x, vertexes[0].y);
|
|
@@ -2883,10 +3192,6 @@ var iDrawCore = function(exports) {
|
|
|
2883
3192
|
const wrapperOpts = { borderColor: wrapperColor, borderWidth: 1, background: "transparent", lineDash: [] };
|
|
2884
3193
|
const ctrlOpts = { ...wrapperOpts, borderWidth: resizeControllerBorderWidth, background: "#FFFFFF" };
|
|
2885
3194
|
drawVertexes(ctx, calcViewVertexes(elementWrapper, opts), wrapperOpts);
|
|
2886
|
-
drawVertexes(ctx, calcViewVertexes(left.vertexes, opts), ctrlOpts);
|
|
2887
|
-
drawVertexes(ctx, calcViewVertexes(right.vertexes, opts), ctrlOpts);
|
|
2888
|
-
drawVertexes(ctx, calcViewVertexes(top.vertexes, opts), ctrlOpts);
|
|
2889
|
-
drawVertexes(ctx, calcViewVertexes(bottom.vertexes, opts), ctrlOpts);
|
|
2890
3195
|
drawVertexes(ctx, calcViewVertexes(topLeft.vertexes, opts), ctrlOpts);
|
|
2891
3196
|
drawVertexes(ctx, calcViewVertexes(topRight.vertexes, opts), ctrlOpts);
|
|
2892
3197
|
drawVertexes(ctx, calcViewVertexes(bottomLeft.vertexes, opts), ctrlOpts);
|
|
@@ -3676,12 +3981,147 @@ var iDrawCore = function(exports) {
|
|
|
3676
3981
|
moveY
|
|
3677
3982
|
};
|
|
3678
3983
|
}
|
|
3984
|
+
const middlewareEventTextEdit = "@middleware/text-edit";
|
|
3985
|
+
const defaultElementDetail = getDefaultElementDetailConfig();
|
|
3986
|
+
const MiddlewareTextEditor = (opts) => {
|
|
3987
|
+
const key2 = "SELECT";
|
|
3988
|
+
const { eventHub, viewContent, viewer } = opts;
|
|
3989
|
+
const canvas = viewContent.boardContext.canvas;
|
|
3990
|
+
const textarea = document.createElement("textarea");
|
|
3991
|
+
const canvasWrapper = document.createElement("div");
|
|
3992
|
+
const container = opts.container || document.body;
|
|
3993
|
+
const mask = document.createElement("div");
|
|
3994
|
+
let activeElem = null;
|
|
3995
|
+
canvasWrapper.appendChild(textarea);
|
|
3996
|
+
canvasWrapper.style.position = "absolute";
|
|
3997
|
+
mask.appendChild(canvasWrapper);
|
|
3998
|
+
mask.style.position = "fixed";
|
|
3999
|
+
mask.style.top = "0";
|
|
4000
|
+
mask.style.bottom = "0";
|
|
4001
|
+
mask.style.left = "0";
|
|
4002
|
+
mask.style.right = "0";
|
|
4003
|
+
mask.style.display = "none";
|
|
4004
|
+
container.appendChild(mask);
|
|
4005
|
+
const showTextArea = (e) => {
|
|
4006
|
+
resetCanvasWrapper();
|
|
4007
|
+
resetTextArea(e);
|
|
4008
|
+
mask.style.display = "block";
|
|
4009
|
+
};
|
|
4010
|
+
const hideTextArea = () => {
|
|
4011
|
+
mask.style.display = "none";
|
|
4012
|
+
activeElem = null;
|
|
4013
|
+
};
|
|
4014
|
+
const getCanvasRect = () => {
|
|
4015
|
+
const clientRect = canvas.getBoundingClientRect();
|
|
4016
|
+
const { left, top, width, height } = clientRect;
|
|
4017
|
+
return { left, top, width, height };
|
|
4018
|
+
};
|
|
4019
|
+
const createBox = (opts2) => {
|
|
4020
|
+
const { size, parent } = opts2;
|
|
4021
|
+
const div = document.createElement("div");
|
|
4022
|
+
const { x: x2, y: y2, w: w2, h: h2 } = size;
|
|
4023
|
+
const angle2 = limitAngle(size.angle || 0);
|
|
4024
|
+
div.style.position = "absolute";
|
|
4025
|
+
div.style.left = `${x2}px`;
|
|
4026
|
+
div.style.top = `${y2}px`;
|
|
4027
|
+
div.style.width = `${w2}px`;
|
|
4028
|
+
div.style.height = `${h2}px`;
|
|
4029
|
+
div.style.transform = `rotate(${angle2}deg)`;
|
|
4030
|
+
parent.appendChild(div);
|
|
4031
|
+
return div;
|
|
4032
|
+
};
|
|
4033
|
+
const resetTextArea = (e) => {
|
|
4034
|
+
const { viewScaleInfo, element, groupQueue } = e;
|
|
4035
|
+
const { scale, offsetTop, offsetLeft } = viewScaleInfo;
|
|
4036
|
+
if (canvasWrapper.children) {
|
|
4037
|
+
Array.from(canvasWrapper.children).forEach((child) => {
|
|
4038
|
+
child.remove();
|
|
4039
|
+
});
|
|
4040
|
+
}
|
|
4041
|
+
let parent = canvasWrapper;
|
|
4042
|
+
for (let i = 0; i < groupQueue.length; i++) {
|
|
4043
|
+
const group = groupQueue[i];
|
|
4044
|
+
const { x: x2, y: y2, w: w2, h: h2 } = group;
|
|
4045
|
+
const angle2 = limitAngle(group.angle || 0);
|
|
4046
|
+
const size = {
|
|
4047
|
+
x: x2 * scale,
|
|
4048
|
+
y: y2 * scale,
|
|
4049
|
+
w: w2 * scale,
|
|
4050
|
+
h: h2 * scale,
|
|
4051
|
+
angle: angle2
|
|
4052
|
+
};
|
|
4053
|
+
if (i === 0) {
|
|
4054
|
+
size.x += offsetLeft;
|
|
4055
|
+
size.y += offsetTop;
|
|
4056
|
+
}
|
|
4057
|
+
parent = createBox({ size, parent });
|
|
4058
|
+
}
|
|
4059
|
+
const detail = {
|
|
4060
|
+
...defaultElementDetail,
|
|
4061
|
+
...element.detail
|
|
4062
|
+
};
|
|
4063
|
+
textarea.style.position = "absolute";
|
|
4064
|
+
textarea.style.left = `${element.x * scale}px`;
|
|
4065
|
+
textarea.style.top = `${element.y * scale}px`;
|
|
4066
|
+
textarea.style.width = `${element.w * scale}px`;
|
|
4067
|
+
textarea.style.height = `${element.h * scale}px`;
|
|
4068
|
+
textarea.style.transform = `rotate(${limitAngle(element.angle || 0)}deg)`;
|
|
4069
|
+
textarea.style.border = "none";
|
|
4070
|
+
textarea.style.resize = "none";
|
|
4071
|
+
textarea.style.overflow = "hidden";
|
|
4072
|
+
textarea.style.wordBreak = "break-all";
|
|
4073
|
+
textarea.style.background = "#FFFFFF";
|
|
4074
|
+
textarea.style.color = "#333333";
|
|
4075
|
+
textarea.style.fontSize = `${detail.fontSize * scale}px`;
|
|
4076
|
+
textarea.style.lineHeight = `${detail.lineHeight * scale}px`;
|
|
4077
|
+
textarea.style.fontFamily = detail.fontFamily;
|
|
4078
|
+
textarea.style.fontWeight = `${detail.fontWeight}`;
|
|
4079
|
+
textarea.value = detail.text || "";
|
|
4080
|
+
parent.appendChild(textarea);
|
|
4081
|
+
};
|
|
4082
|
+
const resetCanvasWrapper = () => {
|
|
4083
|
+
const { left, top, width, height } = getCanvasRect();
|
|
4084
|
+
canvasWrapper.style.position = "absolute";
|
|
4085
|
+
canvasWrapper.style.overflow = "hidden";
|
|
4086
|
+
canvasWrapper.style.top = `${top}px`;
|
|
4087
|
+
canvasWrapper.style.left = `${left}px`;
|
|
4088
|
+
canvasWrapper.style.width = `${width}px`;
|
|
4089
|
+
canvasWrapper.style.height = `${height}px`;
|
|
4090
|
+
};
|
|
4091
|
+
mask.addEventListener("click", () => {
|
|
4092
|
+
hideTextArea();
|
|
4093
|
+
});
|
|
4094
|
+
textarea.addEventListener("click", (e) => {
|
|
4095
|
+
e.stopPropagation();
|
|
4096
|
+
});
|
|
4097
|
+
textarea.addEventListener("input", (e) => {
|
|
4098
|
+
if (activeElem) {
|
|
4099
|
+
activeElem.detail.text = e.target.value || "";
|
|
4100
|
+
viewer.drawFrame();
|
|
4101
|
+
}
|
|
4102
|
+
});
|
|
4103
|
+
textarea.addEventListener("blur", () => {
|
|
4104
|
+
hideTextArea();
|
|
4105
|
+
});
|
|
4106
|
+
eventHub.on(middlewareEventTextEdit, (e) => {
|
|
4107
|
+
var _a;
|
|
4108
|
+
if ((e == null ? void 0 : e.element) && ((_a = e == null ? void 0 : e.element) == null ? void 0 : _a.type) === "text") {
|
|
4109
|
+
activeElem = e.element;
|
|
4110
|
+
}
|
|
4111
|
+
showTextArea(e);
|
|
4112
|
+
});
|
|
4113
|
+
return {
|
|
4114
|
+
mode: key2,
|
|
4115
|
+
isDefault: true
|
|
4116
|
+
};
|
|
4117
|
+
};
|
|
4118
|
+
const middlewareEventSelect = "@middleware/select";
|
|
3679
4119
|
const MiddlewareSelector = (opts) => {
|
|
3680
4120
|
const { viewer, sharer, viewContent, calculator, eventHub } = opts;
|
|
3681
4121
|
const { helperContext } = viewContent;
|
|
3682
4122
|
let prevPoint = null;
|
|
3683
4123
|
let inBusyMode = null;
|
|
3684
|
-
eventHub.on(
|
|
4124
|
+
eventHub.on(middlewareEventSelect, ({ uuids }) => {
|
|
3685
4125
|
const actionType = sharer.getSharedStorage(keyActionType);
|
|
3686
4126
|
const data = sharer.getActiveStorage("data");
|
|
3687
4127
|
const elements = findElementsFromList(uuids, (data == null ? void 0 : data.elements) || []);
|
|
@@ -3746,7 +4186,7 @@ var iDrawCore = function(exports) {
|
|
|
3746
4186
|
sharer.setSharedStorage(keySelectedElementController, null);
|
|
3747
4187
|
}
|
|
3748
4188
|
if ((opts2 == null ? void 0 : opts2.triggerEvent) === true) {
|
|
3749
|
-
eventHub.trigger(
|
|
4189
|
+
eventHub.trigger(middlewareEventSelect, { uuids: list.map((elem) => elem.uuid) });
|
|
3750
4190
|
}
|
|
3751
4191
|
};
|
|
3752
4192
|
const pointTargetBaseOptions = () => {
|
|
@@ -4048,7 +4488,7 @@ var iDrawCore = function(exports) {
|
|
|
4048
4488
|
viewer.drawFrame();
|
|
4049
4489
|
},
|
|
4050
4490
|
doubleClick(e) {
|
|
4051
|
-
var _a;
|
|
4491
|
+
var _a, _b;
|
|
4052
4492
|
const target = getPointTarget(e.point, pointTargetBaseOptions());
|
|
4053
4493
|
if (target.elements.length === 1 && ((_a = target.elements[0]) == null ? void 0 : _a.type) === "group") {
|
|
4054
4494
|
const pushResult = pushGroupQueue(target.elements[0]);
|
|
@@ -4057,6 +4497,12 @@ var iDrawCore = function(exports) {
|
|
|
4057
4497
|
viewer.drawFrame();
|
|
4058
4498
|
return;
|
|
4059
4499
|
}
|
|
4500
|
+
} else if (target.elements.length === 1 && ((_b = target.elements[0]) == null ? void 0 : _b.type) === "text") {
|
|
4501
|
+
eventHub.trigger(middlewareEventTextEdit, {
|
|
4502
|
+
element: target.elements[0],
|
|
4503
|
+
groupQueue: sharer.getSharedStorage(keyGroupQueue) || [],
|
|
4504
|
+
viewScaleInfo: sharer.getActiveViewScaleInfo()
|
|
4505
|
+
});
|
|
4060
4506
|
}
|
|
4061
4507
|
sharer.setSharedStorage(keyActionType, null);
|
|
4062
4508
|
},
|
|
@@ -4117,9 +4563,15 @@ var iDrawCore = function(exports) {
|
|
|
4117
4563
|
const keyPrevPoint = Symbol(`${key}_prevPoint`);
|
|
4118
4564
|
const keyActivePoint = Symbol(`${key}_activePoint`);
|
|
4119
4565
|
const keyActiveThumbType = Symbol(`${key}_activeThumbType`);
|
|
4566
|
+
const minScrollerWidth = 12;
|
|
4120
4567
|
const scrollerLineWidth = 16;
|
|
4121
|
-
const scrollerAlpha = 0.12;
|
|
4122
4568
|
const scrollerThumbAlpha = 0.36;
|
|
4569
|
+
const scrollConfig = {
|
|
4570
|
+
width: minScrollerWidth,
|
|
4571
|
+
thumbColor: "#000000AA",
|
|
4572
|
+
scrollBarColor: "#FFFFFF60",
|
|
4573
|
+
showScrollBar: false
|
|
4574
|
+
};
|
|
4123
4575
|
function isPointAtRect(helperContext, p, rect) {
|
|
4124
4576
|
const ctx = helperContext;
|
|
4125
4577
|
const { x: x2, y: y2, w: w2, h: h2 } = rect;
|
|
@@ -4156,58 +4608,59 @@ var iDrawCore = function(exports) {
|
|
|
4156
4608
|
const { width, height } = viewSizeInfo;
|
|
4157
4609
|
const { offsetTop, offsetBottom, offsetLeft, offsetRight } = viewScaleInfo;
|
|
4158
4610
|
const sliderMinSize = scrollerLineWidth * 2.5;
|
|
4159
|
-
const
|
|
4611
|
+
const lineSize2 = scrollerLineWidth;
|
|
4160
4612
|
let xSize = 0;
|
|
4161
4613
|
let ySize = 0;
|
|
4162
|
-
xSize = Math.max(sliderMinSize, width - (Math.abs(offsetLeft) + Math.abs(offsetRight)));
|
|
4614
|
+
xSize = Math.max(sliderMinSize, width - lineSize2 * 2 - (Math.abs(offsetLeft) + Math.abs(offsetRight)));
|
|
4163
4615
|
if (xSize >= width) {
|
|
4164
4616
|
xSize = width;
|
|
4165
4617
|
}
|
|
4166
|
-
ySize = Math.max(sliderMinSize, height - (Math.abs(offsetTop) + Math.abs(offsetBottom)));
|
|
4618
|
+
ySize = Math.max(sliderMinSize, height - lineSize2 * 2 - (Math.abs(offsetTop) + Math.abs(offsetBottom)));
|
|
4167
4619
|
if (ySize >= height) {
|
|
4168
4620
|
ySize = height;
|
|
4169
4621
|
}
|
|
4170
|
-
const xStart =
|
|
4171
|
-
const xEnd = width - xSize -
|
|
4622
|
+
const xStart = lineSize2;
|
|
4623
|
+
const xEnd = width - xSize - lineSize2;
|
|
4172
4624
|
let translateX = xStart;
|
|
4173
4625
|
if (offsetLeft > 0) {
|
|
4174
4626
|
translateX = xStart;
|
|
4175
4627
|
} else if (offsetRight > 0) {
|
|
4176
4628
|
translateX = xEnd;
|
|
4177
4629
|
} else if (offsetLeft <= 0 && xSize > 0 && !(offsetLeft === 0 && offsetRight === 0)) {
|
|
4178
|
-
translateX =
|
|
4179
|
-
translateX = Math.min(Math.max(0, translateX -
|
|
4630
|
+
translateX = xStart + (width - xSize) * Math.abs(offsetLeft) / (Math.abs(offsetLeft) + Math.abs(offsetRight));
|
|
4631
|
+
translateX = Math.min(Math.max(0, translateX - xStart), width - xSize);
|
|
4180
4632
|
}
|
|
4181
|
-
const yStart =
|
|
4182
|
-
const yEnd = height - ySize -
|
|
4633
|
+
const yStart = lineSize2;
|
|
4634
|
+
const yEnd = height - ySize - lineSize2;
|
|
4183
4635
|
let translateY = yStart;
|
|
4184
4636
|
if (offsetTop > 0) {
|
|
4185
4637
|
translateY = yStart;
|
|
4186
4638
|
} else if (offsetBottom > 0) {
|
|
4187
4639
|
translateY = yEnd;
|
|
4188
4640
|
} else if (offsetTop <= 0 && ySize > 0 && !(offsetTop === 0 && offsetBottom === 0)) {
|
|
4189
|
-
translateY =
|
|
4190
|
-
translateY = Math.min(Math.max(0, translateY -
|
|
4641
|
+
translateY = yStart + (height - ySize) * Math.abs(offsetTop) / (Math.abs(offsetTop) + Math.abs(offsetBottom));
|
|
4642
|
+
translateY = Math.min(Math.max(0, translateY - yStart), height - ySize);
|
|
4191
4643
|
}
|
|
4192
4644
|
const xThumbRect = {
|
|
4193
4645
|
x: translateX,
|
|
4194
|
-
y: height -
|
|
4646
|
+
y: height - lineSize2,
|
|
4195
4647
|
w: xSize,
|
|
4196
|
-
h:
|
|
4648
|
+
h: lineSize2
|
|
4197
4649
|
};
|
|
4198
4650
|
const yThumbRect = {
|
|
4199
|
-
x: width -
|
|
4651
|
+
x: width - lineSize2,
|
|
4200
4652
|
y: translateY,
|
|
4201
|
-
w:
|
|
4653
|
+
w: lineSize2,
|
|
4202
4654
|
h: ySize
|
|
4203
4655
|
};
|
|
4204
4656
|
const scrollWrapper = {
|
|
4205
|
-
lineSize,
|
|
4657
|
+
lineSize: lineSize2,
|
|
4206
4658
|
xSize,
|
|
4207
4659
|
ySize,
|
|
4208
4660
|
translateY,
|
|
4209
4661
|
translateX,
|
|
4210
|
-
|
|
4662
|
+
thumbColor: scrollConfig.thumbColor,
|
|
4663
|
+
scrollBarColor: scrollConfig.scrollBarColor,
|
|
4211
4664
|
xThumbRect,
|
|
4212
4665
|
yThumbRect
|
|
4213
4666
|
};
|
|
@@ -4215,47 +4668,54 @@ var iDrawCore = function(exports) {
|
|
|
4215
4668
|
}
|
|
4216
4669
|
function drawScrollerThumb(ctx, opts) {
|
|
4217
4670
|
let { x: x2, y: y2, h: h2, w: w2 } = opts;
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4671
|
+
ctx.save();
|
|
4672
|
+
ctx.shadowColor = "#FFFFFF";
|
|
4673
|
+
ctx.shadowOffsetX = 0;
|
|
4674
|
+
ctx.shadowOffsetY = 0;
|
|
4675
|
+
ctx.shadowBlur = 1;
|
|
4676
|
+
{
|
|
4677
|
+
const { color: color2, axis } = opts;
|
|
4678
|
+
if (axis === "X") {
|
|
4679
|
+
y2 = y2 + h2 / 4 + 0;
|
|
4680
|
+
h2 = h2 / 2;
|
|
4681
|
+
} else if (axis === "Y") {
|
|
4682
|
+
x2 = x2 + w2 / 4 + 0;
|
|
4683
|
+
w2 = w2 / 2;
|
|
4684
|
+
}
|
|
4685
|
+
let r = opts.r;
|
|
4686
|
+
r = Math.min(r, w2 / 2, h2 / 2);
|
|
4687
|
+
if (w2 < r * 2 || h2 < r * 2) {
|
|
4688
|
+
r = 0;
|
|
4689
|
+
}
|
|
4690
|
+
ctx.globalAlpha = scrollerThumbAlpha;
|
|
4691
|
+
ctx.beginPath();
|
|
4692
|
+
ctx.moveTo(x2 + r, y2);
|
|
4693
|
+
ctx.arcTo(x2 + w2, y2, x2 + w2, y2 + h2, r);
|
|
4694
|
+
ctx.arcTo(x2 + w2, y2 + h2, x2, y2 + h2, r);
|
|
4695
|
+
ctx.arcTo(x2, y2 + h2, x2, y2, r);
|
|
4696
|
+
ctx.arcTo(x2, y2, x2 + w2, y2, r);
|
|
4697
|
+
ctx.closePath();
|
|
4698
|
+
ctx.fillStyle = color2;
|
|
4699
|
+
ctx.fill();
|
|
4700
|
+
ctx.globalAlpha = 1;
|
|
4701
|
+
ctx.beginPath();
|
|
4702
|
+
ctx.lineWidth = 1;
|
|
4703
|
+
ctx.strokeStyle = color2;
|
|
4704
|
+
ctx.setLineDash([]);
|
|
4705
|
+
ctx.moveTo(x2 + r, y2);
|
|
4706
|
+
ctx.arcTo(x2 + w2, y2, x2 + w2, y2 + h2, r);
|
|
4707
|
+
ctx.arcTo(x2 + w2, y2 + h2, x2, y2 + h2, r);
|
|
4708
|
+
ctx.arcTo(x2, y2 + h2, x2, y2, r);
|
|
4709
|
+
ctx.arcTo(x2, y2, x2 + w2, y2, r);
|
|
4710
|
+
ctx.closePath();
|
|
4711
|
+
ctx.stroke();
|
|
4712
|
+
}
|
|
4713
|
+
ctx.restore();
|
|
4253
4714
|
}
|
|
4254
4715
|
function drawScrollerInfo(helperContext, opts) {
|
|
4255
4716
|
const ctx = helperContext;
|
|
4256
4717
|
const { viewScaleInfo, viewSizeInfo, scrollInfo } = opts;
|
|
4257
4718
|
const { activeThumbType, prevPoint, activePoint } = scrollInfo;
|
|
4258
|
-
const { width, height } = viewSizeInfo;
|
|
4259
4719
|
const wrapper = calcScrollerInfo(viewScaleInfo, viewSizeInfo);
|
|
4260
4720
|
let xThumbRect = { ...wrapper.xThumbRect };
|
|
4261
4721
|
let yThumbRect = { ...wrapper.yThumbRect };
|
|
@@ -4268,27 +4728,17 @@ var iDrawCore = function(exports) {
|
|
|
4268
4728
|
yThumbRect.y = yThumbRect.y + (activePoint.y - prevPoint.y);
|
|
4269
4729
|
}
|
|
4270
4730
|
}
|
|
4271
|
-
{
|
|
4272
|
-
ctx.globalAlpha = scrollerAlpha;
|
|
4273
|
-
ctx.fillStyle = wrapper.color;
|
|
4274
|
-
ctx.fillRect(0, height - wrapper.lineSize, width, wrapper.lineSize);
|
|
4275
|
-
}
|
|
4276
4731
|
drawScrollerThumb(ctx, {
|
|
4277
4732
|
axis: "X",
|
|
4278
4733
|
...xThumbRect,
|
|
4279
4734
|
r: wrapper.lineSize / 2,
|
|
4280
|
-
color: wrapper.
|
|
4735
|
+
color: wrapper.thumbColor
|
|
4281
4736
|
});
|
|
4282
|
-
{
|
|
4283
|
-
ctx.globalAlpha = scrollerAlpha;
|
|
4284
|
-
ctx.fillStyle = wrapper.color;
|
|
4285
|
-
ctx.fillRect(width - wrapper.lineSize, 0, wrapper.lineSize, height);
|
|
4286
|
-
}
|
|
4287
4737
|
drawScrollerThumb(ctx, {
|
|
4288
4738
|
axis: "Y",
|
|
4289
4739
|
...yThumbRect,
|
|
4290
4740
|
r: wrapper.lineSize / 2,
|
|
4291
|
-
color: wrapper.
|
|
4741
|
+
color: wrapper.thumbColor
|
|
4292
4742
|
});
|
|
4293
4743
|
ctx.globalAlpha = 1;
|
|
4294
4744
|
return {
|
|
@@ -4405,9 +4855,12 @@ var iDrawCore = function(exports) {
|
|
|
4405
4855
|
}
|
|
4406
4856
|
};
|
|
4407
4857
|
};
|
|
4858
|
+
const middlewareEventScale = "@middleware/scale";
|
|
4408
4859
|
const MiddlewareScaler = (opts) => {
|
|
4409
4860
|
const key2 = "SCALE";
|
|
4410
|
-
const { viewer, sharer } = opts;
|
|
4861
|
+
const { viewer, sharer, eventHub } = opts;
|
|
4862
|
+
const maxScale = 50;
|
|
4863
|
+
const minScale = 0.05;
|
|
4411
4864
|
return {
|
|
4412
4865
|
mode: key2,
|
|
4413
4866
|
isDefault: true,
|
|
@@ -4420,23 +4873,258 @@ var iDrawCore = function(exports) {
|
|
|
4420
4873
|
} else if (deltaY > 0) {
|
|
4421
4874
|
newScaleNum = scale * 0.9;
|
|
4422
4875
|
}
|
|
4876
|
+
if (newScaleNum < minScale || newScaleNum > maxScale) {
|
|
4877
|
+
return;
|
|
4878
|
+
}
|
|
4423
4879
|
const { moveX, moveY } = viewer.scale({ scale: newScaleNum, point });
|
|
4424
4880
|
viewer.scroll({ moveX, moveY });
|
|
4425
4881
|
viewer.drawFrame();
|
|
4882
|
+
const scaleNum = formatNumber(scale);
|
|
4883
|
+
eventHub.trigger(middlewareEventScale, { scale: scaleNum });
|
|
4884
|
+
}
|
|
4885
|
+
};
|
|
4886
|
+
};
|
|
4887
|
+
const rulerSize = 16;
|
|
4888
|
+
const background = "#FFFFFFA8";
|
|
4889
|
+
const borderColor = "#00000080";
|
|
4890
|
+
const scaleColor = "#000000";
|
|
4891
|
+
const textColor = "#00000080";
|
|
4892
|
+
const fontFamily = "monospace";
|
|
4893
|
+
const fontSize = 10;
|
|
4894
|
+
const fontWeight = 100;
|
|
4895
|
+
const gridColor = "#AAAAAA30";
|
|
4896
|
+
const gridKeyColor = "#AAAAAA70";
|
|
4897
|
+
const lineSize = 1;
|
|
4898
|
+
function calcRulerScaleList(opts) {
|
|
4899
|
+
const { scale, viewLength, viewOffset } = opts;
|
|
4900
|
+
const list = [];
|
|
4901
|
+
let rulerUnit = 10;
|
|
4902
|
+
rulerUnit = formatNumber(rulerUnit / scale, { decimalPlaces: 0 });
|
|
4903
|
+
rulerUnit = Math.max(10, Math.min(rulerUnit, 1e3));
|
|
4904
|
+
const rulerKeyUnit = rulerUnit * 10;
|
|
4905
|
+
const rulerSubKeyUnit = rulerUnit * 5;
|
|
4906
|
+
let index = 0;
|
|
4907
|
+
const viewUnit = rulerUnit * scale;
|
|
4908
|
+
const startNum = 0 - viewOffset;
|
|
4909
|
+
const startPosition = 0;
|
|
4910
|
+
const remainderNum = startNum % viewUnit;
|
|
4911
|
+
const firstNum = (startNum - remainderNum + viewUnit) / scale;
|
|
4912
|
+
const firstPosition = startPosition + (viewUnit - remainderNum);
|
|
4913
|
+
while (firstPosition + index * viewUnit < viewLength) {
|
|
4914
|
+
const num = formatNumber(firstNum + index * rulerUnit, { decimalPlaces: 0 });
|
|
4915
|
+
const position = formatNumber(firstPosition + index * viewUnit, { decimalPlaces: 0 });
|
|
4916
|
+
const rulerScale = {
|
|
4917
|
+
num,
|
|
4918
|
+
position,
|
|
4919
|
+
showNum: num % rulerKeyUnit === 0,
|
|
4920
|
+
isKeyNum: num % rulerKeyUnit === 0,
|
|
4921
|
+
isSubKeyNum: num % rulerSubKeyUnit === 0
|
|
4922
|
+
};
|
|
4923
|
+
list.push(rulerScale);
|
|
4924
|
+
index++;
|
|
4925
|
+
}
|
|
4926
|
+
return list;
|
|
4927
|
+
}
|
|
4928
|
+
function calcXRulerScaleList(opts) {
|
|
4929
|
+
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
4930
|
+
const { scale, offsetLeft } = viewScaleInfo;
|
|
4931
|
+
const { width } = viewSizeInfo;
|
|
4932
|
+
return calcRulerScaleList({
|
|
4933
|
+
axis: "X",
|
|
4934
|
+
scale,
|
|
4935
|
+
viewLength: width,
|
|
4936
|
+
viewOffset: offsetLeft
|
|
4937
|
+
});
|
|
4938
|
+
}
|
|
4939
|
+
function calcYRulerScaleList(opts) {
|
|
4940
|
+
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
4941
|
+
const { scale, offsetTop } = viewScaleInfo;
|
|
4942
|
+
const { height } = viewSizeInfo;
|
|
4943
|
+
return calcRulerScaleList({
|
|
4944
|
+
axis: "Y",
|
|
4945
|
+
scale,
|
|
4946
|
+
viewLength: height,
|
|
4947
|
+
viewOffset: offsetTop
|
|
4948
|
+
});
|
|
4949
|
+
}
|
|
4950
|
+
function drawXRuler(ctx, opts) {
|
|
4951
|
+
const { scaleList } = opts;
|
|
4952
|
+
const scaleDrawStart = rulerSize;
|
|
4953
|
+
const scaleDrawEnd = rulerSize * 4 / 5;
|
|
4954
|
+
const subKeyScaleDrawEnd = rulerSize * 2 / 5;
|
|
4955
|
+
const keyScaleDrawEnd = rulerSize * 1 / 5;
|
|
4956
|
+
const fontStart = rulerSize / 5;
|
|
4957
|
+
for (let i = 0; i < scaleList.length; i++) {
|
|
4958
|
+
const item = scaleList[i];
|
|
4959
|
+
if (item.position < rulerSize) {
|
|
4960
|
+
continue;
|
|
4961
|
+
}
|
|
4962
|
+
ctx.beginPath();
|
|
4963
|
+
ctx.moveTo(item.position, scaleDrawStart);
|
|
4964
|
+
ctx.lineTo(item.position, item.isKeyNum ? keyScaleDrawEnd : item.isSubKeyNum ? subKeyScaleDrawEnd : scaleDrawEnd);
|
|
4965
|
+
ctx.closePath();
|
|
4966
|
+
ctx.lineWidth = lineSize;
|
|
4967
|
+
ctx.setLineDash([]);
|
|
4968
|
+
ctx.fillStyle = scaleColor;
|
|
4969
|
+
ctx.stroke();
|
|
4970
|
+
if (item.isKeyNum) {
|
|
4971
|
+
ctx.fillStyle = textColor;
|
|
4972
|
+
ctx.textBaseline = "top";
|
|
4973
|
+
ctx.$setFont({
|
|
4974
|
+
fontWeight,
|
|
4975
|
+
fontSize,
|
|
4976
|
+
fontFamily
|
|
4977
|
+
});
|
|
4978
|
+
ctx.fillText(`${item.num}`, item.position + fontStart, fontStart);
|
|
4979
|
+
}
|
|
4980
|
+
}
|
|
4981
|
+
}
|
|
4982
|
+
function drawYRuler(ctx, opts) {
|
|
4983
|
+
const { scaleList } = opts;
|
|
4984
|
+
const scaleDrawStart = rulerSize;
|
|
4985
|
+
const scaleDrawEnd = rulerSize * 4 / 5;
|
|
4986
|
+
const subKeyScaleDrawEnd = rulerSize * 2 / 5;
|
|
4987
|
+
const keyScaleDrawEnd = rulerSize * 1 / 5;
|
|
4988
|
+
const fontStart = rulerSize / 5;
|
|
4989
|
+
for (let i = 0; i < scaleList.length; i++) {
|
|
4990
|
+
const item = scaleList[i];
|
|
4991
|
+
if (item.position < rulerSize) {
|
|
4992
|
+
continue;
|
|
4993
|
+
}
|
|
4994
|
+
ctx.beginPath();
|
|
4995
|
+
ctx.moveTo(scaleDrawStart, item.position);
|
|
4996
|
+
ctx.lineTo(item.isKeyNum ? keyScaleDrawEnd : item.isSubKeyNum ? subKeyScaleDrawEnd : scaleDrawEnd, item.position);
|
|
4997
|
+
ctx.closePath();
|
|
4998
|
+
ctx.fillStyle = scaleColor;
|
|
4999
|
+
ctx.lineWidth = lineSize;
|
|
5000
|
+
ctx.setLineDash([]);
|
|
5001
|
+
ctx.stroke();
|
|
5002
|
+
if (item.showNum === true) {
|
|
5003
|
+
const textX = fontStart;
|
|
5004
|
+
const textY = item.position + fontStart;
|
|
5005
|
+
const numText = `${item.num}`;
|
|
5006
|
+
rotateByCenter(ctx, -90, { x: textX, y: textY }, () => {
|
|
5007
|
+
ctx.fillStyle = textColor;
|
|
5008
|
+
ctx.textBaseline = "top";
|
|
5009
|
+
ctx.$setFont({
|
|
5010
|
+
fontWeight,
|
|
5011
|
+
fontSize,
|
|
5012
|
+
fontFamily
|
|
5013
|
+
});
|
|
5014
|
+
ctx.fillText(numText, fontStart + fontSize, item.position + fontStart);
|
|
5015
|
+
});
|
|
5016
|
+
}
|
|
5017
|
+
}
|
|
5018
|
+
}
|
|
5019
|
+
function drawRulerBackground(ctx, opts) {
|
|
5020
|
+
const { viewSizeInfo } = opts;
|
|
5021
|
+
const { width, height } = viewSizeInfo;
|
|
5022
|
+
ctx.beginPath();
|
|
5023
|
+
ctx.moveTo(0, 0);
|
|
5024
|
+
ctx.lineTo(width + 1, 0);
|
|
5025
|
+
ctx.lineTo(width + 1, rulerSize);
|
|
5026
|
+
ctx.lineTo(rulerSize, rulerSize);
|
|
5027
|
+
ctx.lineTo(rulerSize, height + 1);
|
|
5028
|
+
ctx.lineTo(0, height + 1);
|
|
5029
|
+
ctx.lineTo(0, 0);
|
|
5030
|
+
ctx.closePath();
|
|
5031
|
+
ctx.fillStyle = background;
|
|
5032
|
+
ctx.fill();
|
|
5033
|
+
ctx.lineWidth = lineSize;
|
|
5034
|
+
ctx.setLineDash([]);
|
|
5035
|
+
ctx.strokeStyle = borderColor;
|
|
5036
|
+
ctx.stroke();
|
|
5037
|
+
}
|
|
5038
|
+
function drawUnderGrid(ctx, opts) {
|
|
5039
|
+
const { xList, yList, viewSizeInfo } = opts;
|
|
5040
|
+
const { width, height } = viewSizeInfo;
|
|
5041
|
+
for (let i = 0; i < xList.length; i++) {
|
|
5042
|
+
const item = xList[i];
|
|
5043
|
+
ctx.beginPath();
|
|
5044
|
+
ctx.moveTo(item.position, 0);
|
|
5045
|
+
ctx.lineTo(item.position, height);
|
|
5046
|
+
if (item.isKeyNum === true || item.isSubKeyNum === true) {
|
|
5047
|
+
ctx.strokeStyle = gridKeyColor;
|
|
5048
|
+
} else {
|
|
5049
|
+
ctx.strokeStyle = gridColor;
|
|
5050
|
+
}
|
|
5051
|
+
ctx.closePath();
|
|
5052
|
+
ctx.lineWidth = lineSize;
|
|
5053
|
+
ctx.setLineDash([]);
|
|
5054
|
+
ctx.stroke();
|
|
5055
|
+
}
|
|
5056
|
+
for (let i = 0; i < yList.length; i++) {
|
|
5057
|
+
const item = yList[i];
|
|
5058
|
+
ctx.beginPath();
|
|
5059
|
+
ctx.moveTo(0, item.position);
|
|
5060
|
+
ctx.lineTo(width, item.position);
|
|
5061
|
+
if (item.isKeyNum === true || item.isSubKeyNum === true) {
|
|
5062
|
+
ctx.strokeStyle = gridKeyColor;
|
|
5063
|
+
} else {
|
|
5064
|
+
ctx.strokeStyle = gridColor;
|
|
5065
|
+
}
|
|
5066
|
+
ctx.lineWidth = 1;
|
|
5067
|
+
ctx.closePath();
|
|
5068
|
+
ctx.stroke();
|
|
5069
|
+
}
|
|
5070
|
+
}
|
|
5071
|
+
const middlewareEventRuler = "@middleware/show-ruler";
|
|
5072
|
+
const MiddlewareRuler = (opts) => {
|
|
5073
|
+
const key2 = "RULE";
|
|
5074
|
+
const { viewContent, viewer, eventHub } = opts;
|
|
5075
|
+
const { helperContext, underContext } = viewContent;
|
|
5076
|
+
let show = true;
|
|
5077
|
+
let showGrid = true;
|
|
5078
|
+
eventHub.on(middlewareEventRuler, (e) => {
|
|
5079
|
+
if (typeof (e == null ? void 0 : e.show) === "boolean") {
|
|
5080
|
+
show = e.show;
|
|
5081
|
+
}
|
|
5082
|
+
if (typeof (e == null ? void 0 : e.showGrid) === "boolean") {
|
|
5083
|
+
showGrid = e.showGrid;
|
|
5084
|
+
}
|
|
5085
|
+
if (typeof (e == null ? void 0 : e.show) === "boolean" || typeof (e == null ? void 0 : e.showGrid) === "boolean") {
|
|
5086
|
+
viewer.drawFrame();
|
|
5087
|
+
}
|
|
5088
|
+
});
|
|
5089
|
+
return {
|
|
5090
|
+
mode: key2,
|
|
5091
|
+
isDefault: true,
|
|
5092
|
+
beforeDrawFrame: ({ snapshot }) => {
|
|
5093
|
+
if (show === true) {
|
|
5094
|
+
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
5095
|
+
const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
|
|
5096
|
+
drawRulerBackground(helperContext, { viewScaleInfo, viewSizeInfo });
|
|
5097
|
+
const xList = calcXRulerScaleList({ viewScaleInfo, viewSizeInfo });
|
|
5098
|
+
drawXRuler(helperContext, { scaleList: xList });
|
|
5099
|
+
const yList = calcYRulerScaleList({ viewScaleInfo, viewSizeInfo });
|
|
5100
|
+
drawYRuler(helperContext, { scaleList: yList });
|
|
5101
|
+
if (showGrid === true) {
|
|
5102
|
+
drawUnderGrid(underContext, {
|
|
5103
|
+
xList,
|
|
5104
|
+
yList,
|
|
5105
|
+
viewScaleInfo,
|
|
5106
|
+
viewSizeInfo
|
|
5107
|
+
});
|
|
5108
|
+
}
|
|
5109
|
+
}
|
|
4426
5110
|
}
|
|
4427
5111
|
};
|
|
4428
5112
|
};
|
|
4429
5113
|
class Core {
|
|
4430
5114
|
constructor(container, opts) {
|
|
5115
|
+
__privateAdd(this, _initContainer);
|
|
5116
|
+
__privateAdd(this, _board, void 0);
|
|
5117
|
+
// #opts: CoreOptions;
|
|
5118
|
+
// #canvas: HTMLCanvasElement;
|
|
5119
|
+
__privateAdd(this, _container, void 0);
|
|
4431
5120
|
const { devicePixelRatio = 1, width, height } = opts;
|
|
4432
|
-
this
|
|
4433
|
-
this._container = container;
|
|
5121
|
+
__privateSet(this, _container, container);
|
|
4434
5122
|
const canvas = document.createElement("canvas");
|
|
4435
|
-
this
|
|
5123
|
+
__privateMethod(this, _initContainer, initContainer_fn).call(this);
|
|
4436
5124
|
container.appendChild(canvas);
|
|
4437
5125
|
const ctx = canvas.getContext("2d");
|
|
4438
5126
|
const viewContent = createBoardContexts(ctx, { devicePixelRatio });
|
|
4439
|
-
const board = new Board({ viewContent });
|
|
5127
|
+
const board = new Board({ viewContent, container });
|
|
4440
5128
|
const sharer = board.getSharer();
|
|
4441
5129
|
sharer.setActiveViewSizeInfo({
|
|
4442
5130
|
width,
|
|
@@ -4445,7 +5133,7 @@ var iDrawCore = function(exports) {
|
|
|
4445
5133
|
contextWidth: width,
|
|
4446
5134
|
contextHeight: height
|
|
4447
5135
|
});
|
|
4448
|
-
this
|
|
5136
|
+
__privateSet(this, _board, board);
|
|
4449
5137
|
this.resize(sharer.getActiveViewSizeInfo());
|
|
4450
5138
|
const eventHub = board.getEventHub();
|
|
4451
5139
|
new Cursor(container, {
|
|
@@ -4453,20 +5141,22 @@ var iDrawCore = function(exports) {
|
|
|
4453
5141
|
});
|
|
4454
5142
|
}
|
|
4455
5143
|
use(middleware) {
|
|
4456
|
-
this
|
|
5144
|
+
__privateGet(this, _board).use(middleware);
|
|
4457
5145
|
}
|
|
4458
5146
|
setData(data) {
|
|
4459
5147
|
validateElements((data == null ? void 0 : data.elements) || []);
|
|
4460
|
-
this
|
|
5148
|
+
__privateGet(this, _board).setData(data);
|
|
4461
5149
|
}
|
|
4462
5150
|
getData() {
|
|
4463
|
-
return this
|
|
5151
|
+
return __privateGet(this, _board).getData();
|
|
4464
5152
|
}
|
|
4465
5153
|
scale(opts) {
|
|
4466
|
-
this
|
|
5154
|
+
__privateGet(this, _board).scale(opts);
|
|
5155
|
+
const viewer = __privateGet(this, _board).getViewer();
|
|
5156
|
+
viewer.drawFrame();
|
|
4467
5157
|
}
|
|
4468
5158
|
resize(newViewSize) {
|
|
4469
|
-
const
|
|
5159
|
+
const board = __privateGet(this, _board);
|
|
4470
5160
|
const sharer = board.getSharer();
|
|
4471
5161
|
const viewSizeInfo = sharer.getActiveViewSizeInfo();
|
|
4472
5162
|
board.resize({
|
|
@@ -4475,25 +5165,38 @@ var iDrawCore = function(exports) {
|
|
|
4475
5165
|
});
|
|
4476
5166
|
}
|
|
4477
5167
|
clear() {
|
|
4478
|
-
this
|
|
5168
|
+
__privateGet(this, _board).clear();
|
|
4479
5169
|
}
|
|
4480
5170
|
on(name, callback) {
|
|
4481
|
-
const eventHub = this
|
|
5171
|
+
const eventHub = __privateGet(this, _board).getEventHub();
|
|
4482
5172
|
eventHub.on(name, callback);
|
|
4483
5173
|
}
|
|
4484
5174
|
off(name, callback) {
|
|
4485
|
-
const eventHub = this
|
|
5175
|
+
const eventHub = __privateGet(this, _board).getEventHub();
|
|
4486
5176
|
eventHub.off(name, callback);
|
|
4487
5177
|
}
|
|
4488
5178
|
trigger(name, e) {
|
|
4489
|
-
const eventHub = this
|
|
5179
|
+
const eventHub = __privateGet(this, _board).getEventHub();
|
|
4490
5180
|
eventHub.trigger(name, e);
|
|
4491
5181
|
}
|
|
4492
5182
|
}
|
|
5183
|
+
_board = new WeakMap();
|
|
5184
|
+
_container = new WeakMap();
|
|
5185
|
+
_initContainer = new WeakSet();
|
|
5186
|
+
initContainer_fn = function() {
|
|
5187
|
+
const container = __privateGet(this, _container);
|
|
5188
|
+
container.style.position = "relative";
|
|
5189
|
+
};
|
|
4493
5190
|
exports.Core = Core;
|
|
5191
|
+
exports.MiddlewareRuler = MiddlewareRuler;
|
|
4494
5192
|
exports.MiddlewareScaler = MiddlewareScaler;
|
|
4495
5193
|
exports.MiddlewareScroller = MiddlewareScroller;
|
|
4496
5194
|
exports.MiddlewareSelector = MiddlewareSelector;
|
|
5195
|
+
exports.MiddlewareTextEditor = MiddlewareTextEditor;
|
|
5196
|
+
exports.middlewareEventRuler = middlewareEventRuler;
|
|
5197
|
+
exports.middlewareEventScale = middlewareEventScale;
|
|
5198
|
+
exports.middlewareEventSelect = middlewareEventSelect;
|
|
5199
|
+
exports.middlewareEventTextEdit = middlewareEventTextEdit;
|
|
4497
5200
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4498
5201
|
return exports;
|
|
4499
5202
|
}({});
|