@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.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";
@@ -3082,7 +3082,7 @@ var unsupportedNames = [
3082
3082
  var isHtmlAudioSupported = !unsupportedNames.includes(((_this = (0, import_detect_browser.detect)()) === null || _this === void 0 ? void 0 : _this.name) || "");
3083
3083
  // src/hooks/audioThreads/useMessageAudio/index.ts
3084
3084
  var SPLIT_SENTENCE_REGEX = /[^\.\?!]+[\.\?!]/g;
3085
- var FULL_SENTENCE_REGEX = /^\s*[A-Z].*[.?!]$/;
3085
+ var FULL_SENTENCE_REGEX = /[\.?!]$/;
3086
3086
  var getMessageSentences = function(param) {
3087
3087
  var messageId = param.messageId, input2 = param.input;
3088
3088
  var sentences = input2.match(SPLIT_SENTENCE_REGEX) || [];
@@ -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,11 +3176,10 @@ 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
3183
  (0, import_react40.useEffect)(function() {
3166
3184
  if (isHtmlAudioSupported) {
3167
3185
  var _import_howler_Howler__howls___sounds_, _import_howler_Howler__howls_, _import_howler_Howler;
@@ -3171,10 +3189,12 @@ var useMessageAudio = function(param) {
3171
3189
  }, [
3172
3190
  audioPlayer
3173
3191
  ]);
3192
+ var _ref3 = _sliced_to_array((0, import_react40.useState)(null), 2), audioEngine = _ref3[0], setAudioEngine = _ref3[1];
3193
+ var isAudioEngineInited = (0, import_react40.useRef)(false);
3174
3194
  (0, import_react40.useEffect)(function() {
3175
3195
  if (!audioPlayer.playing) return;
3176
- if (isInited.current) return;
3177
- isInited.current = true;
3196
+ if (isAudioEngineInited.current) return;
3197
+ isAudioEngineInited.current = true;
3178
3198
  if (isHtmlAudioSupported) {
3179
3199
  var audioContext = new AudioContext();
3180
3200
  setAudioEngine({
@@ -3190,7 +3210,7 @@ var useMessageAudio = function(param) {
3190
3210
  }
3191
3211
  }, [
3192
3212
  audioPlayer,
3193
- isInited
3213
+ isAudioEngineInited
3194
3214
  ]);
3195
3215
  var visualizationAnalyser = (0, import_react40.useMemo)(function() {
3196
3216
  if (!audioEngine) return null;
@@ -3208,7 +3228,8 @@ var useMessageAudio = function(param) {
3208
3228
  unplayedMessageSentences
3209
3229
  ]);
3210
3230
  return _object_spread_props(_object_spread({
3211
- isPending: isPending
3231
+ isPending: isPending,
3232
+ isAudioPlayed: isAudioPlayed
3212
3233
  }, audioPlayer), {
3213
3234
  visualizationAnalyser: visualizationAnalyser
3214
3235
  });
@@ -3222,7 +3243,6 @@ var Root8 = function(param) {
3222
3243
  isStopOnSilence: true,
3223
3244
  onStart: /*#__PURE__*/ _async_to_generator(function() {
3224
3245
  return _ts_generator(this, function(_state) {
3225
- console.log("start");
3226
3246
  return [
3227
3247
  2
3228
3248
  ];
@@ -3302,18 +3322,14 @@ var import_radash12 = require("radash");
3302
3322
  var import_jsx_runtime56 = require("react/jsx-runtime");
3303
3323
  var barCount = 4;
3304
3324
  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];
3325
+ var visualizationAnalyser = param.visualizationAnalyser, backgroundColor = param.backgroundColor, height = param.height, barWidth = param.barWidth;
3326
+ var _ref = _sliced_to_array((0, import_react42.useState)([]), 2), barHeights = _ref[0], setBarHeights = _ref[1];
3315
3327
  var draw = (0, import_react42.useCallback)(function(param) {
3316
3328
  var visualizationAnalyser2 = param.visualizationAnalyser;
3329
+ if (!visualizationAnalyser2) {
3330
+ setBarHeights(Array(barCount).fill(0));
3331
+ return;
3332
+ }
3317
3333
  var frequencyData = new Uint8Array(visualizationAnalyser2.frequencyBinCount / 15);
3318
3334
  visualizationAnalyser2.getByteFrequencyData(frequencyData);
3319
3335
  var clusteredFrequencyData = (0, import_radash12.cluster)(frequencyData, frequencyData.length / barCount);
@@ -3328,13 +3344,11 @@ var BarsVisualizer = function(param) {
3328
3344
  }, []);
3329
3345
  (0, import_react42.useEffect)(function() {
3330
3346
  draw({
3331
- visualizationAnalyser: visualizationAnalyser || cachedEmptyVisualizer || getEmptyVisualizer()
3347
+ visualizationAnalyser: visualizationAnalyser
3332
3348
  });
3333
3349
  }, [
3334
3350
  draw,
3335
- visualizationAnalyser,
3336
- cachedEmptyVisualizer,
3337
- getEmptyVisualizer
3351
+ visualizationAnalyser
3338
3352
  ]);
3339
3353
  return /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(import_themes42.Grid, {
3340
3354
  columns: "".concat(barCount),
@@ -3356,7 +3370,7 @@ var BarsVisualizer = function(param) {
3356
3370
  height: "".concat(barHeight + 20, "%"),
3357
3371
  width: barWidth,
3358
3372
  style: {
3359
- backgroundColor: "var(--".concat(color, "-11)"),
3373
+ backgroundColor: backgroundColor,
3360
3374
  borderRadius: "var(--radius-6)"
3361
3375
  }
3362
3376
  })
@@ -3380,12 +3394,12 @@ var Visualization = function() {
3380
3394
  height: "200px",
3381
3395
  width: "200px",
3382
3396
  style: {
3383
- backgroundColor: "var(--".concat(audioThreadContext.status === "playing" ? "mint" : "gray", "-4)"),
3397
+ backgroundColor: audioThreadContext.status === "playing" ? "var(--accent-4)" : "var(--gray-4)",
3384
3398
  borderRadius: "9999px"
3385
3399
  },
3386
3400
  children: /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(BarsVisualizer, {
3387
3401
  visualizationAnalyser: audioThreadContext.messageAudioProps.visualizationAnalyser,
3388
- color: audioThreadContext.status === "playing" ? "mint" : "gray",
3402
+ backgroundColor: audioThreadContext.status === "playing" ? "var(--accent-11)" : "var(--gray-11)",
3389
3403
  height: "40px",
3390
3404
  barWidth: "24px"
3391
3405
  })
@@ -3412,15 +3426,16 @@ var ActionButton = function() {
3412
3426
  onClick: audioThreadContext.recorderProps.pause,
3413
3427
  color: "gray",
3414
3428
  radius: "full",
3429
+ variant: "soft",
3415
3430
  size: "1",
3416
3431
  children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(import_react_icons9.PauseIcon, {})
3417
3432
  })
3418
3433
  }),
3419
3434
  /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(import_themes44.IconButton, {
3420
3435
  onClick: audioThreadContext.recorderProps.stop,
3421
- color: "gray",
3422
3436
  highContrast: true,
3423
3437
  radius: "full",
3438
+ variant: "soft",
3424
3439
  size: "4",
3425
3440
  style: {
3426
3441
  border: "2px solid var(--gray-8)"
@@ -3463,6 +3478,7 @@ var ActionButton = function() {
3463
3478
  size: "4",
3464
3479
  color: "gray",
3465
3480
  radius: "full",
3481
+ variant: "soft",
3466
3482
  style: {
3467
3483
  border: "2px solid var(--gray-8)"
3468
3484
  },
@@ -3475,7 +3491,6 @@ var ActionButton = function() {
3475
3491
  return audioThreadContext.messageAudioProps.play();
3476
3492
  },
3477
3493
  size: "4",
3478
- color: "gray",
3479
3494
  radius: "full",
3480
3495
  style: {
3481
3496
  border: "2px solid var(--gray-8)"
@@ -3485,8 +3500,8 @@ var ActionButton = function() {
3485
3500
  }
3486
3501
  return /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(import_themes44.IconButton, {
3487
3502
  size: "4",
3488
- color: "red",
3489
3503
  radius: "full",
3504
+ variant: "soft",
3490
3505
  disabled: true,
3491
3506
  style: {
3492
3507
  border: "2px solid var(--gray-8)"
@@ -3511,7 +3526,7 @@ var Form = function() {
3511
3526
  align: "center",
3512
3527
  children: /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(import_react_icons10.SpeakerModerateIcon, {
3513
3528
  style: {
3514
- color: "var(--".concat(audioThreadContext.status === "recording" ? "mint" : "gray", "-12)")
3529
+ color: audioThreadContext.status === "recording" ? "var(--accent-12)" : "var(--gray-12)"
3515
3530
  }
3516
3531
  })
3517
3532
  }),
@@ -3519,12 +3534,12 @@ var Form = function() {
3519
3534
  px: "2",
3520
3535
  py: "1",
3521
3536
  style: {
3522
- backgroundColor: "var(--".concat(audioThreadContext.status === "recording" ? "mint" : "gray", "-4)"),
3537
+ backgroundColor: audioThreadContext.status === "recording" ? "var(--accent-4)" : "var(--gray-4)",
3523
3538
  borderRadius: "var(--radius-6)"
3524
3539
  },
3525
3540
  children: /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(BarsVisualizer, {
3526
3541
  visualizationAnalyser: audioThreadContext.recorderProps.visualizationAnalyser,
3527
- color: audioThreadContext.status === "recording" ? "mint" : "gray",
3542
+ backgroundColor: audioThreadContext.status === "recording" ? "var(--accent-11)" : "var(--gray-11)",
3528
3543
  height: "20px",
3529
3544
  barWidth: "12px"
3530
3545
  })