@superinterface/react 2.8.2 → 2.9.1

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";
@@ -2955,7 +2955,7 @@ var unsupportedNames = [
2955
2955
  var isHtmlAudioSupported = !unsupportedNames.includes(((_detect = detect()) === null || _detect === void 0 ? void 0 : _detect.name) || "");
2956
2956
  // src/hooks/audioThreads/useMessageAudio/index.ts
2957
2957
  var SPLIT_SENTENCE_REGEX = /[^\.\?!]+[\.\?!]/g;
2958
- var FULL_SENTENCE_REGEX = /^\s*[A-Z].*[.?!]$/;
2958
+ var FULL_SENTENCE_REGEX = /[\.?!]$/;
2959
2959
  var getMessageSentences = function(param) {
2960
2960
  var messageId = param.messageId, input2 = param.input;
2961
2961
  var sentences = input2.match(SPLIT_SENTENCE_REGEX) || [];
@@ -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,11 +3049,10 @@ 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
3056
  useEffect5(function() {
3039
3057
  if (isHtmlAudioSupported) {
3040
3058
  var _Howler__howls___sounds_, _Howler__howls_;
@@ -3044,10 +3062,12 @@ var useMessageAudio = function(param) {
3044
3062
  }, [
3045
3063
  audioPlayer
3046
3064
  ]);
3065
+ var _useState43 = _sliced_to_array(useState4(null), 2), audioEngine = _useState43[0], setAudioEngine = _useState43[1];
3066
+ var isAudioEngineInited = useRef5(false);
3047
3067
  useEffect5(function() {
3048
3068
  if (!audioPlayer.playing) return;
3049
- if (isInited.current) return;
3050
- isInited.current = true;
3069
+ if (isAudioEngineInited.current) return;
3070
+ isAudioEngineInited.current = true;
3051
3071
  if (isHtmlAudioSupported) {
3052
3072
  var audioContext = new AudioContext();
3053
3073
  setAudioEngine({
@@ -3063,7 +3083,7 @@ var useMessageAudio = function(param) {
3063
3083
  }
3064
3084
  }, [
3065
3085
  audioPlayer,
3066
- isInited
3086
+ isAudioEngineInited
3067
3087
  ]);
3068
3088
  var visualizationAnalyser = useMemo12(function() {
3069
3089
  if (!audioEngine) return null;
@@ -3081,7 +3101,8 @@ var useMessageAudio = function(param) {
3081
3101
  unplayedMessageSentences
3082
3102
  ]);
3083
3103
  return _object_spread_props(_object_spread({
3084
- isPending: isPending
3104
+ isPending: isPending,
3105
+ isAudioPlayed: isAudioPlayed
3085
3106
  }, audioPlayer), {
3086
3107
  visualizationAnalyser: visualizationAnalyser
3087
3108
  });
@@ -3095,7 +3116,6 @@ var Root8 = function(param) {
3095
3116
  isStopOnSilence: true,
3096
3117
  onStart: /*#__PURE__*/ _async_to_generator(function() {
3097
3118
  return _ts_generator(this, function(_state) {
3098
- console.log("start");
3099
3119
  return [
3100
3120
  2
3101
3121
  ];
@@ -3175,18 +3195,14 @@ import { cluster } from "radash";
3175
3195
  import { jsx as jsx56 } from "react/jsx-runtime";
3176
3196
  var barCount = 4;
3177
3197
  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];
3198
+ var visualizationAnalyser = param.visualizationAnalyser, backgroundColor = param.backgroundColor, height = param.height, barWidth = param.barWidth;
3199
+ var _useState5 = _sliced_to_array(useState5([]), 2), barHeights = _useState5[0], setBarHeights = _useState5[1];
3188
3200
  var draw = useCallback4(function(param) {
3189
3201
  var visualizationAnalyser2 = param.visualizationAnalyser;
3202
+ if (!visualizationAnalyser2) {
3203
+ setBarHeights(Array(barCount).fill(0));
3204
+ return;
3205
+ }
3190
3206
  var frequencyData = new Uint8Array(visualizationAnalyser2.frequencyBinCount / 15);
3191
3207
  visualizationAnalyser2.getByteFrequencyData(frequencyData);
3192
3208
  var clusteredFrequencyData = cluster(frequencyData, frequencyData.length / barCount);
@@ -3201,13 +3217,11 @@ var BarsVisualizer = function(param) {
3201
3217
  }, []);
3202
3218
  useEffect6(function() {
3203
3219
  draw({
3204
- visualizationAnalyser: visualizationAnalyser || cachedEmptyVisualizer || getEmptyVisualizer()
3220
+ visualizationAnalyser: visualizationAnalyser
3205
3221
  });
3206
3222
  }, [
3207
3223
  draw,
3208
- visualizationAnalyser,
3209
- cachedEmptyVisualizer,
3210
- getEmptyVisualizer
3224
+ visualizationAnalyser
3211
3225
  ]);
3212
3226
  return /* @__PURE__ */ jsx56(Grid, {
3213
3227
  columns: "".concat(barCount),
@@ -3229,7 +3243,7 @@ var BarsVisualizer = function(param) {
3229
3243
  height: "".concat(barHeight + 20, "%"),
3230
3244
  width: barWidth,
3231
3245
  style: {
3232
- backgroundColor: "var(--".concat(color, "-11)"),
3246
+ backgroundColor: backgroundColor,
3233
3247
  borderRadius: "var(--radius-6)"
3234
3248
  }
3235
3249
  })
@@ -3253,12 +3267,12 @@ var Visualization = function() {
3253
3267
  height: "200px",
3254
3268
  width: "200px",
3255
3269
  style: {
3256
- backgroundColor: "var(--".concat(audioThreadContext.status === "playing" ? "mint" : "gray", "-4)"),
3270
+ backgroundColor: audioThreadContext.status === "playing" ? "var(--accent-4)" : "var(--gray-4)",
3257
3271
  borderRadius: "9999px"
3258
3272
  },
3259
3273
  children: /* @__PURE__ */ jsx57(BarsVisualizer, {
3260
3274
  visualizationAnalyser: audioThreadContext.messageAudioProps.visualizationAnalyser,
3261
- color: audioThreadContext.status === "playing" ? "mint" : "gray",
3275
+ backgroundColor: audioThreadContext.status === "playing" ? "var(--accent-11)" : "var(--gray-11)",
3262
3276
  height: "40px",
3263
3277
  barWidth: "24px"
3264
3278
  })
@@ -3285,15 +3299,16 @@ var ActionButton = function() {
3285
3299
  onClick: audioThreadContext.recorderProps.pause,
3286
3300
  color: "gray",
3287
3301
  radius: "full",
3302
+ variant: "soft",
3288
3303
  size: "1",
3289
3304
  children: /* @__PURE__ */ jsx58(PauseIcon, {})
3290
3305
  })
3291
3306
  }),
3292
3307
  /* @__PURE__ */ jsx58(IconButton4, {
3293
3308
  onClick: audioThreadContext.recorderProps.stop,
3294
- color: "gray",
3295
3309
  highContrast: true,
3296
3310
  radius: "full",
3311
+ variant: "soft",
3297
3312
  size: "4",
3298
3313
  style: {
3299
3314
  border: "2px solid var(--gray-8)"
@@ -3336,6 +3351,7 @@ var ActionButton = function() {
3336
3351
  size: "4",
3337
3352
  color: "gray",
3338
3353
  radius: "full",
3354
+ variant: "soft",
3339
3355
  style: {
3340
3356
  border: "2px solid var(--gray-8)"
3341
3357
  },
@@ -3348,7 +3364,6 @@ var ActionButton = function() {
3348
3364
  return audioThreadContext.messageAudioProps.play();
3349
3365
  },
3350
3366
  size: "4",
3351
- color: "gray",
3352
3367
  radius: "full",
3353
3368
  style: {
3354
3369
  border: "2px solid var(--gray-8)"
@@ -3358,8 +3373,8 @@ var ActionButton = function() {
3358
3373
  }
3359
3374
  return /* @__PURE__ */ jsx58(IconButton4, {
3360
3375
  size: "4",
3361
- color: "red",
3362
3376
  radius: "full",
3377
+ variant: "soft",
3363
3378
  disabled: true,
3364
3379
  style: {
3365
3380
  border: "2px solid var(--gray-8)"
@@ -3384,7 +3399,7 @@ var Form = function() {
3384
3399
  align: "center",
3385
3400
  children: /* @__PURE__ */ jsx59(SpeakerModerateIcon, {
3386
3401
  style: {
3387
- color: "var(--".concat(audioThreadContext.status === "recording" ? "mint" : "gray", "-12)")
3402
+ color: audioThreadContext.status === "recording" ? "var(--accent-12)" : "var(--gray-12)"
3388
3403
  }
3389
3404
  })
3390
3405
  }),
@@ -3392,12 +3407,12 @@ var Form = function() {
3392
3407
  px: "2",
3393
3408
  py: "1",
3394
3409
  style: {
3395
- backgroundColor: "var(--".concat(audioThreadContext.status === "recording" ? "mint" : "gray", "-4)"),
3410
+ backgroundColor: audioThreadContext.status === "recording" ? "var(--accent-4)" : "var(--gray-4)",
3396
3411
  borderRadius: "var(--radius-6)"
3397
3412
  },
3398
3413
  children: /* @__PURE__ */ jsx59(BarsVisualizer, {
3399
3414
  visualizationAnalyser: audioThreadContext.recorderProps.visualizationAnalyser,
3400
- color: audioThreadContext.status === "recording" ? "mint" : "gray",
3415
+ backgroundColor: audioThreadContext.status === "recording" ? "var(--accent-11)" : "var(--gray-11)",
3401
3416
  height: "20px",
3402
3417
  barWidth: "12px"
3403
3418
  })