@barmark/render 0.17.1 → 0.19.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,92 @@ package uses [semantic versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.19.0] - 2026-11-10
10
+
11
+ ### Added
12
+
13
+ - **`columns: "shared" | "row"`**, and the `columns` attribute and
14
+ property on `<barmark-chart>` (stem-shovel#16, ask 5). `"shared"`, the
15
+ default, draws every chart byte for byte as before (a snapshot over
16
+ `examples/` and every chart fixture in the repository holds it to
17
+ that). With `"row"` each row, and each system of parts, sizes its own
18
+ bars to their content, so one busy bar no longer widens its column in
19
+ every row of the section; bar lines no longer line up between rows. The
20
+ chart takes `data-columns="row"`, a section wraps once its widest row
21
+ no longer fits, and the music, the markup inside each bar and what a
22
+ screen reader hears don't change. Any other value is `"shared"`. The
23
+ stylesheet gains the `"row"` rules at its end; `Columns` is exported.
24
+ - **An ending across rows** (barmark's grammar 5.1, an ending continuing
25
+ onto the lines after it). A row an ending continues onto has the
26
+ ending's passes as the model's new optional `continues`, draws the
27
+ bracket's line on over its bars (class `bm-ending`) without a second
28
+ number, and is spoken "ending for pass 1, continued". In a system every
29
+ part's row does.
30
+
31
+ ### Changed
32
+
33
+ - **Breaking: requires `barmark` 0.23.0** (`SimpleSlot.text`: an
34
+ unreadable slot keeps its bar as unknown harmony with its text), whose
35
+ minor release a caret range would not reach.
36
+ - **An unreadable slot is drawn as written** (barmark's grammar 2.3): where
37
+ a slot is unknown harmony with the author's text, such as a `%` copying
38
+ a bar with `CM7`, the bar draws `CM7` (escaped) where it would draw
39
+ `?`, and speaks it as "unreadable: CM7". A written `?` is drawn and
40
+ spoken as before.
41
+ - **A bar line whose only errors are unreadable slots draws as a row**
42
+ (barmark's grammar 2.3, 8), as the printer prints it, instead of as the
43
+ error box: each such slot is drawn as written in the error colour
44
+ (`--barmark-accent`, wavy underline), with the new `::part(unread)` and
45
+ class `bm-unread`, its message as a `title` tooltip and in the bar's
46
+ spoken name ("bar 2: unreadable: CM7, error: …"). The model's slots
47
+ cell gains `unread`, the messages in order. A `%` copy of the bar draws
48
+ the text without the error. A line with any other error still draws as
49
+ the error box.
50
+ - **`rehearsalLetters` adds no letters to a chart with marks of its own.**
51
+ When any bar carries its own rehearsal mark (`@A`, barmark's grammar
52
+ 2.5), the option now letters nothing, where it lettered every section
53
+ beside the chart's marks, so headings showed twice. A chart without
54
+ marks is lettered as before.
55
+ - **The model gains `tempoBeat`** (`{ note, dotted }`, `note` 2, 4, 8 or
56
+ 16) on `ChartModel`, for the header, and on each directive item: the
57
+ beat a tempo there counts (see Fixed). A directive item built by hand
58
+ needs it.
59
+
60
+ ### Fixed
61
+
62
+ - **A tempo shows the beat it counts.** The header and mid-chart changes
63
+ always drew `♩ =`, so 6/8 with `tempo: 40` showed "♩ = 40" though
64
+ barmark (grammar 2.1) and the MIDI and MusicXML exports count 40 dotted
65
+ quarters. A tempo, and a `rit.` or `accel.` `to` one, now shows the beat
66
+ of the `time:` in force at the bar it applies to, as the parser, MIDI and
67
+ MusicXML count it: "♩. = 40" in 6/8, 9/8 and 12/8, 𝅗𝅥 in 2/2, ♪ in 3/8,
68
+ ♩ in 4/4 as before. A `time:` change mid-chart moves it, even one
69
+ written on the line after the `tempo:`; a one-bar meter does not
70
+ (grammar 2.4). The note's `.bm-beat` span tries Apple Symbols, Segoe UI
71
+ Symbol, Noto Music and Symbola first, which hold 𝅗𝅥 and 𝅘𝅥𝅯. Screen
72
+ readers hear the note's name ("dotted quarter note").
73
+
74
+ ## [0.18.0] - 2026-11-09
75
+
76
+ ### Changed
77
+
78
+ - **Requires `barmark` 0.22.0** (a pickup is bar 0, `ChartParse.pickup`),
79
+ whose minor release a caret range would not reach.
80
+ - **A pickup is bar 0** (barmark's grammar 2.4). The gutter draws no
81
+ number on a row that starts with the pickup, and the screen-reader
82
+ text says "pickup" where it said "bar 1"; the bars after it are
83
+ numbered from 1. `RowModel.barNumber` is `0` on such a row. Charts
84
+ without a pickup render exactly as before.
85
+
86
+ ### Fixed
87
+
88
+ - **A bar played many times, or one with many notes and syllables, lays
89
+ out in linear time.** Deciding whether a chart with no parts sings read
90
+ every syllable of every played bar (now once per written bar, with a
91
+ `barmark` whose plays share their syllables), and placing a singing
92
+ bar's syllables under its slots scanned every slot for each syllable
93
+ (now a binary search).
94
+
9
95
  ## [0.17.1] - 2026-11-08
10
96
 
11
97
  ### Changed
@@ -439,7 +525,9 @@ that needs no script or as the `<barmark-chart>` web component. Requires
439
525
  zoom without sideways scrolling, the element renders and re-renders, and
440
526
  a screen reader hears "bar 9: D". Run them with `bun run test:browser`.
441
527
 
442
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.17.1...HEAD
528
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.19.0...HEAD
529
+ [0.19.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.18.0...render-v0.19.0
530
+ [0.18.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.17.1...render-v0.18.0
443
531
  [0.17.1]: https://github.com/kevinpeckham/barmark/compare/render-v0.17.0...render-v0.17.1
444
532
  [0.17.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.16.2...render-v0.17.0
445
533
  [0.16.2]: https://github.com/kevinpeckham/barmark/compare/render-v0.16.1...render-v0.16.2
package/README.md CHANGED
@@ -48,7 +48,7 @@ The element renders from its `text` property, its `src` URL, or a child
48
48
  whenever one changes; it fetches a `src` once, and renders once however
49
49
  many properties and attributes change together. A chart rendered on the
50
50
  server by `renderChart` keeps its music until it has a source of its own,
51
- and still follows `theme`, `bar-numbers` and `wrap`; a change to
51
+ and still follows `theme`, `bar-numbers`, `wrap` and `columns`; a change to
52
52
  `numerals`, `rehearsal-letters` or `show-part` needs the chart's text, so
53
53
  it waits for a source.
54
54
 
@@ -76,14 +76,36 @@ the element loads, with `<style data-barmark-font>` holding
76
76
  |---|---|---|---|
77
77
  | `theme` | `theme` (`theme`) | `"auto"` | `"auto"` follows the system; `"light"` or `"dark"` force one |
78
78
  | `barNumbers` | `bar-numbers="off"` (`barNumbers`) | `true` | bar numbers at the start of each row |
79
- | `rehearsalLetters` | `rehearsal-letters` (`rehearsalLetters`) | `false` | boxed A, B, C… on each section as played |
79
+ | `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) |
80
80
  | `numerals` | `numerals` (`numerals`) | none | `"nashville"` (6m⁷) or `"roman"` (vi⁷): each chord as its degree in its bar's key |
81
81
  | `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 |
82
+ | `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"` |
82
83
  | `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 |
83
84
  | `diagnostics` | | `false` | list the chart's errors and warnings below it |
84
85
  | `fontUrl` | | none | emit Edwin's `@font-face` rule before the chart |
85
86
  | (the `text` argument) | (`text`) | `null` | the chart to draw; wins over `src` and the script child |
86
87
 
88
+ ### Rehearsal letters
89
+
90
+ `rehearsalLetters` letters each section occurrence A, B, C… in play order,
91
+ for a chart that marks no places itself. When any bar in the chart carries
92
+ its own rehearsal mark (`@A`, barmark's grammar 2.5), it adds no letters at
93
+ all: the chart's marks stand alone, so no heading is marked twice, and a
94
+ section the chart leaves unmarked stays unmarked.
95
+
96
+ ### Columns
97
+
98
+ By default a section's rows share their columns: bar lines line up down
99
+ the section, and the widest bar in a column sets that column's width in
100
+ every row, so one busy bar (`| G7 | G7 C6/G Bbmaj7/F Fmaj9 |`) widens
101
+ column two all the way down. With `columns: "row"` (`columns="row"` on the
102
+ element) each row sizes its own bars to their content instead: the busy
103
+ bar widens only its own row, and bar lines no longer line up between rows.
104
+ Every row still starts at the first bar line, and a system's parts keep
105
+ their bar lines together. Only the layout changes: the music, the markup
106
+ inside each bar and what a screen reader hears are the same. A section
107
+ wraps on a narrow screen as before, once its widest row no longer fits.
108
+
87
109
  ### Numerals
88
110
 
89
111
  With `numerals`, each chord shows as its degree in the key its bar is
@@ -126,7 +148,7 @@ Set these custom properties on the element or anything above it:
126
148
  | `--barmark-paper` | the background |
127
149
  | `--barmark-muted` | holds, bar numbers, braces, meta lines |
128
150
  | `--barmark-rule` | bar lines |
129
- | `--barmark-accent` | errors |
151
+ | `--barmark-accent` | errors, and slots that can't be read |
130
152
  | `--barmark-directive` | mid-chart changes (default the muted colour) |
131
153
  | `--barmark-note` | `###` note lines (default the ink colour) |
132
154
  | `--barmark-lyrics` | syllables under a voice line and in lyric rows (default the ink colour) |
@@ -144,7 +166,7 @@ barmark-chart::part(heading) {
144
166
 
145
167
  `::part()` names: `title`, `meta`, `heading`, `bar`, `chord`, `text`,
146
168
  `bar-number`, `rehearsal`, `lyrics` (each verse's line of words, inside
147
- its `bar`). These, the custom properties and the
169
+ its `bar`), `unread` (a slot that can't be read, drawn as written). These, the custom properties and the
148
170
  attributes are the public surface: changing them is a breaking change.
149
171
 
150
172
  ## Light, dark and print
@@ -179,6 +201,14 @@ Bar numbers sit in a gutter at the left edge; section headings, lyrics,
179
201
  note lines and mid-chart changes start at the first bar line. Chords start
180
202
  at the left of their share of the bar. A change written mid-chart names
181
203
  itself: `time: 3/4, tempo: 120` draws as "→ Time 3/4 · Tempo ♩ = 120".
204
+ A tempo shows the beat `tempo:` counts (barmark's grammar 2.1), from the
205
+ `time:` in force at the bar it applies to (a `time:` on the next line
206
+ counts): the bottom number in a simple meter
207
+ (♩ in 4/4, 𝅗𝅥 in 2/2, ♪ in 3/8) and the dotted quarter in 6/8, 9/8 and
208
+ 12/8, so 6/8 with `tempo: 40` shows "♩. = 40" and a `rit. to 90` there
209
+ "rit. to ♩. = 90". A one-bar meter never changes it (grammar 2.4). The
210
+ note is spoken by name ("dotted quarter note"), and the model gives it as
211
+ `tempoBeat` on the chart (for the header) and on each directive item.
182
212
  At the default size chords are 16px and no label is under 12px.
183
213
 
184
214
  Chords appear in their canonical form whatever the author typed (`Cø`
@@ -186,8 +216,12 @@ shows as Cm⁷(♭5)). `%` is drawn as the bar it copies; a replayed section
186
216
  is drawn in full, and its own lyrics replace the written section's. Bar
187
217
  numbers count the bars as written, each once, as a band counts them: a
188
218
  repeat, an ending, a jump or a replay doesn't move them, so a replayed
189
- section shows the numbers it was written with. A line with an error shows as written, underlined,
190
- with its message. `layoutChart(text)` returns all of this as data, if
219
+ section shows the numbers it was written with. A pickup is bar 0: its
220
+ row shows no number in the gutter (`barNumber` is `0` in the model) and
221
+ is spoken as "pickup", and the bars after it are 1, 2, and so on. A line with an error shows as written, underlined,
222
+ with its message, unless its only errors are slots that can't be read
223
+ (`CM7`): that line draws as usual, each such slot as written in the
224
+ error colour with its message as a tooltip and in the bar's spoken name. `layoutChart(text)` returns all of this as data, if
191
225
  you want to draw it yourself, and `typesetChord(parts)` with `glyphs`
192
226
  gives a chord's pieces as the page sets them (root and quality, the
193
227
  raised extension, the bass after a slash, ♯ and ♭), and
package/dist/element.js CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { NUMERALS } from "./chord.js";
8
8
  import { FONT_FAMILY, fontFaceCss } from "./font.js";
9
- import { loadErrorContent, shadowContent, THEMES } from "./html.js";
9
+ import { loadErrorContent, shadowContent, THEMES, } from "./html.js";
10
10
  export function optionsFromAttributes(el) {
11
11
  const theme = el.getAttribute("theme");
12
12
  const numerals = NUMERALS.find((n) => n === el.getAttribute("numerals"));
@@ -19,6 +19,8 @@ export function optionsFromAttributes(el) {
19
19
  wrap: el.getAttribute("wrap") !== "off",
20
20
  ...(numerals ? { numerals } : {}),
21
21
  ...(part ? { part } : {}),
22
+ // Only "row" changes the layout; anything else, or none, keeps the shared columns.
23
+ ...(el.getAttribute("columns") === "row" ? { columns: "row" } : {}),
22
24
  };
23
25
  }
24
26
  /** What a chart draws: its `text` while that is a string, else `src`, else its script child. */
@@ -60,6 +62,7 @@ function defineElement() {
60
62
  "numerals",
61
63
  "wrap",
62
64
  "show-part",
65
+ "columns",
63
66
  ];
64
67
  #observer = new MutationObserver(() => this.#schedule());
65
68
  #renders = 0;
@@ -140,6 +143,16 @@ function defineElement() {
140
143
  else
141
144
  this.setAttribute("numerals", v);
142
145
  }
146
+ /** "row" when each row sizes its own columns; "shared", the default, otherwise. */
147
+ get columns() {
148
+ return optionsFromAttributes(this).columns ?? "shared";
149
+ }
150
+ set columns(v) {
151
+ if (v === "row")
152
+ this.setAttribute("columns", "row");
153
+ else
154
+ this.removeAttribute("columns");
155
+ }
143
156
  /** The label of the part to draw on its own, or null for the whole chart. */
144
157
  get showPart() {
145
158
  return this.getAttribute("show-part");
@@ -202,6 +215,11 @@ function defineElement() {
202
215
  chart?.setAttribute("data-wrap", "off");
203
216
  else
204
217
  chart?.removeAttribute("data-wrap");
218
+ // data-fit keeps the estimate the chart was drawn with: a shared one wraps a "row" section a little early.
219
+ if (options.columns === "row")
220
+ chart?.setAttribute("data-columns", "row");
221
+ else
222
+ chart?.removeAttribute("data-columns");
205
223
  }
206
224
  }
207
225
  customElements.define("barmark-chart", BarmarkChart);
package/dist/html.d.ts CHANGED
@@ -2,6 +2,11 @@ import { type Numerals } from "./chord.js";
2
2
  export type RenderOptions = {
3
3
  theme?: "auto" | "light" | "dark";
4
4
  barNumbers?: boolean;
5
+ /**
6
+ * Boxed letters A, B, C… on each section as played. None when any bar
7
+ * carries its own rehearsal mark (`@A`, barmark's grammar 2.5): the
8
+ * chart's marks then stand alone, so no place is marked twice.
9
+ */
5
10
  rehearsalLetters?: boolean;
6
11
  /** List the chart's errors and warnings below it. */
7
12
  diagnostics?: boolean;
@@ -16,7 +21,17 @@ export type RenderOptions = {
16
21
  wrap?: boolean;
17
22
  /** Draw only the part with this label (barmark's grammar 7.4): one player's view. */
18
23
  part?: string;
24
+ /**
25
+ * How a section sizes its columns. `"shared"` (the default): its rows share
26
+ * column tracks, so bar lines line up down the section and the widest bar
27
+ * sets its column's width in every row. `"row"`: each row sizes its own
28
+ * cells, so one busy bar widens only its own row; bar lines no longer line
29
+ * up between rows. A system's parts still share theirs. Any other value is
30
+ * `"shared"`.
31
+ */
32
+ columns?: Columns;
19
33
  };
34
+ export type Columns = "shared" | "row";
20
35
  export declare function renderChart(text: string, options?: RenderOptions): string;
21
36
  export declare const THEMES: readonly ["auto", "light", "dark"];
22
37
  /** What goes in the shadow root: the styles and the chart. */
package/dist/html.js CHANGED
@@ -9,7 +9,7 @@ import { creditsText } from "./credits.js";
9
9
  import { escapeHtml } from "./escape.js";
10
10
  import { fontFaceCss } from "./font.js";
11
11
  import { isTacet as isTacetCell, layoutChart } from "./model.js";
12
- import { speakBar, speakVerses } from "./speech.js";
12
+ import { barLabel, speakBar, speakVerses } from "./speech.js";
13
13
  import { FIT_STEPS, MIN_BAR, stylesheet } from "./styles.js";
14
14
  import { beatLinesHtml, pitchHtml, sungBar, sungSlotHtml, verseNumbersHtml, verseWidth, } from "./verses-html.js";
15
15
  export function renderChart(text, options = {}) {
@@ -25,12 +25,15 @@ function elementAttributes(options) {
25
25
  numeralsOf(options) ? ` numerals="${numeralsOf(options)}"` : "",
26
26
  options.wrap === false ? ' wrap="off"' : "",
27
27
  options.part ? ` show-part="${escapeHtml(options.part)}"` : "",
28
+ byRow(options) ? ' columns="row"' : "",
28
29
  ].join("");
29
30
  }
30
31
  export const THEMES = ["auto", "light", "dark"];
31
32
  /** Only a known theme reaches the markup: hosts may pass any string through. */
32
33
  const themeOf = (options) => THEMES.find((t) => t === options.theme) ?? "auto";
33
34
  const numeralsOf = (options) => NUMERALS.find((n) => n === options.numerals) ?? null;
35
+ /** Whether each row sizes its own columns: only for `"row"` exactly, so anything else a host passes is shared. */
36
+ const byRow = (options) => options.columns === "row";
34
37
  /** What goes in the shadow root: the styles and the chart. */
35
38
  export const shadowContent = (text, options = {}) => `<style>${stylesheet}</style>${chartHtml(text, options)}`;
36
39
  /** A chart that could not be loaded: the message, shown where the chart would be. */
@@ -50,12 +53,15 @@ function chartHtml(text, options) {
50
53
  barNumbers,
51
54
  gutter: barNumbers || parts,
52
55
  numerals: numeralsOf(options),
56
+ rows: byRow(options),
53
57
  };
54
58
  // Every section's left column is as wide as the longest part label, so tutti rows line up with systems.
55
59
  const widest = Math.max(0, ...model.parts.flatMap(rowLabelsOf).map((l) => l.length));
56
60
  const gutter = parts ? ` data-parts style="--bm-label-chars:${widest}"` : "";
57
- return `<div class="bm-chart" data-theme="${themeOf(options)}"${gutter}${settings.barNumbers ? "" : ' data-bar-numbers="off"'}${options.wrap === false ? ' data-wrap="off"' : ""}>${headerHtml(model)}${model.blocks.map((b) => blockHtml(b, settings)).join("")}${copyrightHtml(model)}${options.diagnostics ? diagnosticsHtml(model) : ""}</div>`;
61
+ return `<div class="bm-chart" data-theme="${themeOf(options)}"${gutter}${layoutAttributes(options, settings)}>${headerHtml(model)}${model.blocks.map((b) => blockHtml(b, settings)).join("")}${copyrightHtml(model)}${options.diagnostics ? diagnosticsHtml(model) : ""}</div>`;
58
62
  }
63
+ /** The chart's layout switches the stylesheet reads, each only when it is off its default. */
64
+ const layoutAttributes = (options, settings) => `${settings.barNumbers ? "" : ' data-bar-numbers="off"'}${options.wrap === false ? ' data-wrap="off"' : ""}${settings.rows ? ' data-columns="row"' : ""}`;
59
65
  /** Whether systems have labelled rows: several parts, or one part writing lines (barmark's grammar 7.6). */
60
66
  const labelled = (model) => model.parts.length > 1 || model.parts.some((p) => (p.lines?.length ?? 0) > 0);
61
67
  /** A part's row labels: its own, and one per line it writes (barmark's grammar 7.6). */
@@ -68,7 +74,9 @@ function headerHtml(model) {
68
74
  ? `<h2 class="bm-title" part="title">${escapeHtml(model.title)}</h2>`
69
75
  : "";
70
76
  const names = model.parts.length > 1 ? model.parts.map((p) => p.name).join(", ") : model.part?.name;
71
- const meta = [names ? escapeHtml(names) : "", metaText(model.header)].filter(Boolean).join(" · ");
77
+ const meta = [names ? escapeHtml(names) : "", metaHtml(model.header, model.tempoBeat)]
78
+ .filter(Boolean)
79
+ .join(" · ");
72
80
  const credits = creditsText(model.credits)
73
81
  .map((c) => `<p class="bm-credits" part="credits">${escapeHtml(c)}</p>`)
74
82
  .join("");
@@ -83,52 +91,86 @@ function copyrightHtml(model) {
83
91
  return "";
84
92
  return `<footer class="bm-copyright" part="copyright">${lines.map((c) => `<p>${escapeHtml(c)}</p>`).join("")}</footer>`;
85
93
  }
86
- /** "rit. to ♩ = 90", "accel.", "a tempo". */
87
- function tempoChangeText(c) {
94
+ /**
95
+ * Each beat note a tempo can count (barmark's grammar 2.1), and its name. A
96
+ * dotted beat adds a full stop, "♩.", as tempo marks are typed in text: the
97
+ * combining augmentation dot (U+1D16D) is missing from most fonts and sits
98
+ * apart from the note where it is drawn.
99
+ */
100
+ const BEAT_NOTES = {
101
+ 2: ["\u{1D15E}", "half"],
102
+ 4: ["♩", "quarter"],
103
+ 8: ["♪", "eighth"],
104
+ 16: ["\u{1D161}", "sixteenth"],
105
+ };
106
+ /** The beat note, spoken by its name: "♩." is "dotted quarter note". */
107
+ function beatHtml(beat) {
108
+ const [glyph, name] = BEAT_NOTES[beat.note];
109
+ const dotted = beat.dotted ? "dotted " : "";
110
+ return `<span class="bm-beat" role="img" aria-label="${dotted}${name} note">${glyph}${beat.dotted ? "." : ""}</span>`;
111
+ }
112
+ const tempoHtml = (bpm, beat) => `${beatHtml(beat)} = ${bpm}`;
113
+ /** "rit. to ♩ = 90" (♩. in 6/8), "accel.", "a tempo". */
114
+ function tempoChangeHtml(c, beat) {
88
115
  if (c.kind === "a tempo")
89
116
  return c.kind;
90
- return `${c.kind}.${c.to === null ? "" : ` to ♩ = ${c.to}`}`;
117
+ return `${c.kind}.${c.to === null ? "" : ` to ${tempoHtml(c.to, beat)}`}`;
91
118
  }
92
- /** "D major · 4/4 · ♩ = 145 · swing" (or "swing 58%"), escaped; labelled, "Key D major · Time 4/4 · …". */
93
- function metaText(d, labelled = false) {
119
+ /**
120
+ * "D major · 4/4 · ♩ = 145 · swing" (or "swing 58%"), as markup, a tempo
121
+ * counting `beat`; labelled, "Key D major · Time 4/4 · …".
122
+ */
123
+ function metaHtml(d, beat, labelled = false) {
94
124
  return [
95
- ["Key", d.key ? `${glyphs(d.key.tonic)} ${d.key.mode}` : ""],
125
+ ["Key", d.key ? escapeHtml(`${glyphs(d.key.tonic)} ${d.key.mode}`) : ""],
96
126
  ["Time", d.time ? `${d.time.n}/${d.time.d}` : ""],
97
- ["Tempo", d.tempo ? `♩ = ${d.tempo}` : ""],
127
+ ["Tempo", d.tempo ? tempoHtml(d.tempo, beat) : ""],
98
128
  // "a tempo" names itself; "Tempo a tempo" would stutter.
99
129
  [
100
130
  d.tempoChange?.kind === "a tempo" ? "" : "Tempo",
101
- d.tempoChange ? tempoChangeText(d.tempoChange) : "",
131
+ d.tempoChange ? tempoChangeHtml(d.tempoChange, beat) : "",
132
+ ],
133
+ [
134
+ "Feel",
135
+ d.feel
136
+ ? escapeHtml(`${d.feel}${d.swingPercent === undefined ? "" : ` ${d.swingPercent}%`}`)
137
+ : "",
102
138
  ],
103
- ["Feel", d.feel ? `${d.feel}${d.swingPercent === undefined ? "" : ` ${d.swingPercent}%`}` : ""],
104
139
  ]
105
140
  .filter(([, value]) => value)
106
- .map(([label, value]) => escapeHtml(labelled && label ? `${label} ${value}` : (value ?? "")))
141
+ .map(([label, value]) => (labelled && label ? `${label} ${value}` : (value ?? "")))
107
142
  .join(" · ");
108
143
  }
109
144
  function blockHtml(block, settings) {
110
145
  const label = block.heading === null ? "" : ` aria-label="${escapeHtml(block.heading)}"`;
111
- return `<section class="bm-section"${label}>${headingHtml(block)}<div class="bm-grid" style="--bm-cols:${Math.max(1, block.columns)}" data-fit="${fitWidth(block)}">${block.items.map((i) => itemHtml(i, block.columns, settings)).join("")}</div></section>`;
146
+ return `<section class="bm-section"${label}>${headingHtml(block)}<div class="bm-grid" style="--bm-cols:${Math.max(1, block.columns)}" data-fit="${fitWidth(block, settings.rows)}">${block.items.map((i) => itemHtml(i, block.columns, settings)).join("")}</div></section>`;
112
147
  }
113
148
  /**
114
- * Roughly how many em a section needs with its columns aligned, rounded up
115
- * to a step the stylesheet knows; narrower than that, its rows wrap.
149
+ * Roughly how many em a section needs, rounded up to a step the stylesheet
150
+ * knows; narrower than that, its rows wrap. With shared columns that is the
151
+ * widest cell of each column, added up; with `rows`, the widest row.
116
152
  */
117
- function fitWidth(block) {
153
+ function fitWidth(block, rows) {
154
+ const lines = block.items.map(rowWidths);
155
+ const sum = (widths) => widths.reduce((a, b) => a + b, 0);
156
+ const needed = rows ? Math.max(0, ...lines.map(sum)) : sum(widest(lines));
157
+ const total = 5 + needed;
158
+ return FIT_STEPS.find((step) => step >= total) ?? FIT_STEPS.at(-1) ?? 0;
159
+ }
160
+ /** Em per cell of a row: its bar, or the words under it when they are wider. None for anything else. */
161
+ function rowWidths(item) {
162
+ if (item.kind !== "row")
163
+ return [];
164
+ const verses = [...(item.verses ?? []), ...(item.lyrics ?? [])];
165
+ return widest([item.cells.map(cellWidth), ...verses.map((v) => v.cells.map(verseWidth))]);
166
+ }
167
+ /** The widest of each column across lines of widths. */
168
+ function widest(lines) {
118
169
  const widths = [];
119
- const widen = (bars) => {
120
- for (const [i, w] of bars.entries())
170
+ for (const line of lines)
171
+ for (const [i, w] of line.entries())
121
172
  widths[i] = Math.max(widths[i] ?? 0, w);
122
- };
123
- for (const item of block.items) {
124
- if (item.kind === "row")
125
- widen(item.cells.map(cellWidth));
126
- const verses = item.kind === "row" ? [...(item.verses ?? []), ...(item.lyrics ?? [])] : [];
127
- for (const v of verses)
128
- widen(v.cells.map(verseWidth));
129
- }
130
- const total = 5 + widths.reduce((a, b) => a + b, 0);
131
- return FIT_STEPS.find((step) => step >= total) ?? FIT_STEPS.at(-1) ?? 0;
173
+ return widths;
132
174
  }
133
175
  /** Em per bar: padding, plus each slot's text and the gap after it. */
134
176
  function cellWidth(cell) {
@@ -182,7 +224,7 @@ function itemHtml(item, columns, settings) {
182
224
  return `<p class="bm-text${item.note ? " bm-note" : ""}" part="text">${escapeHtml(item.text)}</p>`;
183
225
  case "directive":
184
226
  // Mid-chart, a change names itself: "→ Time 3/4", never a lone "3/4".
185
- return `<p class="bm-directive" part="meta"><span class="bm-change" aria-hidden="true">→</span><span>${metaText(item.set, true)}</span></p>`;
227
+ return `<p class="bm-directive" part="meta"><span class="bm-change" aria-hidden="true">→</span><span>${metaHtml(item.set, item.tempoBeat, true)}</span></p>`;
186
228
  case "error":
187
229
  return errorHtml(item.source, item.messages);
188
230
  }
@@ -205,7 +247,8 @@ function systemHtml(item, columns, settings) {
205
247
  function gutterHtml(row, settings, part) {
206
248
  if (!settings.gutter)
207
249
  return "";
208
- const number = settings.barNumbers && (!part || part.first) ? (row.barNumber ?? "") : "";
250
+ const shown = settings.barNumbers && (!part || part.first) && row.barNumber !== 0;
251
+ const number = shown ? (row.barNumber ?? "") : "";
209
252
  const label = part
210
253
  ? `<span class="bm-part-label" part="part-label">${escapeHtml(part.label)}</span>`
211
254
  : "";
@@ -247,7 +290,7 @@ function rowClasses(row, part) {
247
290
  classes.push("bm-sings");
248
291
  if (row.cells.some(isTacetCell))
249
292
  classes.push("bm-tacet");
250
- if (row.ending)
293
+ if (row.ending || row.continues)
251
294
  classes.push("bm-ending");
252
295
  return classes.join(" ");
253
296
  }
@@ -261,8 +304,9 @@ const leads = (part) => !part || part.first;
261
304
  function rowHtml(row, columns, settings, part) {
262
305
  const label = row.ending && leads(part) ? endingLabel(row.ending) : null;
263
306
  const cells = rowCells(row, settings.numerals, label ? ` data-ending="${label.shown}"` : "");
307
+ const goesOn = row.continues && leads(part) ? `${endingLabel(row.continues).spoken}, continued` : "";
264
308
  const empty = `<span class="bm-empty" aria-hidden="true"></span>`.repeat(Math.max(0, columns - row.cells.length));
265
- const said = rowOpening(row, part, label?.spoken ?? "");
309
+ const said = rowOpening(row, part, label?.spoken ?? goesOn);
266
310
  return `<div class="${rowClasses(row, part)}">${said}${gutterHtml(row, settings, part)}${cells.join("")}${empty}<span class="bm-repeat">${leads(part) ? rowRepeatHtml(row) : ""}</span></div>`;
267
311
  }
268
312
  /** An ending's passes as printed, "1.", "1.–3.", "1., 3.", and spoken, "ending for passes 1 to 3". */
@@ -287,10 +331,12 @@ function rowRepeatHtml(row) {
287
331
  return row.closes ? `<span class="bm-sr">repeat end, play 2 times</span>` : "";
288
332
  return repeatHtml(row.repeat).trim();
289
333
  }
334
+ /** A bar's unreadable slots' errors, spoken after the bar (barmark's grammar 2.3). */
335
+ const spokenErrors = (cell) => cell.kind === "slots" ? (cell.unread ?? []).map((m) => `error: ${m}`) : [];
290
336
  function cellHtml(cell, barNumber, marks, numerals, sung) {
291
337
  const numeral = numerals && cell.kind === "slots" && cell.key ? { style: numerals, key: cell.key } : null;
292
- const said = [speakBar(barNumber, cell, numeral !== null), sung.words].filter(Boolean);
293
- const spoken = `<span class="bm-sr">${escapeHtml(said.join(", "))}</span>`;
338
+ const said = [speakBar(barNumber, cell, numeral !== null), ...spokenErrors(cell), sung.words];
339
+ const spoken = `<span class="bm-sr">${escapeHtml(said.filter(Boolean).join(", "))}</span>`;
294
340
  if (cell.kind !== "slots")
295
341
  return betweenBarsHtml(cell, spoken, marks);
296
342
  const change = cell.tempoChange ? ` data-tempo-change="${cell.tempoChange}"` : "";
@@ -302,7 +348,9 @@ function cellHtml(cell, barNumber, marks, numerals, sung) {
302
348
  return `<div class="bm-bar" part="bar"${cell.cut ? " data-cut" : ""}${change}${marks}>${spoken}${numbers}${stack}${end}</div>`;
303
349
  }
304
350
  /** What a bar shows: its meter, its slots (or `%`), and "cut"; then the words after its last slot. */
305
- function barBody(cell, view) {
351
+ function barBody(cell, given) {
352
+ // Each unreadable slot takes its message in turn (barmark's grammar 2.3).
353
+ const view = { ...given, unread: [...(cell.unread ?? [])] };
306
354
  const meter = cell.meter
307
355
  ? `<span class="bm-meter"><span>${cell.meter.n}</span><span>${cell.meter.d}</span></span>`
308
356
  : "";
@@ -314,7 +362,7 @@ function barBody(cell, view) {
314
362
  /** A bar where the part rests; the first of a row says so, in its body. */
315
363
  function tacetHtml(cell, n, marks, first) {
316
364
  const cut = cell.kind === "slots" && cell.cut;
317
- const spoken = `<span class="bm-sr">bar ${n ?? ""}: tacet${cut ? ", cut on this pass" : ""}</span>`;
365
+ const spoken = `<span class="bm-sr">${barLabel(n)}: tacet${cut ? ", cut on this pass" : ""}</span>`;
318
366
  return `<div class="bm-bar bm-tacet-bar" part="bar"${marks}${cut ? " data-cut" : ""}>${spoken}<span class="bm-bar-body" aria-hidden="true">${first ? "tacet" : ""}</span></div>`;
319
367
  }
320
368
  /** A bar's slots, each under any words before it, and the words after the last slot. */
@@ -415,11 +463,23 @@ function unmarkedSlotHtml(slot, view) {
415
463
  case "silence":
416
464
  return `<span class="bm-silence"></span>`;
417
465
  case "unknown":
418
- return `<span class="bm-unknown">?</span>`;
466
+ return unknownHtml(slot.text, view);
419
467
  case "group":
420
468
  return groupHtml(slot.members, view);
421
469
  }
422
470
  }
471
+ /**
472
+ * `?`, or an unreadable slot as its author wrote it (barmark's grammar
473
+ * 2.3); one written on its own line carries its error, a `%` copy doesn't.
474
+ */
475
+ function unknownHtml(text, view) {
476
+ if (text === undefined)
477
+ return `<span class="bm-unknown">?</span>`;
478
+ const message = view.unread?.shift();
479
+ if (message === undefined)
480
+ return `<span class="bm-unknown">${escapeHtml(text)}</span>`;
481
+ return `<span class="bm-unknown bm-unread" part="unread" title="${escapeHtml(message)}">${escapeHtml(text)}</span>`;
482
+ }
423
483
  function chordHtml(record, view) {
424
484
  if (record.kind === "notes" && view.pitches)
425
485
  return pitchHtml(record);
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { type ChordPieces, glyphs, NUMERALS, type Numerals, typesetChord, typesetNumeral, } from "./chord.js";
2
2
  export { creditsText } from "./credits.js";
3
3
  export { FONT_FAMILY, fontFaceCss } from "./font.js";
4
- export { type RenderOptions, renderChart, renderChartUnwrapped } from "./html.js";
4
+ export { type Columns, type RenderOptions, renderChart, renderChartUnwrapped } from "./html.js";
5
5
  export { layoutChart } from "./model.js";
6
6
  export { speakChord } from "./speech.js";
7
7
  export { stylesheet } from "./styles.js";
package/dist/model.js CHANGED
@@ -4,7 +4,8 @@
4
4
  * draws. Built from the parser's document lines; the played bars supply
5
5
  * bar numbers and the slots `%` copies.
6
6
  */
7
- import { extractPart, parseChart, } from "barmark";
7
+ import { extractPart, parseChart, printedAsWritten, unreadSlots, } from "barmark";
8
+ import { tempoBeatOf, tempoBeats } from "./tempo.js";
8
9
  import { landings, rowVerses, singerOf, sungVerses } from "./verses.js";
9
10
  /** Whether a tutti bar's parts play different slots, as `%` or `/` on a tutti line can. */
10
11
  const playedApart = (b, line) => {
@@ -64,12 +65,14 @@ export function layoutChart(text, options = {}) {
64
65
  const ctx = {
65
66
  parse,
66
67
  source: text.split(/\r?\n/),
67
- errors: errorsByLine(parse),
68
+ ...errorsByLine(parse),
68
69
  written: new Map(groups.flatMap((g) => (g.heading ? [[g.heading.line, g]] : []))),
69
70
  bars: indexByLine(barsByLine(parse)),
71
+ beats: tempoBeats(parse.lines),
70
72
  };
71
73
  const blocks = groups.map((g) => layoutGroup(g, ctx));
72
- if (options.rehearsalLetters)
74
+ // A chart that writes its own rehearsal marks keeps them alone: letters beside them would mark each place twice.
75
+ if (options.rehearsalLetters && !parse.bars.some((b) => b.rehearsal !== undefined))
73
76
  letterBlocks(blocks);
74
77
  return {
75
78
  title: parse.title,
@@ -77,10 +80,16 @@ export function layoutChart(text, options = {}) {
77
80
  parts: parse.parts,
78
81
  credits: parse.credits,
79
82
  header,
83
+ tempoBeat: headerBeat(parse.lines, ctx.beats),
80
84
  blocks,
81
85
  diagnostics: parse.diagnostics,
82
86
  };
83
87
  }
88
+ /** The beat the header's tempo counts: its directives' (they share the next bar line), or the default. */
89
+ function headerBeat(lines, beats) {
90
+ const first = lines.find((l) => l.kind === "directive");
91
+ return (first && beats.get(first.line)) ?? tempoBeatOf(undefined);
92
+ }
84
93
  /** Rehearsal letters mark position: every section occurrence, and leading bars, in play order. */
85
94
  function letterBlocks(blocks) {
86
95
  let n = 0;
@@ -95,14 +104,33 @@ function letters(n) {
95
104
  const head = n >= 26 ? letters(Math.floor(n / 26) - 1) : "";
96
105
  return head + String.fromCharCode(65 + (n % 26));
97
106
  }
107
+ /**
108
+ * Error messages by line: a line the printer prints as written is drawn as
109
+ * written; a bar line whose only errors are its unreadable slots is drawn,
110
+ * each slot with its message (barmark's grammar 2.3, 8).
111
+ */
98
112
  function errorsByLine(parse) {
113
+ const asWritten = printedAsWritten(parse);
99
114
  const errors = new Map();
115
+ const unread = new Map();
100
116
  for (const d of parse.diagnostics) {
101
117
  if (d.severity !== "error")
102
118
  continue;
103
- errors.set(d.line, [...(errors.get(d.line) ?? []), d.message]);
119
+ const into = asWritten.has(d.line) ? errors : unread;
120
+ into.set(d.line, [...(into.get(d.line) ?? []), d.message]);
104
121
  }
105
- return errors;
122
+ return { errors, unread };
123
+ }
124
+ /** Each written bar with its unreadable slots' messages, in order (barmark's grammar 2.3). */
125
+ function withUnread(cells, l, ctx) {
126
+ const messages = [...(ctx.unread.get(l.line) ?? [])];
127
+ if (!messages.length)
128
+ return cells;
129
+ return cells.map((c, i) => {
130
+ const own = l.cells[i];
131
+ const unread = own ? messages.splice(0, unreadSlots({ cells: [own] }).length) : [];
132
+ return c.kind === "slots" && unread.length ? { ...c, unread } : c;
133
+ });
106
134
  }
107
135
  /** Lines that name the chart rather than play it: never part of the body. */
108
136
  const NAMING = new Set(["title", "part", "credit"]);
@@ -361,7 +389,11 @@ function layoutLine(l, occurrence, previous, ctx) {
361
389
  case "text":
362
390
  return textItem(l.text);
363
391
  case "directive":
364
- return { kind: "directive", set: l.set };
392
+ return {
393
+ kind: "directive",
394
+ set: l.set,
395
+ tempoBeat: ctx.beats.get(l.line) ?? tempoBeatOf(undefined),
396
+ };
365
397
  case "invalid":
366
398
  return errorItem(l.line, ctx);
367
399
  default:
@@ -391,6 +423,11 @@ function playedOn(line, occurrence, ctx) {
391
423
  const last = occurrence?.lastBar ?? Number.POSITIVE_INFINITY;
392
424
  return barsOn(line, ctx).filter((b) => b.index >= first && b.index <= last);
393
425
  }
426
+ /** A row's repeat marks and ending, the line it continues an ending on included (barmark's grammar 5.1). */
427
+ function rowMarks(l) {
428
+ const marks = { opens: l.opens, closes: l.closes, repeat: l.repeat, ending: l.ending };
429
+ return l.continues ? { ...marks, continues: l.continues } : marks;
430
+ }
394
431
  function layoutRow(l, played, previous, ctx) {
395
432
  const cells = [];
396
433
  // A cut bar is not played: what it would play is what the line's bar played when written.
@@ -410,11 +447,8 @@ function layoutRow(l, played, previous, ctx) {
410
447
  line: l.line,
411
448
  // Numbered as written, as a band counts (issue #92): repeats, endings, jumps and replays don't move it.
412
449
  barNumber: (played[0] ?? written[0])?.written ?? null,
413
- opens: l.opens,
414
- closes: l.closes,
415
- repeat: l.repeat,
416
- ending: l.ending,
417
- cells,
450
+ ...rowMarks(l),
451
+ cells: withUnread(cells, l, ctx),
418
452
  ...singing(l, cells, played, ctx),
419
453
  };
420
454
  }
package/dist/speech.d.ts CHANGED
@@ -7,7 +7,9 @@ import type { CellModel } from "./types.js";
7
7
  /** A chord's name; with a key, its degree first: "five, A seven". */
8
8
  export declare function speakChord(record: ChordRecord, key?: Key): string;
9
9
  export declare function speakSlot(slot: Slot, key?: Key): string;
10
- /** "bar 9: G, hold, D, hold"; a fermata is held until cued. With `numerals`, each chord's degree comes first. */
10
+ /** What a bar is called aloud: "pickup" for bar 0, "bar" with no number, else "bar 9". */
11
+ export declare function barLabel(barNumber: number | null): string;
12
+ /** "bar 9: G, hold, D, hold"; a pickup (bar 0) says "pickup"; a fermata is held until cued. With `numerals`, each chord's degree comes first. */
11
13
  export declare function speakBar(barNumber: number | null, cell: CellModel, numerals?: boolean): string;
12
14
  /**
13
15
  * The words on a bar, each verse's: `sung “maz-ing”` (or `words “…”` in a
package/dist/speech.js CHANGED
@@ -139,7 +139,7 @@ function speakUnpushed(slot, key) {
139
139
  case "silence":
140
140
  return "stop";
141
141
  case "unknown":
142
- return "unknown chord";
142
+ return slot.text === undefined ? "unknown chord" : `unreadable: ${slot.text}`;
143
143
  case "group":
144
144
  return speakGroup(slot.members, key);
145
145
  }
@@ -150,7 +150,13 @@ function speakDirection(d) {
150
150
  return d.kind;
151
151
  return `${d.to === "start" ? "da capo" : "dal segno"}${d.al ? ` al ${d.al}` : ""}`;
152
152
  }
153
- /** "bar 9: G, hold, D, hold"; a fermata is held until cued. With `numerals`, each chord's degree comes first. */
153
+ /** What a bar is called aloud: "pickup" for bar 0, "bar" with no number, else "bar 9". */
154
+ export function barLabel(barNumber) {
155
+ if (barNumber === 0)
156
+ return "pickup";
157
+ return barNumber === null ? "bar" : `bar ${barNumber}`;
158
+ }
159
+ /** "bar 9: G, hold, D, hold"; a pickup (bar 0) says "pickup"; a fermata is held until cued. With `numerals`, each chord's degree comes first. */
154
160
  export function speakBar(barNumber, cell, numerals = false) {
155
161
  if (cell.kind === "fermata")
156
162
  return "fermata: hold until cued";
@@ -158,7 +164,7 @@ export function speakBar(barNumber, cell, numerals = false) {
158
164
  return speakDirection(cell.direction);
159
165
  if (cell.kind === "rehearsal")
160
166
  return `rehearsal ${cell.label}`;
161
- const bar = `bar${barNumber === null ? "" : ` ${barNumber}`}`;
167
+ const bar = barLabel(barNumber);
162
168
  if (cell.simile)
163
169
  return `${bar}: each part repeats its bar before`;
164
170
  const meter = cell.meter ? `, in ${cell.meter.n}/${cell.meter.d}` : "";
@@ -166,7 +172,7 @@ export function speakBar(barNumber, cell, numerals = false) {
166
172
  const words = (at) => (cell.words ?? []).filter((w) => w.at === at).map((w) => `“${w.text}”`);
167
173
  const slots = cell.slots.map((s, i) => [...words(i), speakSlot(s, numerals ? cell.key : undefined)].join(" "));
168
174
  const spoken = [...slots, ...words(cell.slots.length)].join(", ");
169
- return `bar${barNumber === null ? "" : ` ${barNumber}`}${meter}: ${spoken}${cut}`;
175
+ return `${bar}${meter}: ${spoken}${cut}`;
170
176
  }
171
177
  /** A verse's syllables as words: "maz-ing"; elided syllables apart, a held one silent. */
172
178
  function speakSyllables(syllables) {
package/dist/styles.d.ts CHANGED
@@ -13,4 +13,6 @@ export declare const PALETTES: {
13
13
  };
14
14
  /** Section widths, in em, at which a section stops aligning columns and wraps its rows. */
15
15
  export declare const FIT_STEPS: number[];
16
+ /** The rules only `columns: "row"` uses, at the stylesheet's end. */
17
+ export declare const ROW_COLUMNS_CSS: string;
16
18
  export declare const stylesheet: string;
package/dist/styles.js CHANGED
@@ -63,9 +63,21 @@ export const FIT_STEPS = Array.from({ length: 23 }, (_, i) => 8 + i * 4);
63
63
  const colours = (p) => Object.keys(p)
64
64
  .map((k) => `--bm-${k}:var(--barmark-${k},${p[k]});`)
65
65
  .join("");
66
+ /**
67
+ * A section's column tracks: the gutter (bar numbers, or part labels as wide
68
+ * as the longest), a track per cell, and the repeat count's.
69
+ */
70
+ const CELLS = "repeat(var(--bm-cols),auto) auto";
71
+ const TRACKS = {
72
+ numbers: `${em(GUTTER)} ${CELLS}`,
73
+ bare: CELLS,
74
+ parts: `calc(${em(GUTTER + 0.9)} + var(--bm-label-chars) * .62em) ${CELLS}`,
75
+ };
66
76
  const SANS = `system-ui,-apple-system,"Segoe UI",sans-serif`;
67
77
  /** The meta line, directives, headings and diagnostics. */
68
78
  const LABEL = `var(--barmark-label-font,${SANS})`;
79
+ /** Fonts holding the beat notes outside the Basic Multilingual Plane (𝅗𝅥 U+1D15E, 𝅘𝅥𝅯 U+1D161), tried before the label's. */
80
+ const SYMBOLS = `"Apple Symbols","Segoe UI Symbol","Noto Music",Symbola`;
69
81
  /** Lyrics and note lines: a serif every system has, with a true italic (Edwin has none). */
70
82
  const TEXT = "var(--barmark-text-font,Georgia,serif)";
71
83
  const CHART_FONT = `var(--barmark-font,"${FONT_FAMILY}","Edwin",Georgia,serif)`;
@@ -87,6 +99,7 @@ const css = `
87
99
  .bm-credits{font-family:${LABEL};font-size:${em(SIZES.meta)};margin:0 0 .15em}
88
100
  .bm-copyright{font-family:${LABEL};font-size:${em(SIZES.meta)};color:var(--bm-muted);margin-top:1.5em}
89
101
  .bm-copyright p{margin:0}
102
+ .bm-beat{font-family:${SYMBOLS},${LABEL}}
90
103
  .bm-meta{font-family:${LABEL};font-size:${em(SIZES.meta)};color:var(--bm-muted);margin:0}
91
104
  .bm-directive{grid-column:1/-1;display:flex;align-items:baseline;gap:.4em;margin:.9em 0 .3em ${at(SIZES.directive, GUTTER)};font-family:${LABEL};font-size:${em(SIZES.directive)};color:var(--barmark-directive,var(--bm-muted))}
92
105
  .bm-directive::after{content:"";flex:1;align-self:center;margin-left:.4em;border-top:.06em solid var(--bm-rule);opacity:.6}
@@ -94,11 +107,11 @@ const css = `
94
107
  .bm-heading{display:flex;align-items:center;gap:.5em;margin:0 0 ${at(SIZES.heading, HEADING_GAP)} ${at(SIZES.heading, GUTTER)};font:600 ${em(SIZES.heading)}/1 ${LABEL};letter-spacing:.08em;text-transform:uppercase;color:var(--bm-ink)}
95
108
  .bm-rehearsal{border:.12em solid currentColor;padding:.15em .35em;border-radius:.15em;letter-spacing:0}
96
109
  .bm-times{font:italic 1.2em/1 Georgia,serif;text-transform:none;letter-spacing:0;color:var(--bm-muted)}
97
- .bm-grid{display:grid;grid-template-columns:${em(GUTTER)} repeat(var(--bm-cols),auto) auto;width:max-content;max-width:100%}
98
- .bm-chart[data-bar-numbers="off"] .bm-grid{grid-template-columns:repeat(var(--bm-cols),auto) auto}
110
+ .bm-grid{display:grid;grid-template-columns:${TRACKS.numbers};width:max-content;max-width:100%}
111
+ .bm-chart[data-bar-numbers="off"] .bm-grid{grid-template-columns:${TRACKS.bare}}
99
112
  .bm-chart[data-wrap="off"] .bm-grid{max-width:none}
100
113
  .bm-row,.bm-system{display:contents}
101
- .bm-chart[data-parts] .bm-grid{grid-template-columns:calc(${em(GUTTER + 0.9)} + var(--bm-label-chars) * .62em) repeat(var(--bm-cols),auto) auto}
114
+ .bm-chart[data-parts] .bm-grid{grid-template-columns:${TRACKS.parts}}
102
115
  .bm-chart[data-parts] .bm-bar-number{width:auto;justify-content:flex-end;gap:.35em;padding-right:.45em}
103
116
  .bm-part-row>.bm-bar-number{border-right:.15em solid var(--bm-rule)}
104
117
  .bm-part-label{margin-right:auto}
@@ -122,6 +135,7 @@ const css = `
122
135
  .bm-chord sup{font-size:${em(SIZES.superscript)};vertical-align:.55em;line-height:0}
123
136
  .bm-chord sub{font-size:${em(SIZES.octave)};line-height:0}
124
137
  .bm-hold,.bm-unknown,.bm-brace,.bm-simile{color:var(--bm-muted)}
138
+ .bm-unread{color:var(--bm-accent);text-decoration:underline wavy var(--bm-accent);text-decoration-thickness:.08em;text-underline-offset:.25em}
125
139
  .bm-nc{font-size:${em(SIZES.noChord)};letter-spacing:.06em}
126
140
  .bm-silence{display:inline-block;width:.9em;height:.32em;background:var(--bm-ink);vertical-align:.25em}
127
141
  .bm-ring,.bm-notes{font-size:${em(SIZES.noteNames)}}
@@ -193,9 +207,26 @@ ${FIT_STEPS.map((w) => {
193
207
  return `@container bm (max-width:${w}em){${g}{display:block}${g}>.bm-row{display:flex;flex-wrap:wrap;row-gap:${em(ROW_GAP)}}${g} .bm-empty{display:none}${g} .bm-bar{flex:0 1 auto;max-width:100%;border-left:.075em solid var(--bm-rule);margin-left:-.075em}${g} :is(.bm-bar-body,.bm-group,.bm-notes){flex-wrap:wrap}${g} .bm-bar-body>*{flex:1 1 auto;min-width:auto}}`;
194
208
  }).join("\n")}
195
209
  `;
210
+ /**
211
+ * `columns: "row"`: each row, and each system with its parts' rows, is its
212
+ * own grid on the section's tracks, so its cells size to their own content.
213
+ * The section's grid only stacks them. Where a section wraps, a system
214
+ * stands aside again, as in the shared layout. Appended after the shared
215
+ * rules, which it leaves byte for byte as they were.
216
+ */
217
+ const ROW = '.bm-chart[data-columns="row"]';
218
+ const OWN = ":is(.bm-grid>.bm-row,.bm-system)";
219
+ const rowCss = `
220
+ ${ROW} ${OWN}{display:grid;grid-column:1/-1;justify-self:start;grid-template-columns:${TRACKS.numbers}}
221
+ ${ROW}[data-bar-numbers="off"] ${OWN}{grid-template-columns:${TRACKS.bare}}
222
+ ${ROW}[data-parts] ${OWN}{grid-template-columns:${TRACKS.parts}}
223
+ ${FIT_STEPS.map((w) => `@container bm (max-width:${w}em){${ROW}:not([data-wrap="off"]) .bm-grid[data-fit="${w}"]>.bm-system{display:contents}}`).join("\n")}
224
+ `;
196
225
  /** Collapse the readable source above: whitespace around punctuation and between rules. */
197
226
  const minify = (text) => text
198
227
  .replace(/\n\s*/g, "")
199
228
  .replace(/\s*([{};,>])\s*/g, "$1")
200
229
  .replace(/:\s+/g, ":");
201
- export const stylesheet = minify(css);
230
+ /** The rules only `columns: "row"` uses, at the stylesheet's end. */
231
+ export const ROW_COLUMNS_CSS = minify(rowCss);
232
+ export const stylesheet = minify(css) + ROW_COLUMNS_CSS;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The beat a `tempo:` counts, decided from the parse: the meter `time:` set,
3
+ * never a one-bar meter's, so the HTML only draws the note it is given.
4
+ */
5
+ import { type Line, type Meter } from "barmark";
6
+ import type { TempoBeat } from "./types.js";
7
+ /**
8
+ * The beat of a meter (barmark's grammar 2.1), as barmark counts it: where
9
+ * `beatsOf` counts fewer beats than the top number (6/8, 9/8, 12/8), each is
10
+ * three of the bottom note, a dotted note of twice its length.
11
+ */
12
+ export declare function tempoBeatOf(meter: Meter | undefined): TempoBeat;
13
+ /**
14
+ * The beat a tempo counts at each directive line, by line number: that of
15
+ * the `time:` in force at the next bar line, as the parser, MIDI and
16
+ * MusicXML count the bar's meter (grammar 2.1), so a `time:` written on a
17
+ * later line before that bar counts too. Directives after the last bar line
18
+ * take the `time:` in force at the chart's end. One-bar meters set no
19
+ * `time:`, so they never change it (grammar 2.4).
20
+ */
21
+ export declare function tempoBeats(lines: Line[]): Map<number, TempoBeat>;
package/dist/tempo.js ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The beat a `tempo:` counts, decided from the parse: the meter `time:` set,
3
+ * never a one-bar meter's, so the HTML only draws the note it is given.
4
+ */
5
+ import { beatsOf } from "barmark";
6
+ /** The meter in force before any `time:` (barmark's grammar, the `time:` default). */
7
+ const COMMON_TIME = { n: 4, d: 4 };
8
+ /**
9
+ * The beat of a meter (barmark's grammar 2.1), as barmark counts it: where
10
+ * `beatsOf` counts fewer beats than the top number (6/8, 9/8, 12/8), each is
11
+ * three of the bottom note, a dotted note of twice its length.
12
+ */
13
+ export function tempoBeatOf(meter) {
14
+ const m = meter ?? COMMON_TIME;
15
+ // barmark admits a bottom number of 2, 4, 8 or 16 only (grammar, `time:`), and only 8 is compound.
16
+ const note = (beatsOf(m) === m.n ? m.d : m.d / 2);
17
+ return { note, dotted: beatsOf(m) !== m.n };
18
+ }
19
+ /**
20
+ * The beat a tempo counts at each directive line, by line number: that of
21
+ * the `time:` in force at the next bar line, as the parser, MIDI and
22
+ * MusicXML count the bar's meter (grammar 2.1), so a `time:` written on a
23
+ * later line before that bar counts too. Directives after the last bar line
24
+ * take the `time:` in force at the chart's end. One-bar meters set no
25
+ * `time:`, so they never change it (grammar 2.4).
26
+ */
27
+ export function tempoBeats(lines) {
28
+ const beats = new Map();
29
+ let time = COMMON_TIME;
30
+ let waiting = [];
31
+ const settle = () => {
32
+ for (const line of waiting)
33
+ beats.set(line, tempoBeatOf(time));
34
+ waiting = [];
35
+ };
36
+ for (const l of lines) {
37
+ if (l.kind === "bars")
38
+ settle();
39
+ if (l.kind !== "directive")
40
+ continue;
41
+ time = l.set.time ?? time;
42
+ waiting.push(l.line);
43
+ }
44
+ settle();
45
+ return beats;
46
+ }
package/dist/types.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import type { ChartDiagnostic, Credits, DeclaredPart, Direction, Directives, Key, Meter, Repeat, Slot, Syllable, Words } from "barmark";
2
2
  /** `part`: draw only the part with this label (barmark's grammar 7.4), as a single-part chart. */
3
3
  export type LayoutOptions = {
4
+ /**
5
+ * Letter each section occurrence A, B, C… in play order; none when any
6
+ * bar in the chart carries its own rehearsal mark (`@A`, barmark's
7
+ * grammar 2.5), which then stand alone.
8
+ */
4
9
  rehearsalLetters?: boolean;
5
10
  part?: string;
6
11
  };
@@ -15,16 +20,27 @@ export type ChartModel = {
15
20
  credits: Credits;
16
21
  /** Directives before the first heading, bar line or text line. */
17
22
  header: Directives;
23
+ /** The beat the header's tempo counts. */
24
+ tempoBeat: TempoBeat;
18
25
  blocks: SectionBlock[];
19
26
  diagnostics: ChartDiagnostic[];
20
27
  };
28
+ /**
29
+ * The note a `tempo:` counts (barmark's grammar 2.1), from the `time:` in
30
+ * force, never a one-bar meter's (2.4): the bottom number in a simple meter
31
+ * (`note: 4` is a quarter), a dotted quarter in 6/8, 9/8 and 12/8.
32
+ */
33
+ export type TempoBeat = {
34
+ note: 2 | 4 | 8 | 16;
35
+ dotted: boolean;
36
+ };
21
37
  export type SectionBlock = {
22
38
  /** The heading as written; null for content before the first heading. */
23
39
  heading: string | null;
24
40
  /** `## Chorus x2` */
25
41
  repeat: Repeat;
26
42
  form: number | null;
27
- /** "A", "B", … when rehearsal letters are on. */
43
+ /** "A", "B", … when rehearsal letters are on and the chart writes no rehearsal mark of its own. */
28
44
  rehearsal: string | null;
29
45
  /** The widest row's cell count: fermata, direction and rehearsal cells included. */
30
46
  columns: number;
@@ -45,6 +61,8 @@ export type BlockItem = {
45
61
  repeat: Repeat;
46
62
  /** The passes an ending plays on; null for any other row. */
47
63
  ending: number[] | null;
64
+ /** On a row an ending continues onto (barmark's grammar 5.1): that ending's passes. Absent on any other row. */
65
+ continues?: number[];
48
66
  cells: CellModel[];
49
67
  /** Set on a line that sings words (barmark's grammar 7.7): its note sets draw as pitch names over them. */
50
68
  sings?: true;
@@ -77,9 +95,12 @@ export type BlockItem = {
77
95
  kind: "text";
78
96
  text: string;
79
97
  note: boolean;
80
- } | {
98
+ }
99
+ /** A change written mid-chart; `tempoBeat` is the beat a tempo there counts. */
100
+ | {
81
101
  kind: "directive";
82
102
  set: Directives;
103
+ tempoBeat: TempoBeat;
83
104
  } | ErrorItem;
84
105
  /**
85
106
  * One verse's syllables on a row's bars, as the parser places them: per
@@ -113,6 +134,8 @@ export type CellModel = {
113
134
  tacet?: true;
114
135
  /** `%` on a tutti line whose parts each copy a different bar: drawn as `%`, its slots empty (barmark's grammar 7.4). */
115
136
  simile?: true;
137
+ /** The error message of each slot written here that can't be read, in order (barmark's grammar 2.3); absent when none. */
138
+ unread?: string[];
116
139
  } | {
117
140
  kind: "fermata";
118
141
  }
package/dist/verses.js CHANGED
@@ -31,8 +31,18 @@ export function singerOf(l, parse) {
31
31
  const name = l.lineName ?? p.lines?.[0] ?? "";
32
32
  return same(name, p.sings) ? (p.label ?? "") : null;
33
33
  }
34
+ /** Whether a verse's syllables sit on notes, read once for each written bar however often it plays. */
35
+ const noted = new WeakMap();
36
+ function onNote(syllables) {
37
+ let known = noted.get(syllables);
38
+ if (known === undefined) {
39
+ known = syllables.some((s) => s.note);
40
+ noted.set(syllables, known);
41
+ }
42
+ return known;
43
+ }
34
44
  /** Whether a chart with no parts sings: its verse 1 sits on notes. */
35
- const onNotes = (b) => (b.lyrics ?? []).some((v) => v.syllables.some((s) => s.note));
45
+ const onNotes = (b) => (b.lyrics ?? []).some((v) => onNote(v.syllables));
36
46
  /** `onNotes` over the chart, worked out once a parse: asked for each line, it would read every bar each time. */
37
47
  const sang = new WeakMap();
38
48
  function singsOnNotes(parse) {
@@ -91,6 +101,20 @@ function slotStarts(slots) {
91
101
  });
92
102
  return starts;
93
103
  }
104
+ /** The last of the ascending `starts` at or before `at` (within a rounding error), or -1: a binary search, so a bar of many notes and syllables isn't their product. */
105
+ function lastStartBy(starts, at) {
106
+ let lo = 0;
107
+ let hi = starts.length;
108
+ while (lo < hi) {
109
+ const mid = (lo + hi) >> 1;
110
+ const start = starts[mid] ?? 0;
111
+ if (start < at || near(start, at))
112
+ lo = mid + 1;
113
+ else
114
+ hi = mid;
115
+ }
116
+ return lo - 1;
117
+ }
94
118
  /** A verse's syllables in a bar under its slots: each on the slot sounding at its onset. */
95
119
  function underSlots(cell, landing, key, verse) {
96
120
  if (cell.kind !== "slots" || !landing)
@@ -103,8 +127,7 @@ function underSlots(cell, landing, key, verse) {
103
127
  const out = starts.map(() => []);
104
128
  const length = barLength(landing.bar.meter);
105
129
  for (const s of sung) {
106
- const i = starts.findLastIndex((at) => at < s.at / length || near(at, s.at / length));
107
- out[Math.max(0, i)]?.push(s.syllable);
130
+ out[Math.max(0, lastStartBy(starts, s.at / length))]?.push(s.syllable);
108
131
  }
109
132
  return out;
110
133
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barmark/render",
3
- "version": "0.17.1",
3
+ "version": "0.19.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,7 +47,7 @@
47
47
  "url": "https://github.com/kevinpeckham/barmark/issues"
48
48
  },
49
49
  "dependencies": {
50
- "barmark": "^0.21.0"
50
+ "barmark": "^0.23.0"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "rm -rf dist && tsc -p tsconfig.build.json",