@xiping/react-components 1.0.40 → 1.0.45

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.
Files changed (49) hide show
  1. package/dist/cjs/components/flip-text/FlipText.js +1 -1
  2. package/dist/cjs/components/gradient-text/index.d.ts +10 -0
  3. package/dist/cjs/components/gradient-text/index.js +1 -0
  4. package/dist/cjs/components/hyper-text/index.js +1 -1
  5. package/dist/cjs/components/image-viewer/ImageViewer.js +1 -1
  6. package/dist/cjs/components/shimmer-button/ShimmerButton.js +1 -1
  7. package/dist/cjs/components/shiny-button/ShinyButton.js +1 -1
  8. package/dist/cjs/components/sparkles-text/SparklesText.js +1 -1
  9. package/dist/cjs/components/split-text/SplitText.js +1 -1
  10. package/dist/cjs/components/subtitle-player/SubtitlePlayer.d.ts +30 -0
  11. package/dist/cjs/components/subtitle-player/SubtitlePlayer.js +3 -0
  12. package/dist/cjs/components/subtitle-player/index.d.ts +2 -0
  13. package/dist/cjs/components/txt-editor/TxtEditor.d.ts +5 -4
  14. package/dist/cjs/components/txt-editor/TxtEditor.js +32 -1
  15. package/dist/cjs/components/txt-reader/TxtReader.js +1 -1
  16. package/dist/cjs/components/txt-reader/index.module.css.js +1 -1
  17. package/dist/cjs/components/typing-animation/index.js +1 -1
  18. package/dist/cjs/components/variable-proximity/index.d.ts +25 -0
  19. package/dist/cjs/components/variable-proximity/index.js +1 -0
  20. package/dist/cjs/components/video-dialog/VideoDialog.js +1 -1
  21. package/dist/cjs/index.d.ts +3 -0
  22. package/dist/cjs/index.js +1 -1
  23. package/dist/cjs/react-components.css +1 -1
  24. package/dist/cjs/subtitle/lib/src/parser.js +5 -0
  25. package/dist/es/components/flip-text/FlipText.js +15 -14
  26. package/dist/es/components/gradient-text/index.d.ts +10 -0
  27. package/dist/es/components/gradient-text/index.js +22 -0
  28. package/dist/es/components/hyper-text/index.js +27 -25
  29. package/dist/es/components/image-viewer/ImageViewer.js +89 -65
  30. package/dist/es/components/shimmer-button/ShimmerButton.js +29 -62
  31. package/dist/es/components/shiny-button/ShinyButton.js +15 -17
  32. package/dist/es/components/sparkles-text/SparklesText.js +30 -29
  33. package/dist/es/components/split-text/SplitText.js +37 -35
  34. package/dist/es/components/subtitle-player/SubtitlePlayer.d.ts +30 -0
  35. package/dist/es/components/subtitle-player/SubtitlePlayer.js +103 -0
  36. package/dist/es/components/subtitle-player/index.d.ts +2 -0
  37. package/dist/es/components/txt-editor/TxtEditor.d.ts +5 -4
  38. package/dist/es/components/txt-editor/TxtEditor.js +102 -43
  39. package/dist/es/components/txt-reader/TxtReader.js +48 -55
  40. package/dist/es/components/txt-reader/index.module.css.js +6 -2
  41. package/dist/es/components/typing-animation/index.js +11 -13
  42. package/dist/es/components/variable-proximity/index.d.ts +25 -0
  43. package/dist/es/components/variable-proximity/index.js +212 -0
  44. package/dist/es/components/video-dialog/VideoDialog.js +35 -48
  45. package/dist/es/index.d.ts +3 -0
  46. package/dist/es/index.js +60 -54
  47. package/dist/es/react-components.css +1 -1
  48. package/dist/es/subtitle/lib/src/parser.js +56 -0
  49. package/package.json +16 -12
