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,887 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = void 0;
4
+ const VerovioWrapper_1 = require("./utils/VerovioWrapper");
5
+ const random_1 = require("./utils/random");
6
+ const constants_1 = require("./constants");
7
+ const InsertModeHandler_1 = require("./handlers/InsertModeHandler");
8
+ const DeleteHandler_1 = require("./handlers/DeleteHandler");
9
+ const NoteDragHandler_1 = require("./handlers/NoteDragHandler");
10
+ const Mouse2SVG_1 = require("./utils/Mouse2SVG");
11
+ const GlobalKeyboardHandler_1 = require("./handlers/GlobalKeyboardHandler");
12
+ const MusicProcessor_1 = require("./MusicProcessor");
13
+ const meiConverter = require("./utils/MEIConverter");
14
+ const meiOperation = require("./utils/MEIOperations");
15
+ const mei_template_1 = require("./assets/mei_template");
16
+ const SVGEditor_1 = require("./utils/SVGEditor");
17
+ const ScoreGraph_1 = require("./datastructures/ScoreGraph");
18
+ const WindowHandler_1 = require("./handlers/WindowHandler");
19
+ const SidebarHandler_1 = require("./handlers/SidebarHandler");
20
+ const LabelHandler_1 = require("./handlers/LabelHandler");
21
+ const CustomToolbarHandler_1 = require("./handlers/CustomToolbarHandler");
22
+ const cq = require("./utils/convenienceQueries");
23
+ const coordinates = require("./utils/coordinates");
24
+ const TooltipHandler_1 = require("./handlers/TooltipHandler");
25
+ /**
26
+ * The core component the Editor. This manages the database,
27
+ * the verovio toolkit, the cache, and undo/redo stacks.
28
+ */
29
+ class Core {
30
+ constructor(containerId) {
31
+ this.firstStart = true;
32
+ this.noteInputToggle = "on";
33
+ this.reloadDataFunction = (function reloadData() {
34
+ return this.loadData(this.currentMEI, false);
35
+ }).bind(this);
36
+ this.loadDataFunction = (function loadDataFunction(pageURI, data, isUrl) {
37
+ return this.loadData(data, isUrl, { changeOnPageNo: pageURI });
38
+ }).bind(this);
39
+ /**
40
+ * Provides AligFunction for Tabbar. alignFunction will be first set, when musicprocessor will instantiated
41
+ */
42
+ this.alignFunctionCall = (function alignFunction(file) {
43
+ var _a;
44
+ (_a = this.musicProcessor) === null || _a === void 0 ? void 0 : _a.align(file);
45
+ }).bind(this);
46
+ /**
47
+ * Delete array of notes from score
48
+ */
49
+ this.delete = (function d(notes) {
50
+ return new Promise((resolve) => {
51
+ this.getMEI("").then(mei => {
52
+ meiOperation.removeFromMEI(notes, this.currentMEIDoc).then(updatedMEI => {
53
+ if (updatedMEI != undefined) {
54
+ this.loadData(updatedMEI, false).then(() => {
55
+ resolve(true);
56
+ });
57
+ }
58
+ else {
59
+ resolve(true);
60
+ }
61
+ });
62
+ });
63
+ });
64
+ }).bind(this);
65
+ /**
66
+ *
67
+ */
68
+ this.insert = (function insert(newNote, replace = false) {
69
+ this.lastInsertedNoteId = newNote.id;
70
+ this.container.querySelectorAll(".marked").forEach(m => m.classList.remove("marked"));
71
+ return new Promise((resolve, reject) => {
72
+ this.getMEI("").then(mei => {
73
+ var updatedMEI = meiOperation.addToMEI(newNote, this.currentMEIDoc, replace, this.scoreGraph);
74
+ if ((updatedMEI === null || updatedMEI === void 0 ? void 0 : updatedMEI.documentElement.innerHTML.indexOf(newNote.id)) === -1) {
75
+ reject();
76
+ }
77
+ if (updatedMEI != undefined) {
78
+ this.loadData(updatedMEI, false).then(() => {
79
+ resolve(true);
80
+ });
81
+ }
82
+ else {
83
+ reject();
84
+ }
85
+ });
86
+ });
87
+ }).bind(this);
88
+ /**
89
+ * Undo the last action performed on a specific page.
90
+ * @param pageURI - The URI of the selected page.
91
+ * @returns If the action was undone.
92
+ */
93
+ this.undo = (function undo(pageURI = "") {
94
+ return new Promise((resolve) => {
95
+ if (this.container.classList.contains("annotMode")) {
96
+ this.undoAnnotationStacks.pop();
97
+ const annotstate = this.undoAnnotationStacks.pop();
98
+ if (annotstate != undefined) {
99
+ var annotCanvas = this.container.querySelector("#annotationCanvas");
100
+ var annotList = this.container.querySelector("#annotList");
101
+ this.redoAnnotationStacks.push([annotCanvas, annotList]);
102
+ this.undoAnnotationStacks.push([annotCanvas, annotList]);
103
+ annotCanvas.replaceWith(annotstate[0]);
104
+ annotList.replaceWith(annotstate[1]);
105
+ this.keyboardHandler.resetListeners();
106
+ this.container.dispatchEvent(new Event("annotationCanvasChanged"));
107
+ }
108
+ resolve(true);
109
+ return;
110
+ }
111
+ this.undoMEIStacks.pop(); // get rid of currentMEI, since last in line (=initial) MEI is not accessible through verovio
112
+ const meistate = this.undoMEIStacks.pop();
113
+ if (meistate != undefined) {
114
+ this.redoMEIStacks.push(this.currentMEI);
115
+ this.loadData(meistate, false).then(() => resolve(true));
116
+ }
117
+ else {
118
+ resolve(false);
119
+ }
120
+ });
121
+ }).bind(this);
122
+ /**
123
+ * Redo the last action performed on a page.
124
+ * @param pageURI - The page URI.
125
+ * @returns If the action was redone.
126
+ */
127
+ this.redo = (function redo(pageURI = "") {
128
+ return new Promise((resolve) => {
129
+ if (this.container.classList.contains("annotMode")) {
130
+ const annotstate = this.redoAnnotationStacks.pop();
131
+ if (annotstate != undefined) {
132
+ var annotCanvas = this.container.querySelector("#annotationCanvas");
133
+ var annotList = this.container.querySelector("#annotList");
134
+ this.undoAnnotationStacks.push([annotCanvas, annotList]);
135
+ annotCanvas.replaceWith(annotstate[0]);
136
+ annotList.replaceWith(annotstate[1]);
137
+ this.keyboardHandler.resetListeners();
138
+ }
139
+ resolve(true);
140
+ return;
141
+ }
142
+ const meistate = this.redoMEIStacks.pop();
143
+ if (meistate !== undefined) {
144
+ this.undoMEIStacks.push(this.currentMEI);
145
+ this.loadData(meistate, false).then(() => resolve(true));
146
+ }
147
+ else {
148
+ resolve(false);
149
+ }
150
+ });
151
+ }).bind(this);
152
+ this.getElementAttr = (function getElementAttr(id) {
153
+ const message = {
154
+ action: "getElementAttr",
155
+ elementId: id
156
+ };
157
+ return this.verovioWrapper.setMessage(message).attributes;
158
+ }).bind(this);
159
+ this.resetLastInsertedNoteId = function () {
160
+ this.lastInsertedNoteId = undefined;
161
+ }.bind(this);
162
+ this.doHideUI = false;
163
+ this.hideOptions = {};
164
+ this.styleOptions = {};
165
+ this.attributeOptions = {};
166
+ this.containerId = containerId;
167
+ this.container = document.getElementById(containerId);
168
+ this.undoMEIStacks = Array();
169
+ this.redoMEIStacks = new Array();
170
+ this.undoAnnotationStacks = new Array();
171
+ //this.undoAnnotationStacks.push(new Array<Element>())
172
+ this.redoAnnotationStacks = new Array();
173
+ //this.redoAnnotationStacks.push(new Array<Element>())
174
+ this.windowHandler = new WindowHandler_1.default();
175
+ this.svgEditor = new SVGEditor_1.default();
176
+ }
177
+ /**
178
+ * Load data into the verovio toolkit and update the cache.
179
+ */
180
+ loadData(data, isUrl, options = null) {
181
+ this.verovioWrapper = this.verovioWrapper || new VerovioWrapper_1.default();
182
+ var waitingFlag = "waiting";
183
+ if (cq.getVrvSVG(this.containerId) !== null) {
184
+ document.body.classList.add(waitingFlag);
185
+ }
186
+ document.getElementById(this.containerId).dispatchEvent(new Event("loadingStart"));
187
+ var that = this;
188
+ this.svgEditor.setContainerId(this.containerId);
189
+ async function render(pageNo = 1, options = null) {
190
+ return new Promise((resolve, reject) => {
191
+ var message = {
192
+ id: random_1.uuidv4(),
193
+ action: 'renderToSVG',
194
+ pageNo: pageNo
195
+ };
196
+ var response;
197
+ var svg;
198
+ response = that.verovioWrapper.setMessage(message);
199
+ svg = response.svg;
200
+ var svgDoc = new DOMParser().parseFromString(svg, "image/svg+xml");
201
+ var pageElement = svgDoc.querySelector("svg");
202
+ var pageId = "vrvPage" + pageNo.toString();
203
+ pageElement.setAttribute("id", "vrvPage" + pageNo.toString());
204
+ pageElement.classList.add("page");
205
+ try {
206
+ // delete old svg
207
+ if (cq.getVrvSVG(that.containerId).querySelector("#" + pageId) !== null) {
208
+ that.svgEditor.cacheClasses().cacheScales();
209
+ cq.getVrvSVG(that.containerId).querySelector("#" + pageId).innerHTML = ""; //.remove()
210
+ }
211
+ //insert new complete svg
212
+ //document.querySelector("#" + that.containerId + " #vrvSVG").append(pageElement)
213
+ cq.getVrvSVG(that.containerId).querySelector("#" + pageId).replaceWith(pageElement);
214
+ }
215
+ catch (error) {
216
+ document.querySelector("#" + that.containerId + " #vrvSVG").append(pageElement);
217
+ }
218
+ that.svgEditor.distributeIds(pageElement.querySelector(".definition-scale"));
219
+ pageElement.setAttribute("preserveAspectRatio", "xMinYMin meet");
220
+ var systemHeigth = pageElement.querySelector(".system").getBoundingClientRect().height;
221
+ systemHeigth += systemHeigth * 0.2;
222
+ that.verovioWrapper.setHeightValue(systemHeigth);
223
+ resolve();
224
+ });
225
+ }
226
+ //END ASYNC FUNCTION RENDER
227
+ return new Promise((resolve, reject) => {
228
+ var _a, _b, _c, _d, _e;
229
+ var d;
230
+ var u;
231
+ var type = data === null || data === void 0 ? void 0 : data.constructor.name;
232
+ switch (type) {
233
+ case 'String':
234
+ data = meiConverter.reformatMEI(data);
235
+ d = data;
236
+ u = isUrl;
237
+ break;
238
+ case 'XMLDocument':
239
+ data = meiOperation.disableFeatures(["grace", "arpeg"], data); // for Debugging
240
+ that.svgEditor.copyClassesFromMei(data);
241
+ d = new XMLSerializer().serializeToString(data);
242
+ u = false;
243
+ break;
244
+ case 'HTMLUnknownElement':
245
+ d = new XMLSerializer().serializeToString(data);
246
+ u = false;
247
+ break;
248
+ case undefined:
249
+ d = new mei_template_1.default().emptyMEI();
250
+ u = false;
251
+ break;
252
+ default:
253
+ reject("Wrong Datatype: " + type);
254
+ break;
255
+ }
256
+ //just render the data once to make pagecount accessible
257
+ var message = {
258
+ id: random_1.uuidv4(),
259
+ action: 'renderData',
260
+ mei: d,
261
+ isUrl: u
262
+ };
263
+ this.verovioWrapper.setMessage(message);
264
+ var pageGroup = document.createElement("g");
265
+ pageGroup.setAttribute("id", "vrvSVG");
266
+ if (cq.getVrvSVG(that.containerId) !== null) {
267
+ that.svgEditor.cacheClasses().cacheScales();
268
+ //cq.getVrvSVG(that.containerId).remove()
269
+ }
270
+ if (!cq.getVrvSVG(that.containerId))
271
+ document.querySelector("#" + that.containerId + "> #svgContainer").append(pageGroup);
272
+ var pageCount = this.verovioWrapper.getToolkit().getPageCount();
273
+ var renderPromises = new Array();
274
+ var staffId = (_c = (_b = (_a = this.m2s) === null || _a === void 0 ? void 0 : _a.getLastMouseEnter()) === null || _b === void 0 ? void 0 : _b.staff) === null || _c === void 0 ? void 0 : _c.getAttribute("refId");
275
+ var optionPage;
276
+ if ((options === null || options === void 0 ? void 0 : options.changeOnPageNo) != undefined) {
277
+ if (options.changeOnPageNo === "last") {
278
+ optionPage = pageCount;
279
+ }
280
+ else {
281
+ optionPage = parseInt(options.changeOnPageNo);
282
+ }
283
+ }
284
+ //remove all pages, that do not exist anymore
285
+ cq.getVrvSVG(this.containerId).querySelectorAll(":scope > svg").forEach(svg => {
286
+ if (parseInt(svg.id.match(/\d+/)[0]) > pageCount) {
287
+ svg.remove();
288
+ }
289
+ });
290
+ var changeOnPage = optionPage || parseInt((_e = (_d = cq.getVrvSVG(this.containerId).querySelector("#" + staffId)) === null || _d === void 0 ? void 0 : _d.closest(".page")) === null || _e === void 0 ? void 0 : _e.id.split("").reverse()[0]);
291
+ Array.from({ length: pageCount }, (_, index) => index + 1).forEach(pageNo => {
292
+ if (!isNaN(changeOnPage)) {
293
+ if (pageNo < changeOnPage)
294
+ return;
295
+ }
296
+ renderPromises.push(setTimeout(function () { render(pageNo, options); }, 1));
297
+ });
298
+ Promise.all(renderPromises).then(() => {
299
+ document.body.classList.remove(waitingFlag);
300
+ var that = this;
301
+ setTimeout(function () {
302
+ var _a, _b;
303
+ that.svgEditor.drawLinesUnderSystems();
304
+ that.svgEditor.modifyHarm();
305
+ that.createSVGOverlay(true);
306
+ that.svgEditor.setXY((_a = that.windowHandler) === null || _a === void 0 ? void 0 : _a.getX(), (_b = that.windowHandler) === null || _b === void 0 ? void 0 : _b.getY());
307
+ that.getMEI("").then(mei => {
308
+ var _a;
309
+ that.currentMEI = mei;
310
+ that.currentMEIDoc = that.getCurrentMEI(true);
311
+ that.svgEditor.markOverfilledMeasures(that.currentMEIDoc);
312
+ //console.log(that.currentMEIDoc)
313
+ that.svgEditor
314
+ .setContainerId(that.containerId)
315
+ .loadClasses()
316
+ .fillSVG(that.currentMEIDoc);
317
+ that.undoMEIStacks.push(mei);
318
+ var lastAddedClass = "lastAdded";
319
+ document.querySelectorAll("." + lastAddedClass).forEach(m => {
320
+ m.classList.remove(lastAddedClass);
321
+ });
322
+ if (that.lastInsertedNoteId != undefined && ["textmode", "clickmode"].some(mode => that.container.classList.contains(mode))) {
323
+ (_a = that.container.querySelector("#" + that.lastInsertedNoteId)) === null || _a === void 0 ? void 0 : _a.classList.add(lastAddedClass);
324
+ }
325
+ if (that.meiChangedCallback != undefined) {
326
+ that.meiChangedCallback(that.currentMEI);
327
+ }
328
+ });
329
+ //musicProcessor stuff
330
+ that.getMidi().then(midi => {
331
+ that.musicProcessor = that.musicProcessor || new MusicProcessor_1.default(that.containerId);
332
+ that.musicProcessor
333
+ .setMEI(that.currentMEIDoc)
334
+ .setMidi(midi)
335
+ .addCanvas();
336
+ that.getMidiTimesForSymbols().then(md => {
337
+ var _a;
338
+ that.musicProcessor.setMidiTimes(md);
339
+ that.musicProcessor.update();
340
+ that.scoreGraph = new ScoreGraph_1.default(that.currentMEIDoc, that.containerId, md);
341
+ //the first condition should only occur at first starting the score editor
342
+ if (that.container.querySelector(".lastAdded") === null && that.scoreGraph.getCurrentNode() == undefined) {
343
+ that.scoreGraph.setCurrentNodeById(that.container.querySelector(".staff > .layer :is(.note, .rest, .mRest").id);
344
+ }
345
+ else { //second condition always sets lastAdded Note
346
+ that.scoreGraph.setCurrentNodeById((_a = that.container.querySelector(".lastAdded")) === null || _a === void 0 ? void 0 : _a.id);
347
+ }
348
+ that.initializeHandlers();
349
+ that.musicProcessor.setScoreGraph(that.scoreGraph);
350
+ document.getElementById(that.containerId).dispatchEvent(new Event("loadingEnd"));
351
+ that.svg = new XMLSerializer().serializeToString(that.container.querySelector("#svgContainer"));
352
+ console.log(that.currentMEIDoc, that.m2s.getMeasureMatrix());
353
+ resolve(that.currentMEI);
354
+ });
355
+ });
356
+ }, 1);
357
+ });
358
+ });
359
+ }
360
+ /**
361
+ * Initialize Handlers
362
+ */
363
+ initializeHandlers() {
364
+ //must be first!!!
365
+ if (this.m2s == undefined) {
366
+ this.m2s = new Mouse2SVG_1.Mouse2SVG();
367
+ }
368
+ else {
369
+ //this.m2s.update()
370
+ }
371
+ this.m2s
372
+ .setContainerId(this.containerId)
373
+ .setUpdateOverlayCallback(this.createSVGOverlay)
374
+ .setCurrentMEI(this.currentMEIDoc)
375
+ .update();
376
+ //.setMouseEnterElementListeners()
377
+ this.insertModeHandler = this.insertModeHandler || new InsertModeHandler_1.default(this.containerId);
378
+ this.deleteHandler = this.deleteHandler || new DeleteHandler_1.default(this.containerId);
379
+ this.noteDragHandler = new NoteDragHandler_1.default(this.containerId);
380
+ this.globalKeyboardHandler = this.globalKeyboardHandler || new GlobalKeyboardHandler_1.default(this.containerId);
381
+ this.sidebarHandler = this.sidebarHandler || new SidebarHandler_1.default();
382
+ this.labelHandler = this.labelHandler || new LabelHandler_1.default(this.containerId);
383
+ this.modHandler = this.modHandler || new CustomToolbarHandler_1.default(this.containerId);
384
+ this.tooltipHandler = this.tooltipHandler || new TooltipHandler_1.default();
385
+ this.dispatchFunctions();
386
+ }
387
+ /**
388
+ * distribute Callback functions for each element which uses some information from of the Core (Handlers, musicProcessor, Callbacks, etc)
389
+ */
390
+ dispatchFunctions() {
391
+ this.labelHandler
392
+ .setContainerId(this.containerId)
393
+ .setCurrentMEI(this.currentMEIDoc)
394
+ .reset();
395
+ this.insertModeHandler
396
+ .setContainerId(this.containerId)
397
+ .setScoreGraph(this.scoreGraph)
398
+ .setm2s(this.m2s)
399
+ .setMusicProcessor(this.musicProcessor)
400
+ .setDeleteHandler(this.deleteHandler)
401
+ .setLabelHandler(this.labelHandler)
402
+ .activateHarmonyMode()
403
+ .activateSelectionMode()
404
+ .setInsertCallback(this.insert)
405
+ .setDeleteCallback(this.delete)
406
+ .setLoadDataCallback(this.loadDataFunction)
407
+ .setUndoAnnotationStacks(this.undoAnnotationStacks)
408
+ .resetModes()
409
+ .resetCanvas();
410
+ this.noteInputSwitch(this.noteInputToggle);
411
+ this.deleteHandler
412
+ .setContainerId(this.containerId)
413
+ .setDeleteCallback(this.delete)
414
+ .update();
415
+ this.noteDragHandler
416
+ .setContainerId(this.containerId)
417
+ .setCurrentMEI(this.currentMEIDoc)
418
+ .setInsertCallback(this.insert)
419
+ .setMusicProcessor(this.musicProcessor)
420
+ .setm2s(this.m2s)
421
+ .resetListeners();
422
+ this.globalKeyboardHandler
423
+ .setContainerId(this.containerId)
424
+ .setUndoCallback(this.undo)
425
+ .setRedoCallback(this.redo)
426
+ .setCurrentMei(this.currentMEIDoc)
427
+ .setMusicProcessor(this.musicProcessor)
428
+ .setHarmonyHandlerCallback(this.labelHandler.setHarmonyLabelHandlerKey)
429
+ .setLoadDataCallback(this.loadDataFunction)
430
+ .setScoreGraph(this.scoreGraph)
431
+ .resetLastInsertedNoteCallback(this.resetLastInsertedNoteId)
432
+ .resetListeners();
433
+ this.sidebarHandler
434
+ .setContainerId(this.containerId)
435
+ .setCurrentMei(this.currentMEIDoc)
436
+ .setm2s(this.m2s)
437
+ .setLoadDataCallback(this.loadDataFunction)
438
+ .loadMeter()
439
+ .makeScoreElementsClickable()
440
+ .resetListeners();
441
+ this.modHandler
442
+ .setContainerId(this.containerId)
443
+ .resetListeners()
444
+ .setCurrentMEI(this.currentMEIDoc)
445
+ .setLoadDataCallback(this.loadDataFunction);
446
+ this.windowHandler
447
+ .setContainerId(this.containerId)
448
+ .setm2s(this.m2s)
449
+ .setCurrentMEI(this.currentMEIDoc)
450
+ .setLoadDataCallback(this.loadDataFunction)
451
+ .setSVGReloadCallback(this.reloadDataFunction)
452
+ .setAnnotations(this.insertModeHandler.getAnnotations())
453
+ .setInsertModeHandler(this.insertModeHandler)
454
+ .resetListeners();
455
+ this.tooltipHandler
456
+ .setContainerId(this.containerId)
457
+ .removeListeners()
458
+ .setListeners();
459
+ // always start from click mode
460
+ if (this.firstStart) {
461
+ this.container.querySelector("#notationTabBtn").click();
462
+ this.firstStart = false;
463
+ }
464
+ if (this.doHideUI) {
465
+ this.hideUI(this.hideOptions);
466
+ }
467
+ else {
468
+ this.viewUI(this.hideOptions);
469
+ }
470
+ if (Object.entries(this.styleOptions).length > 0) {
471
+ this.setStyles(this.styleOptions);
472
+ }
473
+ if (Object.entries(this.attributeOptions).length > 0) {
474
+ this.setAttributes(this.attributeOptions);
475
+ }
476
+ }
477
+ ////// VEROVIO REQUESTS /////////////////
478
+ /**
479
+ * Get the MEI for a specific page.
480
+ * @param pageURI - The URI of the selected page.
481
+ */
482
+ getMEI(pageURI) {
483
+ return new Promise((resolve, reject) => {
484
+ const message = {
485
+ action: "getMEI",
486
+ id: random_1.uuidv4()
487
+ };
488
+ var response;
489
+ response = this.verovioWrapper.setMessage(message);
490
+ if (response.mei) {
491
+ this.currentMEI = response.mei;
492
+ }
493
+ else {
494
+ //console.log(meiConverter.meiToDoc(response.mei))
495
+ }
496
+ resolve(response.mei);
497
+ });
498
+ }
499
+ getMidi() {
500
+ return new Promise((resolve, reject) => {
501
+ const message = {
502
+ action: "renderToMidi",
503
+ id: random_1.uuidv4()
504
+ };
505
+ var response = this.verovioWrapper.setMessage(message);
506
+ if (response.midi) {
507
+ this.currentMidi = response.mei;
508
+ resolve(response.midi);
509
+ }
510
+ else {
511
+ reject("fail!");
512
+ }
513
+ });
514
+ }
515
+ /**
516
+ * Get all times (tick position) for each event visible in the score (notes, rests, etc.)
517
+ * @returns
518
+ */
519
+ getMidiTimesForSymbols() {
520
+ return new Promise((resolve) => {
521
+ var noteTimes = new Map();
522
+ var that = this;
523
+ var container = cq.getVrvSVG(this.containerId);
524
+ var midi = that.verovioWrapper.getMidiJSON();
525
+ var tracks = midi.tracks;
526
+ tracks.forEach((t, tIdx) => {
527
+ var svgNotes = container.querySelectorAll(".staff[n=\"" + (tIdx + 1).toString() + "\"] .note");
528
+ var prevNote;
529
+ t.notes.forEach((n, nIdx) => {
530
+ if (!noteTimes.has(n.ticks)) {
531
+ noteTimes.set(n.ticks, new Array());
532
+ }
533
+ var arr = noteTimes.get(n.ticks);
534
+ var currNote = svgNotes[nIdx];
535
+ //indicaton, that some rests are in between
536
+ //trailing rests are intentionally left out, since there is nothing to play anyway
537
+ if ((prevNote === null || prevNote === void 0 ? void 0 : prevNote.midi.ticks) + (prevNote === null || prevNote === void 0 ? void 0 : prevNote.midi.durationTicks) != n.ticks) {
538
+ var elements = container.querySelectorAll(".staff[n=\"" + (tIdx + 1).toString() + "\"] .note, .staff[n=\"" + (tIdx + 1).toString() + "\"] .rest");
539
+ var elementIds = Array.from(elements).map(e => e.id);
540
+ var sliceLeft = prevNote == undefined && n.ticks > 0 ? 0 : undefined;
541
+ sliceLeft = prevNote != undefined ? elementIds.findIndex(eid => eid === prevNote.svg.id) + 1 : 0;
542
+ var sliceRight = elementIds.findIndex(eid => eid === currNote.id) - 1;
543
+ var slicedElementIds = elementIds.slice(sliceLeft, sliceRight);
544
+ var currentTickPos = (prevNote === null || prevNote === void 0 ? void 0 : prevNote.midi.ticks) + (prevNote === null || prevNote === void 0 ? void 0 : prevNote.midi.durationTicks) || 0;
545
+ slicedElementIds.forEach(id => {
546
+ var ratio = meiOperation.getAbsoluteRatio(this.currentMEIDoc.getElementById(id));
547
+ var tickDur = 4 * ratio * midi.header.ppq;
548
+ if (!noteTimes.has(currentTickPos)) {
549
+ noteTimes.set(currentTickPos, new Array());
550
+ }
551
+ var restArr = noteTimes.get(currentTickPos);
552
+ restArr.push(container.querySelector("#" + id));
553
+ currentTickPos += tickDur;
554
+ });
555
+ }
556
+ arr.push(currNote);
557
+ prevNote = {
558
+ midi: n,
559
+ svg: svgNotes[nIdx]
560
+ };
561
+ });
562
+ });
563
+ resolve(noteTimes);
564
+ });
565
+ }
566
+ /**
567
+ * Create an overlay of all interative elements over the the score svg.
568
+ */
569
+ createSVGOverlay(loadBBoxes = true) {
570
+ return new Promise((resolve) => {
571
+ var _a;
572
+ document.getElementById(this.containerId).focus();
573
+ var refSVG = document.getElementById(this.containerId).querySelector("#vrvSVG");
574
+ this.interactionOverlay = document.getElementById(this.containerId).querySelector("#interactionOverlay");
575
+ if (this.interactionOverlay === null) {
576
+ var overlay = document.createElementNS(constants_1.constants._SVGNS_, "svg");
577
+ overlay.setAttribute("id", "interactionOverlay");
578
+ this.interactionOverlay = overlay;
579
+ }
580
+ var svgContainer = document.getElementById(this.containerId).querySelector("#svgContainer");
581
+ var vrvContainer = cq.getVrvSVG(this.containerId);
582
+ var root = svgContainer.getBoundingClientRect().height > vrvContainer.getBoundingClientRect().height ? svgContainer : vrvContainer;
583
+ var rootBBox = root.getBoundingClientRect();
584
+ var rootWidth = (rootBBox.width).toString();
585
+ var rootHeigth = (rootBBox.height).toString();
586
+ //if (this.interactionOverlay.getAttribute("viewBox") === null) {
587
+ this.interactionOverlay.setAttribute("viewBox", ["0", "0", rootWidth, rootHeigth].join(" "));
588
+ //}
589
+ (_a = document.getElementById(this.containerId).querySelector("#interactionOverlay #scoreRects")) === null || _a === void 0 ? void 0 : _a.remove();
590
+ var scoreRects = document.createElementNS(constants_1.constants._SVGNS_, "svg");
591
+ scoreRects.setAttribute("id", "scoreRects");
592
+ scoreRects.setAttribute("viewBox", ["0", "0", rootWidth, rootHeigth].join(" "));
593
+ Array.from(refSVG.attributes).forEach(a => {
594
+ if (!["id", "width", "height"].includes(a.name)) {
595
+ this.interactionOverlay.setAttribute(a.name, a.value);
596
+ }
597
+ });
598
+ this.interactionOverlay.appendChild(scoreRects);
599
+ refSVG.insertAdjacentElement("beforebegin", this.interactionOverlay);
600
+ if (loadBBoxes) {
601
+ var svgBoxes = Array.from(document.getElementById(this.containerId)
602
+ .querySelectorAll(".definition-scale :is(g,path)")) //".definition-scale path, .definition-scale .bounding-box"))
603
+ .filter(el => {
604
+ var condition = !["system", "measure", "layer", "ledgerLines", "flag"].some(cn => el.classList.contains(cn));
605
+ return condition;
606
+ });
607
+ var reorderedBoxes = new Array(); // reorder so that dependent elements are already in array
608
+ svgBoxes.forEach(sb => {
609
+ if (sb.querySelector(":scope > use, :scope > rect, :scope > path") === null) {
610
+ reorderedBoxes.push(sb);
611
+ }
612
+ else {
613
+ reorderedBoxes.unshift(sb);
614
+ }
615
+ });
616
+ // staff always has to be on top of sibling elements, so that one can interact with score elements
617
+ reorderedBoxes = reorderedBoxes.reverse();
618
+ async function computeCoords(box, interactionOverlay) {
619
+ return new Promise((resolve) => {
620
+ var g = document.createElementNS(constants_1.constants._SVGNS_, "g");
621
+ var refId = box.id !== "" ? box.id : box.getAttribute("refId");
622
+ if (refId !== "" && refId !== null) {
623
+ g.setAttribute("refId", refId);
624
+ }
625
+ box.classList.forEach(c => g.classList.add(c));
626
+ var bbox = box.getBoundingClientRect();
627
+ var cc = coordinates.getDOMMatrixCoordinates(bbox, interactionOverlay);
628
+ var rect = document.createElementNS(constants_1.constants._SVGNS_, "rect");
629
+ rect.setAttribute("x", cc.left.toString());
630
+ rect.setAttribute("y", cc.top.toString());
631
+ var w;
632
+ if (cc.width === 0)
633
+ w = 2;
634
+ rect.setAttribute("width", (w === null || w === void 0 ? void 0 : w.toString()) || cc.width.toString());
635
+ var h;
636
+ if (cc.height === 0)
637
+ h = 2;
638
+ rect.setAttribute("height", (h === null || h === void 0 ? void 0 : h.toString()) || cc.height.toString());
639
+ g.appendChild(rect);
640
+ scoreRects.append(g);
641
+ resolve(true);
642
+ });
643
+ }
644
+ var coordPromises = new Array();
645
+ reorderedBoxes.forEach(sr => {
646
+ if (!["g", "path"].includes(sr.tagName.toLowerCase())) {
647
+ return;
648
+ }
649
+ else if (Array.from(sr.classList).some(srcl => srcl.includes("page") || srcl.includes("system"))) {
650
+ return;
651
+ }
652
+ else {
653
+ coordPromises.push(computeCoords(sr, this.interactionOverlay));
654
+ }
655
+ });
656
+ setTimeout(function () { Promise.all(coordPromises); }, 1);
657
+ }
658
+ resolve(true);
659
+ });
660
+ }
661
+ replaceWithRect(el) {
662
+ if (!["g", "path", "svg"].includes(el.tagName.toLowerCase())) {
663
+ el.remove();
664
+ return;
665
+ }
666
+ if (el.childElementCount > 0) {
667
+ Array.from(el.children).forEach(ec => {
668
+ this.replaceWithRect(ec);
669
+ });
670
+ }
671
+ if ("svg" !== el.tagName.toLowerCase()) {
672
+ var childCopy = new Array();
673
+ Array.from(el.children).forEach(ec => childCopy.push(ec.cloneNode(true)));
674
+ var bbox = el.getBoundingClientRect();
675
+ var rect = document.createElementNS(constants_1.constants._SVGNS_, "rect");
676
+ rect.setAttribute("refId", el.id);
677
+ el.classList.forEach(c => rect.classList.add(c));
678
+ var cc = coordinates.getDOMMatrixCoordinates(bbox, this.interactionOverlay);
679
+ rect.setAttribute("x", cc.left.toString());
680
+ rect.setAttribute("y", cc.top.toString());
681
+ var w;
682
+ if (cc.width === 0)
683
+ w = 2;
684
+ rect.setAttribute("width", (w === null || w === void 0 ? void 0 : w.toString()) || cc.width.toString());
685
+ var h;
686
+ if (cc.height === 0)
687
+ h = 2;
688
+ rect.setAttribute("height", (h === null || h === void 0 ? void 0 : h.toString()) || cc.height.toString());
689
+ childCopy.forEach(cc => rect.appendChild(childCopy.shift()));
690
+ el.insertAdjacentElement("beforebegin", rect);
691
+ el.remove();
692
+ }
693
+ }
694
+ /**
695
+ * hide ui elements, so that no interaction is possible
696
+ * should be best called after promise of loadData
697
+ * @param options
698
+ */
699
+ hideUI(options = {}) {
700
+ var _a, _b, _c;
701
+ if (Object.entries(options).length === 0) {
702
+ options = { annotationCanvas: true, labelCanvas: true, canvasMusicPlayer: true, scoreRects: true, manipulatorCanvas: true, sidebarContainer: true, btnToolbar: true, customToolbar: true, groups: true };
703
+ }
704
+ for (const [key, value] of Object.entries(options)) {
705
+ if (value) {
706
+ if (key === "groups") {
707
+ ((_a = document.getElementById(this.containerId)) === null || _a === void 0 ? void 0 : _a.querySelectorAll("[role=\"group\"]")).forEach(g => g.classList.add("hideUI")); // style.setProperty("display", "none", "important"))
708
+ }
709
+ else {
710
+ (_c = (_b = document.getElementById(this.containerId)) === null || _b === void 0 ? void 0 : _b.querySelector("#" + key)) === null || _c === void 0 ? void 0 : _c.classList.add("hideUI"); //style.setProperty("display", "none", "important")
711
+ }
712
+ }
713
+ }
714
+ }
715
+ /**
716
+ * View Ui elements if they where hidden earlier
717
+ * @param options
718
+ */
719
+ viewUI(options = {}) {
720
+ var _a, _b, _c;
721
+ if (Object.entries(options).length === 0) {
722
+ options = { annotationCanvas: true, labelCanvas: true, canvasMusicPlayer: true, scoreRects: true, manipulatorCanvas: true, sidebarContainer: true, btnToolbar: true, customToolbar: true, groups: true };
723
+ }
724
+ for (const [key, value] of Object.entries(options)) {
725
+ if (value) {
726
+ if (key === "groups") {
727
+ ((_a = document.getElementById(this.containerId)) === null || _a === void 0 ? void 0 : _a.querySelectorAll("[role=\"group\"]")).forEach(g => g.classList.remove("hideUI")); // style.setProperty("display", "none", "important"))
728
+ }
729
+ else {
730
+ (_c = (_b = document.getElementById(this.containerId)) === null || _b === void 0 ? void 0 : _b.querySelector("#" + key)) === null || _c === void 0 ? void 0 : _c.classList.remove("hideUI"); //style.setProperty("display", "none", "important")
731
+ }
732
+ }
733
+ }
734
+ }
735
+ /**
736
+ * Note Input will be disabled. All other interactions stay active.
737
+ */
738
+ noteInputSwitch(toggle) {
739
+ var _a, _b, _c, _d;
740
+ this.noteInputToggle = toggle;
741
+ if (toggle === "off") {
742
+ (_a = this.insertModeHandler) === null || _a === void 0 ? void 0 : _a.disableNoteInput();
743
+ (_b = this.noteDragHandler) === null || _b === void 0 ? void 0 : _b.removeListeners();
744
+ }
745
+ else if (toggle === "on") {
746
+ (_c = this.insertModeHandler) === null || _c === void 0 ? void 0 : _c.enableNoteInput();
747
+ (_d = this.noteDragHandler) === null || _d === void 0 ? void 0 : _d.setListeners();
748
+ }
749
+ else {
750
+ console.log(arguments.callee.name, toggle + " has no effect!");
751
+ }
752
+ }
753
+ ////////// GETTER/ SETTER
754
+ /**
755
+ *
756
+ * @returns current Mouse2SVG Instance
757
+ */
758
+ getMouse2SVG() {
759
+ return this.m2s;
760
+ }
761
+ getDeleteHandler() {
762
+ return this.deleteHandler;
763
+ }
764
+ getInsertModeHandler() {
765
+ return this.insertModeHandler;
766
+ }
767
+ getCurrentMEI(asDocument = true) {
768
+ if (asDocument) {
769
+ var meiDoc = meiConverter.meiToDoc(this.currentMEI);
770
+ meiDoc = meiConverter.standardizeAccid(meiDoc);
771
+ return meiDoc;
772
+ }
773
+ return this.currentMEI;
774
+ }
775
+ /**
776
+ * Get SVG of the current container.
777
+ * @param {boolean} [plain=true] - delete classes which would result in coloration of the score
778
+ * @returns {string} - serialized svg
779
+ */
780
+ getSVG(plain = true) {
781
+ var svgDom = this.container.querySelector("#svgContainer");
782
+ if (plain) {
783
+ svgDom.querySelectorAll(".lastAdded, .marked").forEach(sd => {
784
+ sd.classList.remove("lastAdded");
785
+ sd.classList.remove("marked");
786
+ });
787
+ }
788
+ return new XMLSerializer().serializeToString(svgDom);
789
+ }
790
+ getNoteDragHandler() {
791
+ return this.noteDragHandler;
792
+ }
793
+ getGlobalKeyboardHandler() {
794
+ return this.globalKeyboardHandler;
795
+ }
796
+ getSidebarHandler() {
797
+ return this.sidebarHandler;
798
+ }
799
+ getLabelHandler() {
800
+ return this.labelHandler;
801
+ }
802
+ getModifierHandler() {
803
+ return this.modHandler;
804
+ }
805
+ getWindowHandler() {
806
+ return this.windowHandler;
807
+ }
808
+ getCurrentMidi() {
809
+ return this.currentMidi;
810
+ }
811
+ getMusicProcessor() {
812
+ return this.musicProcessor;
813
+ }
814
+ getScoreGraph() {
815
+ return this.scoreGraph;
816
+ }
817
+ getContainer() {
818
+ return this.container;
819
+ }
820
+ /**
821
+ * Access Verovio from outside of score editor.
822
+ * Use getToolkit method to access any method which is not wrapped
823
+ * @returns VerovioWrapper instance
824
+ */
825
+ getVerovioWrapper() {
826
+ return this.verovioWrapper;
827
+ }
828
+ setMEIChangedCallback(meiChangedCallback) {
829
+ this.meiChangedCallback = meiChangedCallback;
830
+ }
831
+ setHideUI(hide) {
832
+ this.doHideUI = hide;
833
+ }
834
+ setHideOptions(options) {
835
+ this.hideOptions = options;
836
+ }
837
+ /**
838
+ * Set Attibutes for any element in the result svg as {selector: {attributeName: [values as string]}}.
839
+ * By default will be concatenated with spaces as value string for this attribute
840
+ * @param options
841
+ * @param separator optional separator, default: " "
842
+ */
843
+ setAttributes(options, separator = " ") {
844
+ var svg = cq.getVrvSVG(this.containerId);
845
+ for (const [elKey, elValue] of Object.entries(options)) {
846
+ var element = svg.querySelector(elKey);
847
+ if (element !== null) {
848
+ for (const [attrKey, attrValue] of Object.entries(elValue)) {
849
+ element.setAttribute(attrKey, attrValue.join(separator));
850
+ }
851
+ }
852
+ }
853
+ }
854
+ setAttributeOptions(options) {
855
+ this.attributeOptions = options;
856
+ return this;
857
+ }
858
+ /**
859
+ * Set Styles for any element in the result svg as {selector: {attributeName: [values as string]}}.
860
+ * By default will be concatenated with spaces as value string for this attribute
861
+ * @param options
862
+ * @param separator optional separator, default: " "
863
+ */
864
+ setStyles(options, separator = " ") {
865
+ var svg = cq.getVrvSVG(this.containerId);
866
+ for (const [elKey, elValue] of Object.entries(options)) {
867
+ var element = svg.querySelector(elKey);
868
+ if (element !== null) {
869
+ for (const [styleKey, styleValue] of Object.entries(elValue)) {
870
+ var importantIdx = styleValue.indexOf("important");
871
+ if (importantIdx === -1) {
872
+ element.style.setProperty(styleKey, styleValue.join(separator));
873
+ }
874
+ else {
875
+ var important = styleValue.splice(importantIdx, 1)[0];
876
+ element.style.setProperty(styleKey, styleValue.join(separator), important);
877
+ }
878
+ }
879
+ }
880
+ }
881
+ }
882
+ setStyleOptions(options) {
883
+ this.styleOptions = options;
884
+ return this;
885
+ }
886
+ }
887
+ exports.default = Core;