instruments-chords 0.0.4 → 0.0.5
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/dist/getChordSvg.js +12 -12
- package/dist/svg/base.js +2 -2
- package/dist/svg/constants.d.ts +1 -1
- package/dist/svg/constants.js +1 -1
- package/dist/svg/markers.js +4 -4
- package/package.json +1 -1
package/dist/getChordSvg.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { getChord } from './getChord';
|
|
2
2
|
import { renderBase } from './svg/base';
|
|
3
|
-
import { SVG_HEIGTH, SVG_WIDTH } from './svg/constants';
|
|
4
3
|
import { renderMarkers } from './svg/markers';
|
|
4
|
+
import { SVG_WIDTH, SVG_HEIGHT } from './svg/constants';
|
|
5
5
|
export function getChordSvg(root, quality) {
|
|
6
6
|
const chord = getChord(root, quality);
|
|
7
|
-
if (chord
|
|
7
|
+
if (!chord)
|
|
8
8
|
return null;
|
|
9
9
|
const base = renderBase();
|
|
10
10
|
const markers = renderMarkers(chord);
|
|
11
11
|
return `
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
<svg
|
|
13
|
+
width="${SVG_WIDTH}"
|
|
14
|
+
height="${SVG_HEIGHT}"
|
|
15
|
+
viewBox="0 0 ${SVG_WIDTH} ${SVG_HEIGHT}"
|
|
16
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
17
|
+
>
|
|
18
|
+
${base}
|
|
19
|
+
${markers}
|
|
20
|
+
</svg>
|
|
21
|
+
`.trim();
|
|
22
22
|
}
|
package/dist/svg/base.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FRET_COUNT, FRET_SPACING, START_X, START_Y,
|
|
1
|
+
import { STRING_COUNT, FRET_COUNT, STRING_SPACING, FRET_SPACING, START_X, START_Y, } from './constants';
|
|
2
2
|
export function renderBase() {
|
|
3
3
|
let svg = '';
|
|
4
4
|
// cuerdas
|
|
5
|
-
for (let i = 0; i
|
|
5
|
+
for (let i = 0; i < STRING_COUNT; i++) {
|
|
6
6
|
const x = START_X + i * STRING_SPACING;
|
|
7
7
|
svg += `<line x1="${x}" y1="${START_Y}" x2="${x}" y2="${START_Y + FRET_SPACING * FRET_COUNT}" stroke="black"/>`;
|
|
8
8
|
}
|
package/dist/svg/constants.d.ts
CHANGED
package/dist/svg/constants.js
CHANGED
package/dist/svg/markers.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getStringX, getFretY } from './utils';
|
|
2
2
|
export function renderMarkers(chord) {
|
|
3
3
|
let svg = '';
|
|
4
4
|
for (const [string, fret] of Object.entries(chord)) {
|
|
5
5
|
const s = Number(string);
|
|
6
6
|
const x = getStringX(s);
|
|
7
7
|
if (fret === 'x') {
|
|
8
|
-
svg += `<text
|
|
8
|
+
svg += `<text x="${x}" y="20" text-anchor="middle">x</text>`;
|
|
9
9
|
}
|
|
10
10
|
else if (fret === 0) {
|
|
11
|
-
svg += `<
|
|
11
|
+
svg += `<circle cx="${x}" cy="20" r="5" fill="none" stroke="black"/>`;
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
14
|
const y = getFretY(fret);
|
|
15
|
-
svg += `<
|
|
15
|
+
svg += `<circle cx="${x}" cy="${y}" r="6" fill="black"/>`;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
return svg;
|