ascii-tabs 0.11.2 → 0.11.3

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.
package/README.md CHANGED
@@ -62,7 +62,7 @@ Design notes: [spec](docs/spec-v0.1.md), [glossary](GLOSSARY.md), [ADRs](docs/ad
62
62
  ## Usage
63
63
 
64
64
  ```html
65
- <script type="module" src="https://cdn.jsdelivr.net/gh/libasoles/ascii-tabs@0.11.2/ascii-tabs.js"></script>
65
+ <script type="module" src="https://cdn.jsdelivr.net/gh/libasoles/ascii-tabs@0.11.3/ascii-tabs.js"></script>
66
66
 
67
67
  <ascii-tabs></ascii-tabs>
68
68
  ```
@@ -409,7 +409,7 @@ E|-----3-|</pre>
409
409
  The copy button copies the same plain ASCII. `parse` and `format` are exported as pure functions:
410
410
 
411
411
  ```js
412
- import { parse, format } from 'https://cdn.jsdelivr.net/gh/libasoles/ascii-tabs@0.11.2/ascii-tabs.js';
412
+ import { parse, format } from 'https://cdn.jsdelivr.net/gh/libasoles/ascii-tabs@0.11.3/ascii-tabs.js';
413
413
 
414
414
  const tab = parse('1 -3--5-\n2 ------\n3 ------\n4 ------\n5 ------\n6 ------'); // one Tab: Column[]
415
415
  format(tab, { spacing: 2 }); // "1 -3--5-\n2 ------\n..."
@@ -590,10 +590,11 @@ Strings are labelled `1`–`6` by default, on screen and in copied text. `labels
590
590
  String labels have no bars by default. Add the boolean `string-bars` attribute
591
591
  (or set `element.stringBars = true`) to draw a `|` at the start of each String,
592
592
  independently of the labels. The bars also appear in copied ASCII. Remove the
593
- attribute or set the property to `false` to hide them.
593
+ attribute or set the property to `false` to hide them. With labels, the bar
594
+ replaces the separating space, so `e|` and `1|` occupy two characters.
594
595
 
595
596
  ```html
596
- <ascii-tabs labels="notes" string-bars></ascii-tabs> <!-- e |-3--5- -->
597
+ <ascii-tabs labels="notes" string-bars></ascii-tabs> <!-- e|-3--5- -->
597
598
  <ascii-tabs labels="none" string-bars></ascii-tabs> <!-- |-3--5- -->
598
599
  ```
599
600
 
package/ascii-tabs.js CHANGED
@@ -23,15 +23,16 @@ const normalizeTuning = value => {
23
23
  : [...STANDARD_TUNING];
24
24
  };
25
25
  const labelStyle = value => (value === 'notes' || value === 'none' ? value : 'numbers');
26
- const stringLabels = (labels, tuning) => {
26
+ const stringLabels = (labels, tuning, stringBars = false) => {
27
27
  if (labelStyle(labels) === 'none') return Array(STRING_COUNT).fill('');
28
- if (labelStyle(labels) === 'numbers') return ['1 ', '2 ', '3 ', '4 ', '5 ', '6 '];
29
- const names = tuning.map((name, s) => `${s === 0 ? name.toLowerCase() : name} `);
30
- const width = Math.max(...names.map(name => name.length));
28
+ const names = labelStyle(labels) === 'numbers'
29
+ ? ['1', '2', '3', '4', '5', '6']
30
+ : tuning.map((name, s) => s === 0 ? name.toLowerCase() : name);
31
+ const width = Math.max(...names.map(name => name.length)) + (stringBars ? 0 : 1);
31
32
  return names.map(name => name.padEnd(width, ' '));
32
33
  };
33
- const labelWidth = (labels, tuning) => stringLabels(labels, tuning)[0].length;
34
- const prefixWidth = (labels, tuning, stringBars) => labelWidth(labels, tuning) + (stringBars ? 1 : 0);
34
+ const labelWidth = (labels, tuning, stringBars = false) => stringLabels(labels, tuning, stringBars)[0].length;
35
+ const prefixWidth = (labels, tuning, stringBars) => labelWidth(labels, tuning, stringBars) + (stringBars ? 1 : 0);
35
36
  const notationStyle = value => (value === 'letters' || value === 'solfege' ? value : 'frets');
36
37
  const NOTE_NAMES = {
37
38
  letters: ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'],
@@ -180,7 +181,7 @@ function layout(tab, spacing, capacity, notation, tuning, sizes = []) {
180
181
  function format(tab, { spacing = DEFAULT_SPACING, labels = 'numbers', stringBars = false, notation = 'frets', tuning = STANDARD_TUNING, width = Infinity, annotations = [], annotationFit = 'overflow' } = {}) {
181
182
  tuning = normalizeTuning(tuning);
182
183
  annotations = normalizeAnnotations([annotations], [tab])[0] ?? [];
183
- const names = stringLabels(labels, tuning);
184
+ const names = stringLabels(labels, tuning, stringBars);
184
185
  const columns = tab.slice(0, lastContent(tab, annotations) + 1);
185
186
  if (!columns.length) return '';
186
187
  const lead = '-'.repeat(leadingDashes(spacing));
@@ -1183,8 +1184,8 @@ class AsciiTabs extends Base {
1183
1184
  this.#annotationResizeObserver?.disconnect();
1184
1185
  const annotationPositions = [];
1185
1186
  const labels = this.labels, notation = this.notation, tuning = this.tuning;
1186
- const gutter = labelWidth(labels, tuning);
1187
- const names = stringLabels(labels, tuning);
1187
+ const gutter = labelWidth(labels, tuning, this.stringBars);
1188
+ const names = stringLabels(labels, tuning, this.stringBars);
1188
1189
  this.#titleEls.forEach((title, t) => {
1189
1190
  title.textContent = this.#tabTitles[t] ?? '';
1190
1191
  title.hidden = !title.textContent && !(this.titlesEditable && !this.readonly);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ascii-tabs",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
4
4
  "description": "A zero-dependency web component to write and show guitar tabs as plain ASCII.",
5
5
  "type": "module",
6
6
  "main": "./ascii-tabs.js",