Initial commit: Luminary photo catalog and RAW editor
Browser-based photo catalog with an optional team server (SQLite + LibRaw). Local database, uploaded photos, build output and dependencies are gitignored. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Tracks the "hold Ctrl while dragging Exposure" clipping preview.
|
||||
*
|
||||
* The slider starts a session on pointer down; the overlay follows the
|
||||
* modifier key for as long as the drag lasts, so Ctrl can be pressed or
|
||||
* released mid-drag. Kept outside React so the pointer listeners are attached
|
||||
* once and the renderer subscription stays cheap.
|
||||
*/
|
||||
|
||||
type Listener = (active: boolean) => void;
|
||||
|
||||
let dragging = false;
|
||||
let active = false;
|
||||
const listeners = new Set<Listener>();
|
||||
|
||||
function emit() {
|
||||
for (const listener of listeners) listener(active);
|
||||
}
|
||||
|
||||
export function clipPreviewActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
export function subscribeClipPreview(listener: Listener) {
|
||||
listeners.add(listener);
|
||||
listener(active);
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
}
|
||||
|
||||
export function beginClipPreview(ctrlHeld: boolean) {
|
||||
dragging = true;
|
||||
active = Boolean(ctrlHeld);
|
||||
emit();
|
||||
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key !== 'Control' && e.key !== 'Meta') return;
|
||||
active = dragging && e.type === 'keydown';
|
||||
emit();
|
||||
};
|
||||
|
||||
const stop = () => {
|
||||
dragging = false;
|
||||
active = false;
|
||||
emit();
|
||||
window.removeEventListener('keydown', onKey, true);
|
||||
window.removeEventListener('keyup', onKey, true);
|
||||
window.removeEventListener('pointerup', stop, true);
|
||||
window.removeEventListener('pointercancel', stop, true);
|
||||
window.removeEventListener('blur', stop);
|
||||
};
|
||||
|
||||
window.addEventListener('keydown', onKey, true);
|
||||
window.addEventListener('keyup', onKey, true);
|
||||
window.addEventListener('pointerup', stop, true);
|
||||
window.addEventListener('pointercancel', stop, true);
|
||||
window.addEventListener('blur', stop);
|
||||
}
|
||||
Reference in New Issue
Block a user