@chordsketch/node 0.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/index.d.ts +72 -0
- package/index.js +88 -0
- package/package.json +57 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @chordsketch/node — TypeScript declarations.
|
|
2
|
+
//
|
|
3
|
+
// Mirrors the public API defined by `crates/napi/src/lib.rs` #[napi] items.
|
|
4
|
+
// Keep in sync with the Rust source: every exported function and object
|
|
5
|
+
// over there must have a matching declaration here.
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Rendering options accepted by the `*WithOptions` functions.
|
|
9
|
+
*
|
|
10
|
+
* Matches the `RenderOptions` struct in `crates/napi/src/lib.rs`.
|
|
11
|
+
*/
|
|
12
|
+
export interface RenderOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Semitone transposition offset. Defaults to 0.
|
|
15
|
+
*
|
|
16
|
+
* Any integer is accepted, but values outside the i8 range (-128..=127)
|
|
17
|
+
* are clamped before the underlying renderer reduces modulo 12.
|
|
18
|
+
*/
|
|
19
|
+
transpose?: number;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Configuration preset name (e.g. "guitar", "ukulele") or an inline
|
|
23
|
+
* RRJSON configuration string.
|
|
24
|
+
*/
|
|
25
|
+
config?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A single validation issue reported by `validate`.
|
|
30
|
+
*/
|
|
31
|
+
export interface ValidationError {
|
|
32
|
+
/** One-based line number of the issue within the input. */
|
|
33
|
+
line: number;
|
|
34
|
+
/** Column offset (byte) within the line, one-based. */
|
|
35
|
+
column: number;
|
|
36
|
+
/** Human-readable description of the issue. */
|
|
37
|
+
message: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Returns the version string baked into the compiled Rust crate. */
|
|
41
|
+
export function version(): string;
|
|
42
|
+
|
|
43
|
+
/** Renders the ChordPro source to plain text. */
|
|
44
|
+
export function renderText(source: string): string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Renders the ChordPro source to plain text with rendering options applied.
|
|
48
|
+
*/
|
|
49
|
+
export function renderTextWithOptions(source: string, options: RenderOptions): string;
|
|
50
|
+
|
|
51
|
+
/** Renders the ChordPro source to HTML. */
|
|
52
|
+
export function renderHtml(source: string): string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Renders the ChordPro source to HTML with rendering options applied.
|
|
56
|
+
*/
|
|
57
|
+
export function renderHtmlWithOptions(source: string, options: RenderOptions): string;
|
|
58
|
+
|
|
59
|
+
/** Renders the ChordPro source to a PDF document, returned as a Buffer. */
|
|
60
|
+
export function renderPdf(source: string): Buffer;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Renders the ChordPro source to a PDF document with rendering options
|
|
64
|
+
* applied.
|
|
65
|
+
*/
|
|
66
|
+
export function renderPdfWithOptions(source: string, options: RenderOptions): Buffer;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Validates a ChordPro source document and returns a list of issues. An
|
|
70
|
+
* empty array indicates the document parses cleanly.
|
|
71
|
+
*/
|
|
72
|
+
export function validate(source: string): ValidationError[];
|
package/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// @chordsketch/node — platform resolver for the napi-rs native addon.
|
|
2
|
+
//
|
|
3
|
+
// Loads the right per-platform prebuilt binary package at runtime, matching
|
|
4
|
+
// the napi-rs multi-package convention. The five platform packages declared
|
|
5
|
+
// in `optionalDependencies` of package.json cover every target in the
|
|
6
|
+
// `napi.targets` list of this package's manifest:
|
|
7
|
+
//
|
|
8
|
+
// - @chordsketch/node-linux-x64-gnu (linux x64)
|
|
9
|
+
// - @chordsketch/node-linux-arm64-gnu (linux arm64)
|
|
10
|
+
// - @chordsketch/node-darwin-x64 (macOS x64)
|
|
11
|
+
// - @chordsketch/node-darwin-arm64 (macOS arm64 / Apple Silicon)
|
|
12
|
+
// - @chordsketch/node-win32-x64-msvc (Windows x64)
|
|
13
|
+
//
|
|
14
|
+
// If you see "Unsupported platform" from this file, either the runtime
|
|
15
|
+
// platform is not in the supported list (add a new target to napi.targets,
|
|
16
|
+
// build + publish a prebuilt package, and extend this resolver) OR the
|
|
17
|
+
// right optional dependency failed to install (check npm's error output
|
|
18
|
+
// for the optional dep that was skipped).
|
|
19
|
+
//
|
|
20
|
+
// This file is committed deliberately rather than generated by `napi build`
|
|
21
|
+
// so the publish job does not have to run the Rust build — it only needs
|
|
22
|
+
// to move each platform's .node artifact into its platform subdirectory
|
|
23
|
+
// under `npm/` before running `npm publish`. See docs/releasing.md for the
|
|
24
|
+
// full flow.
|
|
25
|
+
|
|
26
|
+
const { platform, arch } = process;
|
|
27
|
+
|
|
28
|
+
let nativeBinding = null;
|
|
29
|
+
let loadErrors = [];
|
|
30
|
+
|
|
31
|
+
function tryLoad(pkg) {
|
|
32
|
+
try {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
34
|
+
return require(pkg);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
loadErrors.push({ pkg, err });
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
switch (platform) {
|
|
42
|
+
case 'linux':
|
|
43
|
+
if (arch === 'x64') {
|
|
44
|
+
nativeBinding = tryLoad('@chordsketch/node-linux-x64-gnu');
|
|
45
|
+
} else if (arch === 'arm64') {
|
|
46
|
+
nativeBinding = tryLoad('@chordsketch/node-linux-arm64-gnu');
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
|
|
50
|
+
case 'darwin':
|
|
51
|
+
if (arch === 'x64') {
|
|
52
|
+
nativeBinding = tryLoad('@chordsketch/node-darwin-x64');
|
|
53
|
+
} else if (arch === 'arm64') {
|
|
54
|
+
nativeBinding = tryLoad('@chordsketch/node-darwin-arm64');
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case 'win32':
|
|
59
|
+
if (arch === 'x64') {
|
|
60
|
+
nativeBinding = tryLoad('@chordsketch/node-win32-x64-msvc');
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!nativeBinding) {
|
|
66
|
+
if (loadErrors.length > 0) {
|
|
67
|
+
// A matching platform package exists in optionalDependencies but failed
|
|
68
|
+
// to load. Surface the first load error so the user sees the actual
|
|
69
|
+
// require() failure rather than a generic "unsupported platform".
|
|
70
|
+
const { pkg, err } = loadErrors[0];
|
|
71
|
+
const reason = err && err.message ? err.message : String(err);
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Failed to load @chordsketch/node: native binding ${pkg} is installed ` +
|
|
74
|
+
`but could not be loaded (${reason}). This usually means the ` +
|
|
75
|
+
`optional dependency failed to install cleanly; try reinstalling ` +
|
|
76
|
+
`with \`npm install --force @chordsketch/node\`.`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Unsupported platform: ${platform} ${arch}. ` +
|
|
81
|
+
`@chordsketch/node ships prebuilt binaries for linux/darwin (x64, arm64) ` +
|
|
82
|
+
`and win32 x64; other targets must build from source via ` +
|
|
83
|
+
`\`cargo build --release -p chordsketch-napi\`.`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = nativeBinding;
|
|
88
|
+
module.exports.default = nativeBinding;
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chordsketch/node",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Native Node.js addon for ChordPro parsing and rendering via napi-rs.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/koedame/chordsketch.git",
|
|
9
|
+
"directory": "crates/napi"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/koedame/chordsketch",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=15.12.0"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"chordpro",
|
|
17
|
+
"music",
|
|
18
|
+
"chord",
|
|
19
|
+
"parser",
|
|
20
|
+
"lyrics",
|
|
21
|
+
"napi-rs",
|
|
22
|
+
"node-addon",
|
|
23
|
+
"n-api",
|
|
24
|
+
"native"
|
|
25
|
+
],
|
|
26
|
+
"main": "index.js",
|
|
27
|
+
"types": "index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"index.js",
|
|
30
|
+
"index.d.ts"
|
|
31
|
+
],
|
|
32
|
+
"optionalDependencies": {
|
|
33
|
+
"@chordsketch/node-darwin-x64": "0.2.0",
|
|
34
|
+
"@chordsketch/node-darwin-arm64": "0.2.0",
|
|
35
|
+
"@chordsketch/node-linux-x64-gnu": "0.2.0",
|
|
36
|
+
"@chordsketch/node-linux-arm64-gnu": "0.2.0",
|
|
37
|
+
"@chordsketch/node-win32-x64-msvc": "0.2.0"
|
|
38
|
+
},
|
|
39
|
+
"napi": {
|
|
40
|
+
"binaryName": "chordsketch-napi",
|
|
41
|
+
"packageName": "@chordsketch/node",
|
|
42
|
+
"targets": [
|
|
43
|
+
"x86_64-apple-darwin",
|
|
44
|
+
"aarch64-apple-darwin",
|
|
45
|
+
"x86_64-unknown-linux-gnu",
|
|
46
|
+
"aarch64-unknown-linux-gnu",
|
|
47
|
+
"x86_64-pc-windows-msvc"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@napi-rs/cli": "^3.4.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "napi build --release --manifest-path Cargo.toml",
|
|
55
|
+
"build:debug": "napi build --manifest-path Cargo.toml"
|
|
56
|
+
}
|
|
57
|
+
}
|