@yuntijs/ui 1.0.0-beta.67 → 1.0.0-beta.69

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/es/index.d.ts CHANGED
@@ -31,9 +31,11 @@ export * from './ChatItem';
31
31
  export * from './EditableMessage';
32
32
  export * from './Highlighter';
33
33
  export * from './styles';
34
+ export * from './useSpeechSynthes';
34
35
  export { Affix, type AffixProps, Anchor, type AnchorProps, type MentionProps as AntdMentionProps, Mentions as AntdMentions, AutoComplete, type AutoCompleteProps, Avatar, type AvatarProps, BackTop, type BackTopProps, Badge, // @todo composed type
35
36
  type BadgeProps, Button, // @todo dependence unifiedLink. link type, hover primary color, back button
36
37
  type ButtonProps, Calendar, type CalendarProps, Carousel, type CarouselProps, Cascader, type CascaderProps, Checkbox, type CheckboxProps, Col, Collapse, type CollapseProps, ColorPicker, type ColorPickerProps, type ColProps, // @todo center style
37
38
  type CountdownProps, DatePicker, type DatePickerProps, Empty, type EmptyProps, Flex, type FlexProps, FloatButton, type GlobalToken, Grid, Image, type ImageProps, Input, InputNumber, type InputNumberProps, type InputProps, type InputRef, Layout, type LayoutProps, List, type ListProps, type MappingAlgorithm, Menu, type MenuItemProps, type MenuProps, type MenuRef, type MenuTheme, message, type MessageArgsProps, Pagination, type PaginationProps, Popconfirm, type PopconfirmProps, Popover, type PopoverProps, Progress, type ProgressProps, QRCode, type QRCodeProps, type QRPropsCanvas, type QRPropsSvg, Rate, type RateProps, type RefSelectProps, Result, type ResultProps, Row, type RowProps, Segmented, type SegmentedProps, Select, type SelectProps, Skeleton, type SkeletonProps, Slider, type SliderSingleProps, Space, type SpaceProps, Spin, type SpinProps, Statistic, type StatisticProps, type StepProps, Steps, type StepsProps, type SubMenuProps, Switch, type SwitchProps, type TabPaneProps, Tabs, type TabsProps, Tag, type TagProps, type TagType, theme, Timeline, type TimelineItemProps, type TimelineProps, TimePicker, type TimePickerProps, type TimeRangePickerProps, Tooltip, type TooltipProps, Tour, type TourProps, type TourStepProps, Transfer, type TransferProps, Tree, type TreeDataNode, type TreeNodeProps, type TreeProps, TreeSelect, type TreeSelectProps, Upload, type UploadFile, type UploadProps, version, Watermark, type WatermarkProps, } from 'antd';
38
39
  export { Markdown, type MarkdownProps, SyntaxHighlighter, type SyntaxHighlighterProps, } from '@lobehub/ui';
40
+ export { SpeechSynthesisTTS } from '@lobehub/tts';
39
41
  export { useResponsive, useTheme, useThemeMode } from 'antd-style';
package/es/index.js CHANGED
@@ -36,6 +36,9 @@ export * from "./EditableMessage";
36
36
  export * from "./Highlighter";
37
37
  export * from "./styles";
38
38
 
39
+ // ~ custom @lobehub/tts
40
+ export * from "./useSpeechSynthes";
41
+
39
42
  // ~ antd
