vexflow 5.1.1 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VexFlow 5.1.1 2026-11-16T03:47:09.194Z 271f9428354588de1f6c83a065428c8a5c442513
2
+ * VexFlow 5.1.2 2026-11-16T14:50:27.719Z 419436ad3c5fb5efeb2590a6a88b2a403cbdae64
3
3
  * Copyright (c) 2023-present VexFlow contributors (see https://github.com/vexflow/vexflow/blob/main/AUTHORS.md).
4
4
  */
5
5
  (function webpackUniversalModuleDefinition(root, factory) {
@@ -2769,6 +2769,132 @@ class CanvasContext extends _rendercontext__WEBPACK_IMPORTED_MODULE_1__.RenderCo
2769
2769
  }
2770
2770
 
2771
2771
 
2772
+ /***/ },
2773
+
2774
+ /***/ "./src/chordkerning.ts"
2775
+ /*!*****************************!*\
2776
+ !*** ./src/chordkerning.ts ***!
2777
+ \*****************************/
2778
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2779
+
2780
+ __webpack_require__.r(__webpack_exports__);
2781
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2782
+ /* harmony export */ chordKerningProfile: () => (/* binding */ chordKerningProfile),
2783
+ /* harmony export */ layoutChordRuns: () => (/* binding */ layoutChordRuns)
2784
+ /* harmony export */ });
2785
+ /* harmony import */ var _font__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./font */ "./src/font.ts");
2786
+ /* harmony import */ var _glyphs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glyphs */ "./src/glyphs.ts");
2787
+ // Opt-in chord typography: explicit font profiles and backend-independent run placement.
2788
+
2789
+
2790
+ /** Conservative optical corrections for the bundled regular faces; unspecified pairs use zero. */
2791
+ function scriptPairs(a, f) {
2792
+ const symbols = [_glyphs__WEBPACK_IMPORTED_MODULE_1__.Glyphs.csymDiminished, _glyphs__WEBPACK_IMPORTED_MODULE_1__.Glyphs.csymHalfDiminished, _glyphs__WEBPACK_IMPORTED_MODULE_1__.Glyphs.csymMajorSeventh];
2793
+ return symbols.flatMap((right) => [
2794
+ { left: 'A', right, position: 'superscript', adjustmentEm: a },
2795
+ { left: 'F', right, position: 'subscript', adjustmentEm: f },
2796
+ ]);
2797
+ }
2798
+ /** Font-specific values are deliberately small; the ordinary text remains browser-shaped. */
2799
+ const profiles = [
2800
+ { textFont: 'Academico', musicFont: 'Bravura', pairs: scriptPairs(-0.18, -0.12) },
2801
+ { textFont: 'Petaluma Script', musicFont: 'Petaluma', pairs: scriptPairs(-0.12, -0.08) },
2802
+ ];
2803
+ /** Normalize only the supported CSS spellings; an unknown weight or face never borrows a profile. */
2804
+ function normalWeight(weight) {
2805
+ return weight === undefined || weight === '' || weight === 'normal' ? '400' : String(weight);
2806
+ }
2807
+ /** Match explicit leading faces, not a guess about which fallback face supplied a glyph. */
2808
+ function chordKerningProfile(font, custom) {
2809
+ var _a;
2810
+ const families = ((_a = font.family) !== null && _a !== void 0 ? _a : '').split(',').map((family) => family.trim().replace(/^['"]|['"]$/g, ''));
2811
+ return (custom ? [custom] : profiles).find((profile) => families[0] === profile.textFont &&
2812
+ families[1] === profile.musicFont &&
2813
+ normalWeight(font.weight) === normalWeight(profile.weight) &&
2814
+ (font.style || 'normal') === (profile.style || 'normal'));
2815
+ }
2816
+ /** Restrict splitting to chord symbols and accidentals. Leave other text and combining marks intact. */
2817
+ function musicCharacter(character) {
2818
+ return /[\uE870-\uE87F\uED60-\uED67\uE260-\uE26F]/u.test(character);
2819
+ }
2820
+ /** Merge adjacent fragments at the same baseline before splitting into text/music font runs. */
2821
+ function groups(blocks) {
2822
+ const result = [];
2823
+ for (const block of blocks) {
2824
+ if (!block.text)
2825
+ continue;
2826
+ const previous = result[result.length - 1];
2827
+ if ((previous === null || previous === void 0 ? void 0 : previous.position) === block.position)
2828
+ previous.text += block.text;
2829
+ else
2830
+ result.push(Object.assign({}, block));
2831
+ }
2832
+ return result;
2833
+ }
2834
+ /** Split only at font-role boundaries, so words and digit sequences retain native shaping. */
2835
+ function spans(text) {
2836
+ const result = [];
2837
+ for (const character of text) {
2838
+ const music = musicCharacter(character);
2839
+ const previous = result[result.length - 1];
2840
+ if ((previous === null || previous === void 0 ? void 0 : previous.music) === music)
2841
+ previous.text += character;
2842
+ else
2843
+ result.push({ text: character, music });
2844
+ }
2845
+ return result;
2846
+ }
2847
+ /** Pair values move the following run and its advance together, never just the painted glyph. */
2848
+ function adjustment(profile, left, right, position) {
2849
+ var _a, _b;
2850
+ const last = Array.from(left).slice(-1)[0];
2851
+ const first = Array.from(right)[0];
2852
+ return ((_b = (_a = profile.pairs.find((pair) => pair.left === last && pair.right === first && pair.position === position)) === null || _a === void 0 ? void 0 : _a.adjustmentEm) !== null && _b !== void 0 ? _b : 0);
2853
+ }
2854
+ /** Rebuild positions on every format pass. No accumulated shifts or separate SVG-only corrections. */
2855
+ function layoutChordRuns(blocks, font, profile, options, measure) {
2856
+ var _a, _b;
2857
+ const em = _font__WEBPACK_IMPORTED_MODULE_0__.Font.convertSizeToPixelValue((_a = font.size) !== null && _a !== void 0 ? _a : 12);
2858
+ const runs = [];
2859
+ let cursor = 0;
2860
+ let previousText = '';
2861
+ let stack;
2862
+ for (const group of groups(blocks)) {
2863
+ const script = group.position !== 'baseline';
2864
+ const stacked = script && stack && stack.position !== group.position;
2865
+ let x = stacked ? stack.x : cursor;
2866
+ if (!stacked && runs.length) {
2867
+ x += options.spacing * em + adjustment(profile, previousText, group.text, group.position) * em;
2868
+ }
2869
+ const anchor = x;
2870
+ const y = group.position === 'superscript'
2871
+ ? options.superscript * em
2872
+ : group.position === 'subscript'
2873
+ ? options.subscript * em
2874
+ : 0;
2875
+ let previousSpan = '';
2876
+ for (const span of spans(group.text)) {
2877
+ if (previousSpan)
2878
+ x += adjustment(profile, previousSpan, span.text, group.position) * em;
2879
+ const runFont = Object.assign(Object.assign({}, font), { family: span.music ? profile.musicFont : profile.textFont, size: script ? _font__WEBPACK_IMPORTED_MODULE_0__.Font.scaleSize((_b = font.size) !== null && _b !== void 0 ? _b : 12, options.ratio) : font.size });
2880
+ const metrics = measure(span.text, runFont);
2881
+ runs.push({ text: span.text, position: group.position, font: runFont, x, y, metrics });
2882
+ x += metrics.width;
2883
+ previousSpan = span.text;
2884
+ }
2885
+ cursor = stacked ? Math.max(stack.end, x) : x;
2886
+ stack = script && !stacked ? { position: group.position, x: anchor, end: cursor } : undefined;
2887
+ previousText = group.text;
2888
+ }
2889
+ // Include ink overhangs without discarding advances (including intentional spaces).
2890
+ const left = Math.min(0, ...runs.map((run) => run.x - run.metrics.actualBoundingBoxLeft));
2891
+ const right = Math.max(cursor, ...runs.map((run) => run.x + run.metrics.actualBoundingBoxRight));
2892
+ for (const run of runs)
2893
+ run.x -= left;
2894
+ return { runs, width: right - left };
2895
+ }
2896
+
2897
+
2772
2898
  /***/ },
2773
2899
 
2774
2900
  /***/ "./src/chordsymbol.ts"
@@ -2785,14 +2911,16 @@ __webpack_require__.r(__webpack_exports__);
2785
2911
  /* harmony export */ ChordSymbolVerticalJustify: () => (/* binding */ ChordSymbolVerticalJustify),
2786
2912
  /* harmony export */ SymbolModifiers: () => (/* binding */ SymbolModifiers)
2787
2913
  /* harmony export */ });
