music-lyric-kit 0.12.0 → 0.13.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 +73 -11
- package/dist/index.ecma.js +126 -80
- package/dist/index.ecma.js.map +1 -1
- package/package.json +13 -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 h=require("@music-lyric-kit/lyric"),x=require("@music-lyric-kit/plugin-format-lrc"),P=require("@music-lyric-kit/plugin-format-ttml"),w=require("@music-lyric-kit/plugin-transform-interlude"),b=require("@music-lyric-kit/plugin-transform-background"),y=require("@music-lyric-kit/plugin-transform-agent"),T=require("@music-lyric-kit/plugin-transform-space"),k=require("@music-lyric-kit/plugin-transform-pure"),S=require("@music-lyric-kit/plugin-transform-stress"),O=require("@music-lyric-kit/plugin-transform-language"),s=require("@music-lyric-kit/core");function n(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const u=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,u.get?u:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const f=n(x),i=n(P),m=n(w),c=n(b),g=n(y),p=n(T),a=n(k),d=n(S),o=n(O),j=Object.freeze(Object.defineProperty({__proto__:null,Lrc:f,Ttml:i},Symbol.toStringTag,{value:"Module"})),C=Object.freeze(Object.defineProperty({__proto__:null,Agent:g,Background:c,Interlude:m,Language:o,Pure:a,Space:p,Stress:d},Symbol.toStringTag,{value:"Module"})),l=[new f.Parser,new i.AmllParser,new i.ItunesParser];class I{constructor(e){this.client=e}_extract=new g.Extract;extract(e){return this.client.run(this._extract,e)}}class L{constructor(e){this.client=e}_extract=new c.Extract;_clean=new c.Clean;extract(e){return this.client.run(this._extract,e)}clean(){return this.client.run(this._clean)}}class q{constructor(e){this.client=e}_extractCreator=new a.ExtractCreator;_clean=new a.Clean;extractCreator(e){return this.client.run(this._extractCreator,e)}clean(e){return this.client.run(this._clean,e)}}class ${constructor(e){this.client=e}_insert=new m.Insert;insert(e){return this.client.run(this._insert,e)}}class A{constructor(e){this.client=e}_insert=new p.Insert;insert(e){return this.client.run(this._insert,e)}}class B{constructor(e){this.client=e}_mark=new d.Mark;mark(e){return this.client.run(this._mark,e)}}class F{constructor(e){this.client=e}_infer=new o.Infer;_calculatePercent=new o.CalculatePercent;infer(e){return this.client.run(this._infer,e)}calculatePercent(e){return this.client.run(this._calculatePercent,e)}}class _{context;format;input;done;agent;background;pure;interlude;space;stress;language;constructor(e){this.done=!1,this.input=e,this.format=this.input.format||"";const t=new h.Lyric.Info;this.context=new s.ParserContext({content:this.input.content,musicInfo:this.input.musicInfo},t),this.agent=new I(this),this.background=new L(this),this.pure=new q(this),this.interlude=new $(this),this.space=new A(this),this.stress=new B(this),this.language=new F(this)}applyConfig(e,t){e.config&&(e.config.reset(),t&&e.config.update(t))}exec(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}`)}}run(e,t){return this.applyConfig(e,t),this.exec(e),this}infer(){if(this.format)return this;for(const e of l)try{if(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}final(){return this.done||(this.context.cleanWord(),this.context.syncLineTimeWithWord(),this.context.sort(),this.context.calcAgentIndex(),this.context.syncLineTimeWithBackground(),this.done=!0),{format:this.format,result:this.context.result}}}const E=r=>new _(r);Object.defineProperty(exports,"Lyric",{enumerable:!0,get:()=>h.Lyric});Object.defineProperty(exports,"Generator",{enumerable:!0,get:()=>s.Generator});Object.defineProperty(exports,"GeneratorContext",{enumerable:!0,get:()=>s.GeneratorContext});Object.defineProperty(exports,"Parser",{enumerable:!0,get:()=>s.Parser});Object.defineProperty(exports,"ParserContext",{enumerable:!0,get:()=>s.ParserContext});exports.Format=j;exports.ParserPipeline=_;exports.Transform=C;exports.createParserPipeline=E;
|
|
2
2
|
//# sourceMappingURL=index.comm.js.map
|
package/dist/index.comm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.comm.js","sources":["../src/parser/pipeline.ts"],"sourcesContent":["import type { ParserParams } from '@music-lyric-kit/core'\n\nimport { Lyric } from '@music-lyric-kit/lyric'\nimport { ParserContext, ParserPlugin } from '@music-lyric-kit/core'\n\nimport { Format, Transform } 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: Lyric.Info\n}\n\nconst BuiltInFormats = [new Format.Lrc.Parser(), new Format.Ttml.AmllParser()]\n\
|
|
1
|
+
{"version":3,"file":"index.comm.js","sources":["../src/parser/pipeline.ts"],"sourcesContent":["import type { ParserParams } from '@music-lyric-kit/core'\n\nimport { Lyric } from '@music-lyric-kit/lyric'\nimport { ParserContext, ParserPlugin } from '@music-lyric-kit/core'\n\nimport { Format, Transform } 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: Lyric.Info\n}\n\nconst BuiltInFormats = [new Format.Lrc.Parser(), new Format.Ttml.AmllParser(), new Format.Ttml.ItunesParser()]\n\nclass Agent {\n private _extract = new Transform.Agent.Extract()\n\n constructor(private client: ParserPipeline) {}\n\n extract(options?: Transform.Agent.ExtractConfig) {\n return this.client.run(this._extract, options)\n }\n}\n\nclass Background {\n private _extract = new Transform.Background.Extract()\n private _clean = new Transform.Background.Clean()\n\n constructor(private client: ParserPipeline) {}\n\n extract(options?: Transform.Background.ExtractConfig) {\n return this.client.run(this._extract, options)\n }\n\n clean() {\n return this.client.run(this._clean)\n }\n}\n\nclass Pure {\n private _extractCreator = new Transform.Pure.ExtractCreator()\n private _clean = new Transform.Pure.Clean()\n\n constructor(private client: ParserPipeline) {}\n\n extractCreator(options?: Transform.Pure.ExtractCreatorConfig) {\n return this.client.run(this._extractCreator, options)\n }\n\n clean(options?: Transform.Pure.CleanConfig) {\n return this.client.run(this._clean, options)\n }\n}\n\nclass Interlude {\n private _insert = new Transform.Interlude.Insert()\n\n constructor(private client: ParserPipeline) {}\n\n insert(options?: Transform.Interlude.InsertConfig) {\n return this.client.run(this._insert, options)\n }\n}\n\nclass Space {\n private _insert = new Transform.Space.Insert()\n\n constructor(private client: ParserPipeline) {}\n\n insert(options?: Transform.Space.SpaceConfig) {\n return this.client.run(this._insert, options)\n }\n}\n\nclass Stress {\n private _mark = new Transform.Stress.Mark()\n\n constructor(private client: ParserPipeline) {}\n\n mark(options?: Transform.Stress.MarkConfig) {\n return this.client.run(this._mark, options)\n }\n}\n\nclass Language {\n private _infer = new Transform.Language.Infer()\n private _calculatePercent = new Transform.Language.CalculatePercent()\n\n constructor(private client: ParserPipeline) {}\n\n infer(options?: Transform.Language.InferConfig) {\n return this.client.run(this._infer, options)\n }\n\n calculatePercent(options?: Transform.Language.CalculateConfig) {\n return this.client.run(this._calculatePercent, options)\n }\n}\n\nexport class ParserPipeline {\n private context: ParserContext\n private format: string\n private input: ParserPipelineInput\n private done: boolean\n\n readonly agent: Agent\n readonly background: Background\n readonly pure: Pure\n readonly interlude: Interlude\n readonly space: Space\n readonly stress: Stress\n readonly language: Language\n\n constructor(input: ParserPipelineInput) {\n this.done = false\n this.input = input\n this.format = this.input.format || ''\n\n const init = new Lyric.Info()\n this.context = new ParserContext({ content: this.input.content, musicInfo: this.input.musicInfo }, init)\n\n this.agent = new Agent(this)\n this.background = new Background(this)\n this.pure = new Pure(this)\n this.interlude = new Interlude(this)\n this.space = new Space(this)\n this.stress = new Stress(this)\n this.language = new Language(this)\n }\n\n private applyConfig(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 exec(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 /**\n * Apply optional config to a plugin and execute it against the current context.\n * Intended for use by the pipeline plugin scopes.\n */\n run(plugin: ParserPlugin, options?: any): this {\n this.applyConfig(plugin, options)\n this.exec(plugin)\n return this\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 break\n }\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 final(): ParserPipelineResult {\n if (!this.done) {\n this.context.cleanWord()\n this.context.syncLineTimeWithWord()\n this.context.sort()\n this.context.calcAgentIndex()\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","Format.Lrc","Format.Ttml","Agent","client","Transform.Agent","options","Background","Transform.Background","Pure","Transform.Pure","Interlude","Transform.Interlude","Space","Transform.Space","Stress","Transform.Stress","Language","Transform.Language","ParserPipeline","input","init","Lyric","ParserContext","plugin","e","parser","item","createParserPipeline"],"mappings":"0tCAkBMA,EAAiB,CAAC,IAAIC,EAAW,OAAU,IAAIC,EAAY,WAAc,IAAIA,EAAY,YAAc,EAE7G,MAAMC,CAAM,CAGV,YAAoBC,EAAwB,CAAxB,KAAA,OAAAA,CAAyB,CAFrC,SAAW,IAAIC,EAAgB,QAIvC,QAAQC,EAAyC,CAC/C,OAAO,KAAK,OAAO,IAAI,KAAK,SAAUA,CAAO,CAC/C,CACF,CAEA,MAAMC,CAAW,CAIf,YAAoBH,EAAwB,CAAxB,KAAA,OAAAA,CAAyB,CAHrC,SAAW,IAAII,EAAqB,QACpC,OAAS,IAAIA,EAAqB,MAI1C,QAAQF,EAA8C,CACpD,OAAO,KAAK,OAAO,IAAI,KAAK,SAAUA,CAAO,CAC/C,CAEA,OAAQ,CACN,OAAO,KAAK,OAAO,IAAI,KAAK,MAAM,CACpC,CACF,CAEA,MAAMG,CAAK,CAIT,YAAoBL,EAAwB,CAAxB,KAAA,OAAAA,CAAyB,CAHrC,gBAAkB,IAAIM,EAAe,eACrC,OAAS,IAAIA,EAAe,MAIpC,eAAeJ,EAA+C,CAC5D,OAAO,KAAK,OAAO,IAAI,KAAK,gBAAiBA,CAAO,CACtD,CAEA,MAAMA,EAAsC,CAC1C,OAAO,KAAK,OAAO,IAAI,KAAK,OAAQA,CAAO,CAC7C,CACF,CAEA,MAAMK,CAAU,CAGd,YAAoBP,EAAwB,CAAxB,KAAA,OAAAA,CAAyB,CAFrC,QAAU,IAAIQ,EAAoB,OAI1C,OAAON,EAA4C,CACjD,OAAO,KAAK,OAAO,IAAI,KAAK,QAASA,CAAO,CAC9C,CACF,CAEA,MAAMO,CAAM,CAGV,YAAoBT,EAAwB,CAAxB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A,EACb,KAAK,KAAO,IAGP,CACL,OAAQ,KAAK,OACb,OAAQ,KAAK,QAAQ,MAAA,CAEzB,CACF,CAEO,MAAMG,EAAwBR,GAC5B,IAAID,EAAeC,CAAK"}
|
package/dist/index.ecma.d.ts
CHANGED
|
@@ -6,18 +6,36 @@ import { GeneratorOptions } from '@music-lyric-kit/core';
|
|
|
6
6
|
import { GeneratorParams } from '@music-lyric-kit/core';
|
|
7
7
|
import { GeneratorResult } from '@music-lyric-kit/core';
|
|
8
8
|
import * as Interlude from '@music-lyric-kit/plugin-transform-interlude';
|
|
9
|
+
import * as Language from '@music-lyric-kit/plugin-transform-language';
|
|
9
10
|
import * as Lrc from '@music-lyric-kit/plugin-format-lrc';
|
|
10
11
|
import { Lyric } from '@music-lyric-kit/lyric';
|
|
11
12
|
import { Parser } from '@music-lyric-kit/core';
|
|
12
13
|
import { ParserContext } from '@music-lyric-kit/core';
|
|
13
14
|
import { ParserOptions } from '@music-lyric-kit/core';
|
|
14
15
|
import { ParserParams } from '@music-lyric-kit/core';
|
|
16
|
+
import { ParserPlugin } from '@music-lyric-kit/core';
|
|
15
17
|
import { ParserResult } from '@music-lyric-kit/core';
|
|
16
18
|
import * as Pure from '@music-lyric-kit/plugin-transform-pure';
|
|
17
19
|
import * as Space from '@music-lyric-kit/plugin-transform-space';
|
|
18
20
|
import * as Stress from '@music-lyric-kit/plugin-transform-stress';
|
|
19
21
|
import * as Ttml from '@music-lyric-kit/plugin-format-ttml';
|
|
20
22
|
|
|
23
|
+
declare class Agent_2 {
|
|
24
|
+
private client;
|
|
25
|
+
private _extract;
|
|
26
|
+
constructor(client: ParserPipeline);
|
|
27
|
+
extract(options?: Transform.Agent.ExtractConfig): ParserPipeline;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare class Background_2 {
|
|
31
|
+
private client;
|
|
32
|
+
private _extract;
|
|
33
|
+
private _clean;
|
|
34
|
+
constructor(client: ParserPipeline);
|
|
35
|
+
extract(options?: Transform.Background.ExtractConfig): ParserPipeline;
|
|
36
|
+
clean(): ParserPipeline;
|
|
37
|
+
}
|
|
38
|
+
|
|
21
39
|
export declare const createParserPipeline: (input: ParserPipelineInput) => ParserPipeline;
|
|
22
40
|
|
|
23
41
|
declare namespace Format {
|
|
@@ -38,6 +56,22 @@ export { GeneratorParams }
|
|
|
38
56
|
|
|
39
57
|
export { GeneratorResult }
|
|
40
58
|
|
|
59
|
+
declare class Interlude_2 {
|
|
60
|
+
private client;
|
|
61
|
+
private _insert;
|
|
62
|
+
constructor(client: ParserPipeline);
|
|
63
|
+
insert(options?: Transform.Interlude.InsertConfig): ParserPipeline;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare class Language_2 {
|
|
67
|
+
private client;
|
|
68
|
+
private _infer;
|
|
69
|
+
private _calculatePercent;
|
|
70
|
+
constructor(client: ParserPipeline);
|
|
71
|
+
infer(options?: Transform.Language.InferConfig): ParserPipeline;
|
|
72
|
+
calculatePercent(options?: Transform.Language.CalculateConfig): ParserPipeline;
|
|
73
|
+
}
|
|
74
|
+
|
|
41
75
|
export { Lyric }
|
|
42
76
|
|
|
43
77
|
export { Parser }
|
|
@@ -53,19 +87,23 @@ export declare class ParserPipeline {
|
|
|
53
87
|
private format;
|
|
54
88
|
private input;
|
|
55
89
|
private done;
|
|
90
|
+
readonly agent: Agent_2;
|
|
91
|
+
readonly background: Background_2;
|
|
92
|
+
readonly pure: Pure_2;
|
|
93
|
+
readonly interlude: Interlude_2;
|
|
94
|
+
readonly space: Space_2;
|
|
95
|
+
readonly stress: Stress_2;
|
|
96
|
+
readonly language: Language_2;
|
|
56
97
|
constructor(input: ParserPipelineInput);
|
|
57
|
-
private
|
|
58
|
-
private
|
|
98
|
+
private applyConfig;
|
|
99
|
+
private exec;
|
|
100
|
+
/**
|
|
101
|
+
* Apply optional config to a plugin and execute it against the current context.
|
|
102
|
+
* Intended for use by the pipeline plugin scopes.
|
|
103
|
+
*/
|
|
104
|
+
run(plugin: ParserPlugin, options?: any): this;
|
|
59
105
|
infer(): this;
|
|
60
106
|
parse(): this;
|
|
61
|
-
backgroundExtract(options?: Transform.Background.ExtractConfig): this;
|
|
62
|
-
backgroundClean(): this;
|
|
63
|
-
agentExtract(options?: Transform.Agent.ExtractConfig): this;
|
|
64
|
-
pureExtract(options?: Transform.Pure.ExtractCreatorConfig): this;
|
|
65
|
-
pureClean(options?: Transform.Pure.CleanConfig): this;
|
|
66
|
-
interludeInsert(options?: Transform.Interlude.InsertConfig): this;
|
|
67
|
-
spaceInsert(options?: Transform.Space.SpaceConfig): this;
|
|
68
|
-
stressMark(options?: Transform.Stress.MarkConfig): this;
|
|
69
107
|
final(): ParserPipelineResult;
|
|
70
108
|
}
|
|
71
109
|
|
|
@@ -82,6 +120,29 @@ export declare interface ParserPipelineResult {
|
|
|
82
120
|
|
|
83
121
|
export { ParserResult }
|
|
84
122
|
|
|
123
|
+
declare class Pure_2 {
|
|
124
|
+
private client;
|
|
125
|
+
private _extractCreator;
|
|
126
|
+
private _clean;
|
|
127
|
+
constructor(client: ParserPipeline);
|
|
128
|
+
extractCreator(options?: Transform.Pure.ExtractCreatorConfig): ParserPipeline;
|
|
129
|
+
clean(options?: Transform.Pure.CleanConfig): ParserPipeline;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
declare class Space_2 {
|
|
133
|
+
private client;
|
|
134
|
+
private _insert;
|
|
135
|
+
constructor(client: ParserPipeline);
|
|
136
|
+
insert(options?: Transform.Space.SpaceConfig): ParserPipeline;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
declare class Stress_2 {
|
|
140
|
+
private client;
|
|
141
|
+
private _mark;
|
|
142
|
+
constructor(client: ParserPipeline);
|
|
143
|
+
mark(options?: Transform.Stress.MarkConfig): ParserPipeline;
|
|
144
|
+
}
|
|
145
|
+
|
|
85
146
|
declare namespace Transform {
|
|
86
147
|
export {
|
|
87
148
|
Interlude,
|
|
@@ -89,7 +150,8 @@ declare namespace Transform {
|
|
|
89
150
|
Agent,
|
|
90
151
|
Space,
|
|
91
152
|
Pure,
|
|
92
|
-
Stress
|
|
153
|
+
Stress,
|
|
154
|
+
Language
|
|
93
155
|
}
|
|
94
156
|
}
|
|
95
157
|
export { Transform }
|
package/dist/index.ecma.js
CHANGED
|
@@ -1,77 +1,147 @@
|
|
|
1
|
-
import { Lyric as
|
|
2
|
-
import { Lyric as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
1
|
+
import { Lyric as m } from "@music-lyric-kit/lyric";
|
|
2
|
+
import { Lyric as A } from "@music-lyric-kit/lyric";
|
|
3
|
+
import * as c from "@music-lyric-kit/plugin-format-lrc";
|
|
4
|
+
import * as n from "@music-lyric-kit/plugin-format-ttml";
|
|
5
5
|
import * as l from "@music-lyric-kit/plugin-transform-interlude";
|
|
6
|
-
import * as
|
|
6
|
+
import * as s from "@music-lyric-kit/plugin-transform-background";
|
|
7
7
|
import * as u from "@music-lyric-kit/plugin-transform-agent";
|
|
8
8
|
import * as h from "@music-lyric-kit/plugin-transform-space";
|
|
9
9
|
import * as i from "@music-lyric-kit/plugin-transform-pure";
|
|
10
10
|
import * as f from "@music-lyric-kit/plugin-transform-stress";
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
|
|
11
|
+
import * as o from "@music-lyric-kit/plugin-transform-language";
|
|
12
|
+
import { ParserContext as p } from "@music-lyric-kit/core";
|
|
13
|
+
import { Generator as E, GeneratorContext as j, Parser as F, ParserContext as O } from "@music-lyric-kit/core";
|
|
14
|
+
const I = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
14
15
|
__proto__: null,
|
|
15
|
-
Lrc:
|
|
16
|
-
Ttml:
|
|
17
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
16
|
+
Lrc: c,
|
|
17
|
+
Ttml: n
|
|
18
|
+
}, Symbol.toStringTag, { value: "Module" })), b = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
18
19
|
__proto__: null,
|
|
19
20
|
Agent: u,
|
|
20
|
-
Background:
|
|
21
|
+
Background: s,
|
|
21
22
|
Interlude: l,
|
|
23
|
+
Language: o,
|
|
22
24
|
Pure: i,
|
|
23
25
|
Space: h,
|
|
24
26
|
Stress: f
|
|
25
|
-
}, Symbol.toStringTag, { value: "Module" })), a = [new
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
background: {
|
|
30
|
-
extract: new n.Extract(),
|
|
31
|
-
clean: new n.Clean()
|
|
32
|
-
},
|
|
33
|
-
pure: {
|
|
34
|
-
extract: new i.ExtractCreator(),
|
|
35
|
-
clean: new i.Clean()
|
|
36
|
-
},
|
|
37
|
-
space: {
|
|
38
|
-
insert: new h.Insert()
|
|
39
|
-
},
|
|
40
|
-
interlude: {
|
|
41
|
-
insert: new l.Insert()
|
|
42
|
-
},
|
|
43
|
-
stress: {
|
|
44
|
-
mark: new f.Mark()
|
|
27
|
+
}, Symbol.toStringTag, { value: "Module" })), a = [new c.Parser(), new n.AmllParser(), new n.ItunesParser()];
|
|
28
|
+
class g {
|
|
29
|
+
constructor(t) {
|
|
30
|
+
this.client = t;
|
|
45
31
|
}
|
|
46
|
-
|
|
32
|
+
_extract = new u.Extract();
|
|
33
|
+
extract(t) {
|
|
34
|
+
return this.client.run(this._extract, t);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
47
37
|
class d {
|
|
38
|
+
constructor(t) {
|
|
39
|
+
this.client = t;
|
|
40
|
+
}
|
|
41
|
+
_extract = new s.Extract();
|
|
42
|
+
_clean = new s.Clean();
|
|
43
|
+
extract(t) {
|
|
44
|
+
return this.client.run(this._extract, t);
|
|
45
|
+
}
|
|
46
|
+
clean() {
|
|
47
|
+
return this.client.run(this._clean);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
class x {
|
|
51
|
+
constructor(t) {
|
|
52
|
+
this.client = t;
|
|
53
|
+
}
|
|
54
|
+
_extractCreator = new i.ExtractCreator();
|
|
55
|
+
_clean = new i.Clean();
|
|
56
|
+
extractCreator(t) {
|
|
57
|
+
return this.client.run(this._extractCreator, t);
|
|
58
|
+
}
|
|
59
|
+
clean(t) {
|
|
60
|
+
return this.client.run(this._clean, t);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
class w {
|
|
64
|
+
constructor(t) {
|
|
65
|
+
this.client = t;
|
|
66
|
+
}
|
|
67
|
+
_insert = new l.Insert();
|
|
68
|
+
insert(t) {
|
|
69
|
+
return this.client.run(this._insert, t);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class _ {
|
|
73
|
+
constructor(t) {
|
|
74
|
+
this.client = t;
|
|
75
|
+
}
|
|
76
|
+
_insert = new h.Insert();
|
|
77
|
+
insert(t) {
|
|
78
|
+
return this.client.run(this._insert, t);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
class P {
|
|
82
|
+
constructor(t) {
|
|
83
|
+
this.client = t;
|
|
84
|
+
}
|
|
85
|
+
_mark = new f.Mark();
|
|
86
|
+
mark(t) {
|
|
87
|
+
return this.client.run(this._mark, t);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
class k {
|
|
91
|
+
constructor(t) {
|
|
92
|
+
this.client = t;
|
|
93
|
+
}
|
|
94
|
+
_infer = new o.Infer();
|
|
95
|
+
_calculatePercent = new o.CalculatePercent();
|
|
96
|
+
infer(t) {
|
|
97
|
+
return this.client.run(this._infer, t);
|
|
98
|
+
}
|
|
99
|
+
calculatePercent(t) {
|
|
100
|
+
return this.client.run(this._calculatePercent, t);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
class y {
|
|
48
104
|
context;
|
|
49
105
|
format;
|
|
50
106
|
input;
|
|
51
107
|
done;
|
|
108
|
+
agent;
|
|
109
|
+
background;
|
|
110
|
+
pure;
|
|
111
|
+
interlude;
|
|
112
|
+
space;
|
|
113
|
+
stress;
|
|
114
|
+
language;
|
|
52
115
|
constructor(t) {
|
|
53
116
|
this.done = !1, this.input = t, this.format = this.input.format || "";
|
|
54
|
-
const
|
|
55
|
-
this.context = new
|
|
117
|
+
const e = new m.Info();
|
|
118
|
+
this.context = new p({ content: this.input.content, musicInfo: this.input.musicInfo }, e), this.agent = new g(this), this.background = new d(this), this.pure = new x(this), this.interlude = new w(this), this.space = new _(this), this.stress = new P(this), this.language = new k(this);
|
|
56
119
|
}
|
|
57
|
-
|
|
58
|
-
t.config && (t.config.reset(),
|
|
120
|
+
applyConfig(t, e) {
|
|
121
|
+
t.config && (t.config.reset(), e && t.config.update(e));
|
|
59
122
|
}
|
|
60
|
-
|
|
123
|
+
exec(t) {
|
|
61
124
|
this.done = !1;
|
|
62
125
|
try {
|
|
63
126
|
if (!t.check(this.context))
|
|
64
127
|
return;
|
|
65
|
-
} catch (
|
|
66
|
-
console.warn(`plugin check failed id=${t.id} err=${
|
|
128
|
+
} catch (e) {
|
|
129
|
+
console.warn(`plugin check failed id=${t.id} err=${e?.message}`);
|
|
67
130
|
return;
|
|
68
131
|
}
|
|
69
132
|
try {
|
|
70
133
|
t.exec(this.context);
|
|
71
|
-
} catch (
|
|
72
|
-
console.warn(`plugin call failed id=${t.id} err=${
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.warn(`plugin call failed id=${t.id} err=${e?.message}`);
|
|
73
136
|
}
|
|
74
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Apply optional config to a plugin and execute it against the current context.
|
|
140
|
+
* Intended for use by the pipeline plugin scopes.
|
|
141
|
+
*/
|
|
142
|
+
run(t, e) {
|
|
143
|
+
return this.applyConfig(t, e), this.exec(t), this;
|
|
144
|
+
}
|
|
75
145
|
infer() {
|
|
76
146
|
if (this.format)
|
|
77
147
|
return this;
|
|
@@ -89,58 +159,34 @@ class d {
|
|
|
89
159
|
parse() {
|
|
90
160
|
if (!this.format)
|
|
91
161
|
throw new Error("no format detected. call .infer() before .parse()");
|
|
92
|
-
const t = a.find((
|
|
162
|
+
const t = a.find((e) => e.format === this.format);
|
|
93
163
|
if (!t)
|
|
94
164
|
throw new Error(`parser plugin not found: "${this.format}"`);
|
|
95
165
|
this.done = !1;
|
|
96
166
|
try {
|
|
97
167
|
t.exec(this.context);
|
|
98
|
-
} catch (
|
|
99
|
-
console.warn(`plugin call failed id=${t.id} err=${
|
|
168
|
+
} catch (e) {
|
|
169
|
+
console.warn(`plugin call failed id=${t.id} err=${e?.message}`);
|
|
100
170
|
}
|
|
101
171
|
return this;
|
|
102
172
|
}
|
|
103
|
-
backgroundExtract(t) {
|
|
104
|
-
return this.handleApplyConfig(e.background.extract, t), this.handleExecPlugin(e.background.extract), this;
|
|
105
|
-
}
|
|
106
|
-
backgroundClean() {
|
|
107
|
-
return this.handleExecPlugin(e.background.clean), this;
|
|
108
|
-
}
|
|
109
|
-
agentExtract(t) {
|
|
110
|
-
return this.handleApplyConfig(e.agent.extract, t), this.handleExecPlugin(e.agent.extract), this;
|
|
111
|
-
}
|
|
112
|
-
pureExtract(t) {
|
|
113
|
-
return this.handleApplyConfig(e.pure.extract, t), this.handleExecPlugin(e.pure.extract), this;
|
|
114
|
-
}
|
|
115
|
-
pureClean(t) {
|
|
116
|
-
return this.handleApplyConfig(e.pure.clean, t), this.handleExecPlugin(e.pure.clean), this;
|
|
117
|
-
}
|
|
118
|
-
interludeInsert(t) {
|
|
119
|
-
return this.handleApplyConfig(e.interlude.insert, t), this.handleExecPlugin(e.interlude.insert), this;
|
|
120
|
-
}
|
|
121
|
-
spaceInsert(t) {
|
|
122
|
-
return this.handleApplyConfig(e.space.insert, t), this.handleExecPlugin(e.space.insert), this;
|
|
123
|
-
}
|
|
124
|
-
stressMark(t) {
|
|
125
|
-
return this.handleApplyConfig(e.stress.mark, t), this.handleExecPlugin(e.stress.mark), this;
|
|
126
|
-
}
|
|
127
173
|
final() {
|
|
128
|
-
return this.done || (this.context.cleanWord(), this.context.
|
|
174
|
+
return this.done || (this.context.cleanWord(), this.context.syncLineTimeWithWord(), this.context.sort(), this.context.calcAgentIndex(), this.context.syncLineTimeWithBackground(), this.done = !0), {
|
|
129
175
|
format: this.format,
|
|
130
176
|
result: this.context.result
|
|
131
177
|
};
|
|
132
178
|
}
|
|
133
179
|
}
|
|
134
|
-
const
|
|
180
|
+
const S = (r) => new y(r);
|
|
135
181
|
export {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
182
|
+
I as Format,
|
|
183
|
+
E as Generator,
|
|
184
|
+
j as GeneratorContext,
|
|
185
|
+
A as Lyric,
|
|
186
|
+
F as Parser,
|
|
187
|
+
O as ParserContext,
|
|
188
|
+
y as ParserPipeline,
|
|
189
|
+
b as Transform,
|
|
190
|
+
S as createParserPipeline
|
|
145
191
|
};
|
|
146
192
|
//# sourceMappingURL=index.ecma.js.map
|
package/dist/index.ecma.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.ecma.js","sources":["../src/parser/pipeline.ts"],"sourcesContent":["import type { ParserParams } from '@music-lyric-kit/core'\n\nimport { Lyric } from '@music-lyric-kit/lyric'\nimport { ParserContext, ParserPlugin } from '@music-lyric-kit/core'\n\nimport { Format, Transform } 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: Lyric.Info\n}\n\nconst BuiltInFormats = [new Format.Lrc.Parser(), new Format.Ttml.AmllParser()]\n\nconst BuiltInPlugins = {\n agent: {\n extract: new Transform.Agent.Extract(),\n },\n background: {\n extract: new Transform.Background.Extract(),\n clean: new Transform.Background.Clean(),\n },\n pure: {\n extract: new Transform.Pure.ExtractCreator(),\n clean: new Transform.Pure.Clean(),\n },\n space: {\n insert: new Transform.Space.Insert(),\n },\n interlude: {\n insert: new Transform.Interlude.Insert(),\n },\n stress: {\n mark: new Transform.Stress.Mark(),\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 Lyric.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 break\n }\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?: Transform.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?: Transform.Agent.ExtractConfig): this {\n this.handleApplyConfig(BuiltInPlugins.agent.extract, options)\n this.handleExecPlugin(BuiltInPlugins.agent.extract)\n return this\n }\n\n pureExtract(options?: Transform.Pure.ExtractCreatorConfig): this {\n this.handleApplyConfig(BuiltInPlugins.pure.extract, options)\n this.handleExecPlugin(BuiltInPlugins.pure.extract)\n return this\n }\n\n pureClean(options?: Transform.Pure.CleanConfig): this {\n this.handleApplyConfig(BuiltInPlugins.pure.clean, options)\n this.handleExecPlugin(BuiltInPlugins.pure.clean)\n return this\n }\n\n interludeInsert(options?: Transform.Interlude.InsertConfig): this {\n this.handleApplyConfig(BuiltInPlugins.interlude.insert, options)\n this.handleExecPlugin(BuiltInPlugins.interlude.insert)\n return this\n }\n\n spaceInsert(options?: Transform.Space.SpaceConfig): this {\n this.handleApplyConfig(BuiltInPlugins.space.insert, options)\n this.handleExecPlugin(BuiltInPlugins.space.insert)\n return this\n }\n\n stressMark(options?: Transform.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","Format.Lrc","Format.Ttml","BuiltInPlugins","Transform.Agent","Transform.Background","Transform.Pure","Transform.Space","Transform.Interlude","Transform.Stress","ParserPipeline","input","init","Lyric","ParserContext","plugin","options","e","parser","item","createParserPipeline"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;8CAkBMA,IAAiB,CAAC,IAAIC,EAAW,OAAA,GAAU,IAAIC,EAAY,YAAY,GAEvEC,IAAiB;AAAA,EACrB,OAAO;AAAA,IACL,SAAS,IAAIC,EAAgB,QAAA;AAAA,EAAQ;AAAA,EAEvC,YAAY;AAAA,IACV,SAAS,IAAIC,EAAqB,QAAA;AAAA,IAClC,OAAO,IAAIA,EAAqB,MAAA;AAAA,EAAM;AAAA,EAExC,MA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Bb,EAAe,UAAU,MAAM,GAC9C;AAAA,EACT;AAAA,EAEA,YAAYa,GAA6C;AACvD,gBAAK,kBAAkBb,EAAe,MAAM,QAAQa,CAAO,GAC3D,KAAK,iBAAiBb,EAAe,MAAM,MAAM,GAC1C;AAAA,EACT;AAAA,EAEA,WAAWa,GAA6C;AACtD,gBAAK,kBAAkBb,EAAe,OAAO,MAAMa,CAAO,GAC1D,KAAK,iBAAiBb,EAAe,OAAO,IAAI,GACzC;AAAA,EACT;AAAA,EAEA,QAA8B;AAC5B,WAAK,KAAK,SACR,KAAK,QAAQ,UAAA,GACb,KAAK,QAAQ,eAAA,GACb,KAAK,QAAQ,qBAAA,GACb,KAAK,QAAQ,KAAA,GACb,KAAK,QAAQ,2BAAA,GACb,KAAK,OAAO,KAGP;AAAA,MACL,QAAQ,KAAK;AAAA,MACb,QAAQ,KAAK,QAAQ;AAAA,IAAA;AAAA,EAEzB;AACF;AAEO,MAAMiB,IAAuB,CAACT,MAC5B,IAAID,EAAeC,CAAK;"}
|
|
1
|
+
{"version":3,"file":"index.ecma.js","sources":["../src/parser/pipeline.ts"],"sourcesContent":["import type { ParserParams } from '@music-lyric-kit/core'\n\nimport { Lyric } from '@music-lyric-kit/lyric'\nimport { ParserContext, ParserPlugin } from '@music-lyric-kit/core'\n\nimport { Format, Transform } 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: Lyric.Info\n}\n\nconst BuiltInFormats = [new Format.Lrc.Parser(), new Format.Ttml.AmllParser(), new Format.Ttml.ItunesParser()]\n\nclass Agent {\n private _extract = new Transform.Agent.Extract()\n\n constructor(private client: ParserPipeline) {}\n\n extract(options?: Transform.Agent.ExtractConfig) {\n return this.client.run(this._extract, options)\n }\n}\n\nclass Background {\n private _extract = new Transform.Background.Extract()\n private _clean = new Transform.Background.Clean()\n\n constructor(private client: ParserPipeline) {}\n\n extract(options?: Transform.Background.ExtractConfig) {\n return this.client.run(this._extract, options)\n }\n\n clean() {\n return this.client.run(this._clean)\n }\n}\n\nclass Pure {\n private _extractCreator = new Transform.Pure.ExtractCreator()\n private _clean = new Transform.Pure.Clean()\n\n constructor(private client: ParserPipeline) {}\n\n extractCreator(options?: Transform.Pure.ExtractCreatorConfig) {\n return this.client.run(this._extractCreator, options)\n }\n\n clean(options?: Transform.Pure.CleanConfig) {\n return this.client.run(this._clean, options)\n }\n}\n\nclass Interlude {\n private _insert = new Transform.Interlude.Insert()\n\n constructor(private client: ParserPipeline) {}\n\n insert(options?: Transform.Interlude.InsertConfig) {\n return this.client.run(this._insert, options)\n }\n}\n\nclass Space {\n private _insert = new Transform.Space.Insert()\n\n constructor(private client: ParserPipeline) {}\n\n insert(options?: Transform.Space.SpaceConfig) {\n return this.client.run(this._insert, options)\n }\n}\n\nclass Stress {\n private _mark = new Transform.Stress.Mark()\n\n constructor(private client: ParserPipeline) {}\n\n mark(options?: Transform.Stress.MarkConfig) {\n return this.client.run(this._mark, options)\n }\n}\n\nclass Language {\n private _infer = new Transform.Language.Infer()\n private _calculatePercent = new Transform.Language.CalculatePercent()\n\n constructor(private client: ParserPipeline) {}\n\n infer(options?: Transform.Language.InferConfig) {\n return this.client.run(this._infer, options)\n }\n\n calculatePercent(options?: Transform.Language.CalculateConfig) {\n return this.client.run(this._calculatePercent, options)\n }\n}\n\nexport class ParserPipeline {\n private context: ParserContext\n private format: string\n private input: ParserPipelineInput\n private done: boolean\n\n readonly agent: Agent\n readonly background: Background\n readonly pure: Pure\n readonly interlude: Interlude\n readonly space: Space\n readonly stress: Stress\n readonly language: Language\n\n constructor(input: ParserPipelineInput) {\n this.done = false\n this.input = input\n this.format = this.input.format || ''\n\n const init = new Lyric.Info()\n this.context = new ParserContext({ content: this.input.content, musicInfo: this.input.musicInfo }, init)\n\n this.agent = new Agent(this)\n this.background = new Background(this)\n this.pure = new Pure(this)\n this.interlude = new Interlude(this)\n this.space = new Space(this)\n this.stress = new Stress(this)\n this.language = new Language(this)\n }\n\n private applyConfig(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 exec(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 /**\n * Apply optional config to a plugin and execute it against the current context.\n * Intended for use by the pipeline plugin scopes.\n */\n run(plugin: ParserPlugin, options?: any): this {\n this.applyConfig(plugin, options)\n this.exec(plugin)\n return this\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 break\n }\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 final(): ParserPipelineResult {\n if (!this.done) {\n this.context.cleanWord()\n this.context.syncLineTimeWithWord()\n this.context.sort()\n this.context.calcAgentIndex()\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","Format.Lrc","Format.Ttml","Agent","client","Transform.Agent","options","Background","Transform.Background","Pure","Transform.Pure","Interlude","Transform.Interlude","Space","Transform.Space","Stress","Transform.Stress","Language","Transform.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K,CAAC0B,MAASA,EAAK,WAAW,KAAK,MAAM;AACxE,QAAI,CAACD;AACH,YAAM,IAAI,MAAM,6BAA6B,KAAK,MAAM,GAAG;AAG7D,SAAK,OAAO;AAEZ,QAAI;AACF,MAAAA,EAAO,KAAK,KAAK,OAAO;AAAA,IAC1B,SAAS,GAAQ;AACf,cAAQ,KAAK,yBAAyBA,EAAO,EAAE,QAAQ,GAAG,OAAO,EAAE;AAAA,IACrE;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,QAA8B;AAC5B,WAAK,KAAK,SACR,KAAK,QAAQ,UAAA,GACb,KAAK,QAAQ,qBAAA,GACb,KAAK,QAAQ,KAAA,GACb,KAAK,QAAQ,eAAA,GACb,KAAK,QAAQ,2BAAA,GACb,KAAK,OAAO,KAGP;AAAA,MACL,QAAQ,KAAK;AAAA,MACb,QAAQ,KAAK,QAAQ;AAAA,IAAA;AAAA,EAEzB;AACF;AAEO,MAAME,IAAuB,CAACP,MAC5B,IAAID,EAAeC,CAAK;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "music-lyric-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"author": "folltoshe",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Music Lyric Kit",
|
|
@@ -34,17 +34,18 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@music-lyric-kit/core": "0.
|
|
38
|
-
"@music-lyric-kit/lyric": "0.
|
|
39
|
-
"@music-lyric-kit/
|
|
40
|
-
"@music-lyric-kit/plugin-format-
|
|
41
|
-
"@music-lyric-kit/
|
|
42
|
-
"@music-lyric-kit/plugin-transform-interlude": "0.
|
|
43
|
-
"@music-lyric-kit/plugin-transform-
|
|
44
|
-
"@music-lyric-kit/plugin-transform-
|
|
45
|
-
"@music-lyric-kit/plugin-transform-
|
|
46
|
-
"@music-lyric-kit/plugin-transform-
|
|
47
|
-
"@music-lyric-kit/plugin-transform-
|
|
37
|
+
"@music-lyric-kit/core": "0.13.0",
|
|
38
|
+
"@music-lyric-kit/lyric": "0.13.0",
|
|
39
|
+
"@music-lyric-kit/utils": "0.13.0",
|
|
40
|
+
"@music-lyric-kit/plugin-format-lrc": "0.13.0",
|
|
41
|
+
"@music-lyric-kit/plugin-format-ttml": "0.13.0",
|
|
42
|
+
"@music-lyric-kit/plugin-transform-interlude": "0.13.0",
|
|
43
|
+
"@music-lyric-kit/plugin-transform-background": "0.13.0",
|
|
44
|
+
"@music-lyric-kit/plugin-transform-space": "0.13.0",
|
|
45
|
+
"@music-lyric-kit/plugin-transform-pure": "0.13.0",
|
|
46
|
+
"@music-lyric-kit/plugin-transform-agent": "0.13.0",
|
|
47
|
+
"@music-lyric-kit/plugin-transform-stress": "0.13.0",
|
|
48
|
+
"@music-lyric-kit/plugin-transform-language": "0.13.0"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
51
|
"build": "vite build"
|