astro-lilypond 0.3.4 → 0.5.0
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/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -8
- package/dist/index.js.map +1 -1
- package/dist/rehype-plugin.d.ts.map +1 -1
- package/dist/rehype-plugin.js +11 -4
- package/dist/rehype-plugin.js.map +1 -1
- package/dist/remark-plugin.d.ts.map +1 -1
- package/dist/remark-plugin.js +11 -4
- package/dist/remark-plugin.js.map +1 -1
- package/dist/render.d.ts +15 -9
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +54 -32
- package/dist/render.js.map +1 -1
- package/dist/satteri-plugin.d.ts.map +1 -1
- package/dist/satteri-plugin.js +11 -4
- package/dist/satteri-plugin.js.map +1 -1
- package/dist/util.d.ts +12 -11
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +22 -13
- package/dist/util.js.map +1 -1
- package/package.json +15 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { AstroIntegration } from "astro";
|
|
2
|
-
import type { LilypondPluginOptions
|
|
3
|
-
export type { OutputFormat };
|
|
2
|
+
import type { LilypondPluginOptions } from "./util.js";
|
|
4
3
|
export type { LilypondPluginOptions };
|
|
5
4
|
export interface LilypondOptions extends LilypondPluginOptions {
|
|
6
5
|
/**
|
|
@@ -14,10 +13,13 @@ export interface LilypondOptions extends LilypondPluginOptions {
|
|
|
14
13
|
* Output format. Defaults to `"svg"`.
|
|
15
14
|
*
|
|
16
15
|
* - `"svg"` — inline SVG embedded directly in the HTML (default)
|
|
17
|
-
* - `"png"` — `<img>` element with a base64 data URI
|
|
18
|
-
* - `{ type: "png", resolution: number }` — PNG at a specific DPI
|
|
16
|
+
* - `"png"` — `<img>` element with a base64 data URI
|
|
19
17
|
*/
|
|
20
|
-
format?:
|
|
18
|
+
format?: "svg" | "png";
|
|
19
|
+
/**
|
|
20
|
+
* Resolution in DPI (only applies to PNG). Defaults to `144`.
|
|
21
|
+
*/
|
|
22
|
+
resolution?: number;
|
|
21
23
|
/**
|
|
22
24
|
* Crop the output tightly to the content bounding box. Defaults to `true`.
|
|
23
25
|
*/
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAS9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAS9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAMvD,YAAY,EAAE,qBAAqB,EAAE,CAAC;AAEtC,MAAM,WAAW,eAAgB,SAAQ,qBAAqB;IAC7D;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACvB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAsBD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,OAAO,GAAE,eAAoB,GAAG,gBAAgB,CAiGhF"}
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import { promisify } from "util";
|
|
|
3
3
|
import { remarkLilypondPlugin } from "./remark-plugin.js";
|
|
4
4
|
import { rehypeLilypondPlugin } from "./rehype-plugin.js";
|
|
5
5
|
import { satteriLilypondPlugin } from "./satteri-plugin.js";
|
|
6
|
-
import { render } from "./render.js";
|
|
7
|
-
import { includePathsFor, prependVersion, renderToHtml,
|
|
6
|
+
import { defaultOptions, render } from "./render.js";
|
|
7
|
+
import { includePathsFor, prependVersion, renderToHtml, sourceNameFor } from "./util.js";
|
|
8
8
|
const execFileAsync = promisify(execFile);
|
|
9
9
|
const LY_EXTENSIONS = [".ly", ".lilypond", ".ily"];
|
|
10
10
|
function lyFilePlugin(options) {
|
|
@@ -15,12 +15,13 @@ function lyFilePlugin(options) {
|
|
|
15
15
|
if (!LY_EXTENSIONS.some(ext => id.endsWith(ext)))
|
|
16
16
|
return;
|
|
17
17
|
const src = options.version ? prependVersion(source, options.version) : source;
|
|
18
|
-
const
|
|
18
|
+
const format = options.format ?? defaultOptions.format;
|
|
19
19
|
const buf = await render(src, {
|
|
20
20
|
format,
|
|
21
|
-
resolution,
|
|
22
|
-
crop: options.crop
|
|
21
|
+
resolution: options.resolution,
|
|
22
|
+
crop: options.crop,
|
|
23
23
|
includePaths: includePathsFor(id),
|
|
24
|
+
sourceName: sourceNameFor(id),
|
|
24
25
|
});
|
|
25
26
|
return { code: `export default ${JSON.stringify(renderToHtml(buf, format))}` };
|
|
26
27
|
},
|
|
@@ -53,7 +54,7 @@ export default function lilypond(options = {}) {
|
|
|
53
54
|
...existingOptions,
|
|
54
55
|
mdastPlugins: [
|
|
55
56
|
...(existingOptions.mdastPlugins ?? []),
|
|
56
|
-
satteriLilypondPlugin(
|
|
57
|
+
satteriLilypondPlugin(options),
|
|
57
58
|
],
|
|
58
59
|
}),
|
|
59
60
|
},
|
|
@@ -74,11 +75,11 @@ export default function lilypond(options = {}) {
|
|
|
74
75
|
...existingOptions,
|
|
75
76
|
remarkPlugins: [
|
|
76
77
|
...(existingOptions.remarkPlugins ?? []),
|
|
77
|
-
[remarkLilypondPlugin,
|
|
78
|
+
[remarkLilypondPlugin, options],
|
|
78
79
|
],
|
|
79
80
|
rehypePlugins: [
|
|
80
81
|
...(existingOptions.rehypePlugins ?? []),
|
|
81
|
-
[rehypeLilypondPlugin,
|
|
82
|
+
[rehypeLilypondPlugin, options],
|
|
82
83
|
],
|
|
83
84
|
}),
|
|
84
85
|
},
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAGzF,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,CAAU,CAAC;AA6B5D,SAAS,YAAY,CAAC,OAAwB;IAC7C,OAAO;QACN,IAAI,EAAE,+BAA+B;QACrC,OAAO,EAAE,KAAK;QACd,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE;YACzB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,G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d,GAAG,CAAC,eAAe,CAAC,aAAa,IAAI,EAAE,CAAC;oCACxC,CAAC,oBAAoB,EAAE,OAAO,CAAC;iCAC/B;gCACD,aAAa,EAAE;oCACd,GAAG,CAAC,eAAe,CAAC,aAAa,IAAI,EAAE,CAAC;oCACxC,CAAC,oBAAoB,EAAE,OAAO,CAAC;iCAC/B;6BACD,CAAC;yBACF;qBACD,CAAC,CAAC;oBACH,MAAM,EAAE,IAAI,CAAC,0DAA0D,CAAC,CAAC;oBACzE,OAAO;gBACR,CAAC;gBAED,MAAM,IAAI,KAAK,CACd,mEAAmE;oBAClE,gEAAgE;oBAChE,2EAA2E;oBAC3E,uBAAuB,iBAAiB,EAAE,IAAI,IAAI,MAAM,GAAG,CAC5D,CAAC;YACH,CAAC;YAED,mBAAmB,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE;gBACxC,WAAW,CAAC;oBACX,QAAQ,EAAE,eAAe;oBACzB,OAAO,EAAE,aAAa;yBACpB,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,oBAAoB,GAAG,uDAAuD,CAAC;yBAC1F,IAAI,CAAC,IAAI,CAAC;iBACZ,CAAC,CAAC;YACJ,CAAC;SACD;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehype-plugin.d.ts","sourceRoot":"","sources":["../src/rehype-plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rehype-plugin.d.ts","sourceRoot":"","sources":["../src/rehype-plugin.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAQvD,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAKxD,wBAAgB,oBAAoB,CACnC,OAAO,GAAE,mBAAwB,GAC/B,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAuDxD"}
|
package/dist/rehype-plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
|
-
import { render } from "./render.js";
|
|
3
|
-
import { includePathsFor, isLilypondLang, prependVersion, renderToHtml,
|
|
2
|
+
import { defaultOptions, render } from "./render.js";
|
|
3
|
+
import { includePathsFor, isLilypondLang, prependVersion, renderToHtml, sourceNameFor, } from "./util.js";
|
|
4
4
|
// Typed loosely so it's assignable to both RehypePlugin and the unified
|
|
5
5
|
// Plugin generic regardless of which @types/hast version the host project pins.
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -8,6 +8,7 @@ export function rehypeLilypondPlugin(options = {}) {
|
|
|
8
8
|
return async (tree, file) => {
|
|
9
9
|
const promises = [];
|
|
10
10
|
const includePaths = includePathsFor(file?.path);
|
|
11
|
+
const sourceName = sourceNameFor(file?.path);
|
|
11
12
|
visit(tree, "element", (node, index, parent) => {
|
|
12
13
|
if (node.tagName !== "pre" ||
|
|
13
14
|
node.children?.length !== 1 ||
|
|
@@ -30,8 +31,14 @@ export function rehypeLilypondPlugin(options = {}) {
|
|
|
30
31
|
const source = options.version
|
|
31
32
|
? prependVersion(raw, options.version)
|
|
32
33
|
: raw;
|
|
33
|
-
const
|
|
34
|
-
const promise = render(source, {
|
|
34
|
+
const format = options.format ?? defaultOptions.format;
|
|
35
|
+
const promise = render(source, {
|
|
36
|
+
format,
|
|
37
|
+
resolution: options.resolution,
|
|
38
|
+
crop: options.crop,
|
|
39
|
+
includePaths,
|
|
40
|
+
sourceName,
|
|
41
|
+
})
|
|
35
42
|
.then((buf) => {
|
|
36
43
|
const rawNode = {
|
|
37
44
|
type: "raw",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehype-plugin.js","sourceRoot":"","sources":["../src/rehype-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAA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,CAAC;IAC7B,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-plugin.d.ts","sourceRoot":"","sources":["../src/remark-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,IAAI,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"remark-plugin.d.ts","sourceRoot":"","sources":["../src/remark-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,IAAI,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAUtC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAExD,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC,EAAE,IAAI,CAoCrE,CAAC"}
|
package/dist/remark-plugin.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
|
-
import { render } from "./render.js";
|
|
3
|
-
import { includePathsFor, isLilypondLang, prependVersion, renderToHtml,
|
|
2
|
+
import { defaultOptions, render } from "./render.js";
|
|
3
|
+
import { includePathsFor, isLilypondLang, prependVersion, renderToHtml, sourceNameFor, } from "./util.js";
|
|
4
4
|
export const remarkLilypondPlugin = (options = {}) => {
|
|
5
5
|
return async (tree, file) => {
|
|
6
6
|
const promises = [];
|
|
7
7
|
const includePaths = includePathsFor(file?.path);
|
|
8
|
+
const sourceName = sourceNameFor(file?.path);
|
|
8
9
|
visit(tree, "code", (node, index, parent) => {
|
|
9
10
|
if (!isLilypondLang(node.lang) || index === undefined || !parent)
|
|
10
11
|
return;
|
|
11
12
|
const source = options.version
|
|
12
13
|
? prependVersion(node.value, options.version)
|
|
13
14
|
: node.value;
|
|
14
|
-
const
|
|
15
|
-
const promise = render(source, {
|
|
15
|
+
const format = options.format ?? defaultOptions.format;
|
|
16
|
+
const promise = render(source, {
|
|
17
|
+
format,
|
|
18
|
+
resolution: options.resolution,
|
|
19
|
+
crop: options.crop,
|
|
20
|
+
includePaths,
|
|
21
|
+
sourceName,
|
|
22
|
+
})
|
|
16
23
|
.then((buf) => {
|
|
17
24
|
const htmlNode = {
|
|
18
25
|
type: "html",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-plugin.js","sourceRoot":"","sources":["../src/remark-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"remark-plugin.js","sourceRoot":"","sources":["../src/remark-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EACN,eAAe,EACf,cAAc,EACd,cAAc,EACd,YAAY,EACZ,aAAa,GACb,MAAM,WAAW,CAAC;AAKnB,MAAM,CAAC,MAAM,oBAAoB,GAAyC,CACzE,OAAO,GAAG,EAAE,EACX,EAAE;IACH,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAoB,EAAE,CAAC;QACrC,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACjD,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAE7C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM;gBAAE,OAAO;YAEzE,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO;gBAC7B,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;gBAC7C,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;YACd,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,cAAc,CAAC,MAAM,CAAC;YAEvD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE;gBAC9B,MAAM;gBACN,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,YAAY;gBACZ,UAAU;aACV,CAAC;iBACA,IAAI,CAAC,CAAC,GAAG,EAAQ,EAAE;gBACnB,MAAM,QAAQ,GAAS;oBACtB,IAAI,EAAE,MAAM;oBACZ,KAAK,EAAE,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC;iBAChC,CAAC;gBACF,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;YACnC,CAAC,CAAC,CAAC;YAEJ,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC,CAAC;AACH,CAAC,CAAC"}
|
package/dist/render.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
declare const FORMATS: readonly ["png", "svg"];
|
|
2
|
+
export type Format = (typeof FORMATS)[number];
|
|
2
3
|
export interface RenderOptions {
|
|
3
4
|
/** Output format. Defaults to `"svg"`. */
|
|
4
5
|
format?: Format;
|
|
@@ -7,19 +8,24 @@ export interface RenderOptions {
|
|
|
7
8
|
/** Path to the `lilypond` binary. Defaults to `"lilypond"`. */
|
|
8
9
|
binaryPath?: string;
|
|
9
10
|
/**
|
|
10
|
-
* Crop the output
|
|
11
|
-
*
|
|
11
|
+
* Crop the output tightly to the content bounding box.
|
|
12
|
+
* Disable if full-page renders are preferred.
|
|
13
|
+
* Defaults to `true`.
|
|
12
14
|
*/
|
|
13
15
|
crop?: boolean;
|
|
14
16
|
/**
|
|
15
|
-
* Extra directories LilyPond should search for `\include`d files
|
|
16
|
-
*
|
|
17
|
-
* containing the source `.ly`/Markdown file, so sibling
|
|
18
|
-
* `\include "foo.ily"` files resolve even though rendering happens in a
|
|
19
|
-
* temp directory.
|
|
17
|
+
* Extra directories LilyPond should search for `\include`d files.
|
|
18
|
+
* Typically the directory containing the source `.ly`/Markdown file.
|
|
20
19
|
*/
|
|
21
20
|
includePaths?: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Base name to give the temp input file passed to LilyPond, so build
|
|
23
|
+
* output (e.g. `Processing "bach-schenker.ly"`). Falls back to
|
|
24
|
+
* `"input.ly"` when omitted or unsafe to use as a filename.
|
|
25
|
+
*/
|
|
26
|
+
sourceName?: string;
|
|
22
27
|
}
|
|
23
|
-
export declare const defaultOptions: Required<Omit<RenderOptions, "includePaths">>;
|
|
28
|
+
export declare const defaultOptions: Required<Omit<RenderOptions, "includePaths" | "sourceName">>;
|
|
24
29
|
export declare function render(source: string, options?: RenderOptions): Promise<Buffer>;
|
|
30
|
+
export {};
|
|
25
31
|
//# sourceMappingURL=render.d.ts.map
|
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAsBA,QAAA,MAAM,OAAO,YAAI,KAAK,EAAE,KAAK,CAAU,CAAC;AAExC,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9C,MAAM,WAAW,aAAa;IAC7B,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB;;;;OAIG;IACF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,cAAc,GAAG,YAAY,CAAC,CAKvF,CAAC;AAEF,wBAAsB,MAAM,CAC3B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,aAAkB,GACzB,OAAO,CAAC,MAAM,CAAC,CAkEjB"}
|
package/dist/render.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { execFile } from "child_process";
|
|
2
2
|
import { mkdtemp, readFile, rm, writeFile } from "fs/promises";
|
|
3
|
-
import { join } from "path";
|
|
3
|
+
import { basename, join } from "path";
|
|
4
4
|
import { tmpdir } from "os";
|
|
5
5
|
import { promisify } from "util";
|
|
6
6
|
const execFileAsync = promisify(execFile);
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
// Concurrent `lilypond` processes can encounter race conditions
|
|
8
|
+
// and corrupt the output. Serialize invocations of the binary so
|
|
9
|
+
// no two processes build at once.
|
|
10
|
+
let invocationQueue = Promise.resolve();
|
|
11
|
+
function runExclusive(task) {
|
|
12
|
+
const result = invocationQueue.then(task, task);
|
|
13
|
+
invocationQueue = result.then(() => undefined, () => undefined);
|
|
14
|
+
return result;
|
|
14
15
|
}
|
|
15
|
-
const
|
|
16
|
-
midi: null,
|
|
17
|
-
pdf: "--pdf",
|
|
18
|
-
png: "--png",
|
|
19
|
-
ps: "--ps",
|
|
20
|
-
svg: "--svg",
|
|
21
|
-
eps: "--eps",
|
|
22
|
-
};
|
|
16
|
+
const FORMATS = ["png", "svg"];
|
|
23
17
|
export const defaultOptions = {
|
|
24
18
|
format: "svg",
|
|
25
19
|
resolution: 144,
|
|
@@ -27,45 +21,73 @@ export const defaultOptions = {
|
|
|
27
21
|
crop: true,
|
|
28
22
|
};
|
|
29
23
|
export async function render(source, options = {}) {
|
|
30
|
-
const { format = defaultOptions.format, resolution = defaultOptions.resolution, binaryPath = defaultOptions.binaryPath, crop = defaultOptions.crop, includePaths = [], } = options;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
throw new Error(`${opts.format} is not a supported format`);
|
|
24
|
+
const { format = defaultOptions.format, resolution = defaultOptions.resolution, binaryPath = defaultOptions.binaryPath, crop = defaultOptions.crop, includePaths = [], sourceName, } = options;
|
|
25
|
+
if (!FORMATS.includes(format)) {
|
|
26
|
+
throw new Error(`${format} is not a supported format`);
|
|
34
27
|
}
|
|
35
28
|
const dir = await mkdtemp(join(tmpdir(), "astro-lilypond-"));
|
|
36
|
-
const inputPath = join(dir,
|
|
29
|
+
const inputPath = join(dir, safeInputFileName(sourceName));
|
|
37
30
|
const outputBase = join(dir, "output");
|
|
38
31
|
try {
|
|
39
32
|
await writeFile(inputPath, source, "utf8");
|
|
40
33
|
const args = [
|
|
41
|
-
|
|
42
|
-
`--
|
|
34
|
+
// Render the correct format
|
|
35
|
+
`--format=${format}`,
|
|
36
|
+
// Define defaults — these can be overridden with the appropriate flags
|
|
37
|
+
// inside of individual .ly files
|
|
38
|
+
// Disable point-and-click behavior on SVGs when clicking noteheads
|
|
43
39
|
"--define-default=no-point-and-click",
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"--
|
|
40
|
+
// Use the `cairo` backend for graphics rendering; faster than the default `ps` backend
|
|
41
|
+
// https://lilypond.org/doc/v2.26/Documentation/usage/advanced-command_002dline-options-for-lilypond
|
|
42
|
+
"--define-default=backend=cairo",
|
|
43
|
+
// Resolution for generating PNGs (set in DPI)
|
|
44
|
+
`--define-default=resolution=${resolution}`,
|
|
45
|
+
// Set cropping
|
|
46
|
+
`--define-default=crop=${crop ? "#t" : "#f"}`,
|
|
47
|
+
// If the LilyPond file imports from others via \include, make sure those files are included
|
|
48
|
+
...includePaths.map((p) => `--include=${p}`),
|
|
47
49
|
"--output",
|
|
48
50
|
outputBase,
|
|
49
51
|
inputPath,
|
|
50
|
-
]
|
|
52
|
+
];
|
|
53
|
+
// LilyPond writes its progress log, and any warnings/errors, to stderr
|
|
54
|
+
// even on success — surface it in the build output so it's visible,
|
|
55
|
+
// but let the exit code (not stderr content) decide pass/fail.
|
|
51
56
|
let stderr;
|
|
52
57
|
try {
|
|
53
|
-
({ stderr } = await execFileAsync(
|
|
58
|
+
({ stderr } = await runExclusive(() => execFileAsync(binaryPath, args)));
|
|
54
59
|
}
|
|
55
60
|
catch (err) {
|
|
56
61
|
const errStderr = err && typeof err === "object" && "stderr" in err
|
|
57
62
|
? String(err.stderr)
|
|
58
63
|
: undefined;
|
|
64
|
+
if (errStderr)
|
|
65
|
+
process.stderr.write(errStderr);
|
|
59
66
|
throw new Error(errStderr || (err instanceof Error ? err.message : String(err)));
|
|
60
67
|
}
|
|
61
|
-
if (stderr
|
|
62
|
-
|
|
63
|
-
return await readOutputFile(outputBase,
|
|
68
|
+
if (stderr)
|
|
69
|
+
process.stderr.write(stderr);
|
|
70
|
+
return await readOutputFile(outputBase, format, crop);
|
|
64
71
|
}
|
|
65
72
|
finally {
|
|
66
73
|
await rm(dir, { recursive: true, force: true });
|
|
67
74
|
}
|
|
68
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Resolves the base name to use for the temp input file. Strips any
|
|
78
|
+
* directory components from `sourceName` (it may be a full path) and
|
|
79
|
+
* rejects anything that isn't a plain, safe file name, falling back to
|
|
80
|
+
* the generic `"input.ly"`.
|
|
81
|
+
*/
|
|
82
|
+
function safeInputFileName(sourceName) {
|
|
83
|
+
if (!sourceName)
|
|
84
|
+
return "input.ly";
|
|
85
|
+
const base = basename(sourceName);
|
|
86
|
+
if (!base || base === "." || base === ".." || !/^[\w.-]+$/.test(base)) {
|
|
87
|
+
return "input.ly";
|
|
88
|
+
}
|
|
89
|
+
return base;
|
|
90
|
+
}
|
|
69
91
|
async function readOutputFile(base, format, crop) {
|
|
70
92
|
// --define-default crop writes <base>.cropped.<format> alongside <base>.<format>
|
|
71
93
|
if (crop) {
|
|
@@ -77,7 +99,7 @@ async function readOutputFile(base, format, crop) {
|
|
|
77
99
|
}
|
|
78
100
|
}
|
|
79
101
|
// Regular output: single page → <base>.<format>, multi-page →
|
|
80
|
-
// <base>-1.<format> (svg
|
|
102
|
+
// <base>-1.<format> (svg) or <base>-page1.<format> (png).
|
|
81
103
|
try {
|
|
82
104
|
return await readFile(`${base}.${format}`);
|
|
83
105
|
}
|
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ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C;IAAC,MAAM,CAAC;QACR,IAAI,CAAC;YACJ,OAAO,MAAM,QAAQ,CAAC,GAAG,IAAI,MAAM,MAAM,EAAE,CAAC,CAAC;QAC9C,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,MAAM,QAAQ,CAAC,GAAG,IAAI,UAAU,MAAM,EAAE,CAAC,CAAC;QAClD,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"satteri-plugin.d.ts","sourceRoot":"","sources":["../src/satteri-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,qBAAqB,EAErB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"satteri-plugin.d.ts","sourceRoot":"","sources":["../src/satteri-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,qBAAqB,EAErB,MAAM,SAAS,CAAC;AASjB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AAEzD,wBAAgB,qBAAqB,CACpC,OAAO,GAAE,oBAAyB,GAChC,qBAAqB,CA2BvB"}
|
package/dist/satteri-plugin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { render } from "./render.js";
|
|
2
|
-
import { includePathsFor, isLilypondLang, prependVersion, renderToHtml,
|
|
1
|
+
import { defaultOptions, render } from "./render.js";
|
|
2
|
+
import { includePathsFor, isLilypondLang, prependVersion, renderToHtml, sourceNameFor, } from "./util.js";
|
|
3
3
|
export function satteriLilypondPlugin(options = {}) {
|
|
4
4
|
return {
|
|
5
5
|
name: "astro-lilypond",
|
|
@@ -12,9 +12,16 @@ export function satteriLilypondPlugin(options = {}) {
|
|
|
12
12
|
const source = options.version
|
|
13
13
|
? prependVersion(node.value, options.version)
|
|
14
14
|
: node.value;
|
|
15
|
-
const
|
|
15
|
+
const format = options.format ?? defaultOptions.format;
|
|
16
16
|
const includePaths = includePathsFor(ctx.fileURL);
|
|
17
|
-
const
|
|
17
|
+
const sourceName = sourceNameFor(ctx.fileURL);
|
|
18
|
+
const buf = await render(source, {
|
|
19
|
+
format,
|
|
20
|
+
resolution: options.resolution,
|
|
21
|
+
crop: options.crop,
|
|
22
|
+
includePaths,
|
|
23
|
+
sourceName,
|
|
24
|
+
});
|
|
18
25
|
return { type: "html", value: renderToHtml(buf, format) };
|
|
19
26
|
},
|
|
20
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"satteri-plugin.js","sourceRoot":"","sources":["../src/satteri-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"satteri-plugin.js","sourceRoot":"","sources":["../src/satteri-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EACN,eAAe,EACf,cAAc,EACd,cAAc,EACd,YAAY,EACZ,aAAa,GACb,MAAM,WAAW,CAAC;AAKnB,MAAM,UAAU,qBAAqB,CACpC,OAAO,GAAyB,EAAE;IAElC,OAAO;QACN,IAAI,EAAE,gBAAgB;QACtB,wEAAwE;QACxE,sEAAsE;QACtE,yEAAyE;QACzE,KAAK,CAAC,IAAI,CACT,IAAoB,EACpB,GAAwB;YAExB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;gBAAE,OAAO,SAAS,CAAC;YACjD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO;gBAC7B,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;gBAC7C,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;YACd,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,cAAc,CAAC,MAAM,CAAC;YACvD,MAAM,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAClD,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC9C,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,MAAM,EAAE;gBAChC,MAAM;gBACN,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,YAAY;gBACZ,UAAU;aACV,CAAC,CAAC;YACH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC;QAC3D,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/util.d.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
export type OutputFormat = "svg" | "png" | {
|
|
2
|
-
type: "png";
|
|
3
|
-
resolution: number;
|
|
4
|
-
};
|
|
5
1
|
export interface LilypondPluginOptions {
|
|
6
2
|
version?: string;
|
|
7
|
-
format?:
|
|
3
|
+
format?: "svg" | "png";
|
|
4
|
+
resolution?: number;
|
|
8
5
|
crop?: boolean;
|
|
9
6
|
}
|
|
10
7
|
/** Returns true for the fenced-block language identifiers that trigger SVG rendering. */
|
|
11
8
|
export declare function isLilypondLang(lang: string | null | undefined): boolean;
|
|
12
|
-
/** Normalises an OutputFormat value into a plain format string and optional resolution (DPI). */
|
|
13
|
-
export declare function resolveFormat(format: OutputFormat): {
|
|
14
|
-
format: "svg" | "png";
|
|
15
|
-
resolution?: number;
|
|
16
|
-
};
|
|
17
9
|
/**
|
|
18
10
|
* If `version` is provided and the source doesn't already declare `\version`,
|
|
19
11
|
* prepend `\version "X.X.X"` so users don't need to write it manually.
|
|
@@ -25,6 +17,15 @@ export declare function prependVersion(source: string, version: string): string;
|
|
|
25
17
|
* directory. Returns `[]` when the source location is unknown.
|
|
26
18
|
*/
|
|
27
19
|
export declare function includePathsFor(source: string | URL | null | undefined): string[];
|
|
28
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Derives `render()`'s `sourceName` from the source file's path or URL, so
|
|
22
|
+
* build output identifies the originating file instead of a generic
|
|
23
|
+
* `input.ly`. Returns `undefined` when the source location is unknown.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sourceNameFor(source: string | URL | null | undefined): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Converts a rendered LilyPond buffer to an HTML string suitable for
|
|
28
|
+
* embedding.
|
|
29
|
+
*/
|
|
29
30
|
export declare function renderToHtml(buf: Buffer, format: "svg" | "png"): string;
|
|
30
31
|
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAGA,MAAM,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,qBAAqB;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAED,yFAAyF;AACzF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAEvE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGtE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,EAAE,CAIjF;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAIzF;AAOD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAGvE"}
|
package/dist/util.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import { dirname } from "path";
|
|
1
|
+
import { basename, dirname } from "path";
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
/** Returns true for the fenced-block language identifiers that trigger SVG rendering. */
|
|
4
4
|
export function isLilypondLang(lang) {
|
|
5
5
|
return lang === "lilypond" || lang === "ly" || lang === "ily";
|
|
6
6
|
}
|
|
7
|
-
/** Normalises an OutputFormat value into a plain format string and optional resolution (DPI). */
|
|
8
|
-
export function resolveFormat(format) {
|
|
9
|
-
if (typeof format === "string")
|
|
10
|
-
return { format };
|
|
11
|
-
return { format: format.type, resolution: format.resolution };
|
|
12
|
-
}
|
|
13
7
|
/**
|
|
14
8
|
* If `version` is provided and the source doesn't already declare `\version`,
|
|
15
9
|
* prepend `\version "X.X.X"` so users don't need to write it manually.
|
|
@@ -30,12 +24,27 @@ export function includePathsFor(source) {
|
|
|
30
24
|
const path = typeof source === "string" ? source : fileURLToPath(source);
|
|
31
25
|
return [dirname(path)];
|
|
32
26
|
}
|
|
33
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Derives `render()`'s `sourceName` from the source file's path or URL, so
|
|
29
|
+
* build output identifies the originating file instead of a generic
|
|
30
|
+
* `input.ly`. Returns `undefined` when the source location is unknown.
|
|
31
|
+
*/
|
|
32
|
+
export function sourceNameFor(source) {
|
|
33
|
+
if (!source)
|
|
34
|
+
return undefined;
|
|
35
|
+
const path = typeof source === "string" ? source : fileURLToPath(source);
|
|
36
|
+
return basename(path);
|
|
37
|
+
}
|
|
38
|
+
const MIME_TYPES = {
|
|
39
|
+
svg: "image/svg+xml",
|
|
40
|
+
png: "image/png",
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Converts a rendered LilyPond buffer to an HTML string suitable for
|
|
44
|
+
* embedding.
|
|
45
|
+
*/
|
|
34
46
|
export function renderToHtml(buf, format) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return `<img class="lilypond" src="data:image/png;base64,${b64}" alt="LilyPond notation">`;
|
|
38
|
-
}
|
|
39
|
-
return buf.toString("utf-8").replace(/<svg\b/, '<svg class="lilypond"');
|
|
47
|
+
const b64 = buf.toString("base64");
|
|
48
|
+
return `<img class="lilypond" src="data:${MIME_TYPES[format]};base64,${b64}" alt="">`;
|
|
40
49
|
}
|
|
41
50
|
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AASpC,yFAAyF;AACzF,MAAM,UAAU,cAAc,CAAC,IAA+B;IAC7D,OAAO,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,OAAe;IAC7D,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,OAAO,cAAc,OAAO,MAAM,MAAM,EAAE,CAAC;AAC5C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuC;IACtE,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,MAAM,IAAI,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACzE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAuC;IACpE,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,MAAM,IAAI,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACzE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,GAAG;IAClB,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,WAAW;CACP,CAAC;AAEX;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,MAAqB;IAC9D,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnC,OAAO,mCAAmC,UAAU,CAAC,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;AACvF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-lilypond",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "An Astro integration for rendering Lilypond
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "An Astro integration for rendering Lilypond markup to music notation.",
|
|
5
|
+
"homepage": "https://lilypond.ky.fyi",
|
|
6
|
+
"author": "Ky Decker",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/kydecker/astro-lilypond"
|
|
11
|
+
},
|
|
5
12
|
"type": "module",
|
|
6
13
|
"main": "./dist/index.js",
|
|
7
14
|
"types": "./dist/index.d.ts",
|
|
@@ -24,15 +31,14 @@
|
|
|
24
31
|
"images",
|
|
25
32
|
"lilypond",
|
|
26
33
|
"markdown",
|
|
34
|
+
"media",
|
|
27
35
|
"music",
|
|
28
|
-
"
|
|
36
|
+
"renderer",
|
|
37
|
+
"score",
|
|
38
|
+
"tooling",
|
|
39
|
+
"withastro",
|
|
40
|
+
"utils"
|
|
29
41
|
],
|
|
30
|
-
"repository": {
|
|
31
|
-
"type": "git",
|
|
32
|
-
"url": "https://github.com/kydecker/astro-lilypond"
|
|
33
|
-
},
|
|
34
|
-
"author": "Ky Decker",
|
|
35
|
-
"license": "MIT",
|
|
36
42
|
"peerDependencies": {
|
|
37
43
|
"astro": ">=7.0.0"
|
|
38
44
|
},
|