@barmark/score 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,73 @@ package uses [semantic versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.6.0] - 2026-11-13
10
+
11
+ ### Added
12
+
13
+ - **`chord-diagrams` and `diagram-hand`**: the element observes them and
14
+ its grid view shows `@barmark/render`'s strip of guitar chord diagrams;
15
+ `renderScoreHtml(text, { chordDiagrams: "guitar" })` writes it too. The
16
+ score view (Verovio) ignores them. Requires `@barmark/render` 0.20.0.
17
+
18
+ ### Changed
19
+
20
+ - **Unbundled pages: add `@barmark/fretboard` to the import map.**
21
+ `@barmark/render`, which the element loads, imports it whether or not
22
+ diagrams are on.
23
+
24
+ ## [0.5.0] - 2026-11-10
25
+
26
+ ### Added
27
+
28
+ - **`verovio-wasm-integrity`**: the SRI digest of the `.wasm` beside a
29
+ `verovio-url` that loads its WebAssembly as a separate file, as
30
+ `@barmark/engraver` does. The worker gives Emscripten an
31
+ `instantiateWasm` hook that downloads the `.wasm` from beside the
32
+ `verovio-url` (never from the module's `blob:` URL), with progress,
33
+ checks its digest and only then compiles it. A missing or mismatched
34
+ `.wasm` fails at once, raced against Verovio's factory, rather than
35
+ hanging to the 60-second load deadline, and with `verovio-integrity`
36
+ set falls back to the package's own copy with a warning. With
37
+ `verovio-integrity` set, a separate `.wasm` needs this digest too
38
+ ("verovio-wasm-integrity is needed for a Verovio that loads a separate
39
+ .wasm"); a wasm digest without a module digest is supported. A
40
+ malformed one is refused, and changing it clears a failure. Stock
41
+ Verovio ignores it. Two elements share one engine: the first source
42
+ loaded wins, and a second element's different digests are ignored.
43
+ - **`ENGRAVER_CDN_URL`, `ENGRAVER_CDN_INTEGRITY`,
44
+ `ENGRAVER_WASM_INTEGRITY`**: `@barmark/engraver` 0.1.1, the smaller
45
+ Verovio 6.4.1 build made by barmark, on jsDelivr, with its module's and
46
+ its `.wasm`'s sha384, for `verovio-url`, `verovio-integrity` and
47
+ `verovio-wasm-integrity`. Opt-in: they are literals, so a site that
48
+ never uses the build never installs it. The build leaves out what this
49
+ package never asks Verovio for (fonts other than Leipzig, footers,
50
+ tablature tunings, `.mxl`); the README says how to load it, with the
51
+ Content-Security-Policy it needs.
52
+
53
+ ### Changed
54
+
55
+ - **A Verovio from `verovio-url` must match the toolkit's version**
56
+ (`VEROVIO_VERSION`, 6.4.1): any other now fails to load, or, with
57
+ `verovio-integrity` set, falls back to the package's own copy with a
58
+ warning, where it was loaded anyway.
59
+ - **A download's progress is measured against the file its digest
60
+ names**: Verovio's module, or `@barmark/engraver`'s module or `.wasm`.
61
+ A compressed `verovio-url` download with no digest, or a digest of no
62
+ build this package knows, shows the bar without a percentage instead of
63
+ being measured against Verovio's 7.4 MB. With
64
+ `verovio-wasm-integrity`, the `.wasm` is the download measured, so the
65
+ bar runs to 100% once.
66
+
67
+ ### Technical
68
+
69
+ - **The browser suite loads `@barmark/engraver`** from
70
+ `packages/engraver/dist` (compiled on the VM, or CI's `engraver-dist`
71
+ artifact): the build used with both digests and its `.wasm` measured,
72
+ a `.wasm` with a flipped byte, a missing `.wasm` (falling back in
73
+ seconds), a module digest without a wasm digest, and stock Verovio
74
+ with a wasm digest.
75
+
9
76
  ## [0.4.0] - 2026-11-10
10
77
 
11
78
  ### Added
@@ -226,7 +293,9 @@ First release.
226
293
  needs no config; Vite 7 needs `optimizeDeps.exclude` and
227
294
  `worker.format: "es"`.
228
295
 
229
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/score-v0.4.0...HEAD
296
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/score-v0.6.0...HEAD
297
+ [0.6.0]: https://github.com/kevinpeckham/barmark/compare/score-v0.5.0...score-v0.6.0
298
+ [0.5.0]: https://github.com/kevinpeckham/barmark/compare/score-v0.4.0...score-v0.5.0
230
299
  [0.4.0]: https://github.com/kevinpeckham/barmark/compare/score-v0.3.0...score-v0.4.0
231
300
  [0.3.0]: https://github.com/kevinpeckham/barmark/compare/score-v0.2.0...score-v0.3.0
232
301
  [0.2.0]: https://github.com/kevinpeckham/barmark/compare/score-v0.1.1...score-v0.2.0
package/README.md CHANGED
@@ -46,10 +46,11 @@ 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`, `columns` | 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`, `chord-diagrams`, `diagram-hand` | the grid's own, as in [`@barmark/render`](../render/README.md#options-and-attributes). The score view ignores `chord-diagrams` and `diagram-hand`: only the grid shows the guitar chord strip |
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
@@ -66,6 +67,10 @@ score.view = "score";
66
67
 
67
68
  ### Bundling the worker
68
69
 
70
+ Loaded without a bundler, the element also needs `@barmark/fretboard` in the
71
+ page's import map (with `barmark` and `@barmark/render`): the element loads
72
+ `@barmark/render`, which imports it whether or not diagrams are on.
73
+
69
74
  The engine runs in a module Worker, created as
70
75
  `new Worker(new URL("./worker.js", import.meta.url), { type: "module" })`.
71
76
  That is the pattern Vite and webpack follow, so a bundler finds the worker
@@ -96,9 +101,14 @@ then point at a Verovio module you host (for example
96
101
  `verovio/dist/verovio-module.mjs` from the `verovio` package) instead of
97
102
  bundling the 7 MB inside the worker; it only changes where that module
98
103
  comes from. The URL is resolved against the page and must be http(s);
99
- anything else is refused and the score is not drawn. The first
100
- `verovio-url` that loads wins for the whole page: every element shares one
101
- worker, so a later or different URL is not loaded. The worker downloads a
104
+ anything else is refused and the score is not drawn. Its Verovio must be
105
+ the version this package's toolkit is (`VEROVIO_VERSION`, 6.4.1): any
106
+ other fails to load, or, with `verovio-integrity` set, falls back to the
107
+ package's own copy with a warning. The first `verovio-url` that loads wins
108
+ for the whole page: every element shares one worker, so a later or
109
+ different URL is not loaded, and a second element's different
110
+ `verovio-integrity` or `verovio-wasm-integrity` is ignored too: the
111
+ engine keeps the source it loaded first, digests and all. The worker downloads a
102
112
  `verovio-url` with `fetch` (with or without `verovio-integrity`) and
103
113
  imports it from a `blob:` URL, so a worker served with its own
104
114
  Content-Security-Policy needs the module's origin (a CDN's, say) in
@@ -123,11 +133,17 @@ The download can be measured when the worker fetches Verovio itself,
123
133
  which it does for a `verovio-url`: it reads the response as it arrives,
124
134
  then imports the module from a `blob:` URL. A compressed response (gzip,
125
135
  brotli) has a `Content-Length` that is the compressed size, while the
126
- bytes read are decoded, so they are measured against Verovio's known
127
- decoded size (`VEROVIO_MODULE_BYTES`) instead; an uncompressed one is
128
- measured against its `Content-Length` (a cross-origin server that does
129
- not expose `Content-Encoding` is taken as compressed when its length is
130
- short of that size); anything else shows the bar without a percentage.
136
+ bytes read are decoded, so they are measured against the known decoded
137
+ size of the file its declared digest names instead: Verovio's module
138
+ (`VEROVIO_MODULE_BYTES`) for `VEROVIO_CDN_INTEGRITY`, or
139
+ `@barmark/engraver`'s module or `.wasm` for its digests. An uncompressed
140
+ one is measured against its `Content-Length` (a cross-origin server that
141
+ does not expose `Content-Encoding` is taken as compressed when its length
142
+ is short of that size). A compressed one with no digest, or a digest of
143
+ no build this package knows, shows the bar without a percentage. With
144
+ `verovio-wasm-integrity`, the module's small download is shown without a
145
+ percentage and the `.wasm`'s is the one measured, so the bar runs to
146
+ 100% once.
131
147
  The package's own copy, without `verovio-url`, is loaded by your
132
148
  bundler, so its download is shown without a percentage; so is a worker
133
149
  bundled with Verovio inside it, whose download is the worker's own
@@ -162,6 +178,66 @@ Verovio once for that site whichever URL it comes from. What a CDN gives
162
178
  is delivery from an edge near the reader and the 2.4 MB kept off your own
163
179
  server.
164
180
 
181
+ ### The lighter build (`@barmark/engraver`)
182
+
183
+ [`@barmark/engraver`](../engraver/) is a modified, smaller build of the
184
+ same Verovio 6.4.1, made by barmark for this package: about 3 MB where
185
+ stock is about 7 MB, checked before each release to draw SVG byte for
186
+ byte the same as stock over a corpus of charts. Its WebAssembly is a
187
+ separate file, `verovio-module.wasm` beside the module, so it takes a
188
+ digest of its own, `verovio-wasm-integrity`. On jsDelivr:
189
+
190
+ ```html
191
+ <barmark-score
192
+ verovio-url="https://cdn.jsdelivr.net/npm/@barmark/engraver@0.1.1/dist/verovio-module.mjs"
193
+ verovio-integrity="sha384-klTppHZB0IPzdIOfSXNr8CbdhJU+1yp5eltjmgp8W3E8uhht5dlRy1mwrBSnmKJO"
194
+ verovio-wasm-integrity="sha384-cBBw1xx6xHEb/I7QDrSFDgImfzzvZVvwru055NG6QbY1zHI/FFLQHjlKdtH7pr5i"
195
+ src="/charts/peaceful-dreams.chart.md"
196
+ ></barmark-score>
197
+ ```
198
+
199
+ The package exports the three as `ENGRAVER_CDN_URL`,
200
+ `ENGRAVER_CDN_INTEGRITY` and `ENGRAVER_WASM_INTEGRITY`. They are written
201
+ into this package, so a site that never uses the lighter build never
202
+ installs it.
203
+
204
+ The worker downloads the module and checks it against
205
+ `verovio-integrity`, then downloads the `.wasm` from beside the
206
+ `verovio-url` (never from the `blob:` URL the module is imported from),
207
+ checks it against `verovio-wasm-integrity` and only then compiles it. A
208
+ module that does not fit its digest, a `.wasm` that does not fit its own,
209
+ a `.wasm` that is missing or fails to download, or a Verovio other than
210
+ 6.4.1 falls back to the package's own copy, once, with a warning naming
211
+ the reason, as for any `verovio-url` with `verovio-integrity`. A failed
212
+ `.wasm` falls back as soon as it fails, not at the 60-second load
213
+ deadline.
214
+
215
+ **`verovio-wasm-integrity` is required whenever `verovio-integrity` is
216
+ set for a build that loads a separate `.wasm`**: a module digest alone
217
+ would leave the `.wasm` unchecked, so without it the load fails with
218
+ "verovio-wasm-integrity is needed for a Verovio that loads a separate
219
+ .wasm" and the package's own copy loads instead. A wasm digest without a
220
+ module digest is supported: the `.wasm` is checked and the module is not,
221
+ and, as for any `verovio-url` without `verovio-integrity`, there is no
222
+ fallback, so a mismatch is a score that can't be drawn. A malformed
223
+ `verovio-wasm-integrity` is refused like a malformed `verovio-integrity`.
224
+ Stock Verovio, which embeds its WebAssembly, ignores
225
+ `verovio-wasm-integrity` and loads as usual, but the progress shows less:
226
+ the digest marks the `.wasm` as the download to measure, and stock never
227
+ fetches one, so its module's download is shown without a percentage and
228
+ "Preparing…" is never announced. Set `verovio-wasm-integrity` only with a
229
+ build that loads a separate `.wasm`.
230
+
231
+ A page with a Content-Security-Policy needs the CDN's origin in
232
+ `connect-src` (the worker fetches both files), `blob:` in `script-src`
233
+ (the module is imported from a `blob:` URL) and `'wasm-unsafe-eval'` in
234
+ `script-src`, which stock Verovio needs as well.
235
+
236
+ The build leaves out what this package never asks Verovio for: only the
237
+ Leipzig font, no footer, no tablature or staff tunings, and no compressed
238
+ MusicXML (`.mxl`). If you pass your own MusicXML to `engraveXml` with a
239
+ toolkit from `@barmark/engraver`, see [its limits](../engraver/README.md#limits).
240
+
165
241
  ### Preloading
166
242
 
167
243
  `preload` starts loading Verovio before the first press, so the score
@@ -182,10 +258,11 @@ If Verovio fails to load, or rejects the MusicXML, or the chart will not
182
258
  export or is too large to draw (see "Engraving directly"), or Verovio
183
259
  takes over 60 seconds to load or 20 seconds to engrave, the grid stays and
184
260
  a note by the switch says "The score couldn't be drawn". The same happens
185
- when `verovio-url` or `verovio-integrity` is refused, when the chart's
186
- `src` could not be loaded, or when the engraving is not clean SVG. The
187
- Score radio is disabled until the chart (`text`, `src` or the script
188
- child), `verovio-url` or `verovio-integrity` changes.
261
+ when `verovio-url`, `verovio-integrity` or `verovio-wasm-integrity` is
262
+ refused, when the chart's `src` could not be loaded, or when the
263
+ engraving is not clean SVG. The Score radio is disabled until the
264
+ chart (`text`, `src` or the script child), `verovio-url`,
265
+ `verovio-integrity` or `verovio-wasm-integrity` changes.
189
266
 
190
267
  The reason goes to the console as a warning, and the element fires a
191
268
  `scoreerror` event (`bubbles`, `composed`) whose `detail.reason` is the
@@ -253,7 +330,9 @@ is the export unchanged.
253
330
 
254
331
  This package is MIT. It uses [Verovio](https://github.com/rism-digital/verovio),
255
332
  which is LGPL-3.0-only, as an ordinary npm dependency, loaded unchanged at
256
- run time; its code is never copied into this package. barmark's own code
333
+ run time, or, if you choose it, the modified build `@barmark/engraver`
334
+ (LGPL-3.0-only, its source published with each release); its code is
335
+ never copied into this package. barmark's own code
257
336
  stays MIT. Verovio © Laurent Pugin and others; its licence text is
258
337
  [COPYING.LESSER](https://github.com/rism-digital/verovio/blob/develop/COPYING.LESSER).
259
338
 
@@ -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 module must have; checked before it is returned. */
38
- integrity?: string;
39
- /** The module's decoded size, when known. */
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 the module at `url` with progress, as a JavaScript blob ready to import from an object URL. */
92
- export async function fetchModule(url, options) {
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 module: the chunks are joined and dropped before it is digested and wrapped.
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
- const blob = new Blob([bytes], { type: "text/javascript" });
117
- return blob;
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
@@ -85,8 +85,12 @@ function takeEarlyText(el) {
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", "preload"],
88
+ "chord-diagrams",
89
+ "diagram-hand",
90
+ ...["view", "verovio-url", "verovio-integrity", "verovio-wasm-integrity", "preload"],
89
91
  ];
92
+ /** The attributes that say where Verovio comes from: a change clears a failure. */
93
+ const VEROVIO_ATTRIBUTES = new Set(["verovio-url", "verovio-integrity", "verovio-wasm-integrity"]);
90
94
  /** With no `requestIdleCallback`, how long after connecting `preload="idle"` starts the load. */
91
95
  const IDLE_FALLBACK_MS = 500;
92
96
  /** Whether the reader asked to save data, or is on a 2G line: `preload="idle"` waits for intent there. */
@@ -102,6 +106,21 @@ const radioOf = (target) => target?.closest?.("[data-view]") ?? null;
102
106
  const same = (a, b) => a !== null && a.text === b.text && Math.abs(a.width - b.width) <= SLACK;
103
107
  const URL_REASON = "verovio-url must be an http(s) URL";
104
108
  const INTEGRITY_REASON = "verovio-integrity must be one sha256-, sha384- or sha512- digest";
109
+ const WASM_INTEGRITY_REASON = "verovio-wasm-integrity must be one sha256-, sha384- or sha512- digest";
110
+ /** The engine call for `verovio`'s digests (only those given), hearing its status on `onStatus`. */
111
+ function callOf({ integrity, wasmIntegrity }, onStatus) {
112
+ return {
113
+ onStatus,
114
+ ...(integrity === undefined ? {} : { integrity }),
115
+ ...(wasmIntegrity === undefined ? {} : { wasmIntegrity }),
116
+ };
117
+ }
118
+ /** A digest attribute: undefined when absent, null when malformed, else trimmed. */
119
+ function digest(value) {
120
+ if (value === null)
121
+ return undefined;
122
+ return isIntegrity(value) ? value.trim() : null;
123
+ }
105
124
  /** `verovio-url` resolved against the page: undefined when absent, null unless http(s). */
106
125
  function verovioHref(value, base) {
107
126
  if (value === null)
@@ -171,7 +190,7 @@ function defineElement() {
171
190
  if (!this.isConnected || old === value)
172
191
  return;
173
192
  // A new URL may be the fix: the Score radio works again, as after a new chart.
174
- if (name === "verovio-url" || name === "verovio-integrity")
193
+ if (VEROVIO_ATTRIBUTES.has(name))
175
194
  this.#clearFailure();
176
195
  else if (name === "preload")
177
196
  this.#preloadChanged();
@@ -339,19 +358,25 @@ function defineElement() {
339
358
  if (source === null)
340
359
  return;
341
360
  this.#preloaded = true;
342
- loadEngine().then((e) => e.preload(source.url, source.integrity), () => { });
361
+ loadEngine().then((e) => e.preload(source.url, source.integrity, source.wasmIntegrity), () => { });
343
362
  }
344
- /** Where Verovio comes from, or null (and why) when `verovio-url` or `verovio-integrity` is refused. */
363
+ /**
364
+ * Where Verovio comes from, or why not when `verovio-url` or a digest is
365
+ * refused. The digests are read only with a `verovio-url`.
366
+ */
345
367
  #verovio() {
346
368
  const url = verovioHref(this.getAttribute("verovio-url"), this.ownerDocument.baseURI);
347
369
  if (url === null)
348
370
  return { refused: URL_REASON };
349
- const integrity = url === undefined ? null : this.getAttribute("verovio-integrity");
371
+ if (url === undefined)
372
+ return { url, integrity: undefined, wasmIntegrity: undefined };
373
+ const integrity = digest(this.getAttribute("verovio-integrity"));
350
374
  if (integrity === null)
351
- return { url, integrity: undefined };
352
- return isIntegrity(integrity)
353
- ? { url, integrity: integrity.trim() }
354
- : { refused: INTEGRITY_REASON };
375
+ return { refused: INTEGRITY_REASON };
376
+ const wasmIntegrity = digest(this.getAttribute("verovio-wasm-integrity"));
377
+ if (wasmIntegrity === null)
378
+ return { refused: WASM_INTEGRITY_REASON };
379
+ return { url, integrity, wasmIntegrity };
355
380
  }
356
381
  #source() {
357
382
  const v = this.#verovio();
@@ -444,7 +469,7 @@ function defineElement() {
444
469
  if (pane && this.#revealed === null)
445
470
  showStatus(pane, s);
446
471
  };
447
- const call = verovio.integrity === undefined ? { onStatus } : { onStatus, integrity: verovio.integrity };
472
+ const call = callOf(verovio, onStatus);
448
473
  const run = (e) => e.engrave(this, want.text, want.width, verovio.url, call);
449
474
  // A loaded engine is asked at once, so its status (not a provisional one) is the first drawn.
450
475
  const request = loaded ? run(loaded) : loadEngine().then(run);
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
- /** `source` without its absent fields (so a request carries no `verovioUrl: undefined`). */
19
- const present = ({ verovioUrl, verovioIntegrity, }) => ({
20
- ...(verovioUrl === undefined ? {} : { verovioUrl }),
21
- ...(verovioUrl === undefined || verovioIntegrity === undefined ? {} : { verovioIntegrity }),
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
- start().postMessage({ ...rest, ...present(loaded ?? { verovioUrl, verovioIntegrity }) });
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({ verovioUrl, verovioIntegrity: call.integrity }),
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({ verovioUrl, verovioIntegrity: integrity }),
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
- /** Instantiates the module's WebAssembly: the toolkit. */
35
- instantiate(m: M): Promise<T>;
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 or any failure falls back to
43
- * the package's own copy, once, with a warning. Without one, a failure is
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 { VEROVIO_MODULE_BYTES } from "./verovio.js";
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 or any failure falls back to
43
- * the package's own copy, once, with a warning. Without one, a failure is
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 prepared(await deps.own(), report), from: {} };
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, integrity, report) => {
56
- const options = integrity === undefined ? { onProgress: report } : { integrity, onProgress: report };
57
- const blob = await deps.fetchModule(verovioUrl, options);
58
- return prepared(await deps.importBlob(blob), report);
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
- if (verovioIntegrity === undefined)
65
- return { toolkit: await fromUrl(verovioUrl, undefined, report), from: { verovioUrl } };
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, verovioIntegrity, report), from: source };
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), expected: VEROVIO_MODULE_BYTES }),
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.default();
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.4.0",
3
+ "version": "0.6.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.9.0",
53
- "@barmark/render": "^0.19.0",
54
- "barmark": "^0.23.0",
52
+ "@barmark/musicxml": "^0.9.1",
53
+ "@barmark/render": "^0.20.0",
54
+ "barmark": "^0.23.1",
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
  }