guidex 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/lib/embed/index.js +1 -1
- package/dist/lib/embed/manual.d.ts +1 -0
- package/dist/lib/embed/manual.js +274 -2
- package/dist/lib/glyphFamilies.d.ts +46 -0
- package/dist/lib/react/index.js +1 -1
- package/dist/lib/{scoreImage-DnFIbtF_.js → scoreImage-oVBasBX5.js} +1 -1
- package/dist-embed/guidex-embed.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -229,6 +229,22 @@ A run with `symbol` set (the `**` star) has no glyph in the destination
|
|
|
229
229
|
fonts: emit `symbol.char` in `symbol.font` (the Symbol asterisk) instead
|
|
230
230
|
of its text. Absent run fields inherit the textus paragraph style.
|
|
231
231
|
|
|
232
|
+
### Glyph families
|
|
233
|
+
|
|
234
|
+
The variant glyphs of each pitch glyph, for building notation tools on top
|
|
235
|
+
of the font: `toVirga`, `toLonga`, `toSmallHead`, `toCephalicus`,
|
|
236
|
+
`toConnectDown(ch, 1–4)`, `toSmallPoint`, the accidentals `modifyUp`,
|
|
237
|
+
`modifyDown`, `modifyNatural`, and `baseOf` for the reverse lookup. Each
|
|
238
|
+
returns `undefined` when the pitch has no such variant.
|
|
239
|
+
|
|
240
|
+
```js
|
|
241
|
+
import { toVirga, modifyUp, baseOf } from 'guidex'
|
|
242
|
+
|
|
243
|
+
toVirga('1') // 'q'
|
|
244
|
+
modifyUp('1') // 'Ì'
|
|
245
|
+
baseOf('q') // { base: '1', role: 'virga' }
|
|
246
|
+
```
|
|
247
|
+
|
|
232
248
|
### Image export
|
|
233
249
|
|
|
234
250
|
Take a rendered score out as an image. The export captures the very DOM
|
package/dist/lib/embed/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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
2
|
//#region src/embed/index.ts
|
|
3
3
|
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", () => init(), { once: true });
|
|
4
4
|
else init();
|
|
@@ -19,6 +19,7 @@ export type { ScriptTransform } from '../guidoScriptTransforms';
|
|
|
19
19
|
export type { StyleSetName, SyllablePart, PartStyle, ChantRunKind } from '../guidoStyles';
|
|
20
20
|
export type { ChantRun, ChantSyllable, ChantWord, ChantMarkupOptions } from '../chantMarkup';
|
|
21
21
|
export { DEFAULT_SPACER, DEFAULT_TAB_INTERVAL_PT, SpacerMeter, layoutForWord, toWordHtml, toWordText, wordLayoutText, type SpacerChar, type SpacerConfig, type SpacerWidth, type WordExportOptions, type WordLayout, type WordLine, type WordRun, type WordStyleNames, type WordTextPiece, } from '../wordExport';
|
|
22
|
+
export { baseOf, gClefPitchOf, modifyDown, modifyNatural, modifyUp, toCephalicus, toConnectDown, toLonga, toSmallHead, toSmallPoint, toVirga, variantOf, type VariantRole, } from '../glyphFamilies';
|
|
22
23
|
export { copyWordHtml, copyWordPlainText, type CopyResult } from '../wordClipboard';
|
|
23
24
|
export { checkWordHtml, type WordCheckIssue, type WordCheckReport, type WordGapClass, type WordGapMechanism, type WordGapStat, type WordParagraphDiag, } from '../wordChecker';
|
|
24
25
|
export { downloadScorePng, downloadScoreSvg, scorePngBlob, scoreSvg, type ScoreDownloadOptions, type ScoreImageOptions, } from '../scoreImage';
|
package/dist/lib/embed/manual.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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
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
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";
|
|
4
4
|
//#region src/chantMarkup.ts
|
|
@@ -40,4 +40,276 @@ var runHtml = (run) => {
|
|
|
40
40
|
};
|
|
41
41
|
var escapeHtml = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
42
42
|
//#endregion
|
|
43
|
-
|
|
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 };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Glyph families: the variant glyphs of each pitch glyph (issue #76).
|
|
3
|
+
*
|
|
4
|
+
* A pitch glyph has two kinds of variants. Shape variants keep the pitch
|
|
5
|
+
* and change the note form (virga, longa, small head, cephalicus, the
|
|
6
|
+
* connecting forms); accidental variants are the sharp, flat and natural
|
|
7
|
+
* signs written before a note. Each variant is a separate glyph in the
|
|
8
|
+
* Guidohu font.
|
|
9
|
+
*
|
|
10
|
+
* The table is hand-written from the notation reference, not derived from
|
|
11
|
+
* `PITCH_ROWS` offsets: the accidentals do not follow row position (`1`
|
|
12
|
+
* takes its sharp from row 6 and its flat from row 5). A missing entry
|
|
13
|
+
* means the pitch has no such variant, not an untranscribed one.
|
|
14
|
+
*/
|
|
15
|
+
/** The variant roles a pitch glyph can carry. */
|
|
16
|
+
export type VariantRole = 'virga' | 'longa' | 'smallHead' | 'cephalicus' | 'connectOneDown' | 'connectTwoDown' | 'connectThreeDown' | 'connectFourDown' | 'smallPoint' | 'modifyUp' | 'modifyDown' | 'modifyNatural';
|
|
17
|
+
/** The standard g-clef pitch name of a base glyph, or of the base of a
|
|
18
|
+
* variant glyph; undefined when the glyph has no pitch. */
|
|
19
|
+
export declare function gClefPitchOf(ch: string): string | undefined;
|
|
20
|
+
/** The variant of `ch` in `role`, or undefined when `ch` has none. */
|
|
21
|
+
export declare function variantOf(ch: string, role: VariantRole): string | undefined;
|
|
22
|
+
/** The virga (the stemmed form) of a pitch glyph. */
|
|
23
|
+
export declare function toVirga(ch: string): string | undefined;
|
|
24
|
+
/** The longa (the double-length form) of a pitch glyph. */
|
|
25
|
+
export declare function toLonga(ch: string): string | undefined;
|
|
26
|
+
/** The small head of a pitch glyph. */
|
|
27
|
+
export declare function toSmallHead(ch: string): string | undefined;
|
|
28
|
+
/** The cephalicus of a pitch glyph. */
|
|
29
|
+
export declare function toCephalicus(ch: string): string | undefined;
|
|
30
|
+
/** The connecting form that joins a pitch to the note `steps` rows below
|
|
31
|
+
* it (1 to 4). */
|
|
32
|
+
export declare function toConnectDown(ch: string, steps: 1 | 2 | 3 | 4): string | undefined;
|
|
33
|
+
/** The small point (the dot that lengthens a note by half) of a pitch glyph. */
|
|
34
|
+
export declare function toSmallPoint(ch: string): string | undefined;
|
|
35
|
+
/** The sharp (raised) form of a pitch glyph. */
|
|
36
|
+
export declare function modifyUp(ch: string): string | undefined;
|
|
37
|
+
/** The flat (lowered) form of a pitch glyph. */
|
|
38
|
+
export declare function modifyDown(ch: string): string | undefined;
|
|
39
|
+
/** The natural sign for a pitch glyph. */
|
|
40
|
+
export declare function modifyNatural(ch: string): string | undefined;
|
|
41
|
+
/** Reverse lookup: the base glyph and role of a variant glyph, or
|
|
42
|
+
* undefined when `ch` is not a variant. */
|
|
43
|
+
export declare function baseOf(ch: string): {
|
|
44
|
+
base: string;
|
|
45
|
+
role: VariantRole;
|
|
46
|
+
} | undefined;
|
package/dist/lib/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
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-
|
|
2
|
+
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";
|
|
3
3
|
import { useEffect, useRef } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/react/GuidexScore.tsx
|
|
@@ -155,7 +155,7 @@ var GuidoRender = class GuidoRender {
|
|
|
155
155
|
//#region src/embed/core.ts
|
|
156
156
|
var version = {
|
|
157
157
|
name: "guidex",
|
|
158
|
-
version: "0.3.
|
|
158
|
+
version: "0.3.1",
|
|
159
159
|
description: "Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime",
|
|
160
160
|
type: "module",
|
|
161
161
|
workspaces: ["examples/*"],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var GuidexEmbed=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return e.trim().startsWith(`@`)}var n=class{source;constructor(e,t={}){this.source=(t.transforms??[]).reduce((e,t)=>t.apply(e),e)}get clef(){let e=this.normalized.match(/^\s*\(([^)]*)\)/);if(!(!e||t(e[1])))return e[1]}get tokens(){let e=this.normalized,n=e.match(/^\s*\(([^)]*)\)/),i=[...(n&&!t(n[1])?e.slice(n[0].length):e).matchAll(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g)].map(([,e,n])=>{if(t(n)){let t=n.trim();if(t!==`@break`)throw Error(`Unknown statement "${t}"`);if(e.trim()!==``)throw Error(`statement must not carry syllable text: "${r(e.trim())}"`);return{kind:`break`,spaceBefore:/^\s/.test(e)}}return{kind:`syllable`,text:r(e.trim()),notes:r(n),spaceBefore:/^\s/.test(e)}}),a=i.reduce((e,t,n)=>t.kind===`syllable`?n:e,-1);for(let[e,t]of i.entries())if(t.kind===`syllable`){t.wordEnd=e===a;for(let n=e+1;!t.wordEnd&&n<i.length;n++){let e=i[n];if(e.spaceBefore&&(t.wordEnd=!0),e.kind===`syllable`)break}}return i}get syllables(){return this.tokens.filter(e=>e.kind===`syllable`).map(({text:e,notes:t,wordEnd:n})=>({text:e,notes:t,wordEnd:n}))}get normalized(){let e=this.source;return(e.match(/(^|[^\\])\(/g)??[]).length>(e.match(/(^|[^\\])\)/g)??[]).length&&(e+=`)`),/(^|[^\\])\)$/.test(e)||(e+=`()`),e}get words(){let e=[],t;for(let n of this.syllables)t??={text:``,syllables:[]},t.syllables.push({text:n.text,notes:n.notes}),t.text=t.syllables.map(e=>e.text).join(``),n.wordEnd&&(e.push(t),t=void 0);return e}toString(){let e=this.tokens.map((e,t)=>{let n=t>0&&e.spaceBefore?` `:``;return e.kind===`break`?`${n}(@break)`:`${n}${i(e.text)}(${i(e.notes)})`});return`${this.clef===void 0?``:`(${this.clef})`}${e.join(``)}`}};function r(e){return e.replace(/\\(.)/g,`$1`)}function i(e){return e.replace(/\\/g,`\\\\`).replace(/[()]/g,e=>`\\${e}`)}function a(e){let t=[...e];for(let e=0;e<t.length;e++){let n=t[e];if(!/\s/.test(n))return{unit:n===`\\`&&t[e+1]!==void 0?n+t[e+1]:n,index:e}}return null}function o(e){let n=e.match(/^\s*\(([^)]*)\)/),i=n?n[0].length:0,o=e.slice(i);for(let n of o.matchAll(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g)){let[,o,s]=n;if(r(s).trim().length===0||t(s))continue;let c=a(o);if(!c||o.trimStart().startsWith(`*`))return e;let l=i+n.index+c.index,u=l+c.unit.length;return`${e.slice(0,l)}*${e.slice(l,u)}*${e.slice(u)}`}return e}var s={startWithInitial:{name:`startWithInitial`,apply:o}},c=[`ðñ0123456789öüó`,`^]qwertzuiopõú`,`ÝÞQWERTZUIOPÕÚ`,`×sdfghjkléáû`,`ØÙDFGHJKLÉÁÛ`,`÷øaASÍYXCVBN$m`,`ÈÊËÌÎÏÐÑÒþßòôùý`,`“”•–—˜™š›œº»`,`®−§ÿ"+!%/=()ÖÜÓ`,`Ÿ¡¢£[¥¦©ª«¬`,`~¯‚ƒ„…†‡ˆ‰Š‹Œ‘’`,`àâãäåæçèêëìîï`,`½°±²³´μ·¾¸¹`];function l(e,t,n){for(let r of c){let i=r.indexOf(e);if(i===-1)continue;let a=i+t;return a<0||a>=r.length?n===`null`?`\0`:r[Math.max(0,Math.min(r.length-1,a))]:r[a]}}function u(e,t,n){let r=``;for(let i=0;i<e.length;i++){let a=e[i],o=a===`\\`&&e[i+1]!==void 0,s=l(o?e[i+1]:a,t,n);if(s===void 0){r+=o?a+e[i+1]:a,o&&i++;continue}r+=`\\()`.includes(s)?`\\${s}`:s,o&&i++}return r}function d(e,n={}){let r=n.overflow??`clamp`;return{name:`transpose`,apply:n=>{if(e===0)return n;let i=n.match(/^\s*\(([^)]*)\)/),a=i?i[0].length:0;return n.slice(0,a)+n.slice(a).replace(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g,(n,i,a)=>t(a)?`${i}(${a})`:`${i}(${u(a,e,r)})`)}}}var f=new Set([`*`,`†`]),p={chars:f,fontFamily:`'Times New Roman', Times, serif`},m={weight:`400`,scale:.7,raise:.2},h={BNS:{textFontStack:`'Book Antiqua', Georgia, serif`,notesFontStack:`'Guidohu'`,markerGlyphs:p,verifiedFonts:[{family:`'Book Antiqua'`,weight:`400`},{family:`'Book Antiqua'`,weight:`700`},{family:`'Guidohu'`,weight:`400`},{family:`'Liturgy'`,weight:`700`}],decorations:{__:{fontFamily:`'Liturgy', serif`,weight:`700`,color:`var(--red)`},_:{uppercase:!0,scale:.7,color:`var(--red)`},"*":{weight:`700`,color:`var(--red)`,initial:!0}},specialStarStyle:{fontFamily:p.fontFamily,weight:`700`,scale:1,measureScale:.95,raise:.1,color:`var(--red)`},padding:12,scriptTransforms:[s.startWithInitial]},Vesperale:{textFontStack:`'Times New Roman', Times, serif`,notesFontStack:`'Guidohu'`,verifiedFonts:[{family:`'Times New Roman', Times, serif`,weight:`400`},{family:`'Times New Roman', Times, serif`,weight:`700`},{family:`'Guidohu'`,weight:`400`},{family:`'Liturgy'`,weight:`700`}],decorations:{__:{fontFamily:`'Liturgy', serif`,weight:`700`},_:{scale:.8,italic:!0},"*":{weight:`700`,initial:!0}},specialStarStyle:{fontFamily:p.fontFamily,weight:`700`,scale:1,measureScale:.95,raise:.2},padding:12,scriptTransforms:[]}};function g(e,t,n,r={}){if(e.length===0)return[];if(e===`**`)return[{text:`∗`,style:{...t.specialStarStyle},kind:`star`}];let i=e,a={},o;for(let n of[`__`,`_`]){let r=t.decorations[n];if(r&&e.length>=n.length*2+1&&e.startsWith(n)&&e.endsWith(n)){i=e.slice(n.length,-n.length),a={...r},o=n===`__`?`liturgy`:`rubric`;break}}let s=t.decorations[`*`],c=[],l=i,u=``;for(let e=/\*([^*]+)\*/.exec(l);e;e=/\*([^*]+)\*/.exec(l))u+=l.slice(0,e.index),u&&=(c.push({text:u,marked:!1}),``),c.push({text:e[1],marked:!0}),l=l.slice(e.index+e[0].length);u+=l,u&&c.push({text:u,marked:!1});let d=c.map(({text:e,marked:t})=>({text:e,style:t?{...a,...s,initial:!0}:{...a},kind:o})),p=t.markerGlyphs,h=[];for(let e of d){e.style.uppercase&&!r.rawCase&&(e.text=e.text.toUpperCase()),n&&(e.style={...e.style,weight:`700`});let t=[...e.text],i=e.style.fontFamily?.includes(`Liturgy`)??!1,a=e=>f.has(e)||p&&p.chars.has(e)?`marker`:i&&e===`+`?`plus`:`text`;if(t.every(e=>a(e)===`text`)){h.push({text:e.text,style:{...e.style},kind:e.kind});continue}let o=``,s=null,c=()=>{if(!o)return;let t={...e.style},n=e.kind;s===`marker`?(n=`marker`,p&&p.chars.has(o[0])&&(t={...t,fontFamily:p.fontFamily})):s===`plus`&&(t={...t,...m},n=`plus`),h.push({text:o,style:t,kind:n}),o=``};for(let e of t){let t=a(e);t!==s&&c(),s=t,o+=e}c()}return h}function _(e,t,n){return[e.italic?`italic`:`normal`,`normal`,e.weight??`400`,`${t*(e.measureScale??e.scale??1)}px`,e.fontFamily??n].join(` `)}function v(e,t){let n={};return e.fontFamily&&(n[`font-family`]=e.fontFamily),e.weight&&(n[`font-weight`]=e.weight),e.italic&&(n[`font-style`]=`italic`),e.scale!==void 0&&(n[`font-size`]=`${t*e.scale}px`),e.color&&(n.color=e.color),e.raise&&(n.position=`relative`,n.top=`${-t*e.raise}px`),n}function y(e,t){return e.verifiedFonts.map(e=>`${e.weight} ${t}px ${e.family}`)}var b=new Set(`,.:?'"+!%/=()ÖÜÓ;`.split(``)),x=new Set(`Ÿ¡¢£[¥¦©ª«¬`.split(``)),ee=new Set(`÷øaASÍYXCVBN$mÈÊËÌÎÏÐÑÒþßòôùý“”•–—˜™š›œº»`.split(``)),S=[`-`,`¨`];function C(e){let t=0;for(;t<e.length&&b.has(e[t]);)t++;t>0&&t<e.length&&e[t]===`-`&&t++;let n=e.length;for(;n>t&&b.has(e[n-1]);)n--;return n<e.length&&n>t&&e[n-1]===`-`&&n--,{leading:e.slice(0,t),core:e.slice(t,n),trailing:e.slice(n)}}var w=null;function T(e,t){return w||=document.createElement(`canvas`).getContext(`2d`),w.font=t,w.measureText(e).width}function te(e,t){w||=document.createElement(`canvas`).getContext(`2d`),w.font=t;let n=w.measureText(e);return{left:n.actualBoundingBoxLeft,right:n.actualBoundingBoxRight}}async function E(e,t={}){let{style:r=`BNS`,bold:i=!1,textPx:a=18,notesPx:o=a*2,maxWidthPx:s=1/0}=t,c=typeof e==`string`?new n(e):e,l=h[r];if(!l)throw Error(`Unknown style set: "${r}"`);for(let e of y(l,a)){try{await document.fonts.load(e)}catch{}if(!document.fonts.check(e))throw Error(`Font could not be loaded: ${e} (style "${r}")`)}let u=`400 ${o}px ${l.notesFontStack}`,d=l.textFontStack,f=_({weight:i?`700`:`400`},a,d),p=e=>g(e,l,i),m=e=>e.reduce((e,t)=>e+T(t.text,_(t.style,a,d)),0),v=T(`-`,u),w=T(`-`,f),E=c.clef===void 0?``:`${c.clef}-`,D=[],O,k,A,j,M=!1,N=[],P=()=>{O&&(O.textCursor=A,O.notesEnd=O.notesParts.length?T(E+O.notesParts.join(``),u):0),O={notesParts:[],segments:[],textCursor:0,notesEnd:0,lastWordEnd:null},D.push(O),k=E,A=0,j=!1,M=!1};P();let F=c.tokens,I=F.filter(e=>e.kind===`syllable`),L=[],R=0;for(let e of F)e.kind===`break`?L.push({kind:`break`}):L.push({kind:`syl`,syl:e,i:R++,text:e.text,notes:e.notes,first:!0,lastSeg:!0});let z=(e,t,n)=>{for(let r=e.length-1;r>0;r--){if(!S.includes(e[r]))continue;let i=r+1;for(;i<e.length&&b.has(e[i]);)i++;if(!(i>=e.length)&&n(e.slice(0,i))<=t)return r}return-1},B=(e,t)=>{let n=e.notes,r=t+1;for(;r<n.length&&b.has(n[r]);)r++;return e.notes=n.slice(0,t)+n.slice(t+1,r),n.slice(r)},V=(e,t,n)=>{e.lastSeg=!1,L.splice(t+1,0,{kind:`syl`,syl:e.syl,i:e.i,text:``,notes:n,first:!1,lastSeg:!0}),H=!0},ne=e=>{for(;N.length>0;){let t=N[0];if(A>0&&A+t.textWidth+(t.wordEnd?0:w)>s){P();continue}N.shift(),O.segments.push({kind:`syl`,parts:t.sylParts,textStart:A,textWidth:t.textWidth,contentWidth:0,contentStart:0,extraDashes:0,tight:!1,noNotes:!0,...e&&N.length===0?{trailing:!0}:{}}),A+=t.textWidth,t.spaceWidth>0&&(O.segments.push({kind:`word-space`,width:t.spaceWidth}),A+=t.spaceWidth),O.lastWordEnd=t.wordEnd,O.textCursor=A}},H=!1,U,W=0;for(;W<L.length;){let e=L[W];if(e.kind===`break`){(O.segments.length>0||N.length>0)&&(ne(!1),H=!0),W++;continue}let t=e.syl,n=e.i;H&&=(P(),!1);let r=e.lastSeg&&n===I.length-1,i=e.text,a=p(i),o=m(a),c=!r&&t.wordEnd?T(` `,f):0,l=N.reduce((e,t)=>e+t.textWidth+t.spaceWidth,0),d=t.notes.length===1&&x.has(t.notes),h=A===0||A+l+o+(t.wordEnd?0:w)<=s;if(t.notes.length===0){N.push({sylParts:a,textWidth:o,spaceWidth:c,wordEnd:t.wordEnd}),W++;continue}if(e.first&&e.lastSeg&&t.text.trim()===``&&C(t.notes).core===``){let e=k[k.length-1],n=e&&e!==`-`&&!b.has(e)&&!t.notes.startsWith(`-`)?`-`:``;O.notesParts.push(n+t.notes),k+=n+t.notes,j=!0,M=!1,U=t.wordEnd,W++;continue}let g=I[n-1]?.notes!==t.notes;if(d&&!g&&O.notesParts.length>0&&!h&&P(),!e.first){for(;!(T(k+e.notes,u)<=s);){let t=z(e.notes,s,e=>T(k+e,u));if(t<0||t+1>=e.notes.length)break;let n=B(e,t);V(e,W,n)}let n=C(e.notes);O.notesParts.push(e.notes),k+=e.notes,e.lastSeg&&(j=n.trailing.length>0),O.lastWordEnd=!0,U=t.wordEnd,e.lastSeg||(H=!0),W++;continue}let _=C(e.notes),y=O.notesParts.length===0||M?``:j||ee.has(_.core[0])?`--`:`---`,S=(e=0)=>{let t=0;for(;t<_.core.length&&ee.has(_.core[t]);)t++;t===_.core.length&&(t=0);let n=_.core.slice(t),r=T(n,u),i=T(k+y+`-`.repeat(e)+_.leading+_.core.slice(0,t),u),a=te(n,u),s=-a.left,c=(a.right-a.left)/2;return{contentWidth:r,contentStart:i,textStart:r>=o||d?i+s:i+c-o/2}},{contentWidth:E,contentStart:D,textStart:F}=S();for(;;){let n=T(k+y+e.notes,u)>s,r=F+o+(t.wordEnd?0:w)>s;if(!n&&!r)break;if(n){let t=z(e.notes,s,e=>T(k+y+e,u));if(t>=0&&t+1<e.notes.length){let n=B(e,t);V(e,W,n),_=C(e.notes),{contentWidth:E,contentStart:D,textStart:F}=S();break}}if(O.notesParts.length===0&&A===0){if(n){let t=z(e.notes,s,e=>T(k+e,u));if(t>=0&&t+1<e.notes.length){let n=B(e,t);e.notes=e.notes.slice(0,t),V(e,W,n),_=C(e.notes),{contentWidth:E,contentStart:D,textStart:F}=S()}}break}P(),y=``,{contentWidth:E,contentStart:D,textStart:F}=S()}let R=O.notesParts.length>0&&!U&&l===0,G=A+w,K=A+l+(M&&R?w:0),q=y+e.notes,J=0,Y=!1,X=t=>{J=t,q=y+`-`.repeat(t)+e.notes,{contentWidth:E,contentStart:D,textStart:F}=S(t)},Z=d&&!g&&O.notesParts.length>0;if(Z){y=``,F=A+l;let t=F+o+c-T(k,u),n=s-T(k+y,u),r=t>0?Math.min(Math.ceil(t/v),Math.max(0,Math.floor(n/v))):0;e.notes=`-`.repeat(r),_=C(e.notes),q=y+e.notes,Y=R}if(!Z){if(!M&&R&&F<G&&(o>E||F<A)){Y=!0,F=A;let t=E>=o?F:F+(o-E)/2;t>D&&(J=Math.round((t-D)/v),q=y+`-`.repeat(J)+e.notes)}else if(F<K){let t=E>=o?K:K+(o-E)/2;if(t>D){let n=Math.max(0,Math.floor((t-D)/v));for(X(n);F<K;)n++,X(n);if(O.notesParts.length>0&&T(k+q,u)>s&&(P(),y=``,q=y+e.notes,J=0,{contentWidth:E,contentStart:D,textStart:F}=S(),F<A+l)){let e=E>=o?A+l:A+l+(o-E)/2;if(e>D){let t=Math.max(0,Math.floor((e-D)/v));for(X(t);F<A+l;)t++,X(t)}}}}}l>0&&F<A+l&&(F=A+l);let Q=Math.max(0,F-l-A);if(O.notesParts.length===0)O.segments.push({kind:`gap`,role:`lead-in`,width:Q,endPx:F-l,textStartPx:F});else if(U)O.segments.push({kind:`gap`,role:`word-gap`,width:Q,endPx:F-l,textStartPx:F});else if(!(l===0&&Y)&&l===0){let e=Math.max(0,(Q-w)/2);O.segments.push({kind:`connector`,pad:e,gapWidth:Q,dashWidth:w,dashStartPx:A+e,nextAnchorPx:F})}let $=F-l;for(let e of N)O.segments.push({kind:`syl`,parts:e.sylParts,textStart:$,textWidth:e.textWidth,contentWidth:0,contentStart:0,extraDashes:0,tight:!1,noNotes:!0}),$+=e.textWidth,e.spaceWidth>0&&(O.segments.push({kind:`word-space`,width:e.spaceWidth}),$+=e.spaceWidth);N=[],O.segments.push({kind:`syl`,parts:a,textStart:F,textWidth:o,contentWidth:E,contentStart:D,extraDashes:J,tight:Y,noNotes:!1}),c>0&&O.segments.push({kind:`word-space`,width:c}),A=F+o+c,k+=q,O.notesParts.push(q),O.lastWordEnd=t.wordEnd,U=t.wordEnd,e.lastSeg&&(j=_.trailing.length>0,M=d),e.lastSeg||(H=!0),W++}ne(!0),O.textCursor=A,O.notesEnd=O.notesParts.length?T(E+O.notesParts.join(``),u):0,D.forEach((e,t)=>{if(t===D.length-1||e.lastWordEnd!==!1)return;let n=e.notesEnd>e.textCursor?Math.max(0,(e.notesEnd-e.textCursor-w)/2):0;e.segments.push({kind:`line-end-dash`,pad:n,dashWidth:w,dashStartPx:e.textCursor+n,trailEndPx:e.notesEnd,textEndPx:e.textCursor})});let G=s+(l.padding??0),K=T(`*`,u);return D.forEach((e,t)=>{if(t===D.length-1)return;if(s===1/0){e.breakMarkerLeftPx=l.padding??0;return}let n=T(E+e.notesParts.join(``),u);for(;n+v<=G-K&&n+v<s;)e.notesParts.push(`-`),n+=v;e.breakMarkerLeftPx=G-n-K}),{lines:D,clefPrefix:E,styleSet:l,styleName:r,textPx:a,notesPx:o,bold:i,maxWidthPx:s,starTarget:G,starWidth:K}}var D=class e{script;constructor(e){this.script=typeof e==`string`?new n(e):e}async render(t,n={}){let{debug:r=!1}=n,{lines:i,clefPrefix:a,styleSet:o,styleName:s,textPx:c,notesPx:l,bold:u,starTarget:d,starWidth:f}=await E(this.script,n);t.style.fontSize=`${c}px`,t.style.fontFamily=o.textFontStack,t.dataset.style=s,t.replaceChildren(...i.flatMap(t=>[e.notesLine(t,a,l,d,f,r),e.textLine(t,c,u,r)]))}static notesLine(e,t,n,r,i,a){let o=document.createElement(`div`);if(o.className=`guido`,o.style.fontSize=`${n}px`,o.textContent=t+e.notesParts.join(``),e.breakMarkerLeftPx!==void 0){let t=document.createElement(`span`);t.className=`guido-break`,t.textContent=`*`,t.style.position=`relative`,t.style.left=`${e.breakMarkerLeftPx}px`,a&&(t.title=`line break at ${r.toFixed(1)}px (staff filled to ${(r-e.breakMarkerLeftPx-i).toFixed(1)}px)`),o.appendChild(t)}return o}static textLine(t,n,r,i){let a=document.createElement(`p`);r&&(a.style.fontWeight=`700`);for(let r of t.segments)switch(r.kind){case`gap`:{let t=e.spacer(r.width);i&&(t.title=`${r.role===`lead-in`?`lead-in`:`word gap`} ${r.width.toFixed(1)}px → text ${r.textStartPx.toFixed(1)}`),a.appendChild(t);break}case`connector`:{let t=e.spacer(r.pad),n=document.createElement(`span`);n.className=`dash`,n.textContent=`-`;let o=e.spacer(r.pad);i&&(t.title=`lead pad ${r.pad.toFixed(1)}px (gap ${r.gapWidth.toFixed(1)} − dash ${r.dashWidth.toFixed(1)}, halved)`,n.title=`dash ${r.dashWidth.toFixed(1)}px`,o.title=`trail pad ${r.pad.toFixed(1)}px`),a.append(t,n,o);break}case`syl`:{let t=e.sylSpan(r.parts,n);if(i){if(r.noNotes)t.title=`no notes, text w ${r.textWidth.toFixed(1)}, ${r.trailing?`end of score`:`before the next syllable with notes`}`;else{let e=(r.textWidth-r.contentWidth)/2,n=r.textStart-r.contentStart;t.title=[`text w ${r.textWidth.toFixed(1)}`,`notes w ${r.contentWidth.toFixed(1)}`,r.extraDashes?`+${r.extraDashes} pad dash(es)`:null,`text start ${r.textStart.toFixed(1)}`,`notes start ${r.contentStart.toFixed(1)}`,`theoDiff: ${e.toFixed(1)}`,`cursDiff: ${n.toFixed(1)}`].filter(Boolean).join(`, `)}}a.appendChild(t);break}case`word-space`:{let e=document.createElement(`span`);e.className=`word-space`,e.textContent=` `,i&&(e.title=`word space ${r.width.toFixed(1)}px`),a.appendChild(e);break}case`line-end-dash`:{let t=e.spacer(r.pad),n=document.createElement(`span`);n.className=`dash`,n.textContent=`-`;let o=e.spacer(r.pad);i&&(t.title=`lead pad ${r.pad.toFixed(1)}px → line-end dash (text end ${r.textEndPx.toFixed(1)}, notes end ${r.trailEndPx.toFixed(1)})`,n.title=`dash ${r.dashWidth.toFixed(1)}px (line end)`,o.title=`trail pad ${r.pad.toFixed(1)}px`),a.append(t,n,o);break}}return a}static sylSpan(e,t){let n=document.createElement(`span`);return n.className=`syl`,e.forEach(e=>{let r=document.createElement(`span`);r.textContent=e.text;for(let[n,i]of Object.entries(v(e.style,t)))r.style.setProperty(n,i);let i=[...e.kind?[e.kind]:[],...e.style.initial?[`initial`]:[]].join(` `);i&&(r.className=i),n.appendChild(r)}),n}static spacer(e){let t=document.createElement(`span`);return t.className=`spacer`,t.style.display=`inline-block`,t.style.width=`${e}px`,t}},O={name:`guidex`,version:`0.3.0`,description:`Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime`,type:`module`,workspaces:[`examples/*`],main:`./dist/lib/embed/manual.js`,types:`./dist/lib/embed/manual.d.ts`,exports:{".":{types:`./dist/lib/embed/manual.d.ts`,default:`./dist/lib/embed/manual.js`},"./embed":{types:`./dist/lib/embed/index.d.ts`,default:`./dist/lib/embed/index.js`},"./guidex.css":{types:`./dist/lib/guidex.css.d.ts`,default:`./dist/lib/guidex.css`},"./fonts/*":`./dist/lib/fonts/*`,"./react":{types:`./dist/lib/react/index.d.ts`,default:`./dist/lib/react/index.js`},"./word":{types:`./dist/lib/word/index.d.ts`,default:`./dist/lib/word/index.js`}},files:[`dist-embed`,`dist/lib`],peerDependencies:{react:`>=18`},peerDependenciesMeta:{react:{optional:!0}},publishConfig:{access:`public`},scripts:{dev:`vite --host`,build:`tsc && vite build`,"build:embed":`vite build --config vite.embed.config.ts`,"build:lib":`vite build --config vite.lib.config.ts`,preview:`vite preview`,test:`vitest run`,lint:`eslint .`},keywords:[`plainchant`,`gregorian`,`guido`,`score`,`notation`,`liturgy`],repository:{type:`git`,url:`git+https://github.com/BrownieMaar/guidex.git`},bugs:{url:`https://github.com/BrownieMaar/guidex/issues`},homepage:`https://github.com/BrownieMaar/guidex#readme`,devDependencies:{"@eslint/js":`^10.0.1`,"@testing-library/dom":`^10.4.2`,"@testing-library/react":`^16.3.3`,"@testing-library/user-event":`^14.6.7`,"@types/react":`^19.3.0`,"@types/react-dom":`^19.3.0`,"@vitejs/plugin-react":`^6.1.1`,eslint:`^10.10.0`,jsdom:`^29.1.1`,react:`^19.3.0`,"react-dom":`^19.3.0`,typescript:`~6.0.2`,"typescript-eslint":`^8.70.0`,vite:`^8.2.2`,"vite-plugin-dts":`^5.1.1`,vitest:`^4.1.11`}}.version,k=`.guidex-script, .guido-script`,A={maxWidth:`auto`,style:`BNS`,bold:!1,textPx:18,transpose:0,debug:!1},j={},M=new WeakMap,N=new WeakMap,P=new WeakMap;function F(e){if(e!==void 0){if(e===``||e===`true`)return!0;if(e===`false`)return!1}}function I(e){if(e===void 0)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function L(e,t){if(/^auto$/i.test(e.trim()))return`auto`;let n=Number(e);return Number.isFinite(n)&&n>0?n:(console.warn(`[guidex] ignoring invalid data-max-width "${e}"`),t)}var R=new WeakMap;function z(e){let t=e.dataset,n=R.get(e)??{};return{maxWidth:t.maxWidth===void 0?n.maxWidth??j.maxWidth??A.maxWidth:L(t.maxWidth,n.maxWidth??j.maxWidth??A.maxWidth),style:t.style??n.style??j.style??A.style,bold:F(t.bold)??n.bold??j.bold??A.bold,textPx:I(t.textPx)??n.textPx??j.textPx??A.textPx,transpose:I(t.transpose)??n.transpose??j.transpose??A.transpose,debug:F(t.debug)??n.debug??j.debug??A.debug}}function B(e){return e.querySelector(`:scope > .guidex-render`)?.clientWidth||e.clientWidth||e.parentElement?.clientWidth||0}function V(e,t,n){if(typeof t==`number`)return t;let r=B(e);if(r<=0)return 1/0;let i=r-(h[n]?.padding??0);return i>0?i:r}function ne(e){for(let t of e.childNodes)if(t.nodeType===Node.TEXT_NODE&&t.nodeValue?.trim())return t.nodeValue.trim();return M.get(e)??``}function H(e){let t=e.querySelector(`:scope > .guidex-render`);if(t)return t;let n=document.createElement(`div`);return n.className=`guidex-render`,e.replaceChildren(n),n}function U(e,t){let n=document.createElement(`p`);n.className=`guidex-error`,n.textContent=t,e.replaceChildren(n)}function W(e,t){let n=[...h[e]?.scriptTransforms??[]];return t!==0&&n.push(d(t)),n}async function G(e){let t=(N.get(e)??0)+1;N.set(e,t);let r=z(e),i=ne(e);M.set(e,i);let a=H(e),o=V(e,r.maxWidth,r.style);P.set(e,o);let s=document.createElement(`div`),c=new n(i,{transforms:W(r.style,r.transpose)});try{if(await new D(c).render(s,{style:r.style,bold:r.bold,textPx:r.textPx,debug:r.debug,maxWidthPx:o}),N.get(e)!==t)return;a.replaceChildren(...s.childNodes),a.style.cssText=s.style.cssText,s.dataset.style&&(a.dataset.style=s.dataset.style)}catch(n){if(N.get(e)!==t)return;console.error(`[guidex]`,n),U(a,n instanceof Error?n.message:String(n))}}var K=new WeakMap;function q(e){let t=z(e),n=V(e,t.maxWidth,t.style);return Math.abs(n-(P.get(e)??NaN))>1}function J(e){if(K.has(e))return;let t;if(typeof ResizeObserver<`u`){let n=new ResizeObserver(()=>{q(e)&&G(e)});n.observe(e),t=()=>n.disconnect()}else{let n=()=>{q(e)&&G(e)};window.addEventListener(`resize`,n),t=()=>window.removeEventListener(`resize`,n)}K.set(e,t)}function Y(e){K.get(e)?.(),K.delete(e),M.delete(e),R.delete(e),N.delete(e),P.delete(e)}async function X(e,t,r={}){R.set(e,r);let i=(N.get(e)??0)+1;N.set(e,i),M.set(e,t);let a=z(e),o=H(e),s=V(e,a.maxWidth,a.style);P.set(e,s),J(e);let c=document.createElement(`div`),l=new n(t,{transforms:W(a.style,a.transpose)});try{if(await new D(l).render(c,{style:a.style,bold:a.bold,textPx:a.textPx,debug:a.debug,maxWidthPx:s}),N.get(e)!==i)return;o.replaceChildren(...c.childNodes),o.style.cssText=c.style.cssText,c.dataset.style&&(o.dataset.style=c.dataset.style)}catch(t){if(N.get(e)!==i)return;console.error(`[guidex]`,t),U(o,t instanceof Error?t.message:String(t))}}async function Z(e=document){let t=j.selector??k,n=[];return e instanceof Element&&e.matches(t)&&n.push(e),n.push(...e.querySelectorAll(t)),Promise.all(n.map(e=>(J(e),G(e)))).then(()=>void 0)}var Q=!1;function $(){if(Q||typeof MutationObserver>`u`)return;Q=!0;let e=j.selector??k;new MutationObserver(t=>{let n=new Set;for(let r of t)for(let t of r.addedNodes)if(t instanceof Element&&!t.closest(`.guidex-render`)){t.matches(e)&&n.add(t);for(let r of t.querySelectorAll(e))n.add(r)}for(let e of n)J(e),G(e)}).observe(document.documentElement,{childList:!0,subtree:!0})}function re(e={}){j={...j,...e},$(),Z()}var ie=[`font-family`,`font-size`,`font-style`,`font-weight`,`line-height`,`letter-spacing`,`text-transform`,`color`,`position`,`top`,`left`,`margin-top`,`margin-bottom`,`padding-top`,`padding-bottom`],ae=[`font-family`,`font-size`,`font-style`,`font-weight`,`line-height`,`letter-spacing`,`color`];function oe(e){return e.classList.contains(`max-width-guide`)||e.hasAttribute(`data-score-image-ignore`)}function se(e){let t=e.querySelector(`.guido`)?.parentElement;if(!t)throw Error(`No rendered score found to export — render a score into the element first.`);return t}function ce(e){let t=e.getBoundingClientRect(),n=[],r=document.createRange();return r.selectNodeContents(e),typeof r.getBoundingClientRect==`function`&&n.push(r.getBoundingClientRect()),e.querySelectorAll(`*`).forEach(e=>n.push(e.getBoundingClientRect())),n.length===0&&n.push(t),{left:Math.min(...n.map(e=>e.left))-t.left,top:Math.min(...n.map(e=>e.top))-t.top,right:Math.max(...n.map(e=>e.right))-t.left,bottom:Math.max(...n.map(e=>e.bottom))-t.top}}function le(e){let t=document.createRange();if(t.selectNodeContents(e),typeof t.getClientRects!=`function`)return 1;let n=Array.from(t.getClientRects()).filter(e=>e.width>0||e.height>0);if(n.length===0)return 1;n.sort((e,t)=>e.top-t.top);let r=0,i=-1/0;for(let e of n)e.top>=i?(r++,i=e.bottom):e.bottom>i&&(i=e.bottom);return r}function ue(e){let t=[],n=``,r=null;for(let i of e)r?i===r?r=null:n+=i:i===`"`||i===`'`?r=i:i===`,`?(t.push(n.trim()),n=``):n+=i;return t.push(n.trim()),t.filter(Boolean)}function de(e){return e===`normal`?`400`:e===`bold`?`700`:e}function fe(e){return e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`).replace(/>/g,`>`)}function pe(e,t,n,r,i){let a=/url\(\s*(['"]?)([^'")]+)\1\s*\)/.exec(r);if(!a)return;let o;try{o=new URL(a[2],i??location.href).toString()}catch{return}return{family:e,style:t||`normal`,weight:de(n||`400`),url:o,format:/format\(\s*['"]?([^'")]+?)['"]?\s*\)/.exec(r)?.[1]}}function me(e,t){let n=[];for(let r of e.matchAll(/@font-face\s*{([^}]*)}/g)){let e=r[1],i=t=>{let n=RegExp(`(?:^|[;\\s])${t}\\s*:\\s*([^;]+)`,`i`).exec(e);return n?n[1].trim():``},a=i(`font-family`),o=i(`src`);if(!a||!o)continue;let s=ue(a)[0];if(!s)continue;let c=pe(s,i(`font-style`),i(`font-weight`),o,t);c&&n.push(c)}return n}async function he(e){let t=[],n=new Set,r=e=>{let r=`${e.family}|${e.style}|${e.weight}`;n.has(r)||(n.add(r),t.push(e))},i=[];for(let t of document.styleSheets){let n;try{n=t.cssRules}catch{t.href&&i.push(t.href);continue}for(let i of Array.from(n)){let n=i.style;if(!n)continue;let a=n.getPropertyValue(`src`),o=n.getPropertyValue(`font-family`);if(!a||!o)continue;let s=ue(o)[0];if(!s||!e.has(s))continue;let c=pe(s,n.getPropertyValue(`font-style`),n.getPropertyValue(`font-weight`),a,t.href??void 0);c&&r(c)}}for(let t of i)try{let n=await fetch(t);if(!n.ok)throw Error(String(n.status));let i=await n.text();for(let n of me(i,t))e.has(n.family)&&r(n)}catch{console.warn(`[guidex] scoreImage: a cross-origin stylesheet (${t}) could not be read — fonts declared only there are missing from the export`)}return t}async function ge(e){let t=await fetch(e);if(!t.ok)return;let n=await t.blob();return new Promise(e=>{let t=new FileReader;t.onload=()=>e(typeof t.result==`string`?t.result:void 0),t.onerror=()=>e(void 0),t.readAsDataURL(n)})}async function _e(e,t){let n=[],r=new Set,i=new Map,a=e=>{let t=i.get(e);return t||(t=ge(e).catch(()=>void 0),i.set(e,t)),t},o=new Map;for(let t of e){let e=o.get(t.family)??[];e.push(t),o.set(t.family,e)}for(let[e,i]of o){let o=i.filter(e=>e.style===`normal`),s=o.length>0?[...o,...t?i.filter(e=>e.style!==`normal`):[]]:i;for(let t of s){let i=await a(t.url);if(!i){r.add(e);continue}let o=t.format?` format('${t.format}')`:``;n.push(`@font-face{font-family:'${t.family}';font-style:${t.style};font-weight:${t.weight};src:url(${i})${o}}`)}}for(let e of r)console.warn(`[guidex] scoreImage: could not embed the ${e} webfont — the export falls back to the next family in its stack`);return n.join(``)}function ve(e){let t=document.createElement(`span`);return t.style.color=e,getComputedStyle(t).color}function ye(e){let t=getComputedStyle(e).getPropertyValue(`--red`).trim();return t?ve(t):``}function be(e,t,n){return n&&t&&ve(t)===n?!0:e.style?.getPropertyValue(`color`).replace(/\s+/g,``)===`var(--red)`}function xe(e,t,n){let r=new Set,i=!1;for(let a=0;a<e.length;a++){let o=e[a],s=t[a],c=getComputedStyle(o);for(let e of a===0?ae:ie){if(e===`color`){let e=c.getPropertyValue(`color`);if(!e)continue;let t=be(o,e,n.accentProbe)?n.accent:n.foreground;s.style.setProperty(`color`,t||e);continue}let t=c.getPropertyValue(e);t&&s.style.setProperty(e,t)}let l=c.getPropertyValue(`font-family`);if(l)for(let e of ue(l))r.add(e);c.getPropertyValue(`font-style`)===`italic`&&(i=!0)}return{families:r,italics:i}}async function Se(){let e=document.fonts;e?.ready&&await e.ready}async function Ce(e,t){let n=Math.max(0,t.padding??0),r=se(e);if(!r.isConnected)throw Error(`scoreImage: the score left the document before the export — re-render it and try again`);await Se();let i=Array.from(r.children).filter(e=>e.classList.contains(`guido`)||e.tagName===`P`);if(i.length===0)throw Error(`No rendered score found to export — render a score into the element first.`);let a=i.map(e=>e.getBoundingClientRect()),o=a[0],s=i.map((e,t)=>{let n=ce(e),r=a[t],i=r.left-o.left,s=le(e)>1;return{left:n.left+i,top:n.top+(r.top-o.top),right:(s?Math.max(r.width,n.right):n.right)+i,bottom:n.bottom+(r.top-o.top),pinWidth:s?r.width:void 0}}),c=Math.min(0,...s.map(e=>e.left)),l=Math.min(0,...s.map(e=>e.top)),u=Math.max(...s.map(e=>e.right)),d=Math.max(...s.map(e=>e.bottom)),f=Math.max(1,Math.ceil(u-c))+n*2,p=Math.max(1,Math.ceil(d-l))+n*2,m=r.cloneNode(!0);m.querySelectorAll(`.max-width-guide, [data-score-image-ignore]`).forEach(e=>e.remove());let h=[r],g=[m],_=(e,t)=>{for(let n of e.children)oe(n)||(t.push(n),_(n,t))};if(_(r,h),_(m,g),g.length!==h.length)throw Error(`scoreImage: the cloned tree diverged from the live one`);for(let e of[m,...m.querySelectorAll(`*`)])e.removeAttribute(`title`);let{families:v,italics:y}=xe(h,g,{foreground:t.foreground,accent:t.accent,accentProbe:ye(r)});m.style.setProperty(`white-space`,`nowrap`);let b=Array.from(m.children).filter(e=>e.classList.contains(`guido`)||e.tagName===`P`);s.forEach((e,t)=>{let n=b[t];e.pinWidth!==void 0&&n&&n.style.setProperty(`width`,`${e.pinWidth}px`)}),m.style.setProperty(`padding-top`,`${n-l}px`),m.style.setProperty(`padding-left`,`${n-c}px`),m.style.setProperty(`padding-right`,`${n}px`),m.style.setProperty(`padding-bottom`,`${n}px`);let x=await _e(await he(v),y),ee=new XMLSerializer().serializeToString(m),S=t.background?`<rect width="100%" height="100%" fill="${fe(t.background)}"/>`:``;return{svg:`<svg xmlns="http://www.w3.org/2000/svg" width="${f}" height="${p}" viewBox="0 0 ${f} ${p}">`+S+(x?`<style>${x}</style>`:``)+`<foreignObject x="0" y="0" width="${f}" height="${p}">`+ee+`</foreignObject></svg>`,width:f,height:p}}async function we(e,t={}){return(await Ce(e,t)).svg}async function Te(e,t={}){let{svg:n,width:r,height:i}=await Ce(e,t),a=Math.max(1,t.scale??2),o=new Image;o.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`,await new Promise((e,t)=>{o.onload=()=>e(),o.onerror=()=>t(Error(`scoreImage: the exported SVG failed to rasterize`))});try{await o.decode()}catch{}let s=document.createElement(`canvas`);s.width=Math.ceil(r*a),s.height=Math.ceil(i*a);let c=s.getContext(`2d`);if(!c)throw Error(`scoreImage: this environment provides no 2D canvas`);c.scale(a,a),t.background&&(c.fillStyle=t.background,c.fillRect(0,0,r,i));let l=()=>c.drawImage(o,0,0,r,i);l(),/^((?!chrome|android|crios|fxios).)*safari/i.test(navigator.userAgent)&&(await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e))),l());let u=await new Promise(e=>s.toBlob(e,`image/png`));if(!u)throw Error(`scoreImage: PNG encoding failed`);return u}function Ee(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),setTimeout(()=>URL.revokeObjectURL(n),1e4)}async function De(e,t={}){let n=t.filename??`score.png`;return Ee(await Te(e,t),n),n}async function Oe(e,t={}){let n=t.filename??`score.svg`;return Ee(new Blob([await we(e,t)],{type:`image/svg+xml;charset=utf-8`}),n),n}return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>re(),{once:!0}):re(),e.dispose=Y,e.downloadScorePng=De,e.downloadScoreSvg=Oe,e.init=re,e.renderAll=Z,e.renderScore=X,e.scorePngBlob=Te,e.scoreSvg=we,e.version=O,e})({});
|
|
1
|
+
var GuidexEmbed=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){return e.trim().startsWith(`@`)}var n=class{source;constructor(e,t={}){this.source=(t.transforms??[]).reduce((e,t)=>t.apply(e),e)}get clef(){let e=this.normalized.match(/^\s*\(([^)]*)\)/);if(!(!e||t(e[1])))return e[1]}get tokens(){let e=this.normalized,n=e.match(/^\s*\(([^)]*)\)/),i=[...(n&&!t(n[1])?e.slice(n[0].length):e).matchAll(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g)].map(([,e,n])=>{if(t(n)){let t=n.trim();if(t!==`@break`)throw Error(`Unknown statement "${t}"`);if(e.trim()!==``)throw Error(`statement must not carry syllable text: "${r(e.trim())}"`);return{kind:`break`,spaceBefore:/^\s/.test(e)}}return{kind:`syllable`,text:r(e.trim()),notes:r(n),spaceBefore:/^\s/.test(e)}}),a=i.reduce((e,t,n)=>t.kind===`syllable`?n:e,-1);for(let[e,t]of i.entries())if(t.kind===`syllable`){t.wordEnd=e===a;for(let n=e+1;!t.wordEnd&&n<i.length;n++){let e=i[n];if(e.spaceBefore&&(t.wordEnd=!0),e.kind===`syllable`)break}}return i}get syllables(){return this.tokens.filter(e=>e.kind===`syllable`).map(({text:e,notes:t,wordEnd:n})=>({text:e,notes:t,wordEnd:n}))}get normalized(){let e=this.source;return(e.match(/(^|[^\\])\(/g)??[]).length>(e.match(/(^|[^\\])\)/g)??[]).length&&(e+=`)`),/(^|[^\\])\)$/.test(e)||(e+=`()`),e}get words(){let e=[],t;for(let n of this.syllables)t??={text:``,syllables:[]},t.syllables.push({text:n.text,notes:n.notes}),t.text=t.syllables.map(e=>e.text).join(``),n.wordEnd&&(e.push(t),t=void 0);return e}toString(){let e=this.tokens.map((e,t)=>{let n=t>0&&e.spaceBefore?` `:``;return e.kind===`break`?`${n}(@break)`:`${n}${i(e.text)}(${i(e.notes)})`});return`${this.clef===void 0?``:`(${this.clef})`}${e.join(``)}`}};function r(e){return e.replace(/\\(.)/g,`$1`)}function i(e){return e.replace(/\\/g,`\\\\`).replace(/[()]/g,e=>`\\${e}`)}function a(e){let t=[...e];for(let e=0;e<t.length;e++){let n=t[e];if(!/\s/.test(n))return{unit:n===`\\`&&t[e+1]!==void 0?n+t[e+1]:n,index:e}}return null}function o(e){let n=e.match(/^\s*\(([^)]*)\)/),i=n?n[0].length:0,o=e.slice(i);for(let n of o.matchAll(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g)){let[,o,s]=n;if(r(s).trim().length===0||t(s))continue;let c=a(o);if(!c||o.trimStart().startsWith(`*`))return e;let l=i+n.index+c.index,u=l+c.unit.length;return`${e.slice(0,l)}*${e.slice(l,u)}*${e.slice(u)}`}return e}var s={startWithInitial:{name:`startWithInitial`,apply:o}},c=[`ðñ0123456789öüó`,`^]qwertzuiopõú`,`ÝÞQWERTZUIOPÕÚ`,`×sdfghjkléáû`,`ØÙDFGHJKLÉÁÛ`,`÷øaASÍYXCVBN$m`,`ÈÊËÌÎÏÐÑÒþßòôùý`,`“”•–—˜™š›œº»`,`®−§ÿ"+!%/=()ÖÜÓ`,`Ÿ¡¢£[¥¦©ª«¬`,`~¯‚ƒ„…†‡ˆ‰Š‹Œ‘’`,`àâãäåæçèêëìîï`,`½°±²³´μ·¾¸¹`];function l(e,t,n){for(let r of c){let i=r.indexOf(e);if(i===-1)continue;let a=i+t;return a<0||a>=r.length?n===`null`?`\0`:r[Math.max(0,Math.min(r.length-1,a))]:r[a]}}function u(e,t,n){let r=``;for(let i=0;i<e.length;i++){let a=e[i],o=a===`\\`&&e[i+1]!==void 0,s=l(o?e[i+1]:a,t,n);if(s===void 0){r+=o?a+e[i+1]:a,o&&i++;continue}r+=`\\()`.includes(s)?`\\${s}`:s,o&&i++}return r}function d(e,n={}){let r=n.overflow??`clamp`;return{name:`transpose`,apply:n=>{if(e===0)return n;let i=n.match(/^\s*\(([^)]*)\)/),a=i?i[0].length:0;return n.slice(0,a)+n.slice(a).replace(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g,(n,i,a)=>t(a)?`${i}(${a})`:`${i}(${u(a,e,r)})`)}}}var f=new Set([`*`,`†`]),p={chars:f,fontFamily:`'Times New Roman', Times, serif`},m={weight:`400`,scale:.7,raise:.2},h={BNS:{textFontStack:`'Book Antiqua', Georgia, serif`,notesFontStack:`'Guidohu'`,markerGlyphs:p,verifiedFonts:[{family:`'Book Antiqua'`,weight:`400`},{family:`'Book Antiqua'`,weight:`700`},{family:`'Guidohu'`,weight:`400`},{family:`'Liturgy'`,weight:`700`}],decorations:{__:{fontFamily:`'Liturgy', serif`,weight:`700`,color:`var(--red)`},_:{uppercase:!0,scale:.7,color:`var(--red)`},"*":{weight:`700`,color:`var(--red)`,initial:!0}},specialStarStyle:{fontFamily:p.fontFamily,weight:`700`,scale:1,measureScale:.95,raise:.1,color:`var(--red)`},padding:12,scriptTransforms:[s.startWithInitial]},Vesperale:{textFontStack:`'Times New Roman', Times, serif`,notesFontStack:`'Guidohu'`,verifiedFonts:[{family:`'Times New Roman', Times, serif`,weight:`400`},{family:`'Times New Roman', Times, serif`,weight:`700`},{family:`'Guidohu'`,weight:`400`},{family:`'Liturgy'`,weight:`700`}],decorations:{__:{fontFamily:`'Liturgy', serif`,weight:`700`},_:{scale:.8,italic:!0},"*":{weight:`700`,initial:!0}},specialStarStyle:{fontFamily:p.fontFamily,weight:`700`,scale:1,measureScale:.95,raise:.2},padding:12,scriptTransforms:[]}};function g(e,t,n,r={}){if(e.length===0)return[];if(e===`**`)return[{text:`∗`,style:{...t.specialStarStyle},kind:`star`}];let i=e,a={},o;for(let n of[`__`,`_`]){let r=t.decorations[n];if(r&&e.length>=n.length*2+1&&e.startsWith(n)&&e.endsWith(n)){i=e.slice(n.length,-n.length),a={...r},o=n===`__`?`liturgy`:`rubric`;break}}let s=t.decorations[`*`],c=[],l=i,u=``;for(let e=/\*([^*]+)\*/.exec(l);e;e=/\*([^*]+)\*/.exec(l))u+=l.slice(0,e.index),u&&=(c.push({text:u,marked:!1}),``),c.push({text:e[1],marked:!0}),l=l.slice(e.index+e[0].length);u+=l,u&&c.push({text:u,marked:!1});let d=c.map(({text:e,marked:t})=>({text:e,style:t?{...a,...s,initial:!0}:{...a},kind:o})),p=t.markerGlyphs,h=[];for(let e of d){e.style.uppercase&&!r.rawCase&&(e.text=e.text.toUpperCase()),n&&(e.style={...e.style,weight:`700`});let t=[...e.text],i=e.style.fontFamily?.includes(`Liturgy`)??!1,a=e=>f.has(e)||p&&p.chars.has(e)?`marker`:i&&e===`+`?`plus`:`text`;if(t.every(e=>a(e)===`text`)){h.push({text:e.text,style:{...e.style},kind:e.kind});continue}let o=``,s=null,c=()=>{if(!o)return;let t={...e.style},n=e.kind;s===`marker`?(n=`marker`,p&&p.chars.has(o[0])&&(t={...t,fontFamily:p.fontFamily})):s===`plus`&&(t={...t,...m},n=`plus`),h.push({text:o,style:t,kind:n}),o=``};for(let e of t){let t=a(e);t!==s&&c(),s=t,o+=e}c()}return h}function _(e,t,n){return[e.italic?`italic`:`normal`,`normal`,e.weight??`400`,`${t*(e.measureScale??e.scale??1)}px`,e.fontFamily??n].join(` `)}function v(e,t){let n={};return e.fontFamily&&(n[`font-family`]=e.fontFamily),e.weight&&(n[`font-weight`]=e.weight),e.italic&&(n[`font-style`]=`italic`),e.scale!==void 0&&(n[`font-size`]=`${t*e.scale}px`),e.color&&(n.color=e.color),e.raise&&(n.position=`relative`,n.top=`${-t*e.raise}px`),n}function y(e,t){return e.verifiedFonts.map(e=>`${e.weight} ${t}px ${e.family}`)}var b=new Set(`,.:?'"+!%/=()ÖÜÓ;`.split(``)),x=new Set(`Ÿ¡¢£[¥¦©ª«¬`.split(``)),ee=new Set(`÷øaASÍYXCVBN$mÈÊËÌÎÏÐÑÒþßòôùý“”•–—˜™š›œº»`.split(``)),S=[`-`,`¨`];function C(e){let t=0;for(;t<e.length&&b.has(e[t]);)t++;t>0&&t<e.length&&e[t]===`-`&&t++;let n=e.length;for(;n>t&&b.has(e[n-1]);)n--;return n<e.length&&n>t&&e[n-1]===`-`&&n--,{leading:e.slice(0,t),core:e.slice(t,n),trailing:e.slice(n)}}var w=null;function T(e,t){return w||=document.createElement(`canvas`).getContext(`2d`),w.font=t,w.measureText(e).width}function te(e,t){w||=document.createElement(`canvas`).getContext(`2d`),w.font=t;let n=w.measureText(e);return{left:n.actualBoundingBoxLeft,right:n.actualBoundingBoxRight}}async function E(e,t={}){let{style:r=`BNS`,bold:i=!1,textPx:a=18,notesPx:o=a*2,maxWidthPx:s=1/0}=t,c=typeof e==`string`?new n(e):e,l=h[r];if(!l)throw Error(`Unknown style set: "${r}"`);for(let e of y(l,a)){try{await document.fonts.load(e)}catch{}if(!document.fonts.check(e))throw Error(`Font could not be loaded: ${e} (style "${r}")`)}let u=`400 ${o}px ${l.notesFontStack}`,d=l.textFontStack,f=_({weight:i?`700`:`400`},a,d),p=e=>g(e,l,i),m=e=>e.reduce((e,t)=>e+T(t.text,_(t.style,a,d)),0),v=T(`-`,u),w=T(`-`,f),E=c.clef===void 0?``:`${c.clef}-`,D=[],O,k,A,j,M=!1,N=[],P=()=>{O&&(O.textCursor=A,O.notesEnd=O.notesParts.length?T(E+O.notesParts.join(``),u):0),O={notesParts:[],segments:[],textCursor:0,notesEnd:0,lastWordEnd:null},D.push(O),k=E,A=0,j=!1,M=!1};P();let F=c.tokens,I=F.filter(e=>e.kind===`syllable`),L=[],R=0;for(let e of F)e.kind===`break`?L.push({kind:`break`}):L.push({kind:`syl`,syl:e,i:R++,text:e.text,notes:e.notes,first:!0,lastSeg:!0});let z=(e,t,n)=>{for(let r=e.length-1;r>0;r--){if(!S.includes(e[r]))continue;let i=r+1;for(;i<e.length&&b.has(e[i]);)i++;if(!(i>=e.length)&&n(e.slice(0,i))<=t)return r}return-1},B=(e,t)=>{let n=e.notes,r=t+1;for(;r<n.length&&b.has(n[r]);)r++;return e.notes=n.slice(0,t)+n.slice(t+1,r),n.slice(r)},V=(e,t,n)=>{e.lastSeg=!1,L.splice(t+1,0,{kind:`syl`,syl:e.syl,i:e.i,text:``,notes:n,first:!1,lastSeg:!0}),H=!0},ne=e=>{for(;N.length>0;){let t=N[0];if(A>0&&A+t.textWidth+(t.wordEnd?0:w)>s){P();continue}N.shift(),O.segments.push({kind:`syl`,parts:t.sylParts,textStart:A,textWidth:t.textWidth,contentWidth:0,contentStart:0,extraDashes:0,tight:!1,noNotes:!0,...e&&N.length===0?{trailing:!0}:{}}),A+=t.textWidth,t.spaceWidth>0&&(O.segments.push({kind:`word-space`,width:t.spaceWidth}),A+=t.spaceWidth),O.lastWordEnd=t.wordEnd,O.textCursor=A}},H=!1,U,W=0;for(;W<L.length;){let e=L[W];if(e.kind===`break`){(O.segments.length>0||N.length>0)&&(ne(!1),H=!0),W++;continue}let t=e.syl,n=e.i;H&&=(P(),!1);let r=e.lastSeg&&n===I.length-1,i=e.text,a=p(i),o=m(a),c=!r&&t.wordEnd?T(` `,f):0,l=N.reduce((e,t)=>e+t.textWidth+t.spaceWidth,0),d=t.notes.length===1&&x.has(t.notes),h=A===0||A+l+o+(t.wordEnd?0:w)<=s;if(t.notes.length===0){N.push({sylParts:a,textWidth:o,spaceWidth:c,wordEnd:t.wordEnd}),W++;continue}if(e.first&&e.lastSeg&&t.text.trim()===``&&C(t.notes).core===``){let e=k[k.length-1],n=e&&e!==`-`&&!b.has(e)&&!t.notes.startsWith(`-`)?`-`:``;O.notesParts.push(n+t.notes),k+=n+t.notes,j=!0,M=!1,U=t.wordEnd,W++;continue}let g=I[n-1]?.notes!==t.notes;if(d&&!g&&O.notesParts.length>0&&!h&&P(),!e.first){for(;!(T(k+e.notes,u)<=s);){let t=z(e.notes,s,e=>T(k+e,u));if(t<0||t+1>=e.notes.length)break;let n=B(e,t);V(e,W,n)}let n=C(e.notes);O.notesParts.push(e.notes),k+=e.notes,e.lastSeg&&(j=n.trailing.length>0),O.lastWordEnd=!0,U=t.wordEnd,e.lastSeg||(H=!0),W++;continue}let _=C(e.notes),y=O.notesParts.length===0||M?``:j||ee.has(_.core[0])?`--`:`---`,S=(e=0)=>{let t=0;for(;t<_.core.length&&ee.has(_.core[t]);)t++;t===_.core.length&&(t=0);let n=_.core.slice(t),r=T(n,u),i=T(k+y+`-`.repeat(e)+_.leading+_.core.slice(0,t),u),a=te(n,u),s=-a.left,c=(a.right-a.left)/2;return{contentWidth:r,contentStart:i,textStart:r>=o||d?i+s:i+c-o/2}},{contentWidth:E,contentStart:D,textStart:F}=S();for(;;){let n=T(k+y+e.notes,u)>s,r=F+o+(t.wordEnd?0:w)>s;if(!n&&!r)break;if(n){let t=z(e.notes,s,e=>T(k+y+e,u));if(t>=0&&t+1<e.notes.length){let n=B(e,t);V(e,W,n),_=C(e.notes),{contentWidth:E,contentStart:D,textStart:F}=S();break}}if(O.notesParts.length===0&&A===0){if(n){let t=z(e.notes,s,e=>T(k+e,u));if(t>=0&&t+1<e.notes.length){let n=B(e,t);e.notes=e.notes.slice(0,t),V(e,W,n),_=C(e.notes),{contentWidth:E,contentStart:D,textStart:F}=S()}}break}P(),y=``,{contentWidth:E,contentStart:D,textStart:F}=S()}let R=O.notesParts.length>0&&!U&&l===0,G=A+w,K=A+l+(M&&R?w:0),q=y+e.notes,J=0,Y=!1,X=t=>{J=t,q=y+`-`.repeat(t)+e.notes,{contentWidth:E,contentStart:D,textStart:F}=S(t)},Z=d&&!g&&O.notesParts.length>0;if(Z){y=``,F=A+l;let t=F+o+c-T(k,u),n=s-T(k+y,u),r=t>0?Math.min(Math.ceil(t/v),Math.max(0,Math.floor(n/v))):0;e.notes=`-`.repeat(r),_=C(e.notes),q=y+e.notes,Y=R}if(!Z){if(!M&&R&&F<G&&(o>E||F<A)){Y=!0,F=A;let t=E>=o?F:F+(o-E)/2;t>D&&(J=Math.round((t-D)/v),q=y+`-`.repeat(J)+e.notes)}else if(F<K){let t=E>=o?K:K+(o-E)/2;if(t>D){let n=Math.max(0,Math.floor((t-D)/v));for(X(n);F<K;)n++,X(n);if(O.notesParts.length>0&&T(k+q,u)>s&&(P(),y=``,q=y+e.notes,J=0,{contentWidth:E,contentStart:D,textStart:F}=S(),F<A+l)){let e=E>=o?A+l:A+l+(o-E)/2;if(e>D){let t=Math.max(0,Math.floor((e-D)/v));for(X(t);F<A+l;)t++,X(t)}}}}}l>0&&F<A+l&&(F=A+l);let Q=Math.max(0,F-l-A);if(O.notesParts.length===0)O.segments.push({kind:`gap`,role:`lead-in`,width:Q,endPx:F-l,textStartPx:F});else if(U)O.segments.push({kind:`gap`,role:`word-gap`,width:Q,endPx:F-l,textStartPx:F});else if(!(l===0&&Y)&&l===0){let e=Math.max(0,(Q-w)/2);O.segments.push({kind:`connector`,pad:e,gapWidth:Q,dashWidth:w,dashStartPx:A+e,nextAnchorPx:F})}let $=F-l;for(let e of N)O.segments.push({kind:`syl`,parts:e.sylParts,textStart:$,textWidth:e.textWidth,contentWidth:0,contentStart:0,extraDashes:0,tight:!1,noNotes:!0}),$+=e.textWidth,e.spaceWidth>0&&(O.segments.push({kind:`word-space`,width:e.spaceWidth}),$+=e.spaceWidth);N=[],O.segments.push({kind:`syl`,parts:a,textStart:F,textWidth:o,contentWidth:E,contentStart:D,extraDashes:J,tight:Y,noNotes:!1}),c>0&&O.segments.push({kind:`word-space`,width:c}),A=F+o+c,k+=q,O.notesParts.push(q),O.lastWordEnd=t.wordEnd,U=t.wordEnd,e.lastSeg&&(j=_.trailing.length>0,M=d),e.lastSeg||(H=!0),W++}ne(!0),O.textCursor=A,O.notesEnd=O.notesParts.length?T(E+O.notesParts.join(``),u):0,D.forEach((e,t)=>{if(t===D.length-1||e.lastWordEnd!==!1)return;let n=e.notesEnd>e.textCursor?Math.max(0,(e.notesEnd-e.textCursor-w)/2):0;e.segments.push({kind:`line-end-dash`,pad:n,dashWidth:w,dashStartPx:e.textCursor+n,trailEndPx:e.notesEnd,textEndPx:e.textCursor})});let G=s+(l.padding??0),K=T(`*`,u);return D.forEach((e,t)=>{if(t===D.length-1)return;if(s===1/0){e.breakMarkerLeftPx=l.padding??0;return}let n=T(E+e.notesParts.join(``),u);for(;n+v<=G-K&&n+v<s;)e.notesParts.push(`-`),n+=v;e.breakMarkerLeftPx=G-n-K}),{lines:D,clefPrefix:E,styleSet:l,styleName:r,textPx:a,notesPx:o,bold:i,maxWidthPx:s,starTarget:G,starWidth:K}}var D=class e{script;constructor(e){this.script=typeof e==`string`?new n(e):e}async render(t,n={}){let{debug:r=!1}=n,{lines:i,clefPrefix:a,styleSet:o,styleName:s,textPx:c,notesPx:l,bold:u,starTarget:d,starWidth:f}=await E(this.script,n);t.style.fontSize=`${c}px`,t.style.fontFamily=o.textFontStack,t.dataset.style=s,t.replaceChildren(...i.flatMap(t=>[e.notesLine(t,a,l,d,f,r),e.textLine(t,c,u,r)]))}static notesLine(e,t,n,r,i,a){let o=document.createElement(`div`);if(o.className=`guido`,o.style.fontSize=`${n}px`,o.textContent=t+e.notesParts.join(``),e.breakMarkerLeftPx!==void 0){let t=document.createElement(`span`);t.className=`guido-break`,t.textContent=`*`,t.style.position=`relative`,t.style.left=`${e.breakMarkerLeftPx}px`,a&&(t.title=`line break at ${r.toFixed(1)}px (staff filled to ${(r-e.breakMarkerLeftPx-i).toFixed(1)}px)`),o.appendChild(t)}return o}static textLine(t,n,r,i){let a=document.createElement(`p`);r&&(a.style.fontWeight=`700`);for(let r of t.segments)switch(r.kind){case`gap`:{let t=e.spacer(r.width);i&&(t.title=`${r.role===`lead-in`?`lead-in`:`word gap`} ${r.width.toFixed(1)}px → text ${r.textStartPx.toFixed(1)}`),a.appendChild(t);break}case`connector`:{let t=e.spacer(r.pad),n=document.createElement(`span`);n.className=`dash`,n.textContent=`-`;let o=e.spacer(r.pad);i&&(t.title=`lead pad ${r.pad.toFixed(1)}px (gap ${r.gapWidth.toFixed(1)} − dash ${r.dashWidth.toFixed(1)}, halved)`,n.title=`dash ${r.dashWidth.toFixed(1)}px`,o.title=`trail pad ${r.pad.toFixed(1)}px`),a.append(t,n,o);break}case`syl`:{let t=e.sylSpan(r.parts,n);if(i){if(r.noNotes)t.title=`no notes, text w ${r.textWidth.toFixed(1)}, ${r.trailing?`end of score`:`before the next syllable with notes`}`;else{let e=(r.textWidth-r.contentWidth)/2,n=r.textStart-r.contentStart;t.title=[`text w ${r.textWidth.toFixed(1)}`,`notes w ${r.contentWidth.toFixed(1)}`,r.extraDashes?`+${r.extraDashes} pad dash(es)`:null,`text start ${r.textStart.toFixed(1)}`,`notes start ${r.contentStart.toFixed(1)}`,`theoDiff: ${e.toFixed(1)}`,`cursDiff: ${n.toFixed(1)}`].filter(Boolean).join(`, `)}}a.appendChild(t);break}case`word-space`:{let e=document.createElement(`span`);e.className=`word-space`,e.textContent=` `,i&&(e.title=`word space ${r.width.toFixed(1)}px`),a.appendChild(e);break}case`line-end-dash`:{let t=e.spacer(r.pad),n=document.createElement(`span`);n.className=`dash`,n.textContent=`-`;let o=e.spacer(r.pad);i&&(t.title=`lead pad ${r.pad.toFixed(1)}px → line-end dash (text end ${r.textEndPx.toFixed(1)}, notes end ${r.trailEndPx.toFixed(1)})`,n.title=`dash ${r.dashWidth.toFixed(1)}px (line end)`,o.title=`trail pad ${r.pad.toFixed(1)}px`),a.append(t,n,o);break}}return a}static sylSpan(e,t){let n=document.createElement(`span`);return n.className=`syl`,e.forEach(e=>{let r=document.createElement(`span`);r.textContent=e.text;for(let[n,i]of Object.entries(v(e.style,t)))r.style.setProperty(n,i);let i=[...e.kind?[e.kind]:[],...e.style.initial?[`initial`]:[]].join(` `);i&&(r.className=i),n.appendChild(r)}),n}static spacer(e){let t=document.createElement(`span`);return t.className=`spacer`,t.style.display=`inline-block`,t.style.width=`${e}px`,t}},O={name:`guidex`,version:`0.3.1`,description:`Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime`,type:`module`,workspaces:[`examples/*`],main:`./dist/lib/embed/manual.js`,types:`./dist/lib/embed/manual.d.ts`,exports:{".":{types:`./dist/lib/embed/manual.d.ts`,default:`./dist/lib/embed/manual.js`},"./embed":{types:`./dist/lib/embed/index.d.ts`,default:`./dist/lib/embed/index.js`},"./guidex.css":{types:`./dist/lib/guidex.css.d.ts`,default:`./dist/lib/guidex.css`},"./fonts/*":`./dist/lib/fonts/*`,"./react":{types:`./dist/lib/react/index.d.ts`,default:`./dist/lib/react/index.js`},"./word":{types:`./dist/lib/word/index.d.ts`,default:`./dist/lib/word/index.js`}},files:[`dist-embed`,`dist/lib`],peerDependencies:{react:`>=18`},peerDependenciesMeta:{react:{optional:!0}},publishConfig:{access:`public`},scripts:{dev:`vite --host`,build:`tsc && vite build`,"build:embed":`vite build --config vite.embed.config.ts`,"build:lib":`vite build --config vite.lib.config.ts`,preview:`vite preview`,test:`vitest run`,lint:`eslint .`},keywords:[`plainchant`,`gregorian`,`guido`,`score`,`notation`,`liturgy`],repository:{type:`git`,url:`git+https://github.com/BrownieMaar/guidex.git`},bugs:{url:`https://github.com/BrownieMaar/guidex/issues`},homepage:`https://github.com/BrownieMaar/guidex#readme`,devDependencies:{"@eslint/js":`^10.0.1`,"@testing-library/dom":`^10.4.2`,"@testing-library/react":`^16.3.3`,"@testing-library/user-event":`^14.6.7`,"@types/react":`^19.3.0`,"@types/react-dom":`^19.3.0`,"@vitejs/plugin-react":`^6.1.1`,eslint:`^10.10.0`,jsdom:`^29.1.1`,react:`^19.3.0`,"react-dom":`^19.3.0`,typescript:`~6.0.2`,"typescript-eslint":`^8.70.0`,vite:`^8.2.2`,"vite-plugin-dts":`^5.1.1`,vitest:`^4.1.11`}}.version,k=`.guidex-script, .guido-script`,A={maxWidth:`auto`,style:`BNS`,bold:!1,textPx:18,transpose:0,debug:!1},j={},M=new WeakMap,N=new WeakMap,P=new WeakMap;function F(e){if(e!==void 0){if(e===``||e===`true`)return!0;if(e===`false`)return!1}}function I(e){if(e===void 0)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function L(e,t){if(/^auto$/i.test(e.trim()))return`auto`;let n=Number(e);return Number.isFinite(n)&&n>0?n:(console.warn(`[guidex] ignoring invalid data-max-width "${e}"`),t)}var R=new WeakMap;function z(e){let t=e.dataset,n=R.get(e)??{};return{maxWidth:t.maxWidth===void 0?n.maxWidth??j.maxWidth??A.maxWidth:L(t.maxWidth,n.maxWidth??j.maxWidth??A.maxWidth),style:t.style??n.style??j.style??A.style,bold:F(t.bold)??n.bold??j.bold??A.bold,textPx:I(t.textPx)??n.textPx??j.textPx??A.textPx,transpose:I(t.transpose)??n.transpose??j.transpose??A.transpose,debug:F(t.debug)??n.debug??j.debug??A.debug}}function B(e){return e.querySelector(`:scope > .guidex-render`)?.clientWidth||e.clientWidth||e.parentElement?.clientWidth||0}function V(e,t,n){if(typeof t==`number`)return t;let r=B(e);if(r<=0)return 1/0;let i=r-(h[n]?.padding??0);return i>0?i:r}function ne(e){for(let t of e.childNodes)if(t.nodeType===Node.TEXT_NODE&&t.nodeValue?.trim())return t.nodeValue.trim();return M.get(e)??``}function H(e){let t=e.querySelector(`:scope > .guidex-render`);if(t)return t;let n=document.createElement(`div`);return n.className=`guidex-render`,e.replaceChildren(n),n}function U(e,t){let n=document.createElement(`p`);n.className=`guidex-error`,n.textContent=t,e.replaceChildren(n)}function W(e,t){let n=[...h[e]?.scriptTransforms??[]];return t!==0&&n.push(d(t)),n}async function G(e){let t=(N.get(e)??0)+1;N.set(e,t);let r=z(e),i=ne(e);M.set(e,i);let a=H(e),o=V(e,r.maxWidth,r.style);P.set(e,o);let s=document.createElement(`div`),c=new n(i,{transforms:W(r.style,r.transpose)});try{if(await new D(c).render(s,{style:r.style,bold:r.bold,textPx:r.textPx,debug:r.debug,maxWidthPx:o}),N.get(e)!==t)return;a.replaceChildren(...s.childNodes),a.style.cssText=s.style.cssText,s.dataset.style&&(a.dataset.style=s.dataset.style)}catch(n){if(N.get(e)!==t)return;console.error(`[guidex]`,n),U(a,n instanceof Error?n.message:String(n))}}var K=new WeakMap;function q(e){let t=z(e),n=V(e,t.maxWidth,t.style);return Math.abs(n-(P.get(e)??NaN))>1}function J(e){if(K.has(e))return;let t;if(typeof ResizeObserver<`u`){let n=new ResizeObserver(()=>{q(e)&&G(e)});n.observe(e),t=()=>n.disconnect()}else{let n=()=>{q(e)&&G(e)};window.addEventListener(`resize`,n),t=()=>window.removeEventListener(`resize`,n)}K.set(e,t)}function Y(e){K.get(e)?.(),K.delete(e),M.delete(e),R.delete(e),N.delete(e),P.delete(e)}async function X(e,t,r={}){R.set(e,r);let i=(N.get(e)??0)+1;N.set(e,i),M.set(e,t);let a=z(e),o=H(e),s=V(e,a.maxWidth,a.style);P.set(e,s),J(e);let c=document.createElement(`div`),l=new n(t,{transforms:W(a.style,a.transpose)});try{if(await new D(l).render(c,{style:a.style,bold:a.bold,textPx:a.textPx,debug:a.debug,maxWidthPx:s}),N.get(e)!==i)return;o.replaceChildren(...c.childNodes),o.style.cssText=c.style.cssText,c.dataset.style&&(o.dataset.style=c.dataset.style)}catch(t){if(N.get(e)!==i)return;console.error(`[guidex]`,t),U(o,t instanceof Error?t.message:String(t))}}async function Z(e=document){let t=j.selector??k,n=[];return e instanceof Element&&e.matches(t)&&n.push(e),n.push(...e.querySelectorAll(t)),Promise.all(n.map(e=>(J(e),G(e)))).then(()=>void 0)}var Q=!1;function $(){if(Q||typeof MutationObserver>`u`)return;Q=!0;let e=j.selector??k;new MutationObserver(t=>{let n=new Set;for(let r of t)for(let t of r.addedNodes)if(t instanceof Element&&!t.closest(`.guidex-render`)){t.matches(e)&&n.add(t);for(let r of t.querySelectorAll(e))n.add(r)}for(let e of n)J(e),G(e)}).observe(document.documentElement,{childList:!0,subtree:!0})}function re(e={}){j={...j,...e},$(),Z()}var ie=[`font-family`,`font-size`,`font-style`,`font-weight`,`line-height`,`letter-spacing`,`text-transform`,`color`,`position`,`top`,`left`,`margin-top`,`margin-bottom`,`padding-top`,`padding-bottom`],ae=[`font-family`,`font-size`,`font-style`,`font-weight`,`line-height`,`letter-spacing`,`color`];function oe(e){return e.classList.contains(`max-width-guide`)||e.hasAttribute(`data-score-image-ignore`)}function se(e){let t=e.querySelector(`.guido`)?.parentElement;if(!t)throw Error(`No rendered score found to export — render a score into the element first.`);return t}function ce(e){let t=e.getBoundingClientRect(),n=[],r=document.createRange();return r.selectNodeContents(e),typeof r.getBoundingClientRect==`function`&&n.push(r.getBoundingClientRect()),e.querySelectorAll(`*`).forEach(e=>n.push(e.getBoundingClientRect())),n.length===0&&n.push(t),{left:Math.min(...n.map(e=>e.left))-t.left,top:Math.min(...n.map(e=>e.top))-t.top,right:Math.max(...n.map(e=>e.right))-t.left,bottom:Math.max(...n.map(e=>e.bottom))-t.top}}function le(e){let t=document.createRange();if(t.selectNodeContents(e),typeof t.getClientRects!=`function`)return 1;let n=Array.from(t.getClientRects()).filter(e=>e.width>0||e.height>0);if(n.length===0)return 1;n.sort((e,t)=>e.top-t.top);let r=0,i=-1/0;for(let e of n)e.top>=i?(r++,i=e.bottom):e.bottom>i&&(i=e.bottom);return r}function ue(e){let t=[],n=``,r=null;for(let i of e)r?i===r?r=null:n+=i:i===`"`||i===`'`?r=i:i===`,`?(t.push(n.trim()),n=``):n+=i;return t.push(n.trim()),t.filter(Boolean)}function de(e){return e===`normal`?`400`:e===`bold`?`700`:e}function fe(e){return e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`).replace(/>/g,`>`)}function pe(e,t,n,r,i){let a=/url\(\s*(['"]?)([^'")]+)\1\s*\)/.exec(r);if(!a)return;let o;try{o=new URL(a[2],i??location.href).toString()}catch{return}return{family:e,style:t||`normal`,weight:de(n||`400`),url:o,format:/format\(\s*['"]?([^'")]+?)['"]?\s*\)/.exec(r)?.[1]}}function me(e,t){let n=[];for(let r of e.matchAll(/@font-face\s*{([^}]*)}/g)){let e=r[1],i=t=>{let n=RegExp(`(?:^|[;\\s])${t}\\s*:\\s*([^;]+)`,`i`).exec(e);return n?n[1].trim():``},a=i(`font-family`),o=i(`src`);if(!a||!o)continue;let s=ue(a)[0];if(!s)continue;let c=pe(s,i(`font-style`),i(`font-weight`),o,t);c&&n.push(c)}return n}async function he(e){let t=[],n=new Set,r=e=>{let r=`${e.family}|${e.style}|${e.weight}`;n.has(r)||(n.add(r),t.push(e))},i=[];for(let t of document.styleSheets){let n;try{n=t.cssRules}catch{t.href&&i.push(t.href);continue}for(let i of Array.from(n)){let n=i.style;if(!n)continue;let a=n.getPropertyValue(`src`),o=n.getPropertyValue(`font-family`);if(!a||!o)continue;let s=ue(o)[0];if(!s||!e.has(s))continue;let c=pe(s,n.getPropertyValue(`font-style`),n.getPropertyValue(`font-weight`),a,t.href??void 0);c&&r(c)}}for(let t of i)try{let n=await fetch(t);if(!n.ok)throw Error(String(n.status));let i=await n.text();for(let n of me(i,t))e.has(n.family)&&r(n)}catch{console.warn(`[guidex] scoreImage: a cross-origin stylesheet (${t}) could not be read — fonts declared only there are missing from the export`)}return t}async function ge(e){let t=await fetch(e);if(!t.ok)return;let n=await t.blob();return new Promise(e=>{let t=new FileReader;t.onload=()=>e(typeof t.result==`string`?t.result:void 0),t.onerror=()=>e(void 0),t.readAsDataURL(n)})}async function _e(e,t){let n=[],r=new Set,i=new Map,a=e=>{let t=i.get(e);return t||(t=ge(e).catch(()=>void 0),i.set(e,t)),t},o=new Map;for(let t of e){let e=o.get(t.family)??[];e.push(t),o.set(t.family,e)}for(let[e,i]of o){let o=i.filter(e=>e.style===`normal`),s=o.length>0?[...o,...t?i.filter(e=>e.style!==`normal`):[]]:i;for(let t of s){let i=await a(t.url);if(!i){r.add(e);continue}let o=t.format?` format('${t.format}')`:``;n.push(`@font-face{font-family:'${t.family}';font-style:${t.style};font-weight:${t.weight};src:url(${i})${o}}`)}}for(let e of r)console.warn(`[guidex] scoreImage: could not embed the ${e} webfont — the export falls back to the next family in its stack`);return n.join(``)}function ve(e){let t=document.createElement(`span`);return t.style.color=e,getComputedStyle(t).color}function ye(e){let t=getComputedStyle(e).getPropertyValue(`--red`).trim();return t?ve(t):``}function be(e,t,n){return n&&t&&ve(t)===n?!0:e.style?.getPropertyValue(`color`).replace(/\s+/g,``)===`var(--red)`}function xe(e,t,n){let r=new Set,i=!1;for(let a=0;a<e.length;a++){let o=e[a],s=t[a],c=getComputedStyle(o);for(let e of a===0?ae:ie){if(e===`color`){let e=c.getPropertyValue(`color`);if(!e)continue;let t=be(o,e,n.accentProbe)?n.accent:n.foreground;s.style.setProperty(`color`,t||e);continue}let t=c.getPropertyValue(e);t&&s.style.setProperty(e,t)}let l=c.getPropertyValue(`font-family`);if(l)for(let e of ue(l))r.add(e);c.getPropertyValue(`font-style`)===`italic`&&(i=!0)}return{families:r,italics:i}}async function Se(){let e=document.fonts;e?.ready&&await e.ready}async function Ce(e,t){let n=Math.max(0,t.padding??0),r=se(e);if(!r.isConnected)throw Error(`scoreImage: the score left the document before the export — re-render it and try again`);await Se();let i=Array.from(r.children).filter(e=>e.classList.contains(`guido`)||e.tagName===`P`);if(i.length===0)throw Error(`No rendered score found to export — render a score into the element first.`);let a=i.map(e=>e.getBoundingClientRect()),o=a[0],s=i.map((e,t)=>{let n=ce(e),r=a[t],i=r.left-o.left,s=le(e)>1;return{left:n.left+i,top:n.top+(r.top-o.top),right:(s?Math.max(r.width,n.right):n.right)+i,bottom:n.bottom+(r.top-o.top),pinWidth:s?r.width:void 0}}),c=Math.min(0,...s.map(e=>e.left)),l=Math.min(0,...s.map(e=>e.top)),u=Math.max(...s.map(e=>e.right)),d=Math.max(...s.map(e=>e.bottom)),f=Math.max(1,Math.ceil(u-c))+n*2,p=Math.max(1,Math.ceil(d-l))+n*2,m=r.cloneNode(!0);m.querySelectorAll(`.max-width-guide, [data-score-image-ignore]`).forEach(e=>e.remove());let h=[r],g=[m],_=(e,t)=>{for(let n of e.children)oe(n)||(t.push(n),_(n,t))};if(_(r,h),_(m,g),g.length!==h.length)throw Error(`scoreImage: the cloned tree diverged from the live one`);for(let e of[m,...m.querySelectorAll(`*`)])e.removeAttribute(`title`);let{families:v,italics:y}=xe(h,g,{foreground:t.foreground,accent:t.accent,accentProbe:ye(r)});m.style.setProperty(`white-space`,`nowrap`);let b=Array.from(m.children).filter(e=>e.classList.contains(`guido`)||e.tagName===`P`);s.forEach((e,t)=>{let n=b[t];e.pinWidth!==void 0&&n&&n.style.setProperty(`width`,`${e.pinWidth}px`)}),m.style.setProperty(`padding-top`,`${n-l}px`),m.style.setProperty(`padding-left`,`${n-c}px`),m.style.setProperty(`padding-right`,`${n}px`),m.style.setProperty(`padding-bottom`,`${n}px`);let x=await _e(await he(v),y),ee=new XMLSerializer().serializeToString(m),S=t.background?`<rect width="100%" height="100%" fill="${fe(t.background)}"/>`:``;return{svg:`<svg xmlns="http://www.w3.org/2000/svg" width="${f}" height="${p}" viewBox="0 0 ${f} ${p}">`+S+(x?`<style>${x}</style>`:``)+`<foreignObject x="0" y="0" width="${f}" height="${p}">`+ee+`</foreignObject></svg>`,width:f,height:p}}async function we(e,t={}){return(await Ce(e,t)).svg}async function Te(e,t={}){let{svg:n,width:r,height:i}=await Ce(e,t),a=Math.max(1,t.scale??2),o=new Image;o.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`,await new Promise((e,t)=>{o.onload=()=>e(),o.onerror=()=>t(Error(`scoreImage: the exported SVG failed to rasterize`))});try{await o.decode()}catch{}let s=document.createElement(`canvas`);s.width=Math.ceil(r*a),s.height=Math.ceil(i*a);let c=s.getContext(`2d`);if(!c)throw Error(`scoreImage: this environment provides no 2D canvas`);c.scale(a,a),t.background&&(c.fillStyle=t.background,c.fillRect(0,0,r,i));let l=()=>c.drawImage(o,0,0,r,i);l(),/^((?!chrome|android|crios|fxios).)*safari/i.test(navigator.userAgent)&&(await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e))),l());let u=await new Promise(e=>s.toBlob(e,`image/png`));if(!u)throw Error(`scoreImage: PNG encoding failed`);return u}function Ee(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),setTimeout(()=>URL.revokeObjectURL(n),1e4)}async function De(e,t={}){let n=t.filename??`score.png`;return Ee(await Te(e,t),n),n}async function Oe(e,t={}){let n=t.filename??`score.svg`;return Ee(new Blob([await we(e,t)],{type:`image/svg+xml;charset=utf-8`}),n),n}return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>re(),{once:!0}):re(),e.dispose=Y,e.downloadScorePng=De,e.downloadScoreSvg=Oe,e.init=re,e.renderAll=Z,e.renderScore=X,e.scorePngBlob=Te,e.scoreSvg=we,e.version=O,e})({});
|