@scalemule/nextjs 0.1.19 → 0.1.20

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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ApiError, RealtimeService, StorageService, PhotoService, VideoService, AudioService, TtsService, TtsJobStatus, FileStatus } from '@scalemule/sdk';
2
+ import { ApiError, RealtimeService, StorageService, PhotoService, VideoService, AudioService, TtsService, TtsJobStatus, FileStatus, TtsAudioInfo } from '@scalemule/sdk';
3
3
  import * as React from 'react';
4
4
  import { ReactNode, ReactElement } from 'react';
5
5
  import { MoneyClient } from '@scalemule/money';
@@ -888,6 +888,21 @@ interface FeedbackWidgetProps {
888
888
  */
889
889
  declare function FeedbackWidget(props: FeedbackWidgetProps): ReactElement | null;
890
890
 
891
+ type NarrationPlayerAudio = TtsAudioInfo & {
892
+ waveform_peaks?: number[] | null;
893
+ ai_generated?: boolean;
894
+ };
895
+ interface NarrationPlayerProps {
896
+ audio: NarrationPlayerAudio;
897
+ className?: string;
898
+ providerLabel?: string;
899
+ narrationLabel?: string;
900
+ refreshing?: boolean;
901
+ onRefresh?: () => void;
902
+ onPlaybackError?: () => void;
903
+ }
904
+ declare function NarrationPlayer({ audio, className, providerLabel, narrationLabel, refreshing, onRefresh, onPlaybackError, }: NarrationPlayerProps): react_jsx_runtime.JSX.Element | null;
905
+
891
906
  /**
892
907
  * Client-side validation helpers
893
908
  *
@@ -1046,4 +1061,4 @@ declare function createSafeLogger(prefix: string): {
1046
1061
  error: (message: string, data?: unknown) => void;
1047
1062
  };
1048
1063
 
1049
- export { ApiError$1 as ApiError, type AudioFile, type AudioUploadResult, type ConversationKind, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type MediaPolicy, type MediaUploadResult, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, type UseAudioReturn, type UseAudioUploadOptions, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, type UseTtsJobOptions, type UseTtsJobReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, validateForm, validators };
1064
+ export { ApiError$1 as ApiError, type AudioFile, type AudioUploadResult, type ConversationKind, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type MediaPolicy, type MediaUploadResult, NarrationPlayer, type NarrationPlayerAudio, type NarrationPlayerProps, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, type UseAudioReturn, type UseAudioUploadOptions, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, type UseTtsJobOptions, type UseTtsJobReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, validateForm, validators };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ApiError, RealtimeService, StorageService, PhotoService, VideoService, AudioService, TtsService, TtsJobStatus, FileStatus } from '@scalemule/sdk';
2
+ import { ApiError, RealtimeService, StorageService, PhotoService, VideoService, AudioService, TtsService, TtsJobStatus, FileStatus, TtsAudioInfo } from '@scalemule/sdk';
3
3
  import * as React from 'react';
4
4
  import { ReactNode, ReactElement } from 'react';
5
5
  import { MoneyClient } from '@scalemule/money';
@@ -888,6 +888,21 @@ interface FeedbackWidgetProps {
888
888
  */
889
889
  declare function FeedbackWidget(props: FeedbackWidgetProps): ReactElement | null;
890
890
 
891
+ type NarrationPlayerAudio = TtsAudioInfo & {
892
+ waveform_peaks?: number[] | null;
893
+ ai_generated?: boolean;
894
+ };
895
+ interface NarrationPlayerProps {
896
+ audio: NarrationPlayerAudio;
897
+ className?: string;
898
+ providerLabel?: string;
899
+ narrationLabel?: string;
900
+ refreshing?: boolean;
901
+ onRefresh?: () => void;
902
+ onPlaybackError?: () => void;
903
+ }
904
+ declare function NarrationPlayer({ audio, className, providerLabel, narrationLabel, refreshing, onRefresh, onPlaybackError, }: NarrationPlayerProps): react_jsx_runtime.JSX.Element | null;
905
+
891
906
  /**
892
907
  * Client-side validation helpers
893
908
  *
@@ -1046,4 +1061,4 @@ declare function createSafeLogger(prefix: string): {
1046
1061
  error: (message: string, data?: unknown) => void;
1047
1062
  };
1048
1063
 
1049
- export { ApiError$1 as ApiError, type AudioFile, type AudioUploadResult, type ConversationKind, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type MediaPolicy, type MediaUploadResult, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, type UseAudioReturn, type UseAudioUploadOptions, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, type UseTtsJobOptions, type UseTtsJobReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, validateForm, validators };
1064
+ export { ApiError$1 as ApiError, type AudioFile, type AudioUploadResult, type ConversationKind, type FeatureFlagEvaluation, type FeatureFlagEvaluation as FeatureFlagResult, type FeedbackItem, type FeedbackItemInput, type FeedbackPriority, type FeedbackStatus, type FeedbackType, FeedbackWidget, type FeedbackWidgetConfig, type FeedbackWidgetProps, ListFilesParams, LoginResponse, type MediaPolicy, type MediaUploadResult, NarrationPlayer, type NarrationPlayerAudio, type NarrationPlayerProps, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleMedia, type ScaleMuleMediaProps, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, type UseAudioReturn, type UseAudioUploadOptions, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseFeatureFlagsOptions, type UseFeatureFlagsReturn, type UseFeedbackOptions, type UseFeedbackResult, type UseFileStatusOptions, type UseFileStatusReturn, type UseFeatureFlagsOptions as UseFlagsOptions, type UseFeatureFlagsReturn as UseFlagsReturn, type UseMediaReturn, type UseMediaUploadOptions, type UsePushNotificationsOptions, type UsePushNotificationsReturn, type UseRealtimeOptions, type UseRealtimeReturn, type UseShareOptions, type UseShareReturn, type UseTtsJobOptions, type UseTtsJobReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, validateForm, validators };
package/dist/index.js CHANGED
@@ -11288,6 +11288,230 @@ function FeedbackWidget(props) {
11288
11288
  ) })
11289
11289
  ] });
11290
11290
  }
11291
+ var SPEEDS = [1, 1.25, 1.5, 2];
11292
+ function formatTime(seconds) {
11293
+ if (!Number.isFinite(seconds) || seconds <= 0) {
11294
+ return "0:00";
11295
+ }
11296
+ const wholeSeconds = Math.floor(seconds);
11297
+ const minutes = Math.floor(wholeSeconds / 60);
11298
+ const remainder = wholeSeconds % 60;
11299
+ return `${minutes}:${remainder.toString().padStart(2, "0")}`;
11300
+ }
11301
+ function getNextSpeed(currentSpeed) {
11302
+ const currentIndex = SPEEDS.findIndex((speed) => speed === currentSpeed);
11303
+ if (currentIndex === -1) {
11304
+ return SPEEDS[0];
11305
+ }
11306
+ return SPEEDS[(currentIndex + 1) % SPEEDS.length];
11307
+ }
11308
+ function NarrationPlayer({
11309
+ audio,
11310
+ className,
11311
+ providerLabel = "ScaleMule",
11312
+ narrationLabel = "AI-Narrated",
11313
+ refreshing = false,
11314
+ onRefresh,
11315
+ onPlaybackError
11316
+ }) {
11317
+ const audioRef = React.useRef(null);
11318
+ const scrubRef = React.useRef(null);
11319
+ const [playing, setPlaying] = React.useState(false);
11320
+ const [currentTime, setCurrentTime] = React.useState(0);
11321
+ const [duration, setDuration] = React.useState(audio.duration_ms ? audio.duration_ms / 1e3 : 0);
11322
+ const [speed, setSpeed] = React.useState(1.5);
11323
+ const peaks = React.useMemo(() => {
11324
+ if (!Array.isArray(audio.waveform_peaks)) {
11325
+ return [];
11326
+ }
11327
+ const sampled = audio.waveform_peaks.filter((_, index) => index % 3 === 0).slice(0, 220);
11328
+ return sampled.length > 0 ? sampled : audio.waveform_peaks.slice(0, 220);
11329
+ }, [audio.waveform_peaks]);
11330
+ React.useEffect(() => {
11331
+ const element = audioRef.current;
11332
+ if (!element) return;
11333
+ setCurrentTime(0);
11334
+ setPlaying(false);
11335
+ element.pause();
11336
+ element.currentTime = 0;
11337
+ }, [audio.url]);
11338
+ React.useEffect(() => {
11339
+ const element = audioRef.current;
11340
+ if (!element) return;
11341
+ element.playbackRate = speed;
11342
+ element.preservesPitch = true;
11343
+ }, [speed]);
11344
+ function togglePlayback() {
11345
+ const element = audioRef.current;
11346
+ if (!element) return;
11347
+ if (element.paused) {
11348
+ element.play().catch(() => {
11349
+ setPlaying(false);
11350
+ onPlaybackError?.();
11351
+ });
11352
+ return;
11353
+ }
11354
+ element.pause();
11355
+ }
11356
+ function seekTo(clientX) {
11357
+ const element = audioRef.current;
11358
+ const scrubber = scrubRef.current;
11359
+ if (!element || !scrubber || !duration) return;
11360
+ const bounds = scrubber.getBoundingClientRect();
11361
+ const ratio = Math.max(0, Math.min(1, (clientX - bounds.left) / bounds.width));
11362
+ const nextTime = ratio * duration;
11363
+ element.currentTime = nextTime;
11364
+ setCurrentTime(nextTime);
11365
+ }
11366
+ const progress = duration > 0 ? Math.min(1, currentTime / duration) : 0;
11367
+ const expiresLabel = audio.expires_at ? new Date(audio.expires_at).toLocaleTimeString([], {
11368
+ hour: "numeric",
11369
+ minute: "2-digit"
11370
+ }) : null;
11371
+ if (!audio.url) {
11372
+ return null;
11373
+ }
11374
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11375
+ "div",
11376
+ {
11377
+ className: "rounded-[1.75rem] border border-slate-200/80 bg-[linear-gradient(180deg,#f8fbff_0%,#edf4ff_100%)] p-4 text-slate-900 shadow-[0_22px_70px_rgba(4,12,24,0.28)] " + (className ?? ""),
11378
+ children: [
11379
+ /* @__PURE__ */ jsxRuntime.jsx(
11380
+ "audio",
11381
+ {
11382
+ ref: audioRef,
11383
+ src: audio.url ?? void 0,
11384
+ preload: "metadata",
11385
+ onLoadedMetadata: (event) => {
11386
+ setDuration(event.currentTarget.duration || 0);
11387
+ },
11388
+ onTimeUpdate: (event) => {
11389
+ setCurrentTime(event.currentTarget.currentTime);
11390
+ },
11391
+ onPlay: () => setPlaying(true),
11392
+ onPause: () => setPlaying(false),
11393
+ onEnded: () => setPlaying(false),
11394
+ onError: () => onPlaybackError?.()
11395
+ }
11396
+ ),
11397
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4 md:flex-row md:items-center", children: [
11398
+ /* @__PURE__ */ jsxRuntime.jsx(
11399
+ "button",
11400
+ {
11401
+ type: "button",
11402
+ onClick: togglePlayback,
11403
+ "aria-label": playing ? "Pause narration" : "Play narration",
11404
+ className: "flex h-[4.5rem] w-[4.5rem] shrink-0 items-center justify-center rounded-full bg-slate-950 text-white shadow-[0_10px_28px_rgba(15,23,42,0.25)] transition hover:bg-slate-800",
11405
+ children: playing ? /* @__PURE__ */ jsxRuntime.jsxs("svg", { viewBox: "0 0 24 24", className: "h-7 w-7 fill-current", "aria-hidden": "true", children: [
11406
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "6", y: "5", width: "4", height: "14", rx: "1.2" }),
11407
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "14", y: "5", width: "4", height: "14", rx: "1.2" })
11408
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", className: "ml-1 h-7 w-7 fill-current", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M7 5.2c0-1.02 1.12-1.65 2-.98l10.2 7.78a1.24 1.24 0 0 1 0 1.98L9 21.76c-.88.67-2-.04-2-1.08V5.2Z" }) })
11409
+ }
11410
+ ),
11411
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
11412
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 text-[0.8rem] font-medium text-slate-500", children: [
11413
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: formatTime(currentTime / speed) }),
11414
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
11415
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rounded-full bg-blue-100 px-3 py-1 text-[0.65rem] font-semibold uppercase tracking-[0.24em] text-blue-700", children: narrationLabel }),
11416
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: formatTime(duration / speed) })
11417
+ ] })
11418
+ ] }),
11419
+ /* @__PURE__ */ jsxRuntime.jsx(
11420
+ "div",
11421
+ {
11422
+ ref: scrubRef,
11423
+ role: "slider",
11424
+ "aria-label": "Narration progress",
11425
+ "aria-valuemin": 0,
11426
+ "aria-valuemax": Math.max(1, Math.floor(duration)),
11427
+ "aria-valuenow": Math.floor(currentTime),
11428
+ tabIndex: 0,
11429
+ onClick: (event) => {
11430
+ seekTo(event.clientX);
11431
+ },
11432
+ className: "relative mt-4 h-12 cursor-pointer overflow-hidden rounded-[1rem] bg-slate-200/90 px-1",
11433
+ children: peaks.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
11434
+ "svg",
11435
+ {
11436
+ viewBox: `0 0 ${peaks.length} 40`,
11437
+ preserveAspectRatio: "none",
11438
+ className: "pointer-events-none absolute inset-0 h-full w-full",
11439
+ children: peaks.map((peak, index) => {
11440
+ const height = Math.max(2, Math.round(Math.abs(peak) * 34));
11441
+ const y = (40 - height) / 2;
11442
+ const filled = index / peaks.length < progress;
11443
+ return /* @__PURE__ */ jsxRuntime.jsx(
11444
+ "rect",
11445
+ {
11446
+ x: index,
11447
+ y,
11448
+ width: 0.82,
11449
+ height,
11450
+ rx: 0.4,
11451
+ className: filled ? "fill-blue-600" : "fill-blue-300"
11452
+ },
11453
+ `${audio.id}-${index}`
11454
+ );
11455
+ })
11456
+ }
11457
+ ) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
11458
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 bg-slate-200/90" }),
11459
+ /* @__PURE__ */ jsxRuntime.jsx(
11460
+ "div",
11461
+ {
11462
+ className: "absolute inset-y-0 left-0 bg-blue-600",
11463
+ style: { width: `${progress * 100}%` }
11464
+ }
11465
+ )
11466
+ ] })
11467
+ }
11468
+ ),
11469
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-4 flex flex-wrap items-center gap-2 text-[0.72rem] font-medium text-slate-500", children: [
11470
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "rounded-full border border-slate-200 bg-white/85 px-3 py-1 text-slate-700", children: [
11471
+ "Provider: ",
11472
+ providerLabel
11473
+ ] }),
11474
+ duration > 0 && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "rounded-full border border-slate-200 bg-white/65 px-3 py-1", children: [
11475
+ "Length ",
11476
+ formatTime(duration / speed)
11477
+ ] }),
11478
+ expiresLabel && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "rounded-full border border-slate-200 bg-white/65 px-3 py-1", children: [
11479
+ "Expires ",
11480
+ expiresLabel
11481
+ ] })
11482
+ ] })
11483
+ ] }),
11484
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex shrink-0 items-center gap-2 self-start md:self-center", children: [
11485
+ /* @__PURE__ */ jsxRuntime.jsxs(
11486
+ "button",
11487
+ {
11488
+ type: "button",
11489
+ onClick: () => {
11490
+ setSpeed((currentSpeed) => getNextSpeed(currentSpeed));
11491
+ },
11492
+ className: "rounded-full border border-slate-300 bg-white/90 px-4 py-2 text-base font-semibold text-slate-700 shadow-sm hover:bg-white",
11493
+ children: [
11494
+ speed,
11495
+ "\xD7"
11496
+ ]
11497
+ }
11498
+ ),
11499
+ onRefresh && /* @__PURE__ */ jsxRuntime.jsx(
11500
+ "button",
11501
+ {
11502
+ type: "button",
11503
+ onClick: onRefresh,
11504
+ disabled: refreshing,
11505
+ className: "rounded-full border border-slate-300 bg-white/75 px-4 py-2 text-sm font-semibold text-slate-700 hover:bg-white disabled:cursor-not-allowed disabled:opacity-60",
11506
+ children: refreshing ? "Refreshing\u2026" : "Refresh"
11507
+ }
11508
+ )
11509
+ ] })
11510
+ ] })
11511
+ ]
11512
+ }
11513
+ );
11514
+ }
11291
11515
 
