astro-lilypond 1.1.2 → 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
  }
@@ -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.2",
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,8 +46,8 @@
46
46
  "utils"
47
47
  ],
48
48
  "peerDependencies": {
49
- "astro": ">=7.0.0",
50
- "@astrojs/markdown-remark": ">=7.0.0"
49
+ "@astrojs/markdown-remark": ">=7.0.0",
50
+ "astro": ">=7.0.0"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "@astrojs/markdown-remark": {
@@ -59,17 +59,17 @@
59
59
  "unist-util-visit": "^5.1.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@astrojs/markdown-remark": "^7.2.2",
63
- "@astrojs/markdown-satteri": "^0.3.5",
62
+ "@astrojs/markdown-remark": "^7.3.1",
63
+ "@astrojs/markdown-satteri": "^0.4.1",
64
64
  "@types/mdast": "^4.0.4",
65
- "@types/node": "^26.1.1",
66
- "@vitest/coverage-v8": "^4.1.10",
67
- "astro": "^7.1.6",
68
- "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",
69
69
  "typescript": "^7.0.2",
70
70
  "unified": "^11.0.5",
71
- "vite": "^8.0.0",
72
- "vitest": "^4.1.10"
71
+ "vite": "^8.2.2",
72
+ "vitest": "^4.1.11"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "tsc --project tsconfig.build.json",