@barmark/render 0.23.2 → 0.24.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 +19 -1
- package/README.md +54 -3
- package/dist/element.d.ts +7 -0
- package/dist/element.js +65 -1
- package/dist/html.d.ts +7 -0
- package/dist/html.js +86 -11
- package/dist/speech.d.ts +6 -0
- package/dist/speech.js +10 -0
- package/dist/styles.d.ts +2 -0
- package/dist/styles.js +38 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,23 @@ package uses [semantic versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.24.0] - 2026-12-02
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **Chord notes** (`chordNotes: true`, `chord-notes` on the element), off by
|
|
14
|
+
default: a chord symbol's notes, as the parser spells them
|
|
15
|
+
(`ChordRecord.pitches`), in a small label under the chord while it is
|
|
16
|
+
pointed at; and while a bar that holds a chord symbol has focus (Tab, or
|
|
17
|
+
a tap), every chord there with its notes in a box under the bar. Each such
|
|
18
|
+
bar is one tab stop, a group described by its chords' notes in words
|
|
19
|
+
("C seven: C, E, G, B flat"). No script is needed but for Escape, which
|
|
20
|
+
hides them in `<barmark-chart>` and leaves focus where it is. Never
|
|
21
|
+
printed; styled through `::part(chord-notes)`. With it off, every chart's
|
|
22
|
+
markup is as before and the element listens for nothing new: its rules
|
|
23
|
+
join the stylesheet's end. A bar that has focus keeps it when the element
|
|
24
|
+
draws the chart again (a new theme, say).
|
|
25
|
+
|
|
9
26
|
## [0.23.2] - 2026-12-02
|
|
10
27
|
|
|
11
28
|
### Changed
|
|
@@ -732,7 +749,8 @@ that needs no script or as the `<barmark-chart>` web component. Requires
|
|
|
732
749
|
zoom without sideways scrolling, the element renders and re-renders, and
|
|
733
750
|
a screen reader hears "bar 9: D". Run them with `bun run test:browser`.
|
|
734
751
|
|
|
735
|
-
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.
|
|
752
|
+
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/render-v0.24.0...HEAD
|
|
753
|
+
[0.24.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.23.2...render-v0.24.0
|
|
736
754
|
[0.23.2]: https://github.com/kevinpeckham/barmark/compare/render-v0.23.1...render-v0.23.2
|
|
737
755
|
[0.23.1]: https://github.com/kevinpeckham/barmark/compare/render-v0.23.0...render-v0.23.1
|
|
738
756
|
[0.23.0]: https://github.com/kevinpeckham/barmark/compare/render-v0.22.3...render-v0.23.0
|
package/README.md
CHANGED
|
@@ -57,8 +57,9 @@ server by `renderChart` keeps its music until it has a source of its own,
|
|
|
57
57
|
and still follows `theme`, `bar-numbers`, `wrap` and `columns` (its bar
|
|
58
58
|
numbers hide and show again, but stay written or played as they were
|
|
59
59
|
drawn: changing between the two needs the chart's text); a change to
|
|
60
|
-
`numerals`, `rehearsal-letters`, `melody`, `show-part`, `chord-diagrams
|
|
61
|
-
`diagram-hand` needs the chart's text, so it waits for a
|
|
60
|
+
`numerals`, `rehearsal-letters`, `melody`, `show-part`, `chord-diagrams`,
|
|
61
|
+
`diagram-hand` or `chord-notes` needs the chart's text, so it waits for a
|
|
62
|
+
source.
|
|
62
63
|
|
|
63
64
|
For a live editor, set `text`:
|
|
64
65
|
|
|
@@ -92,6 +93,7 @@ the element loads, with `<style data-barmark-font>` holding
|
|
|
92
93
|
| `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 |
|
|
93
94
|
| `chordDiagrams` | `chord-diagrams="guitar"` (`chordDiagrams`) | none | `"guitar"`: a strip of guitar chord diagrams after the header, one for each distinct chord (below). Any other value is off |
|
|
94
95
|
| `diagramHand` | `diagram-hand="left"` (`diagramHand`) | `"right"` | `"left"` mirrors the diagrams for a left hand: the low string on the right. Any other value is right |
|
|
96
|
+
| `chordNotes` | `chord-notes` (`chordNotes`) | `false` | show a chord symbol's notes when it is pointed at, or when its bar has focus or is tapped (below) |
|
|
95
97
|
| `diagnostics` | | `false` | list the chart's errors and warnings below it |
|
|
96
98
|
| `fontUrl` | | none | emit Edwin's `@font-face` rule before the chart |
|
|
97
99
|
| (the `text` argument) | (`text`) | `null` | the chart to draw; wins over `src` and the script child |
|
|
@@ -204,6 +206,41 @@ The strip adds about 6.6 KB gzipped to the element (most of it the shape
|
|
|
204
206
|
finder). On a chart rendered on the server, setting `chord-diagrams` later
|
|
205
207
|
needs the chart's text, as the web component section says for `numerals`.
|
|
206
208
|
|
|
209
|
+
### Chord notes
|
|
210
|
+
|
|
211
|
+
With `chordNotes: true` (`chord-notes` on the element), a reader can see
|
|
212
|
+
the notes of a chord symbol:
|
|
213
|
+
|
|
214
|
+
- **Pointing** at a chord shows its notes in a small label under it. The
|
|
215
|
+
label stays while the pointer is on the label itself.
|
|
216
|
+
- **The keyboard** reaches each bar that holds a chord symbol: it is one
|
|
217
|
+
tab stop, and while it has focus a box under the bar shows every chord
|
|
218
|
+
there with its notes, in order. Tab onward and they go.
|
|
219
|
+
- **A tap** on a bar focuses it, so it shows the same box; a tap elsewhere
|
|
220
|
+
hides it.
|
|
221
|
+
- **Escape** hides what is shown and leaves focus where it is, on
|
|
222
|
+
`<barmark-chart>` and `<barmark-score>` only: it takes their script, so
|
|
223
|
+
the static HTML from `renderChart` cannot do it. Everything else needs
|
|
224
|
+
no script.
|
|
225
|
+
|
|
226
|
+
The notes are the parser's reading of the symbol (`ChordRecord.pitches`),
|
|
227
|
+
as it spells and orders them: the root first, then the chord's tones, and
|
|
228
|
+
a slash chord's bass last when it is not one of them (C/E is C E G, C/B♭ is
|
|
229
|
+
C E G B♭). The renderer adds and reorders nothing, so C7alt shows its shell,
|
|
230
|
+
C E B♭, and C11 has no third, as the parser reads them. A transposed chart
|
|
231
|
+
(transpose it with `transposeChart` before rendering) shows the transposed
|
|
232
|
+
chord's notes; in a numeral view the notes are still the chord's real
|
|
233
|
+
notes. Holds, `%` drawn as its sign, N.C., stops, `?`, a slot that can't
|
|
234
|
+
be read and note sets (which show their notes already) have none; a bar of
|
|
235
|
+
only those is not a tab stop. Labels are never printed. Style them through
|
|
236
|
+
`::part(chord-notes)`. The feature adds about 1.2 KB gzipped to the element.
|
|
237
|
+
|
|
238
|
+
```js
|
|
239
|
+
renderChart("| C7 / F/A G |", { chordNotes: true });
|
|
240
|
+
// <barmark-chart chord-notes>… the bar: tabindex="0" role="group" aria-describedby="…"
|
|
241
|
+
// its description: "C seven: C, E, G, B flat; F over A: F, A, C; G: G, B, D"
|
|
242
|
+
```
|
|
243
|
+
|
|
207
244
|
### Spoken names
|
|
208
245
|
|
|
209
246
|
`speakChord(record, key?)` gives a chord the name a screen reader hears
|
|
@@ -250,7 +287,8 @@ barmark-chart::part(heading) {
|
|
|
250
287
|
```
|
|
251
288
|
|
|
252
289
|
`::part()` names: `title`, `meta`, `heading`, `bar`, `chord`, `text`,
|
|
253
|
-
`bar-number`, `rehearsal`, `diagrams`, `diagram`, `
|
|
290
|
+
`bar-number`, `rehearsal`, `diagrams`, `diagram`, `chord-notes` (a chord's
|
|
291
|
+
notes, and a focused bar's box of them), `lyrics` (each verse's line of words, inside
|
|
254
292
|
its `bar`), `unread` (a slot that can't be read, drawn as written). These, the custom properties and the
|
|
255
293
|
attributes are the public surface: changing them is a breaking change.
|
|
256
294
|
|
|
@@ -273,6 +311,19 @@ and Windows High Contrast keeps bar lines and marks visible.
|
|
|
273
311
|
of its own, since that would change its markup.
|
|
274
312
|
- Every bar has a spoken name built from the parsed chart: "bar 9: A seven
|
|
275
313
|
sus four, hold", "triplet: D, E, F sharp minor", "note E", "C over E".
|
|
314
|
+
- With `chordNotes` on, every bar that holds a chord symbol is a tab stop
|
|
315
|
+
of its own: a 60-bar chart has 60, and there is no way to skip past
|
|
316
|
+
them. With it off there are none. Each such bar is exposed as a group
|
|
317
|
+
with no name of its own (`role="group"`, `tabindex="0"`), described
|
|
318
|
+
(`aria-describedby`) by its chords' notes in words: "C seven: C, E, G, B
|
|
319
|
+
flat; F over A: F, A, C". The description's element is `hidden`, so it
|
|
320
|
+
is not in the reading order. The chart's text, its order and the bar's
|
|
321
|
+
spoken sentence are the same as with the option off, and the labels
|
|
322
|
+
drawn on screen are hidden from assistive technology, as the drawn
|
|
323
|
+
chords are. What a screen reader announces when a bar takes focus (the
|
|
324
|
+
group, its contents, the description) depends on the screen reader, and
|
|
325
|
+
this has not been checked with a real one. Escape dismisses the notes in
|
|
326
|
+
the elements (WCAG 1.4.13); the static HTML cannot.
|
|
276
327
|
Sections are labelled by their headings, and repeats are spoken ("play
|
|
277
328
|
2 times").
|
|
278
329
|
|
package/dist/element.d.ts
CHANGED
|
@@ -19,4 +19,11 @@ export declare function chartSource(from: {
|
|
|
19
19
|
}): ChartSource;
|
|
20
20
|
/** Chart text from a script element: blank edges and common indentation removed. */
|
|
21
21
|
export declare function inlineChartText(text: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Listens for chord notes only while the element has `chord-notes` and is in
|
|
24
|
+
* a document, so one without it behaves as if the feature did not exist.
|
|
25
|
+
* Takes what stops the current listening (null for none) and returns the new
|
|
26
|
+
* one. For `<barmark-chart>` and `@barmark/score`'s element.
|
|
27
|
+
*/
|
|
28
|
+
export declare function syncChordNotes(host: HTMLElement, stop: (() => void) | null): (() => void) | null;
|
|
22
29
|
export {};
|
package/dist/element.js
CHANGED
|
@@ -30,6 +30,7 @@ export function optionsFromAttributes(el) {
|
|
|
30
30
|
...(hand ? { diagramHand: hand } : {}),
|
|
31
31
|
// Only "row" changes the layout; anything else, or none, keeps the shared columns.
|
|
32
32
|
...(el.getAttribute("columns") === "row" ? { columns: "row" } : {}),
|
|
33
|
+
...(el.hasAttribute("chord-notes") ? { chordNotes: true } : {}),
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
/** What a chart draws: its `text` while that is a string, else `src`, else its script child. */
|
|
@@ -61,6 +62,51 @@ async function fetchText(src) {
|
|
|
61
62
|
throw new Error(`${response.status} ${response.statusText}`.trim());
|
|
62
63
|
return response.text();
|
|
63
64
|
}
|
|
65
|
+
/** The chord with notes an event reached inside the shadow root, or null. */
|
|
66
|
+
const notedIn = (target) => target?.closest?.(".bm-noted") ?? null;
|
|
67
|
+
/** Marks a chart quiet: its chord notes hidden, until focus moves or the pointer comes to another chord. */
|
|
68
|
+
const quiet = (host, on) => host.shadowRoot?.querySelector(".bm-chart")?.toggleAttribute("data-quiet", on);
|
|
69
|
+
/**
|
|
70
|
+
* Escape hides the chord notes shown (WCAG 1.4.13, dismissible) and moves
|
|
71
|
+
* nothing: the chart is quiet until focus moves, or the pointer comes to a
|
|
72
|
+
* chord it was not on. A focused bar's Escape reaches the host whatever
|
|
73
|
+
* shadow roots hold it; a pointed-at chord's reaches only the document, so
|
|
74
|
+
* that one asks whether the host is under the pointer. Returns what stops it all.
|
|
75
|
+
*/
|
|
76
|
+
function listenForNotes(host) {
|
|
77
|
+
const stop = new AbortController();
|
|
78
|
+
const on = { signal: stop.signal };
|
|
79
|
+
const onEscape = (focused) => (e) => {
|
|
80
|
+
if (e.key === "Escape" && (focused || host.matches(":hover")))
|
|
81
|
+
quiet(host, true);
|
|
82
|
+
};
|
|
83
|
+
host.addEventListener("keydown", onEscape(true), on);
|
|
84
|
+
host.ownerDocument.addEventListener("keydown", onEscape(false), on);
|
|
85
|
+
host.addEventListener("focusin", () => quiet(host, false), on);
|
|
86
|
+
// The chord last pointed at: moving within it keeps the notes hidden, coming to another (or back) shows them.
|
|
87
|
+
let last = null;
|
|
88
|
+
host.addEventListener("pointerover", (e) => {
|
|
89
|
+
const at = notedIn(e.composedPath()[0] ?? null);
|
|
90
|
+
if (at !== last && at)
|
|
91
|
+
quiet(host, false);
|
|
92
|
+
last = at;
|
|
93
|
+
}, on);
|
|
94
|
+
host.addEventListener("pointerleave", () => (last = null), on);
|
|
95
|
+
return () => stop.abort();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Listens for chord notes only while the element has `chord-notes` and is in
|
|
99
|
+
* a document, so one without it behaves as if the feature did not exist.
|
|
100
|
+
* Takes what stops the current listening (null for none) and returns the new
|
|
101
|
+
* one. For `<barmark-chart>` and `@barmark/score`'s element.
|
|
102
|
+
*/
|
|
103
|
+
export function syncChordNotes(host, stop) {
|
|
104
|
+
const wanted = host.isConnected && host.hasAttribute("chord-notes");
|
|
105
|
+
if (wanted === (stop !== null))
|
|
106
|
+
return stop;
|
|
107
|
+
stop?.();
|
|
108
|
+
return wanted ? listenForNotes(host) : null;
|
|
109
|
+
}
|
|
64
110
|
function defineElement() {
|
|
65
111
|
class BarmarkChart extends HTMLElement {
|
|
66
112
|
static observedAttributes = [
|
|
@@ -75,6 +121,7 @@ function defineElement() {
|
|
|
75
121
|
"columns",
|
|
76
122
|
"chord-diagrams",
|
|
77
123
|
"diagram-hand",
|
|
124
|
+
"chord-notes",
|
|
78
125
|
];
|
|
79
126
|
#observer = new MutationObserver(() => this.#schedule());
|
|
80
127
|
#renders = 0;
|
|
@@ -82,7 +129,9 @@ function defineElement() {
|
|
|
82
129
|
/** The text fetched for `src`, kept so a change of options does not fetch again. */
|
|
83
130
|
#fetched = null;
|
|
84
131
|
#text = null;
|
|
132
|
+
#notes = null;
|
|
85
133
|
connectedCallback() {
|
|
134
|
+
this.#notes = syncChordNotes(this, this.#notes);
|
|
86
135
|
// Text set before the element was defined landed on the instance: route it through the setter.
|
|
87
136
|
if (Object.hasOwn(this, "text")) {
|
|
88
137
|
const text = this.text ?? null;
|
|
@@ -95,8 +144,10 @@ function defineElement() {
|
|
|
95
144
|
}
|
|
96
145
|
disconnectedCallback() {
|
|
97
146
|
this.#observer.disconnect();
|
|
147
|
+
this.#notes = syncChordNotes(this, this.#notes);
|
|
98
148
|
}
|
|
99
149
|
attributeChangedCallback() {
|
|
150
|
+
this.#notes = syncChordNotes(this, this.#notes);
|
|
100
151
|
if (this.isConnected)
|
|
101
152
|
this.#schedule();
|
|
102
153
|
}
|
|
@@ -197,6 +248,13 @@ function defineElement() {
|
|
|
197
248
|
else
|
|
198
249
|
this.removeAttribute("diagram-hand");
|
|
199
250
|
}
|
|
251
|
+
/** Whether a chord's notes show when it is pointed at or its bar has focus. */
|
|
252
|
+
get chordNotes() {
|
|
253
|
+
return this.hasAttribute("chord-notes");
|
|
254
|
+
}
|
|
255
|
+
set chordNotes(v) {
|
|
256
|
+
this.toggleAttribute("chord-notes", v);
|
|
257
|
+
}
|
|
200
258
|
/** The label of the part to draw on its own, or null for the whole chart. */
|
|
201
259
|
get showPart() {
|
|
202
260
|
return this.getAttribute("show-part");
|
|
@@ -228,7 +286,13 @@ function defineElement() {
|
|
|
228
286
|
const content = await this.#content(source, script, options);
|
|
229
287
|
if (render !== this.#renders)
|
|
230
288
|
return;
|
|
231
|
-
|
|
289
|
+
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
290
|
+
// A bar with focus keeps it through the new drawing (a new theme, say): the same stop, by its place.
|
|
291
|
+
const stops = () => [...root.querySelectorAll("[tabindex]")];
|
|
292
|
+
const focused = stops().indexOf(root.activeElement);
|
|
293
|
+
root.innerHTML = content;
|
|
294
|
+
if (focused >= 0)
|
|
295
|
+
stops()[focused]?.focus();
|
|
232
296
|
}
|
|
233
297
|
async #content(source, script, options) {
|
|
234
298
|
if (source === "text")
|
package/dist/html.d.ts
CHANGED
|
@@ -52,6 +52,13 @@ export type RenderOptions = {
|
|
|
52
52
|
chordDiagrams?: "guitar";
|
|
53
53
|
/** The diagrams' hand: `"left"` mirrors the strings, low string on the right. Any other value is right. */
|
|
54
54
|
diagramHand?: "right" | "left";
|
|
55
|
+
/**
|
|
56
|
+
* Show a chord symbol's notes, as the parser spells them: over the chord
|
|
57
|
+
* while it is pointed at, and over its bar, for every chord there, while
|
|
58
|
+
* the bar has focus. Each bar holding a chord symbol becomes a tab stop
|
|
59
|
+
* described by its chords' notes. Off by default.
|
|
60
|
+
*/
|
|
61
|
+
chordNotes?: boolean;
|
|
55
62
|
};
|
|
56
63
|
export type Columns = "shared" | "row";
|
|
57
64
|
export declare function renderChart(text: string, options?: RenderOptions): string;
|
package/dist/html.js
CHANGED
|
@@ -10,7 +10,7 @@ import { diagramSvg } from "./diagram.js";
|
|
|
10
10
|
import { escapeHtml } from "./escape.js";
|
|
11
11
|
import { fontFaceCss } from "./font.js";
|
|
12
12
|
import { isTacet as isTacetCell, layoutChart, meloffChanged } from "./model.js";
|
|
13
|
-
import { barLabel, speakBar, speakDiagram, speakVerses, UNPLAYABLE, VOICING_REPLACED, } from "./speech.js";
|
|
13
|
+
import { barLabel, speakBar, speakChordNotes, speakDiagram, speakVerses, UNPLAYABLE, VOICING_REPLACED, } from "./speech.js";
|
|
14
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 = {}) {
|
|
@@ -29,6 +29,7 @@ function elementAttributes(options) {
|
|
|
29
29
|
options.part ? ` show-part="${escapeHtml(options.part)}"` : "",
|
|
30
30
|
byRow(options) ? ' columns="row"' : "",
|
|
31
31
|
diagramAttributes(options),
|
|
32
|
+
options.chordNotes ? " chord-notes" : "",
|
|
32
33
|
].join("");
|
|
33
34
|
}
|
|
34
35
|
/** `barNumbers` as drawn: played, written (true) or none; `"off"` and any falsy value but null are none, as `false` is. */
|
|
@@ -84,12 +85,27 @@ function chartHtml(text, options) {
|
|
|
84
85
|
gutter: barNumbers || parts,
|
|
85
86
|
numerals: numeralsOf(options),
|
|
86
87
|
rows: byRow(options),
|
|
88
|
+
notes: options.chordNotes ? { prefix: notePrefix(text, options), next: 0 } : null,
|
|
87
89
|
};
|
|
88
90
|
const blocks = model.blocks.map((b) => blockHtml(b, settings)).join("");
|
|
89
91
|
// Played numbers bring their own rules, so a chart of written numbers is styled as before.
|
|
90
92
|
const own = played ? `<style>${PLAYED_CSS}</style>` : "";
|
|
91
93
|
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
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* A description id's prefix: a hash of what decides the descriptions, so two
|
|
97
|
+
* charts on one page share no id unless they say the same: the text, the part
|
|
98
|
+
* drawn, whether the melody is left out (both change which bars there are),
|
|
99
|
+
* and the numerals that speak degrees. Deterministic, so the server and the
|
|
100
|
+
* element draw the same ids.
|
|
101
|
+
*/
|
|
102
|
+
function notePrefix(text, options) {
|
|
103
|
+
let h = 5381;
|
|
104
|
+
const key = [numeralsOf(options), options.part, options.melody === false, text];
|
|
105
|
+
for (const c of JSON.stringify(key))
|
|
106
|
+
h = (h * 33) ^ (c.codePointAt(0) ?? 0);
|
|
107
|
+
return `bm-n${(h >>> 0).toString(36)}`;
|
|
108
|
+
}
|
|
93
109
|
/** The widest played numbers any gutter shows, in em of their text: each row's, a system's first row's. */
|
|
94
110
|
function playedWidest(model) {
|
|
95
111
|
let widest = 0;
|
|
@@ -376,7 +392,8 @@ function gutterHtml(row, settings, part) {
|
|
|
376
392
|
const GLYPH_EM = { " ": 0.33, "·": 0.33, "…": 1.02, "~": 0.86 };
|
|
377
393
|
const gutterWidth = (text) => [...text].reduce((w, c) => w + (GLYPH_EM[c] ?? 0.66), 0);
|
|
378
394
|
/** 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,
|
|
395
|
+
function rowCells(row, settings, ending) {
|
|
396
|
+
const played = settings.played !== null;
|
|
380
397
|
let n = row.barNumber;
|
|
381
398
|
const firstTacet = row.cells.findIndex(isTacetCell);
|
|
382
399
|
const firstBar = row.cells.findIndex((c) => c.kind === "slots");
|
|
@@ -394,7 +411,7 @@ function rowCells(row, numerals, ending, played) {
|
|
|
394
411
|
const name = played && cell.kind === "slots" ? (cell.playedNumbers ?? []) : n;
|
|
395
412
|
const html = isTacetCell(cell)
|
|
396
413
|
? tacetHtml(cell, name, marks, i === firstTacet)
|
|
397
|
-
: cellHtml(cell, name, marks,
|
|
414
|
+
: cellHtml(cell, name, marks, settings, sung);
|
|
398
415
|
if (n !== null && cell.kind === "slots")
|
|
399
416
|
n++;
|
|
400
417
|
return html;
|
|
@@ -425,7 +442,7 @@ function rowOpening(row, part, ending) {
|
|
|
425
442
|
const leads = (part) => !part || part.first;
|
|
426
443
|
function rowHtml(row, columns, settings, part) {
|
|
427
444
|
const label = row.ending && leads(part) ? endingLabel(row.ending) : null;
|
|
428
|
-
const cells = rowCells(row, settings
|
|
445
|
+
const cells = rowCells(row, settings, label ? ` data-ending="${label.shown}"` : "");
|
|
429
446
|
const goesOn = row.continues && leads(part) ? `${endingLabel(row.continues).spoken}, continued` : "";
|
|
430
447
|
const empty = `<span class="bm-empty" aria-hidden="true"></span>`.repeat(Math.max(0, columns - row.cells.length));
|
|
431
448
|
const said = rowOpening(row, part, label?.spoken ?? goesOn);
|
|
@@ -455,24 +472,41 @@ function rowRepeatHtml(row) {
|
|
|
455
472
|
}
|
|
456
473
|
/** A bar's unreadable slots' errors, spoken after the bar (barmark's grammar 2.3). */
|
|
457
474
|
const spokenErrors = (cell) => cell.kind === "slots" ? (cell.unread ?? []).map((m) => `error: ${m}`) : [];
|
|
458
|
-
function cellHtml(cell, barNumber, marks, numerals, sung) {
|
|
475
|
+
function cellHtml(cell, barNumber, marks, { numerals, notes: ids }, sung) {
|
|
459
476
|
const numeral = numerals && cell.kind === "slots" && cell.key ? { style: numerals, key: cell.key } : null;
|
|
460
477
|
const said = [speakBar(barNumber, cell, numeral !== null), ...spokenErrors(cell), sung.words];
|
|
461
478
|
const spoken = `<span class="bm-sr">${escapeHtml(said.filter(Boolean).join(", "))}</span>`;
|
|
462
479
|
if (cell.kind !== "slots")
|
|
463
480
|
return betweenBarsHtml(cell, spoken, marks);
|
|
464
481
|
const change = cell.tempoChange ? ` data-tempo-change="${cell.tempoChange}"` : "";
|
|
465
|
-
const
|
|
482
|
+
const notes = notesOf(cell, { numeral, pitches: sung.pitches, sung: sung.bar }, ids);
|
|
483
|
+
const [body, end] = barBody(cell, notes.view);
|
|
466
484
|
const numbers = sung.first ? verseNumbersHtml(sung.bar) : "";
|
|
467
485
|
const drawn = `<span class="bm-bar-body" aria-hidden="true">${body}</span>`;
|
|
468
486
|
// A lyric row's lines go under the bar body, in a stack that wraps with the bar.
|
|
469
487
|
const stack = sung.beats ? `<span class="bm-bar-stack">${drawn}${sung.beats}</span>` : drawn;
|
|
470
|
-
return `<div class="bm-bar" part="bar"${cell.cut ? " data-cut" : ""}${change}${marks}>${spoken}${numbers}${stack}${end}</div>`;
|
|
488
|
+
return `<div class="bm-bar" part="bar"${cell.cut ? " data-cut" : ""}${change}${marks}${notes.stop}>${spoken}${numbers}${stack}${end}${notes.shown}</div>`;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* A bar's chord notes: the view its slots draw with, the keyboard stop's
|
|
492
|
+
* attributes and what follows the body. Nothing changes without
|
|
493
|
+
* `chordNotes`, or in a bar with no chord symbol.
|
|
494
|
+
*/
|
|
495
|
+
function notesOf(cell, view, ids) {
|
|
496
|
+
const noted = ids ? notedChords(cell) : [];
|
|
497
|
+
if (!ids || noted.length === 0)
|
|
498
|
+
return { view, stop: "", shown: "" };
|
|
499
|
+
const [stop, shown] = barNotes(noted, view, ids);
|
|
500
|
+
return { view: { ...view, notes: true }, stop, shown };
|
|
471
501
|
}
|
|
472
502
|
/** What a bar shows: its meter, its slots (or `%`), and "cut"; then the words after its last slot. */
|
|
473
503
|
function barBody(cell, given) {
|
|
474
504
|
// Each unreadable slot takes its message in turn (barmark's grammar 2.3).
|
|
475
|
-
const view = {
|
|
505
|
+
const view = {
|
|
506
|
+
...given,
|
|
507
|
+
unread: [...(cell.unread ?? [])],
|
|
508
|
+
...(given.notes && { notes: { at: 0, of: cell.slots.flatMap(membersOf).length } }),
|
|
509
|
+
};
|
|
476
510
|
const meter = cell.meter
|
|
477
511
|
? `<span class="bm-meter"><span>${cell.meter.n}</span><span>${cell.meter.d}</span></span>`
|
|
478
512
|
: "";
|
|
@@ -575,6 +609,12 @@ function groupHtml(members, view) {
|
|
|
575
609
|
return `<span class="bm-group" data-count="${members.length}"><span class="bm-tuplet">${members.length}</span>${inner}</span>`;
|
|
576
610
|
}
|
|
577
611
|
function unmarkedSlotHtml(slot, view) {
|
|
612
|
+
const html = slotBodyHtml(slot, view);
|
|
613
|
+
if (typeof view.notes === "object" && slot.kind !== "group")
|
|
614
|
+
view.notes.at++;
|
|
615
|
+
return html;
|
|
616
|
+
}
|
|
617
|
+
function slotBodyHtml(slot, view) {
|
|
578
618
|
switch (slot.kind) {
|
|
579
619
|
case "chord":
|
|
580
620
|
return chordHtml(slot.chord, view);
|
|
@@ -607,12 +647,47 @@ function chordHtml(record, view) {
|
|
|
607
647
|
return pitchHtml(record);
|
|
608
648
|
if (record.kind === "notes" || !record.parts)
|
|
609
649
|
return notesHtml(record);
|
|
610
|
-
const
|
|
611
|
-
|
|
650
|
+
const html = namedHtml(record.parts, view.numeral);
|
|
651
|
+
return typeof view.notes === "object" ? notedHtml(record, html, view.notes) : html;
|
|
652
|
+
}
|
|
653
|
+
/** A chord symbol as drawn: its name, or its numeral in the bar's key. */
|
|
654
|
+
function namedHtml(parts, numeral) {
|
|
655
|
+
const pieces = numeral ? typesetNumeral(parts, numeral.key, numeral.style) : null;
|
|
612
656
|
if (!pieces)
|
|
613
|
-
return piecesHtml(typesetChord(
|
|
657
|
+
return piecesHtml(typesetChord(parts), "");
|
|
614
658
|
return piecesHtml(pieces, ` data-numeral="${numeral?.style}"`);
|
|
615
659
|
}
|
|
660
|
+
/** A chord with its notes' label; one in the bar's later half shows them from its right edge, so they stay over the bar. */
|
|
661
|
+
const notedHtml = (record, html, notes) => `<span class="bm-noted"${notes.at * 2 >= notes.of ? " data-end" : ""}>${html}${notesLabel(record, ' part="chord-notes"')}</span>`;
|
|
662
|
+
/** A chord's notes as the parser spells them, with ♯ and ♭: `C E G B♭`. */
|
|
663
|
+
const notesLabel = (record, attributes = "") => `<span class="bm-cn"${attributes}>${escapeHtml(record.pitches.map(glyphs).join(" "))}</span>`;
|
|
664
|
+
/** The slots a bar draws one after another: a group's members each. */
|
|
665
|
+
const membersOf = (slot) => (slot.kind === "group" ? slot.members : [slot]);
|
|
666
|
+
/** A bar's chord symbols, in slot order (a bar drawn as `%` has no slots): no note set, which shows its notes already. */
|
|
667
|
+
const notedChords = (cell) => cell.kind !== "slots"
|
|
668
|
+
? []
|
|
669
|
+
: cell.slots
|
|
670
|
+
.flatMap(membersOf)
|
|
671
|
+
.flatMap((s) => s.kind === "chord" && s.chord.kind === "chord" && s.chord.parts ? [s.chord] : []);
|
|
672
|
+
/**
|
|
673
|
+
* A bar with chord symbols as a keyboard stop: its attributes, and what it
|
|
674
|
+
* adds after its body. A group (it takes focus, and a focusable element needs
|
|
675
|
+
* a role) described by an element that is `hidden`, so it is read only as
|
|
676
|
+
* the description and never in the reading order, and is outside the
|
|
677
|
+
* aria-hidden body. While the bar has focus, the box over it shows each chord
|
|
678
|
+
* as drawn with its notes; it is aria-hidden, said by the description instead.
|
|
679
|
+
*/
|
|
680
|
+
function barNotes(noted, view, ids) {
|
|
681
|
+
const id = `${ids.prefix}-${ids.next++}`;
|
|
682
|
+
const said = speakChordNotes(noted, view.numeral?.key);
|
|
683
|
+
const items = noted
|
|
684
|
+
.map((r) => `<span class="bm-bar-note">${chordHtml(r, view)} ${notesLabel(r)}</span>`)
|
|
685
|
+
.join("");
|
|
686
|
+
return [
|
|
687
|
+
` tabindex="0" role="group" aria-describedby="${id}"`,
|
|
688
|
+
`<span class="bm-bar-notes" part="chord-notes" aria-hidden="true">${items}</span><span id="${id}" hidden>${escapeHtml(said)}</span>`,
|
|
689
|
+
];
|
|
690
|
+
}
|
|
616
691
|
function piecesHtml(p, attributes) {
|
|
617
692
|
const quality = p.quality ? `<span class="bm-quality">${p.quality}</span>` : "";
|
|
618
693
|
const sup = p.superscript ? `<sup>${escapeHtml(p.superscript)}</sup>` : "";
|
package/dist/speech.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ import { type ChordRecord, type Key, type Slot, type Syllable } from "barmark";
|
|
|
6
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
|
+
/**
|
|
10
|
+
* The notes of a bar's chord symbols, as a focused bar describes them: each
|
|
11
|
+
* chord as a bar says it, then its notes as the parser spells them, in slot
|
|
12
|
+
* order: "C seven: C, E, G, B flat; F over A: F, A, C".
|
|
13
|
+
*/
|
|
14
|
+
export declare function speakChordNotes(records: ChordRecord[], key?: Key): string;
|
|
9
15
|
/** A diagram with no shape, shown in its frame and said in its label. */
|
|
10
16
|
export declare const UNPLAYABLE = "not playable in standard tuning";
|
|
11
17
|
/** A written voicing the diagram replaced with the name's shape, shown under the name and said in its label. */
|
package/dist/speech.js
CHANGED
|
@@ -105,6 +105,16 @@ export function speakChord(record, key) {
|
|
|
105
105
|
const degree = key ? speakDegree(record.parts.root, key) : "";
|
|
106
106
|
return `${degree ? `${degree}, ` : ""}${speakParts(record.parts)}`;
|
|
107
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* The notes of a bar's chord symbols, as a focused bar describes them: each
|
|
110
|
+
* chord as a bar says it, then its notes as the parser spells them, in slot
|
|
111
|
+
* order: "C seven: C, E, G, B flat; F over A: F, A, C".
|
|
112
|
+
*/
|
|
113
|
+
export function speakChordNotes(records, key) {
|
|
114
|
+
return records
|
|
115
|
+
.map((r) => `${speakChord(r, key)}: ${r.pitches.map(speakPitch).join(", ")}`)
|
|
116
|
+
.join("; ");
|
|
117
|
+
}
|
|
108
118
|
/** A diagram with no shape, shown in its frame and said in its label. */
|
|
109
119
|
export const UNPLAYABLE = "not playable in standard tuning";
|
|
110
120
|
/** A written voicing the diagram replaced with the name's shape, shown under the name and said in its label. */
|
package/dist/styles.d.ts
CHANGED
|
@@ -26,4 +26,6 @@ export declare const PLAYED_CSS: string;
|
|
|
26
26
|
export declare function playedGutterExtra(width: number, labels: number | null): number;
|
|
27
27
|
/** 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. */
|
|
28
28
|
export declare const DIAGRAMS_CSS: string;
|
|
29
|
+
/** The chord notes' rules, at the stylesheet's very end: no chart drawn without `chordNotes` uses them. */
|
|
30
|
+
export declare const CHORD_NOTES_CSS: string;
|
|
29
31
|
export declare const stylesheet: string;
|
package/dist/styles.js
CHANGED
|
@@ -344,4 +344,41 @@ const diagramsCss = `
|
|
|
344
344
|
`;
|
|
345
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. */
|
|
346
346
|
export const DIAGRAMS_CSS = minify(diagramsCss);
|
|
347
|
-
|
|
347
|
+
/**
|
|
348
|
+
* `chordNotes`: a chord's notes in a small label. Pointed at, a chord shows
|
|
349
|
+
* its own under it, from its left edge, or from its right edge in its bar's
|
|
350
|
+
* later half (`data-end`), so the label stays under its bar; the label is the
|
|
351
|
+
* chord's child, so the pointer can move onto it and it stays (WCAG 1.4.13).
|
|
352
|
+
* A focused bar (`[tabindex]`; a tap focuses it too, so `:focus`, not
|
|
353
|
+
* `:focus-visible`) shows every chord's notes at once in one box under the
|
|
354
|
+
* bar, as wide as the bar, each chord with its notes kept on one line unless
|
|
355
|
+
* it alone is wider than the box. Both are placed absolutely, so the grid
|
|
356
|
+
* never moves, and both open downward, where what overflows a chart can be
|
|
357
|
+
* scrolled to (the page, or a chart that scrolls sideways); upward they ran
|
|
358
|
+
* off the top of the page or the scrolling chart, where nothing scrolls. A
|
|
359
|
+
* chart that scrolls keeps the room for its own vertical scrollbar
|
|
360
|
+
* (`scrollbar-gutter`), so a box under its last row that makes it scroll
|
|
361
|
+
* down moves nothing. Never printed.
|
|
362
|
+
*/
|
|
363
|
+
const N = ".bm-noted>.bm-cn";
|
|
364
|
+
const BOX = ".bm-bar-notes";
|
|
365
|
+
const chordNotesCss = `
|
|
366
|
+
.bm-noted{position:relative}
|
|
367
|
+
${N},${BOX}{display:none;position:absolute;z-index:2;top:100%;padding:.1em .4em;background:var(--bm-paper);border:.07em solid var(--bm-rule);border-radius:.3em}
|
|
368
|
+
.bm-cn{font:${em(SIZES.barNumber)}/1.3 ${LABEL};color:var(--bm-ink)}
|
|
369
|
+
${N}{left:0;width:max-content;max-width:8em}
|
|
370
|
+
.bm-noted[data-end]>.bm-cn{left:auto;right:0}
|
|
371
|
+
.bm-noted:hover>.bm-cn{display:block}
|
|
372
|
+
${BOX}{left:0;right:0;flex-wrap:wrap;gap:0 .7em}
|
|
373
|
+
.bm-bar-note{max-width:100%}
|
|
374
|
+
${BOX} .bm-chord{color:var(--bm-muted)}
|
|
375
|
+
.bm-bar[tabindex]:focus>${BOX}{display:flex}
|
|
376
|
+
.bm-bar[tabindex]:focus ${N}{display:none}
|
|
377
|
+
.bm-bar[tabindex]:focus-visible{outline:.12em solid var(--bm-ink);outline-offset:-.2em}
|
|
378
|
+
.bm-chart[data-quiet] :is(.bm-cn,${BOX}){display:none!important}
|
|
379
|
+
@media screen{.bm-chart:has(.bm-system):has(.bm-bar[tabindex]){scrollbar-gutter:stable}}
|
|
380
|
+
@media print{.bm-cn,${BOX}{display:none!important}}
|
|
381
|
+
`;
|
|
382
|
+
/** The chord notes' rules, at the stylesheet's very end: no chart drawn without `chordNotes` uses them. */
|
|
383
|
+
export const CHORD_NOTES_CSS = minify(chordNotesCss);
|
|
384
|
+
export const stylesheet = minify(css) + DIAGRAMS_CSS + ROW_COLUMNS_CSS + SYSTEM_FIT_CSS + CHORD_NOTES_CSS;
|
package/package.json
CHANGED