vexflow 4.0.1-beta.0 → 4.0.1-beta.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.
Files changed (328) hide show
  1. package/build/cjs/vexflow-bravura.js +2 -2
  2. package/build/cjs/vexflow-bravura.js.map +1 -1
  3. package/build/cjs/vexflow-core.js +2 -2
  4. package/build/cjs/vexflow-core.js.map +1 -1
  5. package/build/cjs/vexflow-debug-with-tests.js +126 -26
  6. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  7. package/build/cjs/vexflow-debug.js +94 -26
  8. package/build/cjs/vexflow-debug.js.map +1 -1
  9. package/build/cjs/vexflow-gonville.js +2 -2
  10. package/build/cjs/vexflow-gonville.js.map +1 -1
  11. package/build/cjs/vexflow-petaluma.js +2 -2
  12. package/build/cjs/vexflow-petaluma.js.map +1 -1
  13. package/build/cjs/vexflow.js +2 -2
  14. package/build/cjs/vexflow.js.map +1 -1
  15. package/build/esm/src/version.js +3 -3
  16. package/package.json +1 -1
  17. package/src/note.ts +2 -2
  18. package/src/stavenote.ts +80 -16
  19. package/build/esm/entry/vexflow-bravura.js +0 -11
  20. package/build/esm/entry/vexflow-core.js +0 -54
  21. package/build/esm/entry/vexflow-debug-with-tests.js +0 -4
  22. package/build/esm/entry/vexflow-debug.js +0 -3
  23. package/build/esm/entry/vexflow-font-bravura.js +0 -7
  24. package/build/esm/entry/vexflow-font-custom.js +0 -7
  25. package/build/esm/entry/vexflow-font-gonville.js +0 -7
  26. package/build/esm/entry/vexflow-font-petaluma.js +0 -7
  27. package/build/esm/entry/vexflow-gonville.js +0 -11
  28. package/build/esm/entry/vexflow-petaluma.js +0 -11
  29. package/build/esm/entry/vexflow.js +0 -9
  30. package/build/esm/src/accidental.js +0 -348
  31. package/build/esm/src/annotation.js +0 -213
  32. package/build/esm/src/articulation.js +0 -264
  33. package/build/esm/src/barnote.js +0 -58
  34. package/build/esm/src/beam.js +0 -632
  35. package/build/esm/src/bend.js +0 -202
  36. package/build/esm/src/boundingbox.js +0 -59
  37. package/build/esm/src/boundingboxcomputation.js +0 -107
  38. package/build/esm/src/canvascontext.js +0 -202
  39. package/build/esm/src/chordsymbol.js +0 -578
  40. package/build/esm/src/clef.js +0 -153
  41. package/build/esm/src/clefnote.js +0 -65
  42. package/build/esm/src/crescendo.js +0 -77
  43. package/build/esm/src/curve.js +0 -118
  44. package/build/esm/src/dot.js +0 -137
  45. package/build/esm/src/easyscore.js +0 -374
  46. package/build/esm/src/element.js +0 -216
  47. package/build/esm/src/factory.js +0 -440
  48. package/build/esm/src/flow.js +0 -275
  49. package/build/esm/src/font.js +0 -264
  50. package/build/esm/src/fonts/bravura_glyphs.js +0 -3239
  51. package/build/esm/src/fonts/bravura_metrics.js +0 -507
  52. package/build/esm/src/fonts/custom_glyphs.js +0 -78
  53. package/build/esm/src/fonts/custom_metrics.js +0 -5
  54. package/build/esm/src/fonts/gonville_glyphs.js +0 -828
  55. package/build/esm/src/fonts/gonville_metrics.js +0 -421
  56. package/build/esm/src/fonts/load_all.js +0 -10
  57. package/build/esm/src/fonts/load_bravura.js +0 -6
  58. package/build/esm/src/fonts/load_custom.js +0 -6
  59. package/build/esm/src/fonts/load_gonville.js +0 -6
  60. package/build/esm/src/fonts/load_petaluma.js +0 -6
  61. package/build/esm/src/fonts/petaluma_glyphs.js +0 -1335
  62. package/build/esm/src/fonts/petaluma_metrics.js +0 -536
  63. package/build/esm/src/fonts/petalumascript_glyphs.js +0 -863
  64. package/build/esm/src/fonts/robotoslab_glyphs.js +0 -863
  65. package/build/esm/src/fonts/textfonts.js +0 -44
  66. package/build/esm/src/formatter.js +0 -568
  67. package/build/esm/src/fraction.js +0 -171
  68. package/build/esm/src/frethandfinger.js +0 -156
  69. package/build/esm/src/ghostnote.js +0 -50
  70. package/build/esm/src/glyph.js +0 -331
  71. package/build/esm/src/glyphnote.js +0 -55
  72. package/build/esm/src/gracenote.js +0 -133
  73. package/build/esm/src/gracenotegroup.js +0 -128
  74. package/build/esm/src/gracetabnote.js +0 -12
  75. package/build/esm/src/index.js +0 -91
  76. package/build/esm/src/keymanager.js +0 -99
  77. package/build/esm/src/keysignature.js +0 -250
  78. package/build/esm/src/keysignote.js +0 -28
  79. package/build/esm/src/modifier.js +0 -128
  80. package/build/esm/src/modifiercontext.js +0 -110
  81. package/build/esm/src/multimeasurerest.js +0 -173
  82. package/build/esm/src/music.js +0 -322
  83. package/build/esm/src/note.js +0 -371
  84. package/build/esm/src/notehead.js +0 -169
  85. package/build/esm/src/notesubgroup.js +0 -59
  86. package/build/esm/src/ornament.js +0 -206
  87. package/build/esm/src/parenthesis.js +0 -76
  88. package/build/esm/src/parser.js +0 -164
  89. package/build/esm/src/pedalmarking.js +0 -192
  90. package/build/esm/src/registry.js +0 -81
  91. package/build/esm/src/rendercontext.js +0 -24
  92. package/build/esm/src/renderer.js +0 -112
  93. package/build/esm/src/repeatnote.js +0 -22
  94. package/build/esm/src/stave.js +0 -547
  95. package/build/esm/src/stavebarline.js +0 -182
  96. package/build/esm/src/staveconnector.js +0 -196
  97. package/build/esm/src/stavehairpin.js +0 -120
  98. package/build/esm/src/staveline.js +0 -218
  99. package/build/esm/src/stavemodifier.js +0 -77
  100. package/build/esm/src/stavenote.js +0 -799
  101. package/build/esm/src/staverepetition.js +0 -155
  102. package/build/esm/src/stavesection.js +0 -58
  103. package/build/esm/src/stavetempo.js +0 -91
  104. package/build/esm/src/stavetext.js +0 -82
  105. package/build/esm/src/stavetie.js +0 -141
  106. package/build/esm/src/stavevolta.js +0 -67
  107. package/build/esm/src/stem.js +0 -131
  108. package/build/esm/src/stemmablenote.js +0 -193
  109. package/build/esm/src/stringnumber.js +0 -231
  110. package/build/esm/src/strokes.js +0 -200
  111. package/build/esm/src/svgcontext.js +0 -414
  112. package/build/esm/src/system.js +0 -116
  113. package/build/esm/src/tables.js +0 -1102
  114. package/build/esm/src/tabnote.js +0 -299
  115. package/build/esm/src/tabslide.js +0 -76
  116. package/build/esm/src/tabstave.js +0 -17
  117. package/build/esm/src/tabtie.js +0 -19
  118. package/build/esm/src/textbracket.js +0 -144
  119. package/build/esm/src/textdynamics.js +0 -81
  120. package/build/esm/src/textformatter.js +0 -177
  121. package/build/esm/src/textnote.js +0 -176
  122. package/build/esm/src/tickable.js +0 -214
  123. package/build/esm/src/tickcontext.js +0 -170
  124. package/build/esm/src/timesigglyph.js +0 -85
  125. package/build/esm/src/timesignature.js +0 -89
  126. package/build/esm/src/timesignote.js +0 -32
  127. package/build/esm/src/tremolo.js +0 -47
  128. package/build/esm/src/tuning.js +0 -54
  129. package/build/esm/src/tuplet.js +0 -240
  130. package/build/esm/src/typeguard.js +0 -30
  131. package/build/esm/src/util.js +0 -58
  132. package/build/esm/src/vex.js +0 -51
  133. package/build/esm/src/vibrato.js +0 -100
  134. package/build/esm/src/vibratobracket.js +0 -50
  135. package/build/esm/src/voice.js +0 -187
  136. package/build/esm/src/web.js +0 -15
  137. package/build/esm/tests/accidental_tests.js +0 -974
  138. package/build/esm/tests/annotation_tests.js +0 -377
  139. package/build/esm/tests/articulation_tests.js +0 -365
  140. package/build/esm/tests/auto_beam_formatting_tests.js +0 -548
  141. package/build/esm/tests/bach_tests.js +0 -335
  142. package/build/esm/tests/barline_tests.js +0 -52
  143. package/build/esm/tests/beam_tests.js +0 -595
  144. package/build/esm/tests/bend_tests.js +0 -215
  145. package/build/esm/tests/boundingbox_tests.js +0 -53
  146. package/build/esm/tests/boundingboxcomputation_tests.js +0 -183
  147. package/build/esm/tests/chordsymbol_tests.js +0 -320
  148. package/build/esm/tests/clef_tests.js +0 -131
  149. package/build/esm/tests/curve_tests.js +0 -118
  150. package/build/esm/tests/dot_tests.js +0 -123
  151. package/build/esm/tests/easyscore_tests.js +0 -459
  152. package/build/esm/tests/factory_tests.js +0 -44
  153. package/build/esm/tests/font_tests.js +0 -135
  154. package/build/esm/tests/formatter/framestack.js +0 -61
  155. package/build/esm/tests/formatter/tests.js +0 -203
  156. package/build/esm/tests/formatter_tests.js +0 -669
  157. package/build/esm/tests/fraction_tests.js +0 -72
  158. package/build/esm/tests/ghostnote_tests.js +0 -77
  159. package/build/esm/tests/glyphnote_tests.js +0 -113
  160. package/build/esm/tests/gracenote_tests.js +0 -370
  161. package/build/esm/tests/gracetabnote_tests.js +0 -79
  162. package/build/esm/tests/index.js +0 -68
  163. package/build/esm/tests/key_clef_tests.js +0 -103
  164. package/build/esm/tests/keymanager_tests.js +0 -68
  165. package/build/esm/tests/keysignature_tests.js +0 -308
  166. package/build/esm/tests/mocks.js +0 -71
  167. package/build/esm/tests/modifier_tests.js +0 -24
  168. package/build/esm/tests/multimeasurerest_tests.js +0 -141
  169. package/build/esm/tests/music_tests.js +0 -161
  170. package/build/esm/tests/notehead_tests.js +0 -137
  171. package/build/esm/tests/notesubgroup_tests.js +0 -149
  172. package/build/esm/tests/offscreencanvas_tests.js +0 -47
  173. package/build/esm/tests/ornament_tests.js +0 -298
  174. package/build/esm/tests/parser_tests.js +0 -122
  175. package/build/esm/tests/pedalmarking_tests.js +0 -64
  176. package/build/esm/tests/percussion_tests.js +0 -180
  177. package/build/esm/tests/registry_tests.js +0 -64
  178. package/build/esm/tests/renderer_tests.js +0 -113
  179. package/build/esm/tests/rests_tests.js +0 -248
  180. package/build/esm/tests/rhythm_tests.js +0 -357
  181. package/build/esm/tests/stave_tests.js +0 -560
  182. package/build/esm/tests/staveconnector_tests.js +0 -402
  183. package/build/esm/tests/stavehairpin_tests.js +0 -90
  184. package/build/esm/tests/staveline_tests.js +0 -122
  185. package/build/esm/tests/stavemodifier_tests.js +0 -51
  186. package/build/esm/tests/stavenote_tests.js +0 -835
  187. package/build/esm/tests/stavetie_tests.js +0 -108
  188. package/build/esm/tests/stringnumber_tests.js +0 -259
  189. package/build/esm/tests/strokes_tests.js +0 -275
  190. package/build/esm/tests/style_tests.js +0 -98
  191. package/build/esm/tests/support/qunit.js +0 -2765
  192. package/build/esm/tests/tabnote_tests.js +0 -474
  193. package/build/esm/tests/tabslide_tests.js +0 -135
  194. package/build/esm/tests/tabstave_tests.js +0 -23
  195. package/build/esm/tests/tabtie_tests.js +0 -173
  196. package/build/esm/tests/textbracket_tests.js +0 -100
  197. package/build/esm/tests/textformatter_tests.js +0 -24
  198. package/build/esm/tests/textnote_tests.js +0 -215
  199. package/build/esm/tests/threevoice_tests.js +0 -132
  200. package/build/esm/tests/tickcontext_tests.js +0 -36
  201. package/build/esm/tests/timesignature_tests.js +0 -134
  202. package/build/esm/tests/tremolo_tests.js +0 -75
  203. package/build/esm/tests/tuning_tests.js +0 -56
  204. package/build/esm/tests/tuplet_tests.js +0 -450
  205. package/build/esm/tests/typeguard_tests.js +0 -82
  206. package/build/esm/tests/vexflow_test_helpers.js +0 -266
  207. package/build/esm/tests/vf_prefix_tests.js +0 -115
  208. package/build/esm/tests/vibrato_tests.js +0 -92
  209. package/build/esm/tests/vibratobracket_tests.js +0 -45
  210. package/build/esm/tests/voice_tests.js +0 -69
  211. package/build/types/entry/vexflow-bravura.d.ts +0 -3
  212. package/build/types/entry/vexflow-core.d.ts +0 -3
  213. package/build/types/entry/vexflow-debug.d.ts +0 -3
  214. package/build/types/entry/vexflow-font-bravura.d.ts +0 -3771
  215. package/build/types/entry/vexflow-font-custom.d.ts +0 -86
  216. package/build/types/entry/vexflow-font-gonville.d.ts +0 -1267
  217. package/build/types/entry/vexflow-font-petaluma.d.ts +0 -1896
  218. package/build/types/entry/vexflow-gonville.d.ts +0 -3
  219. package/build/types/entry/vexflow-petaluma.d.ts +0 -3
  220. package/build/types/entry/vexflow.d.ts +0 -3
  221. package/build/types/src/accidental.d.ts +0 -66
  222. package/build/types/src/annotation.d.ts +0 -60
  223. package/build/types/src/articulation.d.ts +0 -62
  224. package/build/types/src/barnote.d.ts +0 -29
  225. package/build/types/src/beam.d.ts +0 -124
  226. package/build/types/src/bend.d.ts +0 -73
  227. package/build/types/src/boundingbox.d.ts +0 -42
  228. package/build/types/src/boundingboxcomputation.d.ts +0 -33
  229. package/build/types/src/canvascontext.d.ts +0 -89
  230. package/build/types/src/chordsymbol.d.ts +0 -149
  231. package/build/types/src/clef.d.ts +0 -48
  232. package/build/types/src/clefnote.d.ts +0 -25
  233. package/build/types/src/crescendo.d.ts +0 -27
  234. package/build/types/src/curve.d.ts +0 -41
  235. package/build/types/src/dot.d.ts +0 -20
  236. package/build/types/src/easyscore.d.ts +0 -148
  237. package/build/types/src/element.d.ts +0 -202
  238. package/build/types/src/factory.d.ts +0 -271
  239. package/build/types/src/flow.d.ts +0 -245
  240. package/build/types/src/font.d.ts +0 -181
  241. package/build/types/src/fonts/bravura_glyphs.d.ts +0 -3239
  242. package/build/types/src/fonts/bravura_metrics.d.ts +0 -533
  243. package/build/types/src/fonts/custom_glyphs.d.ts +0 -78
  244. package/build/types/src/fonts/custom_metrics.d.ts +0 -5
  245. package/build/types/src/fonts/gonville_glyphs.d.ts +0 -828
  246. package/build/types/src/fonts/gonville_metrics.d.ts +0 -440
  247. package/build/types/src/fonts/load_all.d.ts +0 -1
  248. package/build/types/src/fonts/load_bravura.d.ts +0 -1
  249. package/build/types/src/fonts/load_custom.d.ts +0 -1
  250. package/build/types/src/fonts/load_gonville.d.ts +0 -1
  251. package/build/types/src/fonts/load_petaluma.d.ts +0 -1
  252. package/build/types/src/fonts/petaluma_glyphs.d.ts +0 -1335
  253. package/build/types/src/fonts/petaluma_metrics.d.ts +0 -562
  254. package/build/types/src/fonts/petalumascript_glyphs.d.ts +0 -863
  255. package/build/types/src/fonts/robotoslab_glyphs.d.ts +0 -863
  256. package/build/types/src/fonts/textfonts.d.ts +0 -1
  257. package/build/types/src/formatter.d.ts +0 -203
  258. package/build/types/src/fraction.d.ts +0 -62
  259. package/build/types/src/frethandfinger.d.ts +0 -22
  260. package/build/types/src/ghostnote.d.ts +0 -16
  261. package/build/types/src/glyph.d.ts +0 -139
  262. package/build/types/src/glyphnote.d.ts +0 -17
  263. package/build/types/src/gracenote.d.ts +0 -19
  264. package/build/types/src/gracenotegroup.d.ts +0 -33
  265. package/build/types/src/gracetabnote.d.ts +0 -5
  266. package/build/types/src/index.d.ts +0 -91
  267. package/build/types/src/keymanager.d.ts +0 -25
  268. package/build/types/src/keysignature.d.ts +0 -50
  269. package/build/types/src/keysignote.d.ts +0 -11
  270. package/build/types/src/modifier.d.ts +0 -97
  271. package/build/types/src/modifiercontext.d.ts +0 -45
  272. package/build/types/src/multimeasurerest.d.ts +0 -61
  273. package/build/types/src/music.d.ts +0 -91
  274. package/build/types/src/note.d.ts +0 -230
  275. package/build/types/src/notehead.d.ts +0 -70
  276. package/build/types/src/notesubgroup.d.ts +0 -18
  277. package/build/types/src/ornament.d.ts +0 -76
  278. package/build/types/src/parenthesis.d.ts +0 -22
  279. package/build/types/src/parser.d.ts +0 -45
  280. package/build/types/src/pedalmarking.d.ts +0 -69
  281. package/build/types/src/registry.d.ts +0 -40
  282. package/build/types/src/rendercontext.d.ts +0 -64
  283. package/build/types/src/renderer.d.ts +0 -35
  284. package/build/types/src/repeatnote.d.ts +0 -6
  285. package/build/types/src/stave.d.ts +0 -186
  286. package/build/types/src/stavebarline.d.ts +0 -28
  287. package/build/types/src/staveconnector.d.ts +0 -67
  288. package/build/types/src/stavehairpin.d.ts +0 -56
  289. package/build/types/src/staveline.d.ts +0 -57
  290. package/build/types/src/stavemodifier.d.ts +0 -44
  291. package/build/types/src/stavenote.d.ts +0 -154
  292. package/build/types/src/staverepetition.d.ts +0 -32
  293. package/build/types/src/stavesection.d.ts +0 -15
  294. package/build/types/src/stavetempo.d.ts +0 -25
  295. package/build/types/src/stavetext.d.ts +0 -25
  296. package/build/types/src/stavetie.d.ts +0 -59
  297. package/build/types/src/stavevolta.d.ts +0 -21
  298. package/build/types/src/stem.d.ts +0 -58
  299. package/build/types/src/stemmablenote.d.ts +0 -39
  300. package/build/types/src/stringnumber.d.ts +0 -27
  301. package/build/types/src/strokes.d.ts +0 -33
  302. package/build/types/src/svgcontext.d.ts +0 -131
  303. package/build/types/src/system.d.ts +0 -92
  304. package/build/types/src/tables.d.ts +0 -96
  305. package/build/types/src/tabnote.d.ts +0 -44
  306. package/build/types/src/tabslide.d.ts +0 -34
  307. package/build/types/src/tabstave.d.ts +0 -7
  308. package/build/types/src/tabtie.d.ts +0 -18
  309. package/build/types/src/textbracket.d.ts +0 -55
  310. package/build/types/src/textdynamics.d.ts +0 -39
  311. package/build/types/src/textformatter.d.ts +0 -109
  312. package/build/types/src/textnote.d.ts +0 -49
  313. package/build/types/src/tickable.d.ts +0 -140
  314. package/build/types/src/tickcontext.d.ts +0 -82
  315. package/build/types/src/timesigglyph.d.ts +0 -14
  316. package/build/types/src/timesignature.d.ts +0 -26
  317. package/build/types/src/timesignote.d.ts +0 -11
  318. package/build/types/src/tremolo.d.ts +0 -17
  319. package/build/types/src/tuning.d.ts +0 -23
  320. package/build/types/src/tuplet.d.ts +0 -105
  321. package/build/types/src/typeguard.d.ts +0 -99
  322. package/build/types/src/util.d.ts +0 -27
  323. package/build/types/src/version.d.ts +0 -3
  324. package/build/types/src/vex.d.ts +0 -18
  325. package/build/types/src/vibrato.d.ts +0 -29
  326. package/build/types/src/vibratobracket.d.ts +0 -33
  327. package/build/types/src/voice.d.ts +0 -108
  328. package/build/types/src/web.d.ts +0 -2
