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
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import test from 'node:test';
|
|
12
|
+
const { Element, Font, Metrics, MetricsDefaults } = await import(new URL('../../build/esm/entry/vexflow-core.js', import.meta.url));
|
|
13
|
+
function canvas() {
|
|
14
|
+
let calls = 0;
|
|
15
|
+
const context = {
|
|
16
|
+
font: '',
|
|
17
|
+
direction: 'ltr',
|
|
18
|
+
textAlign: 'start',
|
|
19
|
+
textBaseline: 'alphabetic',
|
|
20
|
+
measureText(text) {
|
|
21
|
+
calls++;
|
|
22
|
+
return Object.create({
|
|
23
|
+
width: text.length * 5,
|
|
24
|
+
actualBoundingBoxLeft: 1,
|
|
25
|
+
actualBoundingBoxRight: 9,
|
|
26
|
+
actualBoundingBoxAscent: 8,
|
|
27
|
+
actualBoundingBoxDescent: 2,
|
|
28
|
+
fontBoundingBoxAscent: 11,
|
|
29
|
+
fontBoundingBoxDescent: 4,
|
|
30
|
+
emHeightAscent: 10,
|
|
31
|
+
emHeightDescent: 3,
|
|
32
|
+
alphabeticBaseline: 0,
|
|
33
|
+
hangingBaseline: 7,
|
|
34
|
+
ideographicBaseline: -3,
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
return { getContext: () => context, context, calls: () => calls };
|
|
39
|
+
}
|
|
40
|
+
test('font and style records preserve caller isolation without deep cloning', () => {
|
|
41
|
+
for (const [get, key] of [
|
|
42
|
+
[Metrics.getFontInfo.bind(Metrics), 'StaveNote'],
|
|
43
|
+
[Metrics.getStyle.bind(Metrics), 'StaveNote'],
|
|
44
|
+
]) {
|
|
45
|
+
const original = get(key);
|
|
46
|
+
const edited = get(key);
|
|
47
|
+
assert.notEqual(edited, original);
|
|
48
|
+
for (const field of Object.keys(edited))
|
|
49
|
+
edited[field] = 'changed';
|
|
50
|
+
assert.deepEqual(get(key), original);
|
|
51
|
+
}
|
|
52
|
+
const first = new Element();
|
|
53
|
+
const second = new Element();
|
|
54
|
+
first.fontInfo.size = 99;
|
|
55
|
+
first.getStyle().lineDash = '2,4';
|
|
56
|
+
assert.notEqual(second.fontInfo.size, 99);
|
|
57
|
+
assert.notEqual(second.getStyle().lineDash, '2,4');
|
|
58
|
+
});
|
|
59
|
+
test('elements and width lookups share native measurements but not mutable results', () => {
|
|
60
|
+
const measured = canvas();
|
|
61
|
+
Element.setTextMeasurementCanvas(measured);
|
|
62
|
+
const first = new Element().setText('abc');
|
|
63
|
+
const metrics = first.measureText();
|
|
64
|
+
assert.equal(metrics.width, 15);
|
|
65
|
+
assert.equal(first.getHeight(), 10);
|
|
66
|
+
assert.equal(metrics.fontBoundingBoxAscent, 11);
|
|
67
|
+
assert.equal(metrics.ideographicBaseline, -3);
|
|
68
|
+
metrics.width = 999;
|
|
69
|
+
metrics.actualBoundingBoxAscent = 100;
|
|
70
|
+
const second = new Element().setText('abc');
|
|
71
|
+
assert.equal(second.getWidth(), 15);
|
|
72
|
+
assert.equal(second.getHeight(), 10);
|
|
73
|
+
assert.equal(Element.measureWidth('abc', 'Element'), 15);
|
|
74
|
+
assert.equal(first.measureText().width, 15);
|
|
75
|
+
assert.equal(measured.calls(), 1);
|
|
76
|
+
});
|
|
77
|
+
test('text, font, shaping, alignment, and baseline settings are distinct cache keys', () => {
|
|
78
|
+
const measured = canvas();
|
|
79
|
+
Element.setTextMeasurementCanvas(measured);
|
|
80
|
+
const el = new Element().setText('one');
|
|
81
|
+
el.measureText();
|
|
82
|
+
el.setText('two').measureText();
|
|
83
|
+
el.setFontSize(22).measureText();
|
|
84
|
+
assert.equal(measured.calls(), 3);
|
|
85
|
+
for (const [name, value] of Object.entries({
|
|
86
|
+
direction: 'rtl',
|
|
87
|
+
textAlign: 'right',
|
|
88
|
+
textBaseline: 'top',
|
|
89
|
+
fontKerning: 'none',
|
|
90
|
+
fontStretch: 'expanded',
|
|
91
|
+
fontVariantCaps: 'small-caps',
|
|
92
|
+
letterSpacing: '1px',
|
|
93
|
+
wordSpacing: '2px',
|
|
94
|
+
textRendering: 'optimizeLegibility',
|
|
95
|
+
lang: 'ja',
|
|
96
|
+
})) {
|
|
97
|
+
const before = measured.calls();
|
|
98
|
+
measured.context[name] = value;
|
|
99
|
+
el.measureText();
|
|
100
|
+
el.measureText();
|
|
101
|
+
assert.equal(measured.calls(), before + 1, name);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
test('canvas replacement and either form of Metrics.clear invalidate shared measurements', () => {
|
|
105
|
+
const first = canvas();
|
|
106
|
+
Element.setTextMeasurementCanvas(first);
|
|
107
|
+
Element.measureWidth('same');
|
|
108
|
+
Element.measureWidth('same');
|
|
109
|
+
assert.equal(first.calls(), 1);
|
|
110
|
+
for (const key of [undefined, 'Element']) {
|
|
111
|
+
Metrics.clear(key);
|
|
112
|
+
Element.measureWidth('same');
|
|
113
|
+
}
|
|
114
|
+
assert.equal(first.calls(), 3);
|
|
115
|
+
Element.setTextMeasurementCanvas(first);
|
|
116
|
+
Element.measureWidth('same');
|
|
117
|
+
assert.equal(first.calls(), 4, 'reinstalling a reconfigured canvas also clears the cache');
|
|
118
|
+
const second = canvas();
|
|
119
|
+
Element.setTextMeasurementCanvas(second);
|
|
120
|
+
Element.measureWidth('same');
|
|
121
|
+
assert.equal(second.calls(), 1);
|
|
122
|
+
Element.clearTextMeasurementCache();
|
|
123
|
+
Element.measureWidth('same');
|
|
124
|
+
assert.equal(second.calls(), 2, 'external font registration can invalidate measurements explicitly');
|
|
125
|
+
});
|
|
126
|
+
test('inherited canvas direction and language participate in measurement keys', () => {
|
|
127
|
+
const measured = canvas();
|
|
128
|
+
let direction = 'ltr';
|
|
129
|
+
let language = 'en';
|
|
130
|
+
Object.assign(measured, {
|
|
131
|
+
ownerDocument: {
|
|
132
|
+
defaultView: { getComputedStyle: () => ({ direction }) },
|
|
133
|
+
documentElement: { lang: 'en' },
|
|
134
|
+
},
|
|
135
|
+
closest: () => ({ getAttribute: () => language }),
|
|
136
|
+
isConnected: true,
|
|
137
|
+
});
|
|
138
|
+
Object.assign(measured.context, { canvas: measured, direction: 'inherit', lang: 'inherit' });
|
|
139
|
+
Element.setTextMeasurementCanvas(measured);
|
|
140
|
+
Element.measureWidth('text');
|
|
141
|
+
Element.measureWidth('text');
|
|
142
|
+
assert.equal(measured.calls(), 1);
|
|
143
|
+
direction = 'rtl';
|
|
144
|
+
Element.measureWidth('text');
|
|
145
|
+
language = 'ja';
|
|
146
|
+
Element.measureWidth('text');
|
|
147
|
+
assert.equal(measured.calls(), 3);
|
|
148
|
+
});
|
|
149
|
+
test('category font/style caches refresh after edits to defaults', () => {
|
|
150
|
+
const key = 'MeasurementTest';
|
|
151
|
+
try {
|
|
152
|
+
MetricsDefaults[key] = { fontSize: 12, fillStyle: '#123456' };
|
|
153
|
+
Metrics.clear(key);
|
|
154
|
+
assert.equal(Metrics.getFontInfo(key).size, 12);
|
|
155
|
+
assert.equal(Metrics.getStyle(key).fillStyle, '#123456');
|
|
156
|
+
MetricsDefaults[key].fontSize = 24;
|
|
157
|
+
MetricsDefaults[key].fillStyle = '#abcdef';
|
|
158
|
+
Metrics.clear(key);
|
|
159
|
+
assert.equal(Metrics.getFontInfo(key).size, 24);
|
|
160
|
+
assert.equal(Metrics.getStyle(key).fillStyle, '#abcdef');
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
delete MetricsDefaults[key];
|
|
164
|
+
Metrics.clear(key);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
test('cache capacity is bounded, hot entries survive, and very long keys are not retained', () => {
|
|
168
|
+
const measured = canvas();
|
|
169
|
+
Element.setTextMeasurementCanvas(measured);
|
|
170
|
+
Element.measureWidth('old');
|
|
171
|
+
for (let i = 0; i < 2200; i++) {
|
|
172
|
+
Element.measureWidth('hot');
|
|
173
|
+
Element.measureWidth(`entry ${i}`);
|
|
174
|
+
}
|
|
175
|
+
const before = measured.calls();
|
|
176
|
+
Element.measureWidth('hot');
|
|
177
|
+
assert.equal(measured.calls(), before);
|
|
178
|
+
Element.measureWidth('old');
|
|
179
|
+
assert.equal(measured.calls(), before + 1);
|
|
180
|
+
Element.measureWidth('x'.repeat(5000));
|
|
181
|
+
Element.measureWidth('x'.repeat(5000));
|
|
182
|
+
assert.equal(measured.calls(), before + 3);
|
|
183
|
+
});
|
|
184
|
+
class Fonts extends EventTarget {
|
|
185
|
+
constructor() {
|
|
186
|
+
super(...arguments);
|
|
187
|
+
this.status = 'loaded';
|
|
188
|
+
this.size = 0;
|
|
189
|
+
}
|
|
190
|
+
add() {
|
|
191
|
+
this.size++;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
test('document and worker font loading, errors, and synchronous set changes invalidate the cache', () => {
|
|
195
|
+
const oldDocument = globalThis.document;
|
|
196
|
+
const oldFonts = globalThis.fonts;
|
|
197
|
+
try {
|
|
198
|
+
for (const location of ['document', 'worker']) {
|
|
199
|
+
const fonts = new Fonts();
|
|
200
|
+
if (location === 'document')
|
|
201
|
+
globalThis.document = { fonts };
|
|
202
|
+
else {
|
|
203
|
+
delete globalThis.document;
|
|
204
|
+
globalThis.fonts = fonts;
|
|
205
|
+
}
|
|
206
|
+
const measured = canvas();
|
|
207
|
+
Element.setTextMeasurementCanvas(measured);
|
|
208
|
+
Element.measureWidth('glyph');
|
|
209
|
+
fonts.status = 'loading';
|
|
210
|
+
Element.measureWidth('glyph');
|
|
211
|
+
Element.measureWidth('glyph');
|
|
212
|
+
assert.equal(measured.calls(), 3, 'fallback metrics are not shared while loading');
|
|
213
|
+
fonts.status = 'loaded';
|
|
214
|
+
Element.measureWidth('glyph');
|
|
215
|
+
Element.measureWidth('glyph');
|
|
216
|
+
assert.equal(measured.calls(), 4);
|
|
217
|
+
for (const type of ['loading', 'loadingdone', 'loadingerror']) {
|
|
218
|
+
fonts.dispatchEvent(new Event(type));
|
|
219
|
+
Element.measureWidth('glyph');
|
|
220
|
+
}
|
|
221
|
+
assert.equal(measured.calls(), 7);
|
|
222
|
+
fonts.size++;
|
|
223
|
+
Element.measureWidth('glyph');
|
|
224
|
+
fonts.size--;
|
|
225
|
+
Element.measureWidth('glyph');
|
|
226
|
+
assert.equal(measured.calls(), 9, 'loaded faces can be added/deleted without loading events');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
if (oldDocument === undefined)
|
|
231
|
+
delete globalThis.document;
|
|
232
|
+
else
|
|
233
|
+
globalThis.document = oldDocument;
|
|
234
|
+
if (oldFonts === undefined)
|
|
235
|
+
delete globalThis.fonts;
|
|
236
|
+
else
|
|
237
|
+
globalThis.fonts = oldFonts;
|
|
238
|
+
Metrics.clear();
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
test('Font.load clears measurements when a font finishes loading or fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
242
|
+
const oldFace = globalThis.FontFace;
|
|
243
|
+
let settle;
|
|
244
|
+
globalThis.FontFace = class {
|
|
245
|
+
load() {
|
|
246
|
+
return new Promise((resolve, reject) => {
|
|
247
|
+
settle = { resolve, reject };
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
try {
|
|
252
|
+
for (const fails of [false, true]) {
|
|
253
|
+
const measured = canvas();
|
|
254
|
+
Element.setTextMeasurementCanvas(measured);
|
|
255
|
+
Element.measureWidth('glyph');
|
|
256
|
+
const loading = Font.load('Test', 'data:font/otf;base64,AA==');
|
|
257
|
+
Element.measureWidth('glyph');
|
|
258
|
+
assert.equal(measured.calls(), 2, 'load start clears old results');
|
|
259
|
+
if (fails) {
|
|
260
|
+
settle.reject(new Error('font failed'));
|
|
261
|
+
yield assert.rejects(loading, /font failed/);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
settle.resolve({ family: 'Test' });
|
|
265
|
+
yield loading;
|
|
266
|
+
}
|
|
267
|
+
Element.measureWidth('glyph');
|
|
268
|
+
assert.equal(measured.calls(), 3, 'settlement clears fallback results');
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
finally {
|
|
272
|
+
if (oldFace === undefined)
|
|
273
|
+
delete globalThis.FontFace;
|
|
274
|
+
else
|
|
275
|
+
globalThis.FontFace = oldFace;
|
|
276
|
+
Metrics.clear();
|
|
277
|
+
}
|
|
278
|
+
}));
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync, } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import test from 'node:test';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { JSDOM } from 'jsdom';
|
|
9
|
+
const root = fileURLToPath(new URL('../../', import.meta.url));
|
|
10
|
+
test('release downloads reject paths, flags, and shell fragments before prompting', () => {
|
|
11
|
+
for (const version of ['../outside', '--help', '4.0.0;echo injected', '4.0.0$(echo injected)', '4.0.0\n', 'latest']) {
|
|
12
|
+
const result = spawnSync(process.execPath, ['tools/get_releases.mjs', version], {
|
|
13
|
+
cwd: root,
|
|
14
|
+
encoding: 'utf8',
|
|
15
|
+
timeout: 3000,
|
|
16
|
+
});
|
|
17
|
+
assert.ifError(result.error);
|
|
18
|
+
assert.notEqual(result.status, 0);
|
|
19
|
+
assert.match(result.stderr, /Invalid release version/);
|
|
20
|
+
assert.doesNotMatch(result.stdout, /Press any key/);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
test('release download commands preserve spaces and shell punctuation in checkout paths', () => {
|
|
24
|
+
const directory = realpathSync(mkdtempSync(join(tmpdir(), "release tools '$literal' ")));
|
|
25
|
+
try {
|
|
26
|
+
mkdirSync(join(directory, 'tools'));
|
|
27
|
+
mkdirSync(join(directory, 'bin'));
|
|
28
|
+
symlinkSync(join(root, 'node_modules'), join(directory, 'node_modules'), 'dir');
|
|
29
|
+
copyFileSync(join(root, 'tools/get_releases.mjs'), join(directory, 'tools/get_releases.mjs'));
|
|
30
|
+
const command = `#!${process.execPath}
|
|
31
|
+
const fs = require('node:fs');
|
|
32
|
+
const path = require('node:path');
|
|
33
|
+
const name = path.basename(process.argv[1]);
|
|
34
|
+
const args = process.argv.slice(2);
|
|
35
|
+
fs.appendFileSync(process.env.COMMAND_LOG, JSON.stringify({name,args}) + '\\n');
|
|
36
|
+
if (name === 'tar') {
|
|
37
|
+
const build = path.join(args[args.indexOf('-C') + 1], 'package', 'build');
|
|
38
|
+
fs.mkdirSync(build, {recursive:true});
|
|
39
|
+
fs.writeFileSync(path.join(build, 'fixture.js'), 'release fixture');
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
for (const name of ['git', 'npm', 'tar'])
|
|
43
|
+
writeFileSync(join(directory, 'bin', name), command, { mode: 0o755 });
|
|
44
|
+
writeFileSync(join(directory, 'stdin.mjs'), 'process.stdin.setRawMode = () => {};');
|
|
45
|
+
const log = join(directory, 'commands.jsonl');
|
|
46
|
+
const result = spawnSync(process.execPath, ['--import', './stdin.mjs', 'tools/get_releases.mjs', '5.0.0-beta.1'], {
|
|
47
|
+
cwd: directory,
|
|
48
|
+
env: Object.assign(Object.assign({}, process.env), { PATH: `${join(directory, 'bin')}:${process.env.PATH}`, COMMAND_LOG: log }),
|
|
49
|
+
input: 'y',
|
|
50
|
+
encoding: 'utf8',
|
|
51
|
+
timeout: 5000,
|
|
52
|
+
});
|
|
53
|
+
assert.ifError(result.error);
|
|
54
|
+
assert.equal(result.status, 0, result.stderr || result.stdout);
|
|
55
|
+
assert.equal(readFileSync(join(directory, 'releases/5.0.0-beta.1/fixture.js'), 'utf8'), 'release fixture');
|
|
56
|
+
const calls = readFileSync(log, 'utf8').trim().split('\n').map(JSON.parse);
|
|
57
|
+
const pack = calls.find(({ name }) => name === 'npm').args;
|
|
58
|
+
assert.equal(pack[pack.indexOf('--pack-destination') + 1], join(directory, 'releases/5.0.0-beta.1-delete-me-later'));
|
|
59
|
+
assert.ok(pack.includes('--ignore-scripts'));
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
rmSync(directory, { recursive: true, force: true });
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
test('font metadata stays literal text while labels retain their formatting', () => {
|
|
66
|
+
const html = readFileSync(join(root, 'demos/opentype/load.html'), 'utf8');
|
|
67
|
+
const dom = new JSDOM(html, { runScripts: 'outside-only' });
|
|
68
|
+
try {
|
|
69
|
+
const { window } = dom;
|
|
70
|
+
window.console.log = () => { };
|
|
71
|
+
const name = '<img src=x onerror="globalThis.injected = true"> & Test';
|
|
72
|
+
window.opentype = { parse: () => ({ names: { fontFamily: { en: name } }, glyphs: { length: 12 } }) };
|
|
73
|
+
window.eval(window.document.querySelector('script:not([src])').textContent);
|
|
74
|
+
assert.equal(window.parseFont(new Uint8Array([0]), 'music'), name);
|
|
75
|
+
const target = window.document.getElementById('musicFontInfo');
|
|
76
|
+
assert.equal(target.querySelector('img'), null);
|
|
77
|
+
assert.equal(window.injected, undefined);
|
|
78
|
+
assert.ok(target.textContent.includes(name));
|
|
79
|
+
assert.deepEqual([...target.querySelectorAll('b')].map((node) => node.textContent), ['Font Family Name:', 'Num Glyphs:']);
|
|
80
|
+
assert.equal(target.querySelectorAll('br').length, 2);
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
dom.window.close();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FontInfo } from './font';
|
|
2
|
+
/** Script position relative to the parent chord's baseline. */
|
|
3
|
+
export type ChordSymbolPosition = 'baseline' | 'superscript' | 'subscript';
|
|
4
|
+
/** A boundary adjustment in parent-font em units. Characters are literal Unicode values. */
|
|
5
|
+
export interface ChordSymbolKerningPair {
|
|
6
|
+
left: string;
|
|
7
|
+
right: string;
|
|
8
|
+
position: ChordSymbolPosition;
|
|
9
|
+
adjustmentEm: number;
|
|
10
|
+
}
|
|
11
|
+
/** Exact faces and style for a calibrated pair table. Custom profiles are per chord. */
|
|
12
|
+
export interface ChordSymbolKerningProfile {
|
|
13
|
+
textFont: string;
|
|
14
|
+
musicFont: string;
|
|
15
|
+
weight?: string | number;
|
|
16
|
+
style?: string;
|
|
17
|
+
pairs: readonly ChordSymbolKerningPair[];
|
|
18
|
+
}
|
|
19
|
+
/** Text stays together until a music glyph or script boundary changes the font run. */
|
|
20
|
+
export interface ChordSymbolText {
|
|
21
|
+
text: string;
|
|
22
|
+
position: ChordSymbolPosition;
|
|
23
|
+
}
|
|
24
|
+
/** A measured run, in unscaled score coordinates, shared by Canvas and SVG. */
|
|
25
|
+
export interface ChordSymbolRun extends ChordSymbolText {
|
|
26
|
+
font: FontInfo;
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
metrics: TextMetrics;
|
|
30
|
+
}
|
|
31
|
+
/** Match explicit leading faces, not a guess about which fallback face supplied a glyph. */
|
|
32
|
+
export declare function chordKerningProfile(font: FontInfo, custom?: ChordSymbolKerningProfile): ChordSymbolKerningProfile | undefined;
|
|
33
|
+
/** Rebuild positions on every format pass. No accumulated shifts or separate SVG-only corrections. */
|
|
34
|
+
export declare function layoutChordRuns(blocks: readonly ChordSymbolText[], font: FontInfo, profile: ChordSymbolKerningProfile, options: {
|
|
35
|
+
spacing: number;
|
|
36
|
+
ratio: number;
|
|
37
|
+
superscript: number;
|
|
38
|
+
subscript: number;
|
|
39
|
+
}, measure: (text: string, font: FontInfo) => TextMetrics): {
|
|
40
|
+
runs: ChordSymbolRun[];
|
|
41
|
+
width: number;
|
|
42
|
+
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { BoundingBox } from './boundingbox';
|
|
2
|
+
import { ChordSymbolKerningProfile, ChordSymbolRun } from './chordkerning';
|
|
2
3
|
import { Element } from './element';
|
|
3
4
|
import { Modifier } from './modifier';
|
|
4
5
|
import { ModifierContextState } from './modifiercontext';
|
|
6
|
+
export type { ChordSymbolKerningPair, ChordSymbolKerningProfile, ChordSymbolPosition } from './chordkerning';
|
|
5
7
|
export declare class ChordSymbolBlock extends Element {
|
|
6
8
|
symbolModifier: SymbolModifiers;
|
|
7
9
|
vAlign: boolean;
|
|
@@ -51,6 +53,22 @@ export declare class ChordSymbol extends Modifier {
|
|
|
51
53
|
protected horizontal: number;
|
|
52
54
|
protected vertical: number;
|
|
53
55
|
protected reportWidth: boolean;
|
|
56
|
+
/** Default rendering stays compatible; only a matching opt-in profile uses shaped runs. */
|
|
57
|
+
protected kerning: 'auto' | 'none';
|
|
58
|
+
protected kerningProfile?: ChordSymbolKerningProfile;
|
|
59
|
+
protected kernedRuns?: ChordSymbolRun[];
|
|
60
|
+
protected kerningMeasurement?: Element;
|
|
61
|
+
protected kerningOrigin: {
|
|
62
|
+
x: number;
|
|
63
|
+
y: number;
|
|
64
|
+
};
|
|
65
|
+
/** Select optical kerning. Format the score again after changing layout settings. */
|
|
66
|
+
setKerning(mode: 'auto' | 'none'): this;
|
|
67
|
+
getKerning(): 'auto' | 'none';
|
|
68
|
+
/** Replace the font-specific table for this chord only. Omit the profile to restore built-ins. */
|
|
69
|
+
setKerningProfile(profile?: ChordSymbolKerningProfile): this;
|
|
70
|
+
/** Re-measure on every format pass; Element's shared cache handles font loading and reuse. */
|
|
71
|
+
protected formatKerning(): number | undefined;
|
|
54
72
|
constructor();
|
|
55
73
|
/**
|
|
56
74
|
* The offset is specified in `em`. Scale this value by the font size in pixels.
|
|
@@ -105,5 +123,6 @@ export declare class ChordSymbol extends Modifier {
|
|
|
105
123
|
getHorizontal(): number;
|
|
106
124
|
/** Render text and glyphs above/below the note. */
|
|
107
125
|
draw(): void;
|
|
126
|
+
/** Return fresh ink bounds, including script offsets and overhangs. Empty symbols have empty bounds. */
|
|
108
127
|
getBoundingBox(): BoundingBox;
|
|
109
128
|
}
|
|
@@ -73,6 +73,8 @@ export declare class Element {
|
|
|
73
73
|
/** Canvas used to measure text. See measureText(): TextMetrics. */
|
|
74
74
|
private static txtCanvas?;
|
|
75
75
|
static setTextMeasurementCanvas(canvas: HTMLCanvasElement | OffscreenCanvas): void;
|
|
76
|
+
/** Clear shared measurements after external font registration or custom context changes. */
|
|
77
|
+
static clearTextMeasurementCache(): void;
|
|
76
78
|
static getTextMeasurementCanvas(): HTMLCanvasElement | OffscreenCanvas | undefined;
|
|
77
79
|
private context?;
|
|
78
80
|
protected attrs: ElementAttributes;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type MeasurementContext = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
|
|
2
|
+
/** Internal cache shared by Element.measureText() and Element.measureWidth(). */
|
|
3
|
+
export declare class TextMetricsCache {
|
|
4
|
+
private static readonly maxEntries;
|
|
5
|
+
private static readonly maxKeyLength;
|
|
6
|
+
private static entries;
|
|
7
|
+
private static context?;
|
|
8
|
+
private static fonts?;
|
|
9
|
+
private static fontCount?;
|
|
10
|
+
private static fontStatus?;
|
|
11
|
+
private static readonly onFontsChanged;
|
|
12
|
+
/** Also used by Metrics.clear() and explicit canvas/font replacement. */
|
|
13
|
+
static clear(): void;
|
|
14
|
+
/** Track document/worker fonts without retaining listeners on a replaced document. */
|
|
15
|
+
private static fontsReady;
|
|
16
|
+
/** Preserve all TextMetrics fields, which are prototype getters in browsers. */
|
|
17
|
+
private static snapshot;
|
|
18
|
+
/** Key shaping and bounds settings as well as font/text; never cache fallback during loading. */
|
|
19
|
+
static measure(context: MeasurementContext, text: string): Readonly<TextMetrics>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
package/changelog/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
# 5.1.2
|
|
2
|
+
|
|
3
|
+
## Notation
|
|
4
|
+
|
|
5
|
+
- Add opt-in chord-symbol kerning for Academico/Bravura and Petaluma Script/Petaluma.
|
|
6
|
+
- Support custom kerning profiles with shared Canvas/SVG positioning and stable script bounds.
|
|
7
|
+
- Add an Explorer comparison for chord kerning.
|
|
8
|
+
|
|
9
|
+
## Testing and deployment
|
|
10
|
+
|
|
11
|
+
- Add `npm run tests:upload` to publish the complete visual test gallery to `vexflow.com/tests/`.
|
|
12
|
+
- Bundle QUnit, the test library, source maps, and fonts with no runtime CDN dependency.
|
|
13
|
+
- Share the Explorer's verified upload path, immutable assets, and short HTML cache.
|
|
14
|
+
- Test the standalone gallery, filtering, and deployment behavior in CI.
|
|
15
|
+
|
|
16
|
+
## Security and tooling
|
|
17
|
+
|
|
18
|
+
- Update development dependencies and remove vulnerable transitive packages.
|
|
19
|
+
- Use argument arrays for release commands and reject invalid version inputs.
|
|
20
|
+
- Render uploaded font metadata as text instead of HTML.
|
|
21
|
+
- Update CI actions and pin Node 26.13.1. Use read-only permissions and audit dependencies in CI.
|
|
22
|
+
|
|
23
|
+
# 5.1.1
|
|
24
|
+
|
|
25
|
+
## Fixes and performance
|
|
26
|
+
|
|
27
|
+
- Cache repeated text measurements with bounded storage and clear cached metrics when fonts change.
|
|
28
|
+
- Keep copied metrics and styles independent without deep-cloning unrelated state.
|
|
29
|
+
- Document UTF-8 encoding in the HTML setup example.
|
|
30
|
+
|
|
31
|
+
## Explorer
|
|
32
|
+
|
|
33
|
+
- Use a compact layout with an 80% preview and the inspector beside the score.
|
|
34
|
+
- Add locally bundled CodeJar editing and Prism syntax highlighting.
|
|
35
|
+
- Format all examples consistently and add explanatory comments.
|
|
36
|
+
- Fix the keyboard shortcut regression test and isolate browser state between tests.
|
|
37
|
+
|
|
1
38
|
# 5.1.0
|
|
2
39
|
|
|
3
40
|
## Features
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vexflow",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.2",
|
|
4
4
|
"description": "A JavaScript library for rendering music notation and guitar tablature.",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -86,19 +86,19 @@
|
|
|
86
86
|
"@vexflow-fonts/sebastiantext": "^1.0.0",
|
|
87
87
|
"canvas": "3.2.3",
|
|
88
88
|
"circular-dependency-plugin": "^5.2.2",
|
|
89
|
+
"codejar": "5.0.0",
|
|
89
90
|
"concurrently": "^9.1.2",
|
|
90
91
|
"eslint": "^9.28.0",
|
|
91
92
|
"eslint-config-prettier": "^10.1.5",
|
|
92
93
|
"eslint-plugin-import": "^2.31.0",
|
|
93
94
|
"eslint-plugin-prettier": "^5.4.1",
|
|
94
95
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
95
|
-
"fork-ts-checker-webpack-plugin": "^9.1.0",
|
|
96
96
|
"globals": "^16.2.0",
|
|
97
97
|
"grunt": "^1.6.1",
|
|
98
98
|
"grunt-cli": "^1.5.0",
|
|
99
99
|
"grunt-contrib-clean": "^2.0.1",
|
|
100
100
|
"grunt-contrib-copy": "^1.0.0",
|
|
101
|
-
"grunt-contrib-qunit": "
|
|
101
|
+
"grunt-contrib-qunit": "11.0.0",
|
|
102
102
|
"grunt-eslint": "^25.0.0",
|
|
103
103
|
"grunt-webpack": "^7.0.0",
|
|
104
104
|
"jsdom": "^26.1.0",
|
|
@@ -106,10 +106,11 @@
|
|
|
106
106
|
"opener": "^1.5.2",
|
|
107
107
|
"opentype.js": "^1.3.4",
|
|
108
108
|
"prettier": "^3.5.3",
|
|
109
|
-
"
|
|
109
|
+
"prismjs": "1.30.0",
|
|
110
|
+
"puppeteer": "25.17.0",
|
|
110
111
|
"qunit": "^2.24.1",
|
|
111
112
|
"recursive-copy": "^2.0.14",
|
|
112
|
-
"release-it": "
|
|
113
|
+
"release-it": "21.1.2",
|
|
113
114
|
"string-replace-loader": "^3.1.0",
|
|
114
115
|
"svg2pdf.js": "^2.5.0",
|
|
115
116
|
"terser-webpack-plugin": "^5.3.14",
|
|
@@ -131,7 +132,10 @@
|
|
|
131
132
|
"explorer": "node tools/explorer/cli.mjs serve",
|
|
132
133
|
"explorer:build": "node tools/explorer/cli.mjs build",
|
|
133
134
|
"explorer:test": "node tools/explorer/test.mjs",
|
|
134
|
-
"explorer:upload": "node tools/explorer/upload.mjs"
|
|
135
|
+
"explorer:upload": "node tools/explorer/upload.mjs",
|
|
136
|
+
"tests:build": "node tools/tests-site.mjs build",
|
|
137
|
+
"tests:upload": "node tools/tests-site.mjs upload",
|
|
138
|
+
"tests:test": "node tools/tests-site.test.mjs"
|
|
135
139
|
},
|
|
136
140
|
"homepage": "https://vexflow.com/",
|
|
137
141
|
"keywords": [
|
|
@@ -145,9 +149,14 @@
|
|
|
145
149
|
"structured-clone-es": "^1.0.0"
|
|
146
150
|
},
|
|
147
151
|
"overrides": {
|
|
148
|
-
"undici": "6.23.0",
|
|
149
152
|
"concurrently": {
|
|
150
153
|
"shell-quote": "1.11.0"
|
|
154
|
+
},
|
|
155
|
+
"@typescript-eslint/typescript-estree": {
|
|
156
|
+
"minimatch": "11.0.7"
|
|
157
|
+
},
|
|
158
|
+
"get-uri": {
|
|
159
|
+
"basic-ftp": "6.2.6"
|
|
151
160
|
}
|
|
152
161
|
}
|
|
153
162
|
}
|
package/tests/flow.html
CHANGED
|
@@ -124,14 +124,16 @@
|
|
|
124
124
|
// When flow.html is hosted on unpkg.com, the query string is not available.
|
|
125
125
|
// Allow the user to specify params via the # fragment identifier.
|
|
126
126
|
const hashParams = new URLSearchParams(location.hash.substr(1));
|
|
127
|
+
// Static deployments supply a local, fingerprinted bundle. Keep all test filters available.
|
|
128
|
+
const bundledSource = document.querySelector('meta[name="vexflow-test-bundle"]')?.content;
|
|
127
129
|
|
|
128
130
|
// Optional: Specify the QUnit module or filter in the query params or fragment identifier.
|
|
129
131
|
let QUnitModule = queryParams.get('module') ?? hashParams.get('module');
|
|
130
132
|
let QUnitFilter = queryParams.get('filter') ?? hashParams.get('filter');
|
|
131
133
|
|
|
132
134
|
// The `ver` query param chooses which VexFlow version to load. If omitted, `ver` defaults to 'build'.
|
|
133
|
-
const ver = queryParams.get('ver') ?? hashParams.get('ver') ?? 'build';
|
|
134
|
-
let useESM = queryParams.get('esm') === 'true' || hashParams.get('esm') === 'true';
|
|
135
|
+
const ver = bundledSource ? 'bundled build' : (queryParams.get('ver') ?? hashParams.get('ver') ?? 'build');
|
|
136
|
+
let useESM = !bundledSource && (queryParams.get('esm') === 'true' || hashParams.get('esm') === 'true');
|
|
135
137
|
const isFileProtocol = location.protocol === 'file:';
|
|
136
138
|
|
|
137
139
|
// Determine if we are loading VexFlow from a CDN.
|
|
@@ -148,7 +150,9 @@
|
|
|
148
150
|
const pathCJSorESM = (useESM ? 'esm/entry' : 'cjs') + '/vexflow-debug-with-tests.js';
|
|
149
151
|
|
|
150
152
|
let vexPlusTestsURL;
|
|
151
|
-
if (
|
|
153
|
+
if (bundledSource) {
|
|
154
|
+
vexPlusTestsURL = bundledSource;
|
|
155
|
+
} else if (useCDN) {
|
|
152
156
|
// `ver` can specify a version hosted on the unpkg.com / jsdelivr.com CDN. We only support VexFlow 4 or newer:
|
|
153
157
|
// ver=unpkg@4.2.3 => https://unpkg.com/vexflow@4.2.3/build/cjs/vexflow-debug-with-tests.js
|
|
154
158
|
// ver=unpkg@alpha => https://unpkg.com/vexflow@alpha/build/cjs/vexflow-debug-with-tests.js
|
|
@@ -182,11 +186,14 @@
|
|
|
182
186
|
};
|
|
183
187
|
}
|
|
184
188
|
|
|
189
|
+
// Load deployed faces before tests measure them, even when the preload spans are empty.
|
|
190
|
+
if (bundledSource) await Promise.all([...document.fonts].map((face) => face.load()));
|
|
185
191
|
const fontFaceSet = await document.fonts.ready;
|
|
186
192
|
|
|
187
193
|
showFontLoadingStatus();
|
|
188
194
|
|
|
189
195
|
const VF = await loadVexFlow();
|
|
196
|
+
if (bundledSource) await document.fonts.ready;
|
|
190
197
|
|
|
191
198
|
// If you did not load the fonts via the div#font-preload above, you can load them with this API:
|
|
192
199
|
// await VF.loadFonts(); // Load all web fonts that VexFlow knows about (Font.FILES).
|