guidex 0.2.6 → 0.3.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.
Files changed (45) hide show
  1. package/README.md +219 -0
  2. package/dist/lib/app/ControlsRow.d.ts +1 -0
  3. package/dist/lib/app/Editor.d.ts +1 -0
  4. package/dist/lib/app/EditorContext.d.ts +17 -0
  5. package/dist/lib/app/EditorTextarea.d.ts +1 -0
  6. package/dist/lib/app/ExportSettings.d.ts +1 -0
  7. package/dist/lib/app/FeedbackSpan.d.ts +5 -0
  8. package/dist/lib/app/RenderSettings.d.ts +1 -0
  9. package/dist/lib/app/SamplesRow.d.ts +1 -0
  10. package/dist/lib/app/SettingsMenu.d.ts +1 -0
  11. package/dist/lib/app/SettingsPanel.d.ts +1 -0
  12. package/dist/lib/app/SyllablesTable.d.ts +1 -0
  13. package/dist/lib/app/WordCheckPanel.d.ts +1 -0
  14. package/dist/lib/app/WordCopyControls.d.ts +1 -0
  15. package/dist/lib/app/chantLibrary.d.ts +11 -0
  16. package/dist/lib/app/editorState.d.ts +159 -0
  17. package/dist/lib/app/samples.d.ts +10 -0
  18. package/dist/lib/app/wordCopy.d.ts +30 -0
  19. package/dist/lib/chantLayout-GAfg2iKS.js +1042 -0
  20. package/dist/lib/chantLayout.d.ts +169 -0
  21. package/dist/lib/chantMarkup.d.ts +36 -0
  22. package/dist/lib/editorStorage.d.ts +179 -0
  23. package/dist/lib/embed/index.d.ts +1 -0
  24. package/dist/lib/embed/index.js +2 -2
  25. package/dist/lib/embed/manual.d.ts +15 -4
  26. package/dist/lib/embed/manual.js +43 -2
  27. package/dist/lib/guidoRender.d.ts +22 -29
  28. package/dist/lib/guidoScript.d.ts +28 -3
  29. package/dist/lib/guidoScriptTransforms.d.ts +5 -4
  30. package/dist/lib/guidoStyles.d.ts +23 -5
  31. package/dist/lib/main.d.ts +0 -1
  32. package/dist/lib/react/index.d.ts +1 -0
  33. package/dist/lib/react/index.js +2 -2
  34. package/dist/lib/scoreImage-DnFIbtF_.js +951 -0
  35. package/dist/lib/scoreImage.d.ts +63 -0
  36. package/dist/lib/word/index.d.ts +17 -0
  37. package/dist/lib/word/index.js +2 -0
  38. package/dist/lib/wordChecker-C3nJrk_j.js +1042 -0
  39. package/dist/lib/wordChecker.d.ts +66 -0
  40. package/dist/lib/wordClipboard.d.ts +25 -0
  41. package/dist/lib/wordExport.d.ts +244 -0
  42. package/dist-embed/guidex-embed.min.js +1 -1
  43. package/package.json +8 -1
  44. package/dist/lib/core-hF6L1EtS.js +0 -1268
  45. package/dist/lib/settingsMenu.d.ts +0 -1