@@ -0,0 +1,103 @@
1
+ import { jsx as s, jsxs as T } from "react/jsx-runtime";
2
+ import { useRef as N, useMemo as S, useEffect as H } from "react";
3
+ import { parseSRT as $, parseVTT as C } from "../../subtitle/lib/src/parser.js";
4
+ /* empty css */
5
+ function d(i) {
6
+ const r = i.replace(",", ".").split(":");
7
+ if (r.length !== 3)
8
+ return 0;
9
+ const c = parseInt(r[0], 10) || 0, o = parseInt(r[1], 10) || 0, m = parseFloat(r[2]) || 0;
10
+ return c * 3600 + o * 60 + m;
11
+ }
12
+ function E(i, n) {
13
+ for (const r of i) {
14
+ const c = d(r.startTime), o = d(r.endTime);
15
+ if (n >= c && n <= o)
16
+ return r;
17
+ }
18
+ return null;
19
+ }
20
+ const B = ({
21
+ subtitles: i,
22
+ currentTime: n,
23
+ mode: r = "current",
24
+ className: c = "",
25
+ style: o
26
+ }) => {
27
+ const m = Array.isArray(i) ? i : [i], f = N(null), y = N(null), b = S(() => m.map((e) => {
28
+ try {
29
+ return {
30
+ entries: e.type === "srt" ? $(e.content) : C(e.content),
31
+ label: e.label
32
+ };
33
+ } catch (t) {
34
+ return console.error("字幕解析失败:", t), {
35
+ entries: [],
36
+ label: e.label
37
+ };
38
+ }
39
+ }), [m]), h = S(() => b.map(({ entries: e, label: t }) => ({
40
+ entry: E(e, n),
41
+ label: t,
42
+ entries: e
43
+ // 保留所有条目用于歌词模式
44
+ })), [b, n]);
45
+ return H(() => {
46
+ if (r === "lyrics" && y.current && f.current) {
47
+ const e = f.current, t = y.current;
48
+ e.getBoundingClientRect(), t.getBoundingClientRect(), e.scrollTop;
49
+ const l = t.offsetTop, a = e.clientHeight, u = t.clientHeight, p = l - a / 2 + u / 2;
50
+ e.scrollTo({
51
+ top: p,
52
+ behavior: "smooth"
53
+ });
54
+ }
55
+ }, [r, n]), r === "current" ? h.some(({ entry: t }) => t !== null) ? /* @__PURE__ */ s(
56
+ "div",
57
+ {
58
+ className: `subtitle-player subtitle-player--current ${c}`,
59
+ style: o,
60
+ children: h.map(({ entry: t, label: l }, a) => t ? /* @__PURE__ */ T(
61
+ "div",
62
+ {
63
+ className: "subtitle-player-item",
64
+ "data-label": l || void 0,
65
+ children: [
66
+ l && /* @__PURE__ */ s("span", { className: "subtitle-player-label", children: l }),
67
+ /* @__PURE__ */ s("div", { className: "subtitle-player-text", children: t.text.split(`
68
+ `).map((u, p) => /* @__PURE__ */ s("div", { className: "subtitle-player-line", children: u }, p)) })
69
+ ]
70
+ },
71
+ a
72
+ ) : null)
73
+ }
74
+ ) : null : /* @__PURE__ */ s(
75
+ "div",
76
+ {
77
+ ref: f,
78
+ className: `subtitle-player subtitle-player--lyrics ${c}`,
79
+ style: o,
80
+ children: b.map(({ entries: e, label: t }, l) => /* @__PURE__ */ T("div", { className: "subtitle-player-group", children: [
81
+ t && /* @__PURE__ */ s("span", { className: "subtitle-player-label", children: t }),
82
+ e.map((a, u) => {
83
+ const p = d(a.startTime), v = d(a.endTime), g = n >= p && n <= v, x = n > v;
84
+ return /* @__PURE__ */ s(
85
+ "div",
86
+ {
87
+ ref: g ? y : null,
88
+ className: `subtitle-player-item ${g ? "subtitle-player-item--active" : ""} ${x ? "subtitle-player-item--past" : ""}`,
89
+ "data-label": t || void 0,
90
+ children: /* @__PURE__ */ s("div", { className: "subtitle-player-text", children: a.text.split(`
91
+ `).map((R, A) => /* @__PURE__ */ s("div", { className: "subtitle-player-line", children: R }, A)) })
92
+ },
93
+ u
94
+ );
95
+ })
96
+ ] }, l))
97
+ }
98
+ );
99
+ };
100
+ export {
101
+ B as SubtitlePlayer,
102
+ B as default
103
+ };
@@ -0,0 +1,2 @@
1
+ export * from './SubtitlePlayer';
2
+ export { default } from './SubtitlePlayer';
@@ -1,4 +1,4 @@
1
- import { OnMount } from '@monaco-editor/react';
1
+ import { Editor } from '@tiptap/react';
2
2
  export interface TxtEditorProps {
3
3
  /**
4
4
  * 编辑器高度
@@ -13,6 +13,7 @@ export interface TxtEditorProps {
13
13
  /**
14
14
  * 编辑器默认语言
15
15
  * @default 'plaintext'
16
+ * @deprecated Tiptap 不支持语法高亮,此属性已废弃
16
17
  */
17
18
  language?: string;
18
19
  /**
@@ -40,13 +41,13 @@ export interface TxtEditorProps {
40
41
  /**
41
42
  * 编辑器加载完成回调
42
43
  */
43
- onMount?: OnMount;
44
+ onMount?: (editor: Editor) => void;
44
45
  /**
45
46
  * 文本编辑器样式
46
47
  */
47
48
  className?: string;
48
49
  }
