@lobehub/ui 2.18.3 → 2.19.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.
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
- var _excluded = ["value", "defaultAvatar", "onChange", "locale", "allowUpload", "allowDelete", "texts", "onDelete", "compressSize", "customEmojis", "className", "loading", "onUpload", "customTabs", "popupClassName", "popupStyle", "customRender", "open", "defaultOpen", "onOpenChange"];
4
+ var _excluded = ["value", "defaultAvatar", "onChange", "locale", "allowUpload", "allowDelete", "texts", "onDelete", "compressSize", "customEmojis", "className", "loading", "onUpload", "customTabs", "popupClassName", "popupStyle", "customRender", "open", "defaultOpen", "onOpenChange", "popupProps"];
5
5
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
6
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
7
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -66,6 +66,7 @@ var EmojiPicker = /*#__PURE__*/memo(function (_ref) {
66
66
  _ref$defaultOpen = _ref.defaultOpen,
67
67
  defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
68
68
  onOpenChange = _ref.onOpenChange,
69
+ popupProps = _ref.popupProps,
69
70
  rest = _objectWithoutProperties(_ref, _excluded);
70
71
  var ref = useRef(null);
71
72
  var _useMergeState = useMergeState(defaultOpen, {
@@ -154,6 +155,7 @@ var EmojiPicker = /*#__PURE__*/memo(function (_ref) {
154
155
  }, popupStyle),
155
156
  children: [showTabs && /*#__PURE__*/_jsxs(Flexbox, {
156
157
  align: 'center',
158
+ className: styles.tabs,
157
159
  horizontal: true,
158
160
  justify: 'space-between',
159
161
  paddingInline: 10,
@@ -163,14 +165,18 @@ var EmojiPicker = /*#__PURE__*/memo(function (_ref) {
163
165
  items: items,
164
166
  onChange: function onChange(key) {
165
167
  return setTab(key);
166
- }
168
+ },
169
+ size: 'small'
167
170
  }), allowDelete && /*#__PURE__*/_jsx(ActionIcon, {
168
171
  icon: TrashIcon,
169
172
  onClick: function onClick() {
170
173
  handleAvatarChange(defaultAvatar);
171
174
  onDelete === null || onDelete === void 0 || onDelete();
172
175
  },
173
- size: 20,
176
+ size: {
177
+ blockSize: 32,
178
+ size: 18
179
+ },
174
180
  title: (texts === null || texts === void 0 ? void 0 : texts.delete) || 'Delete'
175
181
  })]
176
182
  }), tab === 'emoji' && /*#__PURE__*/_jsx(Picker, {
@@ -198,7 +204,7 @@ var EmojiPicker = /*#__PURE__*/memo(function (_ref) {
198
204
  }, item.value);
199
205
  })]
200
206
  });
201
- return /*#__PURE__*/_jsx(Popover, {
207
+ return /*#__PURE__*/_jsx(Popover, _objectSpread(_objectSpread({
202
208
  arrow: false,
203
209
  content: content,
204
210
  defaultOpen: defaultOpen,
@@ -207,15 +213,16 @@ var EmojiPicker = /*#__PURE__*/memo(function (_ref) {
207
213
  setVisible(v);
208
214
  },
209
215
  open: visible,
210
- placement: 'bottomRight',
216
+ placement: 'bottom',
211
217
  rootClassName: styles.popover,
212
- trigger: ['click'],
218
+ trigger: ['click']
219
+ }, popupProps), {}, {
213
220
  children: customRender ? customRender(ava) : /*#__PURE__*/_jsx(Avatar, _objectSpread({
214
221
  avatar: ava,
215
222
  className: cx(styles.root, className),
216
223
  loading: loading
217
224
  }, rest))
218
- });
225
+ }));
219
226
  });
220
227
  EmojiPicker.displayName = 'EmojiPicker';
221
228
  export default EmojiPicker;
@@ -3,4 +3,5 @@ export declare const useStyles: (props?: unknown) => import("antd-style").Return
3
3
  picker: import("antd-style").SerializedStyles;
4
4
  popover: import("antd-style").SerializedStyles;
5
5
  root: import("antd-style").SerializedStyles;
