@music-lyric-player/base 0.1.0 → 0.3.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 +44 -1
- package/dist/index.ecma.js +90 -32
- package/dist/index.ecma.js.map +1 -1
- package/package.json +2 -2
package/dist/index.comm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("lodash-es");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("lodash-es");const r=require("@music-lyric-player/utils"),d={},u="0.5.1";class l{get version(){return u}type="Incorrect";metas=[];lines=[];agents=[];toJSON(){return{version:this.version,type:this.type,metas:this.metas,lines:this.lines,agents:this.agents}}}class o{config=new r.ConfigManager(d);event=new r.Event;state;active;time;info;constructor(){this.state={playing:!1,frameId:null,scanIndex:0},this.active={lines:[],index:[]},this.time={start:0,seek:0},this.info=new l}handleGetCurrentTime(){return this.state.playing?this.time.seek+(performance.now()-this.time.start):this.time.seek}handleGetLineTime(e){if(e<0||e>=this.info.lines.length)return 0;if(e===this.info.lines.length-1)return 1/0;const n=this.info.lines[e],s=this.info.lines[e+1];return Math.max(n.time.end,s.time.start)}handleGetActiveIndex(){return this.active.index.length>0?this.active.index[0]:-1}handleSyncTime(e){const n=[],s=[];let i=this.info.lines.length;for(let t=0;t<this.info.lines.length;t++){const a=this.info.lines[t];if(a.time.start>e){i=t;break}this.handleGetLineTime(t)>e&&(n.push(a),s.push(t))}this.state.scanIndex=i,this.active.lines=n,this.active.index=s,this.event.emit("linesUpdate",[...this.active.lines],[...this.active.index],this.handleGetActiveIndex())}handleUpdateActiveLines(e){let n=!1;const s=[],i=[];for(let t=0;t<this.active.lines.length;t++){const a=this.active.lines[t],h=this.active.index[t];e>=this.handleGetLineTime(h)?n=!0:(s.push(a),i.push(h))}for(;this.state.scanIndex<this.info.lines.length;){const t=this.info.lines[this.state.scanIndex];if(e>=t.time.start)e<this.handleGetLineTime(this.state.scanIndex)&&(s.push(t),i.push(this.state.scanIndex),n=!0),this.state.scanIndex++;else break}n&&(this.active.lines=s,this.active.index=i,this.event.emit("linesUpdate",[...this.active.lines],[...this.active.index],this.handleGetActiveIndex()))}onTick=()=>{if(!this.state.playing)return;const e=this.handleGetCurrentTime();this.handleUpdateActiveLines(e),this.state.frameId=requestAnimationFrame(this.onTick)};updateLyric(e){e&&(this.pause(),this.info=e,this.active.lines=[],this.active.index=[],this.state.scanIndex=0,this.time.seek=0,this.event.emit("lyricUpdate",e),this.event.emit("linesUpdate",[],[],-1))}play(e){this.pause(),typeof e=="number"&&!Number.isNaN(e)&&(this.time.seek=e,this.handleSyncTime(e)),this.time.start=performance.now(),this.state.playing=!0,this.onTick(),this.event.emit("play",this.handleGetCurrentTime())}pause(){this.state.playing&&(this.time.seek=this.handleGetCurrentTime(),this.state.playing=!1),this.state.frameId!==null&&(cancelAnimationFrame(this.state.frameId),this.state.frameId=null),this.event.emit("pause",this.handleGetCurrentTime())}dispose(){this.pause(),this.event.clear(),this.active.lines=[],this.active.index=[],this.info=new l}matchLinesWithTime(e){const n=[],s=[];for(let i=0;i<this.info.lines.length;i++){const t=this.info.lines[i];if(t.time.start>e)break;this.handleGetLineTime(i)>e&&(n.push(t),s.push(i))}return{lines:n,index:s}}get currentPlaying(){return this.state.playing}get currentLines(){return[...this.active.lines]}get currentIndex(){return[...this.active.index]}get currentActive(){return this.handleGetActiveIndex()}get currentInfo(){return this.info}get currentTime(){return this.handleGetCurrentTime()}}exports.BaseLyricPlayer=o;
|
|
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/options.ts","../../../node_modules/.pnpm/@music-lyric-kit+lyric@0.4.0/node_modules/@music-lyric-kit/lyric/dist/index.ecma.js","../src/index.ts"],"sourcesContent":["export interface Options {}\n\nexport const DEFAULT_OPTIONS: Options = {}\n","import { createRandomHex as r } from \"@music-lyric-kit/utils\";\nclass s {\n start = 0;\n end = 0;\n get duration() {\n return this.end - this.start;\n }\n toJSON() {\n return {\n start: this.start,\n end: this.end,\n duration: this.duration\n };\n }\n}\nvar o = /* @__PURE__ */ ((t) => (t.Normal = \"Normal\", t.Space = \"Space\", t))(o || {});\nclass i {\n stress = !1;\n toJSON() {\n return {\n stress: this.stress\n };\n }\n}\nclass p {\n get type() {\n return \"Normal\";\n }\n time = new s();\n content = \"\";\n extended = [];\n config = new i();\n toJSON() {\n return {\n type: this.type,\n time: this.time,\n content: this.content,\n extended: this.extended,\n config: this.config\n };\n }\n}\nclass N {\n get type() {\n return \"Space\";\n }\n count = 1;\n toJSON() {\n return {\n type: this.type,\n count: this.count\n };\n }\n}\nvar a = /* @__PURE__ */ ((t) => (t.UnKnown = \"UnKnown\", t.Translate = \"Translate\", t.Roman = \"Roman\", t))(a || {});\nclass S {\n type = \"UnKnown\";\n content = \"\";\n toJSON() {\n return {\n type: this.type,\n content: this.content\n };\n }\n}\nvar l = /* @__PURE__ */ ((t) => (t.Normal = \"Normal\", t.Interlude = \"Interlude\", t))(l || {});\nclass x {\n get type() {\n return \"Interlude\";\n }\n id = r(4).toUpperCase();\n time = new s();\n toJSON() {\n return {\n id: this.id,\n type: this.type,\n time: this.time\n };\n }\n}\nclass c {\n words = [];\n extended = [];\n get original() {\n return this.words.map((n) => n.type === o.Normal ? n.content : new Array(n.count).fill(\" \").join(\"\")).join(\"\");\n }\n toJSON() {\n return {\n words: this.words,\n extended: this.extended,\n original: this.original\n };\n }\n}\nclass y {\n get type() {\n return \"Normal\";\n }\n id = r(4).toUpperCase();\n time = new s();\n content = new c();\n agent;\n background;\n toJSON() {\n return {\n id: this.id,\n type: this.type,\n time: this.time,\n content: this.content,\n agent: this.agent,\n background: this.background\n };\n }\n}\nvar u = /* @__PURE__ */ ((t) => (t.Offset = \"Offset\", t.Duration = \"Duration\", t.Title = \"Title\", t.Singer = \"Singer\", t.Album = \"Album\", t.Creator = \"Creator\", t.UnKnown = \"UnKnown\", t))(u || {});\nclass e {\n id = r(4).toUpperCase();\n toJSON() {\n return {\n id: this.id,\n type: this.type,\n content: this.content\n };\n }\n}\nclass f extends e {\n get type() {\n return \"Offset\";\n }\n content = 0;\n}\nclass w extends e {\n get type() {\n return \"Duration\";\n }\n content = 0;\n}\nclass O extends e {\n get type() {\n return \"Title\";\n }\n content = \"\";\n}\nclass b extends e {\n get type() {\n return \"Singer\";\n }\n content = \"\";\n}\nclass J extends e {\n get type() {\n return \"Album\";\n }\n content = \"\";\n}\nclass U extends e {\n get type() {\n return \"Creator\";\n }\n content = {\n role: \"\",\n name: []\n };\n}\nclass C extends e {\n get type() {\n return \"UnKnown\";\n }\n content = \"\";\n}\nclass I {\n id = \"\";\n name = \"\";\n count = 0;\n}\nclass d {\n // index in global\n global = 0;\n // index in block\n block = 0;\n toJSON() {\n return {\n global: this.global,\n block: this.block\n };\n }\n}\nclass v {\n id = \"\";\n index = new d();\n toJSON() {\n return {\n id: this.id,\n index: this.index\n };\n }\n}\nconst m = \"0.5.1\";\nvar g = /* @__PURE__ */ ((t) => (t.Incorrect = \"Incorrect\", t.Normal = \"Normal\", t.Syllable = \"Syllable\", t.Pure = \"Pure\", t.Empty = \"Empty\", t.NoTime = \"NoTime\", t))(g || {});\nclass A {\n get version() {\n return m;\n }\n type = \"Incorrect\";\n metas = [];\n lines = [];\n agents = [];\n toJSON() {\n return {\n version: this.version,\n type: this.type,\n metas: this.metas,\n lines: this.lines,\n agents: this.agents\n };\n }\n}\nexport {\n I as Agent,\n v as AgentLine,\n d as AgentLineIndex,\n S as Extended,\n a as ExtendedType,\n A as Info,\n x as LineInterlude,\n y as LineNormal,\n c as LineNormalContent,\n l as LineType,\n J as MetaAlbum,\n U as MetaCreator,\n w as MetaDuration,\n f as MetaOffset,\n b as MetaSinger,\n O as MetaTitle,\n u as MetaType,\n C as MetaUnKnown,\n s as Time,\n g as Type,\n m as Version,\n p as WordNormal,\n N as WordSpace,\n o as WordType\n};\n//# sourceMappingURL=index.ecma.js.map\n","import type { Line } from '@music-lyric-kit/lyric'\nimport type { DeepPartial } from '@music-lyric-player/utils'\nimport type { Options } from './options'\n\nimport { DEFAULT_OPTIONS } from './options'\n\nimport { Info } from '@music-lyric-kit/lyric'\nimport { ConfigManager, Event } from '@music-lyric-player/utils'\n\nexport interface BaseLyricPlayerEventMap {\n /**\n * When the player starts or resumes playback.\n * @param currentTime The current playback time.\n */\n play: (currentTime: number) => void\n\n /**\n * When the player pauses playback.\n * @param currentTime The current playback time.\n */\n pause: (currentTime: number) => void\n\n /**\n * When the entire lyric information is updated (e.g., loading a new lyric/song).\n * @param info The newly loaded lyric information object.\n */\n lyricUpdate: (info: Info) => void\n\n /**\n * When the currently active lyric lines change during playback.\n * @param lines An array of the currently active lyric lines.\n */\n linesUpdate: (lines: Line[]) => void\n}\n\nexport class BaseLyricPlayer {\n readonly config = new ConfigManager<Options, DeepPartial<Options>>(DEFAULT_OPTIONS)\n\n readonly event: Event<BaseLyricPlayerEventMap> = new Event()\n\n private state: {\n playing: boolean\n frameId: number | null\n index: number\n lines: Line[]\n }\n private time: {\n start: number\n seek: number\n }\n private info: Info\n\n constructor() {\n this.state = {\n playing: false,\n frameId: null,\n index: 0,\n lines: [],\n }\n this.time = {\n start: 0,\n seek: 0,\n }\n this.info = new Info()\n }\n\n private handleGetCurrentTime() {\n if (!this.state.playing) {\n return this.time.seek\n }\n return this.time.seek + (performance.now() - this.time.start)\n }\n\n private handleGetLineTime(index: number): number {\n if (index < 0 || index >= this.info.lines.length) {\n return 0\n }\n\n if (index === this.info.lines.length - 1) {\n return Infinity\n }\n\n const line = this.info.lines[index]\n const nextLine = this.info.lines[index + 1]\n return Math.max(line.time.end, nextLine.time.start)\n }\n\n private handleSyncTime(time: number) {\n const result: Line[] = []\n\n let firstIndex = this.info.lines.length\n for (let i = 0; i < this.info.lines.length; i++) {\n const line = this.info.lines[i]\n if (line.time.start > time) {\n firstIndex = i\n break\n }\n\n if (this.handleGetLineTime(i) > time) {\n result.push(line)\n }\n }\n\n this.state.lines = result\n this.state.index = firstIndex\n\n this.event.emit('linesUpdate', [...this.state.lines])\n }\n\n private handleUpdateActiveLines(now: number) {\n let hasChanged = false\n\n const activeLines = this.state.lines.filter((line) => {\n const infoIndex = this.info.lines.indexOf(line)\n if (now >= this.handleGetLineTime(infoIndex)) {\n hasChanged = true\n return false\n }\n return true\n })\n\n while (this.state.index < this.info.lines.length) {\n const nextLine = this.info.lines[this.state.index]\n\n if (now >= nextLine.time.start) {\n if (now < this.handleGetLineTime(this.state.index)) {\n activeLines.push(nextLine)\n hasChanged = true\n }\n this.state.index++\n } else {\n break\n }\n }\n\n if (hasChanged) {\n this.state.lines = activeLines\n this.event.emit('linesUpdate', [...this.state.lines])\n }\n }\n\n private onTick = () => {\n if (!this.state.playing) {\n return\n }\n\n const now = this.handleGetCurrentTime()\n this.handleUpdateActiveLines(now)\n\n this.state.frameId = requestAnimationFrame(this.onTick)\n }\n\n updateLyric(info: Info) {\n this.pause()\n this.info = info\n\n this.state.index = 0\n this.state.lines = []\n this.time.seek = 0\n\n this.event.emit('lyricUpdate', info)\n this.event.emit('linesUpdate', [])\n }\n\n play(time?: number) {\n this.pause()\n\n if (typeof time === 'number' && !Number.isNaN(time)) {\n this.time.seek = time\n this.handleSyncTime(time)\n }\n\n this.time.start = performance.now()\n this.state.playing = true\n this.onTick()\n\n this.event.emit('play', this.handleGetCurrentTime())\n }\n\n pause() {\n if (this.state.playing) {\n this.time.seek = this.handleGetCurrentTime()\n this.state.playing = false\n }\n if (this.state.frameId !== null) {\n cancelAnimationFrame(this.state.frameId)\n this.state.frameId = null\n }\n\n this.event.emit('pause', this.handleGetCurrentTime())\n }\n\n dispose() {\n this.pause()\n this.event.clear()\n this.state.lines = []\n this.info = new Info()\n }\n\n get currentLines() {\n return [...this.state.lines]\n }\n\n get currentInfo() {\n return this.info\n }\n\n get currentTime() {\n return this.handleGetCurrentTime()\n }\n}\n"],"names":["DEFAULT_OPTIONS","m","A","BaseLyricPlayer","ConfigManager","Event","Info","index","line","nextLine","time","result","firstIndex","i","now","hasChanged","activeLines","infoIndex","info"],"mappings":"kJAEaA,EAA2B,CAAA,ECmMlCC,EAAI,QAEV,MAAMC,CAAE,CACN,IAAI,SAAU,CACZ,OAAOD,CACT,CACA,KAAO,YACP,MAAQ,CAAA,EACR,MAAQ,CAAA,EACR,OAAS,CAAA,EACT,QAAS,CACP,MAAO,CACL,QAAS,KAAK,QACd,KAAM,KAAK,KACX,MAAO,KAAK,MACZ,MAAO,KAAK,MACZ,OAAQ,KAAK,MACnB,CACE,CACF,CCrLO,MAAME,CAAgB,CAClB,OAAS,IAAIC,EAAAA,cAA6CJ,CAAe,EAEzE,MAAwC,IAAIK,EAAAA,MAE7C,MAMA,KAIA,KAER,aAAc,CACZ,KAAK,MAAQ,CACX,QAAS,GACT,QAAS,KACT,MAAO,EACP,MAAO,CAAA,CAAC,EAEV,KAAK,KAAO,CACV,MAAO,EACP,KAAM,CAAA,EAER,KAAK,KAAO,IAAIC,CAClB,CAEQ,sBAAuB,CAC7B,OAAK,KAAK,MAAM,QAGT,KAAK,KAAK,MAAQ,YAAY,MAAQ,KAAK,KAAK,OAF9C,KAAK,KAAK,IAGrB,CAEQ,kBAAkBC,EAAuB,CAC/C,GAAIA,EAAQ,GAAKA,GAAS,KAAK,KAAK,MAAM,OACxC,MAAO,GAGT,GAAIA,IAAU,KAAK,KAAK,MAAM,OAAS,EACrC,MAAO,KAGT,MAAMC,EAAO,KAAK,KAAK,MAAMD,CAAK,EAC5BE,EAAW,KAAK,KAAK,MAAMF,EAAQ,CAAC,EAC1C,OAAO,KAAK,IAAIC,EAAK,KAAK,IAAKC,EAAS,KAAK,KAAK,CACpD,CAEQ,eAAeC,EAAc,CACnC,MAAMC,EAAiB,CAAA,EAEvB,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,EACnB,KAAK,MAAM,MAAQ,CAAA,EACnB,KAAK,KAAK,KAAO,EAEjB,KAAK,MAAM,KAAK,cAAeA,CAAI,EACnC,KAAK,MAAM,KAAK,cAAe,CAAA,CAAE,CACnC,CAEA,KAAKR,EAAe,CAClB,KAAK,MAAA,EAED,OAAOA,GAAS,UAAY,CAAC,OAAO,MAAMA,CAAI,IAChD,KAAK,KAAK,KAAOA,EACjB,KAAK,eAAeA,CAAI,GAG1B,KAAK,KAAK,MAAQ,YAAY,IAAA,EAC9B,KAAK,MAAM,QAAU,GACrB,KAAK,OAAA,EAEL,KAAK,MAAM,KAAK,OAAQ,KAAK,sBAAsB,CACrD,CAEA,OAAQ,CACF,KAAK,MAAM,UACb,KAAK,KAAK,KAAO,KAAK,qBAAA,EACtB,KAAK,MAAM,QAAU,IAEnB,KAAK,MAAM,UAAY,OACzB,qBAAqB,KAAK,MAAM,OAAO,EACvC,KAAK,MAAM,QAAU,MAGvB,KAAK,MAAM,KAAK,QAAS,KAAK,sBAAsB,CACtD,CAEA,SAAU,CACR,KAAK,MAAA,EACL,KAAK,MAAM,MAAA,EACX,KAAK,MAAM,MAAQ,CAAA,EACnB,KAAK,KAAO,IAAIJ,CAClB,CAEA,IAAI,cAAe,CACjB,MAAO,CAAC,GAAG,KAAK,MAAM,KAAK,CAC7B,CAEA,IAAI,aAAc,CAChB,OAAO,KAAK,IACd,CAEA,IAAI,aAAc,CAChB,OAAO,KAAK,qBAAA,CACd,CACF","x_google_ignoreList":[1]}
|
|
1
|
+
{"version":3,"file":"index.comm.js","sources":["../src/options.ts","../../../node_modules/.pnpm/@music-lyric-kit+lyric@0.4.0/node_modules/@music-lyric-kit/lyric/dist/index.ecma.js","../src/index.ts"],"sourcesContent":["export interface Options {}\n\nexport const DEFAULT_OPTIONS: Options = {}\n","import { createRandomHex as r } from \"@music-lyric-kit/utils\";\nclass s {\n start = 0;\n end = 0;\n get duration() {\n return this.end - this.start;\n }\n toJSON() {\n return {\n start: this.start,\n end: this.end,\n duration: this.duration\n };\n }\n}\nvar o = /* @__PURE__ */ ((t) => (t.Normal = \"Normal\", t.Space = \"Space\", t))(o || {});\nclass i {\n stress = !1;\n toJSON() {\n return {\n stress: this.stress\n };\n }\n}\nclass p {\n get type() {\n return \"Normal\";\n }\n time = new s();\n content = \"\";\n extended = [];\n config = new i();\n toJSON() {\n return {\n type: this.type,\n time: this.time,\n content: this.content,\n extended: this.extended,\n config: this.config\n };\n }\n}\nclass N {\n get type() {\n return \"Space\";\n }\n count = 1;\n toJSON() {\n return {\n type: this.type,\n count: this.count\n };\n }\n}\nvar a = /* @__PURE__ */ ((t) => (t.UnKnown = \"UnKnown\", t.Translate = \"Translate\", t.Roman = \"Roman\", t))(a || {});\nclass S {\n type = \"UnKnown\";\n content = \"\";\n toJSON() {\n return {\n type: this.type,\n content: this.content\n };\n }\n}\nvar l = /* @__PURE__ */ ((t) => (t.Normal = \"Normal\", t.Interlude = \"Interlude\", t))(l || {});\nclass x {\n get type() {\n return \"Interlude\";\n }\n id = r(4).toUpperCase();\n time = new s();\n toJSON() {\n return {\n id: this.id,\n type: this.type,\n time: this.time\n };\n }\n}\nclass c {\n words = [];\n extended = [];\n get original() {\n return this.words.map((n) => n.type === o.Normal ? n.content : new Array(n.count).fill(\" \").join(\"\")).join(\"\");\n }\n toJSON() {\n return {\n words: this.words,\n extended: this.extended,\n original: this.original\n };\n }\n}\nclass y {\n get type() {\n return \"Normal\";\n }\n id = r(4).toUpperCase();\n time = new s();\n content = new c();\n agent;\n background;\n toJSON() {\n return {\n id: this.id,\n type: this.type,\n time: this.time,\n content: this.content,\n agent: this.agent,\n background: this.background\n };\n }\n}\nvar u = /* @__PURE__ */ ((t) => (t.Offset = \"Offset\", t.Duration = \"Duration\", t.Title = \"Title\", t.Singer = \"Singer\", t.Album = \"Album\", t.Creator = \"Creator\", t.UnKnown = \"UnKnown\", t))(u || {});\nclass e {\n id = r(4).toUpperCase();\n toJSON() {\n return {\n id: this.id,\n type: this.type,\n content: this.content\n };\n }\n}\nclass f extends e {\n get type() {\n return \"Offset\";\n }\n content = 0;\n}\nclass w extends e {\n get type() {\n return \"Duration\";\n }\n content = 0;\n}\nclass O extends e {\n get type() {\n return \"Title\";\n }\n content = \"\";\n}\nclass b extends e {\n get type() {\n return \"Singer\";\n }\n content = \"\";\n}\nclass J extends e {\n get type() {\n return \"Album\";\n }\n content = \"\";\n}\nclass U extends e {\n get type() {\n return \"Creator\";\n }\n content = {\n role: \"\",\n name: []\n };\n}\nclass C extends e {\n get type() {\n return \"UnKnown\";\n }\n content = \"\";\n}\nclass I {\n id = \"\";\n name = \"\";\n count = 0;\n}\nclass d {\n // index in global\n global = 0;\n // index in block\n block = 0;\n toJSON() {\n return {\n global: this.global,\n block: this.block\n };\n }\n}\nclass v {\n id = \"\";\n index = new d();\n toJSON() {\n return {\n id: this.id,\n index: this.index\n };\n }\n}\nconst m = \"0.5.1\";\nvar g = /* @__PURE__ */ ((t) => (t.Incorrect = \"Incorrect\", t.Normal = \"Normal\", t.Syllable = \"Syllable\", t.Pure = \"Pure\", t.Empty = \"Empty\", t.NoTime = \"NoTime\", t))(g || {});\nclass A {\n get version() {\n return m;\n }\n type = \"Incorrect\";\n metas = [];\n lines = [];\n agents = [];\n toJSON() {\n return {\n version: this.version,\n type: this.type,\n metas: this.metas,\n lines: this.lines,\n agents: this.agents\n };\n }\n}\nexport {\n I as Agent,\n v as AgentLine,\n d as AgentLineIndex,\n S as Extended,\n a as ExtendedType,\n A as Info,\n x as LineInterlude,\n y as LineNormal,\n c as LineNormalContent,\n l as LineType,\n J as MetaAlbum,\n U as MetaCreator,\n w as MetaDuration,\n f as MetaOffset,\n b as MetaSinger,\n O as MetaTitle,\n u as MetaType,\n C as MetaUnKnown,\n s as Time,\n g as Type,\n m as Version,\n p as WordNormal,\n N as WordSpace,\n o as WordType\n};\n//# sourceMappingURL=index.ecma.js.map\n","import type { Line } from '@music-lyric-kit/lyric'\nimport type { DeepPartial } from '@music-lyric-player/utils'\nimport type { Options } from './options'\n\nimport { DEFAULT_OPTIONS } from './options'\n\nimport { Info } from '@music-lyric-kit/lyric'\nimport { ConfigManager, Event } from '@music-lyric-player/utils'\n\nexport interface BaseLyricPlayerEventMap {\n /**\n * When the player starts or resumes playback.\n * @param currentTime The current playback time.\n */\n play: (currentTime: number) => void\n\n /**\n * When the player pauses playback.\n * @param currentTime The current playback time.\n */\n pause: (currentTime: number) => void\n\n /**\n * When the entire lyric information is updated (e.g., loading a new lyric/song).\n * @param info The newly loaded lyric information object.\n */\n lyricUpdate: (info: Info) => void\n\n /**\n * When the currently active lyric lines change during playback.\n * @param lines An array of the currently active lyric lines.\n * @param indexs An array of the currently active lyric lines' indexes.\n * @param firstIndex The index of the first currently active lyric line (-1 if none).\n */\n linesUpdate: (lines: Line[], indexs: number[], index: number) => void\n}\n\nexport class BaseLyricPlayer {\n readonly config = new ConfigManager<Options, DeepPartial<Options>>(DEFAULT_OPTIONS)\n\n readonly event: Event<BaseLyricPlayerEventMap> = new Event()\n\n private state: {\n playing: boolean\n frameId: number | null\n scanIndex: number\n }\n private active: {\n lines: Line[]\n index: number[]\n }\n private time: {\n start: number\n seek: number\n }\n private info: Info\n\n constructor() {\n this.state = {\n playing: false,\n frameId: null,\n scanIndex: 0,\n }\n this.active = {\n lines: [],\n index: [],\n }\n this.time = {\n start: 0,\n seek: 0,\n }\n this.info = new Info()\n }\n\n private handleGetCurrentTime() {\n if (!this.state.playing) {\n return this.time.seek\n }\n return this.time.seek + (performance.now() - this.time.start)\n }\n\n private handleGetLineTime(index: number): number {\n if (index < 0 || index >= this.info.lines.length) {\n return 0\n }\n\n if (index === this.info.lines.length - 1) {\n return Infinity\n }\n\n const line = this.info.lines[index]\n const nextLine = this.info.lines[index + 1]\n return Math.max(line.time.end, nextLine.time.start)\n }\n\n private handleGetActiveIndex() {\n return this.active.index.length > 0 ? this.active.index[0] : -1\n }\n\n private handleSyncTime(time: number) {\n const lines: Line[] = []\n const index: number[] = []\n\n let firstIndex = this.info.lines.length\n for (let i = 0; i < this.info.lines.length; i++) {\n const line = this.info.lines[i]\n if (line.time.start > time) {\n firstIndex = i\n break\n }\n\n if (this.handleGetLineTime(i) > time) {\n lines.push(line)\n index.push(i)\n }\n }\n\n this.state.scanIndex = firstIndex\n\n this.active.lines = lines\n this.active.index = index\n\n this.event.emit('linesUpdate', [...this.active.lines], [...this.active.index], this.handleGetActiveIndex())\n }\n\n private handleUpdateActiveLines(now: number) {\n let hasChanged = false\n\n const newActiveLines: Line[] = []\n const newActiveIndex: number[] = []\n\n for (let i = 0; i < this.active.lines.length; i++) {\n const line = this.active.lines[i]\n const infoIndex = this.active.index[i]\n\n if (now >= this.handleGetLineTime(infoIndex)) {\n hasChanged = true\n } else {\n newActiveLines.push(line)\n newActiveIndex.push(infoIndex)\n }\n }\n\n while (this.state.scanIndex < this.info.lines.length) {\n const nextLine = this.info.lines[this.state.scanIndex]\n if (now >= nextLine.time.start) {\n if (now < this.handleGetLineTime(this.state.scanIndex)) {\n newActiveLines.push(nextLine)\n newActiveIndex.push(this.state.scanIndex)\n hasChanged = true\n }\n this.state.scanIndex++\n } else {\n break\n }\n }\n\n if (!hasChanged) {\n return\n }\n\n this.active.lines = newActiveLines\n this.active.index = newActiveIndex\n this.event.emit('linesUpdate', [...this.active.lines], [...this.active.index], this.handleGetActiveIndex())\n }\n\n private onTick = () => {\n if (!this.state.playing) {\n return\n }\n\n const now = this.handleGetCurrentTime()\n this.handleUpdateActiveLines(now)\n\n this.state.frameId = requestAnimationFrame(this.onTick)\n }\n\n updateLyric(info: Info) {\n if (!info) {\n return\n }\n\n this.pause()\n this.info = info\n\n this.active.lines = []\n this.active.index = []\n\n this.state.scanIndex = 0\n this.time.seek = 0\n\n this.event.emit('lyricUpdate', info)\n this.event.emit('linesUpdate', [], [], -1)\n }\n\n /**\n * Start playback\n * @param time Optional time in ms to seek to before starting playback. If not provided, playback will start from the current position.\n */\n play(time?: number) {\n this.pause()\n\n if (typeof time === 'number' && !Number.isNaN(time)) {\n this.time.seek = time\n this.handleSyncTime(time)\n }\n\n this.time.start = performance.now()\n this.state.playing = true\n this.onTick()\n\n this.event.emit('play', this.handleGetCurrentTime())\n }\n\n /**\n * Pause playback\n */\n pause() {\n if (this.state.playing) {\n this.time.seek = this.handleGetCurrentTime()\n this.state.playing = false\n }\n if (this.state.frameId !== null) {\n cancelAnimationFrame(this.state.frameId)\n this.state.frameId = null\n }\n\n this.event.emit('pause', this.handleGetCurrentTime())\n }\n\n /**\n * Stop playback\n */\n dispose() {\n this.pause()\n this.event.clear()\n\n this.active.lines = []\n this.active.index = []\n\n this.info = new Info()\n }\n\n /**\n * Find all active lines at the given time (ms). Does not mutate internal state.\n * @param time time in ms to find active lines for.\n */\n matchLinesWithTime(time: number): { lines: Line[]; index: number[] } {\n const lines: Line[] = []\n const index: number[] = []\n for (let i = 0; i < this.info.lines.length; i++) {\n const line = this.info.lines[i]\n if (line.time.start > time) {\n break\n }\n if (this.handleGetLineTime(i) > time) {\n lines.push(line)\n index.push(i)\n }\n }\n return { lines, index }\n }\n\n /**\n * Whether the player is currently playing.\n */\n get currentPlaying() {\n return this.state.playing\n }\n\n /**\n * Current active lines.\n */\n get currentLines() {\n return [...this.active.lines]\n }\n\n /**\n * Indices of currently active lines.\n */\n get currentIndex() {\n return [...this.active.index]\n }\n\n /**\n * The index of the primary active line, or -1 if none.\n */\n get currentActive() {\n return this.handleGetActiveIndex()\n }\n\n /**\n * The current lyric info object.\n */\n get currentInfo() {\n return this.info\n }\n\n /**\n * The current playback time in ms.\n */\n get currentTime() {\n return this.handleGetCurrentTime()\n }\n}\n"],"names":["DEFAULT_OPTIONS","m","A","BaseLyricPlayer","ConfigManager","Event","Info","index","line","nextLine","time","lines","firstIndex","i","now","hasChanged","newActiveLines","newActiveIndex","infoIndex","info"],"mappings":"kJAEaA,EAA2B,CAAA,ECmMlCC,EAAI,QAEV,MAAMC,CAAE,CACN,IAAI,SAAU,CACZ,OAAOD,CACT,CACA,KAAO,YACP,M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AIA,EAAK,KAAK,MAAQE,EACpB,MAEE,KAAK,kBAAkB,CAAC,EAAIA,IAC9BC,EAAM,KAAKH,CAAI,EACfD,EAAM,KAAK,CAAC,EAEhB,CACA,MAAO,CAAE,MAAAI,EAAO,MAAAJ,CAAA,CAClB,CAKA,IAAI,gBAAiB,CACnB,OAAO,KAAK,MAAM,OACpB,CAKA,IAAI,cAAe,CACjB,MAAO,CAAC,GAAG,KAAK,OAAO,KAAK,CAC9B,CAKA,IAAI,cAAe,CACjB,MAAO,CAAC,GAAG,KAAK,OAAO,KAAK,CAC9B,CAKA,IAAI,eAAgB,CAClB,OAAO,KAAK,qBAAA,CACd,CAKA,IAAI,aAAc,CAChB,OAAO,KAAK,IACd,CAKA,IAAI,aAAc,CAChB,OAAO,KAAK,qBAAA,CACd,CACF","x_google_ignoreList":[1]}
|
package/dist/index.ecma.d.ts
CHANGED
|
@@ -7,20 +7,61 @@ export declare class BaseLyricPlayer {
|
|
|
7
7
|
readonly config: ConfigManager<Options, {}, never>;
|
|
8
8
|
readonly event: Event_2<BaseLyricPlayerEventMap>;
|
|
9
9
|
private state;
|
|
10
|
+
private active;
|
|
10
11
|
private time;
|
|
11
12
|
private info;
|
|
12
13
|
constructor();
|
|
13
14
|
private handleGetCurrentTime;
|
|
14
15
|
private handleGetLineTime;
|
|
16
|
+
private handleGetActiveIndex;
|
|
15
17
|
private handleSyncTime;
|
|
16
18
|
private handleUpdateActiveLines;
|
|
17
19
|
private onTick;
|
|
18
20
|
updateLyric(info: Info): void;
|
|
21
|
+
/**
|
|
22
|
+
* Start playback
|
|
23
|
+
* @param time Optional time in ms to seek to before starting playback. If not provided, playback will start from the current position.
|
|
24
|
+
*/
|
|
19
25
|
play(time?: number): void;
|
|
26
|
+
/**
|
|
27
|
+
* Pause playback
|
|
28
|
+
*/
|
|
20
29
|
pause(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Stop playback
|
|
32
|
+
*/
|
|
21
33
|
dispose(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Find all active lines at the given time (ms). Does not mutate internal state.
|
|
36
|
+
* @param time time in ms to find active lines for.
|
|
37
|
+
*/
|
|
38
|
+
matchLinesWithTime(time: number): {
|
|
39
|
+
lines: Line[];
|
|
40
|
+
index: number[];
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Whether the player is currently playing.
|
|
44
|
+
*/
|
|
45
|
+
get currentPlaying(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Current active lines.
|
|
48
|
+
*/
|
|
22
49
|
get currentLines(): Line[];
|
|
50
|
+
/**
|
|
51
|
+
* Indices of currently active lines.
|
|
52
|
+
*/
|
|
53
|
+
get currentIndex(): number[];
|
|
54
|
+
/**
|
|
55
|
+
* The index of the primary active line, or -1 if none.
|
|
56
|
+
*/
|
|
57
|
+
get currentActive(): number;
|
|
58
|
+
/**
|
|
59
|
+
* The current lyric info object.
|
|
60
|
+
*/
|
|
23
61
|
get currentInfo(): Info;
|
|
62
|
+
/**
|
|
63
|
+
* The current playback time in ms.
|
|
64
|
+
*/
|
|
24
65
|
get currentTime(): number;
|
|
25
66
|
}
|
|
26
67
|
|
|
@@ -43,8 +84,10 @@ export declare interface BaseLyricPlayerEventMap {
|
|
|
43
84
|
/**
|
|
44
85
|
* When the currently active lyric lines change during playback.
|
|
45
86
|
* @param lines An array of the currently active lyric lines.
|
|
87
|
+
* @param indexs An array of the currently active lyric lines' indexes.
|
|
88
|
+
* @param firstIndex The index of the first currently active lyric line (-1 if none).
|
|
46
89
|
*/
|
|
47
|
-
linesUpdate: (lines: Line[]) => void;
|
|
90
|
+
linesUpdate: (lines: Line[], indexs: number[], index: number) => void;
|
|
48
91
|
}
|
|
49
92
|
|
|
50
93
|
declare interface Options {
|
package/dist/index.ecma.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "lodash-es";
|
|
2
|
-
import { ConfigManager as
|
|
3
|
-
const o = {},
|
|
4
|
-
class
|
|
2
|
+
import { ConfigManager as c, Event as d } from "@music-lyric-player/utils";
|
|
3
|
+
const o = {}, u = "0.5.1";
|
|
4
|
+
class r {
|
|
5
5
|
get version() {
|
|
6
|
-
return
|
|
6
|
+
return u;
|
|
7
7
|
}
|
|
8
8
|
type = "Incorrect";
|
|
9
9
|
metas = [];
|
|
@@ -19,22 +19,25 @@ class a {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
class
|
|
23
|
-
config = new
|
|
24
|
-
event = new
|
|
22
|
+
class v {
|
|
23
|
+
config = new c(o);
|
|
24
|
+
event = new d();
|
|
25
25
|
state;
|
|
26
|
+
active;
|
|
26
27
|
time;
|
|
27
28
|
info;
|
|
28
29
|
constructor() {
|
|
29
30
|
this.state = {
|
|
30
31
|
playing: !1,
|
|
31
32
|
frameId: null,
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
scanIndex: 0
|
|
34
|
+
}, this.active = {
|
|
35
|
+
lines: [],
|
|
36
|
+
index: []
|
|
34
37
|
}, this.time = {
|
|
35
38
|
start: 0,
|
|
36
39
|
seek: 0
|
|
37
|
-
}, this.info = new
|
|
40
|
+
}, this.info = new r();
|
|
38
41
|
}
|
|
39
42
|
handleGetCurrentTime() {
|
|
40
43
|
return this.state.playing ? this.time.seek + (performance.now() - this.time.start) : this.time.seek;
|
|
@@ -44,36 +47,40 @@ class c {
|
|
|
44
47
|
return 0;
|
|
45
48
|
if (e === this.info.lines.length - 1)
|
|
46
49
|
return 1 / 0;
|
|
47
|
-
const
|
|
48
|
-
return Math.max(
|
|
50
|
+
const n = this.info.lines[e], s = this.info.lines[e + 1];
|
|
51
|
+
return Math.max(n.time.end, s.time.start);
|
|
52
|
+
}
|
|
53
|
+
handleGetActiveIndex() {
|
|
54
|
+
return this.active.index.length > 0 ? this.active.index[0] : -1;
|
|
49
55
|
}
|
|
50
56
|
handleSyncTime(e) {
|
|
51
|
-
const
|
|
52
|
-
let
|
|
57
|
+
const n = [], s = [];
|
|
58
|
+
let i = this.info.lines.length;
|
|
53
59
|
for (let t = 0; t < this.info.lines.length; t++) {
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
|
|
60
|
+
const a = this.info.lines[t];
|
|
61
|
+
if (a.time.start > e) {
|
|
62
|
+
i = t;
|
|
57
63
|
break;
|
|
58
64
|
}
|
|
59
|
-
this.handleGetLineTime(t) > e &&
|
|
65
|
+
this.handleGetLineTime(t) > e && (n.push(a), s.push(t));
|
|
60
66
|
}
|
|
61
|
-
this.state.
|
|
67
|
+
this.state.scanIndex = i, this.active.lines = n, this.active.index = s, this.event.emit("linesUpdate", [...this.active.lines], [...this.active.index], this.handleGetActiveIndex());
|
|
62
68
|
}
|
|
63
69
|
handleUpdateActiveLines(e) {
|
|
64
|
-
let
|
|
65
|
-
const s =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
let n = !1;
|
|
71
|
+
const s = [], i = [];
|
|
72
|
+
for (let t = 0; t < this.active.lines.length; t++) {
|
|
73
|
+
const a = this.active.lines[t], h = this.active.index[t];
|
|
74
|
+
e >= this.handleGetLineTime(h) ? n = !0 : (s.push(a), i.push(h));
|
|
75
|
+
}
|
|
76
|
+
for (; this.state.scanIndex < this.info.lines.length; ) {
|
|
77
|
+
const t = this.info.lines[this.state.scanIndex];
|
|
71
78
|
if (e >= t.time.start)
|
|
72
|
-
e < this.handleGetLineTime(this.state.
|
|
79
|
+
e < this.handleGetLineTime(this.state.scanIndex) && (s.push(t), i.push(this.state.scanIndex), n = !0), this.state.scanIndex++;
|
|
73
80
|
else
|
|
74
81
|
break;
|
|
75
82
|
}
|
|
76
|
-
|
|
83
|
+
n && (this.active.lines = s, this.active.index = i, this.event.emit("linesUpdate", [...this.active.lines], [...this.active.index], this.handleGetActiveIndex()));
|
|
77
84
|
}
|
|
78
85
|
onTick = () => {
|
|
79
86
|
if (!this.state.playing)
|
|
@@ -82,28 +89,79 @@ class c {
|
|
|
82
89
|
this.handleUpdateActiveLines(e), this.state.frameId = requestAnimationFrame(this.onTick);
|
|
83
90
|
};
|
|
84
91
|
updateLyric(e) {
|
|
85
|
-
this.pause(), this.info = e, this.
|
|
92
|
+
e && (this.pause(), this.info = e, this.active.lines = [], this.active.index = [], this.state.scanIndex = 0, this.time.seek = 0, this.event.emit("lyricUpdate", e), this.event.emit("linesUpdate", [], [], -1));
|
|
86
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Start playback
|
|
96
|
+
* @param time Optional time in ms to seek to before starting playback. If not provided, playback will start from the current position.
|
|
97
|
+
*/
|
|
87
98
|
play(e) {
|
|
88
99
|
this.pause(), typeof e == "number" && !Number.isNaN(e) && (this.time.seek = e, this.handleSyncTime(e)), this.time.start = performance.now(), this.state.playing = !0, this.onTick(), this.event.emit("play", this.handleGetCurrentTime());
|
|
89
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Pause playback
|
|
103
|
+
*/
|
|
90
104
|
pause() {
|
|
91
105
|
this.state.playing && (this.time.seek = this.handleGetCurrentTime(), this.state.playing = !1), this.state.frameId !== null && (cancelAnimationFrame(this.state.frameId), this.state.frameId = null), this.event.emit("pause", this.handleGetCurrentTime());
|
|
92
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Stop playback
|
|
109
|
+
*/
|
|
93
110
|
dispose() {
|
|
94
|
-
this.pause(), this.event.clear(), this.
|
|
111
|
+
this.pause(), this.event.clear(), this.active.lines = [], this.active.index = [], this.info = new r();
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Find all active lines at the given time (ms). Does not mutate internal state.
|
|
115
|
+
* @param time time in ms to find active lines for.
|
|
116
|
+
*/
|
|
117
|
+
matchLinesWithTime(e) {
|
|
118
|
+
const n = [], s = [];
|
|
119
|
+
for (let i = 0; i < this.info.lines.length; i++) {
|
|
120
|
+
const t = this.info.lines[i];
|
|
121
|
+
if (t.time.start > e)
|
|
122
|
+
break;
|
|
123
|
+
this.handleGetLineTime(i) > e && (n.push(t), s.push(i));
|
|
124
|
+
}
|
|
125
|
+
return { lines: n, index: s };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Whether the player is currently playing.
|
|
129
|
+
*/
|
|
130
|
+
get currentPlaying() {
|
|
131
|
+
return this.state.playing;
|
|
95
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Current active lines.
|
|
135
|
+
*/
|
|
96
136
|
get currentLines() {
|
|
97
|
-
return [...this.
|
|
137
|
+
return [...this.active.lines];
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Indices of currently active lines.
|
|
141
|
+
*/
|
|
142
|
+
get currentIndex() {
|
|
143
|
+
return [...this.active.index];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The index of the primary active line, or -1 if none.
|
|
147
|
+
*/
|
|
148
|
+
get currentActive() {
|
|
149
|
+
return this.handleGetActiveIndex();
|
|
98
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* The current lyric info object.
|
|
153
|
+
*/
|
|
99
154
|
get currentInfo() {
|
|
100
155
|
return this.info;
|
|
101
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* The current playback time in ms.
|
|
159
|
+
*/
|
|
102
160
|
get currentTime() {
|
|
103
161
|
return this.handleGetCurrentTime();
|
|
104
162
|
}
|
|
105
163
|
}
|
|
106
164
|
export {
|
|
107
|
-
|
|
165
|
+
v as BaseLyricPlayer
|
|
108
166
|
};
|
|
109
167
|
//# sourceMappingURL=index.ecma.js.map
|
package/dist/index.ecma.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.ecma.js","sources":["../src/options.ts","../../../node_modules/.pnpm/@music-lyric-kit+lyric@0.4.0/node_modules/@music-lyric-kit/lyric/dist/index.ecma.js","../src/index.ts"],"sourcesContent":["export interface Options {}\n\nexport const DEFAULT_OPTIONS: Options = {}\n","import { createRandomHex as r } from \"@music-lyric-kit/utils\";\nclass s {\n start = 0;\n end = 0;\n get duration() {\n return this.end - this.start;\n }\n toJSON() {\n return {\n start: this.start,\n end: this.end,\n duration: this.duration\n };\n }\n}\nvar o = /* @__PURE__ */ ((t) => (t.Normal = \"Normal\", t.Space = \"Space\", t))(o || {});\nclass i {\n stress = !1;\n toJSON() {\n return {\n stress: this.stress\n };\n }\n}\nclass p {\n get type() {\n return \"Normal\";\n }\n time = new s();\n content = \"\";\n extended = [];\n config = new i();\n toJSON() {\n return {\n type: this.type,\n time: this.time,\n content: this.content,\n extended: this.extended,\n config: this.config\n };\n }\n}\nclass N {\n get type() {\n return \"Space\";\n }\n count = 1;\n toJSON() {\n return {\n type: this.type,\n count: this.count\n };\n }\n}\nvar a = /* @__PURE__ */ ((t) => (t.UnKnown = \"UnKnown\", t.Translate = \"Translate\", t.Roman = \"Roman\", t))(a || {});\nclass S {\n type = \"UnKnown\";\n content = \"\";\n toJSON() {\n return {\n type: this.type,\n content: this.content\n };\n }\n}\nvar l = /* @__PURE__ */ ((t) => (t.Normal = \"Normal\", t.Interlude = \"Interlude\", t))(l || {});\nclass x {\n get type() {\n return \"Interlude\";\n }\n id = r(4).toUpperCase();\n time = new s();\n toJSON() {\n return {\n id: this.id,\n type: this.type,\n time: this.time\n };\n }\n}\nclass c {\n words = [];\n extended = [];\n get original() {\n return this.words.map((n) => n.type === o.Normal ? n.content : new Array(n.count).fill(\" \").join(\"\")).join(\"\");\n }\n toJSON() {\n return {\n words: this.words,\n extended: this.extended,\n original: this.original\n };\n }\n}\nclass y {\n get type() {\n return \"Normal\";\n }\n id = r(4).toUpperCase();\n time = new s();\n content = new c();\n agent;\n background;\n toJSON() {\n return {\n id: this.id,\n type: this.type,\n time: this.time,\n content: this.content,\n agent: this.agent,\n background: this.background\n };\n }\n}\nvar u = /* @__PURE__ */ ((t) => (t.Offset = \"Offset\", t.Duration = \"Duration\", t.Title = \"Title\", t.Singer = \"Singer\", t.Album = \"Album\", t.Creator = \"Creator\", t.UnKnown = \"UnKnown\", t))(u || {});\nclass e {\n id = r(4).toUpperCase();\n toJSON() {\n return {\n id: this.id,\n type: this.type,\n content: this.content\n };\n }\n}\nclass f extends e {\n get type() {\n return \"Offset\";\n }\n content = 0;\n}\nclass w extends e {\n get type() {\n return \"Duration\";\n }\n content = 0;\n}\nclass O extends e {\n get type() {\n return \"Title\";\n }\n content = \"\";\n}\nclass b extends e {\n get type() {\n return \"Singer\";\n }\n content = \"\";\n}\nclass J extends e {\n get type() {\n return \"Album\";\n }\n content = \"\";\n}\nclass U extends e {\n get type() {\n return \"Creator\";\n }\n content = {\n role: \"\",\n name: []\n };\n}\nclass C extends e {\n get type() {\n return \"UnKnown\";\n }\n content = \"\";\n}\nclass I {\n id = \"\";\n name = \"\";\n count = 0;\n}\nclass d {\n // index in global\n global = 0;\n // index in block\n block = 0;\n toJSON() {\n return {\n global: this.global,\n block: this.block\n };\n }\n}\nclass v {\n id = \"\";\n index = new d();\n toJSON() {\n return {\n id: this.id,\n index: this.index\n };\n }\n}\nconst m = \"0.5.1\";\nvar g = /* @__PURE__ */ ((t) => (t.Incorrect = \"Incorrect\", t.Normal = \"Normal\", t.Syllable = \"Syllable\", t.Pure = \"Pure\", t.Empty = \"Empty\", t.NoTime = \"NoTime\", t))(g || {});\nclass A {\n get version() {\n return m;\n }\n type = \"Incorrect\";\n metas = [];\n lines = [];\n agents = [];\n toJSON() {\n return {\n version: this.version,\n type: this.type,\n metas: this.metas,\n lines: this.lines,\n agents: this.agents\n };\n }\n}\nexport {\n I as Agent,\n v as AgentLine,\n d as AgentLineIndex,\n S as Extended,\n a as ExtendedType,\n A as Info,\n x as LineInterlude,\n y as LineNormal,\n c as LineNormalContent,\n l as LineType,\n J as MetaAlbum,\n U as MetaCreator,\n w as MetaDuration,\n f as MetaOffset,\n b as MetaSinger,\n O as MetaTitle,\n u as MetaType,\n C as MetaUnKnown,\n s as Time,\n g as Type,\n m as Version,\n p as WordNormal,\n N as WordSpace,\n o as WordType\n};\n//# sourceMappingURL=index.ecma.js.map\n","import type { Line } from '@music-lyric-kit/lyric'\nimport type { DeepPartial } from '@music-lyric-player/utils'\nimport type { Options } from './options'\n\nimport { DEFAULT_OPTIONS } from './options'\n\nimport { Info } from '@music-lyric-kit/lyric'\nimport { ConfigManager, Event } from '@music-lyric-player/utils'\n\nexport interface BaseLyricPlayerEventMap {\n /**\n * When the player starts or resumes playback.\n * @param currentTime The current playback time.\n */\n play: (currentTime: number) => void\n\n /**\n * When the player pauses playback.\n * @param currentTime The current playback time.\n */\n pause: (currentTime: number) => void\n\n /**\n * When the entire lyric information is updated (e.g., loading a new lyric/song).\n * @param info The newly loaded lyric information object.\n */\n lyricUpdate: (info: Info) => void\n\n /**\n * When the currently active lyric lines change during playback.\n * @param lines An array of the currently active lyric lines.\n */\n linesUpdate: (lines: Line[]) => void\n}\n\nexport class BaseLyricPlayer {\n readonly config = new ConfigManager<Options, DeepPartial<Options>>(DEFAULT_OPTIONS)\n\n readonly event: Event<BaseLyricPlayerEventMap> = new Event()\n\n private state: {\n playing: boolean\n frameId: number | null\n index: number\n lines: Line[]\n }\n private time: {\n start: number\n seek: number\n }\n private info: Info\n\n constructor() {\n this.state = {\n playing: false,\n frameId: null,\n index: 0,\n lines: [],\n }\n this.time = {\n start: 0,\n seek: 0,\n }\n this.info = new Info()\n }\n\n private handleGetCurrentTime() {\n if (!this.state.playing) {\n return this.time.seek\n }\n return this.time.seek + (performance.now() - this.time.start)\n }\n\n private handleGetLineTime(index: number): number {\n if (index < 0 || index >= this.info.lines.length) {\n return 0\n }\n\n if (index === this.info.lines.length - 1) {\n return Infinity\n }\n\n const line = this.info.lines[index]\n const nextLine = this.info.lines[index + 1]\n return Math.max(line.time.end, nextLine.time.start)\n }\n\n private handleSyncTime(time: number) {\n const result: Line[] = []\n\n let firstIndex = this.info.lines.length\n for (let i = 0; i < this.info.lines.length; i++) {\n const line = this.info.lines[i]\n if (line.time.start > time) {\n firstIndex = i\n break\n }\n\n if (this.handleGetLineTime(i) > time) {\n result.push(line)\n }\n }\n\n this.state.lines = result\n this.state.index = firstIndex\n\n this.event.emit('linesUpdate', [...this.state.lines])\n }\n\n private handleUpdateActiveLines(now: number) {\n let hasChanged = false\n\n const activeLines = this.state.lines.filter((line) => {\n const infoIndex = this.info.lines.indexOf(line)\n if (now >= this.handleGetLineTime(infoIndex)) {\n hasChanged = true\n return false\n }\n return true\n })\n\n while (this.state.index < this.info.lines.length) {\n const nextLine = this.info.lines[this.state.index]\n\n if (now >= nextLine.time.start) {\n if (now < this.handleGetLineTime(this.state.index)) {\n activeLines.push(nextLine)\n hasChanged = true\n }\n this.state.index++\n } else {\n break\n }\n }\n\n if (hasChanged) {\n this.state.lines = activeLines\n this.event.emit('linesUpdate', [...this.state.lines])\n }\n }\n\n private onTick = () => {\n if (!this.state.playing) {\n return\n }\n\n const now = this.handleGetCurrentTime()\n this.handleUpdateActiveLines(now)\n\n this.state.frameId = requestAnimationFrame(this.onTick)\n }\n\n updateLyric(info: Info) {\n this.pause()\n this.info = info\n\n this.state.index = 0\n this.state.lines = []\n this.time.seek = 0\n\n this.event.emit('lyricUpdate', info)\n this.event.emit('linesUpdate', [])\n }\n\n play(time?: number) {\n this.pause()\n\n if (typeof time === 'number' && !Number.isNaN(time)) {\n this.time.seek = time\n this.handleSyncTime(time)\n }\n\n this.time.start = performance.now()\n this.state.playing = true\n this.onTick()\n\n this.event.emit('play', this.handleGetCurrentTime())\n }\n\n pause() {\n if (this.state.playing) {\n this.time.seek = this.handleGetCurrentTime()\n this.state.playing = false\n }\n if (this.state.frameId !== null) {\n cancelAnimationFrame(this.state.frameId)\n this.state.frameId = null\n }\n\n this.event.emit('pause', this.handleGetCurrentTime())\n }\n\n dispose() {\n this.pause()\n this.event.clear()\n this.state.lines = []\n this.info = new Info()\n }\n\n get currentLines() {\n return [...this.state.lines]\n }\n\n get currentInfo() {\n return this.info\n }\n\n get currentTime() {\n return this.handleGetCurrentTime()\n }\n}\n"],"names":["DEFAULT_OPTIONS","m","A","BaseLyricPlayer","ConfigManager","Event","Info","index","line","nextLine","time","result","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/@music-lyric-kit+lyric@0.4.0/node_modules/@music-lyric-kit/lyric/dist/index.ecma.js","../src/index.ts"],"sourcesContent":["export interface Options {}\n\nexport const DEFAULT_OPTIONS: Options = {}\n","import { createRandomHex as r } from \"@music-lyric-kit/utils\";\nclass s {\n start = 0;\n end = 0;\n get duration() {\n return this.end - this.start;\n }\n toJSON() {\n return {\n start: this.start,\n end: this.end,\n duration: this.duration\n };\n }\n}\nvar o = /* @__PURE__ */ ((t) => (t.Normal = \"Normal\", t.Space = \"Space\", t))(o || {});\nclass i {\n stress = !1;\n toJSON() {\n return {\n stress: this.stress\n };\n }\n}\nclass p {\n get type() {\n return \"Normal\";\n }\n time = new s();\n content = \"\";\n extended = [];\n config = new i();\n toJSON() {\n return {\n type: this.type,\n time: this.time,\n content: this.content,\n extended: this.extended,\n config: this.config\n };\n }\n}\nclass N {\n get type() {\n return \"Space\";\n }\n count = 1;\n toJSON() {\n return {\n type: this.type,\n count: this.count\n };\n }\n}\nvar a = /* @__PURE__ */ ((t) => (t.UnKnown = \"UnKnown\", t.Translate = \"Translate\", t.Roman = \"Roman\", t))(a || {});\nclass S {\n type = \"UnKnown\";\n content = \"\";\n toJSON() {\n return {\n type: this.type,\n content: this.content\n };\n }\n}\nvar l = /* @__PURE__ */ ((t) => (t.Normal = \"Normal\", t.Interlude = \"Interlude\", t))(l || {});\nclass x {\n get type() {\n return \"Interlude\";\n }\n id = r(4).toUpperCase();\n time = new s();\n toJSON() {\n return {\n id: this.id,\n type: this.type,\n time: this.time\n };\n }\n}\nclass c {\n words = [];\n extended = [];\n get original() {\n return this.words.map((n) => n.type === o.Normal ? n.content : new Array(n.count).fill(\" \").join(\"\")).join(\"\");\n }\n toJSON() {\n return {\n words: this.words,\n extended: this.extended,\n original: this.original\n };\n }\n}\nclass y {\n get type() {\n return \"Normal\";\n }\n id = r(4).toUpperCase();\n time = new s();\n content = new c();\n agent;\n background;\n toJSON() {\n return {\n id: this.id,\n type: this.type,\n time: this.time,\n content: this.content,\n agent: this.agent,\n background: this.background\n };\n }\n}\nvar u = /* @__PURE__ */ ((t) => (t.Offset = \"Offset\", t.Duration = \"Duration\", t.Title = \"Title\", t.Singer = \"Singer\", t.Album = \"Album\", t.Creator = \"Creator\", t.UnKnown = \"UnKnown\", t))(u || {});\nclass e {\n id = r(4).toUpperCase();\n toJSON() {\n return {\n id: this.id,\n type: this.type,\n content: this.content\n };\n }\n}\nclass f extends e {\n get type() {\n return \"Offset\";\n }\n content = 0;\n}\nclass w extends e {\n get type() {\n return \"Duration\";\n }\n content = 0;\n}\nclass O extends e {\n get type() {\n return \"Title\";\n }\n content = \"\";\n}\nclass b extends e {\n get type() {\n return \"Singer\";\n }\n content = \"\";\n}\nclass J extends e {\n get type() {\n return \"Album\";\n }\n content = \"\";\n}\nclass U extends e {\n get type() {\n return \"Creator\";\n }\n content = {\n role: \"\",\n name: []\n };\n}\nclass C extends e {\n get type() {\n return \"UnKnown\";\n }\n content = \"\";\n}\nclass I {\n id = \"\";\n name = \"\";\n count = 0;\n}\nclass d {\n // index in global\n global = 0;\n // index in block\n block = 0;\n toJSON() {\n return {\n global: this.global,\n block: this.block\n };\n }\n}\nclass v {\n id = \"\";\n index = new d();\n toJSON() {\n return {\n id: this.id,\n index: this.index\n };\n }\n}\nconst m = \"0.5.1\";\nvar g = /* @__PURE__ */ ((t) => (t.Incorrect = \"Incorrect\", t.Normal = \"Normal\", t.Syllable = \"Syllable\", t.Pure = \"Pure\", t.Empty = \"Empty\", t.NoTime = \"NoTime\", t))(g || {});\nclass A {\n get version() {\n return m;\n }\n type = \"Incorrect\";\n metas = [];\n lines = [];\n agents = [];\n toJSON() {\n return {\n version: this.version,\n type: this.type,\n metas: this.metas,\n lines: this.lines,\n agents: this.agents\n };\n }\n}\nexport {\n I as Agent,\n v as AgentLine,\n d as AgentLineIndex,\n S as Extended,\n a as ExtendedType,\n A as Info,\n x as LineInterlude,\n y as LineNormal,\n c as LineNormalContent,\n l as LineType,\n J as MetaAlbum,\n U as MetaCreator,\n w as MetaDuration,\n f as MetaOffset,\n b as MetaSinger,\n O as MetaTitle,\n u as MetaType,\n C as MetaUnKnown,\n s as Time,\n g as Type,\n m as Version,\n p as WordNormal,\n N as WordSpace,\n o as WordType\n};\n//# sourceMappingURL=index.ecma.js.map\n","import type { Line } from '@music-lyric-kit/lyric'\nimport type { DeepPartial } from '@music-lyric-player/utils'\nimport type { Options } from './options'\n\nimport { DEFAULT_OPTIONS } from './options'\n\nimport { Info } from '@music-lyric-kit/lyric'\nimport { ConfigManager, Event } from '@music-lyric-player/utils'\n\nexport interface BaseLyricPlayerEventMap {\n /**\n * When the player starts or resumes playback.\n * @param currentTime The current playback time.\n */\n play: (currentTime: number) => void\n\n /**\n * When the player pauses playback.\n * @param currentTime The current playback time.\n */\n pause: (currentTime: number) => void\n\n /**\n * When the entire lyric information is updated (e.g., loading a new lyric/song).\n * @param info The newly loaded lyric information object.\n */\n lyricUpdate: (info: Info) => void\n\n /**\n * When the currently active lyric lines change during playback.\n * @param lines An array of the currently active lyric lines.\n * @param indexs An array of the currently active lyric lines' indexes.\n * @param firstIndex The index of the first currently active lyric line (-1 if none).\n */\n linesUpdate: (lines: Line[], indexs: number[], index: number) => void\n}\n\nexport class BaseLyricPlayer {\n readonly config = new ConfigManager<Options, DeepPartial<Options>>(DEFAULT_OPTIONS)\n\n readonly event: Event<BaseLyricPlayerEventMap> = new Event()\n\n private state: {\n playing: boolean\n frameId: number | null\n scanIndex: number\n }\n private active: {\n lines: Line[]\n index: number[]\n }\n private time: {\n start: number\n seek: number\n }\n private info: Info\n\n constructor() {\n this.state = {\n playing: false,\n frameId: null,\n scanIndex: 0,\n }\n this.active = {\n lines: [],\n index: [],\n }\n this.time = {\n start: 0,\n seek: 0,\n }\n this.info = new Info()\n }\n\n private handleGetCurrentTime() {\n if (!this.state.playing) {\n return this.time.seek\n }\n return this.time.seek + (performance.now() - this.time.start)\n }\n\n private handleGetLineTime(index: number): number {\n if (index < 0 || index >= this.info.lines.length) {\n return 0\n }\n\n if (index === this.info.lines.length - 1) {\n return Infinity\n }\n\n const line = this.info.lines[index]\n const nextLine = this.info.lines[index + 1]\n return Math.max(line.time.end, nextLine.time.start)\n }\n\n private handleGetActiveIndex() {\n return this.active.index.length > 0 ? this.active.index[0] : -1\n }\n\n private handleSyncTime(time: number) {\n const lines: Line[] = []\n const index: number[] = []\n\n let firstIndex = this.info.lines.length\n for (let i = 0; i < this.info.lines.length; i++) {\n const line = this.info.lines[i]\n if (line.time.start > time) {\n firstIndex = i\n break\n }\n\n if (this.handleGetLineTime(i) > time) {\n lines.push(line)\n index.push(i)\n }\n }\n\n this.state.scanIndex = firstIndex\n\n this.active.lines = lines\n this.active.index = index\n\n this.event.emit('linesUpdate', [...this.active.lines], [...this.active.index], this.handleGetActiveIndex())\n }\n\n private handleUpdateActiveLines(now: number) {\n let hasChanged = false\n\n const newActiveLines: Line[] = []\n const newActiveIndex: number[] = []\n\n for (let i = 0; i < this.active.lines.length; i++) {\n const line = this.active.lines[i]\n const infoIndex = this.active.index[i]\n\n if (now >= this.handleGetLineTime(infoIndex)) {\n hasChanged = true\n } else {\n newActiveLines.push(line)\n newActiveIndex.push(infoIndex)\n }\n }\n\n while (this.state.scanIndex < this.info.lines.length) {\n const nextLine = this.info.lines[this.state.scanIndex]\n if (now >= nextLine.time.start) {\n if (now < this.handleGetLineTime(this.state.scanIndex)) {\n newActiveLines.push(nextLine)\n newActiveIndex.push(this.state.scanIndex)\n hasChanged = true\n }\n this.state.scanIndex++\n } else {\n break\n }\n }\n\n if (!hasChanged) {\n return\n }\n\n this.active.lines = newActiveLines\n this.active.index = newActiveIndex\n this.event.emit('linesUpdate', [...this.active.lines], [...this.active.index], this.handleGetActiveIndex())\n }\n\n private onTick = () => {\n if (!this.state.playing) {\n return\n }\n\n const now = this.handleGetCurrentTime()\n this.handleUpdateActiveLines(now)\n\n this.state.frameId = requestAnimationFrame(this.onTick)\n }\n\n updateLyric(info: Info) {\n if (!info) {\n return\n }\n\n this.pause()\n this.info = info\n\n this.active.lines = []\n this.active.index = []\n\n this.state.scanIndex = 0\n this.time.seek = 0\n\n this.event.emit('lyricUpdate', info)\n this.event.emit('linesUpdate', [], [], -1)\n }\n\n /**\n * Start playback\n * @param time Optional time in ms to seek to before starting playback. If not provided, playback will start from the current position.\n */\n play(time?: number) {\n this.pause()\n\n if (typeof time === 'number' && !Number.isNaN(time)) {\n this.time.seek = time\n this.handleSyncTime(time)\n }\n\n this.time.start = performance.now()\n this.state.playing = true\n this.onTick()\n\n this.event.emit('play', this.handleGetCurrentTime())\n }\n\n /**\n * Pause playback\n */\n pause() {\n if (this.state.playing) {\n this.time.seek = this.handleGetCurrentTime()\n this.state.playing = false\n }\n if (this.state.frameId !== null) {\n cancelAnimationFrame(this.state.frameId)\n this.state.frameId = null\n }\n\n this.event.emit('pause', this.handleGetCurrentTime())\n }\n\n /**\n * Stop playback\n */\n dispose() {\n this.pause()\n this.event.clear()\n\n this.active.lines = []\n this.active.index = []\n\n this.info = new Info()\n }\n\n /**\n * Find all active lines at the given time (ms). Does not mutate internal state.\n * @param time time in ms to find active lines for.\n */\n matchLinesWithTime(time: number): { lines: Line[]; index: number[] } {\n const lines: Line[] = []\n const index: number[] = []\n for (let i = 0; i < this.info.lines.length; i++) {\n const line = this.info.lines[i]\n if (line.time.start > time) {\n break\n }\n if (this.handleGetLineTime(i) > time) {\n lines.push(line)\n index.push(i)\n }\n }\n return { lines, index }\n }\n\n /**\n * Whether the player is currently playing.\n */\n get currentPlaying() {\n return this.state.playing\n }\n\n /**\n * Current active lines.\n */\n get currentLines() {\n return [...this.active.lines]\n }\n\n /**\n * Indices of currently active lines.\n */\n get currentIndex() {\n return [...this.active.index]\n }\n\n /**\n * The index of the primary active line, or -1 if none.\n */\n get currentActive() {\n return this.handleGetActiveIndex()\n }\n\n /**\n * The current lyric info object.\n */\n get currentInfo() {\n return this.info\n }\n\n /**\n * The current playback time in ms.\n */\n get currentTime() {\n return this.handleGetCurrentTime()\n }\n}\n"],"names":["DEFAULT_OPTIONS","m","A","BaseLyricPlayer","ConfigManager","Event","Info","index","line","nextLine","time","lines","firstIndex","i","now","hasChanged","newActiveLines","newActiveIndex","infoIndex","info"],"mappings":";;AAEO,MAAMA,IAA2B,CAAA,GCmMlCC,IAAI;AAEV,MAAMC,EAAE;AAAA,EACN,IAAI,UAAU;AACZ,WAAOD;AAAA,EACT;AAAA,EACA,OAAO;AAAA,EACP,QAAQ,CAAA;AAAA,EACR,QAAQ,CAAA;AAAA,EACR,SAAS,CAAA;AAAA,EACT,SAAS;AACP,WAAO;AAAA,MACL,SAAS,KAAK;AAAA,MACd,MAAM,KAAK;AAAA,MACX,OAAO,KAAK;AAAA,MACZ,OAAO,KAAK;AAAA,MACZ,QAAQ,KAAK;AAAA,IACnB;AAAA,EACE;AACF;ACnLO,MAAME,EAAgB;AAAA,EAClB,SAAS,IAAIC,EAA6CJ,CAAe;AAAA,EAEzE,QAAwC,IAAIK,EAAA;AAAA,EAE7C;AAAA,EAKA;AAAA,EAIA;AAAA,EAIA;AAAA,EAER,cAAc;AACZ,SAAK,QAAQ;AAAA,MACX,SAAS;AAAA,MACT,SAAS;AAAA,MACT,WAAW;AAAA,IAAA,GAEb,KAAK,SAAS;AAAA,MACZ,OAAO,CAAA;AAAA,MACP,OAAO,CAAA;AAAA,IAAC,GAEV,KAAK,OAAO;AAAA,MACV,OAAO;AAAA,MACP,MAAM;AAAA,IAAA,GAER,KAAK,OAAO,IAAIC,EAAA;AAAA,EAClB;AAAA,EAEQ,uBAAuB;AAC7B,WAAK,KAAK,MAAM,UAGT,KAAK,KAAK,QAAQ,YAAY,QAAQ,KAAK,KAAK,SAF9C,KAAK,KAAK;AAAA,EAGrB;AAAA,EAEQ,kBAAkBC,GAAuB;AAC/C,QAAIA,IAAQ,KAAKA,KAAS,KAAK,KAAK,MAAM;AACxC,aAAO;AAGT,QAAIA,MAAU,KAAK,KAAK,MAAM,SAAS;AACrC,aAAO;AAGT,UAAMC,IAAO,KAAK,K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AClB,WAAO,KAAK,qBAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,cAAc;AAChB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,cAAc;AAChB,WAAO,KAAK,qBAAA;AAAA,EACd;AACF;","x_google_ignoreList":[1]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@music-lyric-player/base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"author": "folltoshe",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Music Lyric Player - Base Player",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@music-lyric-kit/lyric": "^0.4.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@music-lyric-player/utils": "^0.
|
|
35
|
+
"@music-lyric-player/utils": "^0.3.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "vite build"
|