mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-17 12:22:21 +02:00
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>
32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
// Auto-Select hit-testing (Move tool). Walks the layer stack front-to-back
|
|
// and returns the topmost layer whose rendered pixels are opaque at the
|
|
// requested document point. Kept dependency-free so it can run under node
|
|
// for unit tests; the caller injects layer-geometry and pixel sampling.
|
|
|
|
export const AUTO_SELECT_ALPHA_THRESHOLD = 8;
|
|
|
|
export function pickTopmostLayerAt({
|
|
layers,
|
|
point,
|
|
isHidden = () => false,
|
|
isLocked = () => false,
|
|
getOffset = () => ({ x: 0, y: 0 }),
|
|
sampleAlpha,
|
|
} = {}) {
|
|
if (!Array.isArray(layers) || !point || typeof sampleAlpha !== 'function') return null;
|
|
// Front-to-back: the last layer in the array paints on top.
|
|
for (let index = layers.length - 1; index >= 0; index -= 1) {
|
|
const layer = layers[index];
|
|
if (!layer?.visible || layer.kind === 'adjustment' || !layer.canvas) continue;
|
|
if (isHidden(layer)) continue;
|
|
if (isLocked(layer)) continue;
|
|
const offset = getOffset(layer) || { x: 0, y: 0 };
|
|
const x = Math.floor(point.x - offset.x);
|
|
const y = Math.floor(point.y - offset.y);
|
|
if (x < 0 || y < 0 || x >= layer.canvas.width || y >= layer.canvas.height) continue;
|
|
const alpha = sampleAlpha(layer, x, y);
|
|
if (alpha != null && alpha > AUTO_SELECT_ALPHA_THRESHOLD) return layer;
|
|
}
|
|
return null;
|
|
}
|