@idraw/util 0.4.0-beta.2 → 0.4.0-beta.20
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 +13 -9
- package/dist/esm/index.js +13 -9
- package/dist/esm/lib/canvas.d.ts +8 -3
- package/dist/esm/lib/canvas.js +27 -4
- package/dist/esm/lib/config.d.ts +5 -10
- package/dist/esm/lib/config.js +7 -9
- package/dist/esm/lib/context2d.d.ts +2 -0
- package/dist/esm/lib/context2d.js +14 -0
- package/dist/esm/lib/controller.d.ts +5 -1
- package/dist/esm/lib/controller.js +142 -0
- package/dist/esm/lib/data.d.ts +6 -2
- package/dist/esm/lib/data.js +95 -2
- package/dist/esm/lib/element.d.ts +3 -0
- package/dist/esm/lib/element.js +94 -1
- package/dist/esm/lib/event.d.ts +4 -2
- package/dist/esm/lib/event.js +31 -11
- package/dist/esm/lib/file.d.ts +7 -2
- package/dist/esm/lib/file.js +26 -7
- package/dist/esm/lib/handle-element.d.ts +6 -1
- package/dist/esm/lib/handle-element.js +56 -36
- package/dist/esm/lib/html.d.ts +1 -1
- package/dist/esm/lib/istype.d.ts +1 -0
- package/dist/esm/lib/istype.js +3 -0
- package/dist/esm/lib/modify-recorder.d.ts +15 -0
- package/dist/esm/lib/modify-recorder.js +177 -0
- package/dist/esm/lib/modify.d.ts +6 -0
- package/dist/esm/lib/modify.js +99 -0
- package/dist/esm/lib/rect.js +9 -9
- package/dist/esm/lib/resize-element.d.ts +2 -0
- package/dist/esm/lib/resize-element.js +101 -0
- package/dist/esm/lib/store.d.ts +6 -5
- package/dist/esm/lib/store.js +30 -9
- package/dist/esm/lib/time.d.ts +1 -0
- package/dist/esm/lib/time.js +13 -1
- package/dist/esm/lib/view-box.js +3 -2
- package/dist/esm/lib/view-calc.d.ts +20 -3
- package/dist/esm/lib/view-calc.js +171 -3
- package/dist/esm/lib/view-content.d.ts +14 -0
- package/dist/esm/lib/view-content.js +88 -0
- package/dist/esm/lib/view-visible.d.ts +21 -0
- package/dist/esm/lib/view-visible.js +93 -0
- package/dist/index.global.js +1154 -155
- package/dist/index.global.min.js +1 -1
- package/package.json +1 -1
package/dist/index.global.js
CHANGED
|
@@ -17,8 +17,12 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
17
17
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
18
18
|
return value;
|
|
19
19
|
};
|
|
20
|
+
var __privateMethod = (obj, member, method) => {
|
|
21
|
+
__accessCheck(obj, member, "access private method");
|
|
22
|
+
return method;
|
|
23
|
+
};
|
|
20
24
|
|
|
21
|
-
var _ctx, _opts;
|
|
25
|
+
var _ctx, _opts, _listeners, _temp, _backUpDefaultStorage, _createTempStorage, createTempStorage_fn;
|
|
22
26
|
function compose(middleware) {
|
|
23
27
|
return function(context, next) {
|
|
24
28
|
return dispatch(0);
|
|
@@ -47,7 +51,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
47
51
|
function throttle(fn, timeout) {
|
|
48
52
|
let timer = -1;
|
|
49
53
|
return function(...args) {
|
|
50
|
-
if (timer
|
|
54
|
+
if (timer >= 0) {
|
|
51
55
|
return;
|
|
52
56
|
}
|
|
53
57
|
timer = setTimeout(() => {
|
|
@@ -56,20 +60,34 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
56
60
|
}, timeout);
|
|
57
61
|
};
|
|
58
62
|
}
|
|
63
|
+
function debounce(fn, timeout) {
|
|
64
|
+
let timer = -1;
|
|
65
|
+
return function(...args) {
|
|
66
|
+
if (timer >= 0) {
|
|
67
|
+
window.clearTimeout(timer);
|
|
68
|
+
}
|
|
69
|
+
timer = setTimeout(() => {
|
|
70
|
+
fn(...args);
|
|
71
|
+
timer = -1;
|
|
72
|
+
}, timeout);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
59
75
|
function downloadImageFromCanvas(canvas, opts) {
|
|
60
|
-
const {
|
|
76
|
+
const { fileName, type = "image/jpeg" } = opts;
|
|
61
77
|
const stream = canvas.toDataURL(type);
|
|
62
|
-
|
|
78
|
+
let downloadLink = document.createElement("a");
|
|
63
79
|
downloadLink.href = stream;
|
|
64
|
-
downloadLink.download =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
downloadLink.dispatchEvent(downloadClickEvent);
|
|
80
|
+
downloadLink.download = fileName;
|
|
81
|
+
downloadLink.click();
|
|
82
|
+
downloadLink = null;
|
|
68
83
|
}
|
|
69
84
|
function pickFile(opts) {
|
|
70
|
-
const { success, error } = opts;
|
|
85
|
+
const { accept, success, error } = opts;
|
|
71
86
|
let input = document.createElement("input");
|
|
72
87
|
input.type = "file";
|
|
88
|
+
if (accept) {
|
|
89
|
+
input.accept = accept;
|
|
90
|
+
}
|
|
73
91
|
input.addEventListener("change", function() {
|
|
74
92
|
var _a;
|
|
75
93
|
const file = (_a = input.files) == null ? void 0 : _a[0];
|
|
@@ -122,6 +140,23 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
122
140
|
reader.readAsText(file);
|
|
123
141
|
});
|
|
124
142
|
}
|
|
143
|
+
function parseTextToBlobURL(text2) {
|
|
144
|
+
const bytes = new TextEncoder().encode(text2);
|
|
145
|
+
const blob = new Blob([bytes], {
|
|
146
|
+
type: "text/plain;charset=utf-8"
|
|
147
|
+
});
|
|
148
|
+
const blobURL = window.URL.createObjectURL(blob);
|
|
149
|
+
return blobURL;
|
|
150
|
+
}
|
|
151
|
+
function downloadFileFromText(text2, opts) {
|
|
152
|
+
const { fileName } = opts;
|
|
153
|
+
const blobURL = parseTextToBlobURL(text2);
|
|
154
|
+
let downloadLink = document.createElement("a");
|
|
155
|
+
downloadLink.href = blobURL;
|
|
156
|
+
downloadLink.download = fileName;
|
|
157
|
+
downloadLink.click();
|
|
158
|
+
downloadLink = null;
|
|
159
|
+
}
|
|
125
160
|
function toColorHexNum(color2) {
|
|
126
161
|
return parseInt(color2.replace(/^\#/, "0x"));
|
|
127
162
|
}
|
|
@@ -406,6 +441,19 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
406
441
|
}
|
|
407
442
|
return _clone(target);
|
|
408
443
|
}
|
|
444
|
+
function deepCloneElement(element) {
|
|
445
|
+
const elem = deepClone(element);
|
|
446
|
+
const _resetUUID = (e) => {
|
|
447
|
+
e.uuid = createUUID();
|
|
448
|
+
if (e.type === "group" && e.detail.children) {
|
|
449
|
+
e.detail.children.forEach((child) => {
|
|
450
|
+
_resetUUID(child);
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
_resetUUID(elem);
|
|
455
|
+
return elem;
|
|
456
|
+
}
|
|
409
457
|
function is$1(target) {
|
|
410
458
|
return Object.prototype.toString.call(target).replace(/[\]|\[]{1,1}/gi, "").split(" ")[1];
|
|
411
459
|
}
|
|
@@ -442,7 +490,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
442
490
|
const assetUUID = createAssetId(html2);
|
|
443
491
|
if (!assets[assetUUID]) {
|
|
444
492
|
assets[assetUUID] = {
|
|
445
|
-
type: "
|
|
493
|
+
type: "html",
|
|
446
494
|
value: html2
|
|
447
495
|
};
|
|
448
496
|
}
|
|
@@ -463,6 +511,80 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
463
511
|
sortedData.assets = assets;
|
|
464
512
|
return sortedData;
|
|
465
513
|
}
|
|
514
|
+
function filterCompactData(data, opts) {
|
|
515
|
+
const assets = data.assets || {};
|
|
516
|
+
const sortedData = deepClone(data);
|
|
517
|
+
const loadItemMap = (opts == null ? void 0 : opts.loadItemMap) || {};
|
|
518
|
+
const _scanElements = (elems) => {
|
|
519
|
+
elems.forEach((elem) => {
|
|
520
|
+
var _a, _b, _c;
|
|
521
|
+
if (elem.type === "image" && elem.detail.src) {
|
|
522
|
+
const src = elem.detail.src;
|
|
523
|
+
if (isAssetId(src) && !assets[src] && loadItemMap[src] && typeof ((_a = loadItemMap[src]) == null ? void 0 : _a.source) === "string") {
|
|
524
|
+
assets[src] = {
|
|
525
|
+
type: "image",
|
|
526
|
+
value: loadItemMap[src].source
|
|
527
|
+
};
|
|
528
|
+
} else if (!assets[src]) {
|
|
529
|
+
const assetUUID = createAssetId(src);
|
|
530
|
+
if (!assets[assetUUID]) {
|
|
531
|
+
assets[assetUUID] = {
|
|
532
|
+
type: "image",
|
|
533
|
+
value: src
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
elem.detail.src = assetUUID;
|
|
537
|
+
}
|
|
538
|
+
} else if (elem.type === "svg") {
|
|
539
|
+
const svg2 = elem.detail.svg;
|
|
540
|
+
if (isAssetId(svg2) && !assets[svg2] && loadItemMap[svg2] && typeof ((_b = loadItemMap[svg2]) == null ? void 0 : _b.source) === "string") {
|
|
541
|
+
assets[svg2] = {
|
|
542
|
+
type: "svg",
|
|
543
|
+
value: loadItemMap[svg2].source
|
|
544
|
+
};
|
|
545
|
+
} else if (!assets[svg2]) {
|
|
546
|
+
const assetUUID = createAssetId(svg2);
|
|
547
|
+
if (!assets[assetUUID]) {
|
|
548
|
+
assets[assetUUID] = {
|
|
549
|
+
type: "svg",
|
|
550
|
+
value: svg2
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
elem.detail.svg = assetUUID;
|
|
554
|
+
}
|
|
555
|
+
} else if (elem.type === "html") {
|
|
556
|
+
const html2 = elem.detail.html;
|
|
557
|
+
if (isAssetId(html2) && !assets[html2] && loadItemMap[html2] && typeof ((_c = loadItemMap[html2]) == null ? void 0 : _c.source) === "string") {
|
|
558
|
+
assets[html2] = {
|
|
559
|
+
type: "html",
|
|
560
|
+
value: loadItemMap[html2].source
|
|
561
|
+
};
|
|
562
|
+
} else if (!assets[html2]) {
|
|
563
|
+
const assetUUID = createAssetId(html2);
|
|
564
|
+
if (!assets[assetUUID]) {
|
|
565
|
+
assets[assetUUID] = {
|
|
566
|
+
type: "html",
|
|
567
|
+
value: html2
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
elem.detail.html = assetUUID;
|
|
571
|
+
}
|
|
572
|
+
} else if (elem.type === "group" && Array.isArray(elem.detail.children)) {
|
|
573
|
+
const groupAssets = elem.detail.assets || {};
|
|
574
|
+
Object.keys(groupAssets).forEach((assetId) => {
|
|
575
|
+
if (!assets[assetId]) {
|
|
576
|
+
assets[assetId] = groupAssets[assetId];
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
delete elem.detail.assets;
|
|
580
|
+
_scanElements(elem.detail.children);
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
};
|
|
584
|
+
_scanElements(sortedData.elements);
|
|
585
|
+
sortedData.assets = assets;
|
|
586
|
+
return sortedData;
|
|
587
|
+
}
|
|
466
588
|
function parsePrototype(data) {
|
|
467
589
|
const typeStr = Object.prototype.toString.call(data) || "";
|
|
468
590
|
const result = typeStr.replace(/(\[object|\])/gi, "").trim();
|
|
@@ -485,6 +607,9 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
485
607
|
asyncFunction(data) {
|
|
486
608
|
return parsePrototype(data) === "AsyncFunction";
|
|
487
609
|
},
|
|
610
|
+
boolean(data) {
|
|
611
|
+
return parsePrototype(data) === "Boolean";
|
|
612
|
+
},
|
|
488
613
|
string(data) {
|
|
489
614
|
return parsePrototype(data) === "String";
|
|
490
615
|
},
|
|
@@ -790,6 +915,9 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
790
915
|
svgDesc,
|
|
791
916
|
htmlDesc
|
|
792
917
|
};
|
|
918
|
+
const defaultFontSize = 12;
|
|
919
|
+
const defaultFontWeight = "400";
|
|
920
|
+
const defaultFontFamily = `-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'`;
|
|
793
921
|
class Context2D {
|
|
794
922
|
// private _width: number = 0;
|
|
795
923
|
// private _height: number = 0;
|
|
@@ -798,6 +926,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
798
926
|
__privateAdd(this, _opts, void 0);
|
|
799
927
|
__privateSet(this, _ctx, ctx);
|
|
800
928
|
__privateSet(this, _opts, { ...{ devicePixelRatio: 1, offscreenCanvas: null }, ...opts });
|
|
929
|
+
this.$resetFont();
|
|
801
930
|
}
|
|
802
931
|
$undoPixelRatio(num) {
|
|
803
932
|
return num / __privateGet(this, _opts).devicePixelRatio;
|
|
@@ -808,6 +937,9 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
808
937
|
$getContext() {
|
|
809
938
|
return __privateGet(this, _ctx);
|
|
810
939
|
}
|
|
940
|
+
$setContext(ctx) {
|
|
941
|
+
__privateSet(this, _ctx, ctx);
|
|
942
|
+
}
|
|
811
943
|
$setFont(opts) {
|
|
812
944
|
const strList = [];
|
|
813
945
|
if (opts.fontWeight) {
|
|
@@ -817,6 +949,13 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
817
949
|
strList.push(`${opts.fontFamily || "sans-serif"}`);
|
|
818
950
|
__privateGet(this, _ctx).font = `${strList.join(" ")}`;
|
|
819
951
|
}
|
|
952
|
+
$resetFont() {
|
|
953
|
+
this.$setFont({
|
|
954
|
+
fontSize: defaultFontSize,
|
|
955
|
+
fontFamily: defaultFontFamily,
|
|
956
|
+
fontWeight: defaultFontWeight
|
|
957
|
+
});
|
|
958
|
+
}
|
|
820
959
|
$getOffscreenCanvas() {
|
|
821
960
|
return __privateGet(this, _opts).offscreenCanvas;
|
|
822
961
|
}
|
|
@@ -1090,15 +1229,39 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1090
1229
|
});
|
|
1091
1230
|
return context2d;
|
|
1092
1231
|
}
|
|
1093
|
-
function
|
|
1094
|
-
const { width, height, devicePixelRatio, offscreen } = opts;
|
|
1232
|
+
function createBoardContent(canvas, opts) {
|
|
1233
|
+
const { width, height, devicePixelRatio, offscreen, createCustomContext2D } = opts;
|
|
1095
1234
|
const ctxOpts = {
|
|
1096
1235
|
width,
|
|
1097
1236
|
height,
|
|
1098
1237
|
devicePixelRatio
|
|
1099
1238
|
};
|
|
1239
|
+
const ctx = canvas.getContext("2d");
|
|
1240
|
+
if (createCustomContext2D) {
|
|
1241
|
+
const viewContext = createCustomContext2D(ctxOpts);
|
|
1242
|
+
const helperContext = createCustomContext2D(ctxOpts);
|
|
1243
|
+
const underContext = createCustomContext2D(ctxOpts);
|
|
1244
|
+
const boardContext = createContext2D({ ctx, ...ctxOpts });
|
|
1245
|
+
const drawView = () => {
|
|
1246
|
+
const { width: w2, height: h2 } = viewContext.$getSize();
|
|
1247
|
+
boardContext.clearRect(0, 0, w2, h2);
|
|
1248
|
+
boardContext.drawImage(underContext.canvas, 0, 0, w2, h2);
|
|
1249
|
+
boardContext.drawImage(viewContext.canvas, 0, 0, w2, h2);
|
|
1250
|
+
boardContext.drawImage(helperContext.canvas, 0, 0, w2, h2);
|
|
1251
|
+
underContext.clearRect(0, 0, w2, h2);
|
|
1252
|
+
viewContext.clearRect(0, 0, w2, h2);
|
|
1253
|
+
helperContext.clearRect(0, 0, w2, h2);
|
|
1254
|
+
};
|
|
1255
|
+
const content = {
|
|
1256
|
+
underContext,
|
|
1257
|
+
viewContext,
|
|
1258
|
+
helperContext,
|
|
1259
|
+
boardContext,
|
|
1260
|
+
drawView
|
|
1261
|
+
};
|
|
1262
|
+
return content;
|
|
1263
|
+
}
|
|
1100
1264
|
if (offscreen === true) {
|
|
1101
|
-
const ctx = canvas.getContext("2d");
|
|
1102
1265
|
const viewContext = createOffscreenContext2D(ctxOpts);
|
|
1103
1266
|
const helperContext = createOffscreenContext2D(ctxOpts);
|
|
1104
1267
|
const underContext = createOffscreenContext2D(ctxOpts);
|
|
@@ -1122,7 +1285,6 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1122
1285
|
};
|
|
1123
1286
|
return content;
|
|
1124
1287
|
} else {
|
|
1125
|
-
const ctx = canvas.getContext("2d");
|
|
1126
1288
|
const viewContext = createContext2D(ctxOpts);
|
|
1127
1289
|
const helperContext = createContext2D(ctxOpts);
|
|
1128
1290
|
const underContext = createContext2D(ctxOpts);
|
|
@@ -1148,20 +1310,21 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1148
1310
|
}
|
|
1149
1311
|
class EventEmitter {
|
|
1150
1312
|
constructor() {
|
|
1151
|
-
this
|
|
1313
|
+
__privateAdd(this, _listeners, void 0);
|
|
1314
|
+
__privateSet(this, _listeners, /* @__PURE__ */ new Map());
|
|
1152
1315
|
}
|
|
1153
1316
|
on(eventKey, callback) {
|
|
1154
|
-
if (this
|
|
1155
|
-
const callbacks = this
|
|
1317
|
+
if (__privateGet(this, _listeners).has(eventKey)) {
|
|
1318
|
+
const callbacks = __privateGet(this, _listeners).get(eventKey) || [];
|
|
1156
1319
|
callbacks == null ? void 0 : callbacks.push(callback);
|
|
1157
|
-
this
|
|
1320
|
+
__privateGet(this, _listeners).set(eventKey, callbacks);
|
|
1158
1321
|
} else {
|
|
1159
|
-
this
|
|
1322
|
+
__privateGet(this, _listeners).set(eventKey, [callback]);
|
|
1160
1323
|
}
|
|
1161
1324
|
}
|
|
1162
1325
|
off(eventKey, callback) {
|
|
1163
|
-
if (this
|
|
1164
|
-
const callbacks = this
|
|
1326
|
+
if (__privateGet(this, _listeners).has(eventKey)) {
|
|
1327
|
+
const callbacks = __privateGet(this, _listeners).get(eventKey);
|
|
1165
1328
|
if (Array.isArray(callbacks)) {
|
|
1166
1329
|
for (let i = 0; i < (callbacks == null ? void 0 : callbacks.length); i++) {
|
|
1167
1330
|
if (callbacks[i] === callback) {
|
|
@@ -1170,11 +1333,11 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1170
1333
|
}
|
|
1171
1334
|
}
|
|
1172
1335
|
}
|
|
1173
|
-
this
|
|
1336
|
+
__privateGet(this, _listeners).set(eventKey, callbacks || []);
|
|
1174
1337
|
}
|
|
1175
1338
|
}
|
|
1176
1339
|
trigger(eventKey, e) {
|
|
1177
|
-
const callbacks = this
|
|
1340
|
+
const callbacks = __privateGet(this, _listeners).get(eventKey);
|
|
1178
1341
|
if (Array.isArray(callbacks)) {
|
|
1179
1342
|
callbacks.forEach((cb) => {
|
|
1180
1343
|
cb(e);
|
|
@@ -1185,15 +1348,22 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1185
1348
|
}
|
|
1186
1349
|
}
|
|
1187
1350
|
has(name) {
|
|
1188
|
-
if (this
|
|
1189
|
-
const list = this
|
|
1351
|
+
if (__privateGet(this, _listeners).has(name)) {
|
|
1352
|
+
const list = __privateGet(this, _listeners).get(name);
|
|
1190
1353
|
if (Array.isArray(list) && list.length > 0) {
|
|
1191
1354
|
return true;
|
|
1192
1355
|
}
|
|
1193
1356
|
}
|
|
1194
1357
|
return false;
|
|
1195
1358
|
}
|
|
1359
|
+
destroy() {
|
|
1360
|
+
this.clear();
|
|
1361
|
+
}
|
|
1362
|
+
clear() {
|
|
1363
|
+
__privateGet(this, _listeners).clear();
|
|
1364
|
+
}
|
|
1196
1365
|
}
|
|
1366
|
+
_listeners = new WeakMap();
|
|
1197
1367
|
function calcDistance(start, end) {
|
|
1198
1368
|
const distance = (start.x - end.x) * (start.x - end.x) + (start.y - end.y) * (start.y - end.y);
|
|
1199
1369
|
return distance === 0 ? distance : Math.sqrt(distance);
|
|
@@ -1226,25 +1396,37 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1226
1396
|
}
|
|
1227
1397
|
class Store {
|
|
1228
1398
|
constructor(opts) {
|
|
1229
|
-
this
|
|
1230
|
-
this
|
|
1399
|
+
__privateAdd(this, _createTempStorage);
|
|
1400
|
+
__privateAdd(this, _temp, void 0);
|
|
1401
|
+
__privateAdd(this, _backUpDefaultStorage, void 0);
|
|
1402
|
+
__privateSet(this, _backUpDefaultStorage, deepClone(opts.defaultStorage));
|
|
1403
|
+
__privateSet(this, _temp, __privateMethod(this, _createTempStorage, createTempStorage_fn).call(this));
|
|
1231
1404
|
}
|
|
1232
1405
|
set(name, value) {
|
|
1233
|
-
this
|
|
1406
|
+
__privateGet(this, _temp)[name] = value;
|
|
1234
1407
|
}
|
|
1235
1408
|
get(name) {
|
|
1236
|
-
return this
|
|
1409
|
+
return __privateGet(this, _temp)[name];
|
|
1237
1410
|
}
|
|
1238
|
-
getSnapshot() {
|
|
1239
|
-
|
|
1411
|
+
getSnapshot(opts) {
|
|
1412
|
+
if ((opts == null ? void 0 : opts.deepClone) === true) {
|
|
1413
|
+
return deepClone(__privateGet(this, _temp));
|
|
1414
|
+
}
|
|
1415
|
+
return { ...__privateGet(this, _temp) };
|
|
1240
1416
|
}
|
|
1241
1417
|
clear() {
|
|
1242
|
-
this
|
|
1418
|
+
__privateSet(this, _temp, __privateMethod(this, _createTempStorage, createTempStorage_fn).call(this));
|
|
1243
1419
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1420
|
+
destroy() {
|
|
1421
|
+
__privateSet(this, _temp, null);
|
|
1246
1422
|
}
|
|
1247
1423
|
}
|
|
1424
|
+
_temp = new WeakMap();
|
|
1425
|
+
_backUpDefaultStorage = new WeakMap();
|
|
1426
|
+
_createTempStorage = new WeakSet();
|
|
1427
|
+
createTempStorage_fn = function() {
|
|
1428
|
+
return deepClone(__privateGet(this, _backUpDefaultStorage));
|
|
1429
|
+
};
|
|
1248
1430
|
function getViewScaleInfoFromSnapshot(snapshot) {
|
|
1249
1431
|
const { activeStore } = snapshot;
|
|
1250
1432
|
const sacelInfo = {
|
|
@@ -1313,6 +1495,21 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1313
1495
|
};
|
|
1314
1496
|
return calcElementCenter(elemSize);
|
|
1315
1497
|
}
|
|
1498
|
+
function calcRadian(center, start, end) {
|
|
1499
|
+
const startAngle = calcLineRadian(center, start);
|
|
1500
|
+
const endAngle = calcLineRadian(center, end);
|
|
1501
|
+
if (endAngle !== null && startAngle !== null) {
|
|
1502
|
+
if (startAngle > Math.PI * 3 / 2 && endAngle < Math.PI / 2) {
|
|
1503
|
+
return endAngle + (Math.PI * 2 - startAngle);
|
|
1504
|
+
} else if (endAngle > Math.PI * 3 / 2 && startAngle < Math.PI / 2) {
|
|
1505
|
+
return startAngle + (Math.PI * 2 - endAngle);
|
|
1506
|
+
} else {
|
|
1507
|
+
return endAngle - startAngle;
|
|
1508
|
+
}
|
|
1509
|
+
} else {
|
|
1510
|
+
return 0;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1316
1513
|
function calcLineRadian(center, p) {
|
|
1317
1514
|
const x2 = p.x - center.x;
|
|
1318
1515
|
const y2 = p.y - center.y;
|
|
@@ -1505,6 +1702,58 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1505
1702
|
}
|
|
1506
1703
|
return isValid;
|
|
1507
1704
|
}
|
|
1705
|
+
function calcElementListSize(list) {
|
|
1706
|
+
var _a;
|
|
1707
|
+
const area = { x: 0, y: 0, w: 0, h: 0 };
|
|
1708
|
+
let prevElemSize = null;
|
|
1709
|
+
for (let i = 0; i < list.length; i++) {
|
|
1710
|
+
const elem = list[i];
|
|
1711
|
+
if ((_a = elem == null ? void 0 : elem.operations) == null ? void 0 : _a.invisible) {
|
|
1712
|
+
continue;
|
|
1713
|
+
}
|
|
1714
|
+
const elemSize = {
|
|
1715
|
+
x: elem.x,
|
|
1716
|
+
y: elem.y,
|
|
1717
|
+
w: elem.w,
|
|
1718
|
+
h: elem.h,
|
|
1719
|
+
angle: elem.angle || 0
|
|
1720
|
+
};
|
|
1721
|
+
if (elemSize.angle && (elemSize.angle > 0 || elemSize.angle < 0)) {
|
|
1722
|
+
const ves = rotateElementVertexes(elemSize);
|
|
1723
|
+
if (ves.length === 4) {
|
|
1724
|
+
const xList = [ves[0].x, ves[1].x, ves[2].x, ves[3].x];
|
|
1725
|
+
const yList = [ves[0].y, ves[1].y, ves[2].y, ves[3].y];
|
|
1726
|
+
elemSize.x = Math.min(...xList);
|
|
1727
|
+
elemSize.y = Math.min(...yList);
|
|
1728
|
+
elemSize.w = Math.abs(Math.max(...xList) - Math.min(...xList));
|
|
1729
|
+
elemSize.h = Math.abs(Math.max(...yList) - Math.min(...yList));
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
if (prevElemSize) {
|
|
1733
|
+
const areaStartX = Math.min(elemSize.x, area.x);
|
|
1734
|
+
const areaStartY = Math.min(elemSize.y, area.y);
|
|
1735
|
+
const areaEndX = Math.max(elemSize.x + elemSize.w, area.x + area.w);
|
|
1736
|
+
const areaEndY = Math.max(elemSize.y + elemSize.h, area.y + area.h);
|
|
1737
|
+
area.x = areaStartX;
|
|
1738
|
+
area.y = areaStartY;
|
|
1739
|
+
area.w = Math.abs(areaEndX - areaStartX);
|
|
1740
|
+
area.h = Math.abs(areaEndY - areaStartY);
|
|
1741
|
+
} else {
|
|
1742
|
+
area.x = elemSize.x;
|
|
1743
|
+
area.y = elemSize.y;
|
|
1744
|
+
area.w = elemSize.w;
|
|
1745
|
+
area.h = elemSize.h;
|
|
1746
|
+
}
|
|
1747
|
+
prevElemSize = elemSize;
|
|
1748
|
+
}
|
|
1749
|
+
const listSize = {
|
|
1750
|
+
x: Math.floor(area.x),
|
|
1751
|
+
y: Math.floor(area.y),
|
|
1752
|
+
w: Math.ceil(area.w),
|
|
1753
|
+
h: Math.ceil(area.h)
|
|
1754
|
+
};
|
|
1755
|
+
return listSize;
|
|
1756
|
+
}
|
|
1508
1757
|
function calcElementsContextSize(elements, opts) {
|
|
1509
1758
|
const area = { x: 0, y: 0, w: 0, h: 0 };
|
|
1510
1759
|
elements.forEach((elem) => {
|
|
@@ -1640,6 +1889,24 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1640
1889
|
_scan(uuid, elements);
|
|
1641
1890
|
return groupQueue;
|
|
1642
1891
|
}
|
|
1892
|
+
function getGroupQueueByElementPosition(elements, position) {
|
|
1893
|
+
var _a;
|
|
1894
|
+
const groupQueue = [];
|
|
1895
|
+
let currentElements = elements;
|
|
1896
|
+
if (position.length > 1) {
|
|
1897
|
+
for (let i = 0; i < position.length - 1; i++) {
|
|
1898
|
+
const index = position[i];
|
|
1899
|
+
const group = currentElements[index];
|
|
1900
|
+
if ((group == null ? void 0 : group.type) === "group" && Array.isArray((_a = group == null ? void 0 : group.detail) == null ? void 0 : _a.children)) {
|
|
1901
|
+
groupQueue.push(group);
|
|
1902
|
+
currentElements = group.detail.children;
|
|
1903
|
+
} else {
|
|
1904
|
+
return null;
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
return groupQueue;
|
|
1909
|
+
}
|
|
1643
1910
|
function getElementSize(elem) {
|
|
1644
1911
|
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = elem;
|
|
1645
1912
|
const size = { x: x2, y: y2, w: w2, h: h2, angle: angle2 };
|
|
@@ -1730,8 +1997,27 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1730
1997
|
}
|
|
1731
1998
|
return result;
|
|
1732
1999
|
}
|
|
2000
|
+
function findElementQueueFromListByPosition(position, list) {
|
|
2001
|
+
const result = [];
|
|
2002
|
+
let tempList = list;
|
|
2003
|
+
for (let i = 0; i < position.length; i++) {
|
|
2004
|
+
const pos = position[i];
|
|
2005
|
+
const item = tempList[pos];
|
|
2006
|
+
if (item) {
|
|
2007
|
+
result.push(item);
|
|
2008
|
+
} else {
|
|
2009
|
+
break;
|
|
2010
|
+
}
|
|
2011
|
+
if (i < position.length - 1 && item.type === "group") {
|
|
2012
|
+
tempList = item.detail.children;
|
|
2013
|
+
} else {
|
|
2014
|
+
break;
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
return result;
|
|
2018
|
+
}
|
|
1733
2019
|
function getElementPositionFromList(uuid, elements) {
|
|
1734
|
-
|
|
2020
|
+
const result = [];
|
|
1735
2021
|
let over = false;
|
|
1736
2022
|
const _loop = (list) => {
|
|
1737
2023
|
var _a;
|
|
@@ -1757,15 +2043,86 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1757
2043
|
return result;
|
|
1758
2044
|
}
|
|
1759
2045
|
function checkRectIntersect(rect1, rect2) {
|
|
1760
|
-
const
|
|
1761
|
-
const
|
|
1762
|
-
const
|
|
1763
|
-
const
|
|
1764
|
-
const
|
|
1765
|
-
const
|
|
1766
|
-
const
|
|
1767
|
-
const
|
|
1768
|
-
return
|
|
2046
|
+
const rect1MinX = rect1.x;
|
|
2047
|
+
const rect1MinY = rect1.y;
|
|
2048
|
+
const rect1MaxX = rect1.x + rect1.w;
|
|
2049
|
+
const rect1MaxY = rect1.y + rect1.h;
|
|
2050
|
+
const rect2MinX = rect2.x;
|
|
2051
|
+
const rect2MinY = rect2.y;
|
|
2052
|
+
const rect2MaxX = rect2.x + rect2.w;
|
|
2053
|
+
const rect2MaxY = rect2.y + rect2.h;
|
|
2054
|
+
return rect1MinX <= rect2MaxX && rect1MaxX >= rect2MinX && rect1MinY <= rect2MaxY && rect1MaxY >= rect2MinY;
|
|
2055
|
+
}
|
|
2056
|
+
function getElementVertexes(elemSize) {
|
|
2057
|
+
const { x: x2, y: y2, h: h2, w: w2 } = elemSize;
|
|
2058
|
+
return [
|
|
2059
|
+
{ x: x2, y: y2 },
|
|
2060
|
+
{ x: x2 + w2, y: y2 },
|
|
2061
|
+
{ x: x2 + w2, y: y2 + h2 },
|
|
2062
|
+
{ x: x2, y: y2 + h2 }
|
|
2063
|
+
];
|
|
2064
|
+
}
|
|
2065
|
+
function calcElementVertexes(elemSize) {
|
|
2066
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemSize;
|
|
2067
|
+
if (angle2 === 0) {
|
|
2068
|
+
return getElementVertexes(elemSize);
|
|
2069
|
+
}
|
|
2070
|
+
return getElementRotateVertexes(elemSize, calcElementCenter({ x: x2, y: y2, w: w2, h: h2, angle: angle2 }), angle2);
|
|
2071
|
+
}
|
|
2072
|
+
function calcElementQueueVertexesQueueInGroup(groupQueue) {
|
|
2073
|
+
const vesList = [];
|
|
2074
|
+
let totalX = 0;
|
|
2075
|
+
let totalY = 0;
|
|
2076
|
+
const rotateActionList = [];
|
|
2077
|
+
const elemQueue = [...groupQueue];
|
|
2078
|
+
for (let i = 0; i < elemQueue.length; i++) {
|
|
2079
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemQueue[i];
|
|
2080
|
+
totalX += x2;
|
|
2081
|
+
totalY += y2;
|
|
2082
|
+
let ves;
|
|
2083
|
+
if (i === 0) {
|
|
2084
|
+
const elemSize = { x: totalX, y: totalY, w: w2, h: h2, angle: angle2 };
|
|
2085
|
+
ves = calcElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
|
|
2086
|
+
rotateActionList.push({
|
|
2087
|
+
center: calcElementCenter(elemSize),
|
|
2088
|
+
angle: angle2,
|
|
2089
|
+
radian: parseAngleToRadian(angle2)
|
|
2090
|
+
});
|
|
2091
|
+
} else {
|
|
2092
|
+
const elemSize = { x: totalX, y: totalY, w: w2, h: h2, angle: angle2 };
|
|
2093
|
+
ves = getElementVertexes(elemSize);
|
|
2094
|
+
for (let aIdx = 0; aIdx < rotateActionList.length; aIdx++) {
|
|
2095
|
+
const { center, radian } = rotateActionList[aIdx];
|
|
2096
|
+
ves = rotateVertexes(center, ves, radian);
|
|
2097
|
+
}
|
|
2098
|
+
const vesCenter = calcElementCenterFromVertexes(ves);
|
|
2099
|
+
if (angle2 > 0 || angle2 < 0) {
|
|
2100
|
+
const radian = parseAngleToRadian(angle2);
|
|
2101
|
+
ves = rotateVertexes(vesCenter, ves, radian);
|
|
2102
|
+
}
|
|
2103
|
+
rotateActionList.push({
|
|
2104
|
+
center: vesCenter,
|
|
2105
|
+
angle: angle2,
|
|
2106
|
+
radian: parseAngleToRadian(angle2)
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
2109
|
+
vesList.push(ves);
|
|
2110
|
+
}
|
|
2111
|
+
return vesList;
|
|
2112
|
+
}
|
|
2113
|
+
function calcElementVertexesQueueInGroup(targetElem, opts) {
|
|
2114
|
+
const { groupQueue } = opts;
|
|
2115
|
+
if (!(groupQueue.length > 0)) {
|
|
2116
|
+
return [calcElementVertexes(targetElem)];
|
|
2117
|
+
}
|
|
2118
|
+
const elemQueue = [...groupQueue, ...[targetElem]];
|
|
2119
|
+
const vesList = calcElementQueueVertexesQueueInGroup(elemQueue);
|
|
2120
|
+
return vesList;
|
|
2121
|
+
}
|
|
2122
|
+
function calcElementVertexesInGroup(targetElem, opts) {
|
|
2123
|
+
const vesList = calcElementVertexesQueueInGroup(targetElem, opts);
|
|
2124
|
+
const ves = vesList.pop();
|
|
2125
|
+
return ves || null;
|
|
1769
2126
|
}
|
|
1770
2127
|
function calcViewScaleInfo(info, opts) {
|
|
1771
2128
|
const { scale, offsetX, offsetY } = info;
|
|
@@ -1853,9 +2210,9 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1853
2210
|
];
|
|
1854
2211
|
}
|
|
1855
2212
|
function isViewPointInElement(p, opts) {
|
|
1856
|
-
const { context2d: ctx, element: elem, viewScaleInfo
|
|
2213
|
+
const { context2d: ctx, element: elem, viewScaleInfo } = opts;
|
|
1857
2214
|
const { angle: angle2 = 0 } = elem;
|
|
1858
|
-
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo
|
|
2215
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo });
|
|
1859
2216
|
const vertexes = rotateElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
|
|
1860
2217
|
if (vertexes.length >= 2) {
|
|
1861
2218
|
ctx.beginPath();
|
|
@@ -1870,6 +2227,25 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1870
2227
|
}
|
|
1871
2228
|
return false;
|
|
1872
2229
|
}
|
|
2230
|
+
function isViewPointInElementSize(p, elemSize, opts) {
|
|
2231
|
+
const vertexes = calcElementVertexes(elemSize);
|
|
2232
|
+
return isViewPointInVertexes(p, vertexes, opts);
|
|
2233
|
+
}
|
|
2234
|
+
function isViewPointInVertexes(p, vertexes, opts) {
|
|
2235
|
+
const xList = [vertexes[0].x, vertexes[1].x, vertexes[2].x, vertexes[3].x];
|
|
2236
|
+
const yList = [vertexes[0].y, vertexes[1].y, vertexes[2].y, vertexes[3].y];
|
|
2237
|
+
const mixX = Math.min(...xList);
|
|
2238
|
+
const maxX = Math.max(...xList);
|
|
2239
|
+
const mixY = Math.min(...yList);
|
|
2240
|
+
const maxY = Math.max(...yList);
|
|
2241
|
+
if (p.x > mixX && p.x < maxX && p.y > mixY && p.y < maxY) {
|
|
2242
|
+
return true;
|
|
2243
|
+
}
|
|
2244
|
+
if ((opts == null ? void 0 : opts.includeBorder) === true && (p.x === mixX || p.x === maxX || p.y === mixY || p.y === maxY)) {
|
|
2245
|
+
return true;
|
|
2246
|
+
}
|
|
2247
|
+
return false;
|
|
2248
|
+
}
|
|
1873
2249
|
function getViewPointAtElement(p, opts) {
|
|
1874
2250
|
var _a, _b, _c;
|
|
1875
2251
|
const { context2d: ctx, data, viewScaleInfo, viewSizeInfo, groupQueue } = opts;
|
|
@@ -1940,7 +2316,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1940
2316
|
const { viewSizeInfo, viewScaleInfo } = opts;
|
|
1941
2317
|
const { width, height } = viewSizeInfo;
|
|
1942
2318
|
const { angle: angle2 } = elem;
|
|
1943
|
-
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo
|
|
2319
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo });
|
|
1944
2320
|
const ves = rotateElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
|
|
1945
2321
|
const viewSize = { x: 0, y: 0, w: width, h: height };
|
|
1946
2322
|
const elemStartX = Math.min(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
|
|
@@ -1950,76 +2326,244 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1950
2326
|
const elemSize = { x: elemStartX, y: elemStartY, w: elemEndX - elemStartX, h: elemEndY - elemStartY };
|
|
1951
2327
|
return checkRectIntersect(viewSize, elemSize);
|
|
1952
2328
|
}
|
|
1953
|
-
function
|
|
1954
|
-
const {
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
];
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
const
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
2329
|
+
function calcElementOriginRectInfo(elemSize, opts) {
|
|
2330
|
+
const { groupQueue } = opts;
|
|
2331
|
+
const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
|
|
2332
|
+
const top = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
|
|
2333
|
+
const right = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
|
|
2334
|
+
const bottom = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
|
|
2335
|
+
const left = getCenterFromTwoPoints(vertexes[3], vertexes[0]);
|
|
2336
|
+
const topLeft = vertexes[0];
|
|
2337
|
+
const topRight = vertexes[1];
|
|
2338
|
+
const bottomRight = vertexes[2];
|
|
2339
|
+
const bottomLeft = vertexes[3];
|
|
2340
|
+
const maxX = Math.max(topLeft.x, topRight.x, bottomRight.x, bottomLeft.x);
|
|
2341
|
+
const maxY = Math.max(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
|
|
2342
|
+
const minX = Math.min(topLeft.x, topRight.x, bottomRight.x, bottomLeft.x);
|
|
2343
|
+
const minY = Math.min(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
|
|
2344
|
+
const center = {
|
|
2345
|
+
x: (maxX + minX) / 2,
|
|
2346
|
+
y: (maxY + minY) / 2
|
|
2347
|
+
};
|
|
2348
|
+
const rectInfo = {
|
|
2349
|
+
center,
|
|
2350
|
+
topLeft,
|
|
2351
|
+
topRight,
|
|
2352
|
+
bottomLeft,
|
|
2353
|
+
bottomRight,
|
|
2354
|
+
top,
|
|
2355
|
+
right,
|
|
2356
|
+
left,
|
|
2357
|
+
bottom
|
|
2358
|
+
};
|
|
2359
|
+
return rectInfo;
|
|
2360
|
+
}
|
|
2361
|
+
function originRectInfoToRangeRectInfo(originRectInfo) {
|
|
2362
|
+
const rangeMaxX = Math.max(originRectInfo.topLeft.x, originRectInfo.topRight.x, originRectInfo.bottomRight.x, originRectInfo.bottomLeft.x);
|
|
2363
|
+
const rangeMaxY = Math.max(originRectInfo.topLeft.y, originRectInfo.topRight.y, originRectInfo.bottomRight.y, originRectInfo.bottomLeft.y);
|
|
2364
|
+
const rangeMinX = Math.min(originRectInfo.topLeft.x, originRectInfo.topRight.x, originRectInfo.bottomRight.x, originRectInfo.bottomLeft.x);
|
|
2365
|
+
const rangeMinY = Math.min(originRectInfo.topLeft.y, originRectInfo.topRight.y, originRectInfo.bottomRight.y, originRectInfo.bottomLeft.y);
|
|
2366
|
+
const rangeCenter = { x: originRectInfo.center.x, y: originRectInfo.center.y };
|
|
2367
|
+
const rangeTopLeft = { x: rangeMinX, y: rangeMinY };
|
|
2368
|
+
const rangeTopRight = { x: rangeMaxX, y: rangeMinY };
|
|
2369
|
+
const rangeBottomRight = { x: rangeMaxX, y: rangeMaxY };
|
|
2370
|
+
const rangeBottomLeft = { x: rangeMinX, y: rangeMaxY };
|
|
2371
|
+
const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
|
|
2372
|
+
const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
|
|
2373
|
+
const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
|
|
2374
|
+
const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
|
|
2375
|
+
const rangeRectInfo = {
|
|
2376
|
+
center: rangeCenter,
|
|
2377
|
+
topLeft: rangeTopLeft,
|
|
2378
|
+
topRight: rangeTopRight,
|
|
2379
|
+
bottomLeft: rangeBottomLeft,
|
|
2380
|
+
bottomRight: rangeBottomRight,
|
|
2381
|
+
top: rangeTop,
|
|
2382
|
+
right: rangeRight,
|
|
2383
|
+
left: rangeLeft,
|
|
2384
|
+
bottom: rangeBottom
|
|
2385
|
+
};
|
|
2386
|
+
return rangeRectInfo;
|
|
2387
|
+
}
|
|
2388
|
+
function calcElementViewRectInfo(elemSize, opts) {
|
|
2389
|
+
const { groupQueue, viewScaleInfo, range } = opts;
|
|
2390
|
+
const originRectInfo = calcElementOriginRectInfo(elemSize, { groupQueue });
|
|
2391
|
+
const { center, top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight } = originRectInfo;
|
|
2392
|
+
const viewRectInfo = {
|
|
2393
|
+
center: calcViewPointSize(center, { viewScaleInfo }),
|
|
2394
|
+
topLeft: calcViewPointSize(topLeft, { viewScaleInfo }),
|
|
2395
|
+
topRight: calcViewPointSize(topRight, { viewScaleInfo }),
|
|
2396
|
+
bottomLeft: calcViewPointSize(bottomLeft, { viewScaleInfo }),
|
|
2397
|
+
bottomRight: calcViewPointSize(bottomRight, { viewScaleInfo }),
|
|
2398
|
+
top: calcViewPointSize(top, { viewScaleInfo }),
|
|
2399
|
+
right: calcViewPointSize(right, { viewScaleInfo }),
|
|
2400
|
+
left: calcViewPointSize(left, { viewScaleInfo }),
|
|
2401
|
+
bottom: calcViewPointSize(bottom, { viewScaleInfo })
|
|
2402
|
+
};
|
|
2403
|
+
if (range === true) {
|
|
2404
|
+
const viewMaxX = Math.max(viewRectInfo.topLeft.x, viewRectInfo.topRight.x, viewRectInfo.bottomRight.x, viewRectInfo.bottomLeft.x);
|
|
2405
|
+
const viewMaxY = Math.max(viewRectInfo.topLeft.y, viewRectInfo.topRight.y, viewRectInfo.bottomRight.y, viewRectInfo.bottomLeft.y);
|
|
2406
|
+
const viewMinX = Math.min(viewRectInfo.topLeft.x, viewRectInfo.topRight.x, viewRectInfo.bottomRight.x, viewRectInfo.bottomLeft.x);
|
|
2407
|
+
const viewMinY = Math.min(viewRectInfo.topLeft.y, viewRectInfo.topRight.y, viewRectInfo.bottomRight.y, viewRectInfo.bottomLeft.y);
|
|
2408
|
+
const rangeCenter = { x: viewRectInfo.center.x, y: viewRectInfo.center.y };
|
|
2409
|
+
const rangeTopLeft = { x: viewMinX, y: viewMinY };
|
|
2410
|
+
const rangeTopRight = { x: viewMaxX, y: viewMinY };
|
|
2411
|
+
const rangeBottomRight = { x: viewMaxX, y: viewMaxY };
|
|
2412
|
+
const rangeBottomLeft = { x: viewMinX, y: viewMaxY };
|
|
2413
|
+
const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
|
|
2414
|
+
const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
|
|
2415
|
+
const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
|
|
2416
|
+
const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
|
|
2417
|
+
const rangeRectInfo = {
|
|
2418
|
+
center: rangeCenter,
|
|
2419
|
+
topLeft: rangeTopLeft,
|
|
2420
|
+
topRight: rangeTopRight,
|
|
2421
|
+
bottomLeft: rangeBottomLeft,
|
|
2422
|
+
bottomRight: rangeBottomRight,
|
|
2423
|
+
top: rangeTop,
|
|
2424
|
+
right: rangeRight,
|
|
2425
|
+
left: rangeLeft,
|
|
2426
|
+
bottom: rangeBottom
|
|
2427
|
+
};
|
|
2428
|
+
return rangeRectInfo;
|
|
2429
|
+
}
|
|
2430
|
+
return viewRectInfo;
|
|
2431
|
+
}
|
|
2432
|
+
function calcElementViewRectInfoMap(elemSize, opts) {
|
|
2433
|
+
const { groupQueue, viewScaleInfo } = opts;
|
|
2434
|
+
const originRectInfo = calcElementOriginRectInfo(elemSize, { groupQueue });
|
|
2435
|
+
const { center, top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight } = originRectInfo;
|
|
2436
|
+
const viewRectInfo = {
|
|
2437
|
+
center: calcViewPointSize(center, { viewScaleInfo }),
|
|
2438
|
+
topLeft: calcViewPointSize(topLeft, { viewScaleInfo }),
|
|
2439
|
+
topRight: calcViewPointSize(topRight, { viewScaleInfo }),
|
|
2440
|
+
bottomLeft: calcViewPointSize(bottomLeft, { viewScaleInfo }),
|
|
2441
|
+
bottomRight: calcViewPointSize(bottomRight, { viewScaleInfo }),
|
|
2442
|
+
top: calcViewPointSize(top, { viewScaleInfo }),
|
|
2443
|
+
right: calcViewPointSize(right, { viewScaleInfo }),
|
|
2444
|
+
left: calcViewPointSize(left, { viewScaleInfo }),
|
|
2445
|
+
bottom: calcViewPointSize(bottom, { viewScaleInfo })
|
|
2446
|
+
};
|
|
2447
|
+
const viewMaxX = Math.max(viewRectInfo.topLeft.x, viewRectInfo.topRight.x, viewRectInfo.bottomRight.x, viewRectInfo.bottomLeft.x);
|
|
2448
|
+
const viewMaxY = Math.max(viewRectInfo.topLeft.y, viewRectInfo.topRight.y, viewRectInfo.bottomRight.y, viewRectInfo.bottomLeft.y);
|
|
2449
|
+
const viewMinX = Math.min(viewRectInfo.topLeft.x, viewRectInfo.topRight.x, viewRectInfo.bottomRight.x, viewRectInfo.bottomLeft.x);
|
|
2450
|
+
const viewMinY = Math.min(viewRectInfo.topLeft.y, viewRectInfo.topRight.y, viewRectInfo.bottomRight.y, viewRectInfo.bottomLeft.y);
|
|
2451
|
+
const rangeCenter = { x: viewRectInfo.center.x, y: viewRectInfo.center.y };
|
|
2452
|
+
const rangeTopLeft = { x: viewMinX, y: viewMinY };
|
|
2453
|
+
const rangeTopRight = { x: viewMaxX, y: viewMinY };
|
|
2454
|
+
const rangeBottomRight = { x: viewMaxX, y: viewMaxY };
|
|
2455
|
+
const rangeBottomLeft = { x: viewMinX, y: viewMaxY };
|
|
2456
|
+
const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
|
|
2457
|
+
const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
|
|
2458
|
+
const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
|
|
2459
|
+
const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
|
|
2460
|
+
const rangeRectInfo = {
|
|
2461
|
+
center: rangeCenter,
|
|
2462
|
+
topLeft: rangeTopLeft,
|
|
2463
|
+
topRight: rangeTopRight,
|
|
2464
|
+
bottomLeft: rangeBottomLeft,
|
|
2465
|
+
bottomRight: rangeBottomRight,
|
|
2466
|
+
top: rangeTop,
|
|
2467
|
+
right: rangeRight,
|
|
2468
|
+
left: rangeLeft,
|
|
2469
|
+
bottom: rangeBottom
|
|
2470
|
+
};
|
|
2471
|
+
return {
|
|
2472
|
+
originRectInfo,
|
|
2473
|
+
// viewRectInfo,
|
|
2474
|
+
rangeRectInfo
|
|
2475
|
+
};
|
|
1968
2476
|
}
|
|
1969
|
-
function
|
|
1970
|
-
const
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
} else {
|
|
1989
|
-
const elemSize = { x: totalX, y: totalY, w: w2, h: h2, angle: angle2 };
|
|
1990
|
-
ves = getElementVertexes(elemSize);
|
|
1991
|
-
for (let aIdx = 0; aIdx < rotateActionList.length; aIdx++) {
|
|
1992
|
-
const { center, radian } = rotateActionList[aIdx];
|
|
1993
|
-
ves = rotateVertexes(center, ves, radian);
|
|
1994
|
-
}
|
|
1995
|
-
const vesCenter = calcElementCenterFromVertexes(ves);
|
|
1996
|
-
if (angle2 > 0 || angle2 < 0) {
|
|
1997
|
-
const radian = parseAngleToRadian(angle2);
|
|
1998
|
-
ves = rotateVertexes(vesCenter, ves, radian);
|
|
2477
|
+
function sortElementsViewVisiableInfoMap(elements, opts) {
|
|
2478
|
+
const visibleInfoMap = {};
|
|
2479
|
+
const currentPosition = [];
|
|
2480
|
+
const _walk = (elem) => {
|
|
2481
|
+
const baseInfo = {
|
|
2482
|
+
isVisibleInView: true,
|
|
2483
|
+
isGroup: elem.type === "group",
|
|
2484
|
+
position: [...currentPosition]
|
|
2485
|
+
};
|
|
2486
|
+
let originRectInfo = null;
|
|
2487
|
+
const groupQueue = getGroupQueueByElementPosition(elements, currentPosition);
|
|
2488
|
+
originRectInfo = calcElementOriginRectInfo(elem, {
|
|
2489
|
+
groupQueue: groupQueue || []
|
|
2490
|
+
});
|
|
2491
|
+
visibleInfoMap[elem.uuid] = {
|
|
2492
|
+
...baseInfo,
|
|
2493
|
+
...{
|
|
2494
|
+
originRectInfo,
|
|
2495
|
+
rangeRectInfo: is.angle(elem.angle) ? originRectInfoToRangeRectInfo(originRectInfo) : originRectInfo
|
|
1999
2496
|
}
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2497
|
+
};
|
|
2498
|
+
if (elem.type === "group") {
|
|
2499
|
+
elem.detail.children.forEach((ele, i) => {
|
|
2500
|
+
currentPosition.push(i);
|
|
2501
|
+
_walk(ele);
|
|
2502
|
+
currentPosition.pop();
|
|
2004
2503
|
});
|
|
2005
2504
|
}
|
|
2006
|
-
|
|
2505
|
+
};
|
|
2506
|
+
elements.forEach((elem, index) => {
|
|
2507
|
+
currentPosition.push(index);
|
|
2508
|
+
_walk(elem);
|
|
2509
|
+
currentPosition.pop();
|
|
2510
|
+
});
|
|
2511
|
+
return updateViewVisibleInfoMapStatus(visibleInfoMap, opts);
|
|
2512
|
+
}
|
|
2513
|
+
function isRangeRectInfoCollide(info1, info2) {
|
|
2514
|
+
const rect1MinX = Math.min(info1.topLeft.x, info1.topRight.x, info1.bottomLeft.x, info1.bottomRight.x);
|
|
2515
|
+
const rect1MaxX = Math.max(info1.topLeft.x, info1.topRight.x, info1.bottomLeft.x, info1.bottomRight.x);
|
|
2516
|
+
const rect1MinY = Math.min(info1.topLeft.y, info1.topRight.y, info1.bottomLeft.y, info1.bottomRight.y);
|
|
2517
|
+
const rect1MaxY = Math.max(info1.topLeft.y, info1.topRight.y, info1.bottomLeft.y, info1.bottomRight.y);
|
|
2518
|
+
const rect2MinX = Math.min(info2.topLeft.x, info2.topRight.x, info2.bottomLeft.x, info2.bottomRight.x);
|
|
2519
|
+
const rect2MaxX = Math.max(info2.topLeft.x, info2.topRight.x, info2.bottomLeft.x, info2.bottomRight.x);
|
|
2520
|
+
const rect2MinY = Math.min(info2.topLeft.y, info2.topRight.y, info2.bottomLeft.y, info2.bottomRight.y);
|
|
2521
|
+
const rect2MaxY = Math.max(info2.topLeft.y, info2.topRight.y, info2.bottomLeft.y, info2.bottomRight.y);
|
|
2522
|
+
if (rect1MinX <= rect2MaxX && rect1MaxX >= rect2MinX && rect1MinY <= rect2MaxY && rect1MaxY >= rect2MinY || rect2MaxX <= rect1MaxY && rect2MaxX >= rect1MaxY && rect2MaxX <= rect1MaxY && rect2MaxX >= rect1MaxY) {
|
|
2523
|
+
return true;
|
|
2007
2524
|
}
|
|
2008
|
-
return
|
|
2525
|
+
return false;
|
|
2009
2526
|
}
|
|
2010
|
-
function
|
|
2011
|
-
const
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2527
|
+
function updateViewVisibleInfoMapStatus(viewVisibleInfoMap, opts) {
|
|
2528
|
+
const canvasRectInfo = calcVisibleOriginCanvasRectInfo(opts);
|
|
2529
|
+
let visibleCount = 0;
|
|
2530
|
+
let invisibleCount = 0;
|
|
2531
|
+
Object.keys(viewVisibleInfoMap).forEach((uuid) => {
|
|
2532
|
+
const info = viewVisibleInfoMap[uuid];
|
|
2533
|
+
info.isVisibleInView = isRangeRectInfoCollide(info.rangeRectInfo, canvasRectInfo);
|
|
2534
|
+
info.isVisibleInView ? visibleCount++ : invisibleCount++;
|
|
2535
|
+
});
|
|
2536
|
+
return { viewVisibleInfoMap, visibleCount, invisibleCount };
|
|
2018
2537
|
}
|
|
2019
|
-
function
|
|
2020
|
-
const
|
|
2021
|
-
const
|
|
2022
|
-
|
|
2538
|
+
function calcVisibleOriginCanvasRectInfo(opts) {
|
|
2539
|
+
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
2540
|
+
const { scale, offsetTop, offsetLeft } = viewScaleInfo;
|
|
2541
|
+
const { width, height } = viewSizeInfo;
|
|
2542
|
+
const x2 = 0 - offsetLeft / scale;
|
|
2543
|
+
const y2 = 0 - offsetTop / scale;
|
|
2544
|
+
const w2 = width / scale;
|
|
2545
|
+
const h2 = height / scale;
|
|
2546
|
+
const center = calcElementCenter({ x: x2, y: y2, w: w2, h: h2 });
|
|
2547
|
+
const topLeft = { x: x2, y: y2 };
|
|
2548
|
+
const topRight = { x: x2 + w2, y: y2 };
|
|
2549
|
+
const bottomLeft = { x: x2, y: y2 + h2 };
|
|
2550
|
+
const bottomRight = { x: x2 + w2, y: y2 + h2 };
|
|
2551
|
+
const left = { x: x2, y: center.y };
|
|
2552
|
+
const top = { x: center.x, y: y2 };
|
|
2553
|
+
const right = { x: x2 + w2, y: center.y };
|
|
2554
|
+
const bottom = { x: center.x, y: y2 + h2 };
|
|
2555
|
+
const rectInfo = {
|
|
2556
|
+
center,
|
|
2557
|
+
topLeft,
|
|
2558
|
+
topRight,
|
|
2559
|
+
bottomLeft,
|
|
2560
|
+
bottomRight,
|
|
2561
|
+
left,
|
|
2562
|
+
top,
|
|
2563
|
+
right,
|
|
2564
|
+
bottom
|
|
2565
|
+
};
|
|
2566
|
+
return rectInfo;
|
|
2023
2567
|
}
|
|
2024
2568
|
function createControllerElementSizeFromCenter(center, opts) {
|
|
2025
2569
|
const { x: x2, y: y2 } = center;
|
|
@@ -2056,6 +2600,16 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2056
2600
|
totalAngle += angle22;
|
|
2057
2601
|
});
|
|
2058
2602
|
const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
|
|
2603
|
+
const rotateElemVertexes = calcElementVertexesInGroup(
|
|
2604
|
+
{
|
|
2605
|
+
x: x2 - ctrlSize * 2,
|
|
2606
|
+
y: y2 - ctrlSize * 2,
|
|
2607
|
+
h: h2 + ctrlSize * 4,
|
|
2608
|
+
w: w2 + ctrlSize * 4,
|
|
2609
|
+
angle: angle2
|
|
2610
|
+
},
|
|
2611
|
+
{ groupQueue: [...groupQueue] }
|
|
2612
|
+
);
|
|
2059
2613
|
const topCenter = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
|
|
2060
2614
|
const rightCenter = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
|
|
2061
2615
|
const bottomCenter = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
|
|
@@ -2064,6 +2618,10 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2064
2618
|
const topRightCenter = vertexes[1];
|
|
2065
2619
|
const bottomRightCenter = vertexes[2];
|
|
2066
2620
|
const bottomLeftCenter = vertexes[3];
|
|
2621
|
+
const topMiddleSize = createControllerElementSizeFromCenter(topCenter, { size: ctrlSize, angle: totalAngle });
|
|
2622
|
+
const rightMiddleSize = createControllerElementSizeFromCenter(rightCenter, { size: ctrlSize, angle: totalAngle });
|
|
2623
|
+
const bottomMiddleSize = createControllerElementSizeFromCenter(bottomCenter, { size: ctrlSize, angle: totalAngle });
|
|
2624
|
+
const leftMiddleSize = createControllerElementSizeFromCenter(leftCenter, { size: ctrlSize, angle: totalAngle });
|
|
2067
2625
|
const topLeftSize = createControllerElementSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: totalAngle });
|
|
2068
2626
|
const topRightSize = createControllerElementSizeFromCenter(topRightCenter, { size: ctrlSize, angle: totalAngle });
|
|
2069
2627
|
const bottomLeftSize = createControllerElementSizeFromCenter(bottomLeftCenter, { size: ctrlSize, angle: totalAngle });
|
|
@@ -2076,6 +2634,13 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2076
2634
|
const rightVertexes = [topRightVertexes[3], topRightVertexes[2], bottomRightVertexes[1], bottomRightVertexes[0]];
|
|
2077
2635
|
const bottomVertexes = [bottomLeftVertexes[1], bottomRightVertexes[0], bottomRightVertexes[3], bottomLeftVertexes[2]];
|
|
2078
2636
|
const leftVertexes = [topLeftVertexes[3], topLeftVertexes[2], bottomLeftVertexes[1], bottomLeftVertexes[0]];
|
|
2637
|
+
const topMiddleVertexes = calcElementVertexes(topMiddleSize);
|
|
2638
|
+
const rightMiddleVertexes = calcElementVertexes(rightMiddleSize);
|
|
2639
|
+
const bottomMiddleVertexes = calcElementVertexes(bottomMiddleSize);
|
|
2640
|
+
const leftMiddleVertexes = calcElementVertexes(leftMiddleSize);
|
|
2641
|
+
const rotateCenter = getCenterFromTwoPoints(rotateElemVertexes[0], rotateElemVertexes[1]);
|
|
2642
|
+
const rotateSize = createControllerElementSizeFromCenter(rotateCenter, { size: ctrlSize, angle: totalAngle });
|
|
2643
|
+
const rotateVertexes2 = calcElementVertexes(rotateSize);
|
|
2079
2644
|
const sizeController = {
|
|
2080
2645
|
elementWrapper: vertexes,
|
|
2081
2646
|
left: {
|
|
@@ -2117,6 +2682,128 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2117
2682
|
type: "bottom-right",
|
|
2118
2683
|
vertexes: bottomRightVertexes,
|
|
2119
2684
|
center: bottomRightCenter
|
|
2685
|
+
},
|
|
2686
|
+
leftMiddle: {
|
|
2687
|
+
type: "left-middle",
|
|
2688
|
+
vertexes: leftMiddleVertexes,
|
|
2689
|
+
center: leftCenter
|
|
2690
|
+
},
|
|
2691
|
+
rightMiddle: {
|
|
2692
|
+
type: "right-middle",
|
|
2693
|
+
vertexes: rightMiddleVertexes,
|
|
2694
|
+
center: rightCenter
|
|
2695
|
+
},
|
|
2696
|
+
topMiddle: {
|
|
2697
|
+
type: "top-middle",
|
|
2698
|
+
vertexes: topMiddleVertexes,
|
|
2699
|
+
center: topCenter
|
|
2700
|
+
},
|
|
2701
|
+
bottomMiddle: {
|
|
2702
|
+
type: "bottom-middle",
|
|
2703
|
+
vertexes: bottomMiddleVertexes,
|
|
2704
|
+
center: bottomCenter
|
|
2705
|
+
},
|
|
2706
|
+
rotate: {
|
|
2707
|
+
type: "rotate",
|
|
2708
|
+
vertexes: rotateVertexes2,
|
|
2709
|
+
center: rotateCenter
|
|
2710
|
+
}
|
|
2711
|
+
};
|
|
2712
|
+
return sizeController;
|
|
2713
|
+
}
|
|
2714
|
+
function calcLayoutSizeController(layoutSize, opts) {
|
|
2715
|
+
const { controllerSize, viewScaleInfo } = opts;
|
|
2716
|
+
const ctrlSize = controllerSize && controllerSize > 0 ? controllerSize : 8;
|
|
2717
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(layoutSize, { viewScaleInfo });
|
|
2718
|
+
const center = calcElementCenter({ x: x2, y: y2, w: w2, h: h2 });
|
|
2719
|
+
const topCenter = { x: center.x, y: y2 };
|
|
2720
|
+
const rightCenter = { x: x2 + w2, y: center.y };
|
|
2721
|
+
const bottomCenter = { x: center.x, y: y2 + h2 };
|
|
2722
|
+
const leftCenter = { x: x2, y: center.y };
|
|
2723
|
+
const topLeftCenter = { x: x2, y: y2 };
|
|
2724
|
+
const topRightCenter = { x: x2 + w2, y: y2 };
|
|
2725
|
+
const bottomRightCenter = { x: x2 + w2, y: y2 + h2 };
|
|
2726
|
+
const bottomLeftCenter = { x: x2, y: y2 + h2 };
|
|
2727
|
+
const topMiddleSize = createControllerElementSizeFromCenter(topCenter, { size: ctrlSize, angle: 0 });
|
|
2728
|
+
const rightMiddleSize = createControllerElementSizeFromCenter(rightCenter, { size: ctrlSize, angle: 0 });
|
|
2729
|
+
const bottomMiddleSize = createControllerElementSizeFromCenter(bottomCenter, { size: ctrlSize, angle: 0 });
|
|
2730
|
+
const leftMiddleSize = createControllerElementSizeFromCenter(leftCenter, { size: ctrlSize, angle: 0 });
|
|
2731
|
+
const topLeftSize = createControllerElementSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: 0 });
|
|
2732
|
+
const topRightSize = createControllerElementSizeFromCenter(topRightCenter, { size: ctrlSize, angle: 0 });
|
|
2733
|
+
const bottomLeftSize = createControllerElementSizeFromCenter(bottomLeftCenter, { size: ctrlSize, angle: 0 });
|
|
2734
|
+
const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, { size: ctrlSize, angle: 0 });
|
|
2735
|
+
const topLeftVertexes = calcElementVertexes(topLeftSize);
|
|
2736
|
+
const topRightVertexes = calcElementVertexes(topRightSize);
|
|
2737
|
+
const bottomLeftVertexes = calcElementVertexes(bottomLeftSize);
|
|
2738
|
+
const bottomRightVertexes = calcElementVertexes(bottomRightSize);
|
|
2739
|
+
const topVertexes = [topLeftVertexes[1], topRightVertexes[0], topRightVertexes[3], topLeftVertexes[2]];
|
|
2740
|
+
const rightVertexes = [topRightVertexes[3], topRightVertexes[2], bottomRightVertexes[1], bottomRightVertexes[0]];
|
|
2741
|
+
const bottomVertexes = [bottomLeftVertexes[1], bottomRightVertexes[0], bottomRightVertexes[3], bottomLeftVertexes[2]];
|
|
2742
|
+
const leftVertexes = [topLeftVertexes[3], topLeftVertexes[2], bottomLeftVertexes[1], bottomLeftVertexes[0]];
|
|
2743
|
+
const topMiddleVertexes = calcElementVertexes(topMiddleSize);
|
|
2744
|
+
const rightMiddleVertexes = calcElementVertexes(rightMiddleSize);
|
|
2745
|
+
const bottomMiddleVertexes = calcElementVertexes(bottomMiddleSize);
|
|
2746
|
+
const leftMiddleVertexes = calcElementVertexes(leftMiddleSize);
|
|
2747
|
+
const sizeController = {
|
|
2748
|
+
left: {
|
|
2749
|
+
type: "left",
|
|
2750
|
+
vertexes: leftVertexes,
|
|
2751
|
+
center: leftCenter
|
|
2752
|
+
},
|
|
2753
|
+
right: {
|
|
2754
|
+
type: "right",
|
|
2755
|
+
vertexes: rightVertexes,
|
|
2756
|
+
center: rightCenter
|
|
2757
|
+
},
|
|
2758
|
+
top: {
|
|
2759
|
+
type: "top",
|
|
2760
|
+
vertexes: topVertexes,
|
|
2761
|
+
center: topCenter
|
|
2762
|
+
},
|
|
2763
|
+
bottom: {
|
|
2764
|
+
type: "bottom",
|
|
2765
|
+
vertexes: bottomVertexes,
|
|
2766
|
+
center: bottomCenter
|
|
2767
|
+
},
|
|
2768
|
+
topLeft: {
|
|
2769
|
+
type: "top-left",
|
|
2770
|
+
vertexes: topLeftVertexes,
|
|
2771
|
+
center: topLeftCenter
|
|
2772
|
+
},
|
|
2773
|
+
topRight: {
|
|
2774
|
+
type: "top-right",
|
|
2775
|
+
vertexes: topRightVertexes,
|
|
2776
|
+
center: topRightCenter
|
|
2777
|
+
},
|
|
2778
|
+
bottomLeft: {
|
|
2779
|
+
type: "bottom-left",
|
|
2780
|
+
vertexes: bottomLeftVertexes,
|
|
2781
|
+
center: bottomLeftCenter
|
|
2782
|
+
},
|
|
2783
|
+
bottomRight: {
|
|
2784
|
+
type: "bottom-right",
|
|
2785
|
+
vertexes: bottomRightVertexes,
|
|
2786
|
+
center: bottomRightCenter
|
|
2787
|
+
},
|
|
2788
|
+
leftMiddle: {
|
|
2789
|
+
type: "left-middle",
|
|
2790
|
+
vertexes: leftMiddleVertexes,
|
|
2791
|
+
center: leftCenter
|
|
2792
|
+
},
|
|
2793
|
+
rightMiddle: {
|
|
2794
|
+
type: "right-middle",
|
|
2795
|
+
vertexes: rightMiddleVertexes,
|
|
2796
|
+
center: rightCenter
|
|
2797
|
+
},
|
|
2798
|
+
topMiddle: {
|
|
2799
|
+
type: "top-middle",
|
|
2800
|
+
vertexes: topMiddleVertexes,
|
|
2801
|
+
center: topCenter
|
|
2802
|
+
},
|
|
2803
|
+
bottomMiddle: {
|
|
2804
|
+
type: "bottom-middle",
|
|
2805
|
+
vertexes: bottomMiddleVertexes,
|
|
2806
|
+
center: bottomCenter
|
|
2120
2807
|
}
|
|
2121
2808
|
};
|
|
2122
2809
|
return sizeController;
|
|
@@ -2354,6 +3041,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2354
3041
|
}
|
|
2355
3042
|
return radian;
|
|
2356
3043
|
}
|
|
3044
|
+
const defaultText = "Text Element";
|
|
2357
3045
|
function getDefaultElementDetailConfig() {
|
|
2358
3046
|
const config = {
|
|
2359
3047
|
boxSizing: "border-box",
|
|
@@ -2370,7 +3058,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2370
3058
|
textAlign: "left",
|
|
2371
3059
|
verticalAlign: "top",
|
|
2372
3060
|
fontSize: 16,
|
|
2373
|
-
lineHeight: 20,
|
|
3061
|
+
// lineHeight: 20,
|
|
2374
3062
|
fontFamily: "sans-serif",
|
|
2375
3063
|
fontWeight: 400,
|
|
2376
3064
|
overflow: "hidden"
|
|
@@ -2383,24 +3071,22 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2383
3071
|
};
|
|
2384
3072
|
return detail;
|
|
2385
3073
|
}
|
|
2386
|
-
function getDefaultElementCircleDetail(
|
|
3074
|
+
function getDefaultElementCircleDetail() {
|
|
2387
3075
|
const detail = {
|
|
2388
3076
|
background: "#D9D9D9",
|
|
2389
3077
|
radius: 0
|
|
2390
3078
|
};
|
|
2391
3079
|
return detail;
|
|
2392
3080
|
}
|
|
2393
|
-
function getDefaultElementTextDetail(
|
|
2394
|
-
var _a;
|
|
3081
|
+
function getDefaultElementTextDetail(elementSize) {
|
|
2395
3082
|
const detailConfig = getDefaultElementDetailConfig();
|
|
2396
|
-
const scale = ((_a = opts == null ? void 0 : opts.viewScaleInfo) == null ? void 0 : _a.scale) || 1;
|
|
2397
3083
|
const detail = {
|
|
2398
|
-
text:
|
|
3084
|
+
text: defaultText,
|
|
2399
3085
|
color: detailConfig.color,
|
|
2400
3086
|
fontFamily: detailConfig.fontFamily,
|
|
2401
3087
|
fontWeight: detailConfig.fontWeight,
|
|
2402
|
-
lineHeight:
|
|
2403
|
-
fontSize:
|
|
3088
|
+
lineHeight: elementSize.w / defaultText.length,
|
|
3089
|
+
fontSize: elementSize.w / defaultText.length,
|
|
2404
3090
|
textAlign: "center",
|
|
2405
3091
|
verticalAlign: "middle"
|
|
2406
3092
|
};
|
|
@@ -2418,7 +3104,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2418
3104
|
};
|
|
2419
3105
|
return detail;
|
|
2420
3106
|
}
|
|
2421
|
-
function getDefaultElementGroupDetail(
|
|
3107
|
+
function getDefaultElementGroupDetail() {
|
|
2422
3108
|
const detail = {
|
|
2423
3109
|
children: [],
|
|
2424
3110
|
background: "#D9D9D9",
|
|
@@ -2430,8 +3116,9 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2430
3116
|
function calcViewBoxSize(viewElem, opts) {
|
|
2431
3117
|
const { viewScaleInfo } = opts;
|
|
2432
3118
|
const { scale } = viewScaleInfo;
|
|
2433
|
-
let { borderRadius: borderRadius2
|
|
2434
|
-
|
|
3119
|
+
let { borderRadius: borderRadius2 } = viewElem.detail;
|
|
3120
|
+
const { boxSizing = defaultElemConfig.boxSizing, borderWidth: borderWidth2 } = viewElem.detail;
|
|
3121
|
+
if (Array.isArray(borderWidth2)) {
|
|
2435
3122
|
borderRadius2 = 0;
|
|
2436
3123
|
}
|
|
2437
3124
|
let { x: x2, y: y2, w: w2, h: h2 } = viewElem;
|
|
@@ -2475,9 +3162,105 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2475
3162
|
radiusList
|
|
2476
3163
|
};
|
|
2477
3164
|
}
|
|
3165
|
+
const doNum = (n) => {
|
|
3166
|
+
return formatNumber(n, { decimalPlaces: 4 });
|
|
3167
|
+
};
|
|
3168
|
+
function resizeElementBaseDetail(elem, opts) {
|
|
3169
|
+
const { detail } = elem;
|
|
3170
|
+
const { xRatio, yRatio, maxRatio } = opts;
|
|
3171
|
+
const middleRatio = (xRatio + yRatio) / 2;
|
|
3172
|
+
const { borderWidth: borderWidth2, borderRadius: borderRadius2, borderDash, shadowOffsetX, shadowOffsetY, shadowBlur } = detail;
|
|
3173
|
+
if (typeof borderWidth2 === "number") {
|
|
3174
|
+
detail.borderWidth = doNum(borderWidth2 * middleRatio);
|
|
3175
|
+
} else if (Array.isArray(detail.borderWidth)) {
|
|
3176
|
+
const bw = borderWidth2;
|
|
3177
|
+
detail.borderWidth = [doNum(bw[0] * yRatio), doNum(bw[1] * xRatio), doNum(bw[2] * yRatio), doNum(bw[3] * xRatio)];
|
|
3178
|
+
}
|
|
3179
|
+
if (typeof borderRadius2 === "number") {
|
|
3180
|
+
detail.borderRadius = doNum(borderRadius2 * middleRatio);
|
|
3181
|
+
} else if (Array.isArray(detail.borderRadius)) {
|
|
3182
|
+
const br = borderRadius2;
|
|
3183
|
+
detail.borderRadius = [br[0] * xRatio, br[1] * xRatio, br[2] * yRatio, br[3] * yRatio];
|
|
3184
|
+
}
|
|
3185
|
+
if (Array.isArray(borderDash)) {
|
|
3186
|
+
borderDash.forEach((dash, i) => {
|
|
3187
|
+
detail.borderDash[i] = doNum(dash * maxRatio);
|
|
3188
|
+
});
|
|
3189
|
+
}
|
|
3190
|
+
if (typeof shadowOffsetX === "number") {
|
|
3191
|
+
detail.shadowOffsetX = doNum(shadowOffsetX * maxRatio);
|
|
3192
|
+
}
|
|
3193
|
+
if (typeof shadowOffsetY === "number") {
|
|
3194
|
+
detail.shadowOffsetX = doNum(shadowOffsetY * maxRatio);
|
|
3195
|
+
}
|
|
3196
|
+
if (typeof shadowBlur === "number") {
|
|
3197
|
+
detail.shadowOffsetX = doNum(shadowBlur * maxRatio);
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
function resizeElementBase(elem, opts) {
|
|
3201
|
+
const { xRatio, yRatio } = opts;
|
|
3202
|
+
const { x: x2, y: y2, w: w2, h: h2 } = elem;
|
|
3203
|
+
elem.x = doNum(x2 * xRatio);
|
|
3204
|
+
elem.y = doNum(y2 * yRatio);
|
|
3205
|
+
elem.w = doNum(w2 * xRatio);
|
|
3206
|
+
elem.h = doNum(h2 * yRatio);
|
|
3207
|
+
resizeElementBaseDetail(elem, opts);
|
|
3208
|
+
}
|
|
3209
|
+
function resizeTextElementDetail(elem, opts) {
|
|
3210
|
+
const { minRatio, maxRatio } = opts;
|
|
3211
|
+
const { fontSize: fontSize2, lineHeight: lineHeight2 } = elem.detail;
|
|
3212
|
+
const ratio = (minRatio + maxRatio) / 2;
|
|
3213
|
+
if (fontSize2 && fontSize2 > 0) {
|
|
3214
|
+
elem.detail.fontSize = doNum(fontSize2 * ratio);
|
|
3215
|
+
}
|
|
3216
|
+
if (lineHeight2 && lineHeight2 > 0) {
|
|
3217
|
+
elem.detail.lineHeight = doNum(lineHeight2 * ratio);
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
function resizeElement(elem, opts) {
|
|
3221
|
+
const { type } = elem;
|
|
3222
|
+
resizeElementBase(elem, opts);
|
|
3223
|
+
if (type === "circle")
|
|
3224
|
+
;
|
|
3225
|
+
else if (type === "text") {
|
|
3226
|
+
resizeTextElementDetail(elem, opts);
|
|
3227
|
+
} else if (type === "image")
|
|
3228
|
+
;
|
|
3229
|
+
else if (type === "svg")
|
|
3230
|
+
;
|
|
3231
|
+
else if (type === "html")
|
|
3232
|
+
;
|
|
3233
|
+
else if (type === "path")
|
|
3234
|
+
;
|
|
3235
|
+
else if (type === "group" && Array.isArray(elem.detail.children)) {
|
|
3236
|
+
elem.detail.children.forEach((child) => {
|
|
3237
|
+
resizeElement(child, opts);
|
|
3238
|
+
});
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
function deepResizeGroupElement(elem, size) {
|
|
3242
|
+
const resizeW = size.w && size.w > 0 ? size.w : elem.w;
|
|
3243
|
+
const resizeH = size.h && size.h > 0 ? size.h : elem.h;
|
|
3244
|
+
const xRatio = resizeW / elem.w;
|
|
3245
|
+
const yRatio = resizeH / elem.h;
|
|
3246
|
+
if (xRatio === yRatio && xRatio === 1) {
|
|
3247
|
+
return elem;
|
|
3248
|
+
}
|
|
3249
|
+
const minRatio = Math.min(xRatio, yRatio);
|
|
3250
|
+
const maxRatio = Math.max(xRatio, yRatio);
|
|
3251
|
+
elem.w = resizeW;
|
|
3252
|
+
elem.h = resizeH;
|
|
3253
|
+
const opts = { xRatio, yRatio, minRatio, maxRatio };
|
|
3254
|
+
if (elem.type === "group" && Array.isArray(elem.detail.children)) {
|
|
3255
|
+
elem.detail.children.forEach((child) => {
|
|
3256
|
+
resizeElement(child, opts);
|
|
3257
|
+
});
|
|
3258
|
+
}
|
|
3259
|
+
resizeElementBaseDetail(elem, opts);
|
|
3260
|
+
return elem;
|
|
3261
|
+
}
|
|
2478
3262
|
const defaultViewWidth = 200;
|
|
2479
3263
|
const defaultViewHeight = 200;
|
|
2480
|
-
const defaultDetail = getDefaultElementDetailConfig();
|
|
2481
3264
|
function createElementSize(type, opts) {
|
|
2482
3265
|
let x2 = 0;
|
|
2483
3266
|
let y2 = 0;
|
|
@@ -2487,26 +3270,23 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2487
3270
|
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
2488
3271
|
const { scale, offsetLeft, offsetTop } = viewScaleInfo;
|
|
2489
3272
|
const { width, height } = viewSizeInfo;
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
3273
|
+
const limitViewWidth = width / 4;
|
|
3274
|
+
const limitViewHeight = height / 4;
|
|
3275
|
+
if (defaultViewWidth >= limitViewWidth) {
|
|
3276
|
+
w2 = limitViewWidth / scale;
|
|
2494
3277
|
} else {
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
if (["circle", "svg", "image"].includes(type)) {
|
|
2508
|
-
w2 = h2 = Math.max(w2, h2);
|
|
2509
|
-
}
|
|
3278
|
+
w2 = defaultViewWidth / scale;
|
|
3279
|
+
}
|
|
3280
|
+
if (defaultViewHeight >= limitViewHeight) {
|
|
3281
|
+
h2 = limitViewHeight / scale;
|
|
3282
|
+
} else {
|
|
3283
|
+
h2 = defaultViewHeight / scale;
|
|
3284
|
+
}
|
|
3285
|
+
if (["circle", "svg", "image"].includes(type)) {
|
|
3286
|
+
w2 = h2 = Math.max(w2, h2);
|
|
3287
|
+
} else if (type === "text") {
|
|
3288
|
+
const fontSize2 = w2 / defaultText.length;
|
|
3289
|
+
h2 = fontSize2 * 2;
|
|
2510
3290
|
}
|
|
2511
3291
|
x2 = (0 - offsetLeft + width / 2 - w2 * scale / 2) / scale;
|
|
2512
3292
|
y2 = (0 - offsetTop + height / 2 - h2 * scale / 2) / scale;
|
|
@@ -2520,16 +3300,14 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2520
3300
|
return elemSize;
|
|
2521
3301
|
}
|
|
2522
3302
|
function createElement(type, baseElem, opts) {
|
|
2523
|
-
const
|
|
3303
|
+
const elementSize = createElementSize(type, opts);
|
|
2524
3304
|
let detail = {};
|
|
2525
3305
|
if (type === "rect") {
|
|
2526
3306
|
detail = getDefaultElementRectDetail();
|
|
2527
3307
|
} else if (type === "circle") {
|
|
2528
|
-
detail = getDefaultElementCircleDetail(
|
|
2529
|
-
radius: elemSize.w
|
|
2530
|
-
});
|
|
3308
|
+
detail = getDefaultElementCircleDetail();
|
|
2531
3309
|
} else if (type === "text") {
|
|
2532
|
-
detail = getDefaultElementTextDetail(
|
|
3310
|
+
detail = getDefaultElementTextDetail(elementSize);
|
|
2533
3311
|
} else if (type === "svg") {
|
|
2534
3312
|
detail = getDefaultElementSVGDetail();
|
|
2535
3313
|
} else if (type === "image") {
|
|
@@ -2538,7 +3316,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2538
3316
|
detail = getDefaultElementGroupDetail();
|
|
2539
3317
|
}
|
|
2540
3318
|
const elem = {
|
|
2541
|
-
...
|
|
3319
|
+
...elementSize,
|
|
2542
3320
|
...baseElem,
|
|
2543
3321
|
uuid: createUUID(),
|
|
2544
3322
|
type,
|
|
@@ -2602,15 +3380,16 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2602
3380
|
return deleteElementInListByPosition(position, list);
|
|
2603
3381
|
}
|
|
2604
3382
|
function moveElementPosition(elements, opts) {
|
|
2605
|
-
const
|
|
3383
|
+
const from = [...opts.from];
|
|
3384
|
+
const to = [...opts.to];
|
|
2606
3385
|
if (from.length === 0 || to.length === 0) {
|
|
2607
|
-
return elements;
|
|
3386
|
+
return { elements, from, to };
|
|
2608
3387
|
}
|
|
2609
3388
|
if (from.length <= to.length) {
|
|
2610
3389
|
for (let i = 0; i < from.length; i++) {
|
|
2611
3390
|
if (to[i] === from[i]) {
|
|
2612
3391
|
if (i === from.length - 1) {
|
|
2613
|
-
return elements;
|
|
3392
|
+
return { elements, from, to };
|
|
2614
3393
|
}
|
|
2615
3394
|
continue;
|
|
2616
3395
|
}
|
|
@@ -2620,7 +3399,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2620
3399
|
if (target) {
|
|
2621
3400
|
const insterResult = insertElementToListByPosition(target, to, elements);
|
|
2622
3401
|
if (!insterResult) {
|
|
2623
|
-
return elements;
|
|
3402
|
+
return { elements, from, to };
|
|
2624
3403
|
}
|
|
2625
3404
|
let trimDeletePosIndex = -1;
|
|
2626
3405
|
for (let i = 0; i < from.length; i++) {
|
|
@@ -2641,7 +3420,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2641
3420
|
}
|
|
2642
3421
|
deleteElementInListByPosition(from, elements);
|
|
2643
3422
|
}
|
|
2644
|
-
return elements;
|
|
3423
|
+
return { elements, from, to };
|
|
2645
3424
|
}
|
|
2646
3425
|
function mergeElement(originElem, updateContent) {
|
|
2647
3426
|
var _a;
|
|
@@ -2674,38 +3453,243 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2674
3453
|
return originElem;
|
|
2675
3454
|
}
|
|
2676
3455
|
function updateElementInList(uuid, updateContent, elements) {
|
|
2677
|
-
var _a;
|
|
3456
|
+
var _a, _b;
|
|
2678
3457
|
let targetElement = null;
|
|
2679
3458
|
for (let i = 0; i < elements.length; i++) {
|
|
2680
3459
|
const elem = elements[i];
|
|
2681
3460
|
if (elem.uuid === uuid) {
|
|
3461
|
+
if (elem.type === "group" && ((_a = elem.operations) == null ? void 0 : _a.deepResize) === true) {
|
|
3462
|
+
if (updateContent.w && updateContent.w > 0 || updateContent.h && updateContent.h > 0) {
|
|
3463
|
+
deepResizeGroupElement(elem, {
|
|
3464
|
+
w: updateContent.w,
|
|
3465
|
+
h: updateContent.h
|
|
3466
|
+
});
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
2682
3469
|
mergeElement(elem, updateContent);
|
|
2683
3470
|
targetElement = elem;
|
|
2684
3471
|
break;
|
|
2685
3472
|
} else if (elem.type === "group") {
|
|
2686
|
-
targetElement = updateElementInList(uuid, updateContent, ((
|
|
3473
|
+
targetElement = updateElementInList(uuid, updateContent, ((_b = elem == null ? void 0 : elem.detail) == null ? void 0 : _b.children) || []);
|
|
2687
3474
|
}
|
|
2688
3475
|
}
|
|
2689
3476
|
return targetElement;
|
|
2690
3477
|
}
|
|
3478
|
+
function updateElementInListByPosition(position, updateContent, elements) {
|
|
3479
|
+
var _a;
|
|
3480
|
+
const elem = findElementFromListByPosition(position, elements);
|
|
3481
|
+
if (elem) {
|
|
3482
|
+
if (elem.type === "group" && ((_a = elem.operations) == null ? void 0 : _a.deepResize) === true) {
|
|
3483
|
+
if (updateContent.w && updateContent.w > 0 || updateContent.h && updateContent.h > 0) {
|
|
3484
|
+
deepResizeGroupElement(elem, {
|
|
3485
|
+
w: updateContent.w,
|
|
3486
|
+
h: updateContent.h
|
|
3487
|
+
});
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
mergeElement(elem, updateContent);
|
|
3491
|
+
}
|
|
3492
|
+
return elem;
|
|
3493
|
+
}
|
|
3494
|
+
function calcViewCenterContent(data, opts) {
|
|
3495
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3496
|
+
let offsetX = 0;
|
|
3497
|
+
let offsetY = 0;
|
|
3498
|
+
let scale = 1;
|
|
3499
|
+
let contentX = ((_b = (_a = data == null ? void 0 : data.elements) == null ? void 0 : _a[0]) == null ? void 0 : _b.x) || 0;
|
|
3500
|
+
let contentY = ((_d = (_c = data == null ? void 0 : data.elements) == null ? void 0 : _c[0]) == null ? void 0 : _d.y) || 0;
|
|
3501
|
+
let contentW = ((_f = (_e = data == null ? void 0 : data.elements) == null ? void 0 : _e[0]) == null ? void 0 : _f.w) || 0;
|
|
3502
|
+
let contentH = ((_h = (_g = data == null ? void 0 : data.elements) == null ? void 0 : _g[0]) == null ? void 0 : _h.h) || 0;
|
|
3503
|
+
const { width, height } = opts.viewSizeInfo;
|
|
3504
|
+
if (data.layout && ((_j = (_i = data.layout) == null ? void 0 : _i.detail) == null ? void 0 : _j.overflow) === "hidden") {
|
|
3505
|
+
contentX = 0;
|
|
3506
|
+
contentY = 0;
|
|
3507
|
+
contentW = data.layout.w || 0;
|
|
3508
|
+
contentH = data.layout.h || 0;
|
|
3509
|
+
} else {
|
|
3510
|
+
data.elements.forEach((elem) => {
|
|
3511
|
+
const elemSize = {
|
|
3512
|
+
x: elem.x,
|
|
3513
|
+
y: elem.y,
|
|
3514
|
+
w: elem.w,
|
|
3515
|
+
h: elem.h,
|
|
3516
|
+
angle: elem.angle
|
|
3517
|
+
};
|
|
3518
|
+
if (elemSize.angle && (elemSize.angle > 0 || elemSize.angle < 0)) {
|
|
3519
|
+
const ves = rotateElementVertexes(elemSize);
|
|
3520
|
+
if (ves.length === 4) {
|
|
3521
|
+
const xList = [ves[0].x, ves[1].x, ves[2].x, ves[3].x];
|
|
3522
|
+
const yList = [ves[0].y, ves[1].y, ves[2].y, ves[3].y];
|
|
3523
|
+
elemSize.x = Math.min(...xList);
|
|
3524
|
+
elemSize.y = Math.min(...yList);
|
|
3525
|
+
elemSize.w = Math.abs(Math.max(...xList) - Math.min(...xList));
|
|
3526
|
+
elemSize.h = Math.abs(Math.max(...yList) - Math.min(...yList));
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
const areaStartX = Math.min(elemSize.x, contentX);
|
|
3530
|
+
const areaStartY = Math.min(elemSize.y, contentY);
|
|
3531
|
+
const areaEndX = Math.max(elemSize.x + elemSize.w, contentX + contentW);
|
|
3532
|
+
const areaEndY = Math.max(elemSize.y + elemSize.h, contentY + contentH);
|
|
3533
|
+
contentX = areaStartX;
|
|
3534
|
+
contentY = areaStartY;
|
|
3535
|
+
contentW = Math.abs(areaEndX - areaStartX);
|
|
3536
|
+
contentH = Math.abs(areaEndY - areaStartY);
|
|
3537
|
+
});
|
|
3538
|
+
}
|
|
3539
|
+
if (data.layout) {
|
|
3540
|
+
const { x: x2, y: y2, w: w2, h: h2 } = data.layout;
|
|
3541
|
+
if (is.x(x2) && is.y(y2) && is.w(w2) && is.h(h2)) {
|
|
3542
|
+
contentX = Math.min(contentX, x2);
|
|
3543
|
+
contentY = Math.min(contentY, y2);
|
|
3544
|
+
contentW = Math.max(contentW, w2);
|
|
3545
|
+
contentH = Math.max(contentH, h2);
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
if (contentW > 0 && contentH > 0) {
|
|
3549
|
+
const scaleW = formatNumber(width / contentW, { decimalPlaces: 4 });
|
|
3550
|
+
const scaleH = formatNumber(height / contentH, { decimalPlaces: 4 });
|
|
3551
|
+
scale = Math.min(scaleW, scaleH, 1);
|
|
3552
|
+
offsetX = (contentW * scale - width) / 2 / scale + contentX;
|
|
3553
|
+
offsetY = (contentH * scale - height) / 2 / scale + contentY;
|
|
3554
|
+
}
|
|
3555
|
+
const result = {
|
|
3556
|
+
offsetX: formatNumber(offsetX, { decimalPlaces: 0 }),
|
|
3557
|
+
offsetY: formatNumber(offsetY, { decimalPlaces: 0 }),
|
|
3558
|
+
scale
|
|
3559
|
+
};
|
|
3560
|
+
return result;
|
|
3561
|
+
}
|
|
3562
|
+
function calcViewCenter(opts) {
|
|
3563
|
+
let x2 = 0;
|
|
3564
|
+
let y2 = 0;
|
|
3565
|
+
if (opts) {
|
|
3566
|
+
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
3567
|
+
const { offsetLeft, offsetTop, scale } = viewScaleInfo;
|
|
3568
|
+
const { width, height } = viewSizeInfo;
|
|
3569
|
+
x2 = 0 - offsetLeft + width / scale / 2;
|
|
3570
|
+
y2 = 0 - offsetTop + height / scale / 2;
|
|
3571
|
+
}
|
|
3572
|
+
const p = {
|
|
3573
|
+
x: x2,
|
|
3574
|
+
y: y2
|
|
3575
|
+
};
|
|
3576
|
+
return p;
|
|
3577
|
+
}
|
|
3578
|
+
function modifyElement(data, options) {
|
|
3579
|
+
const { type } = options;
|
|
3580
|
+
const content = { ...options.content };
|
|
3581
|
+
if (type === "addElement") {
|
|
3582
|
+
const opts = options;
|
|
3583
|
+
const { element, position } = opts.content;
|
|
3584
|
+
if ((position == null ? void 0 : position.length) > 0) {
|
|
3585
|
+
insertElementToListByPosition(element, [...position], data.elements);
|
|
3586
|
+
} else {
|
|
3587
|
+
data.elements.push(element);
|
|
3588
|
+
}
|
|
3589
|
+
} else if (type === "deleteElement") {
|
|
3590
|
+
const opts = options;
|
|
3591
|
+
const { position } = opts.content;
|
|
3592
|
+
deleteElementInListByPosition(position, data.elements);
|
|
3593
|
+
} else if (type === "moveElement") {
|
|
3594
|
+
const opts = options;
|
|
3595
|
+
const { from, to } = opts.content;
|
|
3596
|
+
const movedResult = moveElementPosition(data.elements, { from, to });
|
|
3597
|
+
content.from = movedResult.from;
|
|
3598
|
+
content.to = movedResult.to;
|
|
3599
|
+
data.elements = movedResult.elements;
|
|
3600
|
+
} else if (type === "updateElement") {
|
|
3601
|
+
const opts = options;
|
|
3602
|
+
const { position, afterModifiedElement } = opts.content;
|
|
3603
|
+
updateElementInListByPosition(position, afterModifiedElement, data.elements);
|
|
3604
|
+
}
|
|
3605
|
+
return { data, content };
|
|
3606
|
+
}
|
|
3607
|
+
function _get(source, path, defaultValue = void 0) {
|
|
3608
|
+
const keyList = path.split(".");
|
|
3609
|
+
const result = keyList.reduce((obj, key) => {
|
|
3610
|
+
return Object(obj)[key];
|
|
3611
|
+
}, source);
|
|
3612
|
+
return result === void 0 ? defaultValue : result;
|
|
3613
|
+
}
|
|
3614
|
+
function _set(obj, path, value) {
|
|
3615
|
+
const keys = path.split(".");
|
|
3616
|
+
if (typeof obj !== "object")
|
|
3617
|
+
return obj;
|
|
3618
|
+
keys.reduce((o, k, i, _) => {
|
|
3619
|
+
if (i === _.length - 1) {
|
|
3620
|
+
o[k] = value;
|
|
3621
|
+
return null;
|
|
3622
|
+
} else if (k in o) {
|
|
3623
|
+
return o[k];
|
|
3624
|
+
} else {
|
|
3625
|
+
o[k] = /^[0-9]{1,}$/.test(_[i + 1]) ? [] : {};
|
|
3626
|
+
return o[k];
|
|
3627
|
+
}
|
|
3628
|
+
}, obj);
|
|
3629
|
+
return obj;
|
|
3630
|
+
}
|
|
3631
|
+
function getModifiedElement(target, originElement) {
|
|
3632
|
+
const modifiedElement = {};
|
|
3633
|
+
const pathList = [];
|
|
3634
|
+
const _walk = (t) => {
|
|
3635
|
+
if (istype.json(t)) {
|
|
3636
|
+
const keys = Object.keys(t);
|
|
3637
|
+
keys.forEach((key) => {
|
|
3638
|
+
pathList.push(key);
|
|
3639
|
+
if (istype.json(t[key]) || istype.array(t[key])) {
|
|
3640
|
+
_walk(t[key]);
|
|
3641
|
+
} else {
|
|
3642
|
+
const pathStr = pathList.join(".");
|
|
3643
|
+
if (pathStr !== "uuid") {
|
|
3644
|
+
const value = _get(originElement, pathStr);
|
|
3645
|
+
_set(modifiedElement, pathList.join("."), value);
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
pathList.pop();
|
|
3649
|
+
});
|
|
3650
|
+
} else if (istype.array(t)) {
|
|
3651
|
+
t.forEach((index) => {
|
|
3652
|
+
pathList.push(index);
|
|
3653
|
+
if (istype.json(t[index]) || istype.array(t[index])) {
|
|
3654
|
+
_walk(t[index]);
|
|
3655
|
+
} else {
|
|
3656
|
+
const value = _get(originElement, pathList.join("."));
|
|
3657
|
+
_set(modifiedElement, pathList.join("."), value);
|
|
3658
|
+
}
|
|
3659
|
+
pathList.pop();
|
|
3660
|
+
});
|
|
3661
|
+
}
|
|
3662
|
+
};
|
|
3663
|
+
_walk(target);
|
|
3664
|
+
return modifiedElement;
|
|
3665
|
+
}
|
|
2691
3666
|
exports.Context2D = Context2D;
|
|
2692
3667
|
exports.EventEmitter = EventEmitter;
|
|
2693
3668
|
exports.Store = Store;
|
|
2694
3669
|
exports.calcDistance = calcDistance;
|
|
2695
3670
|
exports.calcElementCenter = calcElementCenter;
|
|
2696
3671
|
exports.calcElementCenterFromVertexes = calcElementCenterFromVertexes;
|
|
3672
|
+
exports.calcElementListSize = calcElementListSize;
|
|
3673
|
+
exports.calcElementOriginRectInfo = calcElementOriginRectInfo;
|
|
2697
3674
|
exports.calcElementQueueVertexesQueueInGroup = calcElementQueueVertexesQueueInGroup;
|
|
2698
3675
|
exports.calcElementSizeController = calcElementSizeController;
|
|
2699
3676
|
exports.calcElementVertexesInGroup = calcElementVertexesInGroup;
|
|
2700
3677
|
exports.calcElementVertexesQueueInGroup = calcElementVertexesQueueInGroup;
|
|
3678
|
+
exports.calcElementViewRectInfo = calcElementViewRectInfo;
|
|
3679
|
+
exports.calcElementViewRectInfoMap = calcElementViewRectInfoMap;
|
|
2701
3680
|
exports.calcElementsContextSize = calcElementsContextSize;
|
|
2702
3681
|
exports.calcElementsViewInfo = calcElementsViewInfo;
|
|
3682
|
+
exports.calcLayoutSizeController = calcLayoutSizeController;
|
|
3683
|
+
exports.calcRadian = calcRadian;
|
|
2703
3684
|
exports.calcSpeed = calcSpeed;
|
|
2704
3685
|
exports.calcViewBoxSize = calcViewBoxSize;
|
|
3686
|
+
exports.calcViewCenter = calcViewCenter;
|
|
3687
|
+
exports.calcViewCenterContent = calcViewCenterContent;
|
|
2705
3688
|
exports.calcViewElementSize = calcViewElementSize;
|
|
2706
3689
|
exports.calcViewPointSize = calcViewPointSize;
|
|
2707
3690
|
exports.calcViewScaleInfo = calcViewScaleInfo;
|
|
2708
3691
|
exports.calcViewVertexes = calcViewVertexes;
|
|
3692
|
+
exports.calcVisibleOriginCanvasRectInfo = calcVisibleOriginCanvasRectInfo;
|
|
2709
3693
|
exports.check = check;
|
|
2710
3694
|
exports.checkRectIntersect = checkRectIntersect;
|
|
2711
3695
|
exports.colorNameToHex = colorNameToHex;
|
|
@@ -2714,21 +3698,27 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2714
3698
|
exports.compose = compose;
|
|
2715
3699
|
exports.compressImage = compressImage;
|
|
2716
3700
|
exports.createAssetId = createAssetId;
|
|
3701
|
+
exports.createBoardContent = createBoardContent;
|
|
2717
3702
|
exports.createContext2D = createContext2D;
|
|
2718
3703
|
exports.createElement = createElement;
|
|
2719
3704
|
exports.createOffscreenContext2D = createOffscreenContext2D;
|
|
2720
3705
|
exports.createUUID = createUUID;
|
|
2721
|
-
exports.
|
|
3706
|
+
exports.debounce = debounce;
|
|
2722
3707
|
exports.deepClone = deepClone;
|
|
3708
|
+
exports.deepCloneElement = deepCloneElement;
|
|
3709
|
+
exports.deepResizeGroupElement = deepResizeGroupElement;
|
|
2723
3710
|
exports.delay = delay;
|
|
2724
3711
|
exports.deleteElementInList = deleteElementInList;
|
|
2725
3712
|
exports.deleteElementInListByPosition = deleteElementInListByPosition;
|
|
3713
|
+
exports.downloadFileFromText = downloadFileFromText;
|
|
2726
3714
|
exports.downloadImageFromCanvas = downloadImageFromCanvas;
|
|
2727
3715
|
exports.equalPoint = equalPoint;
|
|
2728
3716
|
exports.equalTouchPoint = equalTouchPoint;
|
|
3717
|
+
exports.filterCompactData = filterCompactData;
|
|
2729
3718
|
exports.filterElementAsset = filterElementAsset;
|
|
2730
3719
|
exports.findElementFromList = findElementFromList;
|
|
2731
3720
|
exports.findElementFromListByPosition = findElementFromListByPosition;
|
|
3721
|
+
exports.findElementQueueFromListByPosition = findElementQueueFromListByPosition;
|
|
2732
3722
|
exports.findElementsFromList = findElementsFromList;
|
|
2733
3723
|
exports.findElementsFromListByPositions = findElementsFromListByPositions;
|
|
2734
3724
|
exports.formatNumber = formatNumber;
|
|
@@ -2742,7 +3732,9 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2742
3732
|
exports.getElementRotateVertexes = getElementRotateVertexes;
|
|
2743
3733
|
exports.getElementSize = getElementSize;
|
|
2744
3734
|
exports.getElementVertexes = getElementVertexes;
|
|
3735
|
+
exports.getGroupQueueByElementPosition = getGroupQueueByElementPosition;
|
|
2745
3736
|
exports.getGroupQueueFromList = getGroupQueueFromList;
|
|
3737
|
+
exports.getModifiedElement = getModifiedElement;
|
|
2746
3738
|
exports.getSelectedElementUUIDs = getSelectedElementUUIDs;
|
|
2747
3739
|
exports.getViewPointAtElement = getViewPointAtElement;
|
|
2748
3740
|
exports.getViewScaleInfoFromSnapshot = getViewScaleInfoFromSnapshot;
|
|
@@ -2754,6 +3746,8 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2754
3746
|
exports.isElementInView = isElementInView;
|
|
2755
3747
|
exports.isResourceElement = isResourceElement;
|
|
2756
3748
|
exports.isViewPointInElement = isViewPointInElement;
|
|
3749
|
+
exports.isViewPointInElementSize = isViewPointInElementSize;
|
|
3750
|
+
exports.isViewPointInVertexes = isViewPointInVertexes;
|
|
2757
3751
|
exports.istype = istype;
|
|
2758
3752
|
exports.limitAngle = limitAngle;
|
|
2759
3753
|
exports.loadHTML = loadHTML;
|
|
@@ -2763,7 +3757,9 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2763
3757
|
exports.matrixToRadian = matrixToRadian;
|
|
2764
3758
|
exports.mergeElementAsset = mergeElementAsset;
|
|
2765
3759
|
exports.mergeHexColorAlpha = mergeHexColorAlpha;
|
|
3760
|
+
exports.modifyElement = modifyElement;
|
|
2766
3761
|
exports.moveElementPosition = moveElementPosition;
|
|
3762
|
+
exports.originRectInfoToRangeRectInfo = originRectInfoToRangeRectInfo;
|
|
2767
3763
|
exports.parseAngleToRadian = parseAngleToRadian;
|
|
2768
3764
|
exports.parseFileToBase64 = parseFileToBase64;
|
|
2769
3765
|
exports.parseFileToText = parseFileToText;
|
|
@@ -2778,10 +3774,13 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2778
3774
|
exports.rotatePointInGroup = rotatePointInGroup;
|
|
2779
3775
|
exports.rotateVertexes = rotateVertexes;
|
|
2780
3776
|
exports.sortDataAsserts = sortDataAsserts;
|
|
3777
|
+
exports.sortElementsViewVisiableInfoMap = sortElementsViewVisiableInfoMap;
|
|
2781
3778
|
exports.throttle = throttle;
|
|
2782
3779
|
exports.toColorHexNum = toColorHexNum;
|
|
2783
3780
|
exports.toColorHexStr = toColorHexStr;
|
|
2784
3781
|
exports.updateElementInList = updateElementInList;
|
|
3782
|
+
exports.updateElementInListByPosition = updateElementInListByPosition;
|
|
3783
|
+
exports.updateViewVisibleInfoMapStatus = updateViewVisibleInfoMapStatus;
|
|
2785
3784
|
exports.vaildPoint = vaildPoint;
|
|
2786
3785
|
exports.vaildTouchPoint = vaildTouchPoint;
|
|
2787
3786
|
exports.validateElements = validateElements;
|