astro-lilypond 0.5.2 → 0.7.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/deleteAssets.d.ts +27 -0
- package/dist/deleteAssets.d.ts.map +1 -0
- package/dist/deleteAssets.js +52 -0
- package/dist/deleteAssets.js.map +1 -0
- package/dist/execLilyPond.d.ts +2 -3
- package/dist/execLilyPond.d.ts.map +1 -1
- package/dist/execLilyPond.js +2 -1
- package/dist/execLilyPond.js.map +1 -1
- package/dist/index.d.ts +19 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +60 -15
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/rehype.d.ts +3 -3
- package/dist/plugins/rehype.d.ts.map +1 -1
- package/dist/plugins/rehype.js +27 -16
- package/dist/plugins/rehype.js.map +1 -1
- package/dist/plugins/remark.d.ts +3 -3
- package/dist/plugins/remark.d.ts.map +1 -1
- package/dist/plugins/remark.js +27 -16
- package/dist/plugins/remark.js.map +1 -1
- package/dist/plugins/satteri.d.ts +3 -3
- package/dist/plugins/satteri.d.ts.map +1 -1
- package/dist/plugins/satteri.js +29 -12
- package/dist/plugins/satteri.js.map +1 -1
- package/dist/plugins/types.d.ts +16 -3
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/render.d.ts +46 -11
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +11 -6
- package/dist/render.js.map +1 -1
- package/dist/types/lilypondVersion.d.ts +6 -0
- package/dist/types/lilypondVersion.d.ts.map +1 -0
- package/dist/types/lilypondVersion.js +2 -0
- package/dist/types/lilypondVersion.js.map +1 -0
- package/dist/utils/assetsUrlBaseFor.d.ts +7 -0
- package/dist/utils/assetsUrlBaseFor.d.ts.map +1 -0
- package/dist/utils/assetsUrlBaseFor.js +11 -0
- package/dist/utils/assetsUrlBaseFor.js.map +1 -0
- package/dist/utils/contentHashFor.d.ts +20 -0
- package/dist/utils/contentHashFor.d.ts.map +1 -0
- package/dist/utils/contentHashFor.js +21 -0
- package/dist/utils/contentHashFor.js.map +1 -0
- package/dist/utils/imgTag.d.ts +5 -0
- package/dist/utils/imgTag.d.ts.map +1 -0
- package/dist/utils/imgTag.js +7 -0
- package/dist/utils/imgTag.js.map +1 -0
- package/dist/utils/index.d.ts +6 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +6 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/ownAssetFileName.d.ts +12 -0
- package/dist/utils/ownAssetFileName.d.ts.map +1 -0
- package/dist/utils/ownAssetFileName.js +25 -0
- package/dist/utils/ownAssetFileName.js.map +1 -0
- package/dist/utils/resolveDefaults.d.ts +4 -0
- package/dist/utils/resolveDefaults.d.ts.map +1 -0
- package/dist/utils/resolveDefaults.js +11 -0
- package/dist/utils/resolveDefaults.js.map +1 -0
- package/dist/utils/titleFor.d.ts +8 -0
- package/dist/utils/titleFor.d.ts.map +1 -0
- package/dist/utils/titleFor.js +19 -0
- package/dist/utils/titleFor.js.map +1 -0
- package/dist/writeAsset.d.ts +31 -0
- package/dist/writeAsset.d.ts.map +1 -0
- package/dist/writeAsset.js +29 -0
- package/dist/writeAsset.js.map +1 -0
- package/package.json +1 -1
- package/dist/utils/renderToHtml.d.ts +0 -5
- package/dist/utils/renderToHtml.d.ts.map +0 -1
- package/dist/utils/renderToHtml.js +0 -12
- package/dist/utils/renderToHtml.js.map +0 -1
|
@@ -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,CAA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G,CAAC,SAAS,CAAC,CAAC;IAChC,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC/C,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAEpC,IAAI,CAAC,QAAQ;QAAE,OAAO;IAEtB,MAAM,KAAK,GAAG,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"}
|
package/dist/execLilyPond.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { Format } from "./render.js";
|
|
1
|
+
import type { Format, LilypondDefines } from "./render.js";
|
|
2
2
|
export interface ExecLilypondOptions {
|
|
3
3
|
binaryPath: string;
|
|
4
4
|
format: Format;
|
|
5
|
-
|
|
6
|
-
crop: boolean;
|
|
5
|
+
defaults: Required<LilypondDefines>;
|
|
7
6
|
includePaths: string[];
|
|
8
7
|
timeout: number;
|
|
9
8
|
inputPath: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execLilyPond.d.ts","sourceRoot":"","sources":["../src/execLilyPond.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"execLilyPond.d.ts","sourceRoot":"","sources":["../src/execLilyPond.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAM3D,MAAM,WAAW,mBAAmB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IACpC,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"}
|
package/dist/execLilyPond.js
CHANGED
|
@@ -8,7 +8,8 @@ const MAX_BUFFER = 16 * 1024 * 1024; // 16 MiB
|
|
|
8
8
|
* build output); throws a normalized Error on a non-zero exit or timeout.
|
|
9
9
|
*/
|
|
10
10
|
export async function execLilyPond(options) {
|
|
11
|
-
const { binaryPath, format,
|
|
11
|
+
const { binaryPath, format, defaults, includePaths, timeout, inputPath, outputBase, } = options;
|
|
12
|
+
const { resolution, crop } = defaults;
|
|
12
13
|
const args = [
|
|
13
14
|
// Render the correct format
|
|
14
15
|
`--format=${format}`,
|
package/dist/execLilyPond.js.map
CHANGED
|
@@ -1 +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;
|
|
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,CA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O,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,34 +1,34 @@
|
|
|
1
1
|
import type { AstroIntegration } from "astro";
|
|
2
2
|
import { type PluginOptions } from "./plugins/index.js";
|
|
3
|
-
|
|
3
|
+
import { type LilypondDefaults } from "./render.js";
|
|
4
|
+
export type { LilypondDefaults, PluginOptions as LilypondPluginOptions };
|
|
4
5
|
export interface LilypondOptions extends PluginOptions {
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* When omitted, blocks must include `\version` themselves.
|
|
10
|
-
*/
|
|
11
|
-
version?: string;
|
|
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
|
|
7
|
+
* Output format to be written to a file under `outputDir`.
|
|
8
|
+
* @default "svg"
|
|
17
9
|
*/
|
|
18
10
|
format?: "svg" | "png";
|
|
19
11
|
/**
|
|
20
|
-
*
|
|
12
|
+
* Defaults passed to each score — `version`, `resolution`, `crop`.
|
|
13
|
+
* Each can still be overridden by an individual `.ly` file.
|
|
21
14
|
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Crop the output tightly to the content bounding box. Defaults to `true`.
|
|
25
|
-
*/
|
|
26
|
-
crop?: boolean;
|
|
15
|
+
defaults?: LilypondDefaults;
|
|
27
16
|
/**
|
|
28
17
|
* Milliseconds to wait for a single `lilypond` invocation before
|
|
29
|
-
* aborting it.
|
|
18
|
+
* aborting it.
|
|
19
|
+
* @default 60000
|
|
30
20
|
*/
|
|
31
21
|
timeout?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Directory name, relative to Astro's `publicDir`, that rendered assets
|
|
24
|
+
* are written into by both `astro dev` and `astro build`. Filenames are
|
|
25
|
+
* content-addressed, so unchanged scores are reused instead of being
|
|
26
|
+
* re-rendered, and it's safe to commit this directory if you'd like
|
|
27
|
+
* faster rebuilds.
|
|
28
|
+
*
|
|
29
|
+
* @default "_lilypond"
|
|
30
|
+
*/
|
|
31
|
+
outputDir?: string;
|
|
32
32
|
}
|
|
33
33
|
export default function lilypond(options?: LilypondOptions): AstroIntegration;
|
|
34
34
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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;AAC5B,OAAO,EAAkB,KAAK,gBAAgB,EAAU,MAAM,aAAa,CAAC;AAiB5E,YAAY,EAAE,gBAAgB,EAAE,aAAa,IAAI,qBAAqB,EAAE,CAAC;AAEzE,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACrD;;;OAGG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAEvB;;;OAGG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAE5B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAwCD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC/B,OAAO,GAAE,eAAoB,GAC3B,gBAAgB,CA2IlB"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
2
4
|
import { promisify } from "node:util";
|
|
5
|
+
import { pruneOrphanedAssets, pruneStaleAssets } from "./deleteAssets.js";
|
|
3
6
|
import { rehypePlugin, remarkPlugin, satteriPlugin, } from "./plugins/index.js";
|
|
4
7
|
import { defaultOptions, render } from "./render.js";
|
|
5
|
-
import { includePathsFor, prependVersion,
|
|
8
|
+
import { assetsUrlBaseFor, contentHashFor, imgTag, includePathsFor, prependVersion, resolveDefaults, sourceNameFor, titleFor, } from "./utils/index.js";
|
|
9
|
+
import { writeAsset } from "./writeAsset.js";
|
|
6
10
|
const execFileAsync = promisify(execFile);
|
|
7
11
|
const LY_EXTENSIONS = [".ly", ".lilypond", ".ily"];
|
|
8
12
|
function lyFilePlugin(options) {
|
|
@@ -12,25 +16,40 @@ function lyFilePlugin(options) {
|
|
|
12
16
|
async transform(source, id) {
|
|
13
17
|
if (!LY_EXTENSIONS.some((ext) => id.endsWith(ext)))
|
|
14
18
|
return;
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
: source;
|
|
19
|
+
const { version, resolution, crop } = resolveDefaults(options.defaults);
|
|
20
|
+
const src = version ? prependVersion(source, version) : source;
|
|
18
21
|
const format = options.format ?? defaultOptions.format;
|
|
19
|
-
const
|
|
22
|
+
const includePaths = includePathsFor(id);
|
|
23
|
+
const sourceName = sourceNameFor(id);
|
|
24
|
+
const title = titleFor(sourceName);
|
|
25
|
+
const hash = contentHashFor({ source: src, format, resolution, crop });
|
|
26
|
+
const fileName = `${hash}.${title}.${format}`;
|
|
27
|
+
const url = await writeAsset({
|
|
28
|
+
hash,
|
|
29
|
+
title,
|
|
20
30
|
format,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
outputDir: options.assetsDir,
|
|
32
|
+
urlBase: options.assetsUrlBase,
|
|
33
|
+
trackAsset: options.trackAsset,
|
|
34
|
+
getBuffer: () => render(src, {
|
|
35
|
+
format,
|
|
36
|
+
defaults: options.defaults,
|
|
37
|
+
timeout: options.timeout,
|
|
38
|
+
includePaths,
|
|
39
|
+
sourceName,
|
|
40
|
+
}),
|
|
26
41
|
});
|
|
42
|
+
await options.pruneStaleAssets(id, [fileName]);
|
|
27
43
|
return {
|
|
28
|
-
code: `export default ${JSON.stringify(
|
|
44
|
+
code: `export default ${JSON.stringify(imgTag(url))}`,
|
|
29
45
|
};
|
|
30
46
|
},
|
|
31
47
|
};
|
|
32
48
|
}
|
|
33
49
|
export default function lilypond(options = {}) {
|
|
50
|
+
const referencedAssets = new Set();
|
|
51
|
+
const assetsBySource = new Map();
|
|
52
|
+
let assetsDir;
|
|
34
53
|
return {
|
|
35
54
|
name: "astro-lilypond",
|
|
36
55
|
hooks: {
|
|
@@ -40,8 +59,25 @@ export default function lilypond(options = {}) {
|
|
|
40
59
|
logger?.warn("astro-lilypond: `lilypond` binary not found — LilyPond blocks will render as errors. Install LilyPond and ensure it is on PATH.");
|
|
41
60
|
}
|
|
42
61
|
});
|
|
62
|
+
const outputDirName = options.outputDir ?? "_lilypond";
|
|
63
|
+
const assetsUrlBase = assetsUrlBaseFor(config.base, outputDirName);
|
|
64
|
+
const resolvedAssetsDir = join(fileURLToPath(config.publicDir), outputDirName);
|
|
65
|
+
assetsDir = resolvedAssetsDir;
|
|
66
|
+
const resolvedOptions = {
|
|
67
|
+
...options,
|
|
68
|
+
assetsDir,
|
|
69
|
+
assetsUrlBase,
|
|
70
|
+
trackAsset: (fileName) => referencedAssets.add(fileName),
|
|
71
|
+
pruneStaleAssets: (sourceKey, fileNames) => pruneStaleAssets({
|
|
72
|
+
assetsBySource,
|
|
73
|
+
sourceKey,
|
|
74
|
+
fileNames,
|
|
75
|
+
outputDir: resolvedAssetsDir,
|
|
76
|
+
logger,
|
|
77
|
+
}),
|
|
78
|
+
};
|
|
43
79
|
updateConfig({
|
|
44
|
-
vite: { plugins: [lyFilePlugin(
|
|
80
|
+
vite: { plugins: [lyFilePlugin(resolvedOptions)] },
|
|
45
81
|
});
|
|
46
82
|
const existingProcessor = config.markdown?.processor;
|
|
47
83
|
if (existingProcessor?.name === "satteri") {
|
|
@@ -57,7 +93,7 @@ export default function lilypond(options = {}) {
|
|
|
57
93
|
...existingOptions,
|
|
58
94
|
mdastPlugins: [
|
|
59
95
|
...(existingOptions.mdastPlugins ?? []),
|
|
60
|
-
satteriPlugin(
|
|
96
|
+
satteriPlugin(resolvedOptions),
|
|
61
97
|
],
|
|
62
98
|
}),
|
|
63
99
|
},
|
|
@@ -78,11 +114,11 @@ export default function lilypond(options = {}) {
|
|
|
78
114
|
...existingOptions,
|
|
79
115
|
remarkPlugins: [
|
|
80
116
|
...(existingOptions.remarkPlugins ?? []),
|
|
81
|
-
[remarkPlugin,
|
|
117
|
+
[remarkPlugin, resolvedOptions],
|
|
82
118
|
],
|
|
83
119
|
rehypePlugins: [
|
|
84
120
|
...(existingOptions.rehypePlugins ?? []),
|
|
85
|
-
[rehypePlugin,
|
|
121
|
+
[rehypePlugin, resolvedOptions],
|
|
86
122
|
],
|
|
87
123
|
}),
|
|
88
124
|
},
|
|
@@ -101,6 +137,15 @@ export default function lilypond(options = {}) {
|
|
|
101
137
|
content: LY_EXTENSIONS.map((ext) => `declare module "*${ext}" {\n const html: string;\n export default html;\n}`).join("\n"),
|
|
102
138
|
});
|
|
103
139
|
},
|
|
140
|
+
"astro:build:done": async ({ logger }) => {
|
|
141
|
+
if (!assetsDir)
|
|
142
|
+
return;
|
|
143
|
+
await pruneOrphanedAssets({
|
|
144
|
+
dir: assetsDir,
|
|
145
|
+
referenced: referencedAssets,
|
|
146
|
+
logger,
|
|
147
|
+
});
|
|
148
|
+
},
|
|
104
149
|
},
|
|
105
150
|
};
|
|
106
151
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAGN,YAAY,EACZ,YAAY,EACZ,aAAa,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAyB,MAAM,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EACN,gBAAgB,EAChB,cAAc,EACd,MAAM,EACN,eAAe,EACf,cAAc,EACd,eAAe,EACf,aAAa,EACb,QAAQ,GACR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,MAAM,aAAa,GAAG,CAAC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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"}
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { rehypePlugin } from "./rehype.js";
|
|
2
2
|
export { remarkPlugin } from "./remark.js";
|
|
3
3
|
export { satteriPlugin } from "./satteri.js";
|
|
4
|
-
export type { PluginOptions } from "./types.js";
|
|
4
|
+
export type { PluginOptions, ResolvedPluginOptions } from "./types.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +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,MAAM,YAAY,CAAC"}
|
|
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"}
|
package/dist/plugins/rehype.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type RehypePluginOptions =
|
|
3
|
-
export declare function rehypePlugin(options
|
|
1
|
+
import type { ResolvedPluginOptions } from "./types.js";
|
|
2
|
+
export type RehypePluginOptions = ResolvedPluginOptions;
|
|
3
|
+
export declare function rehypePlugin(options: RehypePluginOptions): (tree: any, file?: {
|
|
4
4
|
path?: string;
|
|
5
5
|
}) => Promise<void>;
|
|
6
6
|
//# sourceMappingURL=rehype.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehype.d.ts","sourceRoot":"","sources":["../../src/plugins/rehype.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rehype.d.ts","sourceRoot":"","sources":["../../src/plugins/rehype.ts"],"names":[],"mappings":"AAaA,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,CAqExD"}
|
package/dist/plugins/rehype.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
2
|
import { defaultOptions, render } from "../render.js";
|
|
3
|
-
import { includePathsFor, isLilypondLang, prependVersion,
|
|
3
|
+
import { contentHashFor, imgTag, includePathsFor, isLilypondLang, prependVersion, resolveDefaults, sourceNameFor, titleFor, } from "../utils/index.js";
|
|
4
|
+
import { writeAsset } from "../writeAsset.js";
|
|
4
5
|
// Typed loosely so it's assignable to both RehypePlugin and the unified
|
|
5
6
|
// Plugin generic regardless of which @types/hast version the host project pins.
|
|
6
|
-
export function rehypePlugin(options
|
|
7
|
+
export function rehypePlugin(options) {
|
|
7
8
|
return async (tree, file) => {
|
|
8
9
|
const promises = [];
|
|
10
|
+
const fileNames = [];
|
|
9
11
|
const includePaths = includePathsFor(file?.path);
|
|
10
12
|
const sourceName = sourceNameFor(file?.path);
|
|
13
|
+
const title = titleFor(sourceName);
|
|
11
14
|
visit(tree, "element", (node, index, parent) => {
|
|
12
15
|
if (node.tagName !== "pre" ||
|
|
13
16
|
node.children?.length !== 1 ||
|
|
@@ -29,27 +32,35 @@ export function rehypePlugin(options = {}) {
|
|
|
29
32
|
.filter((c) => c.type === "text")
|
|
30
33
|
.map((c) => c.value)
|
|
31
34
|
.join("");
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
: raw;
|
|
35
|
+
const { version, resolution, crop } = resolveDefaults(options.defaults);
|
|
36
|
+
const source = version ? prependVersion(raw, version) : raw;
|
|
35
37
|
const format = options.format ?? defaultOptions.format;
|
|
36
|
-
const
|
|
38
|
+
const hash = contentHashFor({ source, format, resolution, crop });
|
|
39
|
+
fileNames.push(`${hash}.${title}.${format}`);
|
|
40
|
+
const promise = writeAsset({
|
|
41
|
+
hash,
|
|
42
|
+
title,
|
|
37
43
|
format,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
44
|
+
outputDir: options.assetsDir,
|
|
45
|
+
urlBase: options.assetsUrlBase,
|
|
46
|
+
trackAsset: options.trackAsset,
|
|
47
|
+
getBuffer: () => render(source, {
|
|
48
|
+
format,
|
|
49
|
+
defaults: options.defaults,
|
|
50
|
+
timeout: options.timeout,
|
|
51
|
+
includePaths,
|
|
52
|
+
sourceName,
|
|
53
|
+
}),
|
|
54
|
+
}).then((url) => {
|
|
55
|
+
const rawNode = { type: "raw", value: imgTag(url) };
|
|
48
56
|
parent.children[index] = rawNode;
|
|
49
57
|
});
|
|
50
58
|
promises.push(promise);
|
|
51
59
|
});
|
|
52
60
|
await Promise.all(promises);
|
|
61
|
+
if (file?.path) {
|
|
62
|
+
await options.pruneStaleAssets(file.path, fileNames);
|
|
63
|
+
}
|
|
53
64
|
};
|
|
54
65
|
}
|
|
55
66
|
//# sourceMappingURL=rehype.js.map
|
|
@@ -1 +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,eAAe,EACf,cAAc,EACd,cAAc,EACd,
|
|
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,EACd,eAAe,EACf,aAAa,EACb,QAAQ,GACR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAW9C,wEAAwE;AACxE,gFAAgF;AAChF,MAAM,UAAU,YAAY,CAC3B,OAA4B;IAG5B,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAoB,EAAE,CAAC;QACrC,MAAM,SAAS,GAAa,EAAE,CAAC;QAC/B,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACjD,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC7C,MAAM,KAAK,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;QAEnC,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC9C,IACC,IAAI,CAAC,OAAO,KAAK,KAAK;gBACtB,IAAI,CAAC,QAAQ,EAAE,MAAM,KAAK,CAAC;gBAC3B,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC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CAAC,GAAG,IAAI,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC,CAAC;YAE7C,MAAM,OAAO,GAAG,UAAU,CAAC;gBAC1B,IAAI;gBACJ,KAAK;gBACL,MAAM;gBACN,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,OAAO,EAAE,OAAO,CAAC,aAAa;gBAC9B,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,SAAS,EAAE,GAAG,EAAE,CACf,MAAM,CAAC,MAAM,EAAE;oBACd,MAAM;oBACN,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,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"}
|
package/dist/plugins/remark.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Root } from "mdast";
|
|
2
2
|
import type { Plugin } from "unified";
|
|
3
|
-
import type {
|
|
4
|
-
export type RemarkPluginOptions =
|
|
5
|
-
export declare const remarkPlugin: Plugin<[RemarkPluginOptions
|
|
3
|
+
import type { ResolvedPluginOptions } from "./types.js";
|
|
4
|
+
export type RemarkPluginOptions = ResolvedPluginOptions;
|
|
5
|
+
export declare const remarkPlugin: Plugin<[RemarkPluginOptions], Root>;
|
|
6
6
|
//# sourceMappingURL=remark.d.ts.map
|
|
@@ -1 +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;
|
|
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;AActC,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,CA8C5D,CAAC"}
|
package/dist/plugins/remark.js
CHANGED
|
@@ -1,35 +1,46 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
2
|
import { defaultOptions, render } from "../render.js";
|
|
3
|
-
import { includePathsFor, isLilypondLang, prependVersion,
|
|
4
|
-
|
|
3
|
+
import { contentHashFor, imgTag, includePathsFor, isLilypondLang, prependVersion, resolveDefaults, sourceNameFor, titleFor, } from "../utils/index.js";
|
|
4
|
+
import { writeAsset } from "../writeAsset.js";
|
|
5
|
+
export const remarkPlugin = (options) => {
|
|
5
6
|
return async (tree, file) => {
|
|
6
7
|
const promises = [];
|
|
8
|
+
const fileNames = [];
|
|
7
9
|
const includePaths = includePathsFor(file?.path);
|
|
8
10
|
const sourceName = sourceNameFor(file?.path);
|
|
11
|
+
const title = titleFor(sourceName);
|
|
9
12
|
visit(tree, "code", (node, index, parent) => {
|
|
10
13
|
if (!isLilypondLang(node.lang) || index === undefined || !parent)
|
|
11
14
|
return;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
: node.value;
|
|
15
|
+
const { version, resolution, crop } = resolveDefaults(options.defaults);
|
|
16
|
+
const source = version ? prependVersion(node.value, version) : node.value;
|
|
15
17
|
const format = options.format ?? defaultOptions.format;
|
|
16
|
-
const
|
|
18
|
+
const hash = contentHashFor({ source, format, resolution, crop });
|
|
19
|
+
fileNames.push(`${hash}.${title}.${format}`);
|
|
20
|
+
const promise = writeAsset({
|
|
21
|
+
hash,
|
|
22
|
+
title,
|
|
17
23
|
format,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
24
|
+
outputDir: options.assetsDir,
|
|
25
|
+
urlBase: options.assetsUrlBase,
|
|
26
|
+
trackAsset: options.trackAsset,
|
|
27
|
+
getBuffer: () => render(source, {
|
|
28
|
+
format,
|
|
29
|
+
defaults: options.defaults,
|
|
30
|
+
timeout: options.timeout,
|
|
31
|
+
includePaths,
|
|
32
|
+
sourceName,
|
|
33
|
+
}),
|
|
34
|
+
}).then((url) => {
|
|
35
|
+
const htmlNode = { type: "html", value: imgTag(url) };
|
|
28
36
|
parent.children[index] = htmlNode;
|
|
29
37
|
});
|
|
30
38
|
promises.push(promise);
|
|
31
39
|
});
|
|
32
40
|
await Promise.all(promises);
|
|
41
|
+
if (file?.path) {
|
|
42
|
+
await options.pruneStaleAssets(file.path, fileNames);
|
|
43
|
+
}
|
|
33
44
|
};
|
|
34
45
|
};
|
|
35
46
|
//# sourceMappingURL=remark.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark.js","sourceRoot":"","sources":["../../src/plugins/remark.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kBA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C;IACF,CAAC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MdastPluginDefinition } from "satteri";
|
|
2
|
-
import type {
|
|
3
|
-
export type SatteriPluginOptions =
|
|
4
|
-
export declare function satteriPlugin(options
|
|
2
|
+
import type { ResolvedPluginOptions } from "./types.js";
|
|
3
|
+
export type SatteriPluginOptions = ResolvedPluginOptions;
|
|
4
|
+
export declare function satteriPlugin(options: SatteriPluginOptions): MdastPluginDefinition;
|
|
5
5
|
//# sourceMappingURL=satteri.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"satteri.d.ts","sourceRoot":"","sources":["../../src/plugins/satteri.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAuB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"satteri.d.ts","sourceRoot":"","sources":["../../src/plugins/satteri.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAuB,MAAM,SAAS,CAAC;AAa1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AAEzD,wBAAgB,aAAa,CAC5B,OAAO,EAAE,oBAAoB,GAC3B,qBAAqB,CA+CvB"}
|