@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,30 @@
1
+ import { type ExcerptOptions, type ExcerptPlayer } from "./createExcerptPlayer.js";
2
+ /** What marks a block of JSON as an excerpt: `<script type="application/json" data-not-angka>`. */
3
+ export declare const EXCERPT_SELECTOR = "script[type='application/json'][data-not-angka]";
4
+ /** Excerpt options, and whether to wait until the excerpt is near the screen before drawing it. */
5
+ export type MountOptions = ExcerptOptions & {
6
+ lazy?: boolean;
7
+ };
8
+ /** The part of the outside world mounting needs: to hear that an element is (nearly) on screen. */
9
+ export type MountEnvironment = {
10
+ /** Calls `onNear` once, when `element` is within a screen of the viewport (at once if the browser cannot tell). Returns a cancel. */
11
+ observeNear: (element: HTMLElement, onNear: () => void) => () => void;
12
+ };
13
+ /** The excerpts mounted by one call: the ones drawn so far (more appear as lazy ones come near), and a way to remove them all. */
14
+ export type ExcerptMounts = {
15
+ readonly players: readonly ExcerptPlayer[];
16
+ /** Cancel the ones waiting, destroy the drawn ones and remove their places from the page. */
17
+ destroy(): void;
18
+ };
19
+ /**
20
+ * Turns every `<script type="application/json" data-not-angka>` under `root` into an excerpt placed
21
+ * right after it, so a blog author only pastes the JSON:
22
+ *
23
+ * <script type="application/json" data-not-angka>{"measures": [...], "parts": [...]}</script>
24
+ *
25
+ * Excerpts are drawn when they come within a screen of the viewport (`lazy: false`, or
26
+ * `data-lazy="false"`, draws them at once), so a page with many costs only the ones being read. JSON
27
+ * that is not valid shows its error in the page at once; a score that cannot be drawn shows it when
28
+ * its turn comes. The others still mount. A block is mounted once.
29
+ */
30
+ export declare function mountExcerpts(root?: ParentNode, options?: MountOptions, environment?: MountEnvironment): ExcerptMounts;
@@ -0,0 +1,109 @@
1
+ import { ScoreFormatError } from "../schema/normalize.js";
2
+ import { createExcerptPlayer } from "./createExcerptPlayer.js";
3
+ import { el } from "./dom.js";
4
+ /** What marks a block of JSON as an excerpt: `<script type="application/json" data-not-angka>`. */
5
+ export const EXCERPT_SELECTOR = "script[type='application/json'][data-not-angka]";
6
+ /** How far outside the viewport an excerpt starts to be drawn, so it is ready before it scrolls in. */
7
+ const NEAR = "400px";
8
+ /** Room kept for an excerpt that is not drawn yet, so the text below it does not jump much when it is. */
9
+ const PLACEHOLDER_HEIGHT = "7rem";
10
+ const browserEnvironment = (doc) => ({
11
+ observeNear(element, onNear) {
12
+ const Observer = doc.defaultView?.IntersectionObserver;
13
+ if (!Observer) {
14
+ onNear();
15
+ return () => { };
16
+ }
17
+ const observer = new Observer((entries) => {
18
+ if (!entries.some((entry) => entry.isIntersecting))
19
+ return;
20
+ observer.disconnect();
21
+ onNear();
22
+ }, { rootMargin: NEAR });
23
+ observer.observe(element);
24
+ return () => observer.disconnect();
25
+ },
26
+ });
27
+ const CONTROLS = { basic: "basic", full: "full", none: false };
28
+ const THEMES = ["light", "dark", "auto"];
29
+ const isOn = (value) => value !== "false";
30
+ /** The options written on the tag (`data-controls="full"`, `data-size="16"`, ...); what is not written is left out, so the host's options still apply. */
31
+ const optionsOf = ({ dataset }) => {
32
+ const { controls, header, info, theme, loop, tempo, label, size, fonts, lazy } = dataset;
33
+ return {
34
+ ...(controls !== undefined && controls in CONTROLS && { controls: CONTROLS[controls] }),
35
+ ...(header !== undefined && { header: isOn(header) }),
36
+ ...(info !== undefined && { info: isOn(info) }),
37
+ ...(THEMES.some((t) => t === theme) && { theme: theme }),
38
+ ...(loop !== undefined && { loop: isOn(loop) }),
39
+ ...(tempo && { tempo: Number(tempo) }),
40
+ ...(label && { label }),
41
+ ...(size && { size: Number(size) }),
42
+ ...(fonts !== undefined && { fonts: isOn(fonts) }),
43
+ ...(lazy !== undefined && { lazy: isOn(lazy) }),
44
+ };
45
+ };
46
+ /** Shows why an excerpt is missing, right after its JSON (and in the console). */
47
+ function showFailure(script, error) {
48
+ const known = error instanceof ScoreFormatError || error instanceof SyntaxError;
49
+ const message = known ? error.message : "The score could not be shown.";
50
+ script.after(el(script.ownerDocument, "p", { class: "nlp-error", role: "alert" }, message));
51
+ console.error("[not-angka]", error);
52
+ }
53
+ const ownerOf = (root) => ("ownerDocument" in root && root.ownerDocument) || root;
54
+ /**
55
+ * Turns every `<script type="application/json" data-not-angka>` under `root` into an excerpt placed
56
+ * right after it, so a blog author only pastes the JSON:
57
+ *
58
+ * <script type="application/json" data-not-angka>{"measures": [...], "parts": [...]}</script>
59
+ *
60
+ * Excerpts are drawn when they come within a screen of the viewport (`lazy: false`, or
61
+ * `data-lazy="false"`, draws them at once), so a page with many costs only the ones being read. JSON
62
+ * that is not valid shows its error in the page at once; a score that cannot be drawn shows it when
63
+ * its turn comes. The others still mount. A block is mounted once.
64
+ */
65
+ export function mountExcerpts(root = document, options = {}, environment = browserEnvironment(ownerOf(root))) {
66
+ const doc = ownerOf(root);
67
+ const players = [];
68
+ const hosts = [];
69
+ const cancels = [];
70
+ root.querySelectorAll(EXCERPT_SELECTOR).forEach((script) => {
71
+ if (script.dataset.notAngkaMounted !== undefined)
72
+ return;
73
+ script.dataset.notAngkaMounted = "";
74
+ const { lazy = true, ...player } = { ...options, ...optionsOf(script) };
75
+ let score;
76
+ try {
77
+ score = JSON.parse(script.textContent ?? "");
78
+ }
79
+ catch (error) {
80
+ showFailure(script, error);
81
+ return;
82
+ }
83
+ const host = el(doc, "div", { class: "nlp-host" });
84
+ script.after(host);
85
+ hosts.push(host);
86
+ const mount = () => {
87
+ host.style.minHeight = "";
88
+ try {
89
+ players.push(createExcerptPlayer(host, score, player));
90
+ }
91
+ catch (error) {
92
+ host.remove();
93
+ showFailure(script, error);
94
+ }
95
+ };
96
+ if (!lazy)
97
+ return mount();
98
+ host.style.minHeight = PLACEHOLDER_HEIGHT;
99
+ cancels.push(environment.observeNear(host, mount));
100
+ });
101
+ return {
102
+ players,
103
+ destroy() {
104
+ cancels.splice(0).forEach((cancel) => cancel());
105
+ players.splice(0).forEach((player) => player.destroy());
106
+ hosts.splice(0).forEach((host) => host.remove());
107
+ },
108
+ };
109
+ }
@@ -0,0 +1,12 @@
1
+ import { type PlayingBeat } from "../playback/cues.js";
2
+ import type { PlayerState } from "../playback/createPlayerStore.js";
3
+ /** What is sounding now: the events playing, the ones in parts that are heard, and the beat. */
4
+ export type Playhead = {
5
+ playing: string[];
6
+ heard: string[];
7
+ beat: PlayingBeat | null;
8
+ };
9
+ export declare const NO_PLAYHEAD: Playhead;
10
+ export declare function playheadOf({ track, position, mix }: Pick<PlayerState, "track" | "position" | "mix">): Playhead;
11
+ /** Equal for two playheads that look the same, so a repaint is skipped while nothing changed. */
12
+ export declare const playheadKey: ({ playing, heard, beat }: Playhead) => string;
@@ -0,0 +1,14 @@
1
+ import { isAudible } from "../playback/mix.js";
2
+ import { playingBeat, playingEventIds } from "../playback/cues.js";
3
+ export const NO_PLAYHEAD = { playing: [], heard: [], beat: null };
4
+ export function playheadOf({ track, position, mix }) {
5
+ if (!track)
6
+ return NO_PLAYHEAD;
7
+ return {
8
+ playing: playingEventIds(track, position),
9
+ heard: playingEventIds(track, position, (part) => isAudible(part, mix)),
10
+ beat: playingBeat(track, position),
11
+ };
12
+ }
13
+ /** Equal for two playheads that look the same, so a repaint is skipped while nothing changed. */
14
+ export const playheadKey = ({ playing, heard, beat }) => `${playing.join(",")}|${heard.join(",")}|${beat ? `${beat.pass}:${beat.beat}` : ""}`;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Styles a shadow tree. Browsers with constructable stylesheets share one parsed sheet between every
3
+ * excerpt on the page (twenty excerpts cost one sheet, not twenty copies); the others get a `<style>`.
4
+ */
5
+ export declare function applyShadowStyles(doc: Document, shadow: ShadowRoot, css: string): void;
@@ -0,0 +1,23 @@
1
+ import { el } from "./dom.js";
2
+ /** One stylesheet per document and text: every excerpt on a page adopts the same object. */
3
+ const shared = new WeakMap();
4
+ const canAdopt = (shadow, view) => "adoptedStyleSheets" in shadow && typeof view?.CSSStyleSheet?.prototype?.replaceSync === "function";
5
+ /**
6
+ * Styles a shadow tree. Browsers with constructable stylesheets share one parsed sheet between every
7
+ * excerpt on the page (twenty excerpts cost one sheet, not twenty copies); the others get a `<style>`.
8
+ */
9
+ export function applyShadowStyles(doc, shadow, css) {
10
+ const view = doc.defaultView;
11
+ if (!canAdopt(shadow, view)) {
12
+ shadow.append(el(doc, "style", {}, css));
13
+ return;
14
+ }
15
+ let entry = shared.get(doc);
16
+ if (!entry || entry.css !== css) {
17
+ const sheet = new view.CSSStyleSheet();
18
+ sheet.replaceSync(css);
19
+ entry = { css, sheet };
20
+ shared.set(doc, entry);
21
+ }
22
+ shadow.adoptedStyleSheets = [entry.sheet];
23
+ }
@@ -0,0 +1,7 @@
1
+ import { type SvgOptions } from "../export/svgExport.js";
2
+ import type { ScoreJson } from "../schema/scoreJson.js";
3
+ /**
4
+ * A whole score as one standalone SVG string, every page stacked (black on white unless a
5
+ * `style` is given). Needs no browser: use it on a server, in a build step or in a script.
6
+ */
7
+ export declare function renderScoreToSvg(score: ScoreJson, options?: SvgOptions): string;
@@ -0,0 +1,10 @@
1
+ import { exportScoreSvg } from "../export/svgExport.js";
2
+ import { loadScore } from "./loadScore.js";
3
+ /**
4
+ * A whole score as one standalone SVG string, every page stacked (black on white unless a
5
+ * `style` is given). Needs no browser: use it on a server, in a build step or in a script.
6
+ */
7
+ export function renderScoreToSvg(score, options = {}) {
8
+ const { view, pages } = loadScore(score);
9
+ return exportScoreSvg({ pages, music: view.music, setup: view.setup, meta: view.meta }, options);
10
+ }
@@ -0,0 +1,28 @@
1
+ /** Class names the player uses. Style them from outside, or set the `--nlp-*` variables on the root. */
2
+ export declare const CLASS: {
3
+ readonly root: "nlp";
4
+ readonly excerpt: "nlp-excerpt";
5
+ /** The element an excerpt's shadow tree hangs from: style it (or set `--nlp-*` on it) from the page. */
6
+ readonly shadowHost: "nlp-shadow";
7
+ readonly info: "nlp-info";
8
+ readonly pages: "nlp-pages";
9
+ readonly page: "nlp-page";
10
+ readonly bar: "nlp-bar";
11
+ readonly button: "nlp-button";
12
+ readonly clock: "nlp-clock";
13
+ readonly tempo: "nlp-tempo";
14
+ readonly parts: "nlp-parts";
15
+ readonly part: "nlp-part";
16
+ };
17
+ /** The full player's stylesheet, added to the page; the colors are set on its root by theme. */
18
+ export declare const PLAYER_CSS = "\n.nlp{--nlp-accent:#1e64ef;--nlp-fg:#14171f;--nlp-muted:#5b6172;--nlp-bg:#f1f3f9;--nlp-bar:#ffffff;--nlp-border:#d9dde8;\n--nlp-chord:#b9efc9;--nlp-playing-muted:#d4d6dd;--nlp-orchid:#eba6f5;--nlp-periwinkle:#778eec;--nlp-sky:#83dff6;--nlp-ivory:#eef2df;--nlp-sage:#cada98;}\n.nlp[data-theme=dark]{--nlp-accent:#6b95f5;--nlp-fg:#e7e9f1;--nlp-muted:#9aa1b5;--nlp-bg:#12151e;--nlp-bar:#1b1f2b;--nlp-border:#2c3243;--nlp-playing-muted:#4a4f5e;}\n\n.nlp{display:flex;flex-direction:column;height:30rem;min-height:14rem;overflow:hidden;border-radius:.75rem;border:1px solid var(--nlp-border);\nbackground:var(--nlp-bg);color:var(--nlp-fg);font:14px/1.3 system-ui,-apple-system,\"Segoe UI\",sans-serif}\n.nlp,.nlp *{box-sizing:border-box}\n.nlp svg{max-width:none}\n.nlp-pages{flex:1;min-height:0;overflow:auto;padding:12px;scrollbar-width:thin}\n.nlp-page{display:block;margin:0 auto 12px;width:calc(var(--nlp-zoom,1)*100%);box-shadow:0 1px 3px rgb(0 0 0/.15)}\n.nlp-page svg{display:block;width:100%;height:auto}\n.nlp-bar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;min-height:40px;padding:4px 8px;border-top:1px solid var(--nlp-border);background:var(--nlp-bar)}\n.nlp .nlp-button{display:inline-grid;place-items:center;width:30px;height:30px;min-height:0;margin:0;padding:0;border:0;border-radius:6px;background:none;box-shadow:none;color:var(--nlp-fg);font:inherit;line-height:1;text-transform:none;letter-spacing:normal;cursor:pointer}\n.nlp .nlp-button:hover{background:color-mix(in srgb,var(--nlp-accent) 12%,transparent)}\n.nlp .nlp-button[aria-pressed=true]{color:var(--nlp-accent);background:color-mix(in srgb,var(--nlp-accent) 14%,transparent)}\n.nlp .nlp-button:focus-visible{outline:2px solid var(--nlp-accent);outline-offset:1px}\n.nlp .nlp-button:disabled{opacity:.45;cursor:default}\n.nlp .nlp-button svg{width:18px;height:18px;fill:currentColor}\n.nlp-clock{min-width:5.5em;font:12px ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--nlp-muted)}\n.nlp-tempo{display:flex;align-items:center;gap:4px;color:var(--nlp-muted);font-size:12px}\n.nlp-tempo input{width:4.2em;height:26px;border:1px solid var(--nlp-border);border-radius:6px;background:transparent;color:var(--nlp-fg);padding:0 4px;font:inherit}\n.nlp-parts{display:flex;gap:4px;margin-left:auto;flex-wrap:wrap}\n.nlp-part{display:inline-flex;align-items:center;gap:2px;font-size:12px;color:var(--nlp-muted)}\n.nlp-part button{height:24px;min-width:24px;padding:0 5px;border:1px solid var(--nlp-border);border-radius:5px;background:none;color:inherit;font:inherit;cursor:pointer}\n.nlp-part button[aria-pressed=true]{background:var(--nlp-accent);border-color:var(--nlp-accent);color:#fff}\n.nlp-error{color:#c0392b;font-size:12px}\n.nlp [data-tone=default]{fill:color-mix(in srgb,var(--nlp-accent) 28%,transparent)}\n.nlp [data-tone=orchid]{fill:var(--nlp-orchid)}.nlp [data-tone=periwinkle]{fill:var(--nlp-periwinkle)}\n.nlp [data-tone=sky]{fill:var(--nlp-sky)}.nlp [data-tone=ivory]{fill:var(--nlp-ivory)}.nlp [data-tone=sage]{fill:var(--nlp-sage)}\n.nlp[data-theme=dark] [data-tone=orchid],.nlp[data-theme=dark] [data-tone=periwinkle],.nlp[data-theme=dark] [data-tone=sky],.nlp[data-theme=dark] [data-tone=ivory],.nlp[data-theme=dark] [data-tone=sage]{fill-opacity:.5}\n.nlp [data-tone=muted]{fill:var(--nlp-playing-muted)}\n.nlp [data-cursor-line]{fill:color-mix(in srgb,var(--nlp-accent) 35%,transparent)}\n.nlp [data-playing-chord]{fill:var(--nlp-chord)}\n.nlp[data-theme=dark] [data-playing-chord]{fill-opacity:.45}\n.nlp [data-beat-dot]{fill:var(--nlp-accent)}\n@media (prefers-reduced-motion:no-preference){.nlp [data-beat-dot]{animation:nlp-beat 180ms ease-out;transform-box:fill-box;transform-origin:center}}\n@keyframes nlp-beat{from{transform:scale(1.8);opacity:.6}to{transform:scale(1);opacity:1}}\n";
19
+ /**
20
+ * An excerpt's stylesheet, inside its shadow tree, so the host page's CSS cannot restyle it and it
21
+ * cannot restyle the page. The colors sit on `:host`, which any rule of the page outranks: a page
22
+ * recolors the excerpt with `--nlp-accent` and the rest on `.nlp-shadow`, or `--nlp-ink`.
23
+ */
24
+ export declare const EXCERPT_CSS = "\n:host{all:initial;display:block;max-width:100%;margin:1.25em 0;--nlp-accent:#1e64ef;--nlp-fg:#14171f;--nlp-muted:#5b6172;--nlp-bg:#f1f3f9;--nlp-bar:#ffffff;--nlp-border:#d9dde8;\n--nlp-chord:#b9efc9;--nlp-playing-muted:#d4d6dd;--nlp-orchid:#eba6f5;--nlp-periwinkle:#778eec;--nlp-sky:#83dff6;--nlp-ivory:#eef2df;--nlp-sage:#cada98;--nlp-ink:var(--nlp-fg);--nlp-rule:var(--nlp-muted);}\n:host([data-theme=dark]){--nlp-accent:#6b95f5;--nlp-fg:#e7e9f1;--nlp-muted:#9aa1b5;--nlp-bg:#12151e;--nlp-bar:#1b1f2b;--nlp-border:#2c3243;--nlp-playing-muted:#4a4f5e;}\n\n.nlp{display:flex;flex-direction:column;height:30rem;min-height:14rem;overflow:hidden;border-radius:.75rem;border:1px solid var(--nlp-border);\nbackground:var(--nlp-bg);color:var(--nlp-fg);font:14px/1.3 system-ui,-apple-system,\"Segoe UI\",sans-serif}\n.nlp,.nlp *{box-sizing:border-box}\n.nlp svg{max-width:none}\n.nlp-pages{flex:1;min-height:0;overflow:auto;padding:12px;scrollbar-width:thin}\n.nlp-page{display:block;margin:0 auto 12px;width:calc(var(--nlp-zoom,1)*100%);box-shadow:0 1px 3px rgb(0 0 0/.15)}\n.nlp-page svg{display:block;width:100%;height:auto}\n.nlp-bar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;min-height:40px;padding:4px 8px;border-top:1px solid var(--nlp-border);background:var(--nlp-bar)}\n.nlp .nlp-button{display:inline-grid;place-items:center;width:30px;height:30px;min-height:0;margin:0;padding:0;border:0;border-radius:6px;background:none;box-shadow:none;color:var(--nlp-fg);font:inherit;line-height:1;text-transform:none;letter-spacing:normal;cursor:pointer}\n.nlp .nlp-button:hover{background:color-mix(in srgb,var(--nlp-accent) 12%,transparent)}\n.nlp .nlp-button[aria-pressed=true]{color:var(--nlp-accent);background:color-mix(in srgb,var(--nlp-accent) 14%,transparent)}\n.nlp .nlp-button:focus-visible{outline:2px solid var(--nlp-accent);outline-offset:1px}\n.nlp .nlp-button:disabled{opacity:.45;cursor:default}\n.nlp .nlp-button svg{width:18px;height:18px;fill:currentColor}\n.nlp-clock{min-width:5.5em;font:12px ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--nlp-muted)}\n.nlp-tempo{display:flex;align-items:center;gap:4px;color:var(--nlp-muted);font-size:12px}\n.nlp-tempo input{width:4.2em;height:26px;border:1px solid var(--nlp-border);border-radius:6px;background:transparent;color:var(--nlp-fg);padding:0 4px;font:inherit}\n.nlp-parts{display:flex;gap:4px;margin-left:auto;flex-wrap:wrap}\n.nlp-part{display:inline-flex;align-items:center;gap:2px;font-size:12px;color:var(--nlp-muted)}\n.nlp-part button{height:24px;min-width:24px;padding:0 5px;border:1px solid var(--nlp-border);border-radius:5px;background:none;color:inherit;font:inherit;cursor:pointer}\n.nlp-part button[aria-pressed=true]{background:var(--nlp-accent);border-color:var(--nlp-accent);color:#fff}\n.nlp-error{color:#c0392b;font-size:12px}\n.nlp [data-tone=default]{fill:color-mix(in srgb,var(--nlp-accent) 28%,transparent)}\n.nlp [data-tone=orchid]{fill:var(--nlp-orchid)}.nlp [data-tone=periwinkle]{fill:var(--nlp-periwinkle)}\n.nlp [data-tone=sky]{fill:var(--nlp-sky)}.nlp [data-tone=ivory]{fill:var(--nlp-ivory)}.nlp [data-tone=sage]{fill:var(--nlp-sage)}\n.nlp[data-theme=dark] [data-tone=orchid],.nlp[data-theme=dark] [data-tone=periwinkle],.nlp[data-theme=dark] [data-tone=sky],.nlp[data-theme=dark] [data-tone=ivory],.nlp[data-theme=dark] [data-tone=sage]{fill-opacity:.5}\n.nlp [data-tone=muted]{fill:var(--nlp-playing-muted)}\n.nlp [data-cursor-line]{fill:color-mix(in srgb,var(--nlp-accent) 35%,transparent)}\n.nlp [data-playing-chord]{fill:var(--nlp-chord)}\n.nlp[data-theme=dark] [data-playing-chord]{fill-opacity:.45}\n.nlp [data-beat-dot]{fill:var(--nlp-accent)}\n@media (prefers-reduced-motion:no-preference){.nlp [data-beat-dot]{animation:nlp-beat 180ms ease-out;transform-box:fill-box;transform-origin:center}}\n@keyframes nlp-beat{from{transform:scale(1.8);opacity:.6}to{transform:scale(1);opacity:1}}\n\n.nlp-excerpt{height:auto;min-height:0;max-width:100%;border-radius:14px;border-color:color-mix(in srgb,var(--nlp-accent) 28%,var(--nlp-border));\nbackground:var(--nlp-bar);\nbox-shadow:0 1px 2px rgb(0 0 0/.04),0 8px 24px -12px color-mix(in srgb,var(--nlp-accent) 35%,transparent)}\n.nlp-excerpt .nlp-info{padding:12px 14px 0;font:500 12px/1.5 \"Plus Jakarta Sans\",ui-sans-serif,system-ui,sans-serif;color:var(--nlp-fg)}\n.nlp-excerpt .nlp-pages{flex:none;overflow:visible;padding:4px 14px 0}\n.nlp-excerpt .nlp-page{margin:0;box-shadow:none}\n.nlp-excerpt .nlp-bar{gap:8px;min-height:34px;padding:4px 14px 8px;border-top:0;background:none}\n.nlp.nlp-excerpt .nlp-button{width:24px;height:24px;border-radius:50%;background:color-mix(in srgb,var(--nlp-accent) 10%,transparent);color:var(--nlp-accent)}\n.nlp.nlp-excerpt .nlp-button:hover{background:color-mix(in srgb,var(--nlp-accent) 20%,transparent)}\n.nlp.nlp-excerpt .nlp-button svg{width:13px;height:13px}\n.nlp.nlp-excerpt .nlp-bar .nlp-button:first-child{background:var(--nlp-accent);color:#fff;box-shadow:0 2px 6px color-mix(in srgb,var(--nlp-accent) 45%,transparent)}\n.nlp.nlp-excerpt .nlp-bar .nlp-button:first-child:hover{background:color-mix(in srgb,var(--nlp-accent) 88%,#000)}\n.nlp-excerpt .nlp-clock{font-size:12px;min-width:5em}\n";
25
+ /** Adds a `<style>` with this id to the page head, once (a second player on the page reuses it). */
26
+ export declare function addStyleOnce(doc: Document, id: string, css: string): void;
27
+ /** Adds the full player's stylesheet to the page once. */
28
+ export declare const injectStyles: (doc: Document) => void;
@@ -0,0 +1,98 @@
1
+ /** Class names the player uses. Style them from outside, or set the `--nlp-*` variables on the root. */
2
+ export const CLASS = {
3
+ root: "nlp",
4
+ excerpt: "nlp-excerpt",
5
+ /** The element an excerpt's shadow tree hangs from: style it (or set `--nlp-*` on it) from the page. */
6
+ shadowHost: "nlp-shadow",
7
+ info: "nlp-info",
8
+ pages: "nlp-pages",
9
+ page: "nlp-page",
10
+ bar: "nlp-bar",
11
+ button: "nlp-button",
12
+ clock: "nlp-clock",
13
+ tempo: "nlp-tempo",
14
+ parts: "nlp-parts",
15
+ part: "nlp-part",
16
+ };
17
+ const STYLE_ID = "nodelyra-player-styles";
18
+ /** The colors, light and dark. Variables, so a page can restyle the player without touching it. */
19
+ const LIGHT_VARS = `--nlp-accent:#1e64ef;--nlp-fg:#14171f;--nlp-muted:#5b6172;--nlp-bg:#f1f3f9;--nlp-bar:#ffffff;--nlp-border:#d9dde8;
20
+ --nlp-chord:#b9efc9;--nlp-playing-muted:#d4d6dd;--nlp-orchid:#eba6f5;--nlp-periwinkle:#778eec;--nlp-sky:#83dff6;--nlp-ivory:#eef2df;--nlp-sage:#cada98;`;
21
+ const DARK_VARS = `--nlp-accent:#6b95f5;--nlp-fg:#e7e9f1;--nlp-muted:#9aa1b5;--nlp-bg:#12151e;--nlp-bar:#1b1f2b;--nlp-border:#2c3243;--nlp-playing-muted:#4a4f5e;`;
22
+ /** The notation is drawn in the text and muted colors, as the editor draws it (set `--nlp-ink` or `--nlp-rule` to choose others). */
23
+ const EXCERPT_VARS = `--nlp-ink:var(--nlp-fg);--nlp-rule:var(--nlp-muted);`;
24
+ /** Everything that is not a color value: layout, controls, playing marks (shared by the player and the excerpt). */
25
+ const SHARED_RULES = `
26
+ .nlp{display:flex;flex-direction:column;height:30rem;min-height:14rem;overflow:hidden;border-radius:.75rem;border:1px solid var(--nlp-border);
27
+ background:var(--nlp-bg);color:var(--nlp-fg);font:14px/1.3 system-ui,-apple-system,"Segoe UI",sans-serif}
28
+ .nlp,.nlp *{box-sizing:border-box}
29
+ .nlp svg{max-width:none}
30
+ .nlp-pages{flex:1;min-height:0;overflow:auto;padding:12px;scrollbar-width:thin}
31
+ .nlp-page{display:block;margin:0 auto 12px;width:calc(var(--nlp-zoom,1)*100%);box-shadow:0 1px 3px rgb(0 0 0/.15)}
32
+ .nlp-page svg{display:block;width:100%;height:auto}
33
+ .nlp-bar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;min-height:40px;padding:4px 8px;border-top:1px solid var(--nlp-border);background:var(--nlp-bar)}
34
+ .nlp .nlp-button{display:inline-grid;place-items:center;width:30px;height:30px;min-height:0;margin:0;padding:0;border:0;border-radius:6px;background:none;box-shadow:none;color:var(--nlp-fg);font:inherit;line-height:1;text-transform:none;letter-spacing:normal;cursor:pointer}
35
+ .nlp .nlp-button:hover{background:color-mix(in srgb,var(--nlp-accent) 12%,transparent)}
36
+ .nlp .nlp-button[aria-pressed=true]{color:var(--nlp-accent);background:color-mix(in srgb,var(--nlp-accent) 14%,transparent)}
37
+ .nlp .nlp-button:focus-visible{outline:2px solid var(--nlp-accent);outline-offset:1px}
38
+ .nlp .nlp-button:disabled{opacity:.45;cursor:default}
39
+ .nlp .nlp-button svg{width:18px;height:18px;fill:currentColor}
40
+ .nlp-clock{min-width:5.5em;font:12px ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--nlp-muted)}
41
+ .nlp-tempo{display:flex;align-items:center;gap:4px;color:var(--nlp-muted);font-size:12px}
42
+ .nlp-tempo input{width:4.2em;height:26px;border:1px solid var(--nlp-border);border-radius:6px;background:transparent;color:var(--nlp-fg);padding:0 4px;font:inherit}
43
+ .nlp-parts{display:flex;gap:4px;margin-left:auto;flex-wrap:wrap}
44
+ .nlp-part{display:inline-flex;align-items:center;gap:2px;font-size:12px;color:var(--nlp-muted)}
45
+ .nlp-part button{height:24px;min-width:24px;padding:0 5px;border:1px solid var(--nlp-border);border-radius:5px;background:none;color:inherit;font:inherit;cursor:pointer}
46
+ .nlp-part button[aria-pressed=true]{background:var(--nlp-accent);border-color:var(--nlp-accent);color:#fff}
47
+ .nlp-error{color:#c0392b;font-size:12px}
48
+ .nlp [data-tone=default]{fill:color-mix(in srgb,var(--nlp-accent) 28%,transparent)}
49
+ .nlp [data-tone=orchid]{fill:var(--nlp-orchid)}.nlp [data-tone=periwinkle]{fill:var(--nlp-periwinkle)}
50
+ .nlp [data-tone=sky]{fill:var(--nlp-sky)}.nlp [data-tone=ivory]{fill:var(--nlp-ivory)}.nlp [data-tone=sage]{fill:var(--nlp-sage)}
51
+ .nlp[data-theme=dark] [data-tone=orchid],.nlp[data-theme=dark] [data-tone=periwinkle],.nlp[data-theme=dark] [data-tone=sky],.nlp[data-theme=dark] [data-tone=ivory],.nlp[data-theme=dark] [data-tone=sage]{fill-opacity:.5}
52
+ .nlp [data-tone=muted]{fill:var(--nlp-playing-muted)}
53
+ .nlp [data-cursor-line]{fill:color-mix(in srgb,var(--nlp-accent) 35%,transparent)}
54
+ .nlp [data-playing-chord]{fill:var(--nlp-chord)}
55
+ .nlp[data-theme=dark] [data-playing-chord]{fill-opacity:.45}
56
+ .nlp [data-beat-dot]{fill:var(--nlp-accent)}
57
+ @media (prefers-reduced-motion:no-preference){.nlp [data-beat-dot]{animation:nlp-beat 180ms ease-out;transform-box:fill-box;transform-origin:center}}
58
+ @keyframes nlp-beat{from{transform:scale(1.8);opacity:.6}to{transform:scale(1);opacity:1}}
59
+ `;
60
+ /** The full player's stylesheet, added to the page; the colors are set on its root by theme. */
61
+ export const PLAYER_CSS = `
62
+ .nlp{${LIGHT_VARS}}
63
+ .nlp[data-theme=dark]{${DARK_VARS}}
64
+ ${SHARED_RULES}`;
65
+ /**
66
+ * An excerpt's stylesheet, inside its shadow tree, so the host page's CSS cannot restyle it and it
67
+ * cannot restyle the page. The colors sit on `:host`, which any rule of the page outranks: a page
68
+ * recolors the excerpt with `--nlp-accent` and the rest on `.nlp-shadow`, or `--nlp-ink`.
69
+ */
70
+ export const EXCERPT_CSS = `
71
+ :host{all:initial;display:block;max-width:100%;margin:1.25em 0;${LIGHT_VARS}${EXCERPT_VARS}}
72
+ :host([data-theme=dark]){${DARK_VARS}}
73
+ ${SHARED_RULES}
74
+ .nlp-excerpt{height:auto;min-height:0;max-width:100%;border-radius:14px;border-color:color-mix(in srgb,var(--nlp-accent) 28%,var(--nlp-border));
75
+ background:var(--nlp-bar);
76
+ box-shadow:0 1px 2px rgb(0 0 0/.04),0 8px 24px -12px color-mix(in srgb,var(--nlp-accent) 35%,transparent)}
77
+ .nlp-excerpt .nlp-info{padding:12px 14px 0;font:500 12px/1.5 "Plus Jakarta Sans",ui-sans-serif,system-ui,sans-serif;color:var(--nlp-fg)}
78
+ .nlp-excerpt .nlp-pages{flex:none;overflow:visible;padding:4px 14px 0}
79
+ .nlp-excerpt .nlp-page{margin:0;box-shadow:none}
80
+ .nlp-excerpt .nlp-bar{gap:8px;min-height:34px;padding:4px 14px 8px;border-top:0;background:none}
81
+ .nlp.nlp-excerpt .nlp-button{width:24px;height:24px;border-radius:50%;background:color-mix(in srgb,var(--nlp-accent) 10%,transparent);color:var(--nlp-accent)}
82
+ .nlp.nlp-excerpt .nlp-button:hover{background:color-mix(in srgb,var(--nlp-accent) 20%,transparent)}
83
+ .nlp.nlp-excerpt .nlp-button svg{width:13px;height:13px}
84
+ .nlp.nlp-excerpt .nlp-bar .nlp-button:first-child{background:var(--nlp-accent);color:#fff;box-shadow:0 2px 6px color-mix(in srgb,var(--nlp-accent) 45%,transparent)}
85
+ .nlp.nlp-excerpt .nlp-bar .nlp-button:first-child:hover{background:color-mix(in srgb,var(--nlp-accent) 88%,#000)}
86
+ .nlp-excerpt .nlp-clock{font-size:12px;min-width:5em}
87
+ `;
88
+ /** Adds a `<style>` with this id to the page head, once (a second player on the page reuses it). */
89
+ export function addStyleOnce(doc, id, css) {
90
+ if (doc.getElementById(id))
91
+ return;
92
+ const style = doc.createElement("style");
93
+ style.id = id;
94
+ style.textContent = css;
95
+ doc.head.append(style);
96
+ }
97
+ /** Adds the full player's stylesheet to the page once. */
98
+ export const injectStyles = (doc) => addStyleOnce(doc, STYLE_ID, PLAYER_CSS);
@@ -0,0 +1,8 @@
1
+ import type { SvgStyle } from "../export/svgExport.js";
2
+ export type Theme = "light" | "dark" | "auto";
3
+ /** The colors the score is drawn in (ink and paper), for a theme already resolved to light or dark. */
4
+ export declare const SCORE_STYLES: Record<Exclude<Theme, "auto">, SvgStyle>;
5
+ /** An excerpt's ink and rules are CSS variables of the player, so the page can recolor it and a theme change needs no redraw. */
6
+ export declare const EXCERPT_STYLE: SvgStyle;
7
+ /** "auto" follows the visitor's system setting at the time the player is made. */
8
+ export declare function resolveTheme(theme: Theme, prefersDark: () => boolean): Exclude<Theme, "auto">;
@@ -0,0 +1,13 @@
1
+ /** The colors the score is drawn in (ink and paper), for a theme already resolved to light or dark. */
2
+ export const SCORE_STYLES = {
3
+ light: { ink: "#14171f", rule: "#5b6172", page: "#ffffff" },
4
+ dark: { ink: "#e7e9f1", rule: "#9aa1b5", page: "#1b1f2b" },
5
+ };
6
+ /** An excerpt's ink and rules are CSS variables of the player, so the page can recolor it and a theme change needs no redraw. */
7
+ export const EXCERPT_STYLE = { ink: "var(--nlp-ink,#14171f)", rule: "var(--nlp-rule,#5b6172)", page: "transparent" };
8
+ /** "auto" follows the visitor's system setting at the time the player is made. */
9
+ export function resolveTheme(theme, prefersDark) {
10
+ if (theme !== "auto")
11
+ return theme;
12
+ return prefersDark() ? "dark" : "light";
13
+ }
@@ -0,0 +1,76 @@
1
+ import type { PlayerState } from "../playback/createPlayerStore.js";
2
+ import type { VolumeChannel } from "../playback/volume.js";
3
+ import type { Theme } from "./theme.js";
4
+ /** What a listener can see of the player: where it is, what it plays, how it is set. */
5
+ export type PlayerSnapshot = Pick<PlayerState, "status" | "message" | "position" | "duration" | "tempo" | "loop" | "metronome" | "mix" | "volumes" | "partVolumes" | "ends">;
6
+ /** What a person can do with a player (the control bar uses only this). */
7
+ export interface PlayerControls {
8
+ play(): Promise<void>;
9
+ pause(): void;
10
+ resume(): void;
11
+ stop(): void;
12
+ setTempo(bpm: number | null): void;
13
+ setLoop(on: boolean): void;
14
+ setMetronome(on: boolean): void;
15
+ toggleMute(partId: string): void;
16
+ toggleSolo(partId: string): void;
17
+ }
18
+ export interface ScorePlayer extends PlayerControls {
19
+ /** The current state; also delivered to `subscribe`rs as it changes. */
20
+ readonly snapshot: PlayerSnapshot;
21
+ /** The parts of the score, for building your own mixer. */
22
+ readonly parts: readonly {
23
+ id: string;
24
+ name: string;
25
+ }[];
26
+ /** Play, pause or resume, whichever comes next. */
27
+ toggle(): void;
28
+ /** Turn the music or the metronome up or down (0..1); applies at once, also while playing. */
29
+ setVolume(channel: VolumeChannel, level: number): void;
30
+ /** Turn one part up or down (0..1) within the music; applies at once, also while playing. */
31
+ setPartVolume(partId: string, level: number): void;
32
+ /** Scale the pages: 1 fits the player's width, 2 is twice as wide (the pages then scroll sideways). */
33
+ setZoom(zoom: number): void;
34
+ /** Switch between the light and dark look (the pages are redrawn; "auto" follows the visitor's setting). */
35
+ setTheme(theme: Theme): void;
36
+ subscribe(listener: (snapshot: PlayerSnapshot) => void): () => void;
37
+ /** Show another score (stops playing). Throws `ScoreFormatError` for JSON that cannot be drawn. */
38
+ update(score: import("../schema/scoreJson.js").ScoreJson): void;
39
+ /** Stop, release the sound device and remove the player from the page. */
40
+ destroy(): void;
41
+ }
42
+ /** The words on the controls; translate them by passing your own. */
43
+ export type PlayerLabels = {
44
+ play: string;
45
+ pause: string;
46
+ stop: string;
47
+ loop: string;
48
+ metronome: string;
49
+ tempo: string;
50
+ mute: string;
51
+ solo: string;
52
+ parts: string;
53
+ failed: string;
54
+ };
55
+ export declare const DEFAULT_LABELS: PlayerLabels;
56
+ export type PlayerOptions = {
57
+ /** "auto" (default) follows the visitor's light or dark setting. */
58
+ theme?: Theme;
59
+ /** Show the control bar (default true). Without it, drive the player with its methods. */
60
+ controls?: boolean;
61
+ /** CSS height of the player (default "30rem"); the pages scroll inside it. */
62
+ height?: string;
63
+ /** Start with loop on (default false). */
64
+ loop?: boolean;
65
+ /** Start with the metronome on (default false). */
66
+ metronome?: boolean;
67
+ /** Accessible name of the player (default "Score player"). */
68
+ label?: string;
69
+ /** Start at this tempo instead of the score's (BPM). */
70
+ tempo?: number;
71
+ /** Start with the pages scaled (default 1: the player's width). */
72
+ zoom?: number;
73
+ labels?: Partial<PlayerLabels>;
74
+ /** Load the editor's fonts (default true). Set false when your page already sets the notation in its own fonts. */
75
+ fonts?: boolean;
76
+ };
@@ -0,0 +1,12 @@
1
+ export const DEFAULT_LABELS = {
2
+ play: "Play",
3
+ pause: "Pause",
4
+ stop: "Stop",
5
+ loop: "Loop",
6
+ metronome: "Metronome",
7
+ tempo: "Tempo (BPM)",
8
+ mute: "Mute",
9
+ solo: "Solo",
10
+ parts: "Parts",
11
+ failed: "This score could not be played.",
12
+ };
@@ -0,0 +1,6 @@
1
+ import type { ScoreMusic } from "../schema/types.js";
2
+ import type { PlacedSystem } from "../layout/LayoutEngine.js";
3
+ import { type NotationProfile } from "../notation/profile.js";
4
+ import type { Primitive } from "./primitives.js";
5
+ /** Everything drawn for one system, in system coordinates. */
6
+ export declare function renderSystem(system: PlacedSystem, music: ScoreMusic, profile?: NotationProfile): Primitive[];
@@ -0,0 +1,58 @@
1
+ import { NOT_ANGKA } from "../notation/profile.js";
2
+ import { renderArc } from "./arcRenderer.js";
3
+ import { drawnBarline, drawnRepeatStart } from "../layout/barlineShapes.js";
4
+ import { octaveShiftOf } from "../model/lowVoices.js";
5
+ import { drawnIn } from "../model/rowPresence.js";
6
+ import { renderBarlines } from "./barlineRenderer.js";
7
+ import { renderTextBar } from "./textBarRenderer.js";
8
+ import { renderKeyBox } from "./keyMarkRenderer.js";
9
+ import { renderDirections } from "./directionRenderer.js";
10
+ import { isTextBar } from "../model/textBars.js";
11
+ import { renderDurationLines } from "./durationLineRenderer.js";
12
+ import { renderTuplets } from "./tupletRenderer.js";
13
+ import { renderFrame, renderMarkings } from "./frameRenderer.js";
14
+ import { renderLyrics } from "./lyricsRenderer.js";
15
+ import { renderBlankMeasure, renderSlices } from "./sliceRenderer.js";
16
+ const notes = (system, music, profile) => system.rows.flatMap((row) => {
17
+ // A low voice (tenor, baritone, bass) is drawn an octave up: its dots shift, its notes do not.
18
+ const shift = octaveShiftOf(music.parts[row.partIndex], system.lowVoicesUp);
19
+ return row.measures.flatMap((m) => [
20
+ ...renderSlices(row, m, music.parts[row.partIndex].measures[m.measureIndex].events, profile, shift),
21
+ ...renderBlankMeasure(row, m, profile),
22
+ ...renderDurationLines(row, m, profile),
23
+ ...renderTuplets(row, m),
24
+ ]);
25
+ });
26
+ const barlines = (system, music) => system.rows.flatMap((row, index) => system.measures.flatMap((bounds, i) => {
27
+ // A part's row is blank outside the bars it plays, and where it is merged into the row
28
+ // above or hidden (ADR 0012, 0013): no bar lines there either.
29
+ if (!drawnIn(music, music.parts[row.partIndex], bounds.measureIndex))
30
+ return [];
31
+ const barline = drawnBarline(music, system.measures, i);
32
+ const start = drawnRepeatStart(music, system.measures, i);
33
+ // A text bar spans the whole system: the bar lines around it run through the lyrics.
34
+ const next = system.measures[i + 1];
35
+ const bordersText = isTextBar(music.measures[bounds.measureIndex]) || (next ? isTextBar(music.measures[next.measureIndex]) : false);
36
+ return renderBarlines(system.rows, index, bounds, barline, start, bordersText);
37
+ }));
38
+ const textBars = (system, music) => system.measures.flatMap((bounds) => renderTextBar(music, system.rows, bounds));
39
+ const keyBoxes = (system, _music, profile) => system.measures.flatMap((bounds) => renderKeyBox(system.rows, bounds, profile));
40
+ /**
41
+ * The drawing of a system, layer by layer (PRD FR-069..FR-073). Each layer is a pure renderer;
42
+ * add a notation element by adding a layer, not by editing the others.
43
+ */
44
+ const LAYERS = [
45
+ (system, music) => renderFrame(system, system.bracket ?? true, music.parts.filter((p) => p.visible).length),
46
+ (system) => renderMarkings(system.markings, system.headroom),
47
+ notes,
48
+ textBars,
49
+ keyBoxes,
50
+ barlines,
51
+ (system, _music, profile) => system.arcs.map((arc) => renderArc(arc, profile)),
52
+ (system) => renderDirections(system.directions),
53
+ (system) => renderLyrics(system.lyrics),
54
+ ];
55
+ /** Everything drawn for one system, in system coordinates. */
56
+ export function renderSystem(system, music, profile = NOT_ANGKA) {
57
+ return LAYERS.flatMap((layer) => layer(system, music, profile));
58
+ }
@@ -0,0 +1,4 @@
1
+ import type { AccidentalMark } from "../notation/profile.js";
2
+ import type { Primitive } from "./primitives.js";
3
+ /** The accidental of the note whose digit is centred at `x`, as the profile writes it. */
4
+ export declare function renderAccidental(mark: AccidentalMark, x: number, noteY: number, owner: string): Primitive[];
@@ -0,0 +1,41 @@
1
+ import { NOTATION } from "../layout/notationMetrics.js";
2
+ /** One renderer per way of writing an accidental; a new kind is a compile error until it has one. */
3
+ const ACCIDENTAL_RENDERERS = {
4
+ // A stroke through the digit, a little longer than it: "/" rises left to right, "\" falls.
5
+ stroke: (mark, x, noteY, owner) => {
6
+ const dy = mark.direction === "rising" ? NOTATION.strokeHalfHeight : -NOTATION.strokeHalfHeight;
7
+ return [
8
+ {
9
+ kind: "line",
10
+ role: "accidental",
11
+ owner,
12
+ x1: x - NOTATION.strokeHalfWidth,
13
+ y1: noteY + dy,
14
+ x2: x + NOTATION.strokeHalfWidth,
15
+ y2: noteY - dy,
16
+ width: NOTATION.strokeWidth,
17
+ tone: "ink",
18
+ },
19
+ ];
20
+ },
21
+ // A small glyph before the digit, raised (♯, ♭).
22
+ glyph: (mark, x, noteY, owner) => [
23
+ {
24
+ kind: "text",
25
+ role: "accidental",
26
+ owner,
27
+ x: x - 7,
28
+ y: noteY - 5,
29
+ text: mark.text,
30
+ size: NOTATION.accidentalSize,
31
+ anchor: "middle",
32
+ font: "text",
33
+ tone: "ink",
34
+ },
35
+ ],
36
+ };
37
+ /** The accidental of the note whose digit is centred at `x`, as the profile writes it. */
38
+ export function renderAccidental(mark, x, noteY, owner) {
39
+ const render = ACCIDENTAL_RENDERERS[mark.kind];
40
+ return render(mark, x, noteY, owner);
41
+ }
@@ -0,0 +1,9 @@
1
+ import type { Arc } from "../layout/arcs.js";
2
+ import type { NotationProfile } from "../notation/profile.js";
3
+ import type { Primitive } from "./primitives.js";
4
+ /**
5
+ * A tie or slur as a curve between its two notes. Half of an arc broken by a system break leaves
6
+ * its note the same way and reaches the system edge at its lowest point, running flat: the two
7
+ * halves read as one arc cut in the middle.
8
+ */
9
+ export declare function renderArc(arc: Arc, profile: NotationProfile): Primitive;
@@ -0,0 +1,32 @@
1
+ import { NOTATION } from "../layout/notationMetrics.js";
2
+ /** How deep a whole arc's lowest point sits below its ends: 3/4 of its control-point dip. */
3
+ const DIP_SCALE = 1.35;
4
+ /**
5
+ * A tie or slur as a curve between its two notes. Half of an arc broken by a system break leaves
6
+ * its note the same way and reaches the system edge at its lowest point, running flat: the two
7
+ * halves read as one arc cut in the middle.
8
+ */
9
+ export function renderArc(arc, profile) {
10
+ const side = profile.arcs === "below" ? 1 : -1;
11
+ const y = side > 0 ? arc.y : arc.y - 2 * NOTATION.arcOffset;
12
+ const dip = y + side * NOTATION.arcDepth * DIP_SCALE;
13
+ const bottom = y + side * NOTATION.arcDepth * DIP_SCALE * 0.75;
14
+ const span = arc.x2 - arc.x1;
15
+ const pull = Math.min(10, Math.max(2, span / 3));
16
+ return {
17
+ kind: "path",
18
+ role: arc.kind,
19
+ owner: arc.owner,
20
+ d: arcPath(arc, y, dip, bottom, pull, span),
21
+ width: 0.9,
22
+ tone: "ink",
23
+ };
24
+ }
25
+ function arcPath(arc, y, dip, bottom, pull, span) {
26
+ const { x1, x2 } = arc;
27
+ if (arc.openEnd)
28
+ return `M ${x1} ${y} C ${x1 + pull} ${dip}, ${x1 + span / 2} ${bottom}, ${x2} ${bottom}`;
29
+ if (arc.openStart)
30
+ return `M ${x1} ${bottom} C ${x2 - span / 2} ${bottom}, ${x2 - pull} ${dip}, ${x2} ${y}`;
31
+ return `M ${x1} ${y} C ${x1 + pull} ${dip}, ${x2 - pull} ${dip}, ${x2} ${y}`;
32
+ }