guidex 0.2.6 → 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 +235 -0
- package/dist/lib/app/ControlsRow.d.ts +1 -0
- package/dist/lib/app/Editor.d.ts +1 -0
- package/dist/lib/app/EditorContext.d.ts +17 -0
- package/dist/lib/app/EditorTextarea.d.ts +1 -0
- package/dist/lib/app/ExportSettings.d.ts +1 -0
- package/dist/lib/app/FeedbackSpan.d.ts +5 -0
- package/dist/lib/app/RenderSettings.d.ts +1 -0
- package/dist/lib/app/SamplesRow.d.ts +1 -0
- package/dist/lib/app/SettingsMenu.d.ts +1 -0
- package/dist/lib/app/SettingsPanel.d.ts +1 -0
- package/dist/lib/app/SyllablesTable.d.ts +1 -0
- package/dist/lib/app/WordCheckPanel.d.ts +1 -0
- package/dist/lib/app/WordCopyControls.d.ts +1 -0
- package/dist/lib/app/chantLibrary.d.ts +11 -0
- package/dist/lib/app/editorState.d.ts +159 -0
- package/dist/lib/app/samples.d.ts +10 -0
- package/dist/lib/app/wordCopy.d.ts +30 -0
- package/dist/lib/chantLayout-GAfg2iKS.js +1042 -0
- package/dist/lib/chantLayout.d.ts +169 -0
- package/dist/lib/chantMarkup.d.ts +36 -0
- package/dist/lib/editorStorage.d.ts +179 -0
- package/dist/lib/embed/index.d.ts +1 -0
- package/dist/lib/embed/index.js +2 -2
- package/dist/lib/embed/manual.d.ts +16 -4
- package/dist/lib/embed/manual.js +315 -2
- package/dist/lib/glyphFamilies.d.ts +46 -0
- package/dist/lib/guidoRender.d.ts +22 -29
- package/dist/lib/guidoScript.d.ts +28 -3
- package/dist/lib/guidoScriptTransforms.d.ts +5 -4
- package/dist/lib/guidoStyles.d.ts +23 -5
- package/dist/lib/main.d.ts +0 -1
- package/dist/lib/react/index.d.ts +1 -0
- package/dist/lib/react/index.js +2 -2
- package/dist/lib/scoreImage-oVBasBX5.js +951 -0
- package/dist/lib/scoreImage.d.ts +63 -0
- package/dist/lib/word/index.d.ts +17 -0
- package/dist/lib/word/index.js +2 -0
- package/dist/lib/wordChecker-C3nJrk_j.js +1042 -0
- package/dist/lib/wordChecker.d.ts +66 -0
- package/dist/lib/wordClipboard.d.ts +25 -0
- package/dist/lib/wordExport.d.ts +244 -0
- package/dist-embed/guidex-embed.min.js +1 -1
- package/package.json +8 -1
- package/dist/lib/core-hF6L1EtS.js +0 -1268
- package/dist/lib/settingsMenu.d.ts +0 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export interface WordCheckIssue {
|
|
2
|
+
severity: 'error' | 'warning';
|
|
3
|
+
paragraph?: number;
|
|
4
|
+
/** Character offset within the paragraph's visible text */
|
|
5
|
+
offset?: number;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
export interface WordParagraphDiag {
|
|
9
|
+
index: number;
|
|
10
|
+
kind: 'nota' | 'textus' | 'unknown';
|
|
11
|
+
styleName: string | null;
|
|
12
|
+
/** The paragraph's visible text (spacer runs and artifacts stripped) */
|
|
13
|
+
text: string;
|
|
14
|
+
}
|
|
15
|
+
export type WordGapClass = 'lead-in' | 'word-gap' | 'connector' | 'line-end';
|
|
16
|
+
export type WordGapMechanism = 'tab' | 'spacerun' | 'char';
|
|
17
|
+
export interface WordGapStat {
|
|
18
|
+
gapClass: WordGapClass;
|
|
19
|
+
mechanism: WordGapMechanism;
|
|
20
|
+
/** The spacer character (tabs report the tab itself) */
|
|
21
|
+
character: string;
|
|
22
|
+
/** Letter-spacing Word applied to this class's runs, pt. Runs
|
|
23
|
+
* aggregate per spacing — a tuned run next to untuned ones reports
|
|
24
|
+
* apart, so neither skews the other's width estimate. */
|
|
25
|
+
letterSpacingPt: number;
|
|
26
|
+
/** Spacer runs observed in this class */
|
|
27
|
+
runs: number;
|
|
28
|
+
/** Total spacer units across the runs */
|
|
29
|
+
units: number;
|
|
30
|
+
/** Estimated effective width per gap, pt — units × unit width, where
|
|
31
|
+
* the unit width comes from the pasted tab interval or a canvas
|
|
32
|
+
* measurement of the spacer character (in the TEXT font — the text
|
|
33
|
+
* lines are what carry spacers). An estimate: Word's real metrics
|
|
34
|
+
* come from its own rendering. */
|
|
35
|
+
effectiveWidthPt: number | null;
|
|
36
|
+
}
|
|
37
|
+
export interface WordCheckReport {
|
|
38
|
+
ok: boolean;
|
|
39
|
+
issues: WordCheckIssue[];
|
|
40
|
+
paragraphs: WordParagraphDiag[];
|
|
41
|
+
/** Style names declared in the <style> block and used on paragraphs */
|
|
42
|
+
styleNames: string[];
|
|
43
|
+
gapCensus: {
|
|
44
|
+
mechanism: WordGapMechanism | null;
|
|
45
|
+
/** Letter-spacing observed on spacer runs, pt */
|
|
46
|
+
letterSpacingPt: number | null;
|
|
47
|
+
/** The pasted tab interval, pt (tab mechanism only) */
|
|
48
|
+
unitPt: number | null;
|
|
49
|
+
gaps: WordGapStat[];
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The census measures gap characters in the TEXT font: the declared
|
|
54
|
+
* textus rule is picked explicitly, because the nota style is usually
|
|
55
|
+
* declared first and would hand back the larger chant-font metrics.
|
|
56
|
+
* Falls back to the first font-bearing rule that is not the notes style,
|
|
57
|
+
* and to a default serif when nothing identifiable remains.
|
|
58
|
+
*/
|
|
59
|
+
export declare function pickTextusFont(styleText: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Checks a pasted Word HTML document (the text/html clipboard flavour).
|
|
62
|
+
* Returns the positioned issues, the paragraph structure, the style names
|
|
63
|
+
* in use, and the gap census. `ok` is false when any error-level issue
|
|
64
|
+
* was found; warnings alone keep it true.
|
|
65
|
+
*/
|
|
66
|
+
export declare function checkWordHtml(html: string): WordCheckReport;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { GuidoScript } from './guidoScript';
|
|
2
|
+
import { WordExportOptions } from './wordExport';
|
|
3
|
+
export interface CopyResult {
|
|
4
|
+
/** The Word-flavoured HTML document (the text/html flavour) */
|
|
5
|
+
html: string;
|
|
6
|
+
/** The plain-text equivalent (the text/plain flavour) */
|
|
7
|
+
text: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Copies the score for pasting into Word: text/html (the Word export)
|
|
11
|
+
* with text/plain as the fallback flavour. Returns what was prepared.
|
|
12
|
+
* Throws when no clipboard path works.
|
|
13
|
+
*/
|
|
14
|
+
export declare function copyWordHtml(source: GuidoScript | string, options?: WordExportOptions): Promise<CopyResult>;
|
|
15
|
+
/**
|
|
16
|
+
* The deliberate plain-text-only copy: the same layout and spacer counts
|
|
17
|
+
* without the HTML envelope, for workflows that want the raw text.
|
|
18
|
+
*/
|
|
19
|
+
export declare function copyWordPlainText(source: GuidoScript | string, options?: WordExportOptions): Promise<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Copies raw text with no export flavour — the same write path as the
|
|
22
|
+
* Word copy's plain fallback, for copies of the script source itself.
|
|
23
|
+
* Returns the copied text; throws when no clipboard path works.
|
|
24
|
+
*/
|
|
25
|
+
export declare function copyPlainText(text: string): Promise<string>;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { GuidoScript } from './guidoScript';
|
|
2
|
+
import { ChantRunKind, StyleSetName } from './guidoStyles';
|
|
3
|
+
/** The spacer character faking every horizontal gap. A custom character
|
|
4
|
+
* (any non-empty string) is emitted verbatim. */
|
|
5
|
+
export type SpacerChar = 'tab' | 'en' | 'em' | 'nbsp' | 'space' | (string & {});
|
|
6
|
+
/** Independent width tuning for the spacer character. */
|
|
7
|
+
export type SpacerWidth =
|
|
8
|
+
/** Tab strategy: each tab advances one interval on Word's absolute
|
|
9
|
+
* grid (the target document's ruler setting is irrelevant). */
|
|
10
|
+
{
|
|
11
|
+
kind: 'tabInterval';
|
|
12
|
+
pt: number;
|
|
13
|
+
}
|
|
14
|
+
/** Scale against the character's natural advance (1 = untouched). */
|
|
15
|
+
| {
|
|
16
|
+
kind: 'scale';
|
|
17
|
+
factor: number;
|
|
18
|
+
}
|
|
19
|
+
/** Absolute width per unit. */
|
|
20
|
+
| {
|
|
21
|
+
kind: 'absolute';
|
|
22
|
+
pt: number;
|
|
23
|
+
}
|
|
24
|
+
/** Extra advance per character, Word's condensed/expanded spacing —
|
|
25
|
+
* emitted as letter-spacing on the spacer run, so the user can keep
|
|
26
|
+
* tuning inside Word after pasting. */
|
|
27
|
+
| {
|
|
28
|
+
kind: 'letterSpacing';
|
|
29
|
+
pt: number;
|
|
30
|
+
};
|
|
31
|
+
export interface SpacerConfig {
|
|
32
|
+
character: SpacerChar;
|
|
33
|
+
width?: SpacerWidth;
|
|
34
|
+
}
|
|
35
|
+
/** 0.5 mm, the issue's example of a fixed small tab unit. */
|
|
36
|
+
export declare const DEFAULT_TAB_INTERVAL_PT: number;
|
|
37
|
+
/** The default spacer: a no-break space at its natural advance. The
|
|
38
|
+
* natural advance is proportional to the inherited font size, so the gaps
|
|
39
|
+
* scale with Word's rendering of the destination styles, and no-break
|
|
40
|
+
* spaces are plain characters — nothing mso-* that a paste path could
|
|
41
|
+
* strip. Tabs (interval-tuned) and tuned space characters remain the
|
|
42
|
+
* explicit choices. */
|
|
43
|
+
export declare const DEFAULT_SPACER: SpacerConfig;
|
|
44
|
+
export interface WordStyleNames {
|
|
45
|
+
nota: string;
|
|
46
|
+
textus: string;
|
|
47
|
+
textusChar: string;
|
|
48
|
+
}
|
|
49
|
+
export interface WordExportOptions {
|
|
50
|
+
/** Named style set from STYLE_SETS (default: BNS) */
|
|
51
|
+
style?: StyleSetName;
|
|
52
|
+
/** Export all text bold, measurements included */
|
|
53
|
+
bold?: boolean;
|
|
54
|
+
/** Text line size in px (default 18; 13.5pt in Word) */
|
|
55
|
+
textPx?: number;
|
|
56
|
+
/** Notes line size in px (default textPx * 2) */
|
|
57
|
+
notesPx?: number;
|
|
58
|
+
/** Maximum notes-line width before a staff break, in px — the lines
|
|
59
|
+
* break exactly as the renderer breaks them. Default: Infinity (one
|
|
60
|
+
* unbroken line pair, no break markers). The caller always resolves a
|
|
61
|
+
* concrete width before exporting; `auto` never reaches the emitter. */
|
|
62
|
+
maxWidthPx?: number;
|
|
63
|
+
/** Text line size in pt at the DESTINATION document (default: none —
|
|
64
|
+
* textPx governs). Takes precedence over textPx; notes default to
|
|
65
|
+
* twice the text size (the established BNS ratio). Laying out at the
|
|
66
|
+
* destination's true sizes is what a real Word round-trip wants: Word
|
|
67
|
+
* renders the pasted styles at its own pt sizes regardless of the
|
|
68
|
+
* preview, so width tuning converges on the true grid and line breaks
|
|
69
|
+
* match the destination column. */
|
|
70
|
+
textPt?: number;
|
|
71
|
+
/** Notes line size in pt at the destination document (default:
|
|
72
|
+
* textPt × 2, or notesPx). Takes precedence over notesPx. */
|
|
73
|
+
notesPt?: number;
|
|
74
|
+
/** Maximum notes-line width before a staff break, in pt at the
|
|
75
|
+
* destination document (default: maxWidthPx). Takes precedence over
|
|
76
|
+
* maxWidthPx. */
|
|
77
|
+
maxWidthPt?: number;
|
|
78
|
+
/** The spacer mechanism faking every gap (default: a no-break space
|
|
79
|
+
* at its natural advance) */
|
|
80
|
+
spacer?: SpacerConfig;
|
|
81
|
+
/** The Word style names the export declares and targets; Word maps
|
|
82
|
+
* them by mso-style-name onto the document's own definitions when
|
|
83
|
+
* present. Defaults derived from the style set name. */
|
|
84
|
+
styleNames?: Partial<WordStyleNames>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The self-correcting spacer meter: converts ideal px anchors into
|
|
88
|
+
* `unit × count` spacer runs. `advance` targets absolute positions, so
|
|
89
|
+
* quantization error never accumulates — each anchor lands within ½ unit.
|
|
90
|
+
* Tabs use the absolute-grid variant: Word places k consecutive tabs at
|
|
91
|
+
* (floor(current ÷ interval) + k) × interval. The width kinds and the
|
|
92
|
+
* spacer characters are validated against each other: the tab interval is
|
|
93
|
+
* the tab's own grid unit, so a tab takes no other width kind and no
|
|
94
|
+
* other character takes the interval — its accounting would advance on a
|
|
95
|
+
* grid the emitted character never lands on.
|
|
96
|
+
*/
|
|
97
|
+
export declare class SpacerMeter {
|
|
98
|
+
readonly character: SpacerChar;
|
|
99
|
+
/** The spacer character's natural advance in the text font, px */
|
|
100
|
+
readonly naturalPx: number;
|
|
101
|
+
/** One unit's effective width in our measured px */
|
|
102
|
+
readonly unitPx: number;
|
|
103
|
+
/** Letter-spacing to emit on spacer runs, pt (0 = none) */
|
|
104
|
+
readonly letterSpacingPt: number;
|
|
105
|
+
private readonly grid;
|
|
106
|
+
constructor(config: SpacerConfig, spaceFont: string);
|
|
107
|
+
/** The spacer character as it appears in plain text. */
|
|
108
|
+
get char(): string;
|
|
109
|
+
/** Advances the emitted position to `targetPx`, returning the unit
|
|
110
|
+
* count to emit and the new (quantized) emitted position. */
|
|
111
|
+
advance(targetPx: number, emittedPx: number): {
|
|
112
|
+
count: number;
|
|
113
|
+
emittedPx: number;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Renders the score as Word-flavoured HTML: one `nota` paragraph (notes)
|
|
118
|
+
* followed by one `textus` paragraph (text) per rendered line, the
|
|
119
|
+
* declared styles mapping onto the target document's own definitions by
|
|
120
|
+
* mso-style-name. Broken lines end with a tab + the Guido `*` glyph,
|
|
121
|
+
* right-aligned to the paragraph style's tab stop (the style block's stop
|
|
122
|
+
* at finite width; an inline per-line stop at natural width, where no
|
|
123
|
+
* shared star target exists).
|
|
124
|
+
*/
|
|
125
|
+
export declare function toWordHtml(source: GuidoScript | string, options?: WordExportOptions): Promise<string>;
|
|
126
|
+
/** One styled syllable run of a structured Word text line, resolved to
|
|
127
|
+
* Word's terms: absent fields inherit the textus paragraph style. */
|
|
128
|
+
export interface WordRun {
|
|
129
|
+
/** The run's text as sung (the plain-text export's characters) */
|
|
130
|
+
text: string;
|
|
131
|
+
bold: boolean;
|
|
132
|
+
italic: boolean;
|
|
133
|
+
/** Font family override (one family, unquoted) */
|
|
134
|
+
fontFamily?: string;
|
|
135
|
+
/** Font size override, pt */
|
|
136
|
+
sizePt?: number;
|
|
137
|
+
/** Resolved color literal (CSS variables already resolved) */
|
|
138
|
+
color?: string;
|
|
139
|
+
/** Raise above the baseline, pt */
|
|
140
|
+
raisePt?: number;
|
|
141
|
+
/** Set when the text has no glyph in the destination fonts: emit
|
|
142
|
+
* `char` in `font` instead (Word's symbol-run shape), on the
|
|
143
|
+
* baseline — the `**` star rides the Symbol font's asterisk. */
|
|
144
|
+
symbol?: {
|
|
145
|
+
char: string;
|
|
146
|
+
font: string;
|
|
147
|
+
};
|
|
148
|
+
/** The notation-fixed run kind (see chantRuns) */
|
|
149
|
+
kind?: ChantRunKind;
|
|
150
|
+
/** The run is a `*…*` initial */
|
|
151
|
+
initial?: boolean;
|
|
152
|
+
}
|
|
153
|
+
/** One piece of a structured Word text line, in emission order. */
|
|
154
|
+
export type WordTextPiece =
|
|
155
|
+
/** `count` spacer units. `endPt` is the emitted position after the
|
|
156
|
+
* run, measured from the paragraph's left edge — for the tab
|
|
157
|
+
* strategy it lies on the interval grid, so it doubles as an
|
|
158
|
+
* absolute tab-stop position. */
|
|
159
|
+
{
|
|
160
|
+
type: 'spacer';
|
|
161
|
+
count: number;
|
|
162
|
+
endPt: number;
|
|
163
|
+
}
|
|
164
|
+
/** A styled syllable run */
|
|
165
|
+
| {
|
|
166
|
+
type: 'run';
|
|
167
|
+
run: WordRun;
|
|
168
|
+
}
|
|
169
|
+
/** The connector / line-end hyphen, plain text style */
|
|
170
|
+
| {
|
|
171
|
+
type: 'dash';
|
|
172
|
+
}
|
|
173
|
+
/** A word-end space, plain text style */
|
|
174
|
+
| {
|
|
175
|
+
type: 'space';
|
|
176
|
+
};
|
|
177
|
+
/** One line pair of the structured Word layout. */
|
|
178
|
+
export interface WordLine {
|
|
179
|
+
/** The notes paragraph text: clef + notes, verbatim Guido HU */
|
|
180
|
+
notes: string;
|
|
181
|
+
/** The line ends with a staff break: a tab + `*` follows the notes,
|
|
182
|
+
* right-aligned to `breakMarkerTabStopPt` */
|
|
183
|
+
breakMarker: boolean;
|
|
184
|
+
/** The right-aligned tab stop the break marker hangs on, pt — the
|
|
185
|
+
* shared style stop at finite width, a per-line stop at natural
|
|
186
|
+
* width; absent without a break marker */
|
|
187
|
+
breakMarkerTabStopPt?: number;
|
|
188
|
+
/** The text paragraph, gaps faked by spacer counts */
|
|
189
|
+
text: WordTextPiece[];
|
|
190
|
+
}
|
|
191
|
+
/** The structured Word layout: everything toWordHtml emits, as data, for
|
|
192
|
+
* consumers building Word documents directly (e.g. the `docx` library). */
|
|
193
|
+
export interface WordLayout {
|
|
194
|
+
lines: WordLine[];
|
|
195
|
+
style: StyleSetName;
|
|
196
|
+
styleNames: WordStyleNames;
|
|
197
|
+
bold: boolean;
|
|
198
|
+
textPt: number;
|
|
199
|
+
notesPt: number;
|
|
200
|
+
/** Exact line heights of the nota / textus paragraphs, pt */
|
|
201
|
+
notesLineHeightPt: number;
|
|
202
|
+
textLineHeightPt: number;
|
|
203
|
+
/** The text paragraph's font family (one family, unquoted) */
|
|
204
|
+
textFontFamily: string;
|
|
205
|
+
/** The notes paragraph's font family, Word's real name ("Guido HU") */
|
|
206
|
+
notesFontFamily: string;
|
|
207
|
+
/** The width the lines were broken at, pt (Infinity: unbroken) */
|
|
208
|
+
maxWidthPt: number;
|
|
209
|
+
/** The nota style's right tab stop for break markers, pt — null at
|
|
210
|
+
* natural width, where each broken line carries its own stop */
|
|
211
|
+
breakTabStopPt: number | null;
|
|
212
|
+
spacer: {
|
|
213
|
+
character: SpacerChar;
|
|
214
|
+
/** The character as emitted ('\t' for tabs) */
|
|
215
|
+
char: string;
|
|
216
|
+
/** One unit's effective width, pt */
|
|
217
|
+
unitPt: number;
|
|
218
|
+
/** Letter-spacing to apply to spacer runs, pt (0 = none) */
|
|
219
|
+
letterSpacingPt: number;
|
|
220
|
+
/** The tab interval, pt — non-null only for the tab strategy;
|
|
221
|
+
* the document's default tab stop must match it */
|
|
222
|
+
tabIntervalPt: number | null;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Lays the score out for Word as structured lines: per line pair, the
|
|
227
|
+
* notes text and the text line as styled runs, dashes, word spaces, and
|
|
228
|
+
* self-correcting spacer counts (with absolute end positions) — exactly
|
|
229
|
+
* the layout toWordHtml/toWordText emit, for consumers building `.docx`
|
|
230
|
+
* paragraphs directly instead of parsing HTML.
|
|
231
|
+
*
|
|
232
|
+
* Browser-only: the layout measures with canvas and loaded webfonts.
|
|
233
|
+
*/
|
|
234
|
+
export declare function layoutForWord(source: GuidoScript | string, options?: WordExportOptions): Promise<WordLayout>;
|
|
235
|
+
/** Serializes a structured Word layout to the plain-text export:
|
|
236
|
+
* alternating notes / text lines, `\t*` after broken notes lines. */
|
|
237
|
+
export declare function wordLayoutText(layout: WordLayout): string;
|
|
238
|
+
/**
|
|
239
|
+
* Renders the score as the plain-text equivalent of the Word export: the
|
|
240
|
+
* notes verbatim and the same self-correcting spacer counts, but no HTML
|
|
241
|
+
* envelope, no letter-spacing tuning, and no mso runs. The clipboard
|
|
242
|
+
* writer sends this as the text/plain fallback.
|
|
243
|
+
*/
|
|
244
|
+
export declare function toWordText(source: GuidoScript | string, options?: WordExportOptions): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var GuidexEmbed=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class{source;constructor(e,t={}){this.source=(t.transforms??[]).reduce((e,t)=>t.apply(e),e)}get clef(){return this.normalized.match(/^\s*\(([^)]*)\)/)?.[1]}get syllables(){let e=[...this.normalized.replace(/^\s*\([^)]*\)/,``).matchAll(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g)];return e.map(([,t,r],i)=>({text:n(t.trim()),notes:n(r),wordEnd:i===e.length-1||/^\s/.test(e[i+1][1])}))}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.syllables.map((e,t)=>`${t>0&&this.syllables[t-1].wordEnd?` `:``}${r(e.text)}(${r(e.notes)})`);return`${this.clef===void 0?``:`(${this.clef})`}${e.join(``)}`}};function n(e){return e.replace(/\\(.)/g,`$1`)}function r(e){return e.replace(/\\/g,`\\\\`).replace(/[()]/g,e=>`\\${e}`)}function i(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 a(e){let t=e.match(/^\s*\(([^)]*)\)/),r=t?t[0].length:0,a=e.slice(r);for(let t of a.matchAll(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g)){let[,a,o]=t;if(n(o).trim().length===0)continue;let s=i(a);if(!s||a.trimStart().startsWith(`*`))return e;let c=r+t.index+s.index,l=c+s.unit.length;return`${e.slice(0,c)}*${e.slice(c,l)}*${e.slice(l)}`}return e}var o={startWithInitial:{name:`startWithInitial`,apply:a}},s=[`ðñ0123456789öüó`,`^]qwertzuiopõú`,`ÝÞQWERTZUIOPÕÚ`,`×sdfghjkléáû`,`ØÙDFGHJKLÉÁÛ`,`÷øaASÍYXCVBN$m`,`ÈÊËÌÎÏÐÑÒþ¬ßòôùý`,`“”•–—˜™š›œº»`,`®−§ÿ"+!%/=()ÖÜÓ`,`Ÿ¡¢£[¥¦©ª«¬`,`~¯‚ƒ„…†‡ˆ‰Š‹Œ‘’`,`àâãäåæçèêëìîï`,`½°±²³´μ·¾¸¹`];function c(e,t,n){for(let r of s){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 l(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=c(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 u(e,t={}){let n=t.overflow??`clamp`;return{name:`transpose`,apply:t=>{if(e===0)return t;let r=t.match(/^\s*\(([^)]*)\)/),i=r?r[0].length:0;return t.slice(0,i)+t.slice(i).replace(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g,(t,r,i)=>`${r}(${l(i,e,n)})`)}}}var d={chars:new Set([`*`,`†`]),fontFamily:`'Times New Roman', Times, serif`},f={weight:`400`,scale:.7,raise:.2},p={BNS:{textFontStack:`'Book Antiqua', Georgia, serif`,notesFontStack:`'Guidohu'`,markerGlyphs:d,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:d.fontFamily,weight:`700`,scale:1,measureScale:.95,raise:.1,color:`var(--red)`},padding:12,scriptTransforms:[o.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:d.fontFamily,weight:`700`,scale:1,measureScale:.95,raise:.2},padding:12,scriptTransforms:[]}};function m(e,t,n){if(e.length===0)return[];if(e===`**`)return[{text:`∗`,style:{...t.specialStarStyle}}];let r=e,i={};for(let n of[`__`,`_`]){let a=t.decorations[n];if(a&&e.length>=n.length*2+1&&e.startsWith(n)&&e.endsWith(n)){r=e.slice(n.length,-n.length),i={...a};break}}let a=t.decorations[`*`],o=[],s=r,c=``;for(let e=/\*([^*]+)\*/.exec(s);e;e=/\*([^*]+)\*/.exec(s))c+=s.slice(0,e.index),c&&=(o.push({text:c,marked:!1}),``),o.push({text:e[1],marked:!0}),s=s.slice(e.index+e[0].length);c+=s,c&&o.push({text:c,marked:!1});let l=o.map(({text:e,marked:t})=>({text:e,style:t?{...i,...a,initial:!0}:{...i}})),u=t.markerGlyphs,d=[];for(let e of l){e.style.uppercase&&(e.text=e.text.toUpperCase()),n&&(e.style={...e.style,weight:`700`});let t=[...e.text],r=e.style.fontFamily?.includes(`Liturgy`)??!1,i=e=>u&&u.chars.has(e)?`marker`:r&&e===`+`?`plus`:`text`;if(t.every(e=>i(e)===`text`)){d.push({text:e.text,style:{...e.style}});continue}let a=``,o=null,s=()=>{if(!a)return;let t={...e.style};o===`marker`&&u?t={...t,fontFamily:u.fontFamily}:o===`plus`&&(t={...t,...f}),d.push({text:a,style:t}),a=``};for(let e of t){let t=i(e);t!==o&&s(),o=t,a+=e}s()}return d}function h(e,t,n){return[e.italic?`italic`:`normal`,`normal`,e.weight??`400`,`${t*(e.measureScale??e.scale??1)}px`,e.fontFamily??n].join(` `)}function g(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 _(e,t){return e.verifiedFonts.map(e=>`${e.weight} ${t}px ${e.family}`)}var v=new Set(`,.:?'"+!%/=()ÖÜÓ;`.split(``)),ee=new Set(`Ÿ¡¢£[¥¦©ª«¬`.split(``)),y=[`-`,`¨`];function b(e){let t=0;for(;t<e.length&&v.has(e[t]);)t++;t>0&&t<e.length&&e[t]===`-`&&t++;let n=e.length;for(;n>t&&v.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 x=class e{script;constructor(e){this.script=typeof e==`string`?new t(e):e}static ctx=null;static measure(t,n){return e.ctx||=document.createElement(`canvas`).getContext(`2d`),e.ctx.font=n,e.ctx.measureText(t).width}static ink(t,n){e.ctx||=document.createElement(`canvas`).getContext(`2d`),e.ctx.font=n;let r=e.ctx.measureText(t);return{left:r.actualBoundingBoxLeft,right:r.actualBoundingBoxRight}}async render(t,n={}){let{style:r=`BNS`,bold:i=!1,textPx:a=18,notesPx:o=a*2,debug:s=!1,maxWidthPx:c=1/0}=n,l=p[r];if(!l)throw Error(`Unknown style set: "${r}"`);for(let e of _(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=h({weight:i?`700`:`400`},a,d),g=e=>m(e,l,i),x=e=>e.reduce((e,t)=>e+S(t.text,h(t.style,a,d)),0),S=(t,n)=>e.measure(t,n),C=S(`-`,u),w=S(`-`,f);t.style.fontSize=`${a}px`,t.style.fontFamily=d,t.dataset.style=r;let T=this.script.clef===void 0?``:`${this.script.clef}-`,E=[],D,O,k,A,j=!1,M=[],N=()=>{D&&(D.textCursor=k,D.notesEnd=D.notesParts.length?S(T+D.notesParts.join(``),u):0);let e=document.createElement(`div`);e.className=`guido`,e.style.fontSize=`${o}px`;let t=document.createElement(`p`);i&&(t.style.fontWeight=`700`),D={notesEl:e,textEl:t,notesParts:[],textCursor:0,notesEnd:0,lastWordEnd:null},E.push(D),O=T,k=0,A=!1,j=!1};N();let P=this.script.syllables,F=P.map((e,t)=>({syl:e,i:t,text:e.text,notes:e.notes,first:!0,lastSeg:!0})),I=(e,t,n)=>{for(let r=e.length-1;r>0;r--){if(!y.includes(e[r]))continue;let i=r+1;for(;i<e.length&&v.has(e[i]);)i++;if(!(i>=e.length)&&n(e.slice(0,i))<=t)return r}return-1},L=(e,t)=>{let n=e.notes,r=t+1;for(;r<n.length&&v.has(n[r]);)r++;return e.notes=n.slice(0,t)+n.slice(t+1,r),n.slice(r)},R=(e,t,n)=>{e.lastSeg=!1,F.splice(t+1,0,{syl:e.syl,i:e.i,text:``,notes:n,first:!1,lastSeg:!0}),z=!0},z=!1,B=0;for(;B<F.length;){let t=F[B],n=t.syl,r=t.i;z&&=(N(),!1);let i=t.lastSeg&&r===P.length-1,o=t.text,l=g(o),d=x(l),p=!i&&n.wordEnd?S(` `,f):0,m=M.reduce((e,t)=>e+t.textWidth+t.spaceWidth,0),h=n.notes.length===1&&ee.has(n.notes),_=k===0||k+m+d+(n.wordEnd?0:w)<=c;if(n.notes.length===0){M.push({sylParts:l,textWidth:d,spaceWidth:p,wordEnd:n.wordEnd}),B++;continue}if(t.first&&t.lastSeg&&n.text.trim()===``&&b(n.notes).core===``){let e=O[O.length-1],t=e&&e!==`-`&&!v.has(e)&&!n.notes.startsWith(`-`)?`-`:``;D.notesParts.push(t+n.notes),O+=t+n.notes,A=!0,j=!1,B++;continue}let y=P[r-1]?.notes!==n.notes;if(h&&!y&&D.notesParts.length>0&&!_&&N(),!t.first){for(;!(S(O+t.notes,u)<=c);){let e=I(t.notes,c,e=>S(O+e,u));if(e<0||e+1>=t.notes.length)break;let n=L(t,e);R(t,B,n)}let e=b(t.notes);D.notesParts.push(t.notes),O+=t.notes,t.lastSeg&&(A=e.trailing.length>0),D.lastWordEnd=!0,t.lastSeg||(z=!0),B++;continue}let T=D.notesParts.length===0||j?``:A?`--`:`---`,E=b(t.notes),V=(t=0)=>{let n=S(E.core,u),r=S(O+T+`-`.repeat(t)+E.leading,u),i=e.ink(E.core,u),a=-i.left,o=(i.right-i.left)/2;return{contentWidth:n,contentStart:r,textStart:n>=d||h?r+a:r+o-d/2}},{contentWidth:H,contentStart:U,textStart:W}=V();for(;;){let e=S(O+T+t.notes,u)>c,r=W+d+(n.wordEnd?0:w)>c;if(!e&&!r)break;if(e){let e=I(t.notes,c,e=>S(O+T+e,u));if(e>=0&&e+1<t.notes.length){let n=L(t,e);R(t,B,n),E=b(t.notes),{contentWidth:H,contentStart:U,textStart:W}=V();break}}if(D.notesParts.length===0&&k===0){if(e){let e=I(t.notes,c,e=>S(O+e,u));if(e>=0&&e+1<t.notes.length){let n=L(t,e);t.notes=t.notes.slice(0,e),R(t,B,n),E=b(t.notes),{contentWidth:H,contentStart:U,textStart:W}=V()}}break}N(),T=``,{contentWidth:H,contentStart:U,textStart:W}=V()}let G=D.notesParts.length>0&&!F[B-1].syl.wordEnd&&m===0,K=k+w,q=k+m+(j&&G?w:0),J=T+t.notes,Y=0,X=!1,Z=e=>{Y=e,J=T+`-`.repeat(e)+t.notes,{contentWidth:H,contentStart:U,textStart:W}=V(e)},te=h&&!y&&D.notesParts.length>0;if(te){T=``,W=k+m;let e=W+d+p-S(O,u),n=c-S(O+T,u),r=e>0?Math.min(Math.ceil(e/C),Math.max(0,Math.floor(n/C))):0;t.notes=`-`.repeat(r),E=b(t.notes),J=T+t.notes,X=G}if(!te){if(!j&&G&&W<K&&(d>H||W<k)){X=!0,W=k;let e=H>=d?W:W+(d-H)/2;e>U&&(Y=Math.round((e-U)/C),J=T+`-`.repeat(Y)+t.notes)}else if(W<q){let e=H>=d?q:q+(d-H)/2;if(e>U){let n=Math.max(0,Math.floor((e-U)/C));for(Z(n);W<q;)n++,Z(n);if(D.notesParts.length>0&&S(O+J,u)>c&&(N(),T=``,J=T+t.notes,Y=0,{contentWidth:H,contentStart:U,textStart:W}=V(),W<k+m)){let e=H>=d?k+m:k+m+(d-H)/2;if(e>U){let t=Math.max(0,Math.floor((e-U)/C));for(Z(t);W<k+m;)t++,Z(t)}}}}}m>0&&W<k+m&&(W=k+m);let Q=Math.max(0,W-m-k),$=e.sylSpan(l,a);if(D.notesParts.length===0){let t=e.spacer(Q);s&&(t.title=`lead-in ${Q.toFixed(1)}px → text ${W.toFixed(1)}`),D.textEl.appendChild(t)}else if(F[B-1].syl.wordEnd){let t=e.spacer(Q);s&&(t.title=`word gap ${Q.toFixed(1)}px → text ${W.toFixed(1)}`),D.textEl.appendChild(t)}else if(m===0&&X)s&&($.title+=` | tight pair`);else if(m===0){let t=Math.max(0,(Q-w)/2),n=e.spacer(t),r=document.createElement(`span`);r.className=`dash`,r.textContent=`-`;let i=e.spacer(t);s&&(n.title=`lead pad ${t.toFixed(1)}px (gap ${Q.toFixed(1)} − dash ${w.toFixed(1)}, halved)`,r.title=`dash ${w.toFixed(1)}px`,i.title=`trail pad ${t.toFixed(1)}px`),D.textEl.append(n,r,i)}if(s){let e=(d-H)/2,t=W-U;$.title=[`text w ${d.toFixed(1)}`,`notes w ${H.toFixed(1)}`,Y?`+${Y} pad dash(es)`:null,`text start ${W.toFixed(1)}`,`notes start ${U.toFixed(1)}`,`theoDiff: ${e.toFixed(1)}`,`cursDiff: ${t.toFixed(1)}`].filter(Boolean).join(`, `)}for(let t of M){let n=e.sylSpan(t.sylParts,a);if(s&&(n.title=`no notes, text w ${t.textWidth.toFixed(1)}, before the next syllable with notes`),D.textEl.appendChild(n),t.spaceWidth>0){let e=document.createElement(`span`);e.className=`word-space`,e.textContent=` `,s&&(e.title=`word space ${t.spaceWidth.toFixed(1)}px`),D.textEl.appendChild(e)}}if(M=[],D.textEl.appendChild($),p>0){let e=document.createElement(`span`);e.className=`word-space`,e.textContent=` `,s&&(e.title=`word space ${p.toFixed(1)}px`),D.textEl.appendChild(e)}k=W+d+p,O+=J,D.notesParts.push(J),D.lastWordEnd=n.wordEnd,t.lastSeg&&(A=E.trailing.length>0,j=h),t.lastSeg||(z=!0),B++}if(M.length>0){for(let t of M){let n=e.sylSpan(t.sylParts,a);if(s&&(n.title=`no notes, text w ${t.textWidth.toFixed(1)}, end of score`),D.textEl.appendChild(n),t.spaceWidth>0){let e=document.createElement(`span`);e.className=`word-space`,e.textContent=` `,s&&(e.title=`word space ${t.spaceWidth.toFixed(1)}px`),D.textEl.appendChild(e)}k+=t.textWidth+t.spaceWidth}D.lastWordEnd=M[M.length-1].wordEnd,D.textCursor=k}E.forEach((t,n)=>{if(n===E.length-1||t.lastWordEnd!==!1)return;let r=t.notesEnd>t.textCursor?Math.max(0,(t.notesEnd-t.textCursor-w)/2):0,i=e.spacer(r),a=document.createElement(`span`);a.className=`dash`,a.textContent=`-`;let o=e.spacer(r);s&&(i.title=`lead pad ${r.toFixed(1)}px → line-end dash (text end ${t.textCursor.toFixed(1)}, notes end ${t.notesEnd.toFixed(1)})`,a.title=`dash ${w.toFixed(1)}px (line end)`,o.title=`trail pad ${r.toFixed(1)}px`),t.textEl.append(i,a,o)});let V=c+(l.padding??0),H=S(`*`,u);E.forEach((e,t)=>{if(t===E.length-1)return;let n=S(T+e.notesParts.join(``),u);for(;n+C<=V-H&&n+C<c;)e.notesParts.push(`-`),n+=C;e.breakMarkerLeftPx=V-n-H}),E.forEach(e=>{e.notesEl.textContent=T+e.notesParts.join(``)}),E.forEach((e,t)=>{if(t===E.length-1)return;let n=document.createElement(`span`);n.className=`guido-break`,n.textContent=`*`,n.style.position=`relative`,n.style.left=`${e.breakMarkerLeftPx}px`,s&&(n.title=`line break at ${V.toFixed(1)}px (staff filled to ${(V-e.breakMarkerLeftPx-H).toFixed(1)}px)`),e.notesEl.appendChild(n)}),t.replaceChildren(...E.flatMap(e=>[e.notesEl,e.textEl]))}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(g(e.style,t)))r.style.setProperty(n,i);e.style.initial&&(r.className=`initial`),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}},S={name:`guidex`,version:`0.2.6`,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`}},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`,"@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,C=`.guidex-script, .guido-script`,w={maxWidth:`auto`,style:`BNS`,bold:!1,textPx:18,transpose:0,debug:!1},T={},E=new WeakMap,D=new WeakMap,O=new WeakMap;function k(e){if(e!==void 0){if(e===``||e===`true`)return!0;if(e===`false`)return!1}}function A(e){if(e===void 0)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function j(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 M=new WeakMap;function N(e){let t=e.dataset,n=M.get(e)??{};return{maxWidth:t.maxWidth===void 0?n.maxWidth??T.maxWidth??w.maxWidth:j(t.maxWidth,n.maxWidth??T.maxWidth??w.maxWidth),style:t.style??n.style??T.style??w.style,bold:k(t.bold)??n.bold??T.bold??w.bold,textPx:A(t.textPx)??n.textPx??T.textPx??w.textPx,transpose:A(t.transpose)??n.transpose??T.transpose??w.transpose,debug:k(t.debug)??n.debug??T.debug??w.debug}}function P(e){return e.querySelector(`:scope > .guidex-render`)?.clientWidth||e.clientWidth||e.parentElement?.clientWidth||0}function F(e,t,n){if(typeof t==`number`)return t;let r=P(e);if(r<=0)return 1/0;let i=r-(p[n]?.padding??0);return i>0?i:r}function I(e){for(let t of e.childNodes)if(t.nodeType===Node.TEXT_NODE&&t.nodeValue?.trim())return t.nodeValue.trim();return E.get(e)??``}function L(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 R(e,t){let n=document.createElement(`p`);n.className=`guidex-error`,n.textContent=t,e.replaceChildren(n)}function z(e,t){let n=[...p[e]?.scriptTransforms??[]];return t!==0&&n.push(u(t)),n}async function B(e){let n=(D.get(e)??0)+1;D.set(e,n);let r=N(e),i=I(e);E.set(e,i);let a=L(e),o=F(e,r.maxWidth,r.style);O.set(e,o);let s=document.createElement(`div`),c=new t(i,{transforms:z(r.style,r.transpose)});try{if(await new x(c).render(s,{style:r.style,bold:r.bold,textPx:r.textPx,debug:r.debug,maxWidthPx:o}),D.get(e)!==n)return;a.replaceChildren(...s.childNodes),a.style.cssText=s.style.cssText,s.dataset.style&&(a.dataset.style=s.dataset.style)}catch(t){if(D.get(e)!==n)return;console.error(`[guidex]`,t),R(a,t instanceof Error?t.message:String(t))}}var V=new WeakMap;function H(e){let t=N(e),n=F(e,t.maxWidth,t.style);return Math.abs(n-(O.get(e)??NaN))>1}function U(e){if(V.has(e))return;let t;if(typeof ResizeObserver<`u`){let n=new ResizeObserver(()=>{H(e)&&B(e)});n.observe(e),t=()=>n.disconnect()}else{let n=()=>{H(e)&&B(e)};window.addEventListener(`resize`,n),t=()=>window.removeEventListener(`resize`,n)}V.set(e,t)}function W(e){V.get(e)?.(),V.delete(e),E.delete(e),M.delete(e),D.delete(e),O.delete(e)}async function G(e,n,r={}){M.set(e,r);let i=(D.get(e)??0)+1;D.set(e,i),E.set(e,n);let a=N(e),o=L(e),s=F(e,a.maxWidth,a.style);O.set(e,s),U(e);let c=document.createElement(`div`),l=new t(n,{transforms:z(a.style,a.transpose)});try{if(await new x(l).render(c,{style:a.style,bold:a.bold,textPx:a.textPx,debug:a.debug,maxWidthPx:s}),D.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(D.get(e)!==i)return;console.error(`[guidex]`,t),R(o,t instanceof Error?t.message:String(t))}}async function K(e=document){let t=T.selector??C,n=[];return e instanceof Element&&e.matches(t)&&n.push(e),n.push(...e.querySelectorAll(t)),Promise.all(n.map(e=>(U(e),B(e)))).then(()=>void 0)}var q=!1;function J(){if(q||typeof MutationObserver>`u`)return;q=!0;let e=T.selector??C;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)U(e),B(e)}).observe(document.documentElement,{childList:!0,subtree:!0})}function Y(e={}){T={...T,...e},J(),K()}return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>Y(),{once:!0}):Y(),e.dispose=W,e.init=Y,e.renderAll=K,e.renderScore=G,e.version=S,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})({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "guidex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"workspaces": [
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
"./react": {
|
|
26
26
|
"types": "./dist/lib/react/index.d.ts",
|
|
27
27
|
"default": "./dist/lib/react/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./word": {
|
|
30
|
+
"types": "./dist/lib/word/index.d.ts",
|
|
31
|
+
"default": "./dist/lib/word/index.js"
|
|
28
32
|
}
|
|
29
33
|
},
|
|
30
34
|
"files": [
|
|
@@ -69,6 +73,9 @@
|
|
|
69
73
|
"homepage": "https://github.com/BrownieMaar/guidex#readme",
|
|
70
74
|
"devDependencies": {
|
|
71
75
|
"@eslint/js": "^10.0.1",
|
|
76
|
+
"@testing-library/dom": "^10.4.2",
|
|
77
|
+
"@testing-library/react": "^16.3.3",
|
|
78
|
+
"@testing-library/user-event": "^14.6.7",
|
|
72
79
|
"@types/react": "^19.3.0",
|
|
73
80
|
"@types/react-dom": "^19.3.0",
|
|
74
81
|
"@vitejs/plugin-react": "^6.1.1",
|