6
+ tabs: import("antd-style").SerializedStyles;
6
7
  }>;
@@ -1,4 +1,4 @@
1
- var _templateObject, _templateObject2, _templateObject3, _templateObject4;
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
3
  import { createStyles } from 'antd-style';
4
4
  import chroma from 'chroma-js';
@@ -10,6 +10,7 @@ export var useStyles = createStyles(function (_ref) {
10
10
  editor: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow: hidden;\n border: 1px solid ", ";\n border-radius: ", "px;\n "])), token.colorBorder, token.borderRadiusLG),
11
11
  picker: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: relative;\n\n em-emoji-picker {\n --rgb-accent: ", ";\n --shadow: none;\n --rgb-background: ", ";\n --border-radius: 0;\n }\n "])), chroma(token.colorPrimary).rgb().join(','), chroma(token.colorBgElevated).rgb().join(',')),
12
12
  popover: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n .", "-popover-inner {\n overflow: hidden;\n padding: 0;\n }\n "])), prefixCls),
13
- root: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: relative;\n transition: box-shadow 100ms ", ";\n\n &:hover {\n box-shadow: 0 0 0 3px ", ";\n }\n "])), token.motionEaseOut, token.colorText)
13
+ root: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: relative;\n transition: background 150ms ", ";\n\n &:hover {\n background: ", ";\n }\n "])), token.motionEaseOut, token.colorFillSecondary),
14
+ tabs: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n border-block-end: 1px solid ", ";\n\n .ant-tabs-tab {\n display: flex;\n align-items: center;\n justify-content: center;\n\n width: 32px;\n height: 32px;\n padding: 0 !important;\n }\n "])), token.colorBorderSecondary)
14
15
  };
15
16
  });
@@ -1,3 +1,4 @@
1
+ import { PopoverProps } from 'antd';
1
2
  import { CSSProperties, ReactNode } from 'react';
2
3
  import type { AvatarProps } from "../Avatar/type";
3
4
  import type { AvatarUploaderProps } from "./AvatarUploader";
@@ -37,6 +38,7 @@ export interface EmojiPickerProps extends Omit<AvatarProps, 'onChange' | 'avatar
37
38
  onUpload?: AvatarUploaderProps['onUpload'];
38
39
  open?: boolean;
39
40
  popupClassName?: string;
41
+ popupProps?: Omit<PopoverProps, 'onOpenChange' | 'defaultOpen' | 'content' | 'open' | 'rootClassName' | 'trigger'>;
40
42
  popupStyle?: CSSProperties;
41
43
  size?: number;
