musicxml-io 0.8.0 → 0.8.2

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/README.md CHANGED
@@ -360,7 +360,23 @@ Entry-level helpers for individual notes, directions, and parts.
360
360
  ```typescript
361
361
  import { transpose } from 'musicxml-io/operations';
362
362
  import { findNotes } from 'musicxml-io/query';
363
- import { isRest, getPartName } from 'musicxml-io/entry-accessors';
363
+ import { isRest, getPartName } from 'musicxml-io/accessors';
364
+ ```
365
+
366
+ The package declares `"sideEffects": false`, so bundlers can drop everything
367
+ you don't import — pulling in only `parse` costs roughly 50 KB minified
368
+ (~14 KB gzip).
369
+
370
+ ### Browser usage
371
+
372
+ The main entry exports the Node-only file helpers (`parseFile`,
373
+ `serializeToFile`), which depend on `fs`. Bundlers that honor the `browser`
374
+ condition (webpack, Vite, esbuild with `--platform=browser`, etc.)
375
+ automatically get a browser-safe build without any `fs`/`node:*` imports.
376
+ You can also import it explicitly:
377
+
378
+ ```typescript
379
+ import { parse, serialize } from 'musicxml-io/browser';
364
380
  ```
365
381
 
366
382
  ## Unique Element IDs
@@ -369,9 +385,9 @@ All elements in the Score structure have a unique `_id` property that is automat
369
385
  - MusicXML is parsed/imported
370
386
  - New elements are created via operations
371
387
 
372
- The ID format is `"i" + nanoid(10)` (11 characters total), where:
388
+ The ID format is `"i"` + 10 random characters (11 characters total), where:
373
389
  - `"i"` prefix ensures XML ID compatibility (IDs must start with a letter or underscore)
374
- - `nanoid(10)` generates a URL-safe unique identifier
390
+ - the suffix is drawn from a 64-character URL-safe alphabet backed by `crypto.getRandomValues` (same format as nanoid)
375
391
 
