vibe-editor 0.0.0 → 0.0.1
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/LICENSE +1 -1
- package/README.md +12 -9
- package/package.json +11 -5
- package/src/scripts/js/Core.js +212 -186
- package/src/scripts/js/MusicProcessor.js +286 -128
- package/src/scripts/js/{VerovioScoreEditor.js → VIBE.js} +62 -28
- package/src/scripts/js/assets/mei_template.js +5 -1
- package/src/scripts/js/datastructures/MeasureMatrix.js +6 -85
- package/src/scripts/js/datastructures/ScoreGraph.js +1 -1
- package/src/scripts/js/entry.js +3 -2
- package/src/scripts/js/gui/Annotations.js +188 -111
- package/src/scripts/js/gui/HarmonyLabel.js +26 -2
- package/src/scripts/js/gui/ScoreManipulator.js +61 -31
- package/src/scripts/js/gui/Tabbar.js +41 -21
- package/src/scripts/js/gui/Toolbar.js +4 -4
- package/src/scripts/js/handlers/AnnotationChangeHandler.js +131 -60
- package/src/scripts/js/handlers/ClickModeHandler.js +406 -143
- package/src/scripts/js/handlers/CustomToolbarHandler.js +26 -24
- package/src/scripts/js/handlers/GlobalKeyboardHandler.js +12 -7
- package/src/scripts/js/handlers/InsertModeHandler.js +26 -32
- package/src/scripts/js/handlers/KeyModeHandler.js +12 -86
- package/src/scripts/js/handlers/LabelHandler.js +3 -2
- package/src/scripts/js/handlers/PhantomElementHandler.js +1 -1
- package/src/scripts/js/handlers/ScoreManipulatorHandler.js +101 -14
- package/src/scripts/js/handlers/SelectionHandler.js +80 -36
- package/src/scripts/js/handlers/SideBarHandler.js +10 -3
- package/src/scripts/js/handlers/WindowHandler.js +25 -4
- package/src/scripts/js/utils/DOMCreator.js +1 -1
- package/src/scripts/js/utils/MEIConverter.js +13 -1
- package/src/scripts/js/utils/MEIOperations.js +180 -187
- package/src/scripts/js/utils/Mouse2SVG.js +200 -43
- package/src/scripts/js/utils/ReactWrapper.js +46 -0
- package/src/scripts/js/utils/RectWrapper.js +10 -0
- package/src/scripts/js/utils/SVGEditor.js +94 -3
- package/src/scripts/js/utils/VerovioWrapper.js +6 -1
- package/src/scripts/js/utils/convenienceQueries.js +2 -0
- package/src/scripts/js/utils/mappings.js +322 -56
- package/src/styles/VerovioScoreEditor.css +0 -694
@@ -3,27 +3,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const constants_1 = require("../constants");
|
4
4
|
const random_1 = require("../utils/random");
|
5
5
|
const AnnotationChangeHandler_1 = require("../handlers/AnnotationChangeHandler");
|
6
|
-
const CustomAnnotationShapeDrawer_1 = require("../handlers/CustomAnnotationShapeDrawer");
|
7
6
|
const cq = require("../utils/convenienceQueries");
|
8
7
|
const coordinates = require("../utils/coordinates");
|
9
8
|
class Annotations {
|
10
9
|
constructor(containerId) {
|
10
|
+
this.clickHarmonyBtnHandler = (function clickHarmonyBtnHandler(e) {
|
11
|
+
//e.preventDefault()
|
12
|
+
this.removeTextListeners();
|
13
|
+
e.target.dispatchEvent(new Event("annotationButtonClicked"));
|
14
|
+
}).bind(this);
|
15
|
+
this.clickAnnotTextHandler = (function clickAnnotTextHandler(e) {
|
16
|
+
//e.preventDefault()
|
17
|
+
this.resetTextListeners();
|
18
|
+
e.target.dispatchEvent(new Event("annotationButtonClicked"));
|
19
|
+
}).bind(this);
|
11
20
|
////HANDLERS////
|
12
21
|
this.clickHandler = (function clickHandler(e) {
|
13
|
-
e.preventDefault()
|
14
|
-
if (!this.annotationCanvas.classList.contains("front")) {
|
15
|
-
|
16
|
-
}
|
17
|
-
|
18
|
-
|
19
|
-
}
|
22
|
+
//e.preventDefault()
|
23
|
+
// if (!this.annotationCanvas.classList.contains("front")) {
|
24
|
+
// this.setToFront()
|
25
|
+
// } else {
|
26
|
+
// this.setToBack()
|
27
|
+
// }
|
20
28
|
}).bind(this);
|
21
29
|
this.createAnnotationHandler = (function createAnnotationHandler(e) {
|
22
30
|
var _a;
|
23
31
|
var t = e.target;
|
24
|
-
if ((_a = t.closest(".
|
32
|
+
if ((_a = t.closest(".vibeContainer")) === null || _a === void 0 ? void 0 : _a.classList.contains("clickmode"))
|
25
33
|
return; // creation should only be possible when annotation tab is on
|
26
|
-
var selectedAnnotations = this.
|
34
|
+
var selectedAnnotations = cq.getInteractOverlay(this.containerId).querySelectorAll("#annotationCanvas .selected");
|
27
35
|
if (selectedAnnotations.length === 0) {
|
28
36
|
this.createAnnotation(e);
|
29
37
|
}
|
@@ -40,11 +48,11 @@ class Annotations {
|
|
40
48
|
if (!cq.hasActiveElement(this.containerId)) {
|
41
49
|
return;
|
42
50
|
}
|
43
|
-
var canvasClone = this.
|
51
|
+
var canvasClone = cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas").cloneNode(true);
|
44
52
|
var listClone = this.container.querySelector("#annotList").cloneNode(true);
|
45
53
|
this.annotList = this.container.querySelector("#annotList");
|
46
54
|
this.undoStacks.push([canvasClone, listClone]);
|
47
|
-
this.annotationCanvas = this.
|
55
|
+
this.annotationCanvas = cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas");
|
48
56
|
}).bind(this);
|
49
57
|
this.updateRedoStacks = (function updateRedoStacks(e) {
|
50
58
|
if (!cq.hasActiveElement(this.containerId)) {
|
@@ -62,6 +70,7 @@ class Annotations {
|
|
62
70
|
var target = e.target;
|
63
71
|
target.setAttribute("contenteditable", "true");
|
64
72
|
target.focus();
|
73
|
+
console.log("activeElement", document.activeElement);
|
65
74
|
this.annotationChangeHandler.removeListeners();
|
66
75
|
}).bind(this);
|
67
76
|
/**
|
@@ -74,11 +83,11 @@ class Annotations {
|
|
74
83
|
}
|
75
84
|
var isValidKey = ["Delete", "Backspace"].some(code => e.code === code);
|
76
85
|
//var isInAnnotMode = this.container.classList.contains("annotMode")
|
77
|
-
var hasEditableElement = this.
|
86
|
+
var hasEditableElement = cq.getInteractOverlay(this.containerId).querySelectorAll(".selected [contenteditable=true]").length > 0;
|
78
87
|
var listHasFocus = Array.from(this.container.querySelectorAll("#annotList > *")).some(le => le === document.activeElement);
|
79
88
|
//if(isValidKey && isInAnnotMode && !hasEditableElement && !listHasFocus){
|
80
89
|
if (isValidKey && !hasEditableElement && !listHasFocus) {
|
81
|
-
this.
|
90
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll("#annotationCanvas .selected").forEach(el => {
|
82
91
|
if (el.closest("g") !== null) {
|
83
92
|
el.closest("g").remove();
|
84
93
|
}
|
@@ -86,16 +95,16 @@ class Annotations {
|
|
86
95
|
el.remove();
|
87
96
|
}
|
88
97
|
});
|
89
|
-
this.
|
90
|
-
this.
|
98
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotChanged"));
|
99
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotationCanvasChanged"));
|
91
100
|
}
|
92
101
|
}).bind(this);
|
93
102
|
this.submitLabelHandler = (function submitHandler(e) {
|
94
103
|
var target = e.target;
|
95
104
|
if ((e.key === "Enter" || e.key === "Escape")) {
|
96
105
|
target.blur();
|
97
|
-
this.
|
98
|
-
this.
|
106
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotChanged"));
|
107
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotationCanvasChanged"));
|
99
108
|
}
|
100
109
|
}).bind(this);
|
101
110
|
this.setContainerId(containerId);
|
@@ -103,25 +112,29 @@ class Annotations {
|
|
103
112
|
this.annotations = new Array();
|
104
113
|
}
|
105
114
|
addCanvas() {
|
106
|
-
|
107
|
-
this.
|
115
|
+
var _a;
|
116
|
+
//cq.getInteractOverlay(this.containerId) = cq.getInteractOverlay(this.containerId)
|
117
|
+
this.rootBBox = cq.getInteractOverlay(this.containerId).getBoundingClientRect(); //this.vrvSVG.getBoundingClientRect()
|
108
118
|
var rootWidth = this.rootBBox.width.toString();
|
109
119
|
var rootHeigth = this.rootBBox.height.toString();
|
110
|
-
var vb = this.
|
111
|
-
|
120
|
+
var vb = cq.getInteractOverlay(this.containerId).getAttribute("viewBox"); //this.vrvSVG.getAttribute("viewBox")
|
121
|
+
this.annotationCanvas = (_a = cq.getInteractOverlay(this.containerId)) === null || _a === void 0 ? void 0 : _a.querySelector("#annotationCanvas");
|
122
|
+
if (!this.annotationCanvas) {
|
112
123
|
this.annotationCanvas = document.createElementNS(constants_1.constants._SVGNS_, "svg");
|
113
124
|
this.annotationCanvas.setAttribute("id", "annotationCanvas");
|
114
125
|
this.annotationCanvas.classList.add("canvas");
|
115
126
|
//this.annotationCanvas.classList.add("back")
|
116
127
|
//this.annotationCanvas.setAttribute("viewBox", ["0", "0", rootWidth, rootHeigth].join(" "))
|
117
128
|
}
|
118
|
-
this.annotationCanvas.setAttribute("viewBox", vb)
|
119
|
-
if (this.annotationCanvas.classList.contains("front")) {
|
120
|
-
|
121
|
-
}
|
122
|
-
else {
|
123
|
-
|
124
|
-
}
|
129
|
+
//this.annotationCanvas.setAttribute("viewBox", vb)
|
130
|
+
// if (this.annotationCanvas.classList.contains("front")) {
|
131
|
+
cq.getInteractOverlay(this.containerId).insertBefore(this.annotationCanvas, cq.getInteractOverlay(this.containerId).lastChild.nextSibling);
|
132
|
+
// }
|
133
|
+
// else {
|
134
|
+
// cq.getInteractOverlay(this.containerId).insertBefore(this.annotationCanvas, cq.getInteractOverlay(this.containerId).firstChild)
|
135
|
+
// }
|
136
|
+
this.updateLinkedTexts();
|
137
|
+
return this;
|
125
138
|
}
|
126
139
|
setMenuClickHandler() {
|
127
140
|
//this.container.querySelector("#activateAnnot")?.addEventListener("click", this.clickHandler)
|
@@ -129,24 +142,23 @@ class Annotations {
|
|
129
142
|
}
|
130
143
|
setListeners() {
|
131
144
|
this.resetTextListeners();
|
132
|
-
this.customAnnotationDrawer = new
|
133
|
-
this.customAnnotationDrawer.setUpdateCallback(this.resetTextListeners.bind(this))
|
134
|
-
var harmonyButton = this.
|
145
|
+
// this.customAnnotationDrawer = new CustomAnnotationShapeDrawer(this.containerId)
|
146
|
+
// this.customAnnotationDrawer.setUpdateCallback(this.resetTextListeners.bind(this))
|
147
|
+
var harmonyButton = cq.getContainer(this.containerId).querySelector("#harmonyAnnotButton");
|
135
148
|
var that = this;
|
136
|
-
this.
|
137
|
-
b.addEventListener("click",
|
138
|
-
that.setToFront();
|
139
|
-
that.resetTextListeners();
|
140
|
-
b.dispatchEvent(new Event("annotationButtonClicked"));
|
141
|
-
});
|
142
|
-
});
|
143
|
-
harmonyButton.addEventListener("click", function () {
|
144
|
-
that.removeTextListeners();
|
145
|
-
harmonyButton.dispatchEvent(new Event("annotationButtonClicked"));
|
149
|
+
cq.getContainer(this.containerId).querySelectorAll(".annotText").forEach(b => {
|
150
|
+
b.addEventListener("click", this.clickAnnotTextHandler);
|
146
151
|
});
|
152
|
+
harmonyButton === null || harmonyButton === void 0 ? void 0 : harmonyButton.addEventListener("click", this.clickHarmonyBtnHandler);
|
153
|
+
return this;
|
147
154
|
}
|
148
155
|
removeListeners() {
|
149
156
|
this.removeTextListeners();
|
157
|
+
var harmonyButton = cq.getContainer(this.containerId).querySelector("#harmonyAnnotButton");
|
158
|
+
cq.getContainer(this.containerId).querySelectorAll(".annotText").forEach(b => {
|
159
|
+
b.removeEventListener("click", this.clickAnnotTextHandler);
|
160
|
+
});
|
161
|
+
harmonyButton === null || harmonyButton === void 0 ? void 0 : harmonyButton.removeEventListener("click", this.clickHarmonyBtnHandler);
|
150
162
|
}
|
151
163
|
setTextListeners() {
|
152
164
|
// this.customAnnotationDrawer = new CustomAnnotationShapeDrawer(this.containerId)
|
@@ -158,20 +170,31 @@ class Annotations {
|
|
158
170
|
.setAnnotations(this.annotations)
|
159
171
|
.update()
|
160
172
|
.resetListeners();
|
161
|
-
this.
|
173
|
+
cq.getInteractOverlay(this.containerId).addEventListener("dblclick", this.createAnnotationHandler);
|
162
174
|
var that = this;
|
163
|
-
this.
|
175
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll(".annotDiv").forEach(ad => {
|
164
176
|
ad.addEventListener("click", this.selectHandler);
|
165
177
|
ad.addEventListener("dblclick", this.activateEditHandler);
|
166
178
|
ad.addEventListener("focus", function () {
|
167
|
-
|
179
|
+
var _a;
|
180
|
+
(_a = that.musicPlayer) === null || _a === void 0 ? void 0 : _a.removePlayListener();
|
168
181
|
});
|
169
182
|
ad.addEventListener("blur", function () {
|
170
|
-
|
183
|
+
var _a;
|
184
|
+
ad.closest("svg").classList.remove("selected");
|
185
|
+
ad.setAttribute("contenteditable", "false");
|
186
|
+
cq.getInteractOverlay(that.containerId).querySelectorAll(`#${ad.closest("g").id} .lineDragRect`).forEach(ldr => ldr.remove());
|
187
|
+
(_a = that.musicPlayer) === null || _a === void 0 ? void 0 : _a.setPlayListener();
|
188
|
+
});
|
189
|
+
ad.addEventListener("mouseenter", function () {
|
190
|
+
cq.getContainer(that.containerId).classList.add("annotMode");
|
191
|
+
});
|
192
|
+
ad.addEventListener("mouseleave", function () {
|
193
|
+
cq.getContainer(that.containerId).classList.remove("annotMode");
|
171
194
|
});
|
172
195
|
ad.addEventListener("keydown", this.submitLabelHandler);
|
173
196
|
});
|
174
|
-
this.
|
197
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll(".customAnnotShape").forEach(cas => {
|
175
198
|
cas.addEventListener("dblclick", this.selectHandler);
|
176
199
|
});
|
177
200
|
document.addEventListener("keydown", this.deleteHandler);
|
@@ -183,16 +206,16 @@ class Annotations {
|
|
183
206
|
var _a;
|
184
207
|
//this.container.querySelector("#activateAnnot").removeEventListener("click", this.clickHandler)
|
185
208
|
this.setMenuClickHandler();
|
186
|
-
this.
|
187
|
-
this.
|
209
|
+
cq.getInteractOverlay(this.containerId).removeEventListener("dblclick", this.createAnnotationHandler);
|
210
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll(".annotDiv").forEach(ad => {
|
188
211
|
var _a;
|
189
212
|
(_a = ad.closest("svg")) === null || _a === void 0 ? void 0 : _a.classList.remove("selected");
|
190
213
|
ad.setAttribute("contenteditable", "false");
|
191
214
|
ad.removeEventListener("click", this.selectHandler);
|
192
215
|
ad.removeEventListener("dblclick", this.activateEditHandler);
|
193
216
|
});
|
194
|
-
this.
|
195
|
-
this.
|
217
|
+
//cq.getInteractOverlay(this.containerId).querySelectorAll(".lineDragRect").forEach(ldr => ldr.remove())
|
218
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll(".customAnnotShape").forEach(cas => {
|
196
219
|
cas.removeEventListener("dblclick", this.selectHandler);
|
197
220
|
});
|
198
221
|
document.removeEventListener("keydown", this.deleteHandler);
|
@@ -206,7 +229,9 @@ class Annotations {
|
|
206
229
|
this.setTextListeners();
|
207
230
|
}
|
208
231
|
resetListeners() {
|
209
|
-
this.resetTextListeners()
|
232
|
+
//this.resetTextListeners()
|
233
|
+
this.removeListeners();
|
234
|
+
this.setListeners();
|
210
235
|
}
|
211
236
|
setCustomShapeListener() {
|
212
237
|
var customShapes = null;
|
@@ -222,8 +247,6 @@ class Annotations {
|
|
222
247
|
return;
|
223
248
|
switch (selectedButton) {
|
224
249
|
case "linkedAnnotButton":
|
225
|
-
this.createTextAnnotation(e, selectedButton);
|
226
|
-
break;
|
227
250
|
case "staticTextButton":
|
228
251
|
this.createTextAnnotation(e, selectedButton);
|
229
252
|
break;
|
@@ -241,10 +264,10 @@ class Annotations {
|
|
241
264
|
* @returns
|
242
265
|
*/
|
243
266
|
createTextAnnotation(e, textButtonId) {
|
244
|
-
if (e.target.id !== this.
|
267
|
+
if (e.target.id !== cq.getInteractOverlay(this.containerId).id) {
|
245
268
|
return;
|
246
269
|
}
|
247
|
-
this.setToFront()
|
270
|
+
//this.setToFront()
|
248
271
|
var selcount = 0;
|
249
272
|
this.annotationCanvas.querySelectorAll(":scope > .selected").forEach(el => {
|
250
273
|
el.classList.remove("selected");
|
@@ -275,6 +298,7 @@ class Annotations {
|
|
275
298
|
text.classList.add("annotLinkedText");
|
276
299
|
else if (isStaticText)
|
277
300
|
text.classList.add("annotStaticText");
|
301
|
+
text.classList.add("annotText");
|
278
302
|
var textForeignObject = document.createElementNS(constants_1.constants._SVGNS_, "foreignObject");
|
279
303
|
textForeignObject.classList.add("annotFO");
|
280
304
|
var textDiv = document.createElement("div");
|
@@ -287,17 +311,29 @@ class Annotations {
|
|
287
311
|
var rectPadding = 5;
|
288
312
|
// text.setAttribute("x", "0")
|
289
313
|
// text.setAttribute("y", "0")
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
314
|
+
var foX = (posx + rectPadding).toString();
|
315
|
+
var foY = posy.toString();
|
316
|
+
var foH = (50 + 2 * rectPadding + 10).toString();
|
317
|
+
var foW = (50 + 2 * rectPadding + 50).toString();
|
318
|
+
textForeignObject.setAttribute("x", foX);
|
319
|
+
textForeignObject.setAttribute("y", foY);
|
320
|
+
textForeignObject.setAttribute("height", foH);
|
321
|
+
textForeignObject.setAttribute("width", foW);
|
294
322
|
if (isLinked) {
|
295
323
|
var line = document.createElementNS(constants_1.constants._SVGNS_, "line");
|
296
324
|
line.classList.add("annotLine");
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
325
|
+
const lX2 = textForeignObject.x.baseVal.valueAsString;
|
326
|
+
const lY2 = textForeignObject.y.baseVal.valueAsString;
|
327
|
+
const lX1 = annotationTarget.x.toString();
|
328
|
+
const lY1 = annotationTarget.y.toString();
|
329
|
+
line.setAttribute("x2", lX2);
|
330
|
+
line.setAttribute("y2", lY2);
|
331
|
+
line.setAttribute("x1", lX1);
|
332
|
+
line.setAttribute("y1", lY1);
|
333
|
+
const xDiff = parseFloat(lX1) - parseFloat(lX2);
|
334
|
+
const yDiff = parseFloat(lY1) - parseFloat(lY2);
|
335
|
+
line.setAttribute("x-diff", xDiff.toString());
|
336
|
+
line.setAttribute("y-diff", yDiff.toString());
|
301
337
|
line.classList.add("annotLine");
|
302
338
|
textGroup.appendChild(line);
|
303
339
|
}
|
@@ -315,20 +351,26 @@ class Annotations {
|
|
315
351
|
this.annotationCanvas.appendChild(textGroup);
|
316
352
|
this.deactivateEdit();
|
317
353
|
this.resetTextListeners();
|
318
|
-
this.
|
319
|
-
this.
|
354
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotChanged"));
|
355
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotationCanvasChanged"));
|
320
356
|
}
|
321
357
|
/**
|
322
358
|
* Mark an annotation as selected.
|
323
359
|
* @param e
|
324
360
|
*/
|
325
361
|
select(e) {
|
326
|
-
var _a
|
327
|
-
e.stopPropagation()
|
362
|
+
var _a;
|
363
|
+
//e.stopPropagation() //do not trigger other events
|
328
364
|
var t = e.target;
|
365
|
+
const cursorElement = document.elementFromPoint(e.clientX, e.clientY);
|
366
|
+
const cursorStyle = window.getComputedStyle(cursorElement).getPropertyValue('cursor');
|
367
|
+
// console.log("cursorStyle", cursorStyle)
|
368
|
+
// console.log(t, t.closest("svg"))
|
369
|
+
//if(!t.closest("svg")?.classList.contains("selected") && t.getAttribute("contenteditable") === "false") return
|
370
|
+
//t.setAttribute("contenteditable", "false")
|
329
371
|
if (t.classList.contains("annotDiv") && t.closest(".annotLinkedText") !== null) { // only apply for linked texts
|
330
372
|
//Add A selection Rect to line target
|
331
|
-
this.
|
373
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll(".lineDragRect").forEach(ldr => ldr.remove());
|
332
374
|
var line = t.closest("g").querySelector(".annotLine");
|
333
375
|
//Rect attacted to x2 target
|
334
376
|
var lineDragRect = document.createElementNS(constants_1.constants._SVGNS_, "rect");
|
@@ -346,11 +388,11 @@ class Annotations {
|
|
346
388
|
lineDragRect.setAttribute("y", line.y1.baseVal.valueAsString);
|
347
389
|
//this.AnnotationLineHandler.initDragRects()
|
348
390
|
}
|
349
|
-
(
|
391
|
+
(_a = t.closest("svg")) === null || _a === void 0 ? void 0 : _a.classList.add("selected");
|
350
392
|
this.annotationChangeHandler.resetListeners();
|
351
393
|
}
|
352
394
|
deactivateEdit() {
|
353
|
-
this.
|
395
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll(".annotDiv").forEach(ad => {
|
354
396
|
ad.setAttribute("contenteditable", "false");
|
355
397
|
ad.removeEventListener("dblclick", this.activateEditHandler);
|
356
398
|
});
|
@@ -360,12 +402,8 @@ class Annotations {
|
|
360
402
|
var _a;
|
361
403
|
this.addCanvas();
|
362
404
|
(_a = this.annotationChangeHandler) === null || _a === void 0 ? void 0 : _a.update();
|
363
|
-
|
364
|
-
|
365
|
-
}
|
366
|
-
else {
|
367
|
-
this.resetTextListeners();
|
368
|
-
}
|
405
|
+
this.resetListeners();
|
406
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotationCanvasChanged"));
|
369
407
|
}
|
370
408
|
updateAnnotationList(annotionCanvs) {
|
371
409
|
//TODO: Aktuallsieren des Datenmodells aus den Informarionen in der SVG: übersetzen der SVG in Annotation-Objekte
|
@@ -378,45 +416,83 @@ class Annotations {
|
|
378
416
|
};
|
379
417
|
that.annotations.push(a);
|
380
418
|
});
|
381
|
-
this.
|
419
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotChanged"));
|
382
420
|
this.resetTextListeners();
|
383
421
|
}
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
this.setListeners();
|
397
|
-
this.container.classList.forEach(c => {
|
398
|
-
if (c.toLowerCase().includes("mode")) { // ensure to only allow one mode when switching to annotMode
|
399
|
-
this.container.classList.remove(c);
|
422
|
+
updateLinkedTexts() {
|
423
|
+
var _a;
|
424
|
+
(_a = this.annotations) === null || _a === void 0 ? void 0 : _a.forEach(a => {
|
425
|
+
//0. Distance between annotId and targetId is saved in the line attributes x-diff and y-diff
|
426
|
+
//1. set Line x2/y2 to x/y of targetId
|
427
|
+
//2. set x/y of annotBox to targetx + x-diff/ targetY + y-diff
|
428
|
+
//3. if dragRects present, then update them as well
|
429
|
+
const source = cq.getInteractOverlay(this.containerId).querySelector(`#${a.sourceID}`);
|
430
|
+
if (!(source === null || source === void 0 ? void 0 : source.querySelector(".annotLinkedText")))
|
431
|
+
return;
|
432
|
+
if (!a.targetID) {
|
433
|
+
a.targetID = source.getAttribute("targetid");
|
400
434
|
}
|
435
|
+
const target = cq.getContainer(this.containerId).querySelector(`#${a.targetID}`);
|
436
|
+
if (!target)
|
437
|
+
return;
|
438
|
+
var foreignObject = source.querySelector(".annotFO");
|
439
|
+
const targetBbox = target.getBoundingClientRect();
|
440
|
+
const targetPt = coordinates.transformToDOMMatrixCoordinates(targetBbox.x, targetBbox.y, cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas"));
|
441
|
+
var line = source.querySelector("line");
|
442
|
+
const xSource = targetPt.x + parseFloat(line.getAttribute("x-diff"));
|
443
|
+
const ySource = targetPt.y + parseFloat(line.getAttribute("y-diff"));
|
444
|
+
line.setAttribute("x1", (targetPt.x).toString());
|
445
|
+
line.setAttribute("y1", (targetPt.y).toString());
|
446
|
+
line.setAttribute("x2", xSource.toString());
|
447
|
+
line.setAttribute("y2", ySource.toString());
|
448
|
+
foreignObject.setAttribute("x", xSource.toString());
|
449
|
+
foreignObject.setAttribute("y", ySource.toString());
|
450
|
+
source.querySelectorAll(".lineDragRect").forEach(ldr => {
|
451
|
+
if (ldr.classList.contains("x2")) {
|
452
|
+
ldr.setAttribute("x", xSource.toString());
|
453
|
+
ldr.setAttribute("y", ySource.toString());
|
454
|
+
}
|
455
|
+
else if (ldr.classList.contains("x1")) {
|
456
|
+
ldr.setAttribute("x", line.getAttribute("x1"));
|
457
|
+
ldr.setAttribute("y", line.getAttribute("y1"));
|
458
|
+
}
|
459
|
+
});
|
401
460
|
});
|
402
|
-
this.container.classList.add("annotMode");
|
403
|
-
return this;
|
404
461
|
}
|
462
|
+
/////////// UTILITIES //////////////
|
405
463
|
/**
|
406
|
-
*
|
464
|
+
* Put annotationCanvas to Front for editing
|
407
465
|
* @returns
|
408
466
|
*/
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
}
|
467
|
+
// setToFront(): Annotations {
|
468
|
+
// if (this.annotationCanvas.classList.contains("front")) { return this }
|
469
|
+
// this.annotationCanvas.classList.remove("back")
|
470
|
+
// this.annotationCanvas.classList.add("front")
|
471
|
+
// cq.getInteractOverlay(this.containerId).insertBefore(this.getAnnotationCanvas(), cq.getInteractOverlay(this.containerId).lastChild.nextSibling)
|
472
|
+
// this.setListeners()
|
473
|
+
// this.container.classList.forEach(c => {
|
474
|
+
// if (c.toLowerCase().includes("mode")) { // ensure to only allow one mode when switching to annotMode
|
475
|
+
// this.container.classList.remove(c)
|
476
|
+
// }
|
477
|
+
// })
|
478
|
+
// this.container.classList.add("annotMode")
|
479
|
+
// return this
|
480
|
+
// }
|
481
|
+
// /**
|
482
|
+
// * Set annotationCanvas to Back, when in different mode
|
483
|
+
// * @returns
|
484
|
+
// */
|
485
|
+
// setToBack() {
|
486
|
+
// // if( this.annotationCanvas.classList.contains("back")){return}
|
487
|
+
// // this.annotationCanvas.classList.remove("front")
|
488
|
+
// // this.annotationCanvas.classList.add("back")
|
489
|
+
// // if((this.getAnnotationCanvas() !== (cq.getInteractOverlay(this.containerId).firstChild as SVGSVGElement) && this.getAnnotationCanvas() !== null)){
|
490
|
+
// // cq.getInteractOverlay(this.containerId).insertBefore(this.getAnnotationCanvas(), cq.getInteractOverlay(this.containerId).firstChild)
|
491
|
+
// // }
|
492
|
+
// // this.removeListeners()
|
493
|
+
// // this.container.classList.remove("annotMode")
|
494
|
+
// return this
|
495
|
+
// }
|
420
496
|
////////// GETTER/ SETTER////////////
|
421
497
|
setm2s(m2s) {
|
422
498
|
this.m2s = m2s;
|
@@ -427,10 +503,11 @@ class Annotations {
|
|
427
503
|
return this;
|
428
504
|
}
|
429
505
|
getAnnotationCanvas() {
|
430
|
-
return this.
|
506
|
+
return cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas") || this.annotationCanvas;
|
431
507
|
}
|
432
508
|
setAnnotationCanvas(annotationCanvas) {
|
433
509
|
this.updateAnnotationList(annotationCanvas);
|
510
|
+
return this;
|
434
511
|
}
|
435
512
|
getAnnotationChangeHandler() {
|
436
513
|
return this.annotationChangeHandler;
|
@@ -438,7 +515,7 @@ class Annotations {
|
|
438
515
|
setUndoStacks(arr) {
|
439
516
|
if (arr[0] == undefined || this.undoStacks == undefined) {
|
440
517
|
this.undoStacks = arr;
|
441
|
-
var canvasClone = this.
|
518
|
+
var canvasClone = cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas").cloneNode(true);
|
442
519
|
var listClone = this.container.querySelector("#annotList").cloneNode(true);
|
443
520
|
this.undoStacks.push([canvasClone, listClone]);
|
444
521
|
//this.annotationCanvas = document.getElementById("annotationCanvas") as unknown as SVGSVGElement
|
@@ -449,7 +526,7 @@ class Annotations {
|
|
449
526
|
this.containerId = id;
|
450
527
|
this.container = document.getElementById(id);
|
451
528
|
this.vrvSVG = cq.getVrvSVG(id);
|
452
|
-
this.interactionOverlay = cq.getInteractOverlay(
|
529
|
+
this.interactionOverlay = cq.getInteractOverlay(this.containerId);
|
453
530
|
return this;
|
454
531
|
}
|
455
532
|
}
|
@@ -20,9 +20,13 @@ class HarmonyLabel {
|
|
20
20
|
this.isBassoContinuo = false;
|
21
21
|
this.isText = false;
|
22
22
|
var letters = /[AaBC-Zc-z].*/; // b is allowed character in bc
|
23
|
+
var isEmpty = inputString === "";
|
23
24
|
if (inputString.match(letters)) {
|
24
25
|
this.isText = true;
|
25
26
|
}
|
27
|
+
else if (isEmpty) {
|
28
|
+
this.element.dispatchEvent(new Event("emptyHarmonyText"));
|
29
|
+
}
|
26
30
|
else {
|
27
31
|
this.isBassoContinuo = true;
|
28
32
|
}
|
@@ -55,7 +59,16 @@ class HarmonyLabel {
|
|
55
59
|
}
|
56
60
|
parseText(inputString) {
|
57
61
|
inputString = inputString.replace("b", mappings_1.keyToUnicode.get("b"));
|
58
|
-
inputString = inputString.replace(/(?<!&)#/g,
|
62
|
+
//inputString = inputString.replace(/(?<!&)#/g, keyToUnicode.get("#"))
|
63
|
+
var regex = /(&)?#/g;
|
64
|
+
inputString = inputString.replace(regex, function (match, capturedGroup) {
|
65
|
+
if (capturedGroup === "&") {
|
66
|
+
return match;
|
67
|
+
}
|
68
|
+
else {
|
69
|
+
return mappings_1.keyToUnicode.get("#");
|
70
|
+
}
|
71
|
+
});
|
59
72
|
inputString = inputString.replace("n", mappings_1.keyToUnicode.get("n"));
|
60
73
|
inputString = inputString.replace("\\^", mappings_1.keyToUnicode.get("\\^"));
|
61
74
|
inputString = inputString.replace("/(?<!\/)°\/g", mappings_1.keyToUnicode.get("°"));
|
@@ -71,7 +84,18 @@ class HarmonyLabel {
|
|
71
84
|
splitArray.forEach(sa => {
|
72
85
|
var f = this.currentMEI.createElementNS(constants_1.constants._MEINS_, "f");
|
73
86
|
sa = sa.replace("b", mappings_1.keyToUnicode.get("b"));
|
74
|
-
sa = sa.replace(/(?<!&)#/g,
|
87
|
+
//sa = sa.replace(/(?<!&)#/g, keyToUnicode.get("#"))
|
88
|
+
var regex = /(&)?#/g;
|
89
|
+
sa = sa.replace(regex, function (match, capturedGroup) {
|
90
|
+
if (capturedGroup === "&") {
|
91
|
+
// If the '#' is preceded by '&', leave it as is
|
92
|
+
return match;
|
93
|
+
}
|
94
|
+
else {
|
95
|
+
// Replace '#' with the desired value
|
96
|
+
return mappings_1.keyToUnicode.get("#");
|
97
|
+
}
|
98
|
+
});
|
75
99
|
sa = sa.replace("n", mappings_1.keyToUnicode.get("n"));
|
76
100
|
f.textContent = sa;
|
77
101
|
fb.appendChild(f);
|