@dreamtree-org/twreact-ui 1.1.3 → 1.1.5

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/index.esm.js CHANGED
@@ -15913,6 +15913,220 @@ function LocationPicker(_ref) {
15913
15913
  }, iconButton)));
15914
15914
  }
15915
15915
 
15916
+ var SpeechToText = /*#__PURE__*/forwardRef(function (_ref, ref) {
15917
+ var _ref$lang = _ref.lang,
15918
+ lang = _ref$lang === void 0 ? "ne-NP" : _ref$lang,
15919
+ _ref$continuous = _ref.continuous,
15920
+ continuous = _ref$continuous === void 0 ? true : _ref$continuous,
15921
+ _ref$interimResults = _ref.interimResults,
15922
+ interimResults = _ref$interimResults === void 0 ? true : _ref$interimResults,
15923
+ _ref$onSpeechComplete = _ref.onSpeechComplete,
15924
+ onSpeechComplete = _ref$onSpeechComplete === void 0 ? function () {} : _ref$onSpeechComplete,
15925
+ _ref$onSpeaking = _ref.onSpeaking,
15926
+ onSpeaking = _ref$onSpeaking === void 0 ? function () {} : _ref$onSpeaking,
15927
+ _ref$onError = _ref.onError,
15928
+ onError = _ref$onError === void 0 ? function () {} : _ref$onError,
15929
+ _ref$onStart = _ref.onStart,
15930
+ onStart = _ref$onStart === void 0 ? function () {} : _ref$onStart,
15931
+ _ref$onStop = _ref.onStop,
15932
+ onStop = _ref$onStop === void 0 ? function () {} : _ref$onStop,
15933
+ _ref$renderButton = _ref.renderButton,
15934
+ renderButton = _ref$renderButton === void 0 ? null : _ref$renderButton,
15935
+ _ref$autoStart = _ref.autoStart,
15936
+ autoStart = _ref$autoStart === void 0 ? false : _ref$autoStart,
15937
+ _ref$disabled = _ref.disabled,
15938
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled;
15939
+ var recognitionRef = useRef(null);
15940
+ var finalTranscriptRef = useRef("");
15941
+ var _useState = useState(false),
15942
+ _useState2 = _slicedToArray(_useState, 2),
15943
+ _isListening = _useState2[0],
15944
+ setIsListening = _useState2[1];
15945
+ var _useState3 = useState(true),
15946
+ _useState4 = _slicedToArray(_useState3, 2),
15947
+ _isSupported = _useState4[0],
15948
+ setIsSupported = _useState4[1];
15949
+ useEffect(function () {
15950
+ if (!("webkitSpeechRecognition" in window) && !("SpeechRecognition" in window)) {
15951
+ setIsSupported(false);
15952
+ } else {
15953
+ setIsSupported(true);
15954
+ }
15955
+ }, []);
15956
+ useEffect(function () {
15957
+ if (autoStart && _isSupported) {
15958
+ startListening();
15959
+ }
15960
+ return function () {
15961
+ if (recognitionRef.current) {
15962
+ try {
15963
+ recognitionRef.current.onresult = null;
15964
+ recognitionRef.current.onerror = null;
15965
+ recognitionRef.current.onend = null;
15966
+ recognitionRef.current.onstart = null;
15967
+ recognitionRef.current.stop();
15968
+ } catch (e) {}
15969
+ }
15970
+ };
15971
+ }, [autoStart, _isSupported]);
15972
+ function initializeRecognition() {
15973
+ if (recognitionRef.current) return recognitionRef.current;
15974
+ var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
15975
+ if (!SpeechRecognition) {
15976
+ var err = new Error("SpeechRecognition API not available");
15977
+ onError(err);
15978
+ return null;
15979
+ }
15980
+ var recognition = new SpeechRecognition();
15981
+ recognition.continuous = !!continuous;
15982
+ recognition.interimResults = !!interimResults;
15983
+ recognition.lang = lang;
15984
+ recognition.onstart = function () {
15985
+ finalTranscriptRef.current = finalTranscriptRef.current || "";
15986
+ setIsListening(true);
15987
+ onStart();
15988
+ };
15989
+ recognition.onresult = function (event) {
15990
+ var interim = "";
15991
+ var finalPart = "";
15992
+ for (var i = event.resultIndex; i < event.results.length; i++) {
15993
+ var piece = event.results[i][0].transcript;
15994
+ if (event.results[i].isFinal) {
15995
+ finalPart += piece + " ";
15996
+ } else {
15997
+ interim += piece;
15998
+ }
15999
+ }
16000
+ if (interim) {
16001
+ onSpeaking(interim);
16002
+ }
16003
+ if (finalPart) {
16004
+ finalTranscriptRef.current = (finalTranscriptRef.current || "") + finalPart;
16005
+ onSpeechComplete(finalTranscriptRef.current.trim());
16006
+ }
16007
+ };
16008
+ recognition.onerror = function (event) {
16009
+ var err = event && event.error ? new Error(event.error) : new Error("Speech recognition error");
16010
+ onError(err);
16011
+ setIsListening(false);
16012
+ };
16013
+ recognition.onend = function () {
16014
+ setIsListening(false);
16015
+ onStop();
16016
+ onSpeechComplete((finalTranscriptRef.current || "").trim());
16017
+ };
16018
+ recognitionRef.current = recognition;
16019
+ return recognition;
16020
+ }
16021
+ function startListening() {
16022
+ if (!_isSupported) {
16023
+ onError(new Error("Speech recognition not supported in this browser"));
16024
+ return;
16025
+ }
16026
+ try {
16027
+ var rec = initializeRecognition();
16028
+ if (!rec) return;
16029
+ rec.start();
16030
+ } catch (err) {
16031
+ onError(err);
16032
+ }
16033
+ }
16034
+ function stopListening() {
16035
+ if (recognitionRef.current) {
16036
+ try {
16037
+ recognitionRef.current.stop();
16038
+ } catch (e) {}
16039
+ }
16040
+ }
16041
+ function toggleListening() {
16042
+ if (disabled) return;
16043
+ if (_isListening) {
16044
+ stopListening();
16045
+ } else {
16046
+ startListening();
16047
+ }
16048
+ }
16049
+ useImperativeHandle(ref, function () {
16050
+ return {
16051
+ start: startListening,
16052
+ stop: stopListening,
16053
+ toggle: toggleListening,
16054
+ isListening: function isListening() {
16055
+ return _isListening;
16056
+ },
16057
+ isSupported: function isSupported() {
16058
+ return _isSupported;
16059
+ },
16060
+ getTranscript: function getTranscript() {
16061
+ return (finalTranscriptRef.current || "").trim();
16062
+ },
16063
+ clearTranscript: function clearTranscript() {
16064
+ finalTranscriptRef.current = "";
16065
+ }
16066
+ };
16067
+ }, [_isListening, _isSupported]);
16068
+ if (renderButton && typeof renderButton === "function") {
16069
+ return renderButton({
16070
+ isListening: _isListening,
16071
+ isSupported: _isSupported,
16072
+ start: startListening,
16073
+ stop: stopListening,
16074
+ toggle: toggleListening,
16075
+ disabled: disabled
16076
+ });
16077
+ }
16078
+ return /*#__PURE__*/React__default.createElement("button", {
16079
+ type: "button",
16080
+ "aria-pressed": _isListening,
16081
+ onClick: toggleListening,
16082
+ disabled: disabled || !_isSupported
16083
+ }, _isListening ? "Stop" : "Start");
16084
+ });
16085
+
16086
+ var TextToSpeech = function TextToSpeech(_ref) {
16087
+ var _ref$text = _ref.text,
16088
+ text = _ref$text === void 0 ? "" : _ref$text,
16089
+ _ref$rate = _ref.rate,
16090
+ rate = _ref$rate === void 0 ? 1 : _ref$rate,
16091
+ _ref$pitch = _ref.pitch,
16092
+ pitch = _ref$pitch === void 0 ? 0.5 : _ref$pitch,
16093
+ _ref$onSpeak = _ref.onSpeak,
16094
+ onSpeak = _ref$onSpeak === void 0 ? function () {} : _ref$onSpeak,
16095
+ renderButton = _ref.renderButton;
16096
+ var _useState = useState(text),
16097
+ _useState2 = _slicedToArray(_useState, 2),
16098
+ inputText = _useState2[0];
16099
+ _useState2[1];
16100
+ var _useState3 = useState(false),
16101
+ _useState4 = _slicedToArray(_useState3, 2),
16102
+ isSpeaking = _useState4[0],
16103
+ setIsSpeaking = _useState4[1];
16104
+ var handleSpeak = function handleSpeak() {
16105
+ var utterance = new SpeechSynthesisUtterance(inputText);
16106
+ utterance.rate = rate;
16107
+ utterance.pitch = pitch;
16108
+ utterance.onstart = function () {
16109
+ onSpeak(inputText);
16110
+ setIsSpeaking(true);
16111
+ };
16112
+ utterance.onend = function () {
16113
+ setIsSpeaking(false);
16114
+ };
16115
+ if (isSpeaking) {
16116
+ window.speechSynthesis.cancel();
16117
+ setIsSpeaking(false);
16118
+ } else {
16119
+ window.speechSynthesis.speak(utterance);
16120
+ }
16121
+ };
16122
+ return /*#__PURE__*/React__default.createElement("div", null, renderButton && typeof renderButton === "function" ? renderButton({
16123
+ onClick: handleSpeak,
16124
+ isSpeaking: isSpeaking
16125
+ }) : /*#__PURE__*/React__default.createElement("button", {
16126
+ onClick: handleSpeak
16127
+ }, isSpeaking ? "Stop" : "Speak"));
16128
+ };
16129
+
15916
16130
  var _excluded$d = ["items", "collapsed", "onToggle", "className", "logo", "user", "onUserClick", "drawerPosition", "isMobileOpen", "setIsMobileOpen", "showCollapsedTooltips", "tooltipOptions"];
