@xiping/react-components 1.0.55 → 1.0.58
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/cjs/components/blur-text/BlurText.d.ts +16 -0
- package/dist/cjs/components/blur-text/BlurText.js +1 -0
- package/dist/cjs/components/blur-text/index.d.ts +2 -0
- package/dist/cjs/components/button/Button.css +1 -0
- package/dist/cjs/components/button/Button.js +1 -1
- package/dist/cjs/components/comic-text/ComicText.css +1 -0
- package/dist/cjs/components/comic-text/ComicText.js +2 -2
- package/dist/cjs/components/dock/Duck.css +1 -0
- package/dist/cjs/components/dock/Duck.d.ts +2 -4
- package/dist/cjs/components/dock/Duck.js +1 -1
- package/dist/cjs/components/flip-text/FlipText.css +1 -0
- package/dist/cjs/components/flip-text/FlipText.js +1 -1
- package/dist/cjs/components/gradient-text/index.css +1 -0
- package/dist/cjs/components/gradient-text/index.js +1 -1
- package/dist/cjs/components/hyper-text/HyperText.css +1 -0
- package/dist/cjs/components/hyper-text/index.js +1 -1
- package/dist/cjs/components/image-compare/ImageCompare.css +1 -0
- package/dist/cjs/components/image-compare/ImageCompare.d.ts +4 -2
- package/dist/cjs/components/image-compare/ImageCompare.js +1 -1
- package/dist/cjs/components/image-viewer/ImageThumbnails.css +1 -0
- package/dist/cjs/components/image-viewer/ImageThumbnails.js +1 -1
- package/dist/cjs/components/image-viewer/ImageViewer.css +1 -0
- package/dist/cjs/components/image-viewer/ImageViewer.js +1 -1
- package/dist/cjs/components/message/Message.css +1 -0
- package/dist/cjs/components/message/Message.js +1 -1
- package/dist/cjs/components/pointer/Pointer.css +1 -0
- package/dist/cjs/components/pointer/Pointer.js +1 -1
- package/dist/cjs/components/scratch-to-reveal/ScratchToReveal.css +1 -0
- package/dist/cjs/components/scratch-to-reveal/ScratchToReveal.js +1 -1
- package/dist/cjs/components/shimmer-button/ShimmerButton.css +1 -0
- package/dist/cjs/components/shimmer-button/ShimmerButton.js +1 -1
- package/dist/cjs/components/shiny-button/ShinyButton.css +1 -0
- package/dist/cjs/components/shiny-button/ShinyButton.js +1 -1
- package/dist/cjs/components/shiny-text/ShinyText.css +1 -0
- package/dist/cjs/components/shiny-text/ShinyText.d.ts +16 -0
- package/dist/cjs/components/shiny-text/ShinyText.js +1 -0
- package/dist/cjs/components/shiny-text/index.d.ts +2 -0
- package/dist/cjs/components/sparkles-text/SparklesText.css +1 -0
- package/dist/cjs/components/sparkles-text/SparklesText.js +1 -1
- package/dist/cjs/components/split-text/SplitText.css +1 -0
- package/dist/cjs/components/split-text/SplitText.js +1 -1
- package/dist/cjs/components/subtitle-player/CurrentMode.css +1 -0
- package/dist/cjs/components/subtitle-player/CurrentMode.d.ts +2 -0
- package/dist/cjs/components/subtitle-player/CurrentMode.js +2 -2
- package/dist/cjs/components/subtitle-player/LyricsMode.css +1 -0
- package/dist/cjs/components/subtitle-player/LyricsMode.d.ts +2 -0
- package/dist/cjs/components/subtitle-player/LyricsMode.js +2 -2
- package/dist/cjs/components/subtitle-player/SubtitlePlayer.css +1 -0
- package/dist/cjs/components/subtitle-player/SubtitlePlayer.d.ts +2 -0
- package/dist/cjs/components/subtitle-player/SubtitlePlayer.js +1 -1
- package/dist/cjs/components/text-animate/TextAnimate.css +1 -0
- package/dist/cjs/components/text-animate/TextAnimate.js +2 -2
- package/dist/cjs/components/text-type/TextType.css +1 -0
- package/dist/cjs/components/text-type/TextType.js +1 -1
- package/dist/cjs/components/txt-reader/index.module.css +1 -0
- package/dist/cjs/components/txt-reader/index.module.css.js +1 -1
- package/dist/cjs/components/typing-animation/index.css +1 -0
- package/dist/cjs/components/typing-animation/index.js +1 -1
- package/dist/cjs/components/variable-proximity/index.css +1 -0
- package/dist/cjs/components/variable-proximity/index.js +1 -1
- package/dist/cjs/components/video-dialog/VideoDialog.css +1 -0
- package/dist/cjs/components/video-dialog/VideoDialog.js +1 -1
- package/dist/cjs/components/video-subtitle-player/VideoSubtitlePlayer.css +1 -0
- package/dist/cjs/components/video-subtitle-player/VideoSubtitlePlayer.d.ts +3 -3
- package/dist/cjs/components/video-subtitle-player/VideoSubtitlePlayer.js +1 -1
- package/dist/cjs/components/video-subtitle-player/VideoSubtitlePlayer.mobile.css +1 -0
- package/dist/cjs/components/video-subtitle-player/VideoSubtitlePlayer.pc.css +1 -0
- package/dist/cjs/components/video-subtitle-player/VideoSubtitlePlayerMobile.d.ts +20 -0
- package/dist/cjs/components/video-subtitle-player/VideoSubtitlePlayerMobile.js +1 -0
- package/dist/cjs/components/video-subtitle-player/VideoSubtitlePlayerPC.d.ts +23 -0
- package/dist/cjs/components/video-subtitle-player/VideoSubtitlePlayerPC.js +1 -0
- package/dist/cjs/components/video-subtitle-player/layouts/VideoSubtitlePlayerLayoutMobile.d.ts +8 -0
- package/dist/cjs/components/video-subtitle-player/layouts/VideoSubtitlePlayerLayoutMobile.js +1 -0
- package/dist/cjs/components/video-subtitle-player/layouts/VideoSubtitlePlayerLayoutPC.d.ts +6 -0
- package/dist/cjs/components/video-subtitle-player/layouts/VideoSubtitlePlayerLayoutPC.js +1 -0
- package/dist/cjs/components/video-subtitle-player/layouts/index.d.ts +3 -0
- package/dist/cjs/components/video-subtitle-player/layouts/types.d.ts +17 -0
- package/dist/cjs/components/video-subtitle-player/useXGPlayer.d.ts +10 -0
- package/dist/cjs/components/video-subtitle-player/useXGPlayer.js +1 -0
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/llms.txt +2 -13
- package/dist/cjs/node_modules/.pnpm/xgplayer@3.0.23_core-js@3.47.0/node_modules/xgplayer/dist/index.min.css +1 -0
- package/dist/cjs/react-components.css +114 -1
- package/dist/es/components/blur-text/BlurText.d.ts +16 -0
- package/dist/es/components/blur-text/BlurText.js +77 -0
- package/dist/es/components/blur-text/index.d.ts +2 -0
- package/dist/es/components/button/Button.css +1 -0
- package/dist/es/components/button/Button.js +35 -46
- package/dist/es/components/comic-text/ComicText.css +1 -0
- package/dist/es/components/comic-text/ComicText.js +13 -12
- package/dist/es/components/dock/Duck.css +1 -0
- package/dist/es/components/dock/Duck.d.ts +2 -4
- package/dist/es/components/dock/Duck.js +60 -64
- package/dist/es/components/flip-text/FlipText.css +1 -0
- package/dist/es/components/flip-text/FlipText.js +8 -8
- package/dist/es/components/gradient-text/index.css +1 -0
- package/dist/es/components/gradient-text/index.js +9 -8
- package/dist/es/components/hyper-text/HyperText.css +1 -0
- package/dist/es/components/hyper-text/index.js +16 -13
- package/dist/es/components/image-compare/ImageCompare.css +1 -0
- package/dist/es/components/image-compare/ImageCompare.d.ts +4 -2
- package/dist/es/components/image-compare/ImageCompare.js +55 -48
- package/dist/es/components/image-viewer/ImageThumbnails.css +1 -0
- package/dist/es/components/image-viewer/ImageThumbnails.js +41 -42
- package/dist/es/components/image-viewer/ImageViewer.css +1 -0
- package/dist/es/components/image-viewer/ImageViewer.js +34 -35
- package/dist/es/components/message/Message.css +1 -0
- package/dist/es/components/message/Message.js +65 -54
- package/dist/es/components/pointer/Pointer.css +1 -0
- package/dist/es/components/pointer/Pointer.js +23 -25
- package/dist/es/components/scratch-to-reveal/ScratchToReveal.css +1 -0
- package/dist/es/components/scratch-to-reveal/ScratchToReveal.js +17 -16
- package/dist/es/components/shimmer-button/ShimmerButton.css +1 -0
- package/dist/es/components/shimmer-button/ShimmerButton.js +8 -8
- package/dist/es/components/shiny-button/ShinyButton.css +1 -0
- package/dist/es/components/shiny-button/ShinyButton.js +13 -13
- package/dist/es/components/shiny-text/ShinyText.css +1 -0
- package/dist/es/components/shiny-text/ShinyText.d.ts +16 -0
- package/dist/es/components/shiny-text/ShinyText.js +76 -0
- package/dist/es/components/shiny-text/index.d.ts +2 -0
- package/dist/es/components/sparkles-text/SparklesText.css +1 -0
- package/dist/es/components/sparkles-text/SparklesText.js +14 -14
- package/dist/es/components/split-text/SplitText.css +1 -0
- package/dist/es/components/split-text/SplitText.js +1 -1
- package/dist/es/components/subtitle-player/CurrentMode.css +1 -0
- package/dist/es/components/subtitle-player/CurrentMode.d.ts +2 -0
- package/dist/es/components/subtitle-player/CurrentMode.js +75 -40
- package/dist/es/components/subtitle-player/LyricsMode.css +1 -0
- package/dist/es/components/subtitle-player/LyricsMode.d.ts +2 -0
- package/dist/es/components/subtitle-player/LyricsMode.js +139 -68
- package/dist/es/components/subtitle-player/SubtitlePlayer.css +1 -0
- package/dist/es/components/subtitle-player/SubtitlePlayer.d.ts +2 -0
- package/dist/es/components/subtitle-player/SubtitlePlayer.js +63 -60
- package/dist/es/components/text-animate/TextAnimate.css +1 -0
- package/dist/es/components/text-animate/TextAnimate.js +57 -55
- package/dist/es/components/text-type/TextType.css +1 -0
- package/dist/es/components/text-type/TextType.js +24 -19
- package/dist/es/components/txt-reader/index.module.css +1 -0
- package/dist/es/components/txt-reader/index.module.css.js +1 -1
- package/dist/es/components/typing-animation/index.css +1 -0
- package/dist/es/components/typing-animation/index.js +12 -12
- package/dist/es/components/variable-proximity/index.css +1 -0
- package/dist/es/components/variable-proximity/index.js +19 -18
- package/dist/es/components/video-dialog/VideoDialog.css +1 -0
- package/dist/es/components/video-dialog/VideoDialog.js +1 -1
- package/dist/es/components/video-subtitle-player/VideoSubtitlePlayer.css +1 -0
- package/dist/es/components/video-subtitle-player/VideoSubtitlePlayer.d.ts +3 -3
- package/dist/es/components/video-subtitle-player/VideoSubtitlePlayer.js +69 -122
- package/dist/es/components/video-subtitle-player/VideoSubtitlePlayer.mobile.css +1 -0
- package/dist/es/components/video-subtitle-player/VideoSubtitlePlayer.pc.css +1 -0
- package/dist/es/components/video-subtitle-player/VideoSubtitlePlayerMobile.d.ts +20 -0
- package/dist/es/components/video-subtitle-player/VideoSubtitlePlayerMobile.js +47 -0
- package/dist/es/components/video-subtitle-player/VideoSubtitlePlayerPC.d.ts +23 -0
- package/dist/es/components/video-subtitle-player/VideoSubtitlePlayerPC.js +75 -0
- package/dist/es/components/video-subtitle-player/layouts/VideoSubtitlePlayerLayoutMobile.d.ts +8 -0
- package/dist/es/components/video-subtitle-player/layouts/VideoSubtitlePlayerLayoutMobile.js +21 -0
- package/dist/es/components/video-subtitle-player/layouts/VideoSubtitlePlayerLayoutPC.d.ts +6 -0
- package/dist/es/components/video-subtitle-player/layouts/VideoSubtitlePlayerLayoutPC.js +50 -0
- package/dist/es/components/video-subtitle-player/layouts/index.d.ts +3 -0
- package/dist/es/components/video-subtitle-player/layouts/types.d.ts +17 -0
- package/dist/es/components/video-subtitle-player/useXGPlayer.d.ts +10 -0
- package/dist/es/components/video-subtitle-player/useXGPlayer.js +36 -0
- package/dist/es/index.d.ts +2 -1
- package/dist/es/index.js +59 -60
- package/dist/es/llms.txt +2 -13
- package/dist/es/node_modules/.pnpm/xgplayer@3.0.23_core-js@3.47.0/node_modules/xgplayer/dist/index.min.css +1 -0
- package/dist/es/react-components.css +114 -1
- package/package.json +20 -15
- package/dist/cjs/components/animated-list/AnimatedList.d.ts +0 -9
- package/dist/cjs/components/animated-list/AnimatedList.js +0 -1
- package/dist/cjs/components/animated-list/index.d.ts +0 -1
- package/dist/cjs/utils/utils.js +0 -1
- package/dist/es/components/animated-list/AnimatedList.d.ts +0 -9
- package/dist/es/components/animated-list/AnimatedList.js +0 -44
- package/dist/es/components/animated-list/index.d.ts +0 -1
- package/dist/es/utils/utils.js +0 -8
|
@@ -1,81 +1,152 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import
|
|
4
|
-
import { secondsToTimeString as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { jsxs as $, Fragment as K, jsx as c } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as W, useMemo as I, useEffect as b, useCallback as j } from "react";
|
|
3
|
+
import A from "clsx";
|
|
4
|
+
import { secondsToTimeString as H, renderTextWithWords as L } from "./utils.js";
|
|
5
|
+
import './LyricsMode.css';/* empty css */
|
|
6
|
+
const M = ({
|
|
7
|
+
entry: t,
|
|
8
|
+
label: s,
|
|
9
|
+
endTime: v,
|
|
10
|
+
currentTime: _,
|
|
11
|
+
isActive: y,
|
|
12
|
+
isFirstItem: u,
|
|
13
|
+
timeString: g,
|
|
14
|
+
textAlign: N,
|
|
15
|
+
enableWordHover: d,
|
|
16
|
+
wordHoverFactory: h,
|
|
17
|
+
onSubtitleClick: n,
|
|
18
|
+
itemRef: e
|
|
13
19
|
}) => {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
const r = _ > v, i = j(
|
|
21
|
+
(m) => {
|
|
22
|
+
n && n(m, t, s);
|
|
23
|
+
},
|
|
24
|
+
[n, t, s]
|
|
25
|
+
), o = I(
|
|
26
|
+
() => d ? h(t, s) : void 0,
|
|
27
|
+
[d, h, t, s]
|
|
28
|
+
), l = I(() => t.text.split(`
|
|
29
|
+
`).reduce(
|
|
30
|
+
(p, x, a) => {
|
|
31
|
+
if (!t.words || t.words.length === 0)
|
|
32
|
+
return p.content.push(
|
|
33
|
+
/* @__PURE__ */ c(
|
|
34
|
+
"div",
|
|
35
|
+
{
|
|
36
|
+
className: "xiping-subtitle-player__lyrics-line",
|
|
37
|
+
children: x
|
|
38
|
+
},
|
|
39
|
+
a
|
|
40
|
+
)
|
|
41
|
+
), p;
|
|
42
|
+
const f = L(
|
|
43
|
+
x,
|
|
44
|
+
t.words,
|
|
45
|
+
p.nextWordIndex,
|
|
46
|
+
a,
|
|
47
|
+
o
|
|
48
|
+
);
|
|
49
|
+
return p.content.push(
|
|
50
|
+
/* @__PURE__ */ c(
|
|
51
|
+
"div",
|
|
52
|
+
{
|
|
53
|
+
className: "xiping-subtitle-player__lyrics-line",
|
|
54
|
+
children: f.nodes
|
|
55
|
+
},
|
|
56
|
+
a
|
|
57
|
+
)
|
|
58
|
+
), {
|
|
59
|
+
content: p.content,
|
|
60
|
+
nextWordIndex: f.nextWordIndex
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
{ content: [], nextWordIndex: 0 }
|
|
64
|
+
).content, [t.text, t.words, o]);
|
|
65
|
+
return /* @__PURE__ */ $(
|
|
66
|
+
"div",
|
|
67
|
+
{
|
|
68
|
+
ref: e,
|
|
69
|
+
className: A("xiping-subtitle-player__lyrics-item", {
|
|
70
|
+
"xiping-subtitle-player__lyrics-item--active": y,
|
|
71
|
+
"xiping-subtitle-player__lyrics-item--past": r
|
|
72
|
+
}),
|
|
73
|
+
"data-label": s || void 0,
|
|
74
|
+
onClick: n ? i : void 0,
|
|
75
|
+
style: n ? { cursor: "pointer" } : void 0,
|
|
76
|
+
children: [
|
|
77
|
+
u && g && /* @__PURE__ */ c("span", { className: "xiping-subtitle-player__lyrics-time", children: g }),
|
|
78
|
+
s && /* @__PURE__ */ c("span", { className: "xiping-subtitle-player__lyrics-label", children: s }),
|
|
79
|
+
/* @__PURE__ */ c(
|
|
80
|
+
"div",
|
|
81
|
+
{
|
|
82
|
+
className: "xiping-subtitle-player__lyrics-text",
|
|
83
|
+
style: { textAlign: N },
|
|
84
|
+
children: l
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}, q = ({
|
|
91
|
+
groupedEntriesByTime: t,
|
|
92
|
+
currentTime: s,
|
|
93
|
+
wordHoverFactory: v,
|
|
94
|
+
enableWordHover: _,
|
|
95
|
+
overlayNode: y,
|
|
96
|
+
containerRef: u,
|
|
97
|
+
onSubtitleClick: g,
|
|
98
|
+
textAlign: N = "left"
|
|
99
|
+
}) => {
|
|
100
|
+
const d = W(null), h = W(null), n = I(() => {
|
|
101
|
+
for (let e = 0; e < t.length; e++) {
|
|
102
|
+
const r = t[e];
|
|
103
|
+
for (let i = 0; i < r.length; i++) {
|
|
104
|
+
const { startTime: o, endTime: l } = r[i];
|
|
105
|
+
if (s >= o && s <= l)
|
|
106
|
+
return `${e}-${i}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}, [t, s]);
|
|
111
|
+
return b(() => {
|
|
112
|
+
if (n && n !== h.current && d.current && u.current) {
|
|
113
|
+
const e = u.current, r = d.current, i = r.offsetTop, o = e.clientHeight, l = r.clientHeight, m = i - o / 2 + l / 2;
|
|
18
114
|
e.scrollTo({
|
|
19
|
-
top:
|
|
115
|
+
top: m,
|
|
20
116
|
behavior: "smooth"
|
|
21
|
-
});
|
|
117
|
+
}), h.current = n;
|
|
22
118
|
}
|
|
23
|
-
}, [
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
119
|
+
}, [n, u]), /* @__PURE__ */ $(K, { children: [
|
|
120
|
+
t.map((e, r) => {
|
|
121
|
+
const i = e[0];
|
|
122
|
+
if (!i)
|
|
123
|
+
return null;
|
|
124
|
+
const o = H(i.startTime);
|
|
125
|
+
return /* @__PURE__ */ c("div", { className: "xiping-subtitle-player__group", children: e.map(({ entry: l, label: m, startTime: p, endTime: x }, a) => {
|
|
126
|
+
const f = s >= p && s <= x, w = `${r}-${a}`;
|
|
127
|
+
return /* @__PURE__ */ c(
|
|
128
|
+
M,
|
|
31
129
|
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
`).map((l, d) => {
|
|
45
|
-
if (!t.words || t.words.length === 0)
|
|
46
|
-
return /* @__PURE__ */ s(
|
|
47
|
-
"div",
|
|
48
|
-
{
|
|
49
|
-
className: "xiping-subtitle-player__line",
|
|
50
|
-
children: l
|
|
51
|
-
},
|
|
52
|
-
d
|
|
53
|
-
);
|
|
54
|
-
const f = A(
|
|
55
|
-
l,
|
|
56
|
-
t.words,
|
|
57
|
-
x,
|
|
58
|
-
d,
|
|
59
|
-
u ? N(t, i) : void 0
|
|
60
|
-
);
|
|
61
|
-
return x = f.nextWordIndex, /* @__PURE__ */ s(
|
|
62
|
-
"div",
|
|
63
|
-
{
|
|
64
|
-
className: "xiping-subtitle-player__line",
|
|
65
|
-
children: f.nodes
|
|
66
|
-
},
|
|
67
|
-
d
|
|
68
|
-
);
|
|
69
|
-
}) })
|
|
70
|
-
]
|
|
130
|
+
entry: l,
|
|
131
|
+
label: m,
|
|
132
|
+
endTime: x,
|
|
133
|
+
currentTime: s,
|
|
134
|
+
isActive: f,
|
|
135
|
+
isFirstItem: a === 0,
|
|
136
|
+
timeString: a === 0 ? o : void 0,
|
|
137
|
+
textAlign: N,
|
|
138
|
+
enableWordHover: _,
|
|
139
|
+
wordHoverFactory: v,
|
|
140
|
+
onSubtitleClick: g,
|
|
141
|
+
itemRef: f ? d : void 0
|
|
71
142
|
},
|
|
72
|
-
|
|
143
|
+
w
|
|
73
144
|
);
|
|
74
145
|
}) }, r);
|
|
75
146
|
}),
|
|
76
|
-
|
|
147
|
+
_ && /* @__PURE__ */ c("div", { className: "xiping-subtitle-player__lyrics-hover-layer", children: y })
|
|
77
148
|
] });
|
|
78
149
|
};
|
|
79
150
|
export {
|
|
80
|
-
|
|
151
|
+
q as LyricsMode
|
|
81
152
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.xiping-subtitle-player{display:flex;flex-direction:column;gap:.75rem;padding:1rem;background:#000000bf;border-radius:.5rem;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);color:#fff;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;line-height:1.6;max-width:100%;box-sizing:border-box;position:relative}.xiping-subtitle-player__hover-overlay{position:absolute;transform:translate(-50%,.5rem);z-index:10;pointer-events:auto}.xiping-subtitle-player:has(.xiping-subtitle-player__current-item:only-child){align-items:center}.xiping-subtitle-player:has(.xiping-subtitle-player__current-item:not(:only-child)){align-items:flex-start}.xiping-subtitle-word{display:inline-block;position:relative;transition:all .2s ease;padding:0 .05em;margin:0 .05em;border-radius:2px}.xiping-subtitle-word:hover{background-color:#ffffff1a;transform:translateY(-1px)}.xiping-subtitle-word-before,.xiping-subtitle-word-after{display:inline}@media(max-width:768px){.xiping-subtitle-player{padding:.75rem;font-size:.9rem}}
|
|
@@ -19,6 +19,8 @@ export interface SubtitlePlayerProps {
|
|
|
19
19
|
currentTime: number;
|
|
20
20
|
/** 显示模式:'current' 只显示当前字幕,'lyrics' 显示全部字幕并高亮当前 */
|
|
21
21
|
mode?: SubtitleDisplayMode;
|
|
22
|
+
/** 文本对齐方式:'left' 左对齐,'center' 居中,默认为 'left' */
|
|
23
|
+
textAlign?: "left" | "center";
|
|
22
24
|
/** 自定义类名 */
|
|
23
25
|
className?: string;
|
|
24
26
|
/** 自定义样式 */
|
|
@@ -1,35 +1,36 @@
|
|
|
1
|
-
import { jsx as S, jsxs as
|
|
2
|
-
import { useMemo as
|
|
1
|
+
import { jsx as S, jsxs as F } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as f, useRef as G, useState as D, useEffect as V, useCallback as u } from "react";
|
|
3
3
|
import { parseSRT as w, parseVTT as v } from "../../packages/subtitle/lib/src/parser.js";
|
|
4
|
-
import { srtToJson as
|
|
5
|
-
import
|
|
6
|
-
import { CurrentMode as
|
|
7
|
-
import { LyricsMode as
|
|
8
|
-
import { getCurrentSubtitleEntry as
|
|
9
|
-
|
|
10
|
-
const
|
|
4
|
+
import { srtToJson as q, vttToJson as K } from "../../packages/subtitle/lib/src/json-converter.js";
|
|
5
|
+
import Q from "clsx";
|
|
6
|
+
import { CurrentMode as U } from "./CurrentMode.js";
|
|
7
|
+
import { LyricsMode as X } from "./LyricsMode.js";
|
|
8
|
+
import { getCurrentSubtitleEntry as Y, timeStringToSeconds as J } from "./utils.js";
|
|
9
|
+
import './SubtitlePlayer.css';/* empty css */
|
|
10
|
+
const ct = ({
|
|
11
11
|
subtitles: p,
|
|
12
|
-
currentTime:
|
|
12
|
+
currentTime: h,
|
|
13
13
|
mode: m = "current",
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
textAlign: E = "left",
|
|
15
|
+
className: L = "",
|
|
16
|
+
style: A,
|
|
16
17
|
onWordHoverChange: a,
|
|
17
18
|
renderWordOverlay: d,
|
|
18
19
|
onWordClick: y,
|
|
19
20
|
onSubtitleClick: T
|
|
20
21
|
}) => {
|
|
21
|
-
const i =
|
|
22
|
+
const i = f(
|
|
22
23
|
() => Array.isArray(p) ? p : [p],
|
|
23
24
|
[p]
|
|
24
|
-
), l =
|
|
25
|
-
|
|
25
|
+
), l = G(null), [s, M] = D(null), [R, b] = D([]);
|
|
26
|
+
V(() => {
|
|
26
27
|
let r = !0;
|
|
27
28
|
async function c() {
|
|
28
29
|
try {
|
|
29
30
|
const e = await Promise.all(
|
|
30
31
|
i.map(async (t) => {
|
|
31
32
|
try {
|
|
32
|
-
const n = t.language || "zh", o = t.type === "srt" ? await
|
|
33
|
+
const n = t.language || "zh", o = t.type === "srt" ? await q(t.content, n) : await K(t.content, n);
|
|
33
34
|
return {
|
|
34
35
|
entries: JSON.parse(o),
|
|
35
36
|
label: t.label
|
|
@@ -42,7 +43,7 @@ const ot = ({
|
|
|
42
43
|
}
|
|
43
44
|
})
|
|
44
45
|
);
|
|
45
|
-
r &&
|
|
46
|
+
r && b(e);
|
|
46
47
|
} catch (e) {
|
|
47
48
|
if (console.error("加载字幕失败:", e), r) {
|
|
48
49
|
const t = i.map((n) => {
|
|
@@ -58,7 +59,7 @@ const ot = ({
|
|
|
58
59
|
};
|
|
59
60
|
}
|
|
60
61
|
});
|
|
61
|
-
|
|
62
|
+
b(t);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -66,7 +67,7 @@ const ot = ({
|
|
|
66
67
|
r = !1;
|
|
67
68
|
};
|
|
68
69
|
}, [i]);
|
|
69
|
-
const g =
|
|
70
|
+
const g = f(() => R.length > 0 ? R : i.map((r) => {
|
|
70
71
|
try {
|
|
71
72
|
return {
|
|
72
73
|
entries: r.type === "srt" ? w(r.content) : v(r.content),
|
|
@@ -78,20 +79,20 @@ const ot = ({
|
|
|
78
79
|
label: r.label
|
|
79
80
|
};
|
|
80
81
|
}
|
|
81
|
-
}), [R, i]),
|
|
82
|
-
entry:
|
|
82
|
+
}), [R, i]), W = f(() => g.map(({ entries: r, label: c }) => ({
|
|
83
|
+
entry: Y(r, h),
|
|
83
84
|
label: c,
|
|
84
85
|
entries: r
|
|
85
86
|
// 保留所有条目用于歌词模式
|
|
86
|
-
})), [g,
|
|
87
|
+
})), [g, h]), _ = f(() => {
|
|
87
88
|
const r = [];
|
|
88
89
|
g.forEach(({ entries: t, label: n }) => {
|
|
89
90
|
t.forEach((o) => {
|
|
90
91
|
r.push({
|
|
91
92
|
entry: o,
|
|
92
93
|
label: n,
|
|
93
|
-
startTime:
|
|
94
|
-
endTime:
|
|
94
|
+
startTime: J(o.startTime),
|
|
95
|
+
endTime: J(o.endTime)
|
|
95
96
|
});
|
|
96
97
|
});
|
|
97
98
|
}), r.sort((t, n) => t.startTime - n.startTime);
|
|
@@ -105,7 +106,7 @@ const ot = ({
|
|
|
105
106
|
t.startTime <= n.endTime ? e.push(t) : (c.push(e), e = [t]);
|
|
106
107
|
}
|
|
107
108
|
return e.length > 0 && c.push(e), c;
|
|
108
|
-
}, [g]),
|
|
109
|
+
}, [g]), x = u(
|
|
109
110
|
(r, c) => {
|
|
110
111
|
const e = r.currentTarget.getBoundingClientRect(), t = l.current?.getBoundingClientRect(), n = t !== void 0 ? new DOMRect(
|
|
111
112
|
e.left - t.left,
|
|
@@ -117,12 +118,12 @@ const ot = ({
|
|
|
117
118
|
rect: n,
|
|
118
119
|
element: r.currentTarget
|
|
119
120
|
};
|
|
120
|
-
|
|
121
|
+
M(o), a?.(o);
|
|
121
122
|
},
|
|
122
123
|
[a]
|
|
123
|
-
),
|
|
124
|
-
|
|
125
|
-
}, [a]),
|
|
124
|
+
), B = u(() => {
|
|
125
|
+
M(null), a?.(null);
|
|
126
|
+
}, [a]), C = u(
|
|
126
127
|
(r, c) => {
|
|
127
128
|
if (!y) return;
|
|
128
129
|
r.stopPropagation();
|
|
@@ -140,36 +141,36 @@ const ot = ({
|
|
|
140
141
|
y(o);
|
|
141
142
|
},
|
|
142
143
|
[y]
|
|
143
|
-
),
|
|
144
|
+
), N = u(
|
|
144
145
|
(r, c, e) => {
|
|
145
146
|
if (!T || r.target.closest(".xiping-subtitle-word"))
|
|
146
147
|
return;
|
|
147
|
-
const n = r.currentTarget.getBoundingClientRect(), o = l.current?.getBoundingClientRect(),
|
|
148
|
+
const n = r.currentTarget.getBoundingClientRect(), o = l.current?.getBoundingClientRect(), k = o !== void 0 ? new DOMRect(
|
|
148
149
|
n.left - o.left,
|
|
149
150
|
n.top - o.top,
|
|
150
151
|
n.width,
|
|
151
152
|
n.height
|
|
152
|
-
) : n,
|
|
153
|
+
) : n, z = {
|
|
153
154
|
type: "subtitle",
|
|
154
155
|
entry: c,
|
|
155
156
|
label: e,
|
|
156
|
-
rect:
|
|
157
|
+
rect: k,
|
|
157
158
|
element: r.currentTarget
|
|
158
159
|
};
|
|
159
|
-
T(
|
|
160
|
+
T(z);
|
|
160
161
|
},
|
|
161
162
|
[T]
|
|
162
|
-
),
|
|
163
|
+
), O = u(
|
|
163
164
|
(r, c) => (e, t, n) => ({
|
|
164
|
-
onMouseEnter: (o) =>
|
|
165
|
+
onMouseEnter: (o) => x(o, {
|
|
165
166
|
word: e,
|
|
166
167
|
wordIndex: t,
|
|
167
168
|
lineIndex: n,
|
|
168
169
|
entry: r,
|
|
169
170
|
label: c
|
|
170
171
|
}),
|
|
171
|
-
onMouseLeave:
|
|
172
|
-
onClick: (o) =>
|
|
172
|
+
onMouseLeave: B,
|
|
173
|
+
onClick: (o) => C(o, {
|
|
173
174
|
word: e,
|
|
174
175
|
wordIndex: t,
|
|
175
176
|
lineIndex: n,
|
|
@@ -177,8 +178,8 @@ const ot = ({
|
|
|
177
178
|
label: c
|
|
178
179
|
})
|
|
179
180
|
}),
|
|
180
|
-
[
|
|
181
|
-
),
|
|
181
|
+
[x, B, C]
|
|
182
|
+
), P = d && s ? /* @__PURE__ */ S(
|
|
182
183
|
"div",
|
|
183
184
|
{
|
|
184
185
|
className: "xiping-subtitle-player__hover-overlay",
|
|
@@ -188,38 +189,40 @@ const ot = ({
|
|
|
188
189
|
},
|
|
189
190
|
children: d(s)
|
|
190
191
|
}
|
|
191
|
-
) : null,
|
|
192
|
-
return /* @__PURE__ */
|
|
192
|
+
) : null, j = !!(d || a);
|
|
193
|
+
return /* @__PURE__ */ F(
|
|
193
194
|
"div",
|
|
194
195
|
{
|
|
195
196
|
ref: l,
|
|
196
|
-
className:
|
|
197
|
+
className: Q(
|
|
197
198
|
"xiping-subtitle-player",
|
|
198
199
|
m === "lyrics" ? "xiping-subtitle-player--lyrics" : "xiping-subtitle-player--current",
|
|
199
|
-
|
|
200
|
+
L
|
|
200
201
|
),
|
|
201
|
-
style:
|
|
202
|
+
style: A,
|
|
202
203
|
children: [
|
|
203
204
|
m === "current" && /* @__PURE__ */ S(
|
|
204
|
-
|
|
205
|
+
U,
|
|
205
206
|
{
|
|
206
|
-
currentEntries:
|
|
207
|
-
wordHoverFactory:
|
|
208
|
-
enableWordHover:
|
|
209
|
-
overlayNode:
|
|
210
|
-
onSubtitleClick:
|
|
207
|
+
currentEntries: W,
|
|
208
|
+
wordHoverFactory: O,
|
|
209
|
+
enableWordHover: j,
|
|
210
|
+
overlayNode: P,
|
|
211
|
+
onSubtitleClick: N,
|
|
212
|
+
textAlign: E
|
|
211
213
|
}
|
|
212
214
|
),
|
|
213
215
|
m === "lyrics" && /* @__PURE__ */ S(
|
|
214
|
-
|
|
216
|
+
X,
|
|
215
217
|
{
|
|
216
|
-
groupedEntriesByTime:
|
|
217
|
-
currentTime:
|
|
218
|
-
wordHoverFactory:
|
|
219
|
-
enableWordHover:
|
|
220
|
-
overlayNode:
|
|
218
|
+
groupedEntriesByTime: _,
|
|
219
|
+
currentTime: h,
|
|
220
|
+
wordHoverFactory: O,
|
|
221
|
+
enableWordHover: j,
|
|
222
|
+
overlayNode: P,
|
|
221
223
|
containerRef: l,
|
|
222
|
-
onSubtitleClick:
|
|
224
|
+
onSubtitleClick: N,
|
|
225
|
+
textAlign: E
|
|
223
226
|
}
|
|
224
227
|
)
|
|
225
228
|
]
|
|
@@ -227,6 +230,6 @@ const ot = ({
|
|
|
227
230
|
);
|
|
228
231
|
};
|
|
229
232
|
export {
|
|
230
|
-
|
|
231
|
-
|
|
233
|
+
ct as SubtitlePlayer,
|
|
234
|
+
ct as default
|
|
232
235
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.xiping-text-animate{white-space:pre-wrap}.xiping-text-animate-segment{display:inline-block;white-space:pre}.xiping-text-animate-segment--line{display:block}
|