@barmark/score 0.1.0 → 0.1.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 +31 -1
- package/README.md +4 -1
- package/dist/element.js +20 -1
- package/dist/engrave.d.ts +6 -0
- package/dist/engrave.js +26 -1
- package/dist/markup.d.ts +2 -0
- package/dist/markup.js +3 -1
- package/dist/switch.d.ts +13 -2
- package/dist/switch.js +22 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,35 @@ package uses [semantic versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.1.1] - 2026-11-09
|
|
10
|
+
|
|
11
|
+
Requires `@barmark/musicxml` 0.7.2.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- **A chord symbol is drawn as the chart spells it.** Verovio 6.4 appends
|
|
16
|
+
every `<degree>` to the kind text, `print-object="no"` or not, so
|
|
17
|
+
`D7sus4` was drawn `D7sus4(7)` and `G5(7)` as `G5(7)(no3)`. The score
|
|
18
|
+
now drops a degree that is not printed before Verovio reads the
|
|
19
|
+
MusicXML (with `@barmark/musicxml`'s next release, which hides a degree
|
|
20
|
+
its kind text already spells). `Engraved.xml` is the export unchanged.
|
|
21
|
+
The pass is linear (a single `indexOf` scan, no backtracking regex), so a
|
|
22
|
+
hostile MusicXML given to `engraveXml` cannot stall it.
|
|
23
|
+
- **The Grid / Score switch follows the element's `theme`.** It sits
|
|
24
|
+
outside the grid's themed `.bm-chart`, and render's `:host{all:initial}`
|
|
25
|
+
reset its colour and font, so on a dark page it was black text in the
|
|
26
|
+
browser's serif. It now takes render's ink and rule for `theme="dark"`,
|
|
27
|
+
for `auto` (or no theme) under a dark colour scheme, and light ones
|
|
28
|
+
otherwise and in print, honouring `--barmark-ink` and `--barmark-rule`,
|
|
29
|
+
in render's label font (`--barmark-label-font`). A page no longer has to
|
|
30
|
+
colour the host itself.
|
|
31
|
+
- **Chord accidentals and the tempo's note draw in Chromium.** Verovio
|
|
32
|
+
declares its Leipzig font (the ♯, ♭ and ♩) inside the score's SVG, in the
|
|
33
|
+
shadow root, where Chromium never registers a font face, so `C♯m7` drew
|
|
34
|
+
as `C m7`. The element now copies that face, once per document, into a
|
|
35
|
+
`<style data-barmark-score-font>` in the head. A page that copied it
|
|
36
|
+
itself can drop the copy.
|
|
37
|
+
|
|
9
38
|
## [0.1.0] - 2026-11-08
|
|
10
39
|
|
|
11
40
|
First release.
|
|
@@ -62,5 +91,6 @@ First release.
|
|
|
62
91
|
needs no config; Vite 7 needs `optimizeDeps.exclude` and
|
|
63
92
|
`worker.format: "es"`.
|
|
64
93
|
|
|
65
|
-
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/score-v0.1.
|
|
94
|
+
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/score-v0.1.1...HEAD
|
|
95
|
+
[0.1.1]: https://github.com/kevinpeckham/barmark/compare/score-v0.1.0...score-v0.1.1
|
|
66
96
|
[0.1.0]: https://github.com/kevinpeckham/barmark/releases/tag/score-v0.1.0
|
package/README.md
CHANGED
|
@@ -127,7 +127,10 @@ else console.warn(result.reason);
|
|
|
127
127
|
|
|
128
128
|
The SVG is cleaned with an allow-list (`cleanSvg`) before it is returned;
|
|
129
129
|
`scorePane` and `scoreStyles` wrap it so it follows the grid's light and
|
|
130
|
-
dark palette.
|
|
130
|
+
dark palette. `engraveChart` and `engraveXml` drop a chord `<degree>`
|
|
131
|
+
marked `print-object="no"` before Verovio reads the MusicXML, as Verovio
|
|
132
|
+
6.4 prints every degree after the chord's text (`D7sus4(7)`); `result.xml`
|
|
133
|
+
is the export unchanged.
|
|
131
134
|
|
|
132
135
|
## Licence
|
|
133
136
|
|
package/dist/element.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { FONT_FAMILY, fontFaceCss, renderChartUnwrapped, } from "@barmark/render";
|
|
10
10
|
import { chartSource, inlineChartText, optionsFromAttributes, } from "@barmark/render/element";
|
|
11
11
|
import { parseChart } from "barmark";
|
|
12
|
-
import { scorePane } from "./markup.js";
|
|
12
|
+
import { isLeipzigFace, scorePane } from "./markup.js";
|
|
13
13
|
import { decodeCarried, gridError, scoreShell } from "./shell.js";
|
|
14
14
|
import { viewOf } from "./switch.js";
|
|
15
15
|
let testEngine = null;
|
|
@@ -47,6 +47,24 @@ function addFont(doc) {
|
|
|
47
47
|
font.setAttribute("data-barmark-font", FONT_FAMILY);
|
|
48
48
|
doc.head.append(font);
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Verovio's Leipzig face (the ♯, ♭ and ♩ of chord symbols and tempo marks), once per
|
|
52
|
+
* document. Verovio declares it in a `<style>` inside the score's SVG, in the shadow
|
|
53
|
+
* root, where Chromium never registers a font face, so "C♯m7" drew as "C m7". The
|
|
54
|
+
* copy is the face `cleanSvg` already let through, checked again here.
|
|
55
|
+
*/
|
|
56
|
+
function addScoreFont(doc, pane) {
|
|
57
|
+
if (doc.querySelector("style[data-barmark-score-font]") !== null)
|
|
58
|
+
return;
|
|
59
|
+
const css = [...pane.querySelectorAll("style")]
|
|
60
|
+
.map((s) => s.textContent ?? "")
|
|
61
|
+
.find(isLeipzigFace);
|
|
62
|
+
if (!css)
|
|
63
|
+
return;
|
|
64
|
+
const font = Object.assign(doc.createElement("style"), { textContent: css });
|
|
65
|
+
font.setAttribute("data-barmark-score-font", "Leipzig");
|
|
66
|
+
doc.head.append(font);
|
|
67
|
+
}
|
|
50
68
|
const load = (src) => fetch(src).then((r) => r.ok ? r.text() : Promise.reject(new Error(`${r.status} ${r.statusText}`.trim())));
|
|
51
69
|
/** Text set on the element before it was defined is an own property; it is taken off and returned. */
|
|
52
70
|
function takeEarlyText(el) {
|
|
@@ -358,6 +376,7 @@ function defineElement() {
|
|
|
358
376
|
if (this.#revealed?.svg !== svg || this.#revealed.theme !== theme) {
|
|
359
377
|
try {
|
|
360
378
|
pane.innerHTML = scorePane(svg, theme, label);
|
|
379
|
+
addScoreFont(this.ownerDocument, pane);
|
|
361
380
|
}
|
|
362
381
|
catch (e) {
|
|
363
382
|
return this.#fail(messageOf(e));
|
package/dist/engrave.d.ts
CHANGED
|
@@ -26,6 +26,12 @@ export declare const LAYOUT: {
|
|
|
26
26
|
readonly header: "auto";
|
|
27
27
|
readonly justifyVertically: false;
|
|
28
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* The MusicXML as Verovio should read it. Verovio 6.4 appends every chord <degree> to the
|
|
31
|
+
* kind text, `print-object="no"` or not, so a degree the text already spells is drawn twice
|
|
32
|
+
* (`D7sus4(7)`); a degree that is not printed is dropped, which changes nothing it draws.
|
|
33
|
+
*/
|
|
34
|
+
export declare function forVerovio(xml: string): string;
|
|
29
35
|
/** MusicXML laid out for a width, every page as SVG in a `bms-score-page` div. Throws on unreadable XML. */
|
|
30
36
|
export declare function engraveXml(vrv: VerovioToolkit, xml: string, options: EngraveOptions): {
|
|
31
37
|
svg: string;
|
package/dist/engrave.js
CHANGED
|
@@ -12,6 +12,31 @@ export const LAYOUT = {
|
|
|
12
12
|
};
|
|
13
13
|
const DEFAULT_SCALE = 40;
|
|
14
14
|
const MIN_WIDTH = 320;
|
|
15
|
+
const HIDDEN_DEGREE = '<degree print-object="no">';
|
|
16
|
+
const DEGREE_END = "</degree>";
|
|
17
|
+
/**
|
|
18
|
+
* The MusicXML as Verovio should read it. Verovio 6.4 appends every chord <degree> to the
|
|
19
|
+
* kind text, `print-object="no"` or not, so a degree the text already spells is drawn twice
|
|
20
|
+
* (`D7sus4(7)`); a degree that is not printed is dropped, which changes nothing it draws.
|
|
21
|
+
*/
|
|
22
|
+
export function forVerovio(xml) {
|
|
23
|
+
// One pass with indexOf, never a backtracking regex: an opener with no closer ends the
|
|
24
|
+
// search, so a hostile file of openers costs linear time, not a rescan per opener.
|
|
25
|
+
const parts = [];
|
|
26
|
+
let from = 0;
|
|
27
|
+
for (;;) {
|
|
28
|
+
const open = xml.indexOf(HIDDEN_DEGREE, from);
|
|
29
|
+
if (open < 0)
|
|
30
|
+
break;
|
|
31
|
+
const close = xml.indexOf(DEGREE_END, open + HIDDEN_DEGREE.length);
|
|
32
|
+
if (close < 0)
|
|
33
|
+
break;
|
|
34
|
+
parts.push(xml.slice(from, open));
|
|
35
|
+
from = close + DEGREE_END.length;
|
|
36
|
+
}
|
|
37
|
+
parts.push(xml.slice(from));
|
|
38
|
+
return parts.join("");
|
|
39
|
+
}
|
|
15
40
|
/** MusicXML laid out for a width, every page as SVG in a `bms-score-page` div. Throws on unreadable XML. */
|
|
16
41
|
export function engraveXml(vrv, xml, options) {
|
|
17
42
|
const scale = options.scale ?? DEFAULT_SCALE;
|
|
@@ -21,7 +46,7 @@ export function engraveXml(vrv, xml, options) {
|
|
|
21
46
|
// Verovio's page width is in its own units at scale 100.
|
|
22
47
|
pageWidth: Math.round((Math.max(MIN_WIDTH, options.width) * 100) / scale),
|
|
23
48
|
});
|
|
24
|
-
if (!vrv.loadData(xml))
|
|
49
|
+
if (!vrv.loadData(forVerovio(xml)))
|
|
25
50
|
throw new Error("Verovio could not read the score");
|
|
26
51
|
const pages = vrv.getPageCount();
|
|
27
52
|
if (pages < 1)
|
package/dist/markup.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export type ScoreTheme = "auto" | "light" | "dark";
|
|
2
|
+
/** Whether a stylesheet is Verovio's embedded Leipzig face, exactly (and nothing else). */
|
|
3
|
+
export declare const isLeipzigFace: (css: string) => boolean;
|
|
2
4
|
/**
|
|
3
5
|
* Verovio's SVG reduced to what Verovio emits: only the listed elements and
|
|
4
6
|
* attributes survive, an unlisted element goes with its content, links keep
|
package/dist/markup.js
CHANGED
|
@@ -46,8 +46,10 @@ const STYLE_ID = /^#([A-Za-z0-9]+) g\.ending,/;
|
|
|
46
46
|
const STYLE_TEMPLATE = "#@ g.ending, #@ g.fing, #@ g.reh, #@ g.tempo {font-weight:bold;}#@ g.dir, #@ g.dynam, #@ g.mNum {font-style:italic;}#@ g.label {font-weight:normal;}#@ ellipse, #@ path, #@ polygon, #@ polyline, #@ rect {stroke:currentColor}#@ g.cursor {fill:dodgerblue; color:dodgerblue;}#@ g.cursor.chord {fill:limegreen; color:limegreen;}#@ g.placeholder {visibility:hidden}";
|
|
47
47
|
/** The one embedded font Verovio adds for some scores: Leipzig as a base64 woff2, nothing else. */
|
|
48
48
|
const FONT_FACE = /^@font-face \{\s*font-family: 'Leipzig';\s*src: url\(data:application\/font-woff2;charset=utf-8;base64,[A-Za-z0-9+/=]+\) format\('woff2'\);\s*font-weight: normal;\s*font-style: normal;\s*\}$/;
|
|
49
|
+
/** Whether a stylesheet is Verovio's embedded Leipzig face, exactly (and nothing else). */
|
|
50
|
+
export const isLeipzigFace = (css) => FONT_FACE.test(css);
|
|
49
51
|
function isVerovioStyle(css) {
|
|
50
|
-
if (
|
|
52
|
+
if (isLeipzigFace(css))
|
|
51
53
|
return true;
|
|
52
54
|
const id = STYLE_ID.exec(css)?.[1];
|
|
53
55
|
return id !== undefined && css === STYLE_TEMPLATE.replaceAll("@", id);
|
package/dist/switch.d.ts
CHANGED
|
@@ -3,5 +3,16 @@ export type ScoreView = "grid" | "score";
|
|
|
3
3
|
export declare const viewOf: (value: unknown) => ScoreView;
|
|
4
4
|
/** The Grid / Score switch: a radio group of two buttons, the current view checked. */
|
|
5
5
|
export declare function switchHtml(view: ScoreView): string;
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The switch's ink and rule: @barmark/render's palettes (its `PALETTES`, which it does not
|
|
8
|
+
* export; tests/switch.test.ts holds the two equal), with its `--barmark-ink` and
|
|
9
|
+
* `--barmark-rule` overrides. The switch sits outside render's `.bm-chart`, whose
|
|
10
|
+
* `data-theme` sets the palette, and render's `:host{all:initial}` resets its colour and
|
|
11
|
+
* font, so it keys the same choice off the element's own `theme` attribute.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SWITCH_PALETTES: Record<"light" | "dark", {
|
|
14
|
+
ink: string;
|
|
15
|
+
rule: string;
|
|
16
|
+
}>;
|
|
17
|
+
/** The switch's own look, in its theme's colours and render's label font. */
|
|
18
|
+
export declare const switchStyles: string;
|
package/dist/switch.js
CHANGED
|
@@ -5,10 +5,28 @@ export function switchHtml(view) {
|
|
|
5
5
|
const radio = (value, label) => `<button type="button" role="radio" data-view="${value}" aria-checked="${view === value}"${view === value ? "" : ' tabindex="-1"'}>${label}</button>`;
|
|
6
6
|
return `<div class="bms-switch" role="radiogroup" aria-label="View">${radio("grid", "Grid")}${radio("score", "Score")}</div>`;
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
.
|
|
8
|
+
/**
|
|
9
|
+
* The switch's ink and rule: @barmark/render's palettes (its `PALETTES`, which it does not
|
|
10
|
+
* export; tests/switch.test.ts holds the two equal), with its `--barmark-ink` and
|
|
11
|
+
* `--barmark-rule` overrides. The switch sits outside render's `.bm-chart`, whose
|
|
12
|
+
* `data-theme` sets the palette, and render's `:host{all:initial}` resets its colour and
|
|
13
|
+
* font, so it keys the same choice off the element's own `theme` attribute.
|
|
14
|
+
*/
|
|
15
|
+
export const SWITCH_PALETTES = {
|
|
16
|
+
light: { ink: "#1d1d1f", rule: "#4a4a4a" },
|
|
17
|
+
dark: { ink: "#ece8e0", rule: "#8f897f" },
|
|
18
|
+
};
|
|
19
|
+
const colours = ({ ink, rule }) => `--bms-ink:var(--barmark-ink,${ink});--bms-rule:var(--barmark-rule,${rule});`;
|
|
20
|
+
const AUTO = ':host(:not([theme="light"]):not([theme="dark"]))';
|
|
21
|
+
/** The switch's own look, in its theme's colours and render's label font. */
|
|
22
|
+
export const switchStyles = `:host{${colours(SWITCH_PALETTES.light)}}
|
|
23
|
+
:host([theme="dark"]){${colours(SWITCH_PALETTES.dark)}}
|
|
24
|
+
@media (prefers-color-scheme:dark){${AUTO}{${colours(SWITCH_PALETTES.dark)}}}
|
|
25
|
+
@media print{:host,:host([theme="dark"]),${AUTO}{${colours(SWITCH_PALETTES.light)}}}
|
|
26
|
+
.bms-switch,.bms-note{font-family:var(--barmark-label-font,system-ui,-apple-system,"Segoe UI",sans-serif)}
|
|
27
|
+
.bms-switch{display:inline-flex;margin:0 0 .5rem;border:1px solid var(--bms-rule);border-radius:.4rem;overflow:hidden}
|
|
28
|
+
.bms-switch button{font:inherit;color:var(--bms-ink);background:transparent;border:0;padding:.25rem .75rem;cursor:pointer}
|
|
11
29
|
.bms-switch button[aria-checked="true"]{font-weight:bold;text-decoration:underline}
|
|
12
30
|
.bms-switch button:focus-visible{outline:2px solid currentColor;outline-offset:-2px}
|
|
13
31
|
.bms-switch button[aria-disabled="true"]{opacity:.5;cursor:not-allowed}
|
|
14
|
-
.bms-note{margin:0 0 .5rem;font-size:.875em;color:var(--
|
|
32
|
+
.bms-note{margin:0 0 .5rem;font-size:.875em;color:var(--bms-ink)}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barmark/score",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Show a barmark chord chart as a full engraved score: MusicXML from @barmark/musicxml, engraved by Verovio (LGPL-3.0, a dependency loaded unchanged).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"url": "https://github.com/kevinpeckham/barmark/issues"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@barmark/musicxml": "^0.7.
|
|
52
|
+
"@barmark/musicxml": "^0.7.2",
|
|
53
53
|
"@barmark/render": "^0.17.1",
|
|
54
54
|
"barmark": "^0.21.0",
|
|
55
55
|
"verovio": "^6.4.1"
|