@barmark/render 0.20.1 → 0.21.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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,26 @@ package uses [semantic versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.21.0] - 2026-11-19
10
+
11
+ ### Added
12
+
13
+ - **`melody: false`** (attribute `melody="off"`, property `melody`) leaves a
14
+ voice part's singing line out of the grid, so a lead sheet of chords,
15
+ melody and words draws as chords and words. The words stay, spaced by
16
+ beat under the chords. The melody is left out only beside a line that
17
+ draws its bars; a melody on its own stays, a line with a problem stays
18
+ so the grid still shows where the problem is, and a singing line that
19
+ writes chord names, `N.C.` or `?` (or a `%` copying one) stays; nothing
20
+ musical changes.
21
+
22
+ ## [0.20.2] - 2026-11-19
23
+
24
+ ### Changed
25
+
26
+ - **Requires `barmark` 0.25.0**, whose minor release a caret range
27
+ would not reach.
28
+
9
29
  ## [0.20.1] - 2026-11-14
10
30
 
11
31
  ### Changed
@@ -571,7 +591,9 @@ that needs no script or as the `<barmark-chart>` web component. Requires
571
591
  zoom without sideways scrolling, the element renders and re-renders, and
572
592
  a screen reader hears "bar 9: D". Run them with `bun run test:browser`.
573
593
 
