guidex 0.3.1 → 0.3.2

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 (33) hide show
  1. package/README.md +53 -3
  2. package/dist/lib/app/EditorContext.d.ts +6 -1
  3. package/dist/lib/app/ExactTransposeControls.d.ts +1 -0
  4. package/dist/lib/app/StanzaControls.d.ts +1 -0
  5. package/dist/lib/app/TransposeSettings.d.ts +1 -0
  6. package/dist/lib/app/editorState.d.ts +78 -6
  7. package/dist/lib/app/shareLink.d.ts +22 -0
  8. package/dist/lib/chantLayout-B0xiaMo9.js +2641 -0
  9. package/dist/lib/chantLayout.d.ts +41 -8
  10. package/dist/lib/composeScript.d.ts +71 -0
  11. package/dist/lib/editorStorage.d.ts +6 -0
  12. package/dist/lib/embed/core.d.ts +28 -2
  13. package/dist/lib/embed/index.js +1 -1
  14. package/dist/lib/embed/manual.d.ts +12 -3
  15. package/dist/lib/embed/manual.js +324 -276
  16. package/dist/lib/exactTranspose.d.ts +54 -0
  17. package/dist/lib/glyphFamilies.d.ts +22 -0
  18. package/dist/lib/guidoRender.d.ts +5 -3
  19. package/dist/lib/guidoScript.d.ts +92 -10
  20. package/dist/lib/guidoScriptTransforms.d.ts +19 -7
  21. package/dist/lib/noteGroups.d.ts +22 -0
  22. package/dist/lib/react/GuidexScore.d.ts +19 -1
  23. package/dist/lib/react/index.d.ts +2 -1
  24. package/dist/lib/react/index.js +23 -3
  25. package/dist/lib/{scoreImage-oVBasBX5.js → scoreImage-DSEupCru.js} +102 -51
  26. package/dist/lib/stanzas.d.ts +135 -0
  27. package/dist/lib/word/index.js +1 -1
  28. package/dist/lib/{wordChecker-C3nJrk_j.js → wordChecker-EQx8frRp.js} +97 -45
  29. package/dist/lib/wordClipboard.d.ts +3 -3
  30. package/dist/lib/wordExport.d.ts +9 -5
  31. package/dist-embed/guidex-embed.min.js +1 -1
  32. package/package.json +1 -1
  33. package/dist/lib/chantLayout-GAfg2iKS.js +0 -1042
