Group local mask shapes into editable components.

A local adjustment is now a list of shapes composited in order (add, subtract,
intersect) instead of a single shape, so dodging and burning can be built from
several brushes, gradients and auto masks without spending layer channels.
Existing edits migrate on load: the flat layer fields become components[0],
keeping geometry, invert, feather and the layer's blend mode unchanged. The
panel gains a shape list with active-shape editing, and the render gate now
asserts a subtract shape clears the group while an intersect keeps it.
This commit is contained in:
2026-11-28 16:09:14 +00:00
parent acf582251f
commit b884616889
10 changed files with 666 additions and 183 deletions
+119 -18
View File
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { ASPECTS, BW_FILTERS, HUE_BANDS, identityCurve, MAX_LOCAL_LAYERS } from '../lib/edits';
import { ASPECTS, BW_FILTERS, HUE_BANDS, identityCurve, MAX_LOCAL_COMPONENTS, MAX_LOCAL_LAYERS } from '../lib/edits';
import { computeAutoEdits, computeAutoWhiteBalance } from '../lib/auto';
import { autoNoiseFor } from '../lib/noiseProfile';
import { clearDenoised, getDenoiseJob, startDenoise } from '../lib/api';
@@ -9,6 +9,7 @@ import type {
Edits,
EventRecord,
HistoryEntry,
LocalComponent,
LocalLayer,
LocalMaskKind,
MetadataPreset,
@@ -1494,6 +1495,10 @@ export function LocalPanel({
set,
activeId,
onSelect,
componentId,
onSelectComponent,
onAddComponent,
onDeleteComponent,
onAdd,
onDelete,
onDuplicate,
@@ -1510,6 +1515,11 @@ export function LocalPanel({
}: PanelSetProps & {
activeId: string | null;
onSelect: (id: string) => void;
/** Shape inside the active layer that the mask controls edit. */
componentId: string | null;
onSelectComponent: (id: string) => void;
onAddComponent: (kind: LocalMaskKind) => void;
onDeleteComponent: (id: string) => void;
onAdd: (kind: LocalMaskKind) => void;
onDelete: (id: string) => void;
onDuplicate: (id: string) => void;
@@ -1527,11 +1537,31 @@ export function LocalPanel({
}) {
const layers = edits.local ?? [];
const active = layers.find((layer) => layer.id === activeId) ?? null;
const shapes = active?.components ?? [];
const shape = shapes.find((component) => component.id === componentId) ?? shapes[0] ?? null;
const patch = (next: Partial<LocalLayer>, label: string) => {
if (!active) return;
set({ local: layers.map((layer) => (layer.id === active.id ? { ...layer, ...next } : layer)) }, label);
};
const patchShape = (next: Partial<LocalComponent>, label: string) => {
if (!active || !shape) return;
set(
{
local: layers.map((layer) =>
layer.id === active.id
? {
...layer,
components: layer.components.map((component) =>
component.id === shape.id ? { ...component, ...next } : component,
),
}
: layer,
),
},
label,
);
};
const adjust = (key: keyof LocalLayer['adjust'], value: number) =>
active && patch({ adjust: { ...active.adjust, [key]: value } }, `Local ${key}`);
const range = (key: keyof LocalLayer['range'], value: number | boolean) =>
@@ -1594,21 +1624,55 @@ export function LocalPanel({
className={`local-item ${layer.id === activeId ? 'on' : ''}`}
onClick={() => onSelect(layer.id)}
>
<span className="local-icon">{LOCAL_ICON[layer.kind]}</span>
<span className="local-icon">{LOCAL_ICON[layer.components[0]?.kind ?? 'brush']}</span>
<span className="local-name">{layer.name}</span>
<span className="local-kind">{layer.kind}</span>
<span className="local-kind">
{layer.components.length > 1
? `${layer.components.length} shapes`
: (layer.components[0]?.kind ?? 'mask')}
</span>
</button>
))}
</div>
{active && (
<div className="local-subhead">Mask shapes</div>
<div className="local-list shapes">
{shapes.map((component, index) => (
<button
key={component.id}
className={`local-item ${component.id === shape?.id ? 'on' : ''}`}
onClick={() => onSelectComponent(component.id)}
>
<span className="local-icon">{LOCAL_ICON[component.kind]}</span>
<span className="local-name">Shape {index + 1}</span>
<span className="local-kind">
{component.mode === 'add' ? component.kind : `${component.kind} · ${component.mode}`}
</span>
</button>
))}
</div>
<div className="btn-row local-add">
{(['brush', 'linear', 'radial'] as const).map((kind) => (
<button
key={kind}
className="btn ghost small"
onClick={() => onAddComponent(kind)}
disabled={shapes.length >= MAX_LOCAL_COMPONENTS}
title="Add a shape to this mask group"
>
+ {LOCAL_ICON[kind]} {kind}
</button>
))}
</div>
{active && shape && (
<>
<div className="btn-row local-actions">
<button
className={`btn ghost small ${maskMode ? 'on' : ''}`}
onClick={onEditMask}
disabled={active.kind === 'raster'}
title={active.kind === 'raster' ? 'Auto masks are generated, not painted' : undefined}
disabled={shape.kind === 'raster'}
title={shape.kind === 'raster' ? 'Auto masks are generated, not painted' : undefined}
>
{maskMode ? 'Done mask' : 'Edit mask'}
</button>
@@ -1620,13 +1684,13 @@ export function LocalPanel({
</button>
</div>
{active.kind === 'raster' && (
{shape.kind === 'raster' && (
<p className="muted small panel-hint">
Auto mask · adjust the feather, invert it, paint it away by adding a brush layer, or regenerate from the buttons above.
</p>
)}
{active.kind === 'brush' && (
{shape.kind === 'brush' && (
<Slider
label="Brush size"
min={8}
@@ -1638,19 +1702,56 @@ export function LocalPanel({
/>
)}
{active.kind !== 'linear' && (
{shape.kind !== 'linear' && (
<Slider
label="Feather"
min={0}
max={100}
value={active.feather}
value={shape.feather}
def={50}
onChange={(v) => patch({ feather: v }, 'Local feather')}
onChange={(v) => patchShape({ feather: v }, 'Local feather')}
format={(v) => `${Math.round(v)}%`}
/>
)}
<div className="local-subhead">Combine</div>
<div className="local-subhead">Shape blend</div>
<div className="btn-row local-modes">
{(['add', 'subtract', 'intersect'] as const).map((mode) => (
<button
key={mode}
className={`chip tiny ${shape.mode === mode ? 'on' : ''}`}
disabled={shapes[0]?.id === shape.id && mode !== 'add'}
title={
shapes[0]?.id === shape.id
? 'The first shape starts the group, so it always adds'
: mode === 'add'
? 'Union this shape into the group'
: mode === 'subtract'
? 'Cut this shape out of the shapes before it'
: 'Keep only where this shape overlaps the shapes before it'
}
onClick={() => patchShape({ mode }, `Shape ${mode}`)}
>
{mode === 'add' ? 'Add' : mode === 'subtract' ? 'Subtract' : 'Intersect'}
</button>
))}
</div>
<div className="btn-row">
<button
className="btn ghost small danger"
onClick={() => onDeleteComponent(shape.id)}
disabled={shapes.length <= 1}
title={
shapes.length <= 1
? 'A layer needs one shape; delete the layer instead'
: 'Remove this shape from the group'
}
>
Delete shape
</button>
</div>
<div className="local-subhead">Layer blend</div>
<div className="btn-row local-modes">
{(['add', 'subtract', 'intersect'] as const).map((mode) => (
<button
@@ -1658,12 +1759,12 @@ export function LocalPanel({
className={`chip tiny ${active.mode === mode ? 'on' : ''}`}
title={
mode === 'add'
? 'Apply this adjustment inside the mask'
? 'Apply this layer inside its mask'
: mode === 'subtract'
? 'Apply it outside this mask, within the layer above'
: 'Apply it only where this mask overlaps the layer above'
? 'Apply it outside its mask, within the layer above'
: 'Apply it only where the mask overlaps the layer above'
}
onClick={() => patch({ mode }, `Mask ${mode}`)}
onClick={() => patch({ mode }, `Layer ${mode}`)}
>
{mode === 'add' ? 'Add' : mode === 'subtract' ? 'Subtract' : 'Intersect'}
</button>
@@ -1823,8 +1924,8 @@ export function LocalPanel({
<div className="btn-row">
<button
className={`btn ghost small ${active.inverted ? 'on' : ''}`}
onClick={() => patch({ inverted: !active.inverted }, 'Invert mask')}
className={`btn ghost small ${shape.inverted ? 'on' : ''}`}
onClick={() => patchShape({ inverted: !shape.inverted }, 'Invert mask')}
>
Invert mask
</button>