astro-abcjs 1.1.0 → 2.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-abcjs",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "An Astro component to embed abcjs in content",
5
5
  "keywords": [
6
6
  "astro",
@@ -1,19 +1,36 @@
1
1
  ---
2
2
  // AbcjsPlayer.astro
3
3
  // Reusable Astro component for rendering ABCjs music notation and audio playback
4
+
4
5
  import "abcjs/abcjs-audio.css";
5
6
 
7
+ // Use official abcjs types
8
+ import type { AbcVisualParams } from "abcjs";
9
+
10
+ // Props interface using official abcjs types
6
11
  interface Props {
7
12
  notation: string;
13
+ /**
14
+ * Options for abcjs.renderAbc (see AbcVisualParams in abcjs types)
15
+ * Note: Function callbacks (e.g., clickListener) are not supported as options
16
+ * are serialized to JSON for client-side use. For advanced interactivity, use
17
+ * custom events or request a callback/event API.
18
+ */
19
+ options?: AbcVisualParams;
20
+ /**
21
+ * Show audio playback controls (default: true)
22
+ */
8
23
  showControls?: boolean;
9
- responsive?: boolean;
24
+ /**
25
+ * abcjs version to load from CDN (default: "6.6.0")
26
+ */
10
27
  abcjsVersion?: string;
11
28
  }
12
29
 
13
30
  const {
14
31
  notation,
32
+ options = {},
15
33
  showControls = true,
16
- responsive = true,
17
34
  abcjsVersion = "6.6.0",
18
35
  } = Astro.props;
19
36
  ---
@@ -21,13 +38,13 @@ const {
21
38
  <div
22
39
  class="abcjs-container"
23
40
  data-notation={notation}
24
- data-responsive={responsive}
41
+ data-options={JSON.stringify(options)}
25
42
  >
26
43
  <div class="abcjs-paper"></div>
27
44
  {showControls && <div class="abcjs-audio" />}
28
45
  </div>
29
46
 
30
- <script define:vars={{ abcjsVersion }}>
47
+ <script define:vars={{ abcjsVersion, options }}>
31
48
  if (typeof window !== "undefined") {
32
49
  // Load abcjs browser build from CDN if not already loaded
33
50
  if (!window.ABCJS) {
@@ -47,19 +64,14 @@ const {
47
64
  if (container.dataset.abcjsInitialized === "true") return;
48
65
  const notation = container.getAttribute("data-notation");
49
66
  if (!notation) return;
50
- const isResponsive =
51
- container.getAttribute("data-responsive") === "true";
52
67
  const paperDiv = container.querySelector(".abcjs-paper");
53
68
  const audioDiv = container.querySelector(".abcjs-audio");
54
- // Render music notation
55
- const visualObj = abcjs.renderAbc(paperDiv, notation, {
56
- responsive: isResponsive ? "resize" : undefined,
57
- add_classes: true,
58
- paddingleft: 0,
59
- paddingright: 0,
60
- paddingbottom: 10,
61
- paddingtop: 10,
62
- });
69
+ // Render music notation using options prop (passed via define:vars)
70
+ // Render music notation using per-container options
71
+ const containerOptions = JSON.parse(
72
+ container.getAttribute("data-options") || "{}",
73
+ );
74
+ const visualObj = abcjs.renderAbc(paperDiv, notation, containerOptions);
63
75
  // Audio playback controls
64
76
  if (audioDiv && abcjs.synth) {
65
77
  const synthControl = new abcjs.synth.SynthController();