0
2
next: scrolling, a fling's stop or a swipe opens no gallery, nor a photo's tap
Only what this pull adds. It is built on The next grain.social and grain-ios, drawn by HUD.
vendor/hud/ios/HUDKit/Sources/HUDKit/Tree/ResolvedMedia.swift+9−5
| @@ -17,9 +17,10 @@ import SwiftUI | ||
/// lightbox at that picture. With `carousel`, as a photo app's feed shows a | ||
/// gallery: one picture at a time, swiped between a picture at a time, each | ||
/// whole in one frame shaped for them all (the tallest's, no taller than | ||
/// 9:16), dots over its foot saying which, and no lightbox: a tap is the | ||
/// item's, which opens the gallery; with `zoom` (the gallery's own screen), | ||
/// a tap opens that picture in the lightbox. With `bleed` they reach the edges of | ||
/// 9:16), dots over its foot saying which, and no lightbox: a tap opens | ||
/// nothing, not the item holding it, as a tap on a photo in Grain's feeds; | ||
/// with `zoom` (the gallery's own screen), a tap opens that picture in the | ||
/// lightbox. With `bleed` they reach the edges of | ||
/// what holds them, square, as a photo app's feed draws them (`ImageBox`'s); | ||
/// with `showAlt`, each with alt text keeps it behind an ALT badge; each with | ||
/// `info` (its camera), its lines behind an ⓘ in the other corner. | ||
| @@ -127,7 +128,7 @@ struct ResolvedGallery: View { | ||
| ||
/// One picture at a time in one frame, swiped a picture at a time, the | ||
/// one after the one showing loaded ahead, so a swipe shows it at once; | ||
/// the dots over its foot; no lightbox, a tap being the item's. Under it, the | ||
/// the dots over its foot; no lightbox, a tap opening nothing. Under it, the | ||
/// info of the picture showing (its camera), swapped as it is swiped, as | ||
/// Grain draws it: as many lines as the most any picture has, so it keeps | ||
/// its height between pictures with info, and nothing for one without. | ||
| @@ -199,6 +200,9 @@ struct ResolvedGallery: View { | ||
} | ||
} | ||
.clipShape(.rect(cornerRadius: bleed ? 0 : 4, style: .continuous)) | ||
// A tap on it is its own, never the item's holding it: it opens nothing but a picture that zooms. | ||
.contentShape(.rect) | ||
.onTapGesture {} | ||
} | ||
} | ||
| ||
| @@ -211,7 +215,7 @@ struct CarouselDot: Equatable, Sendable { | ||
| ||
extension View { | ||
/// A carousel's picture that opens in the lightbox (`zoom`) as tapped; | ||
/// with none, as it is, a tap going to what holds it. | ||
/// with none, as it is. | ||
@ViewBuilder | ||
fileprivate func zoomable(_ open: (@MainActor () -> Void)?) -> some View { | ||
if let open { | ||
vendor/hud/web/renderer/src/tree/List.svelte+8−14
| @@ -2,6 +2,7 @@ | ||
import { opens, tagOf } from '../open'; | ||
import { setSlot, sizeOf, slotOf, tileSlot } from '../slot'; | ||
import { FRAMED, ListWindow } from '../view/window'; | ||
import { strays } from '../view/taps'; | ||
import { getTreeContext, opener, stamp, unhosted } from './context'; | ||
import Node from './Node.svelte'; | ||
import type { UiListProps, UiNode } from './types'; | ||
| @@ -9,7 +10,10 @@ | ||
// `List`: its items, each its parts, as rows, cards, a grid, inline, or | ||
// a strip that scrolls sideways (`style`). An item that opens | ||
// something opens it when clicked anywhere but on a link or button of | ||
// its own; one its feed is told of is watched for being seen, when the | ||
// its own, or on what swipes (a feed card's carousel), whose taps are its | ||
// own, as Grain's apps take a tap on a feed's photo; a touch that moved, | ||
// or that stopped the list's scroller moving, opens nothing | ||
// (../view/taps.ts). One its feed is told of is watched for being seen, when the | ||
// app asks to know (../view/seen.ts), and its feed told it was opened | ||
// (the app's to do, from the report its call comes with); of `pages`, | ||
// it opens with every item's call, for the app's pager of them. An empty list | ||
| @@ -59,11 +63,6 @@ | ||
called = true; | ||
void tree.onaction('call', { method: shown.method, service: shown.service, input: stamp(shown.input, new Date().toISOString()) }).catch(() => undefined); | ||
}); | ||
/** A tap on what swipes inside an item that opens (a feed card's carousel), not on its own buttons, opens the item; a swipe scrolls it and is no click. */ | ||
function tapThrough(event: MouseEvent, run: () => void) { | ||
const at = event.target as Element; | ||
if (at.closest('[data-swipes]') && !at.closest('a, button, input, audio, video, details, summary')) run(); | ||
} | ||
</script> | ||
| ||
{#if items.length === 0} | ||
| @@ -86,6 +85,7 @@ | ||
style:--gap={style === 'grid' ? GRID_GAP : undefined} | ||
style:--columns={style === 'grid' ? columns : undefined} | ||
{@attach windowed ? win.attach : undefined} | ||
{@attach strays} | ||
> | ||
{#each items as item, i (i)} | ||
{@const idle = windowed && win.idle.has(i)} | ||
| @@ -105,9 +105,7 @@ | ||
{#if open} | ||
<svelte:element this={tagOf(open)} {...opens(open)} class="open" aria-label={open.label}></svelte:element> | ||
{/if} | ||
{@const run = open?.run} | ||
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions (the item's own open button is its keyboard's and screen reader's way in) --> | ||
<div class="content" onclick={run ? (event) => tapThrough(event, run) : undefined}> | ||
<div class="content"> | ||
{#each item.k ?? [] as child, j (j)}<Node node={child} />{/each} | ||
</div> | ||
{/if} | ||
| @@ -411,12 +409,8 @@ | ||
pointer-events: none; | ||
} | ||
| ||
/* Its own controls take the pointer, and what swipes (a carousel), which a drag scrolls and a tap opens the item through. */ | ||
/* Its own controls take the pointer, and what swipes (a carousel), which a drag scrolls. */ | ||
.openable > .content :global(:is(a, button, input, audio, video, details, summary, [data-swipes])) { | ||
pointer-events: auto; | ||
} | ||
| ||
.openable > .content :global([data-swipes]) { | ||
cursor: pointer; | ||
} | ||
</style> | ||
vendor/hud/web/renderer/src/view/taps.tsnew+65−0
| @@ -0,0 +1,65 @@ | ||
// A tap is a touch that stays put on something still. A click that ends a | ||
// touch which moved more than a few pixels, or that came down within a | ||
// moment of what holds a list scrolling (a tap that stops a fling, which a | ||
// phone's browser may end as a click on whatever scrolled under it), is no | ||
// tap: `strays`, on a list, drops it before it reaches the item, its link or | ||
// its buttons. A mouse's clicks and a keyboard's are left as they are. Its | ||
// listeners are the browser's alone: attached as a list is, never on a server. | ||
| ||
/** How far a touch may move and still be a tap, in CSS pixels. */ | ||
const SLOP = 10; | ||
/** How long after a scroller moved a touch on it is still taken as stopping it. */ | ||
const SETTLE = 300; | ||
| ||
/** The touch last put down: where, when, and whether it has moved past the slop or been taken for a scroll. */ | ||
let down: { x: number; y: number; at: number; touch: boolean; moved: boolean } | null = null; | ||
/** When each scroller last moved, by its event's target (the document for the page's own). */ | ||
const scrolled = new WeakMap<EventTarget, number>(); | ||
let listening = false; | ||
| ||
function listen() { | ||
if (listening) return; | ||
listening = true; | ||
const options = { capture: true, passive: true }; | ||
window.addEventListener( | ||
'pointerdown', | ||
(event) => { | ||
if (event.isPrimary) down = { x: event.clientX, y: event.clientY, at: event.timeStamp, touch: event.pointerType !== 'mouse', moved: false }; | ||
}, | ||
options | ||
); | ||
window.addEventListener( | ||
'pointermove', | ||
(event) => { | ||
if (down?.touch && event.isPrimary && Math.hypot(event.clientX - down.x, event.clientY - down.y) > SLOP) down.moved = true; | ||
}, | ||
options | ||
); | ||
// The browser took the touch for a scroll. | ||
window.addEventListener('pointercancel', () => down && (down.moved = true), options); | ||
window.addEventListener('scroll', (event) => event.target && scrolled.set(event.target, event.timeStamp), options); | ||
} | ||
| ||
/** Whether `event`, a click in `list`, ends a touch that was no tap. */ | ||
function stray(list: Element, event: MouseEvent): boolean { | ||
// A keyboard's click (or a script's) has no press count. | ||
if (!down?.touch || event.detail === 0) return false; | ||
if (down.moved || Math.hypot(event.clientX - down.x, event.clientY - down.y) > SLOP) return true; | ||
for (let at: Node | null = list; at; at = at.parentNode) { | ||
const moved = scrolled.get(at); | ||
if (moved !== undefined && moved > down.at - SETTLE) return true; | ||
} | ||
return false; | ||
} | ||
| ||
/** An attachment: a click in `list` that ends no tap is dropped, the link it landed on not followed. */ | ||
export function strays(list: HTMLElement) { | ||
listen(); | ||
const drop = (event: MouseEvent) => { | ||
if (!stray(list, event)) return; | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
}; | ||
list.addEventListener('click', drop, true); | ||
return () => list.removeEventListener('click', drop, true); | ||
} | ||
vendor/hud/web/renderer/src/Covers.svelte+5−3
| @@ -25,6 +25,7 @@ | ||
<script lang="ts"> | ||
import CoverCard from './CoverCard.svelte'; | ||
import CoverTile from './CoverTile.svelte'; | ||
import { strays } from './view/taps'; | ||
| ||
// Cover cards in a grid, such as an account's photo galleries or albums: | ||
// two across in a narrow frame, more as it widens. As `tiles`, square | ||
| @@ -32,21 +33,22 @@ | ||
// more as it widens, reaching the edges of what holds them where it says | ||
// how far (`--hud-bleed`), as a list's rows do. With `min`, a CSS | ||
// width, none narrower than it, as many across as fit; with `columns`, | ||
// at most that many across, sharing the line however wide it is. | ||
// at most that many across, sharing the line however wide it is. A touch | ||
// that moved, or stopped the page scrolling, opens nothing (./view/taps.ts). | ||
let { covers, tiles = false, min, columns }: { covers: Cover[]; tiles?: boolean; min?: string; columns?: number } = $props(); | ||
</script> | ||
| ||
{#if covers.length === 0} | ||
<p class="empty">Nothing here yet.</p> | ||
{:else if tiles} | ||
<ul class="tiles" class:sized={min !== undefined} class:capped={columns !== undefined} style:--min={min} style:--columns={columns}> | ||
<ul class="tiles" class:sized={min !== undefined} class:capped={columns !== undefined} style:--min={min} style:--columns={columns} {@attach strays}> | ||
{#each covers as cover, i (i)} | ||
<li><CoverTile {cover} name={cover.title || `Gallery ${i + 1} of ${covers.length}`} /></li> | ||
{/each} | ||
</ul> | ||
{:else} | ||
<div class="frame"> | ||
<ul class="grid" class:capped={columns !== undefined} style:--card={min} style:--columns={columns}> | ||
<ul class="grid" class:capped={columns !== undefined} style:--card={min} style:--columns={columns} {@attach strays}> | ||
{#each covers as cover, i (i)} | ||
<li><CoverCard {cover} /></li> | ||
{/each} | ||
vendor/hud/web/renderer/src/Gallery.svelte+5−5
| @@ -24,10 +24,10 @@ | ||
// before the image arrives, so nothing moves as they load; a carousel's | ||
// frame is one shape for all, its narrowest picture's but no narrower | ||
// than 9:16, each picture whole in it. One with a full size opens the set | ||
// in a lightbox at it, but in a carousel, whose tap is what holds it's (a | ||
// feed's gallery opens), unless `zoom` (a gallery's own screen); its | ||
// strip is marked `data-swipes`, so a list item that opens takes its | ||
// swipes as a scroll and its taps as the item's. With | ||
// in a lightbox at it, but in a carousel, whose tap opens nothing (as a | ||
// tap on a photo in Grain's feeds), unless `zoom` (a gallery's own | ||
// screen); its strip is marked `data-swipes`, so a list item that opens | ||
// leaves its swipes and taps to it. With | ||
// `bleed`, the gallery reaches past the padding | ||
// of what holds it, its pictures square-cornered, as an Image with bleed | ||
// does; with `showAlt`, each picture with alt text has "ALT" in its corner; | ||
| @@ -122,7 +122,7 @@ | ||
{#if style === 'carousel' && i > reached + 1} | ||
<!-- Not near yet: its place alone, its frame's shape. --> | ||
{:else if item.full && (style !== 'carousel' || zoom)} | ||
<!-- A carousel's tap is what holds it's (a feed's gallery opens) unless it zooms: then it opens the lightbox. --> | ||
<!-- A carousel's tap opens nothing unless it zooms: then it opens the lightbox. --> | ||
<button type="button" class="open" aria-label="Open {label}" onclick={() => (open = i)}> | ||
<Picture src={item.src} alt={label} {fit} {...sized} /> | ||
</button> | ||
vendor/hud/COMMIT+1−1
| @@ -1 +1 @@ | ||
5e18dd439178bbd9dcd8046fe330d5b3f3b5c21e | ||
fa60f262f155a6cd16124aed6fcbc6835757e5c3 | ||