@nodelyra/not-angka 0.0.0-stage → 0.1.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.
Files changed (251) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -2
  3. package/THIRD_PARTY.md +24 -0
  4. package/dist/esm/cursor/activeChord.d.ts +12 -0
  5. package/dist/esm/cursor/activeChord.js +36 -0
  6. package/dist/esm/cursor/beatDot.d.ts +30 -0
  7. package/dist/esm/cursor/beatDot.js +49 -0
  8. package/dist/esm/cursor/drawnTop.d.ts +9 -0
  9. package/dist/esm/cursor/drawnTop.js +16 -0
  10. package/dist/esm/cursor/pageBoxes.d.ts +28 -0
  11. package/dist/esm/cursor/pageBoxes.js +75 -0
  12. package/dist/esm/cursor/playbackCursor.d.ts +25 -0
  13. package/dist/esm/cursor/playbackCursor.js +42 -0
  14. package/dist/esm/cursor/playingStyle.d.ts +16 -0
  15. package/dist/esm/cursor/playingStyle.js +34 -0
  16. package/dist/esm/cursor/playingTones.d.ts +8 -0
  17. package/dist/esm/cursor/playingTones.js +16 -0
  18. package/dist/esm/cursor/target.d.ts +47 -0
  19. package/dist/esm/cursor/target.js +63 -0
  20. package/dist/esm/export/pageText.d.ts +8 -0
  21. package/dist/esm/export/pageText.js +80 -0
  22. package/dist/esm/export/svgExport.d.ts +46 -0
  23. package/dist/esm/export/svgExport.js +88 -0
  24. package/dist/esm/geometry/metrics.d.ts +42 -0
  25. package/dist/esm/geometry/metrics.js +52 -0
  26. package/dist/esm/geometry/pageSetup.d.ts +61 -0
  27. package/dist/esm/geometry/pageSetup.js +85 -0
  28. package/dist/esm/geometry/paper.d.ts +16 -0
  29. package/dist/esm/geometry/paper.js +16 -0
  30. package/dist/esm/index.d.ts +35 -0
  31. package/dist/esm/index.js +23 -0
  32. package/dist/esm/layout/LayoutEngine.d.ts +64 -0
  33. package/dist/esm/layout/LayoutEngine.js +92 -0
  34. package/dist/esm/layout/arcs.d.ts +20 -0
  35. package/dist/esm/layout/arcs.js +53 -0
  36. package/dist/esm/layout/barlineShapes.d.ts +52 -0
  37. package/dist/esm/layout/barlineShapes.js +71 -0
  38. package/dist/esm/layout/directions.d.ts +48 -0
  39. package/dist/esm/layout/directions.js +122 -0
  40. package/dist/esm/layout/elementBoxes.d.ts +17 -0
  41. package/dist/esm/layout/elementBoxes.js +72 -0
  42. package/dist/esm/layout/floating.d.ts +29 -0
  43. package/dist/esm/layout/floating.js +39 -0
  44. package/dist/esm/layout/keyMarks.d.ts +26 -0
  45. package/dist/esm/layout/keyMarks.js +30 -0
  46. package/dist/esm/layout/lyricAlign.d.ts +6 -0
  47. package/dist/esm/layout/lyricAlign.js +15 -0
  48. package/dist/esm/layout/lyricWords.d.ts +13 -0
  49. package/dist/esm/layout/lyricWords.js +27 -0
  50. package/dist/esm/layout/lyricsLayout.d.ts +55 -0
  51. package/dist/esm/layout/lyricsLayout.js +122 -0
  52. package/dist/esm/layout/markings.d.ts +97 -0
  53. package/dist/esm/layout/markings.js +150 -0
  54. package/dist/esm/layout/measurePlan.d.ts +74 -0
  55. package/dist/esm/layout/measurePlan.js +232 -0
  56. package/dist/esm/layout/measureSegments.d.ts +24 -0
  57. package/dist/esm/layout/measureSegments.js +64 -0
  58. package/dist/esm/layout/notationMetrics.d.ts +110 -0
  59. package/dist/esm/layout/notationMetrics.js +122 -0
  60. package/dist/esm/layout/systemBreaking.d.ts +59 -0
  61. package/dist/esm/layout/systemBreaking.js +137 -0
  62. package/dist/esm/layout/systemLayout.d.ts +138 -0
  63. package/dist/esm/layout/systemLayout.js +266 -0
  64. package/dist/esm/layout/tupletSpacing.d.ts +9 -0
  65. package/dist/esm/layout/tupletSpacing.js +33 -0
  66. package/dist/esm/layout/tuplets.d.ts +30 -0
  67. package/dist/esm/layout/tuplets.js +39 -0
  68. package/dist/esm/model/hiddenParts.d.ts +23 -0
  69. package/dist/esm/model/hiddenParts.js +39 -0
  70. package/dist/esm/model/locate.d.ts +18 -0
  71. package/dist/esm/model/locate.js +31 -0
  72. package/dist/esm/model/lowVoices.d.ts +9 -0
  73. package/dist/esm/model/lowVoices.js +20 -0
  74. package/dist/esm/model/partColors.d.ts +13 -0
  75. package/dist/esm/model/partColors.js +10 -0
  76. package/dist/esm/model/partSpan.d.ts +25 -0
  77. package/dist/esm/model/partSpan.js +49 -0
  78. package/dist/esm/model/rowPresence.d.ts +14 -0
  79. package/dist/esm/model/rowPresence.js +19 -0
  80. package/dist/esm/model/sharedLyrics.d.ts +23 -0
  81. package/dist/esm/model/sharedLyrics.js +68 -0
  82. package/dist/esm/model/textBars.d.ts +12 -0
  83. package/dist/esm/model/textBars.js +21 -0
  84. package/dist/esm/model/tickRanges.d.ts +22 -0
  85. package/dist/esm/model/tickRanges.js +34 -0
  86. package/dist/esm/model/unisons.d.ts +69 -0
  87. package/dist/esm/model/unisons.js +181 -0
  88. package/dist/esm/notation/chords.d.ts +12 -0
  89. package/dist/esm/notation/chords.js +29 -0
  90. package/dist/esm/notation/elision.d.ts +24 -0
  91. package/dist/esm/notation/elision.js +47 -0
  92. package/dist/esm/notation/keys.d.ts +50 -0
  93. package/dist/esm/notation/keys.js +59 -0
  94. package/dist/esm/notation/lyricAlign.d.ts +7 -0
  95. package/dist/esm/notation/lyricAlign.js +15 -0
  96. package/dist/esm/notation/navigation.d.ts +3 -0
  97. package/dist/esm/notation/navigation.js +5 -0
  98. package/dist/esm/notation/pitch.d.ts +39 -0
  99. package/dist/esm/notation/pitch.js +74 -0
  100. package/dist/esm/notation/pitchName.d.ts +2 -0
  101. package/dist/esm/notation/pitchName.js +3 -0
  102. package/dist/esm/notation/profile.d.ts +35 -0
  103. package/dist/esm/notation/profile.js +16 -0
  104. package/dist/esm/notation/rhythm.d.ts +59 -0
  105. package/dist/esm/notation/rhythm.js +116 -0
  106. package/dist/esm/notation/time.d.ts +98 -0
  107. package/dist/esm/notation/time.js +85 -0
  108. package/dist/esm/performance/compilePerformance.d.ts +7 -0
  109. package/dist/esm/performance/compilePerformance.js +8 -0
  110. package/dist/esm/performance/dynamics.d.ts +6 -0
  111. package/dist/esm/performance/dynamics.js +78 -0
  112. package/dist/esm/performance/model.d.ts +56 -0
  113. package/dist/esm/performance/model.js +1 -0
  114. package/dist/esm/performance/playOrder.d.ts +16 -0
  115. package/dist/esm/performance/playOrder.js +64 -0
  116. package/dist/esm/performance/readScore.d.ts +4 -0
  117. package/dist/esm/performance/readScore.js +58 -0
  118. package/dist/esm/performance/timeline.d.ts +10 -0
  119. package/dist/esm/performance/timeline.js +144 -0
  120. package/dist/esm/playback/audioOutput.d.ts +46 -0
  121. package/dist/esm/playback/audioOutput.js +106 -0
  122. package/dist/esm/playback/clock.d.ts +16 -0
  123. package/dist/esm/playback/clock.js +44 -0
  124. package/dist/esm/playback/createPlayerStore.d.ts +79 -0
  125. package/dist/esm/playback/createPlayerStore.js +135 -0
  126. package/dist/esm/playback/cues.d.ts +34 -0
  127. package/dist/esm/playback/cues.js +52 -0
  128. package/dist/esm/playback/errors.d.ts +6 -0
  129. package/dist/esm/playback/errors.js +6 -0
  130. package/dist/esm/playback/metronome.d.ts +13 -0
  131. package/dist/esm/playback/metronome.js +15 -0
  132. package/dist/esm/playback/mix.d.ts +9 -0
  133. package/dist/esm/playback/mix.js +8 -0
  134. package/dist/esm/playback/pass.d.ts +27 -0
  135. package/dist/esm/playback/pass.js +36 -0
  136. package/dist/esm/playback/schedule.d.ts +7 -0
  137. package/dist/esm/playback/schedule.js +12 -0
  138. package/dist/esm/playback/session.d.ts +46 -0
  139. package/dist/esm/playback/session.js +107 -0
  140. package/dist/esm/playback/source.d.ts +6 -0
  141. package/dist/esm/playback/source.js +1 -0
  142. package/dist/esm/playback/start.d.ts +28 -0
  143. package/dist/esm/playback/start.js +38 -0
  144. package/dist/esm/playback/timing.d.ts +14 -0
  145. package/dist/esm/playback/timing.js +11 -0
  146. package/dist/esm/playback/types.d.ts +60 -0
  147. package/dist/esm/playback/types.js +1 -0
  148. package/dist/esm/playback/volume.d.ts +12 -0
  149. package/dist/esm/playback/volume.js +8 -0
  150. package/dist/esm/player/ControlBar.d.ts +22 -0
  151. package/dist/esm/player/ControlBar.js +77 -0
  152. package/dist/esm/player/CursorPainter.d.ts +17 -0
  153. package/dist/esm/player/CursorPainter.js +53 -0
  154. package/dist/esm/player/InfoLine.d.ts +6 -0
  155. package/dist/esm/player/InfoLine.js +23 -0
  156. package/dist/esm/player/PageView.d.ts +10 -0
  157. package/dist/esm/player/PageView.js +16 -0
  158. package/dist/esm/player/actions.d.ts +24 -0
  159. package/dist/esm/player/actions.js +26 -0
  160. package/dist/esm/player/balanceSystems.d.ts +8 -0
  161. package/dist/esm/player/balanceSystems.js +18 -0
  162. package/dist/esm/player/createExcerptPlayer.d.ts +33 -0
  163. package/dist/esm/player/createExcerptPlayer.js +169 -0
  164. package/dist/esm/player/createScorePlayer.d.ts +24 -0
  165. package/dist/esm/player/createScorePlayer.js +118 -0
  166. package/dist/esm/player/dom.d.ts +6 -0
  167. package/dist/esm/player/dom.js +15 -0
  168. package/dist/esm/player/embeddedFonts.d.ts +1 -0
  169. package/dist/esm/player/embeddedFonts.js +3 -0
  170. package/dist/esm/player/exclusivePlayback.d.ts +10 -0
  171. package/dist/esm/player/exclusivePlayback.js +13 -0
  172. package/dist/esm/player/followCursor.d.ts +5 -0
  173. package/dist/esm/player/followCursor.js +16 -0
  174. package/dist/esm/player/icons.d.ts +7 -0
  175. package/dist/esm/player/icons.js +9 -0
  176. package/dist/esm/player/injectFonts.d.ts +8 -0
  177. package/dist/esm/player/injectFonts.js +19 -0
  178. package/dist/esm/player/loadExcerpt.d.ts +21 -0
  179. package/dist/esm/player/loadExcerpt.js +123 -0
  180. package/dist/esm/player/loadScore.d.ts +12 -0
  181. package/dist/esm/player/loadScore.js +12 -0
  182. package/dist/esm/player/mountExcerpts.d.ts +30 -0
  183. package/dist/esm/player/mountExcerpts.js +109 -0
  184. package/dist/esm/player/playhead.d.ts +12 -0
  185. package/dist/esm/player/playhead.js +14 -0
  186. package/dist/esm/player/shadowStyles.d.ts +5 -0
  187. package/dist/esm/player/shadowStyles.js +23 -0
  188. package/dist/esm/player/staticSvg.d.ts +7 -0
  189. package/dist/esm/player/staticSvg.js +10 -0
  190. package/dist/esm/player/styles.d.ts +28 -0
  191. package/dist/esm/player/styles.js +98 -0
  192. package/dist/esm/player/theme.d.ts +8 -0
  193. package/dist/esm/player/theme.js +13 -0
  194. package/dist/esm/player/types.d.ts +76 -0
  195. package/dist/esm/player/types.js +12 -0
  196. package/dist/esm/rendering/SystemRenderer.d.ts +6 -0
  197. package/dist/esm/rendering/SystemRenderer.js +58 -0
  198. package/dist/esm/rendering/accidentalRenderer.d.ts +4 -0
  199. package/dist/esm/rendering/accidentalRenderer.js +41 -0
  200. package/dist/esm/rendering/arcRenderer.d.ts +9 -0
  201. package/dist/esm/rendering/arcRenderer.js +32 -0
  202. package/dist/esm/rendering/barlineRenderer.d.ts +8 -0
  203. package/dist/esm/rendering/barlineRenderer.js +59 -0
  204. package/dist/esm/rendering/directionRenderer.d.ts +4 -0
  205. package/dist/esm/rendering/directionRenderer.js +50 -0
  206. package/dist/esm/rendering/durationLineRenderer.d.ts +9 -0
  207. package/dist/esm/rendering/durationLineRenderer.js +27 -0
  208. package/dist/esm/rendering/dynamicGlyphs.d.ts +25 -0
  209. package/dist/esm/rendering/dynamicGlyphs.js +56 -0
  210. package/dist/esm/rendering/frameRenderer.d.ts +17 -0
  211. package/dist/esm/rendering/frameRenderer.js +252 -0
  212. package/dist/esm/rendering/keyMarkRenderer.d.ts +8 -0
  213. package/dist/esm/rendering/keyMarkRenderer.js +57 -0
  214. package/dist/esm/rendering/lyricsRenderer.d.ts +4 -0
  215. package/dist/esm/rendering/lyricsRenderer.js +44 -0
  216. package/dist/esm/rendering/primitives.d.ts +64 -0
  217. package/dist/esm/rendering/primitives.js +1 -0
  218. package/dist/esm/rendering/sliceRenderer.d.ts +19 -0
  219. package/dist/esm/rendering/sliceRenderer.js +79 -0
  220. package/dist/esm/rendering/textBarRenderer.d.ts +8 -0
  221. package/dist/esm/rendering/textBarRenderer.js +28 -0
  222. package/dist/esm/rendering/tupletRenderer.d.ts +7 -0
  223. package/dist/esm/rendering/tupletRenderer.js +42 -0
  224. package/dist/esm/schema/normalize.d.ts +14 -0
  225. package/dist/esm/schema/normalize.js +123 -0
  226. package/dist/esm/schema/pageMeta.d.ts +11 -0
  227. package/dist/esm/schema/pageMeta.js +1 -0
  228. package/dist/esm/schema/scoreJson.d.ts +59 -0
  229. package/dist/esm/schema/scoreJson.js +1 -0
  230. package/dist/esm/schema/scoreView.d.ts +16 -0
  231. package/dist/esm/schema/scoreView.js +24 -0
  232. package/dist/esm/schema/types.d.ts +339 -0
  233. package/dist/esm/schema/types.js +1 -0
  234. package/dist/esm/text/creditLines.d.ts +12 -0
  235. package/dist/esm/text/creditLines.js +11 -0
  236. package/dist/esm/text/fonts.d.ts +50 -0
  237. package/dist/esm/text/fonts.js +98 -0
  238. package/dist/esm/text/headerFooter.d.ts +13 -0
  239. package/dist/esm/text/headerFooter.js +21 -0
  240. package/dist/esm/text/textLines.d.ts +7 -0
  241. package/dist/esm/text/textLines.js +13 -0
  242. package/dist/index.cjs +65 -0
  243. package/dist/index.cjs.map +1 -0
  244. package/dist/nodelyra-player.global.js +65 -0
  245. package/dist/nodelyra-player.global.js.map +1 -0
  246. package/dist/nodelyra-player.lite.global.js +63 -0
  247. package/dist/nodelyra-player.lite.global.js.map +1 -0
  248. package/examples/blog-excerpt.html +54 -0
  249. package/examples/twinkle.html +23 -0
  250. package/examples/twinkle.json +91 -0
  251. package/package.json +70 -4
