abcjs 6.5.2 → 6.6.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.
@@ -39,7 +39,7 @@ function renderText(renderer, params, alreadyInGroup) {
39
39
 
40
40
  // MAE 9 May 2025 for free text blocks
41
41
  var text;
42
- if (params.name == "free-text"){
42
+ if (params.name === "free-text"){
43
43
  text = params.text.replace(/^[ \t]*\n/gm, ' \n');
44
44
  }
45
45
  else{
@@ -74,6 +74,8 @@ var EngraverController = function (paper, params) {
74
74
  this.germanAlphabet = params.germanAlphabet;
75
75
  if (params.lineThickness)
76
76
  this.lineThickness = params.lineThickness;
77
+ if (params.chordGrid)
78
+ this.chordGrid = params.chordGrid;
77
79
  this.renderer.controller = this; // TODO-GD needed for highlighting
78
80
  this.renderer.foregroundColor = params.foregroundColor ? params.foregroundColor : "currentColor";
79
81
  if (params.ariaLabel !== undefined)
@@ -251,7 +253,7 @@ EngraverController.prototype.engraveTune = function (abcTune, tuneNumber, lineOf
251
253
 
252
254
  var origJazzChords = this.jazzchords
253
255
  var scale = this.setupTune(abcTune, tuneNumber);
254
-
256
+
255
257
  // Create all of the element objects that will appear on the page.
256
258
  this.constructTuneElements(abcTune);
257
259
 
@@ -300,7 +302,7 @@ EngraverController.prototype.engraveTune = function (abcTune, tuneNumber, lineOf
300
302
  }
301
303
 
302
304
  // Do all the writing to the SVG
303
- var ret = draw(this.renderer, this.classes, abcTune, this.width, maxWidth, this.responsive, scale, this.selectTypes, tuneNumber, lineOffset);
305
+ var ret = draw(this.renderer, this.classes, abcTune, this.width, maxWidth, this.responsive, scale, this.selectTypes, tuneNumber, lineOffset, this.chordGrid);
304
306
  this.staffgroups = ret.staffgroups;
305
307
  this.selectables = ret.selectables;
306
308
  if (this.oneSvgPerLine) {
@@ -189,7 +189,22 @@ function createAdditionalBeams(elems, asc, beam, isGrace, dy) {
189
189
 
190
190
 
191
191
  if (auxBeams[j].single) {
192
- auxBeamEndX = (i === 0) ? x + 5 : x - 5;
192
+ if(i === 0) {
193
+ // This is the first note in the group, always draw the beam to the right
194
+ auxBeamEndX = x + 5;
195
+ } else if (i === elems.length - 1) {
196
+ // This is the last note in the group, always draw the beam to the left
197
+ auxBeamEndX = x - 5;
198
+ } else {
199
+ // This is a middle note, check the note durations of the notes to the left and right
200
+ if(elems[i-1].duration === elems[i+1].duration) {
201
+ // The notes on either side are the same duration, alternate which side the beam goes to
202
+ auxBeamEndX = i%2 === 0 ? x + 5 : x - 5;
203
+ } else {
204
+ // The notes on either side are different durations, draw the beam to the shorter note
205
+ auxBeamEndX = elems[i-1].duration > elems[i+1].duration ? x + 5 : x - 5;
206
+ }
207
+ }
193
208
  auxBeamEndY = getBarYAt(beam.startX, beam.startY, beam.endX, beam.endY, auxBeamEndX) + sy * (j + 1);
194
209
  }
195
210
  var b = { startX: auxBeams[j].x, endX: auxBeamEndX, startY: auxBeams[j].y, endY: auxBeamEndY, dy: dy }
@@ -179,6 +179,10 @@ Renderer.prototype.calcY = function (ofs) {
179
179
  return this.y - ofs * spacing.STEP;
180
180
  };
181
181
 
182
+ Renderer.prototype.yToPitch = function (ofs) {
183
+ return ofs / spacing.STEP;
184
+ };
185
+
182
186
  Renderer.prototype.moveY = function (em, numLines) {
183
187
  if (numLines === undefined) numLines = 1;
184
188
  this.y += em * numLines;
package/src/write/svg.js CHANGED
@@ -168,7 +168,7 @@ Svg.prototype.rectBeneath = function (attr) {
168
168
  this.svg.insertBefore(el, this.svg.firstChild);
169
169
  };
170
170
 
171
- Svg.prototype.text = function (text, attr, target) {
171
+ Svg.prototype.text = function (text, attr, target, spanAttr) {
172
172
  var el = document.createElementNS(svgNS, 'text');
173
173
  el.setAttribute("stroke", "none");
174
174
  for (var key in attr) {
@@ -185,6 +185,13 @@ Svg.prototype.text = function (text, attr, target) {
185
185
  }
186
186
 
187
187
  var line = document.createElementNS(svgNS, 'tspan');
188
+ if (spanAttr) {
189
+ for (var skey in spanAttr) {
190
+ if (spanAttr.hasOwnProperty(skey)) {
191
+ line.setAttribute(skey, spanAttr[skey]);
192
+ }
193
+ }
194
+ }
188
195
  line.setAttribute("x", attr.x ? attr.x : 0);
189
196
  if (i !== 0)
190
197
  line.setAttribute("dy", "1.2em");
package/types/index.d.ts CHANGED
@@ -266,6 +266,7 @@ declare module 'abcjs' {
266
266
  add_classes?: boolean;
267
267
  afterParsing?: AfterParsing;
268
268
  ariaLabel?: string;
269
+ chordGrid?:'noMusic'|'withMusic';
269
270
  clickListener?: ClickListener;
270
271
  dragColor?: string;
271
272
  dragging?: boolean;
@@ -872,6 +873,29 @@ declare module 'abcjs' {
872
873
  }
873
874
  }
874
875
 
876
+ interface ChordGridSubtitle {
877
+ type: "subtitle";
878
+ subtitle: string;
879
+ }
880
+ interface ChordGridText {
881
+ type: "text";
882
+ text: string;
883
+ }
884
+ interface ChordGridMeasure {
885
+ chord: [string,string,string,string];
886
+ hasStartRepeat?:boolean;
887
+ hasEndRepeat?:boolean;
888
+ noBorder?:boolean; // for when the line isn't complete, this is a placeholder
889
+ ending?:number; // This bar starts an ending
890
+ annotations?: Array<string>;
891
+ }
892
+ interface ChordGridPart {
893
+ type: "part";
894
+ name: string;
895
+ lines: Array<ChordGridMeasure>;
896
+ }
897
+ type ChordGrid = ChordGridSubtitle | ChordGridText | ChordGridPart;
898
+
875
899
  export interface TuneObject {
876
900
  formatting: Formatting;
877
901
  engraver?: EngraverController;
@@ -881,6 +905,7 @@ declare module 'abcjs' {
881
905
  metaTextInfo: MetaTextInfo;
882
906
  version: string;
883
907
  warnings?: Array<string>;
908
+ chordGrid?: Array<ChordGrid>;
884
909
 
885
910
  getTotalTime: NumberFunction;
886
911
  getTotalBeats: NumberFunction;
package/version.js CHANGED
@@ -1,3 +1,3 @@
1
- var version = '6.5.2';
1
+ var version = '6.6.0';
2
2
 
3
3
  module.exports = version;