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.
Files changed (38) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +12 -9
  3. package/package.json +11 -5
  4. package/src/scripts/js/Core.js +212 -186
  5. package/src/scripts/js/MusicProcessor.js +286 -128
  6. package/src/scripts/js/{VerovioScoreEditor.js → VIBE.js} +62 -28
  7. package/src/scripts/js/assets/mei_template.js +5 -1
  8. package/src/scripts/js/datastructures/MeasureMatrix.js +6 -85
  9. package/src/scripts/js/datastructures/ScoreGraph.js +1 -1
  10. package/src/scripts/js/entry.js +3 -2
  11. package/src/scripts/js/gui/Annotations.js +188 -111
  12. package/src/scripts/js/gui/HarmonyLabel.js +26 -2
  13. package/src/scripts/js/gui/ScoreManipulator.js +61 -31
  14. package/src/scripts/js/gui/Tabbar.js +41 -21
  15. package/src/scripts/js/gui/Toolbar.js +4 -4
  16. package/src/scripts/js/handlers/AnnotationChangeHandler.js +131 -60
  17. package/src/scripts/js/handlers/ClickModeHandler.js +406 -143
  18. package/src/scripts/js/handlers/CustomToolbarHandler.js +26 -24
  19. package/src/scripts/js/handlers/GlobalKeyboardHandler.js +12 -7
  20. package/src/scripts/js/handlers/InsertModeHandler.js +26 -32
  21. package/src/scripts/js/handlers/KeyModeHandler.js +12 -86
  22. package/src/scripts/js/handlers/LabelHandler.js +3 -2
  23. package/src/scripts/js/handlers/PhantomElementHandler.js +1 -1
  24. package/src/scripts/js/handlers/ScoreManipulatorHandler.js +101 -14
  25. package/src/scripts/js/handlers/SelectionHandler.js +80 -36
  26. package/src/scripts/js/handlers/SideBarHandler.js +10 -3
  27. package/src/scripts/js/handlers/WindowHandler.js +25 -4
  28. package/src/scripts/js/utils/DOMCreator.js +1 -1
  29. package/src/scripts/js/utils/MEIConverter.js +13 -1
  30. package/src/scripts/js/utils/MEIOperations.js +180 -187
  31. package/src/scripts/js/utils/Mouse2SVG.js +200 -43
  32. package/src/scripts/js/utils/ReactWrapper.js +46 -0
  33. package/src/scripts/js/utils/RectWrapper.js +10 -0
  34. package/src/scripts/js/utils/SVGEditor.js +94 -3
  35. package/src/scripts/js/utils/VerovioWrapper.js +6 -1
  36. package/src/scripts/js/utils/convenienceQueries.js +2 -0
  37. package/src/scripts/js/utils/mappings.js +322 -56
  38. 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
