@dsebastien/music-notation 0.20.0 → 0.21.0
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 +1 -1
- package/dist/blocks/renderers.d.ts +6 -0
- package/dist/index.js +310 -8
- package/dist/index.js.map +11 -10
- package/dist/music-notation.css +51 -2
- package/dist/music-notation.publish.min.js +84 -35
- package/dist/music-notation.tab.min.js +58 -9
- package/dist/playback/controls.d.ts +5 -0
- package/dist/playback/copy-image.d.ts +6 -2
- package/dist/playback/full-screen.d.ts +52 -0
- package/dist/publish/index.js +262 -7
- package/dist/publish/index.js.map +12 -11
- package/dist/tab/auto.d.ts +11 -1
- package/dist/tab/index.js +172 -6
- package/dist/tab/index.js.map +6 -5
- package/dist/tab/score-fit.d.ts +18 -0
- package/package.json +1 -1
- package/dist/tab/full-screen.d.ts +0 -19
package/dist/publish/index.js
CHANGED
|
@@ -6135,6 +6135,242 @@ async function toPng(el, options = {}) {
|
|
|
6135
6135
|
return new Promise((resolve, reject) => canvas.toBlob((blob) => blob ? resolve(blob) : reject(new Error("The image could not be made")), "image/png"));
|
|
6136
6136
|
}
|
|
6137
6137
|
|
|
6138
|
+
// src/playback/full-screen.ts
|
|
6139
|
+
var SCROLL_KEYS = new Set(["PageUp", "PageDown", "Home", "End", "ArrowUp", "ArrowDown"]);
|
|
6140
|
+
function backgroundBehind(el) {
|
|
6141
|
+
const win = el.ownerDocument.defaultView;
|
|
6142
|
+
if (!win)
|
|
6143
|
+
return "";
|
|
6144
|
+
for (let node = el.parentElement;node; node = node.parentElement) {
|
|
6145
|
+
const color = win.getComputedStyle(node).backgroundColor;
|
|
6146
|
+
if (color && color !== "transparent" && !/^rgba\(.*,\s*0\)$/.test(color))
|
|
6147
|
+
return color;
|
|
6148
|
+
}
|
|
6149
|
+
return "";
|
|
6150
|
+
}
|
|
6151
|
+
function fullScreenControl(doc, block, surface, follow = () => {}, options = {}) {
|
|
6152
|
+
const redraws = options.redraws !== false;
|
|
6153
|
+
const win = doc.defaultView;
|
|
6154
|
+
const button = iconButton(doc, "mn-tab-full", "Full screen", "full");
|
|
6155
|
+
button.classList.add("mn-play-full");
|
|
6156
|
+
let on = false;
|
|
6157
|
+
let browser = false;
|
|
6158
|
+
let following = false;
|
|
6159
|
+
let before = null;
|
|
6160
|
+
let place = null;
|
|
6161
|
+
let held = false;
|
|
6162
|
+
let ownMinHeight = "";
|
|
6163
|
+
const setFollow = (yes) => {
|
|
6164
|
+
if (following === yes)
|
|
6165
|
+
return;
|
|
6166
|
+
following = yes;
|
|
6167
|
+
follow(yes);
|
|
6168
|
+
};
|
|
6169
|
+
const show = () => {
|
|
6170
|
+
block.classList.toggle("mn-fullscreen", on);
|
|
6171
|
+
button.classList.toggle("mn-on", on);
|
|
6172
|
+
button.setAttribute("aria-pressed", String(on));
|
|
6173
|
+
button.title = on ? "Exit full screen" : "Full screen";
|
|
6174
|
+
button.replaceChildren(icon(doc, on ? "exit" : "full"));
|
|
6175
|
+
};
|
|
6176
|
+
const enter = () => {
|
|
6177
|
+
if (on)
|
|
6178
|
+
return;
|
|
6179
|
+
on = true;
|
|
6180
|
+
before = {
|
|
6181
|
+
x: win?.scrollX ?? 0,
|
|
6182
|
+
y: win?.scrollY ?? 0,
|
|
6183
|
+
background: block.style.backgroundColor
|
|
6184
|
+
};
|
|
6185
|
+
if (!held)
|
|
6186
|
+
ownMinHeight = block.style.minHeight;
|
|
6187
|
+
held = false;
|
|
6188
|
+
place = doc.createElement("div");
|
|
6189
|
+
place.className = "mn-fullscreen-place";
|
|
6190
|
+
place.style.height = `${block.offsetHeight}px`;
|
|
6191
|
+
const margins = win?.getComputedStyle(block);
|
|
6192
|
+
if (margins) {
|
|
6193
|
+
place.style.marginTop = margins.marginTop;
|
|
6194
|
+
place.style.marginBottom = margins.marginBottom;
|
|
6195
|
+
}
|
|
6196
|
+
block.before(place);
|
|
6197
|
+
const background = backgroundBehind(block);
|
|
6198
|
+
if (background)
|
|
6199
|
+
block.style.backgroundColor = background;
|
|
6200
|
+
show();
|
|
6201
|
+
surface.tabIndex = 0;
|
|
6202
|
+
surface.focus({ preventScroll: true });
|
|
6203
|
+
setFollow(true);
|
|
6204
|
+
options.changed?.(true);
|
|
6205
|
+
try {
|
|
6206
|
+
block.requestFullscreen?.().catch(() => {});
|
|
6207
|
+
} catch {}
|
|
6208
|
+
};
|
|
6209
|
+
const leave = (focus = true) => {
|
|
6210
|
+
if (!on)
|
|
6211
|
+
return;
|
|
6212
|
+
on = false;
|
|
6213
|
+
setFollow(false);
|
|
6214
|
+
show();
|
|
6215
|
+
block.style.backgroundColor = before?.background ?? "";
|
|
6216
|
+
if (place) {
|
|
6217
|
+
if (redraws) {
|
|
6218
|
+
block.style.minHeight = place.style.height;
|
|
6219
|
+
held = true;
|
|
6220
|
+
}
|
|
6221
|
+
place.remove();
|
|
6222
|
+
place = null;
|
|
6223
|
+
}
|
|
6224
|
+
surface.removeAttribute("tabindex");
|
|
6225
|
+
surface.scrollTop = 0;
|
|
6226
|
+
if (browser && doc.fullscreenElement === block)
|
|
6227
|
+
doc.exitFullscreen?.().catch(() => {});
|
|
6228
|
+
browser = false;
|
|
6229
|
+
if (before && win)
|
|
6230
|
+
win.scrollTo(before.x, before.y);
|
|
6231
|
+
before = null;
|
|
6232
|
+
options.changed?.(false);
|
|
6233
|
+
if (focus)
|
|
6234
|
+
button.focus({ preventScroll: true });
|
|
6235
|
+
};
|
|
6236
|
+
button.addEventListener("click", () => on ? leave() : enter());
|
|
6237
|
+
block.addEventListener("keydown", (event) => {
|
|
6238
|
+
if (!on || event.key !== "Escape")
|
|
6239
|
+
return;
|
|
6240
|
+
event.stopPropagation();
|
|
6241
|
+
event.preventDefault();
|
|
6242
|
+
leave();
|
|
6243
|
+
});
|
|
6244
|
+
const byHand = () => {
|
|
6245
|
+
if (on)
|
|
6246
|
+
setFollow(false);
|
|
6247
|
+
};
|
|
6248
|
+
surface.addEventListener("wheel", byHand, { passive: true });
|
|
6249
|
+
surface.addEventListener("touchmove", byHand, { passive: true });
|
|
6250
|
+
surface.addEventListener("keydown", (event) => {
|
|
6251
|
+
if (SCROLL_KEYS.has(event.key))
|
|
6252
|
+
byHand();
|
|
6253
|
+
});
|
|
6254
|
+
const space = (event) => {
|
|
6255
|
+
if (!on || event.key !== " " || event.ctrlKey || event.metaKey || event.altKey)
|
|
6256
|
+
return;
|
|
6257
|
+
if (!block.isConnected) {
|
|
6258
|
+
leave(false);
|
|
6259
|
+
return;
|
|
6260
|
+
}
|
|
6261
|
+
const target = event.target;
|
|
6262
|
+
if (target?.closest("input:not([type=range]), textarea, select, [contenteditable=true]"))
|
|
6263
|
+
return;
|
|
6264
|
+
event.preventDefault();
|
|
6265
|
+
event.stopPropagation();
|
|
6266
|
+
if (event.type !== "keydown" || event.repeat)
|
|
6267
|
+
return;
|
|
6268
|
+
block.querySelector(".mn-play .mn-play-toggle")?.click();
|
|
6269
|
+
};
|
|
6270
|
+
doc.addEventListener("keydown", space, true);
|
|
6271
|
+
doc.addEventListener("keyup", space, true);
|
|
6272
|
+
const changed = () => {
|
|
6273
|
+
if (doc.fullscreenElement === block)
|
|
6274
|
+
browser = true;
|
|
6275
|
+
else if (browser)
|
|
6276
|
+
leave();
|
|
6277
|
+
};
|
|
6278
|
+
doc.addEventListener("fullscreenchange", changed);
|
|
6279
|
+
show();
|
|
6280
|
+
return {
|
|
6281
|
+
button,
|
|
6282
|
+
active: () => on,
|
|
6283
|
+
playing: () => {
|
|
6284
|
+
if (on)
|
|
6285
|
+
setFollow(true);
|
|
6286
|
+
},
|
|
6287
|
+
drawn: () => {
|
|
6288
|
+
if (on || !held)
|
|
6289
|
+
return;
|
|
6290
|
+
held = false;
|
|
6291
|
+
block.style.minHeight = ownMinHeight;
|
|
6292
|
+
},
|
|
6293
|
+
destroy: () => {
|
|
6294
|
+
leave(false);
|
|
6295
|
+
doc.removeEventListener("fullscreenchange", changed);
|
|
6296
|
+
doc.removeEventListener("keydown", space, true);
|
|
6297
|
+
doc.removeEventListener("keyup", space, true);
|
|
6298
|
+
}
|
|
6299
|
+
};
|
|
6300
|
+
}
|
|
6301
|
+
var ZOOMS = [4, 3.5, 3, 2.5, 2.25, 2, 1.75, 1.5, 1.25, 1];
|
|
6302
|
+
var TALL_ZOOM = 1.5;
|
|
6303
|
+
function chooseZoom(fits) {
|
|
6304
|
+
const wide = [];
|
|
6305
|
+
for (const zoom of ZOOMS) {
|
|
6306
|
+
const fit = fits(zoom);
|
|
6307
|
+
if (fit.width && fit.height)
|
|
6308
|
+
return zoom;
|
|
6309
|
+
if (fit.width)
|
|
6310
|
+
wide.push(zoom);
|
|
6311
|
+
}
|
|
6312
|
+
return wide.find((zoom) => zoom <= TALL_ZOOM) ?? 1;
|
|
6313
|
+
}
|
|
6314
|
+
function blockFullScreen(doc, block) {
|
|
6315
|
+
const win = doc.defaultView;
|
|
6316
|
+
let frame = 0;
|
|
6317
|
+
const fit = () => {
|
|
6318
|
+
frame = 0;
|
|
6319
|
+
if (!block.classList.contains("mn-fullscreen"))
|
|
6320
|
+
return;
|
|
6321
|
+
const zoom = chooseZoom((z) => {
|
|
6322
|
+
block.style.setProperty("--mn-zoom", String(z));
|
|
6323
|
+
return {
|
|
6324
|
+
width: block.scrollWidth <= block.clientWidth + 1,
|
|
6325
|
+
height: block.scrollHeight <= block.clientHeight + 1
|
|
6326
|
+
};
|
|
6327
|
+
});
|
|
6328
|
+
block.style.setProperty("--mn-zoom", String(zoom));
|
|
6329
|
+
for (const bar of nested())
|
|
6330
|
+
bar.style.setProperty("zoom", String(1 / zoom));
|
|
6331
|
+
};
|
|
6332
|
+
const nested = () => [
|
|
6333
|
+
...block.querySelectorAll(":scope > :not(.mn-play) .mn-play")
|
|
6334
|
+
];
|
|
6335
|
+
const later = () => {
|
|
6336
|
+
if (!win || frame)
|
|
6337
|
+
return;
|
|
6338
|
+
frame = win.requestAnimationFrame(fit);
|
|
6339
|
+
};
|
|
6340
|
+
const control = fullScreenControl(doc, block, block, undefined, {
|
|
6341
|
+
redraws: false,
|
|
6342
|
+
changed: (on) => {
|
|
6343
|
+
block.classList.toggle("mn-fullscreen-fit", on);
|
|
6344
|
+
if (on) {
|
|
6345
|
+
fit();
|
|
6346
|
+
later();
|
|
6347
|
+
win?.addEventListener("resize", later);
|
|
6348
|
+
} else {
|
|
6349
|
+
win?.removeEventListener("resize", later);
|
|
6350
|
+
block.style.removeProperty("--mn-zoom");
|
|
6351
|
+
for (const bar of nested())
|
|
6352
|
+
bar.style.removeProperty("zoom");
|
|
6353
|
+
}
|
|
6354
|
+
}
|
|
6355
|
+
});
|
|
6356
|
+
return {
|
|
6357
|
+
...control,
|
|
6358
|
+
destroy: () => {
|
|
6359
|
+
control.destroy();
|
|
6360
|
+
win?.removeEventListener("resize", later);
|
|
6361
|
+
if (frame)
|
|
6362
|
+
win?.cancelAnimationFrame(frame);
|
|
6363
|
+
}
|
|
6364
|
+
};
|
|
6365
|
+
}
|
|
6366
|
+
function addFullScreen(doc, bar, block, on = true) {
|
|
6367
|
+
if (!on || !block || block.querySelector(".mn-play-full"))
|
|
6368
|
+
return () => {};
|
|
6369
|
+
const full = blockFullScreen(doc, block);
|
|
6370
|
+
bar.appendChild(full.button);
|
|
6371
|
+
return () => full.destroy();
|
|
6372
|
+
}
|
|
6373
|
+
|
|
6138
6374
|
// src/playback/copy-image.ts
|
|
6139
6375
|
var COPY_SAID = {
|
|
6140
6376
|
copied: "Copied",
|
|
@@ -6192,13 +6428,16 @@ function copyImageButton(doc, win, target, make = (el) => toPng(el)) {
|
|
|
6192
6428
|
return [button, said];
|
|
6193
6429
|
}
|
|
6194
6430
|
var NOT_DRAWN_HERE = ".mn-tab, .mn-tab-holder, .mn-tab-surface, .mn-exercise-tab";
|
|
6195
|
-
function attachCopy(el, make) {
|
|
6431
|
+
function attachCopy(el, make, options = {}) {
|
|
6196
6432
|
const doc = el.ownerDocument;
|
|
6197
6433
|
const win = doc.defaultView;
|
|
6198
6434
|
if (!win)
|
|
6199
6435
|
return () => {};
|
|
6200
6436
|
const blocks = el.classList.contains("mn-block") ? [el] : [...el.querySelectorAll(".mn-block")];
|
|
6201
6437
|
const bars = [];
|
|
6438
|
+
const frees = [];
|
|
6439
|
+
if (options.copy === false && options.fullScreen === false)
|
|
6440
|
+
return () => {};
|
|
6202
6441
|
for (const block of blocks) {
|
|
6203
6442
|
if (block.querySelector(".mn-play"))
|
|
6204
6443
|
continue;
|
|
@@ -6207,7 +6446,9 @@ function attachCopy(el, make) {
|
|
|
6207
6446
|
if (!drawings.length && !timed)
|
|
6208
6447
|
continue;
|
|
6209
6448
|
const bar = playBar(doc, "mn-copy-bar", "Image");
|
|
6210
|
-
|
|
6449
|
+
if (options.copy !== false)
|
|
6450
|
+
bar.append(...copyImageButton(doc, win, () => block, make));
|
|
6451
|
+
frees.push(addFullScreen(doc, bar, block, options.fullScreen));
|
|
6211
6452
|
if (timed)
|
|
6212
6453
|
block.appendChild(bar);
|
|
6213
6454
|
else
|
|
@@ -6215,6 +6456,8 @@ function attachCopy(el, make) {
|
|
|
6215
6456
|
bars.push(bar);
|
|
6216
6457
|
}
|
|
6217
6458
|
return () => {
|
|
6459
|
+
for (const free of frees)
|
|
6460
|
+
free();
|
|
6218
6461
|
for (const bar of bars)
|
|
6219
6462
|
bar.remove();
|
|
6220
6463
|
};
|
|
@@ -6371,6 +6614,7 @@ function timedBarFor(doc, win, drawing, options, piece) {
|
|
|
6371
6614
|
bar.appendChild(choice(doc, "mn-play-sound", "Sound", ["guitar", "piano"], settings.sound, { guitar: "Guitar", piano: "Piano" }, (value) => settings.sound = value === "piano" ? "piano" : "guitar"));
|
|
6372
6615
|
if (options.copy !== false)
|
|
6373
6616
|
bar.append(...copyImageButton(doc, win, () => wrap.closest(".mn-block") ?? wrap));
|
|
6617
|
+
const freeFull = addFullScreen(doc, bar, wrap.closest(".mn-block"), options.fullScreen);
|
|
6374
6618
|
const app = handToApp(options, bar, {
|
|
6375
6619
|
kind: piece.kind,
|
|
6376
6620
|
drawing,
|
|
@@ -6379,6 +6623,7 @@ function timedBarFor(doc, win, drawing, options, piece) {
|
|
|
6379
6623
|
});
|
|
6380
6624
|
return () => {
|
|
6381
6625
|
stop();
|
|
6626
|
+
freeFull();
|
|
6382
6627
|
app.free();
|
|
6383
6628
|
};
|
|
6384
6629
|
}
|
|
@@ -6529,6 +6774,7 @@ function progressionBarFor(doc, win, drawing, options, diagrams = null) {
|
|
|
6529
6774
|
}));
|
|
6530
6775
|
if (options.copy !== false)
|
|
6531
6776
|
bar.append(...copyImageButton(doc, win, () => drawing.closest(".mn-block") ?? drawing));
|
|
6777
|
+
const freeFull = addFullScreen(doc, bar, drawing.closest(".mn-block"), options.fullScreen);
|
|
6532
6778
|
const app = handToApp(options, bar, {
|
|
6533
6779
|
kind: drawing.classList.contains("mn-chart") ? "chart" : "progression",
|
|
6534
6780
|
drawing,
|
|
@@ -6537,6 +6783,7 @@ function progressionBarFor(doc, win, drawing, options, diagrams = null) {
|
|
|
6537
6783
|
});
|
|
6538
6784
|
return () => {
|
|
6539
6785
|
stop();
|
|
6786
|
+
freeFull();
|
|
6540
6787
|
if (diagrams?.onPlay === stop) {
|
|
6541
6788
|
diagrams.onPlay = null;
|
|
6542
6789
|
diagrams.stopOthers = null;
|
|
@@ -7432,6 +7679,7 @@ function blockBarFor(doc, win, block, diagrams, options) {
|
|
|
7432
7679
|
bar.appendChild(sound);
|
|
7433
7680
|
if (options.copy !== false)
|
|
7434
7681
|
bar.append(...copyImageButton(doc, win, (whole) => whole || !several ? block : diagramImage(made.selected.wrap)));
|
|
7682
|
+
const freeFull = addFullScreen(doc, bar, block, options.fullScreen);
|
|
7435
7683
|
bind({
|
|
7436
7684
|
changed() {
|
|
7437
7685
|
const busy = made.busy;
|
|
@@ -7452,7 +7700,10 @@ function blockBarFor(doc, win, block, diagrams, options) {
|
|
|
7452
7700
|
sound.value = made.sound;
|
|
7453
7701
|
}
|
|
7454
7702
|
});
|
|
7455
|
-
return () =>
|
|
7703
|
+
return () => {
|
|
7704
|
+
freeFull();
|
|
7705
|
+
group.destroy();
|
|
7706
|
+
};
|
|
7456
7707
|
}
|
|
7457
7708
|
|
|
7458
7709
|
// src/playback/controls.ts
|
|
@@ -12492,11 +12743,13 @@ function renderBlock(language, source, host, given = {}) {
|
|
|
12492
12743
|
}
|
|
12493
12744
|
const picks = options.pick ? [...el.querySelectorAll("svg[data-mn-pick]")].map((svg) => attachPick(svg, pickOptions(options))) : [];
|
|
12494
12745
|
const copy = options.copy !== false;
|
|
12746
|
+
const fullScreen = options.fullScreen !== false;
|
|
12495
12747
|
const stopPlayback = options.play ? attachPlayback(el, {
|
|
12496
12748
|
hand: options.hand,
|
|
12497
12749
|
...typeof options.play === "object" ? options.play : {},
|
|
12498
|
-
copy
|
|
12499
|
-
|
|
12750
|
+
copy,
|
|
12751
|
+
fullScreen
|
|
12752
|
+
}) : copy || fullScreen ? attachCopy(el, undefined, { copy, fullScreen }) : null;
|
|
12500
12753
|
return {
|
|
12501
12754
|
ok: error === null,
|
|
12502
12755
|
el,
|
|
@@ -13243,7 +13496,9 @@ function fingerprint(text) {
|
|
|
13243
13496
|
return `${text.length}:${hash.toString(36)}`;
|
|
13244
13497
|
}
|
|
13245
13498
|
var renderingOf = (pre) => {
|
|
13246
|
-
|
|
13499
|
+
let next = pre.nextElementSibling;
|
|
13500
|
+
if (next?.classList.contains("mn-fullscreen-place"))
|
|
13501
|
+
next = next.nextElementSibling;
|
|
13247
13502
|
return next?.classList.contains("mn-block") ? next : null;
|
|
13248
13503
|
};
|
|
13249
13504
|
function renderAll(root, options = {}) {
|
|
@@ -13311,5 +13566,5 @@ export {
|
|
|
13311
13566
|
renderAll
|
|
13312
13567
|
};
|
|
13313
13568
|
|
|
13314
|
-
//# debugId=
|
|
13569
|
+
//# debugId=03EC35FD01BDA81C64756E2164756E21
|
|
13315
13570
|
//# sourceMappingURL=index.js.map
|