@@ -1,6 +1,326 @@
1
- import { a as dispose, c as renderScore, i as scoreSvg, l as version, n as downloadScoreSvg, o as init, r as scorePngBlob, s as renderAll, t as downloadScorePng } from "../scoreImage-oVBasBX5.js";
2
- import { f as GuidoScript, m as unescape, o as DEFAULT_STYLE_SET, p as chantText, s as STYLE_SETS, u as resolveSyllableParts } from "../chantLayout-GAfg2iKS.js";
3
- import { a as DEFAULT_TAB_INTERVAL_PT, c as toWordHtml, i as DEFAULT_SPACER, l as toWordText, n as copyWordHtml, o as SpacerMeter, r as copyWordPlainText, s as layoutForWord, t as checkWordHtml, u as wordLayoutText } from "../wordChecker-C3nJrk_j.js";
1
+ import { a as dispose, c as renderScore, i as scoreSvg, l as version, n as downloadScoreSvg, o as init, r as scorePngBlob, s as renderAll, t as downloadScorePng } from "../scoreImage-DSEupCru.js";
2
+ import { $ as variantOf, A as stanzaWarnings, C as selectStanza, D as stackedStanzaNumbers, E as stackStanzas, F as chantText, G as modifyNatural, H as gClefPitchOf, I as escape, J as toConnectDown, K as modifyUp, L as scriptSyllables, M as SCORE_MARKERS, N as splitNoteMarkers, O as stanzaCount, P as GuidoScript, Q as toVirga, R as statementSource, S as parseStanza, T as smallHeads, U as isClefGlyph, V as baseOf, W as modifyDown, X as toSmallHead, Y as toLonga, Z as toSmallPoint, _ as transposeExact, a as DEFAULT_STYLE_SET, b as isSlot, d as transposeBy, f as transposeNotes, g as sameKeyGlyphs, h as parseInterval, j as withStanza, k as stanzaTexts, l as resolveSyllableParts, m as TranspositionRangeError, o as STYLE_SETS, p as KEY_SIGNATURES, q as toCephalicus, u as PITCH_ROWS, v as transposeScript, w as slotCount, x as padStanza, y as STANZA_PLACEHOLDER, z as unescape } from "../chantLayout-B0xiaMo9.js";
3
+ import { a as DEFAULT_TAB_INTERVAL_PT, c as toWordHtml, i as DEFAULT_SPACER, l as toWordText, n as copyWordHtml, o as SpacerMeter, r as copyWordPlainText, s as layoutForWord, t as checkWordHtml, u as wordLayoutText } from "../wordChecker-EQx8frRp.js";
4
+ //#region src/composeScript.ts
5
+ /**
6
+ * Combining scripts (issue #71): one GuidoScript built from parts of
7
+ * others — an antiphon intonation (the antiphon through a syllable, then
8
+ * a psalm-tone ending as a text-less run), a reprise (the antiphon with
9
+ * the BNS `**` after its intonation), a hymn with an Amen.
10
+ *
11
+ * Every part boundary is a word boundary: the parts are joined with a
12
+ * space. The result keeps the first part's clef; a later part written in
13
+ * another clef or key is reconciled the way the caller chooses (an
14
+ * inline `(@clef …)` / `(@key …)` statement, or a re-notation into the
15
+ * clef and key in effect), so the result is correct or an error, never
16
+ * a quietly wrong score. Stanzas (issue #69) join one by one across the
17
+ * parts and are written back as `(@stanza …)` statements at the end.
18
+ */
19
+ var DEFAULT_GLYPHS = {
20
+ bar: ",",
21
+ finalBar: "."
22
+ };
23
+ /** The opening clef group's content as a clef state; throws when it
24
+ * does not start with a clef glyph. */
25
+ function readClef(content) {
26
+ if (content === void 0 || content.trim() === "") return void 0;
27
+ const group = content.trim();
28
+ if (!isClefGlyph(group[0])) throw new Error(`The opening group "(${content})" does not start with a clef glyph`);
29
+ return {
30
+ clef: group[0],
31
+ key: group.slice(1)
32
+ };
33
+ }
34
+ function clefGroup(state) {
35
+ return state ? `(${state.clef}${state.key})` : "";
36
+ }
37
+ /** The clef in effect after `tokens`, starting from `state`. */
38
+ function stateAfter(tokens, state) {
39
+ for (const tok of tokens) if (tok.kind === "clef") state = {
40
+ clef: tok.clef,
41
+ key: tok.key
42
+ };
43
+ else if (tok.kind === "key") state = {
44
+ clef: state?.clef ?? "M",
45
+ key: tok.key
46
+ };
47
+ return state;
48
+ }
49
+ /** Tokens written back as script source (the `GuidoScript.toString`
50
+ * rules: an empty slot always writes its `~`). */
51
+ function writeTokens(tokens) {
52
+ return tokens.map((tok, i) => {
53
+ const prefix = i > 0 && tok.spaceBefore ? " " : "";
54
+ if (tok.kind !== "syllable") return prefix + statementSource(tok);
55
+ return `${prefix}${tok.empty ? "~" : tok.text === "~" ? "\\~" : escape(tok.text)}(${escape(tok.notes)})`;
56
+ }).join("");
57
+ }
58
+ /** A stanza item written back as stanza text (see `parseStanza`). */
59
+ function stanzaItemSource(item) {
60
+ if (item.kind === "hold") return "-";
61
+ if (item.kind === "empty") return "~";
62
+ const text = Array.from(item.text, (ch) => /\s/.test(ch) ? "~" : "\\-=­~()".includes(ch) ? `\\${ch}` : ch).join("");
63
+ return item.wordEnd ? text : `${text}-`;
64
+ }
65
+ /** Applies a staff-degree or exact transposition to a whole script. */
66
+ function transposed(source, transpose, overflow) {
67
+ if (transpose === void 0) return source;
68
+ if (typeof transpose === "number") {
69
+ if (!Number.isInteger(transpose)) throw new Error(`A staff-degree transposition is a whole number, not ${transpose}`);
70
+ return transposeBy(transpose, { overflow }).apply(source);
71
+ }
72
+ return transposeScript(source, transpose);
73
+ }
74
+ /** The token index just past syllable `token`'s held run. */
75
+ function afterHeldRun(tokens, token) {
76
+ let last = token;
77
+ for (let i = token + 1; i < tokens.length; i++) {
78
+ const tok = tokens[i];
79
+ if (tok.kind !== "syllable") continue;
80
+ if (!tok.held) break;
81
+ last = i;
82
+ }
83
+ return last + 1;
84
+ }
85
+ /** Strips the closing markers of the last note group (marker-only held
86
+ * groups after it go). */
87
+ function stripTrailing(tokens) {
88
+ for (let i = tokens.length - 1; i >= 0; i--) {
89
+ const tok = tokens[i];
90
+ if (tok.kind !== "syllable" || tok.notes === "") continue;
91
+ const parts = splitNoteMarkers(tok.notes);
92
+ if (parts.core === "") {
93
+ if (tok.held) tokens.splice(i, 1);
94
+ continue;
95
+ }
96
+ tokens[i] = {
97
+ ...tok,
98
+ notes: parts.leading + parts.core
99
+ };
100
+ return;
101
+ }
102
+ }
103
+ /** A script part as a chunk; `state` is the clef in effect where it
104
+ * joins (undefined for the first part). */
105
+ function scriptChunk(part, state, first, options) {
106
+ const script = new GuidoScript(part.script);
107
+ const tokens = script.tokens;
108
+ const syllables = scriptSyllables(script);
109
+ const from = part.from ?? 0;
110
+ const to = part.to ?? syllables.length;
111
+ for (const [name, value] of [["from", part.from], ["to", part.to]]) if (value !== void 0 && (!Number.isInteger(value) || value < 0 || value > syllables.length)) throw new RangeError(`"${name}" ${value} is outside the script's ${syllables.length} text-bearing syllables`);
112
+ if (from >= to) throw new RangeError(`The slice from ${from} to ${to} is empty`);
113
+ const start = part.from === void 0 ? 0 : syllables[from].token;
114
+ const end = part.to === void 0 ? tokens.length : afterHeldRun(tokens, syllables[to - 1].token);
115
+ const opening = stateAfter(tokens.slice(0, start), readClef(script.clef)) ?? state;
116
+ const slice = tokens.slice(start, end);
117
+ if (part.stripTrailingMarkers) stripTrailing(slice);
118
+ const slotIndices = tokens.flatMap((tok, i) => isSlot(tok) ? [i] : []);
119
+ const before = slotIndices.filter((i) => i < start).length;
120
+ const inside = slotIndices.filter((i) => i >= start && i < end).length;
121
+ const stanzas = script.stanzas.map((text) => {
122
+ const items = parseStanza(text);
123
+ return Array.from({ length: inside }, (_, i) => items[before + i] ?? {
124
+ kind: "syllable",
125
+ text: "_…_",
126
+ wordEnd: true
127
+ });
128
+ });
129
+ let source = transposed(clefGroup(opening) + writeTokens(slice), part.transpose, options.overflow);
130
+ let own = readClef(new GuidoScript(source).clef);
131
+ let lead;
132
+ if (!first && own) {
133
+ const current = state ?? {
134
+ clef: "M",
135
+ key: ""
136
+ };
137
+ if (own.clef !== current.clef || !sameKeyGlyphs(own.key, current.key, current.clef)) {
138
+ if (options.clefs === "renotate") {
139
+ source = transposeScript(source, {
140
+ clef: current.clef,
141
+ key: current.key
142
+ });
143
+ own = readClef(new GuidoScript(source).clef);
144
+ } else lead = own.clef !== current.clef ? {
145
+ kind: "clef",
146
+ clef: own.clef,
147
+ key: own.key,
148
+ spaceBefore: false
149
+ } : {
150
+ kind: "key",
151
+ key: own.key,
152
+ spaceBefore: false
153
+ };
154
+ }
155
+ }
156
+ const body = new GuidoScript(source).tokens;
157
+ const slots = body.filter(isSlot).length;
158
+ if (slots !== inside) throw new Error(`Internal error: the slice has ${slots} slots, its stanzas ${inside}`);
159
+ return {
160
+ chunk: {
161
+ tokens: lead ? [lead, ...body] : body,
162
+ stanzas,
163
+ slots
164
+ },
165
+ opening: own,
166
+ end: stateAfter(body, own ?? state)
167
+ };
168
+ }
169
+ /** A notes part as a chunk of `~(…)` empty slots. */
170
+ function notesChunk(part, state, options) {
171
+ if (part.notes.length === 0) throw new Error("A notes part needs at least one note group");
172
+ const separator = part.separator ?? "--";
173
+ const groups = /^\s+$/.test(separator) ? part.notes : [part.notes.join(separator)];
174
+ let source = groups.map((notes) => `~(${notes})`).join(" ");
175
+ const { transpose } = part;
176
+ if (typeof transpose === "number") {
177
+ if (!Number.isInteger(transpose)) throw new Error(`A staff-degree transposition is a whole number, not ${transpose}`);
178
+ source = groups.map((notes) => `~(${transposeNotes(notes, transpose, { overflow: options.overflow })})`).join(" ");
179
+ } else if (transpose !== void 0) {
180
+ if (transpose.clef !== void 0 || transpose.key !== void 0) throw new Error("A notes part is written in the clef in effect: its transposition takes no clef or key");
181
+ const current = state ?? {
182
+ clef: "M",
183
+ key: ""
184
+ };
185
+ const moved = transposeScript(`${clefGroup(current)}${source}`, {
186
+ ...transpose,
187
+ clef: current.clef,
188
+ key: current.key
189
+ });
190
+ source = moved.slice(moved.indexOf(")") + 1);
191
+ }
192
+ const tokens = new GuidoScript(`(M)${source}`).tokens;
193
+ return {
194
+ tokens,
195
+ stanzas: [],
196
+ slots: tokens.filter(isSlot).length
197
+ };
198
+ }
199
+ /** Writes `glyph` as the leading marker of a note group. */
200
+ function leadWith(notes, glyph) {
201
+ return splitNoteMarkers(notes).leading === "" ? `${glyph}--${notes}` : glyph + notes;
202
+ }
203
+ /** Writes `glyph` as the closing marker of a note group. */
204
+ function closeWith(notes, glyph) {
205
+ return splitNoteMarkers(notes).trailing === "" ? `${notes}-${glyph}` : notes + glyph;
206
+ }
207
+ /**
208
+ * Builds one script from parts of others (see `ScriptPart`): script
209
+ * slices, text-less note runs and signs, joined in order with a space
210
+ * (every part boundary is a word boundary). The result opens with the
211
+ * first part's clef; later clef or key differences are reconciled as
212
+ * `options.clefs` says. Stanza k of the result is stanza k of every
213
+ * part in turn: a part without one (every notes and marker part, and a
214
+ * script with fewer stanzas) gets `~` empty slots there; the stanzas
215
+ * are written as `(@stanza …)` statements at the end. Throws on a bad
216
+ * slice, a clef that cannot be reconciled, a transposition past the
217
+ * glyph range, or a bar with no note group to attach to.
218
+ */
219
+ function composeScript(parts, options = {}) {
220
+ const opts = {
221
+ clefs: options.clefs ?? "inline",
222
+ overflow: options.overflow ?? "error"
223
+ };
224
+ if (opts.clefs !== "inline" && opts.clefs !== "renotate") throw new Error(`Unknown clef handling "${String(opts.clefs)}"`);
225
+ const out = [];
226
+ const chunks = [];
227
+ let state;
228
+ let opening;
229
+ let started = false;
230
+ let pendingBar;
231
+ const append = (chunk) => {
232
+ chunk.tokens.forEach((tok, i) => {
233
+ out.push(i === 0 ? {
234
+ ...tok,
235
+ spaceBefore: out.length > 0
236
+ } : tok);
237
+ });
238
+ chunks.push(chunk);
239
+ };
240
+ for (const [p, part] of parts.entries()) {
241
+ if ("marker" in part) {
242
+ if (part.marker === "intonation") {
243
+ if (pendingBar !== void 0) throw new Error("A bar must stand next to a note group");
244
+ append({
245
+ tokens: [{
246
+ kind: "syllable",
247
+ text: "**",
248
+ notes: "",
249
+ wordEnd: true,
250
+ spaceBefore: false
251
+ }],
252
+ stanzas: [],
253
+ slots: 0
254
+ });
255
+ continue;
256
+ }
257
+ if (part.marker !== "bar" && part.marker !== "finalBar") throw new Error(`Unknown marker "${String(part.marker)}"`);
258
+ const glyph = part.glyph ?? DEFAULT_GLYPHS[part.marker];
259
+ const next = parts[p + 1];
260
+ if (next !== void 0 && "notes" in next) {
261
+ if (pendingBar !== void 0) throw new Error("Two bars in a row");
262
+ pendingBar = glyph;
263
+ continue;
264
+ }
265
+ let i = out.length - 1;
266
+ while (i >= 0 && out[i].kind !== "syllable") i--;
267
+ const last = out[i];
268
+ if (last?.kind !== "syllable" || splitNoteMarkers(last.notes).core === "") throw new Error(`The ${part.marker === "bar" ? "bar" : "final bar"} has no note group to close`);
269
+ out[i] = {
270
+ ...last,
271
+ notes: closeWith(last.notes, glyph)
272
+ };
273
+ continue;
274
+ }
275
+ if ("notes" in part) {
276
+ const chunk = notesChunk(part, state, opts);
277
+ if (pendingBar !== void 0) {
278
+ const head = chunk.tokens[0];
279
+ chunk.tokens[0] = {
280
+ ...head,
281
+ notes: leadWith(head.notes, pendingBar)
282
+ };
283
+ pendingBar = void 0;
284
+ }
285
+ append(chunk);
286
+ started = true;
287
+ continue;
288
+ }
289
+ if (!("script" in part)) throw new Error("A part is a script slice, a notes run or a marker");
290
+ const result = scriptChunk(part, state, !started, opts);
291
+ if (!started) opening = result.opening;
292
+ started = true;
293
+ state = result.end;
294
+ append(result.chunk);
295
+ }
296
+ const count = Math.max(1, ...chunks.map((c) => c.stanzas.length + 1));
297
+ const stanzas = [];
298
+ for (let k = 2; k <= count; k++) {
299
+ const items = chunks.flatMap((chunk) => {
300
+ if (chunk.slots === 0) return [];
301
+ const items = [...chunk.stanzas[k - 2] ?? Array.from({ length: chunk.slots }, () => ({ kind: "empty" }))];
302
+ if (items[0].kind === "hold") items[0] = { kind: "empty" };
303
+ for (let i = items.length - 1; i >= 0; i--) {
304
+ const item = items[i];
305
+ if (item.kind !== "syllable") continue;
306
+ items[i] = {
307
+ ...item,
308
+ wordEnd: true
309
+ };
310
+ break;
311
+ }
312
+ return items;
313
+ });
314
+ const text = items.map((item, i) => {
315
+ const prev = items[i - 1];
316
+ const joined = prev?.kind === "syllable" && !prev.wordEnd && item.kind === "syllable";
317
+ return (i === 0 || joined ? "" : " ") + stanzaItemSource(item);
318
+ }).join("");
319
+ stanzas.push(`(@stanza${text === "" ? "" : ` ${text}`})`);
320
+ }
321
+ return clefGroup(opening) + writeTokens(out) + stanzas.join("");
322
+ }
323
+ //#endregion
4
324
  //#region src/chantMarkup.ts
