// abc2svg - ABC to SVG translator // @source: https://chiselapp.com/user/moinejf/repository/abc2svg // Copyright (C) 2014-2023 Jean-Francois Moine - LGPL3+ //abcweb-1.js file to include in html pages window.onerror = function (msg, url, line) { if (typeof msg == 'string') alert("window error: " + msg + "\nURL: " + url + "\nLine: " + line) else if (typeof msg == 'object') alert("window error: " + msg.type + ' ' + msg.target.src) else alert("window error: " + msg) return false } var user, abcplay if (typeof abc2svg == "undefined") var abc2svg = {} abc2svg.mu = "" abc2svg.abc_end = function () { } abc2svg.jsdir = document.currentScript ? document.currentScript.src.match(/.*\//) : (function () { var s_a = document.getElementsByTagName('script') for (var k = 0; k < s_a.length; k++) { if (s_a[k].src.indexOf("abcweb") >= 0) return s_a[k].src.match(/.*\//) || '' } return "" })() abc2svg.loadjs = function (fn, relay, onerror) { var s = document.createElement('script') if (/:\/\//.test(fn)) s.src = fn else s.src = abc2svg.jsdir + fn s.onload = relay s.onerror = function () { if (onerror) onerror(fn) else alert('error loading ' + fn) } document.head.appendChild(s) } function dom_loaded() { var abc, src, outb, err, a_inc = {}, tune_lst = [], html, busy, playing, playconf = { onend: function () { playing = 0 } } function visible() { var mu, r, wh = window.innerHeight || document.documentElement.clientHeight while (1) { mu = abc2svg.alldiv[0] if (!mu) break r = mu.d.getBoundingClientRect() if (r.top > wh) break musgen(mu) abc2svg.alldiv.shift() } if (abc2svg.alldiv.length) { if (!abc2svg.onscroll) { abc2svg.onscroll = visible window.addEventListener("scroll", visible) } } else { window.removeEventListener("scroll", visible) } } function get_p(e) { var i, j, k, r, o = '', sh = document.styleSheets, s = e.style c = e.getAttribute("class") if (c) { c = '.' + c for (i = 0; i < sh.length; i++) { r = sh[i].rules for (j = 0; j < r.length; j++) { if (r[j].selectorText == c) break } if (j < r.length) break } if (i < sh.length) { r = r[j] for (i = 0; i < r.style.length; i++) { k = r.style[i] if (k[0] == '-' && k[1] == '-') o += '%%' + k.slice(2) + ' ' + r.style.getPropertyValue(k) + '\n' } } } for (i = 0; i < s.length; i++) { k = s[i] if (k[0] == '-' && k[1] == '-') o += '%%' + k.slice(2) + ' ' + s.getPropertyValue(k) + '\n' } return o } function move_music(src) { var re, res, i, j, k, t, re_stop = /\n<|\n%.begin[^\s]+/g, ss = 0, out = "" if (/<[^>]* class="[^"]*abc[^"]*/.test(src)) re = '<[^>]* class="[^"]*abc[^"]*' else re = '%abc-\\d|X:\\s*\\d' re = new RegExp('(^|\n)(' + re + ')', 'g') while (1) { res = re.exec(src) if (!res) break i = re.lastIndex - res[0].length if (i > ss) { out += src.slice(ss, i) html = 1 } t = res[2] if (t[0] == '<') { i = src.indexOf('>', i) + 1 j = res[2].indexOf(' ') t = res[2].slice(1, j) j = src.indexOf('' + t + '>', i) ss = j + t.length + 4 } else { re_stop.lastIndex = i while (1) { res = re_stop.exec(src) if (!res || res[0] == "\n<") break k = src.indexOf(res[0].replace("begin", "end"), re_stop.lastIndex) if (k < 0) break re_stop.lastIndex = k } if (!res || k < 0) j = src.length else j = re_stop.lastIndex - 1 ss = j } out += '\n' re.lastIndex = ss } out += src.slice(ss) if (abc2svg.page && html) out += '\
\ Printing may be bad because the file contains pure HTML and %%pageheight\\n' document.body.innerHTML = out } function save_music() { var i, k, div, c, s, sa abc2svg.music = [{ t: "", n: "mus0" }] k = location.search if (k) { k = k.substr(1).split("&") for (i = 0; i < k.length; i++) abc2svg.music[0].t += "%%" + decodeURIComponent(k[i].replace('=', ' ')) + '\n' } while (1) { sa = document.getElementsByTagName('script') for (i = 0; i < sa.length; i++) { s = sa[i] if (s.type == 'text/vnd.abc') break } if (i >= sa.length) break c = get_p(s) div = document.createElement('div') if (s.text.indexOf('\nX:') < 0) { abc2svg.music[0].t += c + s.innerHTML if (!abc2svg.music[0].d) abc2svg.music[0].d = div } else { abc2svg.music.push({ n: "mus" + abc2svg.music.length, t: c + s.innerHTML, d: div }) } s.parentNode.replaceChild(div, s) } } function musgen(mu) { var t = mu.t if (busy) { mu.w = 1 return } busy = 1 function render() { var i, j, e outb = err = "" abc.tosvg(mu.n, t) abc2svg.abc_end() if (mu.d) { if (err) outb += '
' + err + "\n" if (abc.cfmt().with_source && outb) outb = '
' + clean_txt(t) + '\n\