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,278 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cq = require("../utils/convenienceQueries");
4
+ const meiConverter = require("../utils/MEIConverter");
5
+ class WindowHandler {
6
+ constructor() {
7
+ this.updateFunction = this.update.bind(this);
8
+ /**
9
+ * Reload svg when registered events ended
10
+ */
11
+ this.reloadTimer = new Array();
12
+ this.reloadSVGFunction = this.reloadSVG.bind(this);
13
+ this.toggleCTRLFunction = this.toggleCTRL.bind(this);
14
+ this.deltaTemp = 1;
15
+ this.zoomTimer = new Array();
16
+ this.wheelZoomFunction = this.wheelZoom.bind(this);
17
+ this.clickZoomFunction = this.clickZoom.bind(this);
18
+ this.cacheContainerAttrFunction = this.cacheContainerAttr.bind(this);
19
+ this.loadContainerAttrFunction = this.loadContainerAttr.bind(this);
20
+ this.ctrlPressed = false;
21
+ this.w = window;
22
+ while (this.w !== this.w.parent) {
23
+ this.w = this.w.parent;
24
+ }
25
+ this.scrollingTimer = new Array();
26
+ }
27
+ setListeners() {
28
+ this.eventContainer = this.container;
29
+ window.addEventListener("scroll", this.updateFunction);
30
+ //window.addEventListener("resize", this.update)
31
+ //this.w.addEventListener("resize", this.reloadSVGFunction)
32
+ this.w.addEventListener("deviceorientation", this.updateFunction);
33
+ this.eventContainer.querySelector("#sidebarContainer").addEventListener("transitionend", this.updateFunction);
34
+ //this.eventContainer.querySelector("#sidebarContainer").addEventListener("transitionend", this.reloadSVGFunction)
35
+ this.eventContainer.querySelector("#sidebarContainer").addEventListener("resizemove", this.updateFunction);
36
+ //this.eventContainer.querySelector("#sidebarContainer").addEventListener("resizemove", this.reloadSVGFunction)
37
+ this.vrvSVG.addEventListener("scroll", this.updateFunction);
38
+ //this.vrvSVG.addEventListener("resize", this.update)
39
+ this.vrvSVG.addEventListener("deviceorientation", this.updateFunction);
40
+ document.addEventListener("fullscreenchange", this.updateFunction);
41
+ this.eventContainer.addEventListener("wheel", this.wheelZoomFunction);
42
+ this.eventContainer.querySelectorAll("#zoomGroup > button").forEach(b => b.addEventListener("click", this.clickZoomFunction));
43
+ document.addEventListener("keydown", this.toggleCTRLFunction);
44
+ document.addEventListener("keyup", this.toggleCTRLFunction);
45
+ this.eventContainer.addEventListener("loadingStart", this.cacheContainerAttrFunction);
46
+ this.eventContainer.addEventListener("loadingEnd", this.loadContainerAttrFunction);
47
+ return this;
48
+ }
49
+ removeListeners() {
50
+ var _a, _b, _c, _d, _e, _f, _g, _h;
51
+ window.removeEventListener("scroll", this.updateFunction);
52
+ this.w.removeEventListener("resize", this.updateFunction);
53
+ this.w.removeEventListener("resize", this.reloadSVGFunction);
54
+ this.w.removeEventListener("deviceorientation", this.updateFunction);
55
+ (_a = this.eventContainer) === null || _a === void 0 ? void 0 : _a.querySelector("#sidebarContainer").removeEventListener("transitionend", this.updateFunction);
56
+ (_b = this.eventContainer) === null || _b === void 0 ? void 0 : _b.querySelector("#sidebarContainer").removeEventListener("transitionend", this.reloadSVGFunction);
57
+ (_c = this.eventContainer) === null || _c === void 0 ? void 0 : _c.querySelector("#sidebarContainer").removeEventListener("resizemove", this.updateFunction);
58
+ (_d = this.eventContainer) === null || _d === void 0 ? void 0 : _d.querySelector("#sidebarContainer").removeEventListener("resizemove", this.reloadSVGFunction);
59
+ this.vrvSVG.removeEventListener("scroll", this.updateFunction);
60
+ //this.vrvSVG.removeEventListener("resize", this.update)
61
+ this.vrvSVG.removeEventListener("deviceorientation", this.updateFunction);
62
+ document.removeEventListener("fullscreenchange", this.updateFunction);
63
+ (_e = this.eventContainer) === null || _e === void 0 ? void 0 : _e.removeEventListener("wheel", this.wheelZoomFunction);
64
+ (_f = this.eventContainer) === null || _f === void 0 ? void 0 : _f.querySelectorAll("#zoomGroup > button").forEach(b => b.removeEventListener("click", this.clickZoomFunction));
65
+ document.removeEventListener("keydown", this.toggleCTRLFunction);
66
+ document.removeEventListener("keyup", this.toggleCTRLFunction);
67
+ (_g = this.eventContainer) === null || _g === void 0 ? void 0 : _g.removeEventListener("loadingStart", this.cacheContainerAttrFunction);
68
+ (_h = this.eventContainer) === null || _h === void 0 ? void 0 : _h.removeEventListener("loadingEnd", this.loadContainerAttrFunction);
69
+ return this;
70
+ }
71
+ /**
72
+ * Update all elements that are affected by a window size change
73
+ */
74
+ update(e) {
75
+ var _a;
76
+ // special rule for transition events since so much with different propertynames are fired
77
+ if (e instanceof TransitionEvent) {
78
+ if (!e.propertyName.includes("width"))
79
+ return;
80
+ }
81
+ var that = this;
82
+ (_a = this.scrollingTimer) === null || _a === void 0 ? void 0 : _a.forEach(s => clearTimeout(s));
83
+ this.scrollingTimer.push(setTimeout(function () {
84
+ var _a, _b, _c, _d;
85
+ that.updateXY();
86
+ (_a = that.m2s) === null || _a === void 0 ? void 0 : _a.update();
87
+ (_b = that.annotations) === null || _b === void 0 ? void 0 : _b.updateCanvas();
88
+ (_d = (_c = that.insertModeHandler) === null || _c === void 0 ? void 0 : _c.getPhantomNoteHandler()) === null || _d === void 0 ? void 0 : _d.resetCanvas();
89
+ that.scrollingTimer = new Array();
90
+ }, 500));
91
+ }
92
+ reloadSVG(e) {
93
+ var _a;
94
+ var t = e.target;
95
+ var that = this;
96
+ (_a = this.reloadTimer) === null || _a === void 0 ? void 0 : _a.forEach(r => clearTimeout(r));
97
+ if (t.id === "sidebarContainer" && !(e.propertyName.includes("width"))) {
98
+ // Timeout is needed to ensure, that transition has been completed and in eventphase 0
99
+ // Must be a slighty longer than transitiontime
100
+ this.reloadTimer.push(setTimeout(function () {
101
+ that.updateXY();
102
+ var mei = meiConverter.restoreXmlIdTags(that.currentMEI);
103
+ that.loadDataCallback("", mei, false, null);
104
+ that.reloadTimer = new Array();
105
+ }, e.elapsedTime * 1000 + 10));
106
+ }
107
+ else if (e.type === "resize" || e.type === "resizemove" || t.id.startsWith("zoom")) {
108
+ this.reloadTimer.push(setTimeout(function () {
109
+ that.updateXY();
110
+ var mei = meiConverter.restoreXmlIdTags(that.currentMEI);
111
+ that.loadDataCallback("", mei, false, null);
112
+ that.reloadTimer = new Array();
113
+ }, 500));
114
+ }
115
+ }
116
+ /**
117
+ * Toggle ctrl or meta button. Is used to activte zoom function
118
+ * @param e
119
+ */
120
+ toggleCTRL(e) {
121
+ if (e.key === "Meta" || e.key === "Control") {
122
+ if (e.type === "keydown") {
123
+ this.ctrlPressed = true;
124
+ }
125
+ else {
126
+ this.ctrlPressed = false;
127
+ }
128
+ }
129
+ }
130
+ /**
131
+ * Zoom according to movement of mouse wheel (also applies to two finger scroll gesture on trackpad).
132
+ * Can only be executed when container is active Element and when ctrl/meta is pressed.
133
+ * The scale is accumulated with every call of this method.
134
+ * @param e
135
+ * @returns
136
+ */
137
+ wheelZoom(e) {
138
+ this.updateXY();
139
+ if (!cq.hasActiveElement(this.containerId))
140
+ return;
141
+ if (!this.ctrlPressed)
142
+ return;
143
+ e.preventDefault();
144
+ this.deltaTemp = this.deltaTemp + e.deltaY / 1000;
145
+ this.zoomSVG(this.deltaTemp);
146
+ }
147
+ /**
148
+ * Zoom when Zoombuttons are clicked (In div #zoomGroup).
149
+ *
150
+ * @param e
151
+ */
152
+ clickZoom(e) {
153
+ var t = e.target;
154
+ if (t.id === "zoomInBtn") {
155
+ this.deltaTemp = this.deltaTemp + 100 / 1000;
156
+ }
157
+ else if (t.id === "zoomOutBtn") {
158
+ this.deltaTemp = this.deltaTemp - 100 / 1000;
159
+ }
160
+ this.zoomSVG(this.deltaTemp);
161
+ }
162
+ /**
163
+ * General zoom logic for all top level svgs (interactionOverlay + vrvSVG (= rendered score by verovio))
164
+ * @param delta
165
+ */
166
+ zoomSVG(delta) {
167
+ var _a;
168
+ var that = this;
169
+ // ensure that with every call of all obsolete timeouts are deleted so that only one is left to be executed
170
+ (_a = this.zoomTimer) === null || _a === void 0 ? void 0 : _a.forEach(zt => clearTimeout(zt));
171
+ this.zoomTimer.push(setTimeout(function () {
172
+ var svgContainer = cq.getContainer(that.containerId).querySelector("#svgContainer");
173
+ svgContainer.querySelectorAll("#interactionOverlay, #vrvSVG").forEach((el) => {
174
+ el.style.transformOrigin = "0 0";
175
+ el.style.transform = "scale(" + delta.toString() + ")";
176
+ // if(el.id === "interactionOverlay"){
177
+ // const transformValue = window.getComputedStyle(el).getPropertyValue('transform');
178
+ // const matrix = new DOMMatrix(transformValue);
179
+ // const scaleX = matrix.a;
180
+ // const scaleY = matrix.d;
181
+ // var vbsplit = el.getAttribute("viewBox").split(" ")
182
+ // var newVb = new Array<string>()
183
+ // vbsplit.forEach((n, i) => {
184
+ // if(i === 2){
185
+ // newVb.push((parseFloat(n)/scaleX).toString())
186
+ // }else if(i === 3){
187
+ // newVb.push((parseFloat(n)/scaleY).toString())
188
+ // }else{
189
+ // newVb.push((parseFloat(n)).toString())
190
+ // }
191
+ // })
192
+ // el.setAttribute("viewBox", newVb.join(" "))
193
+ // }
194
+ });
195
+ }, 10));
196
+ }
197
+ /**
198
+ * Cache container attributes that need to be loaded after the score is loaded.
199
+ * - Scorllpositions of the containers
200
+ *
201
+ * Listens to "loadStart" Event in Core class
202
+ * @param e Event
203
+ */
204
+ cacheContainerAttr(e) {
205
+ this.divScrolls = new Map();
206
+ var container = document.getElementById(this.containerId);
207
+ container.querySelectorAll(":scope div").forEach(d => {
208
+ this.divScrolls.set(d.id, { sl: d.scrollLeft, st: d.scrollTop });
209
+ });
210
+ }
211
+ /**
212
+ * Load all container attributes saved in @function cacheContainerAttr after score is loaded.
213
+ * Listens to "loadEnd" Event in Core class
214
+ * @param e Event
215
+ * @returns
216
+ */
217
+ loadContainerAttr(e) {
218
+ var _a;
219
+ if (this.divScrolls == undefined)
220
+ return;
221
+ for (const [key, value] of this.divScrolls.entries()) {
222
+ (_a = document.getElementById(key)) === null || _a === void 0 ? void 0 : _a.scrollTo(value.sl, value.st);
223
+ }
224
+ }
225
+ /**
226
+ * Set X and Y coordinates of the current boundingbox of the of the VerovioScore (#vrvSVG)
227
+ */
228
+ updateXY() {
229
+ var _a;
230
+ var bb = (_a = document.getElementById(this.containerId)) === null || _a === void 0 ? void 0 : _a.querySelector("#vrvSVG").getBoundingClientRect();
231
+ this.x = bb.x;
232
+ this.y = bb.y;
233
+ }
234
+ resetListeners() {
235
+ this
236
+ .removeListeners()
237
+ .setListeners();
238
+ return this;
239
+ }
240
+ setm2s(m2s) {
241
+ this.m2s = m2s;
242
+ return this;
243
+ }
244
+ setAnnotations(annotations) {
245
+ this.annotations = annotations;
246
+ return this;
247
+ }
248
+ setCurrentMEI(mei) {
249
+ this.currentMEI = mei;
250
+ return this;
251
+ }
252
+ setContainerId(containerId) {
253
+ this.containerId = containerId;
254
+ this.container = document.getElementById(this.containerId);
255
+ this.interactionOverlay = cq.getInteractOverlay(this.containerId);
256
+ this.vrvSVG = cq.getVrvSVG(this.containerId);
257
+ return this;
258
+ }
259
+ setInsertModeHandler(imh) {
260
+ this.insertModeHandler = imh;
261
+ return this;
262
+ }
263
+ setLoadDataCallback(loadDataCallback) {
264
+ this.loadDataCallback = loadDataCallback;
265
+ return this;
266
+ }
267
+ setSVGReloadCallback(svgReloadCallback) {
268
+ this.svgReloadCallback = svgReloadCallback;
269
+ return this;
270
+ }
271
+ getX() {
272
+ return this.x;
273
+ }
274
+ getY() {
275
+ return this.y;
276
+ }
277
+ }
278
+ exports.default = WindowHandler;