@dsebastien/music-notation 0.14.0 → 0.16.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.
@@ -1,4 +1,3 @@
1
- /** DOM and SVG helpers. Everything is created in the host's document (popout windows, Publish). */
2
1
  export declare const SVG_NS = "http://www.w3.org/2000/svg";
3
2
  type Attributes = Record<string, string | number | undefined>;
4
3
  /** An SVG element with attributes and children. */
@@ -0,0 +1,82 @@
1
+ import { type PlayOptions } from '../playback/controls.js';
2
+ /** A target as the app sees it: where it is and what it sounds. */
3
+ export interface Pick {
4
+ /** 1 is the highest string, as on the dots; null on keyboards. */
5
+ string: number | null;
6
+ fret: number | null;
7
+ /** The pitch class as the drawing spells it ("C", "Bb"). */
8
+ note: string;
9
+ /** MIDI. */
10
+ pitch: number;
11
+ /** The target (`rect.mn-pick`). */
12
+ element: SVGElement;
13
+ /** A click, or Space or Enter on the focused target. */
14
+ via: 'pointer' | 'keyboard';
15
+ }
16
+ /**
17
+ * A target by its place on a fretboard, or every target of a pitch. A pick may be passed as it is:
18
+ * its place wins (its own target), and on keyboards its pitch is its key.
19
+ */
20
+ export type PickAt = {
21
+ string: number;
22
+ fret: number;
23
+ } | {
24
+ pitch: number;
25
+ string?: number | null;
26
+ fret?: number | null;
27
+ };
28
+ export type PickResult = 'right' | 'wrong';
29
+ export interface PickOptions {
30
+ /** Called with each pick and the layer (to mark it). A handler that throws is ignored. */
31
+ onPick?: (pick: Pick, layer: PickLayer) => void;
32
+ /**
33
+ * Plays each pick's note for 1.5 s (off by default): the play options' player, volume
34
+ * (read at each pick) and sound (guitar on fretboards, piano on keyboards by default). A new
35
+ * pick stops the note before. Through `renderBlock`, `true` uses the block's `play` options.
36
+ */
37
+ play?: boolean | PlayOptions;
38
+ }
39
+ /** How long a picked note sounds, in seconds (as a click on a note of a playable diagram). */
40
+ export declare const PICK_NOTE = 1.5;
41
+ export interface PickLayer {
42
+ /** The diagram. */
43
+ readonly element: Element;
44
+ /** Every target, in document order (the highest string's frets first; white keys, then black). */
45
+ targets(): Pick[];
46
+ /** Marks the target(s) at `at` right or wrong (replacing a mark); false when none is there. */
47
+ mark(at: PickAt, result: PickResult): boolean;
48
+ /** Takes the mark(s) at `at` away; false when none was there. */
49
+ unmark(at: PickAt): boolean;
50
+ /** Takes every mark away. */
51
+ clear(): void;
52
+ /** Focuses the target at `at` (the first one there), else the layer's tab stop. */
53
+ focus(at?: PickAt): boolean;
54
+ /** Stops picking: listeners off, marks, names and tab stops removed. */
55
+ destroy(): void;
56
+ }
57
+ export interface PickTargetData {
58
+ pitch: number;
59
+ note: string;
60
+ /** 1 is the highest string (fretboards). */
61
+ string?: number;
62
+ fret?: number;
63
+ /** The place, for screen readers ("String 5, fret 3"): never the note, so it gives no answer away. */
64
+ name: string;
65
+ /** Where a mark goes, and its radius. */
66
+ mark: [number, number];
67
+ radius: number;
68
+ }
69
+ /** The layer's group, drawn last (above the dots and labels). */
70
+ export declare function pickGroup(doc: Document): SVGElement;
71
+ /** One target: a transparent rectangle that takes clicks, without the stylesheet too. */
72
+ export declare function pickTarget(doc: Document, area: {
73
+ x: number;
74
+ y: number;
75
+ width: number;
76
+ height: number;
77
+ }, data: PickTargetData): SVGElement;
78
+ /**
79
+ * Makes a diagram's pick layer live (see `PickLayer`). A diagram without one gets a layer with no
80
+ * targets; a diagram whose layer is live gets that layer (its first options).
81
+ */
82
+ export declare function attachPick(diagram: Element, options?: PickOptions): PickLayer;
@@ -1,5 +1,6 @@
1
1
  /** Render a notation block into a host element. Never throws: errors render inline. */
2
2
  import { type NotationLanguage, type RenderOptions } from '../blocks/renderers.js';
3
+ import { type PickLayer } from './pick.js';
3
4
  export declare const LANGUAGES: NotationLanguage[];
4
5
  export declare const isNotationLanguage: (language: string) => language is NotationLanguage;
5
6
  /** More diagrams than this in one block is an error, so a page stays quick to draw. */
@@ -12,6 +13,8 @@ export interface RenderResult {
12
13
  error: string | null;
13
14
  /** Removes what was rendered. */
14
15
  destroy(): void;
16
+ /** The live pick layers (the `pick` option), one per diagram that has one, in page order. */
17
+ picks: PickLayer[];
15
18
  }
16
19
  export declare function renderBlock(language: NotationLanguage, source: string, host: HTMLElement, given?: RenderOptions): RenderResult;
17
20
  /** Properties as given, or what a function of the block's element returns; null when it fails. */