vexflow 5.1.0 → 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.
- package/README.md +18 -6
- package/build/cjs/vexflow-bravura.js +2 -2
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +2 -2
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +427 -83
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +427 -83
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/src/chordkerning.js +98 -0
- package/build/esm/src/chordsymbol.js +108 -27
- package/build/esm/src/element.js +7 -2
- package/build/esm/src/font.js +3 -1
- package/build/esm/src/metrics.js +4 -3
- package/build/esm/src/textmetricscache.js +93 -0
- package/build/esm/src/version.js +3 -3
- package/build/esm/tests/node/chord-kerning-tests.mjs +173 -0
- package/build/esm/tests/node/metrics-tests.mjs +278 -0
- package/build/esm/tests/node/tool-security-tests.mjs +85 -0
- package/build/types/src/chordkerning.d.ts +42 -0
- package/build/types/src/chordsymbol.d.ts +19 -0
- package/build/types/src/element.d.ts +2 -0
- package/build/types/src/textmetricscache.d.ts +21 -0
- package/changelog/CHANGELOG.md +37 -0
- package/package.json +16 -7
- package/tests/flow.html +10 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VexFlow 5.1.
|
|
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
|
|
2789
|
-
/* harmony import */ var
|
|
2790
|
-
/* harmony import */ var
|
|
2791
|
-
/* harmony import */ var
|
|
2792
|
-
/* harmony import */ var
|
|
2793
|
-
/* harmony import */ var
|
|
2794
|
-
/* harmony import */ var
|
|
2795
|
-
/* harmony import */ var
|
|
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,
|
|
2948
|
+
(0,_util__WEBPACK_IMPORTED_MODULE_9__.log)('VexFlow.ChordSymbol', args);
|
|
2819
2949
|
}
|
|
2820
|
-
class ChordSymbolBlock extends
|
|
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
|
|
2988
|
+
class ChordSymbol extends _modifier__WEBPACK_IMPORTED_MODULE_6__.Modifier {
|
|
2859
2989
|
static get CATEGORY() {
|
|
2860
|
-
return
|
|
2990
|
+
return "ChordSymbol" /* Category.ChordSymbol */;
|
|
2861
2991
|
}
|
|
2862
2992
|
static get superSubRatio() {
|
|
2863
|
-
return
|
|
2993
|
+
return _metrics__WEBPACK_IMPORTED_MODULE_5__.Metrics.get('ChordSymbol.superSubRatio');
|
|
2864
2994
|
}
|
|
2865
2995
|
static get spacingBetweenBlocks() {
|
|
2866
|
-
return
|
|
2996
|
+
return _metrics__WEBPACK_IMPORTED_MODULE_5__.Metrics.get('ChordSymbol.spacing');
|
|
2867
2997
|
}
|
|
2868
2998
|
static get superscriptOffset() {
|
|
2869
|
-
return
|
|
2999
|
+
return _metrics__WEBPACK_IMPORTED_MODULE_5__.Metrics.get('ChordSymbol.superscriptOffset');
|
|
2870
3000
|
}
|
|
2871
3001
|
static get subscriptOffset() {
|
|
2872
|
-
return
|
|
3002
|
+
return _metrics__WEBPACK_IMPORTED_MODULE_5__.Metrics.get('ChordSymbol.subscriptOffset');
|
|
2873
3003
|
}
|
|
2874
3004
|
static get minPadding() {
|
|
2875
|
-
return
|
|
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
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
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
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
const
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
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,
|
|
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 *
|
|
3155
|
+
return ChordSymbol.superscriptOffset * _font__WEBPACK_IMPORTED_MODULE_3__.Font.convertSizeToPixelValue(this.fontInfo.size);
|
|
2966
3156
|
}
|
|
2967
3157
|
get subscriptOffset() {
|
|
2968
|
-
return ChordSymbol.subscriptOffset *
|
|
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 =
|
|
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(
|
|
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 +
|
|
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.
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
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
|
-
|
|
3328
|
+
/** Return fresh ink bounds, including script offsets and overhangs. Empty symbols have empty bounds. */
|
|
3130
3329
|
getBoundingBox() {
|
|
3131
|
-
|
|
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:
|
|
3157
|
-
dim:
|
|
3158
|
-
halfDiminished:
|
|
3159
|
-
'+':
|
|
3160
|
-
augmented:
|
|
3161
|
-
majorSeventh:
|
|
3162
|
-
minor:
|
|
3163
|
-
'-':
|
|
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:
|
|
3169
|
-
rightBracket:
|
|
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
|
-
'/':
|
|
3173
|
-
over:
|
|
3174
|
-
'#':
|
|
3175
|
-
b:
|
|
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
|
|
|
@@ -4412,8 +4626,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4412
4626
|
/* harmony import */ var _font__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./font */ "./src/font.ts");
|
|
4413
4627
|
/* harmony import */ var _metrics__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./metrics */ "./src/metrics.ts");
|
|
4414
4628
|
/* harmony import */ var _registry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./registry */ "./src/registry.ts");
|
|
4415
|
-
/* harmony import */ var
|
|
4416
|
-
/* harmony import */ var
|
|
4629
|
+
/* harmony import */ var _textmetricscache__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./textmetricscache */ "./src/textmetricscache.ts");
|
|
4630
|
+
/* harmony import */ var _typeguard__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./typeguard */ "./src/typeguard.ts");
|
|
4631
|
+
/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./util */ "./src/util.ts");
|
|
4417
4632
|
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
4418
4633
|
// Shared element ownership, styling, fonts, and drawing state.
|
|
4419
4634
|
// MIT License
|
|
@@ -4424,6 +4639,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4424
4639
|
|
|
4425
4640
|
|
|
4426
4641
|
|
|
4642
|
+
|
|
4427
4643
|
/**
|
|
4428
4644
|
* Element implements a generic base class for VexFlow, with implementations
|
|
4429
4645
|
* of general functions and properties that can be inherited by all VexFlow elements.
|
|
@@ -4440,7 +4656,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4440
4656
|
*/
|
|
4441
4657
|
class Element {
|
|
4442
4658
|
static get CATEGORY() {
|
|
4443
|
-
return
|
|
4659
|
+
return _typeguard__WEBPACK_IMPORTED_MODULE_5__.Category.Element;
|
|
4444
4660
|
}
|
|
4445
4661
|
static newID() {
|
|
4446
4662
|
return `auto${Element.ID++}`;
|
|
@@ -4449,6 +4665,11 @@ class Element {
|
|
|
4449
4665
|
// https://www.npmjs.com/package/canvas
|
|
4450
4666
|
static setTextMeasurementCanvas(canvas /* | Canvas */) {
|
|
4451
4667
|
Element.txtCanvas = canvas;
|
|
4668
|
+
Element.clearTextMeasurementCache();
|
|
4669
|
+
}
|
|
4670
|
+
/** Clear shared measurements after external font registration or custom context changes. */
|
|
4671
|
+
static clearTextMeasurementCache() {
|
|
4672
|
+
_textmetricscache__WEBPACK_IMPORTED_MODULE_4__.TextMetricsCache.clear();
|
|
4452
4673
|
}
|
|
4453
4674
|
static getTextMeasurementCanvas() {
|
|
4454
4675
|
let txtCanvas = Element.txtCanvas;
|
|
@@ -4516,7 +4737,7 @@ class Element {
|
|
|
4516
4737
|
*/
|
|
4517
4738
|
addChild(child) {
|
|
4518
4739
|
if (child.parent)
|
|
4519
|
-
throw new
|
|
4740
|
+
throw new _util__WEBPACK_IMPORTED_MODULE_6__.RuntimeError('Element', 'Parent already defined');
|
|
4520
4741
|
child.parent = this;
|
|
4521
4742
|
this.children.push(child);
|
|
4522
4743
|
return this;
|
|
@@ -4618,7 +4839,7 @@ class Element {
|
|
|
4618
4839
|
}
|
|
4619
4840
|
/** Draw an element. */
|
|
4620
4841
|
draw() {
|
|
4621
|
-
throw new
|
|
4842
|
+
throw new _util__WEBPACK_IMPORTED_MODULE_6__.RuntimeError('Element', 'Draw not defined');
|
|
4622
4843
|
}
|
|
4623
4844
|
/** Check if it has a class label (An element can have multiple class labels). */
|
|
4624
4845
|
hasClass(className) {
|
|
@@ -4687,7 +4908,7 @@ class Element {
|
|
|
4687
4908
|
}
|
|
4688
4909
|
/** Return associated SVGElement. */
|
|
4689
4910
|
getSVGElement(suffix = '') {
|
|
4690
|
-
const id = (0,
|
|
4911
|
+
const id = (0,_util__WEBPACK_IMPORTED_MODULE_6__.prefix)(this.attrs.id + suffix);
|
|
4691
4912
|
const element = document.getElementById(id);
|
|
4692
4913
|
if (element)
|
|
4693
4914
|
return element;
|
|
@@ -4725,7 +4946,7 @@ class Element {
|
|
|
4725
4946
|
}
|
|
4726
4947
|
/** Validate and return the rendering context. */
|
|
4727
4948
|
checkContext() {
|
|
4728
|
-
return (0,
|
|
4949
|
+
return (0,_util__WEBPACK_IMPORTED_MODULE_6__.defined)(this.context, 'NoContext', 'No rendering context attached to instance.');
|
|
4729
4950
|
}
|
|
4730
4951
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
4731
4952
|
// Font Handling
|
|
@@ -4948,7 +5169,8 @@ class Element {
|
|
|
4948
5169
|
return this._textMetrics;
|
|
4949
5170
|
}
|
|
4950
5171
|
context.font = _font__WEBPACK_IMPORTED_MODULE_1__.Font.toCSSString(_font__WEBPACK_IMPORTED_MODULE_1__.Font.validate(this.fontInfo));
|
|
4951
|
-
|
|
5172
|
+
// Keep per-element results independent, including writable node-canvas metrics.
|
|
5173
|
+
this._textMetrics = Object.assign({}, _textmetricscache__WEBPACK_IMPORTED_MODULE_4__.TextMetricsCache.measure(context, this.text));
|
|
4952
5174
|
this._height = this._textMetrics.actualBoundingBoxAscent + this._textMetrics.actualBoundingBoxDescent;
|
|
4953
5175
|
this._width = this._textMetrics.width;
|
|
4954
5176
|
this.metricsValid = true;
|
|
@@ -4964,7 +5186,7 @@ class Element {
|
|
|
4964
5186
|
return 0;
|
|
4965
5187
|
}
|
|
4966
5188
|
context.font = _font__WEBPACK_IMPORTED_MODULE_1__.Font.toCSSString(_metrics__WEBPACK_IMPORTED_MODULE_2__.Metrics.getFontInfo(key));
|
|
4967
|
-
return
|
|
5189
|
+
return _textmetricscache__WEBPACK_IMPORTED_MODULE_4__.TextMetricsCache.measure(context, text).width;
|
|
4968
5190
|
}
|
|
4969
5191
|
/** Get the text metrics. */
|
|
4970
5192
|
getTextMetrics() {
|
|
@@ -5680,6 +5902,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
5680
5902
|
/* harmony export */ FontWeight: () => (/* binding */ FontWeight)
|
|
5681
5903
|
/* harmony export */ });
|
|
5682
5904
|
/* harmony import */ var _metrics__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./metrics */ "./src/metrics.ts");
|
|
5905
|
+
/* harmony import */ var _textmetricscache__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./textmetricscache */ "./src/textmetricscache.ts");
|
|
5683
5906
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5684
5907
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5685
5908
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -5691,6 +5914,7 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
|
|
|
5691
5914
|
};
|
|
5692
5915
|
// Font parsing, loading, and the built-in text faces used alongside SMuFL music fonts.
|
|
5693
5916
|
|
|
5917
|
+
|
|
5694
5918
|
var FontWeight;
|
|
5695
5919
|
(function (FontWeight) {
|
|
5696
5920
|
FontWeight["NORMAL"] = "normal";
|
|
@@ -5935,7 +6159,8 @@ class Font {
|
|
|
5935
6159
|
fontFaceSet = self.fonts;
|
|
5936
6160
|
}
|
|
5937
6161
|
fontFaceSet === null || fontFaceSet === void 0 ? void 0 : fontFaceSet.add(fontFace);
|
|
5938
|
-
|
|
6162
|
+
_textmetricscache__WEBPACK_IMPORTED_MODULE_1__.TextMetricsCache.clear();
|
|
6163
|
+
return fontFaceLoadPromise.finally(() => _textmetricscache__WEBPACK_IMPORTED_MODULE_1__.TextMetricsCache.clear());
|
|
5939
6164
|
});
|
|
5940
6165
|
}
|
|
5941
6166
|
static getURLForFont(fontName) {
|
|
@@ -14614,13 +14839,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
14614
14839
|
/* harmony export */ Metrics: () => (/* binding */ Metrics),
|
|
14615
14840
|
/* harmony export */ MetricsDefaults: () => (/* binding */ MetricsDefaults)
|
|
14616
14841
|
/* harmony export */ });
|
|
14617
|
-
/* harmony import */ var
|
|
14842
|
+
/* harmony import */ var _textmetricscache__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./textmetricscache */ "./src/textmetricscache.ts");
|
|
14618
14843
|
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
14619
14844
|
// Shared drawing metrics, with separate defaults for text and music glyphs.
|
|
14620
14845
|
|
|
14621
14846
|
class Metrics {
|
|
14622
14847
|
/** Use the provided key to look up a FontInfo in CommonMetrics. **/
|
|
14623
14848
|
static clear(key) {
|
|
14849
|
+
_textmetricscache__WEBPACK_IMPORTED_MODULE_0__.TextMetricsCache.clear();
|
|
14624
14850
|
if (key) {
|
|
14625
14851
|
this.cacheFont.delete(key);
|
|
14626
14852
|
this.cacheStyle.delete(key);
|
|
@@ -14641,7 +14867,8 @@ class Metrics {
|
|
|
14641
14867
|
};
|
|
14642
14868
|
this.cacheFont.set(key, font);
|
|
14643
14869
|
}
|
|
14644
|
-
|
|
14870
|
+
// FontInfo contains only scalar values. Each caller still receives its own object.
|
|
14871
|
+
return Object.assign({}, font);
|
|
14645
14872
|
}
|
|
14646
14873
|
/** Keep text spaces in the text font while honoring class-specific font overrides. */
|
|
14647
14874
|
static getFontFamily(key) {
|
|
@@ -14671,7 +14898,8 @@ class Metrics {
|
|
|
14671
14898
|
};
|
|
14672
14899
|
this.cacheStyle.set(key, style);
|
|
14673
14900
|
}
|
|
14674
|
-
|
|
14901
|
+
// ElementStyle contains only scalar values, including the SVG lineDash string.
|
|
14902
|
+
return Object.assign({}, style);
|
|
14675
14903
|
}
|
|
14676
14904
|
/**
|
|
14677
14905
|
* Use the provided key to look up a value in CommonMetrics.
|
|
@@ -25071,6 +25299,122 @@ class TextDynamics extends _note__WEBPACK_IMPORTED_MODULE_2__.Note {
|
|
|
25071
25299
|
TextDynamics.DEBUG = false;
|
|
25072
25300
|
|
|
25073
25301
|
|
|
25302
|
+
/***/ },
|
|
25303
|
+
|
|
25304
|
+
/***/ "./src/textmetricscache.ts"
|
|
25305
|
+
/*!*********************************!*\
|
|
25306
|
+
!*** ./src/textmetricscache.ts ***!
|
|
25307
|
+
\*********************************/
|
|
25308
|
+
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
25309
|
+
|
|
25310
|
+
__webpack_require__.r(__webpack_exports__);
|
|
25311
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
25312
|
+
/* harmony export */ TextMetricsCache: () => (/* binding */ TextMetricsCache)
|
|
25313
|
+
/* harmony export */ });
|
|
25314
|
+
// Bounded, shared canvas text measurements. No DOM or canvas is required at import time.
|
|
25315
|
+
/** Internal cache shared by Element.measureText() and Element.measureWidth(). */
|
|
25316
|
+
class TextMetricsCache {
|
|
25317
|
+
/** Also used by Metrics.clear() and explicit canvas/font replacement. */
|
|
25318
|
+
static clear() {
|
|
25319
|
+
this.entries.clear();
|
|
25320
|
+
}
|
|
25321
|
+
/** Track document/worker fonts without retaining listeners on a replaced document. */
|
|
25322
|
+
static fontsReady() {
|
|
25323
|
+
var _a;
|
|
25324
|
+
const fonts = typeof document !== 'undefined'
|
|
25325
|
+
? document.fonts
|
|
25326
|
+
: globalThis.fonts;
|
|
25327
|
+
if (fonts !== this.fonts) {
|
|
25328
|
+
for (const type of ['loading', 'loadingdone', 'loadingerror']) {
|
|
25329
|
+
(_a = this.fonts) === null || _a === void 0 ? void 0 : _a.removeEventListener(type, this.onFontsChanged);
|
|
25330
|
+
fonts === null || fonts === void 0 ? void 0 : fonts.addEventListener(type, this.onFontsChanged);
|
|
25331
|
+
}
|
|
25332
|
+
this.fonts = fonts;
|
|
25333
|
+
this.clear();
|
|
25334
|
+
}
|
|
25335
|
+
// add()/delete() of already-loaded faces need not dispatch a loading event.
|
|
25336
|
+
if ((fonts === null || fonts === void 0 ? void 0 : fonts.size) !== this.fontCount || (fonts === null || fonts === void 0 ? void 0 : fonts.status) !== this.fontStatus) {
|
|
25337
|
+
this.fontCount = fonts === null || fonts === void 0 ? void 0 : fonts.size;
|
|
25338
|
+
this.fontStatus = fonts === null || fonts === void 0 ? void 0 : fonts.status;
|
|
25339
|
+
this.clear();
|
|
25340
|
+
}
|
|
25341
|
+
return (fonts === null || fonts === void 0 ? void 0 : fonts.status) !== 'loading';
|
|
25342
|
+
}
|
|
25343
|
+
/** Preserve all TextMetrics fields, which are prototype getters in browsers. */
|
|
25344
|
+
static snapshot(metrics) {
|
|
25345
|
+
return Object.freeze({
|
|
25346
|
+
width: metrics.width,
|
|
25347
|
+
actualBoundingBoxLeft: metrics.actualBoundingBoxLeft,
|
|
25348
|
+
actualBoundingBoxRight: metrics.actualBoundingBoxRight,
|
|
25349
|
+
actualBoundingBoxAscent: metrics.actualBoundingBoxAscent,
|
|
25350
|
+
actualBoundingBoxDescent: metrics.actualBoundingBoxDescent,
|
|
25351
|
+
fontBoundingBoxAscent: metrics.fontBoundingBoxAscent,
|
|
25352
|
+
fontBoundingBoxDescent: metrics.fontBoundingBoxDescent,
|
|
25353
|
+
emHeightAscent: metrics.emHeightAscent,
|
|
25354
|
+
emHeightDescent: metrics.emHeightDescent,
|
|
25355
|
+
hangingBaseline: metrics.hangingBaseline,
|
|
25356
|
+
alphabeticBaseline: metrics.alphabeticBaseline,
|
|
25357
|
+
ideographicBaseline: metrics.ideographicBaseline,
|
|
25358
|
+
});
|
|
25359
|
+
}
|
|
25360
|
+
/** Key shaping and bounds settings as well as font/text; never cache fallback during loading. */
|
|
25361
|
+
static measure(context, text) {
|
|
25362
|
+
var _a, _b, _c;
|
|
25363
|
+
if (context !== this.context) {
|
|
25364
|
+
this.context = context;
|
|
25365
|
+
this.clear();
|
|
25366
|
+
}
|
|
25367
|
+
const cacheable = this.fontsReady();
|
|
25368
|
+
// lang is a newer canvas API and may be absent from TypeScript's DOM definitions.
|
|
25369
|
+
let lang = context.lang;
|
|
25370
|
+
let direction = context.direction;
|
|
25371
|
+
const canvas = context.canvas;
|
|
25372
|
+
if (canvas && 'ownerDocument' in canvas) {
|
|
25373
|
+
if (direction === 'inherit') {
|
|
25374
|
+
direction = canvas.isConnected
|
|
25375
|
+
? ((_a = canvas.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(canvas).direction) || 'ltr'
|
|
25376
|
+
: canvas.style.direction || canvas.dir || 'ltr';
|
|
25377
|
+
}
|
|
25378
|
+
if (!lang || lang === 'inherit') {
|
|
25379
|
+
lang = (_c = (_b = canvas.closest('[lang]')) === null || _b === void 0 ? void 0 : _b.getAttribute('lang')) !== null && _c !== void 0 ? _c : canvas.ownerDocument.documentElement.lang;
|
|
25380
|
+
}
|
|
25381
|
+
}
|
|
25382
|
+
const key = JSON.stringify([
|
|
25383
|
+
context.font,
|
|
25384
|
+
direction,
|
|
25385
|
+
context.textAlign,
|
|
25386
|
+
context.textBaseline,
|
|
25387
|
+
context.fontKerning,
|
|
25388
|
+
context.fontStretch,
|
|
25389
|
+
context.fontVariantCaps,
|
|
25390
|
+
context.letterSpacing,
|
|
25391
|
+
context.wordSpacing,
|
|
25392
|
+
context.textRendering,
|
|
25393
|
+
lang,
|
|
25394
|
+
text,
|
|
25395
|
+
]);
|
|
25396
|
+
const cached = cacheable ? this.entries.get(key) : undefined;
|
|
25397
|
+
if (cached) {
|
|
25398
|
+
// Refresh insertion order for least-recently-used eviction.
|
|
25399
|
+
this.entries.delete(key);
|
|
25400
|
+
this.entries.set(key, cached);
|
|
25401
|
+
return cached;
|
|
25402
|
+
}
|
|
25403
|
+
const metrics = this.snapshot(context.measureText(text));
|
|
25404
|
+
if (cacheable && key.length <= this.maxKeyLength) {
|
|
25405
|
+
if (this.entries.size >= this.maxEntries)
|
|
25406
|
+
this.entries.delete(this.entries.keys().next().value);
|
|
25407
|
+
this.entries.set(key, metrics);
|
|
25408
|
+
}
|
|
25409
|
+
return metrics;
|
|
25410
|
+
}
|
|
25411
|
+
}
|
|
25412
|
+
TextMetricsCache.maxEntries = 2048;
|
|
25413
|
+
TextMetricsCache.maxKeyLength = 4096;
|
|
25414
|
+
TextMetricsCache.entries = new Map();
|
|
25415
|
+
TextMetricsCache.onFontsChanged = () => TextMetricsCache.clear();
|
|
25416
|
+
|
|
25417
|
+
|
|
25074
25418
|
/***/ },
|
|
25075
25419
|
|
|
25076
25420
|
/***/ "./src/textnote.ts"
|