music-lyric-kit 0.12.1 → 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 +13 -1
- package/dist/index.ecma.js +75 -59
- 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\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\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\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 }\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","ParserPipeline","input","init","Lyric","ParserContext","plugin","e","parser","item","createParserPipeline"],"mappings":"
|
|
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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eAAA,EACb,KAAK,QAAQ,2BAAA,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,6 +6,7 @@ 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';
|
|
@@ -62,6 +63,15 @@ declare class Interlude_2 {
|
|
|
62
63
|
insert(options?: Transform.Interlude.InsertConfig): ParserPipeline;
|
|
63
64
|
}
|
|
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
|
+
|
|
65
75
|
export { Lyric }
|
|
66
76
|
|
|
67
77
|
export { Parser }
|
|
@@ -83,6 +93,7 @@ export declare class ParserPipeline {
|
|
|
83
93
|
readonly interlude: Interlude_2;
|
|
84
94
|
readonly space: Space_2;
|
|
85
95
|
readonly stress: Stress_2;
|
|
96
|
+
readonly language: Language_2;
|
|
86
97
|
constructor(input: ParserPipelineInput);
|
|
87
98
|
private applyConfig;
|
|
88
99
|
private exec;
|
|
@@ -139,7 +150,8 @@ declare namespace Transform {
|
|
|
139
150
|
Agent,
|
|
140
151
|
Space,
|
|
141
152
|
Pure,
|
|
142
|
-
Stress
|
|
153
|
+
Stress,
|
|
154
|
+
Language
|
|
143
155
|
}
|
|
144
156
|
}
|
|
145
157
|
export { Transform }
|
package/dist/index.ecma.js
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
|
-
import { Lyric as
|
|
2
|
-
import { Lyric as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
9
|
-
import * as
|
|
10
|
-
import * as
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
|
|
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
|
+
import * as l from "@music-lyric-kit/plugin-transform-interlude";
|
|
6
|
+
import * as s 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 * 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
|
-
Agent:
|
|
20
|
-
Background:
|
|
21
|
-
Interlude:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
Agent: u,
|
|
21
|
+
Background: s,
|
|
22
|
+
Interlude: l,
|
|
23
|
+
Language: o,
|
|
24
|
+
Pure: i,
|
|
25
|
+
Space: h,
|
|
26
|
+
Stress: f
|
|
27
|
+
}, Symbol.toStringTag, { value: "Module" })), a = [new c.Parser(), new n.AmllParser(), new n.ItunesParser()];
|
|
28
|
+
class g {
|
|
27
29
|
constructor(t) {
|
|
28
30
|
this.client = t;
|
|
29
31
|
}
|
|
30
|
-
_extract = new
|
|
32
|
+
_extract = new u.Extract();
|
|
31
33
|
extract(t) {
|
|
32
34
|
return this.client.run(this._extract, t);
|
|
33
35
|
}
|
|
@@ -36,8 +38,8 @@ class d {
|
|
|
36
38
|
constructor(t) {
|
|
37
39
|
this.client = t;
|
|
38
40
|
}
|
|
39
|
-
_extract = new
|
|
40
|
-
_clean = new
|
|
41
|
+
_extract = new s.Extract();
|
|
42
|
+
_clean = new s.Clean();
|
|
41
43
|
extract(t) {
|
|
42
44
|
return this.client.run(this._extract, t);
|
|
43
45
|
}
|
|
@@ -49,8 +51,8 @@ class x {
|
|
|
49
51
|
constructor(t) {
|
|
50
52
|
this.client = t;
|
|
51
53
|
}
|
|
52
|
-
_extractCreator = new
|
|
53
|
-
_clean = new
|
|
54
|
+
_extractCreator = new i.ExtractCreator();
|
|
55
|
+
_clean = new i.Clean();
|
|
54
56
|
extractCreator(t) {
|
|
55
57
|
return this.client.run(this._extractCreator, t);
|
|
56
58
|
}
|
|
@@ -58,34 +60,47 @@ class x {
|
|
|
58
60
|
return this.client.run(this._clean, t);
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
|
-
class
|
|
63
|
+
class w {
|
|
62
64
|
constructor(t) {
|
|
63
65
|
this.client = t;
|
|
64
66
|
}
|
|
65
|
-
_insert = new
|
|
67
|
+
_insert = new l.Insert();
|
|
66
68
|
insert(t) {
|
|
67
69
|
return this.client.run(this._insert, t);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
|
-
class
|
|
72
|
+
class _ {
|
|
71
73
|
constructor(t) {
|
|
72
74
|
this.client = t;
|
|
73
75
|
}
|
|
74
|
-
_insert = new
|
|
76
|
+
_insert = new h.Insert();
|
|
75
77
|
insert(t) {
|
|
76
78
|
return this.client.run(this._insert, t);
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
class
|
|
81
|
+
class P {
|
|
80
82
|
constructor(t) {
|
|
81
83
|
this.client = t;
|
|
82
84
|
}
|
|
83
|
-
_mark = new
|
|
85
|
+
_mark = new f.Mark();
|
|
84
86
|
mark(t) {
|
|
85
87
|
return this.client.run(this._mark, t);
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
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 {
|
|
89
104
|
context;
|
|
90
105
|
format;
|
|
91
106
|
input;
|
|
@@ -96,40 +111,41 @@ class k {
|
|
|
96
111
|
interlude;
|
|
97
112
|
space;
|
|
98
113
|
stress;
|
|
114
|
+
language;
|
|
99
115
|
constructor(t) {
|
|
100
116
|
this.done = !1, this.input = t, this.format = this.input.format || "";
|
|
101
|
-
const
|
|
102
|
-
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);
|
|
103
119
|
}
|
|
104
|
-
applyConfig(t,
|
|
105
|
-
t.config && (t.config.reset(),
|
|
120
|
+
applyConfig(t, e) {
|
|
121
|
+
t.config && (t.config.reset(), e && t.config.update(e));
|
|
106
122
|
}
|
|
107
123
|
exec(t) {
|
|
108
124
|
this.done = !1;
|
|
109
125
|
try {
|
|
110
126
|
if (!t.check(this.context))
|
|
111
127
|
return;
|
|
112
|
-
} catch (
|
|
113
|
-
console.warn(`plugin check failed id=${t.id} err=${
|
|
128
|
+
} catch (e) {
|
|
129
|
+
console.warn(`plugin check failed id=${t.id} err=${e?.message}`);
|
|
114
130
|
return;
|
|
115
131
|
}
|
|
116
132
|
try {
|
|
117
133
|
t.exec(this.context);
|
|
118
|
-
} catch (
|
|
119
|
-
console.warn(`plugin call failed id=${t.id} err=${
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.warn(`plugin call failed id=${t.id} err=${e?.message}`);
|
|
120
136
|
}
|
|
121
137
|
}
|
|
122
138
|
/**
|
|
123
139
|
* Apply optional config to a plugin and execute it against the current context.
|
|
124
140
|
* Intended for use by the pipeline plugin scopes.
|
|
125
141
|
*/
|
|
126
|
-
run(t,
|
|
127
|
-
return this.applyConfig(t,
|
|
142
|
+
run(t, e) {
|
|
143
|
+
return this.applyConfig(t, e), this.exec(t), this;
|
|
128
144
|
}
|
|
129
145
|
infer() {
|
|
130
146
|
if (this.format)
|
|
131
147
|
return this;
|
|
132
|
-
for (const t of
|
|
148
|
+
for (const t of a)
|
|
133
149
|
try {
|
|
134
150
|
if (t.check(this.context)) {
|
|
135
151
|
this.format = t.format;
|
|
@@ -143,14 +159,14 @@ class k {
|
|
|
143
159
|
parse() {
|
|
144
160
|
if (!this.format)
|
|
145
161
|
throw new Error("no format detected. call .infer() before .parse()");
|
|
146
|
-
const t =
|
|
162
|
+
const t = a.find((e) => e.format === this.format);
|
|
147
163
|
if (!t)
|
|
148
164
|
throw new Error(`parser plugin not found: "${this.format}"`);
|
|
149
165
|
this.done = !1;
|
|
150
166
|
try {
|
|
151
167
|
t.exec(this.context);
|
|
152
|
-
} catch (
|
|
153
|
-
console.warn(`plugin call failed id=${t.id} err=${
|
|
168
|
+
} catch (e) {
|
|
169
|
+
console.warn(`plugin call failed id=${t.id} err=${e?.message}`);
|
|
154
170
|
}
|
|
155
171
|
return this;
|
|
156
172
|
}
|
|
@@ -161,16 +177,16 @@ class k {
|
|
|
161
177
|
};
|
|
162
178
|
}
|
|
163
179
|
}
|
|
164
|
-
const
|
|
180
|
+
const S = (r) => new y(r);
|
|
165
181
|
export {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
|
175
191
|
};
|
|
176
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\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\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\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 }\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","ParserPipeline","input","init","Lyric","ParserContext","plugin","e","parser","item","createParserPipe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,KAAK,OAAO,KAGP;AAAA,MACL,QAAQ,KAAK;AAAA,MACb,QAAQ,KAAK,QAAQ;AAAA,IAAA;AAAA,EAEzB;AACF;AAEO,MAAMG,IAAuB,CAACR,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.Language","ParserPipeline","input","init","Lyric","ParserContext","plugin","parser","item","createParserPipeline"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;8CAkBMA,IAAiB,CAAC,IAAIC,EAAW,UAAU,IAAIC,EAAY,cAAc,IAAIA,EAAY,cAAc;AAE7G,MAAMC,EAAM;AAAA,EAGV,YAAoBC,GAAwB;AAAxB,SAAA,SAAAA;AAAA,EAAyB;AAAA,EAFrC,WAAW,IAAIC,EAAgB,QAAA;AAAA,EAIvC,QAAQC,GAAyC;AAC/C,WAAO,KAAK,OAAO,IAAI,KAAK,UAAUA,CAAO;AAAA,EAC/C;AACF;AAEA,MAAMC,EAAW;AAAA,EAIf,YAAoBH,GAAwB;AAAxB,SAAA,SAAAA;AAAA,EAAyB;AAA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AK,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/utils": "0.
|
|
40
|
-
"@music-lyric-kit/plugin-format-
|
|
41
|
-
"@music-lyric-kit/plugin-format-
|
|
42
|
-
"@music-lyric-kit/plugin-transform-interlude": "0.
|
|
43
|
-
"@music-lyric-kit/plugin-transform-background": "0.
|
|
44
|
-
"@music-lyric-kit/plugin-transform-space": "0.
|
|
45
|
-
"@music-lyric-kit/plugin-transform-
|
|
46
|
-
"@music-lyric-kit/plugin-transform-
|
|
47
|
-
"@music-lyric-kit/plugin-transform-stress": "0.
|
|
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"
|