5
325
  /**
6
326
  * The marked-up sung text of a chant script, for other applications: the
@@ -40,276 +360,4 @@ var runHtml = (run) => {
40
360
  };
41
361
  var escapeHtml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
42
362
  //#endregion
43
- //#region src/glyphFamilies.ts
44
- /** Base pitch glyph → its variants. Keys are the note glyphs of the
45
- * first column of `PITCH_ROWS`' notation table. */
46
- var FAMILIES = {
47
- ð: {
48
- smallHead: "~",
49
- modifyUp: "È",
50
- cephalicus: "®"
51
- },
52
- ñ: {
53
- virga: "^",
54
- smallHead: "¯",
55
- modifyUp: "Ê",
56
- modifyDown: "÷",
57
- cephalicus: "−",
58
- connectOneDown: "Ý"
59
- },
60
- "0": {
61
- virga: "]",
62
- smallHead: "‚",
63
- modifyUp: "Ë",
64
- modifyDown: "ø",
65
- modifyNatural: "“",
66
- cephalicus: "§",
67
- connectOneDown: "Þ"
68
- },
69
- "1": {
70
- virga: "q",
71
- longa: "Ÿ",
72
- smallHead: "ƒ",
73
- modifyUp: "Ì",
74
- modifyDown: "a",
75
- modifyNatural: "”",
76
- cephalicus: "ÿ",
77
- connectOneDown: "Q",
78
- connectTwoDown: "×",
79
- connectThreeDown: "Ø",
80
- smallPoint: "í"
81
- },
82
- "2": {
83
- virga: "w",
84
- longa: "¡",
85
- smallHead: "„",
86
- modifyUp: "Î",
87
- modifyDown: "A",
88
- modifyNatural: "•",
89
- cephalicus: "\"",
90
- connectOneDown: "W",
91
- connectTwoDown: "s",
92
- connectThreeDown: "Ù",
93
- connectFourDown: "½"
94
- },
95
- "3": {
96
- virga: "e",
97
- longa: "¢",
98
- smallHead: "…",
99
- modifyUp: "Ï",
100
- modifyDown: "S",
101
- modifyNatural: "–",
102
- cephalicus: "+",
103
- connectOneDown: "E",
104
- connectTwoDown: "d",
105
- connectThreeDown: "D",
106
- connectFourDown: "°",
107
- smallPoint: "y"
108
- },
109
- "4": {
110
- virga: "r",
111
- longa: "£",
112
- smallHead: "†",
113
- modifyUp: "Ð",
114
- modifyDown: "Í",
115
- modifyNatural: "—",
116
- cephalicus: "!",
117
- connectOneDown: "R",
118
- connectTwoDown: "f",
119
- connectThreeDown: "F",
120
- connectFourDown: "±"
121
- },
122
- "5": {
123
- virga: "t",
124
- longa: "[",
125
- smallHead: "‡",
126
- modifyUp: "Ñ",
127
- modifyDown: "Y",
128
- modifyNatural: "˜",
129
- cephalicus: "%",
130
- connectOneDown: "T",
131
- connectTwoDown: "g",
132
- connectThreeDown: "G",
133
- connectFourDown: "²",
134
- smallPoint: "x"
135
- },
136
- "6": {
137
- virga: "z",
138
- longa: "¥",
139
- smallHead: "ˆ",
140
- modifyUp: "Ò",
141
- modifyDown: "X",
142
- modifyNatural: "™",
143
- cephalicus: "/",
144
- connectOneDown: "Z",
145
- connectTwoDown: "h",
146
- connectThreeDown: "H",
147
- connectFourDown: "³"
148
- },
149
- "7": {
150
- virga: "u",
151
- longa: "¦",
152
- smallHead: "‰",
153
- modifyUp: "þ",
154
- modifyDown: "C",
155
- modifyNatural: "š",
156
- cephalicus: "=",
157
- connectOneDown: "U",
158
- connectTwoDown: "j",
159
- connectThreeDown: "J",
160
- connectFourDown: "´",
161
- smallPoint: "c"
162
- },
163
- "8": {
164
- virga: "i",
165
- longa: "©",
166
- smallHead: "Š",
167
- modifyUp: "ß",
168
- modifyDown: "V",
169
- modifyNatural: "›",
170
- cephalicus: "(",
171
- connectOneDown: "I",
172
- connectTwoDown: "k",
173
- connectThreeDown: "K",
174
- connectFourDown: "μ"
175
- },
176
- "9": {
177
- virga: "o",
178
- longa: "ª",
179
- smallHead: "‹",
180
- modifyUp: "ò",
181
- modifyDown: "B",
182
- modifyNatural: "œ",
183
- cephalicus: ")",
184
- connectOneDown: "O",
185
- connectTwoDown: "l",
186
- connectThreeDown: "L",
187
- connectFourDown: "·",
188
- smallPoint: "v"
189
- },
190
- ö: {
191
- virga: "p",
192
- longa: "«",
193
- smallHead: "Œ",
194
- modifyUp: "ô",
195
- modifyDown: "N",
196
- modifyNatural: "º",
197
- cephalicus: "Ö",
198
- connectOneDown: "P",
199
- connectTwoDown: "é",
200
- connectThreeDown: "É",
201
- connectFourDown: "¾"
202
- },
203
- ü: {
204
- virga: "õ",
205
- longa: "¬",
206
- smallHead: "‘",
207
- modifyUp: "ù",
208
- modifyDown: "$",
209
- modifyNatural: "»",
210
- cephalicus: "Ü",
211
- connectOneDown: "Õ",
212
- connectTwoDown: "á",
213
- connectThreeDown: "Á",
214
- connectFourDown: "¸",
215
- smallPoint: "b"
216
- },
217
- ó: {
218
- virga: "ú",
219
- smallHead: "’",
220
- modifyUp: "ý",
221
- modifyDown: "m",
222
- cephalicus: "Ó",
223
- connectOneDown: "Ú",
224
- connectTwoDown: "û",
225
- connectThreeDown: "Û",
226
- connectFourDown: "¹"
227
- }
228
- };
229
- /** Base pitch glyph → its pitch name in the standard g-clef (the
230
- * "pitch in standard g-clef" column of the notation table). The last
231
- * row of that table has no base glyph, so it has no entry here. */
232
- var G_CLEF_PITCHES = {
233
- ð: "a",
234
- ñ: "b",
235
- "0": "c'",
236
- "1": "d'",
237
- "2": "e'",
238
- "3": "f'",
239
- "4": "g'",
240
- "5": "a'",
241
- "6": "b'",
242
- "7": "c''",
243
- "8": "d''",
244
- "9": "e''",
245
- ö: "f''",
246
- ü: "g''",
247
- ó: "a''"
248
- };
249
- /** The standard g-clef pitch name of a base glyph, or of the base of a
250
- * variant glyph; undefined when the glyph has no pitch. */
251
- function gClefPitchOf(ch) {
252
- return G_CLEF_PITCHES[ch] ?? G_CLEF_PITCHES[baseOf(ch)?.base ?? ""];
253
- }
254
- /** Reverse lookup: variant glyph → its base glyph and role. Built once;
255
- * the table has no glyph in two places, so each variant maps to one base. */
256
- var BASES = /* @__PURE__ */ new Map();
257
- for (const [base, family] of Object.entries(FAMILIES)) for (const role of Object.keys(family)) BASES.set(family[role], {
258
- base,
259
- role
260
- });
261
- /** The variant of `ch` in `role`, or undefined when `ch` has none. */
262
- function variantOf(ch, role) {
263
- return FAMILIES[ch]?.[role];
264
- }
265
- /** The virga (the stemmed form) of a pitch glyph. */
266
- function toVirga(ch) {
267
- return variantOf(ch, "virga");
268
- }
269
- /** The longa (the double-length form) of a pitch glyph. */
270
- function toLonga(ch) {
271
- return variantOf(ch, "longa");
272
- }
273
- /** The small head of a pitch glyph. */
274
- function toSmallHead(ch) {
275
- return variantOf(ch, "smallHead");
276
- }
277
- /** The cephalicus of a pitch glyph. */
278
- function toCephalicus(ch) {
279
- return variantOf(ch, "cephalicus");
280
- }
281
- /** The connecting form that joins a pitch to the note `steps` rows below
282
- * it (1 to 4). */
283
- function toConnectDown(ch, steps) {
284
- const role = [
285
- "connectOneDown",
286
- "connectTwoDown",
287
- "connectThreeDown",
288
- "connectFourDown"
289
- ][steps - 1];
290
- return variantOf(ch, role);
291
- }
292
- /** The small point (the dot that lengthens a note by half) of a pitch glyph. */
293
- function toSmallPoint(ch) {
294
- return variantOf(ch, "smallPoint");
295
- }
296
- /** The sharp (raised) form of a pitch glyph. */
297
- function modifyUp(ch) {
298
- return variantOf(ch, "modifyUp");
299
- }
300
- /** The flat (lowered) form of a pitch glyph. */
301
- function modifyDown(ch) {
302
- return variantOf(ch, "modifyDown");
303
- }
304
- /** The natural sign for a pitch glyph. */
305
- function modifyNatural(ch) {
306
- return variantOf(ch, "modifyNatural");
307
- }
308
- /** Reverse lookup: the base glyph and role of a variant glyph, or
309
- * undefined when `ch` is not a variant. */
310
- function baseOf(ch) {
311
- const entry = BASES.get(ch);
312
- return entry ? { ...entry } : void 0;
313
- }
314
- //#endregion
315
- export { DEFAULT_SPACER, DEFAULT_STYLE_SET, DEFAULT_TAB_INTERVAL_PT, GuidoScript, STYLE_SETS, SpacerMeter, baseOf, chantHtml, chantRuns, chantText, checkWordHtml, copyWordHtml, copyWordPlainText, dispose, downloadScorePng, downloadScoreSvg, gClefPitchOf, init, layoutForWord, modifyDown, modifyNatural, modifyUp, renderAll, renderScore, resolveSyllableParts, scorePngBlob, scoreSvg, toCephalicus, toConnectDown, toLonga, toSmallHead, toSmallPoint, toVirga, toWordHtml, toWordText, unescape, variantOf, version, wordLayoutText };
363
+ export { DEFAULT_SPACER, DEFAULT_STYLE_SET, DEFAULT_TAB_INTERVAL_PT, GuidoScript, KEY_SIGNATURES, PITCH_ROWS, SCORE_MARKERS, STANZA_PLACEHOLDER, STYLE_SETS, SpacerMeter, TranspositionRangeError, baseOf, chantHtml, chantRuns, chantText, checkWordHtml, composeScript, copyWordHtml, copyWordPlainText, dispose, downloadScorePng, downloadScoreSvg, gClefPitchOf, init, layoutForWord, modifyDown, modifyNatural, modifyUp, padStanza, parseInterval, parseStanza, renderAll, renderScore, resolveSyllableParts, scorePngBlob, scoreSvg, scriptSyllables, selectStanza, slotCount, smallHeads, splitNoteMarkers, stackStanzas, stackedStanzaNumbers, stanzaCount, stanzaTexts, stanzaWarnings, toCephalicus, toConnectDown, toLonga, toSmallHead, toSmallPoint, toVirga, toWordHtml, toWordText, transposeBy, transposeExact, transposeNotes, transposeScript, unescape, variantOf, version, withStanza, wordLayoutText };
@@ -0,0 +1,54 @@
1
+ import { ScriptTransform } from './guidoScriptTransforms';
2
+ /** A spelled interval: letter steps (a third is 2) and semitones (a
3
+ * major third is 4). Negative values move down. */
4
+ export interface SpelledInterval {
5
+ steps: number;
6
+ semitones: number;
7
+ }
8
+ /** The target of an exact transposition. `interval` (a spelled interval
9
+ * or a name like `'P4'`, `'-P5'`, `'m3'`) or `final` (the pitch letter
10
+ * the script's last note should land on, e.g. `'g'`, `'bb'`, `'f#'`)
11
+ * gives the move; neither means unison. `clef` (a clef glyph)
12
+ * re-notates the whole script in that clef; `key` replaces the opening
13
+ * key — a signed count (−2 = two flats, 3 = three sharps) or modifier
14
+ * glyphs read under the target clef. */
15
+ export interface TranspositionTarget {
16
+ interval?: SpelledInterval | string;
17
+ final?: string;
18
+ clef?: string;
19
+ key?: number | string;
20
+ }
21
+ /** A transposed note past the end of the glyph range. Thrown as its own
22
+ * class so the octave search for a `final` can tell it apart. */
23
+ export declare class TranspositionRangeError extends Error {
24
+ constructor(message: string);
25
+ }
26
+ /** The key-signature glyphs per clef glyph (issue #70): flats in the
27
+ * order b e a d g c f, sharps in the order f c g d a e b, each at the
28
+ * highest octave of the shape that stays on the staff. A key of n signs
29
+ * is the first n glyphs of its row. */
30
+ export declare const KEY_SIGNATURES: Readonly<Record<string, {
31
+ flats: string;
32
+ sharps: string;
33
+ }>>;
34
+ /** Whether two keys written as modifier glyphs under `clef` alter the
35
+ * same pitch letters the same way (glyph order and octave aside). */
36
+ export declare function sameKeyGlyphs(a: string, b: string, clef: string): boolean;
37
+ /** Parses an interval name: an optional sign, a quality (`P`, `M`, `m`,
38
+ * `A`, `d`) and a number (`P1`, `-P5`, `M3`, `A4`, `P8`, `M9`). */
39
+ export declare function parseInterval(name: string): SpelledInterval;
40
+ /**
41
+ * Transposes a script exactly: moves its sounding pitches and
42
+ * re-notates them under the target clef and key (see
43
+ * `TranspositionTarget`). Without a key, the key moves with the
44
+ * interval; without a clef, the clefs stay as written (mid-script
45
+ * `(@clef …)` included); `(@key …)` statements always move with the
46
+ * interval. A target clef re-notates the whole script in that clef and
47
+ * removes mid-script `(@clef …)` statements (one that changed the key
48
+ * leaves a `(@key …)` behind). With a `final`, the octave whose result
49
+ * fits the glyph range wins — the smaller move when several fit.
50
+ * Throws past the glyph range and on a missing glyph variant.
51
+ */
52
+ export declare function transposeScript(source: string, target: TranspositionTarget): string;
53
+ /** The exact transposition as a script transform (see `transposeScript`). */
54
+ export declare function transposeExact(target: TranspositionTarget): ScriptTransform;
@@ -44,3 +44,25 @@ export declare function baseOf(ch: string): {
44
44
  base: string;
45
45
  role: VariantRole;
46
46
  } | undefined;
