-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c758402
commit 3268037
Showing
9 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import renderAbc from './vendor/abc/mod.ts' | ||
|
||
export const renderFromString = (d: string) => renderAbc(d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# sheet music | ||
|
||
```ts | ||
import { | ||
renderFromString, | ||
} from "https://deno.land/x/serea/sheet-music/mod.ts"; | ||
``` | ||
|
||
## renderFromString | ||
|
||
```ts | ||
const svg = renderFromString(` | ||
X: 1 | ||
T: Cooley's | ||
M: 4/4 | ||
L: 1/8 | ||
K: Emin | ||
|:D2|"Em"EB{c}BA B2 EB|~B2 AB dBAG| "D"FDAD BDAD|FDAD dAFD| | ||
"Em"EBBA B2 EB|B2 AB defg| "D"afe^c dBAF|"Em"DEFD E2:| | ||
|:gf|"Em"eB B2 efge|eB B2 gedB| "D"A2 FA DAFA|A2 FA defg| | ||
"Em"eB B2 eBgB|eB B2 defg| "D"afe^c dBAF|"Em"DEFD E2:| | ||
`); | ||
``` | ||
|
||
returns an SVG, see the [example](./example.svg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { renderFromString } from './mod.ts' | ||
|
||
console.log(await renderFromString(` | ||
X: 1 | ||
T: Cooley's | ||
M: 4/4 | ||
L: 1/8 | ||
K: Emin | ||
|:D2|"Em"EB{c}BA B2 EB|~B2 AB dBAG| "D"FDAD BDAD|FDAD dAFD| | ||
"Em"EBBA B2 EB|B2 AB defg| "D"afe^c dBAF|"Em"DEFD E2:| | ||
|:gf|"Em"eB B2 efge|eB B2 gedB| "D"A2 FA DAFA|A2 FA defg| | ||
"Em"eB B2 eBgB|eB B2 defg| "D"afe^c dBAF|"Em"DEFD E2:| | ||
`)) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// deno-fmt-ignore-file | ||
|
||
const { parseHTML } = require('linkedom') | ||
const renderAbc = require('abcjs/src/api/abc_tunebook_svg') | ||
|
||
const toSvg = async abc => { | ||
const html = '<!DOCTYPE html>\n<html><body><div id="sheet"></div></body></html>' | ||
const { document } = parseHTML(html) | ||
const el = document.getElementById('sheet') | ||
|
||
globalThis.document = document | ||
await renderAbc(el, abc) | ||
|
||
const svg = el.getElementsByTagName('svg')[0] | ||
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg') | ||
|
||
const viewBox = `0 0 ${svg.getAttribute('width')} ${svg.getAttribute('height')}` | ||
svg.setAttribute('viewBox', viewBox) | ||
svg.removeAttribute('height') | ||
svg.removeAttribute('width') | ||
svg.removeAttribute('style') | ||
|
||
const style = svg.getElementsByTagName('style')[0] | ||
if (style) { | ||
svg.removeChild(style) | ||
} | ||
|
||
return svg.outerHTML | ||
} | ||
|
||
module.exports = toSvg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"scripts": { | ||
"build": "esbuild index.js --bundle --minify --format=esm --outfile=abc.js" | ||
}, | ||
"dependencies": { | ||
"abcjs": "^6.0.2", | ||
"esbuild": "^0.14.38", | ||
"linkedom": "^0.14.9" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { default as abcToSvg } from "./abc.js"; | ||
|
||
/** | ||
* @param {string} abc music notation https://paulrosen.github.io/abcjs/overview/abc-notation.html | ||
* @returns {Promise<string>} svg string | ||
*/ | ||
export default (abc: string): Promise<string> => abcToSvg(abc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# abc | ||
|
||
https://paulrosen.github.io/abcjs/ https://github.com/WebReflection/linkedom | ||
|
||
License: [MIT](https://github.com/paulrosen/abcjs/blob/main/license.js) | ||
|
||
## How to build | ||
|
||
``` | ||
cd lib | ||
npm install | ||
npm run build | ||
``` |