Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ Presentation-layer note:
- on screens wider than 900px the preview panel is an aside fixed on the right at about 65% of the width and 0.8rem top/bottom insets, with the bookmark, `…`, and Close controls in its header; the page keeps its normal scroll behavior
- at 900px or narrower the borderless panel covers the full viewport and the footer places the bookmark, `…`, and Close after Previous/Next (in both portrait and landscape). Above 900px the aside header holds the bookmark, `…`, and Close. The `…` button opens a settings-style dialog headed by the article title with its source icon/host and a close button, with the actions stacked as full-width rows over the standard backdrop (dismiss with the close button, backdrop, Escape, or by choosing an action). Content respects left/right safe-area insets in iPhone landscape; while the panel covers the viewport the `theme-color` tint matches the panel surface so the status-bar strip blends with it
- on phones, the glass preview header and footer slide away while scrolling down and return when scrolling up; the desktop aside keeps its chrome visible
- on phones, dragging right from the left screen edge drags the fullscreen preview with the finger and reveals the feed underneath; releasing past about 30% of the width (or a quick flick) closes the preview and returns to the same feed position, while a shorter drag springs back. Vertical drags from the edge still scroll the article, the gesture is ignored while the `…` dialog is open, and rotating cancels it. In a regular Safari tab the system edge-back gesture may take precedence; the app gesture is reliable in the installed PWA
- preview is available on every device; phones open the reader view full-screen, and the Reading option is always shown in Reader settings

