vexflow 5.1.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -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 +144 -14
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +144 -14
- 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/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/metrics-tests.mjs +278 -0
- package/build/types/src/element.d.ts +2 -0
- package/build/types/src/textmetricscache.d.ts +21 -0
- package/changelog/CHANGELOG.md +15 -0
- package/package.json +3 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VexFlow 5.1.
|
|
2
|
+
* VexFlow 5.1.1 2026-11-16T03:47:09.194Z 271f9428354588de1f6c83a065428c8a5c442513
|
|
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) {
|
|
@@ -4412,8 +4412,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4412
4412
|
/* harmony import */ var _font__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./font */ "./src/font.ts");
|
|
4413
4413
|
/* harmony import */ var _metrics__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./metrics */ "./src/metrics.ts");
|
|
4414
4414
|
/* harmony import */ var _registry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./registry */ "./src/registry.ts");
|
|
4415
|
-
/* harmony import */ var
|
|
4416
|
-
/* harmony import */ var
|
|
4415
|
+
/* harmony import */ var _textmetricscache__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./textmetricscache */ "./src/textmetricscache.ts");
|
|
4416
|
+
/* harmony import */ var _typeguard__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./typeguard */ "./src/typeguard.ts");
|
|
4417
|
+
/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./util */ "./src/util.ts");
|
|
4417
4418
|
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
4418
4419
|
// Shared element ownership, styling, fonts, and drawing state.
|
|
4419
4420
|
// MIT License
|
|
@@ -4424,6 +4425,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4424
4425
|
|
|
4425
4426
|
|
|
4426
4427
|
|
|
4428
|
+
|
|
4427
4429
|
/**
|
|
4428
4430
|
* Element implements a generic base class for VexFlow, with implementations
|
|
4429
4431
|
* of general functions and properties that can be inherited by all VexFlow elements.
|
|
@@ -4440,7 +4442,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4440
4442
|
*/
|
|
4441
4443
|
class Element {
|
|
4442
4444
|
static get CATEGORY() {
|
|
4443
|
-
return
|
|
4445
|
+
return _typeguard__WEBPACK_IMPORTED_MODULE_5__.Category.Element;
|
|
4444
4446
|
}
|
|
4445
4447
|
static newID() {
|
|
4446
4448
|
return `auto${Element.ID++}`;
|
|
@@ -4449,6 +4451,11 @@ class Element {
|
|
|
4449
4451
|
// https://www.npmjs.com/package/canvas
|
|
4450
4452
|
static setTextMeasurementCanvas(canvas /* | Canvas */) {
|
|
4451
4453
|
Element.txtCanvas = canvas;
|
|
4454
|
+
Element.clearTextMeasurementCache();
|
|
4455
|
+
}
|
|
4456
|
+
/** Clear shared measurements after external font registration or custom context changes. */
|
|
4457
|
+
static clearTextMeasurementCache() {
|
|
4458
|
+
_textmetricscache__WEBPACK_IMPORTED_MODULE_4__.TextMetricsCache.clear();
|
|
4452
4459
|
}
|
|
4453
4460
|
static getTextMeasurementCanvas() {
|
|
4454
4461
|
let txtCanvas = Element.txtCanvas;
|
|
@@ -4516,7 +4523,7 @@ class Element {
|
|
|
4516
4523
|
*/
|
|
4517
4524
|
addChild(child) {
|
|
4518
4525
|
if (child.parent)
|
|
4519
|
-
throw new
|
|
4526
|
+
throw new _util__WEBPACK_IMPORTED_MODULE_6__.RuntimeError('Element', 'Parent already defined');
|
|
4520
4527
|
child.parent = this;
|
|
4521
4528
|
this.children.push(child);
|
|
4522
4529
|
return this;
|
|
@@ -4618,7 +4625,7 @@ class Element {
|
|
|
4618
4625
|
}
|
|
4619
4626
|
/** Draw an element. */
|
|
4620
4627
|
draw() {
|
|
4621
|
-
throw new
|
|
4628
|
+
throw new _util__WEBPACK_IMPORTED_MODULE_6__.RuntimeError('Element', 'Draw not defined');
|
|
4622
4629
|
}
|
|
4623
4630
|
/** Check if it has a class label (An element can have multiple class labels). */
|
|
4624
4631
|
hasClass(className) {
|
|
@@ -4687,7 +4694,7 @@ class Element {
|
|
|
4687
4694
|
}
|
|
4688
4695
|
/** Return associated SVGElement. */
|
|
4689
4696
|
getSVGElement(suffix = '') {
|
|
4690
|
-
const id = (0,
|
|
4697
|
+
const id = (0,_util__WEBPACK_IMPORTED_MODULE_6__.prefix)(this.attrs.id + suffix);
|
|
4691
4698
|
const element = document.getElementById(id);
|
|
4692
4699
|
if (element)
|
|
4693
4700
|
return element;
|
|
@@ -4725,7 +4732,7 @@ class Element {
|
|
|
4725
4732
|
}
|
|
4726
4733
|
/** Validate and return the rendering context. */
|
|
4727
4734
|
checkContext() {
|
|
4728
|
-
return (0,
|
|
4735
|
+
return (0,_util__WEBPACK_IMPORTED_MODULE_6__.defined)(this.context, 'NoContext', 'No rendering context attached to instance.');
|
|
4729
4736
|
}
|
|
4730
4737
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
4731
4738
|
// Font Handling
|
|
@@ -4948,7 +4955,8 @@ class Element {
|
|
|
4948
4955
|
return this._textMetrics;
|
|
4949
4956
|
}
|
|
4950
4957
|
context.font = _font__WEBPACK_IMPORTED_MODULE_1__.Font.toCSSString(_font__WEBPACK_IMPORTED_MODULE_1__.Font.validate(this.fontInfo));
|
|
4951
|
-
|
|
4958
|
+
// Keep per-element results independent, including writable node-canvas metrics.
|
|
4959
|
+
this._textMetrics = Object.assign({}, _textmetricscache__WEBPACK_IMPORTED_MODULE_4__.TextMetricsCache.measure(context, this.text));
|
|
4952
4960
|
this._height = this._textMetrics.actualBoundingBoxAscent + this._textMetrics.actualBoundingBoxDescent;
|
|
4953
4961
|
this._width = this._textMetrics.width;
|
|
4954
4962
|
this.metricsValid = true;
|
|
@@ -4964,7 +4972,7 @@ class Element {
|
|
|
4964
4972
|
return 0;
|
|
4965
4973
|
}
|
|
4966
4974
|
context.font = _font__WEBPACK_IMPORTED_MODULE_1__.Font.toCSSString(_metrics__WEBPACK_IMPORTED_MODULE_2__.Metrics.getFontInfo(key));
|
|
4967
|
-
return
|
|
4975
|
+
return _textmetricscache__WEBPACK_IMPORTED_MODULE_4__.TextMetricsCache.measure(context, text).width;
|
|
4968
4976
|
}
|
|
4969
4977
|
/** Get the text metrics. */
|
|
4970
4978
|
getTextMetrics() {
|
|
@@ -5680,6 +5688,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
5680
5688
|
/* harmony export */ FontWeight: () => (/* binding */ FontWeight)
|
|
5681
5689
|
/* harmony export */ });
|
|
5682
5690
|
/* harmony import */ var _metrics__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./metrics */ "./src/metrics.ts");
|
|
5691
|
+
/* harmony import */ var _textmetricscache__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./textmetricscache */ "./src/textmetricscache.ts");
|
|
5683
5692
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5684
5693
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5685
5694
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -5691,6 +5700,7 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
|
|
|
5691
5700
|
};
|
|
5692
5701
|
// Font parsing, loading, and the built-in text faces used alongside SMuFL music fonts.
|
|
5693
5702
|
|
|
5703
|
+
|
|
5694
5704
|
var FontWeight;
|
|
5695
5705
|
(function (FontWeight) {
|
|
5696
5706
|
FontWeight["NORMAL"] = "normal";
|
|
@@ -5935,7 +5945,8 @@ class Font {
|
|
|
5935
5945
|
fontFaceSet = self.fonts;
|
|
5936
5946
|
}
|
|
5937
5947
|
fontFaceSet === null || fontFaceSet === void 0 ? void 0 : fontFaceSet.add(fontFace);
|
|
5938
|
-
|
|
5948
|
+
_textmetricscache__WEBPACK_IMPORTED_MODULE_1__.TextMetricsCache.clear();
|
|
5949
|
+
return fontFaceLoadPromise.finally(() => _textmetricscache__WEBPACK_IMPORTED_MODULE_1__.TextMetricsCache.clear());
|
|
5939
5950
|
});
|
|
5940
5951
|
}
|
|
5941
5952
|
static getURLForFont(fontName) {
|
|
@@ -14614,13 +14625,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
14614
14625
|
/* harmony export */ Metrics: () => (/* binding */ Metrics),
|
|
14615
14626
|
/* harmony export */ MetricsDefaults: () => (/* binding */ MetricsDefaults)
|
|
14616
14627
|
/* harmony export */ });
|
|
14617
|
-
/* harmony import */ var
|
|
14628
|
+
/* harmony import */ var _textmetricscache__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./textmetricscache */ "./src/textmetricscache.ts");
|
|
14618
14629
|
// Copyright (c) 2023-present VexFlow contributors: https://github.com/vexflow/vexflow/graphs/contributors
|
|
14619
14630
|
// Shared drawing metrics, with separate defaults for text and music glyphs.
|
|
14620
14631
|
|
|
14621
14632
|
class Metrics {
|
|
14622
14633
|
/** Use the provided key to look up a FontInfo in CommonMetrics. **/
|
|
14623
14634
|
static clear(key) {
|
|
14635
|
+
_textmetricscache__WEBPACK_IMPORTED_MODULE_0__.TextMetricsCache.clear();
|
|
14624
14636
|
if (key) {
|
|
14625
14637
|
this.cacheFont.delete(key);
|
|
14626
14638
|
this.cacheStyle.delete(key);
|
|
@@ -14641,7 +14653,8 @@ class Metrics {
|
|
|
14641
14653
|
};
|
|
14642
14654
|
this.cacheFont.set(key, font);
|
|
14643
14655
|
}
|
|
14644
|
-
|
|
14656
|
+
// FontInfo contains only scalar values. Each caller still receives its own object.
|
|
14657
|
+
return Object.assign({}, font);
|
|
14645
14658
|
}
|
|
14646
14659
|
/** Keep text spaces in the text font while honoring class-specific font overrides. */
|
|
14647
14660
|
static getFontFamily(key) {
|
|
@@ -14671,7 +14684,8 @@ class Metrics {
|
|
|
14671
14684
|
};
|
|
14672
14685
|
this.cacheStyle.set(key, style);
|
|
14673
14686
|
}
|
|
14674
|
-
|
|
14687
|
+
// ElementStyle contains only scalar values, including the SVG lineDash string.
|
|
14688
|
+
return Object.assign({}, style);
|
|
14675
14689
|
}
|
|
14676
14690
|
/**
|
|
14677
14691
|
* Use the provided key to look up a value in CommonMetrics.
|
|
@@ -25071,6 +25085,122 @@ class TextDynamics extends _note__WEBPACK_IMPORTED_MODULE_2__.Note {
|
|
|
25071
25085
|
TextDynamics.DEBUG = false;
|
|
25072
25086
|
|
|
25073
25087
|
|
|
25088
|
+
/***/ },
|
|
25089
|
+
|
|
25090
|
+
/***/ "./src/textmetricscache.ts"
|
|
25091
|
+
/*!*********************************!*\
|
|
25092
|
+
!*** ./src/textmetricscache.ts ***!
|
|
25093
|
+
\*********************************/
|
|
25094
|
+
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
25095
|
+
|
|
25096
|
+
__webpack_require__.r(__webpack_exports__);
|
|
25097
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
25098
|
+
/* harmony export */ TextMetricsCache: () => (/* binding */ TextMetricsCache)
|
|
25099
|
+
/* harmony export */ });
|
|
25100
|
+
// Bounded, shared canvas text measurements. No DOM or canvas is required at import time.
|
|
25101
|
+
/** Internal cache shared by Element.measureText() and Element.measureWidth(). */
|
|
25102
|
+
class TextMetricsCache {
|
|
25103
|
+
/** Also used by Metrics.clear() and explicit canvas/font replacement. */
|
|
25104
|
+
static clear() {
|
|
25105
|
+
this.entries.clear();
|
|
25106
|
+
}
|
|
25107
|
+
/** Track document/worker fonts without retaining listeners on a replaced document. */
|
|
25108
|
+
static fontsReady() {
|
|
25109
|
+
var _a;
|
|
25110
|
+
const fonts = typeof document !== 'undefined'
|
|
25111
|
+
? document.fonts
|
|
25112
|
+
: globalThis.fonts;
|
|
25113
|
+
if (fonts !== this.fonts) {
|
|
25114
|
+
for (const type of ['loading', 'loadingdone', 'loadingerror']) {
|
|
25115
|
+
(_a = this.fonts) === null || _a === void 0 ? void 0 : _a.removeEventListener(type, this.onFontsChanged);
|
|
25116
|
+
fonts === null || fonts === void 0 ? void 0 : fonts.addEventListener(type, this.onFontsChanged);
|
|
25117
|
+
}
|
|
25118
|
+
this.fonts = fonts;
|
|
25119
|
+
this.clear();
|
|
25120
|
+
}
|
|
25121
|
+
// add()/delete() of already-loaded faces need not dispatch a loading event.
|
|
25122
|
+
if ((fonts === null || fonts === void 0 ? void 0 : fonts.size) !== this.fontCount || (fonts === null || fonts === void 0 ? void 0 : fonts.status) !== this.fontStatus) {
|
|
25123
|
+
this.fontCount = fonts === null || fonts === void 0 ? void 0 : fonts.size;
|
|
25124
|
+
this.fontStatus = fonts === null || fonts === void 0 ? void 0 : fonts.status;
|
|
25125
|
+
this.clear();
|
|
25126
|
+
}
|
|
25127
|
+
return (fonts === null || fonts === void 0 ? void 0 : fonts.status) !== 'loading';
|
|
25128
|
+
}
|
|
25129
|
+
/** Preserve all TextMetrics fields, which are prototype getters in browsers. */
|
|
25130
|
+
static snapshot(metrics) {
|
|
25131
|
+
return Object.freeze({
|
|
25132
|
+
width: metrics.width,
|
|
25133
|
+
actualBoundingBoxLeft: metrics.actualBoundingBoxLeft,
|
|
25134
|
+
actualBoundingBoxRight: metrics.actualBoundingBoxRight,
|
|
25135
|
+
actualBoundingBoxAscent: metrics.actualBoundingBoxAscent,
|
|
25136
|
+
actualBoundingBoxDescent: metrics.actualBoundingBoxDescent,
|
|
25137
|
+
fontBoundingBoxAscent: metrics.fontBoundingBoxAscent,
|
|
25138
|
+
fontBoundingBoxDescent: metrics.fontBoundingBoxDescent,
|
|
25139
|
+
emHeightAscent: metrics.emHeightAscent,
|
|
25140
|
+
emHeightDescent: metrics.emHeightDescent,
|
|
25141
|
+
hangingBaseline: metrics.hangingBaseline,
|
|
25142
|
+
alphabeticBaseline: metrics.alphabeticBaseline,
|
|
25143
|
+
ideographicBaseline: metrics.ideographicBaseline,
|
|
25144
|
+
});
|
|
25145
|
+
}
|
|
25146
|
+
/** Key shaping and bounds settings as well as font/text; never cache fallback during loading. */
|
|
25147
|
+
static measure(context, text) {
|
|
25148
|
+
var _a, _b, _c;
|
|
25149
|
+
if (context !== this.context) {
|
|
25150
|
+
this.context = context;
|
|
25151
|
+
this.clear();
|
|
25152
|
+
}
|
|
25153
|
+
const cacheable = this.fontsReady();
|
|
25154
|
+
// lang is a newer canvas API and may be absent from TypeScript's DOM definitions.
|
|
25155
|
+
let lang = context.lang;
|
|
25156
|
+
let direction = context.direction;
|
|
25157
|
+
const canvas = context.canvas;
|
|
25158
|
+
if (canvas && 'ownerDocument' in canvas) {
|
|
25159
|
+
if (direction === 'inherit') {
|
|
25160
|
+
direction = canvas.isConnected
|
|
25161
|
+
? ((_a = canvas.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(canvas).direction) || 'ltr'
|
|
25162
|
+
: canvas.style.direction || canvas.dir || 'ltr';
|
|
25163
|
+
}
|
|
25164
|
+
if (!lang || lang === 'inherit') {
|
|
25165
|
+
lang = (_c = (_b = canvas.closest('[lang]')) === null || _b === void 0 ? void 0 : _b.getAttribute('lang')) !== null && _c !== void 0 ? _c : canvas.ownerDocument.documentElement.lang;
|
|
25166
|
+
}
|
|
25167
|
+
}
|
|
25168
|
+
const key = JSON.stringify([
|
|
25169
|
+
context.font,
|
|
25170
|
+
direction,
|
|
25171
|
+
context.textAlign,
|
|
25172
|
+
context.textBaseline,
|
|
25173
|
+
context.fontKerning,
|
|
25174
|
+
context.fontStretch,
|
|
25175
|
+
context.fontVariantCaps,
|
|
25176
|
+
context.letterSpacing,
|
|
25177
|
+
context.wordSpacing,
|
|
25178
|
+
context.textRendering,
|
|
25179
|
+
lang,
|
|
25180
|
+
text,
|
|
25181
|
+
]);
|
|
25182
|
+
const cached = cacheable ? this.entries.get(key) : undefined;
|
|
25183
|
+
if (cached) {
|
|
25184
|
+
// Refresh insertion order for least-recently-used eviction.
|
|
25185
|
+
this.entries.delete(key);
|
|
25186
|
+
this.entries.set(key, cached);
|
|
25187
|
+
return cached;
|
|
25188
|
+
}
|
|
25189
|
+
const metrics = this.snapshot(context.measureText(text));
|
|
25190
|
+
if (cacheable && key.length <= this.maxKeyLength) {
|
|
25191
|
+
if (this.entries.size >= this.maxEntries)
|
|
25192
|
+
this.entries.delete(this.entries.keys().next().value);
|
|
25193
|
+
this.entries.set(key, metrics);
|
|
25194
|
+
}
|
|
25195
|
+
return metrics;
|
|
25196
|
+
}
|
|
25197
|
+
}
|
|
25198
|
+
TextMetricsCache.maxEntries = 2048;
|
|
25199
|
+
TextMetricsCache.maxKeyLength = 4096;
|
|
25200
|
+
TextMetricsCache.entries = new Map();
|
|
25201
|
+
TextMetricsCache.onFontsChanged = () => TextMetricsCache.clear();
|
|
25202
|
+
|
|
25203
|
+
|
|
25074
25204
|
/***/ },
|
|
25075
25205
|
|
|
25076
25206
|
/***/ "./src/textnote.ts"
|