@dsebastien/music-notation 0.12.0 → 0.14.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.
@@ -16,6 +16,8 @@ export declare function dotLabel(doc: Document, text: string, point: [number, nu
16
16
  export declare function svgLine(doc: Document, [x1, y1]: [number, number], [x2, y2]: [number, number], cls: string): SVGElement;
17
17
  /** An HTML element with a class and optional text. */
18
18
  export declare function html<K extends keyof HTMLElementTagNameMap>(doc: Document, tag: K, cls?: string, text?: string): HTMLElementTagNameMap[K];
19
+ /** An id unique on the page (a counter behind this copy's random prefix). */
20
+ export declare const uniqueId: () => string;
19
21
  /**
20
22
  * A root <svg> sized by its viewBox, scaling with the container up to its natural width.
21
23
  *
package/dist/tab/index.js CHANGED
@@ -44,6 +44,7 @@ function html(doc, tag, cls, text) {
44
44
  }
45
45
  var NAME_PREFIX = `mn-name-${Math.random().toString(36).slice(2, 8)}-`;
46
46
  var names = 0;
47
+ var uniqueId = () => `${NAME_PREFIX}${++names}`;
47
48
  function svgRoot(doc, width, height, cls, label) {
48
49
  const id = `${NAME_PREFIX}${++names}`;
49
50
  const title = svg(doc, "title", { class: "mn-name", id });
@@ -191,6 +192,21 @@ function parseTuning(text) {
191
192
  }
192
193
  return midis;
193
194
  }
195
+ function tuningNames(text) {
196
+ const trimmed = text.trim();
197
+ const named = NAMED.get(trimmed.toLowerCase().replace(/\s*\(.*\)$/, ""));
198
+ if (named)
199
+ return tuningNames(named);
200
+ if (!parseTuning(trimmed))
201
+ return null;
202
+ const spaced = trimmed.split(/[\s,]+/).filter(Boolean);
203
+ const names = spaced.length > 1 ? spaced : trimmed.match(/[A-G][#♯b♭]?|[a-g][#♯♭]?/g) ?? [];
204
+ return names.map((n) => {
205
+ const letter = n.charAt(0).toUpperCase();
206
+ const accidental = n.slice(1).replace(/-?\d+$/, "").replace("♯", "#").replace("♭", "b");
207
+ return letter + accidental;
208
+ });
209
+ }
194
210
 
195
211
  // src/convert/text-tab.ts
196
212
  var STRING_PREFIX = /^\s*([A-Ga-g][#b]?|[1-8](?=\s*[|:]))?\s*[|:]?/;
@@ -2090,5 +2106,5 @@ export {
2090
2106
  textTabToAlphaTex
2091
2107
  };
2092
2108
 
2093
- //# debugId=2EE54AC69188D00D64756E2164756E21
2109
+ //# debugId=88C605D20363676064756E2164756E21
2094
2110
  //# sourceMappingURL=index.js.map