49
50
  /**
50
- * Monaco Editor 文本编辑器组件
51
+ * Tiptap 文本编辑器组件
51
52
  */
52
- export declare const TxtEditor: ({ height, width, language, defaultValue, value, theme, readOnly, onChange, onMount, className, }: TxtEditorProps) => import("react/jsx-runtime").JSX.Element;
53
+ export declare const TxtEditor: ({ height, width, language: _language, defaultValue, value, theme, readOnly, onChange, onMount, className, }: TxtEditorProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,54 +1,113 @@
1
- import { jsx as m } from "react/jsx-runtime";
2
- import h from "@monaco-editor/react";
3
- import { useRef as c } from "react";
4
- const M = ({
5
- height: e = "500px",
6
- width: t = "100%",
7
- language: i = "plaintext",
8
- defaultValue: a,
9
- value: r,
10
- theme: l = "light",
11
- readOnly: o = !1,
12
- onChange: d,
1
+ import { jsxs as k, jsx as c } from "react/jsx-runtime";
2
+ import { useEditor as M, EditorContent as w } from "@tiptap/react";
3
+ import C from "@tiptap/starter-kit";
4
+ import { useMemo as P, useEffect as a } from "react";
5
+ const U = ({
6
+ height: t = "500px",
7
+ width: i = "100%",
8
+ language: y = "plaintext",
9
+ // eslint-disable-line @typescript-eslint/no-unused-vars
10
+ defaultValue: d,
11
+ value: o,
12
+ theme: p = "light",
13
+ readOnly: n = !1,
14
+ onChange: m,
13
15
  onMount: s,
14
16
  className: u
15
17
  }) => {
16
- const f = c(null);
17
- return /* @__PURE__ */ m(
18
- h,
18
+ const l = o !== void 0, g = P(() => d || o || "", [d, o]), e = M({
19
+ extensions: [
20
+ C.configure({
21
+ // 禁用大部分格式化功能,保持纯文本编辑体验
22
+ bold: !1,
23
+ italic: !1,
24
+ strike: !1,
25
+ code: !1,
26
+ heading: !1,
27
+ blockquote: !1,
28
+ horizontalRule: !1,
29
+ hardBreak: !1
30
+ // 保留历史记录、拖拽光标和间隙光标功能(使用默认配置)
31
+ })
32
+ ],
33
+ content: g,
34
+ editable: !n,
35
+ immediatelyRender: !1,
36
+ onUpdate: ({ editor: f }) => {
37
+ const b = f.getText();
38
+ m?.(b);
39
+ }
40
+ });
41
+ if (a(() => {
42
+ if (!e || !l) return;
43
+ const f = e.getText();
44
+ o !== f && e.commands.setContent(o || "", { emitUpdate: !1 });
45
+ }, [e, o, l]), a(() => {
46
+ e && e.setEditable(!n);
47
+ }, [e, n]), a(() => {
48
+ e && s && s(e);
49
+ }, [e, s]), !e)
50
+ return null;
51
+ const x = typeof t == "number" ? `${t}px` : t, h = typeof i == "number" ? `${i}px` : i, r = p === "vs-dark";
52
+ return /* @__PURE__ */ k(
53
+ "div",
19
54
  {
20
55
  className: u,
21
- height: e,
22
- width: t,
23
- defaultLanguage: i,
24
- defaultValue: a,
25
- value: r,
26
- theme: l,
27
- onMount: (n, p) => {
28
- f.current = n, s?.(n, p), n.updateOptions({
29
- minimap: { enabled: !1 },
30
- // 禁用小地图
31
- lineNumbers: "on",
32
- // 显示行号
33
- roundedSelection: !1,
34
- // 方形选区
35
- scrollBeyondLastLine: !1,
36
- // 禁止滚动到最后一行之后
37
- readOnly: o,
38
- // 是否只读
39
- fontSize: 14
40
- // 字体大小
41
- });
42
- },
43
- onChange: (n) => {
44
- d?.(n || "");
56
+ style: {
57
+ width: h,
58
+ height: x,
59
+ border: `1px solid ${r ? "#3e3e3e" : "#d4d4d4"}`,
60
+ borderRadius: "4px",
61
+ overflow: "hidden",
62
+ backgroundColor: r ? "#1e1e1e" : "#ffffff"
45
63
  },
46
- options: {
47
- readOnly: o
48
- }
64
+ children: [
65
+ /* @__PURE__ */ c(
66
+ w,
67
+ {
68
+ editor: e,
69
+ style: {
70
+ height: "100%",
71
+ overflow: "auto"
72
+ }
73
+ }
74
+ ),
75
+ /* @__PURE__ */ c("style", { children: `
76
+ .ProseMirror {
77
+ outline: none;
78
+ padding: 12px;
79
+ min-height: 100%;
80
+ font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
81
+ font-size: 14px;
82
+ line-height: 1.5;
83
+ color: ${r ? "#d4d4d4" : "#333333"};
84
+ white-space: pre-wrap;
85
+ word-wrap: break-word;
86
+ }
87
+ .ProseMirror p {
88
+ margin: 0;
89
+ padding: 0;
90
+ }
91
+ .ProseMirror p + p {
92
+ margin-top: 0;
93
+ }
94
+ .ProseMirror:focus {
95
+ outline: none;
96
+ }
97
+ ${r ? `
98
+ .ProseMirror {
99
+ background-color: #1e1e1e;
100
+ }
101
+ ` : `
102
+ .ProseMirror {
103
+ background-color: #ffffff;
104
+ }
105
+ `}
106
+ ` })
107
+ ]
49
108
  }
50
109
  );
51
110
  };
52
111
  export {
53
- M as TxtEditor
112
+ U as TxtEditor
54
113
  };
@@ -1,83 +1,76 @@
1
- import { jsxs as w, Fragment as E, jsx as e } from "react/jsx-runtime";
2
- import { useRef as n } from "react";
3
- import t from "clsx";
4
- import { useScroll as F, useTransform as _, useMotionTemplate as v, motion as i } from "motion/react";
5
- import y from "./index.module.css.js";
6
- const I = 16, L = 1.5, R = "normal", k = ({
7
- content: c,
8
- lineHeight: a = L,
9
- fontSize: f = I,
10
- fontWeight: m = R,
11
- className: p = "",
12
- style: d = {},
1
+ import { jsxs as h, Fragment as v, jsx as t } from "react/jsx-runtime";
2
+ import { useRef as c } from "react";
3
+ import r from "clsx";
4
+ import { useScroll as y, useTransform as I, useMotionTemplate as L, motion as l } from "motion/react";
5
+ import e from "./index.module.css.js";
6
+ const R = 16, S = 1.5, A = "normal", O = ({
7
+ content: a,
8
+ lineHeight: m = S,
9
+ fontSize: p = R,
10
+ fontWeight: d = A,
11
+ className: f = "",
12
+ style: g = {},
13
13
  onProgressChange: u,
14
- initialScrollPosition: S,
15
- cacheKey: A,
16
- showTopProgress: h = !0,
17
- topProgressClassName: x,
18
- showBottomProgress: g = !0,
19
- bottomProgressClassName: T
14
+ initialScrollPosition: D,
15
+ cacheKey: H,
16
+ showTopProgress: x = !0,
17
+ topProgressClassName: T,
18
+ showBottomProgress: N = !0,
19
+ bottomProgressClassName: E
20
20
  }) => {
21
- const r = n(null), o = n(null), { scrollYProgress: l } = F({
22
- container: r,
23
- target: o
24
- }), s = _(() => (l.get() * 100).toFixed(2).replace(/\.0*$/, "")), N = v`${s}%`;
25
- return s.on("change", (b) => {
26
- u?.(Number(b));
27
- }), /* @__PURE__ */ w(E, { children: [
28
- h && /* @__PURE__ */ e(
29
- i.div,
21
+ const o = c(null), n = c(null), { scrollYProgress: s } = y({
22
+ container: o,
23
+ target: n
24
+ }), i = I(() => (s.get() * 100).toFixed(2).replace(/\.0*$/, "")), F = L`${i}%`;
25
+ return i.on("change", (_) => {
26
+ u?.(Number(_));
27
+ }), /* @__PURE__ */ h(v, { children: [
28
+ x && /* @__PURE__ */ t(
29
+ l.div,
30
30
  {
31
31
  id: "scroll-indicator",
32
- className: t(
33
- "fixed left-0 top-0 right-0 bg-[#ff0088] h-2.5",
34
- x
35
- ),
32
+ className: r(e["xiping-top-progress"], T),
36
33
  style: {
37
- scaleX: l,
34
+ scaleX: s,
38
35
  originX: 0
39
36
  }
40
37
  }
41
38
  ),
42
- /* @__PURE__ */ e(
39
+ /* @__PURE__ */ t(
43
40
  "div",
44
41
  {
45
- className: t(
46
- "relative w-full h-full overflow-y-auto",
47
- y.textContent
48
- // "scrollbar-thumb-rounded-full scrollbar-track-rounded-full scrollbar scrollbar-thumb-slate-700 scrollbar-track-slate-300",
49
- ),
50
- ref: r,
51
- children: /* @__PURE__ */ e(
42
+ className: r(e["xiping-container"], e.textContent),
43
+ ref: o,
44
+ children: /* @__PURE__ */ t(
52
45
  "div",
53
46
  {
54
- ref: o,
55
- className: t("w-full whitespace-pre-wrap break-words", p),
47
+ ref: n,
48
+ className: r(e["xiping-content"], f),
56
49
  style: {
57
- fontSize: `${f}px`,
58
- lineHeight: a,
59
- fontWeight: m,
60
- ...d
50
+ fontSize: `${p}px`,
51
+ lineHeight: m,
52
+ fontWeight: d,
53
+ ...g
61
54
  },
62
- children: c
55
+ children: a
63
56
  }
64
57
  )
65
58
  }
66
59
  ),
67
- g && /* @__PURE__ */ e(
68
- i.div,
60
+ N && /* @__PURE__ */ t(
61
+ l.div,
69
62
  {
70
63
  id: "scroll-present",
71
- className: t(
72
- "fixed text-white rounded text-sm bg-black/70 pl-2 pr-2 pb-1 pt-1 right-5 bottom-5",
73
- T
64
+ className: r(
65
+ e["xiping-bottom-progress"],
66
+ E
74
67
  ),
75
- children: N
68
+ children: F
76
69
  }
77
70
  )
78
71
  ] });
79
72
  };
80
73
  export {
81
- k as TxtReader,
82
- k as default
74
+ O as TxtReader,
75
+ O as default
83
76
  };
@@ -1,7 +1,11 @@
1
- const t = "_textContent_8n59h_23", e = {
1
+ const t = "_textContent_yv2bi_63", n = {
2
+ "xiping-top-progress": "_xiping-top-progress_yv2bi_23",
3
+ "xiping-container": "_xiping-container_yv2bi_33",
4
+ "xiping-content": "_xiping-content_yv2bi_41",
5
+ "xiping-bottom-progress": "_xiping-bottom-progress_yv2bi_48",
2
6
  textContent: t
3
7
  };
4
8
  export {
5
- e as default,
9
+ n as default,
6
10
  t as textContent
7
11
  };
@@ -1,20 +1,21 @@
1
1
  "use client";
2
2
  import { jsx as T } from "react/jsx-runtime";
3
3
  import { cn as x } from "../../utils/utils.js";
4
- import { motion as b } from "motion/react";
5
- import { useState as u, useRef as I, useEffect as a } from "react";
6
- function R({
4
+ import { motion as I } from "motion/react";
5
+ import { useState as u, useRef as b, useEffect as a } from "react";
6
+ /* empty css */
7
+ function S({
7
8
  children: r,
8
- className: l,
9
+ className: m,
9
10
  duration: s = 100,
10
11
  delay: n = 0,
11
- as: m = "div",
12
+ as: l = "div",
12
13
  startOnView: i = !1,
13
14
  ...p
14
15
  }) {
15
- const d = b.create(m, {
16
+ const d = I.create(l, {
16
17
  forwardMotionProps: !0
17
- }), [g, v] = u(""), [c, f] = u(!1), o = I(null);
18
+ }), [g, v] = u(""), [c, f] = u(!1), o = b(null);
18
19
  return a(() => {
19
20
  if (!i) {
20
21
  const t = setTimeout(() => {
@@ -44,16 +45,13 @@ function R({
44
45
  d,
45
46
  {
46
47
  ref: o,
47
- className: x(
48
- "text-4xl font-bold leading-[5rem] tracking-[-0.02em]",
49
- l
50
- ),
48
+ className: x("xiping-typing-animation", m),
51
49
  ...p,
52
50
  children: g
53
51
  }
54
52
  );
55
53
  }
56
54
  export {
57
- R as TypingAnimation,
58
- R as default
55
+ S as TypingAnimation,
56
+ S as default
59
57
  };
@@ -0,0 +1,25 @@
1
+ import { RefObject, HTMLAttributes } from 'react';
2
+ interface VariableProximityProps extends HTMLAttributes<HTMLSpanElement> {
3
+ label: string;
4
+ fromFontVariationSettings: string;
5
+ toFontVariationSettings: string;
6
+ containerRef: RefObject<HTMLElement>;
7
+ radius?: number;
8
+ falloff?: "linear" | "exponential" | "gaussian";
9
+ className?: string;
10
+ onClick?: () => void;
11
+ style?: React.CSSProperties;
12
+ /**
13
+ * 自定义字体族,如果不提供则使用默认的可变字体
14
+ * 例如: "'Custom Font', 'Roboto Flex', sans-serif"
15
+ */
16
+ fontFamily?: string;
17
+ /**
18
+ * 是否自动加载默认字体(当 fontFamily 未提供时)
19
+ * @default true
20
+ */
21
+ autoLoadFonts?: boolean;
22
+ }
23
+ declare const VariableProximity: import('react').ForwardRefExoticComponent<VariableProximityProps & import('react').RefAttributes<HTMLSpanElement>>;
24
+ export { VariableProximity };
25
+ export default VariableProximity;