guidex 0.5.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +215 -0
  2. package/README.md +62 -16
  3. package/dist/lib/app/App.d.ts +1 -0
  4. package/dist/lib/app/AretinoControls.d.ts +35 -0
  5. package/dist/lib/app/CaretBand.d.ts +28 -0
  6. package/dist/lib/app/Developers.d.ts +13 -0
  7. package/dist/lib/app/EditorContext.d.ts +15 -0
  8. package/dist/lib/app/EditorTextarea.d.ts +18 -1
  9. package/dist/lib/app/EditorToolbar.d.ts +13 -0
  10. package/dist/lib/app/ExportSettings.d.ts +20 -1
  11. package/dist/lib/app/Footer.d.ts +1 -0
  12. package/dist/lib/app/GlyphChooser.d.ts +31 -0
  13. package/dist/lib/app/Inspector.d.ts +26 -0
  14. package/dist/lib/app/LiveScore.d.ts +31 -0
  15. package/dist/lib/app/Opening.d.ts +3 -0
  16. package/dist/lib/app/Reference.d.ts +28 -0
  17. package/dist/lib/app/RenderSettings.d.ts +2 -1
  18. package/dist/lib/app/ScriptViews.d.ts +8 -0
  19. package/dist/lib/app/SectionSize.d.ts +33 -0
  20. package/dist/lib/app/StaffSettings.d.ts +4 -0
  21. package/dist/lib/app/StaffedGlyph.d.ts +8 -0
  22. package/dist/lib/app/Tabs.d.ts +15 -0
  23. package/dist/lib/app/TakeItOut.d.ts +1 -0
  24. package/dist/lib/app/ThemeSwitch.d.ts +1 -0
  25. package/dist/lib/app/TopBar.d.ts +6 -0
  26. package/dist/lib/app/WidthControls.d.ts +21 -0
  27. package/dist/lib/app/aretinoCaret.d.ts +47 -0
  28. package/dist/lib/app/aretinoSource.d.ts +46 -0
  29. package/dist/lib/app/caretSync.d.ts +48 -0
  30. package/dist/lib/app/chantLibrary.d.ts +8 -4
  31. package/dist/lib/app/editorSnapshot.d.ts +11 -0
  32. package/dist/lib/app/editorState.d.ts +38 -5
  33. package/dist/lib/app/expandLink.d.ts +19 -0
  34. package/dist/lib/app/glyphData.d.ts +37 -0
  35. package/dist/lib/app/inCode.d.ts +4 -0
  36. package/dist/lib/app/insertAtCaret.d.ts +12 -0
  37. package/dist/lib/app/learn/Learn.d.ts +1 -0
  38. package/dist/lib/app/learn/LessonCard.d.ts +12 -0
  39. package/dist/lib/app/learn/lessons.d.ts +64 -0
  40. package/dist/lib/app/learn/narrowing.d.ts +24 -0
  41. package/dist/lib/app/learn/progress.d.ts +14 -0
  42. package/dist/lib/app/pageEvents.d.ts +14 -0
  43. package/dist/lib/app/previewHighlight.d.ts +44 -0
  44. package/dist/lib/app/samples.d.ts +9 -1
  45. package/dist/lib/app/scriptParts.d.ts +31 -0
  46. package/dist/lib/app/shareLink.d.ts +12 -2
  47. package/dist/lib/app/showcases/Showcases.d.ts +17 -0
  48. package/dist/lib/app/wordCopy.d.ts +4 -0
  49. package/dist/lib/aretino/fromAretino.d.ts +99 -0
  50. package/dist/lib/aretino/index.d.ts +38 -0
  51. package/dist/lib/aretino/index.js +1870 -0
  52. package/dist/lib/aretino/toAretino.d.ts +27 -0
  53. package/dist/lib/chantLayout-BRQ6FYND.js +1345 -0
  54. package/dist/lib/chantLayout.d.ts +101 -6
  55. package/dist/lib/chantMarkup-DX4K86Rv.js +993 -0
  56. package/dist/lib/drawnStaff.d.ts +39 -5
  57. package/dist/lib/editorStorage.d.ts +48 -6
  58. package/dist/lib/embed/core.d.ts +15 -1
  59. package/dist/lib/embed/index.js +1 -1
  60. package/dist/lib/embed/manual.d.ts +5 -4
  61. package/dist/lib/embed/manual.js +6 -4
  62. package/dist/lib/fonts/guidohu-staffless.woff2 +0 -0
  63. package/dist/lib/fonts/guidohu.ttf +0 -0
  64. package/dist/lib/glyphFamilies.d.ts +5 -1
  65. package/dist/lib/guidoRender.d.ts +30 -1
  66. package/dist/lib/guidoScriptTransforms.d.ts +2 -2
  67. package/dist/lib/guidoStyles-CvnACCsk.js +1466 -0
  68. package/dist/lib/guidoStyles.d.ts +23 -2
  69. package/dist/lib/react/GuidexScore.d.ts +10 -2
  70. package/dist/lib/react/index.js +14 -4
  71. package/dist/lib/{scoreImage-B2SGdROL.js → scoreImage-CKsQxHg5.js} +282 -1026
  72. package/dist/lib/theme.d.ts +13 -0
  73. package/dist/lib/word/index.d.ts +1 -1
  74. package/dist/lib/word/index.js +1 -1
  75. package/dist/lib/{wordChecker-CjYl2yof.js → wordChecker-BN_9dKAx.js} +133 -20
  76. package/dist/lib/wordChecker.d.ts +18 -1
  77. package/dist/lib/wordExport.d.ts +51 -3
  78. package/dist-embed/demo.html +2 -2
  79. package/dist-embed/fonts/guidohu-staffless.woff2 +0 -0
  80. package/dist-embed/fonts/guidohu.ttf +0 -0
  81. package/dist-embed/guidex-embed.min.js +1 -1
  82. package/package.json +10 -1
  83. package/dist/lib/app/ControlsRow.d.ts +0 -1
  84. package/dist/lib/app/SettingsMenu.d.ts +0 -1
  85. package/dist/lib/app/SettingsPanel.d.ts +0 -1
  86. package/dist/lib/chantLayout-BrCQUOhp.js +0 -2616
