@barmark/render 0.13.0 → 0.14.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,25 @@ package uses [semantic versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.14.0] - 2026-11-04
10
+
11
+ Needs `barmark` 0.16.0.
12
+
13
+ ### Added
14
+
15
+ - **Part lines** (barmark's grammar 7.6): a system draws a row per line a
16
+ part writes, labelled `Pno.RH`, `Pno.LH`, in score order; a part with no
17
+ line there keeps its tacet row, and `part: "Pno"` draws both hands. The
18
+ label column is as wide as the widest line label. A screen reader
19
+ hears each row as its part and line: "Piano RH". `parts` in the model
20
+ are barmark's `DeclaredPart`, with `lines`.
21
+ - **Pedal marks** (grammar 2.9): "Ped." under a press and "✱" under a
22
+ release, the slot marked `data-pedal`; a bar with one makes room below.
23
+ Spoken as "pedal G" and "pedal up C".
24
+ - **Dotted figures** (grammar 2.2): a dotted group draws no tuplet number
25
+ and puts a dot after its dotted member (`data-dotted` on the group);
26
+ spoken "C dotted, D".
27
+
9
28
  ## [0.13.0] - 2026-11-04
10
29
 
11
30
  Needs `barmark` 0.15.0.
@@ -330,7 +349,8 @@ that needs no script or as the `<barmark-chart>` web component. Requires
330
349
  zoom without sideways scrolling, the element renders and re-renders, and
331
350
  a screen reader hears "bar 9: D". Run them with `bun run test:browser`.
332
351
 
333
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.13.0...HEAD
352
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.14.0...HEAD
353
+ [0.14.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.13.0...render-v0.14.0
334
354
  [0.13.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.12.0...render-v0.13.0
335
355
  [0.12.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.11.0...render-v0.12.0
336
356
  [0.11.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.10.0...render-v0.11.0
package/dist/html.js CHANGED
@@ -44,17 +44,24 @@ function chartHtml(text, options) {
44
44
  ...(options.part && { part: options.part }),
45
45
  });
46
46
  const barNumbers = options.barNumbers ?? true;
47
- const parts = model.parts.length > 1;
47
+ const parts = labelled(model);
48
48
  const settings = {
49
49
  barNumbers,
50
50
  gutter: barNumbers || parts,
51
51
  numerals: numeralsOf(options),
52
52
  };
53
53
  // Every section's left column is as wide as the longest part label, so tutti rows line up with systems.
54
- const widest = Math.max(0, ...model.parts.map((p) => p.label?.length ?? 0));
54
+ const widest = Math.max(0, ...model.parts.flatMap(rowLabelsOf).map((l) => l.length));
55
55
  const gutter = parts ? ` data-parts style="--bm-label-chars:${widest}"` : "";
56
56
  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>`;
57
57
  }
58
+ /** Whether systems have labelled rows: several parts, or one part writing lines (barmark's grammar 7.6). */
59
+ const labelled = (model) => model.parts.length > 1 || model.parts.some((p) => (p.lines?.length ?? 0) > 0);
60
+ /** A part's row labels: its own, and one per line it writes (barmark's grammar 7.6). */
61
+ const rowLabelsOf = (p) => [
62
+ p.label ?? "",
63
+ ...(p.lines ?? []).map((n) => `${p.label ?? ""}.${n}`),
64
+ ];
58
65
  function headerHtml(model) {
59
66
  const title = model.title
60
67
  ? `<h2 class="bm-title" part="title">${escapeHtml(model.title)}</h2>`
@@ -330,21 +337,43 @@ const FERMATA = `<svg class="bm-fermata-glyph" viewBox="0 0 24 14" width="1.4em"
330
337
  /** `‹` for an eighth push, `«` for a sixteenth. */
331
338
  const PUSH_MARK = { eighth: "‹", sixteenth: "«" };
332
339
  const ARTICULATION_MARK = { accent: ">", hit: "^" };
340
+ /** The piano score's marks: Ped. under a press, ✱ under a release (barmark's grammar 2.9). */
341
+ const PEDAL_MARK = { press: "Ped.", release: "✱" };
333
342
  const marksOf = (slot) => ({
334
343
  push: "push" in slot ? (slot.push ?? null) : null,
335
344
  articulation: slot.kind === "chord" ? (slot.articulation ?? null) : null,
345
+ pedal: slot.kind === "chord" ? (slot.pedal ?? null) : null,
336
346
  });
337
- /** A slot with its push mark before it and its accent or hit above it. */
347
+ const dataOf = (marks) => Object.entries(marks)
348
+ .map(([k, v]) => (v ? ` data-${k}="${v}"` : ""))
349
+ .join("");
350
+ /** A slot with its push mark before it, its accent or hit above it and its pedal mark below. */
338
351
  function slotHtml(slot, view) {
339
352
  const body = unmarkedSlotHtml(slot, view);
340
- const { push, articulation } = marksOf(slot);
341
- if (!push && !articulation)
353
+ const marks = marksOf(slot);
354
+ const { push, articulation, pedal } = marks;
355
+ if (!push && !articulation && !pedal)
342
356
  return body;
343
- const data = `${push ? ` data-push="${push}"` : ""}${articulation ? ` data-articulation="${articulation}"` : ""}`;
357
+ const before = push ? `<span class="bm-push" aria-hidden="true">${PUSH_MARK[push]}</span>` : "";
344
358
  const above = articulation
345
359
  ? `<span class="bm-artic">${ARTICULATION_MARK[articulation]}</span>`
346
360
  : "";
347
- return `<span class="bm-marked"${data}>${push ? `<span class="bm-push" aria-hidden="true">${PUSH_MARK[push]}</span>` : ""}${above}${body}</span>`;
361
+ const below = pedal
362
+ ? `<span class="bm-pedal" aria-hidden="true">${PEDAL_MARK[pedal]}</span>`
363
+ : "";
364
+ return `<span class="bm-marked"${dataOf(marks)}>${before}${above}${body}${below}</span>`;
365
+ }
366
+ /** A group: a tuplet number over equal members, or a dotted figure with its dot (barmark's grammar 2.2). */
367
+ function groupHtml(members, view) {
368
+ const dotted = members.some((m) => m.dotted);
369
+ const inner = members
370
+ .map((m) => m.dotted
371
+ ? `<span class="bm-dotted">${slotHtml(m, view)}<span class="bm-dot" aria-hidden="true">.</span></span>`
372
+ : slotHtml(m, view))
373
+ .join("");
374
+ if (dotted)
375
+ return `<span class="bm-group" data-count="${members.length}" data-dotted>${inner}</span>`;
376
+ return `<span class="bm-group" data-count="${members.length}"><span class="bm-tuplet">${members.length}</span>${inner}</span>`;
348
377
  }
349
378
  function unmarkedSlotHtml(slot, view) {
350
379
  switch (slot.kind) {
@@ -359,7 +388,7 @@ function unmarkedSlotHtml(slot, view) {
359
388
  case "unknown":
360
389
  return `<span class="bm-unknown">?</span>`;
361
390
  case "group":
362
- return `<span class="bm-group" data-count="${slot.members.length}"><span class="bm-tuplet">${slot.members.length}</span>${slot.members.map((m) => slotHtml(m, view)).join("")}</span>`;
391
+ return groupHtml(slot.members, view);
363
392
  }
364
393
  }
365
394
  function chordHtml(record, view) {
package/dist/model.js CHANGED
@@ -10,17 +10,19 @@ const playedApart = (b, line) => {
10
10
  const own = (b.parts ?? []).filter((p) => p?.line === line).map((p) => JSON.stringify(p?.slots));
11
11
  return new Set(own).size > 1;
12
12
  };
13
- /** Each part's bars on its own lines; a tutti bar once (barmark's grammar 7.4). */
13
+ /** What each line written plays in a bar: each part's share, or each of its lines' (barmark's grammar 7.4, 7.6). */
14
+ const sharesOf = (b) => b.lines ?? (b.parts ?? []).flatMap((p) => p?.lines ?? [p]);
15
+ /** Each part's bars on its own lines, and each line's; a tutti bar once (barmark's grammar 7.4, 7.6). */
14
16
  function barsByLine(parse) {
15
- if (parse.parts.length < 2)
17
+ if (parse.parts.length < 2 && !parse.parts.some((p) => p.lines))
16
18
  return parse.bars;
17
19
  const seen = new Set();
18
- return parse.bars.flatMap((b) => (b.parts ?? []).flatMap((p) => {
20
+ return parse.bars.flatMap((b) => sharesOf(b).flatMap((p) => {
19
21
  const key = `${b.index}:${p?.line}`;
20
22
  if (!p || seen.has(key))
21
23
  return [];
22
24
  seen.add(key);
23
- const { words: _w, parts: _p, tacet: _t, ...shared } = b;
25
+ const { words: _w, parts: _p, tacet: _t, lines: _l, ...shared } = b;
24
26
  const apart = playedApart(b, p.line) ? { perPart: true } : {};
25
27
  return [
26
28
  { ...shared, ...apart, line: p.line, slots: p.slots, ...(p.words && { words: p.words }) },
@@ -248,20 +250,31 @@ const lastOfSystem = (item) => {
248
250
  };
249
251
  /** A bar where the part rests, in a system or a part's own view (barmark's grammar 7.4). */
250
252
  export const isTacet = (c) => c.kind === "slots" && c.tacet === true;
251
- /** A row per declared part, in score order: its own line, its error, or tacet bars. */
253
+ /** A part's lines in a system, in score order: its bare line, then its lines (barmark's grammar 7.6). */
254
+ function ownLines(lines, p) {
255
+ const order = (l) => l.lineName === undefined ? -1 : (p.lines ?? []).indexOf(l.lineName);
256
+ return lines.filter((l) => l.part === p.label).sort((a, b) => order(a) - order(b));
257
+ }
258
+ /** A row's spoken name: the part's, and its line's (barmark's grammar 7.6): "Piano RH". */
259
+ const spokenOf = (p, l) => l.lineName === undefined ? p.name : `${p.name} ${l.lineName}`;
260
+ /** A system row's label: the part's, and its line's name (`Pno.RH`). */
261
+ const labelOf = (l) => `${l.part ?? ""}${l.lineName === undefined ? "" : `.${l.lineName}`}`;
262
+ /** A row per declared part, or per line it writes, in score order: its own line, its error, or tacet bars. */
252
263
  function layoutSystem(lines, occurrence, previous, ctx) {
253
264
  const ref = lines.find((l) => l.kind === "bars" && !ctx.errors.has(l.line));
254
265
  const reference = ref
255
266
  ? layoutRow(ref, playedOn(ref.line, occurrence, ctx.bars), previous, ctx)
256
267
  : null;
257
- const rows = ctx.parse.parts.map((p) => {
258
- const own = lines.find((l) => l.part === p.label);
259
- const row = own && ctx.errors.has(own.line)
260
- ? errorItem(own.line, ctx)
261
- : own?.kind === "bars"
262
- ? layoutRow(own, playedOn(own.line, occurrence, ctx.bars), previous, ctx)
263
- : tacetRow(reference, lines[0]?.line ?? 0);
264
- return { label: p.label ?? "", name: p.name, row };
268
+ const ownRow = (own) => ctx.errors.has(own.line) || own.kind !== "bars"
269
+ ? errorItem(own.line, ctx)
270
+ : layoutRow(own, playedOn(own.line, occurrence, ctx.bars), previous, ctx);
271
+ const rows = ctx.parse.parts.flatMap((p) => {
272
+ const own = ownLines(lines, p);
273
+ if (!own.length)
274
+ return [
275
+ { label: p.label ?? "", name: p.name, row: tacetRow(reference, lines[0]?.line ?? 0) },
276
+ ];
277
+ return own.map((l) => ({ label: labelOf(l), name: spokenOf(p, l), row: ownRow(l) }));
265
278
  });
266
279
  return {
267
280
  kind: "system",
package/dist/speech.js CHANGED
@@ -114,9 +114,19 @@ function speakChordSlot(slot, key) {
114
114
  return `accented ${voiced}`;
115
115
  return slot.articulation === "hit" ? `${voiced} short hit` : voiced;
116
116
  }
117
+ const PEDALLED = { press: "pedal", release: "pedal up" };
117
118
  export function speakSlot(slot, key) {
118
- const said = speakUnpushed(slot, key);
119
- return "push" in slot && slot.push ? `${said} ${PUSHED[slot.push]}` : said;
119
+ const unpushed = speakUnpushed(slot, key);
120
+ const said = "push" in slot && slot.push ? `${unpushed} ${PUSHED[slot.push]}` : unpushed;
121
+ const dotted = "dotted" in slot && slot.dotted ? `${said} dotted` : said;
122
+ return slot.kind === "chord" && slot.pedal ? `${PEDALLED[slot.pedal]} ${dotted}` : dotted;
123
+ }
124
+ /** "triplet: C, D, E"; a dotted figure is its members: "C dotted, D". */
125
+ function speakGroup(members, key) {
126
+ const said = members.map((m) => speakSlot(m, key)).join(", ");
127
+ if (members.some((m) => m.dotted))
128
+ return said;
129
+ return `${GROUPS[members.length] ?? `group of ${members.length}`}: ${said}`;
120
130
  }
121
131
  function speakUnpushed(slot, key) {
122
132
  switch (slot.kind) {
@@ -131,7 +141,7 @@ function speakUnpushed(slot, key) {
131
141
  case "unknown":
132
142
  return "unknown chord";
133
143
  case "group":
134
- return `${GROUPS[slot.members.length] ?? `group of ${slot.members.length}`}: ${slot.members.map((m) => speakSlot(m, key)).join(", ")}`;
144
+ return speakGroup(slot.members, key);
135
145
  }
136
146
  }
137
147
  /** "segno", "to coda", "dal segno al coda", "da capo al fine". */
package/dist/styles.js CHANGED
@@ -136,6 +136,10 @@ const css = `
136
136
  .bm-push{font:700 .8em/1 system-ui,sans-serif;color:var(--bm-muted);margin-right:.08em}
137
137
  .bm-artic{position:absolute;left:50%;top:-.95em;transform:translateX(-50%);font:700 .7em/1 system-ui,sans-serif;color:var(--bm-ink)}
138
138
  .bm-marked[data-push]>.bm-artic{left:calc(50% + .25em)}
139
+ .bm-pedal{position:absolute;left:0;bottom:-1.05em;font:italic 600 .62em/1 Georgia,serif;color:var(--bm-muted);white-space:nowrap}
140
+ .bm-dotted{display:inline-flex;align-items:baseline}
141
+ .bm-dot{font-weight:700;margin-left:.05em}
142
+ .bm-bar:has(.bm-pedal){padding-bottom:1.05em}
139
143
  .bm-words{position:absolute;left:0;top:-1.05em;font:italic .62em/1 Georgia,serif;color:var(--bm-muted);white-space:nowrap}
140
144
  .bm-bar>.bm-words-end{left:auto;right:.5em;top:.15em}
141
145
  .bm-bar[data-ending]::after{content:attr(data-ending);position:absolute;left:.45em;top:.2em;font:italic .75em/1 Georgia,serif;color:var(--bm-muted)}
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ChartDiagnostic, Credits, Direction, Directives, Key, Meter, Part, Repeat, Slot, Words } from "barmark";
1
+ import type { ChartDiagnostic, Credits, DeclaredPart, Direction, Directives, Key, Meter, Repeat, Slot, 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
4
  rehearsalLetters?: boolean;
@@ -8,9 +8,9 @@ export type LayoutOptions = {
8
8
  export type ChartModel = {
9
9
  title: string | null;
10
10
  /** What `part:` names in a single-part chart; null when the chart names none or several. */
11
- part: Part | null;
12
- /** Every declared part, in score order (barmark's grammar 7.4). */
13
- parts: Part[];
11
+ part: DeclaredPart | null;
12
+ /** Every declared part, in score order (barmark's grammar 7.4), with its lines (7.6). */
13
+ parts: DeclaredPart[];
14
14
  /** The chart's credit lines (barmark's grammar 7.5). */
15
15
  credits: Credits;
16
16
  /** Directives before the first heading, bar line or text line. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barmark/render",
3
- "version": "0.13.0",
3
+ "version": "0.14.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.15.0"
50
+ "barmark": "^0.16.0"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "rm -rf dist && tsc -p tsconfig.build.json",