Skip to content

Commit 4bae34d

Browse files
K-ArthurKevin Arthur
andauthored
refactor(engine,editor): replay + adjustment-editor seam splits, ported to origin (#212)
* refactor(editor): split adjustment editor into adjustmentEditors/ modules (Batch B/B-11) Pure code motion: the 2,405-line AdjustmentEditor.tsx becomes a 15-line definition shell (same four named exports, dispatcher body verbatim, CSS import once) plus 24 modules under adjustmentEditors/ (every module <=400 lines; largest 322). LegacyAdjustmentEditor (807 lines) is split into a runtime hook (hooks and hueSaturationRange state stay in the base order) plus four plain phase renderers that keep the switch's case bodies verbatim; the nested LutEditor stays nested so its remount semantics are unchanged. HalftoneEditor (446 lines) becomes a hook, a shell with the S1-S5 JSX verbatim, and an unconditionally mounted advanced phase so the disclosure state lifetime is unchanged. BooleanRow, AdjustmentEditorProps, the family editors, the color converters, and the halftone options each get exactly one home; the original path re-exports the moved public names by name. Proof: refactor-verify --base master --dest .../adjustmentEditors exit 0 {ok:true, baseCount:24, presentCount:33, missing:[], missingExports:[]}; covering suite AdjustmentEditor.test.tsx + AdjustmentPanel.test.tsx 32/32 passed before and after (18/18 direct target, test untouched); direct recursive tsc substitute 22 projects exit 0 with 0 diagnostics; biome clean; audit-health passed; partition proof 2,405 = 50 import-region + 2,307 moved + 23 wrapper + 25 blank lines. Baseline: 0 added, 0 grown, exactly one removed, 945 -> 944; repo map regenerated from the staged tree. No visual surface changed; no e2e/visual/lockfile/manifest/dated-doc changes. (cherry picked from commit 42207fe) * refactor(engine): split Canvas2D replay into replay/ modules (Batch C/C-01) Move the 3,898-line Canvas2D IR replay entry into one module per replay family plus orchestrator phases under packages/engine/src/replay/. The entry keeps its path and public surface as a 371-line orchestrator: the COMPLEXITY header, the four per-replay state bindings (now exported for sibling reads), the 281-line replayIr item pass, the two existing re-export statements and six explicit re-exports of the moved public names. Destination modules (all <=400 lines; largest text.ts 370, typography 355, effect 317, backdrop 312, primitive 290): types, color, isolatedSurface, primitive (paintShapeFill with its per-kind monomorphic switch, traceOutline, traceSquirclePath, paintPathFill, TAU), primitiveBounds, effect, effectDiagnostics, alphaMask, backdrop (shadowOps/alphaStrokeOps, backdrop blur, glass material), backdropCache, fill, fillImage, fillImageMask, table, raster, text (paintText dispatch), textRich, textCanonical, textPath, typography. No dispatch table, no renames, no behavior change. Proof: extraction script asserted 107/107 block assignment, source tiling identity and the 400-line cap before writing; independent verifier vs git show 8082741 reports base statements 107 = after statements 107 + 6 planned re-exports, AST-printer identity missing 0/extra 0, comments 238/238 exact (18 exact-text diffs are biome line-rewrap only); planned edits are export prefixes and 14 inline import() specifier rebases. refactor-verify --base master --dest packages/engine/src/replay exits 0 ({ok:true, baseCount:105,presentCount:105,missing:[],missingExports:[]}) before tests and after biome. Covering set unchanged: replay.test.ts 10/10, replay*.test.ts 29 files/224 tests, __goldens__ 3 files/12 tests, before and after, 0 failures; no test file edited. Direct recursive tsc substitute (20 package tsconfigs + apps/desktop + tests/e2e): 22 projects/0 failures before and after; engine tsc 0; biome clean on 21 files; audit-health exit 0; audit:emoji, audit:committed-imports and the staged commit checkpoint pass. Batch C benchmark: canonical replay bench before/after 100 and 1,000 rects plus an extended same-harness 10k/50k measurement (temporary untracked copy, removed before staging); audit-render-perf --ci before PASS and after two quiet runs PASS with no performance baseline regeneration (one intermediate loaded run flagged only the sub-millisecond 100-node panZoom ratio boundary and was re-verified). Architecture cycle identity delta recorded in SEAM_SPEC.md (engine madge identities 11 -> 19; the pre-existing audit-architecture gate was already red from B-05, no allowlist update). Baseline: added 0, grown 0, removed exactly packages/engine/src/replay.ts, 944 -> 943; report 6,333 scanned / 943 frozen / 0 stale / 0 WIP / 289,430 excess lines. Worktree .worktrees/C-01, branch seam/C/C-01-replay created from seam/B/B-11-adjustment-editor 9c9da88 and rebased onto local master 39e9be0 (HEAD 8082741); local master was not advanced. No visual surface changed; front-end gate not triggered and visual validation not required. (cherry picked from commit 2bf4871) * fix(engine): break replay split cycles without behavior change (cherry picked from commit 7694e7a) --------- Co-authored-by: Kevin Arthur <hello@kevinarthur.design>
1 parent 3bbe2ae commit 4bae34d

57 files changed

Lines changed: 8172 additions & 6013 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/editor/src/components/AdjustmentLayer/AdjustmentEditor.tsx‎

Lines changed: 5 additions & 2395 deletions
Large diffs are not rendered by default.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { Adjustment } from '@varve/scene';
2+
import { renderChannelCases } from './legacy/renderChannelCases';
3+
import { renderEffectCases } from './legacy/renderEffectCases';
4+
import { renderLuminanceCases } from './legacy/renderLuminanceCases';
5+
import { renderTonalCases } from './legacy/renderTonalCases';
6+
import { useLegacyEditorContext } from './legacy/useLegacyEditorContext';
7+
import type { AdjustmentEditorProps } from './types';
8+
9+
export function LegacyAdjustmentEditor(props: AdjustmentEditorProps) {
10+
const context = useLegacyEditorContext(props);
11+
12+
const luminance = renderLuminanceCases(context);
13+
if (luminance !== undefined) return luminance;
14+
15+
const tonal = renderTonalCases(context);
16+
if (tonal !== undefined) return tonal;
17+
18+
const channel = renderChannelCases(context);
19+
if (channel !== undefined) return channel;
20+
21+
const effects = renderEffectCases(context);
22+
if (effects !== undefined) return effects;
23+
24+
const { adjustment } = props;
25+
return (
26+
<div className="adj-editor__slider-row">
27+
<span className="adj-editor__label" style={{ color: 'var(--color-text-muted)' }}>
28+
No editor for {(adjustment as Adjustment).kind}
29+
</span>
30+
</div>
31+
);
32+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import type { Color } from '@varve/engine';
2+
import type { Adjustment } from '@varve/scene';
3+
import { ColorPicker } from '@varve/ui/components/ColorPicker';
4+
import { RangeValueControl } from '../../Inspector/controls/RangeValueControl';
5+
import { BooleanRow } from './controls';
6+
import { colorToManaged, managedToColor } from './managedColor';
7+
import type { AdjustmentEditorProps } from './types';
8+
9+
export function BlackAndWhiteEditor({
10+
adjustment,
11+
onChange,
12+
onEditStart,
13+
onEditEnd,
14+
}: AdjustmentEditorProps) {
15+
const adj = adjustment as import('@varve/scene').BlackAndWhiteAdjustment;
16+
const channels: { key: keyof import('@varve/scene').BlackAndWhiteAdjustment; label: string }[] = [
17+
{ key: 'reds', label: 'Reds' },
18+
{ key: 'yellows', label: 'Yellows' },
19+
{ key: 'greens', label: 'Greens' },
20+
{ key: 'cyans', label: 'Cyans' },
21+
{ key: 'blues', label: 'Blues' },
22+
{ key: 'magentas', label: 'Magentas' },
23+
];
24+
25+
return (
26+
<div className="adj-editor__group">
27+
{channels.map((ch) => (
28+
<div key={ch.key} className="adj-editor__slider-row">
29+
<div className="adj-editor__slider-label">
30+
<span>{ch.label}</span>
31+
<span>{adj[ch.key] as number}</span>
32+
</div>
33+
<RangeValueControl
34+
label={ch.label}
35+
min={-200}
36+
max={300}
37+
value={adj[ch.key] as number}
38+
onChange={(value) => onChange({ [ch.key]: value } as unknown as Partial<Adjustment>)}
39+
/>
40+
</div>
41+
))}
42+
<div className="adj-editor__slider-row">
43+
<div className="adj-editor__slider-label">
44+
<span>Brightness</span>
45+
<span>{adj.brightness}</span>
46+
</div>
47+
<RangeValueControl
48+
label="Brightness"
49+
min={-100}
50+
max={100}
51+
value={adj.brightness}
52+
onChange={(value) => onChange({ brightness: value } as unknown as Partial<Adjustment>)}
53+
/>
54+
</div>
55+
<BooleanRow
56+
label="Preserve Luminosity"
57+
checked={adj.preserveLuminosity}
58+
onChange={(value) =>
59+
onChange({ preserveLuminosity: value } as unknown as Partial<Adjustment>)
60+
}
61+
/>
62+
<BooleanRow
63+
label="Tint"
64+
checked={adj.tintColor !== undefined}
65+
onChange={(value) =>
66+
onChange({
67+
tintColor: value ? ([190, 170, 140, 255] as Color) : undefined,
68+
} as unknown as Partial<Adjustment>)
69+
}
70+
/>
71+
{adj.tintColor && (
72+
<ColorPicker
73+
value={colorToManaged(adj.tintColor)}
74+
onChange={(color) =>
75+
onChange({ tintColor: managedToColor(color) } as unknown as Partial<Adjustment>)
76+
}
77+
onInteractionStart={onEditStart}
78+
onInteractionEnd={onEditEnd}
79+
/>
80+
)}
81+
</div>
82+
);
83+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { mixerRows } from '@varve/engine';
2+
import type { Adjustment } from '@varve/scene';
3+
import { Button, Select } from '@varve/ui';
4+
import { NumberField } from '../../Inspector/controls/NumberField';
5+
import { BooleanRow } from './controls';
6+
import type { AdjustmentEditorProps } from './types';
7+
8+
export function ChannelMixerEditor({ adjustment, onChange }: AdjustmentEditorProps) {
9+
const adj = adjustment as import('@varve/scene').ChannelMixerAdjustment;
10+
const rows = mixerRows(adj),
11+
active = adj.monochrome ? 'red' : adj.outputChannel,
12+
row = rows[active];
13+
const patchRow = (key: keyof typeof row, value: number) => {
14+
const updated = { ...row, [key]: value };
15+
onChange({ ...updated, rows: { ...rows, [active]: updated } } as Partial<Adjustment>);
16+
};
17+
return (
18+
<div className="curve-editor">
19+
<Select
20+
label="Output channel"
21+
value={active}
22+
disabled={adj.monochrome}
23+
options={[
24+
{ value: 'red', label: 'Red' },
25+
{ value: 'green', label: 'Green' },
26+
{ value: 'blue', label: 'Blue' },
27+
]}
28+
onChange={(v) => {
29+
const channel = v as 'red' | 'green' | 'blue';
30+
onChange({ outputChannel: channel, ...rows[channel], rows } as Partial<Adjustment>);
31+
}}
32+
/>
33+
<BooleanRow
34+
label="Monochrome"
35+
checked={adj.monochrome}
36+
onChange={(monochrome) => onChange({ monochrome, rows } as Partial<Adjustment>)}
37+
/>
38+
<NumberField
39+
label="Red percent"
40+
displayLabel="Red %"
41+
value={row.redPercent}
42+
onChange={(v) => patchRow('redPercent', v)}
43+
step={1}
44+
/>
45+
<NumberField
46+
label="Green percent"
47+
displayLabel="Green %"
48+
value={row.greenPercent}
49+
onChange={(v) => patchRow('greenPercent', v)}
50+
step={1}
51+
/>
52+
<NumberField
53+
label="Blue percent"
54+
displayLabel="Blue %"
55+
value={row.bluePercent}
56+
onChange={(v) => patchRow('bluePercent', v)}
57+
step={1}
58+
/>
59+
<NumberField
60+
label="Constant (code values)"
61+
displayLabel="Offset"
62+
value={row.constant}
63+
onChange={(v) => patchRow('constant', v)}
64+
step={1}
65+
/>
66+
<span className="curve-editor__hint">
67+
Every output reads the original RGB. Coefficients are not normalized. Monochrome uses the
68+
Red row.
69+
</span>
70+
<Button
71+
size="sm"
72+
variant="ghost"
73+
onClick={() =>
74+
onChange({
75+
rows: undefined,
76+
outputChannel: 'red',
77+
redPercent: 100,
78+
greenPercent: 0,
79+
bluePercent: 0,
80+
constant: 0,
81+
monochrome: false,
82+
} as Partial<Adjustment>)
83+
}
84+
>
85+
Reset mixer
86+
</Button>
87+
</div>
88+
);
89+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Switch } from '@varve/ui';
2+
3+
export function BooleanRow({
4+
label,
5+
checked,
6+
onChange,
7+
ariaLabel,
8+
}: {
9+
label: string;
10+
checked: boolean;
11+
onChange: (value: boolean) => void;
12+
ariaLabel?: string;
13+
}) {
14+
return (
15+
<div className="adj-editor__row">
16+
<Switch
17+
className="adj-editor__checkbox-row"
18+
label={label}
19+
checked={checked}
20+
onChange={(event) => onChange(event.target.checked)}
21+
aria-label={ariaLabel ?? label}
22+
/>
23+
</div>
24+
);
25+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import { type CurvePoint, compileCurve, curveChannels } from '@varve/engine';
2+
import type { Adjustment } from '@varve/scene';
3+
import { Button, Select } from '@varve/ui';
4+
import { CurveEditor } from '../../Inspector/controls/CurveEditor';
5+
import { SourceChannels } from '../SourceChannels';
6+
import type { AdjustmentEditorProps } from './types';
7+
8+
// CurvesAdjustment.points ({input, output}, 0-255, document/render space) and
9+
// CurveEditor's CurvePoint ({x, y}, 0-1, plot space) are the same tonal curve
10+
// in two different unit systems — a straight linear scale, not a lossy or
11+
// structural conversion. Order is preserved (not re-sorted) so a drag that
12+
// moves one point doesn't reshuffle the others; CurveEditor already sorts by
13+
// x internally for rendering/hit-testing.
14+
export function curvesPointsToCurvePoints(
15+
points: import('@varve/scene').CurvesPoint[],
16+
): CurvePoint[] {
17+
return points.map((p) => ({
18+
...(p.id ? { id: p.id } : {}),
19+
x: p.input / 255,
20+
y: p.output / 255,
21+
}));
22+
}
23+
export function curvePointsToCurvesPoints(
24+
points: CurvePoint[],
25+
): import('@varve/scene').CurvesPoint[] {
26+
return points.map((p) => ({
27+
...(p.id ? { id: p.id } : {}),
28+
input: Math.max(0, Math.min(1, p.x)) * 255,
29+
output: Math.max(0, Math.min(1, p.y)) * 255,
30+
}));
31+
}
32+
export function CurvesEditor({
33+
adjustment,
34+
onChange,
35+
onEditStart,
36+
onEditEnd,
37+
sourceHistogram,
38+
histogramSourceLabel,
39+
histogramLoading,
40+
sourceImageData,
41+
}: AdjustmentEditorProps) {
42+
const adj = adjustment as import('@varve/scene').CurvesAdjustment;
43+
const channels = curveChannels(adj);
44+
const changeChannel = (channel: 'rgb' | 'red' | 'green' | 'blue') =>
45+
onChange({
46+
channel,
47+
points: channels[channel] ?? [],
48+
channelPoints: channels,
49+
} as Partial<Adjustment>);
50+
const changePoints = (points: CurvePoint[]) => {
51+
const authored = curvePointsToCurvesPoints(points);
52+
onChange({
53+
points: authored,
54+
channelPoints: { ...channels, [adj.channel]: authored },
55+
} as Partial<Adjustment>);
56+
};
57+
58+
return (
59+
<div>
60+
{(histogramSourceLabel || histogramLoading) && (
61+
<div className="histogram-widget__source" role="note">
62+
{histogramLoading ? 'Loading histogram…' : `Histogram: ${histogramSourceLabel}`}
63+
</div>
64+
)}
65+
<Select
66+
label="Curve interpolation"
67+
value={String(adj.algorithmVersion ?? 1)}
68+
options={[
69+
{ value: '1', label: 'Legacy Catmull-Rom' },
70+
{ value: '2', label: 'Shape preserving' },
71+
]}
72+
onChange={(v) => onChange({ algorithmVersion: Number(v) as 1 | 2 } as Partial<Adjustment>)}
73+
/>
74+
<Button
75+
size="sm"
76+
variant="ghost"
77+
onClick={() =>
78+
onChange({
79+
points: [],
80+
channelPoints: { rgb: [], red: [], green: [], blue: [] },
81+
} as Partial<Adjustment>)
82+
}
83+
>
84+
Reset all channels
85+
</Button>
86+
<CurveEditor
87+
key={`${adj.id}-${adj.channel}`}
88+
value={curvesPointsToCurvePoints(channels[adj.channel] ?? [])}
89+
onChange={changePoints}
90+
algorithm={adj.algorithmVersion === 2 ? 'pchip' : 'legacy'}
91+
channel={adj.channel as 'rgb' | 'red' | 'green' | 'blue'}
92+
onChannelChange={changeChannel}
93+
histogram={sourceHistogram ?? undefined}
94+
onDragStart={onEditStart}
95+
onDragEnd={onEditEnd}
96+
/>
97+
<p className="tonal-editor__hint">
98+
Sample upstream input to add a point on the current transfer. RGB uses the arithmetic mean
99+
of the three encoded components.
100+
</p>
101+
<SourceChannels
102+
source={sourceImageData}
103+
label={histogramSourceLabel}
104+
onSample={(x, y) => {
105+
if (!sourceImageData || (channels[adj.channel]?.length ?? 0) >= 256) return;
106+
const at = (y * sourceImageData.width + x) * 4;
107+
if (sourceImageData.data[at + 3] === 0) return;
108+
const c = { red: 0, green: 1, blue: 2 };
109+
let input =
110+
adj.channel === 'rgb'
111+
? (sourceImageData.data[at]! +
112+
sourceImageData.data[at + 1]! +
113+
sourceImageData.data[at + 2]!) /
114+
3
115+
: sourceImageData.data[at + c[adj.channel]]!;
116+
if (adj.channel !== 'rgb') {
117+
input =
118+
compileCurve(
119+
curvesPointsToCurvePoints(channels.rgb ?? []),
120+
adj.algorithmVersion === 2 ? 'pchip' : 'legacy',
121+
)(input / 255) * 255;
122+
}
123+
const points = curvesPointsToCurvePoints(channels[adj.channel] ?? []);
124+
const output = compileCurve(
125+
points,
126+
adj.algorithmVersion === 2 ? 'pchip' : 'legacy',
127+
)(input / 255);
128+
changePoints([...points, { id: crypto.randomUUID(), x: input / 255, y: output }]);
129+
}}
130+
/>
131+
</div>
132+
);
133+
}

0 commit comments

Comments
 (0)