vibe-editor 0.0.3 → 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 +32 -13
- package/src/scripts/js/entry.js +6 -5
- package/src/scripts/js/gui/Annotations.js +28 -13
- package/src/scripts/js/gui/ScoreManipulator.js +13 -11
- package/src/scripts/js/gui/Tabbar.js +14 -5
- package/src/scripts/js/gui/Toolbar.js +1 -1
- package/src/scripts/js/handlers/AnnotationChangeHandler.js +16 -4
- package/src/scripts/js/handlers/CustomAnnotationShapeDrawer.js +2 -2
- package/src/scripts/js/handlers/InsertModeHandler.js +7 -7
- package/src/scripts/js/handlers/KeyModeHandler.js +1 -1
- package/src/scripts/js/handlers/LabelHandler.js +1 -1
- package/src/scripts/js/handlers/NoteDragHandler.js +1 -1
- package/src/scripts/js/handlers/PhantomElementHandler.js +3 -10
- package/src/scripts/js/handlers/{SideBarHandler.js → SidebarHandler.js} +1 -1
- package/src/scripts/js/handlers/TooltipHandler.js +1 -1
- 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/{assets → scripts/assets}/mei_template.js +2 -2
- 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/{gui → scripts/gui}/HarmonyLabel.js +1 -1
- 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 → scripts/gui}/TempoLabel.js +1 -1
- 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/{utils → scripts/utils}/ReactWrapper.js +1 -1
- 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/MEIOperations.js +22 -22
- package/src/scripts/js/utils/Mouse2SVG.js +13 -6
- package/src/scripts/js/utils/SVGEditor.js +2 -2
- 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/{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}/Label.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}/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
@@ -0,0 +1,549 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const constants_1 = require("../constants");
|
4
|
+
const random_1 = require("../utils/random");
|
5
|
+
const AnnotationChangeHandler_1 = require("../handlers/AnnotationChangeHandler");
|
6
|
+
const cq = require("../utils/convenienceQueries");
|
7
|
+
const coordinates = require("../utils/coordinates");
|
8
|
+
class Annotations {
|
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);
|
20
|
+
////HANDLERS////
|
21
|
+
this.clickHandler = (function clickHandler(e) {
|
22
|
+
//e.preventDefault()
|
23
|
+
// if (!this.annotationCanvas.classList.contains("front")) {
|
24
|
+
// this.setToFront()
|
25
|
+
// } else {
|
26
|
+
// this.setToBack()
|
27
|
+
// }
|
28
|
+
}).bind(this);
|
29
|
+
this.createAnnotationHandler = (function createAnnotationHandler(e) {
|
30
|
+
var _a;
|
31
|
+
var t = e.target;
|
32
|
+
if ((_a = t.closest(".vibeContainer")) === null || _a === void 0 ? void 0 : _a.classList.contains("clickmode"))
|
33
|
+
return; // creation should only be possible when annotation tab is on
|
34
|
+
var selectedAnnotations = cq.getInteractOverlay(this.containerId).querySelectorAll("#annotationCanvas .selected");
|
35
|
+
if (selectedAnnotations.length === 0) {
|
36
|
+
this.createAnnotation(e);
|
37
|
+
}
|
38
|
+
else {
|
39
|
+
selectedAnnotations.forEach(sa => {
|
40
|
+
sa.classList.remove("selected");
|
41
|
+
});
|
42
|
+
}
|
43
|
+
}).bind(this);
|
44
|
+
this.selectHandler = (function selectHandler(e) {
|
45
|
+
this.select(e);
|
46
|
+
}).bind(this);
|
47
|
+
this.updateUndoStacks = (function updateUndoStacks(e) {
|
48
|
+
if (!cq.hasActiveElement(this.containerId)) {
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
var canvasClone = cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas").cloneNode(true);
|
52
|
+
var listClone = this.container.querySelector("#annotList").cloneNode(true);
|
53
|
+
this.annotList = this.container.querySelector("#annotList");
|
54
|
+
this.undoStacks.push([canvasClone, listClone]);
|
55
|
+
this.annotationCanvas = cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas");
|
56
|
+
}).bind(this);
|
57
|
+
this.updateRedoStacks = (function updateRedoStacks(e) {
|
58
|
+
if (!cq.hasActiveElement(this.containerId)) {
|
59
|
+
return;
|
60
|
+
}
|
61
|
+
this.redoStacks.push([this.annotationCanvas, this.annotList]);
|
62
|
+
this.annotationCanvas = this.undoStacks[0][0];
|
63
|
+
this.annotList = this.undoStacks[0][1];
|
64
|
+
}).bind(this);
|
65
|
+
/**
|
66
|
+
* Set Contenteditable True when doubleclicked
|
67
|
+
* @param e Doubleclick
|
68
|
+
*/
|
69
|
+
this.activateEditHandler = (function activateEditHandler(e) {
|
70
|
+
var target = e.target;
|
71
|
+
target.setAttribute("contenteditable", "true");
|
72
|
+
target.focus();
|
73
|
+
console.log("activeElement", document.activeElement);
|
74
|
+
this.annotationChangeHandler.removeListeners();
|
75
|
+
}).bind(this);
|
76
|
+
/**
|
77
|
+
* Delete all selected elements by pressing delete. Except: When any Elements are in Editable mode
|
78
|
+
* @param e Keyboardevent (code = Delete)
|
79
|
+
*/
|
80
|
+
this.deleteHandler = (function deleteHandler(e) {
|
81
|
+
if (!cq.hasActiveElement(this.containerId)) {
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
var isValidKey = ["Delete", "Backspace"].some(code => e.code === code);
|
85
|
+
//var isInAnnotMode = this.container.classList.contains("annotMode")
|
86
|
+
var hasEditableElement = cq.getInteractOverlay(this.containerId).querySelectorAll(".selected [contenteditable=true]").length > 0;
|
87
|
+
var listHasFocus = Array.from(this.container.querySelectorAll("#annotList > *")).some(le => le === document.activeElement);
|
88
|
+
//if(isValidKey && isInAnnotMode && !hasEditableElement && !listHasFocus){
|
89
|
+
if (isValidKey && !hasEditableElement && !listHasFocus) {
|
90
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll("#annotationCanvas .selected").forEach(el => {
|
91
|
+
if (el.closest("g") !== null) {
|
92
|
+
el.closest("g").remove();
|
93
|
+
}
|
94
|
+
else {
|
95
|
+
el.remove();
|
96
|
+
}
|
97
|
+
});
|
98
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotChanged"));
|
99
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotationCanvasChanged"));
|
100
|
+
}
|
101
|
+
}).bind(this);
|
102
|
+
this.submitLabelHandler = (function submitHandler(e) {
|
103
|
+
var target = e.target;
|
104
|
+
if ((e.key === "Enter" || e.key === "Escape")) {
|
105
|
+
target.blur();
|
106
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotChanged"));
|
107
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotationCanvasChanged"));
|
108
|
+
}
|
109
|
+
}).bind(this);
|
110
|
+
this.setContainerId(containerId);
|
111
|
+
this.addCanvas();
|
112
|
+
this.annotations = new Array();
|
113
|
+
}
|
114
|
+
addCanvas() {
|
115
|
+
var _a;
|
116
|
+
//cq.getInteractOverlay(this.containerId) = cq.getInteractOverlay(this.containerId)
|
117
|
+
this.rootBBox = cq.getInteractOverlay(this.containerId).getBoundingClientRect(); //this.vrvSVG.getBoundingClientRect()
|
118
|
+
var rootWidth = this.rootBBox.width.toString();
|
119
|
+
var rootHeigth = this.rootBBox.height.toString();
|
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) {
|
123
|
+
this.annotationCanvas = document.createElementNS(constants_1.constants._SVGNS_, "svg");
|
124
|
+
this.annotationCanvas.setAttribute("id", "annotationCanvas");
|
125
|
+
this.annotationCanvas.classList.add("canvas");
|
126
|
+
//this.annotationCanvas.classList.add("back")
|
127
|
+
//this.annotationCanvas.setAttribute("viewBox", ["0", "0", rootWidth, rootHeigth].join(" "))
|
128
|
+
}
|
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;
|
138
|
+
}
|
139
|
+
setMenuClickHandler() {
|
140
|
+
//this.container.querySelector("#activateAnnot")?.addEventListener("click", this.clickHandler)
|
141
|
+
return this;
|
142
|
+
}
|
143
|
+
setListeners() {
|
144
|
+
this.resetTextListeners();
|
145
|
+
// this.customAnnotationDrawer = new CustomAnnotationShapeDrawer(this.containerId)
|
146
|
+
// this.customAnnotationDrawer.setUpdateCallback(this.resetTextListeners.bind(this))
|
147
|
+
var harmonyButton = cq.getContainer(this.containerId).querySelector("#harmonyAnnotButton");
|
148
|
+
var that = this;
|
149
|
+
cq.getContainer(this.containerId).querySelectorAll(".annotText").forEach(b => {
|
150
|
+
b.addEventListener("click", this.clickAnnotTextHandler);
|
151
|
+
});
|
152
|
+
harmonyButton === null || harmonyButton === void 0 ? void 0 : harmonyButton.addEventListener("click", this.clickHarmonyBtnHandler);
|
153
|
+
//window.addEventListener("resize", this.resizeHandler)
|
154
|
+
return this;
|
155
|
+
}
|
156
|
+
removeListeners() {
|
157
|
+
this.removeTextListeners();
|
158
|
+
var harmonyButton = cq.getContainer(this.containerId).querySelector("#harmonyAnnotButton");
|
159
|
+
cq.getContainer(this.containerId).querySelectorAll(".annotText").forEach(b => {
|
160
|
+
b.removeEventListener("click", this.clickAnnotTextHandler);
|
161
|
+
});
|
162
|
+
harmonyButton === null || harmonyButton === void 0 ? void 0 : harmonyButton.removeEventListener("click", this.clickHarmonyBtnHandler);
|
163
|
+
//window.removeEventListener("resize", this.resizeHandler)
|
164
|
+
}
|
165
|
+
setTextListeners() {
|
166
|
+
// this.customAnnotationDrawer = new CustomAnnotationShapeDrawer(this.containerId)
|
167
|
+
// this.customAnnotationDrawer.setUpdateCallback(this.resetTextListeners.bind(this))
|
168
|
+
this.annotationChangeHandler = this.annotationChangeHandler || new AnnotationChangeHandler_1.default(this.containerId);
|
169
|
+
this.annotationChangeHandler
|
170
|
+
.setUpdateCallback(this.resetTextListeners.bind(this))
|
171
|
+
.setm2s(this.m2s)
|
172
|
+
.setAnnotations(this.annotations)
|
173
|
+
.update()
|
174
|
+
.resetListeners();
|
175
|
+
cq.getInteractOverlay(this.containerId).addEventListener("dblclick", this.createAnnotationHandler);
|
176
|
+
var that = this;
|
177
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll(".annotDiv").forEach(ad => {
|
178
|
+
ad.addEventListener("click", this.selectHandler);
|
179
|
+
ad.addEventListener("dblclick", this.activateEditHandler);
|
180
|
+
ad.addEventListener("focus", function () {
|
181
|
+
var _a;
|
182
|
+
(_a = that.musicPlayer) === null || _a === void 0 ? void 0 : _a.removePlayListener();
|
183
|
+
});
|
184
|
+
ad.addEventListener("blur", function () {
|
185
|
+
var _a;
|
186
|
+
ad.closest("svg").classList.remove("selected");
|
187
|
+
ad.setAttribute("contenteditable", "false");
|
188
|
+
cq.getInteractOverlay(that.containerId).querySelectorAll(`#${ad.closest("g").id} .lineDragRect`).forEach(ldr => ldr.remove());
|
189
|
+
(_a = that.musicPlayer) === null || _a === void 0 ? void 0 : _a.setPlayListener();
|
190
|
+
});
|
191
|
+
ad.addEventListener("mouseenter", function () {
|
192
|
+
cq.getContainer(that.containerId).classList.add("annotMode");
|
193
|
+
});
|
194
|
+
ad.addEventListener("mouseleave", function () {
|
195
|
+
cq.getContainer(that.containerId).classList.remove("annotMode");
|
196
|
+
});
|
197
|
+
ad.addEventListener("keydown", this.submitLabelHandler);
|
198
|
+
});
|
199
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll(".customAnnotShape").forEach(cas => {
|
200
|
+
cas.addEventListener("dblclick", this.selectHandler);
|
201
|
+
});
|
202
|
+
document.addEventListener("keydown", this.deleteHandler);
|
203
|
+
document.addEventListener("annotationCanvasChanged", this.updateUndoStacks, true);
|
204
|
+
//document.addEventListener("annotationCanvasChanged", this.updateRedoStacks)
|
205
|
+
return this;
|
206
|
+
}
|
207
|
+
removeTextListeners() {
|
208
|
+
var _a;
|
209
|
+
//this.container.querySelector("#activateAnnot").removeEventListener("click", this.clickHandler)
|
210
|
+
this.setMenuClickHandler();
|
211
|
+
cq.getInteractOverlay(this.containerId).removeEventListener("dblclick", this.createAnnotationHandler);
|
212
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll(".annotDiv").forEach(ad => {
|
213
|
+
var _a;
|
214
|
+
(_a = ad.closest("svg")) === null || _a === void 0 ? void 0 : _a.classList.remove("selected");
|
215
|
+
ad.setAttribute("contenteditable", "false");
|
216
|
+
ad.removeEventListener("click", this.selectHandler);
|
217
|
+
ad.removeEventListener("dblclick", this.activateEditHandler);
|
218
|
+
});
|
219
|
+
//cq.getInteractOverlay(this.containerId).querySelectorAll(".lineDragRect").forEach(ldr => ldr.remove())
|
220
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll(".customAnnotShape").forEach(cas => {
|
221
|
+
cas.removeEventListener("dblclick", this.selectHandler);
|
222
|
+
});
|
223
|
+
document.removeEventListener("keydown", this.deleteHandler);
|
224
|
+
(_a = this.customAnnotationDrawer) === null || _a === void 0 ? void 0 : _a.removeListeners();
|
225
|
+
// interaction with all the annotations should always be possible
|
226
|
+
//this.annotationChangeHandler?.removeListeners()
|
227
|
+
return this;
|
228
|
+
}
|
229
|
+
resetTextListeners() {
|
230
|
+
this.removeTextListeners();
|
231
|
+
this.setTextListeners();
|
232
|
+
}
|
233
|
+
resetListeners() {
|
234
|
+
//this.resetTextListeners()
|
235
|
+
this.removeListeners();
|
236
|
+
this.setListeners();
|
237
|
+
}
|
238
|
+
setCustomShapeListener() {
|
239
|
+
var customShapes = null;
|
240
|
+
}
|
241
|
+
/**
|
242
|
+
* Select a specific annotation methon based on selected button
|
243
|
+
* @param e
|
244
|
+
*/
|
245
|
+
createAnnotation(e) {
|
246
|
+
var _a;
|
247
|
+
var selectedButton = (_a = this.container.querySelector("#annotGroupKM > .selected")) === null || _a === void 0 ? void 0 : _a.id;
|
248
|
+
if (selectedButton === null)
|
249
|
+
return;
|
250
|
+
switch (selectedButton) {
|
251
|
+
case "linkedAnnotButton":
|
252
|
+
case "staticTextButton":
|
253
|
+
this.container.classList.remove("harmonyMode");
|
254
|
+
this.createTextAnnotation(e, selectedButton);
|
255
|
+
break;
|
256
|
+
case "harmonyAnnotButton":
|
257
|
+
//this.createHarmonyAnnot(e)
|
258
|
+
console.log(selectedButton, "Please implement me o(;△;)o");
|
259
|
+
break;
|
260
|
+
default:
|
261
|
+
console.log("There is no implementation at all");
|
262
|
+
}
|
263
|
+
}
|
264
|
+
/**
|
265
|
+
* Create a new linked annotation Instance
|
266
|
+
* @param e
|
267
|
+
* @returns
|
268
|
+
*/
|
269
|
+
createTextAnnotation(e, textButtonId) {
|
270
|
+
if (e.target.id !== cq.getInteractOverlay(this.containerId).id) {
|
271
|
+
return;
|
272
|
+
}
|
273
|
+
//this.setToFront()
|
274
|
+
var selcount = 0;
|
275
|
+
this.annotationCanvas.querySelectorAll(":scope > .selected").forEach(el => {
|
276
|
+
el.classList.remove("selected");
|
277
|
+
selcount += 1;
|
278
|
+
});
|
279
|
+
if (selcount > 0) {
|
280
|
+
return;
|
281
|
+
}
|
282
|
+
var isLinked = false;
|
283
|
+
var isStaticText = false;
|
284
|
+
switch (textButtonId) {
|
285
|
+
case "linkedAnnotButton":
|
286
|
+
isLinked = true;
|
287
|
+
break;
|
288
|
+
case "staticTextButton":
|
289
|
+
isStaticText = true;
|
290
|
+
break;
|
291
|
+
}
|
292
|
+
var pt = coordinates.transformToDOMMatrixCoordinates(e.clientX, e.clientY, cq.getInteractOverlay(this.containerId));
|
293
|
+
var posx = pt.x; //matrixTransform(rootMatrix).x //e.pageX - this.rootBBox.x - window.pageXOffset
|
294
|
+
var posy = pt.y; //matrixTransform(rootMatrix).y //e.pageY - this.rootBBox.y - window.pageYOffset
|
295
|
+
var staves = this.interactionOverlay.querySelectorAll(".staff");
|
296
|
+
var tempDist = Math.pow(10, 10);
|
297
|
+
var annotationTarget = this.m2s.findScoreTarget(posx, posy, false, null, ["mRest"]);
|
298
|
+
if (!annotationTarget) {
|
299
|
+
var annotationCoords;
|
300
|
+
staves.forEach(s => {
|
301
|
+
var coord = coordinates.getDOMMatrixCoordinates(s, this.interactionOverlay);
|
302
|
+
var dist = Math.sqrt(Math.abs(coord.x - posx) ** 2 + Math.abs(coord.y - posy) ** 2);
|
303
|
+
if (dist < tempDist) {
|
304
|
+
tempDist = dist;
|
305
|
+
annotationTarget = this.vrvSVG.querySelector("#" + s.getAttribute("refId"));
|
306
|
+
annotationCoords = coord;
|
307
|
+
}
|
308
|
+
});
|
309
|
+
}
|
310
|
+
var textGroup = document.createElementNS(constants_1.constants._SVGNS_, "g");
|
311
|
+
textGroup.setAttribute("id", random_1.uuidv4());
|
312
|
+
textGroup.setAttribute("targetId", annotationTarget.id);
|
313
|
+
var text = document.createElementNS(constants_1.constants._SVGNS_, "svg");
|
314
|
+
if (isLinked)
|
315
|
+
text.classList.add("annotLinkedText");
|
316
|
+
else if (isStaticText)
|
317
|
+
text.classList.add("annotStaticText");
|
318
|
+
text.classList.add("annotText");
|
319
|
+
var textForeignObject = document.createElementNS(constants_1.constants._SVGNS_, "foreignObject");
|
320
|
+
textForeignObject.classList.add("annotFO");
|
321
|
+
var textDiv = document.createElement("div");
|
322
|
+
textDiv.setAttribute("contenteditable", "false");
|
323
|
+
textDiv.setAttribute("data-text", "New Annotation");
|
324
|
+
textDiv.textContent = "";
|
325
|
+
textDiv.classList.add("annotDiv");
|
326
|
+
text.append(textForeignObject);
|
327
|
+
this.container.appendChild(textDiv);
|
328
|
+
var rectPadding = 5;
|
329
|
+
// text.setAttribute("x", "0")
|
330
|
+
// text.setAttribute("y", "0")
|
331
|
+
var foX = (posx + rectPadding).toString();
|
332
|
+
var foY = posy.toString();
|
333
|
+
var foH = (50 + 2 * rectPadding + 10).toString();
|
334
|
+
var foW = (50 + 2 * rectPadding + 50).toString();
|
335
|
+
textForeignObject.setAttribute("x", foX);
|
336
|
+
textForeignObject.setAttribute("y", foY);
|
337
|
+
// textForeignObject.style.height = foH + "px" //setAttribute("height", foH)
|
338
|
+
// textForeignObject.style.width = foW + "px" //setAttribute("width", foW)
|
339
|
+
if (isLinked) {
|
340
|
+
var line = document.createElementNS(constants_1.constants._SVGNS_, "line");
|
341
|
+
line.classList.add("annotLine");
|
342
|
+
const targetCoords = annotationCoords || annotationTarget;
|
343
|
+
const lX2 = textForeignObject.x.baseVal.valueAsString;
|
344
|
+
const lY2 = textForeignObject.y.baseVal.valueAsString;
|
345
|
+
const lX1 = targetCoords.x.toString();
|
346
|
+
const lY1 = targetCoords.y.toString();
|
347
|
+
line.setAttribute("x2", lX2);
|
348
|
+
line.setAttribute("y2", lY2);
|
349
|
+
line.setAttribute("x1", lX1);
|
350
|
+
line.setAttribute("y1", lY1);
|
351
|
+
const xDiff = parseFloat(lX2) - parseFloat(lX1); //parseFloat(lX1) - parseFloat(lX2)
|
352
|
+
const yDiff = parseFloat(lY2) - parseFloat(lY1); //parseFloat(lY1) - parseFloat(lY2)
|
353
|
+
line.setAttribute("x-diff", xDiff.toString());
|
354
|
+
line.setAttribute("y-diff", yDiff.toString());
|
355
|
+
line.classList.add("annotLine");
|
356
|
+
textGroup.appendChild(line);
|
357
|
+
}
|
358
|
+
textForeignObject.append(textDiv);
|
359
|
+
textGroup.appendChild(text);
|
360
|
+
var newAnnot = {
|
361
|
+
sourceID: textGroup.id,
|
362
|
+
targetID: annotationTarget.id,
|
363
|
+
originalWidth: "200",
|
364
|
+
originalHeight: "100",
|
365
|
+
};
|
366
|
+
this.annotations.push(newAnnot);
|
367
|
+
this.annotationCanvas.appendChild(textGroup);
|
368
|
+
this.deactivateEdit();
|
369
|
+
this.resetTextListeners();
|
370
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotChanged"));
|
371
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotationCanvasChanged"));
|
372
|
+
}
|
373
|
+
/**
|
374
|
+
* Mark an annotation as selected.
|
375
|
+
* @param e
|
376
|
+
*/
|
377
|
+
select(e) {
|
378
|
+
var _a;
|
379
|
+
//e.stopPropagation() //do not trigger other events
|
380
|
+
var t = e.target;
|
381
|
+
const cursorElement = document.elementFromPoint(e.clientX, e.clientY);
|
382
|
+
const cursorStyle = window.getComputedStyle(cursorElement).getPropertyValue('cursor');
|
383
|
+
// console.log("cursorStyle", cursorStyle)
|
384
|
+
// console.log(t, t.closest("svg"))
|
385
|
+
//if(!t.closest("svg")?.classList.contains("selected") && t.getAttribute("contenteditable") === "false") return
|
386
|
+
//t.setAttribute("contenteditable", "false")
|
387
|
+
if (t.classList.contains("annotDiv") && t.closest(".annotLinkedText") !== null) { // only apply for linked texts
|
388
|
+
//Add A selection Rect to line target
|
389
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll(".lineDragRect").forEach(ldr => ldr.remove());
|
390
|
+
var line = t.closest("g").querySelector(".annotLine");
|
391
|
+
//Rect attacted to x2 target
|
392
|
+
var lineDragRect = document.createElementNS(constants_1.constants._SVGNS_, "rect");
|
393
|
+
t.closest("g").appendChild(lineDragRect);
|
394
|
+
lineDragRect.classList.add("lineDragRect");
|
395
|
+
lineDragRect.classList.add("x2");
|
396
|
+
lineDragRect.setAttribute("x", line.x2.baseVal.valueAsString);
|
397
|
+
lineDragRect.setAttribute("y", line.y2.baseVal.valueAsString);
|
398
|
+
//Rect attacted to x1 target
|
399
|
+
lineDragRect = document.createElementNS(constants_1.constants._SVGNS_, "rect");
|
400
|
+
t.closest("g").appendChild(lineDragRect);
|
401
|
+
lineDragRect.classList.add("lineDragRect");
|
402
|
+
lineDragRect.classList.add("x1");
|
403
|
+
lineDragRect.setAttribute("x", line.x1.baseVal.valueAsString);
|
404
|
+
lineDragRect.setAttribute("y", line.y1.baseVal.valueAsString);
|
405
|
+
//this.AnnotationLineHandler.initDragRects()
|
406
|
+
}
|
407
|
+
(_a = t.closest("svg")) === null || _a === void 0 ? void 0 : _a.classList.add("selected");
|
408
|
+
this.annotationChangeHandler.resetListeners();
|
409
|
+
}
|
410
|
+
deactivateEdit() {
|
411
|
+
cq.getInteractOverlay(this.containerId).querySelectorAll(".annotDiv").forEach(ad => {
|
412
|
+
ad.setAttribute("contenteditable", "false");
|
413
|
+
ad.removeEventListener("dblclick", this.activateEditHandler);
|
414
|
+
});
|
415
|
+
this.annotationChangeHandler.removeListeners();
|
416
|
+
}
|
417
|
+
updateCanvas() {
|
418
|
+
var _a;
|
419
|
+
this.addCanvas();
|
420
|
+
(_a = this.annotationChangeHandler) === null || _a === void 0 ? void 0 : _a.update();
|
421
|
+
this.resetListeners();
|
422
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotationCanvasChanged"));
|
423
|
+
}
|
424
|
+
updateAnnotationList(annotionCanvs) {
|
425
|
+
//TODO: Aktuallsieren des Datenmodells aus den Informarionen in der SVG: übersetzen der SVG in Annotation-Objekte
|
426
|
+
var that = this;
|
427
|
+
this.annotationCanvas = annotionCanvs;
|
428
|
+
this.annotationCanvas.querySelectorAll(":scope > g").forEach(g => {
|
429
|
+
var a = {
|
430
|
+
sourceID: g.id,
|
431
|
+
targetID: g.getAttribute("targetId")
|
432
|
+
};
|
433
|
+
that.annotations.push(a);
|
434
|
+
});
|
435
|
+
cq.getInteractOverlay(this.containerId).dispatchEvent(new Event("annotChanged"));
|
436
|
+
this.resetTextListeners();
|
437
|
+
}
|
438
|
+
updateLinkedTexts() {
|
439
|
+
var _a;
|
440
|
+
(_a = this.annotations) === null || _a === void 0 ? void 0 : _a.forEach(a => {
|
441
|
+
//0. Distance between annotId and targetId is saved in the line attributes x-diff and y-diff
|
442
|
+
//1. set Line x2/y2 to x/y of targetId
|
443
|
+
//2. set x/y of annotBox to targetx + x-diff/ targetY + y-diff
|
444
|
+
//3. if dragRects present, then update them as well
|
445
|
+
const source = cq.getInteractOverlay(this.containerId).querySelector(`#${a.sourceID}`);
|
446
|
+
if (!(source === null || source === void 0 ? void 0 : source.querySelector(".annotLinkedText")))
|
447
|
+
return;
|
448
|
+
if (!a.targetID) {
|
449
|
+
a.targetID = source.getAttribute("targetid");
|
450
|
+
}
|
451
|
+
const target = cq.getContainer(this.containerId).querySelector(`#${a.targetID}`);
|
452
|
+
if (!target)
|
453
|
+
return;
|
454
|
+
var foreignObject = source.querySelector(".annotFO");
|
455
|
+
const targetBbox = target.getBoundingClientRect();
|
456
|
+
const targetPt = coordinates.transformToDOMMatrixCoordinates(targetBbox.x, targetBbox.y, cq.getInteractOverlay(this.containerId)); //.querySelector("#annotationCanvas"))
|
457
|
+
var line = source.querySelector("line");
|
458
|
+
const xSource = targetPt.x + parseFloat(line.getAttribute("x-diff"));
|
459
|
+
const ySource = targetPt.y + parseFloat(line.getAttribute("y-diff"));
|
460
|
+
line.setAttribute("x1", (targetPt.x).toString());
|
461
|
+
line.setAttribute("y1", (targetPt.y).toString());
|
462
|
+
line.setAttribute("x2", xSource.toString());
|
463
|
+
line.setAttribute("y2", ySource.toString());
|
464
|
+
foreignObject.setAttribute("x", xSource.toString());
|
465
|
+
foreignObject.setAttribute("y", ySource.toString());
|
466
|
+
source.querySelectorAll(".lineDragRect").forEach(ldr => {
|
467
|
+
if (ldr.classList.contains("x2")) {
|
468
|
+
ldr.setAttribute("x", xSource.toString());
|
469
|
+
ldr.setAttribute("y", ySource.toString());
|
470
|
+
}
|
471
|
+
else if (ldr.classList.contains("x1")) {
|
472
|
+
ldr.setAttribute("x", line.getAttribute("x1"));
|
473
|
+
ldr.setAttribute("y", line.getAttribute("y1"));
|
474
|
+
}
|
475
|
+
});
|
476
|
+
});
|
477
|
+
}
|
478
|
+
/////////// UTILITIES //////////////
|
479
|
+
/**
|
480
|
+
* Put annotationCanvas to Front for editing
|
481
|
+
* @returns
|
482
|
+
*/
|
483
|
+
// setToFront(): Annotations {
|
484
|
+
// if (this.annotationCanvas.classList.contains("front")) { return this }
|
485
|
+
// this.annotationCanvas.classList.remove("back")
|
486
|
+
// this.annotationCanvas.classList.add("front")
|
487
|
+
// cq.getInteractOverlay(this.containerId).insertBefore(this.getAnnotationCanvas(), cq.getInteractOverlay(this.containerId).lastChild.nextSibling)
|
488
|
+
// this.setListeners()
|
489
|
+
// this.container.classList.forEach(c => {
|
490
|
+
// if (c.toLowerCase().includes("mode")) { // ensure to only allow one mode when switching to annotMode
|
491
|
+
// this.container.classList.remove(c)
|
492
|
+
// }
|
493
|
+
// })
|
494
|
+
// this.container.classList.add("annotMode")
|
495
|
+
// return this
|
496
|
+
// }
|
497
|
+
// /**
|
498
|
+
// * Set annotationCanvas to Back, when in different mode
|
499
|
+
// * @returns
|
500
|
+
// */
|
501
|
+
// setToBack() {
|
502
|
+
// // if( this.annotationCanvas.classList.contains("back")){return}
|
503
|
+
// // this.annotationCanvas.classList.remove("front")
|
504
|
+
// // this.annotationCanvas.classList.add("back")
|
505
|
+
// // if((this.getAnnotationCanvas() !== (cq.getInteractOverlay(this.containerId).firstChild as SVGSVGElement) && this.getAnnotationCanvas() !== null)){
|
506
|
+
// // cq.getInteractOverlay(this.containerId).insertBefore(this.getAnnotationCanvas(), cq.getInteractOverlay(this.containerId).firstChild)
|
507
|
+
// // }
|
508
|
+
// // this.removeListeners()
|
509
|
+
// // this.container.classList.remove("annotMode")
|
510
|
+
// return this
|
511
|
+
// }
|
512
|
+
////////// GETTER/ SETTER////////////
|
513
|
+
setm2s(m2s) {
|
514
|
+
this.m2s = m2s;
|
515
|
+
return this;
|
516
|
+
}
|
517
|
+
setMusicProcessor(musicPlayer) {
|
518
|
+
this.musicPlayer = musicPlayer;
|
519
|
+
return this;
|
520
|
+
}
|
521
|
+
getAnnotationCanvas() {
|
522
|
+
return cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas") || this.annotationCanvas;
|
523
|
+
}
|
524
|
+
setAnnotationCanvas(annotationCanvas) {
|
525
|
+
this.updateAnnotationList(annotationCanvas);
|
526
|
+
return this;
|
527
|
+
}
|
528
|
+
getAnnotationChangeHandler() {
|
529
|
+
return this.annotationChangeHandler;
|
530
|
+
}
|
531
|
+
setUndoStacks(arr) {
|
532
|
+
if (arr[0] == undefined || this.undoStacks == undefined) {
|
533
|
+
this.undoStacks = arr;
|
534
|
+
var canvasClone = cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas").cloneNode(true);
|
535
|
+
var listClone = this.container.querySelector("#annotList").cloneNode(true);
|
536
|
+
this.undoStacks.push([canvasClone, listClone]);
|
537
|
+
//this.annotationCanvas = document.getElementById("annotationCanvas") as unknown as SVGSVGElement
|
538
|
+
}
|
539
|
+
return this;
|
540
|
+
}
|
541
|
+
setContainerId(id) {
|
542
|
+
this.containerId = id;
|
543
|
+
this.container = document.getElementById(id);
|
544
|
+
this.vrvSVG = cq.getVrvSVG(id);
|
545
|
+
this.interactionOverlay = cq.getInteractOverlay(this.containerId);
|
546
|
+
return this;
|
547
|
+
}
|
548
|
+
}
|
549
|
+
exports.default = Annotations;
|