astro-lilypond 0.5.1 → 0.6.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.
Files changed (103) hide show
  1. package/README.md +12 -7
  2. package/components/LilyPond.astro +11 -11
  3. package/dist/deleteAssets.d.ts +27 -0
  4. package/dist/deleteAssets.d.ts.map +1 -0
  5. package/dist/deleteAssets.js +52 -0
  6. package/dist/deleteAssets.js.map +1 -0
  7. package/dist/execLilyPond.d.ts +18 -0
  8. package/dist/execLilyPond.d.ts.map +1 -0
  9. package/dist/execLilyPond.js +58 -0
  10. package/dist/execLilyPond.js.map +1 -0
  11. package/dist/index.d.ts +25 -9
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +71 -21
  14. package/dist/index.js.map +1 -1
  15. package/dist/plugins/index.d.ts +5 -0
  16. package/dist/plugins/index.d.ts.map +1 -0
  17. package/dist/plugins/index.js +4 -0
  18. package/dist/plugins/index.js.map +1 -0
  19. package/dist/plugins/rehype.d.ts +6 -0
  20. package/dist/plugins/rehype.d.ts.map +1 -0
  21. package/dist/plugins/rehype.js +70 -0
  22. package/dist/plugins/rehype.js.map +1 -0
  23. package/dist/plugins/remark.d.ts +6 -0
  24. package/dist/plugins/remark.d.ts.map +1 -0
  25. package/dist/plugins/remark.js +50 -0
  26. package/dist/plugins/remark.js.map +1 -0
  27. package/dist/plugins/satteri.d.ts +5 -0
  28. package/dist/plugins/satteri.d.ts.map +1 -0
  29. package/dist/plugins/satteri.js +51 -0
  30. package/dist/plugins/satteri.js.map +1 -0
  31. package/dist/plugins/types.d.ts +22 -0
  32. package/dist/plugins/types.d.ts.map +1 -0
  33. package/dist/plugins/types.js +2 -0
  34. package/dist/plugins/types.js.map +1 -0
  35. package/dist/readOutputFile.d.ts +10 -0
  36. package/dist/readOutputFile.d.ts.map +1 -0
  37. package/dist/readOutputFile.js +42 -0
  38. package/dist/readOutputFile.js.map +1 -0
  39. package/dist/render.d.ts +7 -2
  40. package/dist/render.d.ts.map +1 -1
  41. package/dist/render.js +17 -83
  42. package/dist/render.js.map +1 -1
  43. package/dist/utils/assetsUrlBaseFor.d.ts +7 -0
  44. package/dist/utils/assetsUrlBaseFor.d.ts.map +1 -0
  45. package/dist/utils/assetsUrlBaseFor.js +11 -0
  46. package/dist/utils/assetsUrlBaseFor.js.map +1 -0
  47. package/dist/utils/contentHashFor.d.ts +20 -0
  48. package/dist/utils/contentHashFor.d.ts.map +1 -0
  49. package/dist/utils/contentHashFor.js +21 -0
  50. package/dist/utils/contentHashFor.js.map +1 -0
  51. package/dist/utils/imgTag.d.ts +5 -0
  52. package/dist/utils/imgTag.d.ts.map +1 -0
  53. package/dist/utils/imgTag.js +7 -0
  54. package/dist/utils/imgTag.js.map +1 -0
  55. package/dist/utils/includePathsFor.d.ts +7 -0
  56. package/dist/utils/includePathsFor.d.ts.map +1 -0
  57. package/dist/utils/includePathsFor.js +14 -0
  58. package/dist/utils/includePathsFor.js.map +1 -0
  59. package/dist/utils/index.d.ts +10 -0
  60. package/dist/utils/index.d.ts.map +1 -0
  61. package/dist/utils/index.js +10 -0
  62. package/dist/utils/index.js.map +1 -0
  63. package/dist/utils/isLilypondLang.d.ts +3 -0
  64. package/dist/utils/isLilypondLang.d.ts.map +1 -0
  65. package/dist/utils/isLilypondLang.js +5 -0
  66. package/dist/utils/isLilypondLang.js.map +1 -0
  67. package/dist/utils/ownAssetFileName.d.ts +12 -0
  68. package/dist/utils/ownAssetFileName.d.ts.map +1 -0
  69. package/dist/utils/ownAssetFileName.js +25 -0
  70. package/dist/utils/ownAssetFileName.js.map +1 -0
  71. package/dist/utils/prependVersion.d.ts +6 -0
  72. package/dist/utils/prependVersion.d.ts.map +1 -0
  73. package/dist/utils/prependVersion.js +10 -0
  74. package/dist/utils/prependVersion.js.map +1 -0
  75. package/dist/utils/sourceNameFor.d.ts +7 -0
  76. package/dist/utils/sourceNameFor.d.ts.map +1 -0
  77. package/dist/utils/sourceNameFor.js +14 -0
  78. package/dist/utils/sourceNameFor.js.map +1 -0
  79. package/dist/utils/titleFor.d.ts +8 -0
  80. package/dist/utils/titleFor.d.ts.map +1 -0
  81. package/dist/utils/titleFor.js +19 -0
  82. package/dist/utils/titleFor.js.map +1 -0
  83. package/dist/writeAsset.d.ts +31 -0
  84. package/dist/writeAsset.d.ts.map +1 -0
  85. package/dist/writeAsset.js +29 -0
  86. package/dist/writeAsset.js.map +1 -0
  87. package/package.json +2 -2
  88. package/dist/rehype-plugin.d.ts +0 -6
  89. package/dist/rehype-plugin.d.ts.map +0 -1
  90. package/dist/rehype-plugin.js +0 -54
  91. package/dist/rehype-plugin.js.map +0 -1
  92. package/dist/remark-plugin.d.ts +0 -6
  93. package/dist/remark-plugin.d.ts.map +0 -1
  94. package/dist/remark-plugin.js +0 -35
  95. package/dist/remark-plugin.js.map +0 -1
  96. package/dist/satteri-plugin.d.ts +0 -5
  97. package/dist/satteri-plugin.d.ts.map +0 -1
  98. package/dist/satteri-plugin.js +0 -29
  99. package/dist/satteri-plugin.js.map +0 -1
  100. package/dist/util.d.ts +0 -31
  101. package/dist/util.d.ts.map +0 -1
  102. package/dist/util.js +0 -50
  103. package/dist/util.js.map +0 -1