574
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.20.1...HEAD
594
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.21.0...HEAD
595
+ [0.21.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.20.2...render-v0.21.0
596
+ [0.20.2]: https://github.com/kevinpeckham/barmark/compare/render-v0.20.1...render-v0.20.2
575
597
  [0.20.1]: https://github.com/kevinpeckham/barmark/compare/render-v0.20.0...render-v0.20.1
576
598
  [0.20.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.19.1...render-v0.20.0
577
599
  [0.19.1]: https://github.com/kevinpeckham/barmark/compare/render-v0.19.0...render-v0.19.1
package/README.md CHANGED
@@ -53,7 +53,7 @@ whenever one changes; it fetches a `src` once, and renders once however
53
53
  many properties and attributes change together. A chart rendered on the
54
54
  server by `renderChart` keeps its music until it has a source of its own,
55
55
  and still follows `theme`, `bar-numbers`, `wrap` and `columns`; a change to
56
- `numerals`, `rehearsal-letters`, `show-part`, `chord-diagrams` or
56
+ `numerals`, `rehearsal-letters`, `melody`, `show-part`, `chord-diagrams` or
57
57
  `diagram-hand` needs the chart's text, so it waits for a source.
58
58
 
59
59
  For a live editor, set `text`:
@@ -83,6 +83,7 @@ the element loads, with `<style data-barmark-font>` holding
83
83
  | `rehearsalLetters` | `rehearsal-letters` (`rehearsalLetters`) | `false` | boxed A, B, C… on each section as played; none when the chart writes a rehearsal mark of its own (below) |
84
84
  | `numerals` | `numerals` (`numerals`) | none | `"nashville"` (6m⁷) or `"roman"` (vi⁷): each chord as its degree in its bar's key |
85
85
  | `wrap` | `wrap="off"` (`wrap`) | `true` | wrap a section's rows when it is wider than the chart's box; off, rows keep their columns and the chart overflows, for its page to scroll |
86
+ | `melody` | `melody="off"` (`melody`) | `true` | `false` leaves a voice part's singing line out of the grid; its words stay, drawn by beat under the chords. The melody is left out only beside a line that draws its bars; a melody on its own stays, and so does a line with a problem or one that writes chord names, `N.C.` or `?`. In a one-part lead sheet the chord line then draws as a plain row with no label. `@barmark/score`'s score view still shows it |
86
87
  | `columns` | `columns="row"` (`columns`) | `"shared"` | `"shared"`: a section's rows share column tracks, so bar lines line up down the section; `"row"`: each row sizes its own bars (below). Any other value is `"shared"` |
87
88
  | `part` | `show-part` (`showPart`) | none | draw only the part with this label, as one player reads it: tutti bars, its own bars, and "tacet" where it rests. The attribute isn't `part`, which HTML keeps for `::part()` styling |
88
89
  | `chordDiagrams` | `chord-diagrams="guitar"` (`chordDiagrams`) | none | `"guitar"`: a strip of guitar chord diagrams after the header, one for each distinct chord (below). Any other value is off |
package/dist/element.js CHANGED
@@ -20,6 +20,8 @@ export function optionsFromAttributes(el) {
20
20
  barNumbers: el.getAttribute("bar-numbers") !== "off",
21
21
  rehearsalLetters: el.hasAttribute("rehearsal-letters"),
22
22
  wrap: el.getAttribute("wrap") !== "off",
23
+ // Only "off" hides the melody; anything else, or none, leaves it unset.
24
+ ...(el.getAttribute("melody") === "off" ? { melody: false } : {}),
23
25
  ...(numerals ? { numerals } : {}),
24
26
  ...(part ? { part } : {}),
25
27
  ...(diagrams ? { chordDiagrams: "guitar" } : {}),
@@ -66,6 +68,7 @@ function defineElement() {
66
68
  "rehearsal-letters",
67
69
  "numerals",
68
70
  "wrap",
71
+ "melody",
69
72
  "show-part",
70
73
  "columns",
71
74
  "chord-diagrams",
@@ -134,6 +137,15 @@ function defineElement() {
134
137
  else
135
138
  this.setAttribute("wrap", "off");
136
139
  }
140
+ get melody() {
141
+ return optionsFromAttributes(this).melody ?? true;
142
+ }
143
+ set melody(v) {
144
+ if (v)
145
+ this.removeAttribute("melody");
146
+ else
147
+ this.setAttribute("melody", "off");
148
+ }
137
149
  get rehearsalLetters() {
138
150
  return this.hasAttribute("rehearsal-letters");
139
151
  }
package/dist/html.d.ts CHANGED
@@ -21,6 +21,13 @@ export type RenderOptions = {
21
21
  wrap?: boolean;
22
22
  /** Draw only the part with this label (barmark's grammar 7.4): one player's view. */
23
23
  part?: string;
24
+ /**
25
+ * Draw a singer's melody line in the grid (the default). With `false`
26
+ * (the attribute `melody="off"`) it is left out beside a line that draws
27
+ * its bars, its words kept under the chords. A melody on its own stays, and
28
+ * so does a singing line with a problem or with chord names.
29
+ */
30
+ melody?: boolean;
24
31
  /**
25
32
  * How a section sizes its columns. `"shared"` (the default): its rows share
26
33
  * column tracks, so bar lines line up down the section and the widest bar
package/dist/html.js CHANGED
@@ -9,7 +9,7 @@ import { creditsText } from "./credits.js";
9
9
  import { diagramSvg } from "./diagram.js";
10
10
  import { escapeHtml } from "./escape.js";
11
11
  import { fontFaceCss } from "./font.js";
12
- import { isTacet as isTacetCell, layoutChart } from "./model.js";
12
+ import { isTacet as isTacetCell, layoutChart, meloffChanged } from "./model.js";
13
13
  import { barLabel, speakBar, speakDiagram, speakVerses, UNPLAYABLE, VOICING_REPLACED, } from "./speech.js";
14
14
  import { FIT_STEPS, MIN_BAR, stylesheet } from "./styles.js";
15
15
  import { beatLinesHtml, pitchHtml, sungBar, sungSlotHtml, verseNumbersHtml, verseWidth, } from "./verses-html.js";
@@ -25,6 +25,7 @@ function elementAttributes(options) {
25
25
  options.rehearsalLetters ? " rehearsal-letters" : "",
26
26
  numeralsOf(options) ? ` numerals="${numeralsOf(options)}"` : "",
27
27
  options.wrap === false ? ' wrap="off"' : "",
28
+ options.melody === false ? ' melody="off"' : "",
28
29
  options.part ? ` show-part="${escapeHtml(options.part)}"` : "",
29
30
  byRow(options) ? ' columns="row"' : "",
30
31
  diagramAttributes(options),
@@ -53,18 +54,17 @@ function chartHtml(text, options) {
53
54
  const model = layoutChart(text, {
54
55
  rehearsalLetters: options.rehearsalLetters ?? false,
55
56
  ...(options.part && { part: options.part }),
57
+ ...(options.melody === false && { melody: false }),
56
58
  ...(options.chordDiagrams === "guitar" && { chordDiagrams: "guitar" }),
57
59
  });
58
60
  const barNumbers = options.barNumbers ?? true;
59
- const parts = labelled(model);
61
+ const { parts, widest } = gutterOf(model, options);
60
62
  const settings = {
61
63
  barNumbers,
62
64
  gutter: barNumbers || parts,
63
65
  numerals: numeralsOf(options),
64
66
  rows: byRow(options),
65
67
  };
66
- // Every section's left column is as wide as the longest part label, so tutti rows line up with systems.
67
- const widest = Math.max(0, ...model.parts.flatMap(rowLabelsOf).map((l) => l.length));
68
68
  const gutter = parts ? ` data-parts style="--bm-label-chars:${widest}"` : "";
69
69
  return `<div class="bm-chart" data-theme="${themeOf(options)}"${gutter}${layoutAttributes(options, settings)}>${headerHtml(model)}${diagramsHtml(model.diagrams, settings.numerals, handOf(options))}${model.blocks.map((b) => blockHtml(b, settings)).join("")}${copyrightHtml(model)}${options.diagnostics ? diagnosticsHtml(model) : ""}</div>`;
70
70
  }
@@ -72,6 +72,19 @@ function chartHtml(text, options) {
72
72
  const layoutAttributes = (options, settings) => `${settings.barNumbers ? "" : ' data-bar-numbers="off"'}${options.wrap === false ? ' data-wrap="off"' : ""}${settings.rows ? ' data-columns="row"' : ""}`;
73
73
  /** Whether systems have labelled rows: several parts, or one part writing lines (barmark's grammar 7.6). */
74
74
  const labelled = (model) => model.parts.length > 1 || model.parts.some((p) => (p.lines?.length ?? 0) > 0);
75
+ /**
76
+ * Whether rows are labelled, and how wide the longest label is: every
77
+ * section's left column is as wide, so tutti rows line up with systems.
78
+ * Where `melody: false` changed the drawing, only the labels the systems draw count.
79
+ */
80
+ function gutterOf(model, options) {
81
+ const drawn = options.melody === false && meloffChanged(model);
82
+ const labels = drawn ? drawnLabels(model) : model.parts.flatMap(rowLabelsOf);
83
+ const parts = drawn ? labels.length > 0 : labelled(model);
84
+ return { parts, widest: Math.max(0, ...labels.map((l) => l.length)) };
85
+ }
86
+ /** The labels of the system rows the blocks draw. */
87
+ const drawnLabels = (model) => model.blocks.flatMap((b) => b.items.flatMap((i) => (i.kind === "system" ? i.rows.map((r) => r.label) : [])));
75
88
  /** A part's row labels: its own, and one per line it writes (barmark's grammar 7.6). */
76
89
  const rowLabelsOf = (p) => [
77
90
  p.label ?? "",
package/dist/model.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { CellModel, ChartModel, LayoutOptions } from "./types.js";
2
+ export declare const meloffChanged: (model: ChartModel) => boolean;
2
3
  export declare function layoutChart(text: string, options?: LayoutOptions): ChartModel;
3
4
  /** A bar where the part rests, in a system or a part's own view (barmark's grammar 7.4). */
4
5
  export declare const isTacet: (c: CellModel) => boolean;
package/dist/model.js CHANGED
@@ -8,6 +8,9 @@ import { extractPart, parseChart, printedAsWritten, unreadSlots, } from "barmark
8
8
  import { chartDiagrams } from "./diagrams.js";
9
9
  import { tempoBeatOf, tempoBeats } from "./tempo.js";
10
10
  import { landings, rowVerses, singerOf, sungVerses } from "./verses.js";
11
+ /** Models `melody: false` changed the drawing of: the markup sizes its label gutter from the rows drawn only for these. */
12
+ const meloffModels = new WeakSet();
13
+ export const meloffChanged = (model) => meloffModels.has(model);
11
14
  /** Whether a tutti bar's parts play different slots, as `%` or `/` on a tutti line can. */
12
15
  const playedApart = (b, line) => {
13
16
  const own = (b.parts ?? []).filter((p) => p?.line === line).map((p) => JSON.stringify(p?.slots));
@@ -70,12 +73,15 @@ export function layoutChart(text, options = {}) {
70
73
  written: new Map(groups.flatMap((g) => (g.heading ? [[g.heading.line, g]] : []))),
71
74
  bars: indexByLine(barsByLine(parse)),
72
75
  beats: tempoBeats(parse.lines),
76
+ melody: options.melody !== false,
77
+ changed: false,
78
+ melodies: new Map(),
73
79
  };
74
80
  const blocks = groups.map((g) => layoutGroup(g, ctx));
75
81
  // A chart that writes its own rehearsal marks keeps them alone: letters beside them would mark each place twice.
76
82
  if (options.rehearsalLetters && !parse.bars.some((b) => b.rehearsal !== undefined))
77
83
  letterBlocks(blocks);
78
- return {
84
+ const model = {
79
85
  title: parse.title,
80
86
  part: parse.part,
81
87
  parts: parse.parts,
@@ -86,6 +92,9 @@ export function layoutChart(text, options = {}) {
86
92
  diagnostics: parse.diagnostics,
87
93
  diagrams: options.chordDiagrams === "guitar" ? chartDiagrams(blocks, parse) : [],
88
94
  };
95
+ if (ctx.changed)
96
+ meloffModels.add(model);
97
+ return model;
89
98
  }
90
99
  /** The beat the header's tempo counts: its directives' (they share the next bar line), or the default. */
91
100
  function headerBeat(lines, beats) {
@@ -266,15 +275,80 @@ function layoutLines(lines, occurrence, ctx) {
266
275
  continue;
267
276
  const laid = system === null
268
277
  ? layoutOne(l, occurrence, previous, ctx)
269
- : layoutSystemAt(systemLines(lines, i), occurrence, previous, ctx);
278
+ : layoutSystemOf(systemLines(lines, i), occurrence, previous, ctx);
270
279
  previous = laid.previous;
271
280
  items.push(...laid.items);
272
281
  }
273
282
  return items;
274
283
  }
275
- /** A system, and the words under it that no line in it sings. */
276
- function layoutSystemAt(lines, occurrence, previous, ctx) {
277
- const item = layoutSystem(lines, occurrence, previous, ctx);
284
+ /**
285
+ * A system as drawn: with `melody: false`, its melody lines are left out when
286
+ * a line that does not sing still draws its bars, and their words draw by
287
+ * beat under the rest. In a chart of one singing part, the part's lone bare
288
+ * line draws as a line outside a system does.
289
+ */
290
+ function layoutSystemOf(written, occurrence, previous, ctx) {
291
+ if (ctx.melody)
292
+ return layoutSystemAt(written, written, occurrence, previous, ctx);
293
+ const lines = withoutMelody(written, ctx);
294
+ if (lines.length < written.length)
295
+ ctx.changed = true;
296
+ const [only] = lines;
297
+ if (only && lines.length === 1 && loneBare(only, ctx)) {
298
+ ctx.changed = true;
299
+ return layoutOne(only, occurrence, previous, ctx);
300
+ }
301
+ return layoutSystemAt(lines, written, occurrence, previous, ctx);
302
+ }
303
+ /** Whether the line is the bare line of a chart's only part, which has a singing line, and does not sing itself. */
304
+ const loneBare = (l, ctx) => ctx.parse.parts.length === 1 &&
305
+ ctx.parse.parts[0]?.sings !== undefined &&
306
+ l.lineName === undefined &&
307
+ !sings(l, ctx);
308
+ /** A line with a problem the grid draws where it is written: as written, or on its unreadable slots. */
309
+ const flawed = (l, ctx) => ctx.errors.has(l.line) || ctx.unread.has(l.line);
310
+ const sings = (l, ctx) => l.kind === "bars" && singerOf(l, ctx.parse) !== null;
311
+ const membersOf = (s) => (s.kind === "group" ? s.members : [s]);
312
+ /** A slot a melody is made of: a hold, a rest, or a note set. */
313
+ const melodic = (s) => membersOf(s).every((m) => m.kind === "hold" || m.kind === "silence" || (m.kind === "chord" && m.chord.kind === "notes"));
314
+ /**
315
+ * Whether every slot of the line, as written and as its bars play, is
316
+ * melodic: a chord name, `N.C.`, `?` or a `%` copying one is not. Read once
317
+ * a line, and each bar's slots once however often it plays: a section's
318
+ * every replay asks.
319
+ */
320
+ function melodyOnly(l, ctx) {
321
+ const known = ctx.melodies.get(l.line);
322
+ if (known !== undefined)
323
+ return known;
324
+ const read = new Set();
325
+ const melodicAll = (slots) => {
326
+ if (read.has(slots))
327
+ return true;
328
+ read.add(slots);
329
+ return slots.every(melodic);
330
+ };
331
+ const only = l.cells.every((c) => c.kind !== "slots" || melodicAll(c.slots)) &&
332
+ barsOn(l.line, ctx).every((b) => melodicAll(b.slots));
333
+ ctx.melodies.set(l.line, only);
334
+ return only;
335
+ }
336
+ /**
337
+ * The system's lines but its melody lines (barmark's grammar 7.7): a singing
338
+ * line with no problem drawn in place whose slots are all notes, holds or
339
+ * rests. They go only when a line that does not sing still draws its bars;
340
+ * else all the lines stay.
341
+ */
342
+ function withoutMelody(lines, ctx) {
343
+ const draws = (l) => l.kind === "bars" && !ctx.errors.has(l.line);
344
+ if (!lines.some((l) => !sings(l, ctx) && draws(l)))
345
+ return lines;
346
+ const melody = (l) => l.kind === "bars" && sings(l, ctx) && !flawed(l, ctx) && melodyOnly(l, ctx);
347
+ return lines.filter((l) => !melody(l));
348
+ }
349
+ /** A system, and the words under it that no line in it sings; `written` is every line the system writes, drawn or not. */
350
+ function layoutSystemAt(lines, written, occurrence, previous, ctx) {
351
+ const item = layoutSystem(lines, written, occurrence, previous, ctx);
278
352
  const lyrics = lyricRows(lines, occurrence, ctx);
279
353
  // The words go under the system: in its last row that plays.
280
354
  const last = item.rows.findLastIndex((p) => p.row.kind === "row" && !p.row.cells.some(isTacet));
@@ -347,7 +421,7 @@ const spokenOf = (p, l) => l.lineName === undefined ? p.name : `${p.name} ${l.li
347
421
  /** A system row's label: the part's, and its line's name (`Pno.RH`). */
348
422
  const labelOf = (l) => `${l.part ?? ""}${l.lineName === undefined ? "" : `.${l.lineName}`}`;
349
423
  /** A row per declared part, or per line it writes, in score order: its own line, its error, or tacet bars. */
350
- function layoutSystem(lines, occurrence, previous, ctx) {
424
+ function layoutSystem(lines, written, occurrence, previous, ctx) {
351
425
  const ref = lines.find((l) => l.kind === "bars" && !ctx.errors.has(l.line));
352
426
  const reference = ref ? layoutRow(ref, playedOn(ref.line, occurrence, ctx), previous, ctx) : null;
353
427
  const ownRow = (own) => ctx.errors.has(own.line) || own.kind !== "bars"
@@ -355,6 +429,9 @@ function layoutSystem(lines, occurrence, previous, ctx) {
355
429
  : layoutRow(own, playedOn(own.line, occurrence, ctx), previous, ctx);
356
430
  const rows = ctx.parse.parts.flatMap((p) => {
357
431
  const own = ownLines(lines, p);
432
+ // A part whose every line was left out has no row; one with no line written is tacet.
433
+ if (!own.length && ownLines(written, p).length)
434
+ return [];
358
435
  if (!own.length)
359
436
  return [
360
437
  { label: p.label ?? "", name: p.name, row: tacetRow(reference, lines[0]?.line ?? 0) },
package/dist/types.d.ts CHANGED
@@ -9,6 +9,13 @@ export type LayoutOptions = {
9
9
  */
10
10
  rehearsalLetters?: boolean;
11
11
  part?: string;
12
+ /**
13
+ * Draw a singer's melody line in the grid (the default, `true`). With
14
+ * `false` it is left out of a system that has another line which draws its
15
+ * bars, and its words draw by beat under the chords. A melody on its own
16
+ * stays; so does a singing line with a problem or with chord names.
17
+ */
18
+ melody?: boolean;
12
19
  /** Give the model a diagram entry for each chord, as a guitar plays it; off when absent. */
13
20
  chordDiagrams?: "guitar";
14
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barmark/render",
3
- "version": "0.20.1",
3
+ "version": "0.21.0",
4
4
  "description": "Render barmark chord charts as a clean, accessible bar grid: HTML with Declarative Shadow DOM, or the <barmark-chart> web component.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -47,8 +47,8 @@
47
47
  "url": "https://github.com/kevinpeckham/barmark/issues"
48
48
  },
49
49
  "dependencies": {
50
- "@barmark/fretboard": "^0.1.1",
51
- "barmark": "^0.24.0"
50
+ "@barmark/fretboard": "^0.1.2",
51
+ "barmark": "^0.25.0"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "rm -rf dist && tsc -p tsconfig.build.json",