@@ -1,968 +1,6 @@
1
- import { A as CLEF_GLYPHS, D as resolveSpans, E as unescape, F as isModifierGlyph, K as variantOf, M as baseOf, P as isClefGlyph, U as toSmallHead, _ as GuidoScript, b as isC4ClefGroup, f as resolveMarks, g as unknownMarks, h as styleSetOf, j as STAFF, k as splitNoteMarkers, l as inlineStylesFor, m as resolveTextRuns, r as layoutScore, u as kindOf, w as statementSource, x as isStatementGroup, y as escape, z as pitchLetterOf } from "./chantLayout-BrCQUOhp.js";
2
- //#region src/stanzas.ts
3
- /**
4
- * Stanzas on one melody (issue #69): a hymn stores its melody once, as
5
- * stanza 1's GuidoScript, and every further stanza as syllabified text
6
- * whose syllables map one-to-one onto the melody's note groups — the
7
- * slots.
8
- *
9
- * A slot is one note group: held groups and `~` empty slots included
10
- * (issue #83), syllables without notes and marker-only groups not. The
11
- * further stanzas ride the script as `(@stanza …)` statements at its end
12
- * (`GuidoScript.stanzas`), or come from a `stanzas` option that replaces
13
- * them. Stanza numbers and slot numbers are 1-based: stanza 1 is the
14
- * script itself, and they are what the warnings report.
15
- *
16
- * Stanza text follows Aretino's lyric-line rules (see `parseStanza`).
17
- * Rendering stanza k is a script rewrite (`selectStanza`, `withStanza`):
18
- * its syllables are swapped onto the slots, the notes never change, so
19
- * every emitter (DOM, image, Word) works on the result unchanged.
20
- */
21
- /** The syllable text that marks a slot a stanza is missing a syllable
22
- * for: a rubric ellipsis, red in BNS, so the mismatch shows in the
23
- * render (and in the Word export). */
24
- var STANZA_PLACEHOLDER = "_…_";
25
- /** The unescaped characters that end a syllable within a word: the
26
- * hyphen, the mandatory hyphen and the soft hyphen. */
27
- var SYLLABLE_BREAKS = "-=­";
28
- /** The characters an escape takes out of the syllable formatting. */
29
- var MARKUP_CHARS = "_*†∗{}";
30
- /**
31
- * Parses stanza text into its slot items, by Aretino's lyric-line rules:
32
- *
33
- * - whitespace separates words, `-` separates the syllables of a word
34
- * (a soft hyphen U+00AD counts as `-`, and so does the mandatory
35
- * hyphen `=` — the renderer has no hyphen it may not drop yet);
36
- * - a lone `-` (or an empty syllable, `Al--le`) holds the slot for the
37
- * syllable before it; that syllable's word end is its own (`Al- - le`
38
- * is mid-word, `bunt - gen` ends the word);
39
- * - a lone `~` is an empty slot; `~` inside a syllable is a
40
- * non-breaking space;
41
- * - a backslash makes the next character literal (`\-`, `\~`, `\=`,
42
- * `\(`, `\\`), markup characters included (`\_`, `\*`).
43
- *
44
- * There are no `_` extenders: `_…_`, `__…__` and `*…*` stay the
45
- * syllable formatting of the script notation.
46
- */
47
- function parseStanza(text) {
48
- const words = [];
49
- let word = null;
50
- const chars = Array.from(text);
51
- for (let i = 0; i < chars.length; i++) {
52
- let ch = chars[i];
53
- const escaped = ch === "\\" && i + 1 < chars.length;
54
- if (escaped) ch = chars[++i];
55
- if (!escaped && /\s/.test(ch)) {
56
- word = null;
57
- continue;
58
- }
59
- if (word === null) {
60
- word = [];
61
- words.push(word);
62
- }
63
- word.push({
64
- ch,
65
- escaped
66
- });
67
- }
68
- const out = [];
69
- for (const w of words) {
70
- if (w.length === 1 && !w[0].escaped && w[0].ch === "~") {
71
- out.push({ kind: "empty" });
72
- continue;
73
- }
74
- const pieces = [""];
75
- const written = [""];
76
- for (const { ch, escaped } of w) {
77
- if (!escaped && SYLLABLE_BREAKS.includes(ch)) {
78
- pieces.push("");
79
- written.push("");
80
- continue;
81
- }
82
- const shown = !escaped && ch === "~" ? "\xA0" : ch;
83
- pieces[pieces.length - 1] += shown;
84
- written[written.length - 1] += escaped && MARKUP_CHARS.includes(ch) ? `\\${ch}` : escape(shown);
85
- }
86
- const last = pieces.length - 1;
87
- for (const [p, piece] of pieces.entries()) {
88
- if (piece === "") {
89
- if (p < last) out.push({ kind: "hold" });
90
- continue;
91
- }
92
- const source = written[p];
93
- out.push({
94
- kind: "syllable",
95
- text: piece,
96
- wordEnd: p === last,
97
- ...source !== escape(piece) ? { source } : {}
98
- });
99
- }
100
- }
101
- return standaloneSpans(out);
102
- }
103
- /** Closes a `{…}` span at each stanza syllable and reopens it at the next,
104
- * so a syllable stands on its own wherever a slice cuts the stanza. */
105
- function standaloneSpans(items) {
106
- const syllables = items.filter((item) => item.kind === "syllable");
107
- const written = syllables.map((syl) => syl.source ?? escape(syl.text));
108
- if (!written.some((text) => /[{}]/.test(text))) return items;
109
- const { pieces } = resolveSpans(written);
110
- for (const [i, syl] of syllables.entries()) syl.source = pieces[i].source;
111
- return items;
112
- }
113
- /** Whether a token opens a slot: a sung syllable with notes that are not
114
- * all markers. Labels and signs are never slots. */
115
- function isSlot(tok) {
116
- return tok.kind === "syllable" && tok.role !== "label" && tok.role !== "sign" && tok.notes !== "" && splitNoteMarkers(tok.notes).core !== "";
117
- }
118
- function parsed(script) {
119
- return typeof script === "string" ? new GuidoScript(script) : script;
120
- }
121
- /** The number of slots (note groups that take a stanza syllable). */
122
- function slotCount(script) {
123
- return parsed(script).tokens.filter(isSlot).length;
124
- }
125
- /** The stanza texts of stanzas 2, 3, …: the `stanzas` option when
126
- * given, the script's `(@stanza …)` statements otherwise. */
127
- function stanzaTexts(script, options = {}) {
128
- return options.stanzas ?? parsed(script).stanzas;
129
- }
130
- /** How many stanzas the script has, stanza 1 (the script) included. */
131
- function stanzaCount(script, options = {}) {
132
- return stanzaTexts(script, options).length + 1;
133
- }
134
- function sings(fill) {
135
- return fill.kind === "syllable" || fill.kind === "hold";
136
- }
137
- /** Stanza 1's fills: the slot tokens themselves. */
138
- function scriptFills(slots) {
139
- return slots.map((tok) => tok.empty ? { kind: "empty" } : tok.held ? { kind: "hold" } : {
140
- kind: "syllable",
141
- text: tok.text,
142
- source: tok.source,
143
- wordEnd: tok.wordEnd
144
- });
145
- }
146
- /** A stanza's syllables laid on `count` slots, with its mismatches. */
147
- function alignStanza(text, count, stanza) {
148
- const syllables = parseStanza(text);
149
- const fills = [];
150
- const warnings = [];
151
- for (let i = 0; i < count; i++) {
152
- const syl = syllables[i];
153
- fills.push(syl ?? { kind: "missing" });
154
- if (syl === void 0) warnings.push({
155
- stanza,
156
- slot: i + 1,
157
- kind: "missing",
158
- message: `Stanza ${stanza} has no syllable for slot ${i + 1} of ${count}`
159
- });
160
- }
161
- for (const [i, syl] of syllables.slice(count).entries()) {
162
- const shown = syl.kind === "syllable" ? syl.text : syl.kind === "hold" ? "-" : "~";
163
- warnings.push({
164
- stanza,
165
- slot: count + i + 1,
166
- kind: "extra",
167
- text: shown,
168
- message: `Stanza ${stanza} has an extra syllable "${shown}" past the last slot (${count})`
169
- });
170
- }
171
- return {
172
- fills,
173
- warnings
174
- };
175
- }
176
- /** Throws when `stanza` is not one of the script's stanzas. */
177
- function checkStanzaNumber(stanza, count) {
178
- if (!Number.isInteger(stanza) || stanza < 1 || stanza > count) throw new RangeError(`Stanza ${stanza} does not exist: the script has ${count} stanza${count === 1 ? "" : "s"}`);
179
- }
180
- /** The count mismatches of one stanza (`options.stanza`), or of every
181
- * stanza when none is named. Stanza 1 is the script and never warns;
182
- * an intentional `~` is a syllable like any other. */
183
- function stanzaWarnings(script, options = {}) {
184
- const texts = stanzaTexts(script, options);
185
- const count = slotCount(script);
186
- if (options.stanza !== void 0) {
187
- checkStanzaNumber(options.stanza, texts.length + 1);
188
- if (options.stanza === 1) return [];
189
- return alignStanza(texts[options.stanza - 2], count, options.stanza).warnings;
190
- }
191
- return texts.flatMap((text, i) => alignStanza(text, count, i + 2).warnings);
192
- }
193
- /** Pads stanza text with `~` empty slots up to the script's slot count
194
- * (unchanged when it already has enough syllables). */
195
- function padStanza(script, text) {
196
- const missing = slotCount(script) - parseStanza(text).length;
197
- return missing > 0 ? `${text.trimEnd()}${" ~".repeat(missing)}` : text;
198
- }
199
- /** A note group with its plain heads, virgas and longas swapped for small
200
- * heads (connectors, markers and signs stay). */
201
- function smallHeads(notes) {
202
- return Array.from(notes, (ch) => {
203
- const small = toSmallHead(ch);
204
- if (small !== void 0) return small;
205
- const variant = baseOf(ch);
206
- if (variant && (variant.role === "virga" || variant.role === "longa")) return toSmallHead(variant.base) ?? ch;
207
- return ch;
208
- }).join("");
209
- }
210
- /** A stanza syllable written in the script notation. */
211
- function syllableSource({ text, source }) {
212
- return source ?? (text === "~" ? "\\~" : escape(text));
213
- }
214
- /** Rewrites a script's source to sing stanza `stanza`. */
215
- function stanzaSource(source, stanza, options) {
216
- const script = new GuidoScript(source);
217
- const texts = stanzaTexts(script, options);
218
- checkStanzaNumber(stanza, texts.length + 1);
219
- const rendered = options.rendered ?? [stanza];
220
- for (const k of rendered) checkStanzaNumber(k, texts.length + 1);
221
- const mode = options.emptySlots ?? "normal";
222
- if (stanza === 1 && mode === "normal") return source;
223
- const tokens = script.tokens;
224
- const slotTokens = tokens.filter((t) => isSlot(t));
225
- const allFills = [scriptFills(slotTokens), ...texts.map((text, i) => alignStanza(text, slotTokens.length, i + 2).fills)];
226
- const fills = allFills[stanza - 1];
227
- const cue = (slot) => mode === "partial" ? allFills.some((f) => sings(f[slot])) && !allFills.every((f) => sings(f[slot])) : mode === "small" && rendered.every((k) => !sings(allFills[k - 1][slot])) && allFills.some((f, j) => !rendered.includes(j + 1) && sings(f[slot]));
228
- let out = script.clef !== void 0 ? `(${script.clef})` : "";
229
- let first = true;
230
- let pendingSpace = false;
231
- let canHold = false;
232
- const emit = (piece, space) => {
233
- out += (space && !first ? " " : "") + piece;
234
- first = false;
235
- };
236
- let slot = 0;
237
- for (const tok of tokens) {
238
- if (tok.kind !== "syllable") {
239
- emit(statementSource(tok), pendingSpace);
240
- pendingSpace = false;
241
- continue;
242
- }
243
- if (!isSlot(tok)) {
244
- if (tok.held) {
245
- emit(`(${escape(tok.notes)})`, pendingSpace);
246
- pendingSpace = false;
247
- } else {
248
- emit(`${tok.source}(${escape(tok.notes)})`, pendingSpace || tok.spaceBefore);
249
- pendingSpace = tok.wordEnd;
250
- canHold = tok.notes !== "";
251
- }
252
- continue;
253
- }
254
- const fill = fills[slot];
255
- const notes = escape(cue(slot) ? smallHeads(tok.notes) : tok.notes);
256
- slot++;
257
- switch (fill.kind) {
258
- case "syllable":
259
- emit(`${syllableSource(fill)}(${notes})`, pendingSpace);
260
- pendingSpace = fill.wordEnd;
261
- break;
262
- case "hold":
263
- emit(`${canHold ? "" : "~"}(${notes})`, false);
264
- break;
265
- case "empty":
266
- emit(`~(${notes})`, false);
267
- break;
268
- case "missing":
269
- emit(`${STANZA_PLACEHOLDER}(${notes})`, true);
270
- pendingSpace = true;
271
- }
272
- canHold = true;
273
- }
274
- return out;
275
- }
276
- /** The `selectStanza` transform factory: rewrites the script to sing
277
- * stanza `stanza` (1-based; 1 is the script itself). Its syllables go on
278
- * the slots in order — missing ones become `STANZA_PLACEHOLDER`
279
- * syllables, extra ones are dropped (`stanzaWarnings` reports both) — and
280
- * the `(@stanza …)` statements are dropped. Everything that is not a
281
- * slot (statements, syllables without notes, marker-only groups) stays as
282
- * written. With `emptySlots: 'small'`, a slot the stanza leaves empty
283
- * while another stanza sings it gets small heads (`rendered` lists the
284
- * stanzas stacked with it: then a slot gets small heads when none of
285
- * them sings it while another stanza does). With `emptySlots:
286
- * 'partial'`, every slot some stanza sings and another does not gets
287
- * small heads, whatever is rendered. Stanza 1 with normal
288
- * empty slots returns the source unchanged. Throws a RangeError for a
289
- * stanza the script does not have. Register it first, so the other
290
- * transforms (the initial, the transpositions) see the stanza's text. */
291
- function selectStanza(stanza, options = {}) {
292
- return {
293
- name: "selectStanza",
294
- apply: (source) => stanzaSource(source, stanza, options)
295
- };
296
- }
297
- /** The script singing stanza `stanza` (see `selectStanza`); `transforms`
298
- * run after the stanza swap. A GuidoScript argument is taken by its
299
- * (already transformed) source. */
300
- function withStanza(script, stanza, options = {}) {
301
- const source = typeof script === "string" ? script : script.source;
302
- return new GuidoScript(source, { transforms: [selectStanza(stanza, options), ...options.transforms ?? []] });
303
- }
304
- /** The stanza numbers a stack names: every stanza for `'all'`, the
305
- * listed ones otherwise. Throws a RangeError for an empty list or a
306
- * stanza the script does not have. */
307
- function stackedStanzaNumbers(script, stack, options = {}) {
308
- const count = stanzaCount(script, options);
309
- if (stack === "all") return Array.from({ length: count }, (_, k) => k + 1);
310
- if (stack.length === 0) throw new RangeError("No stanza to stack: the list is empty");
311
- for (const k of stack) checkStanzaNumber(k, count);
312
- return [...stack];
313
- }
314
- /** The scripts of stacked stanzas (issue #84): one per stanza of the
315
- * stack, in its order, each singing its stanza on the shared notes (see
316
- * `withStanza`; `transforms` run after the swap). Hand them to the layout
317
- * together (`layoutScore`, `GuidoRender`, the Word export) for one text
318
- * line per stanza under one staff. With `emptySlots: 'small'`, a slot
319
- * gets small heads when no stacked stanza sings it while a stanza left
320
- * out of the stack does, so every script carries the same notes. */
321
- function stackStanzas(script, stack, options = {}) {
322
- const rendered = stackedStanzaNumbers(script, stack, options);
323
- return rendered.map((k) => withStanza(script, k, {
324
- ...options,
325
- rendered
326
- }));
327
- }
328
- //#endregion
329
- //#region src/exactTranspose.ts
330
- /**
331
- * Exact transposition (issue #70): moves the sounding pitches of a
332
- * script and re-notates them under a target clef and key, so the result
333
- * reads like a chant notated at the new pitch. The staff-degree shift
334
- * (`transposeBy`) stays separate and ignores pitch meaning.
335
- *
336
- * A note's sounding pitch is its staff position + the clef in effect +
337
- * the key in effect + any sign written in its group. A sign affects its
338
- * whole group: every note of that pitch letter, in every octave. The
339
- * transposition is two steps:
340
- *
341
- * 1. Move every pitch by a spelled interval (letter steps + semitones,
342
- * so a major third up turns b♭ into d, not e♭♭).
343
- * 2. Re-notate under the target clef and key: each note's staff position
344
- * and glyph, plus the signs the target key doesn't cover. Added signs
345
- * go before the note group, after its leading markers (the #49 rule).
346
- *
347
- * Keys are written with the classical key-signature layout
348
- * (`KEY_SIGNATURES`). Results past the glyph range and missing glyph
349
- * variants are errors, never silent clamps.
350
- */
351
- /** A transposed note past the end of the glyph range. Thrown as its own
352
- * class so the octave search for a `final` can tell it apart. */
353
- var TranspositionRangeError = class extends Error {
354
- constructor(message) {
355
- super(message);
356
- this.name = "TranspositionRangeError";
357
- }
358
- };
359
- /** The key-signature glyphs per clef glyph (issue #70): flats in the
360
- * order b e a d g c f, sharps in the order f c g d a e b, each at the
361
- * highest octave of the shape that stays on the staff. A key of n signs
362
- * is the first n glyphs of its row. */
363
- var KEY_SIGNATURES = {
364
- M: {
365
- flats: "XBYVÍCS",
366
- sharps: "ôþùßÑòÒ"
367
- },
368
- "<": {
369
- flats: "XBYVÍCS",
370
- sharps: "ôþùßÑòÒ"
371
- },
372
- ">": {
373
- flats: "V$CNXBY",
374
- sharps: "ÑòÒôþùß"
375
- },
376
- "#": {
377
- flats: "NXBYVÍC",
378
- sharps: "þÐßÑÎÒÏ"
379
- },
380
- "&": {
381
- flats: "YVÍCSXA",
382
- sharps: "òÒôþÐßÑ"
383
- },
384
- "@": {
385
- flats: "CNXBYVÍ",
386
- sharps: "ÐßÑòÒôþ"
387
- },
388
- "{": {
389
- flats: "BYVÍCSX",
390
- sharps: "ÒÏþÐÌÑÎ"
391
- },
392
- "}": {
393
- flats: "ÍCSXAYa",
394
- sharps: "ßÑòÒÏþÐ"
395
- }
396
- };
397
- var FLAT_ORDER = "beadgcf";
398
- var SHARP_ORDER = "fcgdaeb";
399
- /** Pitch letters from c, so a diatonic step's letter is `step mod 7`. */
400
- var LETTERS = "cdefgab";
401
- var LETTER_SEMITONES = [
402
- 0,
403
- 2,
404
- 4,
405
- 5,
406
- 7,
407
- 9,
408
- 11
409
- ];
410
- var mod7 = (n) => (n % 7 + 7) % 7;
411
- function semitoneOf({ step, alter }) {
412
- return Math.floor(step / 7) * 12 + LETTER_SEMITONES[mod7(step)] + alter;
413
- }
414
- function letterName(step) {
415
- return LETTERS[mod7(step)];
416
- }
417
- /** A pitch moved by a spelled interval: the letter moves by the steps,
418
- * the alteration absorbs whatever the semitones leave over. */
419
- function movePitch(pitch, interval) {
420
- const step = pitch.step + interval.steps;
421
- const alter = semitoneOf(pitch) + interval.semitones - semitoneOf({
422
- step,
423
- alter: 0
424
- });
425
- if (Math.abs(alter) > 1) throw new Error(`Moving ${letterName(pitch.step)}${alterName(pitch.alter)} lands on a double accidental (${letterName(step)}, ${alter > 0 ? "+" : ""}${alter})`);
426
- return {
427
- step,
428
- alter
429
- };
430
- }
431
- function alterName(alter) {
432
- return alter < 0 ? "♭" : alter > 0 ? "♯" : "";
433
- }
434
- function roleOfAlter(alter) {
435
- return alter < 0 ? "modifyDown" : alter > 0 ? "modifyUp" : "modifyNatural";
436
- }
437
- function alterOfRole(role) {
438
- return role === "modifyDown" ? -1 : role === "modifyUp" ? 1 : 0;
439
- }
440
- /** The staff position of a clef's own line and the step of its pitch. */
441
- function clefAnchor(clef) {
442
- const entry = CLEF_GLYPHS[clef];
443
- const step = {
444
- c: 28,
445
- f: 24,
446
- g: 32
447
- }[entry.clef];
448
- return {
449
- position: STAFF.indexOf("2") + 2 * (entry.line - 1),
450
- step
451
- };
452
- }
453
- function stepAt(position, clef) {
454
- const anchor = clefAnchor(clef);
455
- return anchor.step + position - anchor.position;
456
- }
457
- function positionOf(step, clef) {
458
- const anchor = clefAnchor(clef);
459
- return anchor.position + step - anchor.step;
460
- }
461
- /** The staff position and variant role of a pitched glyph (`'base'` for
462
- * a base glyph), or undefined for a glyph without pitch. */
463
- function glyphOf(ch) {
464
- if (STAFF.includes(ch)) return {
465
- position: STAFF.indexOf(ch),
466
- role: "base"
467
- };
468
- const entry = baseOf(ch);
469
- return entry ? {
470
- position: STAFF.indexOf(entry.base),
471
- role: entry.role
472
- } : void 0;
473
- }
474
- /** Whether `ch` is in a pitch row. Read at call time: this module and
475
- * the transforms module import each other. */
476
- function isPitchChar(ch) {
477
- return PITCH_ROWS.some((row) => row.includes(ch));
478
- }
479
- /** The glyph of `role` at a staff position. Throws past the glyph range
480
- * and when the variant does not exist. */
481
- function glyphAt(position, role, what) {
482
- const base = STAFF[position];
483
- if (base === void 0) throw new TranspositionRangeError(`${what} runs past the glyph range`);
484
- const glyph = role === "base" ? base : variantOf(base, role);
485
- if (glyph === void 0) throw new Error(`${what}: the glyph "${base}" has no ${role} variant`);
486
- return glyph;
487
- }
488
- /** A key read from modifier glyphs under `clef`. Naturals carry no
489
- * alteration, so they drop out. */
490
- function readKey(glyphs, clef) {
491
- const key = /* @__PURE__ */ new Map();
492
- for (const ch of glyphs) {
493
- if (!isModifierGlyph(ch)) continue;
494
- const { base, role } = baseOf(ch);
495
- const letter = mod7(stepAt(STAFF.indexOf(base), clef));
496
- const alter = alterOfRole(role);
497
- if (alter === 0) key.delete(letter);
498
- else key.set(letter, alter);
499
- }
500
- return key;
501
- }
502
- /** A signed key count: −n is the first n flats, n the first n sharps. */
503
- function countedKey(count) {
504
- if (!Number.isInteger(count) || Math.abs(count) > 7) throw new Error(`A key has −7 to 7 signs, not ${count}`);
505
- const order = count < 0 ? FLAT_ORDER : SHARP_ORDER;
506
- const key = /* @__PURE__ */ new Map();
507
- for (const name of order.slice(0, Math.abs(count))) key.set(LETTERS.indexOf(name), Math.sign(count));
508
- return key;
509
- }
510
- /** A key moved by an interval. The key is a scale, not a set of
511
- * pitches: every letter moves (d minor's natural e becomes g minor's
512
- * e♭ a fourth up), and the moved key is whatever the scale alters. */
513
- function moveKey(key, interval) {
514
- const moved = /* @__PURE__ */ new Map();
515
- for (let letter = 0; letter < 7; letter++) {
516
- const pitch = movePitch({
517
- step: letter,
518
- alter: key.get(letter) ?? 0
519
- }, interval);
520
- if (pitch.alter !== 0) moved.set(mod7(pitch.step), pitch.alter);
521
- }
522
- return moved;
523
- }
524
- function sameKey(a, b) {
525
- return a.size === b.size && [...a].every(([letter, alter]) => b.get(letter) === alter);
526
- }
527
- /** Whether two keys written as modifier glyphs under `clef` alter the
528
- * same pitch letters the same way (glyph order and octave aside). */
529
- function sameKeyGlyphs(a, b, clef) {
530
- return sameKey(readKey(a, clef), readKey(b, clef));
531
- }
532
- /** A key written with the key-signature layout of `clef`: flats first,
533
- * then sharps, each in the table's order. */
534
- function writeKey(key, clef) {
535
- const row = KEY_SIGNATURES[clef];
536
- const glyphs = (order, alter, signs) => [...order].map((name, i) => key.get(LETTERS.indexOf(name)) === alter ? signs[i] : "").join("");
537
- return glyphs(FLAT_ORDER, -1, row.flats) + glyphs(SHARP_ORDER, 1, row.sharps);
538
- }
539
- /** Parses an interval name: an optional sign, a quality (`P`, `M`, `m`,
540
- * `A`, `d`) and a number (`P1`, `-P5`, `M3`, `A4`, `P8`, `M9`). */
541
- function parseInterval(name) {
542
- const match = name.trim().match(/^([+-]?)([PMmAd])(\d+)$/);
543
- const number = match ? Number(match[3]) : 0;
544
- if (!match || number < 1) throw new Error(`Unknown interval "${name}"`);
545
- const [, sign, quality] = match;
546
- const steps = number - 1;
547
- const perfect = [
548
- 0,
549
- 3,
550
- 4
551
- ].includes(steps % 7);
552
- if (!(perfect ? "PAd" : "MmAd").includes(quality)) throw new Error(`Unknown interval "${name}"`);
553
- const base = Math.floor(steps / 7) * 12 + LETTER_SEMITONES[steps % 7];
554
- const adjust = {
555
- P: 0,
556
- M: 0,
557
- A: 1,
558
- m: -1,
559
- d: perfect ? -1 : -2
560
- }[quality];
561
- const direction = sign === "-" ? -1 : 1;
562
- return {
563
- steps: direction * steps,
564
- semitones: direction * (base + adjust)
565
- };
566
- }
567
- var GROUP = /((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g;
568
- function escapeNotes(notes) {
569
- return notes.replace(/\\/g, "\\\\").replace(/[()]/g, (ch) => `\\${ch}`);
570
- }
571
- /** Re-notates one note group. `src*` are the clef and key in effect in
572
- * the source, `tgt*` the ones in the result. Records the group's last
573
- * note pitch (the candidate final) through `onNote`. */
574
- function renotateGroup(notes, interval, srcClef, srcKey, tgtClef, tgtKey, onNote) {
575
- const { leading, core, trailing } = splitNoteMarkers(notes);
576
- const chars = [...core];
577
- const groupSigns = /* @__PURE__ */ new Map();
578
- for (const ch of chars) {
579
- if (!isModifierGlyph(ch)) continue;
580
- const glyph = glyphOf(ch);
581
- const letter = mod7(stepAt(glyph.position, srcClef));
582
- const alter = alterOfRole(glyph.role);
583
- if (groupSigns.has(letter) && groupSigns.get(letter) !== alter) throw new Error(`The note group "${notes}" carries two different signs for ${LETTERS[letter]}`);
584
- groupSigns.set(letter, alter);
585
- }
586
- const coveredLetters = /* @__PURE__ */ new Set();
587
- const out = [];
588
- const added = [];
589
- const pending = [];
590
- for (const ch of chars) {
591
- const glyph = glyphOf(ch);
592
- if (!glyph) {
593
- if (isPitchChar(ch)) throw new Error(`The glyph "${ch}" has no glyph-family entry, so it cannot be transposed exactly`);
594
- out.push(ch);
595
- continue;
596
- }
597
- const step = stepAt(glyph.position, srcClef);
598
- const letter = mod7(step);
599
- const keyAlter = srcKey.get(letter) ?? 0;
600
- if (isModifierGlyph(ch)) {
601
- const alter = alterOfRole(glyph.role);
602
- const moved = movePitch({
603
- step,
604
- alter
605
- }, interval);
606
- const tgtAlter = tgtKey.get(mod7(moved.step)) ?? 0;
607
- if (moved.alter !== tgtAlter || alter === keyAlter) {
608
- const position = positionOf(moved.step, tgtClef);
609
- out.push(glyphAt(position, roleOfAlter(moved.alter), `The sign "${ch}"`));
610
- coveredLetters.add(mod7(moved.step));
611
- }
612
- continue;
613
- }
614
- const pitch = {
615
- step,
616
- alter: groupSigns.get(letter) ?? keyAlter
617
- };
618
- const moved = movePitch(pitch, interval);
619
- out.push(glyphAt(positionOf(moved.step, tgtClef), glyph.role, `The note "${ch}"`));
620
- if (glyph.role === "smallPoint") continue;
621
- onNote(pitch);
622
- pending.push(moved);
623
- }
624
- for (const moved of pending) {
625
- const letter = mod7(moved.step);
626
- if (coveredLetters.has(letter) || moved.alter === (tgtKey.get(letter) ?? 0)) continue;
627
- const sign = glyphAt(positionOf(moved.step, tgtClef), roleOfAlter(moved.alter), `The sign for ${letterName(moved.step)}${alterName(moved.alter)}`);
628
- if (!added.includes(sign)) added.push(sign);
629
- }
630
- return leading + added.join("") + out.join("") + trailing;
631
- }
632
- /** One re-notation pass over the source. Returns the result and the
633
- * source's final (the pitch of its last note). */
634
- function renotate(source, plan) {
635
- new GuidoScript(source).tokens;
636
- const head = source.match(/^\s*\(([^)]*)\)/);
637
- const opening = head && (!isStatementGroup(head[1]) || isC4ClefGroup(head[1])) ? head : null;
638
- const openingClef = opening && isClefGlyph(opening[1].trimStart()[0] ?? "") ? opening[1].trimStart()[0] : void 0;
639
- if (opening && openingClef === void 0 && opening[1].trim() !== "") throw new Error(`The opening group "(${opening[1]})" does not start with a clef glyph`);
640
- if (plan.clef !== void 0 && !isClefGlyph(plan.clef)) throw new Error(`"${plan.clef}" is not a clef glyph`);
641
- let srcClef = openingClef ?? "M";
642
- let srcKey = readKey(opening && openingClef ? opening[1].trimStart().slice(1) : "", srcClef);
643
- let tgtClef = plan.clef ?? srcClef;
644
- let tgtKey = plan.key === void 0 ? moveKey(srcKey, plan.interval) : typeof plan.key === "number" ? countedKey(plan.key) : readKey(plan.key, tgtClef);
645
- const openingKey = writeKey(tgtKey, tgtClef);
646
- const openingGroup = opening || plan.clef !== void 0 || openingKey !== "" ? `(${tgtClef}${openingKey})` : "";
647
- let final;
648
- const offset = opening ? opening[0].length : 0;
649
- return {
650
- result: openingGroup + source.slice(offset).replace(GROUP, (_, text, rawNotes) => {
651
- if (isStatementGroup(rawNotes)) {
652
- const [, keyword, args = ""] = rawNotes.trim().match(/^@(\S*)(?: (.*))?$/) ?? [];
653
- if (keyword === "clef") {
654
- srcClef = args[0];
655
- srcKey = readKey(args.slice(1), srcClef);
656
- const moved = moveKey(srcKey, plan.interval);
657
- if (plan.clef === void 0) {
658
- tgtClef = srcClef;
659
- tgtKey = moved;
660
- return `${text}(@clef ${tgtClef}${writeKey(tgtKey, tgtClef)})`;
661
- }
662
- if (sameKey(moved, tgtKey)) return text;
663
- tgtKey = moved;
664
- const key = writeKey(tgtKey, tgtClef);
665
- return `${text}(@key${key === "" ? "" : ` ${key}`})`;
666
- }
667
- if (keyword === "key") {
668
- srcKey = readKey(args, srcClef);
669
- tgtKey = moveKey(srcKey, plan.interval);
670
- const key = writeKey(tgtKey, tgtClef);
671
- return `${text}(@key${key === "" ? "" : ` ${key}`})`;
672
- }
673
- return `${text}(${rawNotes})`;
674
- }
675
- return `${text}(${escapeNotes(renotateGroup(unescape(rawNotes), plan.interval, srcClef, srcKey, tgtClef, tgtKey, (pitch) => {
676
- final = pitch;
677
- }))})`;
678
- }),
679
- final
680
- };
681
- }
682
- /** The finals' pitch letter and alteration (`g`, `bb`, `b♭`, `f#`). */
683
- function parseFinal(final) {
684
- const match = final.trim().match(/^([a-gA-G])(b|♭|#|♯)?$/);
685
- if (!match) throw new Error(`Unknown final "${final}"`);
686
- const alter = match[2] === void 0 ? 0 : "b♭".includes(match[2]) ? -1 : 1;
687
- return {
688
- letter: LETTERS.indexOf(match[1].toLowerCase()),
689
- alter
690
- };
691
- }
692
- /**
693
- * Transposes a script exactly: moves its sounding pitches and
694
- * re-notates them under the target clef and key (see
695
- * `TranspositionTarget`). Without a key, the key moves with the
696
- * interval; without a clef, the clefs stay as written (mid-script
697
- * `(@clef …)` included); `(@key …)` statements always move with the
698
- * interval. A target clef re-notates the whole script in that clef and
699
- * removes mid-script `(@clef …)` statements (one that changed the key
700
- * leaves a `(@key …)` behind). With a `final`, the octave whose result
701
- * fits the glyph range wins — the smaller move when several fit.
702
- * Throws past the glyph range and on a missing glyph variant.
703
- */
704
- function transposeScript(source, target) {
705
- if (target.interval !== void 0 && target.final !== void 0) throw new Error("A transposition target takes an interval or a final, not both");
706
- const plan = (interval) => ({
707
- interval,
708
- clef: target.clef,
709
- key: target.key
710
- });
711
- if (target.final === void 0) return renotate(source, plan(typeof target.interval === "string" ? parseInterval(target.interval) : target.interval ?? {
712
- steps: 0,
713
- semitones: 0
714
- })).result;
715
- const sourceFinal = renotate(source, { interval: {
716
- steps: 0,
717
- semitones: 0
718
- } }).final;
719
- if (sourceFinal === void 0) throw new Error("The script has no notes, so it has no final");
720
- const wanted = parseFinal(target.final);
721
- const up = mod7(wanted.letter - sourceFinal.step);
722
- const candidates = [
723
- -14,
724
- -7,
725
- 0,
726
- 7,
727
- 14
728
- ].map((octave) => {
729
- const semitones = semitoneOf({
730
- step: sourceFinal.step + up + octave,
731
- alter: wanted.alter
732
- }) - semitoneOf(sourceFinal);
733
- return {
734
- steps: up + octave,
735
- semitones
736
- };
737
- }).sort((a, b) => Math.abs(a.semitones) - Math.abs(b.semitones) || b.semitones - a.semitones);
738
- let rangeError;
739
- for (const interval of candidates) try {
740
- return renotate(source, plan(interval)).result;
741
- } catch (error) {
742
- if (!(error instanceof TranspositionRangeError)) throw error;
743
- rangeError ??= error;
744
- }
745
- throw rangeError;
746
- }
747
- /** The exact transposition as a script transform (see `transposeScript`). */
748
- function transposeExact(target) {
749
- return {
750
- name: "transposeExact",
751
- apply: (source) => transposeScript(source, target)
752
- };
753
- }
754
- //#endregion
755
- //#region src/guidoScriptTransforms.ts
756
- /**
757
- * Source-level transformations for GuidoScript: named rewrites applied
758
- * to a script's raw source before parsing (see the `transforms` option
759
- * on the GuidoScript constructor). Each one receives the source and
760
- * returns the rewritten source — or the source unchanged when the
761
- * feature does not apply. They compose in registration order, and the
762
- * parsed script never sees which ones ran. New script-level features
763
- * are added here, and only here, as factories returning a ScriptTransform
764
- * (see `transposeBy`).
765
- */
766
- /** The pitch rows of the chant font: every character carrying pitch
767
- * information, grouped into rows of neighbouring pitches from low to
768
- * high. A transpose shift moves a character this many positions along
769
- * its row; characters outside every row carry no pitch and stay put.
770
- * Rows are searched in order, so a character found in several rows
771
- * transposes within the first one. */
772
- var PITCH_ROWS = [
773
- "ðñ0123456789öüó",
774
- "^]qwertzuiopõú",
775
- "ÝÞQWERTZUIOPÕÚ",
776
- "×sdfghjkléáû",
777
- "ØÙDFGHJKLÉÁÛ",
778
- "÷øaASÍYXCVBN$m",
779
- "ÈÊËÌÎÏÐÑÒþßòôùý",
780
- "“”•–—˜™š›œº»",
781
- "®−§ÿ\"+!%/=()ÖÜÓ",
782
- "Ÿ¡¢£[¥¦©ª«¬",
783
- "~¯‚ƒ„…†‡ˆ‰Š‹Œ‘’",
784
- "àâãäåæçèêëìîï",
785
- "½°±²³´μ·¾¸¹"
786
- ];
787
- /** Maps one character to its pitch-shifted neighbour, or undefined when
788
- * it is not a pitch character (and so stays unchanged). */
789
- function shiftPitch(ch, shift, overflow) {
790
- for (const row of PITCH_ROWS) {
791
- const index = row.indexOf(ch);
792
- if (index === -1) continue;
793
- const target = index + shift;
794
- if (target < 0 || target >= row.length) {
795
- if (overflow === "null") return "\0";
796
- if (overflow === "error") throw new Error(`Transposing "${ch}" by ${shift} runs past the glyph range`);
797
- return row[Math.max(0, Math.min(row.length - 1, target))];
798
- }
799
- return row[target];
800
- }
801
- }
802
- /** Transposes the pitch characters of one note group's content as
803
- * written in the source (escapes included) — the staff-degree shift
804
- * `transposeBy` applies to every group. Escape pairs stand for their
805
- * underlying character (an escaped paren is a pitch glyph of the
806
- * `®−§ÿ…` row), and a shifted result that is a control character of the
807
- * group syntax is written escaped. A statement group's content (`@…`) is returned
808
- * unchanged: its keyword letters are pitch glyphs, but no notes. */
809
- function transposeNotes(notes, shift, options = {}) {
810
- if (shift === 0 || isStatementGroup(notes)) return notes;
811
- const overflow = options.overflow ?? "clamp";
812
- let out = "";
813
- for (let i = 0; i < notes.length; i++) {
814
- const ch = notes[i];
815
- const escaped = ch === "\\" && notes[i + 1] !== void 0;
816
- const shifted = shiftPitch(escaped ? notes[i + 1] : ch, shift, overflow);
817
- if (shifted === void 0) {
818
- out += escaped ? ch + notes[i + 1] : ch;
819
- if (escaped) i++;
820
- continue;
821
- }
822
- out += "\\()".includes(shifted) ? `\\${shifted}` : shifted;
823
- if (escaped) i++;
824
- }
825
- return out;
826
- }
827
- /** The `transposeBy` transform factory: shifts every pitch character of
828
- * every notes group `shift` positions along its pitch row. The clef
829
- * group and the syllable text are left alone — clef handling is a
830
- * separate, future tool. */
831
- function transposeBy(shift, options = {}) {
832
- const overflow = options.overflow ?? "clamp";
833
- const apply = (source) => {
834
- if (shift === 0) return source;
835
- const clefMatch = source.match(/^\s*\(([^)]*)\)/);
836
- const offset = clefMatch ? clefMatch[0].length : 0;
837
- return source.slice(0, offset) + source.slice(offset).replace(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g, (_, text, notes) => `${text}(${transposeNotes(notes, shift, { overflow })})`);
838
- };
839
- return {
840
- name: "transpose",
841
- apply
842
- };
843
- }
844
- //#endregion
845
- //#region src/chantMarkup.ts
846
- /**
847
- * The marked-up text of a chant script, for other applications: the parsed
848
- * runs of the score, with what they mean and what they are for, and no
849
- * style set in them. `chantRuns` gives the structured form; `chantHtml`
850
- * serializes it as HTML spans a consumer styles with its own CSS
851
- * (`chantTextStyle` gives a mark's look in a style set).
852
- */
853
- var ALL_ROLES = [
854
- "sung",
855
- "label",
856
- "sign",
857
- "aid"
858
- ];
859
- var chantRunOf = (run, role) => {
860
- const kind = kindOf(run.marks);
861
- return {
862
- text: run.text,
863
- ...kind ? { kind } : {},
864
- ...run.marks.includes("initial") ? { initial: true } : {},
865
- marks: run.marks,
866
- role
867
- };
868
- };
869
- var sameMarks = (a, b) => a.length === b.length && a.every((mark, i) => mark === b[i]);
870
- function chantRuns(script, options = {}) {
871
- const roles = options.roles ?? ALL_ROLES;
872
- const words = new GuidoScript(script).words.map((word) => ({ syllables: word.syllables.filter((syl) => roles.includes(syl.role) && syl.runs.length > 0).map((syl) => ({ runs: syl.runs.map((run) => chantRunOf(run, syl.role)) })) })).filter((word) => word.syllables.length > 0);
873
- if (options.merge !== "word") return words;
874
- return words.flatMap((word) => {
875
- const merged = [];
876
- for (const run of word.syllables.flatMap((syl) => syl.runs)) {
877
- const last = merged[merged.length - 1];
878
- if (last && last.role === run.role && sameMarks(last.marks, run.marks)) last.text += run.text;
879
- else merged.push({
880
- ...run,
881
- wordEnd: false
882
- });
883
- }
884
- merged[merged.length - 1].wordEnd = true;
885
- return merged;
886
- });
887
- }
888
- /** The marked-up text as an HTML string: one span per marked run, classed
889
- * with its kind, `initial` and any marks of its own, bare text otherwise.
890
- * Syllables of a word concatenate and words join with single spaces —
891
- * hyphenation is the consumer's job, and `chantRuns` has the syllable
892
- * boundaries. Text is HTML-escaped. */
893
- function chantHtml(script, options = {}) {
894
- const run = (r) => runHtml(r, options.classPrefix ?? "");
895
- return chantRuns(script, { roles: options.roles }).map((word) => word.syllables.map((syl) => syl.runs.map(run).join("")).join("")).join(" ");
896
- }
897
- /** The marks the notation names through `kind` and `initial`. */
898
- var NOTATION_MARKS = /* @__PURE__ */ new Set([
899
- "liturgy",
900
- "rubric",
901
- "star",
902
- "marker",
903
- "plus",
904
- "initial"
905
- ]);
906
- var runHtml = (run, prefix) => {
907
- const classes = [
908
- ...run.kind ? [run.kind] : [],
909
- ...run.initial ? ["initial"] : [],
910
- ...run.marks.filter((mark) => !NOTATION_MARKS.has(mark)).map((mark) => mark.replace(/[^\w-]/g, "-"))
911
- ].map((name) => prefix + name).join(" ");
912
- return classes ? `<span class="${classes}">${escapeHtml(run.text)}</span>` : escapeHtml(run.text);
913
- };
914
- var escapeHtml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
915
- /** The resolved look of comma-separated marks (`red,sc`), for a host styling
916
- * prose to match a score. */
917
- function chantTextStyle(marks, options = {}) {
918
- const styleName = options.style ?? "BNS";
919
- const styleSet = styleSetOf(styleName);
920
- if (!styleSet) throw new Error(`Unknown style set: "${styleName}"`);
921
- return resolveMarks(marks, styleSet, options.marks);
922
- }
923
- /** Everything `liturgy.ttf` maps. */
924
- var LITURGY_GLYPHS = /* @__PURE__ */ new Set([
925
- "+",
926
- ".",
927
- "/",
928
- "R",
929
- "V"
930
- ]);
931
- /** What is wrong with the script's text markup: malformed `{…}` spans,
932
- * unknown marks, and characters the Liturgy font does not have, each once
933
- * per syllable. */
934
- function markupWarnings(script, options = {}) {
935
- const parsed = typeof script === "string" ? new GuidoScript(script) : script;
936
- const styleSet = styleSetOf(options.style ?? "BNS");
937
- if (!styleSet) return parsed.spanProblems;
938
- const warnings = [...parsed.spanProblems];
939
- const unknown = /* @__PURE__ */ new Set();
940
- for (const tok of parsed.tokens) {
941
- if (tok.kind !== "syllable") continue;
942
- for (const mark of unknownMarks([...new Set(tok.runs.flatMap((run) => run.marks))], styleSet, options.marks)) {
943
- if (unknown.has(mark)) continue;
944
- unknown.add(mark);
945
- warnings.push({
946
- kind: "mark",
947
- mark,
948
- text: tok.source,
949
- message: `Unknown mark "${mark}" (in "${tok.source}")`
950
- });
951
- }
952
- const drawn = resolveTextRuns(tok.runs, styleSet, false, options.marks).filter((part) => part.style.fontFamily?.includes("Liturgy") && part.kind !== "marker").flatMap((part) => [...part.text]);
953
- for (const char of new Set(drawn)) {
954
- if (LITURGY_GLYPHS.has(char) || /\s/.test(char)) continue;
955
- warnings.push({
956
- kind: "glyph",
957
- char,
958
- text: tok.source,
959
- message: `The Liturgy font has no "${char}" (in "${tok.source}"); it has only + . / R V`
960
- });
961
- }
962
- }
963
- return warnings;
964
- }
965
- //#endregion
1
+ import { M as STAFF, N as baseOf, V as pitchLetterOf, _ as GuidoScript, c as inlineStylesFor, j as CLEF_GLYPHS } from "./guidoStyles-CvnACCsk.js";
2
+ import { S as stackedStanzaNumbers, T as stanzaWarnings, i as markupWarnings, o as transposeBy, v as selectStanza, x as stackStanzas } from "./chantMarkup-DX4K86Rv.js";
3
+ import { i as layoutScore } from "./chantLayout-BRQ6FYND.js";
966
4
  //#region src/staffGlyphs.ts
967
5
  /** Guido HU's units per em. */
968
6
  var GUIDO_UNITS_PER_EM = 1e3;
@@ -1075,6 +113,7 @@ var GLYPH_ADVANCES = {
1075
113
  "¡": 491,
1076
114
  "¢": 491,
1077
115
  "£": 491,
116
+ "¤": 491,
1078
117
  "¥": 491,
1079
118
  "¦": 491,
1080
119
  "§": 74,
@@ -1170,6 +209,8 @@ var GLYPH_ADVANCES = {
1170
209
  "Š": 143,
1171
210
  "š": 252,
1172
211
  "Ÿ": 491,
212
+ "Ž": 491,
213
+ "ž": 491,
1173
214
  "ƒ": 143,
1174
215
  "ˆ": 143,
1175
216
  "ˉ": 143,
@@ -1191,6 +232,7 @@ var GLYPH_ADVANCES = {
1191
232
  "‰": 143,
1192
233
  "‹": 143,
1193
234
  "›": 252,
235
+ "€": 491,
1194
236
  "™": 252,
1195
237
  "−": 74,
1196
238
  "∙": 15
@@ -3764,6 +2806,33 @@ var STAFF_SPANS = {
3764
2806
  571
3765
2807
  ]
3766
2808
  ],
2809
+ "¤": [
2810
+ [
2811
+ 0,
2812
+ 0,
2813
+ 571
2814
+ ],
2815
+ [
2816
+ 1,
2817
+ 0,
2818
+ 571
2819
+ ],
2820
+ [
2821
+ 2,
2822
+ 0,
2823
+ 571
2824
+ ],
2825
+ [
2826
+ 3,
2827
+ 0,
2828
+ 571
2829
+ ],
2830
+ [
2831
+ 4,
2832
+ 0,
2833
+ 571
2834
+ ]
2835
+ ],
3767
2836
  "¥": [
3768
2837
  [
3769
2838
  0,
@@ -6329,6 +5398,60 @@ var STAFF_SPANS = {
6329
5398
  571
6330
5399
  ]
6331
5400
  ],
5401
+ "Ž": [
5402
+ [
5403
+ 0,
5404
+ 0,
5405
+ 571
5406
+ ],
5407
+ [
5408
+ 1,
5409
+ 0,
5410
+ 571
5411
+ ],
5412
+ [
5413
+ 2,
5414
+ 0,
5415
+ 571
5416
+ ],
5417
+ [
5418
+ 3,
5419
+ 0,
5420
+ 571
5421
+ ],
5422
+ [
5423
+ 4,
5424
+ 0,
5425
+ 571
5426
+ ]
5427
+ ],
5428
+ "ž": [
5429
+ [
5430
+ 0,
5431
+ 0,
5432
+ 571
5433
+ ],
5434
+ [
5435
+ 1,
5436
+ 0,
5437
+ 571
5438
+ ],
5439
+ [
5440
+ 2,
5441
+ 0,
5442
+ 571
5443
+ ],
5444
+ [
5445
+ 3,
5446
+ 0,
5447
+ 571
5448
+ ],
5449
+ [
5450
+ 4,
5451
+ 0,
5452
+ 571
5453
+ ]
5454
+ ],
6332
5455
  "ƒ": [
6333
5456
  [
6334
5457
  0,
@@ -6896,6 +6019,33 @@ var STAFF_SPANS = {
6896
6019
  301
6897
6020
  ]
6898
6021
  ],
6022
+ "€": [
6023
+ [
6024
+ 0,
6025
+ 0,
6026
+ 571
6027
+ ],
6028
+ [
6029
+ 1,
6030
+ 0,
6031
+ 571
6032
+ ],
6033
+ [
6034
+ 2,
6035
+ 0,
6036
+ 571
6037
+ ],
6038
+ [
6039
+ 3,
6040
+ 0,
6041
+ 571
6042
+ ],
6043
+ [
6044
+ 4,
6045
+ 0,
6046
+ 571
6047
+ ]
6048
+ ],
6899
6049
  "™": [
6900
6050
  [
6901
6051
  0,
@@ -7035,14 +6185,20 @@ function chooseStaffLines(lines, fewest = STAFF_LINE_COUNT) {
7035
6185
  needLo = Math.min(needLo, Math.max(0, Math.min(top, lo)));
7036
6186
  needHi = Math.max(needHi, Math.max(0, Math.min(top, hi)));
7037
6187
  };
7038
- for (const line of lines) for (const ch of line.clefPrefix + line.notesParts.join("")) {
7039
- const clef = CLEF_GLYPHS[ch];
7040
- if (clef) {
7041
- need((clef.line - 1) * 2, (clef.line - 1) * 2);
7042
- continue;
6188
+ for (const line of lines) {
6189
+ for (const { clef } of line.clefs ?? []) {
6190
+ const at = CLEF_GLYPHS[clef];
6191
+ if (at) need((at.line - 1) * 2, (at.line - 1) * 2);
6192
+ }
6193
+ for (const ch of line.clefPrefix + line.notesParts.join("")) {
6194
+ const clef = CLEF_GLYPHS[ch];
6195
+ if (clef) {
6196
+ need((clef.line - 1) * 2, (clef.line - 1) * 2);
6197
+ continue;
6198
+ }
6199
+ for (const s of pitchSteps(ch)) if (s % 2 === 0) need(s, s);
6200
+ else need(s + 1, s - 1);
7043
6201
  }
7044
- for (const s of pitchSteps(ch)) if (s % 2 === 0) need(s, s);
7045
- else need(s + 1, s - 1);
7046
6202
  }
7047
6203
  const span = (count - 1) * 2;
7048
6204
  if (needHi === -Infinity) return {
@@ -7059,11 +6215,11 @@ function chooseStaffLines(lines, fewest = STAFF_LINE_COUNT) {
7059
6215
  hi: Math.max(needLo, needHi) / 2
7060
6216
  };
7061
6217
  }
7062
- /** The color a line takes under `clef` (a clef glyph), or undefined for
7063
- * the default (the notes' text color). */
7064
6218
  function staffLineColor(index, clef, options) {
7065
6219
  const pitch = pitchLetterOf(STAFF[index * 2 + 4], clef);
7066
- return pitch && options.staffPitchColors?.[pitch] || options.staffLineColors?.[index] || options.staffColor || void 0;
6220
+ const clefLine = CLEF_GLYPHS[clef] ? CLEF_GLYPHS[clef].line - 1 : -1;
6221
+ const clefColor = options.staffClefLineColor === "none" ? void 0 : options.staffClefLineColor;
6222
+ return index === clefLine && clefColor || pitch && options.staffPitchColors?.[pitch] || options.staffLineColors?.[index] || options.staffColor || void 0;
7067
6223
  }
7068
6224
  /** A weight option: a positive finite number, else 1 (no change). */
7069
6225
  function weightOf(value) {
@@ -7084,9 +6240,11 @@ function colorKey(color) {
7084
6240
  * it (clef prefix and notes), plus the break marker `*` when it stands
7085
6241
  * `breakMarkerLeftPx` past the text. Each line index in `range` is one span
7086
6242
  * per run of glyphs with the same color and weight, which change at an
7087
- * inline clef.
6243
+ * inline clef. `clefs` (the layout line's) say where each clef takes
6244
+ * effect when the text has no clef glyphs (`clefMark: 'line'`); clef
6245
+ * glyphs in the text count too.
7088
6246
  */
7089
- function staffSpans(text, notesPx, range, options = {}, breakMarkerLeftPx) {
6247
+ function staffSpans(text, notesPx, range, options = {}, breakMarkerLeftPx, clefs = []) {
7090
6248
  const scale = notesPx / GUIDO_UNITS_PER_EM;
7091
6249
  const raw = [];
7092
6250
  let pen = 0;
@@ -7099,15 +6257,20 @@ function staffSpans(text, notesPx, range, options = {}, breakMarkerLeftPx) {
7099
6257
  left: at + x0 * scale,
7100
6258
  right: at + x1 * scale,
7101
6259
  color: staffLineColor(line, clef, options),
7102
- weight: staffLineWeight(line, clef, options)
6260
+ weight: staffLineWeight(line, clef, options),
6261
+ ...CLEF_GLYPHS[clef] && CLEF_GLYPHS[clef].line - 1 === line ? { clefLine: true } : {}
7103
6262
  });
7104
6263
  }
7105
6264
  };
6265
+ let index = 0;
7106
6266
  for (const ch of text) {
6267
+ for (const c of clefs) if (c.at === index) clef = c.clef;
7107
6268
  if (CLEF_GLYPHS[ch]) clef = ch;
7108
6269
  place(ch, pen);
7109
6270
  pen += (GLYPH_ADVANCES[ch] ?? 0) * scale;
6271
+ index++;
7110
6272
  }
6273
+ for (const c of clefs) if (c.at >= index) clef = c.clef;
7111
6274
  if (breakMarkerLeftPx !== void 0) place("*", pen + breakMarkerLeftPx);
7112
6275
  const out = [];
7113
6276
  for (let line = range.lo; line <= range.hi; line++) {
@@ -7115,7 +6278,7 @@ function staffSpans(text, notesPx, range, options = {}, breakMarkerLeftPx) {
7115
6278
  for (const s of spans) {
7116
6279
  const last = out[out.length - 1];
7117
6280
  if (last && last.line === line && s.left <= last.right + .5) {
7118
- if (colorKey(s.color) === colorKey(last.color) && s.weight === last.weight) {
6281
+ if (colorKey(s.color) === colorKey(last.color) && s.weight === last.weight && !s.clefLine === !last.clefLine) {
7119
6282
  last.right = Math.max(last.right, s.right);
7120
6283
  continue;
7121
6284
  }
@@ -7136,6 +6299,24 @@ function staffSpans(text, notesPx, range, options = {}, breakMarkerLeftPx) {
7136
6299
  }
7137
6300
  return out;
7138
6301
  }
6302
+ /** The inline style of a drawn staff's anchor: zero-size, on the baseline. */
6303
+ var STAFF_ANCHOR_CSS = "position:relative;display:inline-block;width:0;height:0;vertical-align:baseline;user-select:none;pointer-events:none";
6304
+ /**
6305
+ * Where a drawn line stretch sits against its anchor: left and width in
6306
+ * `unit` (the span's own unit: px from `staffSpans` with the notes size, em
6307
+ * with a notes size of 1), bottom and height in em of the notes font. A
6308
+ * weighted line grows from the font line's centre.
6309
+ */
6310
+ function staffLinePlacement(span, unit = "px") {
6311
+ const [b0, b1] = STAFF_BANDS[span.line];
6312
+ const thickness = (b1 - b0) * span.weight;
6313
+ return {
6314
+ left: `${span.left}${unit}`,
6315
+ width: `${span.right - span.left}${unit}`,
6316
+ bottom: `${((b0 + b1) / 2 - thickness / 2) / GUIDO_UNITS_PER_EM}em`,
6317
+ height: `${thickness / GUIDO_UNITS_PER_EM}em`
6318
+ };
6319
+ }
7139
6320
  /**
7140
6321
  * The drawn staff of one notes line: a zero-size anchor on the baseline at
7141
6322
  * the line's start, holding one absolutely placed span per stretch. Heights
@@ -7149,20 +6330,20 @@ function staffLayer(spans) {
7149
6330
  const anchor = document.createElement("span");
7150
6331
  anchor.className = "guidex-staff";
7151
6332
  anchor.setAttribute("aria-hidden", "true");
7152
- anchor.style.cssText = "position:relative;display:inline-block;width:0;height:0;vertical-align:baseline;user-select:none;pointer-events:none";
6333
+ anchor.style.cssText = STAFF_ANCHOR_CSS;
7153
6334
  for (const span of spans) {
7154
- const [b0, b1] = STAFF_BANDS[span.line];
7155
6335
  const el = document.createElement("span");
7156
6336
  el.className = "guidex-staff-line";
7157
6337
  el.dataset.line = String(span.line + 1);
7158
6338
  if (span.weight !== 1) el.dataset.weight = String(span.weight);
7159
- const thickness = (b1 - b0) * span.weight;
6339
+ if (span.clefLine) el.dataset.clefLine = "";
6340
+ const place = staffLinePlacement(span);
7160
6341
  el.style.position = "absolute";
7161
6342
  el.style.zIndex = "-1";
7162
- el.style.left = `${span.left}px`;
7163
- el.style.width = `${span.right - span.left}px`;
7164
- el.style.bottom = `${((b0 + b1) / 2 - thickness / 2) / GUIDO_UNITS_PER_EM}em`;
7165
- el.style.height = `${thickness / GUIDO_UNITS_PER_EM}em`;
6343
+ el.style.left = place.left;
6344
+ el.style.width = place.width;
6345
+ el.style.bottom = place.bottom;
6346
+ el.style.height = place.height;
7166
6347
  const color = span.color;
7167
6348
  if (color !== void 0) {
7168
6349
  const light = typeof color === "string" ? color : color.light;
@@ -7184,21 +6365,26 @@ function staffLayer(spans) {
7184
6365
  */
7185
6366
  function snapStaff(root) {
7186
6367
  const dpr = typeof devicePixelRatio === "number" && devicePixelRatio > 0 ? devicePixelRatio : 1;
6368
+ const measured = [];
7187
6369
  for (const anchor of root.querySelectorAll(".guidex-staff")) {
7188
6370
  if (!anchor.isConnected) continue;
7189
- const baseline = anchor.getBoundingClientRect().bottom;
7190
6371
  const fontPx = parseFloat(getComputedStyle(anchor).fontSize);
7191
6372
  if (!fontPx) continue;
7192
- for (const el of anchor.querySelectorAll(".guidex-staff-line")) {
7193
- const [b0, b1] = STAFF_BANDS[Number(el.dataset.line) - 1];
7194
- const weight = Number(el.dataset.weight ?? 1) || 1;
7195
- const thickness = Math.max(1, Math.round((b1 - b0) * weight / GUIDO_UNITS_PER_EM * fontPx * dpr)) / dpr;
7196
- const centre = baseline - (b0 + b1) / 2 / GUIDO_UNITS_PER_EM * fontPx;
7197
- const top = Math.round((centre - thickness / 2) * dpr) / dpr;
7198
- el.style.bottom = "auto";
7199
- el.style.top = `${top - baseline}px`;
7200
- el.style.height = `${thickness}px`;
7201
- }
6373
+ measured.push({
6374
+ anchor,
6375
+ baseline: anchor.getBoundingClientRect().bottom,
6376
+ fontPx
6377
+ });
6378
+ }
6379
+ for (const { anchor, baseline, fontPx } of measured) for (const el of anchor.querySelectorAll(".guidex-staff-line")) {
6380
+ const [b0, b1] = STAFF_BANDS[Number(el.dataset.line) - 1];
6381
+ const weight = Number(el.dataset.weight ?? 1) || 1;
6382
+ const thickness = Math.max(1, Math.round((b1 - b0) * weight / GUIDO_UNITS_PER_EM * fontPx * dpr)) / dpr;
6383
+ const centre = baseline - (b0 + b1) / 2 / GUIDO_UNITS_PER_EM * fontPx;
6384
+ const top = Math.round((centre - thickness / 2) * dpr) / dpr;
6385
+ el.style.bottom = "auto";
6386
+ el.style.top = `${top - baseline}px`;
6387
+ el.style.height = `${thickness}px`;
7202
6388
  }
7203
6389
  }
7204
6390
  /** Whether `value` is a CSS color the browser accepts (always true where
@@ -7225,6 +6411,10 @@ function parseStaffColor(text, label = "staff color") {
7225
6411
  dark: parts[1]
7226
6412
  } : parts[0];
7227
6413
  }
6414
+ /** The clef line's color as text: a staff color, or `none` (any case). */
6415
+ function parseClefLineColor(text, label = "clef line color") {
6416
+ return text?.trim().toLowerCase() === "none" ? "none" : parseStaffColor(text, label);
6417
+ }
7228
6418
  /** Colors by position as text: up to five colors (`light|dark` each),
7229
6419
  * bottom line first, separated by `;` (an empty entry keeps the default). */
7230
6420
  function parseStaffLineColors(text) {
@@ -7292,21 +6482,34 @@ var GuidoRender = class GuidoRender {
7292
6482
  * unknown or one of its fonts cannot be loaded.
7293
6483
  */
7294
6484
  async render(container, options = {}) {
7295
- const { debug = false } = options;
7296
- const layout = await layoutScore(this.script, options);
7297
- const drawn = options.staff === "drawn";
7298
- const { lines, styleSet, styleName, textPx, notesPx, bold, starWidth } = layout;
6485
+ const { debug = false, sourceMap = false } = options;
6486
+ const drawn = options.staff !== "font";
6487
+ const layout = await layoutScore(this.script, {
6488
+ ...options,
6489
+ clefMark: drawn ? options.clefMark : "glyph"
6490
+ });
6491
+ const { lines, styleSet, styleName, textPx, notesPx, bold, starWidth, leftPaddingPx } = layout;
7299
6492
  let staff;
7300
6493
  if (drawn) {
7301
6494
  await GuidoRender.verifyStaffless(notesPx);
6495
+ const clefLine = layout.clefMark === "line" ? styleSet.clefLine : void 0;
6496
+ const overflow = options.staffOverflow;
7302
6497
  staff = {
7303
6498
  range: chooseStaffLines(lines, options.staffLines),
7304
- options,
6499
+ options: {
6500
+ ...options,
6501
+ staffClefLineColor: options.staffClefLineColor ?? clefLine?.color,
6502
+ staffClefLineWeight: (options.staffClefLineWeight ?? 1) * (clefLine?.weight ?? 1),
6503
+ staffOverflow: leftPaddingPx > 0 ? {
6504
+ ...overflow,
6505
+ start: Math.min(overflow?.start ?? 0, -leftPaddingPx)
6506
+ } : overflow
6507
+ },
7305
6508
  family: `${STAFFLESS_FONT_FAMILY}, ${styleSet.notesFontStack}`
7306
6509
  };
7307
6510
  }
7308
6511
  container.style.fontSize = `${textPx}px`;
7309
- container.style.fontFamily = styleSet.textFontStack;
6512
+ container.style.fontFamily = layout.textFontStack;
7310
6513
  container.dataset.style = styleName;
7311
6514
  if (staff) {
7312
6515
  container.dataset.staff = "drawn";
@@ -7315,7 +6518,11 @@ var GuidoRender = class GuidoRender {
7315
6518
  delete container.dataset.staff;
7316
6519
  delete container.dataset.staffLines;
7317
6520
  }
7318
- container.replaceChildren(...lines.flatMap((l) => [GuidoRender.notesLine(l, notesPx, starWidth, debug, staff), ...l.texts.map((text) => GuidoRender.textLine(text, textPx, bold, debug))]));
6521
+ const shift = (el) => {
6522
+ if (leftPaddingPx > 0) el.style.paddingLeft = `${leftPaddingPx}px`;
6523
+ return el;
6524
+ };
6525
+ container.replaceChildren(...lines.flatMap((l) => [shift(GuidoRender.notesLine(l, notesPx, starWidth, debug, staff, sourceMap)), ...l.texts.map((text) => GuidoRender.textLine(text, textPx, bold, debug, sourceMap))]));
7319
6526
  if (staff && options.staffSnap !== false && container.isConnected) snapStaff(container);
7320
6527
  }
7321
6528
  /** The drawn staff needs the staffless font: a fallback font would draw
@@ -7332,16 +6539,17 @@ var GuidoRender = class GuidoRender {
7332
6539
  * text's baseline) shifted right so its right edge lands on the
7333
6540
  * padding-extended max-width position. position: relative keeps the
7334
6541
  * shift out of the flow measurements. */
7335
- static notesLine(line, notesPx, starWidth, debug, staff) {
6542
+ static notesLine(line, notesPx, starWidth, debug, staff, sourceMap = false) {
7336
6543
  const notesEl = document.createElement("div");
7337
6544
  notesEl.className = "guido";
7338
6545
  notesEl.style.fontSize = `${notesPx}px`;
7339
6546
  const text = line.clefPrefix + line.notesParts.join("");
7340
6547
  notesEl.textContent = text;
6548
+ if (sourceMap) notesEl.dataset.groups = line.groups.map((g) => `${g.syllable}:${g.from}:${g.to}`).join(" ");
7341
6549
  if (staff) {
7342
6550
  notesEl.style.fontFamily = staff.family;
7343
6551
  notesEl.style.isolation = "isolate";
7344
- notesEl.prepend(staffLayer(staffSpans(text, notesPx, staff.range, staff.options, line.breakMarkerLeftPx)));
6552
+ notesEl.prepend(staffLayer(staffSpans(text, notesPx, staff.range, staff.options, line.breakMarkerLeftPx, line.clefs)));
7345
6553
  }
7346
6554
  if (line.breakMarkerLeftPx !== void 0) {
7347
6555
  const star = document.createElement("span");
@@ -7358,7 +6566,7 @@ var GuidoRender = class GuidoRender {
7358
6566
  * every horizontal gap (lead-in, word gaps, dash connector pads), each
7359
6567
  * syllable is one span of nested runs, and word spaces are their own
7360
6568
  * spans. */
7361
- static textLine(line, textPx, bold, debug) {
6569
+ static textLine(line, textPx, bold, debug, sourceMap = false) {
7362
6570
  const textEl = document.createElement("p");
7363
6571
  if (bold) textEl.style.fontWeight = "700";
7364
6572
  for (const seg of line.segments) switch (seg.kind) {
@@ -7382,6 +6590,13 @@ var GuidoRender = class GuidoRender {
7382
6590
  }
7383
6591
  case "syl": {
7384
6592
  const span = GuidoRender.sylSpan(seg.parts, textPx);
6593
+ if (sourceMap) {
6594
+ span.dataset.syl = String(seg.syllable);
6595
+ if (!seg.noNotes) {
6596
+ span.dataset.notesStart = seg.contentStart.toFixed(1);
6597
+ span.dataset.notesWidth = seg.contentWidth.toFixed(1);
6598
+ }
6599
+ }
7385
6600
  if (debug) {
7386
6601
  if (seg.noNotes) span.title = `no notes, text w ${seg.textWidth.toFixed(1)}, ${seg.trailing ? "end of score" : "before the next syllable with notes"}`;
7387
6602
  else {
@@ -7401,6 +6616,20 @@ var GuidoRender = class GuidoRender {
7401
6616
  textEl.appendChild(span);
7402
6617
  break;
7403
6618
  }
6619
+ case "mark": {
6620
+ const box = document.createElement("span");
6621
+ box.className = "mark";
6622
+ box.style.display = "inline-block";
6623
+ box.style.width = "0";
6624
+ const span = GuidoRender.sylSpan(seg.parts, textPx);
6625
+ span.style.position = "relative";
6626
+ span.style.left = `${seg.textStart - seg.flowPx}px`;
6627
+ if (sourceMap) span.dataset.syl = String(seg.syllable);
6628
+ if (debug) span.title = `star under the bar, text w ${seg.textWidth.toFixed(1)}, start ${seg.textStart.toFixed(1)}`;
6629
+ box.appendChild(span);
6630
+ textEl.appendChild(box);
6631
+ break;
6632
+ }
7404
6633
  case "word-space": {
7405
6634
  const ws = document.createElement("span");
7406
6635
  ws.className = "word-space";
@@ -7461,7 +6690,7 @@ var GuidoRender = class GuidoRender {
7461
6690
  //#region src/embed/core.ts
7462
6691
  var version = {
7463
6692
  name: "guidex",
7464
- version: "0.5.0",
6693
+ version: "0.6.0",
7465
6694
  description: "Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime",
7466
6695
  type: "module",
7467
6696
  workspaces: ["examples/*"],
@@ -7488,6 +6717,10 @@ var version = {
7488
6717
  "./word": {
7489
6718
  "types": "./dist/lib/word/index.d.ts",
7490
6719
  "default": "./dist/lib/word/index.js"
6720
+ },
6721
+ "./aretino": {
6722
+ "types": "./dist/lib/aretino/index.d.ts",
6723
+ "default": "./dist/lib/aretino/index.js"
7491
6724
  }
7492
6725
  },
7493
6726
  files: [
@@ -7495,8 +6728,14 @@ var version = {
7495
6728
  "dist/lib",
7496
6729
  "CHANGELOG.md"
7497
6730
  ],
7498
- peerDependencies: { "react": ">=18" },
7499
- peerDependenciesMeta: { "react": { "optional": true } },
6731
+ peerDependencies: {
6732
+ "@aretino-chant/core": ">=0.29.0",
6733
+ "react": ">=18"
6734
+ },
6735
+ peerDependenciesMeta: {
6736
+ "@aretino-chant/core": { "optional": true },
6737
+ "react": { "optional": true }
6738
+ },
7500
6739
  publishConfig: { "access": "public" },
7501
6740
  scripts: {
7502
6741
  "dev": "vite --host",
@@ -7522,6 +6761,7 @@ var version = {
7522
6761
  bugs: { "url": "https://github.com/BrownieMaar/guidex/issues" },
7523
6762
  homepage: "https://github.com/BrownieMaar/guidex#readme",
7524
6763
  devDependencies: {
6764
+ "@aretino-chant/core": "0.29.0",
7525
6765
  "@eslint/js": "^10.0.1",
7526
6766
  "@testing-library/dom": "^10.4.2",
7527
6767
  "@testing-library/react": "^16.3.3",
@@ -7550,15 +6790,19 @@ var DEFAULTS = {
7550
6790
  junctionDashes: 3,
7551
6791
  staffFill: "all-but-last",
7552
6792
  staffFillSnapPx: 0,
6793
+ paddingPx: void 0,
6794
+ clefMark: "glyph",
6795
+ textFont: void 0,
7553
6796
  twoSyllableRecitationsToPlain: true,
7554
6797
  plainRunsToRecitation: false,
6798
+ cutEmptySlots: true,
7555
6799
  transpose: 0,
7556
6800
  stanza: 1,
7557
6801
  stack: void 0,
7558
6802
  emptySlots: "normal",
7559
6803
  stanzas: void 0,
7560
6804
  debug: false,
7561
- staff: "font",
6805
+ staff: "drawn",
7562
6806
  staffLines: 5,
7563
6807
  staffColor: void 0,
7564
6808
  staffLineColors: void 0,
@@ -7566,6 +6810,7 @@ var DEFAULTS = {
7566
6810
  staffWeight: void 0,
7567
6811
  staffLineWeights: void 0,
7568
6812
  staffClefLineWeight: void 0,
6813
+ staffClefLineColor: void 0,
7569
6814
  staffOverflow: void 0,
7570
6815
  staffSnap: true
7571
6816
  };
@@ -7608,6 +6853,11 @@ function emptySlotsValue(value) {
7608
6853
  if (value === "normal" || value === "small" || value === "partial") return value;
7609
6854
  console.warn(`[guidex] ignoring invalid data-empty-slots "${value}"`);
7610
6855
  }
6856
+ function clefMarkValue(value) {
6857
+ if (value === void 0) return void 0;
6858
+ if (value === "glyph" || value === "line") return value;
6859
+ console.warn(`[guidex] ignoring invalid data-clef-mark "${value}"`);
6860
+ }
7611
6861
  function staffFillValue(value) {
7612
6862
  if (value === void 0) return void 0;
7613
6863
  if (value === "all-but-last" || value === "none" || value === "all" || value === "longest") return value;
@@ -7641,8 +6891,12 @@ function readOptions(el) {
7641
6891
  junctionDashes: number(ds.junctionDashes) ?? local.junctionDashes ?? globalOptions.junctionDashes ?? DEFAULTS.junctionDashes,
7642
6892
  staffFill: staffFillValue(ds.staffFill) ?? local.staffFill ?? globalOptions.staffFill ?? DEFAULTS.staffFill,
7643
6893
  staffFillSnapPx: number(ds.staffFillSnap) ?? local.staffFillSnapPx ?? globalOptions.staffFillSnapPx ?? DEFAULTS.staffFillSnapPx,
6894
+ paddingPx: number(ds.padding) ?? local.paddingPx ?? globalOptions.paddingPx ?? DEFAULTS.paddingPx,
6895
+ clefMark: clefMarkValue(ds.clefMark) ?? local.clefMark ?? globalOptions.clefMark ?? DEFAULTS.clefMark,
6896
+ textFont: ds.textFont?.trim() || local.textFont || globalOptions.textFont || DEFAULTS.textFont,
7644
6897
  twoSyllableRecitationsToPlain: flag(ds.twoSyllableRecitationsToPlain) ?? local.twoSyllableRecitationsToPlain ?? globalOptions.twoSyllableRecitationsToPlain ?? DEFAULTS.twoSyllableRecitationsToPlain,
7645
6898
  plainRunsToRecitation: flag(ds.plainRunsToRecitation) ?? local.plainRunsToRecitation ?? globalOptions.plainRunsToRecitation ?? DEFAULTS.plainRunsToRecitation,
6899
+ cutEmptySlots: flag(ds.cutEmptySlots) ?? local.cutEmptySlots ?? globalOptions.cutEmptySlots ?? DEFAULTS.cutEmptySlots,
7646
6900
  transpose: number(ds.transpose) ?? local.transpose ?? globalOptions.transpose ?? DEFAULTS.transpose,
7647
6901
  stanza: number(ds.stanza) ?? local.stanza ?? globalOptions.stanza ?? DEFAULTS.stanza,
7648
6902
  stack: stackValue(ds.stack) ?? local.stack ?? globalOptions.stack ?? DEFAULTS.stack,
@@ -7657,6 +6911,7 @@ function readOptions(el) {
7657
6911
  staffWeight: parseStaffWeight(ds.staffWeight, "data-staff-weight") ?? local.staffWeight ?? globalOptions.staffWeight,
7658
6912
  staffLineWeights: parseStaffLineWeights(ds.staffLineWeights) ?? local.staffLineWeights ?? globalOptions.staffLineWeights,
7659
6913
  staffClefLineWeight: parseStaffWeight(ds.staffClefLineWeight, "data-staff-clef-line-weight") ?? local.staffClefLineWeight ?? globalOptions.staffClefLineWeight,
6914
+ staffClefLineColor: parseClefLineColor(ds.staffClefLineColor, "data-staff-clef-line-color") ?? local.staffClefLineColor ?? globalOptions.staffClefLineColor,
7660
6915
  staffOverflow: ds.staffOverflowStart !== void 0 || ds.staffOverflowEnd !== void 0 ? {
7661
6916
  start: number(ds.staffOverflowStart),
7662
6917
  end: number(ds.staffOverflowEnd)
@@ -7672,19 +6927,16 @@ function contentWidthPx(el) {
7672
6927
  wrapper?.removeAttribute("data-fixed-width");
7673
6928
  return wrapper?.clientWidth || el.clientWidth || el.parentElement?.clientWidth || 0;
7674
6929
  }
7675
- /** The line-breaking budget in pixels for this render. Fixed values pass
7676
- * through; 'auto' fits the element's content box, shrunk by the style
7677
- * set's break-star padding: the renderer hangs the `guido-break` star
7678
- * `padding` px past the budget, and when the budget is the line-box
7679
- * width itself that star would overflow the line and wrap. A zero width
6930
+ /** The line width in pixels for this render. Fixed values pass through;
6931
+ * 'auto' is the element's content box. The layout takes the padding out
6932
+ * of it, so the `guido-break` star's right edge lands on the line box's
6933
+ * edge and never wraps. A zero width
7680
6934
  * (hidden element) renders unbroken; once it becomes visible the resize
7681
6935
  * listener re-renders it at the real width. */
7682
- function resolveWidthPx(el, maxWidth, style) {
6936
+ function resolveWidthPx(el, maxWidth) {
7683
6937
  if (typeof maxWidth === "number") return maxWidth;
7684
6938
  const width = contentWidthPx(el);
7685
- if (width <= 0) return Infinity;
7686
- const budget = width - (styleSetOf(style)?.padding ?? 0);
7687
- return budget > 0 ? budget : width;
6939
+ return width > 0 ? width : Infinity;
7688
6940
  }
7689
6941
  /** The element's script source: a fresh non-empty text node wins (so
7690
6942
  * hosts can update the source by setting textContent and calling
@@ -7763,8 +7015,12 @@ async function drawScore(el, run, source, options, widthPx) {
7763
7015
  junctionDashes: options.junctionDashes,
7764
7016
  staffFill: options.staffFill,
7765
7017
  staffFillSnapPx: options.staffFillSnapPx,
7018
+ paddingPx: options.paddingPx,
7019
+ clefMark: options.clefMark,
7020
+ textFont: options.textFont,
7766
7021
  twoSyllableRecitationsToPlain: options.twoSyllableRecitationsToPlain,
7767
7022
  plainRunsToRecitation: options.plainRunsToRecitation,
7023
+ cutEmptySlots: options.cutEmptySlots,
7768
7024
  debug: options.debug,
7769
7025
  maxWidthPx: widthPx,
7770
7026
  staff: options.staff,
@@ -7775,6 +7031,7 @@ async function drawScore(el, run, source, options, widthPx) {
7775
7031
  staffWeight: options.staffWeight,
7776
7032
  staffLineWeights: options.staffLineWeights,
7777
7033
  staffClefLineWeight: options.staffClefLineWeight,
7034
+ staffClefLineColor: options.staffClefLineColor,
7778
7035
  staffOverflow: options.staffOverflow,
7779
7036
  staffSnap: false
7780
7037
  });
@@ -7786,7 +7043,7 @@ async function drawScore(el, run, source, options, widthPx) {
7786
7043
  for (const key of ["staff", "staffLines"]) if (scratch.dataset[key] !== void 0) wrapper.dataset[key] = scratch.dataset[key];
7787
7044
  else delete wrapper.dataset[key];
7788
7045
  wrapper.toggleAttribute("data-fixed-width", typeof options.maxWidth === "number");
7789
- if (options.staff === "drawn" && options.staffSnap) snapStaff(wrapper);
7046
+ if (scratch.dataset.staff === "drawn" && options.staffSnap) snapStaff(wrapper);
7790
7047
  return { warnings };
7791
7048
  } catch (e) {
7792
7049
  if (runs.get(el) !== run) return { warnings: [] };
@@ -7803,7 +7060,7 @@ async function renderElement(el) {
7803
7060
  const source = extractSource(el);
7804
7061
  sources.set(el, source);
7805
7062
  scoreWrapper(el);
7806
- const widthPx = resolveWidthPx(el, options.maxWidth, options.style);
7063
+ const widthPx = resolveWidthPx(el, options.maxWidth);
7807
7064
  lastWidths.set(el, widthPx);
7808
7065
  await drawScore(el, run, source, options, widthPx);
7809
7066
  }
@@ -7811,8 +7068,7 @@ async function renderElement(el) {
7811
7068
  * Only a changed line-breaking budget (width) triggers a re-render. */
7812
7069
  var detachFns = /* @__PURE__ */ new WeakMap();
7813
7070
  function widthChanged(el) {
7814
- const options = readOptions(el);
7815
- const width = resolveWidthPx(el, options.maxWidth, options.style);
7071
+ const width = resolveWidthPx(el, readOptions(el).maxWidth);
7816
7072
  return Math.abs(width - (lastWidths.get(el) ?? NaN)) > 1;
7817
7073
  }
7818
7074
  function attachResizeListener(el) {
@@ -7874,7 +7130,7 @@ async function renderScore(el, source, options = {}) {
7874
7130
  sources.set(el, source);
7875
7131
  const resolved = readOptions(el);
7876
7132
  scoreWrapper(el);
7877
- const widthPx = resolveWidthPx(el, resolved.maxWidth, resolved.style);
7133
+ const widthPx = resolveWidthPx(el, resolved.maxWidth);
7878
7134
  lastWidths.set(el, widthPx);
7879
7135
  attachResizeListener(el);
7880
7136
  return drawScore(el, run, source, resolved, widthPx);
@@ -8388,4 +7644,4 @@ async function downloadScoreSvg(el, options = {}) {
8388
7644
  return filename;
8389
7645
  }
8390
7646
  //#endregion
8391
- export { TranspositionRangeError as A, slotCount as B, chantRuns as C, transposeBy as D, PITCH_ROWS as E, STANZA_PLACEHOLDER as F, stanzaTexts as G, stackStanzas as H, isSlot as I, stanzaWarnings as K, padStanza as L, sameKeyGlyphs as M, transposeExact as N, transposeNotes as O, transposeScript as P, parseStanza as R, chantHtml as S, markupWarnings as T, stackedStanzaNumbers as U, smallHeads as V, stanzaCount as W, parseStaffWeight as _, dispose as a, staffLineWeight as b, renderScore as c, chooseStaffLines as d, formatStaffColor as f, parseStaffPitchColors as g, parseStaffLineWeights as h, scoreSvg as i, parseInterval as j, KEY_SIGNATURES as k, version as l, parseStaffLineColors as m, downloadScoreSvg as n, init as o, parseStaffColor as p, withStanza as q, scorePngBlob as r, renderAll as s, downloadScorePng as t, STAFFLESS_FONT_FAMILY as u, snapStaff as v, chantTextStyle as w, staffSpans as x, staffLineColor as y, selectStanza as z };
7647
+ export { staffSpans as S, parseStaffPitchColors as _, dispose as a, staffLineColor as b, renderScore as c, chooseStaffLines as d, formatStaffColor as f, parseStaffLineWeights as g, parseStaffLineColors as h, scoreSvg as i, version as l, parseStaffColor as m, downloadScoreSvg as n, init as o, parseClefLineColor as p, scorePngBlob as r, renderAll as s, downloadScorePng as t, STAFFLESS_FONT_FAMILY as u, parseStaffWeight as v, staffLineWeight as x, snapStaff as y };