@gondola-lyrics/kit 0.3.0 → 0.5.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/README.md CHANGED
@@ -10,9 +10,10 @@ npm install @gondola-lyrics/kit
10
10
 
11
11
  ## Supports
12
12
 
13
- | Format | Parse | Generate | Annotation tracks | Notes |
14
- | ------ | ----- | -------- | ----------------- | -------------------------------------------------------------------- |
15
- | LRC | ✅ | ✅ | ✅ | Line and enhanced word timing, metadata, translations, romanizations |
13
+ | Format | Line level | Word level | Annotation | Meta |
14
+ | ------ | ---------- | ---------- | ---------- | ---- |
15
+ | LRC | ✅ | ✅ | ✅ | ✅ |
16
+ | TTML | ✅ | ✅ | ✅ | ✅ |
16
17
 
17
18
  ## Usage
18
19
 
package/dist/formats.d.ts CHANGED
@@ -14,6 +14,13 @@ export declare const detectFormat: (input: unknown) => LyricFormat | undefined;
14
14
  */
15
15
  export declare const detectLrc: (input: unknown) => boolean;
16
16
 
17
+ /**
18
+ * Detects QRC from the original track so annotations cannot change format selection.
19
+ *
20
+ * @returns Whether plaintext or a supported XML payload contains a timed QRC row.
21
+ */
22
+ export declare const detectQrc: (input: unknown) => boolean;
23
+
17
24
  /**
18
25
  * Recognition needs a profile hint, since plain TTML says nothing about which profile wrote it.
19
26
  *
@@ -25,15 +32,18 @@ export declare const detectTtml: (input: unknown) => boolean;
25
32
  /**
26
33
  * Generates text in the requested format, which need not match `lyric.format`.
27
34
  *
28
- * The writer map pairs each format's options with its result and requires a writer for every supported format.
35
+ * The writer map pairs options with results only for formats that have an implemented writer.
29
36
  * An unknown target returns `null`.
30
37
  */
31
- export declare const generate: <Target extends LyricFormat>(lyric: runtime.Lyric, target: Target, options?: GenerateOptions[Target]) => GenerateResults[Target] | null;
38
+ export declare const generate: <Target extends GenerateFormat>(lyric: runtime.Lyric, target: Target, options?: GenerateOptions[Target]) => GenerateResults[Target] | null;
39
+
40
+ export declare type GenerateFormat = keyof GenerateOptions;
32
41
 
33
42
  /**
34
43
  * Generates the LRC text plus the annotations a single file cannot hold.
35
44
  *
36
45
  * Word tags appear only for a word-timed lyric when `wordTiming` is not `none`; otherwise every line stays whole.
46
+ * Word romanizations retain token boundaries; explicit line romanizations take precedence for the same language.
37
47
  */
38
48
  export declare const generateLrc: (lyric: runtime.Lyric, options?: LrcGenerateOptions) => LrcGenerateResult;
39
49
 
