Replace the shadow-only inspector with layered effect and stroke controls and per-corner distortion editors. Share color inputs, layer rows, keyframe controls and property edit boundaries; keep nested selection menus within their property popover and update localized labels. Add property editing, preview interaction and benchmark comparison coverage. Validation: Dart analysis reports no issues and 160 targeted application tests pass. The macOS development app was rebuilt and visually checked during native rendering validation. Exclude local dependency override changes from the committed lockfile.
187 lines
5.1 KiB
Dart
187 lines
5.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cutdex_sdk/editor.dart';
|
|
import 'package:cutdex_sdk/preview.dart';
|
|
import 'package:cutdex_sdk/timeline/model.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
import '../../workspace/timeline_session.dart';
|
|
import 'property_edit_boundary.dart';
|
|
|
|
part 'picture_edits.g.dart';
|
|
part 'picture_edits.freezed.dart';
|
|
|
|
enum PictureEditFailure { keyframes, alignment, invalidTransform, transform }
|
|
|
|
@freezed
|
|
abstract class PictureEditException
|
|
with _$PictureEditException
|
|
implements Exception {
|
|
const factory PictureEditException(PictureEditFailure failure) =
|
|
_PictureEditException;
|
|
}
|
|
|
|
@riverpod
|
|
class PictureEdits extends _$PictureEdits {
|
|
Future<bool>? _pending;
|
|
late PropertyEditBoundary _boundary;
|
|
@override
|
|
AsyncValue<void> build(
|
|
EditorTimelineSession session,
|
|
SequenceId sequence,
|
|
ElementId clip,
|
|
) {
|
|
_boundary = PropertyEditBoundary(session, sequence, clip);
|
|
ref.onDispose(_boundary.dispose);
|
|
return const AsyncData(null);
|
|
}
|
|
|
|
ClipAnimation? animation() {
|
|
final view = session.view(sequence);
|
|
final query = view.version.kernelVersion.query();
|
|
final handle = query.elementById(clip);
|
|
return handle == null
|
|
? null
|
|
: ClipAnimation.at(
|
|
query,
|
|
handle,
|
|
view.playheadTick,
|
|
TimelineClock.standard.toTicks(
|
|
session.persistence.timeline(sequence).format.frameDuration,
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<bool> commit(
|
|
PreviewController? preview,
|
|
ClipTransform Function(ClipTransform) change, {
|
|
required bool Function() isCurrent,
|
|
}) {
|
|
if (state.isLoading || preview?.transforms.hasPending == true) {
|
|
return Future.value(false);
|
|
}
|
|
final work = _run(PictureEditFailure.transform, preview, isCurrent, (
|
|
target,
|
|
) {
|
|
final current = animation()?.value;
|
|
if (current == null) return false;
|
|
final value = change(current);
|
|
if (!value.isValid) {
|
|
throw const PictureEditException(PictureEditFailure.invalidTransform);
|
|
}
|
|
if (value.x == current.x &&
|
|
value.y == current.y &&
|
|
value.scale == current.scale &&
|
|
value.scaleY == current.scaleY &&
|
|
value.rotation == current.rotation &&
|
|
value.sameCorners(current) &&
|
|
value.distortion.same(current.distortion)) {
|
|
return true;
|
|
}
|
|
session.commands.setTransform(
|
|
sequence: sequence,
|
|
clip: clip,
|
|
tick: target.tick,
|
|
change: (_) => value,
|
|
);
|
|
return true;
|
|
});
|
|
_pending = work;
|
|
return work.whenComplete(() {
|
|
if (identical(_pending, work)) _pending = null;
|
|
});
|
|
}
|
|
|
|
Future<void> editKeys(
|
|
PreviewController? preview,
|
|
TransformChannel channel, {
|
|
KeyframeAction? action,
|
|
ParameterInterpolation? interpolation,
|
|
required bool Function() isCurrent,
|
|
}) async {
|
|
final pending = _pending;
|
|
if (pending != null && !await pending) return;
|
|
if (!ref.mounted ||
|
|
!isCurrent() ||
|
|
state.isLoading ||
|
|
preview?.transforms.hasPending == true) {
|
|
return;
|
|
}
|
|
await _run(PictureEditFailure.keyframes, preview, isCurrent, (target) {
|
|
session.commands.editKeyframeChannel(
|
|
sequence: sequence,
|
|
clip: clip,
|
|
tick: target.tick,
|
|
parameterIds: channel.ids,
|
|
action: action,
|
|
interpolation: interpolation,
|
|
);
|
|
return true;
|
|
});
|
|
}
|
|
|
|
Future<void> align(
|
|
PreviewController preview,
|
|
CanvasAlignment alignment, {
|
|
required bool Function() isCurrent,
|
|
}) async {
|
|
if (state.isLoading || preview.transforms.hasPending) return;
|
|
final current = animation();
|
|
if (current == null) return;
|
|
final command = AlignClip(
|
|
clipId: clip.value,
|
|
at: CommandTime(
|
|
current.start + current.localTick,
|
|
TimelineClock.ticksPerSecond,
|
|
),
|
|
alignment: alignment,
|
|
expectedVersion: session.version,
|
|
);
|
|
await _run(PictureEditFailure.alignment, preview, isCurrent, (
|
|
target,
|
|
) async {
|
|
await session.alignClip(
|
|
sequence,
|
|
command,
|
|
isCancelled: () => !target.isCurrent,
|
|
);
|
|
return true;
|
|
});
|
|
}
|
|
|
|
Future<bool> _run(
|
|
PictureEditFailure failure,
|
|
PreviewController? preview,
|
|
bool Function() isCurrent,
|
|
FutureOr<bool> Function(PropertyEditContext) action,
|
|
) async {
|
|
final lease = ref.keepAlive();
|
|
try {
|
|
final applied = await _boundary.run(
|
|
preview,
|
|
action,
|
|
isCurrent: () => ref.mounted && isCurrent(),
|
|
started: () => state = const AsyncLoading(),
|
|
operation: switch (failure) {
|
|
PictureEditFailure.keyframes => 'editKeyframes',
|
|
PictureEditFailure.alignment => 'alignClip',
|
|
_ => 'setTransform',
|
|
},
|
|
);
|
|
if (ref.mounted) state = const AsyncData(null);
|
|
return applied;
|
|
} catch (error, stack) {
|
|
if (ref.mounted) {
|
|
state = AsyncError(
|
|
error is PictureEditException ? error : PictureEditException(failure),
|
|
stack,
|
|
);
|
|
}
|
|
return false;
|
|
} finally {
|
|
lease.close();
|
|
}
|
|
}
|
|
}
|