2788
- /* harmony import */ var _element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./element */ "./src/element.ts");
2789
- /* harmony import */ var _font__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./font */ "./src/font.ts");
2790
- /* harmony import */ var _glyphs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glyphs */ "./src/glyphs.ts");
2791
- /* harmony import */ var _metrics__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./metrics */ "./src/metrics.ts");
2792
- /* harmony import */ var _modifier__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./modifier */ "./src/modifier.ts");
2793
- /* harmony import */ var _tables__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./tables */ "./src/tables.ts");
2794
- /* harmony import */ var _typeguard__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./typeguard */ "./src/typeguard.ts");
2795
- /* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./util */ "./src/util.ts");
2914
+ /* harmony import */ var _boundingbox__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./boundingbox */ "./src/boundingbox.ts");
2915
+ /* harmony import */ var _chordkerning__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./chordkerning */ "./src/chordkerning.ts");
2916
+ /* harmony import */ var _element__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./element */ "./src/element.ts");
2917
+ /* harmony import */ var _font__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./font */ "./src/font.ts");
2918
+ /* harmony import */ var _glyphs__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glyphs */ "./src/glyphs.ts");
2919
+ /* harmony import */ var _metrics__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./metrics */ "./src/metrics.ts");
2920
+ /* harmony import */ var _modifier__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./modifier */ "./src/modifier.ts");
2921
+ /* harmony import */ var _tables__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./tables */ "./src/tables.ts");
2922
+ /* harmony import */ var _typeguard__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./typeguard */ "./src/typeguard.ts");
2923
+ /* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./util */ "./src/util.ts");
2796
2924
  // Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
