Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Merge upstream/main into paperfm24

Anand Baburajand4799aaa4227
diff --cc web/apps/memories/package.json
index 0000000000,d976a290eb..56cce5f552
mode 000000,100644..100644
--- a/web/apps/memories/package.json
+++ b/web/apps/memories/package.json
@@@ -1,0 -1,18 +1,19 @@@
+ {
+ "name": "memories",
+ "version": "0.0.0",
+ "private": true,
+ "scripts": {
+ "build:post": "rm -f out/404.html"
+ },
+ "dependencies": {
+ "@fontsource/itim": "^5.2.7",
+ "ente-base": "*",
+ "ente-gallery": "*",
+ "ente-media": "*",
- "ente-new": "*"
++ "ente-new": "*",
++ "zod": "^4.1.12"
+ },
+ "devDependencies": {
+ "ente-build-config": "*"
+ }
+ }
diff --cc web/apps/memories/src/components/PublicMemoryMedia.tsx
index 0000000000,7b0cdb0701..1a3ed0f703
mode 000000,100644..100644
--- a/web/apps/memories/src/components/PublicMemoryMedia.tsx
+++ b/web/apps/memories/src/components/PublicMemoryMedia.tsx
@@@ -1,0 -1,473 +1,473 @@@
+ import { Box, Typography } from "@mui/material";
+ import { LoadingIndicator } from "ente-base/components/loaders";
+ import log from "ente-base/log";
+ import {
+ downloadManager,
+ type RenderableSourceURLs,
+ } from "ente-gallery/services/download";
+ import type { HLSPlaylistData } from "ente-gallery/services/video";
+ import type { EnteFile } from "ente-media/file";
-import type { PublicMemoryShareFrameCrop } from "ente-new/albums/services/public-memory";
+ import "hls-video-element";
+ import {
+ type CSSProperties,
+ type RefObject,
+ useCallback,
+ useEffect,
+ useRef,
+ useState,
+ } from "react";
++import type { PublicMemoryShareFrameCrop } from "../services/public-memory";
+ import { computeMediaCropStyle } from "../utils/lane";
+
+ const DEFAULT_MEDIA_MAX_WIDTH_CSS = "min(1264px, calc(100vw - 48px))";
+ const DEFAULT_MEDIA_MAX_HEIGHT_CSS = "calc(min(100vh, 100dvh) - 220px)";
+
+ const buildMediaStyle = ({
+ cropRect,
+ cropContainerAspectRatio,
+ fillFrame,
+ mediaAspectRatio,
+ objectFit,
+ }: {
+ cropRect?: PublicMemoryShareFrameCrop;
+ cropContainerAspectRatio?: number;
+ fillFrame?: boolean;
+ mediaAspectRatio?: number;
+ objectFit: "contain" | "cover";
+ }): CSSProperties => {
+ const cropStyle = computeMediaCropStyle({
+ cropRect,
+ mediaAspectRatio,
+ containerAspectRatio: cropContainerAspectRatio,
+ });
+
+ return {
+ display: "block",
+ ...(cropStyle ?? {
+ width: fillFrame ? "100%" : "auto",
+ height: fillFrame ? "100%" : "auto",
+ maxWidth: fillFrame ? "100%" : DEFAULT_MEDIA_MAX_WIDTH_CSS,
+ maxHeight: fillFrame ? "100%" : DEFAULT_MEDIA_MAX_HEIGHT_CSS,
+ objectFit,
+ }),
+ userSelect: "none",
+ pointerEvents: "none",
+ };
+ };
+
+ function MediaLoadingOverlay() {
+ return (
+ <Box
+ sx={{
+ position: "absolute",
+ inset: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
+ zIndex: 2,
+ }}
+ >
+ <LoadingIndicator />
+ </Box>
+ );
+ }
+
+ export interface PhotoImageProps {
+ file: EnteFile;
+ onFullLoad?: () => void;
+ fillFrame?: boolean;
+ objectFit?: "contain" | "cover";
+ thumbnailOnly?: boolean;
+ cropRect?: PublicMemoryShareFrameCrop;
+ cropContainerAspectRatio?: number;
+ mediaAspectRatio?: number;
+ onAspectRatio?: (width: number, height: number) => void;
+ showLoadingOverlay?: boolean;
+ }
+
+ export function PhotoImage({
+ file,
+ onFullLoad,
+ fillFrame,
+ objectFit = "contain",
+ thumbnailOnly = false,
+ cropRect,
+ cropContainerAspectRatio,
+ mediaAspectRatio,
+ onAspectRatio,
+ showLoadingOverlay = true,
+ }: PhotoImageProps) {
+ const [thumbnailURL, setThumbnailURL] = useState<string | undefined>(
+ undefined,
+ );
+ const [fullImageURL, setFullImageURL] = useState<string | undefined>(
+ undefined,
+ );
+ const [isLoading, setIsLoading] = useState(true);
+ const imageRef = useRef<HTMLImageElement | null>(null);
+ const onFullLoadRef = useRef(onFullLoad);
+ const onAspectRatioRef = useRef(onAspectRatio);
+ const mediaReadyRef = useRef(false);
+ const hasNotifiedDisplayReadyRef = useRef(false);
+
+ onFullLoadRef.current = onFullLoad;
+ onAspectRatioRef.current = onAspectRatio;
+
+ const signalReady = useCallback(() => {
+ mediaReadyRef.current = true;
+ if (hasNotifiedDisplayReadyRef.current || !onFullLoadRef.current) {
+ return;
+ }
+ hasNotifiedDisplayReadyRef.current = true;
+ onFullLoadRef.current();
+ }, []);
+
+ useEffect(() => {
+ let cancelled = false;
+ setIsLoading(true);
+ setThumbnailURL(undefined);
+ setFullImageURL(undefined);
+ mediaReadyRef.current = false;
+ hasNotifiedDisplayReadyRef.current = false;
+
+ const loadThumbnail = async () => {
+ try {
+ const nextThumbnailURL =
+ await downloadManager.renderableThumbnailURL(file);
+ if (!cancelled && nextThumbnailURL) {
+ setThumbnailURL(nextThumbnailURL);
+ } else if (!cancelled) {
+ setIsLoading(false);
+ }
+ } catch (error) {
+ log.error("Failed to load thumbnail", error);
+ if (!cancelled) {
+ setIsLoading(false);
+ }
+ }
+ };
+
+ const loadFullImage = async () => {
+ if (thumbnailOnly) {
+ return;
+ }
+ try {
+ const sourceURLs =
+ await downloadManager.renderableSourceURLs(file);
+ if (cancelled) {
+ return;
+ }
+ if (sourceURLs.type === "image") {
+ setFullImageURL(sourceURLs.imageURL);
+ } else {
+ signalReady();
+ }
+ } catch (error) {
+ log.error("Failed to load full image", error);
+ if (!cancelled) {
+ signalReady();
+ }
+ }
+ };
+
+ void loadThumbnail();
+ void loadFullImage();
+
+ return () => {
+ cancelled = true;
+ };
+ }, [file, signalReady, thumbnailOnly]);
+
+ useEffect(() => {
+ if (!onFullLoad) {
+ hasNotifiedDisplayReadyRef.current = false;
+ return;
+ }
+ if (mediaReadyRef.current && !hasNotifiedDisplayReadyRef.current) {
+ hasNotifiedDisplayReadyRef.current = true;
+ onFullLoad();
+ }
+ }, [onFullLoad]);
+
+ useEffect(() => {
+ if (thumbnailOnly || !fullImageURL) {
+ return;
+ }
+ const image = imageRef.current;
+ if (!image?.complete) {
+ return;
+ }
+ if (image.naturalWidth > 0 && image.naturalHeight > 0) {
+ onAspectRatioRef.current?.(image.naturalWidth, image.naturalHeight);
+ }
+ }, [fullImageURL, thumbnailOnly]);
+
+ const displayURL = fullImageURL ?? thumbnailURL;
+ const mediaStyle = buildMediaStyle({
+ cropRect,
+ cropContainerAspectRatio,
+ fillFrame,
+ mediaAspectRatio,
+ objectFit,
+ });
+
+ return (
+ <Box
+ sx={{
+ position: "relative",
+ display: fillFrame ? "block" : "inline-block",
+ width: fillFrame ? "100%" : "auto",
+ height: fillFrame ? "100%" : "auto",
+ overflow: "hidden",
+ }}
+ >
+ {isLoading && showLoadingOverlay && <MediaLoadingOverlay />}
+
+ {displayURL && (
+ <img
+ ref={imageRef}
+ src={displayURL}
+ alt=""
+ draggable={false}
+ onLoad={(event) => {
+ const isFullImageLoad =
+ !thumbnailOnly &&
+ !!fullImageURL &&
+ event.currentTarget.src === fullImageURL;
+ if (isFullImageLoad) {
+ onAspectRatioRef.current?.(
+ event.currentTarget.naturalWidth,
+ event.currentTarget.naturalHeight,
+ );
+ }
+ setIsLoading(false);
+ if (thumbnailOnly || isFullImageLoad) {
+ signalReady();
+ }
+ }}
+ style={mediaStyle}
+ />
+ )}
+ </Box>
+ );
+ }
+
+ export interface VideoPlayerProps {
+ file: EnteFile;
+ onReady?: () => void;
+ onDuration?: (durationSeconds: number) => void;
+ onEnded?: () => void;
+ paused?: boolean;
+ mediaRef?: RefObject<HTMLVideoElement | null>;
+ fillFrame?: boolean;
+ objectFit?: "contain" | "cover";
+ cropRect?: PublicMemoryShareFrameCrop;
+ cropContainerAspectRatio?: number;
+ mediaAspectRatio?: number;
+ onAspectRatio?: (width: number, height: number) => void;
+ showLoadingOverlay?: boolean;
+ }
+
+ export function VideoPlayer({
+ file,
+ onReady,
+ onDuration,
+ onEnded,
+ paused,
+ mediaRef,
+ fillFrame,
+ objectFit = "contain",
+ cropRect,
+ cropContainerAspectRatio,
+ mediaAspectRatio,
+ onAspectRatio,
+ showLoadingOverlay = true,
+ }: VideoPlayerProps) {
+ const [hlsData, setHlsData] = useState<HLSPlaylistData | undefined>(
+ undefined,
+ );
+ const [videoURL, setVideoURL] = useState<string | undefined>(undefined);
+ const [thumbnailURL, setThumbnailURL] = useState<string | undefined>(
+ undefined,
+ );
+ const [isLoading, setIsLoading] = useState(true);
+ const [error, setError] = useState(false);
+ const videoRef = useRef<HTMLVideoElement>(null);
+ const onReadyRef = useRef(onReady);
+ const onDurationRef = useRef(onDuration);
+ const onEndedRef = useRef(onEnded);
+
+ onReadyRef.current = onReady;
+ onDurationRef.current = onDuration;
+ onEndedRef.current = onEnded;
+
+ const setVideoElementRef = useCallback(
+ (node: HTMLVideoElement | null) => {
+ videoRef.current = node;
+ if (mediaRef) {
+ mediaRef.current = node;
+ }
+ },
+ [mediaRef],
+ );
+
+ useEffect(() => {
+ let cancelled = false;
+ setIsLoading(true);
+ setError(false);
+ setVideoURL(undefined);
+ setHlsData(undefined);
+ setThumbnailURL(undefined);
+
+ const load = async () => {
+ try {
+ const nextThumbnailURL =
+ await downloadManager.renderableThumbnailURL(file);
+ if (!cancelled && nextThumbnailURL) {
+ setThumbnailURL(nextThumbnailURL);
+ }
+
+ const nextHlsData =
+ await downloadManager.hlsPlaylistDataForPublicMemory(file);
+ if (
+ !cancelled &&
+ typeof nextHlsData === "object" &&
+ nextHlsData.playlistURL
+ ) {
+ setHlsData(nextHlsData);
+ return;
+ }
+
+ const sourceURLs: RenderableSourceURLs =
+ await downloadManager.renderableSourceURLs(file);
+ if (!cancelled && sourceURLs.type === "video") {
+ setVideoURL(sourceURLs.videoURL);
+ } else if (!cancelled) {
+ setIsLoading(false);
+ }
+ } catch (error) {
+ log.error("Failed to load video", error);
+ if (!cancelled) {
+ setError(true);
+ setIsLoading(false);
+ }
+ }
+ };
+
+ void load();
+
+ return () => {
+ cancelled = true;
+ };
+ }, [file]);
+
+ useEffect(() => {
+ const video = videoRef.current;
+ if (!video || (!videoURL && !hlsData)) {
+ return;
+ }
+
+ if (paused) {
+ video.pause();
+ } else {
+ video.play().catch(() => {
+ // Autoplay may be blocked; ignore.
+ });
+ }
+ }, [hlsData, paused, videoURL]);
+
+ const handleLoadedMetadata = useCallback(() => {
+ const video = videoRef.current;
+ if (video && !Number.isNaN(video.duration) && video.duration > 0) {
+ onAspectRatio?.(video.videoWidth, video.videoHeight);
+ onDurationRef.current?.(video.duration);
+ }
+ }, [onAspectRatio]);
+
+ const handleCanPlay = useCallback(() => {
+ setIsLoading(false);
+ onReadyRef.current?.();
+ const video = videoRef.current;
+ if (video && !paused) {
+ video.play().catch(() => {
+ // Autoplay may be blocked.
+ });
+ }
+ }, [paused]);
+
+ const handleEnded = useCallback(() => {
+ onEndedRef.current?.();
+ }, []);
+
+ const mediaStyle = buildMediaStyle({
+ cropRect,
+ cropContainerAspectRatio,
+ fillFrame,
+ mediaAspectRatio,
+ objectFit,
+ });
+
+ if (error) {
+ return (
+ <Box
+ sx={{
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ width: "100%",
+ height: "100%",
+ }}
+ >
+ <Typography sx={{ color: "rgba(255,255,255,0.7)" }}>
+ Unable to play video
+ </Typography>
+ </Box>
+ );
+ }
+
+ return (
+ <Box
+ sx={{
+ position: "relative",
+ display: fillFrame ? "block" : "inline-block",
+ width: fillFrame ? "100%" : "auto",
+ height: fillFrame ? "100%" : "auto",
+ overflow: "hidden",
+ }}
+ >
+ {isLoading && showLoadingOverlay && <MediaLoadingOverlay />}
+
+ {hlsData && (
+ <hls-video
+ ref={setVideoElementRef}
+ src={hlsData.playlistURL}
+ poster={thumbnailURL}
+ playsInline
+ onLoadedMetadata={handleLoadedMetadata}
+ onCanPlay={handleCanPlay}
+ onEnded={handleEnded}
+ style={mediaStyle}
+ />
+ )}
+
+ {!hlsData && videoURL && (
+ <video
+ ref={setVideoElementRef}
+ src={videoURL}
+ poster={thumbnailURL}
+ playsInline
+ muted={false}
+ onLoadedMetadata={handleLoadedMetadata}
+ onCanPlay={handleCanPlay}
+ onEnded={handleEnded}
+ style={mediaStyle}
+ />
+ )}
+
+ {!videoURL && !hlsData && thumbnailURL && (
+ <img src={thumbnailURL} alt="" style={mediaStyle} />
+ )}
+ </Box>
+ );
+ }
diff --cc web/apps/memories/src/components/PublicMemoryViewerShared.tsx
index 0000000000,93ea8f7b36..2a83582a21
mode 000000,100644..100644
--- a/web/apps/memories/src/components/PublicMemoryViewerShared.tsx
+++ b/web/apps/memories/src/components/PublicMemoryViewerShared.tsx
@@@ -1,0 -1,2295 +1,2295 @@@
+ import { keyframes } from "@emotion/react";
+ import { Box, Typography, styled } from "@mui/material";
+ import { downloadManager } from "ente-gallery/services/download";
+ import type { EnteFile } from "ente-media/file";
+ import { fileCreationPhotoDate } from "ente-media/file-metadata";
+ import { FileType } from "ente-media/file-type";
+ import {
+ type PublicMemoryShareFrame,
+ type PublicMemoryShareMetadata,
-} from "ente-new/albums/services/public-memory";
++} from "../services/public-memory";
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+ import {
+ buildLaneCaptionModel,
+ buildLaneTitle,
+ calculateLaneBlur,
+ calculateLaneOpacity,
+ calculateLaneOverlayOpacity,
+ calculateLaneRotation,
+ calculateLaneScale,
+ calculateLaneYOffset,
+ easeInOutCubic,
+ formatLaneCaption,
+ getFileAspectRatio,
+ getFrameCreationDate,
+ getLaneStackSlices,
+ laneCardShadow,
+ lerp,
+ resolveLaneCropRect,
+ } from "../utils/lane";
+ import {
+ LaneCaptionText,
+ LanePlaybackGlyph,
+ LaneProgressSlider,
+ PlaybackGlyph,
+ ProgressIndicator,
+ } from "./PublicMemoryControls";
+ import { PhotoImage, VideoPlayer } from "./PublicMemoryMedia";
+
+ interface MemoryViewerProps {
+ files: EnteFile[];
+ currentIndex: number;
+ memoryName: string;
+ memoryMetadata?: PublicMemoryShareMetadata;
+ laneFrames?: (PublicMemoryShareFrame | undefined)[];
+ variant: "share" | "lane";
+ onNext: () => void;
+ onPrev: () => void;
+ onSeek: (index: number) => void;
+ }
+
+ const IMAGE_AUTO_PROGRESS_DURATION_MS = 5000;
+ const LANE_FRAME_INTERVAL_MS = 800;
+ const LANE_CARD_TRANSITION_DURATION_MS = 520;
+ const MOBILE_LAYOUT_BREAKPOINT_PX = 600;
+ const SHARE_FOOTER_ACTIONS_BREAKPOINT_PX = 960;
+ const LANE_COMPACT_LAYOUT_BREAKPOINT_PX = 900;
+ const EDGE_NAV_TAP_ZONE_RATIO = 0.2;
+ const HOLD_TO_PAUSE_NAV_SUPPRESSION_MS = 250;
+ const MOBILE_MEDIA_RESERVED_VERTICAL_SPACE_PX = 280;
+ const LANE_MOBILE_MEDIA_RESERVED_VERTICAL_SPACE_PX = 340;
+ const DESKTOP_MEDIA_MAX_WIDTH_PX = 1264;
+ const DESKTOP_MEDIA_HORIZONTAL_PADDING_PX = 48;
+ const DESKTOP_MEDIA_VERTICAL_RESERVED_PX = 220;
+ const DESKTOP_LANE_MEDIA_VERTICAL_RESERVED_PX = 320;
+ const LANE_CARD_ASPECT_RATIO = 0.68;
+ const LANE_MOBILE_CARD_MAX_WIDTH_PX = 326;
+ const LANE_MOBILE_CARD_MIN_WIDTH_PX = 220;
+ const LANE_DESKTOP_CARD_MAX_WIDTH_PX = 420;
+ const LANE_DESKTOP_CARD_MIN_WIDTH_PX = 280;
+ const MEDIA_SWITCH_TRANSITION_DURATION_MS = 380;
+ const DESKTOP_MEDIA_MAX_WIDTH_CSS = `min(${DESKTOP_MEDIA_MAX_WIDTH_PX}px, calc(100vw - ${DESKTOP_MEDIA_HORIZONTAL_PADDING_PX}px))`;
+ const DESKTOP_MEDIA_MAX_HEIGHT_CSS = `calc(min(100vh, 100dvh) - ${DESKTOP_MEDIA_VERTICAL_RESERVED_PX}px)`;
+ const DESKTOP_BACKGROUND_IMAGE_PATH = "/images/memory-lane-bg-desktop.svg";
+ const MOBILE_BACKGROUND_IMAGE_PATH = "/images/memory-lane-bg-mobile.svg";
+ const ENTE_BRAND_TAG_IMAGE_PATH = "/images/ente-brand-tag.svg";
+ const LANE_GRID_CELL_SIZE_PX = 80;
+ const LANE_GRID_LINE_COLOR = "#08c225";
+ const LANE_GRID_LINE_OPACITY = 0.06;
+ const LANE_GRID_DISPLACEMENT_SCALE = 9;
+
+ interface LaneMemoryViewerProps {
+ files: EnteFile[];
+ currentIndex: number;
+ memoryName: string;
+ memoryMetadata?: PublicMemoryShareMetadata;
+ laneFrames?: (PublicMemoryShareFrame | undefined)[];
+ onNext: () => void;
+ onPrev: () => void;
+ onSeek: (index: number) => void;
+ }
+
+ export const LaneMemoryViewer: React.FC<LaneMemoryViewerProps> = ({
+ files,
+ currentIndex,
+ memoryName,
+ memoryMetadata,
+ laneFrames,
+ onNext,
+ onPrev,
+ onSeek,
+ }) => {
+ const [paused, setPaused] = useState(false);
+ const [fileLoaded, setFileLoaded] = useState(false);
+ const [videoDurationKnown, setVideoDurationKnown] = useState(false);
+ const [viewport, setViewport] = useState({ width: 1280, height: 720 });
+ const [stackProgress, setStackProgress] = useState(currentIndex);
+ const [displayIndex, setDisplayIndex] = useState(currentIndex);
+ const [isScrubbing, setIsScrubbing] = useState(false);
+ const [isAnimatingStack, setIsAnimatingStack] = useState(false);
+ const [activeMediaAspectRatio, setActiveMediaAspectRatio] = useState<
+ number | undefined
+ >(undefined);
+ const [previousCaptionValue, setPreviousCaptionValue] = useState<
+ number | undefined
+ >(() => {
+ const initialModel = buildLaneCaptionModel({
+ frame: laneFrames?.[currentIndex],
+ metadata: memoryMetadata,
+ fallbackLabel: memoryName || "Memory lane",
+ });
+ return initialModel.value;
+ });
+ const pressStartedAtRef = useRef<number | null>(null);
+ const suppressTapNavigationRef = useRef(false);
+ const shouldResumeAfterHoldRef = useRef(false);
+ const finishedLanePlaybackRef = useRef(false);
+ const restartOnResumeRef = useRef(false);
+ const animationFrameRef = useRef<number | null>(null);
+ const animationStartTimestampRef = useRef<number | null>(null);
+ const stackProgressRef = useRef(currentIndex);
+ const displayIndexRef = useRef(currentIndex);
+ const currentIndexRef = useRef(currentIndex);
+ const pausedRef = useRef(paused);
+ const isVideoRef = useRef(false);
+ const isAnimatingStackRef = useRef(false);
+ const isScrubbingRef = useRef(false);
+ const fileLoadedRef = useRef(false);
+ const videoDurationKnownRef = useRef(false);
+ const onNextRef = useRef(onNext);
+ const laneAdvanceTimeoutRef = useRef<number | null>(null);
+ const activeVideoElementRef = useRef<HTMLVideoElement | null>(null);
+
+ const currentFile = files[displayIndex]!;
+ const currentLaneFrame = laneFrames?.[displayIndex];
+ const isVideo = currentFile.metadata.fileType === FileType.video;
+ const isMobileLayout = viewport.width <= MOBILE_LAYOUT_BREAKPOINT_PX;
+ const isCompactLaneLayout =
+ viewport.width <= LANE_COMPACT_LAYOUT_BREAKPOINT_PX;
+
+ onNextRef.current = onNext;
+ currentIndexRef.current = currentIndex;
+ pausedRef.current = paused;
+ stackProgressRef.current = stackProgress;
+ displayIndexRef.current = displayIndex;
+ isVideoRef.current = currentFile.metadata.fileType === FileType.video;
+ isAnimatingStackRef.current = isAnimatingStack;
+ isScrubbingRef.current = isScrubbing;
+ fileLoadedRef.current = fileLoaded;
+ videoDurationKnownRef.current = videoDurationKnown;
+ const laneCaptionModel = buildLaneCaptionModel({
+ frame: currentLaneFrame,
+ metadata: memoryMetadata,
+ fallbackLabel: memoryName || "Memory lane",
+ });
+
+ const cancelStackAnimation = useCallback(() => {
+ if (animationFrameRef.current !== null) {
+ window.cancelAnimationFrame(animationFrameRef.current);
+ animationFrameRef.current = null;
+ }
+ animationStartTimestampRef.current = null;
+ setIsAnimatingStack(false);
+ }, []);
+
+ const clearLaneAdvanceTimeout = useCallback(() => {
+ if (laneAdvanceTimeoutRef.current !== null) {
+ window.clearTimeout(laneAdvanceTimeoutRef.current);
+ laneAdvanceTimeoutRef.current = null;
+ }
+ }, []);
+
+ const scheduleLaneAdvance = useCallback(() => {
+ clearLaneAdvanceTimeout();
+ if (files.length <= 1 || pausedRef.current || isVideoRef.current) {
+ return;
+ }
+ if (isScrubbingRef.current || isAnimatingStackRef.current) {
+ return;
+ }
+ if (!fileLoadedRef.current) {
+ return;
+ }
+ if (currentIndexRef.current >= files.length - 1) {
+ return;
+ }
+
+ laneAdvanceTimeoutRef.current = window.setTimeout(() => {
+ laneAdvanceTimeoutRef.current = null;
+ onNextRef.current();
+ }, LANE_FRAME_INTERVAL_MS);
+ }, [clearLaneAdvanceTimeout, files.length]);
+
+ const commitDisplayIndex = useCallback(
+ (nextIndex: number) => {
+ const previousModel = buildLaneCaptionModel({
+ frame: laneFrames?.[displayIndexRef.current],
+ metadata: memoryMetadata,
+ fallbackLabel: memoryName || "Memory lane",
+ });
+ const nextModel = buildLaneCaptionModel({
+ frame: laneFrames?.[nextIndex],
+ metadata: memoryMetadata,
+ fallbackLabel: memoryName || "Memory lane",
+ });
+ setPreviousCaptionValue(previousModel.value ?? nextModel.value);
+ setFileLoaded(false);
+ setVideoDurationKnown(false);
+ setActiveMediaAspectRatio(undefined);
+ setDisplayIndex(nextIndex);
+ },
+ [laneFrames, memoryMetadata, memoryName],
+ );
+
+ useEffect(
+ () => () => {
+ cancelStackAnimation();
+ clearLaneAdvanceTimeout();
+ },
+ [cancelStackAnimation, clearLaneAdvanceTimeout],
+ );
+
+ useEffect(() => {
+ const updateViewport = () =>
+ setViewport({
+ width: window.innerWidth,
+ height: window.innerHeight,
+ });
+
+ updateViewport();
+ window.addEventListener("resize", updateViewport);
+ return () => window.removeEventListener("resize", updateViewport);
+ }, []);
+
+ useEffect(() => {
+ if (isScrubbing) {
+ return;
+ }
+
+ finishedLanePlaybackRef.current = false;
+
+ const targetIndex = Math.min(
+ Math.max(currentIndex, 0),
+ files.length - 1,
+ );
+ const startProgress = stackProgressRef.current;
+ cancelStackAnimation();
+
+ if (Math.abs(targetIndex - startProgress) < 0.0001) {
+ setStackProgress(targetIndex);
+ if (displayIndexRef.current !== targetIndex) {
+ commitDisplayIndex(targetIndex);
+ }
+ return;
+ }
+
+ const duration =
+ LANE_CARD_TRANSITION_DURATION_MS *
+ Math.min(Math.max(Math.abs(targetIndex - startProgress), 1), 4);
+ setIsAnimatingStack(true);
+
+ const tick = (timestamp: number) => {
+ if (animationStartTimestampRef.current === null) {
+ animationStartTimestampRef.current = timestamp;
+ }
+ const elapsed = timestamp - animationStartTimestampRef.current;
+ const progress = Math.min(elapsed / duration, 1);
+ const eased = easeInOutCubic(progress);
+ setStackProgress(lerp(startProgress, targetIndex, eased));
+
+ if (progress < 1) {
+ animationFrameRef.current = window.requestAnimationFrame(tick);
+ return;
+ }
+
+ animationFrameRef.current = null;
+ animationStartTimestampRef.current = null;
+ setIsAnimatingStack(false);
+ setStackProgress(targetIndex);
+ if (displayIndexRef.current !== targetIndex) {
+ commitDisplayIndex(targetIndex);
+ }
+ };
+
+ animationFrameRef.current = window.requestAnimationFrame(tick);
+ }, [
+ cancelStackAnimation,
+ commitDisplayIndex,
+ currentIndex,
+ files.length,
+ isScrubbing,
+ ]);
+
+ useEffect(() => {
+ if (paused) {
+ clearLaneAdvanceTimeout();
+ activeVideoElementRef.current?.pause();
+ return;
+ }
+
+ if (restartOnResumeRef.current) {
+ restartOnResumeRef.current = false;
+ if (currentIndexRef.current > 0) {
+ onSeek(0);
+ return;
+ }
+
+ const activeVideo = activeVideoElementRef.current;
+ if (activeVideo) {
+ activeVideo.currentTime = 0;
+ }
+ }
+
+ if (isAnimatingStack || isScrubbing || !fileLoaded) {
+ return;
+ }
+
+ if (isVideo) {
+ const activeVideo = activeVideoElementRef.current;
+ if (activeVideo) {
+ void activeVideo.play().catch(() => {
+ // Browser playback policies may still reject here.
+ });
+ }
+ return;
+ }
+
+ if (currentIndex >= files.length - 1) {
+ clearLaneAdvanceTimeout();
+ laneAdvanceTimeoutRef.current = window.setTimeout(() => {
+ laneAdvanceTimeoutRef.current = null;
+ finishedLanePlaybackRef.current = true;
+ setPaused(true);
+ }, LANE_FRAME_INTERVAL_MS);
+ return clearLaneAdvanceTimeout;
+ }
+
+ scheduleLaneAdvance();
+ return clearLaneAdvanceTimeout;
+ }, [
+ clearLaneAdvanceTimeout,
+ currentIndex,
+ fileLoaded,
+ files.length,
+ isAnimatingStack,
+ isScrubbing,
+ isVideo,
+ onSeek,
+ paused,
+ scheduleLaneAdvance,
+ videoDurationKnown,
+ ]);
+
+ const handleFullLoad = useCallback(() => {
+ setFileLoaded(true);
+ }, []);
+
+ const handleVideoDuration = useCallback((durationSeconds: number) => {
+ void durationSeconds;
+ setVideoDurationKnown(true);
+ }, []);
+
+ const handleActiveAspectRatio = useCallback(
+ (width: number, height: number) => {
+ if (width <= 0 || height <= 0) {
+ return;
+ }
+ setActiveMediaAspectRatio(width / height);
+ },
+ [],
+ );
+
+ const handlePlaybackToggle = useCallback(
+ (event: React.MouseEvent<HTMLButtonElement>) => {
+ event.stopPropagation();
+ setPaused((previous) => {
+ const nextPaused = !previous;
+ restartOnResumeRef.current =
+ !nextPaused && finishedLanePlaybackRef.current;
+ if (!nextPaused) {
+ finishedLanePlaybackRef.current = false;
+ }
+ return nextPaused;
+ });
+ },
+ [],
+ );
+
+ const handleVideoEnded = useCallback(() => {
+ if (currentIndexRef.current >= files.length - 1) {
+ finishedLanePlaybackRef.current = true;
+ setPaused(true);
+ return;
+ }
+ onNext();
+ }, [files.length, onNext]);
+
+ const handleScreenTap = useCallback(
+ (event: React.MouseEvent<HTMLDivElement>) => {
+ if (suppressTapNavigationRef.current) {
+ suppressTapNavigationRef.current = false;
+ return;
+ }
+ if (isInteractiveTapTarget(event.target)) {
+ return;
+ }
+ if (isAnimatingStackRef.current || isScrubbingRef.current) {
+ return;
+ }
+
+ const clickX = event.clientX;
+ if (clickX <= viewport.width * EDGE_NAV_TAP_ZONE_RATIO) {
+ onPrev();
+ } else if (
+ clickX >=
+ viewport.width * (1 - EDGE_NAV_TAP_ZONE_RATIO)
+ ) {
+ onNext();
+ }
+ },
+ [onNext, onPrev, viewport.width],
+ );
+
+ const laneFrameSize = useMemo(() => {
+ const availableWidth = Math.max(
+ isCompactLaneLayout
+ ? LANE_MOBILE_CARD_MIN_WIDTH_PX
+ : LANE_DESKTOP_CARD_MIN_WIDTH_PX,
+ viewport.width - (isCompactLaneLayout ? 56 : 96),
+ );
+ const availableHeight = Math.max(
+ 200,
+ viewport.height -
+ (isCompactLaneLayout
+ ? LANE_MOBILE_MEDIA_RESERVED_VERTICAL_SPACE_PX - 24
+ : DESKTOP_LANE_MEDIA_VERTICAL_RESERVED_PX),
+ );
+ const preferredWidth = isCompactLaneLayout
+ ? Math.min(LANE_MOBILE_CARD_MAX_WIDTH_PX + 28, availableWidth)
+ : Math.min(
+ LANE_DESKTOP_CARD_MAX_WIDTH_PX,
+ Math.max(
+ LANE_DESKTOP_CARD_MIN_WIDTH_PX,
+ availableWidth * 0.34,
+ ),
+ );
+
+ let width = preferredWidth;
+ let height = width / LANE_CARD_ASPECT_RATIO;
+
+ if (height > availableHeight) {
+ height = availableHeight;
+ width = height * LANE_CARD_ASPECT_RATIO;
+ }
+
+ return { width: Math.round(width), height: Math.round(height) };
+ }, [isCompactLaneLayout, viewport.height, viewport.width]);
+
+ const laneTitle = useMemo(() => {
+ return buildLaneTitle({
+ memoryName,
+ personName: memoryMetadata?.personName,
+ });
+ }, [memoryMetadata?.personName, memoryName]);
+
+ const laneSlices = useMemo(
+ () => getLaneStackSlices(files.length, stackProgress),
+ [files.length, stackProgress],
+ );
+
+ const trackScrubValue = useCallback(
+ (value: number) => {
+ if (files.length <= 1) {
+ return 0;
+ }
+ return Math.min(Math.max(value, 0), files.length - 1);
+ },
+ [files.length],
+ );
+
+ const handleScrubStart = useCallback(() => {
+ setPaused(true);
+ setIsScrubbing(true);
+ cancelStackAnimation();
+ }, [cancelStackAnimation]);
+
+ const handleScrub = useCallback(
+ (value: number) => {
+ const clampedValue = trackScrubValue(value);
+ const roundedIndex = Math.min(
+ Math.max(Math.round(clampedValue), 0),
+ files.length - 1,
+ );
+ setStackProgress(clampedValue);
+ if (displayIndexRef.current !== roundedIndex) {
+ commitDisplayIndex(roundedIndex);
+ }
+ onSeek(roundedIndex);
+ },
+ [commitDisplayIndex, files.length, onSeek, trackScrubValue],
+ );
+
+ const handleScrubEnd = useCallback(
+ (value: number) => {
+ const clampedValue = trackScrubValue(value);
+ const roundedIndex = Math.min(
+ Math.max(Math.round(clampedValue), 0),
+ files.length - 1,
+ );
+ setIsScrubbing(false);
+ setStackProgress(roundedIndex);
+ if (displayIndexRef.current !== roundedIndex) {
+ commitDisplayIndex(roundedIndex);
+ }
+ onSeek(roundedIndex);
+ },
+ [commitDisplayIndex, files.length, onSeek, trackScrubValue],
+ );
+
+ return (
+ <ViewerRoot onClick={handleScreenTap}>
+ <LaneBackground isMobileLayout={isCompactLaneLayout} />
+ <LaneContentContainer
+ style={
+ isCompactLaneLayout
+ ? {
+ maxWidth: isMobileLayout ? "375px" : "440px",
+ padding: isMobileLayout
+ ? "24px 24px 26px"
+ : "32px 28px 30px",
+ gap: isMobileLayout ? "16px" : "20px",
+ }
+ : undefined
+ }
+ >
+ {isCompactLaneLayout ? (
+ <LaneMobileHeaderSection>
+ <LaneMobileTitle variant="h6">
+ {laneTitle}
+ </LaneMobileTitle>
+ </LaneMobileHeaderSection>
+ ) : (
+ <LaneTopBar>
+ <LaneDesktopTitle variant="h6">
+ {laneTitle}
+ </LaneDesktopTitle>
+ <LaneTopBrandSection>
+ <LaneSharedUsingLabel>
+ Shared using
+ </LaneSharedUsingLabel>
+ <BrandLink
+ href="https://ente.io"
+ target="_blank"
+ rel="noreferrer"
+ data-memory-control="true"
+ >
+ <EnteBrandTagImage
+ src={ENTE_BRAND_TAG_IMAGE_PATH}
+ alt="Ente Photos"
+ />
+ </BrandLink>
+ </LaneTopBrandSection>
+ </LaneTopBar>
+ )}
+
+ <LaneCenterSection>
+ <PhotoContainer
+ style={{ flex: "0 0 auto", minHeight: "auto" }}
+ onContextMenu={(event) => event.preventDefault()}
+ onDragStart={(event) => event.preventDefault()}
+ onPointerDown={
+ isCompactLaneLayout
+ ? () => {
+ pressStartedAtRef.current = Date.now();
+ suppressTapNavigationRef.current = false;
+ shouldResumeAfterHoldRef.current =
+ !paused;
+ setPaused(true);
+ }
+ : undefined
+ }
+ onPointerUp={
+ isCompactLaneLayout
+ ? () => {
+ const startedAt =
+ pressStartedAtRef.current;
+ pressStartedAtRef.current = null;
+ if (
+ startedAt &&
+ Date.now() - startedAt >
+ HOLD_TO_PAUSE_NAV_SUPPRESSION_MS
+ ) {
+ suppressTapNavigationRef.current = true;
+ }
+ if (shouldResumeAfterHoldRef.current) {
+ setPaused(false);
+ }
+ shouldResumeAfterHoldRef.current = false;
+ }
+ : undefined
+ }
+ onPointerCancel={
+ isCompactLaneLayout
+ ? () => {
+ pressStartedAtRef.current = null;
+ if (shouldResumeAfterHoldRef.current) {
+ setPaused(false);
+ }
+ shouldResumeAfterHoldRef.current = false;
+ }
+ : undefined
+ }
+ onPointerLeave={
+ isCompactLaneLayout
+ ? () => {
+ if (pressStartedAtRef.current !== null) {
+ pressStartedAtRef.current = null;
+ if (
+ shouldResumeAfterHoldRef.current
+ ) {
+ setPaused(false);
+ }
+ shouldResumeAfterHoldRef.current = false;
+ }
+ }
+ : undefined
+ }
+ >
+ <LaneCardStack
+ style={{
+ width: `${laneFrameSize.width}px`,
+ height: `${laneFrameSize.height}px`,
+ }}
+ >
+ {laneSlices.map((slice) => {
+ const file = files[slice.index]!;
+ const frame = laneFrames?.[slice.index];
+ const scale = calculateLaneScale(
+ slice.distance,
+ );
+ const yOffset = calculateLaneYOffset(
+ slice.distance,
+ laneFrameSize.height,
+ );
+ const opacity = calculateLaneOpacity(
+ slice.distance,
+ );
+ const blurSigma = isScrubbing
+ ? 0
+ : calculateLaneBlur(slice.distance);
+ const rotation =
+ (calculateLaneRotation(slice.distance) *
+ 180) /
+ Math.PI;
+ const overlayOpacity =
+ calculateLaneOverlayOpacity(slice.distance);
+ const cropRect = resolveLaneCropRect(frame);
+ const containerAspectRatio =
+ laneFrameSize.width / laneFrameSize.height;
+ const isDisplayCard =
+ slice.index === displayIndex;
+ const prefersRichImage =
+ file.metadata.fileType === FileType.video
+ ? isDisplayCard
+ : Math.abs(slice.distance) < 1.1;
+ const mediaAspectRatio = isDisplayCard
+ ? (activeMediaAspectRatio ??
+ getFileAspectRatio(file))
+ : getFileAspectRatio(file);
+
+ return (
+ <LaneStackSlice
+ key={`lane-slice-${slice.index}`}
+ style={{
+ opacity,
+ transform: `translateY(${yOffset}px) rotate(${rotation}deg) scale(${scale})`,
+ }}
+ >
+ <LaneCardSurface
+ style={{
+ boxShadow: laneCardShadow(
+ slice.distance,
+ ),
+ }}
+ >
+ <LaneCardMediaLayer
+ style={{
+ filter:
+ blurSigma > 0
+ ? `blur(${blurSigma}px)`
+ : undefined,
+ }}
+ >
+ {file.metadata.fileType ===
+ FileType.video &&
+ isDisplayCard ? (
+ <VideoPlayer
+ file={file}
+ paused={paused}
+ mediaRef={
+ activeVideoElementRef
+ }
+ fillFrame
+ objectFit="cover"
+ cropRect={cropRect}
+ cropContainerAspectRatio={
+ containerAspectRatio
+ }
+ mediaAspectRatio={
+ mediaAspectRatio
+ }
+ onReady={handleFullLoad}
+ onDuration={
+ handleVideoDuration
+ }
+ onEnded={
+ handleVideoEnded
+ }
+ onAspectRatio={
+ handleActiveAspectRatio
+ }
+ />
+ ) : (
+ <PhotoImage
+ file={file}
+ fillFrame
+ objectFit="cover"
+ cropRect={cropRect}
+ cropContainerAspectRatio={
+ containerAspectRatio
+ }
+ mediaAspectRatio={
+ mediaAspectRatio
+ }
+ onFullLoad={
+ isDisplayCard
+ ? handleFullLoad
+ : undefined
+ }
+ onAspectRatio={
+ isDisplayCard
+ ? handleActiveAspectRatio
+ : undefined
+ }
+ showLoadingOverlay={
+ isDisplayCard
+ }
+ thumbnailOnly={
+ !prefersRichImage
+ }
+ />
+ )}
+ </LaneCardMediaLayer>
+ {overlayOpacity > 0 && (
+ <LaneCardOverlayLayer
+ style={{
+ opacity: overlayOpacity,
+ }}
+ />
+ )}
+ </LaneCardSurface>
+ </LaneStackSlice>
+ );
+ })}
+ </LaneCardStack>
+ </PhotoContainer>
+
+ <LaneBottomSection>
+ <LaneCaptionRow>
+ <LanePlaybackButton
+ type="button"
+ data-memory-control="true"
+ onClick={handlePlaybackToggle}
+ >
+ <LanePlaybackGlyph paused={paused} />
+ </LanePlaybackButton>
+ <LaneCaption>
+ <LaneCaptionText
+ model={laneCaptionModel}
+ previousValue={previousCaptionValue}
+ />
+ </LaneCaption>
+ </LaneCaptionRow>
+ <LaneProgressSlider
+ total={files.length}
+ currentProgress={stackProgress}
+ onSeek={onSeek}
+ onScrubStart={handleScrubStart}
+ onScrub={handleScrub}
+ onScrubEnd={handleScrubEnd}
+ />
+ </LaneBottomSection>
+ </LaneCenterSection>
+ <LaneFooter>
+ {isMobileLayout ? (
+ <LaneMobileFooterBar>
+ <BrandLink
+ href="https://ente.io"
+ target="_blank"
+ rel="noreferrer"
+ data-memory-control="true"
+ >
+ <EnteBrandTagImage
+ src={ENTE_BRAND_TAG_IMAGE_PATH}
+ alt="Ente Photos"
+ />
+ </BrandLink>
+ <MobileJoinNowButton
+ href="https://ente.io"
+ target="_blank"
+ rel="noreferrer"
+ >
+ Join now
+ </MobileJoinNowButton>
+ </LaneMobileFooterBar>
+ ) : (
+ <JoinNowButton
+ href="https://ente.io"
+ target="_blank"
+ rel="noreferrer"
+ >
+ Join now
+ </JoinNowButton>
+ )}
+ </LaneFooter>
+ </LaneContentContainer>
+ </ViewerRoot>
+ );
+ };
+
+ const isInteractiveTapTarget = (target: EventTarget | null) => {
+ if (!(target instanceof Element)) return false;
+ return Boolean(
+ target.closest(
+ "button, a, input, textarea, select, [role='button'], [data-memory-control='true']",
+ ),
+ );
+ };
+
+ const mediaSwitchInAnimation = keyframes`
+ from {
+ opacity: 0;
+ transform: translateY(4px) scale(0.996);
+ }
+ to {
+ opacity: 1;
+ transform: translateY(0) scale(1);
+ }
+ `;
+
+ const mediaSwitchOutAnimation = keyframes`
+ from {
+ opacity: 1;
+ transform: translateY(0) scale(1);
+ }
+ to {
+ opacity: 0;
+ transform: translateY(-2px) scale(1.005);
+ }
+ `;
+
+ const laneBackCardPrimaryEnterAnimation = keyframes`
+ from {
+ opacity: 0;
+ transform: translate(26px, -26px) rotate(6.4deg);
+ }
+ to {
+ opacity: 1;
+ transform: translate(14px, -16px) rotate(3.1deg);
+ }
+ `;
+
+ const laneBackCardSecondaryEnterAnimation = keyframes`
+ from {
+ opacity: 0;
+ transform: translate(16px, -14px) rotate(-4.2deg);
+ }
+ to {
+ opacity: 1;
+ transform: translate(6px, -8px) rotate(-1.3deg);
+ }
+ `;
+
+ const laneMediaSwitchInAnimation = keyframes`
+ from {
+ opacity: 0;
+ transform: translateY(-22px) scale(0.97);
+ }
+ to {
+ opacity: 1;
+ transform: translateY(0) scale(1);
+ }
+ `;
+
+ const laneMediaSwitchOutAnimation = keyframes`
+ from {
+ opacity: 1;
+ transform: translateY(0) scale(1);
+ }
+ to {
+ opacity: 0;
+ transform: translateY(76px) scale(1.02);
+ }
+ `;
+
+ export const MemoryViewer: React.FC<MemoryViewerProps> = ({
+ files,
+ currentIndex,
+ memoryName,
+ memoryMetadata,
+ laneFrames,
+ variant,
+ onNext,
+ onPrev,
+ onSeek,
+ }) => {
+ const currentFile = files[currentIndex]!;
+ const currentLaneFrame = laneFrames?.[currentIndex];
+ const [paused, setPaused] = useState(false);
+ const [fileLoaded, setFileLoaded] = useState(false);
+ // For videos, track if duration is known (prevents premature animation start).
+ const [videoDurationKnown, setVideoDurationKnown] = useState(false);
+ // For videos, we track the duration in ms; for images, use the constant.
+ const [progressDuration, setProgressDuration] = useState(
+ IMAGE_AUTO_PROGRESS_DURATION_MS,
+ );
+ const [mediaAspectRatio, setMediaAspectRatio] = useState<number>();
+ const [viewport, setViewport] = useState({ width: 1280, height: 720 });
+ const [outgoingFile, setOutgoingFile] = useState<EnteFile | null>(null);
+ const [outgoingIsVideo, setOutgoingIsVideo] = useState(false);
+ const [outgoingIndex, setOutgoingIndex] = useState<number | null>(null);
+ const pressStartedAtRef = useRef<number | null>(null);
+ const suppressTapNavigationRef = useRef(false);
+ const previousFileRef = useRef(currentFile);
+ const previousIndexRef = useRef(currentIndex);
+ const outgoingClearTimeoutRef = useRef<number | null>(null);
+
+ const isVideo = currentFile.metadata.fileType === FileType.video;
+ const isMobileLayout = viewport.width <= MOBILE_LAYOUT_BREAKPOINT_PX;
+ const useFooterShareActions =
+ viewport.width <= SHARE_FOOTER_ACTIONS_BREAKPOINT_PX;
+ const isCompactLaneLayout =
+ viewport.width <= LANE_COMPACT_LAYOUT_BREAKPOINT_PX;
+
+ // Reset loaded state and duration when file changes.
+ useEffect(() => {
+ setPaused(false);
+ setFileLoaded(false);
+ setVideoDurationKnown(false);
+ setMediaAspectRatio(undefined);
+ // Reset to image duration; video will update this when it loads.
+ setProgressDuration(
+ variant === "lane"
+ ? LANE_FRAME_INTERVAL_MS
+ : IMAGE_AUTO_PROGRESS_DURATION_MS,
+ );
+ }, [currentIndex, variant]);
+
+ useEffect(() => {
+ const previousIndex = previousIndexRef.current;
+ const previousFile = previousFileRef.current;
+ if (previousIndex !== currentIndex) {
+ setOutgoingFile(previousFile);
+ setOutgoingIsVideo(
+ previousFile.metadata.fileType === FileType.video,
+ );
+ setOutgoingIndex(previousIndex);
+
+ if (outgoingClearTimeoutRef.current !== null) {
+ window.clearTimeout(outgoingClearTimeoutRef.current);
+ }
+ outgoingClearTimeoutRef.current = window.setTimeout(() => {
+ setOutgoingFile(null);
+ setOutgoingIndex(null);
+ outgoingClearTimeoutRef.current = null;
+ }, MEDIA_SWITCH_TRANSITION_DURATION_MS);
+ }
+
+ previousIndexRef.current = currentIndex;
+ previousFileRef.current = currentFile;
+ }, [currentFile, currentIndex]);
+
+ useEffect(
+ () => () => {
+ if (outgoingClearTimeoutRef.current !== null) {
+ window.clearTimeout(outgoingClearTimeoutRef.current);
+ }
+ },
+ [],
+ );
+
+ const handleFullLoad = useCallback(() => {
+ setFileLoaded(true);
+ }, []);
+
+ const handleVideoDuration = useCallback((durationSeconds: number) => {
+ // Convert seconds to milliseconds for the progress bar.
+ setProgressDuration(durationSeconds * 1000);
+ setVideoDurationKnown(true);
+ }, []);
+
+ const handleMediaAspectRatio = useCallback(
+ (width: number, height: number) => {
+ if (width <= 0 || height <= 0) return;
+ setMediaAspectRatio(width / height);
+ },
+ [],
+ );
+
+ // Preload next file's thumbnail for smoother navigation.
+ useEffect(() => {
+ if (currentIndex < files.length - 1) {
+ const nextFile = files[currentIndex + 1]!;
+ void downloadManager.renderableThumbnailURL(nextFile);
+ }
+ }, [currentIndex, files]);
+
+ useEffect(() => {
+ const updateViewport = () =>
+ setViewport({
+ width: window.innerWidth,
+ height: window.innerHeight,
+ });
+
+ updateViewport();
+ window.addEventListener("resize", updateViewport);
+ return () => window.removeEventListener("resize", updateViewport);
+ }, []);
+
+ const currentFileDate = useMemo(() => {
+ const frameDate = getFrameCreationDate(currentLaneFrame);
+ if (frameDate) {
+ return formatMemoryDate(frameDate);
+ }
+ try {
+ return formatMemoryDate(fileCreationPhotoDate(currentFile));
+ } catch {
+ return "";
+ }
+ }, [currentFile, currentLaneFrame]);
+
+ const headerTitle = useMemo(() => {
+ if (memoryName && currentFileDate)
+ return `${memoryName} β€’ ${currentFileDate}`;
+ return memoryName || currentFileDate || "Memory";
+ }, [memoryName, currentFileDate]);
+
+ const handleScreenTap = (e: React.MouseEvent<HTMLDivElement>) => {
+ if (suppressTapNavigationRef.current) {
+ suppressTapNavigationRef.current = false;
+ return;
+ }
+ if (isInteractiveTapTarget(e.target)) return;
+
+ const screenWidth = viewport.width;
+ const clickX = e.clientX;
+ if (clickX <= screenWidth * EDGE_NAV_TAP_ZONE_RATIO) {
+ onPrev();
+ } else if (clickX >= screenWidth * (1 - EDGE_NAV_TAP_ZONE_RATIO)) {
+ onNext();
+ }
+ };
+
+ const resolvedMediaAspectRatio = useMemo(() => {
+ if (typeof mediaAspectRatio === "number" && mediaAspectRatio > 0) {
+ return mediaAspectRatio;
+ }
+
+ const width = currentFile.pubMagicMetadata?.data.w;
+ const height = currentFile.pubMagicMetadata?.data.h;
+ if (
+ typeof width === "number" &&
+ width > 0 &&
+ typeof height === "number" &&
+ height > 0
+ ) {
+ return width / height;
+ }
+
+ return undefined;
+ }, [currentFile, mediaAspectRatio]);
+
+ const mobileFrameSize = useMemo(() => {
+ const availableWidth = Math.max(220, viewport.width - 48);
+ const maxWidth = Math.min(326, availableWidth);
+ const maxHeight = Math.max(
+ 180,
+ viewport.height - MOBILE_MEDIA_RESERVED_VERTICAL_SPACE_PX,
+ );
+ const ratio = resolvedMediaAspectRatio ?? 4 / 3;
+
+ let width = maxWidth;
+ let height = width / ratio;
+
+ if (height > maxHeight) {
+ height = maxHeight;
+ width = height * ratio;
+ }
+
+ return { width: Math.round(width), height: Math.round(height) };
+ }, [resolvedMediaAspectRatio, viewport.height, viewport.width]);
+
+ const desktopFrameSize = useMemo(() => {
+ const availableWidth = Math.max(
+ 360,
+ viewport.width - DESKTOP_MEDIA_HORIZONTAL_PADDING_PX,
+ );
+ const availableHeight = Math.max(
+ 240,
+ viewport.height - DESKTOP_MEDIA_VERTICAL_RESERVED_PX,
+ );
+ const maxWidth = Math.min(DESKTOP_MEDIA_MAX_WIDTH_PX, availableWidth);
+ const ratio =
+ typeof resolvedMediaAspectRatio === "number"
+ ? resolvedMediaAspectRatio
+ : 4 / 3;
+
+ let width = maxWidth;
+ let height = width / ratio;
+
+ if (height > availableHeight) {
+ height = availableHeight;
+ width = height * ratio;
+ }
+
+ return { width: Math.round(width), height: Math.round(height) };
+ }, [resolvedMediaAspectRatio, viewport.height, viewport.width]);
+
+ const laneFrameSize = useMemo(() => {
+ const availableWidth = Math.max(
+ isCompactLaneLayout
+ ? LANE_MOBILE_CARD_MIN_WIDTH_PX
+ : LANE_DESKTOP_CARD_MIN_WIDTH_PX,
+ viewport.width - (isCompactLaneLayout ? 56 : 96),
+ );
+ const availableHeight = Math.max(
+ 200,
+ viewport.height -
+ (isCompactLaneLayout
+ ? LANE_MOBILE_MEDIA_RESERVED_VERTICAL_SPACE_PX - 24
+ : DESKTOP_LANE_MEDIA_VERTICAL_RESERVED_PX),
+ );
+ const preferredWidth = isCompactLaneLayout
+ ? Math.min(LANE_MOBILE_CARD_MAX_WIDTH_PX + 28, availableWidth)
+ : Math.min(
+ LANE_DESKTOP_CARD_MAX_WIDTH_PX,
+ Math.max(
+ LANE_DESKTOP_CARD_MIN_WIDTH_PX,
+ availableWidth * 0.34,
+ ),
+ );
+
+ let width = preferredWidth;
+ let height = width / LANE_CARD_ASPECT_RATIO;
+
+ if (height > availableHeight) {
+ height = availableHeight;
+ width = height * LANE_CARD_ASPECT_RATIO;
+ }
+
+ return { width: Math.round(width), height: Math.round(height) };
+ }, [isCompactLaneLayout, viewport.height, viewport.width]);
+
+ const mediaFrameStyle = isMobileLayout
+ ? {
+ width: `${mobileFrameSize.width}px`,
+ aspectRatio: `${resolvedMediaAspectRatio ?? 4 / 3}`,
+ }
+ : {
+ width: `${desktopFrameSize.width}px`,
+ aspectRatio: `${resolvedMediaAspectRatio ?? 4 / 3}`,
+ };
+
+ const laneMediaFrameStyle = {
+ width: `${laneFrameSize.width}px`,
+ height: `${laneFrameSize.height}px`,
+ };
+
+ const isLaneVariant = variant === "lane";
+ const isProgressPaused =
+ paused || !fileLoaded || (isVideo && !videoDurationKnown);
+ const laneTitle = useMemo(() => {
+ return buildLaneTitle({
+ memoryName,
+ personName: memoryMetadata?.personName,
+ });
+ }, [memoryMetadata?.personName, memoryName]);
+ const laneCaption = useMemo(() => {
+ return formatLaneCaption({
+ frame: currentLaneFrame,
+ metadata: memoryMetadata,
+ fallbackLabel: currentFileDate || memoryName || "Memory lane",
+ });
+ }, [currentFileDate, currentLaneFrame, memoryMetadata, memoryName]);
+ const mediaObjectFit: "contain" | "cover" = isLaneVariant
+ ? "cover"
+ : "contain";
+ const laneContainerAspectRatio = laneFrameSize.width / laneFrameSize.height;
+ const currentCropRect = isLaneVariant
+ ? resolveLaneCropRect(currentLaneFrame)
+ : undefined;
+ const outgoingLaneFrame =
+ outgoingIndex !== null ? laneFrames?.[outgoingIndex] : undefined;
+ const outgoingCropRect = isLaneVariant
+ ? resolveLaneCropRect(outgoingLaneFrame)
+ : undefined;
+ const mediaLayers = (
+ <>
+ <MediaSwitchLayer
+ phase="in"
+ variant={isLaneVariant ? "lane" : "share"}
+ key={`memory-file-${currentIndex}`}
+ >
+ {isVideo ? (
+ <VideoPlayer
+ file={currentFile}
+ onReady={handleFullLoad}
+ onDuration={handleVideoDuration}
+ onEnded={onNext}
+ paused={paused}
+ fillFrame
+ objectFit={mediaObjectFit}
+ cropRect={currentCropRect}
+ cropContainerAspectRatio={laneContainerAspectRatio}
+ mediaAspectRatio={resolvedMediaAspectRatio}
+ onAspectRatio={handleMediaAspectRatio}
+ />
+ ) : (
+ <PhotoImage
+ file={currentFile}
+ onFullLoad={handleFullLoad}
+ fillFrame
+ objectFit={mediaObjectFit}
+ cropRect={currentCropRect}
+ cropContainerAspectRatio={laneContainerAspectRatio}
+ mediaAspectRatio={resolvedMediaAspectRatio}
+ onAspectRatio={handleMediaAspectRatio}
+ />
+ )}
+ </MediaSwitchLayer>
+ {outgoingFile && (
+ <MediaSwitchLayer
+ phase="out"
+ variant={isLaneVariant ? "lane" : "share"}
+ key={`memory-file-out-${outgoingIndex ?? currentIndex}`}
+ >
+ {outgoingIsVideo ? (
+ <VideoPlayer
+ file={outgoingFile}
+ paused
+ fillFrame
+ objectFit={mediaObjectFit}
+ cropRect={outgoingCropRect}
+ cropContainerAspectRatio={laneContainerAspectRatio}
+ mediaAspectRatio={getFileAspectRatio(outgoingFile)}
+ showLoadingOverlay={false}
+ />
+ ) : (
+ <PhotoImage
+ file={outgoingFile}
+ fillFrame
+ objectFit={mediaObjectFit}
+ cropRect={outgoingCropRect}
+ cropContainerAspectRatio={laneContainerAspectRatio}
+ mediaAspectRatio={getFileAspectRatio(outgoingFile)}
+ showLoadingOverlay={false}
+ />
+ )}
+ </MediaSwitchLayer>
+ )}
+ </>
+ );
+
+ if (isLaneVariant) {
+ return (
+ <ViewerRoot onClick={handleScreenTap}>
+ <LaneBackground isMobileLayout={isCompactLaneLayout} />
+ <LaneContentContainer
+ style={
+ isCompactLaneLayout
+ ? {
+ maxWidth: isMobileLayout ? "375px" : "440px",
+ padding: isMobileLayout
+ ? "24px 24px 26px"
+ : "32px 28px 30px",
+ gap: isMobileLayout ? "16px" : "20px",
+ }
+ : undefined
+ }
+ >
+ {isCompactLaneLayout ? (
+ <LaneMobileHeaderSection>
+ <LaneMobileTitle variant="h6">
+ {laneTitle}
+ </LaneMobileTitle>
+ </LaneMobileHeaderSection>
+ ) : (
+ <LaneTopBar>
+ <LaneDesktopTitle variant="h6">
+ {laneTitle}
+ </LaneDesktopTitle>
+ <LaneTopBrandSection>
+ <LaneSharedUsingLabel>
+ Shared using
+ </LaneSharedUsingLabel>
+ <BrandLink
+ href="https://ente.io"
+ target="_blank"
+ rel="noreferrer"
+ data-memory-control="true"
+ >
+ <EnteBrandTagImage
+ src={ENTE_BRAND_TAG_IMAGE_PATH}
+ alt="Ente Photos"
+ />
+ </BrandLink>
+ </LaneTopBrandSection>
+ </LaneTopBar>
+ )}
+
+ <LaneCenterSection>
+ <PhotoContainer
+ style={{ flex: "0 0 auto", minHeight: "auto" }}
+ onContextMenu={(event) => event.preventDefault()}
+ onDragStart={(event) => event.preventDefault()}
+ onPointerDown={
+ isCompactLaneLayout
+ ? () => {
+ pressStartedAtRef.current =
+ Date.now();
+ suppressTapNavigationRef.current = false;
+ setPaused(true);
+ }
+ : undefined
+ }
+ onPointerUp={
+ isCompactLaneLayout
+ ? () => {
+ const startedAt =
+ pressStartedAtRef.current;
+ pressStartedAtRef.current = null;
+ if (
+ startedAt &&
+ Date.now() - startedAt >
+ HOLD_TO_PAUSE_NAV_SUPPRESSION_MS
+ ) {
+ suppressTapNavigationRef.current = true;
+ }
+ setPaused(false);
+ }
+ : undefined
+ }
+ onPointerCancel={
+ isCompactLaneLayout
+ ? () => {
+ pressStartedAtRef.current = null;
+ setPaused(false);
+ }
+ : undefined
+ }
+ onPointerLeave={
+ isCompactLaneLayout
+ ? () => {
+ if (
+ pressStartedAtRef.current !== null
+ ) {
+ pressStartedAtRef.current = null;
+ setPaused(false);
+ }
+ }
+ : undefined
+ }
+ >
+ <LaneCardStack style={laneMediaFrameStyle}>
+ <LaneBackCardPrimary
+ key={`lane-back-primary-${currentIndex}`}
+ />
+ <LaneBackCardSecondary
+ key={`lane-back-secondary-${currentIndex}`}
+ />
+ <LaneFrontCard>
+ <MediaFrame
+ style={{
+ width: "100%",
+ height: "100%",
+ maxWidth: "100%",
+ maxHeight: "100%",
+ borderRadius: isCompactLaneLayout
+ ? "18px"
+ : "22px",
+ }}
+ >
+ {mediaLayers}
+ </MediaFrame>
+ </LaneFrontCard>
+ </LaneCardStack>
+ </PhotoContainer>
+
+ <LaneBottomSection>
+ <Box
+ sx={{
+ position: "absolute",
+ width: 1,
+ height: 1,
+ opacity: 0,
+ overflow: "hidden",
+ pointerEvents: "none",
+ }}
+ >
+ <ProgressIndicator
+ total={files.length}
+ current={currentIndex}
+ paused={isProgressPaused}
+ duration={progressDuration}
+ onComplete={onNext}
+ isVideo={isVideo}
+ />
+ </Box>
+ <LaneCaptionRow>
+ <LanePlaybackButton
+ type="button"
+ data-memory-control="true"
+ onClick={(event) => {
+ event.stopPropagation();
+ setPaused((state) => !state);
+ }}
+ >
+ <LanePlaybackGlyph paused={paused} />
+ </LanePlaybackButton>
+ <LaneCaption>{laneCaption}</LaneCaption>
+ </LaneCaptionRow>
+ <LaneProgressSlider
+ total={files.length}
+ current={currentIndex}
+ onSeek={onSeek}
+ />
+ </LaneBottomSection>
+ </LaneCenterSection>
+ <LaneFooter>
+ {isCompactLaneLayout ? (
+ <LaneMobileFooterBar>
+ <BrandLink
+ href="https://ente.io"
+ target="_blank"
+ rel="noreferrer"
+ data-memory-control="true"
+ >
+ <EnteBrandTagImage
+ src={ENTE_BRAND_TAG_IMAGE_PATH}
+ alt="Ente Photos"
+ />
+ </BrandLink>
+ <MobileJoinNowButton
+ href="https://ente.io"
+ target="_blank"
+ rel="noreferrer"
+ >
+ Join now
+ </MobileJoinNowButton>
+ </LaneMobileFooterBar>
+ ) : (
+ <JoinNowButton
+ href="https://ente.io"
+ target="_blank"
+ rel="noreferrer"
+ >
+ Join now
+ </JoinNowButton>
+ )}
+ </LaneFooter>
+ </LaneContentContainer>
+ </ViewerRoot>
+ );
+ }
+
+ return (
+ <ViewerRoot onClick={handleScreenTap}>
+ <BackgroundPattern />
+ <ContentContainer
+ style={
+ isMobileLayout
+ ? {
+ maxWidth: "375px",
+ padding: "24px 24px 26px",
+ gap: "16px",
+ }
+ : undefined
+ }
+ >
+ {isMobileLayout ? (
+ <MobileHeaderSection>
+ <MobileTitle variant="h6">{headerTitle}</MobileTitle>
+ <ProgressIndicator
+ total={files.length}
+ current={currentIndex}
+ paused={isProgressPaused}
+ duration={progressDuration}
+ onComplete={onNext}
+ isVideo={isVideo}
+ compact
+ />
+ </MobileHeaderSection>
+ ) : (
+ <TopControls>
+ <PlaybackControl
+ type="button"
+ onClick={(event) => {
+ event.stopPropagation();
+ setPaused((state) => !state);
+ }}
+ aria-label={paused ? "Play" : "Pause"}
+ data-memory-control="true"
+ >
+ <PlaybackGlyph paused={paused} />
+ </PlaybackControl>
+
+ <HeaderSection>
+ <MemoryTitle variant="h6">
+ {headerTitle}
+ </MemoryTitle>
+ <ProgressIndicator
+ total={files.length}
+ current={currentIndex}
+ paused={isProgressPaused}
+ duration={progressDuration}
+ onComplete={onNext}
+ isVideo={isVideo}
+ />
+ </HeaderSection>
+
+ {!useFooterShareActions && (
+ <TopRightActions>
+ <BrandLink
+ href="https://ente.io"
+ target="_blank"
+ rel="noreferrer"
+ data-memory-control="true"
+ >
+ <EnteBrandTagImage
+ src={ENTE_BRAND_TAG_IMAGE_PATH}
+ alt="Ente Photos"
+ />
+ </BrandLink>
+ <JoinNowButton
+ href="https://ente.io"
+ target="_blank"
+ rel="noreferrer"
+ >
+ Join now
+ </JoinNowButton>
+ </TopRightActions>
+ )}
+ </TopControls>
+ )}
+
+ <PhotoContainer
+ onContextMenu={(event) => event.preventDefault()}
+ onDragStart={(event) => event.preventDefault()}
+ onPointerDown={
+ isMobileLayout
+ ? () => {
+ pressStartedAtRef.current = Date.now();
+ suppressTapNavigationRef.current = false;
+ setPaused(true);
+ }
+ : undefined
+ }
+ onPointerUp={
+ isMobileLayout
+ ? () => {
+ const startedAt = pressStartedAtRef.current;
+ pressStartedAtRef.current = null;
+ if (
+ startedAt &&
+ Date.now() - startedAt >
+ HOLD_TO_PAUSE_NAV_SUPPRESSION_MS
+ ) {
+ suppressTapNavigationRef.current = true;
+ }
+ setPaused(false);
+ }
+ : undefined
+ }
+ onPointerCancel={
+ isMobileLayout
+ ? () => {
+ pressStartedAtRef.current = null;
+ setPaused(false);
+ }
+ : undefined
+ }
+ onPointerLeave={
+ isMobileLayout
+ ? () => {
+ if (pressStartedAtRef.current !== null) {
+ pressStartedAtRef.current = null;
+ setPaused(false);
+ }
+ }
+ : undefined
+ }
+ >
+ <MediaFrame style={mediaFrameStyle}>
+ {mediaLayers}
+ </MediaFrame>
+ </PhotoContainer>
+
+ {useFooterShareActions && (
+ <MobileBottomBar>
+ <BrandLink
+ href="https://ente.io"
+ target="_blank"
+ rel="noreferrer"
+ data-memory-control="true"
+ >
+ <EnteBrandTagImage
+ src={ENTE_BRAND_TAG_IMAGE_PATH}
+ alt="Ente Photos"
+ />
+ </BrandLink>
+ <MobileJoinNowButton
+ href="https://ente.io"
+ target="_blank"
+ rel="noreferrer"
+ >
+ Join now
+ </MobileJoinNowButton>
+ </MobileBottomBar>
+ )}
+ </ContentContainer>
+ </ViewerRoot>
+ );
+ };
+
+ const ViewerRoot = styled("div")({
+ position: "relative",
+ width: "100vw",
+ minHeight: "100vh",
+ height: "100dvh",
+ overflow: "hidden",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ });
+
+ const BackgroundPattern = styled("div")({
+ position: "fixed",
+ inset: 0,
+ backgroundColor: "#1f1f1f",
+ backgroundImage: `url(${DESKTOP_BACKGROUND_IMAGE_PATH})`,
+ backgroundRepeat: "no-repeat",
+ backgroundSize: "cover",
+ backgroundPosition: "center",
+ zIndex: 1,
+ [`@media (max-width: ${MOBILE_LAYOUT_BREAKPOINT_PX}px)`]: {
+ backgroundImage: `url(${MOBILE_BACKGROUND_IMAGE_PATH})`,
+ backgroundRepeat: "no-repeat",
+ backgroundSize: "cover",
+ backgroundPosition: "center",
+ },
+ });
+
+ const LaneDesktopBackgroundPattern = styled("div")({
+ position: "fixed",
+ inset: 0,
+ overflow: "hidden",
+ backgroundColor: "#000000",
+ zIndex: 1,
+ pointerEvents: "none",
+ "&::before": {
+ content: '""',
+ position: "absolute",
+ inset: 0,
+ background: [
+ "radial-gradient(ellipse 102% 138% at 50% 60%, rgba(7, 102, 81, 0.36) 0%, rgba(6, 86, 73, 0.28) 32%, rgba(4, 60, 59, 0.17) 54%, rgba(2, 33, 35, 0.08) 76%, transparent 100%)",
+ "radial-gradient(ellipse 82% 120% at 50% 60%, rgba(8, 123, 91, 0.5) 0%, rgba(7, 104, 83, 0.38) 30%, rgba(5, 78, 69, 0.24) 52%, rgba(3, 48, 48, 0.11) 74%, transparent 100%)",
+ "radial-gradient(ellipse 56% 86% at 50% 60%, rgba(10, 133, 95, 0.24) 0%, rgba(7, 103, 82, 0.14) 42%, transparent 100%)",
+ ].join(", "),
+ },
+ "&::after": {
+ content: '""',
+ position: "absolute",
+ inset: 0,
+ background: [
+ "linear-gradient(180deg, rgba(0, 0, 0, 0.98) 0%, rgba(0, 0, 0, 0.62) 14%, rgba(0, 0, 0, 0.14) 32%, rgba(0, 0, 0, 0.10) 68%, rgba(0, 0, 0, 0.62) 88%, rgba(0, 0, 0, 0.98) 100%)",
+ "radial-gradient(ellipse 62% 30% at 50% 9%, rgba(28, 51, 96, 0.26) 0%, rgba(13, 23, 48, 0.18) 42%, transparent 100%)",
+ "radial-gradient(ellipse 124% 132% at 50% 58%, transparent 24%, rgba(0, 0, 0, 0.18) 48%, rgba(0, 0, 0, 0.86) 100%)",
+ ].join(", "),
+ },
+ });
+
+ const LaneDesktopBackgroundAtmosphere = styled("div")({
+ position: "absolute",
+ inset: "-6% 0 34%",
+ background:
+ "repeating-linear-gradient(90deg, rgba(34, 60, 112, 0.12) 0px, rgba(34, 60, 112, 0.12) 20px, transparent 20px, transparent 94px)",
+ opacity: 0.11,
+ filter: "blur(26px)",
+ maskImage:
+ "linear-gradient(180deg, rgba(0, 0, 0, 0.98) 0%, rgba(0, 0, 0, 0.86) 18%, rgba(0, 0, 0, 0.30) 50%, transparent 100%)",
+ });
+
+ const LaneDesktopBackgroundGrid = styled("svg")({
+ position: "absolute",
+ inset: 0,
+ width: "100%",
+ height: "100%",
+ maskImage:
+ "radial-gradient(ellipse 82% 84% at 50% 56%, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.74) 44%, rgba(0, 0, 0, 0.32) 72%, transparent 100%)",
+ });
+
+ const LaneBackgroundGridFill: React.FC<{
+ patternId: string;
+ filterId: string;
+ }> = ({ patternId, filterId }) => (
+ <>
+ <defs>
+ <pattern
+ id={patternId}
+ width={LANE_GRID_CELL_SIZE_PX}
+ height={LANE_GRID_CELL_SIZE_PX}
+ patternUnits="userSpaceOnUse"
+ >
+ <rect
+ width={LANE_GRID_CELL_SIZE_PX}
+ height="1"
+ fill={LANE_GRID_LINE_COLOR}
+ fillOpacity={LANE_GRID_LINE_OPACITY}
+ />
+ <rect
+ width="1"
+ height={LANE_GRID_CELL_SIZE_PX}
+ fill={LANE_GRID_LINE_COLOR}
+ fillOpacity={LANE_GRID_LINE_OPACITY}
+ />
+ </pattern>
+ <filter
+ id={filterId}
+ x="-6%"
+ y="-6%"
+ width="112%"
+ height="112%"
+ colorInterpolationFilters="sRGB"
+ >
+ <feTurbulence
+ type="turbulence"
+ baseFrequency="0.009"
+ numOctaves="3"
+ seed="3"
+ result="laneGridNoise"
+ />
+ <feDisplacementMap
+ in="SourceGraphic"
+ in2="laneGridNoise"
+ scale={LANE_GRID_DISPLACEMENT_SCALE}
+ xChannelSelector="R"
+ yChannelSelector="G"
+ />
+ </filter>
+ </defs>
+ <rect
+ width="100%"
+ height="100%"
+ fill={`url(#${patternId})`}
+ filter={`url(#${filterId})`}
+ />
+ </>
+ );
+
+ const LaneDesktopBackgroundGridOverlay = () => (
+ <LaneDesktopBackgroundGrid aria-hidden preserveAspectRatio="none">
+ <LaneBackgroundGridFill
+ patternId="lane-desktop-grid-pattern"
+ filterId="lane-desktop-grid-filter"
+ />
+ </LaneDesktopBackgroundGrid>
+ );
+
+ const LaneMobileBackgroundPattern = styled("div")({
+ position: "fixed",
+ inset: 0,
+ overflow: "hidden",
+ backgroundColor: "#000000",
+ zIndex: 1,
+ pointerEvents: "none",
+ "&::before": {
+ content: '""',
+ position: "absolute",
+ inset: 0,
+ background: [
+ "linear-gradient(180deg, rgba(8, 37, 32, 0.96) 0%, rgba(19, 78, 59, 0.88) 16%, rgba(46, 95, 95, 0.94) 50%, rgba(16, 70, 64, 0.88) 72%, rgba(5, 47, 34, 0.94) 100%)",
+ "radial-gradient(ellipse 82% 26% at 50% 16%, rgba(24, 120, 80, 0.42) 0%, rgba(14, 80, 58, 0.24) 46%, transparent 100%)",
+ "radial-gradient(ellipse 100% 34% at 50% 54%, rgba(76, 123, 145, 0.38) 0%, rgba(43, 90, 107, 0.22) 42%, transparent 100%)",
+ "radial-gradient(ellipse 84% 28% at 50% 86%, rgba(18, 96, 54, 0.34) 0%, rgba(9, 58, 39, 0.18) 46%, transparent 100%)",
+ ].join(", "),
+ },
+ "&::after": {
+ content: '""',
+ position: "absolute",
+ inset: 0,
+ background: [
+ "linear-gradient(180deg, rgba(0, 0, 0, 0.96) 0%, rgba(0, 0, 0, 0.34) 12%, rgba(0, 0, 0, 0.08) 24%, rgba(0, 0, 0, 0.10) 48%, rgba(0, 0, 0, 0.16) 68%, rgba(0, 0, 0, 0.46) 88%, rgba(0, 0, 0, 0.96) 100%)",
+ "linear-gradient(90deg, rgba(0, 0, 0, 0.94) 0%, rgba(0, 0, 0, 0.52) 16%, rgba(0, 0, 0, 0.14) 32%, rgba(0, 0, 0, 0.14) 68%, rgba(0, 0, 0, 0.52) 84%, rgba(0, 0, 0, 0.94) 100%)",
+ ].join(", "),
+ },
+ });
+
+ const LaneMobileBackgroundGrid = styled("svg")({
+ position: "absolute",
+ inset: 0,
+ width: "100%",
+ height: "100%",
+ maskImage:
+ "linear-gradient(180deg, rgba(0, 0, 0, 0.96) 0%, rgba(0, 0, 0, 0.78) 10%, rgba(0, 0, 0, 0.42) 24%, rgba(0, 0, 0, 0.30) 52%, rgba(0, 0, 0, 0.52) 76%, rgba(0, 0, 0, 0.92) 100%)",
+ });
+
+ const LaneMobileBackgroundGridOverlay = () => (
+ <LaneMobileBackgroundGrid aria-hidden preserveAspectRatio="none">
+ <LaneBackgroundGridFill
+ patternId="lane-mobile-grid-pattern"
+ filterId="lane-mobile-grid-filter"
+ />
+ </LaneMobileBackgroundGrid>
+ );
+
+ const LaneBackground: React.FC<{ isMobileLayout?: boolean }> = ({
+ isMobileLayout = false,
+ }) =>
+ isMobileLayout ? (
+ <LaneMobileBackgroundPattern>
+ <LaneMobileBackgroundGridOverlay />
+ </LaneMobileBackgroundPattern>
+ ) : (
+ <LaneDesktopBackgroundPattern>
+ <LaneDesktopBackgroundAtmosphere />
+ <LaneDesktopBackgroundGridOverlay />
+ </LaneDesktopBackgroundPattern>
+ );
+
+ const ContentContainer = styled("div")({
+ position: "relative",
+ zIndex: 2,
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ gap: "32px",
+ width: "100%",
+ maxWidth: `${DESKTOP_MEDIA_MAX_WIDTH_PX}px`,
+ minHeight: "100vh",
+ height: "100dvh",
+ padding: "42px 24px 24px",
+ boxSizing: "border-box",
+ });
+
+ const LaneContentContainer = styled("div")({
+ position: "relative",
+ zIndex: 2,
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ gap: "26px",
+ width: "100%",
+ maxWidth: `${DESKTOP_MEDIA_MAX_WIDTH_PX}px`,
+ minHeight: "100vh",
+ height: "100dvh",
+ padding: "56px 48px 40px",
+ boxSizing: "border-box",
+ [`@media (max-width: ${MOBILE_LAYOUT_BREAKPOINT_PX}px)`]: {
+ padding: "24px 24px 26px",
+ },
+ });
+
+ const LaneMobileHeaderSection = styled("div")({
+ width: "100%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "flex-start",
+ minHeight: "40px",
+ });
+
+ const LaneMobileTitle = styled(Typography)({
+ color: "white",
+ fontWeight: 700,
+ fontSize: "16px",
+ lineHeight: "17px",
+ letterSpacing: 0,
+ textAlign: "left",
+ maxWidth: "326px",
+ whiteSpace: "normal",
+ overflowWrap: "anywhere",
+ });
+
+ const LaneTopBar = styled("div")({
+ width: "calc(100% + 48px)",
+ marginLeft: "-24px",
+ marginRight: "-24px",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "space-between",
+ minHeight: "48px",
+ });
+
+ const LaneDesktopTitle = styled(Typography)({
+ color: "white",
+ fontFamily: "'Inter', sans-serif",
+ fontWeight: 500,
+ fontSize: "27px",
+ lineHeight: "24px",
+ letterSpacing: "-1px",
+ textAlign: "left",
+ whiteSpace: "normal",
+ overflowWrap: "anywhere",
+ maxWidth: "70%",
+ "@media (max-width: 900px)": {
+ fontSize: "22px",
+ lineHeight: "22px",
+ letterSpacing: "0px",
+ },
+ });
+
+ const LaneTopBrandSection = styled("div")({
+ display: "flex",
+ alignItems: "center",
+ gap: "12px",
+ });
+
+ const LaneCenterSection = styled("div")({
+ width: "100%",
+ flex: 1,
+ minHeight: 0,
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ justifyContent: "center",
+ gap: "38px",
+ "@media (max-width: 900px)": { gap: "28px" },
+ });
+
+ const LaneFooter = styled("div")({
+ width: "100%",
+ flexShrink: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ paddingBottom: "max(8px, env(safe-area-inset-bottom, 0px))",
+ });
+
+ const LaneSharedUsingLabel = styled("span")({
+ color: "rgba(255, 255, 255, 0.53)",
+ fontFamily: "var(--font-itim), cursive",
+ fontStyle: "normal",
+ fontWeight: 400,
+ fontSize: "24px",
+ lineHeight: "13px",
+ textAlign: "center",
+ whiteSpace: "nowrap",
+ });
+
+ const LaneCardStack = styled("div")({ position: "relative", flexShrink: 0 });
+
+ const LaneStackSlice = styled("div")({
+ position: "absolute",
+ inset: 0,
+ pointerEvents: "none",
+ willChange: "transform, opacity",
+ });
+
+ const LaneCardSurface = styled("div")({
+ position: "relative",
+ width: "100%",
+ height: "100%",
+ overflow: "hidden",
+ borderRadius: "28px",
+ border: "3px solid white",
+ boxSizing: "border-box",
+ backgroundColor: "black",
+ });
+
+ const LaneCardMediaLayer = styled("div")({ position: "absolute", inset: 0 });
+
+ const LaneCardOverlayLayer = styled("div")({
+ position: "absolute",
+ inset: 0,
+ backgroundColor: "rgba(0, 0, 0, 1)",
+ });
+
+ const LaneBackCardBase = styled("div")({
+ position: "absolute",
+ inset: 0,
+ borderRadius: "22px",
+ border: "4px solid rgba(255, 255, 255, 0.82)",
+ backgroundColor: "rgba(255, 255, 255, 0.2)",
+ });
+
+ const LaneBackCardPrimary = styled(LaneBackCardBase)({
+ transform: "translate(14px, -16px) rotate(3.1deg)",
+ transformOrigin: "center",
+ zIndex: 1,
+ animation: `${laneBackCardPrimaryEnterAnimation} 320ms cubic-bezier(0.2, 0.8, 0.2, 1)`,
+ });
+
+ const LaneBackCardSecondary = styled(LaneBackCardBase)({
+ transform: "translate(6px, -8px) rotate(-1.3deg)",
+ transformOrigin: "center",
+ zIndex: 2,
+ animation: `${laneBackCardSecondaryEnterAnimation} 280ms cubic-bezier(0.2, 0.8, 0.2, 1)`,
+ });
+
+ const LaneFrontCard = styled("div")({
+ position: "relative",
+ zIndex: 3,
+ width: "100%",
+ height: "100%",
+ borderRadius: "22px",
+ border: "4px solid rgba(255, 255, 255, 0.92)",
+ overflow: "hidden",
+ backgroundColor: "black",
+ });
+
+ const LaneBottomSection = styled("div")({
+ position: "relative",
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ justifyContent: "flex-end",
+ gap: "20px",
+ width: "100%",
+ paddingBottom: 0,
+ });
+
+ const LaneCaptionRow = styled("div")({
+ display: "flex",
+ alignItems: "center",
+ gap: "10px",
+ });
+
+ const LanePlaybackButton = styled("button")({
+ border: 0,
+ outline: "none",
+ width: "28px",
+ height: "28px",
+ borderRadius: "999px",
+ padding: 0,
+ cursor: "pointer",
+ backgroundColor: "rgba(255, 255, 255, 0.2)",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ color: "white",
+ });
+
+ const LaneCaption = styled("div")({
+ color: "rgba(255, 255, 255, 0.53)",
+ fontFamily: "var(--font-itim), cursive",
+ fontStyle: "normal",
+ fontWeight: 400,
+ fontSize: "24px",
+ lineHeight: "7.801px",
+ textAlign: "center",
+ whiteSpace: "normal",
+ overflowWrap: "anywhere",
+ });
+
+ const MobileHeaderSection = styled("div")({
+ width: "100%",
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "flex-start",
+ gap: "12px",
+ });
+
+ const MobileTitle = styled(Typography)({
+ color: "white",
+ fontWeight: 700,
+ fontSize: "16px",
+ lineHeight: "17px",
+ letterSpacing: 0,
+ textAlign: "left",
+ maxWidth: "326px",
+ whiteSpace: "normal",
+ overflowWrap: "anywhere",
+ });
+
+ const TopControls = styled("div")({
+ position: "relative",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ minHeight: "64px",
+ width: "100%",
+ boxSizing: "border-box",
+ "@media (max-width: 900px)": { minHeight: "56px" },
+ });
+
+ const HeaderSection = styled("div")({
+ width: "min(100%, 448px)",
+ minWidth: 0,
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ gap: "24px",
+ });
+
+ const MemoryTitle = styled(Typography)({
+ color: "white",
+ fontWeight: 700,
+ fontSize: "24px",
+ lineHeight: 1.25,
+ letterSpacing: "0px",
+ textAlign: "center",
+ whiteSpace: "normal",
+ overflowWrap: "anywhere",
+ maxWidth: "100%",
+ "@media (max-width: 900px)": { fontSize: "20px" },
+ "@media (max-width: 700px)": { fontSize: "17px", lineHeight: 1.3 },
+ });
+
+ const PlaybackControl = styled("button")({
+ position: "absolute",
+ left: 0,
+ top: "50%",
+ transform: "translateY(-50%)",
+ width: "64px",
+ height: "64px",
+ borderRadius: "19px",
+ border: 0,
+ cursor: "pointer",
+ backgroundColor: "rgba(255, 255, 255, 0.2)",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ color: "white",
+ padding: 0,
+ transition: "background-color 150ms ease",
+ "&:hover": { backgroundColor: "rgba(255, 255, 255, 0.28)" },
+ "@media (max-width: 900px)": {
+ width: "56px",
+ height: "56px",
+ borderRadius: "16px",
+ },
+ });
+
+ const JoinNowButton = styled("a")({
+ backgroundColor: "#08c225",
+ color: "white",
+ textDecoration: "none",
+ borderRadius: "39px",
+ padding: "18px 32px",
+ fontWeight: 700,
+ fontSize: "16px",
+ lineHeight: "14px",
+ whiteSpace: "nowrap",
+ transition: "filter 150ms ease",
+ "&:hover": { filter: "brightness(1.08)" },
+ "@media (max-width: 900px)": { padding: "14px 24px", fontSize: "14px" },
+ });
+
+ const TopRightActions = styled("div")({
+ position: "absolute",
+ right: "-72px",
+ top: "50%",
+ transform: "translateY(-50%)",
+ display: "flex",
+ alignItems: "center",
+ gap: "16px",
+ "@media (max-width: 1200px)": { right: "-36px" },
+ "@media (max-width: 1000px)": { right: 0 },
+ "@media (max-width: 900px)": { gap: "10px" },
+ });
+
+ const BrandLink = styled("a")({
+ color: "inherit",
+ textDecoration: "none",
+ display: "inline-flex",
+ alignItems: "center",
+ justifyContent: "center",
+ flexShrink: 0,
+ });
+
+ const EnteBrandTagImage = styled("img")({
+ width: "58px",
+ height: "42px",
+ display: "block",
+ userSelect: "none",
+ });
+
+ const MobileBottomBar = styled("div")({
+ width: "100%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ gap: "10px",
+ marginTop: "auto",
+ paddingBottom: "2px",
+ });
+
+ const LaneMobileFooterBar = styled("div")({
+ width: "100%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ gap: "10px",
+ paddingBottom: "2px",
+ });
+
+ const MobileJoinNowButton = styled("a")({
+ backgroundColor: "#08c225",
+ color: "white",
+ textDecoration: "none",
+ borderRadius: "33px",
+ padding: "16px 28px",
+ fontWeight: 700,
+ fontSize: "14px",
+ lineHeight: "12px",
+ whiteSpace: "nowrap",
+ });
+
+ const PhotoContainer = styled("div")({
+ position: "relative",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ flex: 1,
+ minHeight: 0,
+ width: "100%",
+ cursor: "pointer",
+ userSelect: "none",
+ WebkitUserSelect: "none",
+ WebkitTouchCallout: "none",
+ touchAction: "manipulation",
+ });
+
+ const MediaFrame = styled("div")({
+ position: "relative",
+ borderRadius: "24px",
+ overflow: "hidden",
+ isolation: "isolate",
+ backgroundColor: "transparent",
+ width: "fit-content",
+ height: "fit-content",
+ maxWidth: DESKTOP_MEDIA_MAX_WIDTH_CSS,
+ maxHeight: DESKTOP_MEDIA_MAX_HEIGHT_CSS,
+ flexShrink: 0,
+ lineHeight: 0,
+ });
+
+ const MediaSwitchLayer = styled("div", {
+ shouldForwardProp: (prop) => prop !== "phase" && prop !== "variant",
+ })<{ phase: "in" | "out"; variant?: "share" | "lane" }>(
+ ({ phase, variant = "share" }) => ({
+ position: "absolute",
+ inset: 0,
+ width: "100%",
+ height: "100%",
+ zIndex: phase === "out" ? (variant === "lane" ? 3 : 2) : 1,
+ animation: (() => {
+ if (variant === "lane") {
+ return phase === "out"
+ ? `${laneMediaSwitchOutAnimation} ${MEDIA_SWITCH_TRANSITION_DURATION_MS}ms cubic-bezier(0.22, 0.9, 0.2, 1) forwards`
+ : `${laneMediaSwitchInAnimation} ${MEDIA_SWITCH_TRANSITION_DURATION_MS}ms cubic-bezier(0.22, 0.9, 0.2, 1) both`;
+ }
+ return phase === "out"
+ ? `${mediaSwitchOutAnimation} ${MEDIA_SWITCH_TRANSITION_DURATION_MS}ms cubic-bezier(0.16, 1, 0.3, 1) forwards`
+ : `${mediaSwitchInAnimation} ${MEDIA_SWITCH_TRANSITION_DURATION_MS}ms cubic-bezier(0.16, 1, 0.3, 1) both`;
+ })(),
+ willChange: "opacity, transform",
+ pointerEvents: "none",
+ }),
+ );
+
+ /**
+ * Format a date in the style "12th jan, 2022".
+ */
+ const formatMemoryDate = (date: Date): string => {
+ const day = date.getDate();
+ const month = date.toLocaleString("en", { month: "short" }).toLowerCase();
+ const year = date.getFullYear();
+ const ordinal = getOrdinalSuffix(day);
+ return `${day}${ordinal} ${month}, ${year}`;
+ };
+
+ const getOrdinalSuffix = (n: number): string => {
+ const s = ["th", "st", "nd", "rd"];
+ const v = n % 100;
+ return s[(v - 20) % 10] || s[v] || s[0]!;
+ };
diff --cc web/apps/memories/src/hooks/usePublicMemoryPage.ts
index 0000000000,64879fbd6a..5eec8b1aa3
mode 000000,100644..100644
--- a/web/apps/memories/src/hooks/usePublicMemoryPage.ts
+++ b/web/apps/memories/src/hooks/usePublicMemoryPage.ts
@@@ -1,0 -1,129 +1,129 @@@
+ import { useCallback, useEffect, useState } from "react";
+
+ import { downloadManager } from "ente-gallery/services/download";
+ import type { EnteFile } from "ente-media/file";
+ import type {
+ PublicMemoryShareFrame,
+ PublicMemoryShareMetadata,
-} from "ente-new/albums/services/public-memory";
++} from "../services/public-memory";
+ import {
+ loadPublicMemoryPage,
+ type PublicMemoryViewerVariant,
+ } from "../services/public-memory-page";
+
+ export interface UsePublicMemoryPageResult {
+ currentIndex: number;
+ errorMessage: string;
+ files: EnteFile[] | undefined;
+ goToNext: () => void;
+ goToPrev: () => void;
+ handleSeek: (index: number) => void;
+ hideContent: boolean;
+ laneFrames: (PublicMemoryShareFrame | undefined)[] | undefined;
+ loading: boolean;
+ memoryMetadata: PublicMemoryShareMetadata | undefined;
+ memoryName: string;
+ viewerVariant: PublicMemoryViewerVariant;
+ }
+
+ export const usePublicMemoryPage = (): UsePublicMemoryPageResult => {
+ const [memoryName, setMemoryName] = useState<string>("");
+ const [files, setFiles] = useState<EnteFile[] | undefined>(undefined);
+ const [laneFrames, setLaneFrames] = useState<
+ (PublicMemoryShareFrame | undefined)[] | undefined
+ >(undefined);
+ const [memoryMetadata, setMemoryMetadata] = useState<
+ PublicMemoryShareMetadata | undefined
+ >(undefined);
+ const [viewerVariant, setViewerVariant] =
+ useState<PublicMemoryViewerVariant>("share");
+ const [errorMessage, setErrorMessage] = useState<string>("");
+ const [loading, setLoading] = useState(true);
+ const [currentIndex, setCurrentIndex] = useState(0);
+ const [hideContent, setHideContent] = useState(false);
+
+ useEffect(() => {
+ let cancelled = false;
+
+ const main = async () => {
+ const result = await loadPublicMemoryPage(
+ new URL(window.location.href),
+ );
+
+ if (cancelled) {
+ return;
+ }
+
+ switch (result.kind) {
+ case "redirect":
+ setHideContent(true);
+ window.location.href = result.redirectURL;
+ return;
+ case "error":
+ setErrorMessage(result.errorMessage);
+ setLoading(false);
+ return;
+ case "loaded":
+ downloadManager.setPublicMemoryCredentials({
+ accessToken: result.data.accessToken,
+ });
+ setMemoryMetadata(result.data.memoryMetadata);
+ setMemoryName(result.data.memoryName);
+ setViewerVariant(result.data.viewerVariant);
+ setFiles(result.data.files);
+ setLaneFrames(result.data.laneFrames);
+ setLoading(false);
+ return;
+ }
+ };
+
+ void main();
+ return () => {
+ cancelled = true;
+ downloadManager.setPublicMemoryCredentials(undefined);
+ };
+ }, []);
+
+ const goToNext = useCallback(() => {
+ if (!files) return;
+ setCurrentIndex((prev) => (prev < files.length - 1 ? prev + 1 : prev));
+ }, [files]);
+
+ const goToPrev = useCallback(() => {
+ setCurrentIndex((prev) => (prev > 0 ? prev - 1 : prev));
+ }, []);
+
+ const handleSeek = useCallback(
+ (index: number) => {
+ if (!files) return;
+ const max = files.length - 1;
+ const clampedIndex = Math.min(Math.max(index, 0), max);
+ setCurrentIndex(clampedIndex);
+ },
+ [files],
+ );
+
+ useEffect(() => {
+ const handleKeyDown = (e: KeyboardEvent) => {
+ if (e.key === "ArrowRight") goToNext();
+ else if (e.key === "ArrowLeft") goToPrev();
+ };
+ window.addEventListener("keydown", handleKeyDown);
+ return () => window.removeEventListener("keydown", handleKeyDown);
+ }, [goToNext, goToPrev]);
+
+ return {
+ currentIndex,
+ errorMessage,
+ files,
+ goToNext,
+ goToPrev,
+ handleSeek,
+ hideContent,
+ laneFrames,
+ loading,
+ memoryMetadata,
+ memoryName,
+ viewerVariant,
+ };
+ };
diff --cc web/apps/memories/src/services/public-memory-page.ts
index 0000000000,ce93bf439c..155724b1b5
mode 000000,100644..100644
--- a/web/apps/memories/src/services/public-memory-page.ts
+++ b/web/apps/memories/src/services/public-memory-page.ts
@@@ -1,0 -1,121 +1,121 @@@
+ import { isHTTPErrorWithStatus } from "ente-base/http";
+ import log from "ente-base/log";
+ import { memoriesAppOrigin } from "ente-base/origins";
+ import type { EnteFile } from "ente-media/file";
+ import {
+ decryptMemoryShareMetadata,
+ getPublicMemoryFiles,
+ getPublicMemoryInfo,
+ type PublicMemoryShareFrame,
+ type PublicMemoryShareMetadata,
-} from "ente-new/albums/services/public-memory";
++} from "./public-memory";
+ import { alignLaneFilesWithMetadata } from "../utils/lane";
+ import {
+ extractAccessTokenFromURL,
+ extractMemoryShareKeyFromURL,
+ } from "../utils/public-memory-url";
+
+ export type PublicMemoryViewerVariant = "share" | "lane";
+
+ export interface LoadedPublicMemoryPageData {
+ accessToken: string;
+ files: EnteFile[];
+ laneFrames?: (PublicMemoryShareFrame | undefined)[];
+ memoryMetadata?: PublicMemoryShareMetadata;
+ memoryName: string;
+ viewerVariant: PublicMemoryViewerVariant;
+ }
+
+ export type LoadPublicMemoryPageResult =
+ | { kind: "redirect"; redirectURL: string }
+ | { kind: "error"; errorMessage: string }
+ | { kind: "loaded"; data: LoadedPublicMemoryPageData };
+
+ export const loadPublicMemoryPage = async (
+ currentURL: URL,
+ ): Promise<LoadPublicMemoryPageResult> => {
+ try {
+ const accessToken = extractAccessTokenFromURL(currentURL);
+
+ if (!accessToken) {
+ return { kind: "redirect", redirectURL: memoriesAppOrigin() };
+ }
+
+ const shareKey = await extractMemoryShareKeyFromURL(currentURL);
+ if (!shareKey) {
+ return {
+ kind: "error",
+ errorMessage: "Invalid memory link. Missing secret.",
+ };
+ }
+
+ const info = await getPublicMemoryInfo(accessToken);
+
+ let memoryMetadata: PublicMemoryShareMetadata | undefined;
+ if (info.metadataCipher && info.metadataNonce) {
+ memoryMetadata = await decryptMemoryShareMetadata(
+ info.metadataCipher,
+ info.metadataNonce,
+ shareKey,
+ );
+ }
+
+ const viewerVariant: PublicMemoryViewerVariant =
+ info.type === "lane" || memoryMetadata?.kind === "lane"
+ ? "lane"
+ : "share";
+
+ const publicFiles = await getPublicMemoryFiles(accessToken, shareKey);
+ const isLaneShare = viewerVariant === "lane";
+
+ if (isLaneShare && memoryMetadata?.frames.length) {
+ const aligned = alignLaneFilesWithMetadata(
+ publicFiles,
+ memoryMetadata.frames,
+ );
+ return {
+ kind: "loaded",
+ data: {
+ accessToken,
+ files: aligned.files,
+ laneFrames: aligned.frames,
+ memoryMetadata,
+ memoryName: memoryMetadata.name,
+ viewerVariant,
+ },
+ };
+ }
+
+ return {
+ kind: "loaded",
+ data: {
+ accessToken,
+ files: publicFiles.map(({ file }) => file),
+ laneFrames: undefined,
+ memoryMetadata,
+ memoryName: memoryMetadata?.name ?? "",
+ viewerVariant,
+ },
+ };
+ } catch (e) {
+ if (isHTTPErrorWithStatus(e, 401) || isHTTPErrorWithStatus(e, 410)) {
+ return {
+ kind: "error",
+ errorMessage:
+ "This memory link has expired or is no longer available.",
+ };
+ }
+ if (isHTTPErrorWithStatus(e, 429)) {
+ return {
+ kind: "error",
+ errorMessage: "Too many requests. Please try again later.",
+ };
+ }
+
+ log.error("Failed to load public memory share", e);
+ return {
+ kind: "error",
+ errorMessage: "Something went wrong. Please try again later.",
+ };
+ }
+ };
diff --cc web/apps/memories/src/services/public-memory.ts
index 0000000000,d218b253d0..3cc5efe9c9
mode 000000,100644..100644
--- a/web/apps/memories/src/services/public-memory.ts
+++ b/web/apps/memories/src/services/public-memory.ts
@@@ -1,0 -1,249 +1,231 @@@
+ import { decryptBoxBytes } from "ente-base/crypto";
-import { ensureOk, publicRequestHeaders } from "ente-base/http";
++import { ensureOk } from "ente-base/http";
+ import { apiURL } from "ente-base/origins";
++import {
++ authenticatedPublicMemoryRequestHeaders,
++} from "ente-base/public-memory";
+ import {
+ decryptRemoteFile,
+ RemoteEnteFile,
+ type EnteFile,
+ } from "ente-media/file";
++import { gunzip } from "ente-new/photos/utils/gzip";
+ import { z } from "zod";
-import { gunzip } from "../../photos/utils/gzip";
-
-/**
- * Credentials needed to make public memory share related API requests.
- */
-export interface PublicMemoryCredentials {
- /**
- * The access token for the public memory share.
- *
- * This is obtained from the "t" query parameter of the share URL.
- * It both identifies the share and authenticates the request.
- */
- accessToken: string;
-}
+
-/**
- * Return headers for public memory share API requests.
- */
-export const authenticatedPublicMemoryRequestHeaders = ({
- accessToken,
-}: PublicMemoryCredentials) => ({
- "X-Auth-Access-Token": accessToken,
- ...publicRequestHeaders(),
-});
++export type { PublicMemoryCredentials } from "ente-base/public-memory";
+
+ /**
+ * Information about a public memory share fetched from remote.
+ */
+ export interface PublicMemoryShareInfo {
+ id: number;
+ type: "share" | "lane";
+ memoryHash?: string;
+ metadataCipher: string;
+ metadataNonce: string;
+ encryptedKey: string;
+ keyDecryptionNonce: string;
+ }
+
+ const PublicMemoryShareInfoResponse = z.object({
+ memoryShare: z.object({
+ id: z.number(),
+ type: z.enum(["share", "lane"]).optional().default("share"),
+ memoryHash: z.string().optional(),
+ metadataCipher: z.string().optional().default(""),
+ metadataNonce: z.string().optional().default(""),
+ encryptedKey: z.string(),
+ keyDecryptionNonce: z.string(),
+ }),
+ });
+
+ /**
+ * Fetch information about a public memory share from remote.
+ *
+ * @param accessToken The access token from the memory share URL.
+ */
+ export const getPublicMemoryInfo = async (
+ accessToken: string,
+ ): Promise<PublicMemoryShareInfo> => {
+ const res = await fetch(await apiURL("/public-memory/info"), {
+ headers: authenticatedPublicMemoryRequestHeaders({ accessToken }),
+ });
+ ensureOk(res);
+ const { memoryShare } = PublicMemoryShareInfoResponse.parse(
+ await res.json(),
+ );
+ return memoryShare;
+ };
+
+ /**
+ * A file in a public memory share, with its key re-encrypted to the share key.
+ */
+ const PublicMemoryShareFile = z.object({
+ file: RemoteEnteFile,
+ position: z.number(),
+ encryptedKey: z.string(),
+ keyDecryptionNonce: z.string(),
+ });
+
+ const PublicMemoryShareFilesResponse = z.object({
+ files: PublicMemoryShareFile.array(),
+ });
+
+ export interface PublicMemoryFile {
+ file: EnteFile;
+ position: number;
+ }
+
+ export interface PublicMemoryShareFrameCrop {
+ x: number;
+ y: number;
+ width: number;
+ height: number;
+ }
+
+ export interface PublicMemoryShareFrame {
+ fileID: number;
+ position?: number;
+ faceID?: string;
+ faceBox?: PublicMemoryShareFrameCrop;
+ crop?: PublicMemoryShareFrameCrop;
+ creationTime?: number;
+ year?: number;
+ }
+
+ export interface PublicMemoryShareMetadata {
+ name: string;
+ kind?: "share" | "lane";
+ captionType?: "age" | "yearsAgo";
+ personID?: string;
+ personName?: string;
+ birthDate?: string;
+ frames: PublicMemoryShareFrame[];
+ }
+
+ const PublicMemoryShareFrameCropSchema = z.object({
+ x: z.number(),
+ y: z.number(),
+ width: z.number(),
+ height: z.number(),
+ });
+
+ const PublicMemoryShareFrameSchema = z.object({
+ fileID: z.number(),
+ position: z.number().optional(),
+ faceID: z.string().optional(),
+ faceBox: PublicMemoryShareFrameCropSchema.optional(),
+ crop: PublicMemoryShareFrameCropSchema.optional(),
+ creationTime: z.number().optional(),
+ year: z.number().optional(),
+ });
+
+ const PublicMemoryShareMetadataBaseSchema = z.looseObject({
+ name: z.string().optional(),
+ kind: z.enum(["share", "lane"]).optional(),
+ captionType: z.enum(["age", "yearsAgo"]).optional(),
+ personID: z.string().optional(),
+ personName: z.string().optional(),
+ birthDate: z.string().optional(),
+ frames: z.array(z.unknown()).optional(),
+ });
+
+ /**
+ * Fetch the files in a public memory share, decrypt them using the provided
+ * share key, and return them as {@link EnteFile}s.
+ *
+ * @param accessToken The access token from the memory share URL.
+ * @param shareKey The base64 encoded per-share key (from the URL hash).
+ */
+ export const getPublicMemoryFiles = async (
+ accessToken: string,
+ shareKey: string,
+ ): Promise<PublicMemoryFile[]> => {
+ const res = await fetch(await apiURL("/public-memory/files"), {
+ headers: authenticatedPublicMemoryRequestHeaders({ accessToken }),
+ });
+ ensureOk(res);
+ const { files } = PublicMemoryShareFilesResponse.parse(await res.json());
+
+ const publicFiles: PublicMemoryFile[] = [];
+ for (const { file, position, encryptedKey, keyDecryptionNonce } of files) {
+ // The file's key is re-encrypted to the per-share key.
+ // Override the file's encryptedKey/nonce with the share-level values
+ // so that decryptRemoteFile can decrypt using the shareKey.
+ const remoteFile = { ...file, encryptedKey, keyDecryptionNonce };
+ const decrypted = await decryptRemoteFile(remoteFile, shareKey);
+ publicFiles.push({ file: decrypted, position });
+ }
+ return publicFiles.sort((a, b) => a.position - b.position);
+ };
+
+ const decryptMemoryShareMetadataJSON = async (
+ metadataCipher: string,
+ metadataNonce: string,
+ shareKey: string,
+ ): Promise<string> => {
+ const metadataBytes = await decryptBoxBytes(
+ { encryptedData: metadataCipher, nonce: metadataNonce },
+ shareKey,
+ );
+ let metadataJson: string;
+ try {
+ metadataJson = new TextDecoder().decode(metadataBytes);
+ JSON.parse(metadataJson);
+ } catch {
+ metadataJson = await gunzip(metadataBytes);
+ }
+ return metadataJson;
+ };
+
+ /**
+ * Decrypt the memory share's metadata.
+ *
+ * The metadata is a JSON object encrypted with the per-share key.
+ * For lane shares, it can include per-frame crop data that the web app can use
+ * directly for rendering without recomputing face placement.
+ */
+ export const decryptMemoryShareMetadata = async (
+ metadataCipher: string,
+ metadataNonce: string,
+ shareKey: string,
+ ): Promise<PublicMemoryShareMetadata> => {
+ const metadataJson = await decryptMemoryShareMetadataJSON(
+ metadataCipher,
+ metadataNonce,
+ shareKey,
+ );
+ const metadata = PublicMemoryShareMetadataBaseSchema.parse(
+ JSON.parse(metadataJson),
+ );
+ const frames = (metadata.frames ?? []).flatMap((frame) => {
+ const parsed = PublicMemoryShareFrameSchema.safeParse(frame);
+ return parsed.success ? [parsed.data] : [];
+ });
+
+ return {
+ name: metadata.name ?? "",
+ kind: metadata.kind,
+ captionType: metadata.captionType,
+ personID: metadata.personID,
+ personName: metadata.personName,
+ birthDate: metadata.birthDate,
+ frames,
+ };
+ };
+
+ /**
+ * Decrypt the memory share's metadata and extract the name.
+ */
+ export const decryptMemoryShareName = async (
+ metadataCipher: string,
+ metadataNonce: string,
+ shareKey: string,
+ ): Promise<string> => {
+ const metadata = await decryptMemoryShareMetadata(
+ metadataCipher,
+ metadataNonce,
+ shareKey,
+ );
+ return metadata.name;
+ };
diff --cc web/apps/memories/src/utils/lane.ts
index 0000000000,486cdf16a5..58dab2d022
mode 000000,100644..100644
--- a/web/apps/memories/src/utils/lane.ts
+++ b/web/apps/memories/src/utils/lane.ts
@@@ -1,0 -1,387 +1,387 @@@
+ import type { CSSProperties } from "react";
+
+ import type { EnteFile } from "ente-media/file";
+ import type {
+ PublicMemoryFile,
+ PublicMemoryShareFrame,
+ PublicMemoryShareFrameCrop,
+ PublicMemoryShareMetadata,
-} from "ente-new/albums/services/public-memory";
++} from "../services/public-memory";
+
+ const LANE_CROP_REGULAR_PADDING = 0.4;
+ const LANE_CROP_MINIMUM_PADDING = 0.1;
+
+ export interface LaneCaptionModel {
+ prefix?: string;
+ suffix?: string;
+ text: string;
+ value?: number;
+ }
+
+ export interface LaneCardSlice {
+ index: number;
+ distance: number;
+ }
+
+ const sortLaneFrames = (frames: PublicMemoryShareFrame[]) =>
+ [...frames].sort((a, b) => {
+ const aPosition = a.position ?? Number.MAX_SAFE_INTEGER;
+ const bPosition = b.position ?? Number.MAX_SAFE_INTEGER;
+ return aPosition - bPosition;
+ });
+
+ export const alignLaneFilesWithMetadata = (
+ publicFiles: PublicMemoryFile[],
+ frames: PublicMemoryShareFrame[],
+ ) => {
+ const framesByPosition = new Map<number, PublicMemoryShareFrame>();
+ for (const frame of sortLaneFrames(frames)) {
+ if (
+ typeof frame.position === "number" &&
+ frame.position >= 0 &&
+ !framesByPosition.has(frame.position)
+ ) {
+ framesByPosition.set(frame.position, frame);
+ }
+ }
+
+ const orderedFiles: EnteFile[] = [];
+ const orderedFrames: (PublicMemoryShareFrame | undefined)[] = [];
+
+ publicFiles.forEach(({ file, position }) => {
+ orderedFiles.push(file);
+ orderedFrames.push(framesByPosition.get(position));
+ });
+
+ return { files: orderedFiles, frames: orderedFrames };
+ };
+
+ const yearsBetween = (start: Date, end: Date) =>
+ (end.getTime() - start.getTime()) / (365.25 * 24 * 60 * 60 * 1000);
+
+ export const getFileAspectRatio = (file: EnteFile): number | undefined => {
+ const width = file.pubMagicMetadata?.data.w;
+ const height = file.pubMagicMetadata?.data.h;
+ if (
+ typeof width === "number" &&
+ width > 0 &&
+ typeof height === "number" &&
+ height > 0
+ ) {
+ return width / height;
+ }
+ return undefined;
+ };
+
+ const clampCropRect = (
+ crop: PublicMemoryShareFrameCrop,
+ ): PublicMemoryShareFrameCrop => {
+ const x = Math.min(Math.max(crop.x, 0), 1);
+ const y = Math.min(Math.max(crop.y, 0), 1);
+ const width = Math.min(Math.max(crop.width, 0.00001), 1 - x);
+ const height = Math.min(Math.max(crop.height, 0.00001), 1 - y);
+ return { x, y, width, height };
+ };
+
+ const computePaddedLaneCrop = (
+ faceBox: PublicMemoryShareFrameCrop,
+ ): PublicMemoryShareFrameCrop => {
+ const normalizedBox = clampCropRect(faceBox);
+ const xCrop =
+ normalizedBox.x - normalizedBox.width * LANE_CROP_REGULAR_PADDING;
+ const xOvershoot = Math.abs(Math.min(0, xCrop)) / normalizedBox.width;
+ const widthCrop =
+ normalizedBox.width * (1 + 2 * LANE_CROP_REGULAR_PADDING) -
+ 2 *
+ Math.min(
+ xOvershoot,
+ LANE_CROP_REGULAR_PADDING - LANE_CROP_MINIMUM_PADDING,
+ ) *
+ normalizedBox.width;
+
+ const yCrop =
+ normalizedBox.y - normalizedBox.height * LANE_CROP_REGULAR_PADDING;
+ const yOvershoot = Math.abs(Math.min(0, yCrop)) / normalizedBox.height;
+ const heightCrop =
+ normalizedBox.height * (1 + 2 * LANE_CROP_REGULAR_PADDING) -
+ 2 *
+ Math.min(
+ yOvershoot,
+ LANE_CROP_REGULAR_PADDING - LANE_CROP_MINIMUM_PADDING,
+ ) *
+ normalizedBox.height;
+
+ return clampCropRect({
+ x: xCrop,
+ y: yCrop,
+ width: widthCrop,
+ height: heightCrop,
+ });
+ };
+
+ export const resolveLaneCropRect = (
+ frame?: PublicMemoryShareFrame,
+ ): PublicMemoryShareFrameCrop | undefined => {
+ if (!frame) return undefined;
+ if (frame.crop) return clampCropRect(frame.crop);
+ if (frame.faceBox) return computePaddedLaneCrop(frame.faceBox);
+ return undefined;
+ };
+
+ export const computeMediaCropStyle = ({
+ cropRect,
+ mediaAspectRatio,
+ containerAspectRatio,
+ }: {
+ cropRect?: PublicMemoryShareFrameCrop;
+ mediaAspectRatio?: number;
+ containerAspectRatio?: number;
+ }): CSSProperties | undefined => {
+ if (
+ !cropRect ||
+ typeof mediaAspectRatio !== "number" ||
+ mediaAspectRatio <= 0 ||
+ typeof containerAspectRatio !== "number" ||
+ containerAspectRatio <= 0
+ ) {
+ return undefined;
+ }
+
+ const safeCrop = clampCropRect(cropRect);
+ const scale = Math.max(
+ containerAspectRatio / (safeCrop.width * mediaAspectRatio),
+ 1 / safeCrop.height,
+ );
+ const renderedWidthPercent =
+ (scale * mediaAspectRatio * 100) / containerAspectRatio;
+ const renderedHeightPercent = scale * 100;
+ const centerX = safeCrop.x + safeCrop.width / 2;
+ const centerY = safeCrop.y + safeCrop.height / 2;
+
+ return {
+ position: "absolute",
+ width: `${renderedWidthPercent}%`,
+ height: `${renderedHeightPercent}%`,
+ maxWidth: "none",
+ maxHeight: "none",
+ left: `calc(50% - ${centerX * renderedWidthPercent}%)`,
+ top: `calc(50% - ${centerY * renderedHeightPercent}%)`,
+ objectFit: "fill",
+ };
+ };
+
+ export const getFrameCreationDate = (frame?: PublicMemoryShareFrame) => {
+ if (typeof frame?.creationTime !== "number") {
+ return undefined;
+ }
+ const date = new Date(frame.creationTime / 1000);
+ return Number.isNaN(date.getTime()) ? undefined : date;
+ };
+
+ export const formatLaneCaption = ({
+ frame,
+ metadata,
+ fallbackLabel,
+ }: {
+ frame?: PublicMemoryShareFrame;
+ metadata?: PublicMemoryShareMetadata;
+ fallbackLabel: string;
+ }) => {
+ const creationDate = getFrameCreationDate(frame);
+ if (!creationDate) {
+ return fallbackLabel;
+ }
+
+ const personName = metadata?.personName?.trim() ?? "";
+ const captionType =
+ metadata?.captionType ?? (metadata?.birthDate ? "age" : "yearsAgo");
+ const roundedValue = (() => {
+ if (captionType === "age" && metadata?.birthDate) {
+ const birthDate = new Date(metadata.birthDate);
+ if (!Number.isNaN(birthDate.getTime())) {
+ return Math.max(
+ 0,
+ Math.round(yearsBetween(birthDate, creationDate)),
+ );
+ }
+ }
+ return Math.max(0, Math.round(yearsBetween(creationDate, new Date())));
+ })();
+ const yearsLabel = `${roundedValue} year${roundedValue === 1 ? "" : "s"}`;
+
+ if (captionType === "age") {
+ return personName
+ ? `${personName} ${yearsLabel} old`
+ : `${yearsLabel} old`;
+ }
+
+ return personName ? `${personName} ${yearsLabel} ago` : `${yearsLabel} ago`;
+ };
+
+ export const buildLaneCaptionModel = ({
+ frame,
+ metadata,
+ fallbackLabel,
+ }: {
+ frame?: PublicMemoryShareFrame;
+ metadata?: PublicMemoryShareMetadata;
+ fallbackLabel: string;
+ }): LaneCaptionModel => {
+ const creationDate = getFrameCreationDate(frame);
+ if (!creationDate) {
+ return { text: fallbackLabel };
+ }
+
+ const personName = metadata?.personName?.trim() ?? "";
+ const captionType =
+ metadata?.captionType ?? (metadata?.birthDate ? "age" : "yearsAgo");
+ const roundedValue = (() => {
+ if (captionType === "age" && metadata?.birthDate) {
+ const birthDate = new Date(metadata.birthDate);
+ if (!Number.isNaN(birthDate.getTime())) {
+ return Math.max(
+ 0,
+ Math.round(yearsBetween(birthDate, creationDate)),
+ );
+ }
+ }
+ return Math.max(0, Math.round(yearsBetween(creationDate, new Date())));
+ })();
+ const prefix = personName ? `${personName} ` : "";
+ const suffix =
+ captionType === "age"
+ ? ` year${roundedValue === 1 ? "" : "s"} old`
+ : ` year${roundedValue === 1 ? "" : "s"} ago`;
+ return {
+ prefix,
+ suffix,
+ text: `${prefix}${roundedValue}${suffix}`,
+ value: roundedValue,
+ };
+ };
+
+ export const buildLaneTitle = ({
+ memoryName,
+ personName,
+ }: {
+ memoryName: string;
+ personName?: string;
+ }) => {
+ const trimmedTitle = memoryName.trim();
+ const trimmedPersonName = personName?.trim() ?? "";
+ const baseTitle = trimmedTitle || "Memory lane";
+
+ if (!trimmedPersonName) {
+ if (baseTitle.toLowerCase().includes("memory lane")) {
+ return baseTitle;
+ }
+ return `${baseTitle} memory lane`;
+ }
+
+ const possessiveName = trimmedPersonName.endsWith("s")
+ ? `${trimmedPersonName}'`
+ : `${trimmedPersonName}'s`;
+ return `${possessiveName} memory lane`;
+ };
+
+ export const easeInOutCubic = (value: number) =>
+ value < 0.5
+ ? 4 * value * value * value
+ : 1 - Math.pow(-2 * value + 2, 3) / 2;
+
+ export const lerp = (start: number, end: number, t: number) =>
+ start + (end - start) * t;
+
+ export const getLaneStackSlices = (
+ frameCount: number,
+ stackProgress: number,
+ ): LaneCardSlice[] => {
+ const slices: LaneCardSlice[] = [];
+ const clampedProgress = Math.min(
+ Math.max(stackProgress, 0),
+ frameCount - 1,
+ );
+ const startIndex = Math.max(0, Math.floor(clampedProgress) - 3);
+ const endIndex = Math.min(frameCount - 1, Math.ceil(clampedProgress) + 4);
+
+ for (let index = startIndex; index <= endIndex; index++) {
+ const distance = index - clampedProgress;
+ if (distance < -4.5 || distance > 5.5) {
+ continue;
+ }
+ slices.push({ index, distance });
+ }
+
+ const futureSlices = slices
+ .filter((slice) => slice.distance >= 0)
+ .sort((a, b) => b.distance - a.distance);
+ const presentAndPastSlices = slices
+ .filter((slice) => slice.distance < 0)
+ .sort((a, b) => a.distance - b.distance);
+
+ return [...futureSlices, ...presentAndPastSlices];
+ };
+
+ export const calculateLaneScale = (distance: number) => {
+ if (distance >= 0) {
+ return Math.max(0.84, 1.0 - distance * 0.05);
+ }
+ return Math.min(Math.max(1.0 - Math.abs(distance) * 0.02, 0.82), 1.02);
+ };
+
+ export const calculateLaneYOffset = (distance: number, cardHeight: number) => {
+ if (distance >= 0) {
+ const compression = Math.pow(0.72, distance);
+ return -cardHeight * 0.14 * distance * compression;
+ }
+ const downward = Math.abs(distance);
+ const easedComponent = Math.pow(downward, 1.45);
+ const travel = downward * (2.8 + 1.8 * downward);
+ return cardHeight * (travel + easedComponent * 0.65);
+ };
+
+ export const calculateLaneBlur = (distance: number) => {
+ if (distance <= 0) {
+ return 0;
+ }
+ const effective = Math.max(0, distance - 0.15);
+ return Math.min(20, (effective + 0.05) * 10);
+ };
+
+ export const calculateLaneRotation = (distance: number) => {
+ if (distance <= 0) {
+ return 0;
+ }
+ const clamped = Math.min(Math.max(distance, 0), 3);
+ const falloff = Math.max(0.2, 1 - clamped * 0.18);
+ return 0.035 * clamped * falloff;
+ };
+
+ export const calculateLaneOpacity = (distance: number) => {
+ if (distance >= 0) {
+ return Math.max(0.35, 1 - distance * 0.22);
+ }
+ const drop = Math.abs(distance);
+ if (drop <= 0.9) {
+ return 1;
+ }
+ const t = Math.min(Math.max((drop - 0.9) / 0.55, 0), 1);
+ return Math.max(0, 1 - t);
+ };
+
+ export const calculateLaneOverlayOpacity = (distance: number) => {
+ if (distance <= 0) {
+ return 0;
+ }
+ const normalized = Math.min(Math.max(distance / 3, 0), 1);
+ return 0.45 * (1 - Math.pow(1 - normalized, 3));
+ };
+
+ export const laneCardShadow = (distance: number) => {
+ const baseOpacity = 0.55;
+ if (distance > 0) {
+ return `0 26px 38px -6px rgba(0, 0, 0, ${Math.max(0, baseOpacity - distance * 0.12)})`;
+ }
+ const dampening = Math.max(0.2, 1 - Math.abs(distance) * 0.25);
+ return `0 24px 34px -12px rgba(0, 0, 0, ${baseOpacity * dampening})`;
+ };
diff --cc web/packages/base/public-memory.ts
index 0000000000,0000000000..a42a350ef6
new file mode 100644
--- /dev/null
+++ b/web/packages/base/public-memory.ts
@@@ -1,0 -1,0 +1,24 @@@
++import { publicRequestHeaders } from "ente-base/http";
++
++/**
++ * Credentials needed to make public memory share related API requests.
++ */
++export interface PublicMemoryCredentials {
++ /**
++ * The access token for the public memory share.
++ *
++ * This is obtained from the "t" query parameter of the share URL.
++ * It both identifies the share and authenticates the request.
++ */
++ accessToken: string;
++}
++
++/**
++ * Return headers for public memory share API requests.
++ */
++export const authenticatedPublicMemoryRequestHeaders = ({
++ accessToken,
++}: PublicMemoryCredentials) => ({
++ "X-Auth-Access-Token": accessToken,
++ ...publicRequestHeaders(),
++});
diff --cc web/packages/gallery/services/download.ts
index 7cfed9c48a,1e0f524768..c3bc40da61
--- a/web/packages/gallery/services/download.ts
+++ b/web/packages/gallery/services/download.ts
@@@ -14,13 -14,18 +14,18 @@@ import
} from "ente-base/http";
import log from "ente-base/log";
import { apiURL, customAPIOrigin } from "ente-base/origins";
++import {
++ authenticatedPublicMemoryRequestHeaders,
++ type PublicMemoryCredentials,
++} from "ente-base/public-memory";
import { ensureAuthToken } from "ente-base/token";
import type { EnteFile } from "ente-media/file";
import { fileFileName } from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
import { decodeLivePhoto } from "ente-media/live-photo";
-import {
- authenticatedPublicMemoryRequestHeaders,
- type PublicMemoryCredentials,
-} from "ente-new/albums/services/public-memory";
import { detectFileTypeInfoFromChunk } from "../utils/detect-type";
import { playableVideoURL, renderableImageBlob } from "./convert";
+ import { hlsPlaylistDataForFile, type HLSPlaylistDataForFile } from "./video";
/**
* URL(s) for the original image or video, alongwith with potential conversions
diff --cc web/packages/gallery/services/file-data.ts
index 3d7165c277,943cded6ae..ce6bf683da
--- a/web/packages/gallery/services/file-data.ts
+++ b/web/packages/gallery/services/file-data.ts
@@@ -8,7 -8,11 +8,11 @@@ import
type PublicAlbumsCredentials,
} from "ente-base/http";
import { apiURL } from "ente-base/origins";
-import type { EnteFile } from "ente-media/file";
+ import {
+ authenticatedPublicMemoryRequestHeaders,
+ type PublicMemoryCredentials,
-} from "ente-new/albums/services/public-memory";
++} from "ente-base/public-memory";
+import type { EnteFile } from "ente-media/file";
import { nullToUndefined } from "ente-utils/transform";
import { z } from "zod";
diff --cc web/packages/gallery/services/video.ts
index 9962f46516,ad55e38616..6a5df9ccf8
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@@ -8,6 -8,6 +8,7 @@@ import { isHTTP4xxError, type PublicAlb
import { getKV, getKVB, getKVN, setKV } from "ente-base/kv";
import log from "ente-base/log";
import { apiURL } from "ente-base/origins";
++import type { PublicMemoryCredentials } from "ente-base/public-memory";
import { ensureAuthToken } from "ente-base/token";
import { uniqueFilesByID } from "ente-gallery/utils/file";
import { fileLogID, type EnteFile } from "ente-media/file";