15917
16131
 
15918
16132
  /**
@@ -16545,7 +16759,7 @@ var Navbar = function Navbar(_ref3) {
16545
16759
  "text-gray-700 hover:bg-gray-50": !item.active
16546
16760
  })
16547
16761
  }, item.label);
16548
- }))));
16762
+ }))), /*#__PURE__*/React__default.createElement("h1", null, "asddddddddddddd"));
16549
16763
  };
16550
16764
  Navbar.displayName = "Navbar";
16551
16765
  Navbar.propTypes = {
@@ -26585,4 +26799,4 @@ var StoreProvider = function StoreProvider(_ref) {
26585
26799
  }, children));
26586
26800
  };
26587
26801
 
26588
- export { Accordion, Alert, Avatar, Badge, Breadcrumbs, Button, Card, Carousel, Checkbox, ColorPicker, Condition, DatePicker, DateRangePicker, Dialog, EmitterClass as Emitter, FileUpload, FootNav, Form, Helpers, Input, Loader, LocationPicker, Navbar, Pagination, PriceRangePicker, ProgressBar, Radio, Rate, RoundedTag, Select, Sidebar, Skeleton, Stepper, StoreProvider, Switch, Table, Tabs, ThemeProvider, ThreeDotPopoverSimple as ThreeDotPopover, Toast, ToastContainer, Tooltip, cn$1 as cn, useApi, useMixins, useTheme, useToast };
26802
+ export { Accordion, Alert, Avatar, Badge, Breadcrumbs, Button, Card, Carousel, Checkbox, ColorPicker, Condition, DatePicker, DateRangePicker, Dialog, EmitterClass as Emitter, FileUpload, FootNav, Form, Helpers, Input, Loader, LocationPicker, Navbar, Pagination, PriceRangePicker, ProgressBar, Radio, Rate, RoundedTag, Select, Sidebar, Skeleton, SpeechToText, Stepper, StoreProvider, Switch, Table, Tabs, TextToSpeech, ThemeProvider, ThreeDotPopoverSimple as ThreeDotPopover, Toast, ToastContainer, Tooltip, cn$1 as cn, useApi, useMixins, useTheme, useToast };
package/dist/index.js CHANGED
@@ -15933,6 +15933,220 @@ function LocationPicker(_ref) {
15933
15933
  }, iconButton)));