@@ -0,0 +1,951 @@
1
+ import { c as inlineStylesFor, d as transposeBy, f as GuidoScript, i as layoutScore, s as STYLE_SETS } from "./chantLayout-GAfg2iKS.js";
2
+ //#region src/guidoRender.ts
3
+ /**
4
+ * Renders a GuidoScript into a tidy score: a notes line in the chant font,
5
+ * and a text line where each syllable is centered below its notes.
6
+ *
7
+ * The DOM emitter of the shared layout pass (`layoutScore` in
8
+ * chantLayout.ts, which owns every line-breaking and placement decision):
9
+ * `render` turns the laid-out lines into (notes `.guido` div, text `<p>`)
10
+ * pairs — px-measured inline-block spacer spans fake the horizontal gaps.
11
+ * The Word export (wordExport.ts) consumes the same layout with a
12
+ * character-based spacer mechanism instead.
13
+ */
14
+ var GuidoRender = class GuidoRender {
15
+ script;
16
+ constructor(source) {
17
+ this.script = typeof source === "string" ? new GuidoScript(source) : source;
18
+ }
19
+ /**
20
+ * Renders the score into `container` as (notes line, text line) pairs.
21
+ * When `maxWidthPx` is finite, a new pair starts before any syllable
22
+ * whose notes would push the current notes line past it; the clef is
23
+ * repeated at the start of every line. Throws when the style set is
24
+ * unknown or one of its fonts cannot be loaded.
25
+ */
26
+ async render(container, options = {}) {
27
+ const { debug = false } = options;
28
+ const { lines, clefPrefix, styleSet, styleName, textPx, notesPx, bold, starTarget, starWidth } = await layoutScore(this.script, options);
29
+ container.style.fontSize = `${textPx}px`;
30
+ container.style.fontFamily = styleSet.textFontStack;
31
+ container.dataset.style = styleName;
32
+ container.replaceChildren(...lines.flatMap((l) => [GuidoRender.notesLine(l, clefPrefix, notesPx, starTarget, starWidth, debug), GuidoRender.textLine(l, textPx, bold, debug)]));
33
+ }
34
+ /** Builds a line's notes div: the chant font text plus, on broken
35
+ * lines, the break marker `*` as an inline span (so it shares the
36
+ * text's baseline) shifted right so its right edge lands on the
37
+ * padding-extended max-width position. position: relative keeps the
38
+ * shift out of the flow measurements. */
39
+ static notesLine(line, clefPrefix, notesPx, starTarget, starWidth, debug) {
40
+ const notesEl = document.createElement("div");
41
+ notesEl.className = "guido";
42
+ notesEl.style.fontSize = `${notesPx}px`;
43
+ notesEl.textContent = clefPrefix + line.notesParts.join("");
44
+ if (line.breakMarkerLeftPx !== void 0) {
45
+ const star = document.createElement("span");
46
+ star.className = "guido-break";
47
+ star.textContent = "*";
48
+ star.style.position = "relative";
49
+ star.style.left = `${line.breakMarkerLeftPx}px`;
50
+ if (debug) star.title = `line break at ${starTarget.toFixed(1)}px (staff filled to ${(starTarget - line.breakMarkerLeftPx - starWidth).toFixed(1)}px)`;
51
+ notesEl.appendChild(star);
52
+ }
53
+ return notesEl;
54
+ }
55
+ /** Builds a line's text paragraph from its segments: spacer spans fake
56
+ * every horizontal gap (lead-in, word gaps, dash connector pads), each
57
+ * syllable is one span of nested runs, and word spaces are their own
58
+ * spans. */
59
+ static textLine(line, textPx, bold, debug) {
60
+ const textEl = document.createElement("p");
61
+ if (bold) textEl.style.fontWeight = "700";
62
+ for (const seg of line.segments) switch (seg.kind) {
63
+ case "gap": {
64
+ const spacerEl = GuidoRender.spacer(seg.width);
65
+ if (debug) spacerEl.title = `${seg.role === "lead-in" ? "lead-in" : "word gap"} ${seg.width.toFixed(1)}px → text ${seg.textStartPx.toFixed(1)}`;
66
+ textEl.appendChild(spacerEl);
67
+ break;
68
+ }
69
+ case "connector": {
70
+ const leadPad = GuidoRender.spacer(seg.pad);
71
+ const dash = document.createElement("span");
72
+ dash.className = "dash";
73
+ dash.textContent = "-";
74
+ const trailPad = GuidoRender.spacer(seg.pad);
75
+ if (debug) {
76
+ leadPad.title = `lead pad ${seg.pad.toFixed(1)}px (gap ${seg.gapWidth.toFixed(1)} − dash ${seg.dashWidth.toFixed(1)}, halved)`;
77
+ dash.title = `dash ${seg.dashWidth.toFixed(1)}px`;
78
+ trailPad.title = `trail pad ${seg.pad.toFixed(1)}px`;
79
+ }
80
+ textEl.append(leadPad, dash, trailPad);
81
+ break;
82
+ }
83
+ case "syl": {
84
+ const span = GuidoRender.sylSpan(seg.parts, textPx);
85
+ if (debug) {
86
+ if (seg.noNotes) span.title = `no notes, text w ${seg.textWidth.toFixed(1)}, ${seg.trailing ? "end of score" : "before the next syllable with notes"}`;
87
+ else {
88
+ const theoDiff = (seg.textWidth - seg.contentWidth) / 2;
89
+ const cursDiff = seg.textStart - seg.contentStart;
90
+ span.title = [
91
+ `text w ${seg.textWidth.toFixed(1)}`,
92
+ `notes w ${seg.contentWidth.toFixed(1)}`,
93
+ seg.extraDashes ? `+${seg.extraDashes} pad dash(es)` : null,
94
+ `text start ${seg.textStart.toFixed(1)}`,
95
+ `notes start ${seg.contentStart.toFixed(1)}`,
96
+ `theoDiff: ${theoDiff.toFixed(1)}`,
97
+ `cursDiff: ${cursDiff.toFixed(1)}`
98
+ ].filter(Boolean).join(", ");
99
+ }
100
+ }
101
+ textEl.appendChild(span);
102
+ break;
103
+ }
104
+ case "word-space": {
105
+ const ws = document.createElement("span");
106
+ ws.className = "word-space";
107
+ ws.textContent = " ";
108
+ if (debug) ws.title = `word space ${seg.width.toFixed(1)}px`;
109
+ textEl.appendChild(ws);
110
+ break;
111
+ }
112
+ case "line-end-dash": {
113
+ const leadPad = GuidoRender.spacer(seg.pad);
114
+ const dash = document.createElement("span");
115
+ dash.className = "dash";
116
+ dash.textContent = "-";
117
+ const trailPad = GuidoRender.spacer(seg.pad);
118
+ if (debug) {
119
+ leadPad.title = `lead pad ${seg.pad.toFixed(1)}px → line-end dash (text end ${seg.textEndPx.toFixed(1)}, notes end ${seg.trailEndPx.toFixed(1)})`;
120
+ dash.title = `dash ${seg.dashWidth.toFixed(1)}px (line end)`;
121
+ trailPad.title = `trail pad ${seg.pad.toFixed(1)}px`;
122
+ }
123
+ textEl.append(leadPad, dash, trailPad);
124
+ break;
125
+ }
126
+ }
127
+ return textEl;
128
+ }
129
+ /** Builds a syllable span from its resolved runs: one nested span per
130
+ * run, carrying the run's inline styles and its notation-fixed kind
131
+ * class (`liturgy`, `rubric`, `star`, `marker`, `plus`); runs marked
132
+ * `initial` by the `*…*` marker carry the initial class. */
133
+ static sylSpan(parts, textPx) {
134
+ const sylSpan = document.createElement("span");
135
+ sylSpan.className = "syl";
136
+ parts.forEach((part) => {
137
+ const partSpan = document.createElement("span");
138
+ partSpan.textContent = part.text;
139
+ for (const [prop, value] of Object.entries(inlineStylesFor(part.style, textPx))) partSpan.style.setProperty(prop, value);
140
+ const classes = [...part.kind ? [part.kind] : [], ...part.style.initial ? ["initial"] : []].join(" ");
141
+ if (classes) partSpan.className = classes;
142
+ sylSpan.appendChild(partSpan);
143
+ });
144
+ return sylSpan;
145
+ }
146
+ static spacer(width) {
147
+ const spacer = document.createElement("span");
148
+ spacer.className = "spacer";
149
+ spacer.style.display = "inline-block";
150
+ spacer.style.width = `${width}px`;
151
+ return spacer;
152
+ }
153
+ };
154
+ //#endregion
155
+ //#region src/embed/core.ts
156
+ var version = {
157
+ name: "guidex",
158
+ version: "0.3.0",
159
+ description: "Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime",
160
+ type: "module",
161
+ workspaces: ["examples/*"],
162
+ main: "./dist/lib/embed/manual.js",
163
+ types: "./dist/lib/embed/manual.d.ts",
164
+ exports: {
165
+ ".": {
166
+ "types": "./dist/lib/embed/manual.d.ts",
167
+ "default": "./dist/lib/embed/manual.js"
168
+ },
169
+ "./embed": {
170
+ "types": "./dist/lib/embed/index.d.ts",
171
+ "default": "./dist/lib/embed/index.js"
172
+ },
173
+ "./guidex.css": {
174
+ "types": "./dist/lib/guidex.css.d.ts",
175
+ "default": "./dist/lib/guidex.css"
176
+ },
177
+ "./fonts/*": "./dist/lib/fonts/*",
178
+ "./react": {
179
+ "types": "./dist/lib/react/index.d.ts",
180
+ "default": "./dist/lib/react/index.js"
181
+ },
182
+ "./word": {
183
+ "types": "./dist/lib/word/index.d.ts",
184
+ "default": "./dist/lib/word/index.js"
185
+ }
186
+ },
187
+ files: ["dist-embed", "dist/lib"],
188
+ peerDependencies: { "react": ">=18" },
189
+ peerDependenciesMeta: { "react": { "optional": true } },
190
+ publishConfig: { "access": "public" },
191
+ scripts: {
192
+ "dev": "vite --host",
193
+ "build": "tsc && vite build",
194
+ "build:embed": "vite build --config vite.embed.config.ts",
195
+ "build:lib": "vite build --config vite.lib.config.ts",
196
+ "preview": "vite preview",
197
+ "test": "vitest run",
198
+ "lint": "eslint ."
199
+ },
200
+ keywords: [
201
+ "plainchant",
202
+ "gregorian",
203
+ "guido",
204
+ "score",
205
+ "notation",
206
+ "liturgy"
207
+ ],
208
+ repository: {
209
+ "type": "git",
210
+ "url": "git+https://github.com/BrownieMaar/guidex.git"
211
+ },
212
+ bugs: { "url": "https://github.com/BrownieMaar/guidex/issues" },
213
+ homepage: "https://github.com/BrownieMaar/guidex#readme",
214
+ devDependencies: {
215
+ "@eslint/js": "^10.0.1",
216
+ "@testing-library/dom": "^10.4.2",
217
+ "@testing-library/react": "^16.3.3",
218
+ "@testing-library/user-event": "^14.6.7",
219
+ "@types/react": "^19.3.0",
220
+ "@types/react-dom": "^19.3.0",
221
+ "@vitejs/plugin-react": "^6.1.1",
222
+ "eslint": "^10.10.0",
223
+ "jsdom": "^29.1.1",
224
+ "react": "^19.3.0",
225
+ "react-dom": "^19.3.0",
226
+ "typescript": "~6.0.2",
227
+ "typescript-eslint": "^8.70.0",
228
+ "vite": "^8.2.2",
229
+ "vite-plugin-dts": "^5.1.1",
230
+ "vitest": "^4.1.11"
231
+ }
232
+ }.version;
233
+ var DEFAULT_SELECTOR = ".guidex-script, .guido-script";
234
+ var DEFAULTS = {
235
+ maxWidth: "auto",
236
+ style: "BNS",
237
+ bold: false,
238
+ textPx: 18,
239
+ transpose: 0,
240
+ debug: false
241
+ };
242
+ var globalOptions = {};
243
+ /** The raw script of each target, cached across re-renders: rendering
244
+ * replaces the element's content, so the original text would be lost. */
245
+ var sources = /* @__PURE__ */ new WeakMap();
246
+ /** Per-element render race counter: a slow render (font loading) must
247
+ * never overwrite a newer one's output. */
248
+ var runs = /* @__PURE__ */ new WeakMap();
249
+ /** The line-breaking budget each element last rendered at; resize
250
+ * re-renders are skipped while the width is unchanged (height-only
251
+ * ResizeObserver entries from our own renders must not loop). */
252
+ var lastWidths = /* @__PURE__ */ new WeakMap();
253
+ /** data-* boolean attribute: bare presence or 'true' → true, 'false' →
254
+ * false, anything else → unset. */
255
+ function flag(value) {
256
+ if (value === void 0) return void 0;
257
+ if (value === "" || value === "true") return true;
258
+ if (value === "false") return false;
259
+ }
260
+ function number(value) {
261
+ if (value === void 0) return void 0;
262
+ const n = Number(value);
263
+ return Number.isFinite(n) ? n : void 0;
264
+ }
265
+ function parseMaxWidth(value, fallback) {
266
+ if (/^auto$/i.test(value.trim())) return "auto";
267
+ const n = Number(value);
268
+ if (Number.isFinite(n) && n > 0) return n;
269
+ console.warn(`[guidex] ignoring invalid data-max-width "${value}"`);
270
+ return fallback;
271
+ }
272
+ /** Per-element option overrides set by `renderScore` (programmatic
273
+ * callers): element data attributes win over these, these win over
274
+ * `init` site-wide defaults. */
275
+ var overrides = /* @__PURE__ */ new WeakMap();
276
+ /** Element data attributes (or unset) over `renderScore` overrides over
277
+ * init options over defaults. */
278
+ function readOptions(el) {
279
+ const ds = el.dataset;
280
+ const local = overrides.get(el) ?? {};
281
+ return {
282
+ maxWidth: ds.maxWidth !== void 0 ? parseMaxWidth(ds.maxWidth, local.maxWidth ?? globalOptions.maxWidth ?? DEFAULTS.maxWidth) : local.maxWidth ?? globalOptions.maxWidth ?? DEFAULTS.maxWidth,
283
+ style: ds.style ?? local.style ?? globalOptions.style ?? DEFAULTS.style,
284
+ bold: flag(ds.bold) ?? local.bold ?? globalOptions.bold ?? DEFAULTS.bold,
285
+ textPx: number(ds.textPx) ?? local.textPx ?? globalOptions.textPx ?? DEFAULTS.textPx,
286
+ transpose: number(ds.transpose) ?? local.transpose ?? globalOptions.transpose ?? DEFAULTS.transpose,
287
+ debug: flag(ds.debug) ?? local.debug ?? globalOptions.debug ?? DEFAULTS.debug
288
+ };
289
+ }
290
+ /** The element's content-box width (the score wrapper spans it), the
291
+ * line-box width the rendered score actually has to fit. Falls back to
292
+ * the parent for inline targets; zero means no layout (hidden). */
293
+ function contentWidthPx(el) {
294
+ return el.querySelector(":scope > .guidex-render")?.clientWidth || el.clientWidth || el.parentElement?.clientWidth || 0;
295
+ }
296
+ /** The line-breaking budget in pixels for this render. Fixed values pass
297
+ * through; 'auto' fits the element's content box, shrunk by the style
298
+ * set's break-star padding: the renderer hangs the `guido-break` star
299
+ * `padding` px past the budget, and when the budget is the line-box
300
+ * width itself that star would overflow the line and wrap. A zero width
301
+ * (hidden element) renders unbroken; once it becomes visible the resize
302
+ * listener re-renders it at the real width. */
303
+ function resolveWidthPx(el, maxWidth, style) {
304
+ if (typeof maxWidth === "number") return maxWidth;
305
+ const width = contentWidthPx(el);
306
+ if (width <= 0) return Infinity;
307
+ const budget = width - (STYLE_SETS[style]?.padding ?? 0);
308
+ return budget > 0 ? budget : width;
309
+ }
310
+ /** The element's script source: a fresh non-empty text node wins (so
311
+ * hosts can update the source by setting textContent and calling
312
+ * renderAll), otherwise the cached one from the previous render. */
313
+ function extractSource(el) {
314
+ for (const node of el.childNodes) if (node.nodeType === Node.TEXT_NODE && node.nodeValue?.trim()) return node.nodeValue.trim();
315
+ return sources.get(el) ?? "";
316
+ }
317
+ /** The score wrapper inside the target; the renderer swaps the score
318
+ * into it, never touching the target element's own classes or dataset. */
319
+ function scoreWrapper(el) {
320
+ const existing = el.querySelector(":scope > .guidex-render");
321
+ if (existing) return existing;
322
+ const wrapper = document.createElement("div");
323
+ wrapper.className = "guidex-render";
324
+ el.replaceChildren(wrapper);
325
+ return wrapper;
326
+ }
327
+ function renderError(wrapper, message) {
328
+ const note = document.createElement("p");
329
+ note.className = "guidex-error";
330
+ note.textContent = message;
331
+ wrapper.replaceChildren(note);
332
+ }
333
+ /** The transforms a score renders with: the style set's defaults (BNS
334
+ * marks the first initial) plus the user-requested transpose. An unknown
335
+ * style name yields no defaults here — the render itself reports it. */
336
+ function scriptTransforms(style, transpose) {
337
+ const transforms = [...STYLE_SETS[style]?.scriptTransforms ?? []];
338
+ if (transpose !== 0) transforms.push(transposeBy(transpose));
339
+ return transforms;
340
+ }
341
+ /** Renders one target element. The score is built into a detached
342
+ * scratch wrapper and swapped into the live one only when this run is
343
+ * still the latest — a stale render that finished late leaves no
344
+ * footprint. */
345
+ async function renderElement(el) {
346
+ const run = (runs.get(el) ?? 0) + 1;
347
+ runs.set(el, run);
348
+ const options = readOptions(el);
349
+ const source = extractSource(el);
350
+ sources.set(el, source);
351
+ const wrapper = scoreWrapper(el);
352
+ const widthPx = resolveWidthPx(el, options.maxWidth, options.style);
353
+ lastWidths.set(el, widthPx);
354
+ const scratch = document.createElement("div");
355
+ const script = new GuidoScript(source, { transforms: scriptTransforms(options.style, options.transpose) });
356
+ try {
357
+ await new GuidoRender(script).render(scratch, {
358
+ style: options.style,
359
+ bold: options.bold,
360
+ textPx: options.textPx,
361
+ debug: options.debug,
362
+ maxWidthPx: widthPx
363
+ });
364
+ if (runs.get(el) !== run) return;
365
+ wrapper.replaceChildren(...scratch.childNodes);
366
+ wrapper.style.cssText = scratch.style.cssText;
367
+ if (scratch.dataset.style) wrapper.dataset.style = scratch.dataset.style;
368
+ } catch (e) {
369
+ if (runs.get(el) !== run) return;
370
+ console.error("[guidex]", e);
371
+ renderError(wrapper, e instanceof Error ? e.message : String(e));
372
+ }
373
+ }
374
+ /** Sets up one resize listener per target element, on first render.
375
+ * Only a changed line-breaking budget (width) triggers a re-render. */
376
+ var detachFns = /* @__PURE__ */ new WeakMap();
377
+ function widthChanged(el) {
378
+ const options = readOptions(el);
379
+ const width = resolveWidthPx(el, options.maxWidth, options.style);
380
+ return Math.abs(width - (lastWidths.get(el) ?? NaN)) > 1;
381
+ }
382
+ function attachResizeListener(el) {
383
+ if (detachFns.has(el)) return;
384
+ let detach;
385
+ if (typeof ResizeObserver !== "undefined") {
386
+ const observer = new ResizeObserver(() => {
387
+ if (widthChanged(el)) renderElement(el);
388
+ });
389
+ observer.observe(el);
390
+ detach = () => observer.disconnect();
391
+ } else {
392
+ const onResize = () => {
393
+ if (widthChanged(el)) renderElement(el);
394
+ };
395
+ window.addEventListener("resize", onResize);
396
+ detach = () => window.removeEventListener("resize", onResize);
397
+ }
398
+ detachFns.set(el, detach);
399
+ }
400
+ /** Cleans up a programmatically rendered element: stops resize
401
+ * re-rendering and drops the cached source and option overrides. Does
402
+ * not remove the rendered score itself. */
403
+ function dispose(el) {
404
+ detachFns.get(el)?.();
405
+ detachFns.delete(el);
406
+ sources.delete(el);
407
+ overrides.delete(el);
408
+ runs.delete(el);
409
+ lastWidths.delete(el);
410
+ }
411
+ /** Renders a GuidoScript source string into one element
412
+ * programmatically — no selector scanning, no site-wide state. The
413
+ * element's own text content is replaced by the rendered score and
414
+ * re-rendered on resize. Call again with a new source to update.
415
+ * Options set here override `init` defaults; data attributes on the
416
+ * element still win. Resolves when the score has finished rendering. */
417
+ async function renderScore(el, source, options = {}) {
418
+ overrides.set(el, options);
419
+ const run = (runs.get(el) ?? 0) + 1;
420
+ runs.set(el, run);
421
+ sources.set(el, source);
422
+ const resolved = readOptions(el);
423
+ const wrapper = scoreWrapper(el);
424
+ const widthPx = resolveWidthPx(el, resolved.maxWidth, resolved.style);
425
+ lastWidths.set(el, widthPx);
426
+ attachResizeListener(el);
427
+ const scratch = document.createElement("div");
428
+ const script = new GuidoScript(source, { transforms: scriptTransforms(resolved.style, resolved.transpose) });
429
+ try {
430
+ await new GuidoRender(script).render(scratch, {
431
+ style: resolved.style,
432
+ bold: resolved.bold,
433
+ textPx: resolved.textPx,
434
+ debug: resolved.debug,
435
+ maxWidthPx: widthPx
436
+ });
437
+ if (runs.get(el) !== run) return;
438
+ wrapper.replaceChildren(...scratch.childNodes);
439
+ wrapper.style.cssText = scratch.style.cssText;
440
+ if (scratch.dataset.style) wrapper.dataset.style = scratch.dataset.style;
441
+ } catch (e) {
442
+ if (runs.get(el) !== run) return;
443
+ console.error("[guidex]", e);
444
+ renderError(wrapper, e instanceof Error ? e.message : String(e));
445
+ }
446
+ }
447
+ /** Renders every target under `root` (default: the whole document).
448
+ * Already-rendered targets re-render from their cached source, so a
449
+ * host can change data attributes or the source text and call this to
450
+ * refresh. Resolves when every score has finished rendering. */
451
+ async function renderAll(root = document) {
452
+ const selector = globalOptions.selector ?? DEFAULT_SELECTOR;
453
+ const targets = [];
454
+ if (root instanceof Element && root.matches(selector)) targets.push(root);
455
+ targets.push(...root.querySelectorAll(selector));
456
+ return Promise.all(targets.map((el) => {
457
+ attachResizeListener(el);
458
+ return renderElement(el);
459
+ })).then(() => void 0);
460
+ }
461
+ /** Late-added elements (AJAX, SPA routing) render too: document-wide
462
+ * child mutations are scanned for matching targets. Our own score
463
+ * elements are skipped, so renders never re-trigger the observer. */
464
+ var observerStarted = false;
465
+ function startMutationObserver() {
466
+ if (observerStarted || typeof MutationObserver === "undefined") return;
467
+ observerStarted = true;
468
+ const selector = globalOptions.selector ?? DEFAULT_SELECTOR;
469
+ new MutationObserver((mutations) => {
470
+ const targets = /* @__PURE__ */ new Set();
471
+ for (const mutation of mutations) for (const node of mutation.addedNodes) {
472
+ if (!(node instanceof Element)) continue;
473
+ if (node.closest(".guidex-render")) continue;
474
+ if (node.matches(selector)) targets.add(node);
475
+ for (const match of node.querySelectorAll(selector)) targets.add(match);
476
+ }
477
+ for (const el of targets) {
478
+ attachResizeListener(el);
479
+ renderElement(el);
480
+ }
481
+ }).observe(document.documentElement, {
482
+ childList: true,
483
+ subtree: true
484
+ });
485
+ }
486
+ /** Sets site-wide defaults and renders the document. Call again (even
487
+ * with different options) to re-render everything with new settings. */
488
+ function init(options = {}) {
489
+ globalOptions = {
490
+ ...globalOptions,
491
+ ...options
492
+ };
493
+ startMutationObserver();
494
+ renderAll();
495
+ }
496
+ //#endregion
497
+ //#region src/scoreImage.ts
498
+ /** The computed properties that draw a score line and its content:
499
+ * everything load-bearing beyond the renderer's own inline styles (the
500
+ * notes line's leading and padding, the theme's resolved colors, the
501
+ * relative shifts) comes from this list. Box widths are deliberately
502
+ * absent — a block line spans its container, not its content, and the
503
+ * sized elements (the spacer spans) already carry inline widths. */
504
+ var COPY_PROPS = [
505
+ "font-family",
506
+ "font-size",
507
+ "font-style",
508
+ "font-weight",
509
+ "line-height",
510
+ "letter-spacing",
511
+ "text-transform",
512
+ "color",
513
+ "position",
514
+ "top",
515
+ "left",
516
+ "margin-top",
517
+ "margin-bottom",
518
+ "padding-top",
519
+ "padding-bottom"
520
+ ];
521
+ /** The wrapper (the render container's stand-in) gets typography only:
522
+ * no box properties, so the cloned lines stack from the crop's own
523
+ * top-left corner. */
524
+ var WRAPPER_PROPS = [
525
+ "font-family",
526
+ "font-size",
527
+ "font-style",
528
+ "font-weight",
529
+ "line-height",
530
+ "letter-spacing",
531
+ "color"
532
+ ];
533
+ /** Debug/export furniture skipped when cloning: the editor's max-width
534
+ * guide and anything the host marks with `data-score-image-ignore`. The
535
+ * debug syllable guides need no entry — they are ::before/::after CSS,
536
+ * which never clones. */
537
+ function isIgnorable(el) {
538
+ return el.classList.contains("max-width-guide") || el.hasAttribute("data-score-image-ignore");
539
+ }
540
+ /** The element whose direct children are the rendered line pairs: the
541
+ * parent of the first chant-font line under `el`. Accepts the render
542
+ * container itself or any ancestor of it (the editor's outer score div,
543
+ * an embed target). */
544
+ function scoreRoot(el) {
545
+ const root = el.querySelector(".guido")?.parentElement;
546
+ if (!root) throw new Error("No rendered score found to export — render a score into the element first.");
547
+ return root;
548
+ }
549
+ /** One line's content extent, relative to the line box's own top-left
550
+ * corner: the union of its contents' rects. The line box itself is
551
+ * excluded horizontally (it spans the container, not the text); the
552
+ * Range covers the text nodes and each descendant element rect keeps
553
+ * the position:relative shifts (raised runs, the break star). */
554
+ function lineExtent(line) {
555
+ const box = line.getBoundingClientRect();
556
+ const parts = [];
557
+ const range = document.createRange();
558
+ range.selectNodeContents(line);
559
+ if (typeof range.getBoundingClientRect === "function") parts.push(range.getBoundingClientRect());
560
+ line.querySelectorAll("*").forEach((el) => parts.push(el.getBoundingClientRect()));
561
+ if (parts.length === 0) parts.push(box);
562
+ return {
563
+ left: Math.min(...parts.map((r) => r.left)) - box.left,
564
+ top: Math.min(...parts.map((r) => r.top)) - box.top,
565
+ right: Math.max(...parts.map((r) => r.right)) - box.left,
566
+ bottom: Math.max(...parts.map((r) => r.bottom)) - box.top
567
+ };
568
+ }
569
+ /** How many visual rows a line's content occupies: the Range's client
570
+ * rects cluster into rows by vertical overlap (inline boxes of
571
+ * different sizes sit side by side on one row with different tops). A
572
+ * line that wraps inside its host container must re-wrap at the same
573
+ * width in the clone, so it is pinned to its live box width. */
574
+ function countRows(line) {
575
+ const range = document.createRange();
576
+ range.selectNodeContents(line);
577
+ if (typeof range.getClientRects !== "function") return 1;
578
+ const rects = Array.from(range.getClientRects()).filter((r) => r.width > 0 || r.height > 0);
579
+ if (rects.length === 0) return 1;
580
+ rects.sort((a, b) => a.top - b.top);
581
+ let rows = 0;
582
+ let rowBottom = -Infinity;
583
+ for (const r of rects) if (r.top >= rowBottom) {
584
+ rows++;
585
+ rowBottom = r.bottom;
586
+ } else if (r.bottom > rowBottom) rowBottom = r.bottom;
587
+ return rows;
588
+ }
589
+ /** Splits a computed font-family stack into family names, honoring
590
+ * quotes around names that contain commas. */
591
+ function parseFamilies(stack) {
592
+ const families = [];
593
+ let current = "";
594
+ let quote = null;
595
+ for (const ch of stack) if (quote) {
596
+ if (ch === quote) quote = null;
597
+ else current += ch;
598
+ } else if (ch === "\"" || ch === "'") quote = ch;
599
+ else if (ch === ",") {
600
+ families.push(current.trim());
601
+ current = "";
602
+ } else current += ch;
603
+ families.push(current.trim());
604
+ return families.filter(Boolean);
605
+ }
606
+ function normalizeWeight(weight) {
607
+ if (weight === "normal") return "400";
608
+ if (weight === "bold") return "700";
609
+ return weight;
610
+ }
611
+ /** Escapes a value for use inside a double-quoted XML attribute. */
612
+ function escapeXmlAttribute(value) {
613
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
614
+ }
615
+ /** Builds one face from a `src` value plus its descriptor strings,
616
+ * resolving the URL against `baseHref`. Undefined when the src has no
617
+ * fetchable url() (local()-only faces need no embedding). */
618
+ function faceFromSrc(family, styleRaw, weightRaw, src, baseHref) {
619
+ const urlMatch = /url\(\s*(['"]?)([^'")]+)\1\s*\)/.exec(src);
620
+ if (!urlMatch) return void 0;
621
+ let url;
622
+ try {
623
+ url = new URL(urlMatch[2], baseHref ?? location.href).toString();
624
+ } catch {
625
+ return;
626
+ }
627
+ return {
628
+ family,
629
+ style: styleRaw || "normal",
630
+ weight: normalizeWeight(weightRaw || "400"),
631
+ url,
632
+ format: /format\(\s*['"]?([^'")]+?)['"]?\s*\)/.exec(src)?.[1]
633
+ };
634
+ }
635
+ /** Parses @font-face blocks out of a stylesheet's raw text — the
636
+ * fallback for cross-origin sheets whose `cssRules` are unreadable but
637
+ * whose file a CORS fetch can still reach (the CDN-served embed build). */
638
+ function parseFontFacesFromCss(cssText, baseUrl) {
639
+ const faces = [];
640
+ for (const match of cssText.matchAll(/@font-face\s*{([^}]*)}/g)) {
641
+ const block = match[1];
642
+ const pick = (prop) => {
643
+ const m = new RegExp(`(?:^|[;\\s])${prop}\\s*:\\s*([^;]+)`, "i").exec(block);
644
+ return m ? m[1].trim() : "";
645
+ };
646
+ const familyRaw = pick("font-family");
647
+ const src = pick("src");
648
+ if (!familyRaw || !src) continue;
649
+ const family = parseFamilies(familyRaw)[0];
650
+ if (!family) continue;
651
+ const face = faceFromSrc(family, pick("font-style"), pick("font-weight"), src, baseUrl);
652
+ if (face) faces.push(face);
653
+ }
654
+ return faces;
655
+ }
656
+ /** Collects the @font-face rules for `families` from every stylesheet.
657
+ * Cross-origin sheets throw on `cssRules`; their text is fetched
658
+ * instead and parsed by hand, so a CDN-served embed build's fonts still
659
+ * travel with the export. Faces dedupe per family/style/weight — one
660
+ * font file can legitimately serve several declarations. */
661
+ async function collectFontFaces(families) {
662
+ const faces = [];
663
+ const seenKeys = /* @__PURE__ */ new Set();
664
+ const addFace = (face) => {
665
+ const key = `${face.family}|${face.style}|${face.weight}`;
666
+ if (seenKeys.has(key)) return;
667
+ seenKeys.add(key);
668
+ faces.push(face);
669
+ };
670
+ const crossOriginSheets = [];
671
+ for (const sheet of document.styleSheets) {
672
+ let rules;
673
+ try {
674
+ rules = sheet.cssRules;
675
+ } catch {
676
+ if (sheet.href) crossOriginSheets.push(sheet.href);
677
+ continue;
678
+ }
679
+ for (const rule of Array.from(rules)) {
680
+ const style = rule.style;
681
+ if (!style) continue;
682
+ const src = style.getPropertyValue("src");
683
+ const familyRaw = style.getPropertyValue("font-family");
684
+ if (!src || !familyRaw) continue;
685
+ const family = parseFamilies(familyRaw)[0];
686
+ if (!family || !families.has(family)) continue;
687
+ const face = faceFromSrc(family, style.getPropertyValue("font-style"), style.getPropertyValue("font-weight"), src, sheet.href ?? void 0);
688
+ if (face) addFace(face);
689
+ }
690
+ }
691
+ for (const href of crossOriginSheets) try {
692
+ const response = await fetch(href);
693
+ if (!response.ok) throw new Error(String(response.status));
694
+ const text = await response.text();
695
+ for (const face of parseFontFacesFromCss(text, href)) if (families.has(face.family)) addFace(face);
696
+ } catch {
697
+ console.warn(`[guidex] scoreImage: a cross-origin stylesheet (${href}) could not be read — fonts declared only there are missing from the export`);
698
+ }
699
+ return faces;
700
+ }
701
+ async function fetchFontDataUrl(url) {
702
+ const response = await fetch(url);
703
+ if (!response.ok) return void 0;
704
+ const blob = await response.blob();
705
+ return new Promise((resolve) => {
706
+ const reader = new FileReader();
707
+ reader.onload = () => resolve(typeof reader.result === "string" ? reader.result : void 0);
708
+ reader.onerror = () => resolve(void 0);
709
+ reader.readAsDataURL(blob);
710
+ });
711
+ }
712
+ /** Fetches and inlines faces as base64 @font-face blocks. Faces share
713
+ * fetched files through a URL cache; a family's normal faces always
714
+ * embed, its italic faces when the tree uses italics — or when the
715
+ * family declares nothing else, since the browser would use them
716
+ * anyway. A face whose file cannot be fetched is skipped with a warning
717
+ * — the picture falls back to the next family in the stack, as the page
718
+ * itself would. */
719
+ async function embedFontFaces(faces, italics) {
720
+ const blocks = [];
721
+ const failed = /* @__PURE__ */ new Set();
722
+ const dataUrls = /* @__PURE__ */ new Map();
723
+ const fetchDataUrl = (url) => {
724
+ let pending = dataUrls.get(url);
725
+ if (!pending) {
726
+ pending = fetchFontDataUrl(url).catch(() => void 0);
727
+ dataUrls.set(url, pending);
728
+ }
729
+ return pending;
730
+ };
731
+ const byFamily = /* @__PURE__ */ new Map();
732
+ for (const face of faces) {
733
+ const group = byFamily.get(face.family) ?? [];
734
+ group.push(face);
735
+ byFamily.set(face.family, group);
736
+ }
737
+ for (const [family, group] of byFamily) {
738
+ const normal = group.filter((f) => f.style === "normal");
739
+ const keep = normal.length > 0 ? [...normal, ...italics ? group.filter((f) => f.style !== "normal") : []] : group;
740
+ for (const face of keep) {
741
+ const dataUrl = await fetchDataUrl(face.url);
742
+ if (!dataUrl) {
743
+ failed.add(family);
744
+ continue;
745
+ }
746
+ const format = face.format ? ` format('${face.format}')` : "";
747
+ blocks.push(`@font-face{font-family:'${face.family}';font-style:${face.style};font-weight:${face.weight};src:url(${dataUrl})${format}}`);
748
+ }
749
+ }
750
+ for (const family of failed) console.warn(`[guidex] scoreImage: could not embed the ${family} webfont — the export falls back to the next family in its stack`);
751
+ return blocks.join("");
752
+ }
753
+ /** Normalizes any CSS color string to the CSSOM's canonical form, so a
754
+ * stylesheet's `--red: #d40000` matches a computed `rgb(212, 0, 0)`. A
755
+ * fresh probe element per call: getComputedStyle declarations are
756
+ * cached per element, so a reused probe would answer every later
757
+ * comparison with its first value. */
758
+ function colorProbe(value) {
759
+ const probe = document.createElement("span");
760
+ probe.style.color = value;
761
+ return getComputedStyle(probe).color;
762
+ }
763
+ /** The style set's accent, resolved from the container's `--red` custom
764
+ * property to its canonical form ('' when none is in scope). */
765
+ function resolvedAccent(container) {
766
+ const raw = getComputedStyle(container).getPropertyValue("--red").trim();
767
+ return raw ? colorProbe(raw) : "";
768
+ }
769
+ /** Whether an element's ink is the accent: either its computed color
770
+ * equals the resolved accent, or its inline color is the `var(--red)`
771
+ * reference the style sets put on accent runs (the form a CSSOM without
772
+ * custom-property resolution leaves in place). */
773
+ function isAccentInk(el, computedColor, accent) {
774
+ if (accent && computedColor && colorProbe(computedColor) === accent) return true;
775
+ return el.style?.getPropertyValue("color").replace(/\s+/g, "") === "var(--red)";
776
+ }
777
+ /** Copies the computed properties from each original onto its clone and
778
+ * reports which webfont families / styles the tree uses, so only those
779
+ * faces are embedded. Runs after the clone, so literal computed values
780
+ * overwrite the clone's inherited `var()` references — that is what
781
+ * bakes the current theme into the picture. The `foreground`/`accent`
782
+ * overrides remap that ink: accent-classified elements take the accent
783
+ * color, everything else the foreground. */
784
+ function copyComputedStyles(originals, clones, overrides) {
785
+ const families = /* @__PURE__ */ new Set();
786
+ let italics = false;
787
+ for (let i = 0; i < originals.length; i++) {
788
+ const original = originals[i];
789
+ const clone = clones[i];
790
+ const computed = getComputedStyle(original);
791
+ for (const prop of i === 0 ? WRAPPER_PROPS : COPY_PROPS) {
792
+ if (prop === "color") {
793
+ const computedColor = computed.getPropertyValue("color");
794
+ if (!computedColor) continue;
795
+ const override = isAccentInk(original, computedColor, overrides.accentProbe) ? overrides.accent : overrides.foreground;
796
+ clone.style.setProperty("color", override || computedColor);
797
+ continue;
798
+ }
799
+ const value = computed.getPropertyValue(prop);
800
+ if (value) clone.style.setProperty(prop, value);
801
+ }
802
+ const family = computed.getPropertyValue("font-family");
803
+ if (family) for (const f of parseFamilies(family)) families.add(f);
804
+ if (computed.getPropertyValue("font-style") === "italic") italics = true;
805
+ }
806
+ return {
807
+ families,
808
+ italics
809
+ };
810
+ }
811
+ async function fontsReady() {
812
+ const fonts = document.fonts;
813
+ if (fonts?.ready) await fonts.ready;
814
+ }
815
+ /** The whole capture: crop measurement, styled clone, embedded fonts,
816
+ * and the assembled SVG string with its outer pixel size. */
817
+ async function serializeScore(el, options) {
818
+ const padding = Math.max(0, options.padding ?? 0);
819
+ const root = scoreRoot(el);
820
+ if (!root.isConnected) throw new Error("scoreImage: the score left the document before the export — re-render it and try again");
821
+ await fontsReady();
822
+ const lines = Array.from(root.children).filter((child) => child.classList.contains("guido") || child.tagName === "P");
823
+ if (lines.length === 0) throw new Error("No rendered score found to export — render a score into the element first.");
824
+ const lineRects = lines.map((line) => line.getBoundingClientRect());
825
+ const base = lineRects[0];
826
+ const stacked = lines.map((line, i) => {
827
+ const extent = lineExtent(line);
828
+ const rect = lineRects[i];
829
+ const offsetLeft = rect.left - base.left;
830
+ const wraps = countRows(line) > 1;
831
+ return {
832
+ left: extent.left + offsetLeft,
833
+ top: extent.top + (rect.top - base.top),
834
+ right: (wraps ? Math.max(rect.width, extent.right) : extent.right) + offsetLeft,
835
+ bottom: extent.bottom + (rect.top - base.top),
836
+ pinWidth: wraps ? rect.width : void 0
837
+ };
838
+ });
839
+ const cropLeft = Math.min(0, ...stacked.map((e) => e.left));
840
+ const cropTop = Math.min(0, ...stacked.map((e) => e.top));
841
+ const contentRight = Math.max(...stacked.map((e) => e.right));
842
+ const contentBottom = Math.max(...stacked.map((e) => e.bottom));
843
+ const width = Math.max(1, Math.ceil(contentRight - cropLeft)) + padding * 2;
844
+ const height = Math.max(1, Math.ceil(contentBottom - cropTop)) + padding * 2;
845
+ const clone = root.cloneNode(true);
846
+ clone.querySelectorAll(".max-width-guide, [data-score-image-ignore]").forEach((el) => el.remove());
847
+ const originals = [root];
848
+ const clones = [clone];
849
+ const walk = (el, into) => {
850
+ for (const child of el.children) {
851
+ if (isIgnorable(child)) continue;
852
+ into.push(child);
853
+ walk(child, into);
854
+ }
855
+ };
856
+ walk(root, originals);
857
+ walk(clone, clones);
858
+ if (clones.length !== originals.length) throw new Error("scoreImage: the cloned tree diverged from the live one");
859
+ for (const el of [clone, ...clone.querySelectorAll("*")]) el.removeAttribute("title");
860
+ const { families, italics } = copyComputedStyles(originals, clones, {
861
+ foreground: options.foreground,
862
+ accent: options.accent,
863
+ accentProbe: resolvedAccent(root)
864
+ });
865
+ clone.style.setProperty("white-space", "nowrap");
866
+ const cloneLines = Array.from(clone.children).filter((child) => child.classList.contains("guido") || child.tagName === "P");
867
+ stacked.forEach((entry, i) => {
868
+ const cloneLine = cloneLines[i];
869
+ if (entry.pinWidth !== void 0 && cloneLine) cloneLine.style.setProperty("width", `${entry.pinWidth}px`);
870
+ });
871
+ clone.style.setProperty("padding-top", `${padding - cropTop}px`);
872
+ clone.style.setProperty("padding-left", `${padding - cropLeft}px`);
873
+ clone.style.setProperty("padding-right", `${padding}px`);
874
+ clone.style.setProperty("padding-bottom", `${padding}px`);
875
+ const faceCss = await embedFontFaces(await collectFontFaces(families), italics);
876
+ const wrapper = new XMLSerializer().serializeToString(clone);
877
+ const bgRect = options.background ? `<rect width="100%" height="100%" fill="${escapeXmlAttribute(options.background)}"/>` : "";
878
+ return {
879
+ svg: `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">` + bgRect + (faceCss ? `<style>${faceCss}</style>` : "") + `<foreignObject x="0" y="0" width="${width}" height="${height}">` + wrapper + "</foreignObject></svg>",
880
+ width,
881
+ height
882
+ };
883
+ }
884
+ /** Serializes the rendered score under `el` into a self-contained SVG
885
+ * string (fonts embedded, colors resolved) sized to the score's content.
886
+ * Throws when no score was rendered into the element. */
887
+ async function scoreSvg(el, options = {}) {
888
+ return (await serializeScore(el, options)).svg;
889
+ }
890
+ /** Rasterizes the rendered score under `el` to a PNG blob: the
891
+ * self-contained SVG loads as an image (the browser's own renderer
892
+ * paints it, so the picture matches the DOM exactly) and draws onto a
893
+ * canvas at `scale`×. Throws when no score was rendered into the
894
+ * element or the environment has no 2D canvas. */
895
+ async function scorePngBlob(el, options = {}) {
896
+ const { svg, width, height } = await serializeScore(el, options);
897
+ const scale = Math.max(1, options.scale ?? 2);
898
+ const image = new Image();
899
+ image.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
900
+ await new Promise((resolve, reject) => {
901
+ image.onload = () => resolve();
902
+ image.onerror = () => reject(/* @__PURE__ */ new Error("scoreImage: the exported SVG failed to rasterize"));
903
+ });
904
+ try {
905
+ await image.decode();
906
+ } catch {}
907
+ const canvas = document.createElement("canvas");
908
+ canvas.width = Math.ceil(width * scale);
909
+ canvas.height = Math.ceil(height * scale);
910
+ const ctx = canvas.getContext("2d");
911
+ if (!ctx) throw new Error("scoreImage: this environment provides no 2D canvas");
912
+ ctx.scale(scale, scale);
913
+ if (options.background) {
914
+ ctx.fillStyle = options.background;
915
+ ctx.fillRect(0, 0, width, height);
916
+ }
917
+ const draw = () => ctx.drawImage(image, 0, 0, width, height);
918
+ draw();
919
+ if (/^((?!chrome|android|crios|fxios).)*safari/i.test(navigator.userAgent)) {
920
+ await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
921
+ draw();
922
+ }
923
+ const blob = await new Promise((resolve) => canvas.toBlob(resolve, "image/png"));
924
+ if (!blob) throw new Error("scoreImage: PNG encoding failed");
925
+ return blob;
926
+ }
927
+ function downloadBlob(blob, filename) {
928
+ const url = URL.createObjectURL(blob);
929
+ const anchor = document.createElement("a");
930
+ anchor.href = url;
931
+ anchor.download = filename;
932
+ anchor.click();
933
+ setTimeout(() => URL.revokeObjectURL(url), 1e4);
934
+ }
935
+ /** Exports the rendered score under `el` as a PNG download. Resolves
936
+ * with the filename used. */
937
+ async function downloadScorePng(el, options = {}) {
938
+ const filename = options.filename ?? "score.png";
939
+ downloadBlob(await scorePngBlob(el, options), filename);
940
+ return filename;
941
+ }
942
+ /** Exports the rendered score under `el` as a self-contained SVG
943
+ * download (fonts embedded — the print-friendlier artifact). Resolves
944
+ * with the filename used. */
945
+ async function downloadScoreSvg(el, options = {}) {
946
+ const filename = options.filename ?? "score.svg";
947
+ downloadBlob(new Blob([await scoreSvg(el, options)], { type: "image/svg+xml;charset=utf-8" }), filename);
948
+ return filename;
949
+ }
950
+ //#endregion
951
+ export { dispose as a, renderScore as c, scoreSvg as i, version as l, downloadScoreSvg as n, init as o, scorePngBlob as r, renderAll as s, downloadScorePng as t };