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
140 changes: 140 additions & 0 deletions src/site/components/CompareSlider.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
/**
* Draggable before/after split. Same read as the editor preview: the original
* stays on the left of the line, the result on the right, and the handle tracks
* the pointer. No network and no extra packages — the stills are the ones already
* shipped in public/site/results/.
*/
import type { Still } from '../results'

interface Props {
before: Still
after: Still
/** Accessible name for the handle, in the page language. */
label: string
}

const { before, after, label } = Astro.props
const ratio = `${before.width} / ${before.height}`
---

<div
class:list={['compare', after.transparent && 'compare--alpha']}
data-compare
style={`--pos: 50%; --ratio: ${ratio};`}
>
<div class="compare__frame">
<picture class="compare__layer compare__layer--before">
<source srcset={before.avif} type="image/avif" />
<img
src={before.src}
width={before.width}
height={before.height}
alt={before.alt}
draggable="false"
loading={before.priority ? 'eager' : 'lazy'}
decoding={before.priority ? 'sync' : 'async'}
/>
</picture>
<picture class="compare__layer compare__layer--after">
<source srcset={after.avif} type="image/avif" />
<img
src={after.src}
width={after.width}
height={after.height}
alt={after.alt}
draggable="false"
loading={after.priority ? 'eager' : 'lazy'}
decoding={after.priority ? 'sync' : 'async'}
/>
</picture>
</div>
<div
class="compare__handle"
data-compare-handle
role="slider"
tabindex="0"
aria-label={label}
aria-orientation="horizontal"
aria-valuemin="0"
aria-valuemax="100"
aria-valuenow="50"
aria-valuetext={`${before.label} 50%, ${after.label} 50%`}
data-before={before.label}
data-after={after.label}
>
<span class="compare__label compare__label--before">{before.label}</span>
<span class="compare__label compare__label--after">{after.label}</span>
<span class="compare__grip" aria-hidden="true"></span>
</div>
</div>

<script>
const KEY_STEP = 2
const PAGE_STEP = 10

function setPos(root: HTMLElement, percent: number) {
const pct = Math.min(100, Math.max(0, percent))
root.style.setProperty('--pos', `${pct}%`)
const handle = root.querySelector<HTMLElement>('[data-compare-handle]')
if (!handle) return
const rounded = Math.round(pct)
const before = handle.dataset.before ?? ''
const after = handle.dataset.after ?? ''
handle.setAttribute('aria-valuenow', String(rounded))
handle.setAttribute('aria-valuetext', `${before} ${rounded}%, ${after} ${100 - rounded}%`)
}

function pointerPercent(root: HTMLElement, clientX: number) {
const rect = root.getBoundingClientRect()
if (rect.width <= 0) return 50
return ((clientX - rect.left) / rect.width) * 100
}

