guidex 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -0
- package/README.md +161 -3
- package/dist/lib/app/StaffSettings.d.ts +1 -0
- package/dist/lib/app/editorState.d.ts +11 -1
- package/dist/lib/{chantLayout-g_xuQ9nD.js → chantLayout-BrCQUOhp.js} +299 -32
- package/dist/lib/chantLayout.d.ts +2 -1
- package/dist/lib/drawnStaff.d.ts +130 -0
- package/dist/lib/editorStorage.d.ts +35 -0
- package/dist/lib/embed/core.d.ts +10 -1
- package/dist/lib/embed/index.js +1 -1
- package/dist/lib/embed/manual.d.ts +3 -0
- package/dist/lib/embed/manual.js +4 -4
- package/dist/lib/fonts/guidohu-staffless.woff2 +0 -0
- package/dist/lib/guidex.css +27 -0
- package/dist/lib/guidoRender.d.ts +11 -1
- package/dist/lib/react/GuidexScore.d.ts +7 -2
- package/dist/lib/react/index.js +39 -4
- package/dist/lib/recitationSegments.d.ts +93 -0
- package/dist/lib/{scoreImage-Dz3c55Zi.js → scoreImage-B2SGdROL.js} +6417 -11
- package/dist/lib/staffGlyphs.d.ts +12 -0
- package/dist/lib/word/index.js +1 -1
- package/dist/lib/{wordChecker-B_9vyTt6.js → wordChecker-CjYl2yof.js} +4 -2
- package/dist/lib/wordExport.d.ts +6 -0
- package/dist-embed/fonts/guidohu-staffless.woff2 +0 -0
- package/dist-embed/guidex-embed.min.css +1 -1
- package/dist-embed/guidex-embed.min.js +1 -1
- package/package.json +3 -2
|
@@ -1426,6 +1426,198 @@ function fontStringsToVerify(styleSet, textPx) {
|
|
|
1426
1426
|
return styleSet.verifiedFonts.map((f) => `${f.weight} ${textPx}px ${f.family}`);
|
|
1427
1427
|
}
|
|
1428
1428
|
//#endregion
|
|
1429
|
+
//#region src/recitationSegments.ts
|
|
1430
|
+
/** The reciting pitch of a note group: one reciting glyph, or one plain
|
|
1431
|
+
* note that has one, optionally after one accidental sign; null for any
|
|
1432
|
+
* other group. */
|
|
1433
|
+
function recitationPitch(notes) {
|
|
1434
|
+
const sign = notes.length === 2 && isModifierGlyph(notes[0]) ? notes[0] : "";
|
|
1435
|
+
const ch = notes.slice(sign.length);
|
|
1436
|
+
if (ch.length !== 1) return null;
|
|
1437
|
+
const family = baseOf(ch);
|
|
1438
|
+
if (family?.role === "longa") return {
|
|
1439
|
+
sign,
|
|
1440
|
+
plain: family.base,
|
|
1441
|
+
glyph: ch,
|
|
1442
|
+
written: "glyph"
|
|
1443
|
+
};
|
|
1444
|
+
const glyph = toLonga(ch);
|
|
1445
|
+
return glyph ? {
|
|
1446
|
+
sign,
|
|
1447
|
+
plain: ch,
|
|
1448
|
+
glyph,
|
|
1449
|
+
written: "plain"
|
|
1450
|
+
} : null;
|
|
1451
|
+
}
|
|
1452
|
+
/** The notes a group renders with in a mode. */
|
|
1453
|
+
function notesInMode(notes, mode) {
|
|
1454
|
+
const pitch = recitationPitch(notes);
|
|
1455
|
+
if (!pitch || mode === "written") return notes;
|
|
1456
|
+
return pitch.sign + (mode === "recite" ? pitch.glyph : pitch.plain);
|
|
1457
|
+
}
|
|
1458
|
+
/** What a mode renders, in written terms: 'recite' or 'plain'. */
|
|
1459
|
+
function shownAs(notes, mode) {
|
|
1460
|
+
if (mode !== "written") return mode;
|
|
1461
|
+
return recitationPitch(notes)?.written === "glyph" ? "recite" : "plain";
|
|
1462
|
+
}
|
|
1463
|
+
/** The decisions' view of a script: its syllables, and where a clef or key
|
|
1464
|
+
* statement stands (a run never continues across one). */
|
|
1465
|
+
function runSyllables(underlays) {
|
|
1466
|
+
const syllables = [];
|
|
1467
|
+
const pitchBreaks = /* @__PURE__ */ new Set();
|
|
1468
|
+
(underlays[0] ?? []).forEach((tok, k) => {
|
|
1469
|
+
if (tok.kind === "clef" || tok.kind === "key") pitchBreaks.add(syllables.length);
|
|
1470
|
+
if (tok.kind !== "syllable") return;
|
|
1471
|
+
const counted = underlays.some((u) => {
|
|
1472
|
+
const own = u[k];
|
|
1473
|
+
return own?.kind === "syllable" && !own.held && !own.empty;
|
|
1474
|
+
});
|
|
1475
|
+
syllables.push({
|
|
1476
|
+
notes: tok.notes,
|
|
1477
|
+
counted
|
|
1478
|
+
});
|
|
1479
|
+
});
|
|
1480
|
+
return {
|
|
1481
|
+
syllables,
|
|
1482
|
+
pitchBreaks
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
/** Whether a syllable can join a recitation run under the options. */
|
|
1486
|
+
function isMember(syl, options) {
|
|
1487
|
+
const pitch = recitationPitch(syl.notes);
|
|
1488
|
+
if (!pitch) return false;
|
|
1489
|
+
return pitch.written === "glyph" || options.plainRunsToRecitation;
|
|
1490
|
+
}
|
|
1491
|
+
/** The run key of a member: its pitch, glyph and plain note alike. */
|
|
1492
|
+
function runKey(notes) {
|
|
1493
|
+
const pitch = recitationPitch(notes);
|
|
1494
|
+
return pitch.sign + pitch.plain;
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* The mode each member is first laid out in: a recitation when its run in
|
|
1498
|
+
* the script counts 3 or more syllables (so the line segments are counted
|
|
1499
|
+
* with the recitation's widths), else as written (a run of 2 or fewer can
|
|
1500
|
+
* only ever need its pair converted).
|
|
1501
|
+
*/
|
|
1502
|
+
function trialModes(syllables, pitchBreaks, options) {
|
|
1503
|
+
const modes = /* @__PURE__ */ new Map();
|
|
1504
|
+
let k = 0;
|
|
1505
|
+
while (k < syllables.length) {
|
|
1506
|
+
if (!isMember(syllables[k], options)) {
|
|
1507
|
+
k++;
|
|
1508
|
+
continue;
|
|
1509
|
+
}
|
|
1510
|
+
const key = runKey(syllables[k].notes);
|
|
1511
|
+
let end = k;
|
|
1512
|
+
let count = 0;
|
|
1513
|
+
while (end < syllables.length && isMember(syllables[end], options) && runKey(syllables[end].notes) === key && (end === k || !pitchBreaks.has(end))) {
|
|
1514
|
+
if (syllables[end].counted) count++;
|
|
1515
|
+
end++;
|
|
1516
|
+
}
|
|
1517
|
+
for (let j = k; j < end; j++) modes.set(j, count >= 3 ? "recite" : "written");
|
|
1518
|
+
k = end;
|
|
1519
|
+
}
|
|
1520
|
+
return modes;
|
|
1521
|
+
}
|
|
1522
|
+
/** Whether a script has anything for the decisions to do. */
|
|
1523
|
+
function hasCandidates(syllables, options) {
|
|
1524
|
+
if (!options.twoSyllableRecitationsToPlain && !options.plainRunsToRecitation) return false;
|
|
1525
|
+
return syllables.some((s) => isMember(s, options));
|
|
1526
|
+
}
|
|
1527
|
+
/** The line segments of a pass: consecutive members on the same line with
|
|
1528
|
+
* the same placed pitch. */
|
|
1529
|
+
function segmentsOf(syllables, placedNotes, sylLines, options) {
|
|
1530
|
+
const segments = [];
|
|
1531
|
+
let current;
|
|
1532
|
+
let currentKey = "";
|
|
1533
|
+
let currentLine = -1;
|
|
1534
|
+
syllables.forEach((syl, k) => {
|
|
1535
|
+
const placed = placedNotes[k];
|
|
1536
|
+
const line = sylLines[k];
|
|
1537
|
+
if (!(isMember(syl, options) && placed !== void 0 && line !== void 0 && recitationPitch(placed) !== null)) {
|
|
1538
|
+
current = void 0;
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
const key = runKey(placed);
|
|
1542
|
+
if (!current || key !== currentKey || line !== currentLine) {
|
|
1543
|
+
current = {
|
|
1544
|
+
members: [],
|
|
1545
|
+
count: 0
|
|
1546
|
+
};
|
|
1547
|
+
segments.push(current);
|
|
1548
|
+
currentKey = key;
|
|
1549
|
+
currentLine = line;
|
|
1550
|
+
}
|
|
1551
|
+
current.members.push(k);
|
|
1552
|
+
if (syl.counted) current.count++;
|
|
1553
|
+
});
|
|
1554
|
+
return segments;
|
|
1555
|
+
}
|
|
1556
|
+
function initialState() {
|
|
1557
|
+
return {
|
|
1558
|
+
decided: /* @__PURE__ */ new Map(),
|
|
1559
|
+
breakBefore: /* @__PURE__ */ new Set(),
|
|
1560
|
+
pending: null
|
|
1561
|
+
};
|
|
1562
|
+
}
|
|
1563
|
+
/** The mode each member renders with in the next pass. */
|
|
1564
|
+
function passModes(trial, state) {
|
|
1565
|
+
const modes = new Map(trial);
|
|
1566
|
+
for (const [k, mode] of state.decided) modes.set(k, mode);
|
|
1567
|
+
return modes;
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1570
|
+
* One step of the decisions over a laid-out pass, from the left: checks the
|
|
1571
|
+
* segment changed in the previous step, then decides segments in order while
|
|
1572
|
+
* the pass already rendered them as decided, and stops at the first one
|
|
1573
|
+
* whose decision changes what the pass rendered. Returns whether another
|
|
1574
|
+
* pass is needed.
|
|
1575
|
+
*
|
|
1576
|
+
* Every pass lays the score out left to right, so a decision only moves
|
|
1577
|
+
* what comes after it: the segments decided before it stay where they
|
|
1578
|
+
* were. A segment is counted on the line the pass put it on, and a change
|
|
1579
|
+
* keeps it there: one that opened its line still opens it (as plain notes
|
|
1580
|
+
* it might fit the line before), and a member that no longer fits its line
|
|
1581
|
+
* in the new form (a pair turned plain is wider than its recitation) opens
|
|
1582
|
+
* the next one and is decided again there, the members before it keeping
|
|
1583
|
+
* their written form.
|
|
1584
|
+
*/
|
|
1585
|
+
function decideStep(syllables, placedNotes, sylLines, modes, state, options) {
|
|
1586
|
+
if (state.pending) {
|
|
1587
|
+
const { members, line } = state.pending;
|
|
1588
|
+
state.pending = null;
|
|
1589
|
+
const moved = members.findIndex((k) => sylLines[k] !== line);
|
|
1590
|
+
if (moved >= 0) {
|
|
1591
|
+
members.forEach((k, j) => {
|
|
1592
|
+
if (j < moved) state.decided.set(k, "written");
|
|
1593
|
+
else state.decided.delete(k);
|
|
1594
|
+
});
|
|
1595
|
+
state.breakBefore.add(members[moved]);
|
|
1596
|
+
return true;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
for (const segment of segmentsOf(syllables, placedNotes, sylLines, options)) {
|
|
1600
|
+
if (segment.members.every((k) => state.decided.has(k))) continue;
|
|
1601
|
+
const target = segment.count >= 3 ? "recite" : segment.count === 2 && options.twoSyllableRecitationsToPlain ? "plain" : "written";
|
|
1602
|
+
const changes = segment.members.some((k) => {
|
|
1603
|
+
const notes = syllables[k].notes;
|
|
1604
|
+
return shownAs(notes, modes.get(k) ?? "written") !== shownAs(notes, target);
|
|
1605
|
+
});
|
|
1606
|
+
for (const k of segment.members) state.decided.set(k, target);
|
|
1607
|
+
if (changes) {
|
|
1608
|
+
const first = segment.members[0];
|
|
1609
|
+
const line = sylLines[first];
|
|
1610
|
+
if (first > 0 && (sylLines[first - 1] ?? -1) < line) state.breakBefore.add(first);
|
|
1611
|
+
state.pending = {
|
|
1612
|
+
members: segment.members,
|
|
1613
|
+
line
|
|
1614
|
+
};
|
|
1615
|
+
return true;
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
return false;
|
|
1619
|
+
}
|
|
1620
|
+
//#endregion
|
|
1429
1621
|
//#region src/chantLayout.ts
|
|
1430
1622
|
/**
|
|
1431
1623
|
* Special reciting notes: when such a note stands alone in a note group it
|
|
@@ -1618,12 +1810,51 @@ function silent(tok) {
|
|
|
1618
1810
|
* fonts cannot be loaded.
|
|
1619
1811
|
*/
|
|
1620
1812
|
async function layoutScore(source, options = {}) {
|
|
1813
|
+
const recitation = {
|
|
1814
|
+
twoSyllableRecitationsToPlain: options.twoSyllableRecitationsToPlain ?? true,
|
|
1815
|
+
plainRunsToRecitation: options.plainRunsToRecitation ?? false
|
|
1816
|
+
};
|
|
1817
|
+
const { syllables, pitchBreaks } = runSyllables(underlayTokens(source));
|
|
1818
|
+
if (!hasCandidates(syllables, recitation)) return (await layoutKept(source, options, NO_RECITATION)).result;
|
|
1819
|
+
const trial = trialModes(syllables, pitchBreaks, recitation);
|
|
1820
|
+
const state = initialState();
|
|
1821
|
+
for (let step = 0;; step++) {
|
|
1822
|
+
const modes = passModes(trial, state);
|
|
1823
|
+
const pass = await layoutKept(source, options, {
|
|
1824
|
+
notes: notesOverrides(syllables.map((s) => s.notes), modes),
|
|
1825
|
+
breakBefore: state.breakBefore
|
|
1826
|
+
});
|
|
1827
|
+
if (step > 4 * syllables.length + 8 || !decideStep(syllables, pass.placedNotes, pass.sylLines, modes, state, recitation)) return pass.result;
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
/** The notes each syllable renders with under the recitation modes, where
|
|
1831
|
+
* they differ from the written ones. */
|
|
1832
|
+
function notesOverrides(written, modes) {
|
|
1833
|
+
const notes = /* @__PURE__ */ new Map();
|
|
1834
|
+
for (const [k, mode] of modes) {
|
|
1835
|
+
const shown = notesInMode(written[k], mode);
|
|
1836
|
+
if (shown !== written[k]) notes.set(k, shown);
|
|
1837
|
+
}
|
|
1838
|
+
return notes;
|
|
1839
|
+
}
|
|
1840
|
+
var NO_RECITATION = {
|
|
1841
|
+
notes: /* @__PURE__ */ new Map(),
|
|
1842
|
+
breakBefore: /* @__PURE__ */ new Set()
|
|
1843
|
+
};
|
|
1844
|
+
/** One layout with its `(@keep)` runs settled: a run is only known to fit
|
|
1845
|
+
* once it is placed, pads and group splits included, so a run that ends up
|
|
1846
|
+
* split is retried with a break before it. One wider than a fresh line
|
|
1847
|
+
* stops counting: a flat run wraps where it stood, and a run with inner
|
|
1848
|
+
* runs dissolves into them but keeps its break, so the boundary between
|
|
1849
|
+
* pairs still wins over the one between verses. Runs number in opening
|
|
1850
|
+
* order, so the lowest split is the leftmost and outermost. */
|
|
1851
|
+
async function layoutKept(source, options, recitation) {
|
|
1621
1852
|
const breakBefore = /* @__PURE__ */ new Set();
|
|
1622
1853
|
const wraps = /* @__PURE__ */ new Set();
|
|
1623
1854
|
for (;;) {
|
|
1624
|
-
const
|
|
1625
|
-
const open = splitRuns.filter((r) => !wraps.has(r.run));
|
|
1626
|
-
if (open.length === 0) return
|
|
1855
|
+
const pass = await layoutPass(source, options, breakBefore, recitation);
|
|
1856
|
+
const open = pass.splitRuns.filter((r) => !wraps.has(r.run));
|
|
1857
|
+
if (open.length === 0) return pass;
|
|
1627
1858
|
const split = open.reduce((a, b) => b.run < a.run ? b : a);
|
|
1628
1859
|
if (breakBefore.has(split.run) || split.atLineStart) {
|
|
1629
1860
|
wraps.add(split.run);
|
|
@@ -1634,8 +1865,9 @@ async function layoutScore(source, options = {}) {
|
|
|
1634
1865
|
}
|
|
1635
1866
|
/** One pass of `layoutScore`: `breakBefore` lists the `(@keep)` runs (by
|
|
1636
1867
|
* position in the script) that open a fresh line; `splitRuns` reports the
|
|
1637
|
-
* ones that crossed a line break.
|
|
1638
|
-
|
|
1868
|
+
* ones that crossed a line break. `recitation` carries the recitation
|
|
1869
|
+
* segments' forms and breaks (issue #21). */
|
|
1870
|
+
async function layoutPass(source, options, breakBefore, recitation = NO_RECITATION) {
|
|
1639
1871
|
const { style: styleName = "BNS", marks, bold = false, textPx = 18, notesPx = textPx * 2, maxWidthPx = Infinity, junctionDashes = 3, staffFill = "all-but-last", staffFillSnapPx = 0 } = options;
|
|
1640
1872
|
if (!STAFF_FILLS.includes(staffFill)) throw new Error(`Unknown staffFill: "${staffFill}"`);
|
|
1641
1873
|
if (!(staffFillSnapPx >= 0 && Number.isFinite(staffFillSnapPx))) throw new Error(`staffFillSnapPx must be zero or more: ${staffFillSnapPx}`);
|
|
@@ -1748,11 +1980,12 @@ async function layoutPass(source, options, breakBefore) {
|
|
|
1748
1980
|
if (tightDepth === 0) tightGroupPlaced = false;
|
|
1749
1981
|
}
|
|
1750
1982
|
} else {
|
|
1983
|
+
const i = sylIndex++;
|
|
1751
1984
|
const item = {
|
|
1752
1985
|
kind: "syl",
|
|
1753
1986
|
syl: tok,
|
|
1754
|
-
i
|
|
1755
|
-
notes: tok.notes,
|
|
1987
|
+
i,
|
|
1988
|
+
notes: recitation.notes.get(i) ?? tok.notes,
|
|
1756
1989
|
inserted: [],
|
|
1757
1990
|
first: true,
|
|
1758
1991
|
lastSeg: true,
|
|
@@ -1849,8 +2082,15 @@ async function layoutPass(source, options, breakBefore) {
|
|
|
1849
2082
|
const run = keepStack.pop();
|
|
1850
2083
|
if (run && lines.length - 1 > run.line) splitRuns.push(run);
|
|
1851
2084
|
};
|
|
2085
|
+
const sylLines = [];
|
|
2086
|
+
let placedSyl = -1;
|
|
2087
|
+
const notePlacedLine = () => {
|
|
2088
|
+
if (placedSyl >= 0) sylLines[placedSyl] = lines.length - 1;
|
|
2089
|
+
placedSyl = -1;
|
|
2090
|
+
};
|
|
1852
2091
|
let idx = 0;
|
|
1853
2092
|
while (idx < items.length) {
|
|
2093
|
+
notePlacedLine();
|
|
1854
2094
|
const item = items[idx];
|
|
1855
2095
|
if (item.kind === "break") {
|
|
1856
2096
|
if (line.texts.some((x) => x.segments.length > 0) || tracks.some((t) => t.pending.length > 0)) {
|
|
@@ -1909,6 +2149,11 @@ async function layoutPass(source, options, breakBefore) {
|
|
|
1909
2149
|
}
|
|
1910
2150
|
const syl = item.syl;
|
|
1911
2151
|
const i = item.i;
|
|
2152
|
+
if (item.first) placedSyl = i;
|
|
2153
|
+
if (item.first && recitation.breakBefore.has(i) && (line.texts.some((x) => x.segments.length > 0) || tracks.some((t) => t.pending.length > 0))) {
|
|
2154
|
+
flushPending(false);
|
|
2155
|
+
forceBreak = true;
|
|
2156
|
+
}
|
|
1912
2157
|
if (forceBreak) {
|
|
1913
2158
|
startLine();
|
|
1914
2159
|
forceBreak = false;
|
|
@@ -2051,38 +2296,48 @@ async function layoutPass(source, options, breakBefore) {
|
|
|
2051
2296
|
};
|
|
2052
2297
|
};
|
|
2053
2298
|
let placed = place();
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
}
|
|
2067
|
-
}
|
|
2068
|
-
if (line.notesParts.length === 0 && tracks.every((t) => t.cursor === 0)) {
|
|
2299
|
+
const uncut = {
|
|
2300
|
+
notes: item.notes,
|
|
2301
|
+
inserted: item.inserted,
|
|
2302
|
+
lastSeg: item.lastSeg,
|
|
2303
|
+
forceBreak,
|
|
2304
|
+
items: items.length
|
|
2305
|
+
};
|
|
2306
|
+
const fit = () => {
|
|
2307
|
+
for (;;) {
|
|
2308
|
+
const notesOver = measure(notesSoFar + junctionPrefix + item.notes, notesFont) > maxWidthPx;
|
|
2309
|
+
const textOver = voiced.some((s) => placed.textStartOf(s.textWidth) + s.textWidth + (s.own.wordEnd ? 0 : hyphenOf(s.own.hyphen).width) > maxWidthPx);
|
|
2310
|
+
if (!notesOver && !textOver) break;
|
|
2069
2311
|
if (notesOver) {
|
|
2070
|
-
const cut = findBreakCut(item.notes, maxWidthPx, (prefix) => measure(notesSoFar + prefix, notesFont));
|
|
2312
|
+
const cut = findBreakCut(item.notes, maxWidthPx, (prefix) => measure(notesSoFar + junctionPrefix + prefix, notesFont));
|
|
2071
2313
|
if (cut >= 0 && cut + 1 < item.notes.length) {
|
|
2072
2314
|
const rest = applyBreakCut(item, cut);
|
|
2073
|
-
item.notes = item.notes.slice(0, cut);
|
|
2074
2315
|
queueContinuation(item, idx, rest);
|
|
2075
2316
|
parts = splitNoteMarkers(item.notes);
|
|
2076
2317
|
placed = place();
|
|
2318
|
+
break;
|
|
2077
2319
|
}
|
|
2078
2320
|
}
|
|
2079
|
-
|
|
2321
|
+
if (line.notesParts.length === 0 && tracks.every((t) => t.cursor === 0)) {
|
|
2322
|
+
if (notesOver) {
|
|
2323
|
+
const cut = findBreakCut(item.notes, maxWidthPx, (prefix) => measure(notesSoFar + prefix, notesFont));
|
|
2324
|
+
if (cut >= 0 && cut + 1 < item.notes.length) {
|
|
2325
|
+
const rest = applyBreakCut(item, cut);
|
|
2326
|
+
item.notes = item.notes.slice(0, cut);
|
|
2327
|
+
queueContinuation(item, idx, rest);
|
|
2328
|
+
parts = splitNoteMarkers(item.notes);
|
|
2329
|
+
placed = place();
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
break;
|
|
2333
|
+
}
|
|
2334
|
+
startLine();
|
|
2335
|
+
junctionPrefix = "";
|
|
2336
|
+
parts = splitNoteMarkers(item.notes);
|
|
2337
|
+
placed = place();
|
|
2080
2338
|
}
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
parts = splitNoteMarkers(item.notes);
|
|
2084
|
-
placed = place();
|
|
2085
|
-
}
|
|
2339
|
+
};
|
|
2340
|
+
fit();
|
|
2086
2341
|
const decide = (s) => {
|
|
2087
2342
|
const { t, textWidth } = s;
|
|
2088
2343
|
const { contentWidth } = placed;
|
|
@@ -2174,10 +2429,19 @@ async function layoutPass(source, options, breakBefore) {
|
|
|
2174
2429
|
if (line.notesParts.length > 0 && (measure(notesSoFar + junctionPrefix + "-".repeat(padDashes) + item.notes, notesFont) > maxWidthPx || voiced.some((s, v) => {
|
|
2175
2430
|
return Math.max(placements[v].textStart, s.t.cursor + s.pendingTotal) + s.textWidth + (s.own.wordEnd ? 0 : hyphenOf(s.own.hyphen).width) > maxWidthPx;
|
|
2176
2431
|
}))) {
|
|
2432
|
+
const recut = items.length > uncut.items;
|
|
2433
|
+
if (recut) {
|
|
2434
|
+
items.splice(idx + 1, items.length - uncut.items);
|
|
2435
|
+
item.notes = uncut.notes;
|
|
2436
|
+
item.inserted = uncut.inserted;
|
|
2437
|
+
item.lastSeg = uncut.lastSeg;
|
|
2438
|
+
forceBreak = uncut.forceBreak;
|
|
2439
|
+
}
|
|
2177
2440
|
startLine();
|
|
2178
2441
|
junctionPrefix = "";
|
|
2179
2442
|
parts = splitNoteMarkers(item.notes);
|
|
2180
2443
|
placed = place();
|
|
2444
|
+
if (recut) fit();
|
|
2181
2445
|
settle();
|
|
2182
2446
|
}
|
|
2183
2447
|
}
|
|
@@ -2271,6 +2535,7 @@ async function layoutPass(source, options, breakBefore) {
|
|
|
2271
2535
|
if (!item.lastSeg) forceBreak = true;
|
|
2272
2536
|
idx++;
|
|
2273
2537
|
}
|
|
2538
|
+
notePlacedLine();
|
|
2274
2539
|
flushPending(true);
|
|
2275
2540
|
while (keepStack.length > 0) closeKeepRun();
|
|
2276
2541
|
tracks.forEach((t, u) => {
|
|
@@ -2342,8 +2607,10 @@ async function layoutPass(source, options, breakBefore) {
|
|
|
2342
2607
|
starTarget,
|
|
2343
2608
|
starWidth
|
|
2344
2609
|
},
|
|
2345
|
-
splitRuns
|
|
2610
|
+
splitRuns,
|
|
2611
|
+
placedNotes,
|
|
2612
|
+
sylLines
|
|
2346
2613
|
};
|
|
2347
2614
|
}
|
|
2348
2615
|
//#endregion
|
|
2349
|
-
export { CLEF_GLYPHS as A,
|
|
2616
|
+
export { CLEF_GLYPHS as A, toCephalicus as B, scriptSyllables as C, resolveSpans as D, unescape as E, isModifierGlyph as F, toVirga as G, toLonga as H, modifyDown as I, variantOf as K, modifyNatural as L, baseOf as M, gClefPitchOf as N, SCORE_MARKERS as O, isClefGlyph as P, modifyUp as R, runProperties as S, syllableText as T, toSmallHead as U, toConnectDown as V, toSmallPoint as W, GuidoScript as _, DEFAULT_STYLE_SET as a, isC4ClefGroup as b, defineStyleSet as c, measurementFont as d, resolveMarks as f, unknownMarks as g, styleSetOf as h, measure as i, STAFF as j, splitNoteMarkers as k, inlineStylesFor as l, resolveTextRuns as m, SPECIAL_NOTES as n, SMALL_CAP_SCALE as o, resolveSyllableParts as p, layoutScore as r, STYLE_SETS as s, NOTE_MODIFIERS as t, kindOf as u, chantText as v, statementSource as w, isStatementGroup as x, escape as y, pitchLetterOf as z };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GuidoScript } from './guidoScript';
|
|
2
2
|
import { SCORE_MARKERS } from './noteGroups';
|
|
3
3
|
import { StyleSet, MarkDefinitions, StyleSetName, SyllablePart } from './guidoStyles';
|
|
4
|
+
import { RecitationOptions } from './recitationSegments';
|
|
4
5
|
export { SCORE_MARKERS };
|
|
5
6
|
/**
|
|
6
7
|
* Special reciting notes: when such a note stands alone in a note group it
|
|
@@ -31,7 +32,7 @@ export type StaffFill = 'all-but-last' | 'none' | 'all' | 'longest';
|
|
|
31
32
|
export declare const STAFF_FILLS: readonly StaffFill[];
|
|
32
33
|
/** Options for one layout pass. All fields optional; defaults reproduce the
|
|
33
34
|
* original Book Antiqua look (style set BNS). */
|
|
34
|
-
export interface LayoutOptions {
|
|
35
|
+
export interface LayoutOptions extends RecitationOptions {
|
|
35
36
|
/** Named style set (default: BNS) */
|
|
36
37
|
style?: StyleSetName;
|
|
37
38
|
/** Marks this score adds to its style set's */
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** How the staff is drawn: by the font (Guido HU's own lines, the default)
|
|
2
|
+
* or as elements behind the staffless font. */
|
|
3
|
+
export type StaffMode = 'font' | 'drawn';
|
|
4
|
+
/** A staff line color: any CSS color (alpha included), or one for the light
|
|
5
|
+
* and one for the dark color scheme. */
|
|
6
|
+
export type StaffColor = string | {
|
|
7
|
+
readonly light: string;
|
|
8
|
+
readonly dark?: string;
|
|
9
|
+
};
|
|
10
|
+
export type PitchLetter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g';
|
|
11
|
+
/** The drawn staff's options (render, embed and React). */
|
|
12
|
+
export interface DrawnStaffOptions {
|
|
13
|
+
/** How the staff is drawn (default `font`); every option below needs `drawn` */
|
|
14
|
+
staff?: StaffMode;
|
|
15
|
+
/** The fewest lines to draw, 1–5 (default 5). The lines sit where the
|
|
16
|
+
* score's notes and clefs need them, and more are drawn when a note
|
|
17
|
+
* would otherwise need a ledger line (or a clef has no line to sit on). */
|
|
18
|
+
staffLines?: number;
|
|
19
|
+
/** Every drawn line's color (default: the notes' text color) */
|
|
20
|
+
staffColor?: StaffColor;
|
|
21
|
+
/** Colors by position, bottom line first; wins over `staffColor` */
|
|
22
|
+
staffLineColors?: readonly (StaffColor | null | undefined)[];
|
|
23
|
+
/** Colors by the pitch a line carries under the clef in effect (the
|
|
24
|
+
* historical red F and yellow C lines); wins over the others */
|
|
25
|
+
staffPitchColors?: Readonly<Partial<Record<PitchLetter, StaffColor>>>;
|
|
26
|
+
/** Every drawn line's thickness as a multiple of the font's (default 1).
|
|
27
|
+
* The weights multiply: all × by position × clef line. */
|
|
28
|
+
staffWeight?: number;
|
|
29
|
+
/** Thickness multipliers by position, bottom line first (default 1) */
|
|
30
|
+
staffLineWeights?: readonly (number | null | undefined)[];
|
|
31
|
+
/** Thickness multiplier of the line the clef in effect sits on, which
|
|
32
|
+
* follows inline clef changes (default 1): above 1, the clef's line
|
|
33
|
+
* stands out from the others */
|
|
34
|
+
staffClefLineWeight?: number;
|
|
35
|
+
/** Run every drawn line past the score: `start` is where the lines begin
|
|
36
|
+
* and `end` where they end, in px from the notes line's left edge (a
|
|
37
|
+
* negative `start` reaches left of it). A line already longer keeps its
|
|
38
|
+
* own ends. Nothing is resized: the lines just overflow the score (and
|
|
39
|
+
* its container), so the host decides how far, e.g. to the screen's
|
|
40
|
+
* edges, and whether a scrolling ancestor clips them. */
|
|
41
|
+
staffOverflow?: StaffOverflow;
|
|
42
|
+
/** Snap the lines to device pixels after a render (default true) */
|
|
43
|
+
staffSnap?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** How far the drawn lines run past the score (`DrawnStaffOptions.staffOverflow`). */
|
|
46
|
+
export interface StaffOverflow {
|
|
47
|
+
start?: number;
|
|
48
|
+
end?: number;
|
|
49
|
+
}
|
|
50
|
+
/** The staffless font's family, as the notes line's font stack names it. */
|
|
51
|
+
export declare const STAFFLESS_FONT_FAMILY = "'Guidohu Staffless'";
|
|
52
|
+
export declare const STAFF_LINE_COUNT: number;
|
|
53
|
+
/** The drawn lines, as line indices (0 = bottom) `lo`…`hi`. */
|
|
54
|
+
export interface StaffLineRange {
|
|
55
|
+
lo: number;
|
|
56
|
+
hi: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The lines to draw for a score: the lowest run of at least `fewest` lines
|
|
60
|
+
* that carries every note and clef without a ledger line. A note on a line
|
|
61
|
+
* needs that line; a note in a space needs a line next to it (a space just
|
|
62
|
+
* outside the outermost line is fine); a clef needs its line. A note beyond
|
|
63
|
+
* the five lines brings its ledger lines with the glyph, so the staff then
|
|
64
|
+
* runs to the outermost line. When the notes need more lines than `fewest`,
|
|
65
|
+
* more are drawn.
|
|
66
|
+
*/
|
|
67
|
+
export declare function chooseStaffLines(lines: readonly {
|
|
68
|
+
clefPrefix: string;
|
|
69
|
+
notesParts: readonly string[];
|
|
70
|
+
}[], fewest?: number): StaffLineRange;
|
|
71
|
+
/** The color a line takes under `clef` (a clef glyph), or undefined for
|
|
72
|
+
* the default (the notes' text color). */
|
|
73
|
+
export declare function staffLineColor(index: number, clef: string, options: DrawnStaffOptions): StaffColor | undefined;
|
|
74
|
+
/** A line's thickness multiplier under `clef`: all lines × its position ×
|
|
75
|
+
* the clef's own line. */
|
|
76
|
+
export declare function staffLineWeight(index: number, clef: string, options: DrawnStaffOptions): number;
|
|
77
|
+
/** One stretch of a drawn line, in px from the notes line's start. */
|
|
78
|
+
export interface StaffSpan {
|
|
79
|
+
line: number;
|
|
80
|
+
left: number;
|
|
81
|
+
right: number;
|
|
82
|
+
color: StaffColor | undefined;
|
|
83
|
+
/** Thickness multiplier (1 = the font's line) */
|
|
84
|
+
weight: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The drawn line stretches of one notes line: `text` as the notes line holds
|
|
88
|
+
* it (clef prefix and notes), plus the break marker `*` when it stands
|
|
89
|
+
* `breakMarkerLeftPx` past the text. Each line index in `range` is one span
|
|
90
|
+
* per run of glyphs with the same color and weight, which change at an
|
|
91
|
+
* inline clef.
|
|
92
|
+
*/
|
|
93
|
+
export declare function staffSpans(text: string, notesPx: number, range: StaffLineRange, options?: DrawnStaffOptions, breakMarkerLeftPx?: number): StaffSpan[];
|
|
94
|
+
/**
|
|
95
|
+
* The drawn staff of one notes line: a zero-size anchor on the baseline at
|
|
96
|
+
* the line's start, holding one absolutely placed span per stretch. Heights
|
|
97
|
+
* and offsets are in em of the notes font, so the lines sit right without
|
|
98
|
+
* measuring; `snapStaff` then aligns them to device pixels. A weighted line
|
|
99
|
+
* grows from the font line's centre. The spans sit at `z-index: -1`, so the
|
|
100
|
+
* notes paint over them once the notes line is its own stacking context
|
|
101
|
+
* (`isolation: isolate`, which GuidoRender sets).
|
|
102
|
+
*/
|
|
103
|
+
export declare function staffLayer(spans: readonly StaffSpan[]): HTMLSpanElement;
|
|
104
|
+
/**
|
|
105
|
+
* Aligns every drawn staff line under `root` to device pixels: each line's
|
|
106
|
+
* thickness is rounded to whole device pixels (at least one) and its edges
|
|
107
|
+
* land on pixel boundaries, so every line draws as one even, sharp stroke.
|
|
108
|
+
* Needs `root` in the document; call it again after the score moves by a
|
|
109
|
+
* fraction of a pixel (a render calls it, and so does the embed's resize
|
|
110
|
+
* re-render).
|
|
111
|
+
*/
|
|
112
|
+
export declare function snapStaff(root: ParentNode): void;
|
|
113
|
+
/**
|
|
114
|
+
* A staff color written as text (data attributes, settings): one CSS color,
|
|
115
|
+
* or `light|dark`. Empty → undefined; an invalid color warns and gives
|
|
116
|
+
* undefined.
|
|
117
|
+
*/
|
|
118
|
+
export declare function parseStaffColor(text: string | undefined, label?: string): StaffColor | undefined;
|
|
119
|
+
/** Colors by position as text: up to five colors (`light|dark` each),
|
|
120
|
+
* bottom line first, separated by `;` (an empty entry keeps the default). */
|
|
121
|
+
export declare function parseStaffLineColors(text: string | undefined): (StaffColor | undefined)[] | undefined;
|
|
122
|
+
/** Colors by pitch as text: `c: gold; f: #d40000|#ff6060`. */
|
|
123
|
+
export declare function parseStaffPitchColors(text: string | undefined): Partial<Record<PitchLetter, StaffColor>> | undefined;
|
|
124
|
+
/** A weight written as text: a positive number, else undefined (warns). */
|
|
125
|
+
export declare function parseStaffWeight(text: string | undefined, label?: string): number | undefined;
|
|
126
|
+
/** Weights by position as text: up to five numbers, bottom line first,
|
|
127
|
+
* separated by `;` (an empty entry keeps 1). */
|
|
128
|
+
export declare function parseStaffLineWeights(text: string | undefined): (number | undefined)[] | undefined;
|
|
129
|
+
/** The text form of a staff color (`light|dark`), the inverse of `parseStaffColor`. */
|
|
130
|
+
export declare function formatStaffColor(color: StaffColor | undefined): string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StaffFill } from './chantLayout';
|
|
2
2
|
import { StyleSetName } from './guidoStyles';
|
|
3
3
|
import { SpacerChar } from './wordExport';
|
|
4
|
+
import { StaffMode } from './drawnStaff';
|
|
4
5
|
/** Versioned localStorage key; an unknown version is ignored wholesale. */
|
|
5
6
|
export declare const EDITOR_STORAGE_KEY = "guidex.editor.v1";
|
|
6
7
|
export declare const EDITOR_SCHEMA_VERSION = 1;
|
|
@@ -24,6 +25,11 @@ export declare const JUNCTION_DASHES_MIN = 1;
|
|
|
24
25
|
export declare const JUNCTION_DASHES_MAX = 8;
|
|
25
26
|
export declare const STAFF_FILL_SNAP_MIN = 0;
|
|
26
27
|
export declare const STAFF_FILL_SNAP_MAX = 60;
|
|
28
|
+
export declare const STAFF_LINES_MIN = 1;
|
|
29
|
+
export declare const STAFF_LINES_MAX = 5;
|
|
30
|
+
/** The staff weight sliders' range (a multiple of the font's line). */
|
|
31
|
+
export declare const STAFF_WEIGHT_MIN = 0.5;
|
|
32
|
+
export declare const STAFF_WEIGHT_MAX = 4;
|
|
27
33
|
export declare const TRANSPOSE_MIN = -6;
|
|
28
34
|
export declare const TRANSPOSE_MAX = 6;
|
|
29
35
|
/** The destination Word text size default (notes ride at twice it) and the
|
|
@@ -63,6 +69,25 @@ export interface EditorSettings {
|
|
|
63
69
|
staffFill: StaffFill;
|
|
64
70
|
/** With `longest`: the distance from the max width that snaps to it. */
|
|
65
71
|
staffFillSnapPx: number;
|
|
72
|
+
/** Two-syllable recitations as plain notes (issue #21). */
|
|
73
|
+
twoSyllableRecitationsToPlain: boolean;
|
|
74
|
+
/** Three or more plain notes on a line as a recitation (issue #21). */
|
|
75
|
+
plainRunsToRecitation: boolean;
|
|
76
|
+
/** The drawn staff: mode, fewest lines and its colors as text
|
|
77
|
+
* (`light|dark` colors, `;`-separated lists — the embed's attribute syntax). */
|
|
78
|
+
staff: StaffMode;
|
|
79
|
+
staffLines: number;
|
|
80
|
+
staffColor: string;
|
|
81
|
+
staffLineColors: string;
|
|
82
|
+
staffPitchColors: string;
|
|
83
|
+
/** Line thickness multipliers: all lines, by position (`;` list), and
|
|
84
|
+
* the clef's own line. */
|
|
85
|
+
staffWeight: number;
|
|
86
|
+
staffLineWeights: string;
|
|
87
|
+
staffClefLineWeight: number;
|
|
88
|
+
/** The preview's drawn lines run to the screen's edges (a page
|
|
89
|
+
* setting: not part of a saved chant or a share link). */
|
|
90
|
+
staffToEdges: boolean;
|
|
66
91
|
customColors: boolean;
|
|
67
92
|
colorFg: string;
|
|
68
93
|
colorAccent: string;
|
|
@@ -158,6 +183,16 @@ export interface ChantPrefs {
|
|
|
158
183
|
junctionDashes: number;
|
|
159
184
|
staffFill: StaffFill;
|
|
160
185
|
staffFillSnapPx: number;
|
|
186
|
+
twoSyllableRecitationsToPlain: boolean;
|
|
187
|
+
plainRunsToRecitation: boolean;
|
|
188
|
+
staff: StaffMode;
|
|
189
|
+
staffLines: number;
|
|
190
|
+
staffColor: string;
|
|
191
|
+
staffLineColors: string;
|
|
192
|
+
staffPitchColors: string;
|
|
193
|
+
staffWeight: number;
|
|
194
|
+
staffLineWeights: string;
|
|
195
|
+
staffClefLineWeight: number;
|
|
161
196
|
transpose: number;
|
|
162
197
|
}
|
|
163
198
|
export interface SavedChant {
|
package/dist/lib/embed/core.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EmptySlots, StanzaStack, StanzaWarning } from '../stanzas';
|
|
2
2
|
import { MarkWarning } from '../chantMarkup';
|
|
3
|
+
import { DrawnStaffOptions } from '../drawnStaff';
|
|
3
4
|
import { SpanProblem } from '../textMarkup';
|
|
4
5
|
import { StaffFill } from '../chantLayout';
|
|
5
6
|
import { MarkDefinitions, StyleSetName } from '../guidoStyles';
|
|
@@ -11,7 +12,7 @@ export declare const version: string;
|
|
|
11
12
|
* (`overflow-x: auto` to scroll, `hidden` to clip). */
|
|
12
13
|
export type MaxWidth = number | 'auto';
|
|
13
14
|
/** Site-wide defaults, settable through `GuidexEmbed.init`. */
|
|
14
|
-
export interface EmbedOptions {
|
|
15
|
+
export interface EmbedOptions extends DrawnStaffOptions {
|
|
15
16
|
/** Selector for target elements (default '.guidex-script, .guido-script') */
|
|
16
17
|
selector?: string;
|
|
17
18
|
maxWidth?: MaxWidth;
|
|
@@ -27,6 +28,14 @@ export interface EmbedOptions {
|
|
|
27
28
|
/** With `staffFill: 'longest'`: the distance from the available width
|
|
28
29
|
* within which every line runs to it instead (default 0) */
|
|
29
30
|
staffFillSnapPx?: number;
|
|
31
|
+
/** Render a recitation that covers exactly 2 syllables on a line as
|
|
32
|
+
* plain notes of the same pitch (default true, issue #21;
|
|
33
|
+
* `data-two-syllable-recitations-to-plain`) */
|
|
34
|
+
twoSyllableRecitationsToPlain?: boolean;
|
|
35
|
+
/** Render 3 or more syllables on one plain note with a reciting glyph
|
|
36
|
+
* (`1`–`9`, `ö`, `ü`) on a line as a recitation (default false;
|
|
37
|
+
* `data-plain-runs-to-recitation`) */
|
|
38
|
+
plainRunsToRecitation?: boolean;
|
|
30
39
|
transpose?: number;
|
|
31
40
|
/** The stanza sung under the notes (1-based; 1 is the script's own
|
|
32
41
|
* text, 2… its `(@stanza …)` statements or the `stanzas` option). */
|
package/dist/lib/embed/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as dispose, c as renderScore, i as scoreSvg, l as version, n as downloadScoreSvg, o as init, r as scorePngBlob, s as renderAll, t as downloadScorePng } from "../scoreImage-
|
|
1
|
+
import { a as dispose, c as renderScore, i as scoreSvg, l as version, n as downloadScoreSvg, o as init, r as scorePngBlob, s as renderAll, t as downloadScorePng } from "../scoreImage-B2SGdROL.js";
|
|
2
2
|
//#region src/embed/index.ts
|
|
3
3
|
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", () => init(), { once: true });
|
|
4
4
|
else init();
|