@barmark/render 0.15.1 → 0.16.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,37 @@ package uses [semantic versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.16.1] - 2026-11-07
10
+
11
+ ### Changed
12
+
13
+ - **Requires `barmark` 0.18.0**, whose minor release a caret range
14
+ would not reach. No renderer change.
15
+
16
+ ## [0.16.0] - 2026-11-07
17
+
18
+ Chord typesetting for drawers other than HTML, a section's bar count,
19
+ and layout in linear time. Needs `barmark` 0.17.0.
20
+
21
+ ### Added
22
+
23
+ - **Chord typesetting for other drawers** (issue #151): `typesetChord`,
24
+ `glyphs`, `typesetNumeral`, `NUMERALS` and the `ChordPieces` type are
25
+ exported, so a PDF or canvas drawer sets a chord as the page does (root
26
+ and quality on the baseline, the extension raised, the bass after a
27
+ slash, ♯ and ♭ glyphs) without copying the rules.
28
+ - **`SectionBlock.bars`:** the most bars any row of the block has, beside
29
+ `columns`, which also counts fermata, direction and rehearsal cells. A
30
+ drawer that gives those narrow cells their own width divides the row by
31
+ `bars`.
32
+
33
+ ### Fixed
34
+
35
+ - **Long charts lay out in linear time.** Each bar line still read every
36
+ played bar of the chart to find its own, three times over; a chart's
37
+ bars are now indexed by line once. A 2,000-system lead sheet with a
38
+ guitar and a verse 2 row lays out in about a third of the time.
39
+
9
40
  ## [0.15.1] - 2026-11-07
10
41
 
11
42
  ### Fixed
@@ -384,7 +415,9 @@ that needs no script or as the `<barmark-chart>` web component. Requires
384
415
  zoom without sideways scrolling, the element renders and re-renders, and
385
416
  a screen reader hears "bar 9: D". Run them with `bun run test:browser`.
386
417
 
387
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.15.1...HEAD
418
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.16.1...HEAD
419
+ [0.16.1]: https://github.com/kevinpeckham/barmark/compare/render-v0.16.0...render-v0.16.1
420
+ [0.16.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.15.1...render-v0.16.0
388
421
  [0.15.1]: https://github.com/kevinpeckham/barmark/compare/render-v0.15.0...render-v0.15.1
389
422
  [0.15.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.14.0...render-v0.15.0
390
423
  [0.14.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.13.0...render-v0.14.0
package/README.md CHANGED
@@ -188,7 +188,13 @@ numbers count the bars as written, each once, as a band counts them: a
188
188
  repeat, an ending, a jump or a replay doesn't move them, so a replayed
189
189
  section shows the numbers it was written with. A line with an error shows as written, underlined,
190
190
  with its message. `layoutChart(text)` returns all of this as data, if
191
- you want to draw it yourself.
191
+ you want to draw it yourself, and `typesetChord(parts)` with `glyphs`
192
+ gives a chord's pieces as the page sets them (root and quality, the
193
+ raised extension, the bass after a slash, ♯ and ♭), and
194
+ `typesetNumeral(parts, key, style)` its Nashville or Roman numeral, so a
195
+ PDF or canvas drawer matches it. A section block's `bars` counts its
196
+ widest row's bars (0 when it has none), where `columns` also counts its
197
+ fermata, direction and rehearsal cells.
192
198
 
193
199
  A chart of several parts (barmark's grammar 7.4) draws each system as
194
200
  stacked rows, one per part in score order, with the part's label in the
package/dist/chord.d.ts CHANGED
@@ -10,6 +10,7 @@ export type ChordPieces = {
10
10
  };
11
11
  /** `F#` → `F♯`, `b9` → `♭9`, `Bbb` → `B𝄫`. */
12
12
  export declare function glyphs(text: string): string;
13
+ /** A chord as the page sets it: root and quality on the baseline, extension, sus and added tones raised, the bass after the slash, accidentals as glyphs. */
13
14
  export declare function typesetChord(parts: ChordParts): ChordPieces;
14
15
  /** How chords read in a key: Nashville numbers (6m⁷) or Roman numerals (vi⁷). */
15
16
  export type Numerals = "nashville" | "roman";
package/dist/chord.js CHANGED
@@ -10,6 +10,7 @@ const ACCIDENTALS = [
10
10
  export function glyphs(text) {
11
11
  return ACCIDENTALS.reduce((t, [re, g]) => t.replace(re, g), text);
12
12
  }
13
+ /** A chord as the page sets it: root and quality on the baseline, extension, sus and added tones raised, the bass after the slash, accidentals as glyphs. */
13
14
  export function typesetChord(parts) {
14
15
  const tones = parts.tones.length ? `(${parts.tones.join(",")})` : "";
15
16
  return {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { Numerals } from "./chord.js";
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
4
  export { type RenderOptions, renderChart, renderChartUnwrapped } from "./html.js";
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { glyphs, NUMERALS, typesetChord, typesetNumeral, } from "./chord.js";
1
2
  export { creditsText } from "./credits.js";
2
3
  export { FONT_FAMILY, fontFaceCss } from "./font.js";
3
4
  export { renderChart, renderChartUnwrapped } from "./html.js";
package/dist/model.js CHANGED
@@ -13,6 +13,18 @@ const playedApart = (b, line) => {
13
13
  };
14
14
  /** What each line written plays in a bar: each part's share, or each of its lines' (barmark's grammar 7.4, 7.6). */
15
15
  const sharesOf = (b) => b.lines ?? (b.parts ?? []).flatMap((p) => p?.lines ?? [p]);
16
+ /** Played bars grouped by their line, in play order: each line then finds its own without reading every bar. */
17
+ function indexByLine(bars) {
18
+ const out = new Map();
19
+ for (const b of bars) {
20
+ const list = out.get(b.line);
21
+ if (list)
22
+ list.push(b);
23
+ else
24
+ out.set(b.line, [b]);
25
+ }
26
+ return out;
27
+ }
16
28
  /** Each part's bars on its own lines, and each line's; a tutti bar once (barmark's grammar 7.4, 7.6). */
17
29
  function barsByLine(parse) {
18
30
  if (parse.parts.length < 2 && !parse.parts.some((p) => p.lines))
@@ -54,7 +66,7 @@ export function layoutChart(text, options = {}) {
54
66
  source: text.split(/\r?\n/),
55
67
  errors: errorsByLine(parse),
56
68
  written: new Map(groups.flatMap((g) => (g.heading ? [[g.heading.line, g]] : []))),
57
- bars: barsByLine(parse),
69
+ bars: indexByLine(barsByLine(parse)),
58
70
  };
59
71
  const blocks = groups.map((g) => layoutGroup(g, ctx));
60
72
  if (options.rehearsalLetters)
@@ -196,6 +208,13 @@ const widthOf = (i) => i.kind === "row"
196
208
  : i.kind === "system"
197
209
  ? Math.max(0, ...i.rows.map((p) => (p.row.kind === "row" ? p.row.cells.length : 0)))
198
210
  : 0;
211
+ /** How many bars an item's widest row has: its `slots` cells, not its fermatas, directions or rehearsal marks. */
212
+ const barsIn = (cells) => cells.filter((c) => c.kind === "slots").length;
213
+ const barsOf = (i) => i.kind === "row"
214
+ ? barsIn(i.cells)
215
+ : i.kind === "system"
216
+ ? Math.max(0, ...i.rows.map((p) => (p.row.kind === "row" ? barsIn(p.row.cells) : 0)))
217
+ : 0;
199
218
  function blockOf(h, occurrence, items) {
200
219
  return {
201
220
  heading: h?.name ?? null,
@@ -203,6 +222,7 @@ function blockOf(h, occurrence, items) {
203
222
  form: occurrence?.form ?? null,
204
223
  rehearsal: null,
205
224
  columns: Math.max(0, ...items.map(widthOf)),
225
+ bars: Math.max(0, ...items.map(barsOf)),
206
226
  items,
207
227
  };
208
228
  }
@@ -246,7 +266,7 @@ function layoutOne(l, occurrence, previous, ctx) {
246
266
  }
247
267
  /** The written bars a bar line draws, as played in the occurrence: a cut bar as written. */
248
268
  function landingsOn(l, played, ctx) {
249
- const written = ctx.bars.filter((b) => b.line === l.line);
269
+ const written = barsOn(l.line, ctx);
250
270
  let bar = 0;
251
271
  const bars = l.cells.map((cell) => {
252
272
  if (cell.kind !== "slots" && cell.kind !== "simile")
@@ -266,7 +286,7 @@ function lyricRows(lines, occurrence, ctx) {
266
286
  if (!ref)
267
287
  return [];
268
288
  const sung = new Set(drawn.flatMap((l) => singerOf(l, ctx.parse) ?? []));
269
- const lands = landingsOn(ref, playedOn(ref.line, occurrence, ctx.bars), ctx);
289
+ const lands = landingsOn(ref, playedOn(ref.line, occurrence, ctx), ctx);
270
290
  return rowVerses(lands, sung);
271
291
  }
272
292
  const systemOf = (l) => (l?.kind === "bars" || l?.kind === "invalid") && l.system !== undefined ? l.system : null;
@@ -299,12 +319,10 @@ const labelOf = (l) => `${l.part ?? ""}${l.lineName === undefined ? "" : `.${l.l
299
319
  /** A row per declared part, or per line it writes, in score order: its own line, its error, or tacet bars. */
300
320
  function layoutSystem(lines, occurrence, previous, ctx) {
301
321
  const ref = lines.find((l) => l.kind === "bars" && !ctx.errors.has(l.line));
302
- const reference = ref
303
- ? layoutRow(ref, playedOn(ref.line, occurrence, ctx.bars), previous, ctx)
304
- : null;
322
+ const reference = ref ? layoutRow(ref, playedOn(ref.line, occurrence, ctx), previous, ctx) : null;
305
323
  const ownRow = (own) => ctx.errors.has(own.line) || own.kind !== "bars"
306
324
  ? errorItem(own.line, ctx)
307
- : layoutRow(own, playedOn(own.line, occurrence, ctx.bars), previous, ctx);
325
+ : layoutRow(own, playedOn(own.line, occurrence, ctx), previous, ctx);
308
326
  const rows = ctx.parse.parts.flatMap((p) => {
309
327
  const own = ownLines(lines, p);
310
328
  if (!own.length)
@@ -339,7 +357,7 @@ function tacetRow(reference, line) {
339
357
  function layoutLine(l, occurrence, previous, ctx) {
340
358
  switch (l.kind) {
341
359
  case "bars":
342
- return layoutRow(l, playedOn(l.line, occurrence, ctx.bars), previous, ctx);
360
+ return layoutRow(l, playedOn(l.line, occurrence, ctx), previous, ctx);
343
361
  case "text":
344
362
  return textItem(l.text);
345
363
  case "directive":
@@ -365,16 +383,18 @@ function errorItem(line, ctx) {
365
383
  };
366
384
  }
367
385
  const lastSlots = (cells) => cells.findLast((c) => c.kind === "slots") ?? null;
386
+ /** Every bar a line plays, in play order. */
387
+ const barsOn = (line, ctx) => ctx.bars.get(line) ?? [];
368
388
  /** The bars a line plays within its section occurrence, in play order. */
369
- function playedOn(line, occurrence, bars) {
389
+ function playedOn(line, occurrence, ctx) {
370
390
  const first = occurrence?.firstBar ?? 1;
371
391
  const last = occurrence?.lastBar ?? Number.POSITIVE_INFINITY;
372
- return bars.filter((b) => b.line === line && b.index >= first && b.index <= last);
392
+ return barsOn(line, ctx).filter((b) => b.index >= first && b.index <= last);
373
393
  }
374
394
  function layoutRow(l, played, previous, ctx) {
375
395
  const cells = [];
376
396
  // A cut bar is not played: what it would play is what the line's bar played when written.
377
- const written = ctx.bars.filter((b) => b.line === l.line);
397
+ const written = barsOn(l.line, ctx);
378
398
  let bar = 0;
379
399
  let prev = previous;
380
400
  for (const cell of l.cells) {
package/dist/types.d.ts CHANGED
@@ -26,8 +26,10 @@ export type SectionBlock = {
26
26
  form: number | null;
27
27
  /** "A", "B", … when rehearsal letters are on. */
28
28
  rehearsal: string | null;
29
- /** The widest row's cell count. */
29
+ /** The widest row's cell count: fermata, direction and rehearsal cells included. */
30
30
  columns: number;
31
+ /** The most bars any row has: its `slots` cells alone, for a drawer that gives the narrow cells their own width. 0 when no row has a bar. */
32
+ bars: number;
31
33
  items: BlockItem[];
32
34
  };
33
35
  export type RowItem = Extract<BlockItem, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barmark/render",
3
- "version": "0.15.1",
3
+ "version": "0.16.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,7 +47,7 @@
47
47
  "url": "https://github.com/kevinpeckham/barmark/issues"
48
48
  },
49
49
  "dependencies": {
50
- "barmark": "^0.17.0"
50
+ "barmark": "^0.18.0"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "rm -rf dist && tsc -p tsconfig.build.json",