@superinterface/react 2.8.2 → 2.9.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.
package/dist/index.js CHANGED
@@ -2432,7 +2432,7 @@ var CustomToast = function(param) {
2432
2432
  height: "14px",
2433
2433
  align: "center",
2434
2434
  children: toast.type === "success" ? /* @__PURE__ */ jsx47(CheckCircledIcon2, {
2435
- color: "var(--mint-9)"
2435
+ color: "var(--accent-9)"
2436
2436
  }) : /* @__PURE__ */ jsx47(CrossCircledIcon, {
2437
2437
  color: "var(--red-9)"
2438
2438
  })
@@ -2762,8 +2762,8 @@ var useStatus = function(param) {
2762
2762
  var _latestMessageProps_latestMessage;
2763
2763
  if (recorderProps.status === "recording") return "recording";
2764
2764
  if (createMessageProps.isPending) return "creatingMessage";
2765
+ if (messageAudioProps.paused || !messageAudioProps.isAudioPlayed) return "playerPaused";
2765
2766
  if (messageAudioProps.playing || messageAudioProps.isPending) return "playing";
2766
- if (messageAudioProps.paused) return "playerPaused";
2767
2767
  if (!messageAudioProps.isReady) return "loading";
2768
2768
  if (((_latestMessageProps_latestMessage = latestMessageProps.latestMessage) === null || _latestMessageProps_latestMessage === void 0 ? void 0 : _latestMessageProps_latestMessage.status) === "in_progress") return "creatingMessage";
2769
2769
  if (recorderProps.status === "idle") return "idle";
@@ -2968,10 +2968,12 @@ var getMessageSentences = function(param) {
2968
2968
  };
2969
2969
  var useMessageAudio = function(param) {
2970
2970
  var onEnd = param.onEnd;
2971
- var _useState4 = _sliced_to_array(useState4([]), 2), playedMessageSentences = _useState4[0], setPlayedMessageSentences = _useState4[1];
2971
+ var _useState4 = _sliced_to_array(useState4(false), 2), isAudioPlayed = _useState4[0], setIsAudioPlayed = _useState4[1];
2972
+ var _useState41 = _sliced_to_array(useState4([]), 2), playedMessageSentences = _useState41[0], setPlayedMessageSentences = _useState41[1];
2972
2973
  var audioPlayer = useAudioPlayer2();
2974
+ var nextAudioPlayer = useAudioPlayer2();
2973
2975
  var superinterfaceContext = useSuperinterfaceContext();
2974
- var _useState41 = _sliced_to_array(useState4(false), 2), isPlaying = _useState41[0], setIsPlaying = _useState41[1];
2976
+ var _useState42 = _sliced_to_array(useState4(false), 2), isPlaying = _useState42[0], setIsPlaying = _useState42[1];
2975
2977
  var latestMessageProps = useLatestMessage();
2976
2978
  var unplayedMessageSentences = useMemo12(function() {
2977
2979
  if (!latestMessageProps.latestMessage) return [];
@@ -3015,8 +3017,25 @@ var useMessageAudio = function(param) {
3015
3017
  }, superinterfaceContext.variables));
3016
3018
  audioPlayer.load("".concat(superinterfaceContext.baseUrl, "/tts?").concat(searchParams), {
3017
3019
  format: "mp3",
3018
- autoplay: true,
3020
+ autoplay: isAudioPlayed,
3019
3021
  html5: isHtmlAudioSupported,
3022
+ onplay: function() {
3023
+ setIsAudioPlayed(true);
3024
+ },
3025
+ onload: function() {
3026
+ var nextUnplayedMessageSentence = unplayedMessageSentences[1];
3027
+ if (!nextUnplayedMessageSentence) return;
3028
+ var isNextFullSentence = FULL_SENTENCE_REGEX.test(nextUnplayedMessageSentence.sentence);
3029
+ if (!isNextFullSentence) return;
3030
+ var nextSearchParams = new URLSearchParams(_object_spread({
3031
+ input: nextUnplayedMessageSentence.sentence
3032
+ }, superinterfaceContext.variables));
3033
+ nextAudioPlayer.load("".concat(superinterfaceContext.baseUrl, "/tts?").concat(nextSearchParams), {
3034
+ format: "mp3",
3035
+ autoplay: false,
3036
+ html5: isHtmlAudioSupported
3037
+ });
3038
+ },
3020
3039
  onend: function() {
3021
3040
  setIsPlaying(false);
3022
3041
  if (unplayedMessageSentences.length === 1 && latestMessageProps.latestMessage.status !== "in_progress") {
@@ -3030,24 +3049,16 @@ var useMessageAudio = function(param) {
3030
3049
  superinterfaceContext,
3031
3050
  latestMessageProps,
3032
3051
  audioPlayer,
3052
+ nextAudioPlayer,
3033
3053
  playedMessageSentences,
3034
3054
  onEnd
3035
3055
  ]);
3036
- var isInited = useRef5(false);
3037
- var _useState42 = _sliced_to_array(useState4(null), 2), audioEngine = _useState42[0], setAudioEngine = _useState42[1];
3038
- useEffect5(function() {
3039
- if (isHtmlAudioSupported) {
3040
- var _Howler__howls___sounds_, _Howler__howls_;
3041
- if (!(Howler === null || Howler === void 0 ? void 0 : (_Howler__howls_ = Howler._howls[0]) === null || _Howler__howls_ === void 0 ? void 0 : (_Howler__howls___sounds_ = _Howler__howls_._sounds[0]) === null || _Howler__howls___sounds_ === void 0 ? void 0 : _Howler__howls___sounds_._node)) return;
3042
- Howler._howls[0]._sounds[0]._node.crossOrigin = "anonymous";
3043
- }
3044
- }, [
3045
- audioPlayer
3046
- ]);
3056
+ var _useState43 = _sliced_to_array(useState4(null), 2), audioEngine = _useState43[0], setAudioEngine = _useState43[1];
3057
+ var isAudioEngineInited = useRef5(false);
3047
3058
  useEffect5(function() {
3048
3059
  if (!audioPlayer.playing) return;
3049
- if (isInited.current) return;
3050
- isInited.current = true;
3060
+ if (isAudioEngineInited.current) return;
3061
+ isAudioEngineInited.current = true;
3051
3062
  if (isHtmlAudioSupported) {
3052
3063
  var audioContext = new AudioContext();
3053
3064
  setAudioEngine({
@@ -3063,7 +3074,7 @@ var useMessageAudio = function(param) {
3063
3074
  }
3064
3075
  }, [
3065
3076
  audioPlayer,
3066
- isInited
3077
+ isAudioEngineInited
3067
3078
  ]);
3068
3079
  var visualizationAnalyser = useMemo12(function() {
3069
3080
  if (!audioEngine) return null;
@@ -3081,7 +3092,8 @@ var useMessageAudio = function(param) {
3081
3092
  unplayedMessageSentences
3082
3093
  ]);
3083
3094
  return _object_spread_props(_object_spread({
3084
- isPending: isPending
3095
+ isPending: isPending,
3096
+ isAudioPlayed: isAudioPlayed
3085
3097
  }, audioPlayer), {
3086
3098
  visualizationAnalyser: visualizationAnalyser
3087
3099
  });
@@ -3095,7 +3107,6 @@ var Root8 = function(param) {
3095
3107
  isStopOnSilence: true,
3096
3108
  onStart: /*#__PURE__*/ _async_to_generator(function() {
3097
3109
  return _ts_generator(this, function(_state) {
3098
- console.log("start");
3099
3110
  return [
3100
3111
  2
3101
3112
  ];
@@ -3175,18 +3186,14 @@ import { cluster } from "radash";
3175
3186
  import { jsx as jsx56 } from "react/jsx-runtime";
3176
3187
  var barCount = 4;
3177
3188
  var BarsVisualizer = function(param) {
3178
- var visualizationAnalyser = param.visualizationAnalyser, color = param.color, height = param.height, barWidth = param.barWidth;
3179
- var _useState5 = _sliced_to_array(useState5(null), 2), cachedEmptyVisualizer = _useState5[0], setCachedEmptyVisualizer = _useState5[1];
3180
- var getEmptyVisualizer = useCallback4(function() {
3181
- var result = new AudioContext().createAnalyser();
3182
- setCachedEmptyVisualizer(result);
3183
- return result;
3184
- }, [
3185
- cachedEmptyVisualizer
3186
- ]);
3187
- var _useState51 = _sliced_to_array(useState5([]), 2), barHeights = _useState51[0], setBarHeights = _useState51[1];
3189
+ var visualizationAnalyser = param.visualizationAnalyser, backgroundColor = param.backgroundColor, height = param.height, barWidth = param.barWidth;
3190
+ var _useState5 = _sliced_to_array(useState5([]), 2), barHeights = _useState5[0], setBarHeights = _useState5[1];
3188
3191
  var draw = useCallback4(function(param) {
3189
3192
  var visualizationAnalyser2 = param.visualizationAnalyser;
3193
+ if (!visualizationAnalyser2) {
3194
+ setBarHeights(Array(barCount).fill(0));
3195
+ return;
3196
+ }
3190
3197
  var frequencyData = new Uint8Array(visualizationAnalyser2.frequencyBinCount / 15);
3191
3198
  visualizationAnalyser2.getByteFrequencyData(frequencyData);
3192
3199
  var clusteredFrequencyData = cluster(frequencyData, frequencyData.length / barCount);
@@ -3201,13 +3208,11 @@ var BarsVisualizer = function(param) {
3201
3208
  }, []);
3202
3209
  useEffect6(function() {
3203
3210
  draw({
3204
- visualizationAnalyser: visualizationAnalyser || cachedEmptyVisualizer || getEmptyVisualizer()
3211
+ visualizationAnalyser: visualizationAnalyser
3205
3212
  });
3206
3213
  }, [
3207
3214
  draw,
3208
- visualizationAnalyser,
3209
- cachedEmptyVisualizer,
3210
- getEmptyVisualizer
3215
+ visualizationAnalyser
3211
3216
  ]);
3212
3217
  return /* @__PURE__ */ jsx56(Grid, {
3213
3218
  columns: "".concat(barCount),
@@ -3229,7 +3234,7 @@ var BarsVisualizer = function(param) {
3229
3234
  height: "".concat(barHeight + 20, "%"),
3230
3235
  width: barWidth,
3231
3236
  style: {
3232
- backgroundColor: "var(--".concat(color, "-11)"),
3237
+ backgroundColor: backgroundColor,
3233
3238
  borderRadius: "var(--radius-6)"
3234
3239
  }
3235
3240
  })
@@ -3253,12 +3258,12 @@ var Visualization = function() {
3253
3258
  height: "200px",
3254
3259
  width: "200px",
3255
3260
  style: {
3256
- backgroundColor: "var(--".concat(audioThreadContext.status === "playing" ? "mint" : "gray", "-4)"),
3261
+ backgroundColor: audioThreadContext.status === "playing" ? "var(--accent-4)" : "var(--gray-4)",
3257
3262
  borderRadius: "9999px"
3258
3263
  },
3259
3264
  children: /* @__PURE__ */ jsx57(BarsVisualizer, {
3260
3265
  visualizationAnalyser: audioThreadContext.messageAudioProps.visualizationAnalyser,
3261
- color: audioThreadContext.status === "playing" ? "mint" : "gray",
3266
+ backgroundColor: audioThreadContext.status === "playing" ? "var(--accent-11)" : "var(--gray-11)",
3262
3267
  height: "40px",
3263
3268
  barWidth: "24px"
3264
3269
  })
@@ -3348,9 +3353,9 @@ var ActionButton = function() {
3348
3353
  return audioThreadContext.messageAudioProps.play();
3349
3354
  },
3350
3355
  size: "4",
3351
- color: "gray",
3352
3356
  radius: "full",
3353
3357
  style: {
3358
+ backgroundColor: "var(--accent-11)",
3354
3359
  border: "2px solid var(--gray-8)"
3355
3360
  },
3356
3361
  children: /* @__PURE__ */ jsx58(ResumeIcon, {})
@@ -3384,7 +3389,7 @@ var Form = function() {
3384
3389
  align: "center",
3385
3390
  children: /* @__PURE__ */ jsx59(SpeakerModerateIcon, {
3386
3391
  style: {
3387
- color: "var(--".concat(audioThreadContext.status === "recording" ? "mint" : "gray", "-12)")
3392
+ color: audioThreadContext.status === "recording" ? "var(--accent-12)" : "var(--gray-12)"
3388
3393
  }
3389
3394
  })
3390
3395
  }),
@@ -3392,12 +3397,12 @@ var Form = function() {
3392
3397
  px: "2",
3393
3398
  py: "1",
3394
3399
  style: {
3395
- backgroundColor: "var(--".concat(audioThreadContext.status === "recording" ? "mint" : "gray", "-4)"),
3400
+ backgroundColor: audioThreadContext.status === "recording" ? "var(--accent-4)" : "var(--gray-4)",
3396
3401
  borderRadius: "var(--radius-6)"
3397
3402
  },
3398
3403
  children: /* @__PURE__ */ jsx59(BarsVisualizer, {
3399
3404
  visualizationAnalyser: audioThreadContext.recorderProps.visualizationAnalyser,
3400
- color: audioThreadContext.status === "recording" ? "mint" : "gray",
3405
+ backgroundColor: audioThreadContext.status === "recording" ? "var(--accent-11)" : "var(--gray-11)",
3401
3406
  height: "20px",
3402
3407
  barWidth: "12px"
3403
3408
  })