vibe-editor 0.0.0 → 0.0.1-dev
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.
- package/LICENSE +1 -1
- package/README.md +12 -9
- package/package.json +11 -5
- package/src/scripts/js/Core.js +212 -186
- package/src/scripts/js/MusicProcessor.js +286 -128
- package/src/scripts/js/{VerovioScoreEditor.js → VIBE.js} +62 -28
- package/src/scripts/js/assets/mei_template.js +5 -1
- package/src/scripts/js/datastructures/MeasureMatrix.js +6 -85
- package/src/scripts/js/datastructures/ScoreGraph.js +1 -1
- package/src/scripts/js/entry.js +3 -2
- package/src/scripts/js/gui/Annotations.js +188 -111
- package/src/scripts/js/gui/HarmonyLabel.js +26 -2
- package/src/scripts/js/gui/ScoreManipulator.js +61 -31
- package/src/scripts/js/gui/Tabbar.js +41 -21
- package/src/scripts/js/gui/Toolbar.js +4 -4
- package/src/scripts/js/handlers/AnnotationChangeHandler.js +131 -60
- package/src/scripts/js/handlers/ClickModeHandler.js +406 -143
- package/src/scripts/js/handlers/CustomToolbarHandler.js +26 -24
- package/src/scripts/js/handlers/GlobalKeyboardHandler.js +12 -7
- package/src/scripts/js/handlers/InsertModeHandler.js +26 -32
- package/src/scripts/js/handlers/KeyModeHandler.js +12 -86
- package/src/scripts/js/handlers/LabelHandler.js +3 -2
- package/src/scripts/js/handlers/PhantomElementHandler.js +1 -1
- package/src/scripts/js/handlers/ScoreManipulatorHandler.js +101 -14
- package/src/scripts/js/handlers/SelectionHandler.js +80 -36
- package/src/scripts/js/handlers/SideBarHandler.js +10 -3
- package/src/scripts/js/handlers/WindowHandler.js +25 -4
- package/src/scripts/js/utils/DOMCreator.js +1 -1
- package/src/scripts/js/utils/MEIConverter.js +13 -1
- package/src/scripts/js/utils/MEIOperations.js +180 -187
- package/src/scripts/js/utils/Mouse2SVG.js +200 -43
- package/src/scripts/js/utils/ReactWrapper.js +46 -0
- package/src/scripts/js/utils/RectWrapper.js +10 -0
- package/src/scripts/js/utils/SVGEditor.js +94 -3
- package/src/scripts/js/utils/VerovioWrapper.js +6 -1
- package/src/scripts/js/utils/convenienceQueries.js +2 -0
- package/src/scripts/js/utils/mappings.js +322 -56
- package/src/styles/VerovioScoreEditor.css +0 -694
@@ -1,6 +1,5 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const constants_1 = require("../constants");
|
4
3
|
const interactjs_1 = require("interactjs");
|
5
4
|
const cq = require("../utils/convenienceQueries");
|
6
5
|
const coordinates = require("../utils/coordinates");
|
@@ -9,6 +8,9 @@ const coordinates = require("../utils/coordinates");
|
|
9
8
|
*/
|
10
9
|
class AnnotationChangeHandler {
|
11
10
|
constructor(containerId) {
|
11
|
+
this.selectColorsHandler = (function selectColorsHandler() {
|
12
|
+
this.setColors();
|
13
|
+
}).bind(this);
|
12
14
|
// change to function after implementation
|
13
15
|
this.selectHandler = (function selectHandler(e) {
|
14
16
|
var target = e.target;
|
@@ -60,7 +62,7 @@ class AnnotationChangeHandler {
|
|
60
62
|
})
|
61
63
|
]
|
62
64
|
});
|
63
|
-
this.textListener = interactjs_1.default("#" + this.containerId + "
|
65
|
+
this.textListener = interactjs_1.default("#" + this.containerId + " .annotText")
|
64
66
|
.resizable({
|
65
67
|
// resize from all edges and corners
|
66
68
|
edges: { left: true, right: true, bottom: true, top: true },
|
@@ -110,6 +112,18 @@ class AnnotationChangeHandler {
|
|
110
112
|
})
|
111
113
|
]
|
112
114
|
});
|
115
|
+
// this.colorObserver = new MutationObserver(function(mutations){
|
116
|
+
// mutations.forEach(mutation => {
|
117
|
+
// if(mutation.type !== "attributes") return
|
118
|
+
// if(mutation.attributeName === "selectedcolor"){
|
119
|
+
// that.setColors()
|
120
|
+
// }
|
121
|
+
// })
|
122
|
+
// })
|
123
|
+
// this.colorObserver.observe(cq.getContainer(this.containerId).querySelector("#colorGroup"), {
|
124
|
+
// attributes: true
|
125
|
+
// })
|
126
|
+
cq.getContainer(this.containerId).querySelector("#colorGroup").addEventListener("change", this.selectColorsHandler);
|
113
127
|
}
|
114
128
|
removeListeners() {
|
115
129
|
var _a, _b, _c;
|
@@ -117,11 +131,38 @@ class AnnotationChangeHandler {
|
|
117
131
|
(_a = this.shapeListener) === null || _a === void 0 ? void 0 : _a.unset();
|
118
132
|
(_b = this.lineListener) === null || _b === void 0 ? void 0 : _b.unset();
|
119
133
|
(_c = this.textListener) === null || _c === void 0 ? void 0 : _c.unset();
|
134
|
+
//this.colorObserver?.disconnect()
|
135
|
+
cq.getContainer(this.containerId).querySelector("#colorGroup").removeEventListener("change", this.selectColorsHandler);
|
120
136
|
}
|
121
137
|
resetListeners() {
|
122
138
|
this.removeListeners();
|
123
139
|
this.setListeners();
|
124
140
|
}
|
141
|
+
/**
|
142
|
+
* set selected color to all marked elements
|
143
|
+
* color hex is set in the #colorGroup element
|
144
|
+
* @returns
|
145
|
+
*/
|
146
|
+
setColors() {
|
147
|
+
var color = cq.getContainer(this.containerId).querySelector("#colorGroup").getAttribute("selectedcolor");
|
148
|
+
if (!color)
|
149
|
+
return;
|
150
|
+
cq.getContainer(this.containerId).querySelectorAll(".marked").forEach(m => {
|
151
|
+
m.style.fill = color;
|
152
|
+
});
|
153
|
+
cq.getContainer(this.containerId).querySelectorAll(".annotText.selected [contenteditable]").forEach(c => {
|
154
|
+
if (c.closest(".annotLinkedText")) {
|
155
|
+
color += "1A";
|
156
|
+
} //add transparency of 0.1
|
157
|
+
c.style.backgroundColor = color;
|
158
|
+
//change color in annotlist
|
159
|
+
const id = c.closest("g").id;
|
160
|
+
const annotListElement = cq.getContainer(this.containerId).querySelector(`#annotList > [refid=${id}]`);
|
161
|
+
if (!annotListElement)
|
162
|
+
return;
|
163
|
+
annotListElement.style.backgroundColor = color;
|
164
|
+
});
|
165
|
+
}
|
125
166
|
// SHAPES
|
126
167
|
dragShapeListener(event) {
|
127
168
|
var target = event.target;
|
@@ -148,9 +189,13 @@ class AnnotationChangeHandler {
|
|
148
189
|
pt = coordinates.transformToDOMMatrixCoordinates(target.getBoundingClientRect().x, target.getBoundingClientRect().y, cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas"));
|
149
190
|
var rectX = pt.x.toString(); //pt.matrixTransform(this.canvasMatrix).x.toString()
|
150
191
|
var rectY = pt.y.toString(); //pt.matrixTransform(this.canvasMatrix).y.toString()
|
151
|
-
if (line
|
192
|
+
if (line) {
|
152
193
|
line.setAttribute("x1", rectX);
|
153
194
|
line.setAttribute("y1", rectY);
|
195
|
+
var xDiff = parseFloat(line.getAttribute("x2")) - parseFloat(rectX);
|
196
|
+
var yDiff = parseFloat(line.getAttribute("y2")) - parseFloat(rectY);
|
197
|
+
line.setAttribute("x-diff", xDiff.toString());
|
198
|
+
line.setAttribute("y-diff", yDiff.toString());
|
154
199
|
}
|
155
200
|
var dragRects = targetParent === null || targetParent === void 0 ? void 0 : targetParent.querySelectorAll(".lineDragRect");
|
156
201
|
if (dragRects.length > 0) {
|
@@ -165,6 +210,7 @@ class AnnotationChangeHandler {
|
|
165
210
|
resizeShapeListener(event) {
|
166
211
|
var target = event.target;
|
167
212
|
this.interactTarget = target;
|
213
|
+
cq.getContainer(this.containerId).classList.add("annotMode");
|
168
214
|
// update overal dimensions
|
169
215
|
var pt = coordinates.getDOMMatrixCoordinates(event.rect, cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas"));
|
170
216
|
target.style.width = pt.width + 'px';
|
@@ -179,10 +225,12 @@ class AnnotationChangeHandler {
|
|
179
225
|
var distY = (parseFloat(target.getAttribute('distY'))) || edy - ptDist.y; //ptDist.matrixTransform(this.canvasMatrix).y
|
180
226
|
target.setAttribute("distX", distX.toString());
|
181
227
|
target.setAttribute("distY", distY.toString());
|
182
|
-
if (event.edges.left === true)
|
228
|
+
if (event.edges.left === true) {
|
183
229
|
target.setAttribute("x", (edx - distX).toString());
|
184
|
-
|
230
|
+
}
|
231
|
+
if (event.edges.top === true) {
|
185
232
|
target.setAttribute("y", (edy - distY).toString());
|
233
|
+
}
|
186
234
|
//target.textContent = Math.round(event.rect.width) + '\u00D7' + Math.round(event.rect.height)
|
187
235
|
}
|
188
236
|
//update attached line
|
@@ -194,6 +242,10 @@ class AnnotationChangeHandler {
|
|
194
242
|
if (line !== null) {
|
195
243
|
line.setAttribute("x1", rectX);
|
196
244
|
line.setAttribute("y1", rectY);
|
245
|
+
var xDiff = parseFloat(line.getAttribute("x2")) - parseFloat(rectX);
|
246
|
+
var yDiff = parseFloat(line.getAttribute("y2")) - parseFloat(rectY);
|
247
|
+
line.setAttribute("x-diff", xDiff.toString());
|
248
|
+
line.setAttribute("y-diff", yDiff.toString());
|
197
249
|
}
|
198
250
|
if (dragRects.length > 0) {
|
199
251
|
dragRects.forEach(dr => {
|
@@ -209,6 +261,7 @@ class AnnotationChangeHandler {
|
|
209
261
|
var target = event.target.querySelector(".annotFO");
|
210
262
|
this.interactTarget = target;
|
211
263
|
//this.canvasMatrix = (document.getElementById("annotationCanvas") as unknown as SVGGraphicsElement).getScreenCTM().inverse()
|
264
|
+
cq.getContainer(this.containerId).classList.add("annotMode");
|
212
265
|
// update overal dimensions
|
213
266
|
var ptTL = coordinates.getDOMMatrixCoordinates(event.rect, cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas"));
|
214
267
|
target.style.width = ptTL.width + 'px';
|
@@ -223,10 +276,12 @@ class AnnotationChangeHandler {
|
|
223
276
|
var distY = (parseFloat(target.getAttribute('distY'))) || edy - ptDist.y; //matrixTransform(this.canvasMatrix).y
|
224
277
|
target.setAttribute("distX", distX.toString());
|
225
278
|
target.setAttribute("distY", distY.toString());
|
226
|
-
if (event.edges.left === true)
|
279
|
+
if (event.edges.left === true) {
|
227
280
|
target.setAttribute("x", (edx - distX).toString());
|
228
|
-
|
281
|
+
}
|
282
|
+
if (event.edges.top === true) {
|
229
283
|
target.setAttribute("y", (edy - distY).toString());
|
284
|
+
}
|
230
285
|
//target.textContent = Math.round(event.rect.width) + '\u00D7' + Math.round(event.rect.height)
|
231
286
|
}
|
232
287
|
//update attached line
|
@@ -238,6 +293,10 @@ class AnnotationChangeHandler {
|
|
238
293
|
if (line !== null) {
|
239
294
|
line.setAttribute("x2", rectX);
|
240
295
|
line.setAttribute("y2", rectY);
|
296
|
+
var xDiff = parseFloat(rectX) - parseFloat(line.getAttribute("x1"));
|
297
|
+
var yDiff = parseFloat(rectY) - parseFloat(line.getAttribute("y1"));
|
298
|
+
line.setAttribute("x-diff", xDiff.toString());
|
299
|
+
line.setAttribute("y-diff", yDiff.toString());
|
241
300
|
}
|
242
301
|
if (dragRects.length > 0) {
|
243
302
|
dragRects.forEach(dr => {
|
@@ -275,6 +334,10 @@ class AnnotationChangeHandler {
|
|
275
334
|
if (line !== null) {
|
276
335
|
line.setAttribute("x2", rectX);
|
277
336
|
line.setAttribute("y2", rectY);
|
337
|
+
var xDiff = parseFloat(rectX) - parseFloat(line.getAttribute("x1"));
|
338
|
+
var yDiff = parseFloat(rectY) - parseFloat(line.getAttribute("y1"));
|
339
|
+
line.setAttribute("x-diff", xDiff.toString());
|
340
|
+
line.setAttribute("y-diff", yDiff.toString());
|
278
341
|
}
|
279
342
|
if (dragRects.length > 0) {
|
280
343
|
dragRects.forEach(dr => {
|
@@ -293,6 +356,7 @@ class AnnotationChangeHandler {
|
|
293
356
|
if (!this.isInteracting) {
|
294
357
|
this.interactTarget.dispatchEvent(this.dragAnnotStartEvent);
|
295
358
|
}
|
359
|
+
cq.getContainer(this.containerId).classList.add("annotMode");
|
296
360
|
this.isInteracting = true;
|
297
361
|
//this.canvasMatrix = (document.getElementById("annotationCanvas") as unknown as SVGGraphicsElement).getScreenCTM().inverse()
|
298
362
|
this.dragedRect = target;
|
@@ -309,6 +373,10 @@ class AnnotationChangeHandler {
|
|
309
373
|
if (target.classList.contains("x1")) {
|
310
374
|
line.setAttribute("x1", rectX);
|
311
375
|
line.setAttribute("y1", rectY);
|
376
|
+
var xDiff = parseFloat(line.getAttribute("x2")) - parseFloat(rectX);
|
377
|
+
var yDiff = parseFloat(line.getAttribute("y2")) - parseFloat(rectY);
|
378
|
+
line.setAttribute("x-diff", xDiff.toString());
|
379
|
+
line.setAttribute("y-diff", yDiff.toString());
|
312
380
|
this.highlightNextAttachObject(target);
|
313
381
|
}
|
314
382
|
this.interactionOverlay.dispatchEvent(new Event("annotChanged"));
|
@@ -402,32 +470,38 @@ class AnnotationChangeHandler {
|
|
402
470
|
* @param lineDragRect
|
403
471
|
*/
|
404
472
|
updateAnnotationIDs(objToAttach, lineDragRect, objCoord) {
|
473
|
+
if (!objToAttach)
|
474
|
+
return;
|
405
475
|
var line;
|
406
476
|
var targetx;
|
407
477
|
var targety;
|
408
478
|
var highlightRect;
|
409
479
|
var parentGroup = lineDragRect.closest("g");
|
480
|
+
document.querySelectorAll(".highlightAnnotation").forEach(h => h.classList.remove("highlightAnnotation"));
|
481
|
+
objToAttach.classList.add("highlightAnnotation");
|
410
482
|
var otaBBox = objToAttach.getBoundingClientRect();
|
411
483
|
this.annotations.some(annot => {
|
484
|
+
var _a;
|
412
485
|
if (annot.sourceID = parentGroup.id) {
|
413
486
|
var pt = coordinates.getDOMMatrixCoordinates(otaBBox, cq.getInteractOverlay(this.containerId).querySelector("#annotationCanvas"));
|
414
487
|
annot.targetID = objToAttach.id;
|
415
488
|
targetx = pt.x;
|
416
489
|
targety = pt.y;
|
417
|
-
// draw rect for highlighting
|
418
|
-
if
|
419
|
-
|
420
|
-
|
421
|
-
}
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
highlightRect.
|
427
|
-
highlightRect.setAttribute("
|
428
|
-
highlightRect.setAttribute("
|
429
|
-
highlightRect.setAttribute("
|
430
|
-
|
490
|
+
// // draw rect for highlighting
|
491
|
+
// if(parentGroup.querySelector(".highlightAnnotation") === null){
|
492
|
+
// highlightRect = document.createElementNS(c._SVGNS_, "rect")
|
493
|
+
// parentGroup.insertBefore(highlightRect, parentGroup.firstChild)
|
494
|
+
// }else{
|
495
|
+
// highlightRect = parentGroup.querySelector(".highlightAnnotation")
|
496
|
+
// }
|
497
|
+
// var highlightMargin = 0
|
498
|
+
// highlightRect.classList.add("highlightAnnotation")
|
499
|
+
// highlightRect.setAttribute("x", (targetx - highlightMargin).toString())
|
500
|
+
// highlightRect.setAttribute("y", (targety - highlightMargin).toString())
|
501
|
+
// highlightRect.setAttribute("height", (pt.height + 2*highlightMargin).toString())
|
502
|
+
// highlightRect.setAttribute("width", (pt.width + 2*highlightMargin).toString())
|
503
|
+
(_a = cq.getInteractOverlay(this.containerId).querySelector(`#${annot.sourceID}`)) === null || _a === void 0 ? void 0 : _a.setAttribute("targetId", objToAttach.id);
|
504
|
+
annot.targetID = objToAttach.id;
|
431
505
|
return annot.sourceID === parentGroup.id;
|
432
506
|
}
|
433
507
|
});
|
@@ -436,10 +510,6 @@ class AnnotationChangeHandler {
|
|
436
510
|
x: targetx,
|
437
511
|
y: targety
|
438
512
|
};
|
439
|
-
// this.container.querySelectorAll("*[fill=green]").forEach(fg => {
|
440
|
-
// fg.removeAttribute("fill")
|
441
|
-
// })
|
442
|
-
//objToAttach.setAttribute("fill", "green")
|
443
513
|
// some rules for custom shapes
|
444
514
|
if (objToAttach.classList.contains("customAnnotShape")) {
|
445
515
|
parentGroup.querySelector(".highlightAnnotation").remove();
|
@@ -487,6 +557,10 @@ class AnnotationChangeHandler {
|
|
487
557
|
var line = this.dragedRect.closest("g").querySelector(".annotLine");
|
488
558
|
line.setAttribute("x1", this.snapCoords.x.toString());
|
489
559
|
line.setAttribute("y1", this.snapCoords.y.toString());
|
560
|
+
var xDiff = parseFloat(line.getAttribute("x2")) - this.snapCoords.x;
|
561
|
+
var yDiff = parseFloat(line.getAttribute("y2")) - this.snapCoords.y;
|
562
|
+
line.setAttribute("x-diff", xDiff.toString());
|
563
|
+
line.setAttribute("y-diff", yDiff.toString());
|
490
564
|
// clean up after snap
|
491
565
|
this.interactionOverlay.querySelector("#annotationCanvas").querySelectorAll("g").forEach(el => {
|
492
566
|
var shapeChild = el.querySelector(".customAnnotShape");
|
@@ -514,42 +588,39 @@ class AnnotationChangeHandler {
|
|
514
588
|
return this;
|
515
589
|
}
|
516
590
|
setAnnotations(annotations) {
|
517
|
-
var _a, _b, _c, _d;
|
518
591
|
this.annotations = annotations;
|
519
|
-
var newFactor = parseInt((
|
520
|
-
if (newFactor === this.factor)
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
});
|
552
|
-
that.factor = parseInt((_d = (_c = cq.getContainer(this.containerId).querySelector("#svgContainer").style) === null || _c === void 0 ? void 0 : _c.width) === null || _d === void 0 ? void 0 : _d.split("%")[0]);
|
592
|
+
// var newFactor = parseInt((cq.getContainer(this.containerId).querySelector("#svgContainer") as HTMLElement).style?.width?.split("%")[0]) || 100
|
593
|
+
// if (newFactor === this.factor) return this
|
594
|
+
// var that = this
|
595
|
+
// function setXYWH(element) {
|
596
|
+
// var x = parseFloat(element.getAttribute("x")) / that.factor * newFactor
|
597
|
+
// var y = parseFloat(element.getAttribute("y")) / that.factor * newFactor
|
598
|
+
// var w = parseFloat(element.getAttribute("width")) / that.factor * newFactor
|
599
|
+
// var h = parseFloat(element.getAttribute("height")) / that.factor * newFactor
|
600
|
+
// element.setAttribute("x", x.toString())
|
601
|
+
// element.setAttribute("y", y.toString())
|
602
|
+
// element.setAttribute("width", w.toString())
|
603
|
+
// element.setAttribute("height", h.toString())
|
604
|
+
// }
|
605
|
+
// function setLineCoords(line) {
|
606
|
+
// var x1 = parseFloat(line.getAttribute("x1")) / that.factor * newFactor
|
607
|
+
// var y1 = parseFloat(line.getAttribute("y1")) / that.factor * newFactor
|
608
|
+
// var x2 = parseFloat(line.getAttribute("x2")) / that.factor * newFactor
|
609
|
+
// var y2 = parseFloat(line.getAttribute("y2")) / that.factor * newFactor
|
610
|
+
// line.setAttribute("x1", x1.toString())
|
611
|
+
// line.setAttribute("y1", y1.toString())
|
612
|
+
// line.setAttribute("x2", x2.toString())
|
613
|
+
// line.setAttribute("y2", y2.toString())
|
614
|
+
// }
|
615
|
+
// this.annotationCanvas.querySelectorAll(":scope > *").forEach(a => {
|
616
|
+
// if (a.tagName === "rect") {
|
617
|
+
// setXYWH(a)
|
618
|
+
// } else {
|
619
|
+
// a.querySelectorAll("[x][y][width][height]").forEach(e => setXYWH(e))
|
620
|
+
// a.querySelectorAll("line").forEach(l => setLineCoords(l))
|
621
|
+
// }
|
622
|
+
// })
|
623
|
+
// that.factor = parseInt((cq.getContainer(this.containerId).querySelector("#svgContainer") as HTMLElement).style?.width?.split("%")[0])
|
553
624
|
return this;
|
554
625
|
}
|
555
626
|
setm2s(m2s) {
|