@@ -0,0 +1,77 @@
1
+ import { clockText, PLAY_TEMPO } from "../playback/timing.js";
2
+ import { isAudible } from "../playback/mix.js";
3
+ import { el } from "./dom.js";
4
+ import { ICONS } from "./icons.js";
5
+ import { CLASS } from "./styles.js";
6
+ export const FULL_CONTROLS = { tempo: true, loop: true, metronome: true, mixer: true };
7
+ /** What a blog excerpt needs: play/pause/resume, stop and the time. */
8
+ export const BASIC_CONTROLS = { tempo: false, loop: false, metronome: false, mixer: false };
9
+ const toggleButton = (doc, label, icon, onClick) => {
10
+ const button = el(doc, "button", { type: "button", class: CLASS.button, "aria-label": label, title: label });
11
+ button.innerHTML = icon;
12
+ button.addEventListener("click", onClick);
13
+ return button;
14
+ };
15
+ /** The control bar: transport, clock, tempo, loop, metronome and (for several parts) a mixer. */
16
+ export function createControlBar(doc, controls, labels, parts, scoreTempo, getSnapshot, features = FULL_CONTROLS) {
17
+ const play = toggleButton(doc, labels.play, ICONS.play, () => {
18
+ const { status } = getSnapshot();
19
+ if (status === "playing")
20
+ controls.pause();
21
+ else if (status === "paused")
22
+ controls.resume();
23
+ else
24
+ void controls.play();
25
+ });
26
+ const stop = toggleButton(doc, labels.stop, ICONS.stop, () => controls.stop());
27
+ const clock = el(doc, "span", { class: CLASS.clock, role: "timer", "aria-live": "off" });
28
+ const loop = toggleButton(doc, labels.loop, ICONS.loop, () => controls.setLoop(!getSnapshot().loop));
29
+ const metronome = toggleButton(doc, labels.metronome, ICONS.metronome, () => controls.setMetronome(!getSnapshot().metronome));
30
+ const tempo = el(doc, "input", { type: "number", min: PLAY_TEMPO.min, max: PLAY_TEMPO.max, step: 1, "aria-label": labels.tempo });
31
+ tempo.addEventListener("change", () => controls.setTempo(tempo.value === "" ? null : Number(tempo.value)));
32
+ const error = el(doc, "span", { class: "nlp-error", role: "alert" });
33
+ const mixer = el(doc, "div", { class: CLASS.parts, role: "group", "aria-label": labels.parts });
34
+ const partButtons = parts.map((part) => {
35
+ const mute = el(doc, "button", { type: "button", "aria-label": `${labels.mute} ${part.name}`, title: `${labels.mute} ${part.name}` }, "M");
36
+ const solo = el(doc, "button", { type: "button", "aria-label": `${labels.solo} ${part.name}`, title: `${labels.solo} ${part.name}` }, "S");
37
+ mute.addEventListener("click", () => controls.toggleMute(part.id));
38
+ solo.addEventListener("click", () => controls.toggleSolo(part.id));
39
+ mixer.append(el(doc, "span", { class: CLASS.part }, part.name, mute, solo));
40
+ return { part, mute, solo };
41
+ });
42
+ const element = el(doc, "div", { class: CLASS.bar, role: "toolbar" }, play, stop, clock);
43
+ if (features.tempo)
44
+ element.append(el(doc, "span", { class: CLASS.tempo }, "♩ =", tempo));
45
+ if (features.loop)
46
+ element.append(loop);
47
+ if (features.metronome)
48
+ element.append(metronome);
49
+ element.append(error);
50
+ if (features.mixer && parts.length > 1)
51
+ element.append(mixer);
52
+ const setIcon = (button, label, icon) => {
53
+ button.innerHTML = icon;
54
+ button.setAttribute("aria-label", label);
55
+ button.title = label;
56
+ };
57
+ return {
58
+ element,
59
+ update(s) {
60
+ const playing = s.status === "playing";
61
+ setIcon(play, playing ? labels.pause : labels.play, playing ? ICONS.pause : ICONS.play);
62
+ play.disabled = s.status === "loading";
63
+ stop.disabled = s.status === "idle" || s.status === "error";
64
+ clock.textContent = s.status === "idle" ? clockText(0) : `${clockText(s.position)} / ${clockText(s.duration)}`;
65
+ if (doc.activeElement !== tempo)
66
+ tempo.value = String(s.tempo ?? scoreTempo);
67
+ loop.setAttribute("aria-pressed", String(s.loop));
68
+ metronome.setAttribute("aria-pressed", String(s.metronome));
69
+ error.textContent = s.status === "error" ? s.message || labels.failed : "";
70
+ for (const { part, mute, solo } of partButtons) {
71
+ mute.setAttribute("aria-pressed", String(s.mix.muted.includes(part.id)));
72
+ solo.setAttribute("aria-pressed", String(s.mix.solo.includes(part.id)));
73
+ mute.parentElement.style.opacity = isAudible(part.id, s.mix) ? "1" : ".55";
74
+ }
75
+ },
76
+ };
77
+ }
@@ -0,0 +1,17 @@
1
+ import type { LoadedScore } from "./loadScore.js";
2
+ import { type Playhead } from "./playhead.js";
3
+ export type CursorPainter = {
4
+ /** Paints the playhead on every page (nothing when it is the same as last time). */
5
+ paint(playhead: Playhead): void;
6
+ };
7
+ /**
8
+ * Paints playback onto the pages' cursor layers: a box behind each playing note (its part's
9
+ * color, gray when muted), the chord in effect, a line through the system and a dot on the beat.
10
+ * `follow` is told where the line is, so the view can scroll to it. The digits and rests playing
11
+ * and the chord in effect are drawn bold, as in the editor, by a stylesheet `setStyle` puts
12
+ * under `scope` (the pages themselves are not redrawn).
13
+ */
14
+ export declare function createCursorPainter({ score, view, pages }: LoadedScore, layers: readonly Element[], follow: (line: Element) => void, { scope, setStyle }: {
15
+ scope: string;
16
+ setStyle: (css: string) => void;
17
+ }): CursorPainter;
@@ -0,0 +1,53 @@
1
+ import { activeChordBox, activeChordKey } from "../cursor/activeChord.js";
2
+ import { beatDot, DOT_RADIUS } from "../cursor/beatDot.js";
3
+ import { cursorMarks } from "../cursor/playbackCursor.js";
4
+ import { playingChordCss, playingNoteCss } from "../cursor/playingStyle.js";
5
+ import { playingTones } from "../cursor/playingTones.js";
6
+ import { eventParts } from "../model/locate.js";
7
+ import { partTones } from "../model/partColors.js";
8
+ import { NO_PLAYHEAD, playheadKey } from "./playhead.js";
9
+ const LINE_WIDTH = 4;
10
+ const attribute = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
11
+ const n = (value) => Math.round(value * 100) / 100;
12
+ /**
13
+ * Paints playback onto the pages' cursor layers: a box behind each playing note (its part's
14
+ * color, gray when muted), the chord in effect, a line through the system and a dot on the beat.
15
+ * `follow` is told where the line is, so the view can scroll to it. The digits and rests playing
16
+ * and the chord in effect are drawn bold, as in the editor, by a stylesheet `setStyle` puts
17
+ * under `scope` (the pages themselves are not redrawn).
18
+ */
19
+ export function createCursorPainter({ score, view, pages }, layers, follow, { scope, setStyle }) {
20
+ const partOf = eventParts(view.music);
21
+ const colors = partTones(score.parts);
22
+ let last = playheadKey(NO_PLAYHEAD);
23
+ const pageMarkup = (page, playhead, chordKey) => {
24
+ const tones = playingTones(playhead.playing, playhead.heard, partOf, colors);
25
+ const marks = cursorMarks(page, playhead.playing);
26
+ const chord = activeChordBox(page, chordKey);
27
+ const dot = beatDot(page, playhead.beat);
28
+ return [
29
+ marks.line
30
+ ? `<rect data-cursor-line x="${n(marks.line.x - LINE_WIDTH / 2)}" y="${n(marks.line.y)}" width="${LINE_WIDTH}" height="${n(marks.line.height)}" rx="${LINE_WIDTH / 2}"/>`
31
+ : "",
32
+ ...marks.notes.map((box) => `<rect data-playing="${attribute(box.key)}" data-tone="${tones.get(box.key) ?? "muted"}" x="${n(box.x)}" y="${n(box.y)}" width="${n(box.width)}" height="${n(box.height)}" rx="3"/>`),
33
+ chord ? `<rect data-playing-chord="${attribute(chord.key)}" x="${n(chord.x)}" y="${n(chord.y)}" width="${n(chord.width)}" height="${n(chord.height)}" rx="3"/>` : "",
34
+ dot ? `<circle data-beat-dot="${dot.downbeat ? "downbeat" : "beat"}" cx="${n(dot.x)}" cy="${n(dot.y)}" r="${dot.downbeat ? DOT_RADIUS.downbeat : DOT_RADIUS.beat}"/>` : "",
35
+ ].join("");
36
+ };
37
+ return {
38
+ paint(playhead) {
39
+ const key = playheadKey(playhead);
40
+ if (key === last)
41
+ return;
42
+ last = key;
43
+ const chordKey = activeChordKey(view.music, playhead.beat);
44
+ setStyle(playingNoteCss(playhead.heard, scope) + playingChordCss(chordKey, scope));
45
+ pages.forEach((page, index) => {
46
+ layers[index].innerHTML = pageMarkup(page, playhead, chordKey);
47
+ });
48
+ const line = layers.map((layer) => layer.querySelector("[data-cursor-line]")).find(Boolean);
49
+ if (line)
50
+ follow(line);
51
+ },
52
+ };
53
+ }
@@ -0,0 +1,6 @@
1
+ import type { LoadedScore } from "./loadScore.js";
2
+ /**
3
+ * The score's facts above the notation ("do = G · 3/4 · ♩ = 84"): the page setup's info lines, the
4
+ * ones the editor prints under the title, filled in for this score. Null when the score has none.
5
+ */
6
+ export declare function createInfoLine(doc: Document, { view }: Pick<LoadedScore, "view">): HTMLElement | null;
@@ -0,0 +1,23 @@
1
+ import { formatTempo, renderHeaderFooterText } from "../text/headerFooter.js";
2
+ import { singleLine } from "../text/textLines.js";
3
+ import { el } from "./dom.js";
4
+ import { CLASS } from "./styles.js";
5
+ /**
6
+ * The score's facts above the notation ("do = G · 3/4 · ♩ = 84"): the page setup's info lines, the
7
+ * ones the editor prints under the title, filled in for this score. Null when the score has none.
8
+ */
9
+ export function createInfoLine(doc, { view }) {
10
+ const { meta, setup } = view;
11
+ const context = {
12
+ page: 1,
13
+ pages: 1,
14
+ title: singleLine(meta.title),
15
+ key: meta.key,
16
+ time: meta.time,
17
+ tempo: formatTempo(meta.tempo, meta.tempoMarking),
18
+ };
19
+ const lines = setup.header.info.map((line) => renderHeaderFooterText(line, context)).filter((line) => line.trim() !== "");
20
+ if (lines.length === 0)
21
+ return null;
22
+ return el(doc, "div", { class: CLASS.info }, ...lines.flatMap((line, i) => (i === 0 ? [line] : [doc.createElement("br"), line])));
23
+ }
@@ -0,0 +1,10 @@
1
+ import { type SvgStyle } from "../export/svgExport.js";
2
+ import type { LoadedScore } from "./loadScore.js";
3
+ export type PageView = {
4
+ /** The scrolling area that holds the pages. */
5
+ element: HTMLElement;
6
+ /** One group per page, under that page's notation: where playback is painted. */
7
+ cursorLayers: Element[];
8
+ };
9
+ /** Draws every page of a loaded score as an SVG, each with an empty cursor layer. */
10
+ export declare function renderPages(doc: Document, { view, pages }: LoadedScore, style: SvgStyle): PageView;
@@ -0,0 +1,16 @@
1
+ import { renderPageSvg } from "../export/svgExport.js";
2
+ import { CLASS } from "./styles.js";
3
+ import { el, setSvg } from "./dom.js";
4
+ /** Draws every page of a loaded score as an SVG, each with an empty cursor layer. */
5
+ export function renderPages(doc, { view, pages }, style) {
6
+ const element = el(doc, "div", { class: CLASS.pages, role: "document", tabindex: 0 });
7
+ const cursorLayers = [];
8
+ const input = { pages, music: view.music, setup: view.setup, meta: view.meta };
9
+ pages.forEach((_, index) => {
10
+ const page = el(doc, "div", { class: CLASS.page });
11
+ setSvg(page, renderPageSvg(input, index, { style, annotate: true }));
12
+ cursorLayers.push(page.querySelector("[data-layer=cursor]"));
13
+ element.append(page);
14
+ });
15
+ return { element, cursorLayers };
16
+ }
@@ -0,0 +1,24 @@
1
+ import type { StoreApi } from "zustand/vanilla";
2
+ import type { PlayerStore } from "../playback/createPlayerStore.js";
3
+ import type { VolumeChannel } from "../playback/volume.js";
4
+ import type { ScoreInput } from "../schema/types.js";
5
+ import type { PlayerSnapshot } from "./types.js";
6
+ /** What a listener may see of the store's state. */
7
+ export declare const snapshotOf: (s: PlayerSnapshot) => PlayerSnapshot;
8
+ /**
9
+ * The things a person can do with a player, wired to its store. `score` is asked for at the moment
10
+ * of playing, so a player that shows another score later plays that one.
11
+ */
12
+ export declare function createActions(store: StoreApi<PlayerStore>, score: () => ScoreInput): {
13
+ play: () => Promise<void>;
14
+ pause: () => void;
15
+ resume: () => void;
16
+ stop: () => void;
17
+ setTempo: (bpm: number | null) => void;
18
+ setLoop: (on: boolean) => false | void;
19
+ setMetronome: (on: boolean) => false | void;
20
+ toggleMute: (id: string) => void;
21
+ toggleSolo: (id: string) => void;
22
+ setVolume: (channel: VolumeChannel, level: number) => void;
23
+ setPartVolume: (id: string, level: number) => void;
24
+ };
@@ -0,0 +1,26 @@
1
+ /** What a listener may see of the store's state. */
2
+ export const snapshotOf = (s) => ({
3
+ status: s.status, message: s.message, position: s.position, duration: s.duration,
4
+ tempo: s.tempo, loop: s.loop, metronome: s.metronome, mix: s.mix,
5
+ volumes: s.volumes, partVolumes: s.partVolumes, ends: s.ends,
6
+ });
7
+ /**
8
+ * The things a person can do with a player, wired to its store. `score` is asked for at the moment
9
+ * of playing, so a player that shows another score later plays that one.
10
+ */
11
+ export function createActions(store, score) {
12
+ const state = () => store.getState();
13
+ return {
14
+ play: () => state().play(score()),
15
+ pause: () => state().pause(),
16
+ resume: () => state().resume(),
17
+ stop: () => state().stop(),
18
+ setTempo: (bpm) => state().setTempo(bpm),
19
+ setLoop: (on) => on !== state().loop && state().toggleLoop(),
20
+ setMetronome: (on) => on !== state().metronome && state().toggleMetronome(),
21
+ toggleMute: (id) => state().toggleMute(id),
22
+ toggleSolo: (id) => state().toggleSolo(id),
23
+ setVolume: (channel, level) => state().setVolume(channel, level),
24
+ setPartVolume: (id, level) => state().setPartVolume(id, level),
25
+ };
26
+ }
@@ -0,0 +1,8 @@
1
+ import type { MeasureJson } from "../schema/scoreJson.js";
2
+ /**
3
+ * How many measures each of `lines` lines should hold so that `total` measures are spread evenly,
4
+ * the earlier lines taking the extra one: 5 measures on 2 lines are 3 and 2, not 4 and 1.
5
+ */
6
+ export declare function evenLineSizes(total: number, lines: number): number[];
7
+ /** `measures` with a line break after the last measure of every line but the final one. */
8
+ export declare function withLineBreaks(measures: readonly MeasureJson[], sizes: readonly number[]): MeasureJson[];
@@ -0,0 +1,18 @@
1
+ /**
2
+ * How many measures each of `lines` lines should hold so that `total` measures are spread evenly,
3
+ * the earlier lines taking the extra one: 5 measures on 2 lines are 3 and 2, not 4 and 1.
4
+ */
5
+ export function evenLineSizes(total, lines) {
6
+ const base = Math.floor(total / lines);
7
+ const extra = total % lines;
8
+ return Array.from({ length: lines }, (_, i) => base + (i < extra ? 1 : 0));
9
+ }
10
+ /** `measures` with a line break after the last measure of every line but the final one. */
11
+ export function withLineBreaks(measures, sizes) {
12
+ const breaksAfter = new Set();
13
+ sizes.slice(0, -1).reduce((end, size) => {
14
+ breaksAfter.add(end + size - 1);
15
+ return end + size;
16
+ }, 0);
17
+ return measures.map((measure, index) => (breaksAfter.has(index) ? { ...measure, break_after: "line" } : measure));
18
+ }
@@ -0,0 +1,33 @@
1
+ import type { ScoreJson } from "../schema/scoreJson.js";
2
+ import type { PlayerEnvironment } from "./createScorePlayer.js";
3
+ import { type PlayerControls, type PlayerOptions, type ScorePlayer } from "./types.js";
4
+ export type ExcerptOptions = Pick<PlayerOptions, "theme" | "loop" | "metronome" | "label" | "tempo" | "labels" | "fonts"> & {
5
+ /** "basic" (default): play/pause/resume, stop and the time. "full": adds loop, tempo, metronome and the mixer. `false`: none. */
6
+ controls?: "basic" | "full" | false;
7
+ /** Show the title block above the notation (default false: an excerpt sits under the post's own heading). */
8
+ header?: boolean;
9
+ /** Show the score's facts above the notation, "do = G · 3/4 · ♩ = 84" (default true; not with `header`, which has them). */
10
+ info?: boolean;
11
+ /** Digit size in px, 10 to 28 (default 14, or the score's own `page.note_size`); lyrics follow in proportion. */
12
+ size?: number;
13
+ };
14
+ /** What a host can do with an excerpt: play it, read its state, show another, remove it. */
15
+ export type ExcerptPlayer = PlayerControls & Pick<ScorePlayer, "snapshot" | "toggle" | "subscribe" | "update" | "setTheme" | "destroy"> & {
16
+ /** Draw the notation at another digit size (px, 10 to 28); the excerpt lays out again, playing continues. */
17
+ setSize(size: number): void;
18
+ };
19
+ /** The outside world of an excerpt: the player's, plus a way to hear that its box changed width. */
20
+ export type ExcerptEnvironment = PlayerEnvironment & {
21
+ observeWidth: (element: HTMLElement, onChange: () => void) => () => void;
22
+ };
23
+ /**
24
+ * A short piece of numbered notation for a blog post or article: the JSON you give is drawn at the
25
+ * width of `target` (no paper, no page chrome, no scrolling), re-flowed when the width changes,
26
+ * with a Play button under it. The playhead and the playing notes are painted as in the full player.
27
+ *
28
+ * createExcerptPlayer(element, { measures: [...], parts: [...] });
29
+ *
30
+ * Throws `ScoreFormatError` before touching the page when the JSON cannot be drawn. Starting one
31
+ * excerpt stops any other that is playing on the page.
32
+ */
33
+ export declare function createExcerptPlayer(target: HTMLElement, score: ScoreJson, options?: ExcerptOptions, environment?: ExcerptEnvironment): ExcerptPlayer;
@@ -0,0 +1,169 @@
1
+ import { createWebAudioOutput } from "../playback/audioOutput.js";
2
+ import { createPlayerStore } from "../playback/createPlayerStore.js";
3
+ import { localPerformanceSource } from "../performance/compilePerformance.js";
4
+ import { createActions, snapshotOf } from "./actions.js";
5
+ import { BASIC_CONTROLS, createControlBar, FULL_CONTROLS } from "./ControlBar.js";
6
+ import { createInfoLine } from "./InfoLine.js";
7
+ import { createCursorPainter } from "./CursorPainter.js";
8
+ import { el } from "./dom.js";
9
+ import { claimPlayback } from "./exclusivePlayback.js";
10
+ import { loadExcerpt } from "./loadExcerpt.js";
11
+ import { renderPages } from "./PageView.js";
12
+ import { playheadOf } from "./playhead.js";
13
+ import { injectFonts } from "./injectFonts.js";
14
+ import { applyShadowStyles } from "./shadowStyles.js";
15
+ import { CLASS, EXCERPT_CSS } from "./styles.js";
16
+ import { EXCERPT_STYLE, resolveTheme } from "./theme.js";
17
+ import { DEFAULT_LABELS } from "./types.js";
18
+ /** Used until the element has a width (it is not in the page yet, or has no layout). */
19
+ const FALLBACK_WIDTH = 640;
20
+ const BORDER = 2;
21
+ /** A width change smaller than this does not lay the notation out again. */
22
+ const RESIZE_THRESHOLD = 2;
23
+ const browserEnvironment = (target) => ({
24
+ document: target.ownerDocument,
25
+ source: localPerformanceSource,
26
+ createOutput: () => createWebAudioOutput(),
27
+ observeWidth(element, onChange) {
28
+ const Observer = element.ownerDocument.defaultView?.ResizeObserver;
29
+ if (!Observer)
30
+ return () => { };
31
+ const observer = new Observer(onChange);
32
+ observer.observe(element);
33
+ return () => observer.disconnect();
34
+ },
35
+ });
36
+ let excerptCount = 0;
37
+ /**
38
+ * A short piece of numbered notation for a blog post or article: the JSON you give is drawn at the
39
+ * width of `target` (no paper, no page chrome, no scrolling), re-flowed when the width changes,
40
+ * with a Play button under it. The playhead and the playing notes are painted as in the full player.
41
+ *
42
+ * createExcerptPlayer(element, { measures: [...], parts: [...] });
43
+ *
44
+ * Throws `ScoreFormatError` before touching the page when the JSON cannot be drawn. Starting one
45
+ * excerpt stops any other that is playing on the page.
46
+ */
47
+ export function createExcerptPlayer(target, score, options = {}, environment = browserEnvironment(target)) {
48
+ const doc = environment.document;
49
+ const labels = { ...DEFAULT_LABELS, ...options.labels };
50
+ const store = createPlayerStore({ source: environment.source, createOutput: environment.createOutput, repeat: environment.repeat });
51
+ const prefersDark = () => Boolean(doc.defaultView?.matchMedia?.("(prefers-color-scheme: dark)").matches);
52
+ let theme = resolveTheme(options.theme ?? "auto", prefersDark);
53
+ let json = score;
54
+ let laidOutAt = 0;
55
+ let size = options.size;
56
+ let loaded;
57
+ let pagesView;
58
+ let painter;
59
+ let controlBar = null;
60
+ const id = `x${++excerptCount}`;
61
+ // The player lives in a shadow tree: the page's CSS cannot reach in, and ours cannot leak out.
62
+ const shadowHost = el(doc, "div", { class: CLASS.shadowHost, "data-theme": theme });
63
+ const shadow = shadowHost.attachShadow({ mode: "open" });
64
+ const root = el(doc, "div", { class: `${CLASS.root} ${CLASS.excerpt}`, "data-theme": theme, "data-nlp-id": id, role: "region", "aria-label": options.label ?? "Score excerpt" });
65
+ const playingStyle = el(doc, "style", { "data-playing-style": "" });
66
+ root.append(playingStyle);
67
+ applyShadowStyles(doc, shadow, EXCERPT_CSS);
68
+ shadow.append(root);
69
+ const act = createActions(store, () => loaded.score);
70
+ const snapshot = () => snapshotOf(store.getState());
71
+ const availableWidth = () => (root.clientWidth || FALLBACK_WIDTH + BORDER) - BORDER;
72
+ /** Lays the notation out at the current width, keeping the control bar and playback as they are. */
73
+ const layout = () => {
74
+ laidOutAt = availableWidth();
75
+ loaded = loadExcerpt(json, laidOutAt, { header: options.header, size });
76
+ root.querySelector(`.${CLASS.pages}`)?.remove();
77
+ root.querySelector(`.${CLASS.info}`)?.remove();
78
+ pagesView = renderPages(doc, loaded, EXCERPT_STYLE);
79
+ pagesView.element.removeAttribute("tabindex"); // nothing in it scrolls: no tab stop
80
+ painter = createCursorPainter(loaded, pagesView.cursorLayers, () => { }, {
81
+ scope: `.${CLASS.root}[data-nlp-id="${id}"]`,
82
+ setStyle: (css) => void (playingStyle.textContent = css),
83
+ });
84
+ root.prepend(pagesView.element);
85
+ const info = options.info === false || options.header ? null : createInfoLine(doc, loaded);
86
+ if (info)
87
+ root.prepend(info);
88
+ painter.paint(playheadOf(store.getState()));
89
+ };
90
+ const mountControls = () => {
91
+ controlBar?.element.remove();
92
+ controlBar = options.controls === false
93
+ ? null
94
+ : createControlBar(doc, act, labels, loaded.score.parts, loaded.view.meta.tempo, snapshot, options.controls === "full" ? FULL_CONTROLS : BASIC_CONTROLS);
95
+ if (controlBar)
96
+ root.append(controlBar.element);
97
+ controlBar?.update(snapshot());
98
+ };
99
+ if (options.fonts !== false)
100
+ void injectFonts(doc);
101
+ act.setLoop(options.loop ?? false);
102
+ act.setMetronome(options.metronome ?? false);
103
+ if (options.tempo)
104
+ act.setTempo(options.tempo);
105
+ target.append(shadowHost); // in the page first: the notation is laid out at the width it gets there
106
+ try {
107
+ layout();
108
+ mountControls();
109
+ }
110
+ catch (error) {
111
+ shadowHost.remove();
112
+ store.getState().dispose();
113
+ throw error;
114
+ }
115
+ const self = { stop: act.stop };
116
+ let release = null;
117
+ const unsubscribe = store.subscribe((state) => {
118
+ if (state.status === "playing" && !release)
119
+ release = claimPlayback(self);
120
+ if ((state.status === "idle" || state.status === "error") && release) {
121
+ release();
122
+ release = null;
123
+ }
124
+ controlBar?.update(snapshotOf(state));
125
+ painter.paint(playheadOf(state));
126
+ });
127
+ const stopObserving = environment.observeWidth(root, () => {
128
+ if (Math.abs(availableWidth() - laidOutAt) >= RESIZE_THRESHOLD)
129
+ layout();
130
+ });
131
+ return {
132
+ ...act,
133
+ get snapshot() {
134
+ return snapshot();
135
+ },
136
+ toggle() {
137
+ const { status } = store.getState();
138
+ if (status === "playing")
139
+ act.pause();
140
+ else if (status === "paused")
141
+ act.resume();
142
+ else
143
+ void act.play();
144
+ },
145
+ subscribe: (listener) => store.subscribe((state) => listener(snapshotOf(state))),
146
+ update(next) {
147
+ store.getState().stop();
148
+ json = next;
149
+ layout();
150
+ mountControls();
151
+ },
152
+ setSize(next) {
153
+ size = next;
154
+ layout();
155
+ },
156
+ setTheme(next) {
157
+ theme = resolveTheme(next, prefersDark);
158
+ root.dataset.theme = theme;
159
+ shadowHost.dataset.theme = theme;
160
+ },
161
+ destroy() {
162
+ stopObserving();
163
+ unsubscribe();
164
+ release?.();
165
+ store.getState().dispose();
166
+ shadowHost.remove();
167
+ },
168
+ };
169
+ }
@@ -0,0 +1,24 @@
1
+ import { type AudioOutput } from "../playback/audioOutput.js";
2
+ import { type Repeat } from "../playback/createPlayerStore.js";
3
+ import type { PerformanceSource } from "../playback/source.js";
4
+ import type { ScoreJson } from "../schema/scoreJson.js";
5
+ import { type PlayerOptions, type ScorePlayer } from "./types.js";
6
+ /**
7
+ * The parts of the player that touch the outside world, so a test (or a server-side host) can
8
+ * swap them: where the notes come from, the sound device, the timer, and the document.
9
+ */
10
+ export type PlayerEnvironment = {
11
+ document: Document;
12
+ source: PerformanceSource;
13
+ createOutput: () => AudioOutput;
14
+ repeat?: Repeat;
15
+ };
16
+ /**
17
+ * Shows a score as numbered notation inside `target` and plays it. The score is JSON (see
18
+ * `ScoreJson`); the pages are SVG, the sound is Web Audio, there are no dependencies, and it works
19
+ * in any framework: call it when your element is in the page and `destroy()` when it goes.
20
+ *
21
+ * const player = createScorePlayer(element, score);
22
+ * player.play();
23
+ */
24
+ export declare function createScorePlayer(target: HTMLElement, score: ScoreJson, options?: PlayerOptions, environment?: PlayerEnvironment): ScorePlayer;
@@ -0,0 +1,118 @@
1
+ import { createWebAudioOutput } from "../playback/audioOutput.js";
2
+ import { createPlayerStore } from "../playback/createPlayerStore.js";
3
+ import { localPerformanceSource } from "../performance/compilePerformance.js";
4
+ import { createActions, snapshotOf } from "./actions.js";
5
+ import { createControlBar } from "./ControlBar.js";
6
+ import { createCursorPainter } from "./CursorPainter.js";
7
+ import { el } from "./dom.js";
8
+ import { followCursor } from "./followCursor.js";
9
+ import { loadScore } from "./loadScore.js";
10
+ import { renderPages } from "./PageView.js";
11
+ import { playheadOf } from "./playhead.js";
12
+ import { injectFonts } from "./injectFonts.js";
13
+ import { CLASS, injectStyles } from "./styles.js";
14
+ import { resolveTheme, SCORE_STYLES } from "./theme.js";
15
+ import { DEFAULT_LABELS } from "./types.js";
16
+ const browserEnvironment = (target) => ({
17
+ document: target.ownerDocument,
18
+ source: localPerformanceSource,
19
+ createOutput: () => createWebAudioOutput(),
20
+ });
21
+ /** Tells one player's playing style from another's when several are on a page. */
22
+ let playerCount = 0;
23
+ /**
24
+ * Shows a score as numbered notation inside `target` and plays it. The score is JSON (see
25
+ * `ScoreJson`); the pages are SVG, the sound is Web Audio, there are no dependencies, and it works
26
+ * in any framework: call it when your element is in the page and `destroy()` when it goes.
27
+ *
28
+ * const player = createScorePlayer(element, score);
29
+ * player.play();
30
+ */
31
+ export function createScorePlayer(target, score, options = {}, environment = browserEnvironment(target)) {
32
+ const doc = environment.document;
33
+ const labels = { ...DEFAULT_LABELS, ...options.labels };
34
+ const store = createPlayerStore({ source: environment.source, createOutput: environment.createOutput, repeat: environment.repeat });
35
+ const reducedMotion = () => Boolean(doc.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches);
36
+ const prefersDark = () => Boolean(doc.defaultView?.matchMedia?.("(prefers-color-scheme: dark)").matches);
37
+ let theme = resolveTheme(options.theme ?? "auto", prefersDark);
38
+ let json = score;
39
+ let loaded;
40
+ let pagesView;
41
+ let painter;
42
+ let controlBar = null;
43
+ const id = String(++playerCount);
44
+ const root = el(doc, "div", { class: CLASS.root, "data-theme": theme, "data-nlp-id": id, role: "region", "aria-label": options.label ?? "Score player" });
45
+ const playingStyle = el(doc, "style", { "data-playing-style": "" });
46
+ root.append(playingStyle);
47
+ root.style.height = options.height ?? "30rem";
48
+ const setZoom = (zoom) => root.style.setProperty("--nlp-zoom", String(zoom));
49
+ setZoom(options.zoom ?? 1);
50
+ const act = createActions(store, () => loaded.score);
51
+ const snapshot = () => snapshotOf(store.getState());
52
+ const mount = (next) => {
53
+ json = next;
54
+ loaded = loadScore(next);
55
+ root.querySelector(`.${CLASS.pages}`)?.remove();
56
+ controlBar?.element.remove();
57
+ pagesView = renderPages(doc, loaded, SCORE_STYLES[theme]);
58
+ painter = createCursorPainter(loaded, pagesView.cursorLayers, (line) => followCursor(pagesView.element, line, reducedMotion()), {
59
+ scope: `.${CLASS.root}[data-nlp-id="${id}"]`,
60
+ setStyle: (css) => void (playingStyle.textContent = css),
61
+ });
62
+ root.append(pagesView.element);
63
+ controlBar = options.controls === false ? null : createControlBar(doc, act, labels, loaded.score.parts, loaded.view.meta.tempo, snapshot);
64
+ if (controlBar)
65
+ root.append(controlBar.element);
66
+ controlBar?.update(snapshot());
67
+ painter.paint(playheadOf(store.getState()));
68
+ };
69
+ injectStyles(doc);
70
+ if (options.fonts !== false)
71
+ void injectFonts(doc);
72
+ act.setLoop(options.loop ?? false);
73
+ act.setMetronome(options.metronome ?? false);
74
+ if (options.tempo)
75
+ act.setTempo(options.tempo);
76
+ mount(score);
77
+ target.append(root);
78
+ const unsubscribe = store.subscribe((state) => {
79
+ controlBar?.update(snapshotOf(state));
80
+ painter.paint(playheadOf(state));
81
+ });
82
+ return {
83
+ ...act,
84
+ get snapshot() {
85
+ return snapshot();
86
+ },
87
+ get parts() {
88
+ return loaded.score.parts.map(({ id, name }) => ({ id, name }));
89
+ },
90
+ toggle() {
91
+ const { status } = store.getState();
92
+ if (status === "playing")
93
+ act.pause();
94
+ else if (status === "paused")
95
+ act.resume();
96
+ else
97
+ void act.play();
98
+ },
99
+ subscribe(listener) {
100
+ return store.subscribe((state) => listener(snapshotOf(state)));
101
+ },
102
+ update(next) {
103
+ store.getState().stop();
104
+ mount(next);
105
+ },
106
+ setZoom,
107
+ setTheme(next) {
108
+ theme = resolveTheme(next, prefersDark);
109
+ root.dataset.theme = theme;
110
+ mount(json);
111
+ },
112
+ destroy() {
113
+ unsubscribe();
114
+ store.getState().dispose();
115
+ root.remove();
116
+ },
117
+ };
118
+ }
@@ -0,0 +1,6 @@
1
+ type Attributes = Record<string, string | number | boolean | undefined>;
2
+ /** A small element builder: the player is plain DOM, so it works in any framework or none. */
3
+ export declare function el<K extends keyof HTMLElementTagNameMap>(doc: Document, tag: K, attributes?: Attributes, ...children: (Node | string)[]): HTMLElementTagNameMap[K];
4
+ /** Replaces what an element holds with an SVG string (our own output: never user markup). */
5
+ export declare const setSvg: (target: Element, svg: string) => void;
6
+ export {};