vibe-editor 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +65 -61
- package/src/scripts/js/Core.js +28 -9
- package/src/scripts/js/entry.js +6 -5
- package/src/scripts/js/gui/Annotations.js +27 -12
- package/src/scripts/js/gui/ScoreManipulator.js +6 -4
- package/src/scripts/js/gui/Tabbar.js +13 -4
- package/src/scripts/js/handlers/AnnotationChangeHandler.js +13 -1
- package/src/scripts/js/handlers/InsertModeHandler.js +3 -3
- package/src/scripts/js/handlers/PhantomElementHandler.js +3 -10
- package/src/scripts/js/handlers/WindowHandler.js +7 -7
- package/src/scripts/js/scripts/Core.js +932 -0
- package/src/scripts/js/scripts/MusicProcessor.js +810 -0
- package/src/scripts/js/scripts/VIBE.js +219 -0
- package/src/scripts/js/scripts/datastructures/MeasureMatrix.js +156 -0
- package/src/scripts/js/scripts/gui/Annotations.js +549 -0
- package/src/scripts/js/scripts/gui/Cursor.js +203 -0
- package/src/scripts/js/scripts/gui/PhantomElement.js +132 -0
- package/src/scripts/js/scripts/gui/ScoreManipulator.js +188 -0
- package/src/scripts/js/scripts/gui/Tabbar.js +705 -0
- package/src/scripts/js/{gui/Toolbar copy.js → scripts/gui/Toolbar.js} +15 -11
- package/src/scripts/js/scripts/handlers/AnnotationChangeHandler.js +650 -0
- package/src/scripts/js/scripts/handlers/ClickModeHandler.js +535 -0
- package/src/scripts/js/{gui → scripts/handlers}/CustomAnnotationShapeDrawer.js +34 -17
- package/src/scripts/js/{handlers/ModHandler.js → scripts/handlers/CustomToolbarHandler.js} +54 -66
- package/src/scripts/js/scripts/handlers/GlobalKeyboardHandler.js +372 -0
- package/src/scripts/js/scripts/handlers/Handler.js +2 -0
- package/src/scripts/js/{handlers/InsertModeHandler_deprecated.js → scripts/handlers/InsertModeHandler.js} +117 -164
- package/src/scripts/js/scripts/handlers/KeyModeHandler.js +405 -0
- package/src/scripts/js/scripts/handlers/LabelHandler.js +463 -0
- package/src/scripts/js/scripts/handlers/NoteDragHandler.js +97 -0
- package/src/scripts/js/scripts/handlers/PhantomElementHandler.js +168 -0
- package/src/scripts/js/scripts/handlers/ScoreManipulatorHandler.js +233 -0
- package/src/scripts/js/scripts/handlers/SidebarHandler.js +506 -0
- package/src/scripts/js/scripts/handlers/TooltipHandler.js +132 -0
- package/src/scripts/js/scripts/handlers/WindowHandler.js +278 -0
- package/src/scripts/js/scripts/utils/MEIOperations.js +2121 -0
- package/src/scripts/js/{utils/Mouse2MEI.js → scripts/utils/Mouse2SVG.js} +225 -57
- package/src/scripts/js/scripts/utils/SVGEditor.js +453 -0
- package/src/scripts/js/scripts/utils/Types.js +2 -0
- package/src/scripts/js/{utils/VerovioWrapper copy.js → scripts/utils/VerovioWrapper.js} +35 -21
- package/src/scripts/js/scripts/utils/coordinates.js +54 -0
- package/src/scripts/js/utils/Mouse2SVG.js +11 -4
- package/src/scripts/js/utils/VerovioWrapper.js +4 -4
- package/src/scripts/js/utils/coordinates.js +26 -2
- package/src/scripts/js/.DS_Store +0 -0
- package/src/scripts/js/MusicPlayer.js +0 -572
- package/src/scripts/js/datastructures/ScoreGraph copy.js +0 -432
- package/src/scripts/js/gui/CustomAnnotationDrawer.js +0 -114
- package/src/scripts/js/handlers/AnnotationDragHandler.js +0 -113
- package/src/scripts/js/handlers/AnnotationLineHandler.js +0 -113
- package/src/scripts/js/handlers/ArticulationHandler.js +0 -20
- package/src/scripts/js/handlers/HarmonyHandler.js +0 -282
- package/src/scripts/js/handlers/InsertModeHandler copy.js +0 -423
- package/src/scripts/js/handlers/KeyModeHandler copy.js +0 -407
- package/src/scripts/js/handlers/KeyModeHandler_deprecated.js +0 -411
- package/src/scripts/js/handlers/NoteDragHandler copy.js +0 -148
- package/src/scripts/js/handlers/NoteDragHandler_deprecated.js +0 -150
- package/src/scripts/js/handlers/SelectionHandler.js +0 -262
- package/src/scripts/js/utils/RectWrapper.js +0 -10
- package/src/scripts/js/utils/SVGFiller.js +0 -245
- package/src/scripts/js/utils/VerovioWrapperLocal.js +0 -156
- package/src/scripts/js/utils/firefoxBBoxes.js +0 -143
- package/src/styles/vibe.css +0 -785
- /package/src/scripts/js/{assets → scripts/assets}/mei_template.js +0 -0
- /package/src/scripts/js/{constants.js → scripts/constants.js} +0 -0
- /package/src/scripts/js/{datastructures → scripts/datastructures}/ScoreGraph.js +0 -0
- /package/src/scripts/js/{datastructures → scripts/datastructures}/ScoreGraph_deprecated.js +0 -0
- /package/src/scripts/js/{datastructures → scripts/datastructures}/ScoreNode.js +0 -0
- /package/src/scripts/js/{gui → scripts/gui}/HarmonyLabel.js +0 -0
- /package/src/scripts/js/{gui → scripts/gui}/Label.js +0 -0
- /package/src/scripts/js/{gui → scripts/gui}/TempoLabel.js +0 -0
- /package/src/scripts/js/{handlers → scripts/handlers}/DeleteHandler.js +0 -0
- /package/src/scripts/js/{utils → scripts/utils}/DOMCreator.js +0 -0
- /package/src/scripts/js/{utils → scripts/utils}/MEIConverter.js +0 -0
- /package/src/scripts/js/{utils → scripts/utils}/ReactWrapper.js +0 -0
- /package/src/scripts/js/{utils → scripts/utils}/convenienceQueries.js +0 -0
- /package/src/scripts/js/{utils → scripts/utils}/mappings.js +0 -0
- /package/src/scripts/js/{utils → scripts/utils}/random.js +0 -0
@@ -1,432 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const ScoreNode_1 = require("./ScoreNode");
|
4
|
-
const cq = require("../utils/convenienceQueries");
|
5
|
-
const meiNodeSelector = "note, rest, mRest, chord, layer";
|
6
|
-
const documentNodeSelector = ".clef, .meterSig, .keySig, .note, .rest, .mRest, .chord"; //, .layer"
|
7
|
-
const documentNodeSelector2 = ".clef, .meterSig, .keySig, .layer .note, .layer .rest, .layer .mRest, .layer .chord"; //, :scope > .layer"
|
8
|
-
class ScoreGraph {
|
9
|
-
constructor(xmlDoc, containerId, miditimes) {
|
10
|
-
this.containerId = containerId;
|
11
|
-
this.container = document.getElementById(containerId);
|
12
|
-
this.vrvSVG = cq.getVrvSVG(containerId);
|
13
|
-
this.interactionOverlay = cq.getInteractOverlay(containerId);
|
14
|
-
this.populate(xmlDoc, miditimes);
|
15
|
-
}
|
16
|
-
/**
|
17
|
-
* @deprecated
|
18
|
-
* Use function populate instead
|
19
|
-
* @param xmlDoc
|
20
|
-
*/
|
21
|
-
altPop(xmlDoc) {
|
22
|
-
var documentNodes = Array.from(cq.getVrvSVG(this.containerId).querySelectorAll(documentNodeSelector));
|
23
|
-
var documentNodes = documentNodes.filter(dn => {
|
24
|
-
if (!dn.classList.contains("note")) {
|
25
|
-
return dn;
|
26
|
-
}
|
27
|
-
if (dn.classList.contains("note")) {
|
28
|
-
if (dn.closest(".chord") === null) {
|
29
|
-
return dn;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
});
|
33
|
-
var nodeCoodrs = new Map();
|
34
|
-
var root = cq.getVrvSVG(this.containerId);
|
35
|
-
var rootBBox = root.getBoundingClientRect();
|
36
|
-
documentNodes.forEach(dn => {
|
37
|
-
var dnx = dn.getBoundingClientRect().x - rootBBox.x - root.scrollLeft - window.pageXOffset;
|
38
|
-
var dny = dn.getBoundingClientRect().y - rootBBox.y - root.scrollTop - window.pageYOffset;
|
39
|
-
nodeCoodrs.set(dn, { x: dnx, y: dny });
|
40
|
-
});
|
41
|
-
for (const [key, value] of nodeCoodrs.entries()) {
|
42
|
-
var closestLeft;
|
43
|
-
var closestRight;
|
44
|
-
var closestTop;
|
45
|
-
var closestDown;
|
46
|
-
for (const [key, value] of nodeCoodrs.entries()) {
|
47
|
-
//TODO
|
48
|
-
}
|
49
|
-
}
|
50
|
-
}
|
51
|
-
/**
|
52
|
-
* Populate scoreGraoh according to mei
|
53
|
-
* Add midi timeCode
|
54
|
-
* @param xmlDoc
|
55
|
-
* @param miditimes
|
56
|
-
*/
|
57
|
-
populate(xmlDoc, miditimes) {
|
58
|
-
var _a, _b, _c;
|
59
|
-
this.graph = new Map();
|
60
|
-
this.midiTimes = miditimes;
|
61
|
-
xmlDoc.querySelectorAll(meiNodeSelector).forEach(e => {
|
62
|
-
if ((e.tagName === "note" && e.closest("chord") !== null)) { // || (e.tagName === "layer" && e.children.length > 0)){
|
63
|
-
return;
|
64
|
-
}
|
65
|
-
this.graph.set(e.id, new ScoreNode_1.default(e.id));
|
66
|
-
});
|
67
|
-
cq.getVrvSVG(this.containerId).querySelectorAll(documentNodeSelector).forEach(e => {
|
68
|
-
if ((e.classList.contains("note") && e.closest(".chord") !== null)) {
|
69
|
-
return;
|
70
|
-
}
|
71
|
-
this.graph.set(e.id, new ScoreNode_1.default(e.id));
|
72
|
-
});
|
73
|
-
var layerCount = 0;
|
74
|
-
xmlDoc.querySelectorAll("layer").forEach(l => {
|
75
|
-
if (parseInt(l.getAttribute("n")) > layerCount) {
|
76
|
-
layerCount = parseInt(l.getAttribute("n"));
|
77
|
-
}
|
78
|
-
});
|
79
|
-
var staffCount = 0;
|
80
|
-
xmlDoc.querySelectorAll("staff").forEach(l => {
|
81
|
-
if (parseInt(l.getAttribute("n")) > staffCount) {
|
82
|
-
staffCount = parseInt(l.getAttribute("n"));
|
83
|
-
}
|
84
|
-
});
|
85
|
-
// Assign left/right nodes
|
86
|
-
var layerArray;
|
87
|
-
for (var s = 0; s < staffCount; s++) {
|
88
|
-
for (var i = 0; i < layerCount; i++) {
|
89
|
-
layerArray = Array.from(xmlDoc.querySelectorAll("staff[n=\"" + (s + 1).toString() + "\"] > layer[n=\"" + (i + 1).toString() + "\"]"));
|
90
|
-
var elements = new Array();
|
91
|
-
layerArray.forEach(l => {
|
92
|
-
if (cq.getVrvSVG(this.containerId).querySelector("#" + l.id) === null)
|
93
|
-
return;
|
94
|
-
let staff = cq.getVrvSVG(this.containerId).querySelector("#" + l.id).closest(".measure").querySelector(".staff[n='" + l.closest("staff").getAttribute("n") + "']");
|
95
|
-
var documentNodes = Array.from(staff.querySelectorAll(documentNodeSelector2));
|
96
|
-
var documentNodes = documentNodes.filter(dn => {
|
97
|
-
if (!dn.classList.contains("note")) {
|
98
|
-
return dn;
|
99
|
-
}
|
100
|
-
if (dn.classList.contains("note")) {
|
101
|
-
if (dn.closest(".chord") === null) {
|
102
|
-
return dn;
|
103
|
-
}
|
104
|
-
}
|
105
|
-
});
|
106
|
-
elements.push(...documentNodes);
|
107
|
-
elements.forEach((el, idx) => {
|
108
|
-
var currentNode = this.graph.get(el.id);
|
109
|
-
var prevSibling = idx === 0 ? null : this.graph.get(elements[idx - 1].id);
|
110
|
-
var nextSibling = idx === elements.length - 1 ? null : this.graph.get(elements[idx + 1].id);
|
111
|
-
if (idx > 0) {
|
112
|
-
currentNode.setLeft(prevSibling);
|
113
|
-
}
|
114
|
-
else { // empty Node at beginning of Layer
|
115
|
-
this.graph.set("BOL" + i.toString(), new ScoreNode_1.default("BOL" + i.toString()));
|
116
|
-
this.graph.get("BOL" + i.toString()).setLeft(null);
|
117
|
-
this.graph.get("BOL" + i.toString()).setUp(null);
|
118
|
-
this.graph.get("BOL" + i.toString()).setDown(null);
|
119
|
-
this.graph.get("BOL" + i.toString()).setRight(currentNode);
|
120
|
-
currentNode.setLeft(this.graph.get("BOL" + i.toString()));
|
121
|
-
}
|
122
|
-
currentNode.setRight(nextSibling);
|
123
|
-
});
|
124
|
-
});
|
125
|
-
}
|
126
|
-
}
|
127
|
-
//Assign up/down nodes
|
128
|
-
if (this.midiTimes) {
|
129
|
-
// miditimes contain svg Elements (not mei Elements!!!)
|
130
|
-
// first: direct up/down references
|
131
|
-
for (const [key, value] of this.midiTimes.entries()) {
|
132
|
-
var originArr = value;
|
133
|
-
var arr = new Array();
|
134
|
-
originArr.forEach(el => {
|
135
|
-
var chord = el.closest(".chord");
|
136
|
-
if (chord !== null && arr.indexOf(chord) === -1) {
|
137
|
-
arr.push(chord);
|
138
|
-
}
|
139
|
-
else if (chord === null) {
|
140
|
-
arr.push(el);
|
141
|
-
}
|
142
|
-
});
|
143
|
-
arr.forEach((note, idx) => {
|
144
|
-
var current = note;
|
145
|
-
var upSibling = idx === 0 ? null : this.graph.get(arr[idx - 1].id);
|
146
|
-
var downSibling = idx === arr.length - 1 ? null : this.graph.get(arr[idx + 1].id);
|
147
|
-
var currentNode = this.graph.get(current.id);
|
148
|
-
if (typeof currentNode.getTimeCode() === "undefined") {
|
149
|
-
currentNode.setTimeCode(key);
|
150
|
-
}
|
151
|
-
currentNode.setUp(upSibling);
|
152
|
-
currentNode.setDown(downSibling);
|
153
|
-
});
|
154
|
-
}
|
155
|
-
}
|
156
|
-
//DEAL WITH MRESTS
|
157
|
-
var staves = cq.getVrvSVG(this.containerId).querySelectorAll(".staff");
|
158
|
-
for (var i = 0; i < staves.length - 1; i++) {
|
159
|
-
var staffElements = staves[i].querySelectorAll(documentNodeSelector);
|
160
|
-
var emptyElements = staves[i + 1].querySelectorAll(".clef, .meterSig, .keySig, .mRest, .layer");
|
161
|
-
staffElements.forEach((se, idx) => {
|
162
|
-
var gn = this.graph.get(se.id);
|
163
|
-
if ((gn === null || gn === void 0 ? void 0 : gn.getDown()) === null || (gn === null || gn === void 0 ? void 0 : gn.getDown()) == undefined) {
|
164
|
-
var tempIdx = idx;
|
165
|
-
if (idx >= emptyElements.length) {
|
166
|
-
tempIdx = emptyElements.length - 1;
|
167
|
-
}
|
168
|
-
var gnEmpty = this.graph.get(emptyElements[tempIdx].id);
|
169
|
-
if ((gnEmpty === null || gnEmpty === void 0 ? void 0 : gnEmpty.getUp()) === null || (gnEmpty === null || gnEmpty === void 0 ? void 0 : gnEmpty.getUp()) == undefined) {
|
170
|
-
gn === null || gn === void 0 ? void 0 : gn.setDown(gnEmpty);
|
171
|
-
gnEmpty === null || gnEmpty === void 0 ? void 0 : gnEmpty.setUp(gn);
|
172
|
-
}
|
173
|
-
}
|
174
|
-
});
|
175
|
-
}
|
176
|
-
//extra iteration for Beginning of Layer
|
177
|
-
var currBol = null;
|
178
|
-
var prevBol = null;
|
179
|
-
for (const [key, value] of this.graph.entries()) {
|
180
|
-
if (key.indexOf("BOL") !== -1) {
|
181
|
-
currBol = value;
|
182
|
-
var bolIdx = key[key.length - 1];
|
183
|
-
if (bolIdx !== "0") {
|
184
|
-
currBol.setUp(prevBol);
|
185
|
-
if (prevBol !== null) {
|
186
|
-
prevBol.setDown(currBol);
|
187
|
-
}
|
188
|
-
}
|
189
|
-
prevBol = value;
|
190
|
-
}
|
191
|
-
}
|
192
|
-
//if there are no direct up/down references, assign closest references
|
193
|
-
for (const [key, value] of this.graph.entries()) {
|
194
|
-
var currentNode = value;
|
195
|
-
var leftNode = currentNode.getLeft();
|
196
|
-
var rightNode = currentNode.getRight();
|
197
|
-
if (currentNode.getUp() == undefined) {
|
198
|
-
currentNode.setUp(null);
|
199
|
-
}
|
200
|
-
if (currentNode.getDown() == undefined) {
|
201
|
-
currentNode.setDown(null);
|
202
|
-
}
|
203
|
-
// Get closest Node for UP reference
|
204
|
-
//check left
|
205
|
-
var closestTimeUp = 10 ** 10;
|
206
|
-
var upSet = null;
|
207
|
-
if (this.targetNodeIsLeftOrRight(currentNode, currentNode.getUp()) && leftNode !== null) {
|
208
|
-
if (leftNode.getUp() !== null && typeof leftNode.getDown() !== "undefined") {
|
209
|
-
closestTimeUp = (currentNode === null || currentNode === void 0 ? void 0 : currentNode.getTimeCode()) - ((_a = leftNode === null || leftNode === void 0 ? void 0 : leftNode.getUp()) === null || _a === void 0 ? void 0 : _a.getTimeCode()) || 0;
|
210
|
-
upSet = leftNode === null || leftNode === void 0 ? void 0 : leftNode.getUp();
|
211
|
-
}
|
212
|
-
}
|
213
|
-
//check right
|
214
|
-
if (this.targetNodeIsLeftOrRight(currentNode, currentNode.getUp()) && rightNode !== null) {
|
215
|
-
if (rightNode.getUp() !== null && typeof rightNode.getDown() !== "undefined") {
|
216
|
-
if ((((_b = rightNode.getUp()) === null || _b === void 0 ? void 0 : _b.getTimeCode()) - (currentNode === null || currentNode === void 0 ? void 0 : currentNode.getTimeCode())) < closestTimeUp) {
|
217
|
-
upSet = rightNode === null || rightNode === void 0 ? void 0 : rightNode.getUp();
|
218
|
-
}
|
219
|
-
}
|
220
|
-
}
|
221
|
-
if (upSet !== null && upSet !== currentNode && !this.targetNodeIsLeftOrRight(currentNode, upSet)) {
|
222
|
-
currentNode.setUp(upSet);
|
223
|
-
}
|
224
|
-
// Get closest Node for DOWN reference
|
225
|
-
// check left
|
226
|
-
var closestTimeDown = 10 ** 10;
|
227
|
-
var downSet = null;
|
228
|
-
if (this.targetNodeIsLeftOrRight(currentNode, currentNode.getDown()) && leftNode !== null) {
|
229
|
-
if (leftNode.getDown() !== null && typeof leftNode.getDown() !== "undefined") {
|
230
|
-
closestTimeDown = (currentNode === null || currentNode === void 0 ? void 0 : currentNode.getTimeCode()) - ((_c = leftNode === null || leftNode === void 0 ? void 0 : leftNode.getDown()) === null || _c === void 0 ? void 0 : _c.getTimeCode()) || 0;
|
231
|
-
downSet = leftNode.getDown();
|
232
|
-
}
|
233
|
-
}
|
234
|
-
// check right
|
235
|
-
if (this.targetNodeIsLeftOrRight(currentNode, currentNode.getDown()) && rightNode !== null) {
|
236
|
-
if (rightNode.getDown() !== null && rightNode.getDown() != undefined) {
|
237
|
-
if ((rightNode.getDown().getTimeCode() - currentNode.getTimeCode()) < closestTimeDown) {
|
238
|
-
downSet = rightNode.getDown();
|
239
|
-
}
|
240
|
-
}
|
241
|
-
}
|
242
|
-
if (downSet !== null && downSet !== currentNode && !this.targetNodeIsLeftOrRight(currentNode, downSet)) {
|
243
|
-
currentNode.setDown(downSet);
|
244
|
-
}
|
245
|
-
}
|
246
|
-
}
|
247
|
-
targetNodeIsLeftOrRight(startNode, targetNode) {
|
248
|
-
return this.targetIsNodeRight(startNode, targetNode) || this.targetIsNodeLeft(startNode, targetNode);
|
249
|
-
}
|
250
|
-
targetIsNodeLeft(startNode, targetNode) {
|
251
|
-
var tempNode = startNode;
|
252
|
-
var isLeft = false;
|
253
|
-
while (tempNode !== null) {
|
254
|
-
if (tempNode !== null) {
|
255
|
-
if (tempNode == undefined) {
|
256
|
-
return isLeft;
|
257
|
-
}
|
258
|
-
tempNode = tempNode.getLeft();
|
259
|
-
}
|
260
|
-
if (tempNode === targetNode) {
|
261
|
-
isLeft = true;
|
262
|
-
}
|
263
|
-
}
|
264
|
-
return isLeft;
|
265
|
-
}
|
266
|
-
targetIsNodeRight(startNode, targetNode) {
|
267
|
-
var tempNode = startNode;
|
268
|
-
var isRight = false;
|
269
|
-
while (tempNode !== null) {
|
270
|
-
if (tempNode !== null) {
|
271
|
-
if (tempNode == undefined) {
|
272
|
-
return isRight;
|
273
|
-
}
|
274
|
-
tempNode = tempNode.getRight();
|
275
|
-
}
|
276
|
-
if (tempNode === targetNode) {
|
277
|
-
isRight = true;
|
278
|
-
}
|
279
|
-
}
|
280
|
-
return isRight;
|
281
|
-
}
|
282
|
-
getCurrentNode() {
|
283
|
-
return this.currentNode;
|
284
|
-
}
|
285
|
-
setCurrentNodeById(id) {
|
286
|
-
var _a, _b;
|
287
|
-
if (id == undefined)
|
288
|
-
return;
|
289
|
-
var lastNode = this.currentNode;
|
290
|
-
this.currentNode = this.graph.get(id) || this.graph.get((_b = (_a = document.getElementById(id)) === null || _a === void 0 ? void 0 : _a.closest(".chord")) === null || _b === void 0 ? void 0 : _b.id) || lastNode;
|
291
|
-
if (this.currentNode == undefined) {
|
292
|
-
console.log(lastNode);
|
293
|
-
throw new Error("CurrentNode undefined although id is given: " + id);
|
294
|
-
}
|
295
|
-
}
|
296
|
-
setContainerId(containerId) {
|
297
|
-
this.containerId = containerId;
|
298
|
-
}
|
299
|
-
nextUp() {
|
300
|
-
var _a;
|
301
|
-
if (this.currentNode != undefined && ((_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getUp()) !== null) {
|
302
|
-
this.currentNode = this.currentNode.getUp();
|
303
|
-
}
|
304
|
-
return this.currentNode;
|
305
|
-
}
|
306
|
-
nextDown() {
|
307
|
-
var _a;
|
308
|
-
if (this.currentNode != undefined && ((_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getDown()) !== null) {
|
309
|
-
this.currentNode = this.currentNode.getDown();
|
310
|
-
}
|
311
|
-
return this.currentNode;
|
312
|
-
}
|
313
|
-
nextRight() {
|
314
|
-
var _a;
|
315
|
-
if (this.currentNode != undefined && ((_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getRight()) !== null) {
|
316
|
-
this.currentNode = this.currentNode.getRight();
|
317
|
-
}
|
318
|
-
return this.currentNode;
|
319
|
-
}
|
320
|
-
nextLeft() {
|
321
|
-
var _a;
|
322
|
-
if (this.currentNode != undefined && ((_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getLeft()) !== null) {
|
323
|
-
this.currentNode = this.currentNode.getLeft();
|
324
|
-
}
|
325
|
-
return this.currentNode;
|
326
|
-
}
|
327
|
-
nextMeasureRight() {
|
328
|
-
while (this.getCurrentNode().getRight().getDocElement().closest(".measure").id ===
|
329
|
-
this.getCurrentNode().getDocElement().closest(".measure").id) {
|
330
|
-
this.nextRight();
|
331
|
-
}
|
332
|
-
return this.currentNode;
|
333
|
-
}
|
334
|
-
nextMeasureLeft() {
|
335
|
-
while (this.getCurrentNode().getLeft().getDocElement().closest(".measure").id ===
|
336
|
-
this.getCurrentNode().getDocElement().closest(".measure").id) {
|
337
|
-
this.nextLeft();
|
338
|
-
}
|
339
|
-
return this.currentNode;
|
340
|
-
}
|
341
|
-
/**
|
342
|
-
* Go to next Element with given classname.
|
343
|
-
* Whatever comes first according to the classNames array.
|
344
|
-
* @param classNames
|
345
|
-
* @param direction
|
346
|
-
* @returns
|
347
|
-
*/
|
348
|
-
getNextClass(classNames, direction) {
|
349
|
-
var _a;
|
350
|
-
if (typeof classNames === "string")
|
351
|
-
classNames = [classNames];
|
352
|
-
var currentId = (_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getId();
|
353
|
-
if ([null, undefined].some(id => id == currentId))
|
354
|
-
return;
|
355
|
-
var nextIsNull = false;
|
356
|
-
do {
|
357
|
-
switch (direction) {
|
358
|
-
case "ArrowLeft":
|
359
|
-
case "left":
|
360
|
-
this.nextLeft();
|
361
|
-
break;
|
362
|
-
case "ArrowRight":
|
363
|
-
case "right":
|
364
|
-
this.nextRight();
|
365
|
-
break;
|
366
|
-
case "ArrowUp":
|
367
|
-
case "up":
|
368
|
-
this.nextUp();
|
369
|
-
break;
|
370
|
-
case "ArrowDown":
|
371
|
-
case "down":
|
372
|
-
this.nextDown();
|
373
|
-
break;
|
374
|
-
default:
|
375
|
-
console.error(direction + " is not allowed. Use left, right, up or down");
|
376
|
-
return;
|
377
|
-
}
|
378
|
-
nextIsNull = [null, undefined].some(n => this.currentNode == n);
|
379
|
-
} while (!classNames.some(cn => { var _a, _b; return (_b = (_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getDocElement()) === null || _b === void 0 ? void 0 : _b.classList.contains(cn); }) && !nextIsNull);
|
380
|
-
if (nextIsNull) {
|
381
|
-
this.setCurrentNodeById(currentId);
|
382
|
-
}
|
383
|
-
return this.currentNode;
|
384
|
-
}
|
385
|
-
/**
|
386
|
-
* Find node based on class Names. Will not change state and pointers of the graph.
|
387
|
-
* To change this.currentNode, use getNextClass instead.
|
388
|
-
* @param classNames
|
389
|
-
* @param direction
|
390
|
-
* @returns
|
391
|
-
*/
|
392
|
-
lookUp(classNames, direction) {
|
393
|
-
var _a;
|
394
|
-
if (typeof classNames === "string")
|
395
|
-
classNames = [classNames];
|
396
|
-
var currentId = (_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getId();
|
397
|
-
if ([null, undefined].some(id => id == currentId))
|
398
|
-
return;
|
399
|
-
var isNull = false;
|
400
|
-
var node = this.currentNode;
|
401
|
-
do {
|
402
|
-
switch (direction) {
|
403
|
-
case "ArrowLeft":
|
404
|
-
case "left":
|
405
|
-
node = node.getLeft();
|
406
|
-
break;
|
407
|
-
case "ArrowRight":
|
408
|
-
case "right":
|
409
|
-
node = node.getRight();
|
410
|
-
break;
|
411
|
-
case "ArrowUp":
|
412
|
-
case "up":
|
413
|
-
node = node.getUp();
|
414
|
-
break;
|
415
|
-
case "ArrowDown":
|
416
|
-
case "down":
|
417
|
-
node = node.getDown();
|
418
|
-
break;
|
419
|
-
default:
|
420
|
-
console.error(direction + " is not allowed. Use left, right, up or down");
|
421
|
-
return;
|
422
|
-
}
|
423
|
-
isNull = [null, undefined].some(n => node == n);
|
424
|
-
} while (!classNames.some(cn => { var _a; return (_a = node === null || node === void 0 ? void 0 : node.getDocElement()) === null || _a === void 0 ? void 0 : _a.classList.contains(cn); }) && !isNull);
|
425
|
-
return node;
|
426
|
-
}
|
427
|
-
//Check if ScoreGraph is at beginning of layer
|
428
|
-
isBOL() {
|
429
|
-
return this.currentNode.getLeft() === null && this.currentNode.getId().indexOf("BOL") !== -1;
|
430
|
-
}
|
431
|
-
}
|
432
|
-
exports.default = ScoreGraph;
|
@@ -1,114 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const d3 = require("d3");
|
4
|
-
const random_1 = require("../utils/random");
|
5
|
-
const constants_1 = require("../constants");
|
6
|
-
class CustomAnnotationDrawer {
|
7
|
-
constructor() {
|
8
|
-
this.shapes = new Array();
|
9
|
-
this.shapeID = "";
|
10
|
-
this.dragged = false;
|
11
|
-
this.canvas = d3.select(constants_1.constants._ROOTSVGID_WITH_IDSELECTOR_); // draw directly in svg
|
12
|
-
this.dragBehaviour = d3.drag()
|
13
|
-
.on('start', drawStart)
|
14
|
-
.on('drag', this.drawing.bind(this))
|
15
|
-
.on('end', this.drawEnd.bind(this));
|
16
|
-
var that = this;
|
17
|
-
function drawStart() {
|
18
|
-
that.initialX = d3.event.x;
|
19
|
-
that.initialY = d3.event.y;
|
20
|
-
if (d3.event.sourceEvent.srcElement.id === constants_1.constants._ROOTSVGID_) {
|
21
|
-
that.initRect(that.initialX, that.initialY);
|
22
|
-
//that.initCircle(that.initialX, that.initialY)
|
23
|
-
}
|
24
|
-
}
|
25
|
-
this.setListeners();
|
26
|
-
}
|
27
|
-
drawing() {
|
28
|
-
//const currentPt =
|
29
|
-
const curX = d3.event.x;
|
30
|
-
const curY = d3.event.y;
|
31
|
-
if (typeof this.shape === "undefined") {
|
32
|
-
return;
|
33
|
-
}
|
34
|
-
if (Math.abs(curX - this.initialX) > 20 || Math.abs(curY - this.initialY) > 20) {
|
35
|
-
this.dragged = true;
|
36
|
-
const newX = curX < this.initialX ? curX : this.initialX;
|
37
|
-
const newY = curY < this.initialY ? curY : this.initialY;
|
38
|
-
const width = curX < this.initialX ? this.initialX - curX : curX - this.initialX;
|
39
|
-
const height = curY < this.initialY ? this.initialY - curY : curY - this.initialY;
|
40
|
-
this.updateRect(newX, newY, width, height);
|
41
|
-
//this.updateCircle(newX, newY, width, height);
|
42
|
-
}
|
43
|
-
}
|
44
|
-
drawEnd() {
|
45
|
-
if (!this.dragged) {
|
46
|
-
var elToRemove = document.getElementById(this.shapeID);
|
47
|
-
if (elToRemove !== null) {
|
48
|
-
elToRemove.remove();
|
49
|
-
}
|
50
|
-
}
|
51
|
-
else {
|
52
|
-
document.getElementById("annotationCanvas").appendChild(this.shape);
|
53
|
-
this.shapes.push(this.shape.cloneNode(true));
|
54
|
-
}
|
55
|
-
this.shape = undefined;
|
56
|
-
this.updateCallback();
|
57
|
-
}
|
58
|
-
initRect(ulx, uly) {
|
59
|
-
this.shapeID = random_1.uuidv4();
|
60
|
-
this.canvas.append('rect')
|
61
|
-
.attr('x', ulx)
|
62
|
-
.attr('y', uly)
|
63
|
-
.attr('width', 0)
|
64
|
-
.attr('height', 0)
|
65
|
-
.attr("class", "customAnnotShape")
|
66
|
-
.attr("id", this.shapeID);
|
67
|
-
this.shape = document.getElementById(this.shapeID);
|
68
|
-
}
|
69
|
-
initCircle(cx, cy) {
|
70
|
-
this.shapeID = random_1.uuidv4();
|
71
|
-
this.canvas.append('ellipse')
|
72
|
-
.attr('cx', cx)
|
73
|
-
.attr('cy', cy)
|
74
|
-
.attr('rx', 0)
|
75
|
-
.attr('ry', 0)
|
76
|
-
.attr("class", "customAnnotShape")
|
77
|
-
.attr("id", this.shapeID);
|
78
|
-
this.shape = document.getElementById(this.shapeID);
|
79
|
-
}
|
80
|
-
updateRect(newX, newY, currentWidth, currentHeight) {
|
81
|
-
this.shape.setAttribute('x', newX.toString());
|
82
|
-
this.shape.setAttribute('y', newY.toString());
|
83
|
-
this.shape.setAttribute('width', currentWidth.toString());
|
84
|
-
this.shape.setAttribute('height', currentHeight.toString());
|
85
|
-
}
|
86
|
-
updateCircle(newX, newY, currentWidth, currentHeight) {
|
87
|
-
this.shape.setAttribute('cx', newX.toString());
|
88
|
-
this.shape.setAttribute('cy', newY.toString());
|
89
|
-
this.shape.setAttribute('rx', currentWidth.toString());
|
90
|
-
this.shape.setAttribute('ry', currentHeight.toString());
|
91
|
-
}
|
92
|
-
removeListeners() {
|
93
|
-
d3.select(constants_1.constants._ROOTSVGID_WITH_IDSELECTOR_).on('mousedown.drag', null);
|
94
|
-
}
|
95
|
-
setListeners() {
|
96
|
-
this.canvas.call(this.dragBehaviour);
|
97
|
-
}
|
98
|
-
resetListeners() {
|
99
|
-
this.removeListeners();
|
100
|
-
this.setListeners();
|
101
|
-
}
|
102
|
-
///////// GETTER/ SETTER ////////
|
103
|
-
setM2M(m2m) {
|
104
|
-
this.m2m = m2m;
|
105
|
-
}
|
106
|
-
getShapes() {
|
107
|
-
return this.shapes;
|
108
|
-
}
|
109
|
-
//////////// CALLBACKS /////////////
|
110
|
-
setUpdateCallback(updateCallback) {
|
111
|
-
this.updateCallback = updateCallback;
|
112
|
-
}
|
113
|
-
}
|
114
|
-
exports.default = CustomAnnotationDrawer;
|
@@ -1,113 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const d3 = require("d3");
|
4
|
-
//@ts-ignore
|
5
|
-
//const $ = H5P.jQuery;
|
6
|
-
/**
|
7
|
-
* Class that handles insert mode, events, and actions.
|
8
|
-
*/
|
9
|
-
class AnnotationLineHandler {
|
10
|
-
constructor() {
|
11
|
-
this.initDragRects();
|
12
|
-
this.initAnnots();
|
13
|
-
//this.initCustomShapes()
|
14
|
-
}
|
15
|
-
setListeners() {
|
16
|
-
// if(typeof this.customShapes !== "undefined"){
|
17
|
-
// this.customShapes.call(this.dragShapeBehaviour)
|
18
|
-
// }
|
19
|
-
if (typeof this.annotations !== "undefined") {
|
20
|
-
//this.annotations.call(this.dragAnnotBehaviour);
|
21
|
-
this.lines.call(this.dragLineBehaviour);
|
22
|
-
}
|
23
|
-
return this;
|
24
|
-
}
|
25
|
-
removeListeners() {
|
26
|
-
// if(typeof this.customShapes !== "undefined"){
|
27
|
-
// this.customShapes.on(".drag", null);
|
28
|
-
// }
|
29
|
-
if (typeof this.annotations !== "undefined") {
|
30
|
-
//this.annotations.on(".drag", null);
|
31
|
-
this.lines.on(".drag", null);
|
32
|
-
}
|
33
|
-
return this;
|
34
|
-
}
|
35
|
-
resetListeners() {
|
36
|
-
this.removeListeners();
|
37
|
-
this.setListeners();
|
38
|
-
}
|
39
|
-
dragStarted() {
|
40
|
-
this.draggedAnnot = d3.event.sourceEvent.currentTarget;
|
41
|
-
this.draggedLine = d3.event.sourceEvent.currentTarget;
|
42
|
-
this.draggedShape = d3.event.sourceEvent.currentTarget;
|
43
|
-
try {
|
44
|
-
this.attachedLine = this.draggedAnnot.closest("g").getElementsByTagName("line")[0];
|
45
|
-
}
|
46
|
-
catch (_a) {
|
47
|
-
this.attachedLine = undefined;
|
48
|
-
}
|
49
|
-
this.dragStartCoords = [d3.event.x, d3.event.y];
|
50
|
-
this.dx = this.dragStartCoords[0];
|
51
|
-
this.dy = this.dragStartCoords[1];
|
52
|
-
}
|
53
|
-
////////// ANNOTS //////////
|
54
|
-
initAnnots() {
|
55
|
-
this.dragAnnotBehaviour = d3.drag()
|
56
|
-
.on('start', this.dragStarted.bind(this))
|
57
|
-
.on('drag', this.draggingAnnot.bind(this))
|
58
|
-
.on('end', this.dragAnnotEnded.bind(this));
|
59
|
-
this.annotations = d3.selectAll(".annotText");
|
60
|
-
this.dragStartCoords = new Array(this.annotations.size());
|
61
|
-
this.draggedAnnot = null;
|
62
|
-
this.resetListeners();
|
63
|
-
}
|
64
|
-
draggingAnnot() {
|
65
|
-
this.dx = d3.event.x;
|
66
|
-
this.dy = d3.event.y;
|
67
|
-
this.draggedAnnot.setAttribute("x", (this.dx).toString());
|
68
|
-
this.draggedAnnot.setAttribute("y", (this.dy).toString());
|
69
|
-
this.attachedLine.setAttribute("x1", this.draggedAnnot.getAttribute("x"));
|
70
|
-
this.attachedLine.setAttribute("y1", this.draggedAnnot.getAttribute("y"));
|
71
|
-
}
|
72
|
-
dragAnnotEnded() {
|
73
|
-
}
|
74
|
-
//////////// LINE ////////////////////
|
75
|
-
initDragRects() {
|
76
|
-
this.dragLineBehaviour = d3.drag()
|
77
|
-
.on('start', this.dragStarted.bind(this))
|
78
|
-
.on('drag', this.draggingLine.bind(this))
|
79
|
-
.on('end', this.dragLineEnded.bind(this));
|
80
|
-
this.lines = d3.selectAll(".lineDragRect");
|
81
|
-
this.dragStartCoords = new Array(this.lines.size());
|
82
|
-
this.draggedLine = null;
|
83
|
-
this.resetListeners();
|
84
|
-
}
|
85
|
-
draggingLine() {
|
86
|
-
this.dx = d3.event.x;
|
87
|
-
this.dy = d3.event.y;
|
88
|
-
this.draggedLine.setAttribute("x", (this.dx).toString());
|
89
|
-
this.draggedLine.setAttribute("y", (this.dy).toString());
|
90
|
-
this.attachedLine.setAttribute("x2", this.draggedLine.getAttribute("x"));
|
91
|
-
this.attachedLine.setAttribute("y2", this.draggedLine.getAttribute("y"));
|
92
|
-
this.highlightObjectCallback(this.draggedLine);
|
93
|
-
}
|
94
|
-
dragLineEnded() {
|
95
|
-
this.snapToObjCallback(this.attachedLine);
|
96
|
-
}
|
97
|
-
//////////// CALLBACKS ////////////
|
98
|
-
setSnapToObjCallback(snapToObj) {
|
99
|
-
this.snapToObjCallback = snapToObj;
|
100
|
-
return this;
|
101
|
-
}
|
102
|
-
removeUpdateAnnotationIDsCallback() {
|
103
|
-
this.snapToObjCallback = undefined;
|
104
|
-
return this;
|
105
|
-
}
|
106
|
-
sethighlightObjectCallback(highlightObjectCallback) {
|
107
|
-
this.highlightObjectCallback = highlightObjectCallback;
|
108
|
-
}
|
109
|
-
setUpdateCallback(updateCallback) {
|
110
|
-
this.updateCallback = updateCallback;
|
111
|
-
}
|
112
|
-
}
|
113
|
-
exports.default = AnnotationLineHandler;
|