### Bookmarks
Expand Down
4 changes: 2 additions & 2 deletions core/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export function renderIndexPage(data: PageData): string {
<link rel="shortcut icon" href="/favicon.svg?v=8" type="image/svg+xml" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png?v=8" />
<script src="/static/theme-init.js?v=1"></script>
<link rel="stylesheet" href="/static/style.css?v=127" />
<script src="/static/app.js?v=104" defer></script>
<link rel="stylesheet" href="/static/style.css?v=128" />
<script src="/static/app.js?v=105" defer></script>
</head>
<body data-app-version="${escapeHtml(data.appVersion)}">
<header class="shell page-header">
Expand Down
2 changes: 1 addition & 1 deletion docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The optional article preview is served by `GET /api/preview?url=…`.
- `core/preview.ts` additionally rejects non-http(s) schemes, credentials, non-standard ports, and loopback/private/link-local hosts, and re-checks the final URL after redirects.
- Article fetches time out after 10 seconds and read at most 400 KB. The extractor removes scripts/navigation/footer noise and returns structured text segments, image blocks, and table blocks only — upstream HTML is never returned or injected. Text renders with `textContent`/DOM nodes; inline anchors are limited to URLs that pass the same public http(s) validation, and image URLs are re-validated before the browser loads them directly with `loading="lazy"` and `referrerpolicy="no-referrer"`.
- Image blocks may include a `figcaption`-derived caption and intrinsic width/height to reserve layout space. Known avatar/profile-image hosts and paths, SVG wordmarks, and common badge hosts are dropped before the image cap so author-list and README chrome doesn't displace article figures. Table blocks carry a header flag and capped rows/cells. The response also includes byline, publication date, and an estimated reading time. For Hugging Face paper URLs the extractor starts at the Abstract section, then appends the paper's resource links and citing model, dataset, space, and collection lists while excluding community comment chrome; GitHub titles drop the site prefix. The preview and card `…` dialogs expose a stored Hacker News comments URL for HN items; other sources omit it.
- The client highlights the card matching the open preview and provides previous/next navigation over the currently rendered card list, skipping duplicate or unusable cards. When the last rendered card is previewed, Next remains enabled if another page exists and appends it before advancing. On mobile the open panel pins the body scroll position (and reapplies it after rotation), the glass header/footer auto-hide on scroll down and return on scroll up, and the `theme-color` tint switches to the panel surface while the panel covers the viewport.
- The client highlights the card matching the open preview and provides previous/next navigation over the currently rendered card list, skipping duplicate or unusable cards. When the last rendered card is previewed, Next remains enabled if another page exists and appends it before advancing. On mobile the open panel pins the body scroll position (and reapplies it after rotation), the glass header/footer auto-hide on scroll down and return on scroll up, and the `theme-color` tint switches to the panel surface while the panel covers the viewport. A left-edge rightward drag follows the finger and reveals the preserved feed position underneath; releasing past a distance/velocity threshold slides the panel away and closes it, while a shorter drag springs back. Vertical edge drags remain native scrolling and the gesture is inactive while the `…` dialog is open.
- Card host rows keep the optional bookmark toggle and a more-actions dialog trigger. The dialog exposes Share, the stored Hacker News comments URL when present, and Open source; choosing an action does not open the preview.
- Successful previews are edge-cached for 30 minutes; the Cache API is a no-op in local `wrangler dev`.

Expand Down
1 change: 1 addition & 0 deletions docs/RUNBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Before considering any `core/render.ts` change done:
- card host-row actions: the `…` dialog shows Share, Comments only for Hacker News, and Open source, and every action works without opening the preview
- Share uses the native share sheet on supporting browsers and copies the article link otherwise; verify it from both the card `…` dialog and the preview `…` dialog
- on a viewport 900px or narrower the preview panel is fullscreen and its footer places the bookmark, `…`, and Close after Previous/Next in both orientations; above 900px the panel is an aside and those controls stay in its header. The `…` dialog is headed by the article title with its source icon/host and a close button, with full-width action rows over the standard backdrop; it closes on X, backdrop click/Escape and leaves the preview open
- on a phone, a rightward drag from the left screen edge moves the fullscreen preview with the finger and closes it past the distance/velocity threshold, returning to the previous feed position; a short drag springs back, vertical edge drags still scroll the article, and the gesture is ignored while the `…` dialog is open
- in an installed iOS PWA in phone portrait, both the page header and the preview panel header sit below the iOS 26 status-bar blur
- opening the preview on iOS portrait updates the status bar/toolbar tint to the panel surface color, so the strip above the panel is not the page background color and the panel header is not visibly blurred
- in iPhone landscape, the header, feed cards, filters, and full-screen preview content stay inside the left/right safe-area insets (no notch/Dynamic Island overlap)
Expand Down
6 changes: 3 additions & 3 deletions web-static/service-worker.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const SHELL_CACHE = "reader-shell-v138";
const SHELL_CACHE = "reader-shell-v139";
const ITEMS_CACHE = "reader-items-v24";
const CORE_ASSETS = [
"/",
"/static/style.css?v=127",
"/static/app.js?v=104",
"/static/style.css?v=128",
"/static/app.js?v=105",
"/static/theme-init.js?v=1",
"/static/source-icons/hackernews.svg",
"/static/source-icons/github.svg",
Expand Down
203 changes: 203 additions & 0 deletions web-static/static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,209 @@
if (previewScroll) previewScroll.scrollTop = scrollTop;
}

// Fullscreen preview: swipe in from the left screen edge and drag right to
// dismiss it, iOS back-gesture style. The panel follows the finger over the
// feed at its preserved scroll position; releasing past a distance or
// velocity threshold closes it, otherwise it springs back. Touch handling
// lives here rather than in CSS touch-action so wide tables keep horizontal
// panning inside the preview.
const previewSwipeEdgeWidth = 24;
const previewSwipeSlop = 8;
const previewSwipeCloseRatio = 0.3;
const previewSwipeMinDistance = 96;
const previewSwipeFlickVelocity = 0.5;
let previewSwipeTouchId = null;
let previewSwipeActive = false;
let previewSwipeClosing = false;
let previewSwipeStartX = 0;
let previewSwipeStartY = 0;
let previewSwipeOffset = 0;
let previewSwipeSamples = [];
let previewSwipeClickGuard = 0;
let previewSwipeCleanupTimer = 0;
let previewSwipeCloseToken = 0;

function resetPreviewSwipeState() {
previewSwipeCloseToken += 1;
previewSwipeClosing = false;
previewSwipeTouchId = null;
previewSwipeActive = false;
previewSwipeStartX = 0;
previewSwipeStartY = 0;
previewSwipeOffset = 0;
previewSwipeSamples = [];
window.clearTimeout(previewSwipeCleanupTimer);
if (!previewPanel) return;
previewPanel.classList.remove("is-preview-swiping");
previewPanel.style.removeProperty("pointer-events");
previewPanel.style.removeProperty("transition");
previewPanel.style.removeProperty("transform");
}

const springBackPreviewSwipe = () => {
if (!previewPanel) return;
previewPanel.style.transition =
"transform 260ms cubic-bezier(0.22, 1, 0.36, 1)";
previewPanel.style.transform = "";
window.clearTimeout(previewSwipeCleanupTimer);
previewSwipeCleanupTimer = window.setTimeout(() => {
previewPanel.classList.remove("is-preview-swiping");
previewPanel.style.removeProperty("transition");
}, 300);
};

const previewSwipeVelocity = () => {
if (previewSwipeSamples.length < 2) return 0;
const first = previewSwipeSamples[0];
const last = previewSwipeSamples[previewSwipeSamples.length - 1];
const elapsed = last.time - first.time;
return elapsed > 0 ? (last.x - first.x) / elapsed : 0;
};

function startPreviewSwipe(event) {
if (!previewPanel || previewSwipeClosing) return;
if (!mobilePreviewMedia.matches) return;
if (previewPanel.classList.contains("is-hidden")) return;
if (previewActionsDialog?.open) return;
if (event.touches.length !== 1) return;
const touch = event.touches[0];
const left = previewPanel.getBoundingClientRect().left;
if (touch.clientX - left > previewSwipeEdgeWidth) return;
previewSwipeTouchId = touch.identifier;
previewSwipeActive = false;
previewSwipeStartX = touch.clientX;
previewSwipeStartY = touch.clientY;
previewSwipeOffset = 0;
previewSwipeSamples = [{ x: touch.clientX, time: performance.now() }];
}

function finishPreviewSwipe(cancelled) {
previewSwipeTouchId = null;
const wasActive = previewSwipeActive;
const offset = previewSwipeOffset;
// Drop samples from before a pause so holding still before release does
// not register as a flick.
const releaseTime = performance.now();
previewSwipeSamples = previewSwipeSamples.filter(
(sample) => releaseTime - sample.time <= 100,
);
const velocity = previewSwipeVelocity();
previewSwipeActive = false;
previewSwipeOffset = 0;
previewSwipeSamples = [];
if (!wasActive) return;
previewSwipeClickGuard = performance.now() + 350;

const paneWidth = previewPanel.clientWidth || window.innerWidth;
const threshold = Math.max(
previewSwipeMinDistance,
paneWidth * previewSwipeCloseRatio,
);
const shouldClose =
!cancelled &&
(offset >= threshold ||
(offset > previewSwipeEdgeWidth &&
velocity >= previewSwipeFlickVelocity));
if (!shouldClose) {
springBackPreviewSwipe();
return;
}

previewSwipeClosing = true;
const token = ++previewSwipeCloseToken;
previewPanel.style.transition =
"transform 240ms cubic-bezier(0.32, 0.72, 0, 1)";
previewPanel.style.transform = "translate3d(100%, 0, 0)";
previewPanel.style.pointerEvents = "none";
window.setTimeout(() => {
if (token !== previewSwipeCloseToken) return;
closeArticlePreview();
}, 240);
}

function movePreviewSwipe(event) {
if (previewSwipeTouchId === null) return;
if (event.touches.length !== 1) {
finishPreviewSwipe(true);
return;
}
const touch = event.touches[0];
if (touch.identifier !== previewSwipeTouchId) return;
const dx = touch.clientX - previewSwipeStartX;
const dy = touch.clientY - previewSwipeStartY;

if (!previewSwipeActive) {
if (Math.abs(dx) < previewSwipeSlop && Math.abs(dy) < previewSwipeSlop) {
return;
}
// Vertical intent belongs to the preview's own scrolling, and the
// gesture only dismisses, so leftward drags are ignored as well.
if (Math.abs(dy) >= Math.abs(dx) || dx <= 0) {
previewSwipeTouchId = null;
previewSwipeSamples = [];
return;
}
previewSwipeActive = true;
previewSwipeClickGuard = performance.now() + 350;
previewPanel.classList.add("is-preview-swiping");
previewPanel.style.transition = "none";
}

event.preventDefault();
previewSwipeOffset = Math.max(0, dx);
previewPanel.style.transform = `translate3d(${previewSwipeOffset}px, 0, 0)`;

const now = performance.now();
previewSwipeSamples.push({ x: touch.clientX, time: now });
while (
previewSwipeSamples.length > 1 &&
now - previewSwipeSamples[0].time > 100
) {
previewSwipeSamples.shift();
}
}

function endPreviewSwipe(event) {
if (previewSwipeTouchId === null) return;
const ended = Array.from(event.changedTouches ?? []).some(
(touch) => touch.identifier === previewSwipeTouchId,
);
if (!ended) return;
finishPreviewSwipe(false);
}

// Suppress the synthetic click a drag can leave on an edge control.
const guardPreviewSwipeClick = (event) => {
if (!previewSwipeClickGuard || performance.now() > previewSwipeClickGuard) {
return;
}
previewSwipeClickGuard = 0;
event.preventDefault();
event.stopPropagation();
};

if (previewPanel) {
previewPanel.addEventListener("touchstart", startPreviewSwipe, {
passive: true,
});
previewPanel.addEventListener("touchmove", movePreviewSwipe, {
passive: false,
});
previewPanel.addEventListener("touchend", endPreviewSwipe, {
passive: true,
});
previewPanel.addEventListener(
"touchcancel",
() => finishPreviewSwipe(true),
{ passive: true },
);
previewPanel.addEventListener("click", guardPreviewSwipeClick, true);
mobilePreviewMedia.addEventListener?.("change", resetPreviewSwipeState);
window.addEventListener("orientationchange", resetPreviewSwipeState);
}

const resetPreviewPanel = () => {
resetPreviewSwipeState();
closePreviewActionsDialog();
previewPanel?.classList.add("is-hidden");
currentPreviewItem = null;
Expand Down Expand Up @@ -1822,6 +2024,7 @@
return;
}

resetPreviewSwipeState();
closePreviewActionsDialog();
currentPreviewItem = {
url: normalizeVisitedHref(url),
Expand Down
7 changes: 7 additions & 0 deletions web-static/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2385,6 +2385,13 @@ body.is-dialog-open {
box-shadow: none;
}

/* Edge-swipe dismiss: the panel itself moves, so give it depth against the
feed revealed on the left while the finger drags. */
.preview-panel.is-preview-swiping {
will-change: transform;
box-shadow: -12px 0 28px rgba(0, 0, 0, 0.22);
}

.preview-panel-actions .preview-panel-bookmark {
display: none;
}
Expand Down
Loading