@barmark/score 0.3.0 → 0.5.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 +94 -1
- package/README.md +126 -26
- package/dist/download.d.ts +6 -4
- package/dist/download.js +8 -5
- package/dist/element.js +39 -11
- package/dist/engine.d.ts +6 -2
- package/dist/engine.js +25 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/verovio.d.ts +22 -0
- package/dist/verovio.js +29 -0
- package/dist/wasm.d.ts +54 -0
- package/dist/wasm.js +42 -0
- package/dist/worker.d.ts +15 -5
- package/dist/worker.js +80 -22
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,97 @@ package uses [semantic versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.5.0] - 2026-11-10
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **`verovio-wasm-integrity`**: the SRI digest of the `.wasm` beside a
|
|
14
|
+
`verovio-url` that loads its WebAssembly as a separate file, as
|
|
15
|
+
`@barmark/engraver` does. The worker gives Emscripten an
|
|
16
|
+
`instantiateWasm` hook that downloads the `.wasm` from beside the
|
|
17
|
+
`verovio-url` (never from the module's `blob:` URL), with progress,
|
|
18
|
+
checks its digest and only then compiles it. A missing or mismatched
|
|
19
|
+
`.wasm` fails at once, raced against Verovio's factory, rather than
|
|
20
|
+
hanging to the 60-second load deadline, and with `verovio-integrity`
|
|
21
|
+
set falls back to the package's own copy with a warning. With
|
|
22
|
+
`verovio-integrity` set, a separate `.wasm` needs this digest too
|
|
23
|
+
("verovio-wasm-integrity is needed for a Verovio that loads a separate
|
|
24
|
+
.wasm"); a wasm digest without a module digest is supported. A
|
|
25
|
+
malformed one is refused, and changing it clears a failure. Stock
|
|
26
|
+
Verovio ignores it. Two elements share one engine: the first source
|
|
27
|
+
loaded wins, and a second element's different digests are ignored.
|
|
28
|
+
- **`ENGRAVER_CDN_URL`, `ENGRAVER_CDN_INTEGRITY`,
|
|
29
|
+
`ENGRAVER_WASM_INTEGRITY`**: `@barmark/engraver` 0.1.1, the smaller
|
|
30
|
+
Verovio 6.4.1 build made by barmark, on jsDelivr, with its module's and
|
|
31
|
+
its `.wasm`'s sha384, for `verovio-url`, `verovio-integrity` and
|
|
32
|
+
`verovio-wasm-integrity`. Opt-in: they are literals, so a site that
|
|
33
|
+
never uses the build never installs it. The build leaves out what this
|
|
34
|
+
package never asks Verovio for (fonts other than Leipzig, footers,
|
|
35
|
+
tablature tunings, `.mxl`); the README says how to load it, with the
|
|
36
|
+
Content-Security-Policy it needs.
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
- **A Verovio from `verovio-url` must match the toolkit's version**
|
|
41
|
+
(`VEROVIO_VERSION`, 6.4.1): any other now fails to load, or, with
|
|
42
|
+
`verovio-integrity` set, falls back to the package's own copy with a
|
|
43
|
+
warning, where it was loaded anyway.
|
|
44
|
+
- **A download's progress is measured against the file its digest
|
|
45
|
+
names**: Verovio's module, or `@barmark/engraver`'s module or `.wasm`.
|
|
46
|
+
A compressed `verovio-url` download with no digest, or a digest of no
|
|
47
|
+
build this package knows, shows the bar without a percentage instead of
|
|
48
|
+
being measured against Verovio's 7.4 MB. With
|
|
49
|
+
`verovio-wasm-integrity`, the `.wasm` is the download measured, so the
|
|
50
|
+
bar runs to 100% once.
|
|
51
|
+
|
|
52
|
+
### Technical
|
|
53
|
+
|
|
54
|
+
- **The browser suite loads `@barmark/engraver`** from
|
|
55
|
+
`packages/engraver/dist` (compiled on the VM, or CI's `engraver-dist`
|
|
56
|
+
artifact): the build used with both digests and its `.wasm` measured,
|
|
57
|
+
a `.wasm` with a flipped byte, a missing `.wasm` (falling back in
|
|
58
|
+
seconds), a module digest without a wasm digest, and stock Verovio
|
|
59
|
+
with a wasm digest.
|
|
60
|
+
|
|
61
|
+
## [0.4.0] - 2026-11-10
|
|
62
|
+
|
|
63
|
+
### Added
|
|
64
|
+
|
|
65
|
+
- **The grid takes `columns`** (`@barmark/render`'s `columns: "shared" |
|
|
66
|
+
"row"`): `<barmark-score>` observes the `columns` attribute and redraws
|
|
67
|
+
its grid, and `renderScoreHtml` passes the option through. With
|
|
68
|
+
`columns="row"` each row of the grid sizes its own bars; the score view
|
|
69
|
+
is unchanged.
|
|
70
|
+
- **A `scoreerror` event says why the score couldn't be drawn.** Whenever
|
|
71
|
+
`<barmark-score>` shows "The score couldn't be drawn", it fires
|
|
72
|
+
`scoreerror` (`bubbles`, `composed`) with `detail: { reason }`, the
|
|
73
|
+
reason its console warning gives: Verovio failing to load or engrave, a
|
|
74
|
+
refused `verovio-url` or `verovio-integrity`, a `src` that could not be
|
|
75
|
+
loaded, or an engraving that is not clean SVG. Once per failure; a
|
|
76
|
+
retry the chart or a new URL enables fires again if it fails.
|
|
77
|
+
|
|
78
|
+
### Changed
|
|
79
|
+
|
|
80
|
+
- **Requires `barmark` 0.23.0, `@barmark/render` 0.19.0** (the tempo
|
|
81
|
+
beat, the `rehearsal-letters` rule) **and `@barmark/musicxml` 0.9.0**
|
|
82
|
+
(an ending across lines), whose minor releases a caret range would not
|
|
83
|
+
reach.
|
|
84
|
+
- **The grid follows `@barmark/render`'s new `rehearsal-letters` rule**:
|
|
85
|
+
no letters beside a chart's own rehearsal marks (`@A`), so the grid's
|
|
86
|
+
headings no longer show two marks, matching the score, which draws only
|
|
87
|
+
the chart's own.
|
|
88
|
+
|
|
89
|
+
### Fixed
|
|
90
|
+
|
|
91
|
+
- **The grid's tempo shows the beat it counts**, from `@barmark/render`:
|
|
92
|
+
"♩. = 40" in 6/8, 9/8 and 12/8, where it showed "♩ = 40".
|
|
93
|
+
|
|
94
|
+
### Technical
|
|
95
|
+
|
|
96
|
+
- **The README says when Vite needs `worker: { format: "es" }`**: on Vite 8
|
|
97
|
+
too, with `verovio-url`, or the worker inlines Verovio's fallback copy
|
|
98
|
+
and a reader downloads Verovio twice.
|
|
99
|
+
|
|
9
100
|
## [0.3.0] - 2026-11-10
|
|
10
101
|
|
|
11
102
|
### Added
|
|
@@ -187,7 +278,9 @@ First release.
|
|
|
187
278
|
needs no config; Vite 7 needs `optimizeDeps.exclude` and
|
|
188
279
|
`worker.format: "es"`.
|
|
189
280
|
|
|
190
|
-
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/score-v0.
|
|
281
|
+
[Unreleased]: https://github.com/kevinpeckham/barmark/compare/score-v0.5.0...HEAD
|
|
282
|
+
[0.5.0]: https://github.com/kevinpeckham/barmark/compare/score-v0.4.0...score-v0.5.0
|
|
283
|
+
[0.4.0]: https://github.com/kevinpeckham/barmark/compare/score-v0.3.0...score-v0.4.0
|
|
191
284
|
[0.3.0]: https://github.com/kevinpeckham/barmark/compare/score-v0.2.0...score-v0.3.0
|
|
192
285
|
[0.2.0]: https://github.com/kevinpeckham/barmark/compare/score-v0.1.1...score-v0.2.0
|
|
193
286
|
[0.1.1]: https://github.com/kevinpeckham/barmark/compare/score-v0.1.0...score-v0.1.1
|
package/README.md
CHANGED
|
@@ -46,15 +46,18 @@ technology the score is one image named for the chart's title, or "Score".
|
|
|
46
46
|
|
|
47
47
|
| Attribute (property) | |
|
|
48
48
|
|---|---|
|
|
49
|
-
| `src`, `theme`, `bar-numbers`, `rehearsal-letters`, `numerals`, `wrap`, `show-part` | the grid's own, as in [`@barmark/render`](../render/README.md#options-and-attributes) |
|
|
49
|
+
| `src`, `theme`, `bar-numbers`, `rehearsal-letters`, `numerals`, `wrap`, `show-part`, `columns` | the grid's own, as in [`@barmark/render`](../render/README.md#options-and-attributes) |
|
|
50
50
|
| `view` (`view`) | `"grid"` (default) or `"score"`; the view being shown. Set before the chart arrives, `"score"` waits for it |
|
|
51
51
|
| `verovio-url` | where to load Verovio from (below) |
|
|
52
52
|
| `verovio-integrity` | the SRI digest (`sha384-…`) the `verovio-url` copy must have; on a mismatch the package's own copy loads (below) |
|
|
53
|
+
| `verovio-wasm-integrity` | the SRI digest of the `.wasm` beside a `verovio-url` that loads one, such as `@barmark/engraver` (below) |
|
|
53
54
|
| `preload` | `"none"` (default), `"intent"` or `"idle"`: when to start loading Verovio (below) |
|
|
54
55
|
|
|
55
56
|
The `text` property is the chart's text (`null` goes back to `src` or the
|
|
56
57
|
script child). The element fires a `viewchange` event, with
|
|
57
|
-
`detail.view`, whenever the view changes, from the switch or from script
|
|
58
|
+
`detail.view`, whenever the view changes, from the switch or from script,
|
|
59
|
+
and a `scoreerror` event, with `detail.reason`, when the score can't be
|
|
60
|
+
drawn (below).
|
|
58
61
|
|
|
59
62
|
```js
|
|
60
63
|
const score = document.querySelector("barmark-score");
|
|
@@ -69,16 +72,21 @@ The engine runs in a module Worker, created as
|
|
|
69
72
|
That is the pattern Vite and webpack follow, so a bundler finds the worker
|
|
70
73
|
and Verovio for you.
|
|
71
74
|
|
|
72
|
-
Vite 8 (and Vite+)
|
|
73
|
-
|
|
74
|
-
the
|
|
75
|
-
|
|
75
|
+
Vite 8 (and Vite+) draws a score with no config, in `vite dev` or a
|
|
76
|
+
build. But Vite builds workers as `iife` by default, which cannot split, so
|
|
77
|
+
the worker's fallback copy of Verovio is inlined into it: with
|
|
78
|
+
`verovio-url`, a reader then downloads Verovio twice, inside the worker and
|
|
79
|
+
from your URL. Set `worker: { format: "es" }` and Verovio becomes a chunk
|
|
80
|
+
of its own, fetched only if your URL fails. Vite 7 needs that line in any
|
|
81
|
+
case (an `iife` worker cannot load Verovio on demand) and one more: its dev
|
|
82
|
+
pre-bundler moves the element away from the worker and the font it finds
|
|
83
|
+
by URL.
|
|
76
84
|
|
|
77
85
|
```js
|
|
78
|
-
// vite.config.js
|
|
86
|
+
// vite.config.js
|
|
79
87
|
export default {
|
|
80
|
-
|
|
81
|
-
|
|
88
|
+
worker: { format: "es" }, // Vite 8 with verovio-url; Vite 7 always
|
|
89
|
+
optimizeDeps: { exclude: ["@barmark/score"] }, // Vite 7 only (harmless on Vite 8)
|
|
82
90
|
};
|
|
83
91
|
```
|
|
84
92
|
|
|
@@ -89,9 +97,14 @@ then point at a Verovio module you host (for example
|
|
|
89
97
|
`verovio/dist/verovio-module.mjs` from the `verovio` package) instead of
|
|
90
98
|
bundling the 7 MB inside the worker; it only changes where that module
|
|
91
99
|
comes from. The URL is resolved against the page and must be http(s);
|
|
92
|
-
anything else is refused and the score is not drawn.
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
anything else is refused and the score is not drawn. Its Verovio must be
|
|
101
|
+
the version this package's toolkit is (`VEROVIO_VERSION`, 6.4.1): any
|
|
102
|
+
other fails to load, or, with `verovio-integrity` set, falls back to the
|
|
103
|
+
package's own copy with a warning. The first `verovio-url` that loads wins
|
|
104
|
+
for the whole page: every element shares one worker, so a later or
|
|
105
|
+
different URL is not loaded, and a second element's different
|
|
106
|
+
`verovio-integrity` or `verovio-wasm-integrity` is ignored too: the
|
|
107
|
+
engine keeps the source it loaded first, digests and all. The worker downloads a
|
|
95
108
|
`verovio-url` with `fetch` (with or without `verovio-integrity`) and
|
|
96
109
|
imports it from a `blob:` URL, so a worker served with its own
|
|
97
110
|
Content-Security-Policy needs the module's origin (a CDN's, say) in
|
|
@@ -116,11 +129,17 @@ The download can be measured when the worker fetches Verovio itself,
|
|
|
116
129
|
which it does for a `verovio-url`: it reads the response as it arrives,
|
|
117
130
|
then imports the module from a `blob:` URL. A compressed response (gzip,
|
|
118
131
|
brotli) has a `Content-Length` that is the compressed size, while the
|
|
119
|
-
bytes read are decoded, so they are measured against
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
132
|
+
bytes read are decoded, so they are measured against the known decoded
|
|
133
|
+
size of the file its declared digest names instead: Verovio's module
|
|
134
|
+
(`VEROVIO_MODULE_BYTES`) for `VEROVIO_CDN_INTEGRITY`, or
|
|
135
|
+
`@barmark/engraver`'s module or `.wasm` for its digests. An uncompressed
|
|
136
|
+
one is measured against its `Content-Length` (a cross-origin server that
|
|
137
|
+
does not expose `Content-Encoding` is taken as compressed when its length
|
|
138
|
+
is short of that size). A compressed one with no digest, or a digest of
|
|
139
|
+
no build this package knows, shows the bar without a percentage. With
|
|
140
|
+
`verovio-wasm-integrity`, the module's small download is shown without a
|
|
141
|
+
percentage and the `.wasm`'s is the one measured, so the bar runs to
|
|
142
|
+
100% once.
|
|
124
143
|
The package's own copy, without `verovio-url`, is loaded by your
|
|
125
144
|
bundler, so its download is shown without a percentage; so is a worker
|
|
126
145
|
bundled with Verovio inside it, whose download is the worker's own
|
|
@@ -155,6 +174,66 @@ Verovio once for that site whichever URL it comes from. What a CDN gives
|
|
|
155
174
|
is delivery from an edge near the reader and the 2.4 MB kept off your own
|
|
156
175
|
server.
|
|
157
176
|
|
|
177
|
+
### The lighter build (`@barmark/engraver`)
|
|
178
|
+
|
|
179
|
+
[`@barmark/engraver`](../engraver/) is a modified, smaller build of the
|
|
180
|
+
same Verovio 6.4.1, made by barmark for this package: about 3 MB where
|
|
181
|
+
stock is about 7 MB, checked before each release to draw SVG byte for
|
|
182
|
+
byte the same as stock over a corpus of charts. Its WebAssembly is a
|
|
183
|
+
separate file, `verovio-module.wasm` beside the module, so it takes a
|
|
184
|
+
digest of its own, `verovio-wasm-integrity`. On jsDelivr:
|
|
185
|
+
|
|
186
|
+
```html
|
|
187
|
+
<barmark-score
|
|
188
|
+
verovio-url="https://cdn.jsdelivr.net/npm/@barmark/engraver@0.1.1/dist/verovio-module.mjs"
|
|
189
|
+
verovio-integrity="sha384-klTppHZB0IPzdIOfSXNr8CbdhJU+1yp5eltjmgp8W3E8uhht5dlRy1mwrBSnmKJO"
|
|
190
|
+
verovio-wasm-integrity="sha384-cBBw1xx6xHEb/I7QDrSFDgImfzzvZVvwru055NG6QbY1zHI/FFLQHjlKdtH7pr5i"
|
|
191
|
+
src="/charts/peaceful-dreams.chart.md"
|
|
192
|
+
></barmark-score>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
The package exports the three as `ENGRAVER_CDN_URL`,
|
|
196
|
+
`ENGRAVER_CDN_INTEGRITY` and `ENGRAVER_WASM_INTEGRITY`. They are written
|
|
197
|
+
into this package, so a site that never uses the lighter build never
|
|
198
|
+
installs it.
|
|
199
|
+
|
|
200
|
+
The worker downloads the module and checks it against
|
|
201
|
+
`verovio-integrity`, then downloads the `.wasm` from beside the
|
|
202
|
+
`verovio-url` (never from the `blob:` URL the module is imported from),
|
|
203
|
+
checks it against `verovio-wasm-integrity` and only then compiles it. A
|
|
204
|
+
module that does not fit its digest, a `.wasm` that does not fit its own,
|
|
205
|
+
a `.wasm` that is missing or fails to download, or a Verovio other than
|
|
206
|
+
6.4.1 falls back to the package's own copy, once, with a warning naming
|
|
207
|
+
the reason, as for any `verovio-url` with `verovio-integrity`. A failed
|
|
208
|
+
`.wasm` falls back as soon as it fails, not at the 60-second load
|
|
209
|
+
deadline.
|
|
210
|
+
|
|
211
|
+
**`verovio-wasm-integrity` is required whenever `verovio-integrity` is
|
|
212
|
+
set for a build that loads a separate `.wasm`**: a module digest alone
|
|
213
|
+
would leave the `.wasm` unchecked, so without it the load fails with
|
|
214
|
+
"verovio-wasm-integrity is needed for a Verovio that loads a separate
|
|
215
|
+
.wasm" and the package's own copy loads instead. A wasm digest without a
|
|
216
|
+
module digest is supported: the `.wasm` is checked and the module is not,
|
|
217
|
+
and, as for any `verovio-url` without `verovio-integrity`, there is no
|
|
218
|
+
fallback, so a mismatch is a score that can't be drawn. A malformed
|
|
219
|
+
`verovio-wasm-integrity` is refused like a malformed `verovio-integrity`.
|
|
220
|
+
Stock Verovio, which embeds its WebAssembly, ignores
|
|
221
|
+
`verovio-wasm-integrity` and loads as usual, but the progress shows less:
|
|
222
|
+
the digest marks the `.wasm` as the download to measure, and stock never
|
|
223
|
+
fetches one, so its module's download is shown without a percentage and
|
|
224
|
+
"Preparing…" is never announced. Set `verovio-wasm-integrity` only with a
|
|
225
|
+
build that loads a separate `.wasm`.
|
|
226
|
+
|
|
227
|
+
A page with a Content-Security-Policy needs the CDN's origin in
|
|
228
|
+
`connect-src` (the worker fetches both files), `blob:` in `script-src`
|
|
229
|
+
(the module is imported from a `blob:` URL) and `'wasm-unsafe-eval'` in
|
|
230
|
+
`script-src`, which stock Verovio needs as well.
|
|
231
|
+
|
|
232
|
+
The build leaves out what this package never asks Verovio for: only the
|
|
233
|
+
Leipzig font, no footer, no tablature or staff tunings, and no compressed
|
|
234
|
+
MusicXML (`.mxl`). If you pass your own MusicXML to `engraveXml` with a
|
|
235
|
+
toolkit from `@barmark/engraver`, see [its limits](../engraver/README.md#limits).
|
|
236
|
+
|
|
158
237
|
### Preloading
|
|
159
238
|
|
|
160
239
|
`preload` starts loading Verovio before the first press, so the score
|
|
@@ -174,10 +253,28 @@ one load every element on the page uses, and asking twice does nothing.
|
|
|
174
253
|
If Verovio fails to load, or rejects the MusicXML, or the chart will not
|
|
175
254
|
export or is too large to draw (see "Engraving directly"), or Verovio
|
|
176
255
|
takes over 60 seconds to load or 20 seconds to engrave, the grid stays and
|
|
177
|
-
a note by the switch says "The score couldn't be drawn". The
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
256
|
+
a note by the switch says "The score couldn't be drawn". The same happens
|
|
257
|
+
when `verovio-url`, `verovio-integrity` or `verovio-wasm-integrity` is
|
|
258
|
+
refused, when the chart's `src` could not be loaded, or when the
|
|
259
|
+
engraving is not clean SVG. The Score radio is disabled until the
|
|
260
|
+
chart (`text`, `src` or the script child), `verovio-url`,
|
|
261
|
+
`verovio-integrity` or `verovio-wasm-integrity` changes.
|
|
262
|
+
|
|
263
|
+
The reason goes to the console as a warning, and the element fires a
|
|
264
|
+
`scoreerror` event (`bubbles`, `composed`) whose `detail.reason` is the
|
|
265
|
+
same string, so a page can show or log it:
|
|
266
|
+
|
|
267
|
+
```js
|
|
268
|
+
score.addEventListener("scoreerror", (e) => report(e.detail.reason));
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
It fires once per failure, as the note appears, after the grid is shown
|
|
272
|
+
again (and after the `viewchange` back to the grid, when the score was
|
|
273
|
+
being shown). Pressing the disabled Score radio fires nothing; once a
|
|
274
|
+
change enables it, a score that fails again fires again. A score an
|
|
275
|
+
element no longer wants (its chart or width changed) is dropped, not
|
|
276
|
+
failed, and fires nothing: it is cut off after three seconds if the worker
|
|
277
|
+
is already engraving it.
|
|
181
278
|
|
|
182
279
|
## On the server
|
|
183
280
|
|
|
@@ -229,14 +326,17 @@ is the export unchanged.
|
|
|
229
326
|
|
|
230
327
|
This package is MIT. It uses [Verovio](https://github.com/rism-digital/verovio),
|
|
231
328
|
which is LGPL-3.0-only, as an ordinary npm dependency, loaded unchanged at
|
|
232
|
-
run time
|
|
329
|
+
run time, or, if you choose it, the modified build `@barmark/engraver`
|
|
330
|
+
(LGPL-3.0-only, its source published with each release); its code is
|
|
331
|
+
never copied into this package. barmark's own code
|
|
233
332
|
stays MIT. Verovio © Laurent Pugin and others; its licence text is
|
|
234
333
|
[COPYING.LESSER](https://github.com/rism-digital/verovio/blob/develop/COPYING.LESSER).
|
|
235
334
|
|
|
236
335
|
A site that bundles the worker ships Verovio inside its bundle. Keeping
|
|
237
336
|
Verovio a separate file (through `verovio-url`, or the bundler's own
|
|
238
337
|
chunk) and keeping its notice is the easy way to meet the LGPL. If it is
|
|
239
|
-
bundled into one file with the worker instead (Vite
|
|
240
|
-
|
|
241
|
-
link your site's source so a visitor
|
|
242
|
-
barmark.dev does all three in its
|
|
338
|
+
bundled into one file with the worker instead (Vite's default `iife`
|
|
339
|
+
worker format does this), credit it with its copyright and licence, host
|
|
340
|
+
or link the LGPL and GPL texts, and link your site's source so a visitor
|
|
341
|
+
can rebuild it with another Verovio; barmark.dev does all three in its
|
|
342
|
+
footer. This is not legal advice.
|
package/dist/download.d.ts
CHANGED
|
@@ -34,10 +34,12 @@ export declare function checkIntegrity(bytes: BufferSource, integrity: string):
|
|
|
34
34
|
export type FetchModuleOptions = {
|
|
35
35
|
fetch: (url: string) => Promise<Response>;
|
|
36
36
|
onProgress: (d: Download) => void;
|
|
37
|
-
/** The SRI digest the
|
|
38
|
-
integrity?: string;
|
|
39
|
-
/** The
|
|
40
|
-
expected?: number;
|
|
37
|
+
/** The SRI digest the file must have; checked before it is returned. */
|
|
38
|
+
integrity?: string | undefined;
|
|
39
|
+
/** The file's decoded size, when known. */
|
|
40
|
+
expected?: number | undefined;
|
|
41
41
|
};
|
|
42
|
+
/** Downloads `url` with progress, its digest checked (when given) before the bytes are returned. */
|
|
43
|
+
export declare function fetchBytes(url: string, options: FetchModuleOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
42
44
|
/** Downloads the module at `url` with progress, as a JavaScript blob ready to import from an object URL. */
|
|
43
45
|
export declare function fetchModule(url: string, options: FetchModuleOptions): Promise<Blob>;
|
package/dist/download.js
CHANGED
|
@@ -88,8 +88,8 @@ function throttled(report) {
|
|
|
88
88
|
report(shown);
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
/** Downloads
|
|
92
|
-
export async function
|
|
91
|
+
/** Downloads `url` with progress, its digest checked (when given) before the bytes are returned. */
|
|
92
|
+
export async function fetchBytes(url, options) {
|
|
93
93
|
const response = await options.fetch(url);
|
|
94
94
|
if (!response.ok)
|
|
95
95
|
throw new Error(`${response.status} ${response.statusText}`.trim());
|
|
@@ -104,7 +104,7 @@ export async function fetchModule(url, options) {
|
|
|
104
104
|
done += r.value.byteLength;
|
|
105
105
|
report(meter(done), done);
|
|
106
106
|
}
|
|
107
|
-
// One copy of the
|
|
107
|
+
// One copy of the file: the chunks are joined and dropped before it is digested.
|
|
108
108
|
const bytes = new Uint8Array(done);
|
|
109
109
|
let at = 0;
|
|
110
110
|
for (const chunk of chunks.splice(0)) {
|
|
@@ -113,6 +113,9 @@ export async function fetchModule(url, options) {
|
|
|
113
113
|
}
|
|
114
114
|
if (options.integrity !== undefined && !(await checkIntegrity(bytes, options.integrity)))
|
|
115
115
|
throw new Error(`${url} does not match its integrity digest`);
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
return bytes;
|
|
117
|
+
}
|
|
118
|
+
/** Downloads the module at `url` with progress, as a JavaScript blob ready to import from an object URL. */
|
|
119
|
+
export async function fetchModule(url, options) {
|
|
120
|
+
return new Blob([await fetchBytes(url, options)], { type: "text/javascript" });
|
|
118
121
|
}
|
package/dist/element.js
CHANGED
|
@@ -84,8 +84,11 @@ function takeEarlyText(el) {
|
|
|
84
84
|
/** The grid's attributes, as `<barmark-chart>` observes them, then the score's own. */
|
|
85
85
|
const OBSERVED = [
|
|
86
86
|
...["src", "theme", "bar-numbers", "rehearsal-letters", "numerals", "wrap", "show-part"],
|
|
87
|
-
|
|
87
|
+
"columns",
|
|
88
|
+
...["view", "verovio-url", "verovio-integrity", "verovio-wasm-integrity", "preload"],
|
|
88
89
|
];
|
|
90
|
+
/** The attributes that say where Verovio comes from: a change clears a failure. */
|
|
91
|
+
const VEROVIO_ATTRIBUTES = new Set(["verovio-url", "verovio-integrity", "verovio-wasm-integrity"]);
|
|
89
92
|
/** With no `requestIdleCallback`, how long after connecting `preload="idle"` starts the load. */
|
|
90
93
|
const IDLE_FALLBACK_MS = 500;
|
|
91
94
|
/** Whether the reader asked to save data, or is on a 2G line: `preload="idle"` waits for intent there. */
|
|
@@ -101,6 +104,21 @@ const radioOf = (target) => target?.closest?.("[data-view]") ?? null;
|
|
|
101
104
|
const same = (a, b) => a !== null && a.text === b.text && Math.abs(a.width - b.width) <= SLACK;
|
|
102
105
|
const URL_REASON = "verovio-url must be an http(s) URL";
|
|
103
106
|
const INTEGRITY_REASON = "verovio-integrity must be one sha256-, sha384- or sha512- digest";
|
|
107
|
+
const WASM_INTEGRITY_REASON = "verovio-wasm-integrity must be one sha256-, sha384- or sha512- digest";
|
|
108
|
+
/** The engine call for `verovio`'s digests (only those given), hearing its status on `onStatus`. */
|
|
109
|
+
function callOf({ integrity, wasmIntegrity }, onStatus) {
|
|
110
|
+
return {
|
|
111
|
+
onStatus,
|
|
112
|
+
...(integrity === undefined ? {} : { integrity }),
|
|
113
|
+
...(wasmIntegrity === undefined ? {} : { wasmIntegrity }),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** A digest attribute: undefined when absent, null when malformed, else trimmed. */
|
|
117
|
+
function digest(value) {
|
|
118
|
+
if (value === null)
|
|
119
|
+
return undefined;
|
|
120
|
+
return isIntegrity(value) ? value.trim() : null;
|
|
121
|
+
}
|
|
104
122
|
/** `verovio-url` resolved against the page: undefined when absent, null unless http(s). */
|
|
105
123
|
function verovioHref(value, base) {
|
|
106
124
|
if (value === null)
|
|
@@ -170,7 +188,7 @@ function defineElement() {
|
|
|
170
188
|
if (!this.isConnected || old === value)
|
|
171
189
|
return;
|
|
172
190
|
// A new URL may be the fix: the Score radio works again, as after a new chart.
|
|
173
|
-
if (name
|
|
191
|
+
if (VEROVIO_ATTRIBUTES.has(name))
|
|
174
192
|
this.#clearFailure();
|
|
175
193
|
else if (name === "preload")
|
|
176
194
|
this.#preloadChanged();
|
|
@@ -338,19 +356,25 @@ function defineElement() {
|
|
|
338
356
|
if (source === null)
|
|
339
357
|
return;
|
|
340
358
|
this.#preloaded = true;
|
|
341
|
-
loadEngine().then((e) => e.preload(source.url, source.integrity), () => { });
|
|
359
|
+
loadEngine().then((e) => e.preload(source.url, source.integrity, source.wasmIntegrity), () => { });
|
|
342
360
|
}
|
|
343
|
-
/**
|
|
361
|
+
/**
|
|
362
|
+
* Where Verovio comes from, or why not when `verovio-url` or a digest is
|
|
363
|
+
* refused. The digests are read only with a `verovio-url`.
|
|
364
|
+
*/
|
|
344
365
|
#verovio() {
|
|
345
366
|
const url = verovioHref(this.getAttribute("verovio-url"), this.ownerDocument.baseURI);
|
|
346
367
|
if (url === null)
|
|
347
368
|
return { refused: URL_REASON };
|
|
348
|
-
|
|
369
|
+
if (url === undefined)
|
|
370
|
+
return { url, integrity: undefined, wasmIntegrity: undefined };
|
|
371
|
+
const integrity = digest(this.getAttribute("verovio-integrity"));
|
|
349
372
|
if (integrity === null)
|
|
350
|
-
return {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
373
|
+
return { refused: INTEGRITY_REASON };
|
|
374
|
+
const wasmIntegrity = digest(this.getAttribute("verovio-wasm-integrity"));
|
|
375
|
+
if (wasmIntegrity === null)
|
|
376
|
+
return { refused: WASM_INTEGRITY_REASON };
|
|
377
|
+
return { url, integrity, wasmIntegrity };
|
|
354
378
|
}
|
|
355
379
|
#source() {
|
|
356
380
|
const v = this.#verovio();
|
|
@@ -443,7 +467,7 @@ function defineElement() {
|
|
|
443
467
|
if (pane && this.#revealed === null)
|
|
444
468
|
showStatus(pane, s);
|
|
445
469
|
};
|
|
446
|
-
const call = verovio
|
|
470
|
+
const call = callOf(verovio, onStatus);
|
|
447
471
|
const run = (e) => e.engrave(this, want.text, want.width, verovio.url, call);
|
|
448
472
|
// A loaded engine is asked at once, so its status (not a provisional one) is the first drawn.
|
|
449
473
|
const request = loaded ? run(loaded) : loadEngine().then(run);
|
|
@@ -495,7 +519,10 @@ function defineElement() {
|
|
|
495
519
|
pane.toggleAttribute("hidden", false);
|
|
496
520
|
grid?.toggleAttribute("hidden", true);
|
|
497
521
|
}
|
|
498
|
-
/**
|
|
522
|
+
/**
|
|
523
|
+
* The score could not be drawn: the grid again, a note by the switch, Score
|
|
524
|
+
* disabled, and a `scoreerror` event saying why, once per failure.
|
|
525
|
+
*/
|
|
499
526
|
#fail(reason) {
|
|
500
527
|
console.warn(`<barmark-score>: the score couldn't be drawn: ${reason}`);
|
|
501
528
|
this.#failed = true;
|
|
@@ -519,6 +546,7 @@ function defineElement() {
|
|
|
519
546
|
this.#showGrid();
|
|
520
547
|
if (this.view === "score")
|
|
521
548
|
this.view = "grid";
|
|
549
|
+
this.dispatchEvent(new CustomEvent("scoreerror", { detail: { reason }, bubbles: true, composed: true }));
|
|
522
550
|
}
|
|
523
551
|
#clearFailure() {
|
|
524
552
|
if (!this.#failed)
|
package/dist/engine.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ import type { Download } from "./download.js";
|
|
|
7
7
|
export type VerovioSource = {
|
|
8
8
|
verovioUrl?: string;
|
|
9
9
|
verovioIntegrity?: string;
|
|
10
|
+
/** The `.wasm`'s digest, for a Verovio that loads a separate one (`@barmark/engraver`). */
|
|
11
|
+
verovioWasmIntegrity?: string;
|
|
10
12
|
};
|
|
11
13
|
/**
|
|
12
14
|
* What a page asks the worker for: one chart, laid out for a width; or,
|
|
@@ -58,6 +60,8 @@ export type EngineStatus = LoadStatus | {
|
|
|
58
60
|
export type EngraveCall = {
|
|
59
61
|
/** The SRI digest (`sha384-…`) the `verovioUrl` copy must have; on a mismatch the package's own loads. */
|
|
60
62
|
integrity?: string;
|
|
63
|
+
/** The SRI digest the `.wasm` beside a `verovioUrl` copy must have, for a Verovio that loads a separate one (`@barmark/engraver`). */
|
|
64
|
+
wasmIntegrity?: string;
|
|
61
65
|
/** Hears the engine's status now, and as it changes, until the request settles. */
|
|
62
66
|
onStatus?: (status: EngineStatus) => void;
|
|
63
67
|
};
|
|
@@ -82,10 +86,10 @@ export type Engine = {
|
|
|
82
86
|
engrave(key: object, text: string, width: number, verovioUrl?: string, call?: EngraveCall): Promise<EngraveReply | null>;
|
|
83
87
|
/**
|
|
84
88
|
* Starts loading Verovio (from `verovioUrl`, checked against `integrity`
|
|
85
|
-
* when given) with no job, so a first score is quicker. Does nothing if
|
|
89
|
+
* and its `.wasm` against `wasmIntegrity` when given) with no job, so a first score is quicker. Does nothing if
|
|
86
90
|
* a worker has Verovio loaded or is busy: there is one load to share.
|
|
87
91
|
*/
|
|
88
|
-
preload(verovioUrl?: string, integrity?: string): void;
|
|
92
|
+
preload(verovioUrl?: string, integrity?: string, wasmIntegrity?: string): void;
|
|
89
93
|
};
|
|
90
94
|
/** How long one job may engrave, from its worker's Verovio being ready, before the worker is cut off and the request rejects. */
|
|
91
95
|
export declare const JOB_DEADLINE_MS = 20000;
|
package/dist/engine.js
CHANGED
|
@@ -15,11 +15,17 @@ const isReady = (m) => "loaded" in m;
|
|
|
15
15
|
const isProgress = (m) => "status" in m;
|
|
16
16
|
const UNMEASURED = { phase: "download", fraction: null, bytes: null };
|
|
17
17
|
const ENGRAVING = { phase: "engrave" };
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
18
|
+
/**
|
|
19
|
+
* `source` without its absent fields (so a request carries no `verovioUrl:
|
|
20
|
+
* undefined`); with no `verovioUrl`, no digest either.
|
|
21
|
+
*/
|
|
22
|
+
const present = ({ verovioUrl, verovioIntegrity, verovioWasmIntegrity, }) => verovioUrl === undefined
|
|
23
|
+
? {}
|
|
24
|
+
: {
|
|
25
|
+
verovioUrl,
|
|
26
|
+
...(verovioIntegrity === undefined ? {} : { verovioIntegrity }),
|
|
27
|
+
...(verovioWasmIntegrity === undefined ? {} : { verovioWasmIntegrity }),
|
|
28
|
+
};
|
|
23
29
|
const clear = (job) => {
|
|
24
30
|
for (const t of job.timers)
|
|
25
31
|
clearTimeout(t);
|
|
@@ -136,11 +142,12 @@ export function createEngine(makeWorker, options = {}) {
|
|
|
136
142
|
const request = running ? undefined : waiting.shift();
|
|
137
143
|
if (!request)
|
|
138
144
|
return;
|
|
139
|
-
const { verovioUrl, verovioIntegrity, ...rest } = request;
|
|
145
|
+
const { verovioUrl, verovioIntegrity, verovioWasmIntegrity, ...rest } = request;
|
|
140
146
|
const id = rest.id;
|
|
141
147
|
running = { id, superseded: false, graceOver: false, timers: [] };
|
|
142
148
|
running.timers = [setTimeout(overdue(id, "loading Verovio"), loadDeadline)];
|
|
143
|
-
|
|
149
|
+
const asked = { verovioUrl, verovioIntegrity, verovioWasmIntegrity };
|
|
150
|
+
start().postMessage({ ...rest, ...present(loaded ?? asked) });
|
|
144
151
|
};
|
|
145
152
|
/** No one waits for `id` any more: drop it if it waits its turn, cut it off past its grace if it runs. */
|
|
146
153
|
const supersede = (id) => {
|
|
@@ -168,12 +175,16 @@ export function createEngine(makeWorker, options = {}) {
|
|
|
168
175
|
id,
|
|
169
176
|
text,
|
|
170
177
|
width,
|
|
171
|
-
...present({
|
|
178
|
+
...present({
|
|
179
|
+
verovioUrl,
|
|
180
|
+
verovioIntegrity: call.integrity,
|
|
181
|
+
verovioWasmIntegrity: call.wasmIntegrity,
|
|
182
|
+
}),
|
|
172
183
|
});
|
|
173
184
|
next();
|
|
174
185
|
});
|
|
175
186
|
},
|
|
176
|
-
preload(verovioUrl, integrity) {
|
|
187
|
+
preload(verovioUrl, integrity, wasmIntegrity) {
|
|
177
188
|
if (warm || running || waiting.length > 0)
|
|
178
189
|
return;
|
|
179
190
|
const id = ++nextId;
|
|
@@ -183,7 +194,11 @@ export function createEngine(makeWorker, options = {}) {
|
|
|
183
194
|
text: "",
|
|
184
195
|
width: 0,
|
|
185
196
|
preload: true,
|
|
186
|
-
...present({
|
|
197
|
+
...present({
|
|
198
|
+
verovioUrl,
|
|
199
|
+
verovioIntegrity: integrity,
|
|
200
|
+
verovioWasmIntegrity: wasmIntegrity,
|
|
201
|
+
}),
|
|
187
202
|
});
|
|
188
203
|
next();
|
|
189
204
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { createEngine, type Engine, type EngineOptions, type EngineStatus, type EngraveCall, type EngraveReply, engine, JOB_DEADLINE_MS, LOAD_DEADLINE_MS, type LoadStatus, type Progress, type Ready, type Reply, type Request, SUPERSEDED_GRACE_MS, type VerovioSource, type WorkerLike, type WorkerMessage, } from "./engine.js";
|
|
2
2
|
export { type Engraved, type EngraveOptions, engraveChart, engraveXml, LAYOUT, MAX_SCORE_COST, MAX_XML_LENGTH, scoreCost, } from "./engrave.js";
|
|
3
3
|
export { cleanSvg, type ScoreTheme, scorePane, scoreStyles } from "./markup.js";
|
|
4
|
-
export { VEROVIO_CDN_INTEGRITY, VEROVIO_CDN_URL, VEROVIO_MODULE_BYTES, VEROVIO_VERSION, } from "./verovio.js";
|
|
4
|
+
export { ENGRAVER_CDN_INTEGRITY, ENGRAVER_CDN_URL, ENGRAVER_WASM_INTEGRITY, VEROVIO_CDN_INTEGRITY, VEROVIO_CDN_URL, VEROVIO_MODULE_BYTES, VEROVIO_VERSION, } from "./verovio.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { createEngine, engine, JOB_DEADLINE_MS, LOAD_DEADLINE_MS, SUPERSEDED_GRACE_MS, } from "./engine.js";
|
|
2
2
|
export { engraveChart, engraveXml, LAYOUT, MAX_SCORE_COST, MAX_XML_LENGTH, scoreCost, } from "./engrave.js";
|
|
3
3
|
export { cleanSvg, scorePane, scoreStyles } from "./markup.js";
|
|
4
|
-
export { VEROVIO_CDN_INTEGRITY, VEROVIO_CDN_URL, VEROVIO_MODULE_BYTES, VEROVIO_VERSION, } from "./verovio.js";
|
|
4
|
+
export { ENGRAVER_CDN_INTEGRITY, ENGRAVER_CDN_URL, ENGRAVER_WASM_INTEGRITY, VEROVIO_CDN_INTEGRITY, VEROVIO_CDN_URL, VEROVIO_MODULE_BYTES, VEROVIO_VERSION, } from "./verovio.js";
|
package/dist/verovio.d.ts
CHANGED
|
@@ -6,3 +6,25 @@ export declare const VEROVIO_MODULE_BYTES = 7400749;
|
|
|
6
6
|
export declare const VEROVIO_CDN_URL = "https://cdn.jsdelivr.net/npm/verovio@6.4.1/dist/verovio-module.mjs";
|
|
7
7
|
/** Its digest, for `verovio-integrity`. */
|
|
8
8
|
export declare const VEROVIO_CDN_INTEGRITY = "sha384-iGNyhtxpKLNw90cjbI9ES538TJtbNZjLxsFVUuI8PwE2TTNQ+i2j9CjQnRMhZXHk";
|
|
9
|
+
/**
|
|
10
|
+
* `@barmark/engraver`, the smaller Verovio build, on jsDelivr: for `verovio-url`.
|
|
11
|
+
* These are literals, so a site that doesn't opt in never installs the build;
|
|
12
|
+
* tests/engraver.test.ts holds them to `packages/engraver/src/info.ts`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const ENGRAVER_CDN_URL = "https://cdn.jsdelivr.net/npm/@barmark/engraver@0.1.1/dist/verovio-module.mjs";
|
|
15
|
+
/** The build's module digest, for `verovio-integrity`. */
|
|
16
|
+
export declare const ENGRAVER_CDN_INTEGRITY = "sha384-klTppHZB0IPzdIOfSXNr8CbdhJU+1yp5eltjmgp8W3E8uhht5dlRy1mwrBSnmKJO";
|
|
17
|
+
/** Its `.wasm`'s digest, for `verovio-wasm-integrity`. */
|
|
18
|
+
export declare const ENGRAVER_WASM_INTEGRITY = "sha384-cBBw1xx6xHEb/I7QDrSFDgImfzzvZVvwru055NG6QbY1zHI/FFLQHjlKdtH7pr5i";
|
|
19
|
+
/** The Verovio the build is made from. */
|
|
20
|
+
export declare const ENGRAVER_VEROVIO_VERSION = "6.4.1";
|
|
21
|
+
/**
|
|
22
|
+
* True only while the build trails a newer stock `VEROVIO_VERSION`: score's
|
|
23
|
+
* decision at a stock upgrade, so it lives here, not in the engraver's API.
|
|
24
|
+
*/
|
|
25
|
+
export declare const ENGRAVER_LAGGING = false;
|
|
26
|
+
/** The build's module and `.wasm` sizes, decoded. */
|
|
27
|
+
export declare const ENGRAVER_MODULE_BYTES = 29534;
|
|
28
|
+
export declare const ENGRAVER_WASM_BYTES = 2956941;
|
|
29
|
+
/** The decoded size of a known build's file, looked up by its declared digest. */
|
|
30
|
+
export declare function knownSize(integrity: string | undefined): number | undefined;
|
package/dist/verovio.js
CHANGED
|
@@ -6,3 +6,32 @@ export const VEROVIO_MODULE_BYTES = 7_400_749;
|
|
|
6
6
|
export const VEROVIO_CDN_URL = `https://cdn.jsdelivr.net/npm/verovio@${VEROVIO_VERSION}/dist/verovio-module.mjs`;
|
|
7
7
|
/** Its digest, for `verovio-integrity`. */
|
|
8
8
|
export const VEROVIO_CDN_INTEGRITY = "sha384-iGNyhtxpKLNw90cjbI9ES538TJtbNZjLxsFVUuI8PwE2TTNQ+i2j9CjQnRMhZXHk";
|
|
9
|
+
/**
|
|
10
|
+
* `@barmark/engraver`, the smaller Verovio build, on jsDelivr: for `verovio-url`.
|
|
11
|
+
* These are literals, so a site that doesn't opt in never installs the build;
|
|
12
|
+
* tests/engraver.test.ts holds them to `packages/engraver/src/info.ts`.
|
|
13
|
+
*/
|
|
14
|
+
export const ENGRAVER_CDN_URL = "https://cdn.jsdelivr.net/npm/@barmark/engraver@0.1.1/dist/verovio-module.mjs";
|
|
15
|
+
/** The build's module digest, for `verovio-integrity`. */
|
|
16
|
+
export const ENGRAVER_CDN_INTEGRITY = "sha384-klTppHZB0IPzdIOfSXNr8CbdhJU+1yp5eltjmgp8W3E8uhht5dlRy1mwrBSnmKJO";
|
|
17
|
+
/** Its `.wasm`'s digest, for `verovio-wasm-integrity`. */
|
|
18
|
+
export const ENGRAVER_WASM_INTEGRITY = "sha384-cBBw1xx6xHEb/I7QDrSFDgImfzzvZVvwru055NG6QbY1zHI/FFLQHjlKdtH7pr5i";
|
|
19
|
+
/** The Verovio the build is made from. */
|
|
20
|
+
export const ENGRAVER_VEROVIO_VERSION = "6.4.1";
|
|
21
|
+
/**
|
|
22
|
+
* True only while the build trails a newer stock `VEROVIO_VERSION`: score's
|
|
23
|
+
* decision at a stock upgrade, so it lives here, not in the engraver's API.
|
|
24
|
+
*/
|
|
25
|
+
export const ENGRAVER_LAGGING = false;
|
|
26
|
+
/** The build's module and `.wasm` sizes, decoded. */
|
|
27
|
+
export const ENGRAVER_MODULE_BYTES = 29_534;
|
|
28
|
+
export const ENGRAVER_WASM_BYTES = 2_956_941;
|
|
29
|
+
const KNOWN_SIZES = new Map([
|
|
30
|
+
[VEROVIO_CDN_INTEGRITY, VEROVIO_MODULE_BYTES],
|
|
31
|
+
[ENGRAVER_CDN_INTEGRITY, ENGRAVER_MODULE_BYTES],
|
|
32
|
+
[ENGRAVER_WASM_INTEGRITY, ENGRAVER_WASM_BYTES],
|
|
33
|
+
]);
|
|
34
|
+
/** The decoded size of a known build's file, looked up by its declared digest. */
|
|
35
|
+
export function knownSize(integrity) {
|
|
36
|
+
return integrity === undefined ? undefined : KNOWN_SIZES.get(integrity.trim());
|
|
37
|
+
}
|
package/dist/wasm.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loading a Verovio whose `.wasm` is a separate file (`@barmark/engraver`):
|
|
3
|
+
* Emscripten's `instantiateWasm` hook, which downloads the `.wasm` itself
|
|
4
|
+
* and checks its own digest, and the race that keeps a failed download
|
|
5
|
+
* from hanging the factory. Verovio-free, like download.ts.
|
|
6
|
+
*/
|
|
7
|
+
import type { Download } from "./download.js";
|
|
8
|
+
/** The `.wasm`'s name: it always sits beside the module. */
|
|
9
|
+
export declare const WASM_FILE = "verovio-module.wasm";
|
|
10
|
+
export declare const WASM_INTEGRITY_NEEDED = "verovio-wasm-integrity is needed for a Verovio that loads a separate .wasm";
|
|
11
|
+
/**
|
|
12
|
+
* Where the `.wasm` comes from: beside `moduleUrl` (the `verovio-url`, never
|
|
13
|
+
* the blob the module is imported from), checked against `integrity`, which
|
|
14
|
+
* is `required` when the module itself was given a digest.
|
|
15
|
+
*/
|
|
16
|
+
export type WasmSource = {
|
|
17
|
+
moduleUrl: string;
|
|
18
|
+
integrity?: string;
|
|
19
|
+
required: boolean;
|
|
20
|
+
};
|
|
21
|
+
/** What the hook needs, so a test can pass fakes. */
|
|
22
|
+
export type WasmDeps = {
|
|
23
|
+
fetchBytes(url: string, o: {
|
|
24
|
+
integrity?: string | undefined;
|
|
25
|
+
expected?: number | undefined;
|
|
26
|
+
onProgress: (d: Download) => void;
|
|
27
|
+
}): Promise<Uint8Array<ArrayBuffer>>;
|
|
28
|
+
instantiate(bytes: Uint8Array<ArrayBuffer>, imports: WebAssembly.Imports): Promise<{
|
|
29
|
+
instance: WebAssembly.Instance;
|
|
30
|
+
module: WebAssembly.Module;
|
|
31
|
+
}>;
|
|
32
|
+
onProgress: (d: Download) => void;
|
|
33
|
+
};
|
|
34
|
+
/** Emscripten's hook: `{}` says `receive` will be called later. */
|
|
35
|
+
export type InstantiateWasm = (imports: WebAssembly.Imports, receive: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void) => Record<string, never>;
|
|
36
|
+
/**
|
|
37
|
+
* The hook for `source`, and `failed`, which rejects with the reason if the
|
|
38
|
+
* hook's download, digest check or instantiation fails (then `receive` is
|
|
39
|
+
* never called). `failed` never resolves, and an unused one is never an
|
|
40
|
+
* unhandled rejection.
|
|
41
|
+
*/
|
|
42
|
+
export declare function wasmHook(source: WasmSource, deps: WasmDeps): {
|
|
43
|
+
instantiateWasm: InstantiateWasm;
|
|
44
|
+
failed: Promise<never>;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Runs Emscripten's `factory` with the hook, settling as soon as the hook
|
|
48
|
+
* fails; a synchronous throw (the hook's, or the factory's) rejects too.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createWith<M>(factory: (arg: {
|
|
51
|
+
instantiateWasm: InstantiateWasm;
|
|
52
|
+
}) => Promise<M>, hook: ReturnType<typeof wasmHook>): Promise<M>;
|
|
53
|
+
/** Whether a module reporting `moduleVersion` is the toolkit's Verovio: the same, or it then a dash (a build's commit). */
|
|
54
|
+
export declare const sameVerovio: (moduleVersion: string, toolkitVersion: string) => boolean;
|
package/dist/wasm.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { knownSize } from "./verovio.js";
|
|
2
|
+
/** The `.wasm`'s name: it always sits beside the module. */
|
|
3
|
+
export const WASM_FILE = "verovio-module.wasm";
|
|
4
|
+
export const WASM_INTEGRITY_NEEDED = "verovio-wasm-integrity is needed for a Verovio that loads a separate .wasm";
|
|
5
|
+
/**
|
|
6
|
+
* The hook for `source`, and `failed`, which rejects with the reason if the
|
|
7
|
+
* hook's download, digest check or instantiation fails (then `receive` is
|
|
8
|
+
* never called). `failed` never resolves, and an unused one is never an
|
|
9
|
+
* unhandled rejection.
|
|
10
|
+
*/
|
|
11
|
+
export function wasmHook(source, deps) {
|
|
12
|
+
let fail;
|
|
13
|
+
const failed = new Promise((_, reject) => {
|
|
14
|
+
fail = reject;
|
|
15
|
+
});
|
|
16
|
+
failed.catch(() => { });
|
|
17
|
+
const instantiateWasm = (imports, receive) => {
|
|
18
|
+
const { integrity, required } = source;
|
|
19
|
+
if (required && integrity === undefined)
|
|
20
|
+
throw new Error(WASM_INTEGRITY_NEEDED);
|
|
21
|
+
// A URL resolved against the module's drops its query and hash.
|
|
22
|
+
const url = new URL(WASM_FILE, source.moduleUrl).href;
|
|
23
|
+
const options = { integrity, expected: knownSize(integrity), onProgress: deps.onProgress };
|
|
24
|
+
deps
|
|
25
|
+
.fetchBytes(url, options)
|
|
26
|
+
.then((bytes) => deps.instantiate(bytes, imports))
|
|
27
|
+
.then(({ instance, module }) => receive(instance, module))
|
|
28
|
+
.catch(fail);
|
|
29
|
+
return {};
|
|
30
|
+
};
|
|
31
|
+
return { instantiateWasm, failed };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Runs Emscripten's `factory` with the hook, settling as soon as the hook
|
|
35
|
+
* fails; a synchronous throw (the hook's, or the factory's) rejects too.
|
|
36
|
+
*/
|
|
37
|
+
export function createWith(factory, hook) {
|
|
38
|
+
const created = new Promise((resolve) => resolve(factory({ instantiateWasm: hook.instantiateWasm })));
|
|
39
|
+
return Promise.race([created, hook.failed]);
|
|
40
|
+
}
|
|
41
|
+
/** Whether a module reporting `moduleVersion` is the toolkit's Verovio: the same, or it then a dash (a build's commit). */
|
|
42
|
+
export const sameVerovio = (moduleVersion, toolkitVersion) => moduleVersion === toolkitVersion || moduleVersion.startsWith(`${toolkitVersion}-`);
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { VerovioToolkit } from "verovio/esm";
|
|
2
2
|
import { type Download } from "./download.js";
|
|
3
3
|
import type { LoadStatus, Progress, Ready, Reply, Request, VerovioSource, WorkerMessage } from "./engine.js";
|
|
4
|
+
import { type WasmSource } from "./wasm.js";
|
|
4
5
|
type Toolkit = VerovioToolkit;
|
|
5
6
|
/** Run `load` once and keep its result; a load that fails is forgotten, so the next call tries again. */
|
|
6
7
|
export declare function loadOnce<A, T>(load: (arg: A) => Promise<T>): (arg: A) => Promise<T>;
|
|
@@ -25,23 +26,32 @@ export type LoaderDeps<M, T> = {
|
|
|
25
26
|
/** Downloads `url` with progress, checked against `integrity` when given (download.ts). */
|
|
26
27
|
fetchModule(url: string, options: {
|
|
27
28
|
integrity?: string;
|
|
29
|
+
expected?: number | undefined;
|
|
28
30
|
onProgress: (d: Download) => void;
|
|
29
31
|
}): Promise<Blob>;
|
|
30
32
|
/** Imports a downloaded module. */
|
|
31
33
|
importBlob(blob: Blob): Promise<M>;
|
|
32
34
|
/** The package's own Verovio, as the bundler placed it. */
|
|
33
35
|
own(): Promise<M>;
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Instantiates the module's WebAssembly, reporting `prepare`: the
|
|
38
|
+
* toolkit. `wasm`, for a module from a URL, says where a separate
|
|
39
|
+
* `.wasm` comes from, should the module load one.
|
|
40
|
+
*/
|
|
41
|
+
instantiate(m: M, wasm: WasmSource | undefined, report: Report): Promise<T>;
|
|
42
|
+
/** The Verovio version a toolkit reports. */
|
|
43
|
+
versionOf(t: T): string;
|
|
44
|
+
/** The version of the Verovio this package's toolkit is written for. */
|
|
45
|
+
toolkitVersion: string;
|
|
36
46
|
warn(message: string): void;
|
|
37
47
|
};
|
|
38
48
|
/**
|
|
39
49
|
* Loads Verovio from `source`. The package's own copy comes through the
|
|
40
50
|
* bundler, its download unmeasured. A `verovioUrl` is downloaded here,
|
|
41
51
|
* with progress, and imported from a blob; with `verovioIntegrity` its
|
|
42
|
-
* digest is checked first, and a mismatch
|
|
43
|
-
* the package's own copy, once,
|
|
44
|
-
* the failure.
|
|
52
|
+
* digest is checked first, and a mismatch, a Verovio other than the
|
|
53
|
+
* toolkit's, or any failure falls back to the package's own copy, once,
|
|
54
|
+
* with a warning. Without one, a failure is the failure.
|
|
45
55
|
*/
|
|
46
56
|
export declare function verovioLoader<M, T>(deps: LoaderDeps<M, T>): (source: VerovioSource, report: Report) => Promise<Loaded<T>>;
|
|
47
57
|
/**
|
package/dist/worker.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as esm from "verovio/esm";
|
|
2
2
|
import { VerovioToolkit } from "verovio/esm";
|
|
3
|
-
import { fetchModule } from "./download.js";
|
|
3
|
+
import { fetchBytes, fetchModule } from "./download.js";
|
|
4
4
|
import { engraveChart } from "./engrave.js";
|
|
5
|
-
import {
|
|
5
|
+
import { knownSize, VEROVIO_VERSION } from "./verovio.js";
|
|
6
|
+
import { createWith, sameVerovio, wasmHook } from "./wasm.js";
|
|
6
7
|
// Verovio's typings omit the log switch; it is exported all the same.
|
|
7
8
|
const { enableLog, LOG_OFF } = esm;
|
|
8
9
|
/** Run `load` once and keep its result; a load that fails is forgotten, so the next call tries again. */
|
|
@@ -35,36 +36,66 @@ export function toolkitLoader(load) {
|
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
const UNMEASURED = { phase: "download", fraction: null, bytes: null };
|
|
39
|
+
/** The `.wasm` source for a module from `verovioUrl`: its digest is required when the module's is given. */
|
|
40
|
+
const wasmSource = (verovioUrl, { verovioIntegrity, verovioWasmIntegrity }) => ({
|
|
41
|
+
moduleUrl: verovioUrl,
|
|
42
|
+
...(verovioWasmIntegrity === undefined ? {} : { integrity: verovioWasmIntegrity }),
|
|
43
|
+
required: verovioIntegrity !== undefined,
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* How a module's own download reports: measured, or, when a separate
|
|
47
|
+
* `.wasm` will be measured, once as unmeasured, so the bar never runs to
|
|
48
|
+
* 100% twice.
|
|
49
|
+
*/
|
|
50
|
+
const glueProgress = (source, report) => {
|
|
51
|
+
if (source.verovioWasmIntegrity === undefined)
|
|
52
|
+
return report;
|
|
53
|
+
report(UNMEASURED);
|
|
54
|
+
return () => { };
|
|
55
|
+
};
|
|
38
56
|
/**
|
|
39
57
|
* Loads Verovio from `source`. The package's own copy comes through the
|
|
40
58
|
* bundler, its download unmeasured. A `verovioUrl` is downloaded here,
|
|
41
59
|
* with progress, and imported from a blob; with `verovioIntegrity` its
|
|
42
|
-
* digest is checked first, and a mismatch
|
|
43
|
-
* the package's own copy, once,
|
|
44
|
-
* the failure.
|
|
60
|
+
* digest is checked first, and a mismatch, a Verovio other than the
|
|
61
|
+
* toolkit's, or any failure falls back to the package's own copy, once,
|
|
62
|
+
* with a warning. Without one, a failure is the failure.
|
|
45
63
|
*/
|
|
46
64
|
export function verovioLoader(deps) {
|
|
47
|
-
const prepared = async (m, report) => {
|
|
48
|
-
report({ phase: "prepare" });
|
|
49
|
-
return deps.instantiate(m);
|
|
50
|
-
};
|
|
51
65
|
const own = async (report) => {
|
|
52
66
|
report(UNMEASURED);
|
|
53
|
-
return { toolkit: await
|
|
67
|
+
return { toolkit: await deps.instantiate(await deps.own(), undefined, report), from: {} };
|
|
68
|
+
};
|
|
69
|
+
const checked = (t) => {
|
|
70
|
+
const got = deps.versionOf(t);
|
|
71
|
+
if (!sameVerovio(got, deps.toolkitVersion))
|
|
72
|
+
throw new Error(`Verovio ${got} does not match this package's toolkit (${deps.toolkitVersion})`);
|
|
73
|
+
return t;
|
|
54
74
|
};
|
|
55
|
-
const fromUrl = async (verovioUrl,
|
|
56
|
-
const
|
|
57
|
-
const blob = await deps.fetchModule(verovioUrl,
|
|
58
|
-
|
|
75
|
+
const fromUrl = async (verovioUrl, source, report) => {
|
|
76
|
+
const { verovioIntegrity } = source;
|
|
77
|
+
const blob = await deps.fetchModule(verovioUrl, {
|
|
78
|
+
...(verovioIntegrity === undefined ? {} : { integrity: verovioIntegrity }),
|
|
79
|
+
expected: knownSize(verovioIntegrity),
|
|
80
|
+
onProgress: glueProgress(source, report),
|
|
81
|
+
});
|
|
82
|
+
const m = await deps.importBlob(blob);
|
|
83
|
+
return checked(await deps.instantiate(m, wasmSource(verovioUrl, source), report));
|
|
59
84
|
};
|
|
60
85
|
return async (source, report) => {
|
|
61
|
-
const { verovioUrl, verovioIntegrity } = source;
|
|
86
|
+
const { verovioUrl, verovioIntegrity, verovioWasmIntegrity } = source;
|
|
62
87
|
if (verovioUrl === undefined)
|
|
63
88
|
return own(report);
|
|
64
|
-
|
|
65
|
-
|
|
89
|
+
// Without a module digest, no fallback; the wasm digest is kept so a replacement worker checks it too.
|
|
90
|
+
if (verovioIntegrity === undefined) {
|
|
91
|
+
const from = {
|
|
92
|
+
verovioUrl,
|
|
93
|
+
...(verovioWasmIntegrity === undefined ? {} : { verovioWasmIntegrity }),
|
|
94
|
+
};
|
|
95
|
+
return { toolkit: await fromUrl(verovioUrl, source, report), from };
|
|
96
|
+
}
|
|
66
97
|
try {
|
|
67
|
-
return { toolkit: await fromUrl(verovioUrl,
|
|
98
|
+
return { toolkit: await fromUrl(verovioUrl, source, report), from: source };
|
|
68
99
|
}
|
|
69
100
|
catch (err) {
|
|
70
101
|
deps.warn(`<barmark-score>: Verovio from ${verovioUrl} was not used (${String(err)}); loading the package's own copy instead`);
|
|
@@ -82,21 +113,48 @@ async function importBlob(blob) {
|
|
|
82
113
|
URL.revokeObjectURL(url);
|
|
83
114
|
}
|
|
84
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Runs the module's factory, reporting `prepare`: for a module from a URL,
|
|
118
|
+
* with a hook for its `.wasm`. With the `.wasm`'s digest given, its
|
|
119
|
+
* download is the measured one, so `prepare` waits for it to arrive;
|
|
120
|
+
* otherwise (the package's own copy, or a module that ignores the hook)
|
|
121
|
+
* Verovio is preparing from the start.
|
|
122
|
+
*/
|
|
123
|
+
function createModule(m, wasm, report) {
|
|
124
|
+
const prepare = () => report({ phase: "prepare" });
|
|
125
|
+
if (wasm?.integrity === undefined)
|
|
126
|
+
prepare();
|
|
127
|
+
if (wasm === undefined)
|
|
128
|
+
return m.default();
|
|
129
|
+
const hook = wasmHook(wasm, {
|
|
130
|
+
fetchBytes: (u, o) => fetchBytes(u, { ...o, fetch: (x) => fetch(x) }),
|
|
131
|
+
instantiate: (bytes, imports) => {
|
|
132
|
+
if (wasm.integrity !== undefined)
|
|
133
|
+
prepare();
|
|
134
|
+
return WebAssembly.instantiate(bytes, imports);
|
|
135
|
+
},
|
|
136
|
+
onProgress: report,
|
|
137
|
+
});
|
|
138
|
+
return createWith(m.default, hook);
|
|
139
|
+
}
|
|
85
140
|
const toolkit = toolkitLoader(verovioLoader({
|
|
86
|
-
fetchModule: (url, options) => fetchModule(url, { ...options, fetch: (u) => fetch(u)
|
|
141
|
+
fetchModule: (url, options) => fetchModule(url, { ...options, fetch: (u) => fetch(u) }),
|
|
87
142
|
importBlob,
|
|
88
143
|
own: () => import("verovio/wasm"),
|
|
89
|
-
instantiate: async (m) => {
|
|
90
|
-
const module = await m
|
|
144
|
+
instantiate: async (m, wasm, report) => {
|
|
145
|
+
const module = await createModule(m, wasm, report);
|
|
91
146
|
enableLog(LOG_OFF, module);
|
|
92
147
|
return new VerovioToolkit(module);
|
|
93
148
|
},
|
|
149
|
+
versionOf: (t) => t.getVersion(),
|
|
150
|
+
toolkitVersion: VEROVIO_VERSION,
|
|
94
151
|
warn: (message) => console.warn(message),
|
|
95
152
|
}));
|
|
96
153
|
/** `request`'s Verovio source, without its absent fields. */
|
|
97
|
-
const sourceOf = ({ verovioUrl, verovioIntegrity }) => ({
|
|
154
|
+
const sourceOf = ({ verovioUrl, verovioIntegrity, verovioWasmIntegrity, }) => ({
|
|
98
155
|
...(verovioUrl === undefined ? {} : { verovioUrl }),
|
|
99
156
|
...(verovioIntegrity === undefined ? {} : { verovioIntegrity }),
|
|
157
|
+
...(verovioWasmIntegrity === undefined ? {} : { verovioWasmIntegrity }),
|
|
100
158
|
});
|
|
101
159
|
/**
|
|
102
160
|
* The toolkit for `request`, posting its load's progress, then saying it
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barmark/score",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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,13 +49,16 @@
|
|
|
49
49
|
"url": "https://github.com/kevinpeckham/barmark/issues"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@barmark/musicxml": "^0.
|
|
53
|
-
"@barmark/render": "^0.
|
|
54
|
-
"barmark": "^0.
|
|
52
|
+
"@barmark/musicxml": "^0.9.0",
|
|
53
|
+
"@barmark/render": "^0.19.0",
|
|
54
|
+
"barmark": "^0.23.0",
|
|
55
55
|
"verovio": "6.4.1"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
59
59
|
"prepack": "bun run build"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@barmark/engraver": "0.1.1"
|
|
60
63
|
}
|
|
61
64
|
}
|