astro-lilypond 1.1.1 → 1.2.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 CHANGED
@@ -3,7 +3,7 @@ import { type AstroComponentFactory } from "astro/runtime/server/index.js";
3
3
  import { type AutoInstallOptions } from "./binary/index.js";
4
4
  import { type PluginOptions } from "./plugins/index.js";
5
5
  import { type LilypondDefaults } from "./render.js";
6
- import { type LilypondMetadata } from "./utils/index.js";
6
+ import { type LilypondMetadata, type RenderedHtmlOptions } from "./utils/index.js";
7
7
  export declare const LY_EXTENSIONS: readonly [".ly", ".lilypond", ".ily"];
8
8
  export type { AstroComponentFactory, AutoInstallOptions, LilypondDefaults, LilypondMetadata, PluginOptions as LilypondPluginOptions, };
9
9
  export interface LilypondPage {
@@ -54,12 +54,7 @@ export interface GetScoreResult {
54
54
  meta: LilypondMetadata;
55
55
  raw: string;
56
56
  }
57
- interface ScoreImageProps {
58
- pageLimit?: number;
59
- class?: string;
60
- style?: string;
61
- alt?: string;
62
- }
57
+ type ScoreImageProps = RenderedHtmlOptions;
63
58
  /**
64
59
  * Renders a `LilypondScore` (from a `.ly`/`.ily`/`.lilypond` import,
65
60
  * or a `lilypondLoader()` entry) to a renderable `<Score />` component.
package/dist/index.js CHANGED
@@ -10,11 +10,7 @@ export const LY_EXTENSIONS = [".ly", ".lilypond", ".ily"];
10
10
  function createScoreComponent(content) {
11
11
  return createComponent((_result, props) => {
12
12
  const alt = props.alt ?? content.alt ?? "";
13
- const html = renderedHtml(content.pages, alt, {
14
- class: props.class,
15
- style: props.style,
16
- pageLimit: props.pageLimit,
17
- });
13
+ const html = renderedHtml(content.pages, { ...props, alt });
18
14
  return renderTemplate `${unescapeHTML(html)}`;
19
15
  });
20
16
  }
@@ -106,6 +102,13 @@ export const Score = createComponent(async (result, props) => {
106
102
  const { Score: ContentScore } = await getScore(content, { format, crop });
107
103
  return renderTemplate `${renderComponent(result, "Score", ContentScore, imageProps)}`;
108
104
  });
105
+ function injectMarkdownPlugin(processor, key, plugin) {
106
+ if (!processor.options) {
107
+ processor.options = {};
108
+ }
109
+ const options = processor.options;
110
+ options[key] = [...(options[key] ?? []), plugin];
111
+ }
109
112
  function lyFilePlugin(options) {
110
113
  return {
111
114
  name: "vite-plugin-astro-lilypond-ly",
@@ -164,44 +167,17 @@ export default function lilypond(options = {}) {
164
167
  });
165
168
  const existingProcessor = config.markdown?.processor;
166
169
  if (existingProcessor?.name === "satteri") {
167
- const { satteri, isSatteriProcessor } = await import("@astrojs/markdown-satteri");
168
- if (!isSatteriProcessor(existingProcessor)) {
169
- throw new Error("astro-lilypond: the active markdown processor reports the name " +
170
- '"satteri" but failed the isSatteriProcessor check.');
171
- }
172
- const existingOptions = existingProcessor.options ?? {};
173
- updateConfig({
174
- markdown: {
175
- processor: satteri({
176
- ...existingOptions,
177
- mdastPlugins: [
178
- ...(existingOptions.mdastPlugins ?? []),
179
- satteriPlugin(options),
180
- ],
181
- }),
182
- },
183
- });
170
+ injectMarkdownPlugin(existingProcessor, "mdastPlugins", satteriPlugin(options));
171
+ updateConfig({ markdown: { processor: existingProcessor } });
184
172
  logger?.info("Registered Sätteri mdast plugin");
185
173
  return;
186
174
  }
187
175
  if (existingProcessor?.name === "unified") {
188
- const { unified, isUnifiedProcessor } = await import("@astrojs/markdown-remark");
189
- if (!isUnifiedProcessor(existingProcessor)) {
190
- throw new Error("astro-lilypond: the active markdown processor reports the name " +
191
- '"unified" but failed the isUnifiedProcessor check.');
192
- }
193
- const existingOptions = existingProcessor.options ?? {};
194
- updateConfig({
195
- markdown: {
196
- processor: unified({
197
- ...existingOptions,
198
- remarkPlugins: [
199
- ...(existingOptions.remarkPlugins ?? []),
200
- [remarkPlugin, options],
201
- ],
202
- }),
203
- },
204
- });
176
+ injectMarkdownPlugin(existingProcessor, "remarkPlugins", [
177
+ remarkPlugin,
178
+ options,
179
+ ]);
180
+ updateConfig({ markdown: { processor: existingProcessor } });
205
181
  logger?.info("Registered unified remark plugin");
206
182
  return;
207
183
  }
@@ -32,7 +32,7 @@ export async function renderMarkdownBlock(options, block) {
32
32
  logger,
33
33
  }),
34
34
  });
35
- return renderedHtml(pages, alt);
35
+ return renderedHtml(pages, { alt });
36
36
  }
37
37
  catch (err) {
38
38
  if (!options.isDev)
@@ -16,7 +16,7 @@ export type { LyHeaderFields } from "./parseLyHeader.js";
16
16
  export { extractMarkupText, parseLyHeader, parseLyHeaderFields, } from "./parseLyHeader.js";
17
17
  export { prependVersion } from "./prependVersion.js";
18
18
  export { renderedErrorHtml } from "./renderedErrorHtml.js";
19
- export { renderedHtml } from "./renderedHtml.js";
19
+ export { type RenderedHtmlOptions, renderedHtml } from "./renderedHtml.js";
20
20
  export { resolveDefaults } from "./resolveDefaults.js";
21
21
  export { sourceNameFor } from "./sourceNameFor.js";
22
22
  export { titleFor } from "./titleFor.js";
@@ -1,5 +1,6 @@
1
+ import type { HTMLAttributes } from "astro/types";
1
2
  import type { LilypondPage } from "../index.js";
2
- export interface RenderedHtmlOptions {
3
+ export interface RenderedHtmlOptions extends Partial<Pick<HTMLAttributes<"img">, "alt" | "loading" | "decoding" | "fetchpriority">> {
3
4
  /** Class applied to the outer `<img>` or `<ol>` tag. */
4
5
  class?: string;
5
6
  /** Inline styles applied to the outer `<img>` or `<ol>`. */
@@ -7,4 +8,4 @@ export interface RenderedHtmlOptions {
7
8
  /** Render only the first `n` pages. */
8
9
  pageLimit?: number;
9
10
  }
10
- export declare function renderedHtml(pages: LilypondPage[], alt: string, options?: RenderedHtmlOptions): string;
11
+ export declare function renderedHtml(pages: LilypondPage[], options?: RenderedHtmlOptions): string;
@@ -1,19 +1,23 @@
1
1
  import { addAttribute } from "astro/runtime/server/index.js";
2
- function imgTag(page, alt) {
3
- return `<img data-lilypond-image${addAttribute(page.src, "src")}${addAttribute(page.width, "width")}${addAttribute(page.height, "height")}${addAttribute(alt, "alt")}>`;
2
+ function imgTag(page, alt, imageAttrs) {
3
+ return `<img data-lilypond-image${addAttribute(page.src, "src")}${addAttribute(page.width, "width")}${addAttribute(page.height, "height")}${addAttribute(alt, "alt")}${imageAttrs}>`;
4
4
  }
5
- export function renderedHtml(pages, alt, options = {}) {
6
- const { class: className, style, pageLimit } = options;
5
+ export function renderedHtml(pages, options = {}) {
6
+ const { alt, class: className, style, pageLimit, loading, decoding, fetchpriority, } = options;
7
+ const resolvedAlt = alt ?? "";
7
8
  const limitedPages = pageLimit === undefined ? pages : pages.slice(0, pageLimit);
8
9
  if (limitedPages.length === 0)
9
10
  return "";
10
11
  const classAttr = addAttribute(className, "class");
11
12
  const styleAttr = addAttribute(style, "style");
13
+ const imageAttrs = addAttribute(loading, "loading") +
14
+ addAttribute(decoding, "decoding") +
15
+ addAttribute(fetchpriority, "fetchpriority");
12
16
  if (limitedPages.length === 1) {
13
17
  const page = limitedPages[0];
14
- return `<img data-lilypond-image${classAttr}${addAttribute(page.src, "src")}${addAttribute(page.width, "width")}${addAttribute(page.height, "height")}${addAttribute(alt, "alt")}${styleAttr}>`;
18
+ return `<img data-lilypond-image${classAttr}${addAttribute(page.src, "src")}${addAttribute(page.width, "width")}${addAttribute(page.height, "height")}${addAttribute(resolvedAlt, "alt")}${imageAttrs}${styleAttr}>`;
15
19
  }
16
20
  return `<ol data-lilypond-group${classAttr}${styleAttr}>${limitedPages
17
- .map((page) => `<li>${imgTag(page, alt)}</li>`)
21
+ .map((page) => `<li>${imgTag(page, resolvedAlt, imageAttrs)}</li>`)
18
22
  .join("")}</ol>`;
19
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-lilypond",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "An Astro integration for rendering Lilypond markup to music notation.",
5
5
  "homepage": "https://lilypond.ky.fyi",
6
6
  "author": "Ky Decker",
@@ -46,24 +46,30 @@
46
46
  "utils"
47
47
  ],
48
48
  "peerDependencies": {
49
+ "@astrojs/markdown-remark": ">=7.0.0",
49
50
  "astro": ">=7.0.0"
50
51
  },
52
+ "peerDependenciesMeta": {
53
+ "@astrojs/markdown-remark": {
54
+ "optional": true
55
+ }
56
+ },
51
57
  "dependencies": {
52
58
  "astro-emit-asset": "^0.1.4",
53
59
  "unist-util-visit": "^5.1.0"
54
60
  },
55
61
  "devDependencies": {
56
- "@astrojs/markdown-remark": "^7.2.2",
57
- "@astrojs/markdown-satteri": "^0.3.5",
62
+ "@astrojs/markdown-remark": "^7.3.1",
63
+ "@astrojs/markdown-satteri": "^0.4.1",
58
64
  "@types/mdast": "^4.0.4",
59
- "@types/node": "^26.1.1",
60
- "@vitest/coverage-v8": "^4.1.10",
61
- "astro": "^7.1.6",
62
- "satteri": "^0.9.5",
65
+ "@types/node": "^26.4.0",
66
+ "@vitest/coverage-v8": "^4.1.11",
67
+ "astro": "^7.3.2",
68
+ "satteri": "^0.10.5",
63
69
  "typescript": "^7.0.2",
64
70
  "unified": "^11.0.5",
65
- "vite": "^8.0.0",
66
- "vitest": "^4.1.10"
71
+ "vite": "^8.2.2",
72
+ "vitest": "^4.1.11"
67
73
  },
68
74
  "scripts": {
69
75
  "build": "tsc --project tsconfig.build.json",