@@ -1,200 +0,0 @@
1
- import { Font, FontStyle, FontWeight } from './font.js';
2
- import { Glyph } from './glyph.js';
3
- import { Modifier } from './modifier.js';
4
- import { isNote, isStaveNote, isTabNote } from './typeguard.js';
5
- import { RuntimeError } from './util.js';
6
- export class Stroke extends Modifier {
7
- constructor(type, options) {
8
- super();
9
- this.options = Object.assign({ all_voices: true }, options);
10
- this.all_voices = this.options.all_voices;
11
- this.type = type;
12
- this.position = Modifier.Position.LEFT;
13
- this.render_options = {
14
- font_scale: 38,
15
- };
16
- this.resetFont();
17
- this.setXShift(0);
18
- this.setWidth(10);
19
- }
20
- static get CATEGORY() {
21
- return "Stroke";
22
- }
23
- static format(strokes, state) {
24
- const left_shift = state.left_shift;
25
- const stroke_spacing = 0;
26
- if (!strokes || strokes.length === 0)
27
- return false;
28
- const strokeList = strokes.map((stroke) => {
29
- const note = stroke.getNote();
30
- const index = stroke.checkIndex();
31
- if (isStaveNote(note)) {
32
- const { line } = note.getKeyProps()[index];
33
- const shift = note.getLeftDisplacedHeadPx();
34
- return { line, shift, stroke };
35
- }
36
- else if (isTabNote(note)) {
37
- const { str: string } = note.getPositions()[index];
38
- return { line: string, shift: 0, stroke };
39
- }
40
- else {
41
- throw new RuntimeError('Internal', 'Unexpected instance.');
42
- }
43
- });
44
- const strokeShift = left_shift;
45
- const xShift = strokeList.reduce((xShift, { stroke, shift }) => {
46
- stroke.setXShift(strokeShift + shift);
47
- return Math.max(stroke.getWidth() + stroke_spacing, xShift);
48
- }, 0);
49
- state.left_shift += xShift;
50
- return true;
51
- }
52
- getPosition() {
53
- return this.position;
54
- }
55
- addEndNote(note) {
56
- this.note_end = note;
57
- return this;
58
- }
59
- draw() {
60
- const ctx = this.checkContext();
61
- const note = this.checkAttachedNote();
62
- this.setRendered();
63
- const start = note.getModifierStartXY(this.position, this.index);
64
- let ys = note.getYs();
65
- let topY = start.y;
66
- let botY = start.y;
67
- const x = start.x - 5;
68
- const line_space = note.checkStave().getSpacingBetweenLines();
69
- const notes = this.checkModifierContext().getMembers(note.getCategory());
70
- for (let i = 0; i < notes.length; i++) {
71
- const note = notes[i];
72
- if (isNote(note)) {
73
- ys = note.getYs();
74
- for (let n = 0; n < ys.length; n++) {
75
- if (this.note === notes[i] || this.all_voices) {
76
- topY = Math.min(topY, ys[n]);
77
- botY = Math.max(botY, ys[n]);
78
- }
79
- }
80
- }
81
- }
82
- let arrow = '';
83
- let arrow_shift_x = 0;
84
- let arrow_y = 0;
85
- let text_shift_x = 0;
86
- let text_y = 0;
87
- switch (this.type) {
88
- case Stroke.Type.BRUSH_DOWN:
89
- arrow = 'arrowheadBlackUp';
90
- arrow_shift_x = -3;
91
- arrow_y = topY - line_space / 2 + 10;
92
- botY += line_space / 2;
93
- break;
94
- case Stroke.Type.BRUSH_UP:
95
- arrow = 'arrowheadBlackDown';
96
- arrow_shift_x = 0.5;
97
- arrow_y = botY + line_space / 2;
98
- topY -= line_space / 2;
99
- break;
100
- case Stroke.Type.ROLL_DOWN:
101
- case Stroke.Type.RASQUEDO_DOWN:
102
- arrow = 'arrowheadBlackUp';
103
- arrow_shift_x = -3;
104
- text_shift_x = this.x_shift + arrow_shift_x - 2;
105
- if (isStaveNote(note)) {
106
- topY += 1.5 * line_space;
107
- if ((botY - topY) % 2 !== 0) {
108
- botY += 0.5 * line_space;
109
- }
110
- else {
111
- botY += line_space;
112
- }
113
- arrow_y = topY - line_space;
114
- text_y = botY + line_space + 2;
115
- }
116
- else {
117
- topY += 1.5 * line_space;
118
- botY += line_space;
119
- arrow_y = topY - 0.75 * line_space;
120
- text_y = botY + 0.25 * line_space;
121
- }
122
- break;
123
- case Stroke.Type.ROLL_UP:
124
- case Stroke.Type.RASQUEDO_UP:
125
- arrow = 'arrowheadBlackDown';
126
- arrow_shift_x = -4;
127
- text_shift_x = this.x_shift + arrow_shift_x - 1;
128
- if (isStaveNote(note)) {
129
- arrow_y = line_space / 2;
130
- topY += 0.5 * line_space;
131
- if ((botY - topY) % 2 === 0) {
132
- botY += line_space / 2;
133
- }
134
- arrow_y = botY + 0.5 * line_space;
135
- text_y = topY - 1.25 * line_space;
136
- }
137
- else {
138
- topY += 0.25 * line_space;
139
- botY += 0.5 * line_space;
140
- arrow_y = botY + 0.25 * line_space;
141
- text_y = topY - line_space;
142
- }
143
- break;
144
- case Stroke.Type.ARPEGGIO_DIRECTIONLESS:
145
- topY += 0.5 * line_space;
146
- botY += line_space;
147
- break;
148
- default:
149
- throw new RuntimeError('InvalidType', `The stroke type ${this.type} does not exist`);
150
- }
151
- let strokeLine = 'straight';
152
- if (this.type === Stroke.Type.BRUSH_DOWN || this.type === Stroke.Type.BRUSH_UP) {
153
- ctx.fillRect(x + this.x_shift, topY, 1, botY - topY);
154
- }
155
- else {
156
- strokeLine = 'wiggly';
157
- if (isStaveNote(note)) {
158
- for (let i = topY; i <= botY; i += line_space) {
159
- Glyph.renderGlyph(ctx, x + this.x_shift - 4, i, this.render_options.font_scale, 'vexWiggleArpeggioUp');
160
- }
161
- }
162
- else {
163
- let i;
164
- for (i = topY; i <= botY; i += 10) {
165
- Glyph.renderGlyph(ctx, x + this.x_shift - 4, i, this.render_options.font_scale, 'vexWiggleArpeggioUp');
166
- }
167
- if (this.type === Stroke.Type.RASQUEDO_DOWN) {
168
- text_y = i + 0.25 * line_space;
169
- }
170
- }
171
- }
172
- if (this.type === Stroke.Type.ARPEGGIO_DIRECTIONLESS) {
173
- return;
174
- }
175
- Glyph.renderGlyph(ctx, x + this.x_shift + arrow_shift_x, arrow_y, this.render_options.font_scale, arrow, {
176
- category: `stroke.${arrow}.${strokeLine}`,
177
- });
178
- if (this.type === Stroke.Type.RASQUEDO_DOWN || this.type === Stroke.Type.RASQUEDO_UP) {
179
- ctx.save();
180
- ctx.setFont(this.textFont);
181
- ctx.fillText('R', x + text_shift_x, text_y);
182
- ctx.restore();
183
- }
184
- }
185
- }
186
- Stroke.Type = {
187
- BRUSH_DOWN: 1,
188
- BRUSH_UP: 2,
189
- ROLL_DOWN: 3,
190
- ROLL_UP: 4,
191
- RASQUEDO_DOWN: 5,
192
- RASQUEDO_UP: 6,
193
- ARPEGGIO_DIRECTIONLESS: 7,
194
- };
195
- Stroke.TEXT_FONT = {
196
- family: Font.SERIF,
197
- size: Font.SIZE,
198
- weight: FontWeight.BOLD,
199
- style: FontStyle.ITALIC,
200
- };
@@ -1,414 +0,0 @@
1
- import { Font, FontStyle, FontWeight } from './font.js';
2
- import { RenderContext } from './rendercontext.js';
3
- import { normalizeAngle, prefix, RuntimeError } from './util.js';
4
- const ATTRIBUTES_TO_IGNORE = {
5
- path: {
6
- x: true,
7
- y: true,
8
- width: true,
9
- height: true,
10
- 'font-family': true,
11
- 'font-weight': true,
12
- 'font-style': true,
13
- 'font-size': true,
14
- },
15
- rect: {
16
- 'font-family': true,
17
- 'font-weight': true,
18
- 'font-style': true,
19
- 'font-size': true,
20
- },
21
- text: {
22
- width: true,
23
- height: true,
24
- },
25
- };
26
- const SVG_NS = 'http://www.w3.org/2000/svg';
27
- const TWO_PI = 2 * Math.PI;
28
- class MeasureTextCache {
29
- constructor() {
30
- this.cache = {};
31
- }
32
- lookup(text, svg, attributes) {
33
- let entries = this.cache[text];
34
- if (entries === undefined) {
35
- entries = {};
36
- this.cache[text] = entries;
37
- }
38
- const family = attributes['font-family'];
39
- const size = attributes['font-size'];
40
- const weight = attributes['font-weight'];
41
- const style = attributes['font-style'];
42
- const key = `${family}%${size}%${weight}%${style}`;
43
- let entry = entries[key];
44
- if (entry === undefined) {
45
- entry = this.measureImpl(text, svg, attributes);
46
- entries[key] = entry;
47
- }
48
- return entry;
49
- }
50
- measureImpl(text, svg, attributes) {
51
- let txt = this.txt;
52
- if (!txt) {
53
- txt = document.createElementNS(SVG_NS, 'text');
54
- this.txt = txt;
55
- }
56
- txt.textContent = text;
57
- txt.setAttributeNS(null, 'font-family', attributes['font-family']);
58
- txt.setAttributeNS(null, 'font-size', attributes['font-size']);
59
- txt.setAttributeNS(null, 'font-style', attributes['font-style']);
60
- txt.setAttributeNS(null, 'font-weight', attributes['font-weight']);
61
- svg.appendChild(txt);
62
- const bbox = txt.getBBox();
63
- svg.removeChild(txt);
64
- return { x: bbox.x, y: bbox.y, width: bbox.width, height: bbox.height };
65
- }
66
- }
67
- export class SVGContext extends RenderContext {
68
- constructor(element) {
69
- super();
70
- this.width = 0;
71
- this.height = 0;
72
- this.backgroundFillStyle = 'white';
73
- this.fontCSSString = '';
74
- this.element = element;
75
- const svg = this.create('svg');
76
- this.element.appendChild(svg);
77
- this.svg = svg;
78
- this.parent = this.svg;
79
- this.groups = [this.svg];
80
- this.path = '';
81
- this.pen = { x: NaN, y: NaN };
82
- this.lineWidth = 1.0;
83
- const defaultFontAttributes = {
84
- 'font-family': Font.SANS_SERIF,
85
- 'font-size': Font.SIZE + 'pt',
86
- 'font-weight': FontWeight.NORMAL,
87
- 'font-style': FontStyle.NORMAL,
88
- };
89
- this.state = Object.assign({ scale: { x: 1, y: 1 } }, defaultFontAttributes);
90
- this.attributes = Object.assign({ 'stroke-width': 0.3, 'stroke-dasharray': 'none', fill: 'black', stroke: 'black' }, defaultFontAttributes);
91
- this.shadow_attributes = {
92
- width: 0,
93
- color: 'black',
94
- };
95
- this.state_stack = [];
96
- }
97
- create(svgElementType) {
98
- return document.createElementNS(SVG_NS, svgElementType);
99
- }
100
- openGroup(cls, id, attrs) {
101
- const group = this.create('g');
102
- this.groups.push(group);
103
- this.parent.appendChild(group);
104
- this.parent = group;
105
- if (cls)
106
- group.setAttribute('class', prefix(cls));
107
- if (id)
108
- group.setAttribute('id', prefix(id));
109
- if (attrs && attrs.pointerBBox) {
110
- group.setAttribute('pointer-events', 'bounding-box');
111
- }
112
- return group;
113
- }
114
- closeGroup() {
115
- this.groups.pop();
116
- this.parent = this.groups[this.groups.length - 1];
117
- }
118
- add(elem) {
119
- this.parent.appendChild(elem);
120
- }
121
- setFillStyle(style) {
122
- this.attributes.fill = style;
123
- return this;
124
- }
125
- setBackgroundFillStyle(style) {
126
- this.backgroundFillStyle = style;
127
- return this;
128
- }
129
- setStrokeStyle(style) {
130
- this.attributes.stroke = style;
131
- return this;
132
- }
133
- setShadowColor(color) {
134
- this.shadow_attributes.color = color;
135
- return this;
136
- }
137
- setShadowBlur(blur) {
138
- this.shadow_attributes.width = blur;
139
- return this;
140
- }
141
- setLineWidth(width) {
142
- this.attributes['stroke-width'] = width;
143
- this.lineWidth = width;
144
- return this;
145
- }
146
- setLineDash(lineDash) {
147
- if (Object.prototype.toString.call(lineDash) === '[object Array]') {
148
- this.attributes['stroke-dasharray'] = lineDash.join(',');
149
- return this;
150
- }
151
- else {
152
- throw new RuntimeError('ArgumentError', 'lineDash must be an array of integers.');
153
- }
154
- }
155
- setLineCap(capType) {
156
- this.attributes['stroke-linecap'] = capType;
157
- return this;
158
- }
159
- resize(width, height) {
160
- this.width = width;
161
- this.height = height;
162
- this.element.style.width = width.toString();
163
- this.svg.style.width = width.toString();
164
- this.svg.style.height = height.toString();
165
- const attributes = {
166
- width,
167
- height,
168
- };
169
- this.applyAttributes(this.svg, attributes);
170
- this.scale(this.state.scale.x, this.state.scale.y);
171
- return this;
172
- }
173
- scale(x, y) {
174
- this.state.scale = { x, y };
175
- const visibleWidth = this.width / x;
176
- const visibleHeight = this.height / y;
177
- this.setViewBox(0, 0, visibleWidth, visibleHeight);
178
- return this;
179
- }
180
- setViewBox(viewBox_or_minX, minY, width, height) {
181
- if (typeof viewBox_or_minX === 'string') {
182
- this.svg.setAttribute('viewBox', viewBox_or_minX);
183
- }
184
- else {
185
- const viewBoxString = viewBox_or_minX + ' ' + minY + ' ' + width + ' ' + height;
186
- this.svg.setAttribute('viewBox', viewBoxString);
187
- }
188
- }
189
- applyAttributes(element, attributes) {
190
- const attrNamesToIgnore = ATTRIBUTES_TO_IGNORE[element.nodeName];
191
- for (const attrName in attributes) {
192
- if (attrNamesToIgnore && attrNamesToIgnore[attrName]) {
193
- continue;
194
- }
195
- element.setAttributeNS(null, attrName, attributes[attrName]);
196
- }
197
- return element;
198
- }
199
- clear() {
200
- while (this.svg.lastChild) {
201
- this.svg.removeChild(this.svg.lastChild);
202
- }
203
- this.scale(this.state.scale.x, this.state.scale.y);
204
- }
205
- rect(x, y, width, height, attributes) {
206
- if (height < 0) {
207
- y += height;
208
- height *= -1;
209
- }
210
- const rectangle = this.create('rect');
211
- attributes = attributes !== null && attributes !== void 0 ? attributes : { fill: 'none', 'stroke-width': this.lineWidth, stroke: 'black' };
212
- this.applyAttributes(rectangle, Object.assign({ x, y, width, height }, attributes));
213
- this.add(rectangle);
214
- return this;
215
- }
216
- fillRect(x, y, width, height) {
217
- const attributes = { fill: this.attributes.fill };
218
- this.rect(x, y, width, height, attributes);
219
- return this;
220
- }
221
- clearRect(x, y, width, height) {
222
- this.rect(x, y, width, height, { 'stroke-width': 0, fill: this.backgroundFillStyle });
223
- return this;
224
- }
225
- beginPath() {
226
- this.path = '';
227
- this.pen.x = NaN;
228
- this.pen.y = NaN;
229
- return this;
230
- }
231
- moveTo(x, y) {
232
- this.path += 'M' + x + ' ' + y;
233
- this.pen.x = x;
234
- this.pen.y = y;
235
- return this;
236
- }
237
- lineTo(x, y) {
238
- this.path += 'L' + x + ' ' + y;
239
- this.pen.x = x;
240
- this.pen.y = y;
241
- return this;
242
- }
243
- bezierCurveTo(x1, y1, x2, y2, x, y) {
244
- this.path += 'C' + x1 + ' ' + y1 + ',' + x2 + ' ' + y2 + ',' + x + ' ' + y;
245
- this.pen.x = x;
246
- this.pen.y = y;
247
- return this;
248
- }
249
- quadraticCurveTo(x1, y1, x, y) {
250
- this.path += 'Q' + x1 + ' ' + y1 + ',' + x + ' ' + y;
251
- this.pen.x = x;
252
- this.pen.y = y;
253
- return this;
254
- }
255
- arc(x, y, radius, startAngle, endAngle, counterclockwise) {
256
- const x0 = x + radius * Math.cos(startAngle);
257
- const y0 = y + radius * Math.sin(startAngle);
258
- if ((!counterclockwise && endAngle - startAngle >= TWO_PI) ||
259
- (counterclockwise && startAngle - endAngle >= TWO_PI)) {
260
- const x1 = x + radius * Math.cos(startAngle + Math.PI);
261
- const y1 = y + radius * Math.sin(startAngle + Math.PI);
262
- this.path += `M${x0} ${y0} A${radius} ${radius} 0 0 0 ${x1} ${y1} `;
263
- this.path += `A${radius} ${radius} 0 0 0 ${x0} ${y0}`;
264
- this.pen.x = x0;
265
- this.pen.y = y0;
266
- }
267
- else {
268
- const x1 = x + radius * Math.cos(endAngle);
269
- const y1 = y + radius * Math.sin(endAngle);
270
- startAngle = normalizeAngle(startAngle);
271
- endAngle = normalizeAngle(endAngle);
272
- let large;
273
- if (Math.abs(endAngle - startAngle) < Math.PI) {
274
- large = counterclockwise;
275
- }
276
- else {
277
- large = !counterclockwise;
278
- }
279
- if (startAngle > endAngle) {
280
- large = !large;
281
- }
282
- const sweep = !counterclockwise;
283
- this.path += `M${x0} ${y0} A${radius} ${radius} 0 ${+large} ${+sweep} ${x1} ${y1}`;
284
- this.pen.x = x1;
285
- this.pen.y = y1;
286
- }
287
- return this;
288
- }
289
- closePath() {
290
- this.path += 'Z';
291
- return this;
292
- }
293
- getShadowStyle() {
294
- const sa = this.shadow_attributes;
295
- return `filter: drop-shadow(0 0 ${sa.width / 1.5}px ${sa.color})`;
296
- }
297
- fill(attributes) {
298
- const path = this.create('path');
299
- if (typeof attributes === 'undefined') {
300
- attributes = Object.assign(Object.assign({}, this.attributes), { stroke: 'none' });
301
- }
302
- attributes.d = this.path;
303
- if (this.shadow_attributes.width > 0) {
304
- attributes.style = this.getShadowStyle();
305
- }
306
- this.applyAttributes(path, attributes);
307
- this.add(path);
308
- return this;
309
- }
310
- stroke() {
311
- const path = this.create('path');
312
- const attributes = Object.assign(Object.assign({}, this.attributes), { fill: 'none', 'stroke-width': this.lineWidth, d: this.path });
313
- if (this.shadow_attributes.width > 0) {
314
- attributes.style = this.getShadowStyle();
315
- }
316
- this.applyAttributes(path, attributes);
317
- this.add(path);
318
- return this;
319
- }
320
- measureText(text) {
321
- return SVGContext.measureTextCache.lookup(text, this.svg, this.attributes);
322
- }
323
- fillText(text, x, y) {
324
- if (!text || text.length <= 0) {
325
- return this;
326
- }
327
- const attributes = Object.assign(Object.assign({}, this.attributes), { stroke: 'none', x,
328
- y });
329
- const txt = this.create('text');
330
- txt.textContent = text;
331
- this.applyAttributes(txt, attributes);
332
- this.add(txt);
333
- return this;
334
- }
335
- save() {
336
- this.state_stack.push({
337
- state: {
338
- 'font-family': this.state['font-family'],
339
- 'font-weight': this.state['font-weight'],
340
- 'font-style': this.state['font-style'],
341
- 'font-size': this.state['font-size'],
342
- scale: this.state.scale,
343
- },
344
- attributes: {
345
- 'font-family': this.attributes['font-family'],
346
- 'font-weight': this.attributes['font-weight'],
347
- 'font-style': this.attributes['font-style'],
348
- 'font-size': this.attributes['font-size'],
349
- fill: this.attributes.fill,
350
- stroke: this.attributes.stroke,
351
- 'stroke-width': this.attributes['stroke-width'],
352
- 'stroke-dasharray': this.attributes['stroke-dasharray'],
353
- },
354
- shadow_attributes: {
355
- width: this.shadow_attributes.width,
356
- color: this.shadow_attributes.color,
357
- },
358
- lineWidth: this.lineWidth,
359
- });
360
- return this;
361
- }
362
- restore() {
363
- const savedState = this.state_stack.pop();
364
- if (savedState) {
365
- const state = savedState;
366
- this.state['font-family'] = state.state['font-family'];
367
- this.state['font-weight'] = state.state['font-weight'];
368
- this.state['font-style'] = state.state['font-style'];
369
- this.state['font-size'] = state.state['font-size'];
370
- this.state.scale = state.state.scale;
371
- this.attributes['font-family'] = state.attributes['font-family'];
372
- this.attributes['font-weight'] = state.attributes['font-weight'];
373
- this.attributes['font-style'] = state.attributes['font-style'];
374
- this.attributes['font-size'] = state.attributes['font-size'];
375
- this.attributes.fill = state.attributes.fill;
376
- this.attributes.stroke = state.attributes.stroke;
377
- this.attributes['stroke-width'] = state.attributes['stroke-width'];
378
- this.attributes['stroke-dasharray'] = state.attributes['stroke-dasharray'];
379
- this.shadow_attributes.width = state.shadow_attributes.width;
380
- this.shadow_attributes.color = state.shadow_attributes.color;
381
- this.lineWidth = state.lineWidth;
382
- }
383
- return this;
384
- }
385
- set fillStyle(style) {
386
- this.setFillStyle(style);
387
- }
388
- get fillStyle() {
389
- return this.attributes.fill;
390
- }
391
- set strokeStyle(style) {
392
- this.setStrokeStyle(style);
393
- }
394
- get strokeStyle() {
395
- return this.attributes.stroke;
396
- }
397
- setFont(f, size, weight, style) {
398
- const fontInfo = Font.validate(f, size, weight, style);
399
- this.fontCSSString = Font.toCSSString(fontInfo);
400
- const fontAttributes = {
401
- 'font-family': fontInfo.family,
402
- 'font-size': fontInfo.size,
403
- 'font-weight': fontInfo.weight,
404
- 'font-style': fontInfo.style,
405
- };
406
- this.attributes = Object.assign(Object.assign({}, this.attributes), fontAttributes);
407
- this.state = Object.assign(Object.assign({}, this.state), fontAttributes);
408
- return this;
409
- }
410
- getFont() {
411
- return this.fontCSSString;
412
- }
413
- }
414
- SVGContext.measureTextCache = new MeasureTextCache();