11292
11516
  // src/validation.ts
11293
11517
  var phoneCountries = [
@@ -11589,6 +11813,7 @@ Object.defineProperty(exports, "createMoneyClient", {
11589
11813
  get: function () { return money.createMoneyClient; }
11590
11814
  });
11591
11815
  exports.FeedbackWidget = FeedbackWidget;
11816
+ exports.NarrationPlayer = NarrationPlayer;
11592
11817
  exports.ScaleMuleApiError = ScaleMuleApiError;
11593
11818
  exports.ScaleMuleClient = ScaleMuleClient2;
11594
11819
  exports.ScaleMuleMedia = ScaleMuleMedia;
package/dist/index.mjs CHANGED
@@ -11268,6 +11268,230 @@ function FeedbackWidget(props) {
11268
11268
  ) })
11269
11269
  ] });
11270
11270
  }
11271
+ var SPEEDS = [1, 1.25, 1.5, 2];
11272
+ function formatTime(seconds) {
11273
+ if (!Number.isFinite(seconds) || seconds <= 0) {
11274
+ return "0:00";
11275
+ }
11276
+ const wholeSeconds = Math.floor(seconds);
11277
+ const minutes = Math.floor(wholeSeconds / 60);
11278
+ const remainder = wholeSeconds % 60;
11279
+ return `${minutes}:${remainder.toString().padStart(2, "0")}`;
11280
+ }
11281
+ function getNextSpeed(currentSpeed) {
11282
+ const currentIndex = SPEEDS.findIndex((speed) => speed === currentSpeed);
11283
+ if (currentIndex === -1) {
11284
+ return SPEEDS[0];
11285
+ }
11286
+ return SPEEDS[(currentIndex + 1) % SPEEDS.length];
11287
+ }
11288
+ function NarrationPlayer({
11289
+ audio,
11290
+ className,
11291
+ providerLabel = "ScaleMule",
11292
+ narrationLabel = "AI-Narrated",
11293
+ refreshing = false,
11294
+ onRefresh,
11295
+ onPlaybackError
11296
+ }) {
11297
+ const audioRef = useRef(null);
11298
+ const scrubRef = useRef(null);
11299
+ const [playing, setPlaying] = useState(false);
11300
+ const [currentTime, setCurrentTime] = useState(0);
11301
+ const [duration, setDuration] = useState(audio.duration_ms ? audio.duration_ms / 1e3 : 0);
11302
+ const [speed, setSpeed] = useState(1.5);
11303
+ const peaks = useMemo(() => {
11304
+ if (!Array.isArray(audio.waveform_peaks)) {
11305
+ return [];
11306
+ }
11307
+ const sampled = audio.waveform_peaks.filter((_, index) => index % 3 === 0).slice(0, 220);
11308
+ return sampled.length > 0 ? sampled : audio.waveform_peaks.slice(0, 220);
11309
+ }, [audio.waveform_peaks]);
11310
+ useEffect(() => {
11311
+ const element = audioRef.current;
11312
+ if (!element) return;
11313
+ setCurrentTime(0);
11314
+ setPlaying(false);
11315
+ element.pause();
11316
+ element.currentTime = 0;
11317
+ }, [audio.url]);
11318
+ useEffect(() => {
11319
+ const element = audioRef.current;
11320
+ if (!element) return;
11321
+ element.playbackRate = speed;
11322
+ element.preservesPitch = true;
11323
+ }, [speed]);
11324
+ function togglePlayback() {
11325
+ const element = audioRef.current;
11326
+ if (!element) return;
11327
+ if (element.paused) {
11328
+ element.play().catch(() => {
11329
+ setPlaying(false);
11330
+ onPlaybackError?.();
11331
+ });
11332
+ return;
11333
+ }
11334
+ element.pause();
11335
+ }
11336
+ function seekTo(clientX) {
11337
+ const element = audioRef.current;
11338
+ const scrubber = scrubRef.current;
11339
+ if (!element || !scrubber || !duration) return;
11340
+ const bounds = scrubber.getBoundingClientRect();
11341
+ const ratio = Math.max(0, Math.min(1, (clientX - bounds.left) / bounds.width));
11342
+ const nextTime = ratio * duration;
11343
+ element.currentTime = nextTime;
11344
+ setCurrentTime(nextTime);
11345
+ }
11346
+ const progress = duration > 0 ? Math.min(1, currentTime / duration) : 0;
11347
+ const expiresLabel = audio.expires_at ? new Date(audio.expires_at).toLocaleTimeString([], {
11348
+ hour: "numeric",
11349
+ minute: "2-digit"
11350
+ }) : null;
11351
+ if (!audio.url) {
11352
+ return null;
11353
+ }
11354
+ return /* @__PURE__ */ jsxs(
11355
+ "div",
11356
+ {
11357
+ className: "rounded-[1.75rem] border border-slate-200/80 bg-[linear-gradient(180deg,#f8fbff_0%,#edf4ff_100%)] p-4 text-slate-900 shadow-[0_22px_70px_rgba(4,12,24,0.28)] " + (className ?? ""),
11358
+ children: [
11359
+ /* @__PURE__ */ jsx(
11360
+ "audio",
11361
+ {
11362
+ ref: audioRef,
11363
+ src: audio.url ?? void 0,
11364
+ preload: "metadata",
11365
+ onLoadedMetadata: (event) => {
11366
+ setDuration(event.currentTarget.duration || 0);
11367
+ },
11368
+ onTimeUpdate: (event) => {
11369
+ setCurrentTime(event.currentTarget.currentTime);
11370
+ },
11371
+ onPlay: () => setPlaying(true),
11372
+ onPause: () => setPlaying(false),
11373
+ onEnded: () => setPlaying(false),
11374
+ onError: () => onPlaybackError?.()
11375
+ }
11376
+ ),
11377
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4 md:flex-row md:items-center", children: [
11378
+ /* @__PURE__ */ jsx(
11379
+ "button",
11380
+ {
11381
+ type: "button",
11382
+ onClick: togglePlayback,
11383
+ "aria-label": playing ? "Pause narration" : "Play narration",
11384
+ className: "flex h-[4.5rem] w-[4.5rem] shrink-0 items-center justify-center rounded-full bg-slate-950 text-white shadow-[0_10px_28px_rgba(15,23,42,0.25)] transition hover:bg-slate-800",
11385
+ children: playing ? /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", className: "h-7 w-7 fill-current", "aria-hidden": "true", children: [
11386
+ /* @__PURE__ */ jsx("rect", { x: "6", y: "5", width: "4", height: "14", rx: "1.2" }),
11387
+ /* @__PURE__ */ jsx("rect", { x: "14", y: "5", width: "4", height: "14", rx: "1.2" })
11388
+ ] }) : /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", className: "ml-1 h-7 w-7 fill-current", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M7 5.2c0-1.02 1.12-1.65 2-.98l10.2 7.78a1.24 1.24 0 0 1 0 1.98L9 21.76c-.88.67-2-.04-2-1.08V5.2Z" }) })
11389
+ }
11390
+ ),
11391
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
11392
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 text-[0.8rem] font-medium text-slate-500", children: [
11393
+ /* @__PURE__ */ jsx("span", { children: formatTime(currentTime / speed) }),
11394
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
11395
+ /* @__PURE__ */ jsx("span", { className: "rounded-full bg-blue-100 px-3 py-1 text-[0.65rem] font-semibold uppercase tracking-[0.24em] text-blue-700", children: narrationLabel }),
11396
+ /* @__PURE__ */ jsx("span", { children: formatTime(duration / speed) })
11397
+ ] })
11398
+ ] }),
11399
+ /* @__PURE__ */ jsx(
11400
+ "div",
11401
+ {
11402
+ ref: scrubRef,
11403
+ role: "slider",
11404
+ "aria-label": "Narration progress",
11405
+ "aria-valuemin": 0,
11406
+ "aria-valuemax": Math.max(1, Math.floor(duration)),
11407
+ "aria-valuenow": Math.floor(currentTime),
11408
+ tabIndex: 0,
11409
+ onClick: (event) => {
11410
+ seekTo(event.clientX);
11411
+ },
11412
+ className: "relative mt-4 h-12 cursor-pointer overflow-hidden rounded-[1rem] bg-slate-200/90 px-1",
11413
+ children: peaks.length > 0 ? /* @__PURE__ */ jsx(
11414
+ "svg",
11415
+ {
11416
+ viewBox: `0 0 ${peaks.length} 40`,
11417
+ preserveAspectRatio: "none",
11418
+ className: "pointer-events-none absolute inset-0 h-full w-full",
11419
+ children: peaks.map((peak, index) => {
11420
+ const height = Math.max(2, Math.round(Math.abs(peak) * 34));
11421
+ const y = (40 - height) / 2;
11422
+ const filled = index / peaks.length < progress;
11423
+ return /* @__PURE__ */ jsx(
11424
+ "rect",
11425
+ {
11426
+ x: index,
11427
+ y,
11428
+ width: 0.82,
11429
+ height,
11430
+ rx: 0.4,
11431
+ className: filled ? "fill-blue-600" : "fill-blue-300"
11432
+ },
11433
+ `${audio.id}-${index}`
11434
+ );
11435
+ })
11436
+ }
11437
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
11438
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0 bg-slate-200/90" }),
11439
+ /* @__PURE__ */ jsx(
11440
+ "div",
11441
+ {
11442
+ className: "absolute inset-y-0 left-0 bg-blue-600",
11443
+ style: { width: `${progress * 100}%` }
11444
+ }
11445
+ )
11446
+ ] })
11447
+ }
11448
+ ),
11449
+ /* @__PURE__ */ jsxs("div", { className: "mt-4 flex flex-wrap items-center gap-2 text-[0.72rem] font-medium text-slate-500", children: [
11450
+ /* @__PURE__ */ jsxs("span", { className: "rounded-full border border-slate-200 bg-white/85 px-3 py-1 text-slate-700", children: [
11451
+ "Provider: ",
11452
+ providerLabel
11453
+ ] }),
11454
+ duration > 0 && /* @__PURE__ */ jsxs("span", { className: "rounded-full border border-slate-200 bg-white/65 px-3 py-1", children: [
11455
+ "Length ",
11456
+ formatTime(duration / speed)
11457
+ ] }),
11458
+ expiresLabel && /* @__PURE__ */ jsxs("span", { className: "rounded-full border border-slate-200 bg-white/65 px-3 py-1", children: [
11459
+ "Expires ",
11460
+ expiresLabel
11461
+ ] })
11462
+ ] })
11463
+ ] }),
11464
+ /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-2 self-start md:self-center", children: [
11465
+ /* @__PURE__ */ jsxs(
11466
+ "button",
11467
+ {
11468
+ type: "button",
11469
+ onClick: () => {
11470
+ setSpeed((currentSpeed) => getNextSpeed(currentSpeed));
11471
+ },
11472
+ className: "rounded-full border border-slate-300 bg-white/90 px-4 py-2 text-base font-semibold text-slate-700 shadow-sm hover:bg-white",
11473
+ children: [
11474
+ speed,
11475
+ "\xD7"
11476
+ ]
11477
+ }
11478
+ ),
11479
+ onRefresh && /* @__PURE__ */ jsx(
11480
+ "button",
11481
+ {
11482
+ type: "button",
11483
+ onClick: onRefresh,
11484
+ disabled: refreshing,
11485
+ className: "rounded-full border border-slate-300 bg-white/75 px-4 py-2 text-sm font-semibold text-slate-700 hover:bg-white disabled:cursor-not-allowed disabled:opacity-60",
11486
+ children: refreshing ? "Refreshing\u2026" : "Refresh"
11487
+ }
11488
+ )
11489
+ ] })
11490
+ ] })
11491
+ ]
11492
+ }
11493
+ );
11494
+ }
11271
11495
 
