abcjs 6.5.1 → 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
@@ -76,7 +76,7 @@ declare module 'abcjs' {
76
76
  //
77
77
  // Basic types
78
78
  //
79
- export type Selector = string | HTMLElement
79
+ export type Selector = string | Element
80
80
 
81
81
  type NumberFunction = () => number;
82
82
 
@@ -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;
@@ -321,7 +322,7 @@ declare module 'abcjs' {
321
322
  synthControl?: SynthObjectController;
322
323
  el: Selector;
323
324
  cursorControl?: CursorControl;
324
- options?: SynthOptions;
325
+ options?: SynthOptions & SynthVisualOptions;
325
326
  }
326
327
 
327
328
  export interface EditorOptions {
@@ -331,6 +332,7 @@ declare module 'abcjs' {
331
332
  warnings_id?: Selector;
332
333
  onchange?: OnChange;
333
334
  selectionChangeCallback?: SelectionChangeCallback;
335
+ redrawCallback?: RedrawCallback;
334
336
  abcjsParams?: AbcVisualParams;
335
337
  indicate_changed?: boolean;
336
338
  synth?: EditorSynth;
@@ -871,6 +873,29 @@ declare module 'abcjs' {
871
873
  }
872
874
  }
873
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
+
874
899
  export interface TuneObject {
875
900
  formatting: Formatting;
876
901
  engraver?: EngraverController;
@@ -880,6 +905,7 @@ declare module 'abcjs' {
880
905
  metaTextInfo: MetaTextInfo;
881
906
  version: string;
882
907
  warnings?: Array<string>;
908
+ chordGrid?: Array<ChordGrid>;
883
909
 
884
910
  getTotalTime: NumberFunction;
885
911
  getTotalBeats: NumberFunction;
@@ -1144,6 +1170,8 @@ declare module 'abcjs' {
1144
1170
 
1145
1171
  export type SelectionChangeCallback = (startChar: number, endChar: number) => void;
1146
1172
 
1173
+ export type RedrawCallback = (isBefore: boolean) => void;
1174
+
1147
1175
  // Audio
1148
1176
  export interface CursorControl {
1149
1177
  beatSubDivision?: number
@@ -1185,8 +1213,12 @@ declare module 'abcjs' {
1185
1213
  //
1186
1214
  // Editor
1187
1215
  //
1216
+ export class EditArea {
1217
+ constructor(target: Selector);
1218
+ }
1219
+
1188
1220
  export class Editor {
1189
- constructor(target: Selector, options: EditorOptions);
1221
+ constructor(target: Selector | EditArea, options: EditorOptions);
1190
1222
  paramChanged(options: AbcVisualParams): void;
1191
1223
  synthParamChanged(options: SynthOptions): void;
1192
1224
  setNotDirty(): void;
@@ -1195,6 +1227,7 @@ declare module 'abcjs' {
1195
1227
  millisecondsPerMeasure(): number;
1196
1228
  pauseMidi(shouldPause: boolean): void;
1197
1229
  fireChanged():void;
1230
+ getTunes():TuneObjectArray;
1198
1231
  }
1199
1232
 
1200
1233
  //
package/version.js CHANGED
@@ -1,3 +1,3 @@
1
- var version = '6.5.1';
1
+ var version = '6.6.0';
2
2
 
3
3
  module.exports = version;