@idraw/util 0.4.0-alpha.2 → 0.4.0-alpha.4
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 +7 -4
- package/dist/esm/index.js +7 -4
- package/dist/esm/lib/canvas.js +2 -0
- package/dist/esm/lib/color.d.ts +4 -0
- package/dist/esm/lib/color.js +72 -0
- package/dist/esm/lib/config.d.ts +2 -0
- package/dist/esm/lib/config.js +22 -0
- package/dist/esm/lib/context2d.js +2 -1
- package/dist/esm/lib/controller.js +16 -12
- package/dist/esm/lib/element.d.ts +10 -2
- package/dist/esm/lib/element.js +96 -7
- package/dist/esm/lib/file.d.ts +8 -0
- package/dist/esm/lib/file.js +56 -0
- package/dist/esm/lib/matrix.d.ts +3 -0
- package/dist/esm/lib/matrix.js +16 -0
- package/dist/esm/lib/number.js +4 -1
- package/dist/esm/lib/rotate.d.ts +1 -0
- package/dist/esm/lib/rotate.js +8 -3
- package/dist/esm/lib/view-box.d.ts +5 -0
- package/dist/esm/lib/view-box.js +48 -0
- package/dist/index.global.js +339 -25
- package/dist/index.global.min.js +1 -1
- package/package.json +4 -4
package/dist/index.global.js
CHANGED
|
@@ -47,6 +47,62 @@ var iDrawUtil = function(exports) {
|
|
|
47
47
|
downloadClickEvent.initEvent("click", true, false);
|
|
48
48
|
downloadLink.dispatchEvent(downloadClickEvent);
|
|
49
49
|
}
|
|
50
|
+
function pickFile(opts) {
|
|
51
|
+
const { success, error } = opts;
|
|
52
|
+
let input = document.createElement("input");
|
|
53
|
+
input.type = "file";
|
|
54
|
+
input.addEventListener("change", function() {
|
|
55
|
+
var _a;
|
|
56
|
+
const file = (_a = input.files) == null ? void 0 : _a[0];
|
|
57
|
+
success({
|
|
58
|
+
file
|
|
59
|
+
});
|
|
60
|
+
input = null;
|
|
61
|
+
});
|
|
62
|
+
input.addEventListener("error", function(err) {
|
|
63
|
+
if (typeof error === "function") {
|
|
64
|
+
error(err);
|
|
65
|
+
}
|
|
66
|
+
input = null;
|
|
67
|
+
});
|
|
68
|
+
input.click();
|
|
69
|
+
}
|
|
70
|
+
function parseFileToBase64(file) {
|
|
71
|
+
return new Promise(function(resolve, reject) {
|
|
72
|
+
let reader = new FileReader();
|
|
73
|
+
reader.addEventListener("load", function() {
|
|
74
|
+
resolve(reader.result);
|
|
75
|
+
reader = null;
|
|
76
|
+
});
|
|
77
|
+
reader.addEventListener("error", function(err) {
|
|
78
|
+
reject(err);
|
|
79
|
+
reader = null;
|
|
80
|
+
});
|
|
81
|
+
reader.addEventListener("abort", function() {
|
|
82
|
+
reject(new Error("abort"));
|
|
83
|
+
reader = null;
|
|
84
|
+
});
|
|
85
|
+
reader.readAsDataURL(file);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function parseFileToText(file) {
|
|
89
|
+
return new Promise(function(resolve, reject) {
|
|
90
|
+
let reader = new FileReader();
|
|
91
|
+
reader.addEventListener("load", function() {
|
|
92
|
+
resolve(reader.result);
|
|
93
|
+
reader = null;
|
|
94
|
+
});
|
|
95
|
+
reader.addEventListener("error", function(err) {
|
|
96
|
+
reject(err);
|
|
97
|
+
reader = null;
|
|
98
|
+
});
|
|
99
|
+
reader.addEventListener("abort", function() {
|
|
100
|
+
reject(new Error("abort"));
|
|
101
|
+
reader = null;
|
|
102
|
+
});
|
|
103
|
+
reader.readAsText(file);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
50
106
|
function toColorHexNum(color2) {
|
|
51
107
|
return parseInt(color2.replace(/^\#/, "0x"));
|
|
52
108
|
}
|
|
@@ -207,6 +263,73 @@ var iDrawUtil = function(exports) {
|
|
|
207
263
|
}
|
|
208
264
|
return null;
|
|
209
265
|
}
|
|
266
|
+
function colorToCSS(color2) {
|
|
267
|
+
let css = "transparent";
|
|
268
|
+
if (typeof color2 === "string") {
|
|
269
|
+
css = color2;
|
|
270
|
+
} else if ((color2 == null ? void 0 : color2.type) === "linear-gradient") {
|
|
271
|
+
const items = [];
|
|
272
|
+
if (typeof color2.angle === "number") {
|
|
273
|
+
items.push(`${color2.angle}deg`);
|
|
274
|
+
} else {
|
|
275
|
+
items.push(`180deg`);
|
|
276
|
+
}
|
|
277
|
+
if (Array.isArray(color2.stops)) {
|
|
278
|
+
color2.stops.forEach((stop) => {
|
|
279
|
+
items.push(`${stop.color} ${stop.offset * 100}%`);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
css = `linear-gradient(${items.join(", ")})`;
|
|
283
|
+
} else if ((color2 == null ? void 0 : color2.type) === "radial-gradient") {
|
|
284
|
+
const items = [];
|
|
285
|
+
if (Array.isArray(color2.stops)) {
|
|
286
|
+
color2.stops.forEach((stop) => {
|
|
287
|
+
items.push(`${stop.color} ${stop.offset * 100}%`);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
css = `radial-gradient(circle, ${items.join(", ")})`;
|
|
291
|
+
}
|
|
292
|
+
return css;
|
|
293
|
+
}
|
|
294
|
+
function colorToLinearGradientCSS(color2) {
|
|
295
|
+
let css = "transparent";
|
|
296
|
+
if (typeof color2 === "string") {
|
|
297
|
+
css = color2;
|
|
298
|
+
} else if ((color2 == null ? void 0 : color2.type) === "radial-gradient" || (color2 == null ? void 0 : color2.type) === "linear-gradient") {
|
|
299
|
+
const items = [];
|
|
300
|
+
if (Array.isArray(color2.stops) && color2.stops.length > 0) {
|
|
301
|
+
color2.stops.forEach((stop, i) => {
|
|
302
|
+
items.push(`${stop.color} ${stop.offset * 100}%`);
|
|
303
|
+
if (i === color2.stops.length - 1 && stop.offset < 1) {
|
|
304
|
+
items.push(`${stop.color} ${stop.offset * 100}%`);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
css = `linear-gradient(90deg, ${items.join(", ")})`;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return css;
|
|
311
|
+
}
|
|
312
|
+
function mergeHexColorAlpha(hex, alpha) {
|
|
313
|
+
if (alpha === 1) {
|
|
314
|
+
return hex;
|
|
315
|
+
}
|
|
316
|
+
let hexAlpha = 1;
|
|
317
|
+
const regHex1 = /^\#[0-9a-f]{6,6}$/i;
|
|
318
|
+
const regHex2 = /^\#[0-9a-f]{8,8}$/i;
|
|
319
|
+
let result = hex;
|
|
320
|
+
if (regHex1.test(hex)) {
|
|
321
|
+
hexAlpha = parseInt(hex.substring(5, 7).replace(/^\#/, "0x"));
|
|
322
|
+
} else if (regHex2.test(hex)) {
|
|
323
|
+
hexAlpha = parseInt(hex.substring(7, 9).replace(/^\#/, "0x"));
|
|
324
|
+
result = hex.substring(0, 7);
|
|
325
|
+
}
|
|
326
|
+
hexAlpha = hexAlpha * alpha;
|
|
327
|
+
if (regHex1.test(result) && hexAlpha > 0 && hexAlpha < 1) {
|
|
328
|
+
const aHexNum = Math.max(0, Math.min(255, Math.ceil(hexAlpha * 256)));
|
|
329
|
+
result = `${result.toUpperCase()}${aHexNum.toString(16).toUpperCase()}`;
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
}
|
|
210
333
|
function createUUID() {
|
|
211
334
|
function _createStr() {
|
|
212
335
|
return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
|
|
@@ -326,7 +449,7 @@ var iDrawUtil = function(exports) {
|
|
|
326
449
|
const result = typeStr.replace(/(\[object|\])/gi, "").trim();
|
|
327
450
|
return result;
|
|
328
451
|
}
|
|
329
|
-
const istype
|
|
452
|
+
const istype = {
|
|
330
453
|
type(data, lowerCase) {
|
|
331
454
|
const result = parsePrototype(data);
|
|
332
455
|
return lowerCase === true ? result.toLocaleLowerCase() : result;
|
|
@@ -791,7 +914,8 @@ var iDrawUtil = function(exports) {
|
|
|
791
914
|
return this._ctx.getLineDash();
|
|
792
915
|
}
|
|
793
916
|
setLineDash(nums) {
|
|
794
|
-
|
|
917
|
+
const dash = nums.map((n) => this.$doPixelRatio(n));
|
|
918
|
+
return this._ctx.setLineDash(dash);
|
|
795
919
|
}
|
|
796
920
|
stroke(path) {
|
|
797
921
|
return path ? this._ctx.stroke(path) : this._ctx.stroke();
|
|
@@ -928,8 +1052,10 @@ var iDrawUtil = function(exports) {
|
|
|
928
1052
|
};
|
|
929
1053
|
const viewContext = createContext2D(ctxOpts);
|
|
930
1054
|
const helperContext = createContext2D(ctxOpts);
|
|
1055
|
+
const underContext = createContext2D(ctxOpts);
|
|
931
1056
|
const boardContext = createContext2D({ ctx, ...ctxOpts });
|
|
932
1057
|
const content = {
|
|
1058
|
+
underContext,
|
|
933
1059
|
viewContext,
|
|
934
1060
|
helperContext,
|
|
935
1061
|
boardContext
|
|
@@ -1063,9 +1189,8 @@ var iDrawUtil = function(exports) {
|
|
|
1063
1189
|
function parseAngleToRadian(angle2) {
|
|
1064
1190
|
return angle2 / 180 * Math.PI;
|
|
1065
1191
|
}
|
|
1066
|
-
function
|
|
1067
|
-
const
|
|
1068
|
-
const radian = parseAngleToRadian(elemSize.angle || 0);
|
|
1192
|
+
function rotateByCenter(ctx, angle2, center, callback) {
|
|
1193
|
+
const radian = parseAngleToRadian(angle2 || 0);
|
|
1069
1194
|
if (center && (radian > 0 || radian < 0)) {
|
|
1070
1195
|
ctx.translate(center.x, center.y);
|
|
1071
1196
|
ctx.rotate(radian);
|
|
@@ -1078,6 +1203,12 @@ var iDrawUtil = function(exports) {
|
|
|
1078
1203
|
ctx.translate(-center.x, -center.y);
|
|
1079
1204
|
}
|
|
1080
1205
|
}
|
|
1206
|
+
function rotateElement(ctx, elemSize, callback) {
|
|
1207
|
+
const center = calcElementCenter(elemSize);
|
|
1208
|
+
rotateByCenter(ctx, elemSize.angle || 0, center, () => {
|
|
1209
|
+
callback(ctx);
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1081
1212
|
function calcElementCenter(elem) {
|
|
1082
1213
|
const p = {
|
|
1083
1214
|
x: elem.x + elem.w / 2,
|
|
@@ -1426,16 +1557,30 @@ var iDrawUtil = function(exports) {
|
|
|
1426
1557
|
return groupQueue;
|
|
1427
1558
|
}
|
|
1428
1559
|
function mergeElement(originElem, updateContent) {
|
|
1560
|
+
var _a;
|
|
1429
1561
|
const commonKeys = Object.keys(updateContent);
|
|
1430
1562
|
for (let i = 0; i < commonKeys.length; i++) {
|
|
1431
1563
|
const commonKey = commonKeys[i];
|
|
1432
1564
|
if (["x", "y", "w", "h", "angle", "name"].includes(commonKey)) {
|
|
1433
1565
|
originElem[commonKey] = updateContent[commonKey];
|
|
1434
1566
|
} else if (["detail", "operations"].includes(commonKey)) {
|
|
1435
|
-
if (istype.json(updateContent[commonKey])
|
|
1436
|
-
originElem
|
|
1437
|
-
|
|
1438
|
-
|
|
1567
|
+
if (istype.json(updateContent[commonKey])) {
|
|
1568
|
+
if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
|
|
1569
|
+
originElem[commonKey] = {};
|
|
1570
|
+
}
|
|
1571
|
+
if (istype.json(originElem[commonKey])) {
|
|
1572
|
+
originElem[commonKey] = { ...originElem[commonKey], ...updateContent[commonKey] };
|
|
1573
|
+
}
|
|
1574
|
+
} else if (istype.array(updateContent[commonKey])) {
|
|
1575
|
+
if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
|
|
1576
|
+
originElem[commonKey] = [];
|
|
1577
|
+
}
|
|
1578
|
+
if (istype.array(originElem[commonKey])) {
|
|
1579
|
+
(_a = updateContent == null ? void 0 : updateContent[commonKey]) == null ? void 0 : _a.forEach((item, i2) => {
|
|
1580
|
+
originElem[commonKey][i2] = item;
|
|
1581
|
+
});
|
|
1582
|
+
originElem[commonKey] = [...originElem[commonKey], ...updateContent[commonKey]];
|
|
1583
|
+
}
|
|
1439
1584
|
}
|
|
1440
1585
|
}
|
|
1441
1586
|
}
|
|
@@ -1443,16 +1588,82 @@ var iDrawUtil = function(exports) {
|
|
|
1443
1588
|
}
|
|
1444
1589
|
function updateElementInList(uuid, updateContent, elements) {
|
|
1445
1590
|
var _a;
|
|
1591
|
+
let targetElement = null;
|
|
1446
1592
|
for (let i = 0; i < elements.length; i++) {
|
|
1447
1593
|
const elem = elements[i];
|
|
1448
1594
|
if (elem.uuid === uuid) {
|
|
1449
1595
|
mergeElement(elem, updateContent);
|
|
1596
|
+
targetElement = elem;
|
|
1450
1597
|
break;
|
|
1451
1598
|
} else if (elem.type === "group") {
|
|
1452
|
-
updateElementInList(uuid, updateContent, ((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children) || []);
|
|
1599
|
+
targetElement = updateElementInList(uuid, updateContent, ((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children) || []);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
return targetElement;
|
|
1603
|
+
}
|
|
1604
|
+
function getElementSize(elem) {
|
|
1605
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = elem;
|
|
1606
|
+
const size = { x: x2, y: y2, w: w2, h: h2, angle: angle2 };
|
|
1607
|
+
return size;
|
|
1608
|
+
}
|
|
1609
|
+
function mergeElementAsset(element, assets) {
|
|
1610
|
+
const elem = element;
|
|
1611
|
+
let assetId = null;
|
|
1612
|
+
let assetItem = null;
|
|
1613
|
+
if (elem.type === "image") {
|
|
1614
|
+
assetId = elem.detail.src;
|
|
1615
|
+
} else if (elem.type === "svg") {
|
|
1616
|
+
assetId = elem.detail.svg;
|
|
1617
|
+
} else if (elem.type === "html") {
|
|
1618
|
+
assetId = elem.detail.html;
|
|
1619
|
+
}
|
|
1620
|
+
if (assetId && (assetId == null ? void 0 : assetId.startsWith("@assets/"))) {
|
|
1621
|
+
assetItem = assets[assetId];
|
|
1622
|
+
}
|
|
1623
|
+
if ((assetItem == null ? void 0 : assetItem.type) === elem.type && typeof (assetItem == null ? void 0 : assetItem.value) === "string" && (assetItem == null ? void 0 : assetItem.value)) {
|
|
1624
|
+
if (elem.type === "image") {
|
|
1625
|
+
elem.detail.src = assetItem.value;
|
|
1626
|
+
} else if (elem.type === "svg") {
|
|
1627
|
+
elem.detail.svg = assetItem.value;
|
|
1628
|
+
} else if (elem.type === "html") {
|
|
1629
|
+
elem.detail.html = assetItem.value;
|
|
1453
1630
|
}
|
|
1454
1631
|
}
|
|
1455
|
-
return
|
|
1632
|
+
return elem;
|
|
1633
|
+
}
|
|
1634
|
+
function filterElementAsset(element) {
|
|
1635
|
+
let assetId = null;
|
|
1636
|
+
let assetItem = null;
|
|
1637
|
+
let resource = null;
|
|
1638
|
+
if (element.type === "image") {
|
|
1639
|
+
resource = element.detail.src;
|
|
1640
|
+
} else if (element.type === "svg") {
|
|
1641
|
+
resource = element.detail.svg;
|
|
1642
|
+
} else if (element.type === "html") {
|
|
1643
|
+
resource = element.detail.html;
|
|
1644
|
+
}
|
|
1645
|
+
if (typeof resource === "string" && !isAssetId(resource)) {
|
|
1646
|
+
assetId = createAssetId(resource);
|
|
1647
|
+
assetItem = {
|
|
1648
|
+
type: element.type,
|
|
1649
|
+
value: resource
|
|
1650
|
+
};
|
|
1651
|
+
if (element.type === "image") {
|
|
1652
|
+
element.detail.src = assetId;
|
|
1653
|
+
} else if (element.type === "svg") {
|
|
1654
|
+
element.detail.svg = assetId;
|
|
1655
|
+
} else if (element.type === "html") {
|
|
1656
|
+
element.detail.html = assetId;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
return {
|
|
1660
|
+
element,
|
|
1661
|
+
assetId,
|
|
1662
|
+
assetItem
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
function isResourceElement(elem) {
|
|
1666
|
+
return ["image", "svg", "html"].includes(elem == null ? void 0 : elem.type);
|
|
1456
1667
|
}
|
|
1457
1668
|
function checkRectIntersect(rect1, rect2) {
|
|
1458
1669
|
const react1MinX = rect1.x;
|
|
@@ -1743,54 +1954,58 @@ var iDrawUtil = function(exports) {
|
|
|
1743
1954
|
const topRightCenter = vertexes[1];
|
|
1744
1955
|
const bottomRightCenter = vertexes[2];
|
|
1745
1956
|
const bottomLeftCenter = vertexes[3];
|
|
1746
|
-
const topSize = createControllerElementSizeFromCenter(topCenter, { size: ctrlSize, angle: totalAngle });
|
|
1747
|
-
const rightSize = createControllerElementSizeFromCenter(rightCenter, { size: ctrlSize, angle: totalAngle });
|
|
1748
|
-
const bottomSize = createControllerElementSizeFromCenter(bottomCenter, { size: ctrlSize, angle: totalAngle });
|
|
1749
|
-
const leftSize = createControllerElementSizeFromCenter(leftCenter, { size: ctrlSize, angle: totalAngle });
|
|
1750
1957
|
const topLeftSize = createControllerElementSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: totalAngle });
|
|
1751
1958
|
const topRightSize = createControllerElementSizeFromCenter(topRightCenter, { size: ctrlSize, angle: totalAngle });
|
|
1752
1959
|
const bottomLeftSize = createControllerElementSizeFromCenter(bottomLeftCenter, { size: ctrlSize, angle: totalAngle });
|
|
1753
1960
|
const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, { size: ctrlSize, angle: totalAngle });
|
|
1961
|
+
const topLeftVertexes = calcElementVertexes(topLeftSize);
|
|
1962
|
+
const topRightVertexes = calcElementVertexes(topRightSize);
|
|
1963
|
+
const bottomLeftVertexes = calcElementVertexes(bottomLeftSize);
|
|
1964
|
+
const bottomRightVertexes = calcElementVertexes(bottomRightSize);
|
|
1965
|
+
const topVertexes = [topLeftVertexes[1], topRightVertexes[0], topRightVertexes[3], topLeftVertexes[2]];
|
|
1966
|
+
const rightVertexes = [topRightVertexes[3], topRightVertexes[2], bottomRightVertexes[1], bottomRightVertexes[0]];
|
|
1967
|
+
const bottomVertexes = [bottomLeftVertexes[1], bottomRightVertexes[0], bottomRightVertexes[3], bottomLeftVertexes[2]];
|
|
1968
|
+
const leftVertexes = [topLeftVertexes[3], topLeftVertexes[2], bottomLeftVertexes[1], bottomLeftVertexes[0]];
|
|
1754
1969
|
const sizeController = {
|
|
1755
1970
|
elementWrapper: vertexes,
|
|
1756
1971
|
left: {
|
|
1757
1972
|
type: "left",
|
|
1758
|
-
vertexes:
|
|
1973
|
+
vertexes: leftVertexes,
|
|
1759
1974
|
center: leftCenter
|
|
1760
1975
|
},
|
|
1761
1976
|
right: {
|
|
1762
1977
|
type: "right",
|
|
1763
|
-
vertexes:
|
|
1978
|
+
vertexes: rightVertexes,
|
|
1764
1979
|
center: rightCenter
|
|
1765
1980
|
},
|
|
1766
1981
|
top: {
|
|
1767
1982
|
type: "top",
|
|
1768
|
-
vertexes:
|
|
1983
|
+
vertexes: topVertexes,
|
|
1769
1984
|
center: topCenter
|
|
1770
1985
|
},
|
|
1771
1986
|
bottom: {
|
|
1772
1987
|
type: "bottom",
|
|
1773
|
-
vertexes:
|
|
1988
|
+
vertexes: bottomVertexes,
|
|
1774
1989
|
center: bottomCenter
|
|
1775
1990
|
},
|
|
1776
1991
|
topLeft: {
|
|
1777
1992
|
type: "top-left",
|
|
1778
|
-
vertexes:
|
|
1993
|
+
vertexes: topLeftVertexes,
|
|
1779
1994
|
center: topLeftCenter
|
|
1780
1995
|
},
|
|
1781
1996
|
topRight: {
|
|
1782
1997
|
type: "top-right",
|
|
1783
|
-
vertexes:
|
|
1998
|
+
vertexes: topRightVertexes,
|
|
1784
1999
|
center: topRightCenter
|
|
1785
2000
|
},
|
|
1786
2001
|
bottomLeft: {
|
|
1787
2002
|
type: "bottom-left",
|
|
1788
|
-
vertexes:
|
|
2003
|
+
vertexes: bottomLeftVertexes,
|
|
1789
2004
|
center: bottomLeftCenter
|
|
1790
2005
|
},
|
|
1791
2006
|
bottomRight: {
|
|
1792
2007
|
type: "bottom-right",
|
|
1793
|
-
vertexes:
|
|
2008
|
+
vertexes: bottomRightVertexes,
|
|
1794
2009
|
center: bottomRightCenter
|
|
1795
2010
|
}
|
|
1796
2011
|
};
|
|
@@ -2008,9 +2223,93 @@ var iDrawUtil = function(exports) {
|
|
|
2008
2223
|
});
|
|
2009
2224
|
}
|
|
2010
2225
|
function formatNumber(num, opts) {
|
|
2011
|
-
|
|
2226
|
+
let decimalPlaces = 2;
|
|
2227
|
+
if (typeof (opts == null ? void 0 : opts.decimalPlaces) !== "undefined" && (opts == null ? void 0 : opts.decimalPlaces) >= 0) {
|
|
2228
|
+
decimalPlaces = opts.decimalPlaces;
|
|
2229
|
+
}
|
|
2012
2230
|
return parseFloat(num.toFixed(decimalPlaces));
|
|
2013
2231
|
}
|
|
2232
|
+
function matrixToRadian(matrix) {
|
|
2233
|
+
if (matrix[1] != -1 * matrix[3] || matrix[4] != matrix[0] || matrix[0] * matrix[4] - matrix[3] * matrix[1] != 1) {
|
|
2234
|
+
return null;
|
|
2235
|
+
} else {
|
|
2236
|
+
return Math.acos(matrix[0]);
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
function matrixToAngle(matrix) {
|
|
2240
|
+
const radian = matrixToRadian(matrix);
|
|
2241
|
+
if (typeof radian === "number") {
|
|
2242
|
+
const angle2 = radian * 180 / Math.PI;
|
|
2243
|
+
return angle2;
|
|
2244
|
+
}
|
|
2245
|
+
return radian;
|
|
2246
|
+
}
|
|
2247
|
+
function getDefaultElementDetailConfig() {
|
|
2248
|
+
const config = {
|
|
2249
|
+
boxSizing: "border-box",
|
|
2250
|
+
borderWidth: 0,
|
|
2251
|
+
borderColor: "#000000",
|
|
2252
|
+
shadowColor: "#000000",
|
|
2253
|
+
borderRadius: 0,
|
|
2254
|
+
borderDash: [],
|
|
2255
|
+
shadowOffsetX: 0,
|
|
2256
|
+
shadowOffsetY: 0,
|
|
2257
|
+
shadowBlur: 0,
|
|
2258
|
+
opacity: 1,
|
|
2259
|
+
color: "#000000",
|
|
2260
|
+
textAlign: "left",
|
|
2261
|
+
verticalAlign: "top",
|
|
2262
|
+
fontSize: 16,
|
|
2263
|
+
lineHeight: 20,
|
|
2264
|
+
fontFamily: "sans-serif",
|
|
2265
|
+
fontWeight: 400
|
|
2266
|
+
};
|
|
2267
|
+
return config;
|
|
2268
|
+
}
|
|
2269
|
+
const defaultElemConfig = getDefaultElementDetailConfig();
|
|
2270
|
+
function calcViewBoxSize(viewElem, opts) {
|
|
2271
|
+
const { viewScaleInfo } = opts;
|
|
2272
|
+
const { scale } = viewScaleInfo;
|
|
2273
|
+
let { borderRadius: borderRadius2, boxSizing = defaultElemConfig.boxSizing, borderWidth: borderWidth2 } = viewElem.detail;
|
|
2274
|
+
if (typeof borderWidth2 !== "number") {
|
|
2275
|
+
borderRadius2 = 0;
|
|
2276
|
+
}
|
|
2277
|
+
let { x: x2, y: y2, w: w2, h: h2 } = viewElem;
|
|
2278
|
+
let radiusList = [0, 0, 0, 0];
|
|
2279
|
+
if (typeof borderRadius2 === "number") {
|
|
2280
|
+
const br = borderRadius2 * scale;
|
|
2281
|
+
radiusList = [br, br, br, br];
|
|
2282
|
+
} else if (Array.isArray(borderRadius2) && (borderRadius2 == null ? void 0 : borderRadius2.length) === 4) {
|
|
2283
|
+
radiusList = [borderRadius2[0] * scale, borderRadius2[1] * scale, borderRadius2[2] * scale, borderRadius2[3] * scale];
|
|
2284
|
+
}
|
|
2285
|
+
let bw = 0;
|
|
2286
|
+
if (typeof borderWidth2 === "number") {
|
|
2287
|
+
bw = (borderWidth2 || 1) * scale;
|
|
2288
|
+
}
|
|
2289
|
+
if (boxSizing === "border-box") {
|
|
2290
|
+
x2 = viewElem.x + bw / 2;
|
|
2291
|
+
y2 = viewElem.y + bw / 2;
|
|
2292
|
+
w2 = viewElem.w - bw;
|
|
2293
|
+
h2 = viewElem.h - bw;
|
|
2294
|
+
} else if (boxSizing === "content-box") {
|
|
2295
|
+
x2 = viewElem.x - bw / 2;
|
|
2296
|
+
y2 = viewElem.y - bw / 2;
|
|
2297
|
+
w2 = viewElem.w + bw;
|
|
2298
|
+
h2 = viewElem.h + bw;
|
|
2299
|
+
} else {
|
|
2300
|
+
x2 = viewElem.x;
|
|
2301
|
+
y2 = viewElem.y;
|
|
2302
|
+
w2 = viewElem.w;
|
|
2303
|
+
h2 = viewElem.h;
|
|
2304
|
+
}
|
|
2305
|
+
return {
|
|
2306
|
+
x: x2,
|
|
2307
|
+
y: y2,
|
|
2308
|
+
w: w2,
|
|
2309
|
+
h: h2,
|
|
2310
|
+
radiusList
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2014
2313
|
exports.Context2D = Context2D;
|
|
2015
2314
|
exports.EventEmitter = EventEmitter;
|
|
2016
2315
|
exports.Store = Store;
|
|
@@ -2024,12 +2323,15 @@ var iDrawUtil = function(exports) {
|
|
|
2024
2323
|
exports.calcElementsContextSize = calcElementsContextSize;
|
|
2025
2324
|
exports.calcElementsViewInfo = calcElementsViewInfo;
|
|
2026
2325
|
exports.calcSpeed = calcSpeed;
|
|
2326
|
+
exports.calcViewBoxSize = calcViewBoxSize;
|
|
2027
2327
|
exports.calcViewElementSize = calcViewElementSize;
|
|
2028
2328
|
exports.calcViewPointSize = calcViewPointSize;
|
|
2029
2329
|
exports.calcViewVertexes = calcViewVertexes;
|
|
2030
2330
|
exports.check = check;
|
|
2031
2331
|
exports.checkRectIntersect = checkRectIntersect;
|
|
2032
2332
|
exports.colorNameToHex = colorNameToHex;
|
|
2333
|
+
exports.colorToCSS = colorToCSS;
|
|
2334
|
+
exports.colorToLinearGradientCSS = colorToLinearGradientCSS;
|
|
2033
2335
|
exports.compose = compose;
|
|
2034
2336
|
exports.compressImage = compressImage;
|
|
2035
2337
|
exports.createAssetId = createAssetId;
|
|
@@ -2042,14 +2344,17 @@ var iDrawUtil = function(exports) {
|
|
|
2042
2344
|
exports.downloadImageFromCanvas = downloadImageFromCanvas;
|
|
2043
2345
|
exports.equalPoint = equalPoint;
|
|
2044
2346
|
exports.equalTouchPoint = equalTouchPoint;
|
|
2347
|
+
exports.filterElementAsset = filterElementAsset;
|
|
2045
2348
|
exports.findElementFromList = findElementFromList;
|
|
2046
2349
|
exports.findElementsFromList = findElementsFromList;
|
|
2047
2350
|
exports.formatNumber = formatNumber;
|
|
2048
2351
|
exports.generateHTML = generateHTML;
|
|
2049
2352
|
exports.generateSVGPath = generateSVGPath;
|
|
2050
2353
|
exports.getCenterFromTwoPoints = getCenterFromTwoPoints;
|
|
2354
|
+
exports.getDefaultElementDetailConfig = getDefaultElementDetailConfig;
|
|
2051
2355
|
exports.getElemenetsAssetIds = getElemenetsAssetIds;
|
|
2052
2356
|
exports.getElementRotateVertexes = getElementRotateVertexes;
|
|
2357
|
+
exports.getElementSize = getElementSize;
|
|
2053
2358
|
exports.getElementVertexes = getElementVertexes;
|
|
2054
2359
|
exports.getGroupQueueFromList = getGroupQueueFromList;
|
|
2055
2360
|
exports.getSelectedElementUUIDs = getSelectedElementUUIDs;
|
|
@@ -2060,16 +2365,25 @@ var iDrawUtil = function(exports) {
|
|
|
2060
2365
|
exports.isAssetId = isAssetId;
|
|
2061
2366
|
exports.isColorStr = isColorStr;
|
|
2062
2367
|
exports.isElementInView = isElementInView;
|
|
2368
|
+
exports.isResourceElement = isResourceElement;
|
|
2063
2369
|
exports.isViewPointInElement = isViewPointInElement;
|
|
2064
|
-
exports.istype = istype
|
|
2370
|
+
exports.istype = istype;
|
|
2065
2371
|
exports.limitAngle = limitAngle;
|
|
2066
2372
|
exports.loadHTML = loadHTML;
|
|
2067
2373
|
exports.loadImage = loadImage;
|
|
2068
2374
|
exports.loadSVG = loadSVG;
|
|
2375
|
+
exports.matrixToAngle = matrixToAngle;
|
|
2376
|
+
exports.matrixToRadian = matrixToRadian;
|
|
2377
|
+
exports.mergeElementAsset = mergeElementAsset;
|
|
2378
|
+
exports.mergeHexColorAlpha = mergeHexColorAlpha;
|
|
2069
2379
|
exports.parseAngleToRadian = parseAngleToRadian;
|
|
2380
|
+
exports.parseFileToBase64 = parseFileToBase64;
|
|
2381
|
+
exports.parseFileToText = parseFileToText;
|
|
2070
2382
|
exports.parseHTML = parseHTML;
|
|
2071
2383
|
exports.parseRadianToAngle = parseRadianToAngle;
|
|
2072
2384
|
exports.parseSVGPath = parseSVGPath;
|
|
2385
|
+
exports.pickFile = pickFile;
|
|
2386
|
+
exports.rotateByCenter = rotateByCenter;
|
|
2073
2387
|
exports.rotateElement = rotateElement;
|
|
2074
2388
|
exports.rotateElementVertexes = rotateElementVertexes;
|
|
2075
2389
|
exports.rotatePoint = rotatePoint;
|