saltfish 0.2.28 → 0.2.29

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.
@@ -2876,94 +2876,89 @@ class StateMachineActionHandler {
2876
2876
  if (!context.currentStep) {
2877
2877
  return;
2878
2878
  }
2879
- if (context.currentStep.urlRequirement) {
2880
- log(`StateMachineActionHandler: Validating URL requirement for step ${context.currentStep.id}`);
2881
- const isValid = this.validateStepUrlRequirement(context.currentStep);
2879
+ const currentStep = context.currentStep;
2880
+ if (currentStep.urlRequirement) {
2881
+ log(`StateMachineActionHandler: Validating URL requirement for step ${currentStep.id}`);
2882
+ const isValid = this.validateStepUrlRequirement(currentStep);
2882
2883
  if (!isValid) {
2883
2884
  return;
2884
2885
  }
2885
2886
  }
2886
- const videoUrl = this.getVideoUrl(context.currentStep);
2887
+ const videoUrl = this.getVideoUrl(currentStep);
2887
2888
  try {
2888
2889
  this.managers.interactionManager.clearButtons();
2889
2890
  this.managers.interactionManager.clearDOMInteractions();
2890
- if (context.currentStep.domInteractions) {
2891
- this.managers.interactionManager.setupDOMInteractions(context.currentStep.domInteractions);
2891
+ if (currentStep.domInteractions) {
2892
+ this.managers.interactionManager.setupDOMInteractions(currentStep.domInteractions);
2892
2893
  }
2893
- if (context.currentStep.buttons) {
2894
- this.managers.interactionManager.createButtons(context.currentStep.buttons);
2894
+ if (currentStep.buttons) {
2895
+ this.managers.interactionManager.createButtons(currentStep.buttons);
2895
2896
  }
2896
- log(`StateMachineActionHandler: Processing cursor animations for step ${context.currentStep.id}`);
2897
- log(`StateMachineActionHandler: Step has cursor animations: ${!!(context.currentStep.cursorAnimations && context.currentStep.cursorAnimations.length > 0)}`);
2898
- if (context.currentStep.cursorAnimations && context.currentStep.cursorAnimations.length > 0) {
2899
- log(`StateMachineActionHandler: Setting cursor visibility to true for step ${context.currentStep.id}`);
2897
+ log(`StateMachineActionHandler: Processing cursor animations for step ${currentStep.id}`);
2898
+ log(`StateMachineActionHandler: Step has cursor animations: ${!!(currentStep.cursorAnimations && currentStep.cursorAnimations.length > 0)}`);
2899
+ if (currentStep.cursorAnimations && currentStep.cursorAnimations.length > 0) {
2900
+ log(`StateMachineActionHandler: Setting cursor visibility to true for step ${currentStep.id}`);
2900
2901
  this.managers.cursorManager.setShouldShowCursor(true);
2901
- log(`StateMachineActionHandler: Starting cursor animation for step ${context.currentStep.id} with target: ${context.currentStep.cursorAnimations[0].targetSelector || "no target"}`);
2902
- this.managers.cursorManager.animate(context.currentStep.cursorAnimations[0]);
2902
+ log(`StateMachineActionHandler: Starting cursor animation for step ${currentStep.id} with target: ${currentStep.cursorAnimations[0].targetSelector || "no target"}`);
2903
+ this.managers.cursorManager.animate(currentStep.cursorAnimations[0]);
2903
2904
  } else {
2904
- log(`StateMachineActionHandler: Setting cursor visibility to false for step ${context.currentStep.id} - step has no cursor animations`);
2905
+ log(`StateMachineActionHandler: Setting cursor visibility to false for step ${currentStep.id} - step has no cursor animations`);
2905
2906
  this.managers.cursorManager.setShouldShowCursor(false);
2906
2907
  }
2907
- const hasSpecialTransitions = context.currentStep.buttons && context.currentStep.buttons.length > 0 || context.currentStep.transitions.some(
2908
+ const hasSpecialTransitions = currentStep.buttons && currentStep.buttons.length > 0 || currentStep.transitions.some(
2908
2909
  (t) => t.type === "dom-click" || t.type === "url-path" || t.type === "dom-element-visible"
2909
2910
  );
2910
2911
  const completionPolicy = hasSpecialTransitions ? "manual" : "auto";
2911
2912
  if (hasSpecialTransitions) {
2912
2913
  log("StateMachineActionHandler: Setting up transitions immediately for step with special transitions");
2913
- this.managers.transitionManager.setupTransitions(context.currentStep, false);
2914
+ this.managers.transitionManager.setupTransitions(currentStep, false);
2914
2915
  }
2915
2916
  this.managers.videoManager.setCompletionPolicy(completionPolicy, () => {
2916
- if (context.currentStep) {
2917
- const store = useSaltfishStore.getState();
2918
- if (!hasSpecialTransitions) {
2919
- log("StateMachineActionHandler: Setting up transitions after video ended");
2920
- this.managers.transitionManager.setupTransitions(context.currentStep, true);
2921
- const hasValidNextSteps = context.currentStep.transitions.some((transition) => {
2922
- return store.manifest.steps.some((s) => s.id === transition.nextStep);
2923
- });
2924
- if (!hasValidNextSteps) {
2925
- log("StateMachineActionHandler: No valid next steps found, completing playlist");
2926
- store.sendStateMachineEvent({
2927
- type: "COMPLETE_PLAYLIST"
2928
- });
2929
- }
2930
- } else {
2917
+ const store = useSaltfishStore.getState();
2918
+ if (!hasSpecialTransitions) {
2919
+ log("StateMachineActionHandler: Setting up transitions after video ended");
2920
+ this.managers.transitionManager.setupTransitions(currentStep, true);
2921
+ const hasValidNextSteps = currentStep.transitions.some((transition) => {
2922
+ return store.manifest.steps.some((s) => s.id === transition.nextStep);
2923
+ });
2924
+ if (!hasValidNextSteps) {
2925
+ log("StateMachineActionHandler: No valid next steps found, completing playlist");
2931
2926
  store.sendStateMachineEvent({
2932
- type: "VIDEO_FINISHED_WAIT",
2933
- step: context.currentStep
2927
+ type: "COMPLETE_PLAYLIST"
2934
2928
  });
2935
2929
  }
2930
+ } else {
2931
+ store.sendStateMachineEvent({
2932
+ type: "VIDEO_FINISHED_WAIT",
2933
+ step: currentStep
2934
+ });
2936
2935
  }
2937
2936
  });
2938
2937
  log("StateMachineActionHandler: Starting async video load");
2939
2938
  const loadTranscriptForStep = () => {
2940
2939
  var _a, _b, _c;
2941
- if (context.currentStep) {
2942
- const store = useSaltfishStore.getState();
2943
- const currentPlaylistId = (_a = store.manifest) == null ? void 0 : _a.id;
2944
- const currentPlaylist = (_b = store.backendPlaylists) == null ? void 0 : _b.find((p) => p.id === currentPlaylistId);
2945
- const captionsEnabled = (currentPlaylist == null ? void 0 : currentPlaylist.captions) === true;
2946
- const language = (_c = store.config) == null ? void 0 : _c.language;
2947
- let transcript = context.currentStep.transcript;
2948
- if (language && context.currentStep.translations && context.currentStep.translations[language]) {
2949
- const translatedTranscript = context.currentStep.translations[language].transcript;
2950
- if (translatedTranscript) {
2951
- transcript = translatedTranscript;
2952
- log(`StateMachineActionHandler: Loading translated transcript for step ${context.currentStep.id} in language ${language}`);
2953
- } else {
2954
- log(`StateMachineActionHandler: No translated transcript found for language ${language}, using default`);
2955
- }
2956
- } else if (language) {
2957
- log(`StateMachineActionHandler: No translation available for language ${language}, using default transcript`);
2958
- }
2959
- if (transcript) {
2960
- log(`StateMachineActionHandler: Loading transcript for step ${context.currentStep.id}, initially visible: ${captionsEnabled}`);
2961
- this.managers.videoManager.loadTranscript(transcript, captionsEnabled);
2940
+ const store = useSaltfishStore.getState();
2941
+ const currentPlaylistId = (_a = store.manifest) == null ? void 0 : _a.id;
2942
+ const currentPlaylist = (_b = store.backendPlaylists) == null ? void 0 : _b.find((p) => p.id === currentPlaylistId);
2943
+ const captionsEnabled = (currentPlaylist == null ? void 0 : currentPlaylist.captions) === true;
2944
+ const language = (_c = store.config) == null ? void 0 : _c.language;
2945
+ let transcript = currentStep.transcript;
2946
+ if (language && currentStep.translations && currentStep.translations[language]) {
2947
+ const translatedTranscript = currentStep.translations[language].transcript;
2948
+ if (translatedTranscript) {
2949
+ transcript = translatedTranscript;
2950
+ log(`StateMachineActionHandler: Loading translated transcript for step ${currentStep.id} in language ${language}`);
2962
2951
  } else {
2963
- log(`StateMachineActionHandler: No transcript available for step ${context.currentStep.id}`);
2964
- this.managers.videoManager.loadTranscript(null, true);
2952
+ log(`StateMachineActionHandler: No translated transcript found for language ${language}, using default`);
2965
2953
  }
2954
+ } else if (language) {
2955
+ log(`StateMachineActionHandler: No translation available for language ${language}, using default transcript`);
2956
+ }
2957
+ if (transcript) {
2958
+ log(`StateMachineActionHandler: Loading transcript for step ${currentStep.id}, initially visible: ${captionsEnabled}`);
2959
+ this.managers.videoManager.loadTranscript(transcript, captionsEnabled);
2966
2960
  } else {
2961
+ log(`StateMachineActionHandler: No transcript available for step ${currentStep.id}`);
2967
2962
  this.managers.videoManager.loadTranscript(null, true);
2968
2963
  }
2969
2964
  };
@@ -2971,15 +2966,13 @@ class StateMachineActionHandler {
2971
2966
  log("StateMachineActionHandler: Video loaded successfully, playing");
2972
2967
  loadTranscriptForStep();
2973
2968
  this.managers.videoManager.play();
2974
- if (context.currentStep) {
2975
- const nextVideoUrl = this.findNextVideoUrl(context.currentStep);
2976
- if (nextVideoUrl) {
2977
- log(`StateMachineActionHandler: Preloading next video: ${nextVideoUrl}`);
2978
- this.managers.videoManager.preloadNextVideo(nextVideoUrl);
2979
- }
2969
+ const nextVideoUrl = this.findNextVideoUrl(currentStep);
2970
+ if (nextVideoUrl) {
2971
+ log(`StateMachineActionHandler: Preloading next video: ${nextVideoUrl}`);
2972
+ this.managers.videoManager.preloadNextVideo(nextVideoUrl);
2980
2973
  }
2981
2974
  }).catch((error2) => {
2982
- var _a, _b;
2975
+ var _a;
2983
2976
  log(`StateMachineActionHandler: Error loading video: ${error2}`);
2984
2977
  this.managers.uiManager.showError(
2985
2978
  error2 instanceof Error ? error2 : new Error(`Failed to load video: ${error2}`),
@@ -2991,7 +2984,7 @@ class StateMachineActionHandler {
2991
2984
  this.managers.eventManager.trigger("error", {
2992
2985
  timestamp: Date.now(),
2993
2986
  playlistId: ((_a = store.manifest) == null ? void 0 : _a.id) || void 0,
2994
- stepId: (_b = context.currentStep) == null ? void 0 : _b.id,
2987
+ stepId: currentStep.id,
2995
2988
  error: errorObj,
2996
2989
  errorType: "video",
2997
2990
  videoUrl: enrichedError == null ? void 0 : enrichedError.videoUrl,
@@ -3019,34 +3012,35 @@ class StateMachineActionHandler {
3019
3012
  if (!context.currentStep) {
3020
3013
  return;
3021
3014
  }
3022
- const videoUrl = this.getVideoUrl(context.currentStep);
3015
+ const currentStep = context.currentStep;
3016
+ const videoUrl = this.getVideoUrl(currentStep);
3023
3017
  try {
3024
3018
  this.managers.interactionManager.clearButtons();
3025
3019
  this.managers.interactionManager.clearDOMInteractions();
3026
- if (context.currentStep.domInteractions) {
3027
- this.managers.interactionManager.setupDOMInteractions(context.currentStep.domInteractions);
3020
+ if (currentStep.domInteractions) {
3021
+ this.managers.interactionManager.setupDOMInteractions(currentStep.domInteractions);
3028
3022
  }
3029
- if (context.currentStep.buttons) {
3030
- this.managers.interactionManager.createButtons(context.currentStep.buttons);
3023
+ if (currentStep.buttons) {
3024
+ this.managers.interactionManager.createButtons(currentStep.buttons);
3031
3025
  }
3032
- if (context.currentStep.cursorAnimations && context.currentStep.cursorAnimations.length > 0) {
3033
- log(`StateMachineActionHandler: Setting up cursor animations for idle mode step ${context.currentStep.id}`);
3026
+ if (currentStep.cursorAnimations && currentStep.cursorAnimations.length > 0) {
3027
+ log(`StateMachineActionHandler: Setting up cursor animations for idle mode step ${currentStep.id}`);
3034
3028
  this.managers.cursorManager.setShouldShowCursor(true);
3035
- this.managers.cursorManager.animate(context.currentStep.cursorAnimations[0]);
3029
+ this.managers.cursorManager.animate(currentStep.cursorAnimations[0]);
3036
3030
  } else {
3037
3031
  this.managers.cursorManager.setShouldShowCursor(false);
3038
3032
  }
3039
- const hasSpecialTransitions = context.currentStep.buttons && context.currentStep.buttons.length > 0 || context.currentStep.transitions.some(
3033
+ const hasSpecialTransitions = currentStep.buttons && currentStep.buttons.length > 0 || currentStep.transitions.some(
3040
3034
  (t) => t.type === "dom-click" || t.type === "url-path"
3041
3035
  );
3042
3036
  const completionPolicy = hasSpecialTransitions ? "manual" : "auto";
3043
3037
  if (hasSpecialTransitions) {
3044
3038
  log("StateMachineActionHandler: Setting up transitions for idle mode step with special transitions");
3045
- this.managers.transitionManager.setupTransitions(context.currentStep, false);
3039
+ this.managers.transitionManager.setupTransitions(currentStep, false);
3046
3040
  }
3047
3041
  this.managers.videoManager.setCompletionPolicy(completionPolicy, () => {
3048
- if (context.currentStep && !hasSpecialTransitions) {
3049
- this.managers.transitionManager.setupTransitions(context.currentStep, true);
3042
+ if (!hasSpecialTransitions) {
3043
+ this.managers.transitionManager.setupTransitions(currentStep, true);
3050
3044
  }
3051
3045
  });
3052
3046
  log("StateMachineActionHandler: Starting async idle mode video load");
@@ -3061,27 +3055,25 @@ class StateMachineActionHandler {
3061
3055
  log("StateMachineActionHandler: Idle mode video play failed");
3062
3056
  });
3063
3057
  }
3064
- if (context.currentStep) {
3065
- const store = useSaltfishStore.getState();
3066
- const currentPlaylistId = (_a = store.manifest) == null ? void 0 : _a.id;
3067
- const currentPlaylist = (_b = store.backendPlaylists) == null ? void 0 : _b.find((p) => p.id === currentPlaylistId);
3068
- const captionsEnabled = (currentPlaylist == null ? void 0 : currentPlaylist.captions) === true;
3069
- const language = (_c = store.config) == null ? void 0 : _c.language;
3070
- let transcript = context.currentStep.transcript;
3071
- if (language && context.currentStep.translations && context.currentStep.translations[language]) {
3072
- const translation = context.currentStep.translations[language];
3073
- if (translation.transcript) {
3074
- transcript = translation.transcript;
3075
- log(`StateMachineActionHandler: Using translated transcript for idle mode, language: ${language}`);
3076
- }
3077
- }
3078
- if (transcript) {
3079
- log(`StateMachineActionHandler: Loading transcript for idle mode step ${context.currentStep.id}, initially visible: ${captionsEnabled}`);
3080
- this.managers.videoManager.loadTranscript(transcript, captionsEnabled);
3081
- } else {
3082
- this.managers.videoManager.loadTranscript(null, true);
3058
+ const store = useSaltfishStore.getState();
3059
+ const currentPlaylistId = (_a = store.manifest) == null ? void 0 : _a.id;
3060
+ const currentPlaylist = (_b = store.backendPlaylists) == null ? void 0 : _b.find((p) => p.id === currentPlaylistId);
3061
+ const captionsEnabled = (currentPlaylist == null ? void 0 : currentPlaylist.captions) === true;
3062
+ const language = (_c = store.config) == null ? void 0 : _c.language;
3063
+ let transcript = currentStep.transcript;
3064
+ if (language && currentStep.translations && currentStep.translations[language]) {
3065
+ const translation = currentStep.translations[language];
3066
+ if (translation.transcript) {
3067
+ transcript = translation.transcript;
3068
+ log(`StateMachineActionHandler: Using translated transcript for idle mode, language: ${language}`);
3083
3069
  }
3084
3070
  }
3071
+ if (transcript) {
3072
+ log(`StateMachineActionHandler: Loading transcript for idle mode step ${currentStep.id}, initially visible: ${captionsEnabled}`);
3073
+ this.managers.videoManager.loadTranscript(transcript, captionsEnabled);
3074
+ } else {
3075
+ this.managers.videoManager.loadTranscript(null, true);
3076
+ }
3085
3077
  }).catch((error2) => {
3086
3078
  log(`StateMachineActionHandler: Error loading idle mode video: ${error2}`);
3087
3079
  });