376
392
  ```typescript
377
393
  import { parse, generateId } from 'musicxml-io';
@@ -0,0 +1,185 @@
1
+ import { l as DirectionType, D as DirectionEntry, N as NoteEntry, c as PartListEntry, P as PartInfo, S as Score } from '../types-B_6pqTfs.mjs';
2
+
3
+ /**
4
+ * Entry-level accessors for DirectionEntry, NoteEntry, and PartInfo
5
+ *
6
+ * These are simple helper functions for working with individual entries,
7
+ * complementing the score-level query functions in ./query.
8
+ */
9
+
10
+ /**
11
+ * Extracts a specific DirectionType union member by its kind
12
+ */
13
+ type DirectionTypeOfKind<K extends DirectionType['kind']> = Extract<DirectionType, {
14
+ kind: K;
15
+ }>;
16
+ /**
17
+ * Get the first direction type of a specific kind from a DirectionEntry
18
+ *
19
+ * @example
20
+ * const dynamics = getDirectionOfKind(entry, 'dynamics');
21
+ * if (dynamics) {
22
+ * console.log(dynamics.value); // 'ff', 'pp', etc.
23
+ * }
24
+ */
25
+ declare function getDirectionOfKind<K extends DirectionType['kind']>(entry: DirectionEntry, kind: K): DirectionTypeOfKind<K> | undefined;
26
+ /**
27
+ * Get all direction types of a specific kind from a DirectionEntry
28
+ *
29
+ * @example
30
+ * const allWords = getDirectionsOfKind(entry, 'words');
31
+ * allWords.forEach(w => console.log(w.text));
32
+ */
33
+ declare function getDirectionsOfKind<K extends DirectionType['kind']>(entry: DirectionEntry, kind: K): DirectionTypeOfKind<K>[];
34
+ /**
35
+ * Check if a DirectionEntry contains a specific direction type
36
+ *
37
+ * @example
38
+ * if (hasDirectionOfKind(entry, 'metronome')) {
39
+ * // Handle tempo marking
40
+ * }
41
+ */
42
+ declare function hasDirectionOfKind(entry: DirectionEntry, kind: DirectionType['kind']): boolean;
43
+ /**
44
+ * Get tempo from DirectionEntry.sound
45
+ *
46
+ * @example
47
+ * const tempo = getSoundTempo(entry); // 120
48
+ */
49
+ declare function getSoundTempo(entry: DirectionEntry): number | undefined;
50
+ /**
51
+ * Get dynamics value from DirectionEntry.sound (MIDI velocity 0-127)
52
+ *
53
+ * @example
54
+ * const dynamics = getSoundDynamics(entry); // 80
55
+ */
56
+ declare function getSoundDynamics(entry: DirectionEntry): number | undefined;
57
+ /**
58
+ * Get damper pedal state from DirectionEntry.sound
59
+ */
60
+ declare function getSoundDamperPedal(entry: DirectionEntry): 'yes' | 'no' | undefined;
61
+ /**
62
+ * Get soft pedal state from DirectionEntry.sound
63
+ */
64
+ declare function getSoundSoftPedal(entry: DirectionEntry): 'yes' | 'no' | undefined;
65
+ /**
66
+ * Get sostenuto pedal state from DirectionEntry.sound
67
+ */
68
+ declare function getSoundSostenutoPedal(entry: DirectionEntry): 'yes' | 'no' | undefined;
69
+ /**
70
+ * Check if a NoteEntry is a rest
71
+ *
72
+ * @example
73
+ * if (isRest(note)) {
74
+ * console.log('This is a rest');
75
+ * }
76
+ */
77
+ declare function isRest(entry: NoteEntry): boolean;
78
+ /**
79
+ * Check if a NoteEntry is a pitched note (has pitch information)
80
+ *
81
+ * @example
82
+ * if (isPitchedNote(note)) {
83
+ * console.log(`Note: ${note.pitch!.step}${note.pitch!.octave}`);
84
+ * }
85
+ */
86
+ declare function isPitchedNote(entry: NoteEntry): boolean;
87
+ /**
88
+ * Check if a NoteEntry is an unpitched note (percussion)
89
+ */
90
+ declare function isUnpitchedNote(entry: NoteEntry): boolean;
91
+ /**
92
+ * Check if a NoteEntry is part of a chord (shares onset with previous note)
93
+ *
94
+ * @example
95
+ * const chordNotes = notes.filter(isChordNote);
96
+ */
97
+ declare function isChordNote(entry: NoteEntry): boolean;
98
+ /**
99
+ * Check if a NoteEntry is a grace note
100
+ *
101
+ * @example
102
+ * if (isGraceNote(note)) {
103
+ * console.log('Grace note with slash:', note.grace?.slash);
104
+ * }
105
+ */
106
+ declare function isGraceNote(entry: NoteEntry): boolean;
107
+ /**
108
+ * Check if a NoteEntry has any tie (start, stop, or continue)
109
+ *
110
+ * @example
111
+ * if (hasTie(note)) {
112
+ * // Note is tied to another note
113
+ * }
114
+ */
115
+ declare function hasTie(entry: NoteEntry): boolean;
116
+ /**
117
+ * Check if a NoteEntry has a tie start
118
+ */
119
+ declare function hasTieStart(entry: NoteEntry): boolean;
120
+ /**
121
+ * Check if a NoteEntry has a tie stop
122
+ */
123
+ declare function hasTieStop(entry: NoteEntry): boolean;
124
+ /**
125
+ * Check if a NoteEntry is a cue note
126
+ */
127
+ declare function isCueNote(entry: NoteEntry): boolean;
128
+ /**
129
+ * Check if a NoteEntry has any beams
130
+ */
131
+ declare function hasBeam(entry: NoteEntry): boolean;
132
+ /**
133
+ * Check if a NoteEntry has any lyrics
134
+ */
135
+ declare function hasLyrics(entry: NoteEntry): boolean;
136
+ /**
137
+ * Check if a NoteEntry has any notations (articulations, slurs, ornaments, etc.)
138
+ */
139
+ declare function hasNotations(entry: NoteEntry): boolean;
140
+ /**
141
+ * Check if a NoteEntry is part of a tuplet
142
+ */
143
+ declare function hasTuplet(entry: NoteEntry): boolean;
144
+ /**
145
+ * Check if a PartListEntry is a PartInfo (score-part)
146
+ */
147
+ declare function isPartInfo(entry: PartListEntry): entry is PartInfo;
148
+ /**
149
+ * Get PartInfo by part ID
150
+ *
151
+ * @example
152
+ * const partInfo = getPartInfo(score, 'P1');
153
+ * if (partInfo) {
154
+ * console.log(partInfo.name); // 'Piano'
155
+ * }
156
+ */
157
+ declare function getPartInfo(score: Score, partId: string): PartInfo | undefined;
158
+ /**
159
+ * Get part name by part ID
160
+ *
161
+ * @example
162
+ * const name = getPartName(score, 'P1'); // 'Piano'
163
+ */
164
+ declare function getPartName(score: Score, partId: string): string | undefined;
165
+ /**
166
+ * Get part abbreviation by part ID
167
+ *
168
+ * @example
169
+ * const abbr = getPartAbbreviation(score, 'P1'); // 'Pno.'
170
+ */
171
+ declare function getPartAbbreviation(score: Score, partId: string): string | undefined;
172
+ /**
173
+ * Get all PartInfo entries from a score
174
+ */
175
+ declare function getAllPartInfos(score: Score): PartInfo[];
176
+ /**
177
+ * Get a map of part ID to part name
178
+ *
179
+ * @example
180
+ * const names = getPartNameMap(score);
181
+ * // { 'P1': 'Piano', 'P2': 'Violin' }
182
+ */
183
+ declare function getPartNameMap(score: Score): Record<string, string | undefined>;
184
+
185
+ export { type DirectionTypeOfKind, getAllPartInfos, getDirectionOfKind, getDirectionsOfKind, getPartAbbreviation, getPartInfo, getPartName, getPartNameMap, getSoundDamperPedal, getSoundDynamics, getSoundSoftPedal, getSoundSostenutoPedal, getSoundTempo, hasBeam, hasDirectionOfKind, hasLyrics, hasNotations, hasTie, hasTieStart, hasTieStop, hasTuplet, isChordNote, isCueNote, isGraceNote, isPartInfo, isPitchedNote, isRest, isUnpitchedNote };
@@ -0,0 +1,185 @@
1
+ import { l as DirectionType, D as DirectionEntry, N as NoteEntry, c as PartListEntry, P as PartInfo, S as Score } from '../types-B_6pqTfs.js';
2
+
3
+ /**
4
+ * Entry-level accessors for DirectionEntry, NoteEntry, and PartInfo
5
+ *
6
+ * These are simple helper functions for working with individual entries,
7
+ * complementing the score-level query functions in ./query.
8
+ */
9
+
10
+ /**
11
+ * Extracts a specific DirectionType union member by its kind
12
+ */
13
+ type DirectionTypeOfKind<K extends DirectionType['kind']> = Extract<DirectionType, {
14
+ kind: K;
15
+ }>;
16
+ /**
17
+ * Get the first direction type of a specific kind from a DirectionEntry
18
+ *
19
+ * @example
20
+ * const dynamics = getDirectionOfKind(entry, 'dynamics');
21
+ * if (dynamics) {
22
+ * console.log(dynamics.value); // 'ff', 'pp', etc.
23
+ * }
24
+ */
25
+ declare function getDirectionOfKind<K extends DirectionType['kind']>(entry: DirectionEntry, kind: K): DirectionTypeOfKind<K> | undefined;
26
+ /**
27
+ * Get all direction types of a specific kind from a DirectionEntry
28
+ *
29
+ * @example
30
+ * const allWords = getDirectionsOfKind(entry, 'words');
31
+ * allWords.forEach(w => console.log(w.text));
32
+ */
33
+ declare function getDirectionsOfKind<K extends DirectionType['kind']>(entry: DirectionEntry, kind: K): DirectionTypeOfKind<K>[];
34
+ /**
35
+ * Check if a DirectionEntry contains a specific direction type
36
+ *
37
+ * @example
38
+ * if (hasDirectionOfKind(entry, 'metronome')) {
39
+ * // Handle tempo marking
40
+ * }
41
+ */
42
+ declare function hasDirectionOfKind(entry: DirectionEntry, kind: DirectionType['kind']): boolean;
43
+ /**
44
+ * Get tempo from DirectionEntry.sound
45
+ *
46
+ * @example
47
+ * const tempo = getSoundTempo(entry); // 120
48
+ */
49
+ declare function getSoundTempo(entry: DirectionEntry): number | undefined;
50
+ /**
51
+ * Get dynamics value from DirectionEntry.sound (MIDI velocity 0-127)
52
+ *
53
+ * @example
54
+ * const dynamics = getSoundDynamics(entry); // 80
55
+ */
56
+ declare function getSoundDynamics(entry: DirectionEntry): number | undefined;
57
+ /**
58
+ * Get damper pedal state from DirectionEntry.sound
59
+ */
60
+ declare function getSoundDamperPedal(entry: DirectionEntry): 'yes' | 'no' | undefined;
61
+ /**
62
+ * Get soft pedal state from DirectionEntry.sound
63
+ */
64
+ declare function getSoundSoftPedal(entry: DirectionEntry): 'yes' | 'no' | undefined;
65
+ /**
66
+ * Get sostenuto pedal state from DirectionEntry.sound
67
+ */
68
+ declare function getSoundSostenutoPedal(entry: DirectionEntry): 'yes' | 'no' | undefined;
69
+ /**
70
+ * Check if a NoteEntry is a rest
71
+ *
72
+ * @example
73
+ * if (isRest(note)) {
74
+ * console.log('This is a rest');
75
+ * }
76
+ */
77
+ declare function isRest(entry: NoteEntry): boolean;
78
+ /**
79
+ * Check if a NoteEntry is a pitched note (has pitch information)
80
+ *
81
+ * @example
82
+ * if (isPitchedNote(note)) {
83
+ * console.log(`Note: ${note.pitch!.step}${note.pitch!.octave}`);
84
+ * }
85
+ */
86
+ declare function isPitchedNote(entry: NoteEntry): boolean;
87
+ /**
88
+ * Check if a NoteEntry is an unpitched note (percussion)
89
+ */
90
+ declare function isUnpitchedNote(entry: NoteEntry): boolean;
91
+ /**
92
+ * Check if a NoteEntry is part of a chord (shares onset with previous note)
93
+ *
94
+ * @example
95
+ * const chordNotes = notes.filter(isChordNote);
96
+ */
97
+ declare function isChordNote(entry: NoteEntry): boolean;
98
+ /**
99
+ * Check if a NoteEntry is a grace note
100
+ *
101
+ * @example
102
+ * if (isGraceNote(note)) {
103
+ * console.log('Grace note with slash:', note.grace?.slash);
104
+ * }
105
+ */
106
+ declare function isGraceNote(entry: NoteEntry): boolean;
107
+ /**
108
+ * Check if a NoteEntry has any tie (start, stop, or continue)
109
+ *
110
+ * @example
111
+ * if (hasTie(note)) {
112
+ * // Note is tied to another note
113
+ * }
114
+ */
115
+ declare function hasTie(entry: NoteEntry): boolean;
116
+ /**
117
+ * Check if a NoteEntry has a tie start
118
+ */
119
+ declare function hasTieStart(entry: NoteEntry): boolean;
120
+ /**
121
+ * Check if a NoteEntry has a tie stop
122
+ */
123
+ declare function hasTieStop(entry: NoteEntry): boolean;
124
+ /**
125
+ * Check if a NoteEntry is a cue note
126
+ */
127
+ declare function isCueNote(entry: NoteEntry): boolean;
128
+ /**
129
+ * Check if a NoteEntry has any beams
130
+ */
131
+ declare function hasBeam(entry: NoteEntry): boolean;
132
+ /**
133
+ * Check if a NoteEntry has any lyrics
134
+ */
135
+ declare function hasLyrics(entry: NoteEntry): boolean;
136
+ /**
137
+ * Check if a NoteEntry has any notations (articulations, slurs, ornaments, etc.)
138
+ */
139
+ declare function hasNotations(entry: NoteEntry): boolean;
140
+ /**
141
+ * Check if a NoteEntry is part of a tuplet
142
+ */
143
+ declare function hasTuplet(entry: NoteEntry): boolean;
144
+ /**
145
+ * Check if a PartListEntry is a PartInfo (score-part)
146
+ */
147
+ declare function isPartInfo(entry: PartListEntry): entry is PartInfo;
148
+ /**
149
+ * Get PartInfo by part ID
150
+ *
151
+ * @example
152
+ * const partInfo = getPartInfo(score, 'P1');
153
+ * if (partInfo) {
154
+ * console.log(partInfo.name); // 'Piano'
155
+ * }
156
+ */
157
+ declare function getPartInfo(score: Score, partId: string): PartInfo | undefined;
158
+ /**
159
+ * Get part name by part ID
160
+ *
161
+ * @example
162
+ * const name = getPartName(score, 'P1'); // 'Piano'
163
+ */
164
+ declare function getPartName(score: Score, partId: string): string | undefined;
165
+ /**
166
+ * Get part abbreviation by part ID
167
+ *
168
+ * @example
169
+ * const abbr = getPartAbbreviation(score, 'P1'); // 'Pno.'
170
+ */
171
+ declare function getPartAbbreviation(score: Score, partId: string): string | undefined;
172
+ /**
173
+ * Get all PartInfo entries from a score
174
+ */
175
+ declare function getAllPartInfos(score: Score): PartInfo[];
176
+ /**
177
+ * Get a map of part ID to part name
178
+ *
179
+ * @example
180
+ * const names = getPartNameMap(score);
181
+ * // { 'P1': 'Piano', 'P2': 'Violin' }
182
+ */
183
+ declare function getPartNameMap(score: Score): Record<string, string | undefined>;
184
+
185
+ export { type DirectionTypeOfKind, getAllPartInfos, getDirectionOfKind, getDirectionsOfKind, getPartAbbreviation, getPartInfo, getPartName, getPartNameMap, getSoundDamperPedal, getSoundDynamics, getSoundSoftPedal, getSoundSostenutoPedal, getSoundTempo, hasBeam, hasDirectionOfKind, hasLyrics, hasNotations, hasTie, hasTieStart, hasTieStop, hasTuplet, isChordNote, isCueNote, isGraceNote, isPartInfo, isPitchedNote, isRest, isUnpitchedNote };
@@ -0,0 +1,58 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+ var _chunkOEX7NVZNjs = require('../chunk-OEX7NVZN.js');
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+ exports.getAllPartInfos = _chunkOEX7NVZNjs.getAllPartInfos; exports.getDirectionOfKind = _chunkOEX7NVZNjs.getDirectionOfKind; exports.getDirectionsOfKind = _chunkOEX7NVZNjs.getDirectionsOfKind; exports.getPartAbbreviation = _chunkOEX7NVZNjs.getPartAbbreviation; exports.getPartInfo = _chunkOEX7NVZNjs.getPartInfo; exports.getPartName = _chunkOEX7NVZNjs.getPartName; exports.getPartNameMap = _chunkOEX7NVZNjs.getPartNameMap; exports.getSoundDamperPedal = _chunkOEX7NVZNjs.getSoundDamperPedal; exports.getSoundDynamics = _chunkOEX7NVZNjs.getSoundDynamics; exports.getSoundSoftPedal = _chunkOEX7NVZNjs.getSoundSoftPedal; exports.getSoundSostenutoPedal = _chunkOEX7NVZNjs.getSoundSostenutoPedal; exports.getSoundTempo = _chunkOEX7NVZNjs.getSoundTempo; exports.hasBeam = _chunkOEX7NVZNjs.hasBeam; exports.hasDirectionOfKind = _chunkOEX7NVZNjs.hasDirectionOfKind; exports.hasLyrics = _chunkOEX7NVZNjs.hasLyrics; exports.hasNotations = _chunkOEX7NVZNjs.hasNotations; exports.hasTie = _chunkOEX7NVZNjs.hasTie; exports.hasTieStart = _chunkOEX7NVZNjs.hasTieStart; exports.hasTieStop = _chunkOEX7NVZNjs.hasTieStop; exports.hasTuplet = _chunkOEX7NVZNjs.hasTuplet; exports.isChordNote = _chunkOEX7NVZNjs.isChordNote; exports.isCueNote = _chunkOEX7NVZNjs.isCueNote; exports.isGraceNote = _chunkOEX7NVZNjs.isGraceNote; exports.isPartInfo = _chunkOEX7NVZNjs.isPartInfo; exports.isPitchedNote = _chunkOEX7NVZNjs.isPitchedNote; exports.isRest = _chunkOEX7NVZNjs.isRest; exports.isUnpitchedNote = _chunkOEX7NVZNjs.isUnpitchedNote;
@@ -0,0 +1,58 @@
1
+ import {
2
+ getAllPartInfos,
3
+ getDirectionOfKind,
4
+ getDirectionsOfKind,
5
+ getPartAbbreviation,
6
+ getPartInfo,
7
+ getPartName,
8
+ getPartNameMap,
9
+ getSoundDamperPedal,
10
+ getSoundDynamics,
11
+ getSoundSoftPedal,
12
+ getSoundSostenutoPedal,
13
+ getSoundTempo,
14
+ hasBeam,
15
+ hasDirectionOfKind,
16
+ hasLyrics,
17
+ hasNotations,
18
+ hasTie,
19
+ hasTieStart,
20
+ hasTieStop,
21
+ hasTuplet,
22
+ isChordNote,
23
+ isCueNote,
24
+ isGraceNote,
25
+ isPartInfo,
26
+ isPitchedNote,
27
+ isRest,
28
+ isUnpitchedNote
29
+ } from "../chunk-R6JMBTUB.mjs";
30
+ export {
31
+ getAllPartInfos,
32
+ getDirectionOfKind,
33
+ getDirectionsOfKind,
34
+ getPartAbbreviation,
35
+ getPartInfo,
36
+ getPartName,
37
+ getPartNameMap,
38
+ getSoundDamperPedal,
39
+ getSoundDynamics,
40
+ getSoundSoftPedal,
41
+ getSoundSostenutoPedal,
42
+ getSoundTempo,
43
+ hasBeam,
44
+ hasDirectionOfKind,
45
+ hasLyrics,
46
+ hasNotations,
47
+ hasTie,
48
+ hasTieStart,
49
+ hasTieStop,
50
+ hasTuplet,
51
+ isChordNote,
52
+ isCueNote,
53
+ isGraceNote,
54
+ isPartInfo,
55
+ isPitchedNote,
56
+ isRest,
57
+ isUnpitchedNote
58
+ };