@barmark/render 0.22.3 → 0.23.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,44 @@ package uses [semantic versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.23.1] - 2026-12-01
10
+
11
+ ### Fixed
12
+
13
+ - **A system too wide for its box no longer squeezes its chords into each
14
+ other.** A section of several parts' systems (Morning Song's verse, or
15
+ any system whose bars hold long chords) never wrapped, and on a narrow
16
+ screen its bar columns shrank until chords ran over the next bar, and on
17
+ a phone pushed the page sideways too. Now its bars keep their width, its
18
+ parts keep their bar lines together, and the chart scrolls sideways
19
+ inside its own box, and the page itself does not scroll. Text, notes,
20
+ directives and unreadable rows beside or inside a system still wrap at
21
+ the chart's box, and a section whose plain rows are too wide
22
+ wraps as before. A system still does not wrap; the README now says
23
+ so. Charts without systems, and printed charts, are drawn as before,
24
+ and no chart's markup changes: the fix is a few rules at the end of
25
+ `stylesheet`.
26
+
27
+ ## [0.23.0] - 2026-11-30
28
+
29
+ ### Changed
30
+
31
+ - **Bar numbers count the bars on the page, a replayed section included**
32
+ (Kevin, 2026-11-30). A heading with no bars under it replays its
33
+ section, and the grid draws that section's rows again; they used to
34
+ show the numbers the section was written with, so the numbers down the
35
+ page repeated (1, 2, 6, 10, 12, 16, 20, 10, 12, 12, 24). Now a replayed
36
+ section counts as written again where its heading is: its rows go on
37
+ from the count, and every section after it counts them too (1, 2, 6,
38
+ 10, 12, 16, 20, 24, 26, 30, 34). A screen reader hears the same numbers,
39
+ with the numbers hidden too (`barNumbers: false`), where bars are still
40
+ spoken by number.
41
+ A repeat still counts its bars once, a chart with no replay that plays
42
+ is numbered as before, and played numbers (`barNumbers: "played"`) do
43
+ not change. The numbers come from the parser's `pageShift`.
44
+ - **Requires `barmark` 0.27.0**, for `pageShift`: the range is now
45
+ `>=0.27.0 <1.0.0`.
46
+
9
47
  ## [0.22.3] - 2026-11-30
10
48
 
11
49
  ### Changed
@@ -684,7 +722,9 @@ that needs no script or as the `<barmark-chart>` web component. Requires
684
722
  zoom without sideways scrolling, the element renders and re-renders, and
685
723
  a screen reader hears "bar 9: D". Run them with `bun run test:browser`.
686
724
 
