Files
odysseus/static/js/editor/tools/quick-select.js
T
pewdiepie-archdaemonandClaude Opus 5.5 5fac693c1c feat(photo-editor): Ajax Image Editor client (Photoshop-parity tools)
Photoshop-parity editor client: layers, selection/masking, brushes,
smart filters, LUT import, Quick Edit, mobile gestures, workspaces,
batch operations, and the service-worker versioning (v978->v1006).

Source: vendor/photocraft (ad1cff44) photo-editor client files, merged
onto upstream/dev (a8c147b2). Conflict resolution documented in
pr_work/A_conflicts.md; editor files taken from vendor/photocraft
(upstream's editor is an earlier snapshot of the same feature).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 11:57:35 +00:00

64 lines
1.5 KiB
JavaScript

// Quick Selection brush — drag to grow a wand-style selection.
// Reuses the existing magic-wand flood fill by re-sampling along the
// stroke; intermediate samples skip the undo snapshot (retune mode) so a
// whole drag collapses to one history entry (taken on begin).
import { selectionModeForEvent } from '../selection-modifiers.js';
export function createQuickSelectTool({
activeLayer,
saveState,
composite,
runMagicWand,
canvasCoords,
brushSize,
syncToolClearIndicators,
}) {
let painting = false;
let last = null;
const modeFor = (event) => selectionModeForEvent(event, 'add');
const sample = (event) => {
const coords = canvasCoords(event);
if (!coords) return;
runMagicWand(coords.x, coords.y, modeFor(event), { retune: true });
};
const begin = (event) => {
const layer = activeLayer();
if (!layer) return;
saveState();
painting = true;
last = null;
sample(event);
const coords = canvasCoords(event);
if (coords) last = coords;
};
const drag = (event) => {
if (!painting) return;
const coords = canvasCoords(event);
if (!coords) return;
const gap = Math.max(3, (brushSize?.() || 24) / 4);
if (last && Math.hypot(coords.x - last.x, coords.y - last.y) < gap) return;
sample(event);
last = coords;
};
const end = () => {
if (!painting) return;
painting = false;
last = null;
composite();
syncToolClearIndicators?.();
};
const cancel = () => {
painting = false;
last = null;
};
return { begin, drag, end, cancel };
}