47
+ /** Whether `ch` is a modifier glyph (a sharp, flat or natural sign). */
48
+ export declare function isModifierGlyph(ch: string): boolean;
49
+ /** The clef glyphs (issue #49) and the staff line each one sits on,
50
+ * counted from the bottom. The g-clef has two keybindings. */
51
+ export declare const CLEF_GLYPHS: Readonly<Record<string, {
52
+ clef: 'c' | 'f' | 'g';
53
+ line: 1 | 2 | 3 | 4;
54
+ }>>;
55
+ /** Whether `ch` is a clef glyph. */
56
+ export declare function isClefGlyph(ch: string): boolean;
57
+ /** The base pitch glyphs from low to high, one per staff position
58
+ * (spelled out: `Object.keys` would list the digit keys first). The
59
+ * index is the staff position the exact transposition counts with. */
60
+ export declare const STAFF: readonly string[];
61
+ /** The pitch letter (`a`…`g`, octave dropped) of a pitch glyph — a base
62
+ * glyph or any of its variants — under `clef` (a clef glyph; default the
63
+ * standard g-clef). Undefined when the glyph has no pitch or the clef
64
+ * glyph is unknown. */
65
+ export declare function pitchLetterOf(ch: string, clef?: string): string | undefined;
66
+ /** Every base pitch glyph whose pitch letter under `clef` is `letter`,
67
+ * in every octave, low to high. */
68
+ export declare function basesOfLetter(letter: string, clef?: string): string[];