@barmark/render 0.21.1 → 0.22.1

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,71 @@ package uses [semantic versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.22.1] - 2026-11-29
10
+
11
+ ### Changed
12
+
13
+ - **Requires `barmark` 0.26.0**, for the parse's `firstWritten` (each bar
14
+ line's first written bar number), which the grid now reads where it
15
+ recounted the written lines itself; a caret range would not reach that
16
+ minor release.
17
+
18
+ ### Fixed
19
+
20
+ - **Bar numbers after a system come from the parser in two more cases**,
21
+ where a later row whose first bar no pass plays was numbered off and
22
+ could draw and speak another bar's chord in its cells:
23
+ - a system whose every line is excluded or dropped, with lines writing
24
+ different numbers of bars: it was counted by the system's first line,
25
+ not the parser's;
26
+ - a part's own view where that part's lines in a system are left out
27
+ or excluded and another part's line is the reference: with
28
+ `part: "Pno"`, `Gtr | C | D |` over `Pno.RH | G |`, then
29
+ `| E | Coda | F |`, drew that row as `6: F | F`; it is `5: E | 6: F`.
30
+
31
+ ## [0.22.0] - 2026-11-28
32
+
33
+ ### Added
34
+
35
+ - **Played bar numbers**: `barNumbers: "played"` (attribute
36
+ `bar-numbers="played"`, property `barNumbers`) numbers each row in play
37
+ order, from the parser's play order, so a chart lines up with a player or
38
+ a recording that counts bars as played. A row played more than once shows
39
+ each pass's number (`1 · 5`, up to three; `9 … 37` for four or more), a
40
+ row no pass plays shows none, and after an open repeat (`x ...`) the
41
+ numbers are approximate (`~11`). Each bar speaks its own ("bar 1 and bar
42
+ 5", "about bar 11"). A pickup's first pass is never numbered; a later
43
+ pass of its row is. The gutter widens to fit, on one line, and a section
44
+ wraps sooner to make room for it; in a chart without part labels,
45
+ headings, text lines and directives start where the bars do, and with
46
+ part labels they keep their place over the label column, as in written
47
+ mode. `layoutChart` takes `barNumbers: "played"` and gives
48
+ `playedNumbers` on rows and bars. `barNumbers` also takes `"off"`, as
49
+ the attribute does.
50
+ Written numbers stay the default, and a chart drawn with them is byte for
51
+ byte as before but for (a) the bars the fix below describes and (b) a
52
+ `%` that no pass plays on a line some pass plays, which now draws its
53
+ `%` sign where it drew an empty bar.
54
+ - **The layout model's `simile` can be `"unplayed"`** as well as `true`: a
55
+ `%` no pass plays on a line some pass plays. A host reading the model
56
+ sees the wider type.
57
+
58
+ ### Fixed
59
+
60
+ - **A bar a pass leaves early draws its own chord.** When a pass left a
61
+ row early and another pass played further along it, the later bars drew
62
+ an earlier bar's chords, holds, `%`, syllables and lyrics. A jump inside
63
+ the row does this (`To Coda`, a `D.S.` or `D.C.` before the row's end):
64
+ `| Segno | A | To Coda | B | D.S. al Coda | Coda | C |` drew its coda bar
65
+ as A. So does a `->` cut of a section that a jump skips where it is
66
+ written: with `| E | G |` skipped, then `## Skip ->` and `## Skip`, the
67
+ written section drew E twice and the cut bar said "E, cut on this pass".
68
+ Each bar now draws the bar written in it. A bar no pass plays before a
69
+ `Coda` keeps its written number, so the row and the bar after it are
70
+ numbered as written (`| E |
71
+ Coda | F |` is 3 and 4 after a two-bar row, not 4 and 5), and a `%` no
72
+ pass plays there draws the `%` sign.
73
+
9
74
  ## [0.21.1] - 2026-11-19
10
75
 
11
76
  ### Changed
@@ -599,7 +664,9 @@ that needs no script or as the `<barmark-chart>` web component. Requires
599
664
  zoom without sideways scrolling, the element renders and re-renders, and
600
665
  a screen reader hears "bar 9: D". Run them with `bun run test:browser`.
601
666
 
602
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.21.1...HEAD
667
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.22.1...HEAD
668
+ [0.22.1]: https://github.com/kevinpeckham/barmark/compare/render-v0.22.0...render-v0.22.1
669
+ [0.22.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.21.1...render-v0.22.0
603
670
  [0.21.1]: https://github.com/kevinpeckham/barmark/compare/render-v0.21.0...render-v0.21.1
604
671
  [0.21.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.20.2...render-v0.21.0
605
672
  [0.20.2]: https://github.com/kevinpeckham/barmark/compare/render-v0.20.1...render-v0.20.2
package/README.md CHANGED
@@ -52,7 +52,9 @@ The element renders from its `text` property, its `src` URL, or a child
52
52
  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
- and still follows `theme`, `bar-numbers`, `wrap` and `columns`; a change to
55
+ and still follows `theme`, `bar-numbers`, `wrap` and `columns` (its bar
56
+ numbers hide and show again, but stay written or played as they were
57
+ drawn: changing between the two needs the chart's text); a change to
56
58
  `numerals`, `rehearsal-letters`, `melody`, `show-part`, `chord-diagrams` or
57
59
  `diagram-hand` needs the chart's text, so it waits for a source.
58
60
 
@@ -79,7 +81,7 @@ the element loads, with `<style data-barmark-font>` holding
79
81
  | `renderChart` option | Element attribute (property) | Default | |
80
82
  |---|---|---|---|
81
83
  | `theme` | `theme` (`theme`) | `"auto"` | `"auto"` follows the system; `"light"` or `"dark"` force one |
82
- | `barNumbers` | `bar-numbers="off"` (`barNumbers`) | `true` | bar numbers at the start of each row |
84
+ | `barNumbers` | `bar-numbers="off"` or `"played"` (`barNumbers`) | `true` | bar numbers at the start of each row: `true` written numbers, `false` or `"off"` none, `"played"` numbers in play order (below). Any other attribute value is written |
83
85
  | `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
86
  | `numerals` | `numerals` (`numerals`) | none | `"nashville"` (6m⁷) or `"roman"` (vi⁷): each chord as its degree in its bar's key |
85
87
  | `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 |
@@ -113,6 +115,41 @@ their bar lines together. Only the layout changes: the music, the markup
113
115
  inside each bar and what a screen reader hears are the same. A section
114
116
  wraps on a narrow screen as before, once its widest row no longer fits.
115
117
 
118
+ ### Played bar numbers
119
+
120
+ With `barNumbers: "played"` (`bar-numbers="played"` on the element) each
121
+ row shows where its first bar falls in play order, for lining a chart up
122
+ with a player or a recording that counts bars as they are played. The
123
+ numbers come from the parser's play order (`parseChart(text).bars`); the
124
+ grid expands nothing itself. A row played once shows one number. A row
125
+ played more than once where it is drawn (inside `|: :|`, under `x N`, or
126
+ where a `D.S.` or `D.C.` returns) shows its first bar's number on each pass,
127
+ `1 · 5`, up to three; four or more show the first and the last, `9 … 37`.
128
+ A row no pass plays shows none. A pickup's first pass is 0 and never
129
+ shown, as with written numbers; a later pass of its row (inside `|: :|`,
130
+ or where a `D.C.` returns) shows its number. An open repeat (`x ...`) is
131
+ counted once, since its passes are unknown: every number after it is
132
+ approximate and shows as `~11`. A screen reader hears each bar's own
133
+ numbers: "bar 1 and bar 5", "bars 1, 5 and 9", "bars 9 to 37, 8 times",
134
+ "about bar 11", "about bars 12, 14 and 16". The gutter widens to the
135
+ longest numbers on one line, and a section wraps sooner to make room for
136
+ it. In a chart without part labels, headings, text lines and directives
137
+ start where the bars do, as with written numbers; with part labels they
138
+ keep their place over the label column, as in written mode. Played markup
139
+ carries the few rules that do this, so a page that includes `stylesheet`
140
+ needs nothing more. Written numbers stay the default because they are
141
+ what a printed chart and a band use; the model gives played numbers as
142
+ `playedNumbers` on each row and bar (`{ bar, approximate }`, a pass each)
143
+ only in this mode.
144
+
145
+ A played number is `PlayedBar.index`, less one when `parse.pickup` (the
146
+ pickup's first pass is 0). `@barmark/sync`'s timing map numbers bars by
147
+ `PlayedBar.index`, so its pickup is map bar 1: a host showing `barAt().bar`
148
+ beside a played chart subtracts one on a pickup chart to match. A chart
149
+ rendered on the server is drawn in one mode: `bar-numbers` can hide its
150
+ numbers and show them again, but changing between written and played
151
+ renders it again from its text.
152
+
116
153
  ### Numerals
117
154
 
118
155
  With `numerals`, each chord shows as its degree in the key its bar is
@@ -258,7 +295,8 @@ note is spoken by name ("dotted quarter note"), and the model gives it as
258
295
  At the default size chords are 16px and no label is under 12px.
259
296
 
260
297
  Chords appear in their canonical form whatever the author typed (`Cø`
261
- shows as Cm⁷(♭5)). `%` is drawn as the bar it copies; a replayed section
298
+ shows as Cm⁷(♭5)). `%` is drawn as the bar it copies (as the `%` sign
299
+ where no pass plays it); a replayed section
262
300
  is drawn in full, and its own lyrics replace the written section's. Bar
263
301
  numbers count the bars as written, each once, as a band counts them: a
264
302
  repeat, an ending, a jump or a replay doesn't move them, so a replayed
package/dist/element.js CHANGED
@@ -8,6 +8,8 @@ import { NUMERALS } from "./chord.js";
8
8
  import { FONT_FAMILY, fontFaceCss } from "./font.js";
9
9
  import { loadErrorContent, shadowContent, THEMES, } from "./html.js";
10
10
  const HANDS = ["left", "right"];
11
+ /** `bar-numbers`: "off" hides them, "played" counts in play order, anything else (none included) is written. */
12
+ const barNumbersOf = (value) => value === "played" ? "played" : value !== "off";
11
13
  export function optionsFromAttributes(el) {
12
14
  const theme = el.getAttribute("theme");
13
15
  const numerals = NUMERALS.find((n) => n === el.getAttribute("numerals"));
@@ -17,7 +19,7 @@ export function optionsFromAttributes(el) {
17
19
  const hand = HANDS.find((h) => h === el.getAttribute("diagram-hand"));
18
20
  return {
19
21
  theme: THEMES.find((t) => t === theme) ?? "auto",
20
- barNumbers: el.getAttribute("bar-numbers") !== "off",
22
+ barNumbers: barNumbersOf(el.getAttribute("bar-numbers")),
21
23
  rehearsalLetters: el.hasAttribute("rehearsal-letters"),
22
24
  wrap: el.getAttribute("wrap") !== "off",
23
25
  // Only "off" hides the melody; anything else, or none, leaves it unset.
@@ -119,11 +121,14 @@ function defineElement() {
119
121
  set theme(v) {
120
122
  this.setAttribute("theme", v);
121
123
  }
124
+ /** true for written numbers, "played" for numbers in play order, false for none (set `false`, `"off"` or any falsy value). */
122
125
  get barNumbers() {
123
- return optionsFromAttributes(this).barNumbers ?? true;
126
+ return barNumbersOf(this.getAttribute("bar-numbers"));
124
127
  }
125
128
  set barNumbers(v) {
126
- if (v)
129
+ if (v === "played")
130
+ this.setAttribute("bar-numbers", "played");
131
+ else if (v && v !== "off")
127
132
  this.removeAttribute("bar-numbers");
128
133
  else
129
134
  this.setAttribute("bar-numbers", "off");
@@ -246,8 +251,12 @@ function defineElement() {
246
251
  #restyle(options) {
247
252
  const chart = this.shadowRoot?.querySelector(".bm-chart");
248
253
  chart?.setAttribute("data-theme", options.theme ?? "auto");
254
+ // Written or played numbers are the music's: shown again, they are the ones drawn.
255
+ const played = chart?.getAttribute("style")?.includes("--bm-played") === true;
249
256
  if (options.barNumbers === false)
250
257
  chart?.setAttribute("data-bar-numbers", "off");
258
+ else if (played)
259
+ chart?.setAttribute("data-bar-numbers", "played");
251
260
  else
252
261
  chart?.removeAttribute("data-bar-numbers");
253
262
  if (options.wrap === false)
package/dist/html.d.ts CHANGED
@@ -1,7 +1,14 @@
1
1
  import { type Numerals } from "./chord.js";
2
2
  export type RenderOptions = {
3
3
  theme?: "auto" | "light" | "dark";
4
- barNumbers?: boolean;
4
+ /**
5
+ * Bar numbers at the start of each row: `true` (the default), written
6
+ * numbers; `false` or `"off"`, none; `"played"`, each row's place in play
7
+ * order, a number a pass (`1 · 5`), `~` after a vamp. Any other value is
8
+ * written, but for `0` or `""`, which hide them as `false` does; `null`,
9
+ * like none, is the default.
10
+ */
11
+ barNumbers?: boolean | "played" | "off";
5
12
  /**
6
13
  * Boxed letters A, B, C… on each section as played. None when any bar
7
14
  * carries its own rehearsal mark (`@A`, barmark's grammar 2.5): the
package/dist/html.js CHANGED
@@ -11,7 +11,7 @@ import { escapeHtml } from "./escape.js";
11
11
  import { fontFaceCss } from "./font.js";
12
12
  import { isTacet as isTacetCell, layoutChart, meloffChanged } from "./model.js";
13
13
  import { barLabel, speakBar, speakDiagram, speakVerses, UNPLAYABLE, VOICING_REPLACED, } from "./speech.js";
14
- import { FIT_STEPS, MIN_BAR, stylesheet } from "./styles.js";
14
+ import { FIT_STEPS, MIN_BAR, PLAYED_CSS, playedGutterExtra, stylesheet } from "./styles.js";
15
15
  import { beatLinesHtml, pitchHtml, sungBar, sungSlotHtml, verseNumbersHtml, verseWidth, } from "./verses-html.js";
16
16
  export function renderChart(text, options = {}) {
17
17
  return `${fontStyle(options)}<barmark-chart${elementAttributes(options)}><template shadowrootmode="open">${shadowContent(text, options)}</template></barmark-chart>`;
@@ -21,7 +21,7 @@ function elementAttributes(options) {
21
21
  const theme = themeOf(options);
22
22
  return [
23
23
  theme === "auto" ? "" : ` theme="${theme}"`,
24
- options.barNumbers === false ? ' bar-numbers="off"' : "",
24
+ barNumbersAttribute(options),
25
25
  options.rehearsalLetters ? " rehearsal-letters" : "",
26
26
  numeralsOf(options) ? ` numerals="${numeralsOf(options)}"` : "",
27
27
  options.wrap === false ? ' wrap="off"' : "",
@@ -31,6 +31,20 @@ function elementAttributes(options) {
31
31
  diagramAttributes(options),
32
32
  ].join("");
33
33
  }
34
+ /** `barNumbers` as drawn: played, written (true) or none; `"off"` and any falsy value but null are none, as `false` is. */
35
+ const numbersOf = (options) => {
36
+ const value = options.barNumbers ?? true;
37
+ return value === "played" ? value : value !== "off" && Boolean(value);
38
+ };
39
+ /** `bar-numbers` as the element reads it: written numbers need none. */
40
+ const barNumbersAttribute = (options) => {
41
+ const numbers = numbersOf(options);
42
+ return numbers === false
43
+ ? ' bar-numbers="off"'
44
+ : numbers === "played"
45
+ ? ' bar-numbers="played"'
46
+ : "";
47
+ };
34
48
  /** The chord diagrams' attributes: only the values the element reads. */
35
49
  function diagramAttributes(options) {
36
50
  const guitar = options.chordDiagrams === "guitar" ? ' chord-diagrams="guitar"' : "";
@@ -50,26 +64,65 @@ const fontStyle = (options) => options.fontUrl ? `<style>${fontFaceCss(options.f
50
64
  export function renderChartUnwrapped(text, options = {}) {
51
65
  return `${fontStyle(options)}${chartHtml(text, options)}`;
52
66
  }
67
+ /** What the model is laid out with: the options that change what is drawn. */
68
+ const layoutOptionsOf = (options) => ({
69
+ rehearsalLetters: options.rehearsalLetters ?? false,
70
+ ...(options.part && { part: options.part }),
71
+ ...(options.melody === false && { melody: false }),
72
+ ...(options.chordDiagrams === "guitar" && { chordDiagrams: "guitar" }),
73
+ ...(options.barNumbers === "played" && { barNumbers: "played" }),
74
+ });
53
75
  function chartHtml(text, options) {
54
- const model = layoutChart(text, {
55
- rehearsalLetters: options.rehearsalLetters ?? false,
56
- ...(options.part && { part: options.part }),
57
- ...(options.melody === false && { melody: false }),
58
- ...(options.chordDiagrams === "guitar" && { chordDiagrams: "guitar" }),
59
- });
60
- const barNumbers = options.barNumbers ?? true;
76
+ const model = layoutChart(text, layoutOptionsOf(options));
77
+ const barNumbers = numbersOf(options) !== false;
61
78
  const { parts, widest } = gutterOf(model, options);
79
+ const played = options.barNumbers === "played" ? { widest: playedWidest(model) } : null;
62
80
  const settings = {
63
81
  barNumbers,
82
+ played,
83
+ extra: played ? playedGutterExtra(played.widest, parts ? widest : null) : 0,
64
84
  gutter: barNumbers || parts,
65
85
  numerals: numeralsOf(options),
66
86
  rows: byRow(options),
67
87
  };
68
- const gutter = parts ? ` data-parts style="--bm-label-chars:${widest}"` : "";
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>`;
88
+ const blocks = model.blocks.map((b) => blockHtml(b, settings)).join("");
89
+ // Played numbers bring their own rules, so a chart of written numbers is styled as before.
90
+ const own = played ? `<style>${PLAYED_CSS}</style>` : "";
91
+ return `${own}<div class="bm-chart" data-theme="${themeOf(options)}"${gutterAttributes(parts ? widest : null, played)}${layoutAttributes(options, settings)}>${headerHtml(model)}${diagramsHtml(model.diagrams, settings.numerals, handOf(options))}${blocks}${copyrightHtml(model)}${options.diagnostics ? diagnosticsHtml(model) : ""}</div>`;
92
+ }
93
+ /** The widest played numbers any gutter shows, in em of their text: each row's, a system's first row's. */
94
+ function playedWidest(model) {
95
+ let widest = 0;
96
+ for (const b of model.blocks)
97
+ for (const i of b.items) {
98
+ const row = i.kind === "system" ? i.rows.find((p) => p.row.kind === "row")?.row : i;
99
+ if (row?.kind === "row")
100
+ widest = Math.max(widest, gutterWidth(playedText(row)));
101
+ }
102
+ return widest;
103
+ }
104
+ /** What sizes the gutter: the longest part label (null without labels), and the longest played numbers drawn. */
105
+ function gutterAttributes(labels, played) {
106
+ const label = labels === null ? "" : `--bm-label-chars:${labels}`;
107
+ const sizes = played
108
+ ? [label, `--bm-played-width:${Number(played.widest.toFixed(2))}`].filter(Boolean).join(";")
109
+ : label;
110
+ return `${labels === null ? "" : " data-parts"}${sizes ? ` style="${sizes}"` : ""}`;
111
+ }
112
+ /**
113
+ * A row's played numbers as the gutter shows them: up to three passes,
114
+ * `1 · 5 · 9`; four or more, the first and the last, `9 … 37`; `~` before an
115
+ * approximate one. None for a pickup's first pass, as with written numbers.
116
+ */
117
+ function playedText(row) {
118
+ // A pickup's first pass is 0, never shown; a later pass is.
119
+ const passes = (row.playedNumbers ?? []).filter((p) => p.bar !== 0);
120
+ const shown = passes.length > 3 ? [passes[0], passes.at(-1)] : passes;
121
+ const text = (p) => (p ? `${p.approximate ? "~" : ""}${p.bar}` : "");
122
+ return shown.map(text).join(passes.length > 3 ? " … " : " · ");
70
123
  }
71
124
  /** The chart's layout switches the stylesheet reads, each only when it is off its default. */
72
- const layoutAttributes = (options, settings) => `${settings.barNumbers ? "" : ' data-bar-numbers="off"'}${options.wrap === false ? ' data-wrap="off"' : ""}${settings.rows ? ' data-columns="row"' : ""}`;
125
+ const layoutAttributes = (options, settings) => `${settings.played ? ' data-bar-numbers="played"' : settings.barNumbers ? "" : ' data-bar-numbers="off"'}${options.wrap === false ? ' data-wrap="off"' : ""}${settings.rows ? ' data-columns="row"' : ""}`;
73
126
  /** Whether systems have labelled rows: several parts, or one part writing lines (barmark's grammar 7.6). */
74
127
  const labelled = (model) => model.parts.length > 1 || model.parts.some((p) => (p.lines?.length ?? 0) > 0);
75
128
  /**
@@ -203,18 +256,18 @@ function metaHtml(d, beat, labelled = false) {
203
256
  }
204
257
  function blockHtml(block, settings) {
205
258
  const label = block.heading === null ? "" : ` aria-label="${escapeHtml(block.heading)}"`;
206
- 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>`;
259
+ 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)}">${block.items.map((i) => itemHtml(i, block.columns, settings)).join("")}</div></section>`;
207
260
  }
208
261
  /**
209
262
  * Roughly how many em a section needs, rounded up to a step the stylesheet
210
263
  * knows; narrower than that, its rows wrap. With shared columns that is the
211
264
  * widest cell of each column, added up; with `rows`, the widest row.
212
265
  */
213
- function fitWidth(block, rows) {
266
+ function fitWidth(block, { rows, extra }) {
214
267
  const lines = block.items.map(rowWidths);
215
268
  const sum = (widths) => widths.reduce((a, b) => a + b, 0);
216
269
  const needed = rows ? Math.max(0, ...lines.map(sum)) : sum(widest(lines));
217
- const total = 5 + needed;
270
+ const total = 5 + extra + needed;
218
271
  return FIT_STEPS.find((step) => step >= total) ?? FIT_STEPS.at(-1) ?? 0;
219
272
  }
220
273
  /** Em per cell of a row: its bar, or the words under it when they are wider. None for anything else. */
@@ -307,15 +360,23 @@ function systemHtml(item, columns, settings) {
307
360
  function gutterHtml(row, settings, part) {
308
361
  if (!settings.gutter)
309
362
  return "";
310
- const shown = settings.barNumbers && (!part || part.first) && row.barNumber !== 0;
311
- const number = shown ? (row.barNumber ?? "") : "";
363
+ const lead = settings.barNumbers && (!part || part.first);
364
+ const written = row.barNumber !== 0 ? (row.barNumber ?? "") : "";
365
+ const number = lead ? (settings.played ? playedText(row) : written) : "";
312
366
  const label = part
313
367
  ? `<span class="bm-part-label" part="part-label">${escapeHtml(part.label)}</span>`
314
368
  : "";
315
369
  return `<span class="bm-bar-number" part="bar-number" aria-hidden="true">${label}${number}</span>`;
316
370
  }
317
- /** A row's cells; a tacet row says "tacet" in its first bar. */
318
- function rowCells(row, numerals, ending) {
371
+ /**
372
+ * The em a gutter character takes in a wide system sans (DejaVu Sans
373
+ * measured .64 a digit, .84 `~`, .32 a space or `·`, 1 `…`), a little over,
374
+ * so the estimate is rarely short; when it is, the track still grows.
375
+ */
376
+ const GLYPH_EM = { " ": 0.33, "·": 0.33, "…": 1.02, "~": 0.86 };
377
+ const gutterWidth = (text) => [...text].reduce((w, c) => w + (GLYPH_EM[c] ?? 0.66), 0);
378
+ /** A row's cells; a tacet row says "tacet" in its first bar. Each bar says its own number, or with `played` its own played numbers. */
379
+ function rowCells(row, numerals, ending, played) {
319
380
  let n = row.barNumber;
320
381
  const firstTacet = row.cells.findIndex(isTacetCell);
321
382
  const firstBar = row.cells.findIndex((c) => c.kind === "slots");
@@ -330,9 +391,10 @@ function rowCells(row, numerals, ending) {
330
391
  first: i === firstBar,
331
392
  beats: beatLinesHtml(row.lyrics, i, i === firstBar),
332
393
  };
394
+ const name = played && cell.kind === "slots" ? (cell.playedNumbers ?? []) : n;
333
395
  const html = isTacetCell(cell)
334
- ? tacetHtml(cell, n, marks, i === firstTacet)
335
- : cellHtml(cell, n, marks, numerals, sung);
396
+ ? tacetHtml(cell, name, marks, i === firstTacet)
397
+ : cellHtml(cell, name, marks, numerals, sung);
336
398
  if (n !== null && cell.kind === "slots")
337
399
  n++;
338
400
  return html;
@@ -363,7 +425,7 @@ function rowOpening(row, part, ending) {
363
425
  const leads = (part) => !part || part.first;
364
426
  function rowHtml(row, columns, settings, part) {
365
427
  const label = row.ending && leads(part) ? endingLabel(row.ending) : null;
366
- const cells = rowCells(row, settings.numerals, label ? ` data-ending="${label.shown}"` : "");
428
+ const cells = rowCells(row, settings.numerals, label ? ` data-ending="${label.shown}"` : "", settings.played !== null);
367
429
  const goesOn = row.continues && leads(part) ? `${endingLabel(row.continues).spoken}, continued` : "";
368
430
  const empty = `<span class="bm-empty" aria-hidden="true"></span>`.repeat(Math.max(0, columns - row.cells.length));
369
431
  const said = rowOpening(row, part, label?.spoken ?? goesOn);
package/dist/model.js CHANGED
@@ -8,6 +8,27 @@ 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
+ /** The last bar's index among events, starting from `last`. */
12
+ const lastIndex = (events, last) => events.reduce((at, e) => (e.kind === "bar" ? e.bar.index : e.kind === "open" ? lastIndex(e.events, at) : at), last);
13
+ /** The index of the last bar of the first open repeat's pass; every bar when there is none. */
14
+ function exactThrough(events) {
15
+ let last = 0;
16
+ for (const e of events) {
17
+ if (e.kind === "open")
18
+ return lastIndex(e.events, last);
19
+ if (e.kind === "bar")
20
+ last = e.bar.index;
21
+ }
22
+ return Number.POSITIVE_INFINITY;
23
+ }
24
+ const numberingOf = (parse) => ({
25
+ pickup: parse.pickup,
26
+ exactThrough: exactThrough(parse.events),
27
+ });
28
+ const playedNumber = (b, n) => ({
29
+ bar: b.index - (n.pickup ? 1 : 0),
30
+ approximate: b.index > n.exactThrough,
31
+ });
11
32
  /** Models `melody: false` changed the drawing of: the markup sizes its label gutter from the rows drawn only for these. */
12
33
  const meloffModels = new WeakSet();
13
34
  export const meloffChanged = (model) => meloffModels.has(model);
@@ -30,6 +51,20 @@ function indexByLine(bars) {
30
51
  }
31
52
  return out;
32
53
  }
54
+ /**
55
+ * Each bar line's first written number, the parse's `firstWritten`, for a line
56
+ * some pass plays: a row none plays shows no number. A drawn cell's number
57
+ * runs on from its line's first.
58
+ */
59
+ function playedStarts(lines, bars) {
60
+ const starts = new Map();
61
+ for (const l of lines.filter((l) => bars.has(l.line))) {
62
+ const first = l.kind === "bars" || l.kind === "invalid" ? l.firstWritten : undefined;
63
+ if (first !== undefined)
64
+ starts.set(l.line, first);
65
+ }
66
+ return starts;
67
+ }
33
68
  /** Each part's bars on its own lines, and each line's; a tutti bar once (barmark's grammar 7.4, 7.6). */
34
69
  function barsByLine(parse) {
35
70
  if (parse.parts.length < 2 && !parse.parts.some((p) => p.lines))
@@ -66,16 +101,19 @@ export function layoutChart(text, options = {}) {
66
101
  const parse = parseFor(text, options.part);
67
102
  const { header, body } = splitHeader(parse.lines);
68
103
  const groups = groupLines(body);
104
+ const bars = indexByLine(barsByLine(parse));
69
105
  const ctx = {
70
106
  parse,
71
107
  source: text.split(/\r?\n/),
72
108
  ...errorsByLine(parse),
73
109
  written: new Map(groups.flatMap((g) => (g.heading ? [[g.heading.line, g]] : []))),
74
- bars: indexByLine(barsByLine(parse)),
110
+ bars,
111
+ starts: playedStarts(parse.lines, bars),
75
112
  beats: tempoBeats(parse.lines),
76
113
  melody: options.melody !== false,
77
114
  changed: false,
78
115
  melodies: new Map(),
116
+ numbering: options.barNumbers === "played" ? numberingOf(parse) : null,
79
117
  };
80
118
  const blocks = groups.map((g) => layoutGroup(g, ctx));
81
119
  // A chart that writes its own rehearsal marks keeps them alone: letters beside them would mark each place twice.
@@ -188,10 +226,27 @@ function layoutGroup(group, ctx) {
188
226
  ...(broken ? [errorItem(h.line, ctx)] : []),
189
227
  ...(written && occurrence
190
228
  ? layoutReplay(written, group, occurrence, ctx)
191
- : layoutLines(group.lines, occurrence, ctx)),
229
+ : layoutLines(group.lines, drawnOccurrence(h, occurrence, broken), ctx)),
192
230
  ];
193
231
  return blockOf(broken ? null : h, occurrence, items);
194
232
  }
233
+ /** The occurrence a section's rows are laid out in: its heading's, or one that plays nothing when no pass plays the heading. */
234
+ const drawnOccurrence = (h, occurrence, broken) => occurrence ?? (h && !broken ? unplayed(h) : undefined);
235
+ /**
236
+ * A section no pass plays where it is written (a jump passes over it; a
237
+ * replay may play it later): its bars draw as written, from every pass on
238
+ * their lines (no range), and no occurrence of its heading plays them, so
239
+ * they have no played number.
240
+ */
241
+ const unplayed = (h) => ({
242
+ name: h.name,
243
+ line: h.line,
244
+ replayOf: null,
245
+ firstBar: null,
246
+ lastBar: null,
247
+ elided: false,
248
+ form: 0,
249
+ });
195
250
  /**
196
251
  * A replay draws its written section with its own bar numbers. Its own
197
252
  * text lines replace the written section's in order (extra ones follow the
@@ -376,16 +431,54 @@ function layoutOne(l, occurrence, previous, ctx, leftOut = new Set()) {
376
431
  return { items: [row], previous: lastSlots(item.cells) ?? previous };
377
432
  }
378
433
  /** The written bars a bar line draws, as played in the occurrence: a cut bar as written. */
379
- function landingsOn(l, played, ctx) {
380
- const written = barsOn(l.line, ctx);
381
- let bar = 0;
382
- const bars = l.cells.map((cell) => {
434
+ function landingsOn(l, occurrence, ctx) {
435
+ const played = playedOn(l.line, occurrence, ctx);
436
+ const bars = cellBars(l, played, ctx);
437
+ return landings(bars, sungPasses(l.line, bars, played, occurrence, ctx));
438
+ }
439
+ /**
440
+ * The passes whose words a line draws: its occurrence's, and for a bar no
441
+ * pass there plays, the passes of the occurrences a jump makes of it (a
442
+ * `D.S.` return reaching past a `To Coda` in the row); every pass on the
443
+ * line when its occurrence plays none.
444
+ */
445
+ function sungPasses(line, bars, played, occurrence, ctx) {
446
+ if (!played.length)
447
+ return barsOn(line, ctx);
448
+ const here = new Set(played.map((b) => b.written));
449
+ // Only a row a jump leaves early looks further, so a long chart of replays reads each row once.
450
+ if (bars.every((b) => !b || here.has(b.written)))
451
+ return played;
452
+ const later = heardOn(line, occurrence, ctx).filter((b) => !here.has(b.written));
453
+ return [...played, ...later];
454
+ }
455
+ /** Each written number's first bar among `bars`. */
456
+ function firstByWritten(bars) {
457
+ const out = new Map();
458
+ for (const b of bars)
459
+ if (!out.has(b.written))
460
+ out.set(b.written, b);
461
+ return out;
462
+ }
463
+ /**
464
+ * The bar each cell draws, by its written number (a line's bars run on from
465
+ * its first): its first pass in the occurrence, else the line's first (a
466
+ * cut bar is not played: it draws what it played when written); none for a
467
+ * fermata, a direction or a rehearsal mark, or a bar no pass plays.
468
+ */
469
+ function cellBars(l, played, ctx) {
470
+ const start = ctx.starts.get(l.line);
471
+ if (start === undefined)
472
+ return l.cells.map(() => undefined);
473
+ const here = firstByWritten(played);
474
+ const anywhere = firstByWritten(barsOn(l.line, ctx));
475
+ let written = start;
476
+ return l.cells.map((cell) => {
383
477
  if (cell.kind !== "slots" && cell.kind !== "simile")
384
478
  return undefined;
385
- const i = bar++;
386
- return played[i] ?? written[i];
479
+ const n = written++;
480
+ return here.get(n) ?? anywhere.get(n);
387
481
  });
388
- return landings(bars, played.length ? played : written);
389
482
  }
390
483
  /**
391
484
  * The words under a row or system that no line in it sings under its
@@ -397,7 +490,7 @@ function lyricRows(lines, occurrence, ctx, leftOut) {
397
490
  if (!ref)
398
491
  return [];
399
492
  const sung = new Set(drawn.flatMap((l) => singerOf(l, ctx.parse) ?? []));
400
- const lands = landingsOn(ref, playedOn(ref.line, occurrence, ctx), ctx);
493
+ const lands = landingsOn(ref, occurrence, ctx);
401
494
  return rowVerses(lands, sung, leftOut);
402
495
  }
403
496
  const systemOf = (l) => (l?.kind === "bars" || l?.kind === "invalid") && l.system !== undefined ? l.system : null;
@@ -405,11 +498,9 @@ const systemOf = (l) => (l?.kind === "bars" || l?.kind === "invalid") && l.syste
405
498
  function systemLines(lines, i) {
406
499
  const system = systemOf(lines[i]);
407
500
  const out = [];
408
- for (const l of lines.slice(i)) {
409
- if (systemOf(l) !== system)
410
- break;
411
- out.push(l);
412
- }
501
+ // By index: a slice from `i` would copy the rest of the chart for every system.
502
+ for (let j = i; j < lines.length && systemOf(lines[j]) === system; j++)
503
+ out.push(lines[j]);
413
504
  return out;
414
505
  }
415
506
  const lastOfSystem = (item) => {
@@ -430,10 +521,10 @@ const labelOf = (l) => `${l.part ?? ""}${l.lineName === undefined ? "" : `.${l.l
430
521
  /** A row per declared part, or per line it writes, in score order: its own line, its error, or tacet bars. */
431
522
  function layoutSystem(lines, written, occurrence, previous, ctx) {
432
523
  const ref = lines.find((l) => l.kind === "bars" && !ctx.errors.has(l.line));
433
- const reference = ref ? layoutRow(ref, playedOn(ref.line, occurrence, ctx), previous, ctx) : null;
524
+ const reference = ref ? layoutRow(ref, occurrence, previous, ctx) : null;
434
525
  const ownRow = (own) => ctx.errors.has(own.line) || own.kind !== "bars"
435
526
  ? errorItem(own.line, ctx)
436
- : layoutRow(own, playedOn(own.line, occurrence, ctx), previous, ctx);
527
+ : layoutRow(own, occurrence, previous, ctx);
437
528
  const rows = ctx.parse.parts.flatMap((p) => {
438
529
  const own = ownLines(lines, p);
439
530
  // A part whose every line was left out has no row; one with no line written is tacet.
@@ -465,13 +556,22 @@ const NO_ROW = {
465
556
  /** The system's bars, with nothing played in them (barmark's grammar 7.4). */
466
557
  function tacetRow(reference, line) {
467
558
  const base = reference ?? NO_ROW;
468
- const cells = base.cells.map((c) => c.kind === "slots" ? { kind: "slots", meter: c.meter, slots: [], cut: false, tacet: true } : c);
559
+ const cells = base.cells.map((c) => c.kind === "slots"
560
+ ? {
561
+ kind: "slots",
562
+ meter: c.meter,
563
+ slots: [],
564
+ cut: false,
565
+ tacet: true,
566
+ ...(c.playedNumbers && { playedNumbers: c.playedNumbers }),
567
+ }
568
+ : c);
469
569
  return { ...base, line, cells };
470
570
  }
471
571
  function layoutLine(l, occurrence, previous, ctx) {
472
572
  switch (l.kind) {
473
573
  case "bars":
474
- return layoutRow(l, playedOn(l.line, occurrence, ctx), previous, ctx);
574
+ return layoutRow(l, occurrence, previous, ctx);
475
575
  case "text":
476
576
  return textItem(l.text);
477
577
  case "directive":
@@ -514,36 +614,81 @@ function rowMarks(l) {
514
614
  const marks = { opens: l.opens, closes: l.closes, repeat: l.repeat, ending: l.ending };
515
615
  return l.continues ? { ...marks, continues: l.continues } : marks;
516
616
  }
517
- function layoutRow(l, played, previous, ctx) {
617
+ function layoutRow(l, occurrence, previous, ctx) {
618
+ const played = playedOn(l.line, occurrence, ctx);
619
+ const bars = cellBars(l, played, ctx);
518
620
  const cells = [];
519
- // A cut bar is not played: what it would play is what the line's bar played when written.
520
- const written = barsOn(l.line, ctx);
521
- let bar = 0;
522
621
  let prev = previous;
523
- for (const cell of l.cells) {
524
- const model = layoutCell(cell, played[bar] ?? written[bar], prev);
525
- if (cell.kind === "slots" || cell.kind === "simile")
526
- bar++;
622
+ const partly = ctx.starts.has(l.line);
623
+ for (const [i, cell] of l.cells.entries()) {
624
+ const drawn = layoutCell(cell, bars[i], prev);
625
+ const model = partly && cell.kind === "simile" && !bars[i] ? unplayedSimile(drawn) : drawn;
527
626
  if (model.kind === "slots")
528
627
  prev = model;
529
628
  cells.push(model);
530
629
  }
531
- return {
630
+ const row = {
532
631
  kind: "row",
533
632
  line: l.line,
534
633
  // Numbered as written, as a band counts (issue #92): repeats, endings, jumps and replays don't move it.
535
- barNumber: (played[0] ?? written[0])?.written ?? null,
634
+ barNumber: ctx.starts.get(l.line) ?? null,
536
635
  ...rowMarks(l),
537
636
  cells: withUnread(cells, l, ctx),
538
- ...singing(l, cells, played, ctx),
637
+ ...singing(l, cells, occurrence, ctx),
638
+ };
639
+ return withPlayedNumbers(row, occurrence, ctx);
640
+ }
641
+ /**
642
+ * The bars a line plays in its drawn occurrence: the section occurrence the
643
+ * heading draws and any a jump makes of it (the parser gives a D.S. or D.C.
644
+ * return the same heading line), or every bar on the line before any heading.
645
+ */
646
+ function heardOn(line, occurrence, ctx) {
647
+ const all = barsOn(line, ctx);
648
+ if (!occurrence)
649
+ return all;
650
+ const drawn = ctx.parse.sections.filter((s) => s.line === occurrence.line);
651
+ return all.filter((b) => drawn.some((s) => s.firstBar !== null && s.lastBar !== null && b.index >= s.firstBar && b.index <= s.lastBar));
652
+ }
653
+ /**
654
+ * Played numbers, from the parser's play order: each bar's, a pass each in
655
+ * order, and the row's, its first bar's. A bar is known by its written
656
+ * number, which a line's bars each have once. Written numbers alone leave
657
+ * the row as it is.
658
+ */
659
+ function withPlayedNumbers(row, occurrence, ctx) {
660
+ const { numbering } = ctx;
661
+ if (!numbering)
662
+ return row;
663
+ const byWritten = new Map();
664
+ for (const b of heardOn(row.line, occurrence, ctx)) {
665
+ const list = byWritten.get(b.written);
666
+ if (list)
667
+ list.push(playedNumber(b, numbering));
668
+ else
669
+ byWritten.set(b.written, [playedNumber(b, numbering)]);
670
+ }
671
+ // Written numbers run on along a line, a bar a cell, whichever bars a pass leaves out.
672
+ let written = row.barNumber;
673
+ const cells = row.cells.map((c) => {
674
+ if (c.kind !== "slots")
675
+ return c;
676
+ const at = written === null ? undefined : byWritten.get(written++);
677
+ return { ...c, playedNumbers: at ?? [] };
678
+ });
679
+ const first = cells.find((c) => c.kind === "slots");
680
+ return {
681
+ ...row,
682
+ playedNumbers: first?.kind === "slots" ? (first.playedNumbers ?? []) : [],
683
+ cells,
539
684
  };
540
685
  }
541
686
  /** A singing line's fields: its note sets as pitch names, and the verses under its slots (barmark's grammar 7.7). */
542
- function singing(l, cells, played, ctx) {
687
+ function singing(l, cells, occurrence, ctx) {
543
688
  const singer = singerOf(l, ctx.parse);
544
689
  if (singer === null)
545
690
  return {};
546
- const verses = sungVerses(cells, landingsOn(l, played, ctx), singer);
691
+ const verses = sungVerses(cells, landingsOn(l, occurrence, ctx), singer);
547
692
  // A line with no words draws as any part line does.
548
693
  return verses.length ? { sings: true, verses } : {};
549
694
  }
@@ -558,6 +703,12 @@ function layoutCell(cell, played, previous) {
558
703
  return withPlayed(asWritten(cell, previous), played);
559
704
  return withPlayed(layoutBar(cell, played, previous), played);
560
705
  }
706
+ /**
707
+ * A `%` no pass plays on a line a pass does play (a jump lands past it):
708
+ * the parser resolves `%` only where it plays, so it draws as written, the
709
+ * sign itself, and is spoken as a bar with nothing resolved in it.
710
+ */
711
+ const unplayedSimile = (cell) => cell.kind === "slots" ? { ...cell, slots: [], simile: "unplayed" } : cell;
561
712
  /** A tutti bar as written: its own slots, holds as holds, or `%` itself. */
562
713
  function asWritten(cell, previous) {
563
714
  const bar = layoutBar(cell, undefined, previous);
package/dist/speech.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * parsed structure, never from the symbol's text.
4
4
  */
5
5
  import { type ChordRecord, type Key, type Slot, type Syllable } from "barmark";
6
- import type { CellModel, DiagramEntry } from "./types.js";
6
+ import type { CellModel, DiagramEntry, PlayedNumber } 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
  /** A diagram with no shape, shown in its frame and said in its label. */
@@ -20,10 +20,12 @@ export declare const VOICING_REPLACED = "written voicing doesn't fit standard tu
20
20
  */
21
21
  export declare function speakDiagram(entry: DiagramEntry, key?: Key): string;
22
22
  export declare function speakSlot(slot: Slot, key?: Key): string;
23
- /** What a bar is called aloud: "pickup" for bar 0, "bar" with no number, else "bar 9". */
24
- export declare function barLabel(barNumber: number | null): string;
23
+ /** A bar's number: as written (null when it has none), or its played numbers, one a pass. */
24
+ export type BarName = number | null | readonly PlayedNumber[];
25
+ /** What a bar is called aloud: "pickup" for bar 0, "bar" with no number, else "bar 9"; played numbers as `playedLabel` says them. */
26
+ export declare function barLabel(barNumber: BarName): string;
25
27
  /** "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. */
26
- export declare function speakBar(barNumber: number | null, cell: CellModel, numerals?: boolean): string;
28
+ export declare function speakBar(barNumber: BarName, cell: CellModel, numerals?: boolean): string;
27
29
  /**
28
30
  * The words on a bar, each verse's: `sung “maz-ing”` (or `words “…”` in a
29
31
  * lyric row on no melody), or with several verses `verse 1 “maz-ing”,
package/dist/speech.js CHANGED
@@ -176,8 +176,45 @@ function speakDirection(d) {
176
176
  return d.kind;
177
177
  return `${d.to === "start" ? "da capo" : "dal segno"}${d.al ? ` al ${d.al}` : ""}`;
178
178
  }
179
- /** What a bar is called aloud: "pickup" for bar 0, "bar" with no number, else "bar 9". */
179
+ const about = (p) => `${p.approximate ? "about " : ""}${p.bar}`;
180
+ const aboutBar = (p) => `${p.approximate ? "about " : ""}bar ${p.bar}`;
181
+ /**
182
+ * Played numbers aloud: "bar 1", "bar 1 and bar 5", "bars 1, 5 and 9",
183
+ * "bars 9 to 37, 8 times"; after a vamp "about bar 11", and with every pass
184
+ * after it "about bars 2, 3 and 4"; the pickup first, "pickup, then bar 2";
185
+ * "bar" when no pass plays it.
186
+ */
187
+ function playedLabel(passes) {
188
+ const [first, ...rest] = passes;
189
+ const last = rest.at(-1);
190
+ if (!first)
191
+ return "bar";
192
+ if (first.bar === 0)
193
+ return rest.length ? `pickup, then ${playedLabel(rest)}` : "pickup";
194
+ if (!last)
195
+ return aboutBar(first);
196
+ if (passes.every((p) => p.approximate))
197
+ return `about ${barsLabel(passes.map((p) => ({ bar: p.bar, approximate: false })))}`;
198
+ if (rest.length === 1)
199
+ return `${aboutBar(first)} and ${aboutBar(last)}`;
200
+ return barsLabel(passes);
201
+ }
202
+ /** Two passes or more as one list: "bars 9 and 10", "bars 1, 5 and 9", "bars 9 to 37, 8 times". */
203
+ function barsLabel(passes) {
204
+ const [first, second, third] = passes;
205
+ const last = passes.at(-1);
206
+ if (!first || !second || !last)
207
+ return "bar";
208
+ if (passes.length === 2)
209
+ return `bars ${about(first)} and ${about(last)}`;
210
+ if (third && passes.length === 3)
211
+ return `bars ${about(first)}, ${about(second)} and ${about(third)}`;
212
+ return `bars ${about(first)} to ${about(last)}, ${passes.length} times`;
213
+ }
214
+ /** What a bar is called aloud: "pickup" for bar 0, "bar" with no number, else "bar 9"; played numbers as `playedLabel` says them. */
180
215
  export function barLabel(barNumber) {
216
+ if (typeof barNumber === "object" && barNumber !== null)
217
+ return playedLabel(barNumber);
181
218
  if (barNumber === 0)
182
219
  return "pickup";
183
220
  return barNumber === null ? "bar" : `bar ${barNumber}`;
@@ -191,7 +228,7 @@ export function speakBar(barNumber, cell, numerals = false) {
191
228
  if (cell.kind === "rehearsal")
192
229
  return `rehearsal ${cell.label}`;
193
230
  const bar = barLabel(barNumber);
194
- if (cell.simile)
231
+ if (cell.simile === true)
195
232
  return `${bar}: each part repeats its bar before`;
196
233
  const meter = cell.meter ? `, in ${cell.meter.n}/${cell.meter.d}` : "";
197
234
  const cut = cell.cut ? ", cut on this pass" : "";
package/dist/styles.d.ts CHANGED
@@ -15,6 +15,13 @@ export declare const PALETTES: {
15
15
  export declare const FIT_STEPS: number[];
16
16
  /** The rules only `columns: "row"` uses, at the stylesheet's end. */
17
17
  export declare const ROW_COLUMNS_CSS: string;
18
+ export declare const PLAYED_CSS: string;
19
+ /**
20
+ * How many chord em the played gutter's minimum is wider than the written
21
+ * gutter, from the numbers' width (`--bm-played-width`) and, with part
22
+ * labels, the longest label's characters: what a section's fit adds.
23
+ */
24
+ export declare function playedGutterExtra(width: number, labels: number | null): number;
18
25
  /** The strip's rules, between the shared rules and the row rules, so a chart drawn without it is styled byte for byte as before. */
19
26
  export declare const DIAGRAMS_CSS: string;
20
27
  export declare const stylesheet: string;
package/dist/styles.js CHANGED
@@ -230,6 +230,44 @@ const minify = (text) => text
230
230
  .replace(/:\s+/g, ":");
231
231
  /** The rules only `columns: "row"` uses, at the stylesheet's end. */
232
232
  export const ROW_COLUMNS_CSS = minify(rowCss);
233
+ /**
234
+ * `barNumbers: "played"`: the gutter is a track that grows to its numbers
235
+ * (`1 · 5 · 9`, `~101 … ~137`), on one line, and at least as wide as the
236
+ * chart's longest row of them needs, estimated from `--bm-played-width` (em
237
+ * of the numbers' text, from `html.ts`), so the sections and wrapped rows
238
+ * still start their bars together. Not in `stylesheet`: played markup
239
+ * carries these rules itself, so a chart of written numbers is styled byte
240
+ * for byte as before.
241
+ *
242
+ * `playedIndent` is that minimum in the em of text at `size`: headings, text
243
+ * lines and directives start where the bars do, as they do with written
244
+ * numbers. Part labels' charts keep the written indent, as they do with
245
+ * written numbers.
246
+ */
247
+ const playedIndent = (size) => `calc(max(${at(SIZES.barNumber, GUTTER)},var(--bm-played-width) * 1em + .5em) * ${Number((SIZES.barNumber / size).toFixed(4))})`;
248
+ const IS_PLAYED = '[data-bar-numbers="played"]';
249
+ const PLAYED = `.bm-chart${IS_PLAYED}`;
250
+ const playedCss = `
251
+ ${PLAYED} .bm-grid,${ROW}${IS_PLAYED} ${OWN}{grid-template-columns:auto ${CELLS}}
252
+ ${PLAYED} .bm-bar-number{width:auto;min-width:max(${at(SIZES.barNumber, GUTTER)},calc(var(--bm-played-width) * 1em + .5em));padding-right:.5em;white-space:nowrap}
253
+ ${PLAYED}[data-parts] .bm-bar-number{min-width:calc(var(--bm-label-chars) * .62em + var(--bm-played-width) * 1em + 1.4em)}
254
+ ${PLAYED}:not([data-parts]) .bm-heading{margin-left:${playedIndent(SIZES.heading)}}
255
+ ${PLAYED}:not([data-parts]) .bm-text{margin-left:${playedIndent(SIZES.text)}}
256
+ ${PLAYED}:not([data-parts]) .bm-directive{margin-left:${playedIndent(SIZES.directive)}}
257
+ `;
258
+ export const PLAYED_CSS = minify(playedCss);
259
+ /**
260
+ * How many chord em the played gutter's minimum is wider than the written
261
+ * gutter, from the numbers' width (`--bm-played-width`) and, with part
262
+ * labels, the longest label's characters: what a section's fit adds.
263
+ */
264
+ export function playedGutterExtra(width, labels) {
265
+ const played = labels === null
266
+ ? SIZES.barNumber * Math.max(GUTTER / SIZES.barNumber, width + 0.5)
267
+ : SIZES.barNumber * (labels * 0.62 + width + 1.4);
268
+ const written = labels === null ? GUTTER : GUTTER + 0.9 + labels * 0.62;
269
+ return Math.max(0, played - written);
270
+ }
233
271
  /**
234
272
  * A chord diagram, in chord sizes. A viewBox unit is 3.5/78 of a chord size,
235
273
  * so strings stand .45em apart in either image. A wide drawing (one with a
package/dist/types.d.ts CHANGED
@@ -18,6 +18,17 @@ export type LayoutOptions = {
18
18
  melody?: boolean;
19
19
  /** Give the model a diagram entry for each chord, as a guitar plays it; off when absent. */
20
20
  chordDiagrams?: "guitar";
21
+ /** `"played"`: give each row and bar its played numbers (`playedNumbers`); written numbers stay as they are. */
22
+ barNumbers?: boolean | "played";
23
+ };
24
+ /**
25
+ * A bar's number in play order (`PlayedBar.index`, a pickup 0 as written):
26
+ * approximate once play has passed an open repeat (`x ...`), whose passes
27
+ * are unknown.
28
+ */
29
+ export type PlayedNumber = {
30
+ bar: number;
31
+ approximate: boolean;
21
32
  };
22
33
  /** What to draw, with every musical decision already made. */
23
34
  export type ChartModel = {
@@ -81,6 +92,8 @@ export type BlockItem = {
81
92
  line: number;
82
93
  /** The written number of the row's first bar (`PlayedBar.written`); a replay shows its section's numbers. Null for a row with no bar. */
83
94
  barNumber: number | null;
95
+ /** With `barNumbers: "played"`: the played number of the row's first bar on each pass of this drawn occurrence, in order; empty when no pass plays it. */
96
+ playedNumbers?: PlayedNumber[];
84
97
  opens: boolean;
85
98
  closes: boolean;
86
99
  repeat: Repeat;
@@ -157,10 +170,16 @@ export type CellModel = {
157
170
  words?: Words[];
158
171
  /** A bar where the part rests, in a system (barmark's grammar 7.4). */
159
172
  tacet?: true;
160
- /** `%` on a tutti line whose parts each copy a different bar: drawn as `%`, its slots empty (barmark's grammar 7.4). */
161
- simile?: true;
173
+ /**
174
+ * Drawn as `%`, its slots empty: `true` on a tutti line whose parts each
175
+ * copy a different bar (barmark's grammar 7.4); `"unplayed"` where no
176
+ * pass plays it, on a line a pass does play.
177
+ */
178
+ simile?: true | "unplayed";
162
179
  /** The error message of each slot written here that can't be read, in order (barmark's grammar 2.3); absent when none. */
163
180
  unread?: string[];
181
+ /** With `barNumbers: "played"`: this bar's played number on each pass, as the row's `playedNumbers`. */
182
+ playedNumbers?: PlayedNumber[];
164
183
  } | {
165
184
  kind: "fermata";
166
185
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barmark/render",
3
- "version": "0.21.1",
3
+ "version": "0.22.1",
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.2",
51
- "barmark": "^0.25.0"
50
+ "@barmark/fretboard": "^0.1.3",
51
+ "barmark": "^0.26.0"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "rm -rf dist && tsc -p tsconfig.build.json",