abcjs 6.1.2 → 6.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abcjs",
3
- "version": "6.1.2",
3
+ "version": "6.1.4",
4
4
  "description": "Renderer for abc music notation",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -198,7 +198,7 @@ TabRenderer.prototype.doLayout = function () {
198
198
  var padd = 3;
199
199
  var prevIndex = this.staffIndex;
200
200
  var previousStaff = staffGroup.staffs[prevIndex];
201
- var tabTop = previousStaff.top + padd + lyricsHeight;
201
+ var tabTop = this.tabSize + padd - previousStaff.bottom - lyricsHeight;
202
202
  if (previousStaff.isTabStaff) {
203
203
  tabTop = previousStaff.top;
204
204
  }
@@ -41,7 +41,7 @@ function getCoord(ev) {
41
41
  yOffset = svg.viewBox.baseVal.y
42
42
  }
43
43
 
44
- var svgClicked = ev.target.tagName === "svg";
44
+ var svgClicked = ev.target && ev.target.tagName === "svg";
45
45
  var x;
46
46
  var y;
47
47
  if (svgClicked) {
@@ -93,7 +93,7 @@ function keyboardSelection(ev) {
93
93
  handled = true;
94
94
  this.dragTarget = this.selectables[index];
95
95
  this.dragIndex = index;
96
- if (this.dragTarget.isDraggable) {
96
+ if (this.dragTarget && this.dragTarget.isDraggable) {
97
97
  if (this.dragging && this.dragTarget.isDraggable)
98
98
  this.dragTarget.absEl.highlight(undefined, this.dragColor);
99
99
  this.dragYStep--;
@@ -105,7 +105,7 @@ function keyboardSelection(ev) {
105
105
  this.dragTarget = this.selectables[index];
106
106
  this.dragIndex = index;
107
107
  this.dragMechanism = "keyboard";
108
- if (this.dragTarget.isDraggable) {
108
+ if (this.dragTarget && this.dragTarget.isDraggable) {
109
109
  if (this.dragging && this.dragTarget.isDraggable)
110
110
  this.dragTarget.absEl.highlight(undefined, this.dragColor);
111
111
  this.dragYStep++;
@@ -234,6 +234,8 @@ function getMousePosition(self, ev) {
234
234
  }
235
235
 
236
236
  function attachMissingTouchEventAttributes(touchEv) {
237
+ if (!touchEv || !touchEv.target || !touchEv.touches || touchEv.touches.length < 1)
238
+ return
237
239
  var rect = touchEv.target.getBoundingClientRect();
238
240
  var offsetX = touchEv.touches[0].pageX - rect.left;
239
241
  var offsetY = touchEv.touches[0].pageY - rect.top;
@@ -250,13 +252,14 @@ function mouseDown(ev) {
250
252
  var _ev = ev;
251
253
  if (ev.type === 'touchstart') {
252
254
  attachMissingTouchEventAttributes(ev);
253
- _ev = ev.touches[0];
255
+ if (ev.touches.length > 0)
256
+ _ev = ev.touches[0];
254
257
  }
255
258
 
256
259
  var positioning = getMousePosition(this, _ev);
257
260
 
258
261
  // Only start dragging if the user clicked close enough to an element and clicked with the main mouse button.
259
- if (positioning.clickedOn >= 0 && (ev.type === 'touchstart' || ev.button === 0)) {
262
+ if (positioning.clickedOn >= 0 && (ev.type === 'touchstart' || ev.button === 0) && this.selectables[positioning.clickedOn]) {
260
263
  this.dragTarget = this.selectables[positioning.clickedOn];
261
264
  this.dragIndex = positioning.clickedOn;
262
265
  this.dragMechanism = "mouse";
@@ -272,12 +275,13 @@ function mouseMove(ev) {
272
275
  var _ev = ev;
273
276
  if (ev.type === 'touchmove') {
274
277
  attachMissingTouchEventAttributes(ev);
275
- _ev = ev.touches[0];
278
+ if (ev.touches.length > 0)
279
+ _ev = ev.touches[0];
276
280
  }
277
281
  this.lastTouchMove = ev;
278
282
  // "this" is the EngraverController because of the bind(this) when setting the event listener.
279
283
 
280
- if (!this.dragTarget || !this.dragging || !this.dragTarget.isDraggable || this.dragMechanism !== 'mouse')
284
+ if (!this.dragTarget || !this.dragging || !this.dragTarget.isDraggable || this.dragMechanism !== 'mouse' || !this.dragMouseStart)
281
285
  return;
282
286
 
283
287
  var positioning = getMousePosition(this, _ev);
@@ -292,9 +296,10 @@ function mouseMove(ev) {
292
296
  function mouseUp(ev) {
293
297
  // "this" is the EngraverController because of the bind(this) when setting the event listener.
294
298
  var _ev = ev;
295
- if (ev.type === 'touchend') {
299
+ if (ev.type === 'touchend' && this.lastTouchMove) {
296
300
  attachMissingTouchEventAttributes(this.lastTouchMove);
297
- _ev = this.lastTouchMove.touches[0];
301
+ if (ev.touches.length > 0)
302
+ _ev = this.lastTouchMove.touches[0];
298
303
  }
299
304
 
300
305
  if (!this.dragTarget)
@@ -348,10 +353,10 @@ function notifySelect(target, dragStep, dragMax, dragIndex, ev) {
348
353
  if (target.staffPos)
349
354
  analysis.staffPos = target.staffPos;
350
355
  var closest = ev.target;
351
- while (!closest.dataset.name && closest.tagName.toLowerCase() !== 'svg')
356
+ while (closest && !closest.dataset.name && closest.tagName.toLowerCase() !== 'svg')
352
357
  closest = closest.parentNode;
353
358
  var parent = ev.target;
354
- while (!parent.dataset.index && parent.tagName.toLowerCase() !== 'svg')
359
+ while (parent && !parent.dataset.index && parent.tagName.toLowerCase() !== 'svg')
355
360
  parent = parent.parentNode;
356
361
  analysis.name = parent.dataset.name;
357
362
  analysis.clickedName = closest.dataset.name;
package/src/write/svg.js CHANGED
@@ -307,7 +307,7 @@ Svg.prototype.closeGroup = function() {
307
307
  var g = this.currentGroup.shift();
308
308
  if (g && g.children.length === 0) {
309
309
  // If nothing was added to the group it is because all the elements were invisible. We don't need the group, then.
310
- this.svg.removeChild(g);
310
+ g.parentElement.removeChild(g);
311
311
  return null;
312
312
  }
313
313
  return g;
package/version.js CHANGED
@@ -1,3 +1,3 @@
1
- var version = '6.1.2';
1
+ var version = '6.1.4';
2
2
 
3
3
  module.exports = version;