for (const root of document.querySelectorAll<HTMLElement>('[data-compare]')) {
const handle = root.querySelector<HTMLElement>('[data-compare-handle]')
if (!handle) continue

handle.addEventListener('pointerdown', (event) => {
if (event.button !== 0) return
handle.setPointerCapture(event.pointerId)
setPos(root, pointerPercent(root, event.clientX))
})

handle.addEventListener('pointermove', (event) => {
if (!handle.hasPointerCapture(event.pointerId)) return
setPos(root, pointerPercent(root, event.clientX))
})

handle.addEventListener('keydown', (event) => {
const current = Number(handle.getAttribute('aria-valuenow') ?? '50')
let next: number | null = null
switch (event.key) {
case 'ArrowLeft':
case 'ArrowDown':
next = current - (event.shiftKey ? PAGE_STEP : KEY_STEP)
break
case 'ArrowRight':
case 'ArrowUp':
next = current + (event.shiftKey ? PAGE_STEP : KEY_STEP)
break
case 'PageDown':
next = current - PAGE_STEP
break
case 'PageUp':
next = current + PAGE_STEP
break
case 'Home':
next = 0
break
case 'End':
next = 100
break
default:
return
}
event.preventDefault()
setPos(root, next)
})
}
</script>
4 changes: 4 additions & 0 deletions src/site/landing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const landing = {
results: {
h2: 'Before and after, from the sample photos',
lead: 'These are the sample photos shipped with the editor, processed with the same code. Nothing here is a mockup.',
hint: 'Drag the handle to compare. With the handle focused, the arrow keys move it too.',
compareLabel: 'Compare before and after',
},
facts: ['Free and open source', 'Presets, XMP and LUTs', 'Nothing uploaded'],
video: {
Expand Down Expand Up @@ -79,6 +81,8 @@ export const landing = {
results: {
h2: 'Antes y después, con las fotos de ejemplo',
lead: 'Son las fotos de ejemplo que trae el editor, procesadas con el mismo código. No hay maquetas.',
hint: 'Arrastra el control para comparar. Con el control enfocado, las flechas también lo mueven.',
compareLabel: 'Comparar antes y después',
},
facts: ['Gratis y de código abierto', 'Presets, XMP y LUTs', 'Sin subir nada'],
video: {
Expand Down
8 changes: 8 additions & 0 deletions src/site/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export interface ResultExample {
title: string
caption: string
shots: Still[]
/**
* Home before/after showcase. Tool pages still pick the example up through
* `exampleForTool`, so `false` only hides it on `/` and `/es`.
*/
home?: boolean
}

const PATHS: Record<Lang, Record<string, string>> = {
Expand Down Expand Up @@ -130,6 +135,9 @@ export function resultExamples(lang: Lang): ResultExample[] {
{
toolKey: 'remove-objects',
href: href['remove-objects'],
// The heal still reads as a smudge at landing size, so the home showcase skips it.
// The remove-objects tool pages keep this pair, including the still files.
home: false,
title: en ? 'Person healed out' : 'Persona eliminada con el parche',
caption: en
? 'A crop of public/samples/pagoda.jpg. After is one Heal spot on the person standing on the gravel: brush radius about 53 px on the long edge, copying gravel from 110 px left and 70 px up, then blended by the editor’s Heal code. The brush also reaches the second person, who stands against the eaves, so that edge stays soft. An inpaint of these figures filled the hole with leaves, so this still is the Heal result.'
Expand Down
177 changes: 177 additions & 0 deletions src/site/styles/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,187 @@ a {
margin-top: 48px;
}

.ba-grid {
display: grid;
gap: 40px 24px;
}

.ba-grid > .ba-block + .ba-block {
margin-top: 0;
}

.ba-stack {
margin-top: 48px;
}

@media (min-width: 860px) {
.ba-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
align-items: start;
}

.ba-block--lead {
grid-column: 1 / -1;
}
}

.ba-block h3 {
margin-bottom: 12px;
}

/* Landing compare handle. Mirrors the editor split divider (src/index.css .split-divider):
white line, round grip, before on the left of the line and after on the right. */

.compare {
--pos: 50%;
position: relative;
aspect-ratio: var(--ratio, 3 / 2);
overflow: hidden;
border-radius: 12px;
border: 1px solid var(--line-strong);
background: var(--bg-panel);
user-select: none;
-webkit-user-select: none;
}

.compare__frame {
position: absolute;
inset: 0;
overflow: hidden;
border-radius: inherit;
}

.compare--alpha .compare__frame {
background-color: #121816;
background-image:
linear-gradient(45deg, #243028 25%, transparent 25%),
linear-gradient(-45deg, #243028 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, #243028 75%),
linear-gradient(-45deg, transparent 75%, #243028 75%);
background-size: 20px 20px;
background-position:
0 0,
0 10px,
10px -10px,
-10px 0;
}

.compare__layer {
position: absolute;
inset: 0;
margin: 0;
display: block;
}

.compare__layer--before {
/* 1px under the after layer so a subpixel seam never shows the page background. */
clip-path: inset(0 calc(100% - var(--pos) - 1px) 0 0);
}

.compare__layer--after {
clip-path: inset(0 0 0 var(--pos));
}

.compare__layer img {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
max-width: none;
object-fit: cover;
object-position: center;
border: 0;
border-radius: 0;
background: transparent;
pointer-events: none;
-webkit-user-drag: none;
}

.compare__handle {
position: absolute;
z-index: 1;
top: 0;
bottom: 0;
left: var(--pos);
width: 44px;
margin: 0;
padding: 0;
transform: translateX(-50%);
border: 0;
background: transparent;
color: inherit;
cursor: ew-resize;
touch-action: none;
}

.compare__handle::before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 50%;
width: 2px;
transform: translateX(-50%);
background: #fff;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.compare__handle:focus {
outline: none;
}

.compare__handle:focus-visible .compare__grip {
outline: 2px solid var(--accent);
outline-offset: 3px;
}

.compare__grip {
position: absolute;
top: 50%;
left: 50%;
width: 26px;
height: 26px;
transform: translate(-50%, -50%);
border-radius: 999px;
background: #fff;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

.compare__grip::before {
content: '‹ ›';
position: absolute;
inset: 0;
display: grid;
place-items: center;
font-family: var(--font-ui);
font-size: 0.8rem;
font-weight: 700;
color: #222;
letter-spacing: 0.1em;
}

.compare__label {
position: absolute;
top: 0.6rem;
padding: 0.15rem 0.45rem;
border-radius: 999px;
background: rgba(12, 16, 14, 0.7);
font-family: var(--font-ui);
font-size: 0.64rem;
letter-spacing: 0.06em;
text-transform: uppercase;
color: #fff;
white-space: nowrap;
}

.compare__label--before {
right: calc(50% + 20px);
}

.compare__label--after {
left: calc(50% + 20px);
}

.ba-block h3 a {
color: inherit;
text-underline-offset: 3px;
Expand Down
Loading
Loading