|
@@ -25,7 +25,7 @@
|
25
|
25
|
*/
|
26
|
26
|
|
27
|
27
|
(function hand() { //Code isolation
|
28
|
|
- const selectorStates = {
|
|
28
|
+ var selectorStates = {
|
29
|
29
|
pointing: 0,
|
30
|
30
|
selecting: 1,
|
31
|
31
|
moving: 2
|
|
@@ -46,11 +46,13 @@
|
46
|
46
|
els.unshift(a);
|
47
|
47
|
a = a.parentElement;
|
48
|
48
|
}
|
49
|
|
- var parentMathematics = els.find(el => el.getAttribute("class") === "MathElement");
|
|
49
|
+ var parentMathematics = els.find(function(el) {
|
|
50
|
+ return el.getAttribute("class") === "MathElement";
|
|
51
|
+ });
|
50
|
52
|
if ((parentMathematics) && parentMathematics.tagName === "svg") {
|
51
|
53
|
target = parentMathematics;
|
52
|
54
|
}
|
53
|
|
- return target ?? el;
|
|
55
|
+ return target || el;
|
54
|
56
|
}
|
55
|
57
|
|
56
|
58
|
function createSelectorRect() {
|
|
@@ -75,17 +77,15 @@
|
75
|
77
|
selectorState = selectorStates.moving;
|
76
|
78
|
selected = { x: x, y: y };
|
77
|
79
|
// Some of the selected elements could have been deleted
|
78
|
|
- selected_els = selected_els.filter(el => {
|
79
|
|
- return Tools.svg.getElementById(el.id) !== null
|
|
80
|
+ selected_els = selected_els.filter(function(el) {
|
|
81
|
+ return Tools.svg.getElementById(el.id) !== null;
|
|
82
|
+ });
|
|
83
|
+ translation_elements = selected_els.map(function(el) {
|
|
84
|
+ var tmatrix = get_translate_matrix(el);
|
|
85
|
+ return { x: tmatrix.e, y: tmatrix.f };
|
80
|
86
|
});
|
81
|
|
- translation_elements = selected_els.map(el => {
|
82
|
|
- let tmatrix = get_translate_matrix(el);
|
83
|
|
- return { x: tmatrix.e, y: tmatrix.f }
|
84
|
|
- });
|
85
|
|
- {
|
86
|
|
- let tmatrix = get_translate_matrix(selectionRect);
|
87
|
|
- selectionRectTranslation = { x: tmatrix.e, y: tmatrix.f };
|
88
|
|
- }
|
|
87
|
+ var tmatrix = get_translate_matrix(selectionRect);
|
|
88
|
+ selectionRectTranslation = { x: tmatrix.e, y: tmatrix.f };
|
89
|
89
|
}
|
90
|
90
|
|
91
|
91
|
function startSelector(x, y, evt) {
|
|
@@ -107,33 +107,32 @@
|
107
|
107
|
function calculateSelection() {
|
108
|
108
|
var scale = Tools.drawingArea.getCTM().a;
|
109
|
109
|
var selectionTBBox = selectionRect.transformedBBox(scale);
|
110
|
|
- return Array.from(Tools.drawingArea.children).filter(el => {
|
111
|
|
- return transformedBBoxIntersects(
|
112
|
|
- selectionTBBox,
|
113
|
|
- el.transformedBBox(scale)
|
114
|
|
- )
|
115
|
|
- });
|
|
110
|
+ var elements = Tools.drawingArea.children;
|
|
111
|
+ var selected = [];
|
|
112
|
+ for (var i=0; i < elements.length; i++) {
|
|
113
|
+ if (transformedBBoxIntersects(selectionTBBox, elements[i].transformedBBox(scale)))
|
|
114
|
+ selected.push(Tools.drawingArea.children[i]);
|
|
115
|
+ }
|
|
116
|
+ return selected;
|
116
|
117
|
}
|
117
|
118
|
|
118
|
119
|
function moveSelection(x, y) {
|
119
|
120
|
var dx = x - selected.x;
|
120
|
121
|
var dy = y - selected.y;
|
121
|
|
- var msgs = selected_els.map((el, i) => {
|
122
|
|
- return {
|
123
|
|
- type: "update",
|
124
|
|
- id: el.id,
|
125
|
|
- deltax: dx + translation_elements[i].x,
|
126
|
|
- deltay: dy + translation_elements[i].y
|
127
|
|
- }
|
128
|
|
- })
|
|
122
|
+ var msgs = selected_els.map(function(el, i) {
|
|
123
|
+ return {
|
|
124
|
+ type: "update",
|
|
125
|
+ id: el.id,
|
|
126
|
+ deltax: dx + translation_elements[i].x,
|
|
127
|
+ deltay: dy + translation_elements[i].y
|
|
128
|
+ };
|
|
129
|
+ })
|
129
|
130
|
var msg = {
|
130
|
131
|
_children: msgs
|
131
|
132
|
};
|
132
|
|
- {
|
133
|
|
- let tmatrix = get_translate_matrix(selectionRect);
|
134
|
|
- tmatrix.e = dx + selectionRectTranslation.x;
|
135
|
|
- tmatrix.f = dy + selectionRectTranslation.y;
|
136
|
|
- }
|
|
133
|
+ var tmatrix = get_translate_matrix(selectionRect);
|
|
134
|
+ tmatrix.e = dx + selectionRectTranslation.x;
|
|
135
|
+ tmatrix.f = dy + selectionRectTranslation.y;
|
137
|
136
|
var now = performance.now();
|
138
|
137
|
if (now - last_sent > 70) {
|
139
|
138
|
last_sent = now;
|
|
@@ -190,7 +189,7 @@
|
190
|
189
|
|
191
|
190
|
function clickSelector(x, y, evt) {
|
192
|
191
|
var scale = Tools.drawingArea.getCTM().a
|
193
|
|
- selectionRect = selectionRect ?? createSelectorRect();
|
|
192
|
+ selectionRect = selectionRect || createSelectorRect();
|
194
|
193
|
if (pointInTransformedBBox([x, y], selectionRect.transformedBBox(scale))) {
|
195
|
194
|
startMovingElements(x, y, evt);
|
196
|
195
|
} else if (Tools.drawingArea.contains(evt.target)) {
|