@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/tab/auto.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* main thread (web workers can't start from another origin), and gives the diagrams a soundfont
|
|
6
6
|
* player of their own.
|
|
7
7
|
*/
|
|
8
|
-
import { type AlphaTabModule } from './index.js';
|
|
8
|
+
import { alphaTabCdn, createSoundfontPlayer, renderTab, type AlphaTabModule } from './index.js';
|
|
9
9
|
import { type NotePlayer } from '../playback/player.js';
|
|
10
10
|
declare global {
|
|
11
11
|
interface Window {
|
|
@@ -13,5 +13,15 @@ declare global {
|
|
|
13
13
|
musicNotationTabLoaded?: boolean;
|
|
14
14
|
musicNotationSoundfontPlayer?: NotePlayer;
|
|
15
15
|
musicNotationOptions?: unknown;
|
|
16
|
+
/**
|
|
17
|
+
* The tab bundle's API for a page's own scripts (the guide's Sounds page): draw a tab or
|
|
18
|
+
* a score with assets of its choice, make a soundfont player, load alphaTab from jsDelivr.
|
|
19
|
+
*/
|
|
20
|
+
MusicNotationTab?: {
|
|
21
|
+
renderTab: typeof renderTab;
|
|
22
|
+
createSoundfontPlayer: typeof createSoundfontPlayer;
|
|
23
|
+
loadAlphaTab: () => Promise<AlphaTabModule>;
|
|
24
|
+
alphaTabCdn: typeof alphaTabCdn;
|
|
25
|
+
};
|
|
16
26
|
}
|
|
17
27
|
}
|
package/dist/tab/index.js
CHANGED
|
@@ -1940,8 +1940,8 @@ function followVolume(read, handles, start) {
|
|
|
1940
1940
|
};
|
|
1941
1941
|
}
|
|
1942
1942
|
|
|
1943
|
-
// src/
|
|
1944
|
-
var SCROLL_KEYS = new Set(["PageUp", "PageDown", "Home", "End", "ArrowUp", "ArrowDown"
|
|
1943
|
+
// src/playback/full-screen.ts
|
|
1944
|
+
var SCROLL_KEYS = new Set(["PageUp", "PageDown", "Home", "End", "ArrowUp", "ArrowDown"]);
|
|
1945
1945
|
function backgroundBehind(el) {
|
|
1946
1946
|
const win = el.ownerDocument.defaultView;
|
|
1947
1947
|
if (!win)
|
|
@@ -1953,9 +1953,11 @@ function backgroundBehind(el) {
|
|
|
1953
1953
|
}
|
|
1954
1954
|
return "";
|
|
1955
1955
|
}
|
|
1956
|
-
function fullScreenControl(doc, block, surface, follow) {
|
|
1956
|
+
function fullScreenControl(doc, block, surface, follow = () => {}, options = {}) {
|
|
1957
|
+
const redraws = options.redraws !== false;
|
|
1957
1958
|
const win = doc.defaultView;
|
|
1958
1959
|
const button = iconButton(doc, "mn-tab-full", "Full screen", "full");
|
|
1960
|
+
button.classList.add("mn-play-full");
|
|
1959
1961
|
let on = false;
|
|
1960
1962
|
let browser = false;
|
|
1961
1963
|
let following = false;
|
|
@@ -2004,6 +2006,7 @@ function fullScreenControl(doc, block, surface, follow) {
|
|
|
2004
2006
|
surface.tabIndex = 0;
|
|
2005
2007
|
surface.focus({ preventScroll: true });
|
|
2006
2008
|
setFollow(true);
|
|
2009
|
+
options.changed?.(true);
|
|
2007
2010
|
try {
|
|
2008
2011
|
block.requestFullscreen?.().catch(() => {});
|
|
2009
2012
|
} catch {}
|
|
@@ -2016,8 +2019,10 @@ function fullScreenControl(doc, block, surface, follow) {
|
|
|
2016
2019
|
show();
|
|
2017
2020
|
block.style.backgroundColor = before?.background ?? "";
|
|
2018
2021
|
if (place) {
|
|
2019
|
-
|
|
2020
|
-
|
|
2022
|
+
if (redraws) {
|
|
2023
|
+
block.style.minHeight = place.style.height;
|
|
2024
|
+
held = true;
|
|
2025
|
+
}
|
|
2021
2026
|
place.remove();
|
|
2022
2027
|
place = null;
|
|
2023
2028
|
}
|
|
@@ -2029,6 +2034,7 @@ function fullScreenControl(doc, block, surface, follow) {
|
|
|
2029
2034
|
if (before && win)
|
|
2030
2035
|
win.scrollTo(before.x, before.y);
|
|
2031
2036
|
before = null;
|
|
2037
|
+
options.changed?.(false);
|
|
2032
2038
|
if (focus)
|
|
2033
2039
|
button.focus({ preventScroll: true });
|
|
2034
2040
|
};
|
|
@@ -2050,6 +2056,24 @@ function fullScreenControl(doc, block, surface, follow) {
|
|
|
2050
2056
|
if (SCROLL_KEYS.has(event.key))
|
|
2051
2057
|
byHand();
|
|
2052
2058
|
});
|
|
2059
|
+
const space = (event) => {
|
|
2060
|
+
if (!on || event.key !== " " || event.ctrlKey || event.metaKey || event.altKey)
|
|
2061
|
+
return;
|
|
2062
|
+
if (!block.isConnected) {
|
|
2063
|
+
leave(false);
|
|
2064
|
+
return;
|
|
2065
|
+
}
|
|
2066
|
+
const target = event.target;
|
|
2067
|
+
if (target?.closest("input:not([type=range]), textarea, select, [contenteditable=true]"))
|
|
2068
|
+
return;
|
|
2069
|
+
event.preventDefault();
|
|
2070
|
+
event.stopPropagation();
|
|
2071
|
+
if (event.type !== "keydown" || event.repeat)
|
|
2072
|
+
return;
|
|
2073
|
+
block.querySelector(".mn-play .mn-play-toggle")?.click();
|
|
2074
|
+
};
|
|
2075
|
+
doc.addEventListener("keydown", space, true);
|
|
2076
|
+
doc.addEventListener("keyup", space, true);
|
|
2053
2077
|
const changed = () => {
|
|
2054
2078
|
if (doc.fullscreenElement === block)
|
|
2055
2079
|
browser = true;
|
|
@@ -2074,6 +2098,122 @@ function fullScreenControl(doc, block, surface, follow) {
|
|
|
2074
2098
|
destroy: () => {
|
|
2075
2099
|
leave(false);
|
|
2076
2100
|
doc.removeEventListener("fullscreenchange", changed);
|
|
2101
|
+
doc.removeEventListener("keydown", space, true);
|
|
2102
|
+
doc.removeEventListener("keyup", space, true);
|
|
2103
|
+
}
|
|
2104
|
+
};
|
|
2105
|
+
}
|
|
2106
|
+
var ZOOMS = [4, 3.5, 3, 2.5, 2.25, 2, 1.75, 1.5, 1.25, 1];
|
|
2107
|
+
var TALL_ZOOM = 1.5;
|
|
2108
|
+
function chooseZoom(fits) {
|
|
2109
|
+
const wide = [];
|
|
2110
|
+
for (const zoom of ZOOMS) {
|
|
2111
|
+
const fit = fits(zoom);
|
|
2112
|
+
if (fit.width && fit.height)
|
|
2113
|
+
return zoom;
|
|
2114
|
+
if (fit.width)
|
|
2115
|
+
wide.push(zoom);
|
|
2116
|
+
}
|
|
2117
|
+
return wide.find((zoom) => zoom <= TALL_ZOOM) ?? 1;
|
|
2118
|
+
}
|
|
2119
|
+
function blockFullScreen(doc, block) {
|
|
2120
|
+
const win = doc.defaultView;
|
|
2121
|
+
let frame = 0;
|
|
2122
|
+
const fit = () => {
|
|
2123
|
+
frame = 0;
|
|
2124
|
+
if (!block.classList.contains("mn-fullscreen"))
|
|
2125
|
+
return;
|
|
2126
|
+
const zoom = chooseZoom((z) => {
|
|
2127
|
+
block.style.setProperty("--mn-zoom", String(z));
|
|
2128
|
+
return {
|
|
2129
|
+
width: block.scrollWidth <= block.clientWidth + 1,
|
|
2130
|
+
height: block.scrollHeight <= block.clientHeight + 1
|
|
2131
|
+
};
|
|
2132
|
+
});
|
|
2133
|
+
block.style.setProperty("--mn-zoom", String(zoom));
|
|
2134
|
+
for (const bar of nested())
|
|
2135
|
+
bar.style.setProperty("zoom", String(1 / zoom));
|
|
2136
|
+
};
|
|
2137
|
+
const nested = () => [
|
|
2138
|
+
...block.querySelectorAll(":scope > :not(.mn-play) .mn-play")
|
|
2139
|
+
];
|
|
2140
|
+
const later = () => {
|
|
2141
|
+
if (!win || frame)
|
|
2142
|
+
return;
|
|
2143
|
+
frame = win.requestAnimationFrame(fit);
|
|
2144
|
+
};
|
|
2145
|
+
const control = fullScreenControl(doc, block, block, undefined, {
|
|
2146
|
+
redraws: false,
|
|
2147
|
+
changed: (on) => {
|
|
2148
|
+
block.classList.toggle("mn-fullscreen-fit", on);
|
|
2149
|
+
if (on) {
|
|
2150
|
+
fit();
|
|
2151
|
+
later();
|
|
2152
|
+
win?.addEventListener("resize", later);
|
|
2153
|
+
} else {
|
|
2154
|
+
win?.removeEventListener("resize", later);
|
|
2155
|
+
block.style.removeProperty("--mn-zoom");
|
|
2156
|
+
for (const bar of nested())
|
|
2157
|
+
bar.style.removeProperty("zoom");
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
});
|
|
2161
|
+
return {
|
|
2162
|
+
...control,
|
|
2163
|
+
destroy: () => {
|
|
2164
|
+
control.destroy();
|
|
2165
|
+
win?.removeEventListener("resize", later);
|
|
2166
|
+
if (frame)
|
|
2167
|
+
win?.cancelAnimationFrame(frame);
|
|
2168
|
+
}
|
|
2169
|
+
};
|
|
2170
|
+
}
|
|
2171
|
+
function addFullScreen(doc, bar, block, on = true) {
|
|
2172
|
+
if (!on || !block || block.querySelector(".mn-play-full"))
|
|
2173
|
+
return () => {};
|
|
2174
|
+
const full = blockFullScreen(doc, block);
|
|
2175
|
+
bar.appendChild(full.button);
|
|
2176
|
+
return () => full.destroy();
|
|
2177
|
+
}
|
|
2178
|
+
|
|
2179
|
+
// src/tab/score-fit.ts
|
|
2180
|
+
var SCORE_SCALES = [1, 1.25, 1.5, 1.75, 2, 2.5, 3];
|
|
2181
|
+
function scoreFit(apply, fits) {
|
|
2182
|
+
let step = null;
|
|
2183
|
+
let back = false;
|
|
2184
|
+
const go = (to) => {
|
|
2185
|
+
step = to;
|
|
2186
|
+
apply(SCORE_SCALES[to], true);
|
|
2187
|
+
};
|
|
2188
|
+
return {
|
|
2189
|
+
enter() {
|
|
2190
|
+
back = false;
|
|
2191
|
+
go(0);
|
|
2192
|
+
},
|
|
2193
|
+
leave() {
|
|
2194
|
+
step = null;
|
|
2195
|
+
back = false;
|
|
2196
|
+
apply(1, false);
|
|
2197
|
+
},
|
|
2198
|
+
drawn() {
|
|
2199
|
+
if (step === null)
|
|
2200
|
+
return;
|
|
2201
|
+
if (back) {
|
|
2202
|
+
step = null;
|
|
2203
|
+
return;
|
|
2204
|
+
}
|
|
2205
|
+
if (fits()) {
|
|
2206
|
+
if (step + 1 < SCORE_SCALES.length)
|
|
2207
|
+
go(step + 1);
|
|
2208
|
+
else
|
|
2209
|
+
step = null;
|
|
2210
|
+
return;
|
|
2211
|
+
}
|
|
2212
|
+
if (step > 0) {
|
|
2213
|
+
back = true;
|
|
2214
|
+
go(step - 1);
|
|
2215
|
+
} else
|
|
2216
|
+
step = null;
|
|
2077
2217
|
}
|
|
2078
2218
|
};
|
|
2079
2219
|
}
|
|
@@ -2696,9 +2836,35 @@ function renderTab(language, source, host, options) {
|
|
|
2696
2836
|
current.render();
|
|
2697
2837
|
}, options.onKeepView));
|
|
2698
2838
|
if (options.fullScreen !== false) {
|
|
2839
|
+
let page = null;
|
|
2840
|
+
const fit = scoreFit((scale, stretch) => {
|
|
2841
|
+
const display = current.settings.display;
|
|
2842
|
+
if (gone || !display)
|
|
2843
|
+
return;
|
|
2844
|
+
page ??= {
|
|
2845
|
+
scale: display.scale,
|
|
2846
|
+
fill: display.lastSystemFillThreshold
|
|
2847
|
+
};
|
|
2848
|
+
display.scale = stretch ? scale : page.scale;
|
|
2849
|
+
display.lastSystemFillThreshold = stretch ? 0 : page.fill;
|
|
2850
|
+
current.updateSettings();
|
|
2851
|
+
current.render();
|
|
2852
|
+
}, () => surface.scrollHeight <= surface.clientHeight + 1);
|
|
2699
2853
|
const full = fullScreenControl(doc, el, surface, (on) => {
|
|
2700
2854
|
current.settings.player.scrollMode = on ? at.ScrollMode.OffScreen : at.ScrollMode.Off;
|
|
2701
2855
|
current.updateSettings();
|
|
2856
|
+
}, { changed: (on) => on ? fit.enter() : fit.leave() });
|
|
2857
|
+
current.postRenderFinished.on(() => {
|
|
2858
|
+
const area = surface.querySelector(".at-surface");
|
|
2859
|
+
if (area && full.active()) {
|
|
2860
|
+
const bottom = Math.max(0, ...[...area.children].map((part) => {
|
|
2861
|
+
const p = part;
|
|
2862
|
+
return p.offsetTop + p.offsetHeight;
|
|
2863
|
+
}));
|
|
2864
|
+
if (bottom > area.offsetHeight)
|
|
2865
|
+
area.style.height = `${bottom}px`;
|
|
2866
|
+
}
|
|
2867
|
+
fit.drawn();
|
|
2702
2868
|
});
|
|
2703
2869
|
current.playerStateChanged.on((e) => {
|
|
2704
2870
|
if (Number(e.state) === Number(at.synth.PlayerState.Playing))
|
|
@@ -2985,5 +3151,5 @@ export {
|
|
|
2985
3151
|
textTabToAlphaTex
|
|
2986
3152
|
};
|
|
2987
3153
|
|
|
2988
|
-
//# debugId=
|
|
3154
|
+
//# debugId=74AA16B9663E346964756E2164756E21
|
|
2989
3155
|
//# sourceMappingURL=index.js.map
|