guidex 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -3
- package/dist/lib/app/EditorContext.d.ts +6 -1
- package/dist/lib/app/ExactTransposeControls.d.ts +1 -0
- package/dist/lib/app/StanzaControls.d.ts +1 -0
- package/dist/lib/app/TransposeSettings.d.ts +1 -0
- package/dist/lib/app/editorState.d.ts +78 -6
- package/dist/lib/app/shareLink.d.ts +22 -0
- package/dist/lib/chantLayout-B0xiaMo9.js +2641 -0
- package/dist/lib/chantLayout.d.ts +41 -8
- package/dist/lib/composeScript.d.ts +71 -0
- package/dist/lib/editorStorage.d.ts +6 -0
- package/dist/lib/embed/core.d.ts +28 -2
- package/dist/lib/embed/index.js +1 -1
- package/dist/lib/embed/manual.d.ts +12 -3
- package/dist/lib/embed/manual.js +324 -276
- package/dist/lib/exactTranspose.d.ts +54 -0
- package/dist/lib/glyphFamilies.d.ts +22 -0
- package/dist/lib/guidoRender.d.ts +5 -3
- package/dist/lib/guidoScript.d.ts +92 -10
- package/dist/lib/guidoScriptTransforms.d.ts +19 -7
- package/dist/lib/noteGroups.d.ts +22 -0
- package/dist/lib/react/GuidexScore.d.ts +19 -1
- package/dist/lib/react/index.d.ts +2 -1
- package/dist/lib/react/index.js +23 -3
- package/dist/lib/{scoreImage-oVBasBX5.js → scoreImage-DSEupCru.js} +102 -51
- package/dist/lib/stanzas.d.ts +135 -0
- package/dist/lib/word/index.js +1 -1
- package/dist/lib/{wordChecker-C3nJrk_j.js → wordChecker-EQx8frRp.js} +97 -45
- package/dist/lib/wordClipboard.d.ts +3 -3
- package/dist/lib/wordExport.d.ts +9 -5
- package/dist-embed/guidex-embed.min.js +1 -1
- package/package.json +1 -1
- package/dist/lib/chantLayout-GAfg2iKS.js +0 -1042
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GuidoScript } from './guidoScript';
|
|
2
1
|
import { StyleSetName } from './guidoStyles';
|
|
2
|
+
import { LayoutSource } from './chantLayout';
|
|
3
3
|
export { NOTE_MODIFIERS, SCORE_MARKERS } from './chantLayout';
|
|
4
4
|
/** Options for one render. All fields optional; defaults reproduce the
|
|
5
5
|
* original Book Antiqua look (style set BNS). */
|
|
@@ -26,11 +26,13 @@ export interface RenderOptions {
|
|
|
26
26
|
* `render` turns the laid-out lines into (notes `.guido` div, text `<p>`)
|
|
27
27
|
* pairs — px-measured inline-block spacer spans fake the horizontal gaps.
|
|
28
28
|
* The Word export (wordExport.ts) consumes the same layout with a
|
|
29
|
-
* character-based spacer mechanism instead.
|
|
29
|
+
* character-based spacer mechanism instead. Given several underlays of
|
|
30
|
+
* one melody (stacked stanzas, issue #84 — see `stackStanzas`), every
|
|
31
|
+
* notes line is followed by one text `<p>` per underlay.
|
|
30
32
|
*/
|
|
31
33
|
export declare class GuidoRender {
|
|
32
34
|
private readonly script;
|
|
33
|
-
constructor(source:
|
|
35
|
+
constructor(source: LayoutSource);
|
|
34
36
|
/**
|
|
35
37
|
* Renders the score into `container` as (notes line, text line) pairs.
|
|
36
38
|
* When `maxWidthPx` is finite, a new pair starts before any syllable
|
|
@@ -3,20 +3,60 @@ import { ScriptTransform } from './guidoScriptTransforms';
|
|
|
3
3
|
* `spaceBefore` records whether the source had whitespace between the
|
|
4
4
|
* previous group and this token's group — it feeds the previous
|
|
5
5
|
* syllable's `wordEnd` and the `toString()` round-trip. */
|
|
6
|
-
export type ScriptToken =
|
|
6
|
+
export type ScriptToken = SyllableToken | StatementToken;
|
|
7
|
+
/** A syllable token. `held` marks a text-less group held by the syllable
|
|
8
|
+
* before it (its `wordEnd` is that syllable's); `empty` marks an empty
|
|
9
|
+
* slot (`~`, or a text-less group at the start): notes but no syllable.
|
|
10
|
+
* Both flags are only present when set. */
|
|
11
|
+
export type SyllableToken = {
|
|
7
12
|
kind: 'syllable';
|
|
8
13
|
text: string;
|
|
9
14
|
notes: string;
|
|
10
15
|
wordEnd: boolean;
|
|
11
16
|
spaceBefore: boolean;
|
|
12
|
-
|
|
17
|
+
held?: true;
|
|
18
|
+
empty?: true;
|
|
19
|
+
};
|
|
20
|
+
/** A syllable as `GuidoScript.syllables` lists it. */
|
|
21
|
+
export type Syllable = Pick<SyllableToken, 'text' | 'notes' | 'wordEnd' | 'held' | 'empty'>;
|
|
22
|
+
/** Source offsets of one token (see `GuidoScript.tokenSpans`): `start`
|
|
23
|
+
* is its text's first character (its group's `(` when it has no text),
|
|
24
|
+
* `notesStart`/`notesEnd` bound its group's content, `end` is just past
|
|
25
|
+
* its `)`. Offsets index `source`; only the typing conveniences
|
|
26
|
+
* (a closing paren or a `()` appended at the end) reach past it. */
|
|
27
|
+
export interface TokenSpan {
|
|
28
|
+
start: number;
|
|
29
|
+
notesStart: number;
|
|
30
|
+
notesEnd: number;
|
|
31
|
+
end: number;
|
|
32
|
+
}
|
|
33
|
+
/** A control statement token. `clef` is the clef glyph of a `(@clef …)`
|
|
34
|
+
* change; `key` is the key's modifier glyphs (empty when cleared). */
|
|
35
|
+
export type StatementToken = {
|
|
13
36
|
kind: 'break';
|
|
14
37
|
spaceBefore: boolean;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'clef';
|
|
40
|
+
clef: string;
|
|
41
|
+
key: string;
|
|
42
|
+
spaceBefore: boolean;
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'key';
|
|
45
|
+
key: string;
|
|
46
|
+
spaceBefore: boolean;
|
|
15
47
|
};
|
|
16
48
|
/** Whether a group's content is a control statement (`@`-keyword,
|
|
17
49
|
* trimmed). Shared with the transforms, which must leave statement
|
|
18
|
-
* groups alone — their keyword characters are pitch glyphs otherwise.
|
|
50
|
+
* groups alone — their keyword characters are pitch glyphs otherwise.
|
|
51
|
+
* A c4 clef group (`@` + modifier glyphs) counts too: the opening one is
|
|
52
|
+
* told apart by `isC4ClefGroup`, and mid-script it is an error. */
|
|
19
53
|
export declare function isStatementGroup(content: string): boolean;
|
|
54
|
+
/** Whether a group's content has the shape of a c4 clef group: `@`
|
|
55
|
+
* followed by nothing but modifier glyphs. Statement keywords never
|
|
56
|
+
* consist solely of modifier glyphs, so the two cannot collide. */
|
|
57
|
+
export declare function isC4ClefGroup(content: string): boolean;
|
|
58
|
+
/** A statement token written back as its group. */
|
|
59
|
+
export declare function statementSource(tok: StatementToken): string;
|
|
20
60
|
export declare class GuidoScript {
|
|
21
61
|
readonly source: string;
|
|
22
62
|
constructor(source: string, options?: {
|
|
@@ -29,13 +69,20 @@ export declare class GuidoScript {
|
|
|
29
69
|
* control statements. Throws on a malformed statement (syllable text
|
|
30
70
|
* attached to one, or an unknown `@` keyword). */
|
|
31
71
|
get tokens(): ScriptToken[];
|
|
72
|
+
/** The raw text of the `(@stanza …)` statements at the end of the
|
|
73
|
+
* script — stanzas 2, 3, … in order, escapes kept (the stanza text
|
|
74
|
+
* grammar folds them). Throws like `tokens` on a malformed script,
|
|
75
|
+
* and when anything but another stanza follows a stanza statement. */
|
|
76
|
+
get stanzas(): string[];
|
|
77
|
+
/** Where each token stands in the source, parallel to `tokens`:
|
|
78
|
+
* offsets of its text (past leading whitespace), of its group's
|
|
79
|
+
* content and just past its group's `)`. The walker
|
|
80
|
+
* (`scriptSyllables`) reads them. */
|
|
81
|
+
get tokenSpans(): TokenSpan[];
|
|
82
|
+
private parse;
|
|
32
83
|
/** The script broken into syllables, each with its sung text and
|
|
33
84
|
* notes — the syllable tokens, statements filtered out. */
|
|
34
|
-
get syllables():
|
|
35
|
-
text: string;
|
|
36
|
-
notes: string;
|
|
37
|
-
wordEnd: boolean;
|
|
38
|
-
}[];
|
|
85
|
+
get syllables(): Syllable[];
|
|
39
86
|
/**
|
|
40
87
|
* The source with the typing conveniences folded in, so the parser
|
|
41
88
|
* itself only ever sees complete scripts:
|
|
@@ -46,7 +93,8 @@ export declare class GuidoScript {
|
|
|
46
93
|
* renders like a `*()` syllable (text without notes width).
|
|
47
94
|
*/
|
|
48
95
|
private get normalized();
|
|
49
|
-
/** The syllables grouped into the words of the text.
|
|
96
|
+
/** The syllables grouped into the words of the text. Held groups and
|
|
97
|
+
* empty slots sing no syllable of their own, so they are left out. */
|
|
50
98
|
get words(): {
|
|
51
99
|
text: string;
|
|
52
100
|
syllables: {
|
|
@@ -55,12 +103,46 @@ export declare class GuidoScript {
|
|
|
55
103
|
}[];
|
|
56
104
|
}[];
|
|
57
105
|
/** The script rebuilt from the parsed pieces — a round-trip of the
|
|
58
|
-
* source, statements included. */
|
|
106
|
+
* source, statements and stanzas included. */
|
|
59
107
|
toString(): string;
|
|
60
108
|
}
|
|
109
|
+
/** One text-bearing syllable of a script (see `scriptSyllables`). */
|
|
110
|
+
export interface ScriptSyllable {
|
|
111
|
+
/** Its text, escapes folded and whitespace trimmed */
|
|
112
|
+
text: string;
|
|
113
|
+
/** Its own note group's content, escapes folded */
|
|
114
|
+
notes: string;
|
|
115
|
+
/** The groups it holds (issue #83), escapes folded, in order */
|
|
116
|
+
held: string[];
|
|
117
|
+
/** Whether it opens a word (the first syllable always does) */
|
|
118
|
+
wordStart: boolean;
|
|
119
|
+
wordEnd: boolean;
|
|
120
|
+
/** Offset of its text's first character in the source */
|
|
121
|
+
start: number;
|
|
122
|
+
/** Offsets of its own group's content (the `(` is at
|
|
123
|
+
* `notesStart - 1`, the `)` at `notesEnd`) */
|
|
124
|
+
notesStart: number;
|
|
125
|
+
notesEnd: number;
|
|
126
|
+
/** Offset just past the last group of its held run (just past its
|
|
127
|
+
* own group when it holds none) */
|
|
128
|
+
end: number;
|
|
129
|
+
/** Its index among the script's tokens (`GuidoScript.tokens`) */
|
|
130
|
+
token: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The syllables of a script that carry text, in order — the ones the
|
|
134
|
+
* sung text is made of, so their count and texts match `chantText`
|
|
135
|
+
* (and `GuidoScript.words`). Held groups ride on their syllable
|
|
136
|
+
* (`held`), `~` empty slots, statements and `(@stanza …)` are skipped.
|
|
137
|
+
* Offsets index the script's source; index i is the "syllable i" of
|
|
138
|
+
* `composeScript`'s `from`/`to`.
|
|
139
|
+
*/
|
|
140
|
+
export declare function scriptSyllables(script: GuidoScript | string): ScriptSyllable[];
|
|
61
141
|
/** The sung text of the script: the clef stripped, syllables joined
|
|
62
142
|
* into words, and the words joined with single spaces. */
|
|
63
143
|
export declare function chantText(script: string): string;
|
|
64
144
|
/** Folds backslash escapes into the characters they stand for. Shared
|
|
65
145
|
* with the transforms module (guidoScriptTransforms.ts). */
|
|
66
146
|
export declare function unescape(text: string): string;
|
|
147
|
+
/** Turns literal parentheses and backslashes into their escape sequences. */
|
|
148
|
+
export declare function escape(text: string): string;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
export { STANZA_PLACEHOLDER, padStanza, parseStanza, selectStanza, slotCount, smallHeads, stackStanzas, stackedStanzaNumbers, stanzaCount, stanzaTexts, stanzaWarnings, withStanza, type EmptySlots, type SelectStanzaOptions, type StanzaOptions, type StanzaStack, type StanzaSyllable, type StanzaWarning, } from './stanzas';
|
|
2
|
+
export { KEY_SIGNATURES, parseInterval, transposeExact, transposeScript, TranspositionRangeError, type SpelledInterval, type TranspositionTarget, } from './exactTranspose';
|
|
1
3
|
/** A named source-to-source rewrite applied to a script before parsing. */
|
|
2
4
|
export interface ScriptTransform {
|
|
3
5
|
name: string;
|
|
4
6
|
apply: (source: string) => string;
|
|
5
7
|
}
|
|
6
8
|
/** The `startWithInitial` transform: finds the first syllable group with
|
|
7
|
-
* actual notes (the clef, no-notes groups,
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* actual notes and text (the clef, no-notes groups, control statements,
|
|
10
|
+
* text-less groups and `~` empty slots don't count) and wraps the
|
|
11
|
+
* syllable's first character in the `*…*` initial marker. Already-marked
|
|
12
|
+
* text (leading `*`) is left alone. */
|
|
11
13
|
declare function startWithInitial(source: string): string;
|
|
12
14
|
/**
|
|
13
15
|
* The built-in transformations, keyed by name; pass the ones a feature
|
|
@@ -30,8 +32,19 @@ export declare const SCRIPT_TRANSFORMS: {
|
|
|
30
32
|
export declare const PITCH_ROWS: readonly ["ðñ0123456789öüó", "^]qwertzuiopõú", "ÝÞQWERTZUIOPÕÚ", "×sdfghjkléáû", "ØÙDFGHJKLÉÁÛ", "÷øaASÍYXCVBN$m", "ÈÊËÌÎÏÐÑÒþßòôùý", "“”•–—˜™š›œº»", "®−§ÿ\"+!%/=()ÖÜÓ", "Ÿ¡¢£[¥¦©ª«¬", "~¯‚ƒ„…†‡ˆ‰Š‹Œ‘’", "àâãäåæçèêëìîï", "½°±²³´μ·¾¸¹"];
|
|
31
33
|
/** What happens when a shift runs past the end of a pitch row:
|
|
32
34
|
* `clamp` keeps the first/last available character, `null` emits
|
|
33
|
-
* `U+0000`, which shows up as a missing glyph in the score
|
|
34
|
-
|
|
35
|
+
* `U+0000`, which shows up as a missing glyph in the score, and `error`
|
|
36
|
+
* throws. */
|
|
37
|
+
export type TransposeOverflow = 'clamp' | 'null' | 'error';
|
|
38
|
+
/** Transposes the pitch characters of one note group's content as
|
|
39
|
+
* written in the source (escapes included) — the staff-degree shift
|
|
40
|
+
* `transposeBy` applies to every group. Escape pairs stand for their
|
|
41
|
+
* underlying character (an escaped paren is a pitch glyph of the
|
|
42
|
+
* `®−§ÿ…` row), and a shifted result that is a control character of the
|
|
43
|
+
* group syntax is written escaped. A statement group's content (`@…`) is returned
|
|
44
|
+
* unchanged: its keyword letters are pitch glyphs, but no notes. */
|
|
45
|
+
export declare function transposeNotes(notes: string, shift: number, options?: {
|
|
46
|
+
overflow?: TransposeOverflow;
|
|
47
|
+
}): string;
|
|
35
48
|
/** The `transposeBy` transform factory: shifts every pitch character of
|
|
36
49
|
* every notes group `shift` positions along its pitch row. The clef
|
|
37
50
|
* group and the syllable text are left alone — clef handling is a
|
|
@@ -39,4 +52,3 @@ export type TransposeOverflow = 'clamp' | 'null';
|
|
|
39
52
|
export declare function transposeBy(shift: number, options?: {
|
|
40
53
|
overflow?: TransposeOverflow;
|
|
41
54
|
}): ScriptTransform;
|
|
42
|
-
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Note-group anatomy shared by the layout pass and the exact
|
|
3
|
+
* transposition: the score markers and the split of a group into its
|
|
4
|
+
* leading markers, notes and trailing markers. Kept free of imports, so
|
|
5
|
+
* the transforms can use it without pulling in the style sets.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Score marker characters: they carry no pitch, and when they sit at the
|
|
9
|
+
* start or end of a note group (with the adjacent dash) they act as
|
|
10
|
+
* whitespace rather than note width.
|
|
11
|
+
*/
|
|
12
|
+
export declare const SCORE_MARKERS = ",.:?'\"+!%/=()\u00D6\u00DC\u00D3;";
|
|
13
|
+
export declare const MARKER_CHARS: Set<string>;
|
|
14
|
+
export interface NoteGroupParts {
|
|
15
|
+
/** Marker run at the group's start (markers plus their adjacent dash) */
|
|
16
|
+
leading: string;
|
|
17
|
+
/** The notes between the marker runs */
|
|
18
|
+
core: string;
|
|
19
|
+
/** Marker run at the group's end (dash plus markers) */
|
|
20
|
+
trailing: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function splitNoteMarkers(notes: string): NoteGroupParts;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MaxWidth } from '../embed/core';
|
|
2
2
|
import { StyleSetName } from '../guidoStyles';
|
|
3
|
+
import { EmptySlots, StanzaStack, StanzaWarning } from '../stanzas';
|
|
3
4
|
export interface GuidexScoreProps {
|
|
4
5
|
/** The score source in GuidoScript notation, e.g. `'(M)A(0) di(0q)e(qQ0)bus(1) an(3)ti(1e)quis(qQ0-:)'`. */
|
|
5
6
|
script: string;
|
|
@@ -12,8 +13,25 @@ export interface GuidexScoreProps {
|
|
|
12
13
|
textPx?: number;
|
|
13
14
|
/** Transpose the score by N diatonic steps. */
|
|
14
15
|
transpose?: number;
|
|
16
|
+
/** The stanza sung under the notes (1-based, default 1: the
|
|
17
|
+
* script's own text). */
|
|
18
|
+
stanza?: number;
|
|
19
|
+
/** Stacked stanzas under one staff (issue #84): `'all'`, or the
|
|
20
|
+
* stanza numbers in order. Replaces `stanza` when set. */
|
|
21
|
+
stack?: StanzaStack;
|
|
22
|
+
/** Stanzas 2, 3, … as stanza text, replacing the script's
|
|
23
|
+
* `(@stanza …)` statements. */
|
|
24
|
+
stanzas?: string[];
|
|
25
|
+
/** `'small'` draws the slots the stanza leaves empty while another
|
|
26
|
+
* stanza sings them with small heads (stacked: the slots no stacked
|
|
27
|
+
* stanza sings while another stanza does); `'partial'` every slot
|
|
28
|
+
* some stanza sings and another does not. */
|
|
29
|
+
emptySlots?: EmptySlots;
|
|
30
|
+
/** Called after each render with the rendered stanzas' count
|
|
31
|
+
* mismatches (empty when it fits). */
|
|
32
|
+
onWarnings?: (warnings: StanzaWarning[]) => void;
|
|
15
33
|
/** Render measurement debug markers. */
|
|
16
34
|
debug?: boolean;
|
|
17
35
|
className?: string;
|
|
18
36
|
}
|
|
19
|
-
export declare function GuidexScore({ script, maxWidth, style, bold, textPx, transpose, debug, className, }: GuidexScoreProps): import('react').JSX.Element;
|
|
37
|
+
export declare function GuidexScore({ script, maxWidth, style, bold, textPx, transpose, stanza, stack, stanzas, emptySlots, onWarnings, debug, className, }: GuidexScoreProps): import('react').JSX.Element;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* a re-export of the imperative embed API for advanced use.
|
|
4
4
|
*/
|
|
5
5
|
export { GuidexScore, type GuidexScoreProps } from './GuidexScore';
|
|
6
|
-
export { renderScore, renderAll, init, dispose, version, type EmbedOptions, type MaxWidth } from '../embed/core';
|
|
6
|
+
export { renderScore, renderAll, init, dispose, version, type EmbedOptions, type MaxWidth, type RenderResult, type RenderScoreOptions, } from '../embed/core';
|
|
7
7
|
export { downloadScorePng, downloadScoreSvg, scorePngBlob, scoreSvg, type ScoreDownloadOptions, type ScoreImageOptions, } from '../scoreImage';
|
|
8
8
|
export type { StyleSetName } from '../guidoStyles';
|
|
9
|
+
export type { EmptySlots, StanzaStack, StanzaWarning } from '../stanzas';
|
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-DSEupCru.js";
|
|
3
3
|
import { useEffect, useRef } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/react/GuidexScore.tsx
|
|
@@ -10,20 +10,36 @@ import { jsx } from "react/jsx-runtime";
|
|
|
10
10
|
* client'` directive marks it for React Server Components (Next.js App
|
|
11
11
|
* Router); in plain client-side React it is a no-op.
|
|
12
12
|
*/
|
|
13
|
-
function GuidexScore({ script, maxWidth, style, bold, textPx, transpose, debug, className }) {
|
|
13
|
+
function GuidexScore({ script, maxWidth, style, bold, textPx, transpose, stanza, stack, stanzas, emptySlots, onWarnings, debug, className }) {
|
|
14
14
|
const ref = useRef(null);
|
|
15
|
+
const onWarningsRef = useRef(onWarnings);
|
|
16
|
+
onWarningsRef.current = onWarnings;
|
|
17
|
+
const stanzasKey = stanzas === void 0 ? void 0 : JSON.stringify(stanzas);
|
|
18
|
+
const stackKey = stack === void 0 ? void 0 : JSON.stringify(stack);
|
|
15
19
|
useEffect(() => {
|
|
16
20
|
const el = ref.current;
|
|
17
21
|
if (!el) return;
|
|
22
|
+
let live = true;
|
|
23
|
+
const stanzaTexts = stanzasKey === void 0 ? void 0 : JSON.parse(stanzasKey);
|
|
24
|
+
const stacked = stackKey === void 0 ? void 0 : JSON.parse(stackKey);
|
|
18
25
|
renderScore(el, script, {
|
|
19
26
|
maxWidth,
|
|
20
27
|
style,
|
|
21
28
|
bold,
|
|
22
29
|
textPx,
|
|
23
30
|
transpose,
|
|
31
|
+
stanza,
|
|
32
|
+
stack: stacked,
|
|
33
|
+
stanzas: stanzaTexts,
|
|
34
|
+
emptySlots,
|
|
24
35
|
debug
|
|
36
|
+
}).then(({ warnings }) => {
|
|
37
|
+
if (live) onWarningsRef.current?.(warnings);
|
|
25
38
|
});
|
|
26
|
-
return () =>
|
|
39
|
+
return () => {
|
|
40
|
+
live = false;
|
|
41
|
+
dispose(el);
|
|
42
|
+
};
|
|
27
43
|
}, [
|
|
28
44
|
script,
|
|
29
45
|
maxWidth,
|
|
@@ -31,6 +47,10 @@ function GuidexScore({ script, maxWidth, style, bold, textPx, transpose, debug,
|
|
|
31
47
|
bold,
|
|
32
48
|
textPx,
|
|
33
49
|
transpose,
|
|
50
|
+
stanza,
|
|
51
|
+
stackKey,
|
|
52
|
+
stanzasKey,
|
|
53
|
+
emptySlots,
|
|
34
54
|
debug
|
|
35
55
|
]);
|
|
36
56
|
return /* @__PURE__ */ jsx("div", {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as stanzaWarnings, C as selectStanza, D as stackedStanzaNumbers, E as stackStanzas, P as GuidoScript, d as transposeBy, o as STYLE_SETS, r as layoutScore, s as inlineStylesFor } from "./chantLayout-B0xiaMo9.js";
|
|
2
2
|
//#region src/guidoRender.ts
|
|
3
3
|
/**
|
|
4
4
|
* Renders a GuidoScript into a tidy score: a notes line in the chant font,
|
|
@@ -9,12 +9,15 @@ import { c as inlineStylesFor, d as transposeBy, f as GuidoScript, i as layoutSc
|
|
|
9
9
|
* `render` turns the laid-out lines into (notes `.guido` div, text `<p>`)
|
|
10
10
|
* pairs — px-measured inline-block spacer spans fake the horizontal gaps.
|
|
11
11
|
* The Word export (wordExport.ts) consumes the same layout with a
|
|
12
|
-
* character-based spacer mechanism instead.
|
|
12
|
+
* character-based spacer mechanism instead. Given several underlays of
|
|
13
|
+
* one melody (stacked stanzas, issue #84 — see `stackStanzas`), every
|
|
14
|
+
* notes line is followed by one text `<p>` per underlay.
|
|
13
15
|
*/
|
|
14
16
|
var GuidoRender = class GuidoRender {
|
|
15
17
|
script;
|
|
16
18
|
constructor(source) {
|
|
17
|
-
|
|
19
|
+
const parse = (s) => typeof s === "string" ? new GuidoScript(s) : s;
|
|
20
|
+
this.script = typeof source === "string" || source instanceof GuidoScript ? parse(source) : source.map(parse);
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
23
|
* Renders the score into `container` as (notes line, text line) pairs.
|
|
@@ -25,22 +28,22 @@ var GuidoRender = class GuidoRender {
|
|
|
25
28
|
*/
|
|
26
29
|
async render(container, options = {}) {
|
|
27
30
|
const { debug = false } = options;
|
|
28
|
-
const { lines,
|
|
31
|
+
const { lines, styleSet, styleName, textPx, notesPx, bold, starTarget, starWidth } = await layoutScore(this.script, options);
|
|
29
32
|
container.style.fontSize = `${textPx}px`;
|
|
30
33
|
container.style.fontFamily = styleSet.textFontStack;
|
|
31
34
|
container.dataset.style = styleName;
|
|
32
|
-
container.replaceChildren(...lines.flatMap((l) => [GuidoRender.notesLine(l,
|
|
35
|
+
container.replaceChildren(...lines.flatMap((l) => [GuidoRender.notesLine(l, notesPx, starTarget, starWidth, debug), ...l.texts.map((text) => GuidoRender.textLine(text, textPx, bold, debug))]));
|
|
33
36
|
}
|
|
34
37
|
/** Builds a line's notes div: the chant font text plus, on broken
|
|
35
38
|
* lines, the break marker `*` as an inline span (so it shares the
|
|
36
39
|
* text's baseline) shifted right so its right edge lands on the
|
|
37
40
|
* padding-extended max-width position. position: relative keeps the
|
|
38
41
|
* shift out of the flow measurements. */
|
|
39
|
-
static notesLine(line,
|
|
42
|
+
static notesLine(line, notesPx, starTarget, starWidth, debug) {
|
|
40
43
|
const notesEl = document.createElement("div");
|
|
41
44
|
notesEl.className = "guido";
|
|
42
45
|
notesEl.style.fontSize = `${notesPx}px`;
|
|
43
|
-
notesEl.textContent = clefPrefix + line.notesParts.join("");
|
|
46
|
+
notesEl.textContent = line.clefPrefix + line.notesParts.join("");
|
|
44
47
|
if (line.breakMarkerLeftPx !== void 0) {
|
|
45
48
|
const star = document.createElement("span");
|
|
46
49
|
star.className = "guido-break";
|
|
@@ -155,7 +158,7 @@ var GuidoRender = class GuidoRender {
|
|
|
155
158
|
//#region src/embed/core.ts
|
|
156
159
|
var version = {
|
|
157
160
|
name: "guidex",
|
|
158
|
-
version: "0.3.
|
|
161
|
+
version: "0.3.2",
|
|
159
162
|
description: "Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime",
|
|
160
163
|
type: "module",
|
|
161
164
|
workspaces: ["examples/*"],
|
|
@@ -237,6 +240,10 @@ var DEFAULTS = {
|
|
|
237
240
|
bold: false,
|
|
238
241
|
textPx: 18,
|
|
239
242
|
transpose: 0,
|
|
243
|
+
stanza: 1,
|
|
244
|
+
stack: void 0,
|
|
245
|
+
emptySlots: "normal",
|
|
246
|
+
stanzas: void 0,
|
|
240
247
|
debug: false
|
|
241
248
|
};
|
|
242
249
|
var globalOptions = {};
|
|
@@ -273,6 +280,19 @@ function parseMaxWidth(value, fallback) {
|
|
|
273
280
|
* callers): element data attributes win over these, these win over
|
|
274
281
|
* `init` site-wide defaults. */
|
|
275
282
|
var overrides = /* @__PURE__ */ new WeakMap();
|
|
283
|
+
function emptySlotsValue(value) {
|
|
284
|
+
if (value === void 0) return void 0;
|
|
285
|
+
if (value === "normal" || value === "small" || value === "partial") return value;
|
|
286
|
+
console.warn(`[guidex] ignoring invalid data-empty-slots "${value}"`);
|
|
287
|
+
}
|
|
288
|
+
/** `data-stack`: `all`, or a comma-separated list of stanza numbers. */
|
|
289
|
+
function stackValue(value) {
|
|
290
|
+
if (value === void 0) return void 0;
|
|
291
|
+
if (/^\s*all\s*$/i.test(value)) return "all";
|
|
292
|
+
const list = value.split(",").map((n) => Number(n.trim()));
|
|
293
|
+
if (value.trim() !== "" && list.every((n) => Number.isInteger(n) && n > 0)) return list;
|
|
294
|
+
console.warn(`[guidex] ignoring invalid data-stack "${value}"`);
|
|
295
|
+
}
|
|
276
296
|
/** Element data attributes (or unset) over `renderScore` overrides over
|
|
277
297
|
* init options over defaults. */
|
|
278
298
|
function readOptions(el) {
|
|
@@ -284,6 +304,10 @@ function readOptions(el) {
|
|
|
284
304
|
bold: flag(ds.bold) ?? local.bold ?? globalOptions.bold ?? DEFAULTS.bold,
|
|
285
305
|
textPx: number(ds.textPx) ?? local.textPx ?? globalOptions.textPx ?? DEFAULTS.textPx,
|
|
286
306
|
transpose: number(ds.transpose) ?? local.transpose ?? globalOptions.transpose ?? DEFAULTS.transpose,
|
|
307
|
+
stanza: number(ds.stanza) ?? local.stanza ?? globalOptions.stanza ?? DEFAULTS.stanza,
|
|
308
|
+
stack: stackValue(ds.stack) ?? local.stack ?? globalOptions.stack ?? DEFAULTS.stack,
|
|
309
|
+
emptySlots: emptySlotsValue(ds.emptySlots) ?? local.emptySlots ?? globalOptions.emptySlots ?? DEFAULTS.emptySlots,
|
|
310
|
+
stanzas: local.stanzas ?? DEFAULTS.stanzas,
|
|
287
311
|
debug: flag(ds.debug) ?? local.debug ?? globalOptions.debug ?? DEFAULTS.debug
|
|
288
312
|
};
|
|
289
313
|
}
|
|
@@ -330,47 +354,90 @@ function renderError(wrapper, message) {
|
|
|
330
354
|
note.textContent = message;
|
|
331
355
|
wrapper.replaceChildren(note);
|
|
332
356
|
}
|
|
333
|
-
/** The transforms a score renders with
|
|
334
|
-
* marks the first initial)
|
|
335
|
-
* style name yields no defaults here — the render
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
357
|
+
/** The transforms a score renders with after the stanza swap: the style
|
|
358
|
+
* set's defaults (BNS marks the first initial), then the user-requested
|
|
359
|
+
* transpose. An unknown style name yields no defaults here — the render
|
|
360
|
+
* itself reports it. */
|
|
361
|
+
function scriptTransforms(options) {
|
|
362
|
+
const transforms = [...STYLE_SETS[options.style]?.scriptTransforms ?? []];
|
|
363
|
+
if (options.transpose !== 0) transforms.push(transposeBy(options.transpose));
|
|
339
364
|
return transforms;
|
|
340
365
|
}
|
|
341
|
-
/**
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
366
|
+
/** The scripts a score renders: the stacked stanzas when a stack is set
|
|
367
|
+
* (one text line each), otherwise the one stanza — the stanza swap runs
|
|
368
|
+
* first, so the other transforms see the stanza's text. Returns the
|
|
369
|
+
* rendered stanzas' count mismatches with them. */
|
|
370
|
+
function renderedScripts(source, options) {
|
|
371
|
+
const transforms = scriptTransforms(options);
|
|
372
|
+
const { stanzas, emptySlots } = options;
|
|
373
|
+
if (options.stack !== void 0) {
|
|
374
|
+
const rendered = stackedStanzaNumbers(source, options.stack, { stanzas });
|
|
375
|
+
return {
|
|
376
|
+
scripts: stackStanzas(source, rendered, {
|
|
377
|
+
stanzas,
|
|
378
|
+
emptySlots,
|
|
379
|
+
transforms
|
|
380
|
+
}),
|
|
381
|
+
warnings: rendered.flatMap((stanza) => stanzaWarnings(source, {
|
|
382
|
+
stanzas,
|
|
383
|
+
stanza
|
|
384
|
+
}))
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
if (options.stanza !== 1 || emptySlots !== "normal") transforms.unshift(selectStanza(options.stanza, {
|
|
388
|
+
stanzas,
|
|
389
|
+
emptySlots
|
|
390
|
+
}));
|
|
391
|
+
return {
|
|
392
|
+
scripts: [new GuidoScript(source, { transforms })],
|
|
393
|
+
warnings: stanzaWarnings(source, {
|
|
394
|
+
stanzas,
|
|
395
|
+
stanza: options.stanza
|
|
396
|
+
})
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
/** Builds the score into a detached scratch wrapper and swaps it into
|
|
400
|
+
* the live one only when this run is still the latest — a stale render
|
|
401
|
+
* that finished late leaves no footprint. A failure (a script or stanza
|
|
402
|
+
* error, an unloadable font) replaces the score with an error note.
|
|
403
|
+
* Resolves with the rendered stanza's warnings, also logged. */
|
|
404
|
+
async function drawScore(el, run, source, options, widthPx) {
|
|
351
405
|
const wrapper = scoreWrapper(el);
|
|
352
|
-
const widthPx = resolveWidthPx(el, options.maxWidth, options.style);
|
|
353
|
-
lastWidths.set(el, widthPx);
|
|
354
406
|
const scratch = document.createElement("div");
|
|
355
|
-
const script = new GuidoScript(source, { transforms: scriptTransforms(options.style, options.transpose) });
|
|
356
407
|
try {
|
|
357
|
-
|
|
408
|
+
const { scripts, warnings } = renderedScripts(source, options);
|
|
409
|
+
await new GuidoRender(scripts).render(scratch, {
|
|
358
410
|
style: options.style,
|
|
359
411
|
bold: options.bold,
|
|
360
412
|
textPx: options.textPx,
|
|
361
413
|
debug: options.debug,
|
|
362
414
|
maxWidthPx: widthPx
|
|
363
415
|
});
|
|
364
|
-
if (runs.get(el) !== run) return;
|
|
416
|
+
if (runs.get(el) !== run) return { warnings };
|
|
417
|
+
for (const warning of warnings) console.warn(`[guidex] ${warning.message}`);
|
|
365
418
|
wrapper.replaceChildren(...scratch.childNodes);
|
|
366
419
|
wrapper.style.cssText = scratch.style.cssText;
|
|
367
420
|
if (scratch.dataset.style) wrapper.dataset.style = scratch.dataset.style;
|
|
421
|
+
return { warnings };
|
|
368
422
|
} catch (e) {
|
|
369
|
-
if (runs.get(el) !== run) return;
|
|
423
|
+
if (runs.get(el) !== run) return { warnings: [] };
|
|
370
424
|
console.error("[guidex]", e);
|
|
371
425
|
renderError(wrapper, e instanceof Error ? e.message : String(e));
|
|
426
|
+
return { warnings: [] };
|
|
372
427
|
}
|
|
373
428
|
}
|
|
429
|
+
/** Renders one target element from its source and resolved options. */
|
|
430
|
+
async function renderElement(el) {
|
|
431
|
+
const run = (runs.get(el) ?? 0) + 1;
|
|
432
|
+
runs.set(el, run);
|
|
433
|
+
const options = readOptions(el);
|
|
434
|
+
const source = extractSource(el);
|
|
435
|
+
sources.set(el, source);
|
|
436
|
+
scoreWrapper(el);
|
|
437
|
+
const widthPx = resolveWidthPx(el, options.maxWidth, options.style);
|
|
438
|
+
lastWidths.set(el, widthPx);
|
|
439
|
+
await drawScore(el, run, source, options, widthPx);
|
|
440
|
+
}
|
|
374
441
|
/** Sets up one resize listener per target element, on first render.
|
|
375
442
|
* Only a changed line-breaking budget (width) triggers a re-render. */
|
|
376
443
|
var detachFns = /* @__PURE__ */ new WeakMap();
|
|
@@ -413,36 +480,20 @@ function dispose(el) {
|
|
|
413
480
|
* element's own text content is replaced by the rendered score and
|
|
414
481
|
* re-rendered on resize. Call again with a new source to update.
|
|
415
482
|
* Options set here override `init` defaults; data attributes on the
|
|
416
|
-
* element still win.
|
|
483
|
+
* element still win. `stanzas` replaces the script's `(@stanza …)`
|
|
484
|
+
* statements. Resolves when the score has finished rendering, with the
|
|
485
|
+
* rendered stanza's count mismatches. */
|
|
417
486
|
async function renderScore(el, source, options = {}) {
|
|
418
487
|
overrides.set(el, options);
|
|
419
488
|
const run = (runs.get(el) ?? 0) + 1;
|
|
420
489
|
runs.set(el, run);
|
|
421
490
|
sources.set(el, source);
|
|
422
491
|
const resolved = readOptions(el);
|
|
423
|
-
|
|
492
|
+
scoreWrapper(el);
|
|
424
493
|
const widthPx = resolveWidthPx(el, resolved.maxWidth, resolved.style);
|
|
425
494
|
lastWidths.set(el, widthPx);
|
|
426
495
|
attachResizeListener(el);
|
|
427
|
-
|
|
428
|
-
const script = new GuidoScript(source, { transforms: scriptTransforms(resolved.style, resolved.transpose) });
|
|
429
|
-
try {
|
|
430
|
-
await new GuidoRender(script).render(scratch, {
|
|
431
|
-
style: resolved.style,
|
|
432
|
-
bold: resolved.bold,
|
|
433
|
-
textPx: resolved.textPx,
|
|
434
|
-
debug: resolved.debug,
|
|
435
|
-
maxWidthPx: widthPx
|
|
436
|
-
});
|
|
437
|
-
if (runs.get(el) !== run) return;
|
|
438
|
-
wrapper.replaceChildren(...scratch.childNodes);
|
|
439
|
-
wrapper.style.cssText = scratch.style.cssText;
|
|
440
|
-
if (scratch.dataset.style) wrapper.dataset.style = scratch.dataset.style;
|
|
441
|
-
} catch (e) {
|
|
442
|
-
if (runs.get(el) !== run) return;
|
|
443
|
-
console.error("[guidex]", e);
|
|
444
|
-
renderError(wrapper, e instanceof Error ? e.message : String(e));
|
|
445
|
-
}
|
|
496
|
+
return drawScore(el, run, source, resolved, widthPx);
|
|
446
497
|
}
|
|
447
498
|
/** Renders every target under `root` (default: the whole document).
|
|
448
499
|
* Already-rendered targets re-render from their cached source, so a
|