vibe-editor 0.0.4 → 0.0.6

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 (78) hide show
  1. package/package.json +66 -61
  2. package/src/scripts/js/Core.js +28 -9
  3. package/src/scripts/js/entry.js +6 -5
  4. package/src/scripts/js/gui/Annotations.js +27 -12
  5. package/src/scripts/js/gui/ScoreManipulator.js +6 -4
  6. package/src/scripts/js/gui/Tabbar.js +13 -4
  7. package/src/scripts/js/handlers/AnnotationChangeHandler.js +13 -1
  8. package/src/scripts/js/handlers/InsertModeHandler.js +3 -3
  9. package/src/scripts/js/handlers/PhantomElementHandler.js +3 -10
  10. package/src/scripts/js/handlers/WindowHandler.js +7 -7
  11. package/src/scripts/js/scripts/Core.js +932 -0
  12. package/src/scripts/js/scripts/MusicProcessor.js +810 -0
  13. package/src/scripts/js/scripts/VIBE.js +219 -0
  14. package/src/scripts/js/scripts/datastructures/MeasureMatrix.js +156 -0
  15. package/src/scripts/js/scripts/gui/Annotations.js +549 -0
  16. package/src/scripts/js/scripts/gui/Cursor.js +203 -0
  17. package/src/scripts/js/scripts/gui/PhantomElement.js +132 -0
  18. package/src/scripts/js/scripts/gui/ScoreManipulator.js +188 -0
  19. package/src/scripts/js/scripts/gui/Tabbar.js +705 -0
  20. package/src/scripts/js/{gui/Toolbar copy.js → scripts/gui/Toolbar.js} +15 -11
  21. package/src/scripts/js/scripts/handlers/AnnotationChangeHandler.js +650 -0
  22. package/src/scripts/js/scripts/handlers/ClickModeHandler.js +535 -0
  23. package/src/scripts/js/{gui → scripts/handlers}/CustomAnnotationShapeDrawer.js +34 -17
  24. package/src/scripts/js/{handlers/ModHandler.js → scripts/handlers/CustomToolbarHandler.js} +54 -66
  25. package/src/scripts/js/scripts/handlers/GlobalKeyboardHandler.js +372 -0
  26. package/src/scripts/js/scripts/handlers/Handler.js +2 -0
  27. package/src/scripts/js/{handlers/InsertModeHandler_deprecated.js → scripts/handlers/InsertModeHandler.js} +117 -164
  28. package/src/scripts/js/scripts/handlers/KeyModeHandler.js +405 -0
  29. package/src/scripts/js/scripts/handlers/LabelHandler.js +463 -0
  30. package/src/scripts/js/scripts/handlers/NoteDragHandler.js +97 -0
  31. package/src/scripts/js/scripts/handlers/PhantomElementHandler.js +161 -0
  32. package/src/scripts/js/scripts/handlers/ScoreManipulatorHandler.js +233 -0
  33. package/src/scripts/js/scripts/handlers/SidebarHandler.js +506 -0
  34. package/src/scripts/js/scripts/handlers/TooltipHandler.js +132 -0
  35. package/src/scripts/js/scripts/handlers/WindowHandler.js +278 -0
  36. package/src/scripts/js/scripts/utils/MEIOperations.js +2121 -0
  37. package/src/scripts/js/{utils/Mouse2MEI.js → scripts/utils/Mouse2SVG.js} +225 -57
  38. package/src/scripts/js/scripts/utils/SVGEditor.js +453 -0
  39. package/src/scripts/js/scripts/utils/Types.js +2 -0
  40. package/src/scripts/js/{utils/VerovioWrapper copy.js → scripts/utils/VerovioWrapper.js} +32 -18
  41. package/src/scripts/js/scripts/utils/coordinates.js +78 -0
  42. package/src/scripts/js/utils/Mouse2SVG.js +11 -4
  43. package/src/scripts/js/utils/VerovioWrapper.js +4 -4
  44. package/src/scripts/js/utils/coordinates.js +26 -2
  45. package/src/styles/vibe.css +32 -6
  46. package/src/scripts/js/.DS_Store +0 -0
  47. package/src/scripts/js/MusicPlayer.js +0 -572
  48. package/src/scripts/js/datastructures/ScoreGraph copy.js +0 -432
  49. package/src/scripts/js/gui/CustomAnnotationDrawer.js +0 -114
  50. package/src/scripts/js/handlers/AnnotationDragHandler.js +0 -113
  51. package/src/scripts/js/handlers/AnnotationLineHandler.js +0 -113
  52. package/src/scripts/js/handlers/ArticulationHandler.js +0 -20
  53. package/src/scripts/js/handlers/HarmonyHandler.js +0 -282
  54. package/src/scripts/js/handlers/InsertModeHandler copy.js +0 -423
  55. package/src/scripts/js/handlers/KeyModeHandler copy.js +0 -407
  56. package/src/scripts/js/handlers/KeyModeHandler_deprecated.js +0 -411
  57. package/src/scripts/js/handlers/NoteDragHandler copy.js +0 -148
  58. package/src/scripts/js/handlers/NoteDragHandler_deprecated.js +0 -150
  59. package/src/scripts/js/handlers/SelectionHandler.js +0 -262
  60. package/src/scripts/js/utils/RectWrapper.js +0 -10
  61. package/src/scripts/js/utils/SVGFiller.js +0 -245
  62. package/src/scripts/js/utils/VerovioWrapperLocal.js +0 -156
  63. package/src/scripts/js/utils/firefoxBBoxes.js +0 -143
  64. /package/src/scripts/js/{assets → scripts/assets}/mei_template.js +0 -0
  65. /package/src/scripts/js/{constants.js → scripts/constants.js} +0 -0
  66. /package/src/scripts/js/{datastructures → scripts/datastructures}/ScoreGraph.js +0 -0
  67. /package/src/scripts/js/{datastructures → scripts/datastructures}/ScoreGraph_deprecated.js +0 -0
  68. /package/src/scripts/js/{datastructures → scripts/datastructures}/ScoreNode.js +0 -0
  69. /package/src/scripts/js/{gui → scripts/gui}/HarmonyLabel.js +0 -0
  70. /package/src/scripts/js/{gui → scripts/gui}/Label.js +0 -0
  71. /package/src/scripts/js/{gui → scripts/gui}/TempoLabel.js +0 -0
  72. /package/src/scripts/js/{handlers → scripts/handlers}/DeleteHandler.js +0 -0
  73. /package/src/scripts/js/{utils → scripts/utils}/DOMCreator.js +0 -0
  74. /package/src/scripts/js/{utils → scripts/utils}/MEIConverter.js +0 -0
  75. /package/src/scripts/js/{utils → scripts/utils}/ReactWrapper.js +0 -0
  76. /package/src/scripts/js/{utils → scripts/utils}/convenienceQueries.js +0 -0
  77. /package/src/scripts/js/{utils → scripts/utils}/mappings.js +0 -0
  78. /package/src/scripts/js/{utils → scripts/utils}/random.js +0 -0
