vibe-editor 0.0.0

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 (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +51 -0
  3. package/package.json +56 -0
  4. package/src/fonts/bravura/FONTLOG.txt +243 -0
  5. package/src/fonts/bravura/OFL-FAQ.txt +369 -0
  6. package/src/fonts/bravura/OFL.txt +94 -0
  7. package/src/fonts/bravura/bravura-text.md +153 -0
  8. package/src/fonts/bravura/bravura_metadata.json +34718 -0
  9. package/src/fonts/bravura/eot/Bravura.eot +0 -0
  10. package/src/fonts/bravura/eot/BravuraText.eot +0 -0
  11. package/src/fonts/bravura/otf/Bravura.otf +0 -0
  12. package/src/fonts/bravura/otf/BravuraText.otf +0 -0
  13. package/src/fonts/bravura/svg/Bravura.svg +3517 -0
  14. package/src/fonts/bravura/svg/BravuraText.svg +18879 -0
  15. package/src/fonts/bravura/woff/Bravura.woff +0 -0
  16. package/src/fonts/bravura/woff/BravuraText.woff +0 -0
  17. package/src/fonts/colaborate/ColabBol-webfont.eot +0 -0
  18. package/src/fonts/colaborate/ColabBol-webfont.svg +976 -0
  19. package/src/fonts/colaborate/ColabBol-webfont.ttf +0 -0
  20. package/src/fonts/colaborate/ColabBol-webfont.woff +0 -0
  21. package/src/fonts/colaborate/ColabLig-webfont.eot +0 -0
  22. package/src/fonts/colaborate/ColabLig-webfont.svg +976 -0
  23. package/src/fonts/colaborate/ColabLig-webfont.ttf +0 -0
  24. package/src/fonts/colaborate/ColabLig-webfont.woff +0 -0
  25. package/src/fonts/colaborate/ColabMed-webfont.eot +0 -0
  26. package/src/fonts/colaborate/ColabMed-webfont.svg +976 -0
  27. package/src/fonts/colaborate/ColabMed-webfont.ttf +0 -0
  28. package/src/fonts/colaborate/ColabMed-webfont.woff +0 -0
  29. package/src/fonts/colaborate/ColabReg-webfont.eot +0 -0
  30. package/src/fonts/colaborate/ColabReg-webfont.svg +976 -0
  31. package/src/fonts/colaborate/ColabReg-webfont.ttf +0 -0
  32. package/src/fonts/colaborate/ColabReg-webfont.woff +0 -0
  33. package/src/fonts/colaborate/ColabThi-webfont.eot +0 -0
  34. package/src/fonts/colaborate/ColabThi-webfont.svg +970 -0
  35. package/src/fonts/colaborate/ColabThi-webfont.ttf +0 -0
  36. package/src/fonts/colaborate/ColabThi-webfont.woff +0 -0
  37. package/src/images/GUI/.DS_Store +0 -0
  38. package/src/images/GUI/backward-fast-solid.svg +1 -0
  39. package/src/images/GUI/bars-solid.svg +1 -0
  40. package/src/images/GUI/caret-left-solid.svg +1 -0
  41. package/src/images/GUI/caret-right-solid.svg +1 -0
  42. package/src/images/GUI/edit-solid.svg +1 -0
  43. package/src/images/GUI/pause-solid.svg +1 -0
  44. package/src/images/GUI/play-solid.svg +1 -0
  45. package/src/images/GUI/triplet.svg +21 -0
  46. package/src/images/GUI/zoomin.svg +1 -0
  47. package/src/images/GUI/zoomout.svg +1 -0
  48. package/src/images/bravura_notes/.DS_Store +0 -0
  49. package/src/images/bravura_notes/16th.svg +1 -0
  50. package/src/images/bravura_notes/32th.svg +1 -0
  51. package/src/images/bravura_notes/alterDDown.svg +1 -0
  52. package/src/images/bravura_notes/alterDUp.svg +1 -0
  53. package/src/images/bravura_notes/alterDown.svg +1 -0
  54. package/src/images/bravura_notes/alterNeutral.svg +1 -0
  55. package/src/images/bravura_notes/alterUp.svg +1 -0
  56. package/src/images/bravura_notes/beams.svg +1 -0
  57. package/src/images/bravura_notes/eigth.svg +1 -0
  58. package/src/images/bravura_notes/full.svg +1 -0
  59. package/src/images/bravura_notes/half.svg +1 -0
  60. package/src/images/bravura_notes/oneDot.svg +1 -0
  61. package/src/images/bravura_notes/pauseNote.svg +1 -0
  62. package/src/images/bravura_notes/quarter.svg +1 -0
  63. package/src/images/bravura_notes/tie.svg +1 -0
  64. package/src/images/bravura_notes/twoDot.svg +1 -0
  65. package/src/scripts/js/.DS_Store +0 -0
  66. package/src/scripts/js/Core.js +887 -0
  67. package/src/scripts/js/MusicPlayer.js +572 -0
  68. package/src/scripts/js/MusicProcessor.js +652 -0
  69. package/src/scripts/js/VerovioScoreEditor.js +183 -0
  70. package/src/scripts/js/assets/mei_template.js +161 -0
  71. package/src/scripts/js/constants.js +20 -0
  72. package/src/scripts/js/datastructures/MeasureMatrix.js +235 -0
  73. package/src/scripts/js/datastructures/ScoreGraph.js +432 -0
  74. package/src/scripts/js/datastructures/ScoreNode.js +78 -0
  75. package/src/scripts/js/entry.js +4 -0
  76. package/src/scripts/js/gui/Annotations.js +456 -0
  77. package/src/scripts/js/gui/Cursor.js +203 -0
  78. package/src/scripts/js/gui/CustomAnnotationDrawer.js +114 -0
  79. package/src/scripts/js/gui/CustomAnnotationShapeDrawer.js +114 -0
  80. package/src/scripts/js/gui/HarmonyLabel.js +104 -0
  81. package/src/scripts/js/gui/Label.js +2 -0
  82. package/src/scripts/js/gui/PhantomElement.js +132 -0
  83. package/src/scripts/js/gui/ScoreManipulator.js +156 -0
  84. package/src/scripts/js/gui/Tabbar.js +675 -0
  85. package/src/scripts/js/gui/TempoLabel.js +60 -0
  86. package/src/scripts/js/gui/Toolbar copy.js +614 -0
  87. package/src/scripts/js/gui/Toolbar.js +618 -0
  88. package/src/scripts/js/handlers/AnnotationChangeHandler.js +567 -0
  89. package/src/scripts/js/handlers/AnnotationDragHandler.js +113 -0
  90. package/src/scripts/js/handlers/AnnotationLineHandler.js +113 -0
  91. package/src/scripts/js/handlers/ArticulationHandler.js +20 -0
  92. package/src/scripts/js/handlers/ClickModeHandler.js +265 -0
  93. package/src/scripts/js/handlers/CustomAnnotationShapeDrawer.js +131 -0
  94. package/src/scripts/js/handlers/CustomToolbarHandler.js +297 -0
  95. package/src/scripts/js/handlers/DeleteHandler.js +102 -0
  96. package/src/scripts/js/handlers/GlobalKeyboardHandler.js +367 -0
  97. package/src/scripts/js/handlers/Handler.js +2 -0
  98. package/src/scripts/js/handlers/HarmonyHandler.js +282 -0
  99. package/src/scripts/js/handlers/InsertModeHandler copy.js +423 -0
  100. package/src/scripts/js/handlers/InsertModeHandler.js +380 -0
  101. package/src/scripts/js/handlers/InsertModeHandler_deprecated.js +424 -0
  102. package/src/scripts/js/handlers/KeyModeHandler copy.js +407 -0
  103. package/src/scripts/js/handlers/KeyModeHandler.js +456 -0
  104. package/src/scripts/js/handlers/KeyModeHandler_deprecated.js +411 -0
  105. package/src/scripts/js/handlers/LabelHandler.js +461 -0
  106. package/src/scripts/js/handlers/ModHandler.js +311 -0
  107. package/src/scripts/js/handlers/NoteDragHandler copy.js +148 -0
  108. package/src/scripts/js/handlers/NoteDragHandler.js +97 -0
  109. package/src/scripts/js/handlers/NoteDragHandler_deprecated.js +150 -0
  110. package/src/scripts/js/handlers/PhantomElementHandler.js +168 -0
  111. package/src/scripts/js/handlers/ScoreManipulatorHandler.js +135 -0
  112. package/src/scripts/js/handlers/SelectionHandler.js +218 -0
  113. package/src/scripts/js/handlers/SideBarHandler.js +499 -0
  114. package/src/scripts/js/handlers/TooltipHandler.js +132 -0
  115. package/src/scripts/js/handlers/WindowHandler.js +257 -0
  116. package/src/scripts/js/utils/DOMCreator.js +174 -0
  117. package/src/scripts/js/utils/MEIConverter.js +64 -0
  118. package/src/scripts/js/utils/MEIOperations.js +2112 -0
  119. package/src/scripts/js/utils/Mouse2MEI.js +735 -0
  120. package/src/scripts/js/utils/Mouse2SVG.js +737 -0
  121. package/src/scripts/js/utils/SVGEditor.js +352 -0
  122. package/src/scripts/js/utils/SVGFiller.js +245 -0
  123. package/src/scripts/js/utils/Types.js +2 -0
  124. package/src/scripts/js/utils/VerovioWrapper copy.js +156 -0
  125. package/src/scripts/js/utils/VerovioWrapper.js +165 -0
  126. package/src/scripts/js/utils/VerovioWrapperLocal.js +156 -0
  127. package/src/scripts/js/utils/convenienceQueries.js +37 -0
  128. package/src/scripts/js/utils/coordinates.js +54 -0
  129. package/src/scripts/js/utils/firefoxBBoxes.js +143 -0
  130. package/src/scripts/js/utils/mappings.js +332 -0
  131. package/src/scripts/js/utils/random.js +45 -0
  132. package/src/styles/VerovioScoreEditor.css +694 -0
@@ -0,0 +1,456 @@
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 CustomAnnotationShapeDrawer_1 = require("../handlers/CustomAnnotationShapeDrawer");
7
+ const cq = require("../utils/convenienceQueries");
8
+ const coordinates = require("../utils/coordinates");
9
+ class Annotations {
10
+ constructor(containerId) {
11
+ ////HANDLERS////
12
+ 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
+ }
20
+ }).bind(this);
21
+ this.createAnnotationHandler = (function createAnnotationHandler(e) {
22
+ var _a;
23
+ var t = e.target;
24
+ if ((_a = t.closest(".vseContainer")) === null || _a === void 0 ? void 0 : _a.classList.contains("clickmode"))
25
+ return; // creation should only be possible when annotation tab is on
26
+ var selectedAnnotations = this.interactionOverlay.querySelectorAll("#annotationCanvas .selected");
27
+ if (selectedAnnotations.length === 0) {
28
+ this.createAnnotation(e);
29
+ }
30
+ else {
31
+ selectedAnnotations.forEach(sa => {
32
+ sa.classList.remove("selected");
33
+ });
34
+ }
35
+ }).bind(this);
36
+ this.selectHandler = (function selectHandler(e) {
37
+ this.select(e);
38
+ }).bind(this);
39
+ this.updateUndoStacks = (function updateUndoStacks(e) {
40
+ if (!cq.hasActiveElement(this.containerId)) {
41
+ return;
42
+ }
43
+ var canvasClone = this.interactionOverlay.querySelector("#annotationCanvas").cloneNode(true);
44
+ var listClone = this.container.querySelector("#annotList").cloneNode(true);
45
+ this.annotList = this.container.querySelector("#annotList");
46
+ this.undoStacks.push([canvasClone, listClone]);
47
+ this.annotationCanvas = this.interactionOverlay.querySelector("#annotationCanvas");
48
+ }).bind(this);
49
+ this.updateRedoStacks = (function updateRedoStacks(e) {
50
+ if (!cq.hasActiveElement(this.containerId)) {
51
+ return;
52
+ }
53
+ this.redoStacks.push([this.annotationCanvas, this.annotList]);
54
+ this.annotationCanvas = this.undoStacks[0][0];
55
+ this.annotList = this.undoStacks[0][1];
56
+ }).bind(this);
57
+ /**
58
+ * Set Contenteditable True when doubleclicked
59
+ * @param e Doubleclick
60
+ */
61
+ this.activateEditHandler = (function activateEditHandler(e) {
62
+ var target = e.target;
63
+ target.setAttribute("contenteditable", "true");
64
+ target.focus();
65
+ this.annotationChangeHandler.removeListeners();
66
+ }).bind(this);
67
+ /**
68
+ * Delete all selected elements by pressing delete. Except: When any Elements are in Editable mode
69
+ * @param e Keyboardevent (code = Delete)
70
+ */
71
+ this.deleteHandler = (function deleteHandler(e) {
72
+ if (!cq.hasActiveElement(this.containerId)) {
73
+ return;
74
+ }
75
+ var isValidKey = ["Delete", "Backspace"].some(code => e.code === code);
76
+ //var isInAnnotMode = this.container.classList.contains("annotMode")
77
+ var hasEditableElement = this.interactionOverlay.querySelectorAll(".selected [contenteditable=true]").length > 0;
78
+ var listHasFocus = Array.from(this.container.querySelectorAll("#annotList > *")).some(le => le === document.activeElement);
79
+ //if(isValidKey && isInAnnotMode && !hasEditableElement && !listHasFocus){
80
+ if (isValidKey && !hasEditableElement && !listHasFocus) {
81
+ this.interactionOverlay.querySelectorAll("#annotationCanvas .selected").forEach(el => {
82
+ if (el.closest("g") !== null) {
83
+ el.closest("g").remove();
84
+ }
85
+ else {
86
+ el.remove();
87
+ }
88
+ });
89
+ this.interactionOverlay.dispatchEvent(new Event("annotChanged"));
90
+ this.interactionOverlay.dispatchEvent(new Event("annotationCanvasChanged"));
91
+ }
92
+ }).bind(this);
93
+ this.submitLabelHandler = (function submitHandler(e) {
94
+ var target = e.target;
95
+ if ((e.key === "Enter" || e.key === "Escape")) {
96
+ target.blur();
97
+ this.interactionOverlay.dispatchEvent(new Event("annotChanged"));
98
+ this.interactionOverlay.dispatchEvent(new Event("annotationCanvasChanged"));
99
+ }
100
+ }).bind(this);
101
+ this.setContainerId(containerId);
102
+ this.addCanvas();
103
+ this.annotations = new Array();
104
+ }
105
+ addCanvas() {
106
+ this.interactionOverlay = cq.getInteractOverlay(this.containerId);
107
+ this.rootBBox = this.interactionOverlay.getBoundingClientRect(); //this.vrvSVG.getBoundingClientRect()
108
+ var rootWidth = this.rootBBox.width.toString();
109
+ var rootHeigth = this.rootBBox.height.toString();
110
+ var vb = this.interactionOverlay.getAttribute("viewBox"); //this.vrvSVG.getAttribute("viewBox")
111
+ if (this.annotationCanvas == undefined) {
112
+ this.annotationCanvas = document.createElementNS(constants_1.constants._SVGNS_, "svg");
113
+ this.annotationCanvas.setAttribute("id", "annotationCanvas");
114
+ this.annotationCanvas.classList.add("canvas");
115
+ //this.annotationCanvas.classList.add("back")
116
+ //this.annotationCanvas.setAttribute("viewBox", ["0", "0", rootWidth, rootHeigth].join(" "))
117
+ }
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
+ }
125
+ }
126
+ setMenuClickHandler() {
127
+ //this.container.querySelector("#activateAnnot")?.addEventListener("click", this.clickHandler)
128
+ return this;
129
+ }
130
+ setListeners() {
131
+ 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");
135
+ 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"));
146
+ });
147
+ }
148
+ removeListeners() {
149
+ this.removeTextListeners();
150
+ }
151
+ setTextListeners() {
152
+ // this.customAnnotationDrawer = new CustomAnnotationShapeDrawer(this.containerId)
153
+ // this.customAnnotationDrawer.setUpdateCallback(this.resetTextListeners.bind(this))
154
+ this.annotationChangeHandler = this.annotationChangeHandler || new AnnotationChangeHandler_1.default(this.containerId);
155
+ this.annotationChangeHandler
156
+ .setUpdateCallback(this.resetTextListeners.bind(this))
157
+ .setm2s(this.m2s)
158
+ .setAnnotations(this.annotations)
159
+ .update()
160
+ .resetListeners();
161
+ this.interactionOverlay.addEventListener("dblclick", this.createAnnotationHandler);
162
+ var that = this;
163
+ this.interactionOverlay.querySelectorAll(".annotDiv").forEach(ad => {
164
+ ad.addEventListener("click", this.selectHandler);
165
+ ad.addEventListener("dblclick", this.activateEditHandler);
166
+ ad.addEventListener("focus", function () {
167
+ that.musicPlayer.removePlayListener();
168
+ });
169
+ ad.addEventListener("blur", function () {
170
+ that.musicPlayer.setPlayListener();
171
+ });
172
+ ad.addEventListener("keydown", this.submitLabelHandler);
173
+ });
174
+ this.interactionOverlay.querySelectorAll(".customAnnotShape").forEach(cas => {
175
+ cas.addEventListener("dblclick", this.selectHandler);
176
+ });
177
+ document.addEventListener("keydown", this.deleteHandler);
178
+ document.addEventListener("annotationCanvasChanged", this.updateUndoStacks, true);
179
+ //document.addEventListener("annotationCanvasChanged", this.updateRedoStacks)
180
+ return this;
181
+ }
182
+ removeTextListeners() {
183
+ var _a;
184
+ //this.container.querySelector("#activateAnnot").removeEventListener("click", this.clickHandler)
185
+ this.setMenuClickHandler();
186
+ this.interactionOverlay.removeEventListener("dblclick", this.createAnnotationHandler);
187
+ this.interactionOverlay.querySelectorAll(".annotDiv").forEach(ad => {
188
+ var _a;
189
+ (_a = ad.closest("svg")) === null || _a === void 0 ? void 0 : _a.classList.remove("selected");
190
+ ad.setAttribute("contenteditable", "false");
191
+ ad.removeEventListener("click", this.selectHandler);
192
+ ad.removeEventListener("dblclick", this.activateEditHandler);
193
+ });
194
+ this.interactionOverlay.querySelectorAll(".lineDragRect").forEach(ldr => ldr.remove());
195
+ this.interactionOverlay.querySelectorAll(".customAnnotShape").forEach(cas => {
196
+ cas.removeEventListener("dblclick", this.selectHandler);
197
+ });
198
+ document.removeEventListener("keydown", this.deleteHandler);
199
+ (_a = this.customAnnotationDrawer) === null || _a === void 0 ? void 0 : _a.removeListeners();
200
+ // interaction with all the annotations should always be possible
201
+ //this.annotationChangeHandler?.removeListeners()
202
+ return this;
203
+ }
204
+ resetTextListeners() {
205
+ this.removeTextListeners();
206
+ this.setTextListeners();
207
+ }
208
+ resetListeners() {
209
+ this.resetTextListeners();
210
+ }
211
+ setCustomShapeListener() {
212
+ var customShapes = null;
213
+ }
214
+ /**
215
+ * Select a specific annotation methon based on selected button
216
+ * @param e
217
+ */
218
+ createAnnotation(e) {
219
+ var _a;
220
+ var selectedButton = (_a = this.container.querySelector("#annotGroupKM > .selected")) === null || _a === void 0 ? void 0 : _a.id;
221
+ if (selectedButton === null)
222
+ return;
223
+ switch (selectedButton) {
224
+ case "linkedAnnotButton":
225
+ this.createTextAnnotation(e, selectedButton);
226
+ break;
227
+ case "staticTextButton":
228
+ this.createTextAnnotation(e, selectedButton);
229
+ break;
230
+ case "harmonyAnnotButton":
231
+ //this.createHarmonyAnnot(e)
232
+ console.log(selectedButton, "Please implement me o(;△;)o");
233
+ break;
234
+ default:
235
+ console.log("There is no implementation at all");
236
+ }
237
+ }
238
+ /**
239
+ * Create a new linked annotation Instance
240
+ * @param e
241
+ * @returns
242
+ */
243
+ createTextAnnotation(e, textButtonId) {
244
+ if (e.target.id !== this.interactionOverlay.id) {
245
+ return;
246
+ }
247
+ this.setToFront();
248
+ var selcount = 0;
249
+ this.annotationCanvas.querySelectorAll(":scope > .selected").forEach(el => {
250
+ el.classList.remove("selected");
251
+ selcount += 1;
252
+ });
253
+ if (selcount > 0) {
254
+ return;
255
+ }
256
+ var isLinked = false;
257
+ var isStaticText = false;
258
+ switch (textButtonId) {
259
+ case "linkedAnnotButton":
260
+ isLinked = true;
261
+ break;
262
+ case "staticTextButton":
263
+ isStaticText = true;
264
+ break;
265
+ }
266
+ var pt = coordinates.transformToDOMMatrixCoordinates(e.clientX, e.clientY, cq.getInteractOverlay(this.containerId));
267
+ var posx = pt.x; //matrixTransform(rootMatrix).x //e.pageX - this.rootBBox.x - window.pageXOffset
268
+ var posy = pt.y; //matrixTransform(rootMatrix).y //e.pageY - this.rootBBox.y - window.pageYOffset
269
+ var annotationTarget = this.m2s.findScoreTarget(posx, posy, false);
270
+ var textGroup = document.createElementNS(constants_1.constants._SVGNS_, "g");
271
+ textGroup.setAttribute("id", random_1.uuidv4());
272
+ textGroup.setAttribute("targetId", annotationTarget.id);
273
+ var text = document.createElementNS(constants_1.constants._SVGNS_, "svg");
274
+ if (isLinked)
275
+ text.classList.add("annotLinkedText");
276
+ else if (isStaticText)
277
+ text.classList.add("annotStaticText");
278
+ var textForeignObject = document.createElementNS(constants_1.constants._SVGNS_, "foreignObject");
279
+ textForeignObject.classList.add("annotFO");
280
+ var textDiv = document.createElement("div");
281
+ textDiv.setAttribute("contenteditable", "false");
282
+ textDiv.setAttribute("data-text", "New Annotation");
283
+ textDiv.textContent = "";
284
+ textDiv.classList.add("annotDiv");
285
+ text.append(textForeignObject);
286
+ this.container.appendChild(textDiv);
287
+ var rectPadding = 5;
288
+ // text.setAttribute("x", "0")
289
+ // 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());
294
+ if (isLinked) {
295
+ var line = document.createElementNS(constants_1.constants._SVGNS_, "line");
296
+ 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())
301
+ line.classList.add("annotLine");
302
+ textGroup.appendChild(line);
303
+ }
304
+ textForeignObject.append(textDiv);
305
+ textGroup.appendChild(text);
306
+ var newAnnot = {
307
+ sourceID: textGroup.id,
308
+ targetID: annotationTarget.id,
309
+ // relativePos: {
310
+ // x: textGroup.getBoundingClientRect().x - annotationTarget.getBoundingClientRect().x,
311
+ // y: textGroup.getBoundingClientRect().y - annotationTarget.getBoundingClientRect().y
312
+ // }
313
+ };
314
+ this.annotations.push(newAnnot);
315
+ this.annotationCanvas.appendChild(textGroup);
316
+ this.deactivateEdit();
317
+ this.resetTextListeners();
318
+ this.interactionOverlay.dispatchEvent(new Event("annotChanged"));
319
+ this.interactionOverlay.dispatchEvent(new Event("annotationCanvasChanged"));
320
+ }
321
+ /**
322
+ * Mark an annotation as selected.
323
+ * @param e
324
+ */
325
+ select(e) {
326
+ var _a, _b;
327
+ e.stopPropagation(); //do not trigger other events
328
+ var t = e.target;
329
+ if (t.classList.contains("annotDiv") && t.closest(".annotLinkedText") !== null) { // only apply for linked texts
330
+ //Add A selection Rect to line target
331
+ this.interactionOverlay.querySelectorAll(".lineDragRect").forEach(ldr => ldr.remove());
332
+ var line = t.closest("g").querySelector(".annotLine");
333
+ //Rect attacted to x2 target
334
+ var lineDragRect = document.createElementNS(constants_1.constants._SVGNS_, "rect");
335
+ t.closest("g").appendChild(lineDragRect);
336
+ lineDragRect.classList.add("lineDragRect");
337
+ lineDragRect.classList.add("x2");
338
+ lineDragRect.setAttribute("x", line.x2.baseVal.valueAsString);
339
+ lineDragRect.setAttribute("y", line.y2.baseVal.valueAsString);
340
+ //Rect attacted to x1 target
341
+ lineDragRect = document.createElementNS(constants_1.constants._SVGNS_, "rect");
342
+ t.closest("g").appendChild(lineDragRect);
343
+ lineDragRect.classList.add("lineDragRect");
344
+ lineDragRect.classList.add("x1");
345
+ lineDragRect.setAttribute("x", line.x1.baseVal.valueAsString);
346
+ lineDragRect.setAttribute("y", line.y1.baseVal.valueAsString);
347
+ //this.AnnotationLineHandler.initDragRects()
348
+ }
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");
350
+ this.annotationChangeHandler.resetListeners();
351
+ }
352
+ deactivateEdit() {
353
+ this.interactionOverlay.querySelectorAll(".annotDiv").forEach(ad => {
354
+ ad.setAttribute("contenteditable", "false");
355
+ ad.removeEventListener("dblclick", this.activateEditHandler);
356
+ });
357
+ this.annotationChangeHandler.removeListeners();
358
+ }
359
+ updateCanvas() {
360
+ var _a;
361
+ this.addCanvas();
362
+ (_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
+ }
369
+ }
370
+ updateAnnotationList(annotionCanvs) {
371
+ //TODO: Aktuallsieren des Datenmodells aus den Informarionen in der SVG: übersetzen der SVG in Annotation-Objekte
372
+ var that = this;
373
+ this.annotationCanvas = annotionCanvs;
374
+ this.annotationCanvas.querySelectorAll(":scope > g").forEach(g => {
375
+ var a = {
376
+ sourceID: g.id,
377
+ targetID: g.getAttribute("targetId")
378
+ };
379
+ that.annotations.push(a);
380
+ });
381
+ this.interactionOverlay.dispatchEvent(new Event("annotChanged"));
382
+ this.resetTextListeners();
383
+ }
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);
400
+ }
401
+ });
402
+ this.container.classList.add("annotMode");
403
+ return this;
404
+ }
405
+ /**
406
+ * Set annotationCanvas to Back, when in different mode
407
+ * @returns
408
+ */
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
+ }
420
+ ////////// GETTER/ SETTER////////////
421
+ setm2s(m2s) {
422
+ this.m2s = m2s;
423
+ return this;
424
+ }
425
+ setMusicProcessor(musicPlayer) {
426
+ this.musicPlayer = musicPlayer;
427
+ return this;
428
+ }
429
+ getAnnotationCanvas() {
430
+ return this.interactionOverlay.querySelector("#annotationCanvas") || this.annotationCanvas;
431
+ }
432
+ setAnnotationCanvas(annotationCanvas) {
433
+ this.updateAnnotationList(annotationCanvas);
434
+ }
435
+ getAnnotationChangeHandler() {
436
+ return this.annotationChangeHandler;
437
+ }
438
+ setUndoStacks(arr) {
439
+ if (arr[0] == undefined || this.undoStacks == undefined) {
440
+ this.undoStacks = arr;
441
+ var canvasClone = this.interactionOverlay.querySelector("#annotationCanvas").cloneNode(true);
442
+ var listClone = this.container.querySelector("#annotList").cloneNode(true);
443
+ this.undoStacks.push([canvasClone, listClone]);
444
+ //this.annotationCanvas = document.getElementById("annotationCanvas") as unknown as SVGSVGElement
445
+ }
446
+ return this;
447
+ }
448
+ setContainerId(id) {
449
+ this.containerId = id;
450
+ this.container = document.getElementById(id);
451
+ this.vrvSVG = cq.getVrvSVG(id);
452
+ this.interactionOverlay = cq.getInteractOverlay(id);
453
+ return this;
454
+ }
455
+ }
456
+ exports.default = Annotations;
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cq = require("../utils/convenienceQueries");
4
+ class Cursor {
5
+ constructor(containerId) {
6
+ this.maxOpacity = 0;
7
+ this.clickHandler = (function clickHandler(e) {
8
+ //e.stopPropagation();
9
+ var selectRect = this.container.querySelector("#keyModeSelectRect");
10
+ if (selectRect !== null) {
11
+ selectRect.remove();
12
+ this.vrvSVG.querySelectorAll(".marked").forEach(m => {
13
+ m.classList.remove("marked");
14
+ this.interactionOverlay.querySelector("#" + m.id).classList.remove("marked");
15
+ });
16
+ }
17
+ var pt = new DOMPoint(e.clientX, e.clientY);
18
+ var rootMatrix = this.vrvSVG.getScreenCTM().inverse();
19
+ var ptX = pt.matrixTransform(rootMatrix).x;
20
+ var ptY = pt.matrixTransform(rootMatrix).y;
21
+ var element = this.findScoreTarget(ptX, ptY);
22
+ this.definePosById(element === null || element === void 0 ? void 0 : element.id);
23
+ }).bind(this);
24
+ this.setContainerId(containerId);
25
+ if (this.interactionOverlay.querySelector("#cursor") !== null) {
26
+ this.interactionOverlay.querySelector("#cursor").remove();
27
+ }
28
+ // this.cursor = document.createElementNS("http://www.w3.org/2000/svg", "svg");
29
+ // var root = document.getElementById(c._vrvSVGID_)
30
+ // var rootBBox = root.getBoundingClientRect()
31
+ // var rootWidth = rootBBox.width.toString()
32
+ // var rootHeigth = rootBBox.height.toString()
33
+ // this.cursor.setAttribute("viewBox", ["0", "0", rootWidth, rootHeigth].join(" "))
34
+ //this.cursor = document.getElementById("manipulatorCanvas") as unknown as SVGSVGElement
35
+ this.cursorRect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
36
+ this.setClickListener();
37
+ }
38
+ flashStart() {
39
+ var cursorOn = true;
40
+ var speed = 500;
41
+ this.cursorRect.style.opacity = this.maxOpacity.toString();
42
+ this.interval = setInterval(() => {
43
+ if (cursorOn) {
44
+ this.cursorRect.style.opacity = "0";
45
+ cursorOn = false;
46
+ }
47
+ else {
48
+ this.cursorRect.style.opacity = this.maxOpacity.toString();
49
+ cursorOn = true;
50
+ }
51
+ }, speed);
52
+ }
53
+ flashStop() {
54
+ clearInterval(this.interval);
55
+ this.cursorRect.style.opacity = "0";
56
+ this.cursorRect.remove();
57
+ }
58
+ setClickListener() {
59
+ this.setContainerId(this.containerId);
60
+ this.interactionOverlay.addEventListener('click', this.clickHandler);
61
+ }
62
+ removeClickListener() {
63
+ this.setContainerId(this.containerId);
64
+ this.interactionOverlay.removeEventListener('click', this.clickHandler);
65
+ }
66
+ findScoreTarget(x, y) {
67
+ this.posx = x;
68
+ this.posy = y;
69
+ var nbb = this.m2s.findScoreTarget(this.posx, this.posy, true, { left: true, right: false }); // only consider left Elements of click position
70
+ if (nbb != undefined && nbb !== null) {
71
+ var element = this.vrvSVG.querySelector("#" + nbb.id);
72
+ }
73
+ if (element === null || element == undefined)
74
+ return;
75
+ if (element.classList.contains("note") && element.closest(".chord") !== null) {
76
+ element = element.closest(".chord");
77
+ }
78
+ this.nextElement = element;
79
+ //console.log(this.nextElement)
80
+ return element;
81
+ }
82
+ /**
83
+ * Define position of Cursor by ID of Elements. Cursor will then be placed right of the Element
84
+ * @param id
85
+ */
86
+ definePosById(id) {
87
+ var _a, _b, _c;
88
+ // debugging
89
+ this.setContainerId(this.containerId);
90
+ // this.vrvSVG.querySelectorAll("*[fill=green]").forEach(fg => {
91
+ // fg.removeAttribute("fill")
92
+ // })
93
+ //this.vrvSVG.querySelector("#" + id)?.setAttribute("fill", "green")
94
+ //
95
+ if (id == undefined)
96
+ return;
97
+ this.flashStop();
98
+ this.cursor = this.interactionOverlay.querySelector("#manipulatorCanvas");
99
+ this.cursor.insertBefore(this.cursorRect, this.cursor.firstChild);
100
+ var element = this.vrvSVG.querySelector("#" + id);
101
+ element = (element === null || element === void 0 ? void 0 : element.classList.contains("layer")) ? element.closest(".staff") : element; //special rule for layer (== beginning of measure)
102
+ var elementBBox;
103
+ var currLayerY;
104
+ var currLayer;
105
+ var distToElement;
106
+ var elementHeight;
107
+ if (navigator.userAgent.toLowerCase().indexOf("firefox") > -1) {
108
+ distToElement = ["note", "rest", "chord", "keySig", "clef", "meterSig"].some(e => {
109
+ return element === null || element === void 0 ? void 0 : element.classList.contains(e);
110
+ }) ? 40 : 0;
111
+ }
112
+ else {
113
+ distToElement = ["note", "rest", "chord", "keySig", "clef", "meterSig"].some(e => {
114
+ return element === null || element === void 0 ? void 0 : element.classList.contains(e);
115
+ }) ? element.getBoundingClientRect().width + 10 : 0;
116
+ }
117
+ var ptLayer;
118
+ var parentMatrix = this.cursor.getScreenCTM().inverse();
119
+ //determine reference boundingbox for further computation of dimensions
120
+ if (element !== null) {
121
+ elementBBox = element.getBoundingClientRect();
122
+ currLayer = element.classList.contains("staff") ? element.querySelector(".layer") : element.closest(".layer"); //element : element.closest(".layer")
123
+ currLayerY = (currLayer === null || currLayer === void 0 ? void 0 : currLayer.getBoundingClientRect().y) || 0; //element.classList.contains("staff") ? element.getBoundingClientRect().y : element.closest(".layer")?.getBoundingClientRect().y || 0
124
+ this.nextElement = element;
125
+ this.isBol = false;
126
+ }
127
+ else {
128
+ currLayer = this.vrvSVG.querySelector(".layer[n=\"" + (parseInt(id[id.length - 1]) + 1).toString() + "\"]");
129
+ currLayerY = currLayer.getBoundingClientRect().y;
130
+ elementBBox = this.nextElement.getBoundingClientRect();
131
+ element = this.nextElement;
132
+ distToElement = -distToElement;
133
+ this.isBol = true;
134
+ }
135
+ ptLayer = new DOMPoint(0, currLayerY);
136
+ currLayerY = ptLayer.matrixTransform(parentMatrix).y;
137
+ if (navigator.userAgent.toLowerCase().indexOf("firefox") > -1) {
138
+ elementHeight = ((_a = element.querySelector(".stem")) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().height) || ((_b = element.querySelector("barLine")) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect().height) || 11;
139
+ }
140
+ else {
141
+ elementHeight = elementBBox.height;
142
+ }
143
+ //scaled height and width of elemnetBBox
144
+ var ptLT = new DOMPoint(elementBBox.left, elementBBox.top);
145
+ ptLT = ptLT.matrixTransform(parentMatrix);
146
+ var ptRB = new DOMPoint(elementBBox.right, elementBBox.bottom);
147
+ ptRB = ptRB.matrixTransform(parentMatrix);
148
+ var ptWidth = ptRB.x - ptLT.x;
149
+ var ptHeight = ptRB.y - ptLT.y;
150
+ var drawChordRect;
151
+ if ((_c = this.container.querySelector("#chordButton")) === null || _c === void 0 ? void 0 : _c.classList.contains("selected")) {
152
+ drawChordRect = true;
153
+ }
154
+ else {
155
+ drawChordRect = false;
156
+ }
157
+ // set width and height
158
+ this.cursorRect.setAttribute("id", "cursor");
159
+ var ptCursor = new DOMPoint(elementBBox.x, elementBBox.y);
160
+ ptCursor = ptCursor.matrixTransform(parentMatrix);
161
+ if (!drawChordRect || navigator.userAgent.toLowerCase().indexOf("firefox") > -1) { // Firefox only gets the normal text cursor for chord mode :(
162
+ this.posx = ptCursor.x + distToElement;
163
+ this.posy = ptCursor.y;
164
+ this.height = ptHeight + 4;
165
+ this.cursorRect.setAttribute("width", "2px");
166
+ this.cursorRect.setAttribute("height", this.height.toString());
167
+ this.maxOpacity = 1;
168
+ }
169
+ else { // for chord mode
170
+ var padding = 4;
171
+ this.posx = ptCursor.x;
172
+ this.posy = currLayerY;
173
+ this.cursorRect.setAttribute("width", (ptWidth + padding).toString());
174
+ this.cursorRect.setAttribute("height", (ptHeight + padding).toString());
175
+ this.maxOpacity = 0.5;
176
+ }
177
+ this.cursorRect.setAttribute("x", this.posx.toString());
178
+ this.cursorRect.setAttribute("y", this.posy.toString());
179
+ this.cursorRect.setAttribute("refId", element.classList.contains("staff") ? currLayer.id : element.id);
180
+ this.flashStart();
181
+ }
182
+ isBOL() {
183
+ return this.isBol;
184
+ }
185
+ ///////// GETTER/ SETTER ////////////
186
+ getNextElement() {
187
+ return this.nextElement;
188
+ }
189
+ getPos() {
190
+ return { x: this.posx, y: this.posy };
191
+ }
192
+ setm2s(m2s) {
193
+ this.m2s = m2s;
194
+ }
195
+ setContainerId(id) {
196
+ this.containerId = id;
197
+ this.container = document.getElementById(id);
198
+ this.interactionOverlay = cq.getInteractOverlay(id);
199
+ this.vrvSVG = cq.getVrvSVG(id);
200
+ return this;
201
+ }
202
+ }
203
+ exports.default = Cursor;