1+ import {
2+ dotEmpty ,
3+ dotEmpty_h ,
4+ dot ,
5+ dot_h ,
6+ dotWideLeft ,
7+ dotWideRight ,
8+ dotWideMiddle ,
9+ string_o ,
10+ string_x ,
11+ fretb_vert_4 ,
12+ fretb_vert_5 ,
13+ fretb_vert_7 ,
14+ fretb_vert_9 ,
15+ fretb_vert_12 ,
16+ fretb_vert_15 ,
17+ fretb_horiz_5 ,
18+ fretb_horiz_6 ,
19+ fretb_horiz_7 ,
20+ } from './fretboardSVG.js'
21+
22+ const switchList_v = {
23+ 'o' : `<div class='cell dot'>${ dot } </div>` ,
24+ '*' : `<div class='cell dot faded'>${ dot } </div>` ,
25+ '(' : `<div class='cell'>${ dotWideLeft } </div>` ,
26+ ')' : `<div class='cell'>${ dotWideRight } </div>` ,
27+ '=' : `<div class='cell'>${ dotWideMiddle } </div>` ,
28+ '^' : `<div class='cell'>${ string_o } </div>` ,
29+ 'x' : `<div class='cell'>${ string_x } </div>` ,
30+ '|' : `<div class='cell empty'>${ dotEmpty } </div>` ,
31+ ' ' : `<div class='cell empty'>${ dotEmpty } </div>`
32+ }
33+ const switchList_h = {
34+ 'o' : `<div class='cell dot'>${ dot_h } </div>` ,
35+ '*' : `<div class='cell dot faded'>${ dot_h } </div>` ,
36+ 'O' : `<div class='cell dot root'>${ dot_h } </div>` ,
37+ '-' : `<div class='cell empty'>${ dotEmpty_h } </div>` ,
38+ ' ' : `<div class='cell empty'>${ dotEmpty_h } </div>`
39+ }
40+
41+ export const renderFretBoard = ( content ) => {
42+
43+ let fretboardHTML = $ ( '<div class="fretboard_instance"></div>' )
44+ if ( content . includes ( 'title:' ) ) {
45+ const getTitle = content . split ( '\n' , 1 ) [ 0 ] . split ( 'title:' ) [ 1 ] . trim ( )
46+ $ ( fretboardHTML ) . append ( $ ( `<div class="title">${ getTitle } </div>` ) )
47+ content = content . split ( '\n' ) . slice ( 1 ) . join ( '\n' )
48+ }
49+
50+ let fretType = ''
51+ if ( content . startsWith ( 'type:' ) ) {
52+ fretType = content . split ( '\n' , 1 ) [ 0 ] . split ( 'type:' ) [ 1 ] . trim ( ) . split ( ' ' )
53+ content = content . split ( '\n' ) . slice ( 1 ) . join ( '\n' )
54+ }
55+
56+ let fretb_orientation = fretType [ 0 ] . startsWith ( 'v' ) ? 'vert' : 'horiz'
57+ let fretb_len = fretType [ 0 ] . substring ( 1 )
58+
59+ // TODO: to get svg dynamically
60+ let fretb_bg = ''
61+ switch ( fretb_len ) {
62+ case '4' :
63+ fretb_bg = fretb_vert_4
64+ break
65+ case '5' :
66+ if ( fretb_orientation === 'vert' )
67+ fretb_bg = fretb_vert_5
68+ else
69+ fretb_bg = fretb_horiz_5
70+ break
71+ case '6' :
72+ fretb_bg = fretb_horiz_6
73+ break
74+ case '7' :
75+ if ( fretb_orientation === 'vert' )
76+ fretb_bg = fretb_vert_7
77+ else
78+ fretb_bg = fretb_horiz_7
79+ break
80+ case '9' :
81+ fretb_bg = fretb_vert_9
82+ break
83+ case '12' :
84+ fretb_bg = fretb_vert_12
85+ break
86+ case '15' :
87+ fretb_bg = fretb_vert_15
88+ break
89+ }
90+
91+ // create fretboard background HTML
92+ let fretb_class = fretType [ 0 ] [ 0 ] + ' ' + fretType [ 0 ]
93+ let nut = ( fretType [ 1 ] && fretType [ 1 ] === 'noNut' ) ?'noNut' :''
94+ let svgHTML = $ ( `<div class="svg_wrapper ${ fretb_class } ${ nut } "></div>` )
95+ $ ( svgHTML ) . append ( $ ( fretb_bg ) )
96+
97+ // create cells HTML
98+ let cellsHTML = $ ( '<div class="cells"></div>' )
99+ let switchList = fretb_orientation === 'vert' ? switchList_v : switchList_h
100+ let contentCell = content . split ( '' )
101+ // Go through each ASCII character...
102+ contentCell . forEach ( char => {
103+ if ( switchList [ char ] !== undefined ) {
104+ cellsHTML . append ( $ ( switchList [ char ] ) ) ;
105+ }
106+ } )
107+
108+ $ ( svgHTML ) . append ( $ ( cellsHTML ) )
109+ $ ( fretboardHTML ) . append ( $ ( svgHTML ) )
110+
111+ return fretboardHTML [ 0 ] . outerHTML
112+ }
0 commit comments