2797
2925
  //
2798
2926
  // @author Aaron (@AaronDavidNewman)
@@ -2811,13 +2939,15 @@ __webpack_require__.r(__webpack_exports__);
2811
2939
 
2812
2940
 
2813
2941
 
2942
+
2943
+
2814
2944
  // To enable logging for this class. Set `VexFlow.ChordSymbol.DEBUG` to `true`.
2815
2945
  // eslint-disable-next-line
2816
2946
  function L(...args) {
2817
2947
  if (ChordSymbol.DEBUG)
2818
- (0,_util__WEBPACK_IMPORTED_MODULE_7__.log)('VexFlow.ChordSymbol', args);
2948
+ (0,_util__WEBPACK_IMPORTED_MODULE_9__.log)('VexFlow.ChordSymbol', args);
2819
2949
  }
2820
- class ChordSymbolBlock extends _element__WEBPACK_IMPORTED_MODULE_0__.Element {
2950
+ class ChordSymbolBlock extends _element__WEBPACK_IMPORTED_MODULE_2__.Element {
2821
2951
  constructor(text, symbolModifier, xShift, yShift, vAlign) {
2822
2952
  super();
2823
2953
  this.text = text;
@@ -2855,24 +2985,24 @@ var SymbolModifiers;
2855
2985
  * ChordSymbol is a modifier that creates a chord symbol above/below a chord.
2856
2986
  * As a modifier, it is attached to an existing note.
2857
2987
  */
2858
- class ChordSymbol extends _modifier__WEBPACK_IMPORTED_MODULE_4__.Modifier {
2988
+ class ChordSymbol extends _modifier__WEBPACK_IMPORTED_MODULE_6__.Modifier {
2859
2989
  static get CATEGORY() {
2860
- return _typeguard__WEBPACK_IMPORTED_MODULE_6__.Category.ChordSymbol;
2990
+ return "ChordSymbol" /* Category.ChordSymbol */;
2861
2991
  }
2862
2992
  static get superSubRatio() {
2863
- return _metrics__WEBPACK_IMPORTED_MODULE_3__.Metrics.get('ChordSymbol.superSubRatio');
2993
+ return _metrics__WEBPACK_IMPORTED_MODULE_5__.Metrics.get('ChordSymbol.superSubRatio');
2864
2994
  }
2865
2995
  static get spacingBetweenBlocks() {
2866
- return _metrics__WEBPACK_IMPORTED_MODULE_3__.Metrics.get('ChordSymbol.spacing');
2996
+ return _metrics__WEBPACK_IMPORTED_MODULE_5__.Metrics.get('ChordSymbol.spacing');
2867
2997
  }
2868
2998
  static get superscriptOffset() {
2869
- return _metrics__WEBPACK_IMPORTED_MODULE_3__.Metrics.get('ChordSymbol.superscriptOffset');
2999
+ return _metrics__WEBPACK_IMPORTED_MODULE_5__.Metrics.get('ChordSymbol.superscriptOffset');
2870
3000
  }
2871
3001
  static get subscriptOffset() {
2872
- return _metrics__WEBPACK_IMPORTED_MODULE_3__.Metrics.get('ChordSymbol.subscriptOffset');
3002
+ return _metrics__WEBPACK_IMPORTED_MODULE_5__.Metrics.get('ChordSymbol.subscriptOffset');
2873
3003
  }
2874
3004
  static get minPadding() {
2875
- return _metrics__WEBPACK_IMPORTED_MODULE_3__.Metrics.get('NoteHead.minPadding');
3005
+ return _metrics__WEBPACK_IMPORTED_MODULE_5__.Metrics.get('NoteHead.minPadding');
2876
3006
  }
2877
3007
  /**
2878
3008
  * Estimate the width of the whole chord symbol, based on the sum of the widths of the individual blocks.
@@ -2889,31 +3019,39 @@ class ChordSymbol extends _modifier__WEBPACK_IMPORTED_MODULE_4__.Modifier {
2889
3019
  for (const symbol of symbols) {
2890
3020
  const note = symbol.checkAttachedNote();
2891
3021
  let lineSpaces = 1;
2892
- for (let j = 0; j < symbol.symbolBlocks.length; ++j) {
2893
- const block = symbol.symbolBlocks[j];
2894
- const sup = block.isSuperscript();
2895
- const sub = block.isSubscript();
2896
- block.setXShift(width);
2897
- // If there are super/subscripts, they extend beyond the line so
2898
- // assume they take up 2 lines
2899
- if (sup || sub) {
3022
+ const kernedWidth = symbol.formatKerning();
3023
+ if (kernedWidth !== undefined) {
3024
+ width = kernedWidth;
3025
+ if (symbol.symbolBlocks.some((block) => block.isSuperscript() || block.isSubscript()))
2900
3026
  lineSpaces = 2;
2901
- }
2902
- // If a subscript immediately follows a superscript block, try to
2903
- // overlay them.
2904
- if (sub && j > 0) {
2905
- const prev = symbol.symbolBlocks[j - 1];
2906
- if (prev.isSuperscript()) {
2907
- // slide the symbol over so it lines up with superscript
2908
- block.setXShift(width - prev.getWidth() - ChordSymbol.minPadding);
2909
- block.vAlign = true;
2910
- width +=
2911
- -prev.getWidth() -
2912
- ChordSymbol.minPadding +
2913
- (prev.getWidth() > block.getWidth() ? prev.getWidth() - block.getWidth() : 0);
3027
+ }
3028
+ else {
3029
+ for (let j = 0; j < symbol.symbolBlocks.length; ++j) {
3030
+ const block = symbol.symbolBlocks[j];
3031
+ const sup = block.isSuperscript();
3032
+ const sub = block.isSubscript();
3033
+ block.setXShift(width);
3034
+ // If there are super/subscripts, they extend beyond the line so
3035
+ // assume they take up 2 lines
3036
+ if (sup || sub) {
3037
+ lineSpaces = 2;
3038
+ }
3039
+ // If a subscript immediately follows a superscript block, try to
3040
+ // overlay them.
3041
+ if (sub && j > 0) {
3042
+ const prev = symbol.symbolBlocks[j - 1];
3043
+ if (prev.isSuperscript()) {
3044
+ // slide the symbol over so it lines up with superscript
3045
+ block.setXShift(width - prev.getWidth() - ChordSymbol.minPadding);
3046
+ block.vAlign = true;
3047
+ width +=
3048
+ -prev.getWidth() -
3049
+ ChordSymbol.minPadding +
3050
+ (prev.getWidth() > block.getWidth() ? prev.getWidth() - block.getWidth() : 0);
3051
+ }
2914
3052
  }
3053
+ width += block.getWidth() + ChordSymbol.minPadding;
2915
3054
  }
2916
- width += block.getWidth() + ChordSymbol.minPadding;
2917
3055
  }
2918
3056
  if (symbol.getVertical() === ChordSymbolVerticalJustify.TOP) {
2919
3057
  symbol.setTextLine(state.topTextLine);
@@ -2924,7 +3062,7 @@ class ChordSymbol extends _modifier__WEBPACK_IMPORTED_MODULE_4__.Modifier {
2924
3062
  state.textLine += lineSpaces + 1;
2925
3063
  }
2926
3064
  if (symbol.getReportWidth()) {
2927
- if ((0,_typeguard__WEBPACK_IMPORTED_MODULE_6__.isStemmableNote)(note)) {
3065
+ if ((0,_typeguard__WEBPACK_IMPORTED_MODULE_8__.isStemmableNote)(note)) {
2928
3066
  const glyphWidth = note.getGlyphWidth();
2929
3067
  if (symbol.getHorizontal() === ChordSymbolHorizontalJustify.RIGHT) {
2930
3068
  maxLeftGlyphWidth = Math.max(glyphWidth, maxLeftGlyphWidth);
@@ -2941,8 +3079,10 @@ class ChordSymbol extends _modifier__WEBPACK_IMPORTED_MODULE_4__.Modifier {
2941
3079
  maxRightGlyphWidth = Math.max(glyphWidth / 2, maxRightGlyphWidth);
2942
3080
  }
2943
3081
  }
2944
- symbol.width = width;
2945
3082
  }
3083
+ // Opt-in runs need their width for alignment even when they reserve no stave space.
3084
+ if (symbol.getReportWidth() || symbol.kernedRuns)
3085
+ symbol.width = width;
2946
3086
  width = 0; // reset symbol width
2947
3087
  }
2948
3088
  const rightOverlap = Math.min(Math.max(rightWidth - maxRightGlyphWidth, 0), Math.max(rightWidth - state.rightShift, 0));
@@ -2951,21 +3091,71 @@ class ChordSymbol extends _modifier__WEBPACK_IMPORTED_MODULE_4__.Modifier {
2951
3091
  state.rightShift += rightOverlap;
2952
3092
  return true;
2953
3093
  }
3094
+ /** Select optical kerning. Format the score again after changing layout settings. */
3095
+ setKerning(mode) {
3096
+ if (mode !== 'auto' && mode !== 'none')
3097
+ throw new _util__WEBPACK_IMPORTED_MODULE_9__.RuntimeError('BadArgument', 'Kerning must be auto or none.');
3098
+ this.kerning = mode;
3099
+ this.kernedRuns = undefined;
3100
+ return this;
3101
+ }
3102
+ getKerning() {
3103
+ return this.kerning;
3104
+ }
3105
+ /** Replace the font-specific table for this chord only. Omit the profile to restore built-ins. */
3106
+ setKerningProfile(profile) {
3107
+ if (profile &&
3108
+ (!profile.textFont.trim() ||
3109
+ !profile.musicFont.trim() ||
3110
+ profile.pairs.some((pair) => Array.from(pair.left).length !== 1 ||
3111
+ Array.from(pair.right).length !== 1 ||
3112
+ !['baseline', 'superscript', 'subscript'].includes(pair.position) ||
3113
+ !Number.isFinite(pair.adjustmentEm))))
3114
+ throw new _util__WEBPACK_IMPORTED_MODULE_9__.RuntimeError('BadArgument', 'Invalid chord kerning profile.');
3115
+ this.kerningProfile = profile && Object.assign(Object.assign({}, profile), { pairs: profile.pairs.map((pair) => (Object.assign({}, pair))) });
3116
+ this.kernedRuns = undefined;
3117
+ return this;
3118
+ }
3119
+ /** Re-measure on every format pass; Element's shared cache handles font loading and reuse. */
3120
+ formatKerning() {
3121
+ var _a;
3122
+ this.kernedRuns = undefined;
3123
+ if (this.kerning === 'none')
3124
+ return undefined;
3125
+ const profile = (0,_chordkerning__WEBPACK_IMPORTED_MODULE_1__.chordKerningProfile)(this.fontInfo, this.kerningProfile);
3126
+ if (!profile)
3127
+ return undefined;
3128
+ const measurement = (_a = this.kerningMeasurement) !== null && _a !== void 0 ? _a : (this.kerningMeasurement = new _element__WEBPACK_IMPORTED_MODULE_2__.Element());
3129
+ const layout = (0,_chordkerning__WEBPACK_IMPORTED_MODULE_1__.layoutChordRuns)(this.symbolBlocks.map((block) => ({
3130
+ text: block.getText(),
3131
+ position: block.isSuperscript() ? 'superscript' : block.isSubscript() ? 'subscript' : 'baseline',
3132
+ })), this.fontInfo, profile, {
3133
+ spacing: ChordSymbol.spacingBetweenBlocks,
3134
+ ratio: ChordSymbol.superSubRatio,
3135
+ superscript: ChordSymbol.superscriptOffset,
3136
+ subscript: ChordSymbol.subscriptOffset,
3137
+ }, (text, font) => measurement.setText(text).setFont(font).measureText());
3138
+ this.kernedRuns = layout.runs;
3139
+ return layout.width;
3140
+ }
2954
3141
  constructor() {
2955
3142
  super();
2956
3143
  this.symbolBlocks = [];
2957
3144
  this.horizontal = ChordSymbolHorizontalJustify.LEFT;
2958
3145
  this.vertical = ChordSymbolVerticalJustify.TOP;
2959
3146
  this.reportWidth = true;
3147
+ /** Default rendering stays compatible; only a matching opt-in profile uses shaped runs. */
3148
+ this.kerning = 'none';
3149
+ this.kerningOrigin = { x: 0, y: 0 };
2960
3150
  }
2961
3151
  /**
2962
3152
  * The offset is specified in `em`. Scale this value by the font size in pixels.
2963
3153
  */
2964
3154
  get superscriptOffset() {
2965
- return ChordSymbol.superscriptOffset * _font__WEBPACK_IMPORTED_MODULE_1__.Font.convertSizeToPixelValue(this.fontInfo.size);
3155
+ return ChordSymbol.superscriptOffset * _font__WEBPACK_IMPORTED_MODULE_3__.Font.convertSizeToPixelValue(this.fontInfo.size);
2966
3156
  }
2967
3157
  get subscriptOffset() {
2968
- return ChordSymbol.subscriptOffset * _font__WEBPACK_IMPORTED_MODULE_1__.Font.convertSizeToPixelValue(this.fontInfo.size);
3158
+ return ChordSymbol.subscriptOffset * _font__WEBPACK_IMPORTED_MODULE_3__.Font.convertSizeToPixelValue(this.fontInfo.size);
2969
3159
  }
2970
3160
  setReportWidth(value) {
2971
3161
  this.reportWidth = value;
@@ -2989,7 +3179,7 @@ class ChordSymbol extends _modifier__WEBPACK_IMPORTED_MODULE_4__.Modifier {
2989
3179
  }
2990
3180
  if (symbolBlock.isSubscript() || symbolBlock.isSuperscript()) {
2991
3181
  const { family, size, weight, style } = this.fontInfo;
2992
- const smallerFontSize = _font__WEBPACK_IMPORTED_MODULE_1__.Font.scaleSize(size, ChordSymbol.superSubRatio);
3182
+ const smallerFontSize = _font__WEBPACK_IMPORTED_MODULE_3__.Font.scaleSize(size, ChordSymbol.superSubRatio);
2993
3183
  symbolBlock.setFont(family, smallerFontSize, weight, style);
2994
3184
  }
2995
3185
  else {
@@ -3075,7 +3265,7 @@ class ChordSymbol extends _modifier__WEBPACK_IMPORTED_MODULE_4__.Modifier {
3075
3265
  this.setRendered();
3076
3266
  const clsAttribute = this.getAttribute('class');
3077
3267
  ctx.openGroup('chordsymbol' + (clsAttribute ? ' ' + clsAttribute : ''), this.getAttribute('id'));
3078
- const start = note.getModifierStartXY(_modifier__WEBPACK_IMPORTED_MODULE_4__.Modifier.Position.ABOVE, this.index);
3268
+ const start = note.getModifierStartXY(_modifier__WEBPACK_IMPORTED_MODULE_6__.Modifier.Position.ABOVE, this.index);
3079
3269
  ctx.setFont(this.fontInfo);
3080
3270
  let y;
3081
3271
  // The position of the text varies based on whether or not the note
@@ -3084,7 +3274,7 @@ class ChordSymbol extends _modifier__WEBPACK_IMPORTED_MODULE_4__.Modifier {
3084
3274
  const stave = note.checkStave();
3085
3275
  if (this.vertical === ChordSymbolVerticalJustify.BOTTOM) {
3086
3276
  // HACK: We need to compensate for the text's height since its origin is bottom-right.
3087
- y = stave.getYForBottomText(this.textLine + _tables__WEBPACK_IMPORTED_MODULE_5__.Tables.TEXT_HEIGHT_OFFSET_HACK);
3277
+ y = stave.getYForBottomText(this.textLine + _tables__WEBPACK_IMPORTED_MODULE_7__.Tables.TEXT_HEIGHT_OFFSET_HACK);
3088
3278
  if (hasStem) {
3089
3279
  const stemExt = note.checkStem().getExtents();
3090
3280
  const spacing = stave.getSpacingBetweenLines();
@@ -3107,7 +3297,7 @@ class ChordSymbol extends _modifier__WEBPACK_IMPORTED_MODULE_4__.Modifier {
3107
3297
  x = start.x;
3108
3298
  }
3109
3299
  else if (this.horizontal === ChordSymbolHorizontalJustify.RIGHT) {
3110
- x = start.x + this.getWidth();
3300
+ x = this.kernedRuns ? start.x - this.getWidth() : start.x + this.getWidth();
3111
3301
  }
3112
3302
  else if (this.horizontal === ChordSymbolHorizontalJustify.CENTER) {
3113
3303
  x = start.x - this.getWidth() / 2;
@@ -3117,18 +3307,42 @@ class ChordSymbol extends _modifier__WEBPACK_IMPORTED_MODULE_4__.Modifier {
3117
3307
  x = note.getStemX() - this.getWidth() / 2;
3118
3308
  }
3119
3309
  L('Rendering ChordSymbol: ', x, y);
3120
- this.symbolBlocks.forEach((symbol) => {
3121
- L('Rendering Text: ', symbol.getText(), x + symbol.getXShift(), y + symbol.getYShift());
3122
- symbol.setX(x);
3123
- symbol.setY(y);
3124
- symbol.renderText(ctx, 0, 0);
3125
- });
3310
+ if (this.kernedRuns) {
3311
+ this.kerningOrigin = { x, y };
3312
+ for (const run of this.kernedRuns) {
3313
+ ctx.setFont(run.font);
3314
+ ctx.fillText(run.text, x + run.x, y + run.y);
3315
+ }
3316
+ }
3317
+ else {
3318
+ this.symbolBlocks.forEach((symbol) => {
3319
+ L('Rendering Text: ', symbol.getText(), x + symbol.getXShift(), y + symbol.getYShift());
3320
+ symbol.setX(x);
3321
+ symbol.setY(y);
3322
+ symbol.renderText(ctx, 0, 0);
3323
+ });
3324
+ }
3126
3325
  this.drawPointerRect();
3127
3326
  ctx.closeGroup();
3128
3327
  }
3129
- // Get the `BoundingBox` for the entire chord
3328
+ /** Return fresh ink bounds, including script offsets and overhangs. Empty symbols have empty bounds. */
3130
3329
  getBoundingBox() {
3131
- const boundingBox = this.symbolBlocks[0].getBoundingBox();
3330
+ if (this.kernedRuns) {
3331
+ const { x, y } = this.kerningOrigin;
3332
+ let box;
3333
+ for (const run of this.kernedRuns) {
3334
+ const m = run.metrics;
3335
+ const ink = new _boundingbox__WEBPACK_IMPORTED_MODULE_0__.BoundingBox(x + run.x - m.actualBoundingBoxLeft, y + run.y - m.actualBoundingBoxAscent, m.actualBoundingBoxLeft + m.actualBoundingBoxRight, m.actualBoundingBoxAscent + m.actualBoundingBoxDescent);
3336
+ if (box)
3337
+ box.mergeWith(ink);
3338
+ else
3339
+ box = ink;
3340
+ }
3341
+ return box !== null && box !== void 0 ? box : new _boundingbox__WEBPACK_IMPORTED_MODULE_0__.BoundingBox(x, y, 0, 0);
3342
+ }
3343
+ if (!this.symbolBlocks.length)
3344
+ return new _boundingbox__WEBPACK_IMPORTED_MODULE_0__.BoundingBox(0, 0, 0, 0);
3345
+ const boundingBox = _boundingbox__WEBPACK_IMPORTED_MODULE_0__.BoundingBox.copy(this.symbolBlocks[0].getBoundingBox());
3132
3346
  for (let i = 1; i < this.symbolBlocks.length; i++) {
3133
3347
  boundingBox.mergeWith(this.symbolBlocks[i].getBoundingBox());
3134
3348
  }
@@ -3153,26 +3367,26 @@ ChordSymbol.VerticalJustifyString = {
3153
3367
  };
3154
3368
  // Glyph data
3155
3369
  ChordSymbol.glyphs = {
3156
- diminished: _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymDiminished,
3157
- dim: _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymDiminished,
3158
- halfDiminished: _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymHalfDiminished,
3159
- '+': _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymAugmented,
3160
- augmented: _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymAugmented,
3161
- majorSeventh: _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymMajorSeventh,
3162
- minor: _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymMinor,
3163
- '-': _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymMinor,
3370
+ diminished: _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymDiminished,
3371
+ dim: _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymDiminished,
3372
+ halfDiminished: _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymHalfDiminished,
3373
+ '+': _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymAugmented,
3374
+ augmented: _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymAugmented,
3375
+ majorSeventh: _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymMajorSeventh,
3376
+ minor: _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymMinor,
3377
+ '-': _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymMinor,
3164
3378
  '(': '(', // Glyphs.csymParensLeftTall,
3165
3379
  leftParen: '(', // Glyphs.csymParensLeftTall,
3166
3380
  ')': ')', // Glyphs.csymParensRightTall,
3167
3381
  rightParen: ')', // Glyphs.csymParensRightTall,
3168
- leftBracket: _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymBracketLeftTall,
3169
- rightBracket: _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymBracketRightTall,
3382
+ leftBracket: _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymBracketLeftTall,
3383
+ rightBracket: _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymBracketRightTall,
3170
3384
  leftParenTall: '(', // Glyphs.csymParensLeftVeryTall,
3171
3385
  rightParenTall: ')', // Glyphs.csymParensRightVeryTall,
3172
- '/': _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymDiagonalArrangementSlash,
3173
- over: _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymDiagonalArrangementSlash,
3174
- '#': _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymAccidentalSharp,
3175
- b: _glyphs__WEBPACK_IMPORTED_MODULE_2__.Glyphs.csymAccidentalFlat,
3386
+ '/': _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymDiagonalArrangementSlash,
3387
+ over: _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymDiagonalArrangementSlash,
3388
+ '#': _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymAccidentalSharp,
3389
+ b: _glyphs__WEBPACK_IMPORTED_MODULE_4__.Glyphs.csymAccidentalFlat,
3176
3390
  };
3177
3391
  ChordSymbol.symbolModifiers = SymbolModifiers;
3178
3392