saltfish 0.3.3 → 0.3.5

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
  }
@@ -6994,6 +7012,13 @@ class CursorManager {
6994
7012
  this.lastCursorY = this.targetY;
6995
7013
  this.dragPhase = "dragging";
6996
7014
  this.dragAnimationStartTime = performance.now();
7015
+ const dragDistance = this.calculateDistance(
7016
+ this.dragStartX + this.SELECTION_HORIZONTAL_OFFSET,
7017
+ this.dragStartY + this.SELECTION_VERTICAL_OFFSET,
7018
+ this.dragEndX + this.SELECTION_HORIZONTAL_OFFSET,
7019
+ this.dragEndY + this.SELECTION_VERTICAL_OFFSET
7020
+ );
7021
+ this.animationDuration = this.calculateAnimationDuration(dragDistance);
6997
7022
  if (this.cursor) {
6998
7023
  const x = this.lastCursorX;
6999
7024
  const y = this.lastCursorY;
@@ -7074,7 +7099,7 @@ class CursorManager {
7074
7099
  this.updateDragCoordinatesFromElement();
7075
7100
  }
7076
7101
  const elapsed = timestamp - this.dragAnimationStartTime;
7077
- const progress = Math.min(elapsed / 1e3, 1);
7102
+ const progress = Math.min(elapsed / this.animationDuration, 1);
7078
7103
  const easedProgress = 0.5 - 0.5 * Math.cos(progress * Math.PI);
7079
7104
  const currentX = this.dragStartX + (this.dragEndX - this.dragStartX) * easedProgress + this.SELECTION_HORIZONTAL_OFFSET;
7080
7105
  const currentY = this.dragStartY + (this.dragEndY - this.dragStartY) * easedProgress + this.SELECTION_VERTICAL_OFFSET;
@@ -7547,7 +7572,7 @@ class InteractionManager {
7547
7572
  const scrollHeight = container.scrollHeight;
7548
7573
  const scrollTop = container.scrollTop;
7549
7574
  const clientHeight = container.clientHeight;
7550
- if (scrollHeight - scrollTop - clientHeight < 10) {
7575
+ if (scrollHeight - scrollTop - clientHeight < THRESHOLDS.SCROLL_THRESHOLD_PX) {
7551
7576
  this.scrollIndicator.classList.add("sf-scroll-indicator--hidden");
7552
7577
  } else {
7553
7578
  this.scrollIndicator.classList.remove("sf-scroll-indicator--hidden");
@@ -7750,12 +7775,12 @@ class InteractionManager {
7750
7775
  await this.flushAnalytics();
7751
7776
  if (store.currentState === "completedWaitingForInteraction") {
7752
7777
  store.completePlaylist();
7753
- await new Promise((resolve) => setTimeout(resolve, 100));
7778
+ await new Promise((resolve) => setTimeout(resolve, TIMING.STATE_PROCESSING_DELAY_MS));
7754
7779
  } else {
7755
7780
  const isLastStep = this.isCurrentStepLast(store);
7756
7781
  if (isLastStep) {
7757
7782
  store.goToStep("completed");
7758
- await new Promise((resolve) => setTimeout(resolve, 100));
7783
+ await new Promise((resolve) => setTimeout(resolve, TIMING.STATE_PROCESSING_DELAY_MS));
7759
7784
  }
7760
7785
  }
7761
7786
  window.open(buttonConfig.action.target, "_blank");
@@ -7771,7 +7796,7 @@ class InteractionManager {
7771
7796
  await this.flushAnalytics();
7772
7797
  log("InteractionManager: Completing current playlist before starting new one");
7773
7798
  store.completePlaylist();
7774
- await new Promise((resolve) => setTimeout(resolve, 100));
7799
+ await new Promise((resolve) => setTimeout(resolve, TIMING.STATE_PROCESSING_DELAY_MS));
7775
7800
  const { SaltfishPlayer: SaltfishPlayer22 } = await Promise.resolve().then(() => SaltfishPlayer$1);
7776
7801
  const player2 = SaltfishPlayer22.getInstance();
7777
7802
  if (player2) {
@@ -7886,6 +7911,13 @@ class InteractionManager {
7886
7911
  this.container = null;
7887
7912
  }
7888
7913
  }
7914
+ function getSaltfishStore() {
7915
+ try {
7916
+ return useSaltfishStore.getState();
7917
+ } catch (error2) {
7918
+ return null;
7919
+ }
7920
+ }
7889
7921
  class AnalyticsManager {
7890
7922
  // Default to enabled
7891
7923
  /**
@@ -7921,7 +7953,7 @@ class AnalyticsManager {
7921
7953
  return;
7922
7954
  }
7923
7955
  this.eventManager.on("playerPaused", (_) => {
7924
- const store = this.getStore();
7956
+ const store = getSaltfishStore();
7925
7957
  const runId = this.getRunId();
7926
7958
  if ((store == null ? void 0 : store.manifest) && store.currentStepId && runId) {
7927
7959
  this.trackEvent({
@@ -7934,7 +7966,7 @@ class AnalyticsManager {
7934
7966
  }
7935
7967
  });
7936
7968
  this.eventManager.on("playerResumed", (_) => {
7937
- const store = this.getStore();
7969
+ const store = getSaltfishStore();
7938
7970
  const runId = this.getRunId();
7939
7971
  if ((store == null ? void 0 : store.manifest) && store.currentStepId && runId) {
7940
7972
  this.trackEvent({
@@ -7973,7 +8005,7 @@ class AnalyticsManager {
7973
8005
  }
7974
8006
  });
7975
8007
  this.eventManager.on("playerMinimized", (_) => {
7976
- const store = this.getStore();
8008
+ const store = getSaltfishStore();
7977
8009
  const runId = this.getRunId();
7978
8010
  if ((store == null ? void 0 : store.manifest) && store.currentStepId && runId) {
7979
8011
  this.trackEvent({
@@ -7986,7 +8018,7 @@ class AnalyticsManager {
7986
8018
  }
7987
8019
  });
7988
8020
  this.eventManager.on("playerMaximized", (_) => {
7989
- const store = this.getStore();
8021
+ const store = getSaltfishStore();
7990
8022
  const runId = this.getRunId();
7991
8023
  if ((store == null ? void 0 : store.manifest) && store.currentStepId && runId) {
7992
8024
  this.trackEvent({
@@ -7999,17 +8031,6 @@ class AnalyticsManager {
7999
8031
  }
8000
8032
  });
8001
8033
  }
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
8034
  /**
8014
8035
  * Initializes the analytics manager
8015
8036
  * @param config - Saltfish configuration
@@ -8024,7 +8045,7 @@ class AnalyticsManager {
8024
8045
  if (this.analyticsEnabled) {
8025
8046
  this.flushInterval = window.setInterval(() => {
8026
8047
  this.flushEvents();
8027
- }, 3e4);
8048
+ }, ANALYTICS.FLUSH_INTERVAL_MS);
8028
8049
  }
8029
8050
  }
8030
8051
  /**
@@ -8274,7 +8295,7 @@ class SessionManager {
8274
8295
  const sessionData = this.storageManager.getSession();
8275
8296
  if (sessionData) {
8276
8297
  const now = Date.now();
8277
- if (now - sessionData.lastActivity < TIMING.SESSION_EXPIRY) {
8298
+ if (now - sessionData.lastActivity < TIMING$1.SESSION_EXPIRY) {
8278
8299
  log(`SessionManager: Using existing session: ${sessionData.sessionId}`);
8279
8300
  this.updateSessionActivity(sessionData.sessionId);
8280
8301
  return sessionData.sessionId;
@@ -8606,10 +8627,10 @@ class TransitionManager {
8606
8627
  this.triggerTransition(nextStepId);
8607
8628
  } else if (retries < maxRetries) {
8608
8629
  log(`TransitionManager: State still incompatible (${currentStore.currentState}), will retry`);
8609
- setTimeout(retryTransition, 500);
8630
+ setTimeout(retryTransition, TIMING.RETRY_DELAY_MS);
8610
8631
  }
8611
8632
  };
8612
- setTimeout(retryTransition, 500);
8633
+ setTimeout(retryTransition, TIMING.RETRY_DELAY_MS);
8613
8634
  }
8614
8635
  const transitionId = `url-path-${Date.now()}`;
8615
8636
  const intervalId = window.setInterval(() => {
@@ -8618,7 +8639,7 @@ class TransitionManager {
8618
8639
  clearInterval(intervalId);
8619
8640
  this.triggerTransition(nextStepId);
8620
8641
  }
8621
- }, 5e3);
8642
+ }, TIMING.URL_PATH_CHECK_INTERVAL_MS);
8622
8643
  this.activeTransitions.set(transitionId, {
8623
8644
  handlers: /* @__PURE__ */ new Map(),
8624
8645
  // No DOM handlers for URL path transitions
@@ -8755,7 +8776,7 @@ class TransitionManager {
8755
8776
  try {
8756
8777
  log(`TransitionManager: Conditions met, transitioning to step '${nextStepId}'`);
8757
8778
  this.triggerTransition(nextStepId);
8758
- await new Promise((resolve) => setTimeout(resolve, 100));
8779
+ await new Promise((resolve) => setTimeout(resolve, TIMING.STATE_PROCESSING_DELAY_MS));
8759
8780
  log(`TransitionManager: Transition to '${nextStepId}' completed successfully`);
8760
8781
  return true;
8761
8782
  } catch (error2) {
@@ -9931,17 +9952,6 @@ class PlaylistManager {
9931
9952
  this.updateWatchedPlaylistStatus(event.playlist.id, "in_progress", event.step.id);
9932
9953
  });
9933
9954
  }
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
9955
  /**
9946
9956
  * Updates the watched playlist status locally and in the backend
9947
9957
  * @param playlistId - ID of the playlist
@@ -9955,7 +9965,7 @@ class PlaylistManager {
9955
9965
  }
9956
9966
  this.isUpdatingWatchedPlaylists = true;
9957
9967
  try {
9958
- const store = this.getStore();
9968
+ const store = getSaltfishStore();
9959
9969
  if (!store) {
9960
9970
  return;
9961
9971
  }
@@ -10046,7 +10056,10 @@ class PlaylistManager {
10046
10056
  async load(playlistId, options) {
10047
10057
  var _a, _b;
10048
10058
  try {
10049
- const store = useSaltfishStore.getState();
10059
+ const store = getSaltfishStore();
10060
+ if (!store) {
10061
+ throw new Error("Store not available");
10062
+ }
10050
10063
  const isAnonymous = ((_a = store.user) == null ? void 0 : _a.__isAnonymous) === true;
10051
10064
  const savedProgress = isAnonymous ? store.progress : ((_b = store.userData) == null ? void 0 : _b.watchedPlaylists) || store.progress;
10052
10065
  const loadResult = await this.playlistLoader.loadManifest({
@@ -10064,9 +10077,13 @@ class PlaylistManager {
10064
10077
  });
10065
10078
  }
10066
10079
  } catch (error2) {
10067
- const store = useSaltfishStore.getState();
10080
+ const store = getSaltfishStore();
10068
10081
  const errorObj = error2 instanceof Error ? error2 : new Error("Unknown error loading manifest");
10069
- store.setError(errorObj);
10082
+ if (store) {
10083
+ store.setError(errorObj);
10084
+ } else {
10085
+ console.error("[PlaylistManager] Cannot set error: Store not available", errorObj);
10086
+ }
10070
10087
  }
10071
10088
  }
10072
10089
  /**
@@ -10976,7 +10993,7 @@ const _StepTimeoutManager = class _StepTimeoutManager {
10976
10993
  this.destroyCallback = null;
10977
10994
  }
10978
10995
  };
10979
- __publicField(_StepTimeoutManager, "STEP_TIMEOUT_MS", TIMING.STEP_TIMEOUT);
10996
+ __publicField(_StepTimeoutManager, "STEP_TIMEOUT_MS", TIMING$1.STEP_TIMEOUT);
10980
10997
  let StepTimeoutManager = _StepTimeoutManager;
10981
10998
  class ManagerFactory {
10982
10999
  /**
@@ -11234,7 +11251,7 @@ const SaltfishPlayer$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.de
11234
11251
  __proto__: null,
11235
11252
  SaltfishPlayer
11236
11253
  }, Symbol.toStringTag, { value: "Module" }));
11237
- const version = "0.3.3";
11254
+ const version = "0.3.5";
11238
11255
  const packageJson = {
11239
11256
  version
11240
11257
  };