11272
11496
  // src/validation.ts
11273
11497
  var phoneCountries = [
@@ -11560,4 +11784,4 @@ function createSafeLogger(prefix) {
11560
11784
  };
11561
11785
  }
11562
11786
 
11563
- export { FeedbackWidget, ScaleMuleApiError, ScaleMuleClient2 as ScaleMuleClient, ScaleMuleMedia, ScaleMuleProvider, composePhone, createClient, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, validateForm, validators };
11787
+ export { FeedbackWidget, NarrationPlayer, ScaleMuleApiError, ScaleMuleClient2 as ScaleMuleClient, ScaleMuleMedia, ScaleMuleProvider, composePhone, createClient, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAudio, useAuth, useBilling, useContent, useFeatureFlags, useFeedback, useFileStatus, useMedia, useMoney, useMoneyClient, usePushNotifications, useRealtime, useScaleMule, useScaleMuleClient, useShare, useTtsJob, useUser, validateForm, validators };
@@ -0,0 +1,44 @@
1
+ declare const SM_LEDVERY_STATE_COOKIE = "sm_ledvery_state";
2
+ declare const SM_LEDVERY_PKCE_VERIFIER_COOKIE = "sm_ledvery_pkce_verifier";
3
+ declare const SM_LEDVERY_NONCE_COOKIE = "sm_ledvery_nonce";
4
+ declare const SM_LEDVERY_ID_TOKEN_COOKIE = "sm_ledvery_id_token";
5
+ declare const SM_LEDVERY_ACCESS_TOKEN_COOKIE = "sm_ledvery_access_token";
6
+ interface SessionCookieOverrides {
7
+ maxAge?: number;
8
+ domain?: string;
9
+ path?: string;
10
+ sameSite?: 'strict' | 'lax' | 'none';
11
+ secure?: boolean;
12
+ }
13
+ interface LedverySessionData {
14
+ idToken: string;
15
+ accessToken?: string;
16
+ claims: Record<string, unknown>;
17
+ expiresAt: string;
18
+ }
19
+ declare function getLedverySession(request: Request): LedverySessionData | null;
20
+
21
+ interface LedveryRoutesConfig {
22
+ issuer: string;
23
+ clientId: string;
24
+ clientSecret?: string;
25
+ redirectUri: string;
26
+ defaultScope?: string;
27
+ postLoginRedirect?: string;
28
+ postLogoutRedirect?: string;
29
+ cookies?: SessionCookieOverrides;
30
+ storeAccessToken?: boolean;
31
+ fetch?: typeof fetch;
32
+ gatewayUrl?: string;
33
+ }
34
+ type RouteHandler = (request: Request, context: {
35
+ params: Promise<{
36
+ action?: string[];
37
+ }>;
38
+ }) => Promise<Response>;
39
+ declare function createLedveryRoutes(config: LedveryRoutesConfig): {
40
+ GET: RouteHandler;
41
+ POST: RouteHandler;
42
+ };
43
+
44
+ export { type LedveryRoutesConfig as L, SM_LEDVERY_ACCESS_TOKEN_COOKIE as S, type LedverySessionData as a, SM_LEDVERY_ID_TOKEN_COOKIE as b, SM_LEDVERY_NONCE_COOKIE as c, SM_LEDVERY_PKCE_VERIFIER_COOKIE as d, SM_LEDVERY_STATE_COOKIE as e, createLedveryRoutes as f, getLedverySession as g };
@@ -0,0 +1,44 @@
1
+ declare const SM_LEDVERY_STATE_COOKIE = "sm_ledvery_state";
2
+ declare const SM_LEDVERY_PKCE_VERIFIER_COOKIE = "sm_ledvery_pkce_verifier";
3
+ declare const SM_LEDVERY_NONCE_COOKIE = "sm_ledvery_nonce";
4
+ declare const SM_LEDVERY_ID_TOKEN_COOKIE = "sm_ledvery_id_token";
5
+ declare const SM_LEDVERY_ACCESS_TOKEN_COOKIE = "sm_ledvery_access_token";
6
+ interface SessionCookieOverrides {
7
+ maxAge?: number;
8
+ domain?: string;
9
+ path?: string;
10
+ sameSite?: 'strict' | 'lax' | 'none';
11
+ secure?: boolean;
12
+ }
13
+ interface LedverySessionData {
14
+ idToken: string;
15
+ accessToken?: string;
16
+ claims: Record<string, unknown>;
17
+ expiresAt: string;
18
+ }
19
+ declare function getLedverySession(request: Request): LedverySessionData | null;
20
+
21
+ interface LedveryRoutesConfig {
22
+ issuer: string;
23
+ clientId: string;
24
+ clientSecret?: string;
25
+ redirectUri: string;
26
+ defaultScope?: string;
27
+ postLoginRedirect?: string;
28
+ postLogoutRedirect?: string;
29
+ cookies?: SessionCookieOverrides;
30
+ storeAccessToken?: boolean;
31
+ fetch?: typeof fetch;
32
+ gatewayUrl?: string;
33
+ }
34
+ type RouteHandler = (request: Request, context: {
35
+ params: Promise<{
36
+ action?: string[];
37
+ }>;
38
+ }) => Promise<Response>;
39
+ declare function createLedveryRoutes(config: LedveryRoutesConfig): {
40
+ GET: RouteHandler;
41
+ POST: RouteHandler;
42
+ };
43
+
44
+ export { type LedveryRoutesConfig as L, SM_LEDVERY_ACCESS_TOKEN_COOKIE as S, type LedverySessionData as a, SM_LEDVERY_ID_TOKEN_COOKIE as b, SM_LEDVERY_NONCE_COOKIE as c, SM_LEDVERY_PKCE_VERIFIER_COOKIE as d, SM_LEDVERY_STATE_COOKIE as e, createLedveryRoutes as f, getLedverySession as g };
@@ -0,0 +1 @@
1
+ export { L as LedveryRoutesConfig, a as LedverySessionData, f as createLedveryRoutes, g as getLedverySession } from '../ledvery-CxPzZpxP.mjs';
@@ -0,0 +1 @@
1
+ export { L as LedveryRoutesConfig, a as LedverySessionData, f as createLedveryRoutes, g as getLedverySession } from '../ledvery-CxPzZpxP.js';