42
44
  texts?: AvatarUploaderProps['texts'] & {
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ declare const ConfigProvider: import("react").NamedExoticComponent<{
3
+ children?: import("react").ReactNode;
4
+ }>;
5
+ export default ConfigProvider;
@@ -0,0 +1,41 @@
1
+ 'use client';
2
+
3
+ import { ConfigProvider as AntdConfigProvider } from 'antd';
4
+ import { useTheme } from 'antd-style';
5
+ import { memo } from 'react';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ var ConfigProvider = /*#__PURE__*/memo(function (_ref) {
8
+ var children = _ref.children;
9
+ var theme = useTheme();
10
+ return /*#__PURE__*/_jsx(AntdConfigProvider, {
11
+ theme: {
12
+ components: {
13
+ Button: {
14
+ contentFontSizeSM: 12
15
+ },
16
+ DatePicker: {
17
+ activeBorderColor: theme.colorBorder,
18
+ hoverBorderColor: theme.colorBorder
19
+ },
20
+ Input: {
21
+ activeBorderColor: theme.colorBorder,
22
+ hoverBorderColor: theme.colorBorder
23
+ },
24
+ InputNumber: {
25
+ activeBorderColor: theme.colorBorder,
26
+ hoverBorderColor: theme.colorBorder
27
+ },
28
+ Mentions: {
29
+ activeBorderColor: theme.colorBorder,
30
+ hoverBorderColor: theme.colorBorder
31
+ },
32
+ Select: {
33
+ activeBorderColor: theme.colorBorder,
34
+ hoverBorderColor: theme.colorBorder
35
+ }
36
+ }
37
+ },
38
+ children: children
39
+ });
40
+ });
41
+ export default ConfigProvider;
@@ -17,6 +17,7 @@ import { useCdnFn } from "../ConfigProvider";
17
17
  import FontLoader from "../FontLoader";
18
18
  import { lobeCustomStylish, lobeCustomToken } from "../styles";
19
19
  import { createLobeAntdTheme } from "../styles/theme/antdTheme";
20
+ import ConfigProvider from "./ConfigProvider";
20
21
  import GlobalStyle from "./GlobalStyle";
21
22
  import { jsx as _jsx } from "react/jsx-runtime";
22
23
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -71,19 +72,21 @@ var ThemeProvider = /*#__PURE__*/memo(function (_ref) {
71
72
  return /*#__PURE__*/_jsx(FontLoader, {
72
73
  url: webfont
73
74
  }, webfont);
74
- }), /*#__PURE__*/_jsxs(AntdThemeProvider, _objectSpread(_objectSpread({
75
+ }), /*#__PURE__*/_jsx(AntdThemeProvider, _objectSpread(_objectSpread({
75
76
  customStylish: stylish,
76
77
  customToken: token,
77
78
  theme: theme
78
79
  }, rest), {}, {
79
- children: [enableGlobalStyle && /*#__PURE__*/_jsx(GlobalStyle, {}), /*#__PURE__*/_jsx(App, {
80
- className: className,
81
- style: _objectSpread({
82
- minHeight: 'inherit',
83
- width: 'inherit'
84
- }, style),
85
- children: children
86
- })]
80
+ children: /*#__PURE__*/_jsxs(ConfigProvider, {
81
+ children: [enableGlobalStyle && /*#__PURE__*/_jsx(GlobalStyle, {}), /*#__PURE__*/_jsx(App, {
82
+ className: className,
83
+ style: _objectSpread({
84
+ minHeight: 'inherit',
85
+ width: 'inherit'
86
+ }, style),
87
+ children: children
88
+ })]
89
+ })
87
90
  }))]
88
91
  });