@@ -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;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cq = require("../utils/convenienceQueries");
4
+ const coordinates = require("../utils/coordinates");
5
+ const mappings_1 = require("../utils/mappings");
6
+ const svgNS = "http://www.w3.org/2000/svg";
7
+ class PhantomElement {
8
+ constructor(elementName, containerId, options = null, canvas = undefined) {
9
+ elementName = elementName.toLowerCase();
10
+ this.setContainerId(containerId);
11
+ this.phantomCanvas = canvas || this.interactionOverlay.querySelector("#phantomCanvas");
12
+ switch (elementName) {
13
+ case "note":
14
+ this.makeNewPhantomNote();
15
+ break;
16
+ case "line":
17
+ this.makeNewPhantomLine(options);
18
+ break;
19
+ case "timemarkers":
20
+ //this.makeNewTimeMarkers(options)
21
+ break;
22
+ default:
23
+ console.log("Element", elementName, "is not supported");
24
+ break;
25
+ }
26
+ }
27
+ makeNewPhantomNote() {
28
+ this.removePhantomNote();
29
+ if (this.container.classList.contains("clickmode") && this.interactionOverlay.querySelector("#phantomNote") === null) {
30
+ var circle = document.createElementNS(svgNS, "circle");
31
+ this.phantomCanvas.insertBefore(circle, this.phantomCanvas.firstChild);
32
+ circle.setAttribute("id", "phantomNote");
33
+ var r = 5;
34
+ circle.setAttribute("r", r.toString());
35
+ circle.setAttribute("fill", "black");
36
+ circle.setAttribute("opacity", "0.5");
37
+ circle.setAttribute("visibility", "hidden");
38
+ this.noteElement = circle;
39
+ }
40
+ }
41
+ makeNewPhantomLine(options) {
42
+ if (options.lineX == undefined || options.lineY == undefined) {
43
+ return;
44
+ }
45
+ if (this.container.classList.contains("clickmode")) {
46
+ new Promise((resolve) => {
47
+ var _a;
48
+ var line = document.createElementNS(svgNS, "line");
49
+ this.phantomCanvas.insertBefore(line, this.phantomCanvas.firstChild);
50
+ var width = 10;
51
+ var x1, x2, y1, y2;
52
+ y1 = y2 = options.lineY;
53
+ x1 = options.lineX - width;
54
+ x2 = options.lineX + width;
55
+ line.setAttribute("x1", x1.toString());
56
+ line.setAttribute("x2", x2.toString());
57
+ line.setAttribute("y1", y1.toString());
58
+ line.setAttribute("y2", y2.toString());
59
+ line.classList.add("phantomLine");
60
+ line.setAttribute("visibility", (_a = this.phantomCanvas.querySelector("#phantomNote")) === null || _a === void 0 ? void 0 : _a.getAttribute("visibility"));
61
+ resolve(true);
62
+ });
63
+ }
64
+ }
65
+ /**
66
+ * Draw markers in bar to approximate distances between notes.
67
+ * Division is always based on the selected duration in the toolbar and the time unit.
68
+ * @param options.lastStaffEnteredId Id of the staff where the markes will be drawn
69
+ * @returns
70
+ */
71
+ makeNewTimeMarkers(options) {
72
+ var _a;
73
+ if (options.lastStaffEnteredId == undefined)
74
+ return;
75
+ var staff = cq.getVrvSVG(this.containerId).querySelector("#" + options.lastStaffEnteredId);
76
+ var staffHeight = Array.from(staff.querySelectorAll(".staffLine")).reverse()[0].getBoundingClientRect().bottom - staff.querySelector(".staffLine").getBoundingClientRect().top;
77
+ var staffBegin = staff.closest(".measure").getAttribute("n") === "1" ?
78
+ staff.querySelector(".meterSig").getBoundingClientRect().right :
79
+ staff.getBoundingClientRect().left;
80
+ var staffWidth = staff.getBoundingClientRect().right - staffBegin;
81
+ var measureN = staff.closest(".measure").getAttribute("n");
82
+ var staffN = staff.getAttribute("n");
83
+ var ratio = parseInt(options.measureMatrix.get(staffN, measureN).meterSig.count) / parseInt(options.measureMatrix.get(staffN, measureN).meterSig.unit);
84
+ var numLines = mappings_1.NoteButtonIdToNum.get((_a = cq.getContainer(this.containerId).querySelector("#noteGroup > .selected")) === null || _a === void 0 ? void 0 : _a.id) * ratio;
85
+ var cutUnit = staffWidth / numLines;
86
+ var linePosX = new Array();
87
+ var linePosY = staff.querySelector(".staffLine").getBoundingClientRect().top;
88
+ for (var i = 0; i < numLines; i++) {
89
+ linePosX.push(staffBegin + i * cutUnit);
90
+ }
91
+ linePosX.forEach(l => {
92
+ var _a;
93
+ var line = document.createElementNS(svgNS, "line");
94
+ this.phantomCanvas.insertBefore(line, this.phantomCanvas.firstChild);
95
+ var x1, x2, y1, y2;
96
+ y1 = linePosY;
97
+ y2 = linePosY - staffHeight / 5;
98
+ x1 = x2 = l; //+ (staffWidth / numLines)
99
+ var coords1 = coordinates.transformToDOMMatrixCoordinates(x1, y1, this.phantomCanvas);
100
+ var coords2 = coordinates.transformToDOMMatrixCoordinates(x2, y2, this.phantomCanvas);
101
+ line.setAttribute("x1", coords1.x.toString());
102
+ line.setAttribute("x2", coords2.x.toString());
103
+ line.setAttribute("y1", coords1.y.toString());
104
+ line.setAttribute("y2", coords2.y.toString());
105
+ line.classList.add("phantomMarker");
106
+ line.setAttribute("visibility", (_a = this.phantomCanvas.querySelector("#phantomNote")) === null || _a === void 0 ? void 0 : _a.getAttribute("visibility"));
107
+ });
108
+ }
109
+ removePhantomNote() {
110
+ if (this.container.querySelector("#phantomNote") !== null) {
111
+ this.container.querySelector("#phantomNote").remove();
112
+ }
113
+ }
114
+ setNoteRadius(r) {
115
+ this.noteR = r;
116
+ }
117
+ setPhantomCanvas(canvas) {
118
+ this.phantomCanvas = canvas;
119
+ return this;
120
+ }
121
+ setContainerId(id) {
122
+ this.containerId = id;
123
+ this.interactionOverlay = cq.getInteractOverlay(id);
124
+ this.vrvSVG = cq.getVrvSVG(id);
125
+ this.container = document.getElementById(id);
126
+ return this;
127
+ }
128
+ getNoteElement() {
129
+ return this.noteElement;
130
+ }
131
+ }
132
+ exports.default = PhantomElement;
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../constants");
4
+ const cq = require("../utils/convenienceQueries");
5
+ const coordinates_1 = require("../utils/coordinates");
6
+ const manipFlag = "manipulator";
7
+ /**
8
+ * Class for all manipulators (Buttons, Lists, etc) directly visible in the score
9
+ */
10
+ class ScoreManipulator {
11
+ constructor() {
12
+ }
13
+ /**
14
+ *
15
+ * @param id Id for Elment
16
+ * @param classNames
17
+ * @param sign Plus or Minus sign
18
+ * @param posX
19
+ * @param posY
20
+ * @param size
21
+ * @param targetParent Parent to attach element to
22
+ * @param refId
23
+ * @returns
24
+ */
25
+ drawButton(id = null, classNames = null, sign, posX, posY, size, targetParent, refId) {
26
+ var _a;
27
+ var newSVG = document.createElementNS(constants_1.constants._SVGNS_, "svg");
28
+ if (id !== null)
29
+ newSVG.setAttribute("id", id);
30
+ if (Array.from(this.interactionOverlay.querySelectorAll("maniplationCanvas *")).some(el => el.id === id)) {
31
+ return;
32
+ }
33
+ newSVG.classList.add(manipFlag);
34
+ newSVG.setAttribute("x", posX.toString());
35
+ newSVG.setAttribute("y", posY.toString());
36
+ newSVG.setAttribute("height", size.toString());
37
+ newSVG.setAttribute("width", size.toString());
38
+ if (classNames !== null) {
39
+ var cn = classNames.split(" ");
40
+ cn.forEach(c => {
41
+ newSVG.classList.add(c);
42
+ });
43
+ }
44
+ var circle = document.createElementNS(constants_1.constants._SVGNS_, "circle");
45
+ circle.setAttribute("id", "manipulationButton");
46
+ circle.setAttribute("cx", "50%");
47
+ circle.setAttribute("cy", "50%");
48
+ circle.setAttribute("r", "40%");
49
+ newSVG.append(circle);
50
+ if (sign === "-" || sign === "+") {
51
+ var horizonal = document.createElementNS(constants_1.constants._SVGNS_, "line");
52
+ horizonal.classList.add("signElement");
53
+ horizonal.setAttribute("x1", "20%");
54
+ horizonal.setAttribute("y1", "50%");
55
+ horizonal.setAttribute("x2", "80%");
56
+ horizonal.setAttribute("y2", "50%");
57
+ newSVG.append(horizonal);
58
+ }
59
+ if (sign === "+") {
60
+ var vertical = horizonal.cloneNode(true);
61
+ vertical.setAttribute("transform", "rotate(90)");
62
+ vertical.setAttribute("transform-origin", "center");
63
+ newSVG.append(vertical);
64
+ }
65
+ newSVG.setAttribute("refId", refId);
66
+ (_a = this.interactionOverlay.querySelector("#manipulatorCanvas")) === null || _a === void 0 ? void 0 : _a.appendChild(newSVG);
67
+ }
68
+ drawMeasureManipulators() {
69
+ this.lastBline = Array.from(this.vrvSVG.querySelectorAll(".barLine")).reverse()[0].querySelector("path");
70
+ var lastBlineRect = coordinates_1.getDOMMatrixCoordinates(this.lastBline, this.vrvSVG);
71
+ var blineTopAdder = lastBlineRect.top;
72
+ var blineTopRemover = lastBlineRect.top + lastBlineRect.height / 2;
73
+ var blineRight = lastBlineRect.right;
74
+ var containerSize = lastBlineRect.height * 0.4;
75
+ this.drawButton("measureAdder", null, "+", blineRight, blineTopAdder, containerSize, this.lastBline.closest("svg").parentElement, "Add Measure");
76
+ this.drawButton("measureRemover", null, "-", blineRight, blineTopRemover, containerSize, this.lastBline.closest("svg").parentElement, "Remove Measure");
77
+ }
78
+ drawStaffManipulators() {
79
+ this.vrvSVG.querySelector(".measure").querySelectorAll(".staff").forEach(s => {
80
+ //var rootBBox = this.vrvSVG.getBoundingClientRect()
81
+ var refStaffCoords = this.getStaffManipulatorCoords(s);
82
+ var refStaffX = refStaffCoords.x;
83
+ var refStaffYTop = refStaffCoords.yTop;
84
+ var refStaffYBottom = refStaffCoords.yBottom;
85
+ var refStaffWidth = refStaffCoords.width;
86
+ var refStaffHeight = refStaffCoords.height;
87
+ var posX = refStaffX - refStaffWidth * 0.5; //- rootBBox.x
88
+ var topY = refStaffYTop - refStaffHeight * 0.2; //- rootBBox.y
89
+ var containerSize = refStaffHeight / 4;
90
+ this.drawButton(null, "addStaff above", "+", posX, topY, containerSize, this.vrvSVG, s.id);
91
+ if (parseInt(s.getAttribute("n")) > 1) {
92
+ posX = refStaffX; //- rootBBox.x
93
+ this.drawButton(null, "removeStaff above", "-", posX, topY, containerSize, this.vrvSVG, s.id);
94
+ }
95
+ posX = refStaffX - refStaffWidth * 0.5; //- rootBBox.x
96
+ var bottomY = refStaffYBottom; //- rootBBox.y
97
+ var containerSize = (refStaffHeight / 4);
98
+ this.drawButton(null, "addStaff below", "+", posX, bottomY, containerSize, this.vrvSVG, s.id);
99
+ var staffCount = s.parentElement.querySelectorAll(".staff");
100
+ if (parseInt(s.getAttribute("n")) !== staffCount.length) {
101
+ posX = refStaffX; //- rootBBox.x
102
+ this.drawButton(null, "removeStaff below", "-", posX, bottomY, containerSize, this.vrvSVG, s.id);
103
+ }
104
+ });
105
+ }
106
+ /**
107
+ * Draw 4 Buttons at the beginning of each new Line
108
+ */
109
+ drawVoiceSelectors() {
110
+ //var rootBBox = this.vrvSVG.getBoundingClientRect()
111
+ this.vrvSVG.querySelectorAll(".page").forEach(p => {
112
+ p.querySelector(".measure").querySelectorAll(".staff").forEach(staff => {
113
+ var _a;
114
+ var bbox = coordinates_1.getDOMMatrixCoordinates(staff.querySelector(".staffLine"), this.vrvSVG); //staff.querySelector(".staffLine").getBoundingClientRect()
115
+ var x = bbox.left; //- rootBBox.x
116
+ var yTop = bbox.top; //- rootBBox.y
117
+ var yBottom = coordinates_1.getDOMMatrixCoordinates(Array.from(staff.querySelectorAll(".staffLine")).reverse()[0], this.vrvSVG).bottom; //Array.from(staff.querySelectorAll(".staffLine")).reverse()[0].getBoundingClientRect().bottom - rootBBox.y
118
+ var staffHeight = (yBottom - yTop);
119
+ yTop -= staffHeight * 0.20; // center the boxes
120
+ var btnHeight = (staffHeight / 4) * 1.5;
121
+ for (let i = 0; i < 4; i++) {
122
+ var btn = document.createElementNS("http://www.w3.org/2000/svg", "svg");
123
+ var btnRect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
124
+ var btnFO = document.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
125
+ var btnText = document.createElement("div");
126
+ btnFO.append(btnText);
127
+ btnText.textContent = (i + 1).toString();
128
+ btn.setAttribute("x", "3px");
129
+ btn.setAttribute("y", (yTop + btnHeight * i).toString());
130
+ btn.setAttribute("height", btnHeight.toString());
131
+ btn.setAttribute("width", btnHeight.toString());
132
+ btn.classList.add("voiceBtn");
133
+ btn.classList.add("manipulator");
134
+ btn.setAttribute("staffN", staff.getAttribute("n"));
135
+ btn.setAttribute("btnN", (i + 1).toString());
136
+ btn.setAttribute("id", "voiceSelect-" + staff.getAttribute("n") + "-" + (i + 1).toString());
137
+ //btnText is relative to btn
138
+ var fontSize = btnHeight;
139
+ btnText.style.fontSize = fontSize.toString() + "px";
140
+ btn.append(btnRect);
141
+ btn.append(btnFO);
142
+ (_a = this.interactionOverlay.querySelector("#manipulatorCanvas")) === null || _a === void 0 ? void 0 : _a.append(btn);
143
+ }
144
+ });
145
+ });
146
+ }
147
+ /**
148
+ * Get Coords for staf manipulators, since some browsers (Firefox) have problems with bounding boxes
149
+ * @param referenceStaff Staff beside which the staff manipulator should be placed
150
+ * @returns
151
+ */
152
+ getStaffManipulatorCoords(referenceStaff) {
153
+ var x;
154
+ var yTop;
155
+ var yBottom;
156
+ var bbox;
157
+ var width;
158
+ var height;
159
+ if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1) {
160
+ bbox = coordinates_1.getDOMMatrixCoordinates(referenceStaff, this.vrvSVG); //referenceStaff.querySelector(".staffLine").getBoundingClientRect()
161
+ x = bbox.left;
162
+ yTop = bbox.top;
163
+ yBottom = coordinates_1.getDOMMatrixCoordinates(Array.from(referenceStaff.querySelectorAll(".staffLine")).reverse()[0], this.vrvSVG).bottom; //Array.from(referenceStaff.querySelectorAll(".staffLine")).reverse()[0].getBoundingClientRect().bottom
164
+ }
165
+ else {
166
+ bbox = bbox = coordinates_1.getDOMMatrixCoordinates(referenceStaff.querySelector(".clef"), this.vrvSVG); //referenceStaff.querySelector(".clef").getBoundingClientRect()
167
+ x = bbox.left;
168
+ yTop = bbox.top;
169
+ yBottom = bbox.bottom;
170
+ }
171
+ const clefCoords = coordinates_1.getDOMMatrixCoordinates(referenceStaff.querySelector(".clef"), this.vrvSVG);
172
+ //height = referenceStaff.querySelector(".clef").getBoundingClientRect().height
173
+ //width = referenceStaff.querySelector(".clef").getBoundingClientRect().width
174
+ return { x: x, yTop: yTop, yBottom: yBottom, width: clefCoords.width, height: clefCoords.height };
175
+ }
176
+ setMEI(mei) {
177
+ this.mei = mei;
178
+ return this;
179
+ }
180
+ setContainerId(id) {
181
+ this.containerId = id;
182
+ this.container = document.getElementById(id);
183
+ this.interactionOverlay = cq.getInteractOverlay(this.containerId);
184
+ this.vrvSVG = cq.getVrvSVG(this.containerId);
185
+ return this;
186
+ }
187
+ }
188
+ exports.default = ScoreManipulator;