@mcqj/vexflow 0.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +208 -0
- package/build/cjs/vexflow-bravura.js +2 -0
- package/build/cjs/vexflow-bravura.js.map +1 -0
- package/build/cjs/vexflow-core.js +2 -0
- package/build/cjs/vexflow-core.js.map +1 -0
- package/build/cjs/vexflow-debug-with-tests.js +43475 -0
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -0
- package/build/cjs/vexflow-debug.js +19194 -0
- package/build/cjs/vexflow-debug.js.map +1 -0
- package/build/cjs/vexflow.js +2 -0
- package/build/cjs/vexflow.js.map +1 -0
- package/build/esm/entry/vexflow-bravura.js +17 -0
- package/build/esm/entry/vexflow-core.js +4 -0
- package/build/esm/entry/vexflow-debug-with-tests.js +38 -0
- package/build/esm/entry/vexflow-debug.js +31 -0
- package/build/esm/entry/vexflow.js +31 -0
- package/build/esm/package.json +3 -0
- package/build/esm/src/accidental.js +330 -0
- package/build/esm/src/annotation.js +231 -0
- package/build/esm/src/articulation.js +281 -0
- package/build/esm/src/barnote.js +56 -0
- package/build/esm/src/beam.js +644 -0
- package/build/esm/src/bend.js +186 -0
- package/build/esm/src/boundingbox.js +59 -0
- package/build/esm/src/canvascontext.js +216 -0
- package/build/esm/src/chordsymbol.js +325 -0
- package/build/esm/src/clef.js +120 -0
- package/build/esm/src/clefnote.js +35 -0
- package/build/esm/src/crescendo.js +78 -0
- package/build/esm/src/curve.js +126 -0
- package/build/esm/src/dot.js +129 -0
- package/build/esm/src/easyscore.js +374 -0
- package/build/esm/src/element.js +409 -0
- package/build/esm/src/factory.js +463 -0
- package/build/esm/src/flag.js +22 -0
- package/build/esm/src/font.js +237 -0
- package/build/esm/src/fonts/academico.js +1 -0
- package/build/esm/src/fonts/academicobold.js +1 -0
- package/build/esm/src/fonts/bravura.js +1 -0
- package/build/esm/src/fonts/gonville.js +1 -0
- package/build/esm/src/fonts/petaluma.js +1 -0
- package/build/esm/src/fonts/petalumascript.js +1 -0
- package/build/esm/src/formatter.js +610 -0
- package/build/esm/src/fraction.js +170 -0
- package/build/esm/src/frethandfinger.js +141 -0
- package/build/esm/src/ghostnote.js +50 -0
- package/build/esm/src/glyphnote.js +44 -0
- package/build/esm/src/glyphs.js +2936 -0
- package/build/esm/src/gracenote.js +106 -0
- package/build/esm/src/gracenotegroup.js +138 -0
- package/build/esm/src/gracetabnote.js +11 -0
- package/build/esm/src/index.js +86 -0
- package/build/esm/src/keymanager.js +99 -0
- package/build/esm/src/keysignature.js +220 -0
- package/build/esm/src/keysignote.js +28 -0
- package/build/esm/src/metrics.js +237 -0
- package/build/esm/src/modifier.js +121 -0
- package/build/esm/src/modifiercontext.js +110 -0
- package/build/esm/src/multimeasurerest.js +127 -0
- package/build/esm/src/music.js +322 -0
- package/build/esm/src/note.js +383 -0
- package/build/esm/src/notehead.js +89 -0
- package/build/esm/src/notesubgroup.js +59 -0
- package/build/esm/src/ornament.js +192 -0
- package/build/esm/src/parenthesis.js +61 -0
- package/build/esm/src/parser.js +164 -0
- package/build/esm/src/pedalmarking.js +168 -0
- package/build/esm/src/registry.js +81 -0
- package/build/esm/src/rendercontext.js +20 -0
- package/build/esm/src/renderer.js +112 -0
- package/build/esm/src/repeatnote.js +17 -0
- package/build/esm/src/stave.js +579 -0
- package/build/esm/src/stavebarline.js +237 -0
- package/build/esm/src/staveconnector.js +180 -0
- package/build/esm/src/stavehairpin.js +115 -0
- package/build/esm/src/staveline.js +199 -0
- package/build/esm/src/stavemodifier.js +56 -0
- package/build/esm/src/stavenote.js +861 -0
- package/build/esm/src/staverepetition.js +120 -0
- package/build/esm/src/stavesection.js +36 -0
- package/build/esm/src/stavetempo.js +110 -0
- package/build/esm/src/stavetext.js +55 -0
- package/build/esm/src/stavetie.js +186 -0
- package/build/esm/src/stavevolta.js +53 -0
- package/build/esm/src/stem.js +133 -0
- package/build/esm/src/stemmablenote.js +193 -0
- package/build/esm/src/stringnumber.js +228 -0
- package/build/esm/src/strokes.js +164 -0
- package/build/esm/src/svgcontext.js +402 -0
- package/build/esm/src/system.js +166 -0
- package/build/esm/src/tables.js +696 -0
- package/build/esm/src/tabnote.js +278 -0
- package/build/esm/src/tabslide.js +68 -0
- package/build/esm/src/tabstave.js +17 -0
- package/build/esm/src/tabtie.js +19 -0
- package/build/esm/src/textbracket.js +128 -0
- package/build/esm/src/textdynamics.js +53 -0
- package/build/esm/src/textnote.js +116 -0
- package/build/esm/src/tickable.js +224 -0
- package/build/esm/src/tickcontext.js +189 -0
- package/build/esm/src/timesignature.js +169 -0
- package/build/esm/src/timesignote.js +30 -0
- package/build/esm/src/tremolo.js +30 -0
- package/build/esm/src/tuning.js +55 -0
- package/build/esm/src/tuplet.js +258 -0
- package/build/esm/src/typeguard.js +30 -0
- package/build/esm/src/util.js +67 -0
- package/build/esm/src/version.js +3 -0
- package/build/esm/src/vexflow.js +309 -0
- package/build/esm/src/vibrato.js +68 -0
- package/build/esm/src/vibratobracket.js +44 -0
- package/build/esm/src/voice.js +178 -0
- package/build/esm/src/web.js +15 -0
- package/build/esm/tests/accidental_tests.js +1055 -0
- package/build/esm/tests/annotation_tests.js +381 -0
- package/build/esm/tests/articulation_tests.js +432 -0
- package/build/esm/tests/auto_beam_formatting_tests.js +551 -0
- package/build/esm/tests/barline_tests.js +52 -0
- package/build/esm/tests/beam_tests.js +669 -0
- package/build/esm/tests/bend_tests.js +223 -0
- package/build/esm/tests/boundingbox_tests.js +53 -0
- package/build/esm/tests/browser_test_runner.js +128 -0
- package/build/esm/tests/chordsymbol_tests.js +405 -0
- package/build/esm/tests/clef_tests.js +141 -0
- package/build/esm/tests/crossbeam_tests.js +306 -0
- package/build/esm/tests/curve_tests.js +152 -0
- package/build/esm/tests/demo_petzold_tests.js +335 -0
- package/build/esm/tests/dot_tests.js +119 -0
- package/build/esm/tests/easyscore_tests.js +488 -0
- package/build/esm/tests/factory_tests.js +44 -0
- package/build/esm/tests/font_tests.js +134 -0
- package/build/esm/tests/formatter/framestack.js +61 -0
- package/build/esm/tests/formatter/tests.js +251 -0
- package/build/esm/tests/formatter_tests.js +759 -0
- package/build/esm/tests/fraction_tests.js +72 -0
- package/build/esm/tests/ghostnote_tests.js +77 -0
- package/build/esm/tests/glyphnote_tests.js +119 -0
- package/build/esm/tests/gracenote_tests.js +414 -0
- package/build/esm/tests/gracetabnote_tests.js +79 -0
- package/build/esm/tests/index.js +68 -0
- package/build/esm/tests/key_clef_tests.js +106 -0
- package/build/esm/tests/keymanager_tests.js +68 -0
- package/build/esm/tests/keysignature_tests.js +322 -0
- package/build/esm/tests/mocks.js +70 -0
- package/build/esm/tests/modifier_tests.js +24 -0
- package/build/esm/tests/multimeasurerest_tests.js +141 -0
- package/build/esm/tests/music_tests.js +161 -0
- package/build/esm/tests/node_test_runner.js +31 -0
- package/build/esm/tests/notehead_tests.js +224 -0
- package/build/esm/tests/notesubgroup_tests.js +149 -0
- package/build/esm/tests/offscreencanvas_tests.js +47 -0
- package/build/esm/tests/ornament_tests.js +333 -0
- package/build/esm/tests/parser_tests.js +122 -0
- package/build/esm/tests/pedalmarking_tests.js +91 -0
- package/build/esm/tests/percussion_tests.js +184 -0
- package/build/esm/tests/playwright/flow.spec.js +127 -0
- package/build/esm/tests/playwright/visual_helpers.js +30 -0
- package/build/esm/tests/registry_tests.js +64 -0
- package/build/esm/tests/renderer_tests.js +113 -0
- package/build/esm/tests/rests_tests.js +266 -0
- package/build/esm/tests/rhythm_tests.js +357 -0
- package/build/esm/tests/stave_tests.js +570 -0
- package/build/esm/tests/staveconnector_tests.js +402 -0
- package/build/esm/tests/stavehairpin_tests.js +90 -0
- package/build/esm/tests/staveline_tests.js +123 -0
- package/build/esm/tests/stavemodifier_tests.js +51 -0
- package/build/esm/tests/stavenote_tests.js +936 -0
- package/build/esm/tests/stavetie_tests.js +137 -0
- package/build/esm/tests/stringnumber_tests.js +283 -0
- package/build/esm/tests/strokes_tests.js +289 -0
- package/build/esm/tests/style_tests.js +96 -0
- package/build/esm/tests/tabnote_tests.js +462 -0
- package/build/esm/tests/tabslide_tests.js +133 -0
- package/build/esm/tests/tabstave_tests.js +24 -0
- package/build/esm/tests/tabtie_tests.js +171 -0
- package/build/esm/tests/test_runner.js +23 -0
- package/build/esm/tests/textbracket_tests.js +100 -0
- package/build/esm/tests/textnote_tests.js +216 -0
- package/build/esm/tests/threevoice_tests.js +132 -0
- package/build/esm/tests/tickcontext_tests.js +36 -0
- package/build/esm/tests/timesignature_tests.js +173 -0
- package/build/esm/tests/tremolo_tests.js +34 -0
- package/build/esm/tests/tuning_tests.js +56 -0
- package/build/esm/tests/tuplet_tests.js +711 -0
- package/build/esm/tests/typeguard_tests.js +82 -0
- package/build/esm/tests/unison_tests.js +74 -0
- package/build/esm/tests/vexflow_test_helpers.js +318 -0
- package/build/esm/tests/vf_prefix_tests.js +101 -0
- package/build/esm/tests/vibrato_tests.js +93 -0
- package/build/esm/tests/vibratobracket_tests.js +45 -0
- package/build/esm/tests/vitest/job-0.test.js +2 -0
- package/build/esm/tests/vitest/job-1.test.js +2 -0
- package/build/esm/tests/vitest/job-2.test.js +2 -0
- package/build/esm/tests/vitest/job-3.test.js +2 -0
- package/build/esm/tests/vitest/run.js +5 -0
- package/build/esm/tests/vitest.setup.js +44 -0
- package/build/esm/tests/voice_tests.js +69 -0
- package/build/types/entry/vexflow-bravura.d.ts +3 -0
- package/build/types/entry/vexflow-core.d.ts +3 -0
- package/build/types/entry/vexflow-debug.d.ts +3 -0
- package/build/types/entry/vexflow.d.ts +3 -0
- package/build/types/src/accidental.d.ts +60 -0
- package/build/types/src/annotation.d.ts +58 -0
- package/build/types/src/articulation.d.ts +78 -0
- package/build/types/src/barnote.d.ts +29 -0
- package/build/types/src/beam.d.ts +158 -0
- package/build/types/src/bend.d.ts +67 -0
- package/build/types/src/boundingbox.d.ts +42 -0
- package/build/types/src/canvascontext.d.ts +93 -0
- package/build/types/src/chordsymbol.d.ts +109 -0
- package/build/types/src/clef.d.ts +38 -0
- package/build/types/src/clefnote.d.ts +17 -0
- package/build/types/src/crescendo.d.ts +26 -0
- package/build/types/src/curve.d.ts +42 -0
- package/build/types/src/dot.d.ts +19 -0
- package/build/types/src/easyscore.d.ts +152 -0
- package/build/types/src/element.d.ts +278 -0
- package/build/types/src/factory.d.ts +273 -0
- package/build/types/src/flag.d.ts +12 -0
- package/build/types/src/font.d.ts +96 -0
- package/build/types/src/fonts/academico.d.ts +1 -0
- package/build/types/src/fonts/academicobold.d.ts +1 -0
- package/build/types/src/fonts/bravura.d.ts +1 -0
- package/build/types/src/fonts/gonville.d.ts +1 -0
- package/build/types/src/fonts/petaluma.d.ts +1 -0
- package/build/types/src/fonts/petalumascript.d.ts +1 -0
- package/build/types/src/formatter.d.ts +226 -0
- package/build/types/src/fraction.d.ts +65 -0
- package/build/types/src/frethandfinger.d.ts +19 -0
- package/build/types/src/ghostnote.d.ts +16 -0
- package/build/types/src/glyphnote.d.ts +14 -0
- package/build/types/src/glyphs.d.ts +2935 -0
- package/build/types/src/gracenote.d.ts +17 -0
- package/build/types/src/gracenotegroup.d.ts +33 -0
- package/build/types/src/gracetabnote.d.ts +5 -0
- package/build/types/src/index.d.ts +86 -0
- package/build/types/src/keymanager.d.ts +25 -0
- package/build/types/src/keysignature.d.ts +50 -0
- package/build/types/src/keysignote.d.ts +11 -0
- package/build/types/src/metrics.d.ts +25 -0
- package/build/types/src/modifier.d.ts +90 -0
- package/build/types/src/modifiercontext.d.ts +48 -0
- package/build/types/src/multimeasurerest.d.ts +61 -0
- package/build/types/src/music.d.ts +91 -0
- package/build/types/src/note.d.ts +232 -0
- package/build/types/src/notehead.d.ts +50 -0
- package/build/types/src/notesubgroup.d.ts +18 -0
- package/build/types/src/ornament.d.ts +71 -0
- package/build/types/src/parenthesis.d.ts +21 -0
- package/build/types/src/parser.d.ts +45 -0
- package/build/types/src/pedalmarking.d.ts +63 -0
- package/build/types/src/registry.d.ts +40 -0
- package/build/types/src/rendercontext.d.ts +59 -0
- package/build/types/src/renderer.d.ts +35 -0
- package/build/types/src/repeatnote.d.ts +6 -0
- package/build/types/src/stave.d.ts +181 -0
- package/build/types/src/stavebarline.d.ts +38 -0
- package/build/types/src/staveconnector.d.ts +53 -0
- package/build/types/src/stavehairpin.d.ts +56 -0
- package/build/types/src/staveline.d.ts +49 -0
- package/build/types/src/stavemodifier.d.ts +35 -0
- package/build/types/src/stavenote.d.ts +150 -0
- package/build/types/src/staverepetition.d.ts +30 -0
- package/build/types/src/stavesection.d.ts +8 -0
- package/build/types/src/stavetempo.d.ts +43 -0
- package/build/types/src/stavetext.d.ts +11 -0
- package/build/types/src/stavetie.d.ts +104 -0
- package/build/types/src/stavevolta.d.ts +15 -0
- package/build/types/src/stem.d.ts +58 -0
- package/build/types/src/stemmablenote.d.ts +39 -0
- package/build/types/src/stringnumber.d.ts +26 -0
- package/build/types/src/strokes.d.ts +35 -0
- package/build/types/src/svgcontext.d.ts +135 -0
- package/build/types/src/system.d.ts +121 -0
- package/build/types/src/tables.d.ts +86 -0
- package/build/types/src/tabnote.d.ts +45 -0
- package/build/types/src/tabslide.d.ts +36 -0
- package/build/types/src/tabstave.d.ts +7 -0
- package/build/types/src/tabtie.d.ts +18 -0
- package/build/types/src/textbracket.d.ts +45 -0
- package/build/types/src/textdynamics.d.ts +34 -0
- package/build/types/src/textnote.d.ts +48 -0
- package/build/types/src/tickable.d.ts +149 -0
- package/build/types/src/tickcontext.d.ts +112 -0
- package/build/types/src/timesignature.d.ts +75 -0
- package/build/types/src/timesignote.d.ts +11 -0
- package/build/types/src/tremolo.d.ts +12 -0
- package/build/types/src/tuning.d.ts +23 -0
- package/build/types/src/tuplet.d.ts +98 -0
- package/build/types/src/typeguard.d.ts +100 -0
- package/build/types/src/util.d.ts +42 -0
- package/build/types/src/version.d.ts +3 -0
- package/build/types/src/vexflow.d.ts +261 -0
- package/build/types/src/vibrato.d.ts +20 -0
- package/build/types/src/vibratobracket.d.ts +28 -0
- package/build/types/src/voice.d.ts +109 -0
- package/build/types/src/web.d.ts +2 -0
- package/package.json +145 -0
- package/tests/flow.html +256 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Element } from './element.js';
|
|
2
|
+
import { Metrics } from './metrics.js';
|
|
3
|
+
import { Modifier } from './modifier.js';
|
|
4
|
+
import { isTabNote } from './typeguard.js';
|
|
5
|
+
import { RuntimeError } from './util.js';
|
|
6
|
+
export class Bend extends Modifier {
|
|
7
|
+
static get CATEGORY() {
|
|
8
|
+
return "Bend";
|
|
9
|
+
}
|
|
10
|
+
static get UP() {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
static get DOWN() {
|
|
14
|
+
return 1;
|
|
15
|
+
}
|
|
16
|
+
static format(bends, state) {
|
|
17
|
+
if (!bends || bends.length === 0)
|
|
18
|
+
return false;
|
|
19
|
+
let lastWidth = 0;
|
|
20
|
+
for (let i = 0; i < bends.length; ++i) {
|
|
21
|
+
const bend = bends[i];
|
|
22
|
+
const note = bend.checkAttachedNote();
|
|
23
|
+
if (isTabNote(note)) {
|
|
24
|
+
const stringPos = note.leastString() - 1;
|
|
25
|
+
if (state.topTextLine < stringPos) {
|
|
26
|
+
state.topTextLine = stringPos;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
bend.setXShift(lastWidth);
|
|
30
|
+
lastWidth = bend.getWidth();
|
|
31
|
+
bend.setTextLine(state.topTextLine);
|
|
32
|
+
}
|
|
33
|
+
state.rightShift += lastWidth;
|
|
34
|
+
state.topTextLine += 1;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
setStyleLine(style) {
|
|
38
|
+
this.styleLine = style;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
getStyleLine() {
|
|
42
|
+
return this.styleLine;
|
|
43
|
+
}
|
|
44
|
+
constructor(phrase) {
|
|
45
|
+
super();
|
|
46
|
+
this.styleLine = Metrics.getStyle('Bend.line');
|
|
47
|
+
this.xShift = 0;
|
|
48
|
+
this.tap = '';
|
|
49
|
+
this.renderOptions = {
|
|
50
|
+
bendWidth: 8,
|
|
51
|
+
releaseWidth: 8,
|
|
52
|
+
};
|
|
53
|
+
this.phrase = phrase;
|
|
54
|
+
this.updateWidth();
|
|
55
|
+
}
|
|
56
|
+
setXShift(value) {
|
|
57
|
+
this.xShift = value;
|
|
58
|
+
this.updateWidth();
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
setTap(value) {
|
|
62
|
+
this.tap = value;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
getTextHeight() {
|
|
66
|
+
const element = new Element("Bend");
|
|
67
|
+
element.setText(this.phrase[0].text);
|
|
68
|
+
return element.getHeight();
|
|
69
|
+
}
|
|
70
|
+
updateWidth() {
|
|
71
|
+
const measureText = (text) => {
|
|
72
|
+
const element = new Element("Bend");
|
|
73
|
+
element.setText(text);
|
|
74
|
+
return element.getWidth();
|
|
75
|
+
};
|
|
76
|
+
let totalWidth = 0;
|
|
77
|
+
for (let i = 0; i < this.phrase.length; ++i) {
|
|
78
|
+
const bend = this.phrase[i];
|
|
79
|
+
if (bend.width !== undefined) {
|
|
80
|
+
totalWidth += bend.width;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const additionalWidth = bend.type === Bend.UP ? this.renderOptions.bendWidth : this.renderOptions.releaseWidth;
|
|
84
|
+
bend.width = Math.max(additionalWidth, measureText(bend.text)) + 3;
|
|
85
|
+
bend.drawWidth = bend.width / 2;
|
|
86
|
+
totalWidth += bend.width;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
this.setWidth(totalWidth + this.xShift);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
draw() {
|
|
93
|
+
var _a;
|
|
94
|
+
const ctx = this.checkContext();
|
|
95
|
+
const note = this.checkAttachedNote();
|
|
96
|
+
this.setRendered();
|
|
97
|
+
const start = note.getModifierStartXY(Modifier.Position.RIGHT, this.index);
|
|
98
|
+
start.x += 3;
|
|
99
|
+
start.y += 0.5;
|
|
100
|
+
const xShift = this.xShift;
|
|
101
|
+
const stave = note.checkStave();
|
|
102
|
+
const spacing = stave.getSpacingBetweenLines();
|
|
103
|
+
const lowestY = note.getYs().reduce((a, b) => (a < b ? a : b));
|
|
104
|
+
const bendHeight = start.y - ((this.textLine + 1) * spacing + start.y - lowestY) + 3;
|
|
105
|
+
const annotationY = start.y - ((this.textLine + 1) * spacing + start.y - lowestY) - 1;
|
|
106
|
+
const renderBend = (x, y, width, height) => {
|
|
107
|
+
const cpX = x + width;
|
|
108
|
+
const cpY = y;
|
|
109
|
+
this.applyStyle(ctx, this.styleLine);
|
|
110
|
+
ctx.beginPath();
|
|
111
|
+
ctx.moveTo(x, y);
|
|
112
|
+
ctx.quadraticCurveTo(cpX, cpY, x + width, height);
|
|
113
|
+
ctx.stroke();
|
|
114
|
+
};
|
|
115
|
+
const renderRelease = (x, y, width, height) => {
|
|
116
|
+
this.applyStyle(ctx, this.styleLine);
|
|
117
|
+
ctx.beginPath();
|
|
118
|
+
ctx.moveTo(x, height);
|
|
119
|
+
ctx.quadraticCurveTo(x + width, height, x + width, y);
|
|
120
|
+
ctx.stroke();
|
|
121
|
+
};
|
|
122
|
+
const renderArrowHead = (x, y, direction) => {
|
|
123
|
+
const width = 4;
|
|
124
|
+
const yBase = y + width * direction;
|
|
125
|
+
ctx.beginPath();
|
|
126
|
+
ctx.moveTo(x, y);
|
|
127
|
+
ctx.lineTo(x - width, yBase);
|
|
128
|
+
ctx.lineTo(x + width, yBase);
|
|
129
|
+
ctx.closePath();
|
|
130
|
+
ctx.fill();
|
|
131
|
+
};
|
|
132
|
+
const renderText = (x, text) => {
|
|
133
|
+
ctx.setFont(this.fontInfo);
|
|
134
|
+
const renderX = x - ctx.measureText(text).width / 2;
|
|
135
|
+
ctx.fillText(text, renderX, annotationY);
|
|
136
|
+
};
|
|
137
|
+
let lastBend = undefined;
|
|
138
|
+
let lastBendDrawWidth = 0;
|
|
139
|
+
let lastDrawnWidth = 0;
|
|
140
|
+
if ((_a = this.tap) === null || _a === void 0 ? void 0 : _a.length) {
|
|
141
|
+
const tapStart = note.getModifierStartXY(Modifier.Position.CENTER, this.index);
|
|
142
|
+
renderText(tapStart.x, this.tap);
|
|
143
|
+
}
|
|
144
|
+
for (let i = 0; i < this.phrase.length; ++i) {
|
|
145
|
+
const bend = this.phrase[i];
|
|
146
|
+
if (!bend.drawWidth)
|
|
147
|
+
bend.drawWidth = 0;
|
|
148
|
+
if (i === 0)
|
|
149
|
+
bend.drawWidth += xShift;
|
|
150
|
+
lastDrawnWidth = bend.drawWidth + lastBendDrawWidth - (i === 1 ? xShift : 0);
|
|
151
|
+
if (bend.type === Bend.UP) {
|
|
152
|
+
if (lastBend && lastBend.type === Bend.UP) {
|
|
153
|
+
renderArrowHead(start.x, bendHeight, +1);
|
|
154
|
+
}
|
|
155
|
+
renderBend(start.x, start.y, lastDrawnWidth, bendHeight);
|
|
156
|
+
}
|
|
157
|
+
if (bend.type === Bend.DOWN) {
|
|
158
|
+
if (lastBend && lastBend.type === Bend.UP) {
|
|
159
|
+
renderRelease(start.x, start.y, lastDrawnWidth, bendHeight);
|
|
160
|
+
}
|
|
161
|
+
if (lastBend && lastBend.type === Bend.DOWN) {
|
|
162
|
+
renderArrowHead(start.x, start.y, -1);
|
|
163
|
+
renderRelease(start.x, start.y, lastDrawnWidth, bendHeight);
|
|
164
|
+
}
|
|
165
|
+
if (!lastBend) {
|
|
166
|
+
lastDrawnWidth = bend.drawWidth;
|
|
167
|
+
renderRelease(start.x, start.y, lastDrawnWidth, bendHeight);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
renderText(start.x + lastDrawnWidth, bend.text);
|
|
171
|
+
lastBend = bend;
|
|
172
|
+
lastBendDrawWidth = bend.drawWidth;
|
|
173
|
+
lastBend.x = start.x;
|
|
174
|
+
start.x += lastDrawnWidth;
|
|
175
|
+
}
|
|
176
|
+
if (!lastBend || lastBend.x === undefined) {
|
|
177
|
+
throw new RuntimeError('NoLastBendForBend', 'Internal error.');
|
|
178
|
+
}
|
|
179
|
+
if (lastBend.type === Bend.UP) {
|
|
180
|
+
renderArrowHead(lastBend.x + lastDrawnWidth, bendHeight, +1);
|
|
181
|
+
}
|
|
182
|
+
else if (lastBend.type === Bend.DOWN) {
|
|
183
|
+
renderArrowHead(lastBend.x + lastDrawnWidth, start.y, -1);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export class BoundingBox {
|
|
2
|
+
static copy(that) {
|
|
3
|
+
return new BoundingBox(that.x, that.y, that.w, that.h);
|
|
4
|
+
}
|
|
5
|
+
constructor(x, y, w, h) {
|
|
6
|
+
this.x = x;
|
|
7
|
+
this.y = y;
|
|
8
|
+
this.w = w;
|
|
9
|
+
this.h = h;
|
|
10
|
+
}
|
|
11
|
+
getX() {
|
|
12
|
+
return this.x;
|
|
13
|
+
}
|
|
14
|
+
getY() {
|
|
15
|
+
return this.y;
|
|
16
|
+
}
|
|
17
|
+
getW() {
|
|
18
|
+
return this.w;
|
|
19
|
+
}
|
|
20
|
+
getH() {
|
|
21
|
+
return this.h;
|
|
22
|
+
}
|
|
23
|
+
setX(x) {
|
|
24
|
+
this.x = x;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
setY(y) {
|
|
28
|
+
this.y = y;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
setW(w) {
|
|
32
|
+
this.w = w;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
setH(h) {
|
|
36
|
+
this.h = h;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
move(x, y) {
|
|
40
|
+
this.x += x;
|
|
41
|
+
this.y += y;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
clone() {
|
|
45
|
+
return BoundingBox.copy(this);
|
|
46
|
+
}
|
|
47
|
+
mergeWith(boundingBox) {
|
|
48
|
+
const that = boundingBox;
|
|
49
|
+
const newX = this.x < that.x ? this.x : that.x;
|
|
50
|
+
const newY = this.y < that.y ? this.y : that.y;
|
|
51
|
+
const newW = Math.max(this.x + this.w, that.x + that.w) - newX;
|
|
52
|
+
const newH = Math.max(this.y + this.h, that.y + that.h) - newY;
|
|
53
|
+
this.x = newX;
|
|
54
|
+
this.y = newY;
|
|
55
|
+
this.w = newW;
|
|
56
|
+
this.h = newH;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { Font } from './font.js';
|
|
2
|
+
import { RenderContext } from './rendercontext.js';
|
|
3
|
+
import { globalObject, warn } from './util.js';
|
|
4
|
+
import { isHTMLCanvas } from './web.js';
|
|
5
|
+
export class CanvasContext extends RenderContext {
|
|
6
|
+
static get WIDTH() {
|
|
7
|
+
return 600;
|
|
8
|
+
}
|
|
9
|
+
static get HEIGHT() {
|
|
10
|
+
return 400;
|
|
11
|
+
}
|
|
12
|
+
static get CANVAS_BROWSER_SIZE_LIMIT() {
|
|
13
|
+
return 32767;
|
|
14
|
+
}
|
|
15
|
+
static sanitizeCanvasDims(width, height) {
|
|
16
|
+
const limit = this.CANVAS_BROWSER_SIZE_LIMIT;
|
|
17
|
+
if (Math.max(width, height) > limit) {
|
|
18
|
+
warn('Canvas dimensions exceed browser limit. Cropping to ' + limit);
|
|
19
|
+
if (width > limit) {
|
|
20
|
+
width = limit;
|
|
21
|
+
}
|
|
22
|
+
if (height > limit) {
|
|
23
|
+
height = limit;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return [width, height];
|
|
27
|
+
}
|
|
28
|
+
constructor(context) {
|
|
29
|
+
super();
|
|
30
|
+
this.textHeight = 0;
|
|
31
|
+
this.context2D = context;
|
|
32
|
+
this.curTransfrom = context.getTransform();
|
|
33
|
+
if (!context.canvas) {
|
|
34
|
+
this.canvas = {
|
|
35
|
+
width: CanvasContext.WIDTH,
|
|
36
|
+
height: CanvasContext.HEIGHT,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.canvas = context.canvas;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
clear() {
|
|
44
|
+
this.context2D.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
45
|
+
}
|
|
46
|
+
openGroup(cls, id) {
|
|
47
|
+
}
|
|
48
|
+
closeGroup() {
|
|
49
|
+
}
|
|
50
|
+
openRotation(angleDegrees, x, y) {
|
|
51
|
+
this.curTransfrom = this.context2D.getTransform();
|
|
52
|
+
this.context2D.translate(x, y);
|
|
53
|
+
this.context2D.rotate((angleDegrees * Math.PI) / 180);
|
|
54
|
+
this.context2D.translate(-x, -y);
|
|
55
|
+
}
|
|
56
|
+
closeRotation() {
|
|
57
|
+
this.context2D.setTransform(this.curTransfrom);
|
|
58
|
+
}
|
|
59
|
+
add(child) {
|
|
60
|
+
}
|
|
61
|
+
setFillStyle(style) {
|
|
62
|
+
this.context2D.fillStyle = style;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
setBackgroundFillStyle(style) {
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
setStrokeStyle(style) {
|
|
69
|
+
this.context2D.strokeStyle = style;
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
setShadowColor(color) {
|
|
73
|
+
this.context2D.shadowColor = color;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
setShadowBlur(blur) {
|
|
77
|
+
const t = this.context2D.getTransform();
|
|
78
|
+
const scale = Math.sqrt(t.a * t.a + t.b * t.b + t.c * t.c + t.d * t.d);
|
|
79
|
+
this.context2D.shadowBlur = scale * blur;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
setLineWidth(width) {
|
|
83
|
+
this.context2D.lineWidth = width;
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
setLineCap(capType) {
|
|
87
|
+
this.context2D.lineCap = capType;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
setLineDash(dash) {
|
|
91
|
+
this.context2D.setLineDash(dash);
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
scale(x, y) {
|
|
95
|
+
this.context2D.scale(x, y);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
resize(width, height, devicePixelRatio) {
|
|
99
|
+
var _a;
|
|
100
|
+
const canvas = this.context2D.canvas;
|
|
101
|
+
const dpr = (_a = devicePixelRatio !== null && devicePixelRatio !== void 0 ? devicePixelRatio : globalObject().devicePixelRatio) !== null && _a !== void 0 ? _a : 1;
|
|
102
|
+
[width, height] = CanvasContext.sanitizeCanvasDims(width * dpr, height * dpr);
|
|
103
|
+
width = (width / dpr) | 0;
|
|
104
|
+
height = (height / dpr) | 0;
|
|
105
|
+
canvas.width = width * dpr;
|
|
106
|
+
canvas.height = height * dpr;
|
|
107
|
+
if (isHTMLCanvas(canvas)) {
|
|
108
|
+
canvas.style.width = width + 'px';
|
|
109
|
+
canvas.style.height = height + 'px';
|
|
110
|
+
}
|
|
111
|
+
return this.scale(dpr, dpr);
|
|
112
|
+
}
|
|
113
|
+
rect(x, y, width, height) {
|
|
114
|
+
this.context2D.rect(x, y, width, height);
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
fillRect(x, y, width, height) {
|
|
118
|
+
this.context2D.fillRect(x, y, width, height);
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
pointerRect(x, y, width, height) {
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
clearRect(x, y, width, height) {
|
|
125
|
+
this.context2D.clearRect(x, y, width, height);
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
beginPath() {
|
|
129
|
+
this.context2D.beginPath();
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
moveTo(x, y) {
|
|
133
|
+
this.context2D.moveTo(x, y);
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
lineTo(x, y) {
|
|
137
|
+
this.context2D.lineTo(x, y);
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
141
|
+
this.context2D.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
quadraticCurveTo(cpx, cpy, x, y) {
|
|
145
|
+
this.context2D.quadraticCurveTo(cpx, cpy, x, y);
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
arc(x, y, radius, startAngle, endAngle, counterclockwise) {
|
|
149
|
+
this.context2D.arc(x, y, radius, startAngle, endAngle, counterclockwise);
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
fill() {
|
|
153
|
+
this.context2D.fill();
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
stroke() {
|
|
157
|
+
this.context2D.stroke();
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
closePath() {
|
|
161
|
+
this.context2D.closePath();
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
measureText(text) {
|
|
165
|
+
const metrics = this.context2D.measureText(text);
|
|
166
|
+
let y = 0;
|
|
167
|
+
let height = 0;
|
|
168
|
+
if (metrics.fontBoundingBoxAscent) {
|
|
169
|
+
y = -metrics.fontBoundingBoxAscent;
|
|
170
|
+
height = metrics.fontBoundingBoxDescent + metrics.fontBoundingBoxAscent;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
y = -metrics.actualBoundingBoxAscent;
|
|
174
|
+
height = metrics.actualBoundingBoxDescent + metrics.actualBoundingBoxAscent;
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
x: 0,
|
|
178
|
+
y: y,
|
|
179
|
+
width: metrics.width,
|
|
180
|
+
height: height,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
fillText(text, x, y) {
|
|
184
|
+
this.context2D.fillText(text, x, y);
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
save() {
|
|
188
|
+
this.context2D.save();
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
restore() {
|
|
192
|
+
this.context2D.restore();
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
set fillStyle(style) {
|
|
196
|
+
this.context2D.fillStyle = style;
|
|
197
|
+
}
|
|
198
|
+
get fillStyle() {
|
|
199
|
+
return this.context2D.fillStyle;
|
|
200
|
+
}
|
|
201
|
+
set strokeStyle(style) {
|
|
202
|
+
this.context2D.strokeStyle = style;
|
|
203
|
+
}
|
|
204
|
+
get strokeStyle() {
|
|
205
|
+
return this.context2D.strokeStyle;
|
|
206
|
+
}
|
|
207
|
+
setFont(f, size, weight, style) {
|
|
208
|
+
const fontInfo = Font.validate(f, size, weight, style);
|
|
209
|
+
this.context2D.font = Font.toCSSString(fontInfo);
|
|
210
|
+
this.textHeight = Font.convertSizeToPixelValue(fontInfo.size);
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
getFont() {
|
|
214
|
+
return this.context2D.font;
|
|
215
|
+
}
|
|
216
|
+
}
|