music-lyric-kit 0.9.0 → 0.11.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/index.comm.js +1 -1
- package/dist/index.comm.js.map +1 -1
- package/dist/index.ecma.d.ts +59 -0
- package/dist/index.ecma.js +141 -28
- package/dist/index.ecma.js.map +1 -1
- package/package.json +14 -12
package/dist/index.comm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@music-lyric-kit/lyric"),x=require("@music-lyric-kit/plugin-format-lrc"),b=require("@music-lyric-kit/plugin-format-ttml"),y=require("@music-lyric-kit/plugin-transform-interlude"),_=require("@music-lyric-kit/plugin-transform-background"),T=require("@music-lyric-kit/plugin-transform-agent"),w=require("@music-lyric-kit/plugin-transform-space"),k=require("@music-lyric-kit/plugin-transform-pure"),C=require("@music-lyric-kit/plugin-transform-stress"),i=require("@music-lyric-kit/core");function n(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const c=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,c.get?c:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const E=n(u),f=n(x),g=n(b),p=n(y),a=n(_),h=n(T),d=n(w),o=n(k),m=n(C),O=Object.freeze(Object.defineProperty({__proto__:null,Lrc:f,Ttml:g},Symbol.toStringTag,{value:"Module"})),S=Object.freeze(Object.defineProperty({__proto__:null,Agent:h,Background:a,Interlude:p,Pure:o,Space:d,Stress:m},Symbol.toStringTag,{value:"Module"})),j=Object.freeze(Object.defineProperty({__proto__:null,Formats:O,Transforms:S},Symbol.toStringTag,{value:"Module"})),l=[new f.Parser,new g.AmllParser],r={agent:{extract:new h.ExtractPlugin},background:{extract:new a.ExtractPlugin,clean:new a.CleanPlugin},pure:{extract:new o.ExtractCreatorPlugin,clean:new o.CleanPlugin},space:{insert:new d.InsertPlugin},interlude:{insert:new p.InsertPlugin},stress:{mark:new m.MarkPlugin}};class P{context;format;input;done;constructor(e){this.done=!1,this.input=e,this.format=this.input.format||"";const t=new u.Info;this.context=new i.ParserContext({content:this.input.content,musicInfo:this.input.musicInfo},t)}handleApplyConfig(e,t){e.config&&(e.config.reset(),t&&e.config.update(t))}handleExecPlugin(e){this.done=!1;try{if(!e.check(this.context))return}catch(t){console.warn(`plugin check failed id=${e.id} err=${t?.message}`);return}try{e.exec(this.context)}catch(t){console.warn(`plugin call failed id=${e.id} err=${t?.message}`)}}infer(){if(this.format)return this;for(const e of l)try{e.check(this.context)&&(this.format=e.format);break}catch{continue}return this}parse(){if(!this.format)throw new Error("no format detected. call .infer() before .parse()");const e=l.find(t=>t.format===this.format);if(!e)throw new Error(`parser plugin not found: "${this.format}"`);this.done=!1;try{e.exec(this.context)}catch(t){console.warn(`plugin call failed id=${e.id} err=${t?.message}`)}return this}backgroundExtract(e){return this.handleApplyConfig(r.background.extract,e),this.handleExecPlugin(r.background.extract),this}backgroundClean(){return this.handleExecPlugin(r.background.clean),this}agentExtract(e){return this.handleApplyConfig(r.agent.extract,e),this.handleExecPlugin(r.agent.extract),this}pureExtract(e){return this.handleApplyConfig(r.pure.extract,e),this.handleExecPlugin(r.pure.extract),this}pureClean(e){return this.handleApplyConfig(r.pure.clean,e),this.handleExecPlugin(r.pure.clean),this}interludeInsert(e){return this.handleApplyConfig(r.interlude.insert,e),this.handleExecPlugin(r.interlude.insert),this}spaceInsert(e){return this.handleApplyConfig(r.space.insert,e),this.handleExecPlugin(r.space.insert),this}stressMark(e){return this.handleApplyConfig(r.stress.mark,e),this.handleExecPlugin(r.stress.mark),this}final(){return this.done||(this.context.cleanWord(),this.context.calcAgentIndex(),this.context.syncLineTimeWithWord(),this.context.sort(),this.context.syncLineTimeWithBackground(),this.done=!0),{format:this.format,result:this.context.result}}}const A=s=>new P(s);exports.Lyric=E;Object.defineProperty(exports,"Generator",{enumerable:!0,get:()=>i.Generator});Object.defineProperty(exports,"GeneratorContext",{enumerable:!0,get:()=>i.GeneratorContext});Object.defineProperty(exports,"Parser",{enumerable:!0,get:()=>i.Parser});Object.defineProperty(exports,"ParserContext",{enumerable:!0,get:()=>i.ParserContext});exports.ParserPipeline=P;exports.Plugins=j;exports.createParserPipeline=A;
|
|
2
2
|
//# sourceMappingURL=index.comm.js.map
|
package/dist/index.comm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.comm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.comm.js","sources":["../src/parser/pipeline.ts"],"sourcesContent":["import type { ParserParams } from '@music-lyric-kit/core'\n\nimport { Info } from '@music-lyric-kit/lyric'\nimport { ParserContext, ParserPlugin } from '@music-lyric-kit/core'\n\nimport { Formats, Transforms } from '@root/plugin'\n\nexport interface ParserPipelineInput {\n format?: string\n content: any\n musicInfo?: ParserParams['musicInfo']\n}\n\nexport interface ParserPipelineResult {\n format: string\n result: Info\n}\n\nconst BuiltInFormats = [new Formats.Lrc.Parser(), new Formats.Ttml.AmllParser()]\n\nconst BuiltInPlugins = {\n agent: {\n extract: new Transforms.Agent.ExtractPlugin(),\n },\n background: {\n extract: new Transforms.Background.ExtractPlugin(),\n clean: new Transforms.Background.CleanPlugin(),\n },\n pure: {\n extract: new Transforms.Pure.ExtractCreatorPlugin(),\n clean: new Transforms.Pure.CleanPlugin(),\n },\n space: {\n insert: new Transforms.Space.InsertPlugin(),\n },\n interlude: {\n insert: new Transforms.Interlude.InsertPlugin(),\n },\n stress: {\n mark: new Transforms.Stress.MarkPlugin(),\n },\n}\n\nexport class ParserPipeline {\n private context: ParserContext\n private format: string\n private input: ParserPipelineInput\n private done: boolean\n\n constructor(input: ParserPipelineInput) {\n this.done = false\n this.input = input\n this.format = this.input.format || ''\n\n const init = new Info()\n this.context = new ParserContext({ content: this.input.content, musicInfo: this.input.musicInfo }, init)\n }\n\n private handleApplyConfig(plugin: ParserPlugin, options?: any) {\n if (!plugin.config) {\n return\n }\n\n // reset config first\n plugin.config.reset()\n\n if (options) {\n plugin.config.update(options)\n }\n }\n\n private handleExecPlugin(plugin: ParserPlugin) {\n this.done = false\n\n try {\n const result = plugin.check(this.context)\n if (!result) {\n return\n }\n } catch (e: any) {\n console.warn(`plugin check failed id=${plugin.id} err=${e?.message}`)\n return\n }\n\n try {\n plugin.exec(this.context)\n } catch (e: any) {\n console.warn(`plugin call failed id=${plugin.id} err=${e?.message}`)\n }\n }\n\n infer(): this {\n if (this.format) {\n return this\n }\n for (const plugin of BuiltInFormats) {\n try {\n const result = plugin.check(this.context)\n if (result) {\n this.format = plugin.format\n }\n break\n } catch {\n continue\n }\n }\n return this\n }\n\n parse(): this {\n if (!this.format) {\n throw new Error('no format detected. call .infer() before .parse()')\n }\n\n const parser = BuiltInFormats.find((item) => item.format === this.format)\n if (!parser) {\n throw new Error(`parser plugin not found: \"${this.format}\"`)\n }\n\n this.done = false\n\n try {\n parser.exec(this.context)\n } catch (e: any) {\n console.warn(`plugin call failed id=${parser.id} err=${e?.message}`)\n }\n\n return this\n }\n\n backgroundExtract(options?: Transforms.Background.ExtractConfig): this {\n this.handleApplyConfig(BuiltInPlugins.background.extract, options)\n this.handleExecPlugin(BuiltInPlugins.background.extract)\n return this\n }\n\n backgroundClean(): this {\n this.handleExecPlugin(BuiltInPlugins.background.clean)\n return this\n }\n\n agentExtract(options?: Transforms.Agent.ExtractConfig): this {\n this.handleApplyConfig(BuiltInPlugins.agent.extract, options)\n this.handleExecPlugin(BuiltInPlugins.agent.extract)\n return this\n }\n\n pureExtract(options?: Transforms.Pure.ExtractCreatorConfig): this {\n this.handleApplyConfig(BuiltInPlugins.pure.extract, options)\n this.handleExecPlugin(BuiltInPlugins.pure.extract)\n return this\n }\n\n pureClean(options?: Transforms.Pure.CleanConfig): this {\n this.handleApplyConfig(BuiltInPlugins.pure.clean, options)\n this.handleExecPlugin(BuiltInPlugins.pure.clean)\n return this\n }\n\n interludeInsert(options?: Transforms.Interlude.InsertConfig): this {\n this.handleApplyConfig(BuiltInPlugins.interlude.insert, options)\n this.handleExecPlugin(BuiltInPlugins.interlude.insert)\n return this\n }\n\n spaceInsert(options?: Transforms.Space.SpaceConfig): this {\n this.handleApplyConfig(BuiltInPlugins.space.insert, options)\n this.handleExecPlugin(BuiltInPlugins.space.insert)\n return this\n }\n\n stressMark(options?: Transforms.Stress.MarkConfig): this {\n this.handleApplyConfig(BuiltInPlugins.stress.mark, options)\n this.handleExecPlugin(BuiltInPlugins.stress.mark)\n return this\n }\n\n final(): ParserPipelineResult {\n if (!this.done) {\n this.context.cleanWord()\n this.context.calcAgentIndex()\n this.context.syncLineTimeWithWord()\n this.context.sort()\n this.context.syncLineTimeWithBackground()\n this.done = true\n }\n\n return {\n format: this.format,\n result: this.context.result,\n }\n }\n}\n\nexport const createParserPipeline = (input: ParserPipelineInput) => {\n return new ParserPipeline(input)\n}\n"],"names":["BuiltInFormats","Formats.Lrc","Formats.Ttml","BuiltInPlugins","Transforms.Agent","Transforms.Background","Transforms.Pure","Transforms.Space","Transforms.Interlude","Transforms.Stress","ParserPipeline","input","init","Info","ParserContext","plugin","options","e","parser","item","createParserPipeline"],"mappings":"2wCAkBMA,EAAiB,CAAC,IAAIC,EAAY,OAAU,IAAIC,EAAa,UAAY,EAEzEC,EAAiB,CACrB,MAAO,CACL,QAAS,IAAIC,EAAiB,aAAc,EAE9C,WAAY,CACV,QAAS,IAAIC,EAAsB,cACnC,MAAO,IAAIA,EAAsB,WAAY,EAE/C,KAAM,CACJ,QAAS,IAAIC,EAAgB,qBAC7B,MAAO,IAAIA,EAAgB,WAAY,EAEzC,MAAO,CACL,OAAQ,IAAIC,EAAiB,YAAa,EAE5C,UAAW,CACT,OAAQ,IAAIC,EAAqB,YAAa,EAEhD,OAAQ,CACN,KAAM,IAAIC,EAAkB,UAA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eC,CAAK"}
|
package/dist/index.ecma.d.ts
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import * as Agent from '@music-lyric-kit/plugin-transform-agent';
|
|
2
2
|
import * as Background from '@music-lyric-kit/plugin-transform-background';
|
|
3
3
|
import { Generator as Generator_2 } from '@music-lyric-kit/core';
|
|
4
|
+
import { GeneratorContext } from '@music-lyric-kit/core';
|
|
5
|
+
import { GeneratorOptions } from '@music-lyric-kit/core';
|
|
6
|
+
import { GeneratorParams } from '@music-lyric-kit/core';
|
|
7
|
+
import { GeneratorResult } from '@music-lyric-kit/core';
|
|
8
|
+
import { Info } from '@music-lyric-kit/lyric';
|
|
4
9
|
import * as Interlude from '@music-lyric-kit/plugin-transform-interlude';
|
|
5
10
|
import * as Lrc from '@music-lyric-kit/plugin-format-lrc';
|
|
6
11
|
import * as Lyric from '@music-lyric-kit/lyric';
|
|
7
12
|
import { Parser } from '@music-lyric-kit/core';
|
|
13
|
+
import { ParserContext } from '@music-lyric-kit/core';
|
|
14
|
+
import { ParserOptions } from '@music-lyric-kit/core';
|
|
15
|
+
import { ParserParams } from '@music-lyric-kit/core';
|
|
16
|
+
import { ParserResult } from '@music-lyric-kit/core';
|
|
8
17
|
import * as Pure from '@music-lyric-kit/plugin-transform-pure';
|
|
9
18
|
import * as Space from '@music-lyric-kit/plugin-transform-space';
|
|
10
19
|
import * as Stress from '@music-lyric-kit/plugin-transform-stress';
|
|
11
20
|
import * as Ttml from '@music-lyric-kit/plugin-format-ttml';
|
|
12
21
|
|
|
22
|
+
export declare const createParserPipeline: (input: ParserPipelineInput) => ParserPipeline;
|
|
23
|
+
|
|
13
24
|
declare namespace Formats {
|
|
14
25
|
export {
|
|
15
26
|
Lrc,
|
|
@@ -19,10 +30,58 @@ declare namespace Formats {
|
|
|
19
30
|
|
|
20
31
|
export { Generator_2 as Generator }
|
|
21
32
|
|
|
33
|
+
export { GeneratorContext }
|
|
34
|
+
|
|
35
|
+
export { GeneratorOptions }
|
|
36
|
+
|
|
37
|
+
export { GeneratorParams }
|
|
38
|
+
|
|
39
|
+
export { GeneratorResult }
|
|
40
|
+
|
|
22
41
|
export { Lyric }
|
|
23
42
|
|
|
24
43
|
export { Parser }
|
|
25
44
|
|
|
45
|
+
export { ParserContext }
|
|
46
|
+
|
|
47
|
+
export { ParserOptions }
|
|
48
|
+
|
|
49
|
+
export { ParserParams }
|
|
50
|
+
|
|
51
|
+
export declare class ParserPipeline {
|
|
52
|
+
private context;
|
|
53
|
+
private format;
|
|
54
|
+
private input;
|
|
55
|
+
private done;
|
|
56
|
+
constructor(input: ParserPipelineInput);
|
|
57
|
+
private handleApplyConfig;
|
|
58
|
+
private handleExecPlugin;
|
|
59
|
+
infer(): this;
|
|
60
|
+
parse(): this;
|
|
61
|
+
backgroundExtract(options?: Transforms.Background.ExtractConfig): this;
|
|
62
|
+
backgroundClean(): this;
|
|
63
|
+
agentExtract(options?: Transforms.Agent.ExtractConfig): this;
|
|
64
|
+
pureExtract(options?: Transforms.Pure.ExtractCreatorConfig): this;
|
|
65
|
+
pureClean(options?: Transforms.Pure.CleanConfig): this;
|
|
66
|
+
interludeInsert(options?: Transforms.Interlude.InsertConfig): this;
|
|
67
|
+
spaceInsert(options?: Transforms.Space.SpaceConfig): this;
|
|
68
|
+
stressMark(options?: Transforms.Stress.MarkConfig): this;
|
|
69
|
+
final(): ParserPipelineResult;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export declare interface ParserPipelineInput {
|
|
73
|
+
format?: string;
|
|
74
|
+
content: any;
|
|
75
|
+
musicInfo?: ParserParams['musicInfo'];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export declare interface ParserPipelineResult {
|
|
79
|
+
format: string;
|
|
80
|
+
result: Info;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { ParserResult }
|
|
84
|
+
|
|
26
85
|
declare namespace Plugins {
|
|
27
86
|
export {
|
|
28
87
|
Formats,
|
package/dist/index.ecma.js
CHANGED
|
@@ -1,34 +1,147 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as n from "@music-lyric-kit/plugin-transform-
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
9
|
-
import * as
|
|
10
|
-
import
|
|
11
|
-
|
|
1
|
+
import { Info as p } from "@music-lyric-kit/lyric";
|
|
2
|
+
import * as y from "@music-lyric-kit/lyric";
|
|
3
|
+
import * as a from "@music-lyric-kit/plugin-format-lrc";
|
|
4
|
+
import * as c from "@music-lyric-kit/plugin-format-ttml";
|
|
5
|
+
import * as l from "@music-lyric-kit/plugin-transform-interlude";
|
|
6
|
+
import * as n from "@music-lyric-kit/plugin-transform-background";
|
|
7
|
+
import * as u from "@music-lyric-kit/plugin-transform-agent";
|
|
8
|
+
import * as h from "@music-lyric-kit/plugin-transform-space";
|
|
9
|
+
import * as i from "@music-lyric-kit/plugin-transform-pure";
|
|
10
|
+
import * as f from "@music-lyric-kit/plugin-transform-stress";
|
|
11
|
+
import { ParserContext as m } from "@music-lyric-kit/core";
|
|
12
|
+
import { Generator as T, GeneratorContext as A, Parser as I, ParserContext as _ } from "@music-lyric-kit/core";
|
|
13
|
+
const g = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
12
14
|
__proto__: null,
|
|
13
|
-
Lrc:
|
|
14
|
-
Ttml:
|
|
15
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
15
|
+
Lrc: a,
|
|
16
|
+
Ttml: c
|
|
17
|
+
}, Symbol.toStringTag, { value: "Module" })), d = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
16
18
|
__proto__: null,
|
|
17
|
-
Agent:
|
|
18
|
-
Background:
|
|
19
|
-
Interlude:
|
|
20
|
-
Pure:
|
|
21
|
-
Space:
|
|
22
|
-
Stress:
|
|
23
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
19
|
+
Agent: u,
|
|
20
|
+
Background: n,
|
|
21
|
+
Interlude: l,
|
|
22
|
+
Pure: i,
|
|
23
|
+
Space: h,
|
|
24
|
+
Stress: f
|
|
25
|
+
}, Symbol.toStringTag, { value: "Module" })), k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
24
26
|
__proto__: null,
|
|
25
|
-
Formats:
|
|
26
|
-
Transforms:
|
|
27
|
-
}, Symbol.toStringTag, { value: "Module" }))
|
|
27
|
+
Formats: g,
|
|
28
|
+
Transforms: d
|
|
29
|
+
}, Symbol.toStringTag, { value: "Module" })), o = [new a.Parser(), new c.AmllParser()], e = {
|
|
30
|
+
agent: {
|
|
31
|
+
extract: new u.ExtractPlugin()
|
|
32
|
+
},
|
|
33
|
+
background: {
|
|
34
|
+
extract: new n.ExtractPlugin(),
|
|
35
|
+
clean: new n.CleanPlugin()
|
|
36
|
+
},
|
|
37
|
+
pure: {
|
|
38
|
+
extract: new i.ExtractCreatorPlugin(),
|
|
39
|
+
clean: new i.CleanPlugin()
|
|
40
|
+
},
|
|
41
|
+
space: {
|
|
42
|
+
insert: new h.InsertPlugin()
|
|
43
|
+
},
|
|
44
|
+
interlude: {
|
|
45
|
+
insert: new l.InsertPlugin()
|
|
46
|
+
},
|
|
47
|
+
stress: {
|
|
48
|
+
mark: new f.MarkPlugin()
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
class x {
|
|
52
|
+
context;
|
|
53
|
+
format;
|
|
54
|
+
input;
|
|
55
|
+
done;
|
|
56
|
+
constructor(t) {
|
|
57
|
+
this.done = !1, this.input = t, this.format = this.input.format || "";
|
|
58
|
+
const r = new p();
|
|
59
|
+
this.context = new m({ content: this.input.content, musicInfo: this.input.musicInfo }, r);
|
|
60
|
+
}
|
|
61
|
+
handleApplyConfig(t, r) {
|
|
62
|
+
t.config && (t.config.reset(), r && t.config.update(r));
|
|
63
|
+
}
|
|
64
|
+
handleExecPlugin(t) {
|
|
65
|
+
this.done = !1;
|
|
66
|
+
try {
|
|
67
|
+
if (!t.check(this.context))
|
|
68
|
+
return;
|
|
69
|
+
} catch (r) {
|
|
70
|
+
console.warn(`plugin check failed id=${t.id} err=${r?.message}`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
t.exec(this.context);
|
|
75
|
+
} catch (r) {
|
|
76
|
+
console.warn(`plugin call failed id=${t.id} err=${r?.message}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
infer() {
|
|
80
|
+
if (this.format)
|
|
81
|
+
return this;
|
|
82
|
+
for (const t of o)
|
|
83
|
+
try {
|
|
84
|
+
t.check(this.context) && (this.format = t.format);
|
|
85
|
+
break;
|
|
86
|
+
} catch {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
parse() {
|
|
92
|
+
if (!this.format)
|
|
93
|
+
throw new Error("no format detected. call .infer() before .parse()");
|
|
94
|
+
const t = o.find((r) => r.format === this.format);
|
|
95
|
+
if (!t)
|
|
96
|
+
throw new Error(`parser plugin not found: "${this.format}"`);
|
|
97
|
+
this.done = !1;
|
|
98
|
+
try {
|
|
99
|
+
t.exec(this.context);
|
|
100
|
+
} catch (r) {
|
|
101
|
+
console.warn(`plugin call failed id=${t.id} err=${r?.message}`);
|
|
102
|
+
}
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
backgroundExtract(t) {
|
|
106
|
+
return this.handleApplyConfig(e.background.extract, t), this.handleExecPlugin(e.background.extract), this;
|
|
107
|
+
}
|
|
108
|
+
backgroundClean() {
|
|
109
|
+
return this.handleExecPlugin(e.background.clean), this;
|
|
110
|
+
}
|
|
111
|
+
agentExtract(t) {
|
|
112
|
+
return this.handleApplyConfig(e.agent.extract, t), this.handleExecPlugin(e.agent.extract), this;
|
|
113
|
+
}
|
|
114
|
+
pureExtract(t) {
|
|
115
|
+
return this.handleApplyConfig(e.pure.extract, t), this.handleExecPlugin(e.pure.extract), this;
|
|
116
|
+
}
|
|
117
|
+
pureClean(t) {
|
|
118
|
+
return this.handleApplyConfig(e.pure.clean, t), this.handleExecPlugin(e.pure.clean), this;
|
|
119
|
+
}
|
|
120
|
+
interludeInsert(t) {
|
|
121
|
+
return this.handleApplyConfig(e.interlude.insert, t), this.handleExecPlugin(e.interlude.insert), this;
|
|
122
|
+
}
|
|
123
|
+
spaceInsert(t) {
|
|
124
|
+
return this.handleApplyConfig(e.space.insert, t), this.handleExecPlugin(e.space.insert), this;
|
|
125
|
+
}
|
|
126
|
+
stressMark(t) {
|
|
127
|
+
return this.handleApplyConfig(e.stress.mark, t), this.handleExecPlugin(e.stress.mark), this;
|
|
128
|
+
}
|
|
129
|
+
final() {
|
|
130
|
+
return this.done || (this.context.cleanWord(), this.context.calcAgentIndex(), this.context.syncLineTimeWithWord(), this.context.sort(), this.context.syncLineTimeWithBackground(), this.done = !0), {
|
|
131
|
+
format: this.format,
|
|
132
|
+
result: this.context.result
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const b = (s) => new x(s);
|
|
28
137
|
export {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
138
|
+
T as Generator,
|
|
139
|
+
A as GeneratorContext,
|
|
140
|
+
y as Lyric,
|
|
141
|
+
I as Parser,
|
|
142
|
+
_ as ParserContext,
|
|
143
|
+
x as ParserPipeline,
|
|
144
|
+
k as Plugins,
|
|
145
|
+
b as createParserPipeline
|
|
33
146
|
};
|
|
34
147
|
//# sourceMappingURL=index.ecma.js.map
|
package/dist/index.ecma.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.ecma.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.ecma.js","sources":["../src/parser/pipeline.ts"],"sourcesContent":["import type { ParserParams } from '@music-lyric-kit/core'\n\nimport { Info } from '@music-lyric-kit/lyric'\nimport { ParserContext, ParserPlugin } from '@music-lyric-kit/core'\n\nimport { Formats, Transforms } from '@root/plugin'\n\nexport interface ParserPipelineInput {\n format?: string\n content: any\n musicInfo?: ParserParams['musicInfo']\n}\n\nexport interface ParserPipelineResult {\n format: string\n result: Info\n}\n\nconst BuiltInFormats = [new Formats.Lrc.Parser(), new Formats.Ttml.AmllParser()]\n\nconst BuiltInPlugins = {\n agent: {\n extract: new Transforms.Agent.ExtractPlugin(),\n },\n background: {\n extract: new Transforms.Background.ExtractPlugin(),\n clean: new Transforms.Background.CleanPlugin(),\n },\n pure: {\n extract: new Transforms.Pure.ExtractCreatorPlugin(),\n clean: new Transforms.Pure.CleanPlugin(),\n },\n space: {\n insert: new Transforms.Space.InsertPlugin(),\n },\n interlude: {\n insert: new Transforms.Interlude.InsertPlugin(),\n },\n stress: {\n mark: new Transforms.Stress.MarkPlugin(),\n },\n}\n\nexport class ParserPipeline {\n private context: ParserContext\n private format: string\n private input: ParserPipelineInput\n private done: boolean\n\n constructor(input: ParserPipelineInput) {\n this.done = false\n this.input = input\n this.format = this.input.format || ''\n\n const init = new Info()\n this.context = new ParserContext({ content: this.input.content, musicInfo: this.input.musicInfo }, init)\n }\n\n private handleApplyConfig(plugin: ParserPlugin, options?: any) {\n if (!plugin.config) {\n return\n }\n\n // reset config first\n plugin.config.reset()\n\n if (options) {\n plugin.config.update(options)\n }\n }\n\n private handleExecPlugin(plugin: ParserPlugin) {\n this.done = false\n\n try {\n const result = plugin.check(this.context)\n if (!result) {\n return\n }\n } catch (e: any) {\n console.warn(`plugin check failed id=${plugin.id} err=${e?.message}`)\n return\n }\n\n try {\n plugin.exec(this.context)\n } catch (e: any) {\n console.warn(`plugin call failed id=${plugin.id} err=${e?.message}`)\n }\n }\n\n infer(): this {\n if (this.format) {\n return this\n }\n for (const plugin of BuiltInFormats) {\n try {\n const result = plugin.check(this.context)\n if (result) {\n this.format = plugin.format\n }\n break\n } catch {\n continue\n }\n }\n return this\n }\n\n parse(): this {\n if (!this.format) {\n throw new Error('no format detected. call .infer() before .parse()')\n }\n\n const parser = BuiltInFormats.find((item) => item.format === this.format)\n if (!parser) {\n throw new Error(`parser plugin not found: \"${this.format}\"`)\n }\n\n this.done = false\n\n try {\n parser.exec(this.context)\n } catch (e: any) {\n console.warn(`plugin call failed id=${parser.id} err=${e?.message}`)\n }\n\n return this\n }\n\n backgroundExtract(options?: Transforms.Background.ExtractConfig): this {\n this.handleApplyConfig(BuiltInPlugins.background.extract, options)\n this.handleExecPlugin(BuiltInPlugins.background.extract)\n return this\n }\n\n backgroundClean(): this {\n this.handleExecPlugin(BuiltInPlugins.background.clean)\n return this\n }\n\n agentExtract(options?: Transforms.Agent.ExtractConfig): this {\n this.handleApplyConfig(BuiltInPlugins.agent.extract, options)\n this.handleExecPlugin(BuiltInPlugins.agent.extract)\n return this\n }\n\n pureExtract(options?: Transforms.Pure.ExtractCreatorConfig): this {\n this.handleApplyConfig(BuiltInPlugins.pure.extract, options)\n this.handleExecPlugin(BuiltInPlugins.pure.extract)\n return this\n }\n\n pureClean(options?: Transforms.Pure.CleanConfig): this {\n this.handleApplyConfig(BuiltInPlugins.pure.clean, options)\n this.handleExecPlugin(BuiltInPlugins.pure.clean)\n return this\n }\n\n interludeInsert(options?: Transforms.Interlude.InsertConfig): this {\n this.handleApplyConfig(BuiltInPlugins.interlude.insert, options)\n this.handleExecPlugin(BuiltInPlugins.interlude.insert)\n return this\n }\n\n spaceInsert(options?: Transforms.Space.SpaceConfig): this {\n this.handleApplyConfig(BuiltInPlugins.space.insert, options)\n this.handleExecPlugin(BuiltInPlugins.space.insert)\n return this\n }\n\n stressMark(options?: Transforms.Stress.MarkConfig): this {\n this.handleApplyConfig(BuiltInPlugins.stress.mark, options)\n this.handleExecPlugin(BuiltInPlugins.stress.mark)\n return this\n }\n\n final(): ParserPipelineResult {\n if (!this.done) {\n this.context.cleanWord()\n this.context.calcAgentIndex()\n this.context.syncLineTimeWithWord()\n this.context.sort()\n this.context.syncLineTimeWithBackground()\n this.done = true\n }\n\n return {\n format: this.format,\n result: this.context.result,\n }\n }\n}\n\nexport const createParserPipeline = (input: ParserPipelineInput) => {\n return new ParserPipeline(input)\n}\n"],"names":["BuiltInFormats","Formats.Lrc","Formats.Ttml","BuiltInPlugins","Transforms.Agent","Transforms.Background","Transforms.Pure","Transforms.Space","Transforms.Interlude","Transforms.Stress","ParserPipeline","input","init","Info","ParserContext","plugin","options","e","parser","item","createParserPipeline"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;8CAkBMA,IAAiB,CAAC,IAAIC,EAAY,OAAA,GAAU,IAAIC,EAAa,YAAY,GAEzEC,IAAiB;AAAA,EACrB,OAAO;AAAA,IACL,SAAS,IAAIC,EAAiB,cAAA;AAAA,EAAc;AAAA,EAE9C,YAAY;AAAA,IACV,SAAS,IAAIC,EAAsB,cAAA;AAAA,IACnC,OAAO,IAAIA,EAAsB,YAAA;AAAA,EAAY;AAAA,EAE/C,MAAM;AAAA,IACJ,SAAS,IAAIC,EAAgB,qBAAA;AAAA,IAC7B,OAAO,IAAIA,EAAgB,YAAA;AAAA,EAAY;AAAA,EAEzC,OAAO;AAAA,IACL,QAAQ,IAAIC,EAAiB,aAAA;AAAA,EAAa;AAAA,EAE5C,WAAW;AAAA,IACT,QAAQ,IAAIC,EAAqB,aAAA;AAAA,EAAa;AAAA,EAEhD,QAAQ;AAAA,IACN,MAAM,IAAIC,EAAkB,WAAA;AAAA,EAAW;AAE3C;AAEO,MAAMC,EAAe;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAYC,GAA4B;AACtC,SAAK,OAAO,IACZ,KAAK,QAAQA,GACb,KAAK,SAAS,KAAK,MAAM,UAAU;AAEnC,UAAMC,IAAO,IAAIC,EAAA;AACjB,SAAK,UAAU,IAAIC,EAAc,EAAE,SAAS,KAAK,MAAM,SAAS,WAAW,KAAK,MAAM,UAAA,GAAaF,CAAI;AAAA,EACzG;AAAA,EAEQ,kBAAkB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@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "music-lyric-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"author": "folltoshe",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Music Lyric Kit",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "https://github.com/music-lyric/music-lyric-kit-node.git",
|
|
15
|
-
"directory": "
|
|
15
|
+
"directory": "main"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [
|
|
18
18
|
"music",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"types": "./dist/index.ecma.d.ts",
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
+
"dev": "./src/index.ts",
|
|
27
28
|
"types": "./dist/index.ecma.d.ts",
|
|
28
29
|
"import": "./dist/index.ecma.js",
|
|
29
30
|
"require": "./dist/index.comm.js"
|
|
@@ -33,16 +34,17 @@
|
|
|
33
34
|
"dist"
|
|
34
35
|
],
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@music-lyric-kit/core": "0.
|
|
37
|
-
"@music-lyric-kit/
|
|
38
|
-
"@music-lyric-kit/plugin-format-
|
|
39
|
-
"@music-lyric-kit/
|
|
40
|
-
"@music-lyric-kit/
|
|
41
|
-
"@music-lyric-kit/plugin-transform-
|
|
42
|
-
"@music-lyric-kit/plugin-transform-space": "0.
|
|
43
|
-
"@music-lyric-kit/plugin-transform-
|
|
44
|
-
"@music-lyric-kit/plugin-transform-agent": "0.3.
|
|
45
|
-
"@music-lyric-kit/plugin-transform-
|
|
37
|
+
"@music-lyric-kit/core": "^0.7.0",
|
|
38
|
+
"@music-lyric-kit/utils": "^0.5.0",
|
|
39
|
+
"@music-lyric-kit/plugin-format-lrc": "^0.5.1",
|
|
40
|
+
"@music-lyric-kit/lyric": "^0.4.0",
|
|
41
|
+
"@music-lyric-kit/plugin-format-ttml": "^0.1.4",
|
|
42
|
+
"@music-lyric-kit/plugin-transform-interlude": "^0.3.5",
|
|
43
|
+
"@music-lyric-kit/plugin-transform-space": "^0.3.0",
|
|
44
|
+
"@music-lyric-kit/plugin-transform-background": "^0.3.0",
|
|
45
|
+
"@music-lyric-kit/plugin-transform-agent": "^0.3.3",
|
|
46
|
+
"@music-lyric-kit/plugin-transform-pure": "^0.5.0",
|
|
47
|
+
"@music-lyric-kit/plugin-transform-stress": "^0.1.4"
|
|
46
48
|
},
|
|
47
49
|
"scripts": {
|
|
48
50
|
"build": "vite build"
|