/* global $ */
import './css/i.css'
import dotEmpty from './svg/dotEmpty.svg'
import dotEmptyH from './svg/dotEmpty_h.svg'
import dot from './svg/dot.svg'
import dotH from './svg/dot_h.svg'
import dotWideLeft from './svg/dotWideLeft.svg'
import dotWideRight from './svg/dotWideRight.svg'
import dotWideMiddle from './svg/dotWideMiddle.svg'
import stringO from './svg/string_o.svg'
import stringX from './svg/string_x.svg'
const switchListV = {
o: `
${dot}
`,
'*': `${dot}
`,
'(': `${dotWideLeft}
`,
')': `${dotWideRight}
`,
'=': `${dotWideMiddle}
`,
'^': `${stringO}
`,
x: `${stringX}
`,
'|': `${dotEmpty}
`,
' ': `${dotEmpty}
`,
'\n': `${dotEmpty}
`
}
const switchListH = {
o: `${dotH}
`,
'*': `${dotH}
`,
O: `${dotH}
`,
'-': `${dotEmptyH}
`,
' ': `${dotEmptyH}
`,
'\n': `${dotEmptyH}
${dotEmptyH}
`
}
export const renderFretBoard = (content, { title: fretTitle, type }) => {
const fretType = type.split(' ')
const containerClass = fretType && fretType[0].startsWith('h') ? 'fretContainer_h' : 'fretContainer'
const fretboardHTML = $(``)
$(fretboardHTML).append($(`${fretTitle}
`))
// create fretboard background HTML
const fretbOrientation = fretType && fretType[0].startsWith('v') ? 'vert' : 'horiz'
const fretbLen = fretType && fretType[0].substring(1)
const fretbClass = fretType && fretType[0][0] + ' ' + fretType[0]
const nut = (fretType[1] && fretType[1] === 'noNut') ? 'noNut' : ''
const svgHTML = $(``)
const fretbBg = require(`./svg/fretb_${fretbOrientation}_${fretbLen}.svg`)
$(svgHTML).append($(fretbBg))
// create cells HTML
const cellsHTML = $('')
let switchList = ''
if (fretbOrientation && fretbOrientation === 'vert') {
switchList = switchListV
} else {
// calculate position
const emptyFill = new Array(Number(fretbLen) + 3).fill(' ').join('')
content = `${emptyFill}${content}`
switchList = switchListH
}
const contentCell = content && content.split('')
// Go through each ASCII character...
const numArray = [...Array(10).keys()].slice(1)
contentCell && contentCell.forEach(char => {
if (numArray.toString().indexOf(char) !== -1) {
const numType = fretType && fretType[0].startsWith('h') ? '_h' : ''
const numSvg = require(`./svg/number${char}${numType}.svg`)
cellsHTML.append($(`${numSvg}
`))
} else if (switchList[char] !== undefined) {
cellsHTML.append($(switchList[char]))
}
})
$(svgHTML).append($(cellsHTML))
$(fretboardHTML).append($(svgHTML))
return fretboardHTML[0].outerHTML
}