@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.cjs CHANGED
@@ -2559,7 +2559,7 @@ var CustomToast = function(param) {
2559
2559
  height: "14px",
2560
2560
  align: "center",
2561
2561
  children: toast.type === "success" ? /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(import_react_icons6.CheckCircledIcon, {
2562
- color: "var(--mint-9)"
2562
+ color: "var(--accent-9)"
2563
2563
  }) : /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(import_react_icons6.CrossCircledIcon, {
2564
2564
  color: "var(--red-9)"
2565
2565
  })
@@ -2889,8 +2889,8 @@ var useStatus = function(param) {
2889
2889
  var _latestMessageProps_latestMessage;
2890
2890
  if (recorderProps.status === "recording") return "recording";
2891
2891
  if (createMessageProps.isPending) return "creatingMessage";
2892
+ if (messageAudioProps.paused || !messageAudioProps.isAudioPlayed) return "playerPaused";
2892
2893
  if (messageAudioProps.playing || messageAudioProps.isPending) return "playing";
2893
- if (messageAudioProps.paused) return "playerPaused";
2894
2894
  if (!messageAudioProps.isReady) return "loading";
2895
2895
  if (((_latestMessageProps_latestMessage = latestMessageProps.latestMessage) === null || _latestMessageProps_latestMessage === void 0 ? void 0 : _latestMessageProps_latestMessage.status) === "in_progress") return "creatingMessage";
2896
2896
  if (recorderProps.status === "idle") return "idle";
@@ -3095,10 +3095,12 @@ var getMessageSentences = function(param) {
3095
3095
  };
3096
3096
  var useMessageAudio = function(param) {
3097
3097
  var onEnd = param.onEnd;
3098
- var _ref = _sliced_to_array((0, import_react40.useState)([]), 2), playedMessageSentences = _ref[0], setPlayedMessageSentences = _ref[1];
3098
+ var _ref = _sliced_to_array((0, import_react40.useState)(false), 2), isAudioPlayed = _ref[0], setIsAudioPlayed = _ref[1];
3099
+ var _ref1 = _sliced_to_array((0, import_react40.useState)([]), 2), playedMessageSentences = _ref1[0], setPlayedMessageSentences = _ref1[1];
3099
3100
  var audioPlayer = (0, import_react_use_audio_player2.useAudioPlayer)();
3101
+ var nextAudioPlayer = (0, import_react_use_audio_player2.useAudioPlayer)();
3100
3102
  var superinterfaceContext = useSuperinterfaceContext();
3101
- var _ref1 = _sliced_to_array((0, import_react40.useState)(false), 2), isPlaying = _ref1[0], setIsPlaying = _ref1[1];
3103
+ var _ref2 = _sliced_to_array((0, import_react40.useState)(false), 2), isPlaying = _ref2[0], setIsPlaying = _ref2[1];
3102
3104
  var latestMessageProps = useLatestMessage();
3103
3105
  var unplayedMessageSentences = (0, import_react40.useMemo)(function() {
3104
3106
  if (!latestMessageProps.latestMessage) return [];
@@ -3142,8 +3144,25 @@ var useMessageAudio = function(param) {
3142
3144
  }, superinterfaceContext.variables));
3143
3145
  audioPlayer.load("".concat(superinterfaceContext.baseUrl, "/tts?").concat(searchParams), {
3144
3146
  format: "mp3",
3145
- autoplay: true,
3147
+ autoplay: isAudioPlayed,
3146
3148
  html5: isHtmlAudioSupported,
3149
+ onplay: function() {
3150
+ setIsAudioPlayed(true);
3151
+ },
3152
+ onload: function() {
3153
+ var nextUnplayedMessageSentence = unplayedMessageSentences[1];
3154
+ if (!nextUnplayedMessageSentence) return;
3155
+ var isNextFullSentence = FULL_SENTENCE_REGEX.test(nextUnplayedMessageSentence.sentence);
3156
+ if (!isNextFullSentence) return;
3157
+ var nextSearchParams = new URLSearchParams(_object_spread({
3158
+ input: nextUnplayedMessageSentence.sentence
3159
+ }, superinterfaceContext.variables));
3160
+ nextAudioPlayer.load("".concat(superinterfaceContext.baseUrl, "/tts?").concat(nextSearchParams), {
3161
+ format: "mp3",
3162
+ autoplay: false,
3163
+ html5: isHtmlAudioSupported
3164
+ });
3165
+ },
3147
3166
  onend: function() {
3148
3167
  setIsPlaying(false);
3149
3168
  if (unplayedMessageSentences.length === 1 && latestMessageProps.latestMessage.status !== "in_progress") {
@@ -3157,24 +3176,16 @@ var useMessageAudio = function(param) {
3157
3176
  superinterfaceContext,
3158
3177
  latestMessageProps,
3159
3178
  audioPlayer,
3179
+ nextAudioPlayer,
3160
3180
  playedMessageSentences,
3161
3181
  onEnd
3162
3182
  ]);
3163
- var isInited = (0, import_react40.useRef)(false);
3164
- var _ref2 = _sliced_to_array((0, import_react40.useState)(null), 2), audioEngine = _ref2[0], setAudioEngine = _ref2[1];
3165
- (0, import_react40.useEffect)(function() {
3166
- if (isHtmlAudioSupported) {
3167
- var _import_howler_Howler__howls___sounds_, _import_howler_Howler__howls_, _import_howler_Howler;
3168
- if (!((_import_howler_Howler = import_howler.Howler) === null || _import_howler_Howler === void 0 ? void 0 : (_import_howler_Howler__howls_ = _import_howler_Howler._howls[0]) === null || _import_howler_Howler__howls_ === void 0 ? void 0 : (_import_howler_Howler__howls___sounds_ = _import_howler_Howler__howls_._sounds[0]) === null || _import_howler_Howler__howls___sounds_ === void 0 ? void 0 : _import_howler_Howler__howls___sounds_._node)) return;
3169
- import_howler.Howler._howls[0]._sounds[0]._node.crossOrigin = "anonymous";
3170
- }
3171
- }, [
3172
- audioPlayer
3173
- ]);
3183
+ var _ref3 = _sliced_to_array((0, import_react40.useState)(null), 2), audioEngine = _ref3[0], setAudioEngine = _ref3[1];
3184
+ var isAudioEngineInited = (0, import_react40.useRef)(false);
3174
3185
  (0, import_react40.useEffect)(function() {
3175
3186
  if (!audioPlayer.playing) return;
3176
- if (isInited.current) return;
3177
- isInited.current = true;
3187
+ if (isAudioEngineInited.current) return;
3188
+ isAudioEngineInited.current = true;
3178
3189
  if (isHtmlAudioSupported) {
3179
3190
  var audioContext = new AudioContext();
3180
3191
  setAudioEngine({
@@ -3190,7 +3201,7 @@ var useMessageAudio = function(param) {
3190
3201
  }
3191
3202
  }, [
3192
3203
  audioPlayer,
3193
- isInited
3204
+ isAudioEngineInited
3194
3205
  ]);
3195
3206
  var visualizationAnalyser = (0, import_react40.useMemo)(function() {
3196
3207
  if (!audioEngine) return null;
@@ -3208,7 +3219,8 @@ var useMessageAudio = function(param) {
3208
3219
  unplayedMessageSentences
3209
3220
  ]);
3210
3221
  return _object_spread_props(_object_spread({
3211
- isPending: isPending
3222
+ isPending: isPending,
3223
+ isAudioPlayed: isAudioPlayed
3212
3224
  }, audioPlayer), {
3213
3225
  visualizationAnalyser: visualizationAnalyser
3214
3226
  });
@@ -3222,7 +3234,6 @@ var Root8 = function(param) {
3222
3234
  isStopOnSilence: true,
3223
3235
  onStart: /*#__PURE__*/ _async_to_generator(function() {
3224
3236
  return _ts_generator(this, function(_state) {
3225
- console.log("start");
3226
3237
  return [
3227
3238
  2
3228
3239
  ];
@@ -3302,18 +3313,14 @@ var import_radash12 = require("radash");
3302
3313
  var import_jsx_runtime56 = require("react/jsx-runtime");
3303
3314
  var barCount = 4;
3304
3315
  var BarsVisualizer = function(param) {
3305
- var visualizationAnalyser = param.visualizationAnalyser, color = param.color, height = param.height, barWidth = param.barWidth;
3306
- var _ref = _sliced_to_array((0, import_react42.useState)(null), 2), cachedEmptyVisualizer = _ref[0], setCachedEmptyVisualizer = _ref[1];
3307
- var getEmptyVisualizer = (0, import_react42.useCallback)(function() {
3308
- var result = new AudioContext().createAnalyser();
3309
- setCachedEmptyVisualizer(result);
3310
- return result;
3311
- }, [
3312
- cachedEmptyVisualizer
3313
- ]);
3314
- var _ref1 = _sliced_to_array((0, import_react42.useState)([]), 2), barHeights = _ref1[0], setBarHeights = _ref1[1];
3316
+ var visualizationAnalyser = param.visualizationAnalyser, backgroundColor = param.backgroundColor, height = param.height, barWidth = param.barWidth;
3317
+ var _ref = _sliced_to_array((0, import_react42.useState)([]), 2), barHeights = _ref[0], setBarHeights = _ref[1];
3315
3318
  var draw = (0, import_react42.useCallback)(function(param) {
3316
3319
  var visualizationAnalyser2 = param.visualizationAnalyser;
3320
+ if (!visualizationAnalyser2) {
3321
+ setBarHeights(Array(barCount).fill(0));
3322
+ return;
3323
+ }
3317
3324
  var frequencyData = new Uint8Array(visualizationAnalyser2.frequencyBinCount / 15);
3318
3325
  visualizationAnalyser2.getByteFrequencyData(frequencyData);
3319
3326
  var clusteredFrequencyData = (0, import_radash12.cluster)(frequencyData, frequencyData.length / barCount);
@@ -3328,13 +3335,11 @@ var BarsVisualizer = function(param) {
3328
3335
  }, []);
3329
3336
  (0, import_react42.useEffect)(function() {
3330
3337
  draw({
3331
- visualizationAnalyser: visualizationAnalyser || cachedEmptyVisualizer || getEmptyVisualizer()
3338
+ visualizationAnalyser: visualizationAnalyser
3332
3339
  });
3333
3340
  }, [
3334
3341
  draw,
3335
- visualizationAnalyser,
3336
- cachedEmptyVisualizer,
3337
- getEmptyVisualizer
3342
+ visualizationAnalyser
3338
3343
  ]);
3339
3344
  return /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_themes42.Grid, {
3340
3345
  columns: "".concat(barCount),
@@ -3356,7 +3361,7 @@ var BarsVisualizer = function(param) {
3356
3361
  height: "".concat(barHeight + 20, "%"),
3357
3362
  width: barWidth,
3358
3363
  style: {
3359
- backgroundColor: "var(--".concat(color, "-11)"),
3364
+ backgroundColor: backgroundColor,
3360
3365
  borderRadius: "var(--radius-6)"
3361
3366
  }
3362
3367
  })
@@ -3380,12 +3385,12 @@ var Visualization = function() {
3380
3385
  height: "200px",
3381
3386
  width: "200px",
3382
3387
  style: {
3383
- backgroundColor: "var(--".concat(audioThreadContext.status === "playing" ? "mint" : "gray", "-4)"),
3388
+ backgroundColor: audioThreadContext.status === "playing" ? "var(--accent-4)" : "var(--gray-4)",
3384
3389
  borderRadius: "9999px"
3385
3390
  },
3386
3391
  children: /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(BarsVisualizer, {
3387
3392
  visualizationAnalyser: audioThreadContext.messageAudioProps.visualizationAnalyser,
3388
- color: audioThreadContext.status === "playing" ? "mint" : "gray",
3393
+ backgroundColor: audioThreadContext.status === "playing" ? "var(--accent-11)" : "var(--gray-11)",
3389
3394
  height: "40px",
3390
3395
  barWidth: "24px"
3391
3396
  })
@@ -3475,9 +3480,9 @@ var ActionButton = function() {
3475
3480
  return audioThreadContext.messageAudioProps.play();
3476
3481
  },
3477
3482
  size: "4",
3478
- color: "gray",
3479
3483
  radius: "full",
3480
3484
  style: {
3485
+ backgroundColor: "var(--accent-11)",
3481
3486
  border: "2px solid var(--gray-8)"
3482
3487
  },
3483
3488
  children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(import_react_icons9.ResumeIcon, {})
@@ -3511,7 +3516,7 @@ var Form = function() {
3511
3516
  align: "center",
3512
3517
  children: /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(import_react_icons10.SpeakerModerateIcon, {
3513
3518
  style: {
3514
- color: "var(--".concat(audioThreadContext.status === "recording" ? "mint" : "gray", "-12)")
3519
+ color: audioThreadContext.status === "recording" ? "var(--accent-12)" : "var(--gray-12)"
3515
3520
  }
3516
3521
  })
3517
3522
  }),
@@ -3519,12 +3524,12 @@ var Form = function() {
3519
3524
  px: "2",
3520
3525
  py: "1",
3521
3526
  style: {
3522
- backgroundColor: "var(--".concat(audioThreadContext.status === "recording" ? "mint" : "gray", "-4)"),
3527
+ backgroundColor: audioThreadContext.status === "recording" ? "var(--accent-4)" : "var(--gray-4)",
3523
3528
  borderRadius: "var(--radius-6)"
3524
3529
  },
3525
3530
  children: /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(BarsVisualizer, {
3526
3531
  visualizationAnalyser: audioThreadContext.recorderProps.visualizationAnalyser,
3527
- color: audioThreadContext.status === "recording" ? "mint" : "gray",
3532
+ backgroundColor: audioThreadContext.status === "recording" ? "var(--accent-11)" : "var(--gray-11)",
3528
3533
  height: "20px",
3529
3534
  barWidth: "12px"
3530
3535
  })