15934
15934
  }
15935
15935
 
15936
+ var SpeechToText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
15937
+ var _ref$lang = _ref.lang,
15938
+ lang = _ref$lang === void 0 ? "ne-NP" : _ref$lang,
15939
+ _ref$continuous = _ref.continuous,
15940
+ continuous = _ref$continuous === void 0 ? true : _ref$continuous,
15941
+ _ref$interimResults = _ref.interimResults,
15942
+ interimResults = _ref$interimResults === void 0 ? true : _ref$interimResults,
15943
+ _ref$onSpeechComplete = _ref.onSpeechComplete,
15944
+ onSpeechComplete = _ref$onSpeechComplete === void 0 ? function () {} : _ref$onSpeechComplete,
15945
+ _ref$onSpeaking = _ref.onSpeaking,
15946
+ onSpeaking = _ref$onSpeaking === void 0 ? function () {} : _ref$onSpeaking,
15947
+ _ref$onError = _ref.onError,
15948
+ onError = _ref$onError === void 0 ? function () {} : _ref$onError,
15949
+ _ref$onStart = _ref.onStart,
15950
+ onStart = _ref$onStart === void 0 ? function () {} : _ref$onStart,
15951
+ _ref$onStop = _ref.onStop,
15952
+ onStop = _ref$onStop === void 0 ? function () {} : _ref$onStop,
15953
+ _ref$renderButton = _ref.renderButton,
15954
+ renderButton = _ref$renderButton === void 0 ? null : _ref$renderButton,
15955
+ _ref$autoStart = _ref.autoStart,
15956
+ autoStart = _ref$autoStart === void 0 ? false : _ref$autoStart,
15957
+ _ref$disabled = _ref.disabled,
15958
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled;
15959
+ var recognitionRef = React.useRef(null);
15960
+ var finalTranscriptRef = React.useRef("");
15961
+ var _useState = React.useState(false),
15962
+ _useState2 = _slicedToArray(_useState, 2),
15963
+ _isListening = _useState2[0],
15964
+ setIsListening = _useState2[1];
15965
+ var _useState3 = React.useState(true),
15966
+ _useState4 = _slicedToArray(_useState3, 2),
15967
+ _isSupported = _useState4[0],
15968
+ setIsSupported = _useState4[1];
15969
+ React.useEffect(function () {
15970
+ if (!("webkitSpeechRecognition" in window) && !("SpeechRecognition" in window)) {
15971
+ setIsSupported(false);
15972
+ } else {
15973
+ setIsSupported(true);
15974
+ }
15975
+ }, []);
15976
+ React.useEffect(function () {
15977
+ if (autoStart && _isSupported) {
15978
+ startListening();
15979
+ }
15980
+ return function () {
15981
+ if (recognitionRef.current) {
15982
+ try {
15983
+ recognitionRef.current.onresult = null;
15984
+ recognitionRef.current.onerror = null;
15985
+ recognitionRef.current.onend = null;
15986
+ recognitionRef.current.onstart = null;
15987
+ recognitionRef.current.stop();
15988
+ } catch (e) {}
15989
+ }
15990
+ };
15991
+ }, [autoStart, _isSupported]);
15992
+ function initializeRecognition() {
15993
+ if (recognitionRef.current) return recognitionRef.current;
15994
+ var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
15995
+ if (!SpeechRecognition) {
15996
+ var err = new Error("SpeechRecognition API not available");
15997
+ onError(err);
15998
+ return null;
15999
+ }
16000
+ var recognition = new SpeechRecognition();
16001
+ recognition.continuous = !!continuous;
16002
+ recognition.interimResults = !!interimResults;
16003
+ recognition.lang = lang;
16004
+ recognition.onstart = function () {
16005
+ finalTranscriptRef.current = finalTranscriptRef.current || "";
16006
+ setIsListening(true);
16007
+ onStart();
16008
+ };
16009
+ recognition.onresult = function (event) {
16010
+ var interim = "";
16011
+ var finalPart = "";
16012
+ for (var i = event.resultIndex; i < event.results.length; i++) {
16013
+ var piece = event.results[i][0].transcript;
16014
+ if (event.results[i].isFinal) {
16015
+ finalPart += piece + " ";
16016
+ } else {
16017
+ interim += piece;
16018
+ }
16019
+ }
16020
+ if (interim) {
16021
+ onSpeaking(interim);
16022
+ }
16023
+ if (finalPart) {
16024
+ finalTranscriptRef.current = (finalTranscriptRef.current || "") + finalPart;
16025
+ onSpeechComplete(finalTranscriptRef.current.trim());
16026
+ }
16027
+ };
16028
+ recognition.onerror = function (event) {
16029
+ var err = event && event.error ? new Error(event.error) : new Error("Speech recognition error");
16030
+ onError(err);
16031
+ setIsListening(false);
16032
+ };
16033
+ recognition.onend = function () {
16034
+ setIsListening(false);
16035
+ onStop();
16036
+ onSpeechComplete((finalTranscriptRef.current || "").trim());
16037
+ };
16038
+ recognitionRef.current = recognition;
16039
+ return recognition;
16040
+ }
16041
+ function startListening() {
16042
+ if (!_isSupported) {
16043
+ onError(new Error("Speech recognition not supported in this browser"));
16044
+ return;
16045
+ }
16046
+ try {
16047
+ var rec = initializeRecognition();
16048
+ if (!rec) return;
16049
+ rec.start();
16050
+ } catch (err) {
16051
+ onError(err);
16052
+ }
16053
+ }
16054
+ function stopListening() {
16055
+ if (recognitionRef.current) {
16056
+ try {
16057
+ recognitionRef.current.stop();
16058
+ } catch (e) {}
16059
+ }
16060
+ }
16061
+ function toggleListening() {
16062
+ if (disabled) return;
16063
+ if (_isListening) {
16064
+ stopListening();
16065
+ } else {
16066
+ startListening();
16067
+ }
16068
+ }
16069
+ React.useImperativeHandle(ref, function () {
16070
+ return {
16071
+ start: startListening,
16072
+ stop: stopListening,
16073
+ toggle: toggleListening,
16074
+ isListening: function isListening() {
16075
+ return _isListening;
16076
+ },
16077
+ isSupported: function isSupported() {
16078
+ return _isSupported;
16079
+ },
16080
+ getTranscript: function getTranscript() {
16081
+ return (finalTranscriptRef.current || "").trim();
16082
+ },
16083
+ clearTranscript: function clearTranscript() {
16084
+ finalTranscriptRef.current = "";
16085
+ }
16086
+ };
16087
+ }, [_isListening, _isSupported]);
16088
+ if (renderButton && typeof renderButton === "function") {
16089
+ return renderButton({
16090
+ isListening: _isListening,
16091
+ isSupported: _isSupported,
16092
+ start: startListening,
16093
+ stop: stopListening,
16094
+ toggle: toggleListening,
16095
+ disabled: disabled
16096
+ });
16097
+ }
16098
+ return /*#__PURE__*/React.createElement("button", {
16099
+ type: "button",
16100
+ "aria-pressed": _isListening,
16101
+ onClick: toggleListening,
16102
+ disabled: disabled || !_isSupported
16103
+ }, _isListening ? "Stop" : "Start");
16104
+ });
16105
+
16106
+ var TextToSpeech = function TextToSpeech(_ref) {
16107
+ var _ref$text = _ref.text,
16108
+ text = _ref$text === void 0 ? "" : _ref$text,
16109
+ _ref$rate = _ref.rate,
16110
+ rate = _ref$rate === void 0 ? 1 : _ref$rate,
16111
+ _ref$pitch = _ref.pitch,
16112
+ pitch = _ref$pitch === void 0 ? 0.5 : _ref$pitch,
16113
+ _ref$onSpeak = _ref.onSpeak,
16114
+ onSpeak = _ref$onSpeak === void 0 ? function () {} : _ref$onSpeak,
16115
+ renderButton = _ref.renderButton;
16116
+ var _useState = React.useState(text),
16117
+ _useState2 = _slicedToArray(_useState, 2),
16118
+ inputText = _useState2[0];
16119
+ _useState2[1];
16120
+ var _useState3 = React.useState(false),
16121
+ _useState4 = _slicedToArray(_useState3, 2),
16122
+ isSpeaking = _useState4[0],
16123
+ setIsSpeaking = _useState4[1];
16124
+ var handleSpeak = function handleSpeak() {
16125
+ var utterance = new SpeechSynthesisUtterance(inputText);
16126
+ utterance.rate = rate;
16127
+ utterance.pitch = pitch;
16128
+ utterance.onstart = function () {
16129
+ onSpeak(inputText);
16130
+ setIsSpeaking(true);
16131
+ };
16132
+ utterance.onend = function () {
16133
+ setIsSpeaking(false);
16134
+ };
16135
+ if (isSpeaking) {
16136
+ window.speechSynthesis.cancel();
16137
+ setIsSpeaking(false);
16138
+ } else {
16139
+ window.speechSynthesis.speak(utterance);
16140
+ }
16141
+ };
16142
+ return /*#__PURE__*/React.createElement("div", null, renderButton && typeof renderButton === "function" ? renderButton({
16143
+ onClick: handleSpeak,
16144
+ isSpeaking: isSpeaking
16145
+ }) : /*#__PURE__*/React.createElement("button", {
16146
+ onClick: handleSpeak
16147
+ }, isSpeaking ? "Stop" : "Speak"));
16148
+ };
16149
+
15936
16150
  var _excluded$d = ["items", "collapsed", "onToggle", "className", "logo", "user", "onUserClick", "drawerPosition", "isMobileOpen", "setIsMobileOpen", "showCollapsedTooltips", "tooltipOptions"];
