abcjs 6.1.3 → 6.1.5

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.3",
3
+ "version": "6.1.5",
4
4
  "description": "Renderer for abc music notation",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -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++;
@@ -200,11 +200,15 @@ function getTarget(target) {
200
200
 
201
201
  var found = target.getAttribute("selectable");
202
202
  while (!found) {
203
- target = target.parentElement;
204
- if (target.tagName === "svg")
203
+ if (!target.parentElement)
205
204
  found = true;
206
- else
207
- found = target.getAttribute("selectable");
205
+ else {
206
+ target = target.parentElement;
207
+ if (target.tagName === "svg")
208
+ found = true;
209
+ else
210
+ found = target.getAttribute("selectable");
211
+ }
208
212
  }
209
213
  return target;
210
214
  }
@@ -234,6 +238,8 @@ function getMousePosition(self, ev) {
234
238
  }
235
239
 
236
240
  function attachMissingTouchEventAttributes(touchEv) {
241
+ if (!touchEv || !touchEv.target || !touchEv.touches || touchEv.touches.length < 1)
242
+ return
237
243
  var rect = touchEv.target.getBoundingClientRect();
238
244
  var offsetX = touchEv.touches[0].pageX - rect.left;
239
245
  var offsetY = touchEv.touches[0].pageY - rect.top;
@@ -250,13 +256,14 @@ function mouseDown(ev) {
250
256
  var _ev = ev;
251
257
  if (ev.type === 'touchstart') {
252
258
  attachMissingTouchEventAttributes(ev);
253
- _ev = ev.touches[0];
259
+ if (ev.touches.length > 0)
260
+ _ev = ev.touches[0];
254
261
  }
255
262
 
256
263
  var positioning = getMousePosition(this, _ev);
257
264
 
258
265
  // 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)) {
266
+ if (positioning.clickedOn >= 0 && (ev.type === 'touchstart' || ev.button === 0) && this.selectables[positioning.clickedOn]) {
260
267
  this.dragTarget = this.selectables[positioning.clickedOn];
261
268
  this.dragIndex = positioning.clickedOn;
262
269
  this.dragMechanism = "mouse";
@@ -272,12 +279,13 @@ function mouseMove(ev) {
272
279
  var _ev = ev;
273
280
  if (ev.type === 'touchmove') {
274
281
  attachMissingTouchEventAttributes(ev);
275
- _ev = ev.touches[0];
282
+ if (ev.touches.length > 0)
283
+ _ev = ev.touches[0];
276
284
  }
277
285
  this.lastTouchMove = ev;
278
286
  // "this" is the EngraverController because of the bind(this) when setting the event listener.
279
287
 
280
- if (!this.dragTarget || !this.dragging || !this.dragTarget.isDraggable || this.dragMechanism !== 'mouse')
288
+ if (!this.dragTarget || !this.dragging || !this.dragTarget.isDraggable || this.dragMechanism !== 'mouse' || !this.dragMouseStart)
281
289
  return;
282
290
 
283
291
  var positioning = getMousePosition(this, _ev);
@@ -292,9 +300,10 @@ function mouseMove(ev) {
292
300
  function mouseUp(ev) {
293
301
  // "this" is the EngraverController because of the bind(this) when setting the event listener.
294
302
  var _ev = ev;
295
- if (ev.type === 'touchend') {
303
+ if (ev.type === 'touchend' && this.lastTouchMove) {
296
304
  attachMissingTouchEventAttributes(this.lastTouchMove);
297
- _ev = this.lastTouchMove.touches[0];
305
+ if (this.lastTouchMove.touches.length > 0)
306
+ _ev = this.lastTouchMove.touches[0];
298
307
  }
299
308
 
300
309
  if (!this.dragTarget)
@@ -348,10 +357,10 @@ function notifySelect(target, dragStep, dragMax, dragIndex, ev) {
348
357
  if (target.staffPos)
349
358
  analysis.staffPos = target.staffPos;
350
359
  var closest = ev.target;
351
- while (!closest.dataset.name && closest.tagName.toLowerCase() !== 'svg')
360
+ while (closest && !closest.dataset.name && closest.tagName.toLowerCase() !== 'svg')
352
361
  closest = closest.parentNode;
353
362
  var parent = ev.target;
354
- while (!parent.dataset.index && parent.tagName.toLowerCase() !== 'svg')
363
+ while (parent && !parent.dataset.index && parent.tagName.toLowerCase() !== 'svg')
355
364
  parent = parent.parentNode;
356
365
  analysis.name = parent.dataset.name;
357
366
  analysis.clickedName = closest.dataset.name;
package/version.js CHANGED
@@ -1,3 +1,3 @@
1
- var version = '6.1.3';
1
+ var version = '6.1.5';
2
2
 
3
3
  module.exports = version;