mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
/**
|
|
* Interactive behavior for duplicate reports.
|
|
*/
|
|
|
|
import { $, $$ } from './utils/dom';
|
|
|
|
function setupDupeReports() {
|
|
const onion = $<SVGSVGElement>('.onion-skin__image');
|
|
const slider = $<HTMLInputElement>('.onion-skin__slider');
|
|
const swipe = $<SVGSVGElement>('.swipe__image');
|
|
|
|
if (swipe) setupSwipe(swipe);
|
|
if (onion && slider) setupOnionSkin(onion, slider);
|
|
}
|
|
|
|
function setupSwipe(swipe: SVGSVGElement) {
|
|
const [ clip, divider ] = $$<SVGRectElement>('#clip rect, #divider', swipe);
|
|
const { width } = swipe.viewBox.baseVal;
|
|
|
|
function moveDivider({ clientX }: MouseEvent) {
|
|
// Move center to cursor
|
|
const rect = swipe.getBoundingClientRect();
|
|
const newX = (clientX - rect.left) * (width / rect.width);
|
|
|
|
divider.setAttribute('x', newX.toString());
|
|
clip.setAttribute('width', newX.toString());
|
|
}
|
|
|
|
swipe.addEventListener('mousemove', moveDivider);
|
|
}
|
|
|
|
function setupOnionSkin(onion: SVGSVGElement, slider: HTMLInputElement) {
|
|
const target = $<HTMLImageElement>('#target', onion);
|
|
|
|
function setOpacity() {
|
|
if (target) {
|
|
target.setAttribute('opacity', slider.value);
|
|
}
|
|
}
|
|
|
|
setOpacity();
|
|
slider.addEventListener('input', setOpacity);
|
|
}
|
|
|
|
export { setupDupeReports };
|