@@ -52,6 +62,7 @@ declare interface GenerateResults {
52
62
  *
53
63
  * Offsets are baked into timestamps; a negative result or a missing required time throws.
54
64
  * Profile mappings retain the lead agent and first AMLL ruby, omitting unsupported fields and instrumental nodes.
65
+ * Word romanizations are emitted as line text without their token timing.
55
66
  */
56
67
  export declare const generateTtml: (lyric: runtime.Lyric, options?: TtmlGenerateOptions) => TtmlGenerateResult;
57
68
 
@@ -82,6 +93,18 @@ export declare interface LrcGenerateOptions {
82
93
 
83
94
  export declare type LrcGenerateResult = LrcContent;
84
95
 
96
+ export declare interface LrcLineTiming {
97
+ /**
98
+ * Clock timestamp precision in milliseconds; unit-suffixed timestamps use 1ms.
99
+ */
100
+ precision: number;
101
+ }
102
+
103
+ export declare interface LrcMetaTag {
104
+ key: string;
105
+ value: string;
106
+ }
107
+
85
108
  export declare type LrcParseInput = LrcContent;
86
109
 
87
110
  export declare interface LrcParseOptions {
@@ -90,28 +113,67 @@ export declare interface LrcParseOptions {
90
113
  * Defaults to `0`, which requires an exact match.
91
114
  */
92
115
  annotationTolerance?: number;
116
+ /**
117
+ * Maximum roman token drift outside a matched word, in milliseconds; matched boundaries are adjusted to that word.
118
+ * Original word timing is preserved, and incomplete word matches retain the source line romanization.
119
+ *
120
+ * @default 0
121
+ */
122
+ wordAnnotationTolerance?: number;
123
+ /**
124
+ * Recovers unmatched roman fragments from unique two-kana combination starts or equal-sized gaps between timing anchors.
125
+ * Only a base kana followed by its small kana combines; doubled consonants and long vowels retain the whole line romanization.
126
+ * Recovered token times are clipped to their original word; untimed fragments inherit its range.
127
+ *
128
+ * @default false
129
+ */
130
+ wordAnnotationFallback?: boolean;
131
+ }
132
+
133
+ export declare interface LrcReadOptions {
134
+ /**
135
+ * Reports each line with its source precision before normalization can change its identity or order.
136
+ */
137
+ onLine?: (line: runtime.Line, timing: LrcLineTiming) => void;
138
+ }
139
+
140
+ export declare interface LrcReadResult {
141
+ lines: runtime.Line[];
142
+ metaTags: LrcMetaTag[];
93
143
  }
94
144
 
95
145
  /**
96
146
  * Values match the lowercase format names stored in `Lyric.format`.
97
147
  */
98
- export declare type LyricFormat = 'lrc' | 'ttml';
148
+ export declare type LyricFormat = 'lrc' | 'qrc' | 'ttml';
99
149
 
100
150
  /**
101
151
  * Unrecognized text returns `null`; a recognized format returns its canonical lyric and diagnostics.
102
152
  * Annotation tracks travel with the source and are attached by the format's parser.
103
153
  */
104
- export declare const parse: (input: unknown, options?: LrcParseOptions & TtmlParseOptions) => ParseResult | null;
154
+ export declare const parse: (input: unknown, options?: LrcParseOptions & QrcParseOptions & TtmlParseOptions) => ParseResult | null;
105
155
 
106
156
  /**
107
- * Source order, empty timed lines, and missing word times are preserved for model validation.
157
+ * Empty timed rows become instrumental lines; source order and missing word times remain for model validation.
108
158
  *
109
159
  * Annotation tracks are read as lines too and attached by timestamp, and rows that match no line are dropped.
160
+ * Complete roman tracks attach to words by timing and optional local recovery; other tracks retain their source line text.
110
161
  *
111
162
  * `INVALID` means no readable timed lines; the returned diagnostics carry whatever the canonical tree breaks.
112
163
  */
113
164
  export declare const parseLrc: (input: string | LrcParseInput, options?: LrcParseOptions) => ParseResult;
114
165
 
166
+ /**
167
+ * Parses plaintext or XML QRC, retaining explicit timing, word romanization, and ruby from kana metadata.
168
+ * Original-track kana supplies ruby and is removed from the returned metadata.
169
+ *
170
+ * @param input Original lyrics with optional translation and romanization tracks.
171
+ * @param options Independent line and word tolerances, with optional local roman recovery.
172
+ *
173
+ * @returns Canonical lyrics and source diagnostics; an empty result has INVALID status.
174
+ */
175
+ export declare const parseQrc: (input: string | QrcParseInput, options?: QrcParseOptions) => ParseResult;
176
+
115
177
  /**
116
178
  * A parsed lyric in canonical form, with every rule it breaks.
117
179
  */
@@ -128,6 +190,49 @@ export declare interface ParseResult {
128
190
  */
129
191
  export declare const parseTtml: (input: TtmlParseInput, options?: TtmlParseOptions) => ParseResult;
130
192
 
193
+ declare interface QrcContent {
194
+ original: string;
195
+ translations?: string;
196
+ romans?: string;
197
+ }
198
+
199
+ export declare type QrcParseInput = QrcContent;
200
+
201
+ export declare interface QrcParseOptions {
202
+ /**
203
+ * Extra tolerance in milliseconds for line annotations left after exact time and row order matching.
204
+ *
205
+ * @default 0
206
+ */
207
+ annotationTolerance?: number;
208
+ /**
209
+ * Extra word-boundary tolerance in milliseconds; native QRC tracks allow at least 1ms for rounding.
210
+ * LRC auxiliary tracks use exact word boundaries by default, and incomplete matches retain the whole line romanization.
211
+ *
212
+ * @default 0
213
+ */
214
+ wordAnnotationTolerance?: number;
215
+ /**
216
+ * Recovers unmatched roman fragments from unique two-kana combination starts or equal-sized gaps between timing anchors.
217
+ * Only a base kana followed by its small kana combines; doubled consonants and long vowels retain the whole line romanization.
218
+ * Recovered token times are clipped to their original word; untimed fragments inherit its range.
219
+ *
220
+ * @default false
221
+ */
222
+ wordAnnotationFallback?: boolean;
223
+ }
224
+
225
+ /**
226
+ * Reads one LRC track before normalization so consumers retain source order and timing slots.
227
+ * The caller owns metadata mapping, annotation attachment, and final normalization.
228
+ *
229
+ * @param text Original lyrics or one auxiliary track in LRC syntax.
230
+ * @param options Optional observer for source timestamp information.
231
+ *
232
+ * @returns Model lines in input order and metadata tags with lowercase keys and trimmed values.
233
+ */
234
+ export declare const readLrc: (text: string, options?: LrcReadOptions) => LrcReadResult;
235
+
131
236
  export declare interface TtmlGenerateOptions {
132
237
  /**
133
238
  * Defaults to the source TTML profile, or `amll` when the lyric came from another format.