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,453 @@
1
+ "use strict";
2
+ /**
3
+ * Class to edit the rendered svg.
4
+ * E.g. Cache and Load Information from previous version of the SVG; Copy information form MEI to SVG (and vice versa); Edit DOM structure of Elements
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const cq = require("../utils/convenienceQueries");
8
+ const meiOperation = require("./MEIOperations");
9
+ const coords = require("../utils/coordinates");
10
+ const random_1 = require("./random");
11
+ const constants_1 = require("../constants");
12
+ class SVGEditor {
13
+ constructor() {
14
+ this.allowedMeiClasses = ["marked"];
15
+ this.x = 0;
16
+ this.y = 0;
17
+ }
18
+ /**
19
+ * Fill SVG in Dom with relevant mei Information
20
+ * @param mei Document from MEI
21
+ */
22
+ fillSVG(mei) {
23
+ this.fillSystemCounts(mei);
24
+ this.countBarlines();
25
+ return this;
26
+ }
27
+ /**
28
+ * Fill measure, staff and layer with n attributes from MEI
29
+ * @param mei Document from MEI
30
+ */
31
+ fillSystemCounts(mei) {
32
+ var that = this;
33
+ var elements = Array.from(mei.querySelectorAll("measure, staff, layer"));
34
+ elements.forEach(e => {
35
+ if (e.id !== "") {
36
+ var svgElement = that.container.querySelector("#" + e.id);
37
+ if (svgElement === null || e.getAttribute("n") === null) {
38
+ return;
39
+ }
40
+ svgElement.setAttribute("n", e.getAttribute("n"));
41
+ }
42
+ });
43
+ return this;
44
+ }
45
+ cacheClasses() {
46
+ //var svg = document.querySelector("#"+this.containerId + " #vrvSVG")
47
+ var svg = document.querySelector("#" + this.containerId);
48
+ if (!svg)
49
+ return this;
50
+ this.classListMap = new Map();
51
+ var hasLastAdded = !!svg.querySelector(".lastAdded");
52
+ svg.querySelectorAll("*").forEach(el => {
53
+ var _a;
54
+ //if(el.tagName.toLowerCase() === "g" && el.getAttribute("id") !== null){
55
+ if (el.tagName.toLocaleLowerCase() !== "g" && !el.getAttribute("id"))
56
+ return;
57
+ if (hasLastAdded) {
58
+ if (el.classList.contains("marked")) {
59
+ el.classList.remove("marked");
60
+ }
61
+ // if(el.classList.contains("lastAdded")){
62
+ // el.classList.replace("lastAdded", "marked")
63
+ // }
64
+ }
65
+ if (el.getAttribute("id") && !el.classList.contains("lastAdded")) {
66
+ if (!this.classListMap.has(el.id)) {
67
+ this.classListMap.set(el.id, new Array());
68
+ }
69
+ var classes = (_a = el.getAttribute("class")) === null || _a === void 0 ? void 0 : _a.split(" ");
70
+ classes === null || classes === void 0 ? void 0 : classes.forEach(c => {
71
+ if (!this.classListMap.get(el.id).includes(c)) {
72
+ this.classListMap.get(el.id).push(c.slice());
73
+ }
74
+ });
75
+ }
76
+ });
77
+ return this;
78
+ }
79
+ cacheStyles() {
80
+ //var svg = document.querySelector("#"+this.containerId + " #vrvSVG")
81
+ var svg = document.querySelector("#" + this.containerId);
82
+ if (svg === null) {
83
+ return this;
84
+ }
85
+ this.styleListMap = new Map();
86
+ svg.querySelectorAll("[style]").forEach(el => {
87
+ if (el.getAttribute("id")) {
88
+ const styles = el.getAttribute("style");
89
+ if (!this.styleListMap.has(el.id)) {
90
+ this.styleListMap.set(el.id, "");
91
+ }
92
+ this.styleListMap.set(el.id, styles);
93
+ }
94
+ });
95
+ return this;
96
+ }
97
+ loadStyles() {
98
+ if (this.styleListMap == undefined) {
99
+ return this;
100
+ }
101
+ for (const [key, value] of this.styleListMap.entries()) {
102
+ var el = this.container.querySelector("#" + key);
103
+ if (el) {
104
+ el.setAttribute("style", value);
105
+ }
106
+ }
107
+ return this;
108
+ }
109
+ cacheScales() {
110
+ var svg = document.querySelector("#" + this.containerId);
111
+ if (svg === null) {
112
+ return this;
113
+ }
114
+ this.scaleListMap = new Map();
115
+ svg.querySelectorAll("[transform]").forEach(el => {
116
+ if (el.getAttribute("id") !== null) {
117
+ var tattr = el.getAttribute("transform");
118
+ if (tattr.includes("scale")) {
119
+ if (!this.scaleListMap.has(el.id)) {
120
+ this.scaleListMap.set(el.id, tattr);
121
+ }
122
+ }
123
+ }
124
+ });
125
+ return this;
126
+ }
127
+ copyClassesFromMei(mei) {
128
+ if (this.classListMap == undefined) {
129
+ return this;
130
+ }
131
+ mei.querySelectorAll("score *").forEach(el => {
132
+ var _a;
133
+ if (el.hasAttribute("class")) {
134
+ var id = el.getAttribute("id") || el.getAttribute("xml:id");
135
+ if (!this.classListMap.has(id)) {
136
+ this.classListMap.set(id, new Array());
137
+ }
138
+ var classes = (_a = el.getAttribute("class")) === null || _a === void 0 ? void 0 : _a.split(" ");
139
+ classes === null || classes === void 0 ? void 0 : classes.forEach(c => {
140
+ if (!this.classListMap.get(id).includes(c) && this.allowedMeiClasses.includes(c)) {
141
+ this.classListMap.get(id).push(c.slice());
142
+ }
143
+ });
144
+ el.removeAttribute("class");
145
+ }
146
+ });
147
+ return this;
148
+ }
149
+ /**
150
+ * Reload all the classes which where distributed before
151
+ * @returns this (for chaining convenience)
152
+ */
153
+ loadClasses(element = null) {
154
+ if (this.classListMap == undefined) {
155
+ return this;
156
+ }
157
+ if (element) {
158
+ var value = this.classListMap.get(element.id);
159
+ if (value == undefined)
160
+ return this;
161
+ value.forEach(v => {
162
+ if (v === "hideUI")
163
+ return;
164
+ if (v !== "") {
165
+ element.classList.add(v);
166
+ }
167
+ });
168
+ }
169
+ else {
170
+ for (const [key, value] of this.classListMap.entries()) {
171
+ var el = this.container.querySelector("#" + key);
172
+ if (el !== null) {
173
+ //el.removeAttribute("class")
174
+ value.forEach(v => {
175
+ if (v === "hideUI")
176
+ return;
177
+ if (v !== "") {
178
+ el.classList.add(v);
179
+ }
180
+ });
181
+ }
182
+ }
183
+ }
184
+ return this;
185
+ }
186
+ loadScales(element = null) {
187
+ if (this.scaleListMap == undefined) {
188
+ return this;
189
+ }
190
+ if (element !== null) {
191
+ var value = this.scaleListMap.get(element.id);
192
+ if (value == undefined)
193
+ return this;
194
+ element.style.transform = value;
195
+ element.setAttribute("transform", value);
196
+ }
197
+ else {
198
+ for (const [key, value] of this.scaleListMap.entries()) {
199
+ var el = this.container.querySelector("#" + key);
200
+ if (el !== null) {
201
+ el.style.transform = value;
202
+ el.setAttribute("transform", value);
203
+ }
204
+ }
205
+ }
206
+ return this;
207
+ }
208
+ repositionSVG(svg) {
209
+ var _a;
210
+ var transformList = ((_a = svg.getAttribute("transform")) === null || _a === void 0 ? void 0 : _a.split(") ")) || new Array();
211
+ console.log(svg.getAttribute("transform"), transformList);
212
+ var hasTranslate = false;
213
+ transformList.forEach((t, i) => {
214
+ if (t.includes("translate")) {
215
+ transformList[i] = "translate(" + this.x + " " + this.y + ")";
216
+ hasTranslate = true;
217
+ }
218
+ if (t.slice(-1) !== ")") {
219
+ transformList[i] = transformList[i] + ")";
220
+ }
221
+ });
222
+ if (!hasTranslate) {
223
+ transformList.push("translate(" + this.x + " " + this.y + ")");
224
+ }
225
+ var trattr = transformList.join(" ");
226
+ console.log(trattr);
227
+ svg.setAttribute("transform", trattr);
228
+ return this;
229
+ }
230
+ /**
231
+ * Merge all tspans in a harm object in the top tspan to avoid columns for (especially in Firefox browsers)
232
+ * @returns
233
+ */
234
+ clearTspan() {
235
+ var gelements = this.container.querySelectorAll("g .harm");
236
+ gelements.forEach(g => {
237
+ var textEl = g.querySelector("text");
238
+ var textTspan = g.querySelectorAll("tspan");
239
+ var text = "";
240
+ if (textTspan.length <= 2) {
241
+ return;
242
+ }
243
+ text = textTspan[0].textContent;
244
+ text = text.replace(/ /g, '');
245
+ text = text.replace(/\n/g, '');
246
+ textEl.querySelector("tspan").firstElementChild.textContent = text;
247
+ textEl.querySelector("tspan").firstElementChild.setAttribute("font-family", "VerovioText");
248
+ textTspan.forEach((tp, idx) => {
249
+ if (idx >= 2) {
250
+ tp.remove();
251
+ }
252
+ });
253
+ });
254
+ return this;
255
+ }
256
+ drawLinesUnderSystems() {
257
+ this.container.querySelectorAll(".systemLine").forEach(sl => sl.remove());
258
+ this.container.querySelectorAll(".system").forEach(sys => {
259
+ var line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
260
+ line.classList.add("systemLine");
261
+ var systemCoords = coords.getDOMMatrixCoordinates(sys.getBoundingClientRect(), sys.closest("svg"));
262
+ var y = systemCoords.bottom;
263
+ line.setAttribute("x1", systemCoords.left.toString());
264
+ line.setAttribute("y1", y.toString());
265
+ line.setAttribute("x2", systemCoords.right.toString());
266
+ line.setAttribute("y2", y.toString());
267
+ var defScale = sys.closest(".definition-scale");
268
+ defScale.prepend(line);
269
+ });
270
+ }
271
+ /**
272
+ * Modify the harm elements so that they have proper sub- and superscript numbers based on their used symbols (^ or _)
273
+ */
274
+ modifyHarm() {
275
+ // 0, 1 applies for sup; 2, 3 applies for sub
276
+ // create as <sup> element from ^{} or just ^
277
+ // create as <sub> element from _{} or just _
278
+ var indexingRegex = [/\^\{(.*?)\}/g, /\^\s*([^(]*)/g, /\_\{(.*?)\}/g, /\_\s*([^(]*)/g];
279
+ var sameParent; // cache for parent to not replace elements multiple times
280
+ this.container.querySelectorAll("[id].harm tspan").forEach(el => {
281
+ //mustn't be in figured base, and no need for trim indicates that text content node is leaf of tree
282
+ if (el.closest(".fb") !== null || el.textContent != el.textContent.trim())
283
+ return;
284
+ var elSiblings = el.querySelectorAll(":scope ~ tspan");
285
+ if (sameParent === el.parentElement) {
286
+ el.remove();
287
+ return;
288
+ }
289
+ if (elSiblings !== null)
290
+ sameParent = el.parentElement;
291
+ var inputString = elSiblings === null ? el.textContent : el.parentElement.textContent.replace(/[\n\s]/g, "");
292
+ el.textContent = "";
293
+ indexingRegex.forEach((reg, i) => {
294
+ var shift;
295
+ if (i < 2) {
296
+ shift = "super";
297
+ }
298
+ else if (i >= 2 && i < 4) {
299
+ shift = "sub";
300
+ }
301
+ var findStrings = inputString.match(reg);
302
+ if (findStrings !== null) {
303
+ findStrings.forEach(fs => {
304
+ var modPart = fs;
305
+ ["^", "_", "{", "}"].forEach(s => modPart = modPart.replace(s, ""));
306
+ if (modPart === "")
307
+ return;
308
+ modPart = "<tspan class=\"indexBase\" baseline-shift=\"" + shift + "\">" + modPart + "</tspan>";
309
+ inputString = inputString.replace(fs, modPart);
310
+ });
311
+ }
312
+ });
313
+ el.innerHTML = inputString;
314
+ // shift all tspans a little to the left so that they are all aligned vertically
315
+ el.querySelectorAll("tspan").forEach((t, i) => {
316
+ t.style.fontSize = "0.7em";
317
+ if (i > 0) {
318
+ t.setAttribute("dx", (-(0.5) * i).toString() + "em");
319
+ }
320
+ });
321
+ });
322
+ }
323
+ /**
324
+ * Mark the current Measure as overfilled by writing "+!" over the barline
325
+ * @param currentMEI
326
+ */
327
+ markOverfilledMeasures(currentMEI) {
328
+ currentMEI.querySelectorAll("measure").forEach(m => {
329
+ m.querySelectorAll("layer").forEach(l => {
330
+ var layerRatio = meiOperation.getAbsoluteRatio(l);
331
+ var targetRatio = meiOperation.getMeterRatioLocal(currentMEI, l);
332
+ if (layerRatio > targetRatio) {
333
+ var measureSVG = document.querySelector("#vrvSVG #" + m.id);
334
+ if (measureSVG === null)
335
+ return;
336
+ var barLine = measureSVG.querySelector(".barLine");
337
+ var coordinates = coords.getDOMMatrixCoordinates(barLine, barLine.closest("g"));
338
+ var textGroup = document.createElementNS(constants_1.constants._SVGNS_, "g");
339
+ textGroup.setAttribute("id", random_1.uuidv4());
340
+ textGroup.setAttribute("targetId", barLine.id);
341
+ var text = document.createElementNS(constants_1.constants._SVGNS_, "svg");
342
+ var textForeignObject = document.createElementNS(constants_1.constants._SVGNS_, "foreignObject");
343
+ textForeignObject.classList.add("overfillMark");
344
+ var textDiv = document.createElement("div");
345
+ textDiv.setAttribute("contenteditable", "false");
346
+ textDiv.textContent = "+!";
347
+ text.append(textForeignObject);
348
+ textForeignObject.setAttribute("x", (coordinates.x * 0.95).toString());
349
+ textForeignObject.setAttribute("y", (-coordinates.y * 0.55).toString());
350
+ textForeignObject.setAttribute("height", (coordinates.height * 2).toString());
351
+ textForeignObject.setAttribute("width", (300).toString());
352
+ textForeignObject.append(textDiv);
353
+ textGroup.appendChild(text);
354
+ barLine.insertAdjacentElement("afterend", textGroup);
355
+ }
356
+ });
357
+ });
358
+ }
359
+ countBarlines() {
360
+ this.container.querySelectorAll(".barLine").forEach(bl => {
361
+ bl.querySelectorAll("path").forEach((p, idx) => {
362
+ p.setAttribute("n", (idx + 1).toString());
363
+ });
364
+ });
365
+ }
366
+ /**
367
+ * Hide Rests of same duration in parallel layers. Also hide rests, when layer (n >= 2) is just rests.
368
+ * @param currentMEI MEI to parse and compute relationships. Provides IDs for elements in SVG.
369
+ * @returns this
370
+ */
371
+ hideRedundantRests(currentMEI) {
372
+ currentMEI.querySelectorAll("staff").forEach(s => {
373
+ var prevLayerElements;
374
+ const vrv = cq.getVrvSVG(this.containerId);
375
+ s.querySelectorAll("layer").forEach(l => {
376
+ if (parseInt(l.getAttribute("n")) === 1) {
377
+ prevLayerElements = Array.from(l.children);
378
+ return;
379
+ }
380
+ if (parseInt(l.getAttribute("n")) >= 2) {
381
+ if (!prevLayerElements) {
382
+ prevLayerElements = Array.from(l.children);
383
+ return;
384
+ }
385
+ const notes = l.querySelectorAll("note");
386
+ if (notes.length === 0) {
387
+ Array.from(l.children).forEach(c => vrv.querySelectorAll(`#${c.id} use`).forEach(u => u.setAttribute("visibility", "hidden")));
388
+ }
389
+ else {
390
+ Array.from(l.children).forEach(c => {
391
+ prevLayerElements.forEach(ple => {
392
+ var _a;
393
+ const isRest = ple.tagName.toLowerCase().includes("rest") && c.tagName.toLowerCase().includes("rest");
394
+ const sameDur = ple.getAttribute("dur") === c.getAttribute("dur");
395
+ const sameTstamp = meiOperation.getTimestamp(ple) === meiOperation.getTimestamp(c);
396
+ if (isRest && sameDur && sameTstamp) {
397
+ (_a = vrv.querySelector(`#${c.id} use`)) === null || _a === void 0 ? void 0 : _a.setAttribute("visibility", "hidden");
398
+ }
399
+ });
400
+ });
401
+ }
402
+ prevLayerElements = Array.from(l.children);
403
+ }
404
+ });
405
+ });
406
+ return this;
407
+ }
408
+ distributeIds(element, propagation = false) {
409
+ if (propagation) {
410
+ var id = element.id !== "" ? element.id : element.getAttribute("refId");
411
+ Array.from(element.children).forEach(c => {
412
+ var selfId = c.id !== "" ? c.id : c.getAttribute("refId");
413
+ if (selfId === null && id !== null) {
414
+ c.setAttribute("refId", id);
415
+ }
416
+ this.distributeIds(c, true);
417
+ });
418
+ }
419
+ else {
420
+ Array.from(element.querySelectorAll("*")).forEach(el => {
421
+ if (el.id === "") {
422
+ el.setAttribute("id", random_1.uuidv4());
423
+ }
424
+ });
425
+ }
426
+ return this;
427
+ }
428
+ setActiveLayer() {
429
+ var container = cq.getContainer(this.containerId);
430
+ if (!container.querySelector(".layer.activeLayer")) {
431
+ container.querySelectorAll(".layer[n='1']").forEach(l => l.classList.add("activeLayer"));
432
+ }
433
+ container.querySelectorAll(".activeLayer").forEach(al => {
434
+ var staffN = al.closest(".staff").getAttribute("n");
435
+ var layerN = al.getAttribute("n");
436
+ container.querySelectorAll(`.staff[n='${staffN}'] > .layer[n='${layerN}']`).forEach(layer => {
437
+ layer.classList.add("activeLayer");
438
+ });
439
+ });
440
+ return this;
441
+ }
442
+ setContainerId(containerId) {
443
+ this.containerId = containerId;
444
+ this.container = document.getElementById(containerId);
445
+ return this;
446
+ }
447
+ setXY(x, y) {
448
+ this.x = x || 0;
449
+ this.y = y || 0;
450
+ //console.log("müssen die koordinaten noch umgerechnet werden???", x, y)
451
+ }
452
+ }
453
+ exports.default = SVGEditor;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const midi_1 = require("@tonejs/midi");
4
+ const buffer_1 = require("buffer");
3
5
  //@ts-ignore
4
6
  //const $ = H5P.jQuery;
5
7
  /**
@@ -13,23 +15,19 @@ class VerovioWrapper {
13
15
  if (this.isRetina()) {
14
16
  this.r = 2;
15
17
  }
16
- this.widthValue = 2500;
18
+ this.widthValue = 1500;
19
+ var pageWidth = (this.widthValue / (window.devicePixelRatio / this.r)) / (screen.availHeight / window.innerWidth);
17
20
  this.options = {
18
- // from: 'mei',
19
21
  footer: 'none',
20
22
  header: 'none',
21
23
  pageMarginLeft: 50,
22
- pageMarginTop: 100,
23
- pageMarginBottom: 0,
24
+ pageMarginTop: 50,
25
+ adjustPageHeight: true,
24
26
  font: 'Bravura',
25
- //adjustPageWidth: 0,
26
- //adjustPageHeight: 0,
27
- noJustification: 1,
28
- pageWidth: (this.widthValue / (window.devicePixelRatio / this.r)) / (screen.availHeight / window.innerWidth),
29
- //svgRemoveXlink: true,
27
+ //pageWidth: pageWidth, // adjust size with window size
28
+ //pageHeight: pageWidth / 4,
29
+ //justifyVertically: true,
30
30
  svgViewBox: true,
31
- //svgBoundingBoxes: true
32
- //pageHeight: 60000
33
31
  };
34
32
  this.vrvToolkit.setOptions(this.options);
35
33
  }
@@ -59,7 +57,7 @@ class VerovioWrapper {
59
57
  };
60
58
  switch (data.action) {
61
59
  case 'renderData':
62
- result.mei = this.renderData();
60
+ result.svg = this.renderData();
63
61
  break;
64
62
  case 'getElementAttr':
65
63
  result.attributes = this.getElementAttr();
@@ -79,7 +77,7 @@ class VerovioWrapper {
79
77
  result.info = this.editInfo();
80
78
  break;
81
79
  case 'renderToSVG':
82
- result.svg = this.renderToSVG();
80
+ result.svg = this.renderToSVG(data.pageNo);
83
81
  break;
84
82
  case 'renderToMidi':
85
83
  result.midi = this.renderToMidi();
@@ -106,7 +104,9 @@ class VerovioWrapper {
106
104
  else {
107
105
  meiString = this.data.mei;
108
106
  }
109
- return this.vrvToolkit.renderData(meiString, {});
107
+ var render = this.vrvToolkit.renderData(meiString, {});
108
+ // when page count reaches 2 then each one should be rendered seperately
109
+ return render;
110
110
  }
111
111
  getElementAttr() {
112
112
  return this.vrvToolkit.getElementAttr(this.data.elementId);
@@ -129,12 +129,20 @@ class VerovioWrapper {
129
129
  editInfo() {
130
130
  return this.vrvToolkit.editInfo();
131
131
  }
132
- renderToSVG() {
133
- return this.vrvToolkit.renderToSVG(1);
132
+ renderToSVG(pageNo) {
133
+ return this.vrvToolkit.renderToSVG(pageNo);
134
134
  }
135
135
  renderToMidi() {
136
136
  return this.vrvToolkit.renderToMIDI();
137
137
  }
138
+ getMidiJSON() {
139
+ var midiString = this.renderToMidi();
140
+ var buffer = buffer_1.Buffer.from(midiString, "base64");
141
+ return new midi_1.Midi(buffer);
142
+ }
143
+ getTimemap() {
144
+ return this.vrvToolkit.renderToTimemap();
145
+ }
138
146
  /**
139
147
  * Get Toolkit instance to use any method of verovio outside of score editor.
140
148
  * FOr all available methods go to: https://book.verovio.org/toolkit-reference/toolkit-methods.html
@@ -147,10 +155,16 @@ class VerovioWrapper {
147
155
  return this.options;
148
156
  }
149
157
  setWidthValue(wv) {
150
- this.widthValue = wv;
158
+ if (typeof wv === "string")
159
+ wv = parseFloat(wv);
160
+ this.options.pageWidth = wv;
161
+ this.vrvToolkit.setOptions(this.options);
151
162
  }
152
163
  setHeightValue(hv) {
153
- this.heightValue = hv;
164
+ if (typeof hv === "string")
165
+ hv = parseFloat(hv);
166
+ this.options.pageHeight = hv + 250;
167
+ this.vrvToolkit.setOptions(this.options);
154
168
  }
155
169
  }
156
170
  exports.default = VerovioWrapper;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformToDOMMatrixCoordinates = exports.getCanvasCordinates = exports.getDOMMatrixCoordinates = void 0;
4
+ /**
5
+ * Get DOMMatrix coordnates of element according to parent canvas class. Returns null if no canvas is found. If element is DOMRect, canvas must be provided
6
+ * @param element
7
+ * @param canvas provide canvas for element, otherwise closest canvas class will be retrieved
8
+ * @returns
9
+ */
10
+ function getDOMMatrixCoordinates(element, canvas = null) {
11
+ if (canvas === null) {
12
+ canvas = element instanceof Element ? element.closest(".canvas") : null;
13
+ if (element instanceof DOMRect) {
14
+ throw new Error("Canvas must be provided, if input is instance of DOMRect. Actual instance: " + element.constructor.name);
15
+ }
16
+ if (canvas === null)
17
+ return;
18
+ }
19
+ if (canvas.id === "vrvSVG")
20
+ canvas = canvas.previousElementSibling;
21
+ var canvasMatrix = canvas.getScreenCTM().inverse();
22
+ //var elementBBox = !(element instanceof Element) ? element : element.getBoundingClientRect()
23
+ var elementBBox;
24
+ try {
25
+ elementBBox = element.getBoundingClientRect();
26
+ }
27
+ catch (error) {
28
+ elementBBox = element;
29
+ }
30
+ var ptLT = new DOMPoint(elementBBox.left, elementBBox.top);
31
+ ptLT = ptLT.matrixTransform(canvasMatrix);
32
+ var ptRB = new DOMPoint(elementBBox.right, elementBBox.bottom);
33
+ ptRB = ptRB.matrixTransform(canvasMatrix);
34
+ var width = ptRB.x - ptLT.x;
35
+ var height = ptRB.y - ptLT.y;
36
+ return { left: ptLT.x, top: ptLT.y, right: ptRB.x, bottom: ptRB.y, width: width, height: height, x: ptLT.x, y: ptLT.y, matrix: canvasMatrix };
37
+ }
38
+ exports.getDOMMatrixCoordinates = getDOMMatrixCoordinates;
39
+ function getCanvasCordinates(coords, canvas = null) {
40
+ if (!coords.matrix) {
41
+ throw new Error("DOMMatrix is missing.");
42
+ }
43
+ if (canvas === null) {
44
+ canvas = canvas instanceof Element ? canvas.closest(".canvas") : null;
45
+ if (canvas instanceof DOMRect) {
46
+ throw new Error("Canvas must be provided, if input is instance of DOMRect. Actual instance: " + canvas.constructor.name);
47
+ }
48
+ if (canvas === null)
49
+ return;
50
+ }
51
+ // Reverse the transformation
52
+ var canvasMatrix = coords.matrix.inverse();
53
+ var ptLT = new DOMPoint(coords.left, coords.top);
54
+ ptLT = ptLT.matrixTransform(canvasMatrix);
55
+ var ptRB = new DOMPoint(coords.right, coords.bottom);
56
+ ptRB = ptRB.matrixTransform(canvasMatrix);
57
+ var width = ptRB.x - ptLT.x;
58
+ var height = ptRB.y - ptLT.y;
59
+ // Create and return the DOMRect
60
+ return new DOMRect(ptLT.x, ptLT.y, width, height);
61
+ }
62
+ exports.getCanvasCordinates = getCanvasCordinates;
63
+ /**
64
+ * Transforms the given coordinates for a given canvas
65
+ * @param x
66
+ * @param y
67
+ * @param canvas
68
+ * @returns
69
+ */
70
+ function transformToDOMMatrixCoordinates(x, y, canvas) {
71
+ if (canvas.id === "vrvSVG")
72
+ canvas = canvas.previousElementSibling;
73
+ var canvasMatrix = canvas.getScreenCTM().inverse();
74
+ var pt = new DOMPoint(x, y);
75
+ pt = pt.matrixTransform(canvasMatrix);
76
+ return { x: pt.x, y: pt.y };
77
+ }
78
+ exports.transformToDOMMatrixCoordinates = transformToDOMMatrixCoordinates;
@@ -626,13 +626,20 @@ class Mouse2SVG {
626
626
  * @param orientation only consider elements which are left or right of given coordinates
627
627
  * @returns
628
628
  */
629
- findScoreTarget(posX, posY, checkStaff = true, orientation = { left: true, right: true }) {
629
+ findScoreTarget(posX, posY, checkStaff = true, orientation = null, blackList = null) {
630
+ if (!orientation)
631
+ orientation = { left: true, right: true };
630
632
  var notes = this.getNoteBBoxes();
631
633
  var nextNote;
632
634
  var tempDist = Math.pow(10, 10);
633
635
  var i = 0;
634
636
  notes.forEach(n => {
635
637
  var _a, _b, _c, _d;
638
+ if (blackList) {
639
+ var blackListFilter = Array.from(this.getElementinVrvSVG(n.id).classList).filter(element => blackList.includes(element));
640
+ if (blackListFilter.length > 0)
641
+ return;
642
+ }
636
643
  var x;
637
644
  var y;
638
645
  if (((_a = this.getElementinVrvSVG(n.id)) === null || _a === void 0 ? void 0 : _a.closest(".chord")) && navigator.userAgent.toLowerCase().indexOf("firefox") > -1) { // special rule for firefox browsers
@@ -647,11 +654,11 @@ class Mouse2SVG {
647
654
  if (this.vrvSVG.querySelector("#" + n.id) === null)
648
655
  return;
649
656
  if (!this.vrvSVG.querySelector("#" + n.id).classList.contains("mRest")) { //mRest are excluded from this rule
650
- if (orientation.left === false) {
657
+ if (!orientation.left) {
651
658
  if (x < posX)
652
659
  return; //exclude left elements
653
660
  }
654
- else if (orientation.right === false) {
661
+ else if (!orientation.right) {
655
662
  if (x > posX)
656
663
  return; // exclude right elements
657
664
  }
@@ -659,7 +666,7 @@ class Mouse2SVG {
659
666
  var dist = Math.abs(x - posX);
660
667
  var staffCondition = n.parentStaff === this.getElementinVrvSVG((_d = this.lastStaffMouseEnter) === null || _d === void 0 ? void 0 : _d.getAttribute("refId"));
661
668
  staffCondition && (staffCondition = Array.from(this.container.querySelectorAll(".activeLayer")).some(l => n.parentLayer === l));
662
- if (checkStaff === false) {
669
+ if (!checkStaff) {
663
670
  staffCondition = true;
664
671
  dist = Math.sqrt(Math.abs(x - posX) ** 2 + Math.abs(y - posY) ** 2);
665
672
  }