vexflow 5.2.0 → 5.4.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/README.md +2 -0
- package/build/cjs/vexflow-bravura.js +2 -2
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +2 -2
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +6502 -1708
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +5622 -1618
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/accidental.js +10 -3
- package/build/esm/src/alternatingtremolo.js +68 -0
- package/build/esm/src/annotation.js +19 -3
- package/build/esm/src/articulation.js +28 -6
- package/build/esm/src/beam.js +171 -28
- package/build/esm/src/bend.js +79 -23
- package/build/esm/src/clef.js +3 -0
- package/build/esm/src/continuouslayout.js +681 -0
- package/build/esm/src/continuousspan.js +159 -0
- package/build/esm/src/curve.js +48 -55
- package/build/esm/src/dot.js +13 -4
- package/build/esm/src/easyscore/composition.js +52 -2
- package/build/esm/src/easyscore/policies.js +39 -8
- package/build/esm/src/element.js +4 -0
- package/build/esm/src/engravinggeometry.js +157 -0
- package/build/esm/src/engravingprofile.js +44 -0
- package/build/esm/src/factory.js +31 -11
- package/build/esm/src/font.js +9 -1
- package/build/esm/src/formatter.js +9 -1
- package/build/esm/src/fretdiagram.js +77 -0
- package/build/esm/src/gracenote.js +43 -38
- package/build/esm/src/gracenotegroup.js +53 -56
- package/build/esm/src/guitargesture.js +33 -0
- package/build/esm/src/guitarmodifiers.js +26 -0
- package/build/esm/src/index.js +10 -0
- package/build/esm/src/instrumentprofile.js +123 -0
- package/build/esm/src/keysignature.js +24 -2
- package/build/esm/src/modifiercontext.js +11 -0
- package/build/esm/src/notationspelling.js +73 -0
- package/build/esm/src/note.js +3 -0
- package/build/esm/src/notehead.js +11 -6
- package/build/esm/src/ornament.js +43 -18
- package/build/esm/src/pagebreaks.js +58 -0
- package/build/esm/src/pedalmarking.js +39 -17
- package/build/esm/src/phraselayout.js +503 -0
- package/build/esm/src/phraseribbon.js +28 -0
- package/build/esm/src/proportionalformatter.js +54 -6
- package/build/esm/src/publication.js +402 -0
- package/build/esm/src/publicationview.js +114 -0
- package/build/esm/src/scorenavigation.js +172 -0
- package/build/esm/src/sheet.js +14 -2
- package/build/esm/src/stave.js +33 -16
- package/build/esm/src/stavebarline.js +5 -7
- package/build/esm/src/staveconnector.js +1 -0
- package/build/esm/src/stavehairpin.js +53 -27
- package/build/esm/src/stavenote.js +134 -116
- package/build/esm/src/stavetie.js +66 -9
- package/build/esm/src/stem.js +26 -11
- package/build/esm/src/strokes.js +4 -0
- package/build/esm/src/system.js +19 -4
- package/build/esm/src/systembreaks.js +42 -0
- package/build/esm/src/tabnote.js +6 -1
- package/build/esm/src/textbracket.js +24 -5
- package/build/esm/src/tickcontext.js +19 -0
- package/build/esm/src/timesignature.js +20 -6
- package/build/esm/src/tuplet.js +58 -17
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vexflow.js +20 -0
- package/build/esm/src/voice.js +7 -3
- package/build/esm/tests/bend_tests.js +14 -1
- package/build/esm/tests/curve_tests.js +14 -4
- package/build/esm/tests/demo_repertoire_tests.js +27 -0
- package/build/esm/tests/demos/drums.js +54 -0
- package/build/esm/tests/demos/electric.js +63 -0
- package/build/esm/tests/demos/greensleeves.js +90 -0
- package/build/esm/tests/demos/joy.js +61 -0
- package/build/esm/tests/demos/kesh.js +80 -0
- package/build/esm/tests/demos/prelude.js +59 -0
- package/build/esm/tests/demos/quartertones.js +50 -0
- package/build/esm/tests/demos/saints.js +65 -0
- package/build/esm/tests/engraving/continuous-studies.mjs +140 -0
- package/build/esm/tests/engraving/instrument-studies.mjs +273 -0
- package/build/esm/tests/engraving/phrase-studies.mjs +63 -0
- package/build/esm/tests/engraving/publication-studies.mjs +87 -0
- package/build/esm/tests/engraving/score-layout.mjs +75 -0
- package/build/esm/tests/engraving/score-persistence.mjs +262 -0
- package/build/esm/tests/engraving/specialist-studies.mjs +347 -0
- package/build/esm/tests/engraving/studies.mjs +367 -0
- package/build/esm/tests/formatter_tests.js +10 -1
- package/build/esm/tests/index.js +1 -0
- package/build/esm/tests/node/audit-dependencies-tests.mjs +42 -0
- package/build/esm/tests/node/continuous-score-tests.mjs +282 -0
- package/build/esm/tests/node/easyscore-tests.mjs +71 -0
- package/build/esm/tests/node/engraving-layout-tests.mjs +449 -0
- package/build/esm/tests/node/instrument-profile-tests.mjs +224 -0
- package/build/esm/tests/node/local-engraving-tests.mjs +128 -0
- package/build/esm/tests/node/phrase-layout-tests.mjs +281 -0
- package/build/esm/tests/node/proportional-spacing-tests.mjs +64 -0
- package/build/esm/tests/node/publication-tests.mjs +219 -0
- package/build/esm/tests/node/rendering-tests.mjs +6 -2
- package/build/esm/tests/threevoice_tests.js +11 -1
- package/build/esm/tests/vexflow_test_helpers.js +19 -10
- package/build/esm/tools/audit-dependencies.mjs +61 -0
- package/build/esm/tools/easyscore-structure.mjs +1 -1
- package/build/esm/tools/explorer/catalog/entries.mjs +2 -1
- package/build/esm/tools/explorer/catalog/expression.mjs +14 -9
- package/build/esm/tools/explorer/catalog/guitar.mjs +238 -0
- package/build/esm/tools/explorer/catalog/layout.mjs +8 -6
- package/build/esm/tools/explorer/catalog/notes.mjs +16 -14
- package/build/esm/tools/explorer/catalog/staves.mjs +12 -6
- package/build/esm/tools/explorer/catalog/strings.mjs +10 -7
- package/build/esm/tools/score-fixtures.mjs +23 -6
- package/build/types/src/accidental.d.ts +4 -0
- package/build/types/src/alternatingtremolo.d.ts +13 -0
- package/build/types/src/annotation.d.ts +9 -0
- package/build/types/src/articulation.d.ts +9 -1
- package/build/types/src/beam.d.ts +16 -0
- package/build/types/src/bend.d.ts +8 -0
- package/build/types/src/clef.d.ts +3 -0
- package/build/types/src/continuouslayout.d.ts +103 -0
- package/build/types/src/continuousspan.d.ts +60 -0
- package/build/types/src/curve.d.ts +20 -0
- package/build/types/src/dot.d.ts +5 -0
- package/build/types/src/easyscore/composition.d.ts +27 -0
- package/build/types/src/easyscore/policies.d.ts +1 -1
- package/build/types/src/element.d.ts +2 -0
- package/build/types/src/engravinggeometry.d.ts +31 -0
- package/build/types/src/engravingprofile.d.ts +20 -0
- package/build/types/src/factory.d.ts +6 -1
- package/build/types/src/formatter.d.ts +3 -3
- package/build/types/src/fretdiagram.d.ts +23 -0
- package/build/types/src/gracenote.d.ts +7 -0
- package/build/types/src/gracenotegroup.d.ts +7 -2
- package/build/types/src/guitargesture.d.ts +26 -0
- package/build/types/src/guitarmodifiers.d.ts +3 -0
- package/build/types/src/index.d.ts +12 -0
- package/build/types/src/instrumentprofile.d.ts +124 -0
- package/build/types/src/keysignature.d.ts +9 -0
- package/build/types/src/modifiercontext.d.ts +4 -0
- package/build/types/src/notationspelling.d.ts +25 -0
- package/build/types/src/note.d.ts +15 -0
- package/build/types/src/notehead.d.ts +5 -0
- package/build/types/src/ornament.d.ts +10 -1
- package/build/types/src/pagebreaks.d.ts +26 -0
- package/build/types/src/pedalmarking.d.ts +9 -0
- package/build/types/src/phraselayout.d.ts +87 -0
- package/build/types/src/phraseribbon.d.ts +7 -0
- package/build/types/src/proportionalformatter.d.ts +11 -2
- package/build/types/src/publication.d.ts +61 -0
- package/build/types/src/publicationview.d.ts +27 -0
- package/build/types/src/scorenavigation.d.ts +33 -0
- package/build/types/src/sheet.d.ts +5 -0
- package/build/types/src/stave.d.ts +13 -0
- package/build/types/src/stavehairpin.d.ts +18 -0
- package/build/types/src/stavenote.d.ts +20 -2
- package/build/types/src/stavetie.d.ts +9 -0
- package/build/types/src/stem.d.ts +10 -1
- package/build/types/src/system.d.ts +8 -1
- package/build/types/src/systembreaks.d.ts +9 -0
- package/build/types/src/textbracket.d.ts +7 -0
- package/build/types/src/tickcontext.d.ts +5 -0
- package/build/types/src/timesignature.d.ts +6 -0
- package/build/types/src/tuplet.d.ts +5 -48
- package/build/types/src/vexflow.d.ts +20 -0
- package/build/types/src/voice.d.ts +2 -0
- package/changelog/CHANGELOG.md +25 -0
- package/package.json +15 -3
- package/tests/all.html +277 -0
- package/tests/demo_petzold_tests.ts +435 -0
- package/tests/demos/drums.ts +55 -0
- package/tests/demos/drums.webp +0 -0
- package/tests/demos/electric.ts +70 -0
- package/tests/demos/electric.webp +0 -0
- package/tests/demos/greensleeves.ts +97 -0
- package/tests/demos/greensleeves.webp +0 -0
- package/tests/demos/joy.ts +65 -0
- package/tests/demos/joy.webp +0 -0
- package/tests/demos/kesh.ts +86 -0
- package/tests/demos/kesh.webp +0 -0
- package/tests/demos/prelude.ts +65 -0
- package/tests/demos/prelude.webp +0 -0
- package/tests/demos/quartertones.ts +51 -0
- package/tests/demos/quartertones.webp +0 -0
- package/tests/demos/saints.ts +70 -0
- package/tests/demos/saints.webp +0 -0
- package/tests/flow.html +550 -239
- package/tests/fonts.css +493 -0
- package/tests/minuet.webp +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RuntimeError } from './util.js';
|
|
2
|
+
export function bendAmount(bend) {
|
|
3
|
+
var _a;
|
|
4
|
+
return (_a = bend.label) !== null && _a !== void 0 ? _a : (bend.semitones === 2 ? 'full' : bend.semitones === 1 ? '½' : String(bend.semitones) + ' st');
|
|
5
|
+
}
|
|
6
|
+
export function copyBend(bend) {
|
|
7
|
+
if (!Number.isInteger(bend.string) || bend.string < 1 || !Number.isFinite(bend.semitones) || bend.semitones <= 0)
|
|
8
|
+
throw new RuntimeError('BadArguments', 'A timed bend needs a string and positive semitone amount.');
|
|
9
|
+
let previous = [0, 1];
|
|
10
|
+
for (const end of [bend.rise, ...(bend.hold ? [bend.hold] : []), ...(bend.release ? [bend.release] : [])]) {
|
|
11
|
+
if (!Array.isArray(end) ||
|
|
12
|
+
end.length !== 2 ||
|
|
13
|
+
!end.every(Number.isSafeInteger) ||
|
|
14
|
+
end[1] <= 0 ||
|
|
15
|
+
end[0] <= 0 ||
|
|
16
|
+
end[0] > end[1] ||
|
|
17
|
+
BigInt(end[0]) * BigInt(previous[1]) <= BigInt(previous[0]) * BigInt(end[1]))
|
|
18
|
+
throw new RuntimeError('BadArguments', 'Bend endpoints must increase within the written duration.');
|
|
19
|
+
previous = end;
|
|
20
|
+
}
|
|
21
|
+
return Object.assign(Object.assign({}, bend), { rise: [...bend.rise], hold: bend.hold && [...bend.hold], release: bend.release && [...bend.release] });
|
|
22
|
+
}
|
|
23
|
+
export function strokeIdentity(action) {
|
|
24
|
+
var _a;
|
|
25
|
+
if (!['p', 'i', 'm', 'a', 'e'].includes(action.finger) ||
|
|
26
|
+
!['bass-to-treble', 'treble-to-bass'].includes(action.direction) ||
|
|
27
|
+
!['hand', 'strings'].includes((_a = action.arrows) !== null && _a !== void 0 ? _a : 'strings'))
|
|
28
|
+
throw new RuntimeError('BadArguments', 'Invalid rasgueado finger, direction or arrow convention.');
|
|
29
|
+
const label = [action.roll ? 'Rolled rasgueado' : 'Rasgueado', action.finger, action.direction.replace(/-/g, ' ')];
|
|
30
|
+
if (action.golpe)
|
|
31
|
+
label.push('simultaneous golpe');
|
|
32
|
+
return { kind: 'technique', id: 'rasgueado', label: label.join(', '), stroke: Object.assign({}, action) };
|
|
33
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Annotation } from './annotation.js';
|
|
2
|
+
import { Bend } from './bend.js';
|
|
3
|
+
import { Stroke } from './strokes.js';
|
|
4
|
+
import { isTabNote } from './typeguard.js';
|
|
5
|
+
import { RuntimeError } from './util.js';
|
|
6
|
+
function printedStroke(stroke) {
|
|
7
|
+
const down = (stroke.direction === 'bass-to-treble') !== (stroke.arrows === 'hand');
|
|
8
|
+
if (stroke.roll)
|
|
9
|
+
return down ? Stroke.Type.RASGUEADO_DOWN : Stroke.Type.RASGUEADO_UP;
|
|
10
|
+
return down ? Stroke.Type.BRUSH_DOWN : Stroke.Type.BRUSH_UP;
|
|
11
|
+
}
|
|
12
|
+
export function attachGuitarGestures(note) {
|
|
13
|
+
for (const entry of note.notation) {
|
|
14
|
+
const { stroke, bend } = entry;
|
|
15
|
+
if (stroke) {
|
|
16
|
+
note.addModifier(new Stroke(printedStroke(stroke), { allVoices: false }), 0);
|
|
17
|
+
note.addModifier(new Annotation(stroke.finger + (stroke.golpe ? ' + golpe' : '')).setVerticalJustification(Annotation.VerticalJustify.TOP), 0);
|
|
18
|
+
}
|
|
19
|
+
if (bend && isTabNote(note)) {
|
|
20
|
+
const index = note.getPositions().findIndex((p) => p.str === bend.string);
|
|
21
|
+
if (index < 0)
|
|
22
|
+
throw new RuntimeError('BadArguments', 'The bent string must occur in the chord.');
|
|
23
|
+
note.addModifier(Bend.timed(bend), index);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
package/build/esm/src/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './accidental.js';
|
|
2
|
+
export * from './alternatingtremolo.js';
|
|
2
3
|
export * from './annotation.js';
|
|
3
4
|
export * from './articulation.js';
|
|
4
5
|
export * from './barnote.js';
|
|
@@ -14,8 +15,13 @@ export * from './curve.js';
|
|
|
14
15
|
export * from './dot.js';
|
|
15
16
|
export * from './easyscore.js';
|
|
16
17
|
export * from './element.js';
|
|
18
|
+
export * from './engravinggeometry.js';
|
|
19
|
+
export * from './engravingprofile.js';
|
|
17
20
|
export * from './factory.js';
|
|
18
21
|
export * from './font.js';
|
|
22
|
+
export * from './fretdiagram.js';
|
|
23
|
+
export * from './instrumentprofile.js';
|
|
24
|
+
export * from './notationspelling.js';
|
|
19
25
|
export * from './flag.js';
|
|
20
26
|
export * from './formatter.js';
|
|
21
27
|
export * from './fraction.js';
|
|
@@ -40,10 +46,12 @@ export * from './ornament.js';
|
|
|
40
46
|
export * from './parenthesis.js';
|
|
41
47
|
export * from './parser.js';
|
|
42
48
|
export * from './pedalmarking.js';
|
|
49
|
+
export * from './phraselayout.js';
|
|
43
50
|
export * from './registry.js';
|
|
44
51
|
export * from './rendercontext.js';
|
|
45
52
|
export * from './renderer.js';
|
|
46
53
|
export * from './repeatnote.js';
|
|
54
|
+
export * from './scorenavigation.js';
|
|
47
55
|
export * from './sheet.js';
|
|
48
56
|
export * from './stave.js';
|
|
49
57
|
export * from './stavebarline.js';
|
|
@@ -81,6 +89,8 @@ export * from './tuning.js';
|
|
|
81
89
|
export * from './tuplet.js';
|
|
82
90
|
export * from './typeguard.js';
|
|
83
91
|
export * from './util.js';
|
|
92
|
+
export * from './continuouslayout.js';
|
|
93
|
+
export * from './publication.js';
|
|
84
94
|
export * from './vexflow.js';
|
|
85
95
|
export * from './vibrato.js';
|
|
86
96
|
export * from './vibratobracket.js';
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { Fraction } from './fraction.js';
|
|
13
|
+
import { copyBend, strokeIdentity } from './guitargesture.js';
|
|
14
|
+
import { Tables } from './tables.js';
|
|
15
|
+
import { Tuning } from './tuning.js';
|
|
16
|
+
import { RuntimeError } from './util.js';
|
|
17
|
+
export class PercussionMap {
|
|
18
|
+
constructor(entries = PercussionMap.kit) {
|
|
19
|
+
if (new Set(entries.map((e) => e.id)).size !== entries.length)
|
|
20
|
+
throw new RuntimeError('BadArguments', 'Duplicate percussion ID.');
|
|
21
|
+
this.instruments = entries.map((entry) => {
|
|
22
|
+
if (!entry.id || !entry.label || !Number.isSafeInteger(entry.line * 2))
|
|
23
|
+
throw new RuntimeError('BadArguments', 'Invalid percussion entry.');
|
|
24
|
+
return Object.assign({}, entry);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
note(ids, duration, stem) {
|
|
28
|
+
if (!ids.length)
|
|
29
|
+
throw new RuntimeError('BadArguments', 'A percussion attack needs an instrument.');
|
|
30
|
+
const entries = ids.map((id) => {
|
|
31
|
+
const entry = this.instruments.find((item) => item.id === id);
|
|
32
|
+
if (!entry)
|
|
33
|
+
throw new RuntimeError('BadArguments', 'Unknown percussion instrument: ' + id);
|
|
34
|
+
return entry;
|
|
35
|
+
});
|
|
36
|
+
const keys = entries.map(({ line, head }) => {
|
|
37
|
+
const step = 28 + 2 * line;
|
|
38
|
+
const key = 'cdefgab'[((step % 7) + 7) % 7] + '/' + Math.floor(step / 7);
|
|
39
|
+
const shape = head === 'cross' ? 'X' : head === 'circle-cross' ? 'CX' : head === 'triangle' ? 'TU' : '';
|
|
40
|
+
return shape ? key + '/' + shape : key;
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
keys,
|
|
44
|
+
duration,
|
|
45
|
+
clef: 'percussion',
|
|
46
|
+
stemDirection: (stem !== null && stem !== void 0 ? stem : entries[0].stem) === 'up' ? 1 : -1,
|
|
47
|
+
notation: entries.map(({ id, label }, index) => ({ kind: 'unpitched', id, label, index })),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
PercussionMap.kit = [
|
|
52
|
+
{ id: 'kick', label: 'Bass drum', line: 1.5, stem: 'down' },
|
|
53
|
+
{ id: 'snare', label: 'Snare drum', line: 3.5, stem: 'up' },
|
|
54
|
+
{ id: 'hat', label: 'Closed hi-hat', line: 5.5, head: 'cross', stem: 'up' },
|
|
55
|
+
];
|
|
56
|
+
export class FrettedInstrument {
|
|
57
|
+
constructor(tuning = 'standard', capo = 0) {
|
|
58
|
+
this.capo = capo;
|
|
59
|
+
if (!Number.isSafeInteger(capo) || capo < 0)
|
|
60
|
+
throw new RuntimeError('BadArguments', 'Invalid capo fret.');
|
|
61
|
+
this.tuning = new Tuning(tuning);
|
|
62
|
+
}
|
|
63
|
+
rasgueado(positions, strokes) {
|
|
64
|
+
if (!strokes.length)
|
|
65
|
+
throw new RuntimeError('BadArguments', 'A rasgueado needs at least one stroke.');
|
|
66
|
+
const clock = new Fraction(0, 1);
|
|
67
|
+
return strokes.map((_a) => {
|
|
68
|
+
var _b;
|
|
69
|
+
var { duration } = _a, stroke = __rest(_a, ["duration"]);
|
|
70
|
+
const event = this.attack(positions, duration);
|
|
71
|
+
const mark = strokeIdentity(stroke);
|
|
72
|
+
const offset = clock.clone().simplify();
|
|
73
|
+
clock.add(Tables.durationToTicks(duration), Tables.RESOLUTION);
|
|
74
|
+
const notation = [...((_b = event.note.notation) !== null && _b !== void 0 ? _b : []), mark];
|
|
75
|
+
return { offset, note: Object.assign(Object.assign({}, event.note), { notation }), tab: Object.assign(Object.assign({}, event.tab), { notation }) };
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
bentAttack(positions, duration, spec) {
|
|
79
|
+
var _a;
|
|
80
|
+
const event = this.attack(positions, duration);
|
|
81
|
+
const bend = copyBend(spec);
|
|
82
|
+
const index = positions.findIndex((p) => p.str === bend.string);
|
|
83
|
+
if (index < 0)
|
|
84
|
+
throw new RuntimeError('BadArguments', 'The bent string must occur in the chord.');
|
|
85
|
+
const label = 'String ' +
|
|
86
|
+
bend.string +
|
|
87
|
+
', bend ' +
|
|
88
|
+
bend.semitones +
|
|
89
|
+
(bend.semitones === 1 ? ' semitone by ' : ' semitones by ') +
|
|
90
|
+
bend.rise.join('/') +
|
|
91
|
+
(bend.hold ? ', hold to ' + bend.hold.join('/') : '') +
|
|
92
|
+
(bend.release ? ', release to pitch by ' + bend.release.join('/') : '');
|
|
93
|
+
const mark = { kind: 'technique', id: 'string-bend', index, label, bend };
|
|
94
|
+
const notation = [...((_a = event.note.notation) !== null && _a !== void 0 ? _a : []), mark];
|
|
95
|
+
return { note: Object.assign(Object.assign({}, event.note), { notation }), tab: Object.assign(Object.assign({}, event.tab), { notation }) };
|
|
96
|
+
}
|
|
97
|
+
attack(positions, duration) {
|
|
98
|
+
if (!positions.length || new Set(positions.map((p) => p.str)).size !== positions.length)
|
|
99
|
+
throw new RuntimeError('BadArguments', 'A fretted attack needs distinct strings.');
|
|
100
|
+
const keys = positions.map((position) => {
|
|
101
|
+
const { str, fret } = position;
|
|
102
|
+
if (fret === 'X') {
|
|
103
|
+
this.tuning.getValueForString(str);
|
|
104
|
+
if (!Number.isSafeInteger(str) || !position.displayKey || !/^[a-g][bn#]*\/\d+$/i.test(position.displayKey))
|
|
105
|
+
throw new RuntimeError('BadArguments', 'A dead string needs a written display pitch.');
|
|
106
|
+
return position.displayKey + '/X';
|
|
107
|
+
}
|
|
108
|
+
if (!Number.isSafeInteger(str) || !Number.isSafeInteger(fret) || fret < 0)
|
|
109
|
+
throw new RuntimeError('BadArguments', 'Invalid string or fret.');
|
|
110
|
+
return this.tuning.getNoteForFret(fret + this.capo, str);
|
|
111
|
+
});
|
|
112
|
+
const notation = positions.map(({ str, fret }, index) => ({
|
|
113
|
+
kind: fret === 'X' ? 'unpitched' : 'tuning',
|
|
114
|
+
id: 'string-' + str,
|
|
115
|
+
label: fret === 'X' ? 'Muted strike on string ' + str : 'String ' + str + ', fret ' + fret + ', capo ' + this.capo,
|
|
116
|
+
index,
|
|
117
|
+
}));
|
|
118
|
+
return {
|
|
119
|
+
note: { keys, duration, notation },
|
|
120
|
+
tab: { positions: positions.map(({ str, fret }) => ({ str, fret })), duration, notation },
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -4,11 +4,20 @@ import { Glyphs } from './glyphs.js';
|
|
|
4
4
|
import { Stave } from './stave.js';
|
|
5
5
|
import { StaveModifier, StaveModifierPosition } from './stavemodifier.js';
|
|
6
6
|
import { Tables } from './tables.js';
|
|
7
|
-
import { defined } from './util.js';
|
|
7
|
+
import { defined, RuntimeError } from './util.js';
|
|
8
8
|
export class KeySignature extends StaveModifier {
|
|
9
9
|
static get CATEGORY() {
|
|
10
10
|
return "KeySignature";
|
|
11
11
|
}
|
|
12
|
+
setOrdered(entries) {
|
|
13
|
+
for (const entry of entries) {
|
|
14
|
+
if (!entry.type || !Number.isSafeInteger(entry.line * 2))
|
|
15
|
+
throw new RuntimeError('BadArguments', 'Expected an accidental and a staff line or space.');
|
|
16
|
+
}
|
|
17
|
+
this.ordered = entries.map((entry) => (Object.assign({}, entry)));
|
|
18
|
+
this.formatted = false;
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
12
21
|
constructor(keySpec, cancelKeySpec, alterKeySpec) {
|
|
13
22
|
super();
|
|
14
23
|
this.accList = [];
|
|
@@ -20,7 +29,7 @@ export class KeySignature extends StaveModifier {
|
|
|
20
29
|
convertToGlyph(acc, nextAcc, stave) {
|
|
21
30
|
const code = Tables.accidentalCodes(acc.type);
|
|
22
31
|
const glyph = new Element("KeySignature");
|
|
23
|
-
glyph.setText(code);
|
|
32
|
+
glyph.setFont(this.fontInfo).setText(code);
|
|
24
33
|
let extraWidth = 1;
|
|
25
34
|
glyph.setYShift(stave.getYForLine(acc.line));
|
|
26
35
|
if (this.children.length > 0) {
|
|
@@ -160,6 +169,7 @@ export class KeySignature extends StaveModifier {
|
|
|
160
169
|
}
|
|
161
170
|
setKeySig(keySpec, cancelKeySpec, alterKeySpec) {
|
|
162
171
|
this.formatted = false;
|
|
172
|
+
this.ordered = undefined;
|
|
163
173
|
this.keySpec = keySpec;
|
|
164
174
|
this.cancelKeySpec = cancelKeySpec;
|
|
165
175
|
this.alterKeySpec = alterKeySpec;
|
|
@@ -185,8 +195,15 @@ export class KeySignature extends StaveModifier {
|
|
|
185
195
|
stave = new Stave(0, 0, 100);
|
|
186
196
|
this.setStave(stave);
|
|
187
197
|
}
|
|
198
|
+
this.formattedStaveY = stave.getY();
|
|
188
199
|
this.width = 0;
|
|
189
200
|
this.children = [];
|
|
201
|
+
if (this.ordered) {
|
|
202
|
+
this.ordered.forEach((entry, i, list) => this.convertToGlyph(entry, list[i + 1], stave));
|
|
203
|
+
this.calculateDimensions();
|
|
204
|
+
this.formatted = true;
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
190
207
|
this.accList = Tables.keySignature(defined(this.keySpec));
|
|
191
208
|
const accList = this.accList;
|
|
192
209
|
const firstAccidentalType = accList.length > 0 ? accList[0].type : undefined;
|
|
@@ -210,6 +227,11 @@ export class KeySignature extends StaveModifier {
|
|
|
210
227
|
this.calculateDimensions();
|
|
211
228
|
this.formatted = true;
|
|
212
229
|
}
|
|
230
|
+
getInkParts() {
|
|
231
|
+
if (!this.formatted || this.formattedStaveY !== this.checkStave().getY())
|
|
232
|
+
this.format();
|
|
233
|
+
return this.children.map((glyph) => glyph.getTextInk(this.x, 0));
|
|
234
|
+
}
|
|
213
235
|
draw() {
|
|
214
236
|
const stave = this.checkStave();
|
|
215
237
|
const ctx = stave.checkContext();
|
|
@@ -33,6 +33,8 @@ export class ModifierContext {
|
|
|
33
33
|
this.width = 0;
|
|
34
34
|
this.spacing = 0;
|
|
35
35
|
this.annotationRightShift = 0;
|
|
36
|
+
this.measuredTopLines = 0;
|
|
37
|
+
this.measuredBottomLines = 0;
|
|
36
38
|
}
|
|
37
39
|
addModifier(member) {
|
|
38
40
|
L('addModifier is deprecated, use addMember instead.');
|
|
@@ -68,6 +70,9 @@ export class ModifierContext {
|
|
|
68
70
|
getRightShiftForTie() {
|
|
69
71
|
return this.state.rightShift - this.annotationRightShift;
|
|
70
72
|
}
|
|
73
|
+
getUnmeasuredTextLines(above) {
|
|
74
|
+
return above ? this.state.topTextLine - this.measuredTopLines : this.state.textLine - this.measuredBottomLines;
|
|
75
|
+
}
|
|
71
76
|
getState() {
|
|
72
77
|
return this.state;
|
|
73
78
|
}
|
|
@@ -103,12 +108,18 @@ export class ModifierContext {
|
|
|
103
108
|
annotation.getVerticalJustification() === Annotation.VerticalJustify.BOTTOM;
|
|
104
109
|
Annotation.format(annotations.filter((annotation) => !isOutsideNote(annotation)), state);
|
|
105
110
|
const rightShiftBeforeAnnotations = state.rightShift;
|
|
111
|
+
const topBefore = state.topTextLine;
|
|
112
|
+
const bottomBefore = state.textLine;
|
|
106
113
|
Annotation.format(annotations.filter(isOutsideNote), state);
|
|
114
|
+
const topAfter = state.topTextLine;
|
|
115
|
+
const bottomAfter = state.textLine;
|
|
107
116
|
const rightShiftWithAnnotations = state.rightShift;
|
|
108
117
|
state.rightShift = rightShiftBeforeAnnotations;
|
|
109
118
|
ChordSymbol.format(members["ChordSymbol"], state);
|
|
110
119
|
Bend.format(members["Bend"], state);
|
|
111
120
|
Vibrato.format(members["Vibrato"], state, this);
|
|
121
|
+
this.measuredTopLines = state.topTextLine === topAfter ? topAfter - topBefore : 0;
|
|
122
|
+
this.measuredBottomLines = state.textLine === bottomAfter ? bottomAfter - bottomBefore : 0;
|
|
112
123
|
this.annotationRightShift = Math.max(0, rightShiftWithAnnotations - state.rightShift);
|
|
113
124
|
state.rightShift += this.annotationRightShift;
|
|
114
125
|
this.width = state.leftShift + state.rightShift;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Tables } from './tables.js';
|
|
2
|
+
import { RuntimeError } from './util.js';
|
|
3
|
+
export class NotationSpelling {
|
|
4
|
+
static transpose(key, semitones, steps) {
|
|
5
|
+
var _a;
|
|
6
|
+
const parsed = /^([a-g])(bb|##|b|#|n)?\/(-?\d+)$/i.exec(key);
|
|
7
|
+
if (!parsed || !Number.isSafeInteger(semitones) || !Number.isSafeInteger(steps))
|
|
8
|
+
throw new RuntimeError('BadArguments', 'Expected a written pitch and integer transposition.');
|
|
9
|
+
const letters = 'cdefgab', naturals = [0, 2, 4, 5, 7, 9, 11];
|
|
10
|
+
const index = letters.indexOf(parsed[1].toLowerCase()), octave = Number(parsed[3]);
|
|
11
|
+
const target = octave * 7 + index + steps, letter = ((target % 7) + 7) % 7;
|
|
12
|
+
const targetOctave = Math.floor(target / 7);
|
|
13
|
+
const signs = ['bb', 'b', '', '#', '##'];
|
|
14
|
+
const accidental = (_a = parsed[2]) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
15
|
+
const alteration = accidental && accidental !== 'n' ? signs.indexOf(accidental) - 2 : 0;
|
|
16
|
+
const delta = octave * 12 + naturals[index] + alteration + semitones - (targetOctave * 12 + naturals[letter]);
|
|
17
|
+
if (!(Math.abs(delta) <= 2))
|
|
18
|
+
throw new RuntimeError('BadArguments', 'Spelling requires more than a double accidental.');
|
|
19
|
+
return letters[letter] + signs[delta + 2] + '/' + targetOctave;
|
|
20
|
+
}
|
|
21
|
+
static transposeKey(key, semitones, steps) {
|
|
22
|
+
Tables.keySignature(key);
|
|
23
|
+
const minor = key.endsWith('m');
|
|
24
|
+
const pitch = this.transpose((minor ? key.slice(0, -1) : key) + '/4', semitones, steps).split('/')[0];
|
|
25
|
+
const result = pitch[0].toUpperCase() + pitch.slice(1) + (minor ? 'm' : '');
|
|
26
|
+
Tables.keySignature(result);
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
static rhythm(start, length, cuts = [], rest = false) {
|
|
30
|
+
const end = start + length;
|
|
31
|
+
if (![start, length, end, ...cuts].every(Number.isSafeInteger) || start < 0 || length <= 0)
|
|
32
|
+
throw new RuntimeError('BadArguments', 'Expected integer positions in 64th notes and a positive length.');
|
|
33
|
+
const stops = [...new Set(cuts.filter((n) => n > start && n < end))].sort((a, b) => a - b);
|
|
34
|
+
const segments = [];
|
|
35
|
+
let position = start;
|
|
36
|
+
for (const stop of [...stops, end]) {
|
|
37
|
+
while (position < stop) {
|
|
38
|
+
const remaining = stop - position;
|
|
39
|
+
let unit = 64;
|
|
40
|
+
while (unit > remaining)
|
|
41
|
+
unit /= 2;
|
|
42
|
+
const dotted = unit >= 2 && unit * 1.5 <= remaining;
|
|
43
|
+
const next = position + unit * (dotted ? 1.5 : 1);
|
|
44
|
+
segments.push({
|
|
45
|
+
start: position,
|
|
46
|
+
duration: String(64 / unit),
|
|
47
|
+
dots: dotted ? 1 : 0,
|
|
48
|
+
tieNext: !rest && next < end,
|
|
49
|
+
});
|
|
50
|
+
position = next;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return segments;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class WrittenAccidentalState {
|
|
57
|
+
constructor(signature = {}) {
|
|
58
|
+
this.seen = new Map();
|
|
59
|
+
this.signature = Object.assign({}, signature);
|
|
60
|
+
}
|
|
61
|
+
reset() {
|
|
62
|
+
this.seen.clear();
|
|
63
|
+
}
|
|
64
|
+
sign(key, sign, cautionary = false) {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
const pitch = key.toLowerCase();
|
|
67
|
+
if (!/^[a-g]\/-?\d+$/.test(pitch) || !sign)
|
|
68
|
+
throw new RuntimeError('BadArguments', 'Expected a staff pitch and a written accidental.');
|
|
69
|
+
const previous = (_b = (_a = this.seen.get(pitch)) !== null && _a !== void 0 ? _a : this.signature[pitch[0]]) !== null && _b !== void 0 ? _b : 'n';
|
|
70
|
+
this.seen.set(pitch, sign);
|
|
71
|
+
return cautionary || sign !== previous ? sign : undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|
package/build/esm/src/note.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Glyphs } from './glyphs.js';
|
|
2
|
+
import { copyBend } from './guitargesture.js';
|
|
2
3
|
import { Metrics } from './metrics.js';
|
|
3
4
|
import { drawDot } from './rendercontext.js';
|
|
4
5
|
import { Tables } from './tables.js';
|
|
@@ -118,10 +119,12 @@ export class Note extends Tickable {
|
|
|
118
119
|
};
|
|
119
120
|
}
|
|
120
121
|
constructor(noteStruct) {
|
|
122
|
+
var _a;
|
|
121
123
|
super();
|
|
122
124
|
if (!noteStruct) {
|
|
123
125
|
throw new RuntimeError('BadArguments', 'Note must have valid initialization data to identify duration and type.');
|
|
124
126
|
}
|
|
127
|
+
this.notation = ((_a = noteStruct.notation) !== null && _a !== void 0 ? _a : []).map((entry) => (Object.assign(Object.assign(Object.assign({}, entry), (entry.stroke && { stroke: Object.assign({}, entry.stroke) })), (entry.bend && { bend: copyBend(entry.bend) }))));
|
|
125
128
|
const parsedNoteStruct = Note.parseNoteStruct(noteStruct);
|
|
126
129
|
if (!parsedNoteStruct) {
|
|
127
130
|
throw new RuntimeError('BadArguments', `Invalid note initialization object: ${JSON.stringify(noteStruct)}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Note } from './note.js';
|
|
2
2
|
import { Stem } from './stem.js';
|
|
3
|
-
import { defined, log } from './util.js';
|
|
3
|
+
import { defined, log, RuntimeError } from './util.js';
|
|
4
4
|
function L(...args) {
|
|
5
5
|
if (NoteHead.DEBUG)
|
|
6
6
|
log('VexFlow.NoteHead', args);
|
|
@@ -10,7 +10,7 @@ export class NoteHead extends Note {
|
|
|
10
10
|
return "NoteHead";
|
|
11
11
|
}
|
|
12
12
|
constructor(noteStruct) {
|
|
13
|
-
var _a;
|
|
13
|
+
var _a, _b;
|
|
14
14
|
super(noteStruct);
|
|
15
15
|
this.customGlyph = false;
|
|
16
16
|
this.ledger = {
|
|
@@ -22,7 +22,10 @@ export class NoteHead extends Note {
|
|
|
22
22
|
this.y = noteStruct.y || 0;
|
|
23
23
|
if (noteStruct.noteType)
|
|
24
24
|
this.noteType = noteStruct.noteType;
|
|
25
|
-
this.
|
|
25
|
+
this.displacementColumn = (_a = noteStruct.displacementColumn) !== null && _a !== void 0 ? _a : (noteStruct.displaced ? 1 : 0);
|
|
26
|
+
if (!Number.isSafeInteger(this.displacementColumn) || this.displacementColumn < 0)
|
|
27
|
+
throw new RuntimeError('BadArguments', 'Head displacement column must be a nonnegative integer.');
|
|
28
|
+
this.displaced = this.displacementColumn !== 0;
|
|
26
29
|
this.stemDirection = noteStruct.stemDirection || Stem.UP;
|
|
27
30
|
this.line = noteStruct.line || 0;
|
|
28
31
|
this.glyphProps = Note.getGlyphProps(this.duration, this.noteType);
|
|
@@ -35,7 +38,7 @@ export class NoteHead extends Note {
|
|
|
35
38
|
this.customGlyph = true;
|
|
36
39
|
this.text = noteStruct.customGlyphCode;
|
|
37
40
|
}
|
|
38
|
-
this.setStyle((
|
|
41
|
+
this.setStyle((_b = noteStruct.style) !== null && _b !== void 0 ? _b : {});
|
|
39
42
|
this.slashed = noteStruct.slashed || false;
|
|
40
43
|
this.renderOptions = Object.assign({}, this.renderOptions);
|
|
41
44
|
}
|
|
@@ -54,8 +57,10 @@ export class NoteHead extends Note {
|
|
|
54
57
|
}
|
|
55
58
|
getAbsoluteX() {
|
|
56
59
|
const x = !this.preFormatted ? this.x : super.getAbsoluteX();
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
return x + this.getDisplacementX();
|
|
61
|
+
}
|
|
62
|
+
getDisplacementX() {
|
|
63
|
+
return this.displacementColumn * (this.width - Stem.WIDTH / 2) * this.stemDirection;
|
|
59
64
|
}
|
|
60
65
|
setStave(stave) {
|
|
61
66
|
const line = this.getLine();
|
|
@@ -26,12 +26,13 @@ export class Ornament extends Modifier {
|
|
|
26
26
|
for (let i = 0; i < ornaments.length; ++i) {
|
|
27
27
|
const ornament = ornaments[i];
|
|
28
28
|
const increment = 2;
|
|
29
|
+
ornament.sideOffset = 0;
|
|
29
30
|
if (ornament.position === ModifierPosition.RIGHT) {
|
|
30
|
-
ornament.
|
|
31
|
+
ornament.sideOffset = rightShift + 2;
|
|
31
32
|
rightShift += ornament.width + Ornament.minPadding;
|
|
32
33
|
}
|
|
33
34
|
else if (ornament.position === ModifierPosition.LEFT) {
|
|
34
|
-
ornament.
|
|
35
|
+
ornament.sideOffset = -(leftShift + ornament.width + 2);
|
|
35
36
|
leftShift += ornament.width + Ornament.minPadding;
|
|
36
37
|
}
|
|
37
38
|
else if (ornament.position === ModifierPosition.ABOVE) {
|
|
@@ -84,6 +85,8 @@ export class Ornament extends Modifier {
|
|
|
84
85
|
}
|
|
85
86
|
constructor(type) {
|
|
86
87
|
super();
|
|
88
|
+
this.sideOffset = 0;
|
|
89
|
+
this.layoutShiftY = 0;
|
|
87
90
|
this.position = ModifierPosition.ABOVE;
|
|
88
91
|
if (Ornament.ornamentRight.indexOf(type) >= 0) {
|
|
89
92
|
this.position = ModifierPosition.RIGHT;
|
|
@@ -130,15 +133,15 @@ export class Ornament extends Modifier {
|
|
|
130
133
|
this.accidentalLower.setText(Tables.accidentalCodes(accid));
|
|
131
134
|
return this;
|
|
132
135
|
}
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
setLayoutShiftY(y) {
|
|
137
|
+
this.layoutShiftY = y;
|
|
138
|
+
}
|
|
139
|
+
positionElements() {
|
|
135
140
|
const note = this.checkAttachedNote();
|
|
136
|
-
this.setRendered();
|
|
137
141
|
const stave = note.checkStave();
|
|
138
|
-
const
|
|
139
|
-
ctx.openGroup('ornament' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
142
|
+
const parts = [];
|
|
140
143
|
const start = note.getModifierStartXY(this.position, this.index);
|
|
141
|
-
let glyphX = start.x;
|
|
144
|
+
let glyphX = start.x + this.sideOffset;
|
|
142
145
|
const staffSpace = stave.getSpacingBetweenLines();
|
|
143
146
|
const initialOffset = getInitialOffset(note, this.position);
|
|
144
147
|
let glyphY = this.ornamentAlignWithNoteHead ? start.y : 0;
|
|
@@ -148,6 +151,7 @@ export class Ornament extends Modifier {
|
|
|
148
151
|
if (this.position === ModifierPosition.BELOW) {
|
|
149
152
|
glyphY = getBottomY(note, this.textLine) + (this.textLine + initialOffset + 1.5) * staffSpace;
|
|
150
153
|
}
|
|
154
|
+
glyphY += this.layoutShiftY;
|
|
151
155
|
if (this.delayed) {
|
|
152
156
|
let delayXShift = 0;
|
|
153
157
|
const startX = note.getTickContext().getX();
|
|
@@ -164,27 +168,48 @@ export class Ornament extends Modifier {
|
|
|
164
168
|
else {
|
|
165
169
|
delayXShift += (stave.getX() + stave.getWidth() - glyphX) * 0.5;
|
|
166
170
|
}
|
|
167
|
-
this.delayXShift = delayXShift;
|
|
168
171
|
}
|
|
169
172
|
glyphX += delayXShift;
|
|
170
173
|
}
|
|
171
174
|
L('Rendering ornament: ', this.text.charCodeAt(0), glyphX, glyphY);
|
|
172
175
|
if (this.accidentalLower) {
|
|
173
|
-
|
|
176
|
+
parts.push({
|
|
177
|
+
element: this.accidentalLower,
|
|
178
|
+
x: glyphX + this.xShift - this.accidentalLower.getWidth() / 2,
|
|
179
|
+
y: glyphY + this.yShift - this.accidentalLower.getTextMetrics().actualBoundingBoxDescent,
|
|
180
|
+
});
|
|
174
181
|
glyphY -= this.accidentalLower.getHeight() + this.renderOptions.accidentalLowerPadding;
|
|
175
182
|
}
|
|
176
|
-
|
|
177
|
-
this.yShift += this.getHeight();
|
|
178
|
-
}
|
|
183
|
+
const offset = Ornament.ornamentYShift.includes(this.type) ? this.getHeight() : 0;
|
|
179
184
|
this.x =
|
|
180
185
|
glyphX -
|
|
181
|
-
(this.position === ModifierPosition.ABOVE || this.position === ModifierPosition.BELOW ? this.width
|
|
182
|
-
this.y = glyphY;
|
|
183
|
-
|
|
186
|
+
(this.position === ModifierPosition.ABOVE || this.position === ModifierPosition.BELOW ? this.width / 2 : 0);
|
|
187
|
+
this.y = glyphY + offset;
|
|
188
|
+
parts.push({ element: this, x: 0, y: 0 });
|
|
184
189
|
if (this.accidentalUpper) {
|
|
185
|
-
|
|
186
|
-
|
|
190
|
+
parts.push({
|
|
191
|
+
element: this.accidentalUpper,
|
|
192
|
+
x: glyphX + this.xShift - this.accidentalUpper.getWidth() / 2,
|
|
193
|
+
y: this.y +
|
|
194
|
+
this.yShift -
|
|
195
|
+
this.getHeight() -
|
|
196
|
+
this.renderOptions.accidentalUpperPadding -
|
|
197
|
+
this.accidentalUpper.getTextMetrics().actualBoundingBoxDescent,
|
|
198
|
+
});
|
|
187
199
|
}
|
|
200
|
+
return parts;
|
|
201
|
+
}
|
|
202
|
+
getBoundingBox() {
|
|
203
|
+
const boxes = this.positionElements().map(({ element, x, y }) => element.getTextInk(x + element.getX(), y + element.getY()));
|
|
204
|
+
return boxes.reduce((bounds, box) => bounds.mergeWith(box));
|
|
205
|
+
}
|
|
206
|
+
draw() {
|
|
207
|
+
const ctx = this.checkContext();
|
|
208
|
+
this.setRendered();
|
|
209
|
+
const clsAttribute = this.getAttribute('class');
|
|
210
|
+
ctx.openGroup('ornament' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
|
|
211
|
+
for (const { element, x, y } of this.positionElements())
|
|
212
|
+
element.renderText(ctx, x, y);
|
|
188
213
|
this.drawPointerRect();
|
|
189
214
|
ctx.closeGroup();
|
|
190
215
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export function paginate(systems, rules) {
|
|
2
|
+
const count = systems.length;
|
|
3
|
+
const costs = new Array(count + 1);
|
|
4
|
+
const ends = new Array(count);
|
|
5
|
+
costs[count] = { conflicts: 0, pages: 0, penalty: 0 };
|
|
6
|
+
for (let first = count - 1; first >= 0; first--) {
|
|
7
|
+
const capacity = first === 0 ? rules.firstHeight : rules.laterHeight;
|
|
8
|
+
let used = 0;
|
|
9
|
+
for (let i = first; i < count; i++) {
|
|
10
|
+
const row = systems[i];
|
|
11
|
+
if (i > first && rules.forceBefore.has(row.measures[0]))
|
|
12
|
+
break;
|
|
13
|
+
used += row.height + (i === first ? 0 : rules.gap);
|
|
14
|
+
if (i > first && used > capacity + 1e-7)
|
|
15
|
+
break;
|
|
16
|
+
const after = row.measures[row.measures.length - 1];
|
|
17
|
+
const turn = i + 1 < count;
|
|
18
|
+
const rest = costs[i + 1];
|
|
19
|
+
const conflicts = rest.conflicts + Number(turn && rules.forbidAfter.has(after));
|
|
20
|
+
const pages = rest.pages + 1;
|
|
21
|
+
const difficulty = !turn || rules.preferAfter.has(after) ? 0 : rules.part && !row.restAtEnd ? 4 : 1;
|
|
22
|
+
const unused = Math.max(0, capacity - used) / capacity;
|
|
23
|
+
const penalty = rest.penalty + difficulty + (turn ? unused * unused : 0);
|
|
24
|
+
const best = costs[first];
|
|
25
|
+
if (!best ||
|
|
26
|
+
conflicts < best.conflicts ||
|
|
27
|
+
(conflicts === best.conflicts && (pages < best.pages || (pages === best.pages && penalty <= best.penalty)))) {
|
|
28
|
+
costs[first] = { conflicts, pages, penalty };
|
|
29
|
+
ends[first] = i + 1;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const pages = [];
|
|
34
|
+
for (let first = 0; first < count; first = ends[first]) {
|
|
35
|
+
const end = ends[first];
|
|
36
|
+
const rows = systems.slice(first, end);
|
|
37
|
+
const capacity = first === 0 ? rules.firstHeight : rules.laterHeight;
|
|
38
|
+
const spare = capacity - rows.reduce((h, r) => h + r.height, 0) - rules.gap * (rows.length - 1);
|
|
39
|
+
const extra = rows.length > 1 && (end < count || rules.justifyLast)
|
|
40
|
+
? Math.min(rules.maxExtraGap, Math.max(0, spare) / (rows.length - 1))
|
|
41
|
+
: 0;
|
|
42
|
+
let y = 0;
|
|
43
|
+
const offsets = rows.map((row) => {
|
|
44
|
+
const start = y;
|
|
45
|
+
y += row.height + rules.gap + extra;
|
|
46
|
+
return start;
|
|
47
|
+
});
|
|
48
|
+
const measures = rows[rows.length - 1].measures;
|
|
49
|
+
pages.push({
|
|
50
|
+
first,
|
|
51
|
+
end,
|
|
52
|
+
offsets,
|
|
53
|
+
overflow: Math.max(0, -spare),
|
|
54
|
+
forbiddenTurn: end < count && rules.forbidAfter.has(measures[measures.length - 1]),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return pages;
|
|
58
|
+
}
|