package/README.md CHANGED
@@ -4,25 +4,24 @@ An [Astro](https://astro.build) integration for rendering [LilyPond](https://lil
4
4
 
5
5
  - Render LilyPond via Markdown or with a `<LilyPond>` component
6
6
  - Works with both `unified()` and `satteri()` Markdown processors
7
+ - Zero runtime JavaScript!
7
8
  - Supports all LilyPond syntax
8
9
 
9
10
  Docs: https://lilypond.ky.fyi
10
11
 
11
12
  ## Quick Start
12
13
 
13
- ### Prerequisites
14
+ ### 1. Install LilyPond
14
15
 
15
16
  Install the LilyPond binary directly from [lilypond.org](https://lilypond.org/download.html) or with `brew install lilypond` (Mac) or `apt install lilypond` (Linux).
16
17
 
17
- ### Installation
18
-
19
- #### 1. Install `astro-lilypond`
18
+ ### 2. Install `astro-lilypond`
20
19
 
21
20
  ```sh
22
21
  pnpm add astro-lilypond
23
22
  ```
24
23
 
25
- #### 2. Add the integration to your Astro config
24
+ ### 3. Add the integration to your Astro config
26
25
 
27
26
  ```js
28
27
  // astro.config.mjs
@@ -34,9 +33,9 @@ export default defineConfig({
34
33
  });
35
34
  ```
36
35
 
37
- #### 3. Write your music
36
+ ### 4. Write your music
38
37
 
39
- Write LilyPond code within fenced code blocks with the `lilypond` or `ly` language tag.
38
+ Write LilyPond code within fenced code blocks with the `lilypond`, `ly`, or `ily` language tag.
40
39
 
41
40
  ````md
42
41
  ```lilypond
@@ -45,3 +44,9 @@ Write LilyPond code within fenced code blocks with the `lilypond` or `ly` langua
45
44
  ````
46
45
 
47
46
  Your score will be built to `.svg` or `.png` and display alongside the rest of your content.
47
+
48
+ ---
49
+
50
+ For more info, refer to the docs: https://lilypond.ky.fyi
51
+
52
+ Happy notating!
@@ -1,29 +1,29 @@
1
1
  ---
2
2
  const HTML_ENTITIES: Record<string, string> = {
3
- "&": "&amp;",
4
- "<": "&lt;",
5
- ">": "&gt;",
6
- '"': "&quot;",
7
- "'": "&#39;",
3
+ "&": "&amp;",
4
+ "<": "&lt;",
5
+ ">": "&gt;",
6
+ '"': "&quot;",
7
+ "'": "&#39;",
8
8
  };
9
9
 
10
10
  function escapeHtml(text: unknown): string {
11
- return String(text).replace(/[&<>"']/g, (c) => HTML_ENTITIES[c] ?? c);
11
+ return String(text).replace(/[&<>"']/g, (c) => HTML_ENTITIES[c] ?? c);
12
12
  }
13
13
 
14
14
  interface Props {
15
- content: string;
16
- class?: string | undefined;
17
- style?: string | undefined;
15
+ content: string;
16
+ class?: string | undefined;
17
+ style?: string | undefined;
18
18
  }
19
19
 
20
20
  const { content, class: className, style } = Astro.props;
21
21
 
22
22
  let html = content;
23
23
  if (className)
24
- html = html.replace('class="lilypond"', `class="lilypond ${className}"`);
24
+ html = html.replace('class="lilypond"', `class="lilypond ${className}"`);
25
25
  if (style)
26
- html = html.replace(/<(svg|img)\b/, `<$1 style="${escapeHtml(style)}"`);
26
+ html = html.replace(/<(svg|img)\b/, `<$1 style="${escapeHtml(style)}"`);
27
27
  ---
28
28
 
29
29
  <Fragment set:html={html} />
@@ -0,0 +1,27 @@
1
+ export interface PruneOrphanedAssetsOptions {
2
+ /** Absolute filesystem path to the assets output directory. */
3
+ dir: string;
4
+ /** Filenames (e.g. `"ab12…ef.svg"`) referenced during this build. */
5
+ referenced: ReadonlySet<string>;
6
+ logger?: {
7
+ info: (message: string) => void;
8
+ };
9
+ }
10
+ /** Deletes our content-addressed files under `dir` that weren't referenced this build. */
11
+ export declare function pruneOrphanedAssets(options: PruneOrphanedAssetsOptions): Promise<void>;
12
+ export interface PruneStaleAssetsOptions {
13
+ /** Per-source history of output filenames, keyed by module id or file path. */
14
+ assetsBySource: Map<string, Set<string>>;
15
+ /** Stable identifier for the source these `fileNames` were rendered from. */
16
+ sourceKey: string;
17
+ /** Every output filename this source's current transform pass produced. */
18
+ fileNames: readonly string[];
19
+ /** Absolute filesystem path the files live in. */
20
+ outputDir: string;
21
+ logger?: {
22
+ info: (message: string) => void;
23
+ };
24
+ }
25
+ /** Deletes a source's own previously-rendered files that it no longer produces. */
26
+ export declare function pruneStaleAssets(options: PruneStaleAssetsOptions): Promise<void>;
27
+ //# sourceMappingURL=deleteAssets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteAssets.d.ts","sourceRoot":"","sources":["../src/deleteAssets.ts"],"names":[],"mappings":"AAuCA,MAAM,WAAW,0BAA0B;IAC1C,+DAA+D;IAC/D,GAAG,EAAE,MAAM,CAAC;IAEZ,qEAAqE;IACrE,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAEhC,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,CAAC;CAC7C;AAED,0FAA0F;AAC1F,wBAAsB,mBAAmB,CACxC,OAAO,EAAE,0BAA0B,GACjC,OAAO,CAAC,IAAI,CAAC,CAqBf;AAED,MAAM,WAAW,uBAAuB;IACvC,+EAA+E;IAC/E,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAEzC,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;IAElB,2EAA2E;IAC3E,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAE7B,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAElB,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,CAAC;CAC7C;AAED,mFAAmF;AACnF,wBAAsB,gBAAgB,CACrC,OAAO,EAAE,uBAAuB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAkBf"}
@@ -0,0 +1,52 @@
1
+ import { readdir, unlink } from "node:fs/promises";
2
+ import { join, relative } from "node:path";
3
+ import { isOwnAssetFileName } from "./utils/index.js";
4
+ /** Deletes `fileNames` from `dir` and logs a one-line summary. Ignores files that are already gone. */
5
+ async function deleteAssets(options) {
6
+ const { dir, fileNames, reason, context, logger } = options;
7
+ if (fileNames.length === 0)
8
+ return;
9
+ await Promise.all(fileNames.map((name) => unlink(join(dir, name)).catch(() => { })));
10
+ logger?.info(`astro-lilypond: pruned ${fileNames.length} ${reason} asset${fileNames.length === 1 ? "" : "s"} from ${context}`);
11
+ }
12
+ /** Relativizes `path` to the current working directory for log messages. */
13
+ function relativeToCwd(path) {
14
+ return relative(process.cwd(), path) || ".";
15
+ }
16
+ /** Deletes our content-addressed files under `dir` that weren't referenced this build. */
17
+ export async function pruneOrphanedAssets(options) {
18
+ const { dir, referenced, logger } = options;
19
+ let entries;
20
+ try {
21
+ entries = await readdir(dir);
22
+ }
23
+ catch {
24
+ return;
25
+ }
26
+ const orphaned = entries.filter((name) => isOwnAssetFileName(name) && !referenced.has(name));
27
+ await deleteAssets({
28
+ dir,
29
+ fileNames: orphaned,
30
+ reason: "orphaned",
31
+ context: relativeToCwd(dir),
32
+ logger,
33
+ });
34
+ }
35
+ /** Deletes a source's own previously-rendered files that it no longer produces. */
36
+ export async function pruneStaleAssets(options) {
37
+ const { assetsBySource, sourceKey, fileNames, outputDir, logger } = options;
38
+ const next = new Set(fileNames);
39
+ const previous = assetsBySource.get(sourceKey);
40
+ assetsBySource.set(sourceKey, next);
41
+ if (!previous)
42
+ return;
43
+ const stale = [...previous].filter((name) => !next.has(name));
44
+ await deleteAssets({
45
+ dir: outputDir,
46
+ fileNames: stale,
47
+ reason: "stale",
48
+ context: relativeToCwd(sourceKey),
49
+ logger,
50
+ });
51
+ }
52
+ //# sourceMappingURL=deleteAssets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteAssets.js","sourceRoot":"","sources":["../src/deleteAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAkBtD,uGAAuG;AACvG,KAAK,UAAU,YAAY,CAAC,OAA4B;IACvD,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC5D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAEnC,MAAM,OAAO,CAAC,GAAG,CAChB,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,CAChE,CAAC;IAEF,MAAM,EAAE,IAAI,CACX,0BAA0B,SAAS,CAAC,MAAM,IAAI,MAAM,SAAS,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,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AAG,CAAC,GAAG,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAE9D,MAAM,YAAY,CAAC;QAClB,GAAG,EAAE,SAAS;QACd,SAAS,EAAE,KAAK;QAChB,MAAM,EAAE,OAAO;QACf,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC;QACjC,MAAM;KACN,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Format } from "./render.js";
2
+ export interface ExecLilypondOptions {
3
+ binaryPath: string;
4
+ format: Format;
5
+ resolution: number;
6
+ crop: boolean;
7
+ includePaths: string[];
8
+ timeout: number;
9
+ inputPath: string;
10
+ outputBase: string;
11
+ }
12
+ /**
13
+ * Invokes the `lilypond` binary against an already-written input file.
14
+ * Resolves once compilation succeeds (surfacing any stderr warnings to the
15
+ * build output); throws a normalized Error on a non-zero exit or timeout.
16
+ */
17
+ export declare function execLilyPond(options: ExecLilypondOptions): Promise<void>;
18
+ //# sourceMappingURL=execLilyPond.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execLilyPond.d.ts","sourceRoot":"","sources":["../src/execLilyPond.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAM1C,MAAM,WAAW,mBAAmB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CACjC,OAAO,EAAE,mBAAmB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAgEf"}
@@ -0,0 +1,58 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ const execFileAsync = promisify(execFile);
4
+ const MAX_BUFFER = 16 * 1024 * 1024; // 16 MiB
5
+ /**
6
+ * Invokes the `lilypond` binary against an already-written input file.
7
+ * Resolves once compilation succeeds (surfacing any stderr warnings to the
8
+ * build output); throws a normalized Error on a non-zero exit or timeout.
9
+ */
10
+ export async function execLilyPond(options) {
11
+ const { binaryPath, format, resolution, crop, includePaths, timeout, inputPath, outputBase, } = options;
12
+ const args = [
13
+ // Render the correct format
14
+ `--format=${format}`,
15
+ // Define defaults — these can be overridden with the appropriate flags
16
+ // inside of individual .ly files
17
+ // Disable point-and-click behavior on SVGs when clicking noteheads
18
+ "--define-default=no-point-and-click",
19
+ // Use the `cairo` backend for graphics rendering; faster than the default `ps` backend
20
+ // https://lilypond.org/doc/v2.26/Documentation/usage/advanced-command_002dline-options-for-lilypond
21
+ "--define-default=backend=cairo",
22
+ // Resolution for generating PNGs (set in DPI)
23
+ `--define-default=resolution=${resolution}`,
24
+ // Set cropping
25
+ `--define-default=crop=${crop ? "#t" : "#f"}`,
26
+ // If the LilyPond file imports from others via \include, make sure those files are included
27
+ ...includePaths.map((p) => `--include=${p}`),
28
+ "--output",
29
+ outputBase,
30
+ inputPath,
31
+ ];
32
+ // LilyPond writes its progress log, (and any warnings/errors) to stderr,
33
+ // even on success. surface it in the build output so it's visible,
34
+ // but let the exit code (not stderr content) decide pass/fail.
35
+ let stderr;
36
+ try {
37
+ ({ stderr } = await execFileAsync(binaryPath, args, {
38
+ signal: AbortSignal.timeout(timeout),
39
+ maxBuffer: MAX_BUFFER,
40
+ }));
41
+ }
42
+ catch (err) {
43
+ if (err &&
44
+ typeof err === "object" &&
45
+ err.name === "AbortError") {
46
+ throw new Error(`lilypond timed out after ${timeout}ms`);
47
+ }
48
+ const errStderr = err && typeof err === "object" && "stderr" in err
49
+ ? String(err.stderr)
50
+ : undefined;
51
+ if (errStderr)
52
+ process.stderr.write(errStderr);
53
+ throw new Error(errStderr || (err instanceof Error ? err.message : String(err)));
54
+ }
55
+ if (stderr)
56
+ process.stderr.write(stderr);
57
+ }
58
+ //# sourceMappingURL=execLilyPond.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execLilyPond.js","sourceRoot":"","sources":["../src/execLilyPond.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,MAAM,UAAU,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,SAAS;AAa9C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,OAA4B;IAE5B,MAAM,EACL,UAAU,EACV,MAAM,EACN,UAAU,EACV,IAAI,EACJ,YAAY,EACZ,OAAO,EACP,SAAS,EACT,UAAU,GACV,GAAG,OAAO,CAAC;IAEZ,MAAM,IAAI,GAAG;QACZ,4BAA4B;QAC5B,YAAY,MAAM,EAAE;QAEpB,uEAAuE;QACvE,iCAAiC;QAEjC,mEAAmE;QACnE,qCAAqC;QACrC,uFAAuF;QACvF,oGAAoG;QACpG,gCAAgC;QAChC,8CAA8C;QAC9C,+BAA+B,UAAU,EAAE;QAC3C,eAAe;QACf,yBAAyB,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;QAE7C,4FAA4F;QAC5F,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC;QAE5C,UAAU;QACV,UAAU;QACV,SAAS;KACT,CAAC;IAEF,yEAAyE;IACzE,mEAAmE;IACnE,+DAA+D;IAC/D,IAAI,MAAc,CAAC;IACnB,IAAI,CAAC;QACJ,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE;YACnD,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC;YACpC,SAAS,EAAE,UAAU;SACrB,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,IACC,GAAG;YACH,OAAO,GAAG,KAAK,QAAQ;YACtB,GAAyB,CAAC,IAAI,KAAK,YAAY,EAC/C,CAAC;YACF,MAAM,IAAI,KAAK,CAAC,4BAA4B,OAAO,IAAI,CAAC,CAAC;QAC1D,CAAC;QACD,MAAM,SAAS,GACd,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,QAAQ,IAAI,GAAG;YAChD,CAAC,CAAC,MAAM,CAAE,GAA2B,CAAC,MAAM,CAAC;YAC7C,CAAC,CAAC,SAAS,CAAC;QACd,IAAI,SAAS;YAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC/C,MAAM,IAAI,KAAK,CACd,SAAS,IAAI,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAC/D,CAAC;IACH,CAAC;IACD,IAAI,MAAM;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { AstroIntegration } from "astro";
2
- import type { LilypondPluginOptions } from "./util.js";
3
- export type { LilypondPluginOptions };
4
- export interface LilypondOptions extends LilypondPluginOptions {
2
+ import { type PluginOptions } from "./plugins/index.js";
3
+ export type { PluginOptions as LilypondPluginOptions };
4
+ export interface LilypondOptions extends PluginOptions {
5
5
  /**
6
6
  * LilyPond version string to prepend automatically to every block that
7
7
  * doesn't already declare `\version`. Example: `"2.24.0"`.
@@ -10,20 +10,36 @@ export interface LilypondOptions extends LilypondPluginOptions {
10
10
  */
11
11
  version?: string;
12
12
  /**
13
- * Output format. Defaults to `"svg"`.
14
- *
15
- * - `"svg"` — inline SVG embedded directly in the HTML (default)
16
- * - `"png"` — `<img>` element with a base64 data URI
13
+ * Output format to be written to a file under `outputDir`.
14
+ * @default "svg"
17
15
  */
18
16
  format?: "svg" | "png";
19
17
  /**
20
- * Resolution in DPI (only applies to PNG). Defaults to `144`.
18
+ * Resolution in DPI. Only applies when "format" is "png".
19
+ * @default 144
21
20
  */
22
21
  resolution?: number;
23
22
  /**
24
- * Crop the output tightly to the content bounding box. Defaults to `true`.
23
+ * Crop the output tightly to the content bounding box.
24
+ * @default true
25
25
  */
26
26
  crop?: boolean;
27
+ /**
28
+ * Milliseconds to wait for a single `lilypond` invocation before
29
+ * aborting it.
30
+ * @default 60000
31
+ */
32
+ timeout?: number;
33
+ /**
34
+ * Directory name, relative to Astro's `publicDir`, that rendered assets
35
+ * are written into by both `astro dev` and `astro build`. Filenames are
36
+ * content-addressed, so unchanged scores are reused instead of being
37
+ * re-rendered, and it's safe to commit this directory if you'd like
38
+ * faster rebuilds.
39
+ *
40
+ * @default "_lilypond"
41
+ */
42
+ outputDir?: string;
27
43
  }
28
44
  export default function lilypond(options?: LilypondOptions): AstroIntegration;
29
45
  //# sourceMappingURL=index.d.ts.map
@@ -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,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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAG9C,OAAO,EACN,KAAK,aAAa,EAKlB,MAAM,oBAAoB,CAAC;AAiB5B,YAAY,EAAE,aAAa,IAAI,qBAAqB,EAAE,CAAC;AAEvD,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACrD;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAEvB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AA4CD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC/B,OAAO,GAAE,eAAoB,GAC3B,gBAAgB,CA2IlB"}
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
- import { execFile } from "child_process";
2
- import { promisify } from "util";
3
- import { remarkLilypondPlugin } from "./remark-plugin.js";
4
- import { rehypeLilypondPlugin } from "./rehype-plugin.js";
5
- import { satteriLilypondPlugin } from "./satteri-plugin.js";
1
+ import { execFile } from "node:child_process";
2
+ import { join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { promisify } from "node:util";
5
+ import { pruneOrphanedAssets, pruneStaleAssets } from "./deleteAssets.js";
6
+ import { rehypePlugin, remarkPlugin, satteriPlugin, } from "./plugins/index.js";
6
7
  import { defaultOptions, render } from "./render.js";
7
- import { includePathsFor, prependVersion, renderToHtml, sourceNameFor } from "./util.js";
8
+ import { assetsUrlBaseFor, contentHashFor, imgTag, includePathsFor, prependVersion, sourceNameFor, titleFor, } from "./utils/index.js";
9
+ import { writeAsset } from "./writeAsset.js";
8
10
  const execFileAsync = promisify(execFile);
9
11
  const LY_EXTENSIONS = [".ly", ".lilypond", ".ily"];
10
12
  function lyFilePlugin(options) {
@@ -12,22 +14,46 @@ function lyFilePlugin(options) {
12
14
  name: "vite-plugin-astro-lilypond-ly",
13
15
  enforce: "pre",
14
16
  async transform(source, id) {
15
- if (!LY_EXTENSIONS.some(ext => id.endsWith(ext)))
17
+ if (!LY_EXTENSIONS.some((ext) => id.endsWith(ext)))
16
18
  return;
17
- const src = options.version ? prependVersion(source, options.version) : source;
19
+ const src = options.version
20
+ ? prependVersion(source, options.version)
21
+ : source;
18
22
  const format = options.format ?? defaultOptions.format;
19
- const buf = await render(src, {
23
+ const resolution = options.resolution ?? defaultOptions.resolution;
24
+ const crop = options.crop ?? defaultOptions.crop;
25
+ const includePaths = includePathsFor(id);
26
+ const sourceName = sourceNameFor(id);
27
+ const title = titleFor(sourceName);
28
+ const hash = contentHashFor({ source: src, format, resolution, crop });
29
+ const fileName = `${hash}.${title}.${format}`;
30
+ const url = await writeAsset({
31
+ hash,
32
+ title,
20
33
  format,
21
- resolution: options.resolution,
22
- crop: options.crop,
23
- includePaths: includePathsFor(id),
24
- sourceName: sourceNameFor(id),
34
+ outputDir: options.assetsDir,
35
+ urlBase: options.assetsUrlBase,
36
+ trackAsset: options.trackAsset,
37
+ getBuffer: () => render(src, {
38
+ format,
39
+ resolution: options.resolution,
40
+ crop: options.crop,
41
+ timeout: options.timeout,
42
+ includePaths,
43
+ sourceName,
44
+ }),
25
45
  });
26
- return { code: `export default ${JSON.stringify(renderToHtml(buf, format))}` };
46
+ await options.pruneStaleAssets(id, [fileName]);
47
+ return {
48
+ code: `export default ${JSON.stringify(imgTag(url))}`,
49
+ };
27
50
  },
28
51
  };
29
52
  }
30
53
  export default function lilypond(options = {}) {
54
+ const referencedAssets = new Set();
55
+ const assetsBySource = new Map();
56
+ let assetsDir;
31
57
  return {
32
58
  name: "astro-lilypond",
33
59
  hooks: {
@@ -37,8 +63,25 @@ export default function lilypond(options = {}) {
37
63
  logger?.warn("astro-lilypond: `lilypond` binary not found — LilyPond blocks will render as errors. Install LilyPond and ensure it is on PATH.");
38
64
  }
39
65
  });
66
+ const outputDirName = options.outputDir ?? "_lilypond";
67
+ const assetsUrlBase = assetsUrlBaseFor(config.base, outputDirName);
68
+ const resolvedAssetsDir = join(fileURLToPath(config.publicDir), outputDirName);
69
+ assetsDir = resolvedAssetsDir;
70
+ const resolvedOptions = {
71
+ ...options,
72
+ assetsDir,
73
+ assetsUrlBase,
74
+ trackAsset: (fileName) => referencedAssets.add(fileName),
75
+ pruneStaleAssets: (sourceKey, fileNames) => pruneStaleAssets({
76
+ assetsBySource,
77
+ sourceKey,
78
+ fileNames,
79
+ outputDir: resolvedAssetsDir,
80
+ logger,
81
+ }),
82
+ };
40
83
  updateConfig({
41
- vite: { plugins: [lyFilePlugin(options)] },
84
+ vite: { plugins: [lyFilePlugin(resolvedOptions)] },
42
85
  });
43
86
  const existingProcessor = config.markdown?.processor;
44
87
  if (existingProcessor?.name === "satteri") {
@@ -54,7 +97,7 @@ export default function lilypond(options = {}) {
54
97
  ...existingOptions,
55
98
  mdastPlugins: [
56
99
  ...(existingOptions.mdastPlugins ?? []),
57
- satteriLilypondPlugin(options),
100
+ satteriPlugin(resolvedOptions),
58
101
  ],
59
102
  }),
60
103
  },
@@ -75,11 +118,11 @@ export default function lilypond(options = {}) {
75
118
  ...existingOptions,
76
119
  remarkPlugins: [
77
120
  ...(existingOptions.remarkPlugins ?? []),
78
- [remarkLilypondPlugin, options],
121
+ [remarkPlugin, resolvedOptions],
79
122
  ],
80
123
  rehypePlugins: [
81
124
  ...(existingOptions.rehypePlugins ?? []),
82
- [rehypeLilypondPlugin, options],
125
+ [rehypePlugin, resolvedOptions],
83
126
  ],
84
127
  }),
85
128
  },
@@ -95,9 +138,16 @@ export default function lilypond(options = {}) {
95
138
  "astro:config:done": ({ injectTypes }) => {
96
139
  injectTypes({
97
140
  filename: "ly-types.d.ts",
98
- content: LY_EXTENSIONS
99
- .map(ext => `declare module "*${ext}" {\n const html: string;\n export default html;\n}`)
100
- .join("\n"),
141
+ content: LY_EXTENSIONS.map((ext) => `declare module "*${ext}" {\n const html: string;\n export default html;\n}`).join("\n"),
142
+ });
143
+ },
144
+ "astro:build:done": async ({ logger }) => {
145
+ if (!assetsDir)
146
+ return;
147
+ await pruneOrphanedAssets({
148
+ dir: assetsDir,
149
+ referenced: referencedAssets,
150
+ logger,
101
151
  });
102
152
  },
103
153
  },
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,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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B,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,CAAC,GAAG,CACzB,CAAC,GAAG,EAAE,EAAE,CACP,oBAAoB,GAAG,uDAAuD,CAC/E,CAAC,IAAI,CAAC,IAAI,CAAC;iBACZ,CAAC,CAAC;YACJ,CAAC;YAED,kBAAkB,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;gBACxC,IAAI,CAAC,SAAS;oBAAE,OAAO;gBACvB,MAAM,mBAAmB,CAAC;oBACzB,GAAG,EAAE,SAAS;oBACd,UAAU,EAAE,gBAAgB;oBAC5B,MAAM;iBACN,CAAC,CAAC;YACJ,CAAC;SACD;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { rehypePlugin } from "./rehype.js";
2
+ export { remarkPlugin } from "./remark.js";
3
+ export { satteriPlugin } from "./satteri.js";
4
+ export type { PluginOptions, ResolvedPluginOptions } from "./types.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { rehypePlugin } from "./rehype.js";
2
+ export { remarkPlugin } from "./remark.js";
3
+ export { satteriPlugin } from "./satteri.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { ResolvedPluginOptions } from "./types.js";
2
+ export type RehypePluginOptions = ResolvedPluginOptions;
3
+ export declare function rehypePlugin(options: RehypePluginOptions): (tree: any, file?: {
4
+ path?: string;
5
+ }) => Promise<void>;
6
+ //# sourceMappingURL=rehype.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rehype.d.ts","sourceRoot":"","sources":["../../src/plugins/rehype.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAQxD,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAIxD,wBAAgB,YAAY,CAC3B,OAAO,EAAE,mBAAmB,GAE1B,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAyExD"}
@@ -0,0 +1,70 @@
1
+ import { visit } from "unist-util-visit";
2
+ import { defaultOptions, render } from "../render.js";
3
+ import { contentHashFor, imgTag, includePathsFor, isLilypondLang, prependVersion, sourceNameFor, titleFor, } from "../utils/index.js";
4
+ import { writeAsset } from "../writeAsset.js";
5
+ // Typed loosely so it's assignable to both RehypePlugin and the unified
6
+ // Plugin generic regardless of which @types/hast version the host project pins.
7
+ export function rehypePlugin(options) {
8
+ return async (tree, file) => {
9
+ const promises = [];
10
+ const fileNames = [];
11
+ const includePaths = includePathsFor(file?.path);
12
+ const sourceName = sourceNameFor(file?.path);
13
+ const title = titleFor(sourceName);
14
+ visit(tree, "element", (node, index, parent) => {
15
+ if (node.tagName !== "pre" ||
16
+ node.children?.length !== 1 ||
17
+ node.children[0].type !== "element" ||
18
+ node.children[0].tagName !== "code" ||
19
+ index === undefined ||
20
+ !parent)
21
+ return;
22
+ const codeNode = node.children[0];
23
+ const cls = codeNode.properties?.className;
24
+ if (!Array.isArray(cls))
25
+ return;
26
+ const lang = cls
27
+ .find((c) => c.startsWith("language-"))
28
+ ?.slice("language-".length);
29
+ if (!isLilypondLang(lang))
30
+ return;
31
+ const raw = codeNode.children
32
+ .filter((c) => c.type === "text")
33
+ .map((c) => c.value)
34
+ .join("");
35
+ const source = options.version
36
+ ? prependVersion(raw, options.version)
37
+ : raw;
38
+ const format = options.format ?? defaultOptions.format;
39
+ const resolution = options.resolution ?? defaultOptions.resolution;
40
+ const crop = options.crop ?? defaultOptions.crop;
41
+ const hash = contentHashFor({ source, format, resolution, crop });
42
+ fileNames.push(`${hash}.${title}.${format}`);
43
+ const promise = writeAsset({
44
+ hash,
45
+ title,
46
+ format,
47
+ outputDir: options.assetsDir,
48
+ urlBase: options.assetsUrlBase,
49
+ trackAsset: options.trackAsset,
50
+ getBuffer: () => render(source, {
51
+ format,
52
+ resolution: options.resolution,
53
+ crop: options.crop,
54
+ timeout: options.timeout,
55
+ includePaths,
56
+ sourceName,
57
+ }),
58
+ }).then((url) => {
59
+ const rawNode = { type: "raw", value: imgTag(url) };
60
+ parent.children[index] = rawNode;
61
+ });
62
+ promises.push(promise);
63
+ });
64
+ await Promise.all(promises);
65
+ if (file?.path) {
66
+ await options.pruneStaleAssets(file.path, fileNames);
67
+ }
68
+ };
69
+ }
70
+ //# sourceMappingURL=rehype.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rehype.js","sourceRoot":"","sources":["../../src/plugins/rehype.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACN,cAAc,EACd,MAAM,EACN,eAAe,EACf,cAAc,EACd,cAAc,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,YAAY;oBACZ,UAAU;iBACV,CAAC;aACH,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAQ,EAAE;gBACrB,MAAM,OAAO,GAAY,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC7D,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;YAClC,CAAC,CAAC,CAAC;YAEH,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAE5B,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC;YAChB,MAAM,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACtD,CAAC;IACF,CAAC,CAAC;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { Root } from "mdast";
2
+ import type { Plugin } from "unified";
3
+ import type { ResolvedPluginOptions } from "./types.js";
4
+ export type RemarkPluginOptions = ResolvedPluginOptions;
5
+ export declare const remarkPlugin: Plugin<[RemarkPluginOptions], Root>;
6
+ //# sourceMappingURL=remark.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remark.d.ts","sourceRoot":"","sources":["../../src/plugins/remark.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,IAAI,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAatC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAExD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,CAAC,mBAAmB,CAAC,EAAE,IAAI,CAkD5D,CAAC"}