89
92
  });
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { TypewriterEffectProps } from './type';
3
+ declare const TypewriterEffect: import("react").NamedExoticComponent<TypewriterEffectProps>;
4
+ export default TypewriterEffect;
@@ -0,0 +1,250 @@
1
+ 'use client';
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ var _excluded = ["sentences", "as", "typingSpeed", "initialDelay", "pauseDuration", "deletingSpeed", "loop", "className", "color", "showCursor", "hideCursorWhileTyping", "cursorCharacter", "cursorClassName", "cursorColor", "cursorBlinkDuration", "cursorStyle", "textColors", "variableSpeed", "onSentenceComplete", "startOnVisible", "reverseMode"];
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
14
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
15
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
17
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
18
+ import { motion } from 'framer-motion';
19
+ import { createElement, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
20
+ import { useStyles } from "./style";
21
+ import { jsx as _jsx } from "react/jsx-runtime";
22
+ import { Fragment as _Fragment } from "react/jsx-runtime";
23
+ import { jsxs as _jsxs } from "react/jsx-runtime";
24
+ var TypewriterEffect = /*#__PURE__*/memo(function (_ref) {
25
+ var sentences = _ref.sentences,
26
+ _ref$as = _ref.as,
27
+ Component = _ref$as === void 0 ? 'div' : _ref$as,
28
+ _ref$typingSpeed = _ref.typingSpeed,
29
+ typingSpeed = _ref$typingSpeed === void 0 ? 100 : _ref$typingSpeed,
30
+ _ref$initialDelay = _ref.initialDelay,
31
+ initialDelay = _ref$initialDelay === void 0 ? 0 : _ref$initialDelay,
32
+ _ref$pauseDuration = _ref.pauseDuration,
33
+ pauseDuration = _ref$pauseDuration === void 0 ? 2000 : _ref$pauseDuration,
34
+ _ref$deletingSpeed = _ref.deletingSpeed,
35
+ deletingSpeed = _ref$deletingSpeed === void 0 ? 50 : _ref$deletingSpeed,
36
+ _ref$loop = _ref.loop,
37
+ loop = _ref$loop === void 0 ? true : _ref$loop,
38
+ _ref$className = _ref.className,
39
+ className = _ref$className === void 0 ? '' : _ref$className,
40
+ color = _ref.color,
41
+ _ref$showCursor = _ref.showCursor,
42
+ showCursor = _ref$showCursor === void 0 ? true : _ref$showCursor,
43
+ _ref$hideCursorWhileT = _ref.hideCursorWhileTyping,
44
+ hideCursorWhileTyping = _ref$hideCursorWhileT === void 0 ? false : _ref$hideCursorWhileT,
45
+ cursorCharacter = _ref.cursorCharacter,
46
+ _ref$cursorClassName = _ref.cursorClassName,
47
+ cursorClassName = _ref$cursorClassName === void 0 ? '' : _ref$cursorClassName,
48
+ cursorColor = _ref.cursorColor,
49
+ _ref$cursorBlinkDurat = _ref.cursorBlinkDuration,
50
+ cursorBlinkDuration = _ref$cursorBlinkDurat === void 0 ? 0.8 : _ref$cursorBlinkDurat,
51
+ _ref$cursorStyle = _ref.cursorStyle,
52
+ cursorStyle = _ref$cursorStyle === void 0 ? 'pipe' : _ref$cursorStyle,
53
+ _ref$textColors = _ref.textColors,
54
+ textColors = _ref$textColors === void 0 ? [] : _ref$textColors,
55
+ variableSpeed = _ref.variableSpeed,
56
+ onSentenceComplete = _ref.onSentenceComplete,
57
+ _ref$startOnVisible = _ref.startOnVisible,
58
+ startOnVisible = _ref$startOnVisible === void 0 ? false : _ref$startOnVisible,
59
+ _ref$reverseMode = _ref.reverseMode,
60
+ reverseMode = _ref$reverseMode === void 0 ? false : _ref$reverseMode,
61
+ props = _objectWithoutProperties(_ref, _excluded);
62
+ var _useStyles = useStyles(),
63
+ styles = _useStyles.styles,
64
+ cx = _useStyles.cx;
65
+ var _useState = useState(''),
66
+ _useState2 = _slicedToArray(_useState, 2),
67
+ displayedText = _useState2[0],
68
+ setDisplayedText = _useState2[1];
69
+ var _useState3 = useState(0),
70
+ _useState4 = _slicedToArray(_useState3, 2),
71
+ currentCharIndex = _useState4[0],
72
+ setCurrentCharIndex = _useState4[1];
73
+ var _useState5 = useState(false),
74
+ _useState6 = _slicedToArray(_useState5, 2),
75
+ isDeleting = _useState6[0],
76
+ setIsDeleting = _useState6[1];
77
+ var _useState7 = useState(0),
78
+ _useState8 = _slicedToArray(_useState7, 2),
79
+ currentTextIndex = _useState8[0],
80
+ setCurrentTextIndex = _useState8[1];
81
+ var _useState9 = useState(!startOnVisible),
82
+ _useState10 = _slicedToArray(_useState9, 2),
83
+ isVisible = _useState10[0],
84
+ setIsVisible = _useState10[1];
85
+ var containerRef = useRef(null);
86
+ var textArray = useMemo(function () {
87
+ return Array.isArray(sentences) ? sentences : [sentences];
88
+ }, [sentences]);
89
+ var getRandomSpeed = useCallback(function () {
90
+ if (!variableSpeed) return typingSpeed;
91
+ var min = variableSpeed.min,
92
+ max = variableSpeed.max;
93
+ return Math.random() * (max - min) + min;
94
+ }, [variableSpeed, typingSpeed]);
95
+ var getCurrentTextColor = function getCurrentTextColor() {
96
+ if (textColors.length > 0) {
97
+ return textColors[currentTextIndex % textColors.length];
98
+ }
99
+ return color;
100
+ };
101
+ var getCurrentCursorColor = function getCurrentCursorColor() {
102
+ return cursorColor || color;
103
+ };
104
+ useEffect(function () {
105
+ if (!startOnVisible || !containerRef.current) return;
106
+ var observer = new IntersectionObserver(function (entries) {
107
+ entries.forEach(function (entry) {
108
+ if (entry.isIntersecting) {
109
+ setIsVisible(true);
110
+ }
111
+ });
112
+ }, {
113
+ threshold: 0.1
114
+ });
115
+ observer.observe(containerRef.current);
116
+ return function () {
117
+ return observer.disconnect();
118
+ };
119
+ }, [startOnVisible]);
120
+ useEffect(function () {
121
+ if (!isVisible) return;
122
+ var timeout;
123
+ var currentText = textArray[currentTextIndex];
124
+ var processedText = reverseMode ? currentText.split('').reverse().join('') : currentText;
125
+ var executeTypingAnimation = function executeTypingAnimation() {
126
+ if (isDeleting) {
127
+ if (displayedText === '') {
128
+ setIsDeleting(false);
129
+ if (currentTextIndex === textArray.length - 1 && !loop) {
130
+ return;
131
+ }
132
+ if (onSentenceComplete) {
133
+ onSentenceComplete(textArray[currentTextIndex], currentTextIndex);
134
+ }
135
+ setCurrentTextIndex(function (prev) {
136
+ return (prev + 1) % textArray.length;
137
+ });
138
+ setCurrentCharIndex(0);
139
+ timeout = setTimeout(function () {}, pauseDuration);
140
+ } else {
141
+ timeout = setTimeout(function () {
142
+ setDisplayedText(function (prev) {
143
+ return prev.slice(0, -1);
144
+ });
145
+ }, deletingSpeed);
146
+ }
147
+ } else {
148
+ if (currentCharIndex < processedText.length) {
149
+ timeout = setTimeout(function () {
150
+ setDisplayedText(function (prev) {
151
+ return prev + processedText[currentCharIndex];
152
+ });
153
+ setCurrentCharIndex(function (prev) {
154
+ return prev + 1;
155
+ });
156
+ }, variableSpeed ? getRandomSpeed() : typingSpeed);
157
+ } else if (textArray.length >= 1) {
158
+ if (!loop && currentTextIndex === textArray.length - 1) return;
159
+ timeout = setTimeout(function () {
160
+ setIsDeleting(true);
161
+ }, pauseDuration);
162
+ }
163
+ }
164
+ };
165
+ if (currentCharIndex === 0 && !isDeleting && displayedText === '') {
166
+ timeout = setTimeout(executeTypingAnimation, initialDelay);
167
+ } else {
168
+ executeTypingAnimation();
169
+ }
170
+ return function () {
171
+ return clearTimeout(timeout);
172
+ };
173
+ }, [currentCharIndex, displayedText, isDeleting, typingSpeed, deletingSpeed, pauseDuration, textArray, currentTextIndex, loop, initialDelay, isVisible, reverseMode, variableSpeed, onSentenceComplete, getRandomSpeed]);
174
+ var getCursorStyle = function getCursorStyle() {
175
+ if (cursorCharacter) return styles.cursorCustom;
176
+ switch (cursorStyle) {
177
+ case 'block':
178
+ {
179
+ return styles.cursorBlock;
180
+ }
181
+ case 'dot':
182
+ {
183
+ return styles.cursorDot;
184
+ }
185
+ case 'underscore':
186
+ {
187
+ return styles.cursorUnderscore;
188
+ }
189
+ case 'pipe':
190
+ {
191
+ return styles.cursor;
192
+ }
193
+ }
194
+ };
195
+ var shouldHideCursor = hideCursorWhileTyping && (currentCharIndex < textArray[currentTextIndex].length || isDeleting);
196
+ var textColor = getCurrentTextColor();
197
+ var finalCursorColor = getCurrentCursorColor();
198
+
199
+ // Split displayed text into characters for animation
200
+ var characters = displayedText.split('');
201
+ return /*#__PURE__*/createElement(Component, _objectSpread({
202
+ className: cx(styles.container, className),
203
+ ref: containerRef
204
+ }, props), /*#__PURE__*/_jsxs(_Fragment, {
205
+ children: [/*#__PURE__*/_jsx("span", {
206
+ className: styles.text,
207
+ style: textColor ? {
208
+ color: textColor
209
+ } : undefined,
210
+ children: characters.map(function (char, index) {
211
+ return /*#__PURE__*/_jsx(motion.span, {
212
+ animate: {
213
+ opacity: 1
214
+ },
215
+ initial: {
216
+ opacity: 0
217
+ },
218
+ style: {
219
+ display: 'inline-block'
220
+ },
221
+ transition: {
222
+ duration: typingSpeed / 500,
223
+ ease: 'easeInOut'
224
+ },
225
+ children: char === ' ' ? "\xA0" : char
226
+ }, "".concat(currentTextIndex, "-").concat(index));
227
+ })
228
+ }), showCursor && /*#__PURE__*/_jsx(motion.span, {
229
+ animate: {
230
+ opacity: 1
231
+ },
232
+ className: cx(getCursorStyle(), cursorClassName, shouldHideCursor && styles.cursorHidden),
233
+ initial: {
234
+ opacity: 0
235
+ },
236
+ style: finalCursorColor ? {
237
+ backgroundColor: finalCursorColor
238
+ } : undefined,
239
+ transition: {
240
+ duration: cursorBlinkDuration,
241
+ ease: 'easeInOut',
242
+ repeat: Number.POSITIVE_INFINITY,
243
+ repeatType: 'reverse'
244
+ },
245
+ children: cursorCharacter
246
+ })]
247
+ }));
248
+ });
249
+ TypewriterEffect.displayName = 'TypewriterEffect';
250
+ export default TypewriterEffect;
@@ -0,0 +1,2 @@
1
+ export type { CursorStyle, TypewriterEffectProps } from './type';
2
+ export { default } from './TypewriterEffect';
@@ -0,0 +1 @@
1
+ export { default } from "./TypewriterEffect";
@@ -0,0 +1,10 @@
1
+ export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
2
+ container: import("antd-style").SerializedStyles;
3
+ cursor: import("antd-style").SerializedStyles;
4
+ cursorBlock: import("antd-style").SerializedStyles;
5
+ cursorCustom: import("antd-style").SerializedStyles;
6
+ cursorDot: import("antd-style").SerializedStyles;
7
+ cursorHidden: import("antd-style").SerializedStyles;
8
+ cursorUnderscore: import("antd-style").SerializedStyles;
9
+ text: import("antd-style").SerializedStyles;
10
+ }>;
@@ -0,0 +1,18 @@
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8;
2
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
+ import { createStyles } from 'antd-style';
4
+ export var useStyles = createStyles(function (_ref) {
5
+ var css = _ref.css,
6
+ token = _ref.token,
7
+ isDarkMode = _ref.isDarkMode;
8
+ return {
9
+ container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: inline-block;\n white-space: pre-wrap;\n "]))),
10
+ cursor: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n transform: translateY(10%);\n\n display: inline-block;\n align-items: center;\n\n width: 3px;\n height: 1em;\n margin-inline-start: 0.25rem;\n border-radius: 2px;\n\n opacity: 1;\n background-color: ", ";\n "])), token.colorPrimary),
11
+ cursorBlock: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n transform: translateY(10%);\n\n display: inline-block;\n align-items: center;\n\n width: 0.5em;\n height: 1em;\n margin-inline-start: 0.25rem;\n border-radius: 2px;\n\n opacity: 1;\n background-color: ", ";\n "])), token.colorPrimary),
12
+ cursorCustom: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n display: inline-block;\n align-items: center;\n margin-inline-start: 0.25rem;\n opacity: 1;\n "]))),
13
+ cursorDot: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n display: inline-block;\n align-items: center;\n\n width: 0.75em;\n height: 0.75em;\n margin-inline-start: 0.25rem;\n border-radius: 50%;\n\n opacity: 1;\n background-color: ", ";\n "])), token.colorPrimary),
14
+ cursorHidden: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n display: none;\n "]))),
15
+ cursorUnderscore: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n transform: translateY(0.3em);\n\n display: inline-block;\n align-items: center;\n\n width: 0.6em;\n height: 0.15em;\n margin-inline-start: 0.25rem;\n border-radius: 2px;\n\n opacity: 1;\n background-color: ", ";\n "])), token.colorPrimary),
16
+ text: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n color: ", ";\n "])), isDarkMode ? token.colorTextLightSolid : token.colorText)
17
+ };
18
+ });
@@ -0,0 +1,104 @@
1
+ import type { ElementType, ReactNode } from 'react';
2
+ export type CursorStyle = 'pipe' | 'underscore' | 'dot' | 'block';
3
+ export interface TypewriterEffectProps {
4
+ /**
5
+ * Custom element type for the container
6
+ * @default 'div'
7
+ */
8
+ as?: ElementType;
9
+ /**
10
+ * Additional class name for the container
11
+ */
12
+ className?: string;
13
+ /**
14
+ * Text color
15
+ */
16
+ color?: string;
17
+ /**
18
+ * Cursor blink duration in seconds
19
+ * @default 0.8
20
+ */
21
+ cursorBlinkDuration?: number;
22
+ /**
23
+ * Custom cursor character or ReactNode
24
+ * @default undefined (uses cursorStyle)
25
+ */
26
+ cursorCharacter?: string | ReactNode;
27
+ /**
28
+ * Additional class name for the cursor
29
+ */
30
+ cursorClassName?: string;
31
+ /**
32
+ * Cursor color (defaults to color if not provided)
33
+ */
34
+ cursorColor?: string;
35
+ /**
36
+ * Style of the cursor (ignored if cursorCharacter is provided)
37
+ * @default 'pipe'
38
+ */
39
+ cursorStyle?: CursorStyle;
40
+ /**
41
+ * Speed of deleting characters (milliseconds per character)
42
+ * @default 50
43
+ */
44
+ deletingSpeed?: number;
45
+ /**
46
+ * Hide cursor while typing
47
+ * @default false
48
+ */
49
+ hideCursorWhileTyping?: boolean;
50
+ /**
51
+ * Initial delay before starting animation (milliseconds)
52
+ * @default 0
53
+ */
54
+ initialDelay?: number;
55
+ /**
56
+ * Whether to loop through sentences
57
+ * @default true
58
+ */
59
+ loop?: boolean;
60
+ /**
61
+ * Callback when a sentence is completed
62
+ */
63
+ onSentenceComplete?: (sentence: string, index: number) => void;
64
+ /**
65
+ * Pause duration after typing complete before deleting (milliseconds)
66
+ * @default 2000
67
+ */
68
+ pauseDuration?: number;
69
+ /**
70
+ * Reverse mode: type from end to start
71
+ * @default false
72
+ */
73
+ reverseMode?: boolean;
74
+ /**
75
+ * Array of sentences to display
76
+ */
77
+ sentences: string[];
78
+ /**
79
+ * Whether to show cursor
80
+ * @default true
81
+ */
82
+ showCursor?: boolean;
83
+ /**
84
+ * Start animation when element becomes visible
85
+ * @default false
86
+ */
87
+ startOnVisible?: boolean;
88
+ /**
89
+ * Colors for each sentence (cycles through array)
90
+ */
91
+ textColors?: string[];
92
+ /**
93
+ * Speed of typing characters (milliseconds per character)
94
+ * @default 100
95
+ */
96
+ typingSpeed?: number;
97
+ /**
98
+ * Variable typing speed range
99
+ */
100
+ variableSpeed?: {
101
+ max: number;
102
+ min: number;
103
+ };
104
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -7,3 +7,4 @@ export { default as GridBackground, type GridBackgroundProps, GridShowcase, type
7
7
  export { default as Hero, type HeroAction, type HeroProps } from './Hero';
8
8
  export { default as Spotlight, type SpotlightProps } from './Spotlight';
9
9
  export { default as SpotlightCard, type SpotlightCardProps } from './SpotlightCard';
10
+ export { type CursorStyle, default as TypewriterEffect, type TypewriterEffectProps, } from './TypewriterEffect';
@@ -6,4 +6,5 @@ export { default as GradientButton } from "./GradientButton";
6
6
  export { default as GridBackground, GridShowcase } from "./GridBackground";
7
7
  export { default as Hero } from "./Hero";
8
8
  export { default as Spotlight } from "./Spotlight";
9
- export { default as SpotlightCard } from "./SpotlightCard";
9
+ export { default as SpotlightCard } from "./SpotlightCard";
10
+ export { default as TypewriterEffect } from "./TypewriterEffect";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "2.18.3",
3
+ "version": "2.19.0",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",