15937
16151
 
15938
16152
  /**
@@ -16565,7 +16779,7 @@ var Navbar = function Navbar(_ref3) {
16565
16779
  "text-gray-700 hover:bg-gray-50": !item.active
16566
16780
  })
16567
16781
  }, item.label);
16568
- }))));
16782
+ }))), /*#__PURE__*/React.createElement("h1", null, "asddddddddddddd"));
16569
16783
  };
16570
16784
  Navbar.displayName = "Navbar";
16571
16785
  Navbar.propTypes = {
@@ -26637,11 +26851,13 @@ exports.RoundedTag = RoundedTag;
26637
26851
  exports.Select = Select;
26638
26852
  exports.Sidebar = Sidebar;
26639
26853
  exports.Skeleton = Skeleton;
26854
+ exports.SpeechToText = SpeechToText;
26640
26855
  exports.Stepper = Stepper;
26641
26856
  exports.StoreProvider = StoreProvider;
26642
26857
  exports.Switch = Switch;
26643
26858
  exports.Table = Table;
26644
26859
  exports.Tabs = Tabs;
26860
+ exports.TextToSpeech = TextToSpeech;
26645
26861
  exports.ThemeProvider = ThemeProvider;
26646
26862
  exports.ThreeDotPopover = ThreeDotPopoverSimple;
26647
26863
  exports.Toast = Toast;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamtree-org/twreact-ui",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "A comprehensive React + Tailwind components library for building modern web apps",
5
5
  "author": {
6
6
  "name": "Partha Preetham Krishna",