687
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.22.3...HEAD
725
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.23.1...HEAD
726
+ [0.23.1]: https://github.com/kevinpeckham/barmark/compare/render-v0.23.0...render-v0.23.1
727
+ [0.23.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.22.3...render-v0.23.0
688
728
  [0.22.3]: https://github.com/kevinpeckham/barmark/compare/render-v0.22.2...render-v0.22.3
689
729
  [0.22.2]: https://github.com/kevinpeckham/barmark/compare/render-v0.22.1...render-v0.22.2
690
730
  [0.22.1]: https://github.com/kevinpeckham/barmark/compare/render-v0.22.0...render-v0.22.1
package/README.md CHANGED
@@ -81,10 +81,10 @@ the element loads, with `<style data-barmark-font>` holding
81
81
  | `renderChart` option | Element attribute (property) | Default | |
82
82
  |---|---|---|---|
83
83
  | `theme` | `theme` (`theme`) | `"auto"` | `"auto"` follows the system; `"light"` or `"dark"` force one |
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 |
84
+ | `barNumbers` | `bar-numbers="off"` or `"played"` (`barNumbers`) | `true` | bar numbers at the start of each row: `true` the bars counted down the page, a replayed section counted as written again; `false` or `"off"` none; `"played"` numbers in play order (below). Any other attribute value is the default |
85
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) |
86
86
  | `numerals` | `numerals` (`numerals`) | none | `"nashville"` (6m⁷) or `"roman"` (vi⁷): each chord as its degree in its bar's key |
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 |
87
+ | `wrap` | `wrap="off"` (`wrap`) | `true` | wrap a section's rows when it is wider than the chart's box (a section of systems does not wrap: it scrolls sideways inside the chart's box instead, see [What it draws](#what-it-draws)); off, rows keep their columns and the chart overflows, for its page to scroll |
88
88
  | `melody` | `melody="off"` (`melody`) | `true` | `false` leaves a voice part's singing line out of the grid; its words stay, drawn by beat under the chords. The melody is left out only beside a line that draws its bars; a melody on its own stays, and so does a line with a problem or one that writes chord names, `N.C.` or `?`. A melisma's held place is not drawn where the melody is left out, so the words take the space they would with no melody written. In a one-part lead sheet the chord line then draws as a plain row with no label. `@barmark/score`'s score view still shows it |
89
89
  | `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"` |
90
90
  | `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 |
@@ -126,7 +126,7 @@ played more than once where it is drawn (inside `|: :|`, under `x N`, or
126
126
  where a `D.S.` or `D.C.` returns) shows its first bar's number on each pass,
127
127
  `1 · 5`, up to three; four or more show the first and the last, `9 … 37`.
128
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 `|: :|`,
129
+ shown, as in the default; a later pass of its row (inside `|: :|`,
130
130
  or where a `D.C.` returns) shows its number. An open repeat (`x ...`) is
131
131
  counted once, since its passes are unknown: every number after it is
132
132
  approximate and shows as `~11`. A screen reader hears each bar's own
@@ -134,11 +134,11 @@ numbers: "bar 1 and bar 5", "bars 1, 5 and 9", "bars 9 to 37, 8 times",
134
134
  "about bar 11", "about bars 12, 14 and 16". The gutter widens to the
135
135
  longest numbers on one line, and a section wraps sooner to make room for
136
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
137
+ start where the bars do, as in the default; with part labels they
138
+ keep their place over the label column, as in the default. Played markup
139
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
140
+ needs nothing more. The bars counted down the page stay the default
141
+ because they are what a printed chart and a band use; the model gives played numbers as
142
142
  `playedNumbers` on each row and bar (`{ bar, approximate }`, a pass each)
143
143
  only in this mode.
144
144
 
@@ -263,7 +263,12 @@ and Windows High Contrast keeps bar lines and marks visible.
263
263
 
264
264
  - Everything is sized in em from `--barmark-size`, so text size and zoom
265
265
  scale the chart; a section too wide for its container wraps its rows
266
- instead of scrolling sideways.
266
+ instead of scrolling sideways. A system of several parts is the
267
+ exception: a chart holding a system too wide for its box becomes, on
268
+ screen, a region that scrolls sideways. Chromium and Firefox let the
269
+ keyboard reach such a region by default (Tab stops on it, then the
270
+ arrow keys scroll it); Safari does not. The chart adds no `tabindex`
271
+ of its own, since that would change its markup.
267
272
  - Every bar has a spoken name built from the parsed chart: "bar 9: A seven
268
273
  sus four, hold", "triplet: D, E, F sharp minor", "note E", "C over E".
269
274
  Sections are labelled by their headings, and repeats are spoken ("play
@@ -298,11 +303,12 @@ Chords appear in their canonical form whatever the author typed (`Cø`
298
303
  shows as Cm⁷(♭5)). `%` is drawn as the bar it copies (as the `%` sign
299
304
  where no pass plays it); a replayed section
300
305
  is drawn in full, and its own lyrics replace the written section's. Bar
301
- numbers count the bars as written, each once, as a band counts them: a
302
- repeat, an ending, a jump or a replay doesn't move them, so a replayed
303
- section shows the numbers it was written with. A pickup is bar 0: its
306
+ numbers count the bars down the page, each once, as a band counts them: a
307
+ repeat, an ending or a jump doesn't move them, and a replayed section
308
+ counts as written again where its heading is, so its rows go on from the
309
+ count and the numbers after it never repeat (the parser's `pageShift`). A pickup is bar 0: its
304
310
  row shows no number in the gutter (`barNumber` is `0` in the model) and
305
- is spoken as "pickup", and the bars after it are 1, 2, and so on. A line with an error shows as written, underlined,
311
+ is spoken as "pickup", and the bars after it are 1, 2, and so on; drawn again by a replay, the pickup's row is a bar like any other, numbered and spoken with its place in the count. A line with an error shows as written, underlined,
306
312
  with its message, unless its only errors are slots that can't be read
307
313
  (`CM7`): that line draws as usual, each such slot as written in the
308
314
  error colour with its message as a tooltip and in the bar's spoken name. `layoutChart(text)` returns all of this as data, if
@@ -319,8 +325,17 @@ stacked rows, one per part in score order, with the part's label in the
319
325
  gutter and one bar number on the top row. A part tacet in a system gets
320
326
  an empty row that says "tacet" in its first bar, so every system keeps its
321
327
  shape; a tutti line is one row. The header lists the parts' names, and
322
- each part row is announced by name to a screen reader. On a screen too
323
- narrow for a section, its rows wrap one by one, as any row does.
328
+ each part row is announced by name to a screen reader.
329
+
330
+ A system does not wrap. On a screen too narrow for it, its bars keep their
331
+ width, its parts keep their bar lines together, and the chart scrolls
332
+ sideways inside its own box; the page itself does not scroll, and no
333
+ chord runs into the next bar. Text, notes, directives and unreadable
334
+ rows beside or inside a system still wrap at the chart's box. A section
335
+ that also holds a plain row too wide for the box wraps as any section
336
+ does: each bar of its systems then takes a full-width line of its own,
337
+ under its part's label on a line of its own, so the parts no longer line
338
+ up. A printed chart is laid out as before.
324
339
 
325
340
  A voice line (barmark's grammar 4.3 and 7.7: the line a part sings on,
326
341
  such as `Vox.Mel` under a lead sheet's bare `Vox` chord line) draws each
package/dist/element.js CHANGED
@@ -8,7 +8,7 @@ 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. */
11
+ /** `bar-numbers`: "off" hides them, "played" counts in play order, anything else (none included) counts down the page. */
12
12
  const barNumbersOf = (value) => value === "played" ? "played" : value !== "off";
13
13
  export function optionsFromAttributes(el) {
14
14
  const theme = el.getAttribute("theme");
@@ -121,7 +121,7 @@ function defineElement() {
121
121
  set theme(v) {
122
122
  this.setAttribute("theme", v);
123
123
  }
124
- /** true for written numbers, "played" for numbers in play order, false for none (set `false`, `"off"` or any falsy value). */
124
+ /** true for the bars counted down the page, "played" for numbers in play order, false for none (set `false`, `"off"` or any falsy value). */
125
125
  get barNumbers() {
126
126
  return barNumbersOf(this.getAttribute("bar-numbers"));
127
127
  }
package/dist/html.d.ts CHANGED
@@ -2,8 +2,9 @@ import { type Numerals } from "./chord.js";
2
2
  export type RenderOptions = {
3
3
  theme?: "auto" | "light" | "dark";
4
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
5
+ * Bar numbers at the start of each row: `true` (the default), the bars
6
+ * counted down the page, each written bar once and a replayed section
7
+ * counted as written again; `false` or `"off"`, none; `"played"`, each row's place in play
7
8
  * order, a number a pass (`1 · 5`), `~` after a vamp. Any other value is
8
9
  * written, but for `0` or `""`, which hide them as `false` does; `null`,
9
10
  * like none, is the default.
package/dist/html.js CHANGED
@@ -361,8 +361,8 @@ function gutterHtml(row, settings, part) {
361
361
  if (!settings.gutter)
362
362
  return "";
363
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) : "";
364
+ const page = row.barNumber !== 0 ? (row.barNumber ?? "") : "";
365
+ const number = lead ? (settings.played ? playedText(row) : page) : "";
366
366
  const label = part
367
367
  ? `<span class="bm-part-label" part="part-label">${escapeHtml(part.label)}</span>`
368
368
  : "";
package/dist/model.js CHANGED
@@ -114,6 +114,7 @@ export function layoutChart(text, options = {}) {
114
114
  changed: false,
115
115
  melodies: new Map(),
116
116
  numbering: options.barNumbers === "played" ? numberingOf(parse) : null,
117
+ pageShift: 0,
117
118
  };
118
119
  const blocks = groups.map((g) => layoutGroup(g, ctx));
119
120
  // A chart that writes its own rehearsal marks keeps them alone: letters beside them would mark each place twice.
@@ -216,12 +217,15 @@ function groupLines(lines) {
216
217
  groups.push(current);
217
218
  return groups;
218
219
  }
220
+ /** What a section's rows add to their written numbers: the parser counts the bars on the page, a replay's going on from the count (barmark's grammar A.7). */
221
+ const pageShiftOf = (h) => h?.pageShift ?? 0;
219
222
  function layoutGroup(group, ctx) {
220
223
  const h = group.heading;
221
224
  const occurrence = h ? ctx.parse.sections.find((s) => s.line === h.line) : undefined;
222
225
  // A heading with an error is drawn as written, like any line with an error.
223
226
  const broken = h !== null && ctx.errors.has(h.line);
224
227
  const written = occurrence?.replayOf != null ? ctx.written.get(occurrence.replayOf) : undefined;
228
+ ctx.pageShift = pageShiftOf(h);
225
229
  const items = [
226
230
  ...(broken ? [errorItem(h.line, ctx)] : []),
227
231
  ...(written && occurrence
@@ -248,7 +252,7 @@ const unplayed = (h) => ({
248
252
  form: 0,
249
253
  });
250
254
  /**
251
- * A replay draws its written section with its own bar numbers. Its own
255
+ * A replay draws its written section, its bars numbered on down the page. Its own
252
256
  * text lines replace the written section's in order (extra ones follow the
253
257
  * last row); its other lines follow. `->` marks the bar the parser cut.
254
258
  */
@@ -630,14 +634,20 @@ function layoutRow(l, occurrence, previous, ctx) {
630
634
  const row = {
631
635
  kind: "row",
632
636
  line: l.line,
633
- // Numbered as written, as a band counts (issue #92): repeats, endings, jumps and replays don't move it.
634
- barNumber: ctx.starts.get(l.line) ?? null,
637
+ // Numbered down the page (issue #92, barmark's grammar A.7): each written bar once, repeats,
638
+ // endings and jumps not moving it, a replayed section counted as written again.
639
+ barNumber: pageNumber(l.line, ctx),
635
640
  ...rowMarks(l),
636
641
  cells: withUnread(cells, l, ctx),
637
642
  ...singing(l, cells, occurrence, ctx),
638
643
  };
639
644
  return withPlayedNumbers(row, occurrence, ctx);
640
645
  }
646
+ /** A row's number on the page: its line's written first, shifted by its section's place; none for a row no pass plays. */
647
+ function pageNumber(line, ctx) {
648
+ const start = ctx.starts.get(line);
649
+ return start === undefined ? null : start + ctx.pageShift;
650
+ }
641
651
  /**
642
652
  * The bars a line plays in its drawn occurrence: the section occurrence the
643
653
  * heading draws and any a jump makes of it (the parser gives a D.S. or D.C.
@@ -669,7 +679,7 @@ function withPlayedNumbers(row, occurrence, ctx) {
669
679
  byWritten.set(b.written, [playedNumber(b, numbering)]);
670
680
  }
671
681
  // Written numbers run on along a line, a bar a cell, whichever bars a pass leaves out.
672
- let written = row.barNumber;
682
+ let written = ctx.starts.get(row.line) ?? null;
673
683
  const cells = row.cells.map((c) => {
674
684
  if (c.kind !== "slots")
675
685
  return c;
package/dist/styles.d.ts CHANGED
@@ -15,6 +15,8 @@ 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
+ /** The system rules, at the stylesheet's very end. */
19
+ export declare const SYSTEM_FIT_CSS: string;
18
20
  export declare const PLAYED_CSS: string;
19
21
  /**
20
22
  * How many chord em the played gutter's minimum is wider than the written
package/dist/styles.js CHANGED
@@ -230,6 +230,41 @@ 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
+ * A section holding a system (several parts' rows sharing bar columns). A
235
+ * section's fit (`data-fit`) is estimated from its plain rows only, so one
236
+ * made of systems never reaches its wrap and its grid, held to its box by
237
+ * `max-width:100%`, squeezed its columns down to each bar's least width
238
+ * until chords ran into the next bar. Here such a grid keeps its columns at
239
+ * their content's width and, too wide for its box, scrolls inside the
240
+ * chart, its parts' bar lines still together. Where the section does wrap
241
+ * (its plain rows are wider still), it is held to its box again and wraps
242
+ * as before. Only the system's bars may widen the grid: a line spanning
243
+ * it (text, a note, a directive, an unreadable row in the section or among
244
+ * a system's parts) is held to the chart's box, margin and all, as the grid
245
+ * held it, so it wraps where it did. The scrolling chart is positioned, so
246
+ * it holds the spoken spans placed absolutely outside any bar (a repeat
247
+ * count's, an unreadable row's) and they no longer widen the page. On
248
+ * screen only: a printed chart is drawn as it was. Appended after the "row"
249
+ * rules, selecting with `:has()`, so no chart's markup changes and a chart
250
+ * without systems is styled byte for byte as before.
251
+ */
252
+ const HAS_SYSTEM = ":has(>.bm-system)";
253
+ const WRAPS = '.bm-chart:not([data-wrap="off"])';
254
+ const SPANS = `${WRAPS} .bm-grid${HAS_SYSTEM}>`;
255
+ const systemFitCss = `
256
+ @media screen{
257
+ ${WRAPS}:has(.bm-system){overflow-x:auto;position:relative}
258
+ .bm-grid${HAS_SYSTEM}{max-width:none}
259
+ ${WRAPS} .bm-grid${HAS_SYSTEM} .bm-error{max-width:100cqi}
260
+ ${SPANS}.bm-text{max-width:calc(100cqi - ${at(SIZES.text, GUTTER)})}
261
+ ${SPANS}.bm-directive{max-width:calc(100cqi - ${at(SIZES.directive, GUTTER)})}
262
+ ${WRAPS}[data-bar-numbers="off"] .bm-grid${HAS_SYSTEM}>:is(.bm-text,.bm-directive){max-width:100cqi}
263
+ ${FIT_STEPS.map((w) => `@container bm (max-width:${w}em){${WRAPS} .bm-grid[data-fit="${w}"]${HAS_SYSTEM}{max-width:100%}}`).join("\n")}
264
+ }
265
+ `;
266
+ /** The system rules, at the stylesheet's very end. */
267
+ export const SYSTEM_FIT_CSS = minify(systemFitCss);
233
268
  /**
234
269
  * `barNumbers: "played"`: the gutter is a track that grows to its numbers
235
270
  * (`1 · 5 · 9`, `~101 … ~137`), on one line, and at least as wide as the
@@ -309,4 +344,4 @@ const diagramsCss = `
309
344
  `;
310
345
  /** 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. */
311
346
  export const DIAGRAMS_CSS = minify(diagramsCss);
312
- export const stylesheet = minify(css) + DIAGRAMS_CSS + ROW_COLUMNS_CSS;
347
+ export const stylesheet = minify(css) + DIAGRAMS_CSS + ROW_COLUMNS_CSS + SYSTEM_FIT_CSS;
package/dist/types.d.ts CHANGED
@@ -18,7 +18,7 @@ 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. */
21
+ /** `"played"`: give each row and bar its played numbers (`playedNumbers`); `barNumber` stays as it is. */
22
22
  barNumbers?: boolean | "played";
23
23
  };
24
24
  /**
@@ -90,7 +90,12 @@ export type RowItem = Extract<BlockItem, {
90
90
  export type BlockItem = {
91
91
  kind: "row";
92
92
  line: number;
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. */
93
+ /**
94
+ * The number of the row's first bar on the page: its written number
95
+ * (`PlayedBar.written`), counted on past each replay drawn above it, so
96
+ * a replay's rows go on from the count (the heading's `pageShift`,
97
+ * barmark's grammar A.7). Null for a row with no bar, or none a pass plays.
98
+ */
94
99
  barNumber: number | null;
95
100
  /** 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
101
  playedNumbers?: PlayedNumber[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barmark/render",
3
- "version": "0.22.3",
3
+ "version": "0.23.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": {
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@barmark/fretboard": ">=0.1.0 <1.0.0",
51
- "barmark": ">=0.26.0 <1.0.0"
51
+ "barmark": ">=0.27.0 <1.0.0"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "rm -rf dist && tsc -p tsconfig.build.json",