40
43
  export { Affix, Anchor, Mentions as AntdMentions, AutoComplete, Avatar, BackTop, Badge // @todo composed type
41
44
  , Button // @todo dependence unifiedLink. link type, hover primary color, back button
@@ -47,5 +50,8 @@ export { Affix, Anchor, Mentions as AntdMentions, AutoComplete, Avatar, BackTop,
47
50
  // ~ @lobehub/ui
48
51
  export { Markdown, SyntaxHighlighter } from '@lobehub/ui';
49
52
 
53
+ // @lobehub/tts
54
+ export { SpeechSynthesisTTS } from '@lobehub/tts';
55
+
50
56
  // ~ antd-style
51
57
  export { useResponsive, useTheme, useThemeMode } from 'antd-style';
@@ -0,0 +1,3 @@
1
+ export declare const SpeechRecognition: any;
2
+ export declare const SpeechSynthesis: any;
3
+ export declare const SpeechSynthesisUtterance: any;
@@ -0,0 +1,21 @@
1
+ var getSpeechRecognition = function getSpeechRecognition() {
2
+ try {
3
+ var _window, _window2;
4
+ return (globalThis === null || globalThis === void 0 ? void 0 : globalThis.SpeechRecognition) || ((_window = window) === null || _window === void 0 ? void 0 : _window.SpeechRecognition) || ((_window2 = window) === null || _window2 === void 0 ? void 0 : _window2.webkitSpeechRecognition);
5
+ } catch (_unused) {}
6
+ };
7
+ var getSpeechSynthesis = function getSpeechSynthesis() {
8
+ try {
9
+ var _window3, _window4;
10
+ return (globalThis === null || globalThis === void 0 ? void 0 : globalThis.speechSynthesis) || ((_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.speechSynthesis) || ((_window4 = window) === null || _window4 === void 0 ? void 0 : _window4.webkitSpeechSynthesis);
11
+ } catch (_unused2) {}
12
+ };
13
+ var getSpeechSynthesisUtterance = function getSpeechSynthesisUtterance() {
14
+ try {
15
+ var _window5, _window6;
16
+ return (globalThis === null || globalThis === void 0 ? void 0 : globalThis.SpeechSynthesisUtterance) || ((_window5 = window) === null || _window5 === void 0 ? void 0 : _window5.SpeechSynthesisUtterance) || ((_window6 = window) === null || _window6 === void 0 ? void 0 : _window6.webkitSpeechSynthesisUtterance);
17
+ } catch (_unused3) {}
18
+ };
19
+ export var SpeechRecognition = getSpeechRecognition();
20
+ export var SpeechSynthesis = getSpeechSynthesis();
21
+ export var SpeechSynthesisUtterance = getSpeechSynthesisUtterance();
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import { type SsmlOptions } from '@lobehub/tts/core/utils/genSSML';
3
+ export interface SpeechSynthesOptions extends Pick<SsmlOptions, 'voice' | 'rate' | 'pitch'> {
4
+ onStart?: () => void;
5
+ onStop?: () => void;
6
+ }
7
+ export declare const useSpeechSynthes: (defaultText: string, { voice, rate, pitch, ...options }: SpeechSynthesOptions) => {
8
+ isLoading: boolean;
9
+ setText: import("react").Dispatch<import("react").SetStateAction<string>>;
10
+ start: () => void;
11
+ stop: () => void;
12
+ };
13
+ export default useSpeechSynthes;
@@ -0,0 +1,69 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["voice", "rate", "pitch"];
4
+ import { useCallback, useEffect, useMemo, useState } from 'react';
5
+ import { SpeechSynthesis, SpeechSynthesisUtterance } from "./const/polyfill";
6
+ export var useSpeechSynthes = function useSpeechSynthes(defaultText, _ref) {
7
+ var voice = _ref.voice,
8
+ rate = _ref.rate,
9
+ pitch = _ref.pitch,
10
+ options = _objectWithoutProperties(_ref, _excluded);
11
+ var _useState = useState(SpeechSynthesis === null || SpeechSynthesis === void 0 ? void 0 : SpeechSynthesis.getVoices()),
12
+ _useState2 = _slicedToArray(_useState, 2),
13
+ voiceList = _useState2[0],
14
+ setVoiceList = _useState2[1];
15
+ var _useState3 = useState(defaultText),
16
+ _useState4 = _slicedToArray(_useState3, 2),
17
+ text = _useState4[0],
18
+ setText = _useState4[1];
19
+ var _useState5 = useState(false),
20
+ _useState6 = _slicedToArray(_useState5, 2),
21
+ isLoading = _useState6[0],
22
+ setIsLoading = _useState6[1];
23
+ var speechSynthesisUtterance = useMemo(function () {
24
+ if (!SpeechSynthesisUtterance) return;
25
+ var utterance = new SpeechSynthesisUtterance(text);
26
+ utterance.voice = voiceList.find(function (item) {
27
+ return item.name === voice;
28
+ });
29
+ utterance.onstart = function () {
30
+ return setIsLoading(true);
31
+ };
32
+ utterance.onend = function () {
33
+ return setIsLoading(false);
34
+ };
35
+ if (pitch) utterance.pitch = pitch * 10;
36
+ if (rate) utterance.rate = rate * 10;
37
+ return utterance;
38
+ }, [text, voiceList, rate, pitch, voice]);
39
+ useEffect(function () {
40
+ if (!SpeechSynthesis) return;
41
+ SpeechSynthesis.onvoiceschanged = function () {
42
+ setVoiceList(SpeechSynthesis === null || SpeechSynthesis === void 0 ? void 0 : SpeechSynthesis.getVoices());
43
+ };
44
+ SpeechSynthesis.onstart = function () {
45
+ return setIsLoading(true);
46
+ };
47
+ SpeechSynthesis.onend = function () {
48
+ return setIsLoading(false);
49
+ };
50
+ }, []);
51
+ var handleStart = useCallback(function () {
52
+ var _options$onStart;
53
+ options === null || options === void 0 || (_options$onStart = options.onStart) === null || _options$onStart === void 0 || _options$onStart.call(options);
54
+ SpeechSynthesis === null || SpeechSynthesis === void 0 || SpeechSynthesis.speak(speechSynthesisUtterance);
55
+ }, [options, speechSynthesisUtterance]);
56
+ var handleStop = useCallback(function () {
57
+ var _options$onStop, _speechSynthesis;
58
+ options === null || options === void 0 || (_options$onStop = options.onStop) === null || _options$onStop === void 0 || _options$onStop.call(options);
59
+ (_speechSynthesis = speechSynthesis) === null || _speechSynthesis === void 0 || _speechSynthesis.cancel();
60
+ setIsLoading(false);
61
+ }, [options]);
62
+ return {
63
+ isLoading: isLoading,
64
+ setText: setText,
65
+ start: handleStart,
66
+ stop: handleStop
67
+ };
68
+ };
69
+ export default useSpeechSynthes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuntijs/ui",
3
- "version": "1.0.0-beta.67",
3
+ "version": "1.0.0-beta.69",
4
4
  "description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
5
5
  "keywords": [
6
6
  "yuntijs",
@@ -86,6 +86,7 @@
86
86
  "@lexical/selection": "^0.16.1",
87
87
  "@lexical/text": "^0.16.1",
88
88
  "@lexical/utils": "^0.16.1",
89
+ "@lobehub/tts": "^1.25.1",
89
90
  "@lobehub/ui": "^1.147.0",
90
91
  "@melloware/react-logviewer": "^5.2.0",
91
92
  "@monaco-editor/loader": "^1.4.0",
@@ -117,8 +118,8 @@
117
118
  "babel-plugin-antd-style": "latest",
118
119
  "commitlint": "^18",
119
120
  "dayjs": "^1.11.10",
120
- "dumi": "^2.4.7",
121
- "dumi-theme-yunti": "^1.1.8",
121
+ "dumi": "^2.4.9",
122
+ "dumi-theme-yunti": "^1.7.1",
122
123
  "eslint": "^8.56.0",
123
124
  "father": "^4.3.8",
124
125
  "husky": "^8",