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,352 @@
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 meiOperation = require("./MEIOperations");
8
+ const coords = require("../utils/coordinates");
9
+ const random_1 = require("./random");
10
+ const constants_1 = require("../constants");
11
+ class SVGEditor {
12
+ constructor() {
13
+ this.allowedMeiClasses = ["marked"];
14
+ this.x = 0;
15
+ this.y = 0;
16
+ }
17
+ /**
18
+ * Fill SVG in Dom with relevant mei Information
19
+ * @param mei Document from MEI
20
+ */
21
+ fillSVG(mei) {
22
+ this.fillSystemCounts(mei);
23
+ this.countBarlines();
24
+ return this;
25
+ }
26
+ /**
27
+ * Fill measure, staff and layer with n attributes from MEI
28
+ * @param mei Document from MEI
29
+ */
30
+ fillSystemCounts(mei) {
31
+ var that = this;
32
+ var elements = Array.from(mei.querySelectorAll("measure, staff, layer"));
33
+ elements.forEach(e => {
34
+ if (e.id !== "") {
35
+ var svgElement = that.container.querySelector("#" + e.id);
36
+ if (svgElement === null || e.getAttribute("n") === null) {
37
+ return;
38
+ }
39
+ svgElement.setAttribute("n", e.getAttribute("n"));
40
+ }
41
+ });
42
+ return this;
43
+ }
44
+ cacheClasses() {
45
+ //var svg = document.querySelector("#"+this.containerId + " #vrvSVG")
46
+ var svg = document.querySelector("#" + this.containerId);
47
+ if (svg === null) {
48
+ return this;
49
+ }
50
+ this.classListMap = new Map();
51
+ svg.querySelectorAll("*").forEach(el => {
52
+ var _a;
53
+ //if(el.tagName.toLowerCase() === "g" && el.getAttribute("id") !== null){
54
+ if (el.getAttribute("id") !== null) {
55
+ if (!this.classListMap.has(el.id)) {
56
+ this.classListMap.set(el.id, new Array());
57
+ }
58
+ var classes = (_a = el.getAttribute("class")) === null || _a === void 0 ? void 0 : _a.split(" ");
59
+ classes === null || classes === void 0 ? void 0 : classes.forEach(c => {
60
+ if (!this.classListMap.get(el.id).includes(c)) {
61
+ this.classListMap.get(el.id).push(c.slice());
62
+ }
63
+ });
64
+ }
65
+ });
66
+ return this;
67
+ }
68
+ cacheScales() {
69
+ var svg = document.querySelector("#" + this.containerId);
70
+ if (svg === null) {
71
+ return this;
72
+ }
73
+ this.scaleListMap = new Map();
74
+ svg.querySelectorAll("[transform]").forEach(el => {
75
+ if (el.getAttribute("id") !== null) {
76
+ var tattr = el.getAttribute("transform");
77
+ if (tattr.includes("scale")) {
78
+ if (!this.scaleListMap.has(el.id)) {
79
+ this.scaleListMap.set(el.id, tattr);
80
+ }
81
+ }
82
+ }
83
+ });
84
+ return this;
85
+ }
86
+ copyClassesFromMei(mei) {
87
+ if (this.classListMap == undefined) {
88
+ return this;
89
+ }
90
+ mei.querySelectorAll("score *").forEach(el => {
91
+ var _a;
92
+ if (el.hasAttribute("class")) {
93
+ var id = el.getAttribute("id") || el.getAttribute("xml:id");
94
+ if (!this.classListMap.has(id)) {
95
+ this.classListMap.set(id, new Array());
96
+ }
97
+ var classes = (_a = el.getAttribute("class")) === null || _a === void 0 ? void 0 : _a.split(" ");
98
+ classes === null || classes === void 0 ? void 0 : classes.forEach(c => {
99
+ if (!this.classListMap.get(id).includes(c) && this.allowedMeiClasses.includes(c)) {
100
+ this.classListMap.get(id).push(c.slice());
101
+ }
102
+ });
103
+ el.removeAttribute("class");
104
+ }
105
+ });
106
+ return this;
107
+ }
108
+ /**
109
+ * Reload all the classes which where distributed before
110
+ * @returns this (for chaining convenience)
111
+ */
112
+ loadClasses(element = null) {
113
+ if (this.classListMap == undefined) {
114
+ return this;
115
+ }
116
+ if (element !== null) {
117
+ var value = this.classListMap.get(element.id);
118
+ if (value == undefined)
119
+ return this;
120
+ value.forEach(v => {
121
+ if (v !== "") {
122
+ element.classList.add(v);
123
+ }
124
+ });
125
+ }
126
+ else {
127
+ for (const [key, value] of this.classListMap.entries()) {
128
+ var el = this.container.querySelector("#" + key);
129
+ if (el !== null) {
130
+ //el.removeAttribute("class")
131
+ value.forEach(v => {
132
+ if (v !== "") {
133
+ el.classList.add(v);
134
+ }
135
+ });
136
+ }
137
+ }
138
+ }
139
+ return this;
140
+ }
141
+ loadScales(element = null) {
142
+ if (this.scaleListMap == undefined) {
143
+ return this;
144
+ }
145
+ if (element !== null) {
146
+ var value = this.scaleListMap.get(element.id);
147
+ if (value == undefined)
148
+ return this;
149
+ element.style.transform = value;
150
+ element.setAttribute("transform", value);
151
+ }
152
+ else {
153
+ for (const [key, value] of this.scaleListMap.entries()) {
154
+ var el = this.container.querySelector("#" + key);
155
+ if (el !== null) {
156
+ el.style.transform = value;
157
+ el.setAttribute("transform", value);
158
+ }
159
+ }
160
+ }
161
+ return this;
162
+ }
163
+ repositionSVG(svg) {
164
+ var _a;
165
+ var transformList = ((_a = svg.getAttribute("transform")) === null || _a === void 0 ? void 0 : _a.split(") ")) || new Array();
166
+ console.log(svg.getAttribute("transform"), transformList);
167
+ var hasTranslate = false;
168
+ transformList.forEach((t, i) => {
169
+ if (t.includes("translate")) {
170
+ transformList[i] = "translate(" + this.x + " " + this.y + ")";
171
+ hasTranslate = true;
172
+ }
173
+ if (t.slice(-1) !== ")") {
174
+ transformList[i] = transformList[i] + ")";
175
+ }
176
+ });
177
+ if (!hasTranslate) {
178
+ transformList.push("translate(" + this.x + " " + this.y + ")");
179
+ }
180
+ var trattr = transformList.join(" ");
181
+ console.log(trattr);
182
+ svg.setAttribute("transform", trattr);
183
+ return this;
184
+ }
185
+ /**
186
+ * Merge all tspans in a harm object in the top tspan to avoid columns for (especially in Firefox browsers)
187
+ * @returns
188
+ */
189
+ clearTspan() {
190
+ var gelements = this.container.querySelectorAll("g .harm");
191
+ gelements.forEach(g => {
192
+ var textEl = g.querySelector("text");
193
+ var textTspan = g.querySelectorAll("tspan");
194
+ var text = "";
195
+ if (textTspan.length <= 2) {
196
+ return;
197
+ }
198
+ text = textTspan[0].textContent;
199
+ text = text.replace(/ /g, '');
200
+ text = text.replace(/\n/g, '');
201
+ textEl.querySelector("tspan").firstElementChild.textContent = text;
202
+ textEl.querySelector("tspan").firstElementChild.setAttribute("font-family", "VerovioText");
203
+ textTspan.forEach((tp, idx) => {
204
+ if (idx >= 2) {
205
+ tp.remove();
206
+ }
207
+ });
208
+ });
209
+ return this;
210
+ }
211
+ drawLinesUnderSystems() {
212
+ this.container.querySelectorAll(".systemLine").forEach(sl => sl.remove());
213
+ this.container.querySelectorAll(".system").forEach(sys => {
214
+ var line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
215
+ line.classList.add("systemLine");
216
+ var systemCoords = coords.getDOMMatrixCoordinates(sys.getBoundingClientRect(), sys.closest("svg"));
217
+ var y = systemCoords.bottom;
218
+ line.setAttribute("x1", systemCoords.left.toString());
219
+ line.setAttribute("y1", y.toString());
220
+ line.setAttribute("x2", systemCoords.right.toString());
221
+ line.setAttribute("y2", y.toString());
222
+ var defScale = sys.closest(".definition-scale");
223
+ defScale.prepend(line);
224
+ });
225
+ }
226
+ /**
227
+ * Modify the harm elements so that they have proper sub- and superscript numbers based on their used symbols (^ or _)
228
+ */
229
+ modifyHarm() {
230
+ // 0, 1 applies for sup; 2, 3 applies for sub
231
+ // create as <sup> element from ^{} or just ^
232
+ // create as <sub> element from _{} or just _
233
+ var indexingRegex = [/\^\{(.*?)\}/g, /\^\s*([^(]*)/g, /\_\{(.*?)\}/g, /\_\s*([^(]*)/g];
234
+ var sameParent; // cache for parent to not replace elements multiple times
235
+ this.container.querySelectorAll("[id].harm tspan").forEach(el => {
236
+ //mustn't be in figured base, and no need for trim indicates that text content node is leaf of tree
237
+ if (el.closest(".fb") !== null || el.textContent != el.textContent.trim())
238
+ return;
239
+ var elSiblings = el.querySelectorAll(":scope ~ tspan");
240
+ if (sameParent === el.parentElement) {
241
+ el.remove();
242
+ return;
243
+ }
244
+ if (elSiblings !== null)
245
+ sameParent = el.parentElement;
246
+ var inputString = elSiblings === null ? el.textContent : el.parentElement.textContent.replace(/[\n\s]/g, "");
247
+ el.textContent = "";
248
+ indexingRegex.forEach((reg, i) => {
249
+ var shift;
250
+ if (i < 2) {
251
+ shift = "super";
252
+ }
253
+ else if (i >= 2 && i < 4) {
254
+ shift = "sub";
255
+ }
256
+ var findStrings = inputString.match(reg);
257
+ if (findStrings !== null) {
258
+ findStrings.forEach(fs => {
259
+ var modPart = fs;
260
+ ["^", "_", "{", "}"].forEach(s => modPart = modPart.replace(s, ""));
261
+ if (modPart === "")
262
+ return;
263
+ modPart = "<tspan class=\"indexBase\" baseline-shift=\"" + shift + "\">" + modPart + "</tspan>";
264
+ inputString = inputString.replace(fs, modPart);
265
+ });
266
+ }
267
+ });
268
+ el.innerHTML = inputString;
269
+ // shift all tspans a little to the left so that they are all aligned vertically
270
+ el.querySelectorAll("tspan").forEach((t, i) => {
271
+ t.style.fontSize = "0.7em";
272
+ if (i > 0) {
273
+ t.setAttribute("dx", (-(0.5) * i).toString() + "em");
274
+ }
275
+ });
276
+ });
277
+ }
278
+ /**
279
+ * Mark the current Measere as overfilled by writing "+!" over the barline
280
+ * @param currentMEI
281
+ */
282
+ markOverfilledMeasures(currentMEI) {
283
+ currentMEI.querySelectorAll("measure").forEach(m => {
284
+ m.querySelectorAll("layer").forEach(l => {
285
+ var layerRatio = meiOperation.getAbsoluteRatio(l);
286
+ var targetRatio = meiOperation.getMeterRatioLocal(currentMEI, l);
287
+ if (layerRatio > targetRatio) {
288
+ var measureSVG = document.querySelector("#vrvSVG #" + m.id);
289
+ if (measureSVG === null)
290
+ return;
291
+ var barLine = measureSVG.querySelector(".barLine");
292
+ var coordinates = coords.getDOMMatrixCoordinates(barLine, barLine.closest("g"));
293
+ var textGroup = document.createElementNS(constants_1.constants._SVGNS_, "g");
294
+ textGroup.setAttribute("id", random_1.uuidv4());
295
+ textGroup.setAttribute("targetId", barLine.id);
296
+ var text = document.createElementNS(constants_1.constants._SVGNS_, "svg");
297
+ var textForeignObject = document.createElementNS(constants_1.constants._SVGNS_, "foreignObject");
298
+ textForeignObject.classList.add("overfillMark");
299
+ var textDiv = document.createElement("div");
300
+ textDiv.setAttribute("contenteditable", "false");
301
+ textDiv.textContent = "+!";
302
+ text.append(textForeignObject);
303
+ textForeignObject.setAttribute("x", (coordinates.x * 0.95).toString());
304
+ textForeignObject.setAttribute("y", (-coordinates.y * 0.55).toString());
305
+ textForeignObject.setAttribute("height", (coordinates.height * 2).toString());
306
+ textForeignObject.setAttribute("width", (300).toString());
307
+ textForeignObject.append(textDiv);
308
+ textGroup.appendChild(text);
309
+ barLine.insertAdjacentElement("afterend", textGroup);
310
+ }
311
+ });
312
+ });
313
+ }
314
+ countBarlines() {
315
+ this.container.querySelectorAll(".barLine").forEach(bl => {
316
+ bl.querySelectorAll("path").forEach((p, idx) => {
317
+ p.setAttribute("n", (idx + 1).toString());
318
+ });
319
+ });
320
+ }
321
+ distributeIds(element, propagation = false) {
322
+ if (propagation) {
323
+ var id = element.id !== "" ? element.id : element.getAttribute("refId");
324
+ Array.from(element.children).forEach(c => {
325
+ var selfId = c.id !== "" ? c.id : c.getAttribute("refId");
326
+ if (selfId === null && id !== null) {
327
+ c.setAttribute("refId", id);
328
+ }
329
+ this.distributeIds(c, true);
330
+ });
331
+ }
332
+ else {
333
+ Array.from(element.querySelectorAll("*")).forEach(el => {
334
+ if (el.id === "") {
335
+ el.setAttribute("id", random_1.uuidv4());
336
+ }
337
+ });
338
+ }
339
+ return this;
340
+ }
341
+ setContainerId(containerId) {
342
+ this.containerId = containerId;
343
+ this.container = document.getElementById(containerId);
344
+ return this;
345
+ }
346
+ setXY(x, y) {
347
+ this.x = x || 0;
348
+ this.y = y || 0;
349
+ //console.log("müssen die koordinaten noch umgerechnet werden???", x, y)
350
+ }
351
+ }
352
+ exports.default = SVGEditor;
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ /**
3
+ * Class to fill SVG of Score in HTML with information from underlying mei
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const random_1 = require("./random");
7
+ class SVGFiller {
8
+ constructor() {
9
+ this.allowedMeiClasses = ["marked"];
10
+ this.x = 0;
11
+ this.y = 0;
12
+ }
13
+ /**
14
+ * Fill SVG in Dom with relevant mei Information
15
+ * @param mei Document from MEI
16
+ */
17
+ fillSVG(mei) {
18
+ this.fillSystemCounts(mei);
19
+ this.countBarlines();
20
+ return this;
21
+ }
22
+ /**
23
+ * Fill measure, staff and layer with n attributes from MEI
24
+ * @param mei Document from MEI
25
+ */
26
+ fillSystemCounts(mei) {
27
+ var that = this;
28
+ var elements = Array.from(mei.querySelectorAll("measure, staff, layer"));
29
+ elements.forEach(e => {
30
+ if (e.id !== "") {
31
+ var svgElement = that.container.querySelector("#" + e.id);
32
+ if (svgElement === null || e.getAttribute("n") === null) {
33
+ return;
34
+ }
35
+ svgElement.setAttribute("n", e.getAttribute("n"));
36
+ }
37
+ });
38
+ return this;
39
+ }
40
+ cacheClasses() {
41
+ //var svg = document.querySelector("#"+this.containerId + " #vrvSVG")
42
+ var svg = document.querySelector("#" + this.containerId);
43
+ if (svg === null) {
44
+ return this;
45
+ }
46
+ this.classListMap = new Map();
47
+ svg.querySelectorAll("*").forEach(el => {
48
+ var _a;
49
+ //if(el.tagName.toLowerCase() === "g" && el.getAttribute("id") !== null){
50
+ if (el.getAttribute("id") !== null) {
51
+ if (!this.classListMap.has(el.id)) {
52
+ this.classListMap.set(el.id, new Array());
53
+ }
54
+ var classes = (_a = el.getAttribute("class")) === null || _a === void 0 ? void 0 : _a.split(" ");
55
+ classes === null || classes === void 0 ? void 0 : classes.forEach(c => {
56
+ if (!this.classListMap.get(el.id).includes(c)) {
57
+ this.classListMap.get(el.id).push(c.slice());
58
+ }
59
+ });
60
+ }
61
+ });
62
+ return this;
63
+ }
64
+ cacheScales() {
65
+ var svg = document.querySelector("#" + this.containerId);
66
+ if (svg === null) {
67
+ return this;
68
+ }
69
+ this.scaleListMap = new Map();
70
+ svg.querySelectorAll("[transform]").forEach(el => {
71
+ if (el.getAttribute("id") !== null) {
72
+ var tattr = el.getAttribute("transform");
73
+ if (tattr.includes("scale")) {
74
+ if (!this.scaleListMap.has(el.id)) {
75
+ this.scaleListMap.set(el.id, tattr);
76
+ }
77
+ }
78
+ }
79
+ });
80
+ return this;
81
+ }
82
+ copyClassesFromMei(mei) {
83
+ if (this.classListMap == undefined) {
84
+ return this;
85
+ }
86
+ mei.querySelectorAll("score *").forEach(el => {
87
+ var _a;
88
+ if (el.hasAttribute("class")) {
89
+ var id = el.getAttribute("id") || el.getAttribute("xml:id");
90
+ if (!this.classListMap.has(id)) {
91
+ this.classListMap.set(id, new Array());
92
+ }
93
+ var classes = (_a = el.getAttribute("class")) === null || _a === void 0 ? void 0 : _a.split(" ");
94
+ classes === null || classes === void 0 ? void 0 : classes.forEach(c => {
95
+ if (!this.classListMap.get(id).includes(c) && this.allowedMeiClasses.includes(c)) {
96
+ this.classListMap.get(id).push(c.slice());
97
+ }
98
+ });
99
+ el.removeAttribute("class");
100
+ }
101
+ });
102
+ return this;
103
+ }
104
+ /**
105
+ * Reload all the classes which where distributed before
106
+ * @returns this (for chaining convenience)
107
+ */
108
+ loadClasses(element = null) {
109
+ if (this.classListMap == undefined) {
110
+ return this;
111
+ }
112
+ if (element !== null) {
113
+ var value = this.classListMap.get(element.id);
114
+ if (value == undefined)
115
+ return this;
116
+ value.forEach(v => {
117
+ if (v !== "") {
118
+ element.classList.add(v);
119
+ }
120
+ });
121
+ }
122
+ else {
123
+ for (const [key, value] of this.classListMap.entries()) {
124
+ var el = this.container.querySelector("#" + key);
125
+ if (el !== null) {
126
+ //el.removeAttribute("class")
127
+ value.forEach(v => {
128
+ if (v !== "") {
129
+ el.classList.add(v);
130
+ }
131
+ });
132
+ }
133
+ }
134
+ }
135
+ return this;
136
+ }
137
+ loadScales(element = null) {
138
+ if (this.scaleListMap == undefined) {
139
+ return this;
140
+ }
141
+ if (element !== null) {
142
+ var value = this.scaleListMap.get(element.id);
143
+ if (value == undefined)
144
+ return this;
145
+ element.style.transform = value;
146
+ element.setAttribute("transform", value);
147
+ }
148
+ else {
149
+ for (const [key, value] of this.scaleListMap.entries()) {
150
+ var el = this.container.querySelector("#" + key);
151
+ if (el !== null) {
152
+ el.style.transform = value;
153
+ el.setAttribute("transform", value);
154
+ }
155
+ }
156
+ }
157
+ return this;
158
+ }
159
+ repositionSVG(svg) {
160
+ var _a;
161
+ var transformList = ((_a = svg.getAttribute("transform")) === null || _a === void 0 ? void 0 : _a.split(") ")) || new Array();
162
+ console.log(svg.getAttribute("transform"), transformList);
163
+ var hasTranslate = false;
164
+ transformList.forEach((t, i) => {
165
+ if (t.includes("translate")) {
166
+ transformList[i] = "translate(" + this.x + " " + this.y + ")";
167
+ hasTranslate = true;
168
+ }
169
+ if (t.slice(-1) !== ")") {
170
+ transformList[i] = transformList[i] + ")";
171
+ }
172
+ });
173
+ if (!hasTranslate) {
174
+ transformList.push("translate(" + this.x + " " + this.y + ")");
175
+ }
176
+ var trattr = transformList.join(" ");
177
+ console.log(trattr);
178
+ svg.setAttribute("transform", trattr);
179
+ return this;
180
+ }
181
+ /**
182
+ * Merge all tspans in a harm object in the top tspan to avoid columns for (especially in Firefox browsers)
183
+ * @returns
184
+ */
185
+ clearTspan() {
186
+ var gelements = this.container.querySelectorAll("g .harm");
187
+ gelements.forEach(g => {
188
+ var textEl = g.querySelector("text");
189
+ var textTspan = g.querySelectorAll("tspan");
190
+ var text = "";
191
+ if (textTspan.length <= 2) {
192
+ return;
193
+ }
194
+ text = textTspan[0].textContent;
195
+ text = text.replace(/ /g, '');
196
+ text = text.replace(/\n/g, '');
197
+ textEl.querySelector("tspan").firstElementChild.textContent = text;
198
+ textEl.querySelector("tspan").firstElementChild.setAttribute("font-family", "VerovioText");
199
+ textTspan.forEach((tp, idx) => {
200
+ if (idx >= 2) {
201
+ tp.remove();
202
+ }
203
+ });
204
+ });
205
+ return this;
206
+ }
207
+ countBarlines() {
208
+ this.container.querySelectorAll(".barLine").forEach(bl => {
209
+ bl.querySelectorAll("path").forEach((p, idx) => {
210
+ p.setAttribute("n", (idx + 1).toString());
211
+ });
212
+ });
213
+ }
214
+ distributeIds(element, propagation = false) {
215
+ if (propagation) {
216
+ var id = element.id !== "" ? element.id : element.getAttribute("refId");
217
+ Array.from(element.children).forEach(c => {
218
+ var selfId = c.id !== "" ? c.id : c.getAttribute("refId");
219
+ if (selfId === null && id !== null) {
220
+ c.setAttribute("refId", id);
221
+ }
222
+ this.distributeIds(c, true);
223
+ });
224
+ }
225
+ else {
226
+ Array.from(element.querySelectorAll("*")).forEach(el => {
227
+ if (el.id === "") {
228
+ el.setAttribute("id", random_1.uuidv4());
229
+ }
230
+ });
231
+ }
232
+ return this;
233
+ }
234
+ setContainerId(containerId) {
235
+ this.containerId = containerId;
236
+ this.container = document.getElementById(containerId);
237
+ return this;
238
+ }
239
+ setXY(x, y) {
240
+ this.x = x || 0;
241
+ this.y = y || 0;
242
+ //console.log("müssen die koordinaten noch umgerechnet werden???", x, y)
243
+ }
244
+ }
245
+ exports.default = SVGFiller;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });