saltfish 0.3.28 → 0.3.30

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.
@@ -1507,6 +1507,14 @@ const useSaltfishStore = {
1507
1507
  subscribe: saltfishStore.subscribe,
1508
1508
  destroy: saltfishStore.destroy
1509
1509
  };
1510
+ function getSaltfishStore() {
1511
+ try {
1512
+ return useSaltfishStore.getState();
1513
+ } catch (error2) {
1514
+ const errorMessage = `[storeUtils] Failed to access Saltfish store: ${error2}`;
1515
+ throw new Error(errorMessage);
1516
+ }
1517
+ }
1510
1518
  const MAX_PROGRESS_AGE_MS = 6e3;
1511
1519
  function parseProgressTimestamp(progressData) {
1512
1520
  if (!progressData) {
@@ -1688,7 +1696,7 @@ class ErrorHandler {
1688
1696
  */
1689
1697
  static updateStore(error2) {
1690
1698
  try {
1691
- const store = useSaltfishStore.getState();
1699
+ const store = getSaltfishStore();
1692
1700
  store.setError(error2);
1693
1701
  } catch (storeError) {
1694
1702
  console.error("Failed to update store with error:", storeError);
@@ -1700,7 +1708,7 @@ class ErrorHandler {
1700
1708
  static triggerErrorEvent(error2, context, errorType) {
1701
1709
  var _a, _b;
1702
1710
  try {
1703
- const store = useSaltfishStore.getState();
1711
+ const store = getSaltfishStore();
1704
1712
  if (typeof window !== "undefined" && window._saltfishPlayer) {
1705
1713
  const player = window._saltfishPlayer;
1706
1714
  if (player && player.eventManager) {
@@ -1929,7 +1937,7 @@ class PlayerInitializationService {
1929
1937
  // Default to true if not specified
1930
1938
  };
1931
1939
  this.lastConfig = updatedConfig;
1932
- const store = useSaltfishStore.getState();
1940
+ const store = getSaltfishStore();
1933
1941
  store.initialize(updatedConfig);
1934
1942
  this.managers.analyticsManager.initialize(config, this.managers.sessionManager.getSessionId());
1935
1943
  if (data.isAdmin && store.setIsAdmin) {
@@ -1979,7 +1987,7 @@ class PlayerInitializationService {
1979
1987
  async fetchUserData(userId, userData) {
1980
1988
  var _a;
1981
1989
  try {
1982
- const store = useSaltfishStore.getState();
1990
+ const store = getSaltfishStore();
1983
1991
  if (!((_a = store.config) == null ? void 0 : _a.token)) {
1984
1992
  ErrorHandler.handleWarning(
1985
1993
  "Cannot fetch user data: Token not available",
@@ -2103,7 +2111,7 @@ class PlayerInitializationService {
2103
2111
  log("[PlayerInitializationService.loadAnonymousUserData] Loaded existing anonymous user data:", anonymousUserData);
2104
2112
  }
2105
2113
  this.managers.storageManager.setAnonymousUserData(anonymousUserData);
2106
- const store = useSaltfishStore.getState();
2114
+ const store = getSaltfishStore();
2107
2115
  store.setUserData({
2108
2116
  watchedPlaylists: anonymousUserData.watchedPlaylists || {},
2109
2117
  language: userData == null ? void 0 : userData.language
@@ -2158,7 +2166,7 @@ class PlayerInitializationService {
2158
2166
  if (!watchedPlaylists) {
2159
2167
  return false;
2160
2168
  }
2161
- const store = useSaltfishStore.getState();
2169
+ const store = getSaltfishStore();
2162
2170
  const currentManifestId = (_a = store.manifest) == null ? void 0 : _a.id;
2163
2171
  const currentState = store.currentState;
2164
2172
  if (currentManifestId && currentState !== "idle" && currentState !== "error") {
@@ -2284,7 +2292,7 @@ class UserManagementService {
2284
2292
  log(`UserManagementService: Processed language from userData: ${userData.language} -> ${processedLanguage}`);
2285
2293
  }
2286
2294
  this.lastUserIdentification = { userId, userData: processedUserData };
2287
- const store = useSaltfishStore.getState();
2295
+ const store = getSaltfishStore();
2288
2296
  store.identifyUser(userId, processedUserData);
2289
2297
  this.managers.analyticsManager.setUser({
2290
2298
  id: userId,
@@ -2319,7 +2327,7 @@ class UserManagementService {
2319
2327
  }
2320
2328
  const userId = this.playerInitializationService.getOrCreateAnonymousUserId();
2321
2329
  this.lastUserIdentification = { userId, userData: processedUserData };
2322
- const store = useSaltfishStore.getState();
2330
+ const store = getSaltfishStore();
2323
2331
  store.identifyUser(userId, { ...processedUserData, __isAnonymous: true });
2324
2332
  this.managers.analyticsManager.setUser({
2325
2333
  id: userId,
@@ -2333,7 +2341,7 @@ class UserManagementService {
2333
2341
  async recordABTestAttempt(playlistId) {
2334
2342
  var _a;
2335
2343
  try {
2336
- const store = useSaltfishStore.getState();
2344
+ const store = getSaltfishStore();
2337
2345
  const user = store.user;
2338
2346
  if (!user || !((_a = store.config) == null ? void 0 : _a.token)) {
2339
2347
  return;
@@ -2395,7 +2403,7 @@ class PlaylistValidator {
2395
2403
  async validatePlaylistStart(context) {
2396
2404
  const { playlistId, options, eventManager } = context;
2397
2405
  try {
2398
- const store = useSaltfishStore.getState();
2406
+ const store = getSaltfishStore();
2399
2407
  if (!store.config) {
2400
2408
  return {
2401
2409
  isValid: false,
@@ -2506,7 +2514,7 @@ class PlaylistValidator {
2506
2514
  */
2507
2515
  async validateTriggerConditions(playlistId, foundPlaylist, eventManager) {
2508
2516
  var _a, _b;
2509
- const store = useSaltfishStore.getState();
2517
+ const store = getSaltfishStore();
2510
2518
  if (!store.user) {
2511
2519
  ErrorHandler.handlePlaylistError(
2512
2520
  "User must be identified before starting auto-start playlist",
@@ -2522,7 +2530,7 @@ class PlaylistValidator {
2522
2530
  if (!store.userData) {
2523
2531
  await this.waitForUserData(eventManager);
2524
2532
  }
2525
- const currentStore = useSaltfishStore.getState();
2533
+ const currentStore = getSaltfishStore();
2526
2534
  const watchedPlaylists = ((_a = currentStore.userData) == null ? void 0 : _a.watchedPlaylists) || {};
2527
2535
  const hasTriggers = foundPlaylist.hasTriggers ?? foundPlaylist.autoStart ?? false;
2528
2536
  const playlistData = watchedPlaylists[playlistId];
@@ -2540,7 +2548,7 @@ class PlaylistValidator {
2540
2548
  */
2541
2549
  async validateOnceOptionConditions(playlistId, options, eventManager) {
2542
2550
  var _a;
2543
- const store = useSaltfishStore.getState();
2551
+ const store = getSaltfishStore();
2544
2552
  if (!store.user) {
2545
2553
  ErrorHandler.handlePlaylistError(
2546
2554
  "User must be identified before starting playlist with once option",
@@ -2556,7 +2564,7 @@ class PlaylistValidator {
2556
2564
  if (!store.userData) {
2557
2565
  await this.waitForUserData(eventManager);
2558
2566
  }
2559
- const currentStore = useSaltfishStore.getState();
2567
+ const currentStore = getSaltfishStore();
2560
2568
  const watchedPlaylists = ((_a = currentStore.userData) == null ? void 0 : _a.watchedPlaylists) || {};
2561
2569
  const playlistData = watchedPlaylists[playlistId];
2562
2570
  if (playlistData && (playlistData.status === "completed" || playlistData.status === "dismissed")) {
@@ -2627,7 +2635,7 @@ class PlaylistValidator {
2627
2635
  }, 5e3);
2628
2636
  const handler = () => {
2629
2637
  clearTimeout(timeout);
2630
- useSaltfishStore.getState();
2638
+ getSaltfishStore();
2631
2639
  resolve();
2632
2640
  };
2633
2641
  eventManager.on("userDataLoaded", handler);
@@ -2710,7 +2718,7 @@ class PlaylistOrchestrator {
2710
2718
  this.stateMachineActionHandler.registerStateMachineActions();
2711
2719
  }
2712
2720
  }
2713
- const store = useSaltfishStore.getState();
2721
+ const store = getSaltfishStore();
2714
2722
  if (!store.config) {
2715
2723
  const lastConfig = (_b = this.playerInitializationService) == null ? void 0 : _b.getLastConfig();
2716
2724
  if (!lastConfig) {
@@ -2812,7 +2820,7 @@ class PlaylistOrchestrator {
2812
2820
  this.managers.cursorManager.resetFirstAnimation();
2813
2821
  log(`[PlaylistOrchestrator.startPlaylist] Using validated manifest path: ${manifestPathToLoad}`);
2814
2822
  await this.managers.playlistManager.load(manifestPathToLoad, { ...finalOptions, persistence: playlistPersistence });
2815
- const updatedStore = useSaltfishStore.getState();
2823
+ const updatedStore = getSaltfishStore();
2816
2824
  if (updatedStore.manifest) {
2817
2825
  const manifestPersistence = finalOptions.persistence ?? updatedStore.manifest.isPersistent ?? true;
2818
2826
  const currentOptions = updatedStore.playlistOptions || {};
@@ -2854,7 +2862,7 @@ class PlaylistOrchestrator {
2854
2862
  info(`Playlist started: ${playlistId}${updatedStore.manifest ? ` (${updatedStore.manifest.name})` : ""}`);
2855
2863
  } catch (error2) {
2856
2864
  this.managers.uiManager.hideLoading();
2857
- const errorStore = useSaltfishStore.getState();
2865
+ const errorStore = getSaltfishStore();
2858
2866
  errorStore.sendStateMachineEvent({
2859
2867
  type: "ERROR",
2860
2868
  error: error2 instanceof Error ? error2 : new Error(String(error2))
@@ -2874,7 +2882,7 @@ class PlaylistOrchestrator {
2874
2882
  * Reset current playlist to initial state
2875
2883
  */
2876
2884
  resetPlaylist() {
2877
- const store = useSaltfishStore.getState();
2885
+ const store = getSaltfishStore();
2878
2886
  if (store.manifest) {
2879
2887
  store.goToStep(store.manifest.startStep);
2880
2888
  }
@@ -2883,7 +2891,7 @@ class PlaylistOrchestrator {
2883
2891
  * Check if the player is initialized
2884
2892
  */
2885
2893
  isInitialized() {
2886
- const store = useSaltfishStore.getState();
2894
+ const store = getSaltfishStore();
2887
2895
  return !!store.config;
2888
2896
  }
2889
2897
  /**
@@ -2916,7 +2924,7 @@ class StateMachineActionHandler {
2916
2924
  * Register all state machine actions with the store
2917
2925
  */
2918
2926
  registerStateMachineActions() {
2919
- const store = useSaltfishStore.getState();
2927
+ const store = getSaltfishStore();
2920
2928
  store.registerStateMachineActions({
2921
2929
  startVideoPlayback: (context) => {
2922
2930
  this.handleStartVideoPlayback(context);
@@ -2978,7 +2986,7 @@ class StateMachineActionHandler {
2978
2986
  */
2979
2987
  getVideoUrl(step) {
2980
2988
  var _a;
2981
- const store = useSaltfishStore.getState();
2989
+ const store = getSaltfishStore();
2982
2990
  const language = (_a = store.userData) == null ? void 0 : _a.language;
2983
2991
  let videoUrl;
2984
2992
  if (language && step.translations && step.translations[language]) {
@@ -3000,7 +3008,7 @@ class StateMachineActionHandler {
3000
3008
  */
3001
3009
  isUsingAudioFallback(step) {
3002
3010
  var _a;
3003
- const store = useSaltfishStore.getState();
3011
+ const store = getSaltfishStore();
3004
3012
  const language = (_a = store.userData) == null ? void 0 : _a.language;
3005
3013
  let videoUrl;
3006
3014
  if (language && step.translations && step.translations[language]) {
@@ -3014,7 +3022,7 @@ class StateMachineActionHandler {
3014
3022
  * Finds the URL of the next video in the playlist for preloading
3015
3023
  */
3016
3024
  findNextVideoUrl(currentStep) {
3017
- const store = useSaltfishStore.getState();
3025
+ const store = getSaltfishStore();
3018
3026
  if (!store.manifest || !currentStep) {
3019
3027
  return null;
3020
3028
  }
@@ -3109,7 +3117,7 @@ class StateMachineActionHandler {
3109
3117
  const videoUrl = this.getVideoUrl(currentStep);
3110
3118
  const isAudioFallback = this.isUsingAudioFallback(currentStep);
3111
3119
  if (isAudioFallback) {
3112
- const store = useSaltfishStore.getState();
3120
+ const store = getSaltfishStore();
3113
3121
  const manifest = store.manifest;
3114
3122
  const posterUrl = currentStep.gifUrl;
3115
3123
  const avatarThumbnailUrl = manifest == null ? void 0 : manifest.avatarThumbnailUrl;
@@ -3147,7 +3155,7 @@ class StateMachineActionHandler {
3147
3155
  }
3148
3156
  this.managers.videoManager.setCompletionPolicy(completionPolicy, () => {
3149
3157
  var _a;
3150
- const store = useSaltfishStore.getState();
3158
+ const store = getSaltfishStore();
3151
3159
  if (!hasSpecialTransitions) {
3152
3160
  log("StateMachineActionHandler: Setting up transitions after video ended");
3153
3161
  this.managers.transitionManager.setupTransitions(currentStep, true);
@@ -3170,7 +3178,7 @@ class StateMachineActionHandler {
3170
3178
  log(`StateMachineActionHandler: Video ended, setting up timeout transition to ${timeoutTransition.nextStep} with ${timeout}ms delay`);
3171
3179
  setTimeout(() => {
3172
3180
  var _a2;
3173
- const currentStore = useSaltfishStore.getState();
3181
+ const currentStore = getSaltfishStore();
3174
3182
  if (currentStore.currentStepId === currentStep.id && (currentStore.currentState === "waitingForInteraction" || currentStore.currentState === "playing")) {
3175
3183
  log(`StateMachineActionHandler: Timeout expired (${timeout}ms), transitioning to ${timeoutTransition.nextStep}`);
3176
3184
  (_a2 = currentStore.goToStep) == null ? void 0 : _a2.call(currentStore, timeoutTransition.nextStep);
@@ -3198,7 +3206,7 @@ class StateMachineActionHandler {
3198
3206
  log("StateMachineActionHandler: Starting async video load");
3199
3207
  const loadTranscriptForStep = () => {
3200
3208
  var _a, _b;
3201
- const store = useSaltfishStore.getState();
3209
+ const store = getSaltfishStore();
3202
3210
  const captionsEnabled = ((_a = store.manifest) == null ? void 0 : _a.captions) ?? true;
3203
3211
  const language = (_b = store.userData) == null ? void 0 : _b.language;
3204
3212
  let transcript = currentStep.transcript;
@@ -3243,7 +3251,7 @@ class StateMachineActionHandler {
3243
3251
  error2 instanceof Error ? error2 : new Error(`Failed to load video: ${error2}`),
3244
3252
  "video"
3245
3253
  );
3246
- const store = useSaltfishStore.getState();
3254
+ const store = getSaltfishStore();
3247
3255
  const errorObj = error2 instanceof Error ? error2 : new Error(`Failed to load video: ${error2}`);
3248
3256
  const enrichedError = error2;
3249
3257
  this.managers.eventManager.trigger("error", {
@@ -3282,7 +3290,7 @@ class StateMachineActionHandler {
3282
3290
  const isAudioFallback = this.isUsingAudioFallback(currentStep);
3283
3291
  this.managers.uiManager.showPlayer();
3284
3292
  if (isAudioFallback) {
3285
- const store = useSaltfishStore.getState();
3293
+ const store = getSaltfishStore();
3286
3294
  const manifest = store.manifest;
3287
3295
  const posterUrl = currentStep.gifUrl;
3288
3296
  const avatarThumbnailUrl = manifest == null ? void 0 : manifest.avatarThumbnailUrl;
@@ -3307,7 +3315,7 @@ class StateMachineActionHandler {
3307
3315
  }
3308
3316
  handleTrackPlaylistComplete() {
3309
3317
  var _a, _b;
3310
- const store = useSaltfishStore.getState();
3318
+ const store = getSaltfishStore();
3311
3319
  if (store.manifest && this.managers.eventManager) {
3312
3320
  const playlistId = store.manifest.id;
3313
3321
  this.managers.eventManager.trigger("playlistEnded", {
@@ -3331,7 +3339,7 @@ class StateMachineActionHandler {
3331
3339
  log(`StateMachineActionHandler: Handling error: ${(_a = context.error) == null ? void 0 : _a.message}`);
3332
3340
  if (context.error && this.managers.uiManager.getPlayerElement()) {
3333
3341
  this.managers.uiManager.showError(context.error, "player");
3334
- const store = useSaltfishStore.getState();
3342
+ const store = getSaltfishStore();
3335
3343
  this.managers.eventManager.trigger("error", {
3336
3344
  timestamp: Date.now(),
3337
3345
  playlistId: ((_b = store.manifest) == null ? void 0 : _b.id) || void 0,
@@ -3371,7 +3379,7 @@ class StateMachineActionHandler {
3371
3379
  this.managers.uiManager.disablePlayButtonProminent();
3372
3380
  }
3373
3381
  handleTriggerPlaylistDismissed() {
3374
- const store = useSaltfishStore.getState();
3382
+ const store = getSaltfishStore();
3375
3383
  if (store.manifest && this.managers.eventManager) {
3376
3384
  this.managers.eventManager.trigger("playlistDismissed", {
3377
3385
  timestamp: Date.now(),
@@ -3698,7 +3706,7 @@ const _ManagerOrchestrator = class _ManagerOrchestrator {
3698
3706
  if (!this.isInitialized) {
3699
3707
  return;
3700
3708
  }
3701
- const store = useSaltfishStore.getState();
3709
+ const store = getSaltfishStore();
3702
3710
  if (store.currentState === _ManagerOrchestrator.prevState.currentState && store.currentStepId === _ManagerOrchestrator.prevState.currentStepId && store.isMinimized === _ManagerOrchestrator.prevState.isMinimized) {
3703
3711
  return;
3704
3712
  }
@@ -3786,7 +3794,7 @@ const _ManagerOrchestrator = class _ManagerOrchestrator {
3786
3794
  return;
3787
3795
  }
3788
3796
  try {
3789
- const store = useSaltfishStore.getState();
3797
+ const store = getSaltfishStore();
3790
3798
  log("ManagerOrchestrator: Current state before playlist cleanup:", {
3791
3799
  currentState: store.currentState,
3792
3800
  currentStepId: store.currentStepId,
@@ -3825,7 +3833,7 @@ const _ManagerOrchestrator = class _ManagerOrchestrator {
3825
3833
  return;
3826
3834
  }
3827
3835
  try {
3828
- const store = useSaltfishStore.getState();
3836
+ const store = getSaltfishStore();
3829
3837
  log("ManagerOrchestrator: Current state before destroying:", {
3830
3838
  currentState: store.currentState,
3831
3839
  currentStepId: store.currentStepId,
@@ -3864,7 +3872,7 @@ const _ManagerOrchestrator = class _ManagerOrchestrator {
3864
3872
  try {
3865
3873
  log("ManagerOrchestrator: Attempting emergency cleanup after error");
3866
3874
  this.isInitialized = false;
3867
- const store = useSaltfishStore.getState();
3875
+ const store = getSaltfishStore();
3868
3876
  store.reset();
3869
3877
  log("ManagerOrchestrator: Emergency cleanup completed");
3870
3878
  } catch (cleanupError) {
@@ -4731,7 +4739,7 @@ class MobilePlaybackHandler extends DevicePlaybackHandler {
4731
4739
  element.style.setProperty("min-height", config.buttonMinSize.height);
4732
4740
  }
4733
4741
  async handlePlayAttempt(video, hasUserInteracted) {
4734
- const store = useSaltfishStore.getState();
4742
+ const store = getSaltfishStore();
4735
4743
  const userWantsMuted = store.isMuted;
4736
4744
  video.muted = userWantsMuted;
4737
4745
  video.loop = false;
@@ -4815,7 +4823,7 @@ class DesktopPlaybackHandler extends DevicePlaybackHandler {
4815
4823
  configureControlElement(_element) {
4816
4824
  }
4817
4825
  async handlePlayAttempt(video, _hasUserInteracted) {
4818
- const store = useSaltfishStore.getState();
4826
+ const store = getSaltfishStore();
4819
4827
  const userWantsMuted = store.isMuted;
4820
4828
  video.muted = userWantsMuted;
4821
4829
  video.loop = false;
@@ -5123,7 +5131,7 @@ class VideoControlsUI {
5123
5131
  * Sets the muted state
5124
5132
  */
5125
5133
  setMuted(muted) {
5126
- const store = useSaltfishStore.getState();
5134
+ const store = getSaltfishStore();
5127
5135
  store.setMuted(muted);
5128
5136
  this.updateMuteButtonIcon();
5129
5137
  }
@@ -5131,7 +5139,7 @@ class VideoControlsUI {
5131
5139
  * Toggles the muted state
5132
5140
  */
5133
5141
  toggleMute() {
5134
- const store = useSaltfishStore.getState();
5142
+ const store = getSaltfishStore();
5135
5143
  const newMutedState = !store.isMuted;
5136
5144
  this.setMuted(newMutedState);
5137
5145
  this.callbacks.onMuteToggle();
@@ -5140,7 +5148,7 @@ class VideoControlsUI {
5140
5148
  * Gets the current muted state
5141
5149
  */
5142
5150
  getMuted() {
5143
- const store = useSaltfishStore.getState();
5151
+ const store = getSaltfishStore();
5144
5152
  return store.isMuted;
5145
5153
  }
5146
5154
  /**
@@ -5148,7 +5156,7 @@ class VideoControlsUI {
5148
5156
  */
5149
5157
  updateMuteButtonIcon() {
5150
5158
  if (!this.muteButton) return;
5151
- const store = useSaltfishStore.getState();
5159
+ const store = getSaltfishStore();
5152
5160
  const isMuted = store.isMuted;
5153
5161
  if (isMuted) {
5154
5162
  this.muteButton.innerHTML = `
@@ -5615,7 +5623,7 @@ class VideoManager {
5615
5623
  if (video !== activeVideo) {
5616
5624
  return;
5617
5625
  }
5618
- const store = useSaltfishStore.getState();
5626
+ const store = getSaltfishStore();
5619
5627
  if (store.currentState === "autoplayBlocked" || store.currentState === "idleMode") {
5620
5628
  store.currentState === "autoplayBlocked" ? "autoplay blocked" : "idle";
5621
5629
  return;
@@ -5706,7 +5714,7 @@ class VideoManager {
5706
5714
  this.nextVideo.crossOrigin = "anonymous";
5707
5715
  this.deviceHandler.configureVideoElement(this.nextVideo);
5708
5716
  this.container.appendChild(this.nextVideo);
5709
- const store = useSaltfishStore.getState();
5717
+ const store = getSaltfishStore();
5710
5718
  if (store.isMuted) {
5711
5719
  this.currentVideo.muted = true;
5712
5720
  this.nextVideo.muted = true;
@@ -5764,7 +5772,7 @@ class VideoManager {
5764
5772
  return;
5765
5773
  }
5766
5774
  activeVideo.pause();
5767
- const store = useSaltfishStore.getState();
5775
+ const store = getSaltfishStore();
5768
5776
  inactiveVideo.muted = store.isMuted;
5769
5777
  activeVideo.classList.add("sf-hidden");
5770
5778
  inactiveVideo.classList.remove("sf-hidden");
@@ -5788,13 +5796,13 @@ class VideoManager {
5788
5796
  if (this.controls) {
5789
5797
  this.controls.reset90PercentTrigger();
5790
5798
  }
5791
- const store = useSaltfishStore.getState();
5799
+ const store = getSaltfishStore();
5792
5800
  activeVideo.muted = store.isMuted;
5793
5801
  try {
5794
5802
  if (this.controls) {
5795
5803
  this.controls.reset();
5796
5804
  }
5797
- const store2 = useSaltfishStore.getState();
5805
+ const store2 = getSaltfishStore();
5798
5806
  const isPersistenceEnabled = ((_a = store2.playlistOptions) == null ? void 0 : _a.persistence) ?? true;
5799
5807
  if (this.currentVideoUrl === url && activeVideo.src && (activeVideo.src === url || activeVideo.src.endsWith(url))) {
5800
5808
  if (isPersistenceEnabled) {
@@ -5933,7 +5941,7 @@ class VideoManager {
5933
5941
  inactiveVideo.src = url;
5934
5942
  inactiveVideo.load();
5935
5943
  inactiveVideo.preload = "auto";
5936
- const store = useSaltfishStore.getState();
5944
+ const store = getSaltfishStore();
5937
5945
  inactiveVideo.muted = store.isMuted;
5938
5946
  } else {
5939
5947
  fetch(url).then((response) => {
@@ -5962,7 +5970,7 @@ class VideoManager {
5962
5970
  if (activeVideo.ended) {
5963
5971
  activeVideo.currentTime = 0;
5964
5972
  }
5965
- const store = useSaltfishStore.getState();
5973
+ const store = getSaltfishStore();
5966
5974
  const isPersistenceEnabled = ((_a = store.playlistOptions) == null ? void 0 : _a.persistence) ?? true;
5967
5975
  if (isPersistenceEnabled && this.currentVideoUrl) {
5968
5976
  const savedPosition = this.playbackPositions.get(this.currentVideoUrl);
@@ -6010,7 +6018,7 @@ class VideoManager {
6010
6018
  }
6011
6019
  }).catch(() => {
6012
6020
  console.warn("VideoManager: Autoplay handler threw error - browser has strict autoplay policy");
6013
- const store2 = useSaltfishStore.getState();
6021
+ const store2 = getSaltfishStore();
6014
6022
  store2.setAutoplayFallback();
6015
6023
  });
6016
6024
  }
@@ -7830,7 +7838,7 @@ class InteractionManager {
7830
7838
  if (needsScrolling && this.buttonContainer) {
7831
7839
  this.setupScrollIndicator(this.buttonContainer);
7832
7840
  }
7833
- const store = useSaltfishStore.getState();
7841
+ const store = getSaltfishStore();
7834
7842
  if (store.isMinimized) {
7835
7843
  this.buttonContainer.classList.add("sf-hidden");
7836
7844
  }
@@ -7909,7 +7917,7 @@ class InteractionManager {
7909
7917
  if (!this.buttonContainer || this.buttons.length === 0) {
7910
7918
  return;
7911
7919
  }
7912
- const store = useSaltfishStore.getState();
7920
+ const store = getSaltfishStore();
7913
7921
  if (store.isMinimized) {
7914
7922
  this.buttonContainer.classList.add("sf-hidden");
7915
7923
  if (this.scrollIndicator) {
@@ -7980,7 +7988,7 @@ class InteractionManager {
7980
7988
  log(`InteractionManager: Button click detected on button "${buttonConfig.id}"`);
7981
7989
  event.preventDefault();
7982
7990
  event.stopPropagation();
7983
- const store = useSaltfishStore.getState();
7991
+ const store = getSaltfishStore();
7984
7992
  switch (buttonConfig.action.type) {
7985
7993
  case "next":
7986
7994
  store.play();
@@ -7989,7 +7997,7 @@ class InteractionManager {
7989
7997
  if (buttonConfig.action.url) {
7990
7998
  log(`InteractionManager: Goto button with URL redirect - updating to step "${buttonConfig.action.target}" then redirecting to "${buttonConfig.action.url}"`);
7991
7999
  await this.flushAnalytics();
7992
- const currentStore = useSaltfishStore.getState();
8000
+ const currentStore = getSaltfishStore();
7993
8001
  if (currentStore.manifest) {
7994
8002
  useSaltfishStore.setState((state) => {
7995
8003
  state.currentStepId = buttonConfig.action.target;
@@ -8032,7 +8040,7 @@ class InteractionManager {
8032
8040
  const playlistPersistence = ((_d = currentStore.playlistOptions) == null ? void 0 : _d.persistence) ?? true;
8033
8041
  if (playlistPersistence) {
8034
8042
  const userId = (_e = currentStore.user) == null ? void 0 : _e.id;
8035
- const updatedStore = useSaltfishStore.getState();
8043
+ const updatedStore = getSaltfishStore();
8036
8044
  this.storageManager.setProgress(updatedStore.progress, userId);
8037
8045
  log(`InteractionManager: Saved progress for step ${buttonConfig.action.target} before URL redirect`);
8038
8046
  if ((_f = currentStore.user) == null ? void 0 : _f.__isAnonymous) {
@@ -8129,7 +8137,7 @@ class InteractionManager {
8129
8137
  log(`InteractionManager: Set input value to "${interaction.value}"`);
8130
8138
  }
8131
8139
  }
8132
- const store = useSaltfishStore.getState();
8140
+ const store = getSaltfishStore();
8133
8141
  if (store.manifest) {
8134
8142
  const analyticsData = {
8135
8143
  selector: interaction.selector,
@@ -8198,13 +8206,6 @@ class InteractionManager {
8198
8206
  this.container = null;
8199
8207
  }
8200
8208
  }
8201
- function getSaltfishStore() {
8202
- try {
8203
- return useSaltfishStore.getState();
8204
- } catch (error2) {
8205
- return null;
8206
- }
8207
- }
8208
8209
  class AnalyticsManager {
8209
8210
  // Default to enabled
8210
8211
  /**
@@ -8908,7 +8909,7 @@ class TransitionManager {
8908
8909
  return;
8909
8910
  }
8910
8911
  retries++;
8911
- const currentStore = useSaltfishStore.getState();
8912
+ const currentStore = getSaltfishStore();
8912
8913
  if (currentStore.currentState === "waitingForInteraction" || currentStore.currentState === "playing") {
8913
8914
  log(`TransitionManager: State now compatible (${currentStore.currentState}), triggering transition to '${nextStepId}'`);
8914
8915
  this.triggerTransition(nextStepId);
@@ -9005,7 +9006,7 @@ class TransitionManager {
9005
9006
  * @returns true if validation passes or no requirement exists, false if validation fails
9006
9007
  */
9007
9008
  validateCurrentStepUrl() {
9008
- const store = useSaltfishStore.getState();
9009
+ const store = getSaltfishStore();
9009
9010
  const manifest = store.manifest;
9010
9011
  const currentStepId = store.currentStepId;
9011
9012
  if (!manifest || !currentStepId) {
@@ -9027,7 +9028,7 @@ class TransitionManager {
9027
9028
  */
9028
9029
  triggerTransition(nextStepId) {
9029
9030
  var _a;
9030
- const store = useSaltfishStore.getState();
9031
+ const store = getSaltfishStore();
9031
9032
  const currentState = store.currentState;
9032
9033
  store.currentStepId;
9033
9034
  const isMinimized = store.isMinimized;
@@ -9050,7 +9051,7 @@ class TransitionManager {
9050
9051
  * @returns Promise<boolean> - True if transition was successful, false otherwise
9051
9052
  */
9052
9053
  async triggerTransitionWithProgress(nextStepId) {
9053
- const store = useSaltfishStore.getState();
9054
+ const store = getSaltfishStore();
9054
9055
  const currentState = store.currentState;
9055
9056
  store.currentStepId;
9056
9057
  const isMinimized = store.isMinimized;
@@ -9379,7 +9380,7 @@ class TriggerManager {
9379
9380
  if (this.triggeredPlaylistsSet.has(playlistId)) {
9380
9381
  return;
9381
9382
  }
9382
- const store = useSaltfishStore.getState();
9383
+ const store = getSaltfishStore();
9383
9384
  if (!store.user) {
9384
9385
  return;
9385
9386
  }
@@ -9826,7 +9827,7 @@ class ABTestManager {
9826
9827
  * @param abTests - A/B test configurations from validate-token response
9827
9828
  */
9828
9829
  initializeTests(abTests) {
9829
- const store = useSaltfishStore.getState();
9830
+ const store = getSaltfishStore();
9830
9831
  store.setABTests(abTests);
9831
9832
  }
9832
9833
  /**
@@ -9838,7 +9839,7 @@ class ABTestManager {
9838
9839
  */
9839
9840
  assignUserToTests(userId, existingAssignments, userListAssignments) {
9840
9841
  var _a, _b;
9841
- const store = useSaltfishStore.getState();
9842
+ const store = getSaltfishStore();
9842
9843
  const abTests = store.abTests || [];
9843
9844
  const assignments = { ...existingAssignments };
9844
9845
  for (const test of abTests) {
@@ -9889,7 +9890,7 @@ class ABTestManager {
9889
9890
  * @returns Filtered playlists based on A/B test assignments
9890
9891
  */
9891
9892
  getFilteredPlaylists(allPlaylists) {
9892
- const store = useSaltfishStore.getState();
9893
+ const store = getSaltfishStore();
9893
9894
  const abTests = store.abTests || [];
9894
9895
  const assignments = store.abTestAssignments || {};
9895
9896
  if (abTests.length === 0) {
@@ -9915,7 +9916,7 @@ class ABTestManager {
9915
9916
  */
9916
9917
  trackTestParticipation(playlistId) {
9917
9918
  var _a;
9918
- const store = useSaltfishStore.getState();
9919
+ const store = getSaltfishStore();
9919
9920
  const abTests = store.abTests || [];
9920
9921
  const assignments = store.abTestAssignments || {};
9921
9922
  const test = abTests.find((t) => t.playlistId === playlistId);
@@ -9944,7 +9945,7 @@ class ABTestManager {
9944
9945
  * @returns A/B test assignments that should be stored in backend
9945
9946
  */
9946
9947
  getAssignmentsForBackend() {
9947
- const store = useSaltfishStore.getState();
9948
+ const store = getSaltfishStore();
9948
9949
  return store.abTestAssignments || {};
9949
9950
  }
9950
9951
  /**
@@ -9953,7 +9954,7 @@ class ABTestManager {
9953
9954
  * @returns true if playlist is available based on A/B test assignments
9954
9955
  */
9955
9956
  isPlaylistAvailable(playlistId) {
9956
- const store = useSaltfishStore.getState();
9957
+ const store = getSaltfishStore();
9957
9958
  const abTests = store.abTests || [];
9958
9959
  const assignments = store.abTestAssignments || {};
9959
9960
  const test = abTests.find((t) => t.playlistId === playlistId);
@@ -9968,7 +9969,7 @@ class ABTestManager {
9968
9969
  * @returns Array of active test information
9969
9970
  */
9970
9971
  getActiveTestInfo() {
9971
- const store = useSaltfishStore.getState();
9972
+ const store = getSaltfishStore();
9972
9973
  const abTests = store.abTests || [];
9973
9974
  const assignments = store.abTestAssignments || {};
9974
9975
  return abTests.map((test) => {
@@ -10253,9 +10254,6 @@ class PlaylistManager {
10253
10254
  this.isUpdatingWatchedPlaylists = true;
10254
10255
  try {
10255
10256
  const store = getSaltfishStore();
10256
- if (!store) {
10257
- return;
10258
- }
10259
10257
  const currentUserData = store.userData || {};
10260
10258
  const currentWatchedPlaylists = currentUserData.watchedPlaylists || {};
10261
10259
  const updatedPlaylistData = {
@@ -10395,10 +10393,10 @@ class MinimizeButton {
10395
10393
  `;
10396
10394
  this.button.addEventListener("click", this.handleClick.bind(this));
10397
10395
  this.playerElement.appendChild(this.button);
10398
- this.updateVisibility(useSaltfishStore.getState().isMinimized);
10396
+ this.updateVisibility(getSaltfishStore().isMinimized);
10399
10397
  }
10400
10398
  handleClick() {
10401
- const store = useSaltfishStore.getState();
10399
+ const store = getSaltfishStore();
10402
10400
  const isMinimized = !store.isMinimized;
10403
10401
  if (isMinimized) {
10404
10402
  store.minimize();
@@ -10461,7 +10459,7 @@ class PlayPauseButton {
10461
10459
  if (event) {
10462
10460
  event.stopPropagation();
10463
10461
  }
10464
- const store = useSaltfishStore.getState();
10462
+ const store = getSaltfishStore();
10465
10463
  if (store.currentState === "autoplayBlocked") {
10466
10464
  if (this.videoManager) {
10467
10465
  this.videoManager.markUserInteraction();
@@ -10512,11 +10510,11 @@ class ExitButton {
10512
10510
  `;
10513
10511
  this.button.addEventListener("click", this.handleClick.bind(this));
10514
10512
  this.playerElement.appendChild(this.button);
10515
- this.updateVisibility(useSaltfishStore.getState().isMinimized);
10513
+ this.updateVisibility(getSaltfishStore().isMinimized);
10516
10514
  }
10517
10515
  handleClick(e) {
10518
10516
  e.stopPropagation();
10519
- const store = useSaltfishStore.getState();
10517
+ const store = getSaltfishStore();
10520
10518
  store.sendStateMachineEvent({ type: "EXIT" });
10521
10519
  }
10522
10520
  updateVisibility(isMinimized) {
@@ -10760,7 +10758,7 @@ class UIManager {
10760
10758
  cursorManager.create();
10761
10759
  interactionManager.create(this.playerElement);
10762
10760
  this.initializeButtonManagement();
10763
- const store = useSaltfishStore.getState();
10761
+ const store = getSaltfishStore();
10764
10762
  this.handleMinimizeStateChange(store.isMinimized);
10765
10763
  }
10766
10764
  /**
@@ -10771,7 +10769,7 @@ class UIManager {
10771
10769
  const videoContainer = (_a = this.playerElement) == null ? void 0 : _a.querySelector(".sf-video-container");
10772
10770
  if (videoContainer) {
10773
10771
  videoContainer.addEventListener("click", (event) => {
10774
- const store = useSaltfishStore.getState();
10772
+ const store = getSaltfishStore();
10775
10773
  if (store.isMinimized) {
10776
10774
  event.stopPropagation();
10777
10775
  this.handleMinimizeClick();
@@ -10800,7 +10798,7 @@ class UIManager {
10800
10798
  });
10801
10799
  return;
10802
10800
  }
10803
- const store = useSaltfishStore.getState();
10801
+ const store = getSaltfishStore();
10804
10802
  let positionToUse = ((_a = store.playlistOptions) == null ? void 0 : _a.position) || "bottom-right";
10805
10803
  if (store.currentStepId && store.manifest) {
10806
10804
  const currentStep = store.manifest.steps.find((step) => step.id === store.currentStepId);
@@ -10831,7 +10829,7 @@ class UIManager {
10831
10829
  if (!this.playerElement) {
10832
10830
  return;
10833
10831
  }
10834
- const store = useSaltfishStore.getState();
10832
+ const store = getSaltfishStore();
10835
10833
  const isMinimized = !store.isMinimized;
10836
10834
  if (isMinimized) {
10837
10835
  store.minimize();
@@ -10973,7 +10971,7 @@ class UIManager {
10973
10971
  */
10974
10972
  createSaltfishLogo(parentElement) {
10975
10973
  var _a;
10976
- const store = useSaltfishStore.getState();
10974
+ const store = getSaltfishStore();
10977
10975
  if (((_a = store.config) == null ? void 0 : _a.showLogo) === false) {
10978
10976
  return;
10979
10977
  }
@@ -10990,7 +10988,7 @@ class UIManager {
10990
10988
  logoContainer.addEventListener("click", (event) => {
10991
10989
  var _a2;
10992
10990
  event.stopPropagation();
10993
- const currentStore = useSaltfishStore.getState();
10991
+ const currentStore = getSaltfishStore();
10994
10992
  if (currentStore.currentState === "playing") {
10995
10993
  currentStore.pause();
10996
10994
  }
@@ -11064,6 +11062,37 @@ class UIManager {
11064
11062
  }
11065
11063
  }
11066
11064
  }
11065
+ /**
11066
+ * Handles autoplay fallback and idle mode interaction by unmuting and resetting video
11067
+ * @param source - The UI element that triggered the interaction (for logging)
11068
+ */
11069
+ handleAutoplayFallbackInteraction(source) {
11070
+ var _a;
11071
+ const store = getSaltfishStore();
11072
+ if (store.currentState !== "autoplayBlocked" && store.currentState !== "idleMode") {
11073
+ if (this.videoManager) {
11074
+ this.videoManager.markUserInteraction();
11075
+ }
11076
+ return;
11077
+ }
11078
+ store.currentState === "autoplayBlocked" ? "autoplay fallback" : "idle";
11079
+ if (this.videoManager) {
11080
+ this.videoManager.markUserInteraction();
11081
+ this.videoManager.setMuted(false);
11082
+ const videoElement = this.videoManager.getVideoElement();
11083
+ if (videoElement) {
11084
+ videoElement.loop = false;
11085
+ videoElement.currentTime = 0;
11086
+ }
11087
+ } else {
11088
+ const videoElement = (_a = this.playerElement) == null ? void 0 : _a.querySelector(".sf-video-container__video");
11089
+ if (videoElement) {
11090
+ videoElement.muted = false;
11091
+ videoElement.loop = false;
11092
+ videoElement.currentTime = 0;
11093
+ }
11094
+ }
11095
+ }
11067
11096
  /**
11068
11097
  * Creates the center play button with proper click handler
11069
11098
  */
@@ -11086,33 +11115,10 @@ class UIManager {
11086
11115
  `;
11087
11116
  this.playerElement.appendChild(this.centerPlayButton);
11088
11117
  this.centerPlayButton.addEventListener("click", (e) => {
11089
- var _a;
11090
11118
  e.stopPropagation();
11091
11119
  e.preventDefault();
11092
- const store = useSaltfishStore.getState();
11093
- if (store.currentState === "autoplayBlocked" || store.currentState === "idleMode") {
11094
- store.currentState === "autoplayBlocked" ? "autoplay fallback" : "idle";
11095
- if (this.videoManager) {
11096
- this.videoManager.markUserInteraction();
11097
- this.videoManager.setMuted(false);
11098
- const videoElement = this.videoManager.getVideoElement();
11099
- if (videoElement) {
11100
- videoElement.loop = false;
11101
- videoElement.currentTime = 0;
11102
- }
11103
- } else {
11104
- const videoElement = (_a = this.playerElement) == null ? void 0 : _a.querySelector(".sf-video-container__video");
11105
- if (videoElement) {
11106
- videoElement.muted = false;
11107
- videoElement.loop = false;
11108
- videoElement.currentTime = 0;
11109
- }
11110
- }
11111
- } else {
11112
- if (this.videoManager) {
11113
- this.videoManager.markUserInteraction();
11114
- }
11115
- }
11120
+ const store = getSaltfishStore();
11121
+ this.handleAutoplayFallbackInteraction("center play button");
11116
11122
  if (store.currentState === "paused" || store.currentState === "waitingForInteraction" || store.currentState === "completedWaitingForInteraction" || store.currentState === "autoplayBlocked" || store.currentState === "idleMode" || store.currentState === "error") {
11117
11123
  store.play();
11118
11124
  } else if (store.currentState === "playing") {
@@ -11129,7 +11135,7 @@ class UIManager {
11129
11135
  return;
11130
11136
  }
11131
11137
  this.hideCompactLabel();
11132
- const store = useSaltfishStore.getState();
11138
+ const store = getSaltfishStore();
11133
11139
  let positionToUse = ((_a = store.playlistOptions) == null ? void 0 : _a.position) || "bottom-right";
11134
11140
  if (store.currentStepId && store.manifest) {
11135
11141
  const currentStep = store.manifest.steps.find((step) => step.id === store.currentStepId);
@@ -11145,33 +11151,10 @@ class UIManager {
11145
11151
  this.compactLabel.style.cursor = "pointer";
11146
11152
  this.compactLabel.style.pointerEvents = "auto";
11147
11153
  this.compactLabel.addEventListener("click", (e) => {
11148
- var _a2;
11149
11154
  e.stopPropagation();
11150
11155
  e.preventDefault();
11151
- const currentStore = useSaltfishStore.getState();
11152
- if (currentStore.currentState === "autoplayBlocked" || currentStore.currentState === "idleMode") {
11153
- currentStore.currentState === "autoplayBlocked" ? "autoplay fallback" : "idle";
11154
- if (this.videoManager) {
11155
- this.videoManager.markUserInteraction();
11156
- this.videoManager.setMuted(false);
11157
- const videoElement = this.videoManager.getVideoElement();
11158
- if (videoElement) {
11159
- videoElement.loop = false;
11160
- videoElement.currentTime = 0;
11161
- }
11162
- } else {
11163
- const videoElement = (_a2 = this.playerElement) == null ? void 0 : _a2.querySelector(".sf-video-container__video");
11164
- if (videoElement) {
11165
- videoElement.muted = false;
11166
- videoElement.loop = false;
11167
- videoElement.currentTime = 0;
11168
- }
11169
- }
11170
- } else {
11171
- if (this.videoManager) {
11172
- this.videoManager.markUserInteraction();
11173
- }
11174
- }
11156
+ const currentStore = getSaltfishStore();
11157
+ this.handleAutoplayFallbackInteraction("compact label");
11175
11158
  if (currentStore.currentState === "paused" || currentStore.currentState === "waitingForInteraction" || currentStore.currentState === "completedWaitingForInteraction" || currentStore.currentState === "autoplayBlocked" || currentStore.currentState === "idleMode" || currentStore.currentState === "error") {
11176
11159
  currentStore.play();
11177
11160
  }
@@ -11614,7 +11597,7 @@ const SaltfishPlayer$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.de
11614
11597
  __proto__: null,
11615
11598
  SaltfishPlayer
11616
11599
  }, Symbol.toStringTag, { value: "Module" }));
11617
- const version = "0.3.28";
11600
+ const version = "0.3.30";
11618
11601
  const packageJson = {
11619
11602
  version
11620
11603
  };