- this.setToFront();
16
- }
17
- else {
18
- this.setToBack();
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(".vseContainer")) === null || _a === void 0 ? void 0 : _a.classList.contains("clickmode"))
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.interactionOverlay.querySelectorAll("#annotationCanvas .selected");
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.interactionOverlay.querySelector("#annotationCanvas").cloneNode(true);
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.interactionOverlay.querySelector("#annotationCanvas");
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.interactionOverlay.querySelectorAll(".selected [contenteditable=true]").length > 0;
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.interactionOverlay.querySelectorAll("#annotationCanvas .selected").forEach(el => {
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.interactionOverlay.dispatchEvent(new Event("annotChanged"));
90
- this.interactionOverlay.dispatchEvent(new Event("annotationCanvasChanged"));
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.interactionOverlay.dispatchEvent(new Event("annotChanged"));
98
- this.interactionOverlay.dispatchEvent(new Event("annotationCanvasChanged"));
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
- this.interactionOverlay = cq.getInteractOverlay(this.containerId);
107
- this.rootBBox = this.interactionOverlay.getBoundingClientRect(); //this.vrvSVG.getBoundingClientRect()
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.interactionOverlay.getAttribute("viewBox"); //this.vrvSVG.getAttribute("viewBox")
111
- if (this.annotationCanvas == undefined) {
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
- this.interactionOverlay.insertBefore(this.annotationCanvas, this.interactionOverlay.lastChild.nextSibling);
121
- }
122
- else {
123
- this.interactionOverlay.insertBefore(this.annotationCanvas, this.interactionOverlay.firstChild);
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 CustomAnnotationShapeDrawer_1.default(this.containerId);
133
- this.customAnnotationDrawer.setUpdateCallback(this.resetTextListeners.bind(this));
134
- var harmonyButton = this.container.querySelector("#harmonyAnnotButton");
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.container.querySelectorAll("#staticTextButton, #linkedAnnotButton").forEach(b => {
137
- b.addEventListener("click", function () {
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.interactionOverlay.addEventListener("dblclick", this.createAnnotationHandler);
173
+ cq.getInteractOverlay(this.containerId).addEventListener("dblclick", this.createAnnotationHandler);
162
174
  var that = this;
163
- this.interactionOverlay.querySelectorAll(".annotDiv").forEach(ad => {
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
- that.musicPlayer.removePlayListener();
179
+ var _a;
180
+ (_a = that.musicPlayer) === null || _a === void 0 ? void 0 : _a.removePlayListener();
168
181
  });
169
182
  ad.addEventListener("blur", function () {
170
- that.musicPlayer.setPlayListener();
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.interactionOverlay.querySelectorAll(".customAnnotShape").forEach(cas => {
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.interactionOverlay.removeEventListener("dblclick", this.createAnnotationHandler);
187
- this.interactionOverlay.querySelectorAll(".annotDiv").forEach(ad => {
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.interactionOverlay.querySelectorAll(".lineDragRect").forEach(ldr => ldr.remove());
195
- this.interactionOverlay.querySelectorAll(".customAnnotShape").forEach(cas => {
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.interactionOverlay.id) {
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
- textForeignObject.setAttribute("x", (posx + rectPadding).toString());
291
- textForeignObject.setAttribute("y", posy.toString());
292
- textForeignObject.setAttribute("height", (50 + 2 * rectPadding + 10).toString());
293
- textForeignObject.setAttribute("width", (50 + 2 * rectPadding + 50).toString());
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
- line.setAttribute("x2", textForeignObject.x.baseVal.valueAsString);
298
- line.setAttribute("y2", textForeignObject.y.baseVal.valueAsString);
299
- line.setAttribute("x1", annotationTarget.x.toString()); //(annotationTarget.x - this.rootBBox.x - window.pageXOffset).toString())
300
- line.setAttribute("y1", annotationTarget.y.toString()); //(annotationTarget.y - this.rootBBox.y - window.pageYOffset).toString())
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.interactionOverlay.dispatchEvent(new Event("annotChanged"));
319
- this.interactionOverlay.dispatchEvent(new Event("annotationCanvasChanged"));
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, _b;
327
- e.stopPropagation(); //do not trigger other events
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.interactionOverlay.querySelectorAll(".lineDragRect").forEach(ldr => ldr.remove());
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
- (_b = (_a = t === null || t === void 0 ? void 0 : t.closest("svg")) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add("selected");
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.interactionOverlay.querySelectorAll(".annotDiv").forEach(ad => {
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
- if (this.annotationCanvas.classList.contains("back")) {
364
- this.removeListeners();
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.interactionOverlay.dispatchEvent(new Event("annotChanged"));
419
+ cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotChanged"));
382
420
  this.resetTextListeners();
383
421
  }
384
- /////////// UTILITIES //////////////
385
- /**
386
- * Put annotationCanvas to Front for editing
387
- * @returns
388
- */
389
- setToFront() {
390
- if (this.annotationCanvas.classList.contains("front")) {
391
- return this;
392
- }
393
- this.annotationCanvas.classList.remove("back");
394
- this.annotationCanvas.classList.add("front");
395
- this.interactionOverlay.insertBefore(this.getAnnotationCanvas(), this.interactionOverlay.lastChild.nextSibling);
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
- * Set annotationCanvas to Back, when in different mode
464
+ * Put annotationCanvas to Front for editing
407
465
  * @returns
408
466
  */
409
- setToBack() {
410
- // if( this.annotationCanvas.classList.contains("back")){return}
411
- // this.annotationCanvas.classList.remove("front")
412
- // this.annotationCanvas.classList.add("back")
413
- // if((this.getAnnotationCanvas() !== (this.interactionOverlay.firstChild as SVGSVGElement) && this.getAnnotationCanvas() !== null)){
414
- // this.interactionOverlay.insertBefore(this.getAnnotationCanvas(), this.interactionOverlay.firstChild)
415
- // }
416
- // this.removeListeners()
417
- // this.container.classList.remove("annotMode")
418
- return this;
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.interactionOverlay.querySelector("#annotationCanvas") || this.annotationCanvas;
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.interactionOverlay.querySelector("#annotationCanvas").cloneNode(true);
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(id);
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, mappings_1.keyToUnicode.get("#"));
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, mappings_1.keyToUnicode.get("#"));
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);