@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 +4 -3
- package/dist/formats.d.ts +110 -5
- package/dist/formats.js +1188 -266
- package/dist/formats.js.map +1 -1
- package/dist/generator.d.ts +7 -3
- package/dist/index.d.ts +320 -5
- package/dist/index.js +3 -1
- package/dist/language.js +117 -0
- package/dist/language.js.map +1 -0
- package/dist/parser.d.ts +314 -3
- package/dist/parser.js +3 -1
- package/dist/transforms.d.ts +257 -1
- package/dist/transforms.js +3307 -0
- package/dist/transforms.js.map +1 -0
- package/package.json +1 -1
package/dist/generator.d.ts
CHANGED
|
@@ -3,15 +3,18 @@ import { runtime } from '@gondola-lyrics/model';
|
|
|
3
3
|
/**
|
|
4
4
|
* Generates text in the requested format, which need not match `lyric.format`.
|
|
5
5
|
*
|
|
6
|
-
* The writer map pairs
|
|
6
|
+
* The writer map pairs options with results only for formats that have an implemented writer.
|
|
7
7
|
* An unknown target returns `null`.
|
|
8
8
|
*/
|
|
9
|
-
export declare const generate: <Target extends
|
|
9
|
+
export declare const generate: <Target extends GenerateFormat>(lyric: runtime.Lyric, target: Target, options?: GenerateOptions[Target]) => GenerateResults[Target] | null;
|
|
10
|
+
|
|
11
|
+
export declare type GenerateFormat = keyof GenerateOptions;
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Generates the LRC text plus the annotations a single file cannot hold.
|
|
13
15
|
*
|
|
14
16
|
* Word tags appear only for a word-timed lyric when `wordTiming` is not `none`; otherwise every line stays whole.
|
|
17
|
+
* Word romanizations retain token boundaries; explicit line romanizations take precedence for the same language.
|
|
15
18
|
*/
|
|
16
19
|
export declare const generateLrc: (lyric: runtime.Lyric, options?: LrcGenerateOptions) => LrcGenerateResult;
|
|
17
20
|
|
|
@@ -30,6 +33,7 @@ declare interface GenerateResults {
|
|
|
30
33
|
*
|
|
31
34
|
* Offsets are baked into timestamps; a negative result or a missing required time throws.
|
|
32
35
|
* Profile mappings retain the lead agent and first AMLL ruby, omitting unsupported fields and instrumental nodes.
|
|
36
|
+
* Word romanizations are emitted as line text without their token timing.
|
|
33
37
|
*/
|
|
34
38
|
export declare const generateTtml: (lyric: runtime.Lyric, options?: TtmlGenerateOptions) => TtmlGenerateResult;
|
|
35
39
|
|
|
@@ -63,7 +67,7 @@ export declare type LrcGenerateResult = LrcContent;
|
|
|
63
67
|
/**
|
|
64
68
|
* Values match the lowercase format names stored in `Lyric.format`.
|
|
65
69
|
*/
|
|
66
|
-
export declare type LyricFormat = 'lrc' | 'ttml';
|
|
70
|
+
export declare type LyricFormat = 'lrc' | 'qrc' | 'ttml';
|
|
67
71
|
|
|
68
72
|
export declare interface TtmlGenerateOptions {
|
|
69
73
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import { Diagnostic } from '@gondola-lyrics/model/runtime';
|
|
2
2
|
import { runtime } from '@gondola-lyrics/model';
|
|
3
3
|
|
|
4
|
+
export declare const DEFAULT_CREDIT_NAME_SEPARATORS: readonly ["+", ":", "/"];
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Derives emphasis for normal words in lead and background vocals using complete, valid word ranges.
|
|
8
|
+
* The stored word duration must strictly exceed durationThreshold; metadata offset and duration have no effect.
|
|
9
|
+
*
|
|
10
|
+
* Source emphasis, including an explicit false, is preserved; derived emphasis is cleared when a word no longer qualifies.
|
|
11
|
+
*
|
|
12
|
+
* @returns The input when unchanged, or a new lyric sharing all unchanged nodes.
|
|
13
|
+
*
|
|
14
|
+
* @throws {RangeError} If durationThreshold is not a non-negative safe integer in milliseconds.
|
|
15
|
+
*/
|
|
16
|
+
export declare const deriveWordEmphasis: (lyric: runtime.Lyric, options?: DeriveWordEmphasisOptions) => runtime.Lyric;
|
|
17
|
+
|
|
18
|
+
export declare interface DeriveWordEmphasisOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Word duration must strictly exceed this threshold, expressed as a non-negative safe integer in milliseconds.
|
|
21
|
+
*
|
|
22
|
+
* @default 3000
|
|
23
|
+
*/
|
|
24
|
+
durationThreshold?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
4
27
|
/**
|
|
5
28
|
* Recognition reads only the original text; the annotation tracks never decide the format.
|
|
6
29
|
*
|
|
@@ -8,18 +31,106 @@ import { runtime } from '@gondola-lyrics/model';
|
|
|
8
31
|
*/
|
|
9
32
|
export declare const detectFormat: (input: unknown) => LyricFormat | undefined;
|
|
10
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Extracts colon-prefixed performers and carries them across nonempty normal lines, replacing their existing agent lists.
|
|
36
|
+
* Missing bindings enables legacy name inference; supplied bindings accept exact prefixes and reset propagation on unmatched prefixes.
|
|
37
|
+
* Removing prefixes preserves retained line and word times, but drops prefix-only lines with their attached content.
|
|
38
|
+
*
|
|
39
|
+
* @returns The input when unchanged, or a new lyric sharing all unchanged nodes.
|
|
40
|
+
*
|
|
41
|
+
* @throws {TypeError} If bindings reference an agent id absent from lyric.agents.
|
|
42
|
+
*/
|
|
43
|
+
export declare const extractAgents: (lyric: runtime.Lyric, options?: ExtractAgentsOptions) => runtime.Lyric;
|
|
44
|
+
|
|
45
|
+
export declare interface ExtractAgentsOptions {
|
|
46
|
+
/**
|
|
47
|
+
* Maps complete, trimmed prefixes to existing agent ids, preserving array order for joint performers.
|
|
48
|
+
* Matching is case-sensitive and preserves internal whitespace; an empty object disables automatic inference.
|
|
49
|
+
* Omitting this option enables legacy name inference; explicit bindings override its clock exclusion.
|
|
50
|
+
*/
|
|
51
|
+
bindings?: Readonly<Record<string, string | readonly string[]>>;
|
|
52
|
+
/**
|
|
53
|
+
* Removes matched prefixes and drops lines left with no sung text, including their attached content.
|
|
54
|
+
*
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
removePrefixes?: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Pulls bracketed background vocals out of the sung lines and attaches them to the line they accompany.
|
|
62
|
+
*
|
|
63
|
+
* A line holding nothing but brackets becomes a background of the line before it and is removed.
|
|
64
|
+
* A bracket opened on one line and closed on a later one joins the line before the opening, and both source lines go.
|
|
65
|
+
* Text outside brackets stays on its line, and a line left with none keeps its place.
|
|
66
|
+
*
|
|
67
|
+
* @returns The input when unchanged, or a new lyric sharing all unchanged nodes.
|
|
68
|
+
*/
|
|
69
|
+
export declare const extractBackgroundLines: (lyric: runtime.Lyric, options?: ExtractBackgroundLinesOptions) => runtime.Lyric;
|
|
70
|
+
|
|
71
|
+
export declare interface ExtractBackgroundLinesOptions {
|
|
72
|
+
/**
|
|
73
|
+
* Turn a line holding nothing but brackets into a background line of the line before it.
|
|
74
|
+
*
|
|
75
|
+
* @default true
|
|
76
|
+
*/
|
|
77
|
+
fullLine?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Pull the bracketed runs inside a line out into background lines of that same line.
|
|
80
|
+
*
|
|
81
|
+
* @default true
|
|
82
|
+
*/
|
|
83
|
+
inLine?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Join a bracket opened on one line and closed on a later one, attaching it to the line before them.
|
|
86
|
+
*
|
|
87
|
+
* @default true
|
|
88
|
+
*/
|
|
89
|
+
crossLine?: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Preserves source labels and name spelling while matching normalized credit labels in normal lead lines.
|
|
94
|
+
* Merges names by role and original label without inferring their language.
|
|
95
|
+
*
|
|
96
|
+
* @returns The input when unchanged, or a new lyric sharing all unchanged nodes.
|
|
97
|
+
*/
|
|
98
|
+
export declare const extractCredits: (lyric: runtime.Lyric, options?: ExtractCreditsOptions) => runtime.Lyric;
|
|
99
|
+
|
|
100
|
+
export declare interface ExtractCreditsOptions {
|
|
101
|
+
/**
|
|
102
|
+
* Removes extracted source lines unless they carry background vocals, line annotations, or word translations or romanizations.
|
|
103
|
+
* Ruby annotations alone do not prevent removal.
|
|
104
|
+
*
|
|
105
|
+
* Refreshes language usages and falls back to line timing when no word-level content remains.
|
|
106
|
+
*
|
|
107
|
+
* @default false
|
|
108
|
+
*/
|
|
109
|
+
removeSourceLines?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Splits names at literal separators and ignores empty strings; an empty list preserves the complete source name.
|
|
112
|
+
* Longer separators take precedence so overlapping delimiters remain predictable.
|
|
113
|
+
*
|
|
114
|
+
* @default DEFAULT_CREDIT_NAME_SEPARATORS
|
|
115
|
+
*/
|
|
116
|
+
nameSeparators?: readonly string[];
|
|
117
|
+
}
|
|
118
|
+
|
|
11
119
|
/**
|
|
12
120
|
* Generates text in the requested format, which need not match `lyric.format`.
|
|
13
121
|
*
|
|
14
|
-
* The writer map pairs
|
|
122
|
+
* The writer map pairs options with results only for formats that have an implemented writer.
|
|
15
123
|
* An unknown target returns `null`.
|
|
16
124
|
*/
|
|
17
|
-
export declare const generate: <Target extends
|
|
125
|
+
export declare const generate: <Target extends GenerateFormat>(lyric: runtime.Lyric, target: Target, options?: GenerateOptions[Target]) => GenerateResults[Target] | null;
|
|
126
|
+
|
|
127
|
+
export declare type GenerateFormat = keyof GenerateOptions;
|
|
18
128
|
|
|
19
129
|
/**
|
|
20
130
|
* Generates the LRC text plus the annotations a single file cannot hold.
|
|
21
131
|
*
|
|
22
132
|
* Word tags appear only for a word-timed lyric when `wordTiming` is not `none`; otherwise every line stays whole.
|
|
133
|
+
* Word romanizations retain token boundaries; explicit line romanizations take precedence for the same language.
|
|
23
134
|
*/
|
|
24
135
|
export declare const generateLrc: (lyric: runtime.Lyric, options?: LrcGenerateOptions) => LrcGenerateResult;
|
|
25
136
|
|
|
@@ -38,9 +149,112 @@ declare interface GenerateResults {
|
|
|
38
149
|
*
|
|
39
150
|
* Offsets are baked into timestamps; a negative result or a missing required time throws.
|
|
40
151
|
* Profile mappings retain the lead agent and first AMLL ruby, omitting unsupported fields and instrumental nodes.
|
|
152
|
+
* Word romanizations are emitted as line text without their token timing.
|
|
41
153
|
*/
|
|
42
154
|
export declare const generateTtml: (lyric: runtime.Lyric, options?: TtmlGenerateOptions) => TtmlGenerateResult;
|
|
43
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Inserts derived instrumental lines into uncovered gaps on the stored timeline, starting at zero.
|
|
158
|
+
* Existing lines and background vocals occupy their full ranges; an unknown end blocks later gaps.
|
|
159
|
+
*
|
|
160
|
+
* An outro requires an explicit endTime; metadata duration and offset do not affect insertion.
|
|
161
|
+
*
|
|
162
|
+
* @returns The input when unchanged, or a new lyric and lines array sharing existing nodes.
|
|
163
|
+
*/
|
|
164
|
+
export declare const insertInstrumentalLines: (lyric: runtime.Lyric, options?: InsertInstrumentalLinesOptions) => runtime.Lyric;
|
|
165
|
+
|
|
166
|
+
export declare interface InsertInstrumentalLinesOptions {
|
|
167
|
+
/**
|
|
168
|
+
* Minimum gap duration in milliseconds, including an outro.
|
|
169
|
+
*
|
|
170
|
+
* @default 10000
|
|
171
|
+
*/
|
|
172
|
+
minDuration?: number;
|
|
173
|
+
/**
|
|
174
|
+
* Minimum gap duration before the first vocal in milliseconds.
|
|
175
|
+
*
|
|
176
|
+
* @default 5000
|
|
177
|
+
*/
|
|
178
|
+
minIntroDuration?: number;
|
|
179
|
+
/**
|
|
180
|
+
* Outro boundary in milliseconds, measured on the same timeline as line ranges.
|
|
181
|
+
* An omitted boundary leaves the outro unknown.
|
|
182
|
+
*/
|
|
183
|
+
endTime?: number;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Inserts the spaces a source left out, so CJK text set against Latin letters, digits or punctuation reads evenly.
|
|
188
|
+
*
|
|
189
|
+
* A word-level line keeps every word's time and annotation: an inserted space becomes its own space word,
|
|
190
|
+
* and a word the rules split yields one word per character, all sharing the original range.
|
|
191
|
+
* A plain-text line and the annotation tracks are rewritten as whole strings.
|
|
192
|
+
*
|
|
193
|
+
* @returns The input when unchanged, or a new lyric sharing all unchanged nodes.
|
|
194
|
+
*/
|
|
195
|
+
export declare const insertSpacesInLines: (lyric: runtime.Lyric, options?: InsertSpacesOptions) => runtime.Lyric;
|
|
196
|
+
|
|
197
|
+
export declare interface InsertSpacesOptions {
|
|
198
|
+
/**
|
|
199
|
+
* Rules to apply; omitting the list applies all of them.
|
|
200
|
+
*/
|
|
201
|
+
rules?: InsertSpacesRule[];
|
|
202
|
+
/**
|
|
203
|
+
* Rewrite the translation and romanization tracks too.
|
|
204
|
+
*
|
|
205
|
+
* @default true
|
|
206
|
+
*/
|
|
207
|
+
annotations?: boolean;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export declare type InsertSpacesRule = (typeof InsertSpacesRules)[keyof typeof InsertSpacesRules];
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Groups of characters a source may write without a space where one belongs.
|
|
214
|
+
*/
|
|
215
|
+
export declare const InsertSpacesRules: {
|
|
216
|
+
/**
|
|
217
|
+
* A CJK character touching a Latin letter, as in `ABC中文`.
|
|
218
|
+
*/
|
|
219
|
+
readonly CJK_ENGLISH: "cjkEnglish";
|
|
220
|
+
/**
|
|
221
|
+
* A CJK character touching a digit, as in `2026年`.
|
|
222
|
+
*/
|
|
223
|
+
readonly CJK_NUMBER: "cjkNumber";
|
|
224
|
+
/**
|
|
225
|
+
* A comma, semicolon, exclamation mark, question mark or colon touching a character, as in `a,b`; a clock time or thousands separator such as `10:30` stays as written.
|
|
226
|
+
*/
|
|
227
|
+
readonly PUNCTUATION: "punctuation";
|
|
228
|
+
/**
|
|
229
|
+
* A quotation mark touching a neighbouring character.
|
|
230
|
+
*/
|
|
231
|
+
readonly QUOTE: "quote";
|
|
232
|
+
/**
|
|
233
|
+
* A bracket touching the character outside it.
|
|
234
|
+
*/
|
|
235
|
+
readonly BRACKET_OUTSIDE: "bracketOutside";
|
|
236
|
+
/**
|
|
237
|
+
* A plus, equals or ampersand touching a character, as in `a+b`; a compound operator such as `a+=b` stays as written.
|
|
238
|
+
*/
|
|
239
|
+
readonly MATH_OPERATOR: "mathOperator";
|
|
240
|
+
/**
|
|
241
|
+
* A hyphen touching a CJK character, as in `中-文`; a compound word such as `well-known` stays as written.
|
|
242
|
+
*/
|
|
243
|
+
readonly HYPHEN: "hyphen";
|
|
244
|
+
/**
|
|
245
|
+
* A slash touching a character, as in `and/or`; a fraction such as `1/2` stays as written.
|
|
246
|
+
*/
|
|
247
|
+
readonly SLASH: "slash";
|
|
248
|
+
/**
|
|
249
|
+
* Runs of two or more spaces, collapsed to one.
|
|
250
|
+
*/
|
|
251
|
+
readonly COMPRESS_SPACES: "compressSpaces";
|
|
252
|
+
/**
|
|
253
|
+
* Spaces just inside a bracket or quotation mark, removed.
|
|
254
|
+
*/
|
|
255
|
+
readonly TRIM_INSIDE_SYMBOLS: "trimInsideSymbols";
|
|
256
|
+
};
|
|
257
|
+
|
|
44
258
|
declare interface LrcContent {
|
|
45
259
|
original: string;
|
|
46
260
|
translations?: string;
|
|
@@ -76,28 +290,60 @@ export declare interface LrcParseOptions {
|
|
|
76
290
|
* Defaults to `0`, which requires an exact match.
|
|
77
291
|
*/
|
|
78
292
|
annotationTolerance?: number;
|
|
293
|
+
/**
|
|
294
|
+
* Maximum roman token drift outside a matched word, in milliseconds; matched boundaries are adjusted to that word.
|
|
295
|
+
* Original word timing is preserved, and incomplete word matches retain the source line romanization.
|
|
296
|
+
*
|
|
297
|
+
* @default 0
|
|
298
|
+
*/
|
|
299
|
+
wordAnnotationTolerance?: number;
|
|
300
|
+
/**
|
|
301
|
+
* Recovers unmatched roman fragments from unique two-kana combination starts or equal-sized gaps between timing anchors.
|
|
302
|
+
* Only a base kana followed by its small kana combines; doubled consonants and long vowels retain the whole line romanization.
|
|
303
|
+
* Recovered token times are clipped to their original word; untimed fragments inherit its range.
|
|
304
|
+
*
|
|
305
|
+
* @default false
|
|
306
|
+
*/
|
|
307
|
+
wordAnnotationFallback?: boolean;
|
|
79
308
|
}
|
|
80
309
|
|
|
81
310
|
/**
|
|
82
311
|
* Values match the lowercase format names stored in `Lyric.format`.
|
|
83
312
|
*/
|
|
84
|
-
export declare type LyricFormat = 'lrc' | 'ttml';
|
|
313
|
+
export declare type LyricFormat = 'lrc' | 'qrc' | 'ttml';
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Categories the bundled filter rules identify, in rule order.
|
|
317
|
+
*/
|
|
318
|
+
export declare const NON_LYRIC_CATEGORIES: readonly string[];
|
|
85
319
|
|
|
86
320
|
/**
|
|
87
321
|
* Unrecognized text returns `null`; a recognized format returns its canonical lyric and diagnostics.
|
|
88
322
|
* Annotation tracks travel with the source and are attached by the format's parser.
|
|
89
323
|
*/
|
|
90
|
-
export declare const parse: (input: unknown, options?: LrcParseOptions & TtmlParseOptions) => ParseResult | null;
|
|
324
|
+
export declare const parse: (input: unknown, options?: LrcParseOptions & QrcParseOptions & TtmlParseOptions) => ParseResult | null;
|
|
91
325
|
|
|
92
326
|
/**
|
|
93
|
-
*
|
|
327
|
+
* Empty timed rows become instrumental lines; source order and missing word times remain for model validation.
|
|
94
328
|
*
|
|
95
329
|
* Annotation tracks are read as lines too and attached by timestamp, and rows that match no line are dropped.
|
|
330
|
+
* Complete roman tracks attach to words by timing and optional local recovery; other tracks retain their source line text.
|
|
96
331
|
*
|
|
97
332
|
* `INVALID` means no readable timed lines; the returned diagnostics carry whatever the canonical tree breaks.
|
|
98
333
|
*/
|
|
99
334
|
export declare const parseLrc: (input: string | LrcParseInput, options?: LrcParseOptions) => ParseResult;
|
|
100
335
|
|
|
336
|
+
/**
|
|
337
|
+
* Parses plaintext or XML QRC, retaining explicit timing, word romanization, and ruby from kana metadata.
|
|
338
|
+
* Original-track kana supplies ruby and is removed from the returned metadata.
|
|
339
|
+
*
|
|
340
|
+
* @param input Original lyrics with optional translation and romanization tracks.
|
|
341
|
+
* @param options Independent line and word tolerances, with optional local roman recovery.
|
|
342
|
+
*
|
|
343
|
+
* @returns Canonical lyrics and source diagnostics; an empty result has INVALID status.
|
|
344
|
+
*/
|
|
345
|
+
export declare const parseQrc: (input: string | QrcParseInput, options?: QrcParseOptions) => ParseResult;
|
|
346
|
+
|
|
101
347
|
/**
|
|
102
348
|
* A parsed lyric in canonical form, with every rule it breaks.
|
|
103
349
|
*/
|
|
@@ -114,6 +360,75 @@ export declare interface ParseResult {
|
|
|
114
360
|
*/
|
|
115
361
|
export declare const parseTtml: (input: TtmlParseInput, options?: TtmlParseOptions) => ParseResult;
|
|
116
362
|
|
|
363
|
+
declare interface QrcContent {
|
|
364
|
+
original: string;
|
|
365
|
+
translations?: string;
|
|
366
|
+
romans?: string;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export declare type QrcParseInput = QrcContent;
|
|
370
|
+
|
|
371
|
+
export declare interface QrcParseOptions {
|
|
372
|
+
/**
|
|
373
|
+
* Extra tolerance in milliseconds for line annotations left after exact time and row order matching.
|
|
374
|
+
*
|
|
375
|
+
* @default 0
|
|
376
|
+
*/
|
|
377
|
+
annotationTolerance?: number;
|
|
378
|
+
/**
|
|
379
|
+
* Extra word-boundary tolerance in milliseconds; native QRC tracks allow at least 1ms for rounding.
|
|
380
|
+
* LRC auxiliary tracks use exact word boundaries by default, and incomplete matches retain the whole line romanization.
|
|
381
|
+
*
|
|
382
|
+
* @default 0
|
|
383
|
+
*/
|
|
384
|
+
wordAnnotationTolerance?: number;
|
|
385
|
+
/**
|
|
386
|
+
* Recovers unmatched roman fragments from unique two-kana combination starts or equal-sized gaps between timing anchors.
|
|
387
|
+
* Only a base kana followed by its small kana combines; doubled consonants and long vowels retain the whole line romanization.
|
|
388
|
+
* Recovered token times are clipped to their original word; untimed fragments inherit its range.
|
|
389
|
+
*
|
|
390
|
+
* @default false
|
|
391
|
+
*/
|
|
392
|
+
wordAnnotationFallback?: boolean;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Removes normal lead lines matched by the shared notice rules and, when musicInfo is provided, first-line song information.
|
|
397
|
+
* The first non-empty normal line must have one literal " - " separator and a known title and artist on opposite sides; either order and extra text such as bracketed aliases are accepted.
|
|
398
|
+
* Drops attached annotations and backgrounds, refreshes language usages, and falls back to line timing when no word-level content remains.
|
|
399
|
+
*
|
|
400
|
+
* @returns The input when unchanged, or a new lyric sharing all unchanged nodes.
|
|
401
|
+
*/
|
|
402
|
+
export declare const removeNonLyricLines: (lyric: runtime.Lyric, options?: RemoveNonLyricLinesOptions) => runtime.Lyric;
|
|
403
|
+
|
|
404
|
+
export declare interface RemoveNonLyricLinesOptions {
|
|
405
|
+
/**
|
|
406
|
+
* Removes lines identified under these categories; an empty list skips the shared rules.
|
|
407
|
+
* First-line music information is selected independently.
|
|
408
|
+
*
|
|
409
|
+
* @default NON_LYRIC_CATEGORIES
|
|
410
|
+
*/
|
|
411
|
+
categories?: readonly string[];
|
|
412
|
+
/**
|
|
413
|
+
* Enables first-line music-information matching using these known titles and artists.
|
|
414
|
+
* Omitting this option, or leaving either list empty, skips the check; lyric metadata is not inferred.
|
|
415
|
+
*/
|
|
416
|
+
musicInfo?: {
|
|
417
|
+
titles?: readonly string[];
|
|
418
|
+
artists?: readonly string[];
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Removes the brackets some sources wrap around background vocals.
|
|
424
|
+
*
|
|
425
|
+
* One layer is removed from each edge of every background line, leaving a nested pair as `(x)`.
|
|
426
|
+
* A line left with no content is dropped, since a background line must carry something.
|
|
427
|
+
*
|
|
428
|
+
* @returns The input when unchanged, or a new lyric sharing all unchanged nodes.
|
|
429
|
+
*/
|
|
430
|
+
export declare const stripBackgroundBrackets: (lyric: runtime.Lyric) => runtime.Lyric;
|
|
431
|
+
|
|
117
432
|
export declare interface TtmlGenerateOptions {
|
|
118
433
|
/**
|
|
119
434
|
* Defaults to the source TTML profile, or `amll` when the lyric came from another format.
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { detectFormat, generate, generateLrc, generateTtml, parse, parseLrc, parseQrc, parseTtml } from "./formats.js";
|
|
2
|
+
import { DEFAULT_CREDIT_NAME_SEPARATORS, InsertSpacesRules, NON_LYRIC_CATEGORIES, deriveWordEmphasis, extractAgents, extractBackgroundLines, extractCredits, insertInstrumentalLines, insertSpacesInLines, removeNonLyricLines, stripBackgroundBrackets } from "./transforms.js";
|
|
2
3
|
import "./parser.js";
|
|
3
4
|
import "./generator.js";
|
|
5
|
+
export { DEFAULT_CREDIT_NAME_SEPARATORS, InsertSpacesRules, NON_LYRIC_CATEGORIES, deriveWordEmphasis, detectFormat, extractAgents, extractBackgroundLines, extractCredits, generate, generateLrc, generateTtml, insertInstrumentalLines, insertSpacesInLines, parse, parseLrc, parseQrc, parseTtml, removeNonLyricLines, stripBackgroundBrackets };
|
package/dist/language.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
//#region src/utils/array.ts
|
|
2
|
+
/**
|
|
3
|
+
* Preserves the input array when every element keeps its identity, so unchanged parent nodes can also be reused.
|
|
4
|
+
*
|
|
5
|
+
* The callback must leave inputs untouched and return the original element when unchanged.
|
|
6
|
+
*/
|
|
7
|
+
var mapShared = (items, transform) => {
|
|
8
|
+
let result = items;
|
|
9
|
+
for (const [index, item] of items.entries()) {
|
|
10
|
+
const transformed = transform(item);
|
|
11
|
+
if (transformed !== item) {
|
|
12
|
+
if (result === items) result = [...items];
|
|
13
|
+
result[index] = transformed;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Finds the first value meeting a lower bound so range queries can skip earlier candidates.
|
|
20
|
+
*
|
|
21
|
+
* @param values Values sorted in ascending order.
|
|
22
|
+
* @param target Inclusive lower bound.
|
|
23
|
+
*
|
|
24
|
+
* @returns The first matching index, or the array length when every value is smaller.
|
|
25
|
+
*/
|
|
26
|
+
var lowerBound = (values, target) => {
|
|
27
|
+
let left = 0;
|
|
28
|
+
let right = values.length;
|
|
29
|
+
while (left < right) {
|
|
30
|
+
const middle = Math.floor((left + right) / 2);
|
|
31
|
+
if (values[middle] < target) left = middle + 1;
|
|
32
|
+
else right = middle;
|
|
33
|
+
}
|
|
34
|
+
return left;
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/utils/language.ts
|
|
38
|
+
var SCRIPT_PATTERNS = [
|
|
39
|
+
[/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u, 1],
|
|
40
|
+
[/\p{Script=Latin}/u, 2],
|
|
41
|
+
[/\p{Script=Hangul}/u, 3],
|
|
42
|
+
[/\p{Script=Cyrillic}/u, 4],
|
|
43
|
+
[/\p{Script=Greek}/u, 5],
|
|
44
|
+
[/\p{Script=Arabic}/u, 6],
|
|
45
|
+
[/\p{Script=Hebrew}/u, 7],
|
|
46
|
+
[/\p{Script=Devanagari}/u, 8],
|
|
47
|
+
[/\p{Script=Thai}/u, 9]
|
|
48
|
+
];
|
|
49
|
+
var getOtherScript = (text, start, width) => {
|
|
50
|
+
const unit = text.charCodeAt(start);
|
|
51
|
+
if (unit === 12539 || unit === 12540) return 0;
|
|
52
|
+
if (unit >= 1024 && unit <= 1153 || unit >= 1162 && unit <= 1327) return 4;
|
|
53
|
+
if (unit >= 931 && unit <= 993) return 5;
|
|
54
|
+
if (unit >= 1568 && unit <= 1599 || unit >= 1601 && unit <= 1610) return 6;
|
|
55
|
+
if (unit >= 1488 && unit <= 1514) return 7;
|
|
56
|
+
if (unit >= 2304 && unit <= 2384 || unit >= 2389 && unit <= 2403 || unit >= 2406 && unit <= 2431) return 8;
|
|
57
|
+
if (unit >= 3585 && unit <= 3642 || unit >= 3648 && unit <= 3675) return 9;
|
|
58
|
+
const character = text.slice(start, start + width);
|
|
59
|
+
for (const [pattern, script] of SCRIPT_PATTERNS) if (pattern.test(character)) return script;
|
|
60
|
+
return 0;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Finds a boundary between supported scripts without allocating a segment list.
|
|
64
|
+
* Han and kana share a group so Japanese labels stay intact; Hangul, Latin, Cyrillic, Greek, Arabic, Hebrew, Devanagari and Thai remain separate.
|
|
65
|
+
* Punctuation, digits, inherited marks and unsupported scripts stay in the surrounding run.
|
|
66
|
+
*
|
|
67
|
+
* @param start A UTF-16 offset at a code-point boundary, usually the end returned by the previous call.
|
|
68
|
+
*
|
|
69
|
+
* @returns The exclusive UTF-16 end of the run, or text.length when no later boundary exists.
|
|
70
|
+
*/
|
|
71
|
+
var findScriptRunEnd = (text, start = 0) => {
|
|
72
|
+
let script = 0;
|
|
73
|
+
let index = start;
|
|
74
|
+
while (index < text.length) {
|
|
75
|
+
const unit = text.charCodeAt(index);
|
|
76
|
+
let nextScript = 0;
|
|
77
|
+
let width = 1;
|
|
78
|
+
if (unit <= 127) {
|
|
79
|
+
const letter = unit | 32;
|
|
80
|
+
if (letter >= 97 && letter <= 122) {
|
|
81
|
+
if (script !== 0 && script !== 2) return index;
|
|
82
|
+
script = 2;
|
|
83
|
+
do {
|
|
84
|
+
index += 1;
|
|
85
|
+
const nextLetter = text.charCodeAt(index) | 32;
|
|
86
|
+
if (nextLetter < 97 || nextLetter > 122) break;
|
|
87
|
+
} while (index < text.length);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
} else if (unit >= 19968 && unit <= 40959) nextScript = 1;
|
|
91
|
+
else if (unit >= 12353 && unit <= 12438 || unit >= 12449 && unit <= 12538) nextScript = 1;
|
|
92
|
+
else if (unit >= 44032 && unit <= 55203) nextScript = 3;
|
|
93
|
+
else {
|
|
94
|
+
width = unit >= 55296 && unit <= 56319 && text.codePointAt(index) > 65535 ? 2 : 1;
|
|
95
|
+
nextScript = getOtherScript(text, index, width);
|
|
96
|
+
}
|
|
97
|
+
if (nextScript !== 0) {
|
|
98
|
+
if (script !== 0 && script !== nextScript) return index;
|
|
99
|
+
script = nextScript;
|
|
100
|
+
}
|
|
101
|
+
index += width;
|
|
102
|
+
}
|
|
103
|
+
return text.length;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Returns a language tag in the canonical form the model stores, which is lower case.
|
|
107
|
+
*
|
|
108
|
+
* This mirrors the model's own helper, which it does not export.
|
|
109
|
+
* Comparing tags stays with the consumer, since BCP 47 matches by subtag prefix rather than by string equality.
|
|
110
|
+
*/
|
|
111
|
+
var lowerTag = (tag) => {
|
|
112
|
+
return tag ? tag.toLowerCase() : void 0;
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
115
|
+
export { mapShared as i, lowerTag as n, lowerBound as r, findScriptRunEnd as t };
|
|
116
|
+
|
|
117
|
+
//# sourceMappingURL=language.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language.js","names":[],"sources":["../src/utils/array.ts","../src/utils/language.ts"],"sourcesContent":["/**\n * Preserves the input array when every element keeps its identity, so unchanged parent nodes can also be reused.\n *\n * The callback must leave inputs untouched and return the original element when unchanged.\n */\nexport const mapShared = <T>(items: T[], transform: (item: T) => T): T[] => {\n let result = items\n for (const [index, item] of items.entries()) {\n const transformed = transform(item)\n if (transformed !== item) {\n if (result === items) {\n result = [...items]\n }\n result[index] = transformed\n }\n }\n return result\n}\n\n/**\n * Finds the first value meeting a lower bound so range queries can skip earlier candidates.\n *\n * @param values Values sorted in ascending order.\n * @param target Inclusive lower bound.\n *\n * @returns The first matching index, or the array length when every value is smaller.\n */\nexport const lowerBound = (values: readonly number[], target: number): number => {\n let left = 0\n let right = values.length\n while (left < right) {\n const middle = Math.floor((left + right) / 2)\n if (values[middle]! < target) {\n left = middle + 1\n } else {\n right = middle\n }\n }\n return left\n}\n","const enum ScriptGroup {\n NEUTRAL,\n EAST_ASIAN,\n LATIN,\n HANGUL,\n CYRILLIC,\n GREEK,\n ARABIC,\n HEBREW,\n DEVANAGARI,\n THAI,\n}\n\nconst SCRIPT_PATTERNS: readonly (readonly [RegExp, ScriptGroup])[] = [\n [/[\\p{Script=Han}\\p{Script=Hiragana}\\p{Script=Katakana}]/u, ScriptGroup.EAST_ASIAN],\n [/\\p{Script=Latin}/u, ScriptGroup.LATIN],\n [/\\p{Script=Hangul}/u, ScriptGroup.HANGUL],\n [/\\p{Script=Cyrillic}/u, ScriptGroup.CYRILLIC],\n [/\\p{Script=Greek}/u, ScriptGroup.GREEK],\n [/\\p{Script=Arabic}/u, ScriptGroup.ARABIC],\n [/\\p{Script=Hebrew}/u, ScriptGroup.HEBREW],\n [/\\p{Script=Devanagari}/u, ScriptGroup.DEVANAGARI],\n [/\\p{Script=Thai}/u, ScriptGroup.THAI],\n]\n\nconst getOtherScript = (text: string, start: number, width: number): ScriptGroup => {\n const unit = text.charCodeAt(start)\n if (unit === 0x30fb || unit === 0x30fc) {\n return ScriptGroup.NEUTRAL\n }\n if ((unit >= 0x0400 && unit <= 0x0481) || (unit >= 0x048a && unit <= 0x052f)) {\n return ScriptGroup.CYRILLIC\n }\n if (unit >= 0x03a3 && unit <= 0x03e1) {\n return ScriptGroup.GREEK\n }\n if ((unit >= 0x0620 && unit <= 0x063f) || (unit >= 0x0641 && unit <= 0x064a)) {\n return ScriptGroup.ARABIC\n }\n if (unit >= 0x05d0 && unit <= 0x05ea) {\n return ScriptGroup.HEBREW\n }\n if ((unit >= 0x0900 && unit <= 0x0950) || (unit >= 0x0955 && unit <= 0x0963) || (unit >= 0x0966 && unit <= 0x097f)) {\n return ScriptGroup.DEVANAGARI\n }\n if ((unit >= 0x0e01 && unit <= 0x0e3a) || (unit >= 0x0e40 && unit <= 0x0e5b)) {\n return ScriptGroup.THAI\n }\n\n const character = text.slice(start, start + width)\n for (const [pattern, script] of SCRIPT_PATTERNS) {\n if (pattern.test(character)) {\n return script\n }\n }\n return ScriptGroup.NEUTRAL\n}\n\n/**\n * Finds a boundary between supported scripts without allocating a segment list.\n * Han and kana share a group so Japanese labels stay intact; Hangul, Latin, Cyrillic, Greek, Arabic, Hebrew, Devanagari and Thai remain separate.\n * Punctuation, digits, inherited marks and unsupported scripts stay in the surrounding run.\n *\n * @param start A UTF-16 offset at a code-point boundary, usually the end returned by the previous call.\n *\n * @returns The exclusive UTF-16 end of the run, or text.length when no later boundary exists.\n */\nexport const findScriptRunEnd = (text: string, start = 0): number => {\n let script = ScriptGroup.NEUTRAL\n let index = start\n\n while (index < text.length) {\n const unit = text.charCodeAt(index)\n let nextScript = ScriptGroup.NEUTRAL\n let width = 1\n\n if (unit <= 0x7f) {\n const letter = unit | 0x20\n if (letter >= 0x61 && letter <= 0x7a) {\n if (script !== ScriptGroup.NEUTRAL && script !== ScriptGroup.LATIN) {\n return index\n }\n script = ScriptGroup.LATIN\n do {\n index += 1\n const nextLetter = text.charCodeAt(index) | 0x20\n if (nextLetter < 0x61 || nextLetter > 0x7a) {\n break\n }\n } while (index < text.length)\n continue\n }\n } else if (unit >= 0x4e00 && unit <= 0x9fff) {\n nextScript = ScriptGroup.EAST_ASIAN\n } else if ((unit >= 0x3041 && unit <= 0x3096) || (unit >= 0x30a1 && unit <= 0x30fa)) {\n nextScript = ScriptGroup.EAST_ASIAN\n } else if (unit >= 0xac00 && unit <= 0xd7a3) {\n nextScript = ScriptGroup.HANGUL\n } else {\n width = unit >= 0xd800 && unit <= 0xdbff && text.codePointAt(index)! > 0xffff ? 2 : 1\n nextScript = getOtherScript(text, index, width)\n }\n\n if (nextScript !== ScriptGroup.NEUTRAL) {\n if (script !== ScriptGroup.NEUTRAL && script !== nextScript) {\n return index\n }\n script = nextScript\n }\n index += width\n }\n return text.length\n}\n\n/**\n * Returns a language tag in the canonical form the model stores, which is lower case.\n *\n * This mirrors the model's own helper, which it does not export.\n * Comparing tags stays with the consumer, since BCP 47 matches by subtag prefix rather than by string equality.\n */\nexport const lowerTag = (tag: string | undefined): string | undefined => {\n return tag ? tag.toLowerCase() : undefined\n}\n"],"mappings":";;;;;;AAKA,IAAa,aAAgB,OAAY,cAAmC;CAC1E,IAAI,SAAS;CACb,KAAK,MAAM,CAAC,OAAO,SAAS,MAAM,QAAQ,GAAG;EAC3C,MAAM,cAAc,UAAU,IAAI;EAClC,IAAI,gBAAgB,MAAM;GACxB,IAAI,WAAW,OACb,SAAS,CAAC,GAAG,KAAK;GAEpB,OAAO,SAAS;EAClB;CACF;CACA,OAAO;AACT;;;;;;;;;AAUA,IAAa,cAAc,QAA2B,WAA2B;CAC/E,IAAI,OAAO;CACX,IAAI,QAAQ,OAAO;CACnB,OAAO,OAAO,OAAO;EACnB,MAAM,SAAS,KAAK,OAAO,OAAO,SAAS,CAAC;EAC5C,IAAI,OAAO,UAAW,QACpB,OAAO,SAAS;OAEhB,QAAQ;CAEZ;CACA,OAAO;AACT;;;AC1BA,IAAM,kBAA+D;CACnE,CAAC,2DAAA,CAAiF;CAClF,CAAC,qBAAA,CAAsC;CACvC,CAAC,sBAAA,CAAwC;CACzC,CAAC,wBAAA,CAA4C;CAC7C,CAAC,qBAAA,CAAsC;CACvC,CAAC,sBAAA,CAAwC;CACzC,CAAC,sBAAA,CAAwC;CACzC,CAAC,0BAAA,CAAgD;CACjD,CAAC,oBAAA,CAAoC;AACvC;AAEA,IAAM,kBAAkB,MAAc,OAAe,UAA+B;CAClF,MAAM,OAAO,KAAK,WAAW,KAAK;CAClC,IAAI,SAAS,SAAU,SAAS,OAC9B,OAAA;CAEF,IAAK,QAAQ,QAAU,QAAQ,QAAY,QAAQ,QAAU,QAAQ,MACnE,OAAA;CAEF,IAAI,QAAQ,OAAU,QAAQ,KAC5B,OAAA;CAEF,IAAK,QAAQ,QAAU,QAAQ,QAAY,QAAQ,QAAU,QAAQ,MACnE,OAAA;CAEF,IAAI,QAAQ,QAAU,QAAQ,MAC5B,OAAA;CAEF,IAAK,QAAQ,QAAU,QAAQ,QAAY,QAAQ,QAAU,QAAQ,QAAY,QAAQ,QAAU,QAAQ,MACzG,OAAA;CAEF,IAAK,QAAQ,QAAU,QAAQ,QAAY,QAAQ,QAAU,QAAQ,MACnE,OAAA;CAGF,MAAM,YAAY,KAAK,MAAM,OAAO,QAAQ,KAAK;CACjD,KAAK,MAAM,CAAC,SAAS,WAAW,iBAC9B,IAAI,QAAQ,KAAK,SAAS,GACxB,OAAO;CAGX,OAAA;AACF;;;;;;;;;;AAWA,IAAa,oBAAoB,MAAc,QAAQ,MAAc;CACnE,IAAI,SAAA;CACJ,IAAI,QAAQ;CAEZ,OAAO,QAAQ,KAAK,QAAQ;EAC1B,MAAM,OAAO,KAAK,WAAW,KAAK;EAClC,IAAI,aAAA;EACJ,IAAI,QAAQ;EAEZ,IAAI,QAAQ,KAAM;GAChB,MAAM,SAAS,OAAO;GACtB,IAAI,UAAU,MAAQ,UAAU,KAAM;IACpC,IAAI,WAAA,KAAkC,WAAA,GACpC,OAAO;IAET,SAAA;IACA,GAAG;KACD,SAAS;KACT,MAAM,aAAa,KAAK,WAAW,KAAK,IAAI;KAC5C,IAAI,aAAa,MAAQ,aAAa,KACpC;IAEJ,SAAS,QAAQ,KAAK;IACtB;GACF;EACF,OAAO,IAAI,QAAQ,SAAU,QAAQ,OACnC,aAAA;OACK,IAAK,QAAQ,SAAU,QAAQ,SAAY,QAAQ,SAAU,QAAQ,OAC1E,aAAA;OACK,IAAI,QAAQ,SAAU,QAAQ,OACnC,aAAA;OACK;GACL,QAAQ,QAAQ,SAAU,QAAQ,SAAU,KAAK,YAAY,KAAK,IAAK,QAAS,IAAI;GACpF,aAAa,eAAe,MAAM,OAAO,KAAK;EAChD;EAEA,IAAI,eAAA,GAAoC;GACtC,IAAI,WAAA,KAAkC,WAAW,YAC/C,OAAO;GAET,SAAS;EACX;EACA,SAAS;CACX;CACA,OAAO,KAAK;AACd;;;;;;;AAQA,IAAa,YAAY,QAAgD;CACvE,OAAO,MAAM,IAAI,YAAY,IAAI,KAAA;AACnC"}
|