@dsebastien/music-notation 0.18.0 → 0.19.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.
@@ -27,6 +27,14 @@ export declare const uniqueId: () => string;
27
27
  * show no hover tooltip for it: the diagram's visible title already says what it is.
28
28
  */
29
29
  export declare function svgRoot(doc: Document, width: number, height: number, cls: string, label: string): SVGElement;
30
+ /**
31
+ * Adds a description to a diagram made by `svgRoot` (#14): a `<desc>` in its `<defs>`, pointed at
32
+ * by `aria-describedby`, that says what the drawing shows (screen readers read it after the name).
33
+ * Nothing for an empty text.
34
+ */
35
+ export declare function describeDiagram(diagram: SVGElement, text: string): void;
36
+ /** A diagram's description (#14), when it has one. */
37
+ export declare function descriptionOf(diagram: Element): string | null;
30
38
  /** A diagram's name for screen readers (its `aria-labelledby` text, else its `aria-label`). */
31
39
  export declare function accessibleName(el: Element): string | null;
32
40
  /** Renames a diagram made by `svgRoot` (or any element named with `aria-label`). */
@@ -0,0 +1,29 @@
1
+ export type RootMark = 'color' | 'shape';
2
+ export declare const ROOT_MARKS: readonly RootMark[];
3
+ /** A root mark given by an app (any value): a valid one, else null. */
4
+ export declare function rootMarkOf(value: unknown): RootMark | null;
5
+ /** A block's `root-mark:` value; throws what to write otherwise. */
6
+ export declare function parseRootMark(text: string): RootMark;
7
+ /**
8
+ * A block's `root-mark:` line (the last one wins), taken out of its source so the diagrams never
9
+ * see it; null mark without one. Throws what to write for a wrong value.
10
+ */
11
+ export declare function rootMarkInBlock(language: string, text: string): {
12
+ text: string;
13
+ mark: RootMark | null;
14
+ };
15
+ /** Draws under a root mark: the renderers called inside `draw` use it. Color again after. */
16
+ export declare function withRootMark<T>(mark: RootMark, draw: () => T): T;
17
+ /** True while drawing roots as shapes. */
18
+ export declare const rootAsShape: () => boolean;
19
+ type Attributes = Record<string, string | number | undefined>;
20
+ /**
21
+ * A note mark: a circle, or (a root, drawing roots as shapes) a rounded square of the circle's
22
+ * area, with the same classes and data attributes plus `mn-root-shape`.
23
+ */
24
+ export declare function noteMark(doc: Document, root: boolean, { cx, cy, r, class: cls, ...rest }: Attributes & {
25
+ cx: number;
26
+ cy: number;
27
+ r: number;
28
+ }): SVGElement;
29
+ export {};
package/dist/tab/index.js CHANGED
@@ -842,6 +842,28 @@ function svgRoot(doc, width, height, cls, label) {
842
842
  "aria-labelledby": id
843
843
  }, [svg(doc, "defs", {}, [title])]);
844
844
  }
845
+ function describeDiagram(diagram, text) {
846
+ if (!text)
847
+ return;
848
+ const defs = [...diagram.children].find((c) => c.tagName.toLowerCase() === "defs");
849
+ if (!defs)
850
+ return;
851
+ const id = `${NAME_PREFIX}${++names}`;
852
+ const desc = svg(diagram.ownerDocument, "desc", { class: "mn-desc", id });
853
+ desc.textContent = text;
854
+ defs.appendChild(desc);
855
+ diagram.setAttribute("aria-describedby", id);
856
+ }
857
+ function descriptionOf(diagram) {
858
+ const id = diagram.getAttribute("aria-describedby");
859
+ if (!id)
860
+ return null;
861
+ for (const candidate of diagram.querySelectorAll("desc")) {
862
+ if (candidate.getAttribute("id") === id)
863
+ return candidate.textContent;
864
+ }
865
+ return null;
866
+ }
845
867
  var nameElement = (el) => {
846
868
  const id = el.getAttribute("aria-labelledby");
847
869
  if (!id)
@@ -1778,9 +1800,10 @@ var ICONS = {
1778
1800
  all: "M1.5 2.5v11l6.5-5.5zM8 2.5v11l6.5-5.5z",
1779
1801
  loop: "M3 8a5 5 0 0 1 8.5-3.5L13 6V2.5M13 8a5 5 0 0 1-8.5 3.5L3 10v3.5",
1780
1802
  count: "M5.5 14h5L9 2.5H7zM8 11.5l4.5-7",
1781
- click: "M3 5v6M8 5v6M13 5v6"
1803
+ click: "M3 5v6M8 5v6M13 5v6",
1804
+ copy: "M2.5 3.5h11v9h-11zM2.5 11l3.5-3.5 3 3 2-2 2.5 2.5M10.5 6.5h.01"
1782
1805
  };
1783
- var STROKED = new Set(["loop", "count", "click"]);
1806
+ var STROKED = new Set(["loop", "count", "click", "copy"]);
1784
1807
  function icon(doc, name) {
1785
1808
  const root = svg(doc, "svg", {
1786
1809
  class: `mn-play-icon mn-play-icon-${name}${STROKED.has(name) ? " mn-play-icon-line" : ""}`,
@@ -1799,6 +1822,19 @@ function playBar(doc, cls, label) {
1799
1822
  bar.setAttribute("aria-label", label);
1800
1823
  return bar;
1801
1824
  }
1825
+ function placeBar(block, last, bar) {
1826
+ if (last.parentElement?.classList.contains("mn-exercise-block")) {
1827
+ last.after(bar);
1828
+ return;
1829
+ }
1830
+ let node = last;
1831
+ while (node.parentElement && node.parentElement !== block)
1832
+ node = node.parentElement;
1833
+ if (node.parentElement === block)
1834
+ node.after(bar);
1835
+ else
1836
+ block.appendChild(bar);
1837
+ }
1802
1838
  function iconButton(doc, cls, label, name) {
1803
1839
  const button = html(doc, "button", cls);
1804
1840
  button.type = "button";
@@ -1875,7 +1911,9 @@ function volumeOf(volume) {
1875
1911
  }
1876
1912
 
1877
1913
  // src/playback/live-volume.ts
1878
- var listeners = new Set;
1914
+ var REGISTRY = Symbol.for("@dsebastien/music-notation/volume");
1915
+ var shared = globalThis;
1916
+ var listeners = shared[REGISTRY] ??= new Set;
1879
1917
  var level = (value) => typeof value === "number" && Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : null;
1880
1918
  function volumeChanged() {
1881
1919
  for (const listener of [...listeners]) {
@@ -2599,5 +2637,5 @@ export {
2599
2637
  textTabToAlphaTex
2600
2638
  };
2601
2639
 
2602
- //# debugId=10B85D48D2B2B5E264756E2164756E21
2640
+ //# debugId=82D97D2BA239548B64756E2164756E21
2603
2641
  //# sourceMappingURL=index.js.map