saltfish 0.3.3 → 0.3.4

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.
@@ -956,7 +956,7 @@ const STORAGE_KEYS = {
956
956
  SESSION: "saltfish_session",
957
957
  ANONYMOUS_USER: "saltfish_anonymous_user_data"
958
958
  };
959
- const TIMING = {
959
+ const TIMING$1 = {
960
960
  // 5 seconds
961
961
  STEP_TIMEOUT: 12e4,
962
962
  // Session persistence
@@ -6166,6 +6166,24 @@ class VideoManager {
6166
6166
  this.soundbarElement = null;
6167
6167
  }
6168
6168
  }
6169
+ const ANALYTICS = {
6170
+ /** Interval for flushing analytics events to the backend (30 seconds) */
6171
+ FLUSH_INTERVAL_MS: 3e4
6172
+ };
6173
+ const TIMING = {
6174
+ /** Delay for DOM stabilization before cursor operations (0.5 seconds) */
6175
+ DOM_STABILIZATION_DELAY_MS: 500,
6176
+ /** Delay for state processing operations (100 milliseconds) */
6177
+ STATE_PROCESSING_DELAY_MS: 100,
6178
+ /** Interval for checking URL path changes (5 seconds) */
6179
+ URL_PATH_CHECK_INTERVAL_MS: 5e3,
6180
+ /** Retry delay for failed operations (0.5 seconds) */
6181
+ RETRY_DELAY_MS: 500
6182
+ };
6183
+ const THRESHOLDS = {
6184
+ /** Minimum scroll distance in pixels to trigger scroll events */
6185
+ SCROLL_THRESHOLD_PX: 10
6186
+ };
6169
6187
  class CursorManager {
6170
6188
  constructor() {
6171
6189
  __publicField(this, "cursor", null);
@@ -6818,7 +6836,7 @@ class CursorManager {
6818
6836
  console.warn("CursorManager: No targetSelector provided in animation");
6819
6837
  return;
6820
6838
  }
6821
- await new Promise((resolve) => setTimeout(resolve, 500));
6839
+ await new Promise((resolve) => setTimeout(resolve, TIMING.DOM_STABILIZATION_DELAY_MS));
6822
6840
  if (this.isAutoplayBlocked()) {
6823
6841
  return;
6824
6842
  }
@@ -7547,7 +7565,7 @@ class InteractionManager {
7547
7565
  const scrollHeight = container.scrollHeight;
7548
7566
  const scrollTop = container.scrollTop;
7549
7567
  const clientHeight = container.clientHeight;
7550
- if (scrollHeight - scrollTop - clientHeight < 10) {
7568
+ if (scrollHeight - scrollTop - clientHeight < THRESHOLDS.SCROLL_THRESHOLD_PX) {
7551
7569
  this.scrollIndicator.classList.add("sf-scroll-indicator--hidden");
7552
7570
  } else {
7553
7571
  this.scrollIndicator.classList.remove("sf-scroll-indicator--hidden");
@@ -7750,12 +7768,12 @@ class InteractionManager {
7750
7768
  await this.flushAnalytics();
7751
7769
  if (store.currentState === "completedWaitingForInteraction") {
7752
7770
  store.completePlaylist();
7753
- await new Promise((resolve) => setTimeout(resolve, 100));
7771
+ await new Promise((resolve) => setTimeout(resolve, TIMING.STATE_PROCESSING_DELAY_MS));
7754
7772
  } else {
7755
7773
  const isLastStep = this.isCurrentStepLast(store);
7756
7774
  if (isLastStep) {
7757
7775
  store.goToStep("completed");
7758
- await new Promise((resolve) => setTimeout(resolve, 100));
7776
+ await new Promise((resolve) => setTimeout(resolve, TIMING.STATE_PROCESSING_DELAY_MS));
7759
7777
  }
7760
7778
  }
7761
7779
  window.open(buttonConfig.action.target, "_blank");
@@ -7771,7 +7789,7 @@ class InteractionManager {
7771
7789
  await this.flushAnalytics();
7772
7790
  log("InteractionManager: Completing current playlist before starting new one");
7773
7791
  store.completePlaylist();
7774
- await new Promise((resolve) => setTimeout(resolve, 100));
7792
+ await new Promise((resolve) => setTimeout(resolve, TIMING.STATE_PROCESSING_DELAY_MS));
7775
7793
  const { SaltfishPlayer: SaltfishPlayer22 } = await Promise.resolve().then(() => SaltfishPlayer$1);
7776
7794
  const player2 = SaltfishPlayer22.getInstance();
7777
7795
  if (player2) {
@@ -7886,6 +7904,13 @@ class InteractionManager {
7886
7904
  this.container = null;
7887
7905
  }
7888
7906
  }
7907
+ function getSaltfishStore() {
7908
+ try {
7909
+ return useSaltfishStore.getState();
7910
+ } catch (error2) {
7911
+ return null;
7912
+ }
7913
+ }
7889
7914
  class AnalyticsManager {
7890
7915
  // Default to enabled
7891
7916
  /**
@@ -7921,7 +7946,7 @@ class AnalyticsManager {
7921
7946
  return;
7922
7947
  }
7923
7948
  this.eventManager.on("playerPaused", (_) => {
7924
- const store = this.getStore();
7949
+ const store = getSaltfishStore();
7925
7950
  const runId = this.getRunId();
7926
7951
  if ((store == null ? void 0 : store.manifest) && store.currentStepId && runId) {
7927
7952
  this.trackEvent({
@@ -7934,7 +7959,7 @@ class AnalyticsManager {
7934
7959
  }
7935
7960
  });
7936
7961
  this.eventManager.on("playerResumed", (_) => {
7937
- const store = this.getStore();
7962
+ const store = getSaltfishStore();
7938
7963
  const runId = this.getRunId();
7939
7964
  if ((store == null ? void 0 : store.manifest) && store.currentStepId && runId) {
7940
7965
  this.trackEvent({
@@ -7973,7 +7998,7 @@ class AnalyticsManager {
7973
7998
  }
7974
7999
  });
7975
8000
  this.eventManager.on("playerMinimized", (_) => {
7976
- const store = this.getStore();
8001
+ const store = getSaltfishStore();
7977
8002
  const runId = this.getRunId();
7978
8003
  if ((store == null ? void 0 : store.manifest) && store.currentStepId && runId) {
7979
8004
  this.trackEvent({
@@ -7986,7 +8011,7 @@ class AnalyticsManager {
7986
8011
  }
7987
8012
  });
7988
8013
  this.eventManager.on("playerMaximized", (_) => {
7989
- const store = this.getStore();
8014
+ const store = getSaltfishStore();
7990
8015
  const runId = this.getRunId();
7991
8016
  if ((store == null ? void 0 : store.manifest) && store.currentStepId && runId) {
7992
8017
  this.trackEvent({
@@ -7999,17 +8024,6 @@ class AnalyticsManager {
7999
8024
  }
8000
8025
  });
8001
8026
  }
8002
- /**
8003
- * Helper to get the store state when needed
8004
- */
8005
- getStore() {
8006
- try {
8007
- return useSaltfishStore.getState();
8008
- } catch (error2) {
8009
- console.error("Failed to access store:", error2);
8010
- return null;
8011
- }
8012
- }
8013
8027
  /**
8014
8028
  * Initializes the analytics manager
8015
8029
  * @param config - Saltfish configuration
@@ -8024,7 +8038,7 @@ class AnalyticsManager {
8024
8038
  if (this.analyticsEnabled) {
8025
8039
  this.flushInterval = window.setInterval(() => {
8026
8040
  this.flushEvents();
8027
- }, 3e4);
8041
+ }, ANALYTICS.FLUSH_INTERVAL_MS);
8028
8042
  }
8029
8043
  }
8030
8044
  /**
@@ -8274,7 +8288,7 @@ class SessionManager {
8274
8288
  const sessionData = this.storageManager.getSession();
8275
8289
  if (sessionData) {
8276
8290
  const now = Date.now();
8277
- if (now - sessionData.lastActivity < TIMING.SESSION_EXPIRY) {
8291
+ if (now - sessionData.lastActivity < TIMING$1.SESSION_EXPIRY) {
8278
8292
  log(`SessionManager: Using existing session: ${sessionData.sessionId}`);
8279
8293
  this.updateSessionActivity(sessionData.sessionId);
8280
8294
  return sessionData.sessionId;
@@ -8606,10 +8620,10 @@ class TransitionManager {
8606
8620
  this.triggerTransition(nextStepId);
8607
8621
  } else if (retries < maxRetries) {
8608
8622
  log(`TransitionManager: State still incompatible (${currentStore.currentState}), will retry`);
8609
- setTimeout(retryTransition, 500);
8623
+ setTimeout(retryTransition, TIMING.RETRY_DELAY_MS);
8610
8624
  }
8611
8625
  };
8612
- setTimeout(retryTransition, 500);
8626
+ setTimeout(retryTransition, TIMING.RETRY_DELAY_MS);
8613
8627
  }
8614
8628
  const transitionId = `url-path-${Date.now()}`;
8615
8629
  const intervalId = window.setInterval(() => {
@@ -8618,7 +8632,7 @@ class TransitionManager {
8618
8632
  clearInterval(intervalId);
8619
8633
  this.triggerTransition(nextStepId);
8620
8634
  }
8621
- }, 5e3);
8635
+ }, TIMING.URL_PATH_CHECK_INTERVAL_MS);
8622
8636
  this.activeTransitions.set(transitionId, {
8623
8637
  handlers: /* @__PURE__ */ new Map(),
8624
8638
  // No DOM handlers for URL path transitions
@@ -8755,7 +8769,7 @@ class TransitionManager {
8755
8769
  try {
8756
8770
  log(`TransitionManager: Conditions met, transitioning to step '${nextStepId}'`);
8757
8771
  this.triggerTransition(nextStepId);
8758
- await new Promise((resolve) => setTimeout(resolve, 100));
8772
+ await new Promise((resolve) => setTimeout(resolve, TIMING.STATE_PROCESSING_DELAY_MS));
8759
8773
  log(`TransitionManager: Transition to '${nextStepId}' completed successfully`);
8760
8774
  return true;
8761
8775
  } catch (error2) {
@@ -9931,17 +9945,6 @@ class PlaylistManager {
9931
9945
  this.updateWatchedPlaylistStatus(event.playlist.id, "in_progress", event.step.id);
9932
9946
  });
9933
9947
  }
9934
- /**
9935
- * Helper to get the store state when needed
9936
- */
9937
- getStore() {
9938
- try {
9939
- return useSaltfishStore.getState();
9940
- } catch (error2) {
9941
- console.error("Failed to access store:", error2);
9942
- return null;
9943
- }
9944
- }
9945
9948
  /**
9946
9949
  * Updates the watched playlist status locally and in the backend
9947
9950
  * @param playlistId - ID of the playlist
@@ -9955,7 +9958,7 @@ class PlaylistManager {
9955
9958
  }
9956
9959
  this.isUpdatingWatchedPlaylists = true;
9957
9960
  try {
9958
- const store = this.getStore();
9961
+ const store = getSaltfishStore();
9959
9962
  if (!store) {
9960
9963
  return;
9961
9964
  }
@@ -10046,7 +10049,10 @@ class PlaylistManager {
10046
10049
  async load(playlistId, options) {
10047
10050
  var _a, _b;
10048
10051
  try {
10049
- const store = useSaltfishStore.getState();
10052
+ const store = getSaltfishStore();
10053
+ if (!store) {
10054
+ throw new Error("Store not available");
10055
+ }
10050
10056
  const isAnonymous = ((_a = store.user) == null ? void 0 : _a.__isAnonymous) === true;
10051
10057
  const savedProgress = isAnonymous ? store.progress : ((_b = store.userData) == null ? void 0 : _b.watchedPlaylists) || store.progress;
10052
10058
  const loadResult = await this.playlistLoader.loadManifest({
@@ -10064,9 +10070,13 @@ class PlaylistManager {
10064
10070
  });
10065
10071
  }
10066
10072
  } catch (error2) {
10067
- const store = useSaltfishStore.getState();
10073
+ const store = getSaltfishStore();
10068
10074
  const errorObj = error2 instanceof Error ? error2 : new Error("Unknown error loading manifest");
10069
- store.setError(errorObj);
10075
+ if (store) {
10076
+ store.setError(errorObj);
10077
+ } else {
10078
+ console.error("[PlaylistManager] Cannot set error: Store not available", errorObj);
10079
+ }
10070
10080
  }
10071
10081
  }
10072
10082
  /**
@@ -10976,7 +10986,7 @@ const _StepTimeoutManager = class _StepTimeoutManager {
10976
10986
  this.destroyCallback = null;
10977
10987
  }
10978
10988
  };
10979
- __publicField(_StepTimeoutManager, "STEP_TIMEOUT_MS", TIMING.STEP_TIMEOUT);
10989
+ __publicField(_StepTimeoutManager, "STEP_TIMEOUT_MS", TIMING$1.STEP_TIMEOUT);
10980
10990
  let StepTimeoutManager = _StepTimeoutManager;
10981
10991
  class ManagerFactory {
10982
10992
  /**
@@ -11234,7 +11244,7 @@ const SaltfishPlayer$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.de
11234
11244
  __proto__: null,
11235
11245
  SaltfishPlayer
11236
11246
  }, Symbol.toStringTag, { value: "Module" }));
11237
- const version = "0.3.3";
11247
+ const version = "0.3.4";
11238
11248
  const packageJson = {
11239
11249
  version
11240
11250
  };