Skip to content

Commit 510098e

Browse files
committed
docs: 将首页嵌入歌词组件用作效果展示
core: 修正对样式文件的打包产物引用 all: 更新依赖
1 parent e05c19b commit 510098e

File tree

24 files changed

+2677
-2600
lines changed

24 files changed

+2677
-2600
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"license": "GPL-3.0",
55
"devDependencies": {
66
"@biomejs/biome": "^1.9.4",
7-
"lerna": "^8.1.9"
7+
"lerna": "^8.1.9",
8+
"typescript": "^5.7.3"
89
}
9-
}
10+
}

packages/bncm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"stats.js": "^0.17.0",
5555
"svgo": "^3.3.2",
5656
"terser": "^5.36.0",
57-
"typescript": "^5.6.3",
57+
"typescript": "^5.7.3",
5858
"typescript-event-target": "^1.1.1",
5959
"uuid": "^11.0.3",
6060
"vite": "^5.4.11",

packages/core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"require": "./dist/amll-core.cjs"
3535
},
3636
"./style.css": {
37-
"import": "./dist/style.css",
38-
"require": "./dist/style.css"
37+
"import": "./dist/amll-core.css",
38+
"require": "./dist/amll-core.css"
3939
}
4040
},
4141
"devDependencies": {
@@ -49,7 +49,7 @@
4949
"stats.js": "^0.17.0",
5050
"typedoc": "^0.26.11",
5151
"typedoc-plugin-markdown": "^4.2.10",
52-
"typescript": "^5.6.3",
52+
"typescript": "^5.7.3",
5353
"vite": "^5.4.11",
5454
"vite-plugin-dts": "^4.3.0",
5555
"vite-plugin-glsl": "^1.3.0",

packages/core/src/lyric-player/dom/lyric-line.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function generateFadeGradient(
5757

5858
export class RawLyricLineMouseEvent extends MouseEvent {
5959
constructor(
60-
public readonly line: LyricLineEl,
60+
public readonly line: LyricLineBase,
6161
event: MouseEvent,
6262
) {
6363
super(event.type, event);

packages/docs/astro.config.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import starlight from "@astrojs/starlight";
33
import { defineConfig } from "astro/config";
44
import { createStarlightTypeDocPlugin } from "starlight-typedoc";
55

6+
import react from "@astrojs/react";
7+
68
const [coreStarlightTypeDoc, coreTypeDocSidebarGroup] =
79
createStarlightTypeDocPlugin();
810
const [reactStarlightTypeDoc, reactTypeDocSidebarGroup] =
@@ -18,6 +20,7 @@ const [lyricStarlightTypeDoc, lyricTypeDocSidebarGroup] =
1820
export default defineConfig({
1921
base: "applemusic-like-lyrics",
2022
integrations: [
23+
react(),
2124
starlight({
2225
favicon: "favicon.ico",
2326
title: "Apple Music-like Lyrics",
@@ -56,6 +59,9 @@ export default defineConfig({
5659
label: "react",
5760
collapsed: true,
5861
},
62+
typeDoc: {
63+
plugin: ["typedoc-plugin-mark-react-functional-components"],
64+
},
5965
}),
6066
vueStarlightTypeDoc({
6167
entryPoints: ["../vue/src/index.ts"],
@@ -65,6 +71,9 @@ export default defineConfig({
6571
label: "vue",
6672
collapsed: true,
6773
},
74+
typeDoc: {
75+
plugin: ["typedoc-plugin-vue"],
76+
},
6877
}),
6978
reactFullStarlightTypeDoc({
7079
entryPoints: ["../react-full/src/index.ts"],
@@ -74,6 +83,9 @@ export default defineConfig({
7483
label: "react-full",
7584
collapsed: true,
7685
},
86+
typeDoc: {
87+
plugin: ["typedoc-plugin-mark-react-functional-components"],
88+
},
7789
}),
7890
lyricStarlightTypeDoc({
7991
entryPoints: ["../lyric/src/types.d.ts"],

packages/docs/package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,23 @@
1010
"astro": "astro"
1111
},
1212
"dependencies": {
13+
"@applemusic-like-lyrics/core": "workspace:^",
14+
"@applemusic-like-lyrics/react": "workspace:^",
15+
"@applemusic-like-lyrics/react-full": "workspace:^",
16+
"@astrojs/react": "^4.1.5",
1317
"@astrojs/starlight": "^0.30.4",
18+
"@types/react": "^18.3.12",
19+
"@types/react-dom": "^18.3.1",
1420
"astro": "^5.0.2",
21+
"react": "^18.3.1",
22+
"react-dom": "^18.3.1",
1523
"sharp": "^0.32.5"
1624
},
1725
"devDependencies": {
1826
"starlight-typedoc": "^0.18.0",
1927
"typedoc": "^0.26.11",
20-
"typedoc-plugin-markdown": "^4.2.10"
28+
"typedoc-plugin-mark-react-functional-components": "^0.2.2",
29+
"typedoc-plugin-markdown": "^4.2.10",
30+
"typedoc-plugin-vue": "^1.3.0"
2131
}
2232
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import type { LyricLine } from "@applemusic-like-lyrics/core";
2+
import "@applemusic-like-lyrics/core/style.css";
3+
import { LyricPlayer } from "@applemusic-like-lyrics/react";
4+
import { useLayoutEffect, useRef, useState } from "react";
5+
6+
const buildLyricLines = (
7+
lyric: string,
8+
startTime = 1000,
9+
otherParams: Partial<LyricLine> = {},
10+
): LyricLine => {
11+
let curTime = startTime;
12+
const words = [];
13+
for (const word of lyric.split("|")) {
14+
const [text, duration] = word.split(",");
15+
const endTime = curTime + Number.parseInt(duration);
16+
words.push({
17+
word: text,
18+
startTime: curTime,
19+
endTime,
20+
obscene: false,
21+
});
22+
curTime = endTime;
23+
}
24+
return {
25+
startTime,
26+
endTime: curTime + 3000,
27+
translatedLyric: "",
28+
romanLyric: "",
29+
isBG: false,
30+
isDuet: false,
31+
words,
32+
...otherParams,
33+
};
34+
};
35+
36+
const DEMO_LYRICS: LyricLine[][] = [
37+
[
38+
buildLyricLines(
39+
"Apple ,750|Music ,500|Like ,500|Ly,400|ri,500|cs ,250",
40+
1000,
41+
{
42+
translatedLyric: "类苹果歌词",
43+
},
44+
),
45+
// A lyric component library for the web
46+
buildLyricLines(
47+
"A ,400|ly,500|ric ,250|com,500|po,500|nent ,500|li,500|bra,500|ry ,500|for ,500|the ,500|web ,500",
48+
7000,
49+
{
50+
translatedLyric: "为 Web 而生的歌词组件库",
51+
},
52+
),
53+
// Brought to you with
54+
buildLyricLines("Brought ,500|to ,250|you ,800|with ,600", 16000, {
55+
translatedLyric: "为你带来",
56+
}),
57+
// Background Lyric Line
58+
buildLyricLines("Background ,750|Lyric ,300|Line ,500", 16500, {
59+
translatedLyric: "背景歌词行",
60+
isBG: true,
61+
}),
62+
// And Duet Lyric Line
63+
buildLyricLines("And ,300|Duet ,500|Lyric ,500|Line ,750", 21150, {
64+
translatedLyric: "还有对唱歌词行",
65+
isDuet: true,
66+
}),
67+
],
68+
];
69+
70+
export const AMLLPreview = () => {
71+
const [lyricLines, setLyricLines] = useState<LyricLine[]>([]);
72+
const [currentTime, setCurrentTime] = useState(0);
73+
const wRef = useRef<HTMLDivElement>(null);
74+
75+
useLayoutEffect(() => {
76+
let selectedDemo = DEMO_LYRICS.length - 1;
77+
let endTime = 0;
78+
let startTime = 0;
79+
let canceled = false;
80+
81+
const onFrame = (time: number) => {
82+
if (canceled) return;
83+
if (time - startTime > endTime) {
84+
const w = wRef.current;
85+
if (!w) {
86+
if (canceled) return;
87+
return;
88+
}
89+
if (canceled) return;
90+
91+
w.animate(
92+
{
93+
opacity: 0,
94+
filter: "blur(10px)",
95+
},
96+
{
97+
duration: 500,
98+
easing: "ease-in-out",
99+
fill: "forwards",
100+
},
101+
).onfinish = () => {
102+
if (canceled) return;
103+
104+
selectedDemo = (selectedDemo + 1) % DEMO_LYRICS.length;
105+
setLyricLines(JSON.parse(JSON.stringify(DEMO_LYRICS[selectedDemo])));
106+
endTime = DEMO_LYRICS[selectedDemo].reduce(
107+
(acc, v) => Math.max(acc, v.endTime),
108+
0,
109+
);
110+
startTime = time;
111+
112+
setTimeout(() => {
113+
if (canceled) return;
114+
w.animate(
115+
{
116+
opacity: 1,
117+
filter: "blur(0px)",
118+
},
119+
{
120+
duration: 500,
121+
easing: "ease-in-out",
122+
fill: "forwards",
123+
},
124+
).onfinish = () => {
125+
if (canceled) return;
126+
requestAnimationFrame(onFrame);
127+
};
128+
}, 1000);
129+
};
130+
} else {
131+
setCurrentTime((time - startTime) | 0);
132+
requestAnimationFrame(onFrame);
133+
}
134+
};
135+
136+
requestAnimationFrame(onFrame);
137+
return () => {
138+
canceled = true;
139+
};
140+
}, []);
141+
142+
return (
143+
<div
144+
style={{
145+
height: "100%",
146+
maskImage:
147+
"linear-gradient(to bottom, transparent 0%, white 5%, white 95%, transparent 100%)",
148+
transition: "opacity 0.5s, filter 0.5s",
149+
}}
150+
ref={wRef}
151+
>
152+
<LyricPlayer
153+
currentTime={currentTime}
154+
lyricLines={lyricLines}
155+
alignAnchor="top"
156+
alignPosition={0.05}
157+
style={{
158+
height: "100%",
159+
}}
160+
/>
161+
</div>
162+
);
163+
};

packages/docs/src/content/docs/index.mdx

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
import { Aside } from "@astrojs/starlight/components";
3+
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro";
4+
import { AMLLPreview } from "../components/AMLLPreview";
5+
import "../styles/index.css";
6+
7+
// description: 专为网页开发的歌词播放页面组件库
8+
// template: splash
9+
// # hero:
10+
// # tagline: 专为网页开发的歌词播放页面组件库
11+
// # image:
12+
// # file: ../../assets/amll-logo.png
13+
// # actions:
14+
// # - text: 快速入门
15+
// # link: /applemusic-like-lyrics/guides/core/introduction
16+
// # icon: right-arrow
17+
// # - text: 接口参考
18+
// # link: /applemusic-like-lyrics/reference/core/classes/lyricplayer
19+
// # icon: external
20+
// # variant: minimal
21+
---
22+
23+
<StarlightPage frontmatter={{
24+
title: "类苹果歌词",
25+
description: "专为网页开发的歌词播放页面组件库",
26+
template: "splash",
27+
}} lang="zh-CN">
28+
<div style="height: max(500px, 50vh);">
29+
<AMLLPreview client:only="react" />
30+
</div>
31+
<Aside type="caution">
32+
本文档仍在编写当中!内容尚未完成!
33+
</Aside>
34+
</StarlightPage>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
:root[data-theme="light"] {
22
--sl-color-accent-high: #f96868;
3+
--sl-color-text-invert: #fee;
34
--sl-color-accent: #ff4040;
45
}
56

67
:root[data-theme="dark"] {
78
--sl-color-accent-high: #f96868;
9+
--sl-color-text-invert: #fffefe;
810
--sl-color-accent: #ff4040;
11+
--sl-color-bg: #111111;
12+
--sl-color-bg-nav: #111111;
913
}

0 commit comments

Comments
 (0)