@aura3d/editor-runtime 1.0.6 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AnimationSceneEditor.d.ts +111 -0
- package/dist/AnimationSceneEditor.d.ts.map +1 -0
- package/dist/AnimationSceneEditor.js +285 -0
- package/dist/AnimationSceneEditor.js.map +1 -0
- package/dist/AssetDropZone.d.ts +52 -0
- package/dist/AssetDropZone.d.ts.map +1 -0
- package/dist/AssetDropZone.js +115 -0
- package/dist/AssetDropZone.js.map +1 -0
- package/dist/CameraPathEditor.d.ts +48 -0
- package/dist/CameraPathEditor.d.ts.map +1 -0
- package/dist/CameraPathEditor.js +181 -0
- package/dist/CameraPathEditor.js.map +1 -0
- package/dist/CartoonSceneEditor.d.ts +111 -0
- package/dist/CartoonSceneEditor.d.ts.map +1 -0
- package/dist/CartoonSceneEditor.js +285 -0
- package/dist/CartoonSceneEditor.js.map +1 -0
- package/dist/CurveEditor.d.ts +38 -0
- package/dist/CurveEditor.d.ts.map +1 -0
- package/dist/CurveEditor.js +112 -0
- package/dist/CurveEditor.js.map +1 -0
- package/dist/EpisodeReviewPanel.d.ts +67 -0
- package/dist/EpisodeReviewPanel.d.ts.map +1 -0
- package/dist/EpisodeReviewPanel.js +162 -0
- package/dist/EpisodeReviewPanel.js.map +1 -0
- package/dist/EventTrackEditor.d.ts +54 -0
- package/dist/EventTrackEditor.d.ts.map +1 -0
- package/dist/EventTrackEditor.js +124 -0
- package/dist/EventTrackEditor.js.map +1 -0
- package/dist/KeyframeEditor.d.ts +49 -0
- package/dist/KeyframeEditor.d.ts.map +1 -0
- package/dist/KeyframeEditor.js +161 -0
- package/dist/KeyframeEditor.js.map +1 -0
- package/dist/MultiUserReviewWorkflow.d.ts +77 -0
- package/dist/MultiUserReviewWorkflow.d.ts.map +1 -0
- package/dist/MultiUserReviewWorkflow.js +162 -0
- package/dist/MultiUserReviewWorkflow.js.map +1 -0
- package/dist/NonlinearAnimationEditor.d.ts +81 -0
- package/dist/NonlinearAnimationEditor.d.ts.map +1 -0
- package/dist/NonlinearAnimationEditor.js +180 -0
- package/dist/NonlinearAnimationEditor.js.map +1 -0
- package/dist/PropertyPanel.d.ts +21 -0
- package/dist/PropertyPanel.d.ts.map +1 -0
- package/dist/PropertyPanel.js +72 -0
- package/dist/PropertyPanel.js.map +1 -0
- package/dist/RenderQueuePanel.d.ts +38 -0
- package/dist/RenderQueuePanel.d.ts.map +1 -0
- package/dist/RenderQueuePanel.js +72 -0
- package/dist/RenderQueuePanel.js.map +1 -0
- package/dist/SceneOutliner.d.ts +19 -0
- package/dist/SceneOutliner.d.ts.map +1 -0
- package/dist/SceneOutliner.js +64 -0
- package/dist/SceneOutliner.js.map +1 -0
- package/dist/TimelineEditorController.d.ts +102 -0
- package/dist/TimelineEditorController.d.ts.map +1 -0
- package/dist/TimelineEditorController.js +449 -0
- package/dist/TimelineEditorController.js.map +1 -0
- package/dist/TimelineTrackTypes.d.ts +25 -0
- package/dist/TimelineTrackTypes.d.ts.map +1 -0
- package/dist/TimelineTrackTypes.js +48 -0
- package/dist/TimelineTrackTypes.js.map +1 -0
- package/dist/TimelineUI.d.ts +27 -0
- package/dist/TimelineUI.d.ts.map +1 -0
- package/dist/TimelineUI.js +123 -0
- package/dist/TimelineUI.js.map +1 -0
- package/dist/VisualReviewDashboard.d.ts +43 -0
- package/dist/VisualReviewDashboard.d.ts.map +1 -0
- package/dist/VisualReviewDashboard.js +47 -0
- package/dist/VisualReviewDashboard.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/AnimationSceneEditor.ts +368 -0
- package/src/AssetDropZone.ts +144 -0
- package/src/CameraPathEditor.ts +223 -0
- package/src/CurveEditor.ts +152 -0
- package/src/EpisodeReviewPanel.ts +236 -0
- package/src/EventTrackEditor.ts +169 -0
- package/src/KeyframeEditor.ts +214 -0
- package/src/MultiUserReviewWorkflow.ts +229 -0
- package/src/NonlinearAnimationEditor.ts +262 -0
- package/src/PropertyPanel.ts +82 -0
- package/src/RenderQueuePanel.ts +106 -0
- package/src/SceneOutliner.ts +78 -0
- package/src/TimelineEditorController.ts +525 -0
- package/src/TimelineTrackTypes.ts +89 -0
- package/src/TimelineUI.ts +153 -0
- package/src/VisualReviewDashboard.ts +87 -0
- package/src/index.ts +55 -0
- package/tests/editor-runtime.test.ts +490 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// Editor authoring controller for animation event tracks (T2.2). Lets a timeline UI add / move /
|
|
2
|
+
// delete typed markers on named lanes (hitbox active-frames, footsteps, VFX, generic markers) and
|
|
3
|
+
// serialize to the canonical `animation-event-tracks/v1` shape that `@aura3d/animation`'s
|
|
4
|
+
// `deserializeAnimationEventTracks` / `sampleClipEvents` consume — so authored tracks drive gameplay
|
|
5
|
+
// (hitbox windows) and playback (footstep/VFX triggers) deterministically.
|
|
6
|
+
//
|
|
7
|
+
// Type-only imports from `@aura3d/animation` keep this controller free of any runtime coupling to
|
|
8
|
+
// that package (the types are erased at build time); the serialized output is verified to round-trip
|
|
9
|
+
// through the animation package's deserializer in tests.
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
AnimationClipEvent,
|
|
13
|
+
AnimationClipEventType,
|
|
14
|
+
AnimationEventTrack,
|
|
15
|
+
SerializedAnimationEventTracks
|
|
16
|
+
} from "@aura3d/animation";
|
|
17
|
+
|
|
18
|
+
export interface EventMarkerView {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly time: number;
|
|
21
|
+
readonly duration?: number;
|
|
22
|
+
readonly type: AnimationClipEventType;
|
|
23
|
+
readonly selected: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface EventTrackLane {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly type: AnimationClipEventType;
|
|
29
|
+
readonly markers: readonly EventMarkerView[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface EventTrackEditorOptions {
|
|
33
|
+
readonly clipId: string;
|
|
34
|
+
readonly duration: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface AddEventMarkerOptions {
|
|
38
|
+
readonly id?: string;
|
|
39
|
+
readonly type?: AnimationClipEventType;
|
|
40
|
+
/** Window length (seconds). >0 makes the marker an active-frame window (e.g. hitbox on/off). */
|
|
41
|
+
readonly duration?: number;
|
|
42
|
+
readonly payload?: unknown;
|
|
43
|
+
readonly tags?: readonly string[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface LaneState {
|
|
47
|
+
type: AnimationClipEventType;
|
|
48
|
+
markers: AnimationClipEvent[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Timeline event-track authoring controller. Deterministic: marker ids come from a monotonic
|
|
53
|
+
* counter (no `Date.now`/`Math.random`), so undo/redo and serialization are reproducible.
|
|
54
|
+
*/
|
|
55
|
+
export class EventTrackEditor {
|
|
56
|
+
readonly clipId: string;
|
|
57
|
+
duration: number;
|
|
58
|
+
private readonly order: string[] = [];
|
|
59
|
+
private readonly lanesMap = new Map<string, LaneState>();
|
|
60
|
+
private selectedId: string | undefined;
|
|
61
|
+
private idCounter = 0;
|
|
62
|
+
|
|
63
|
+
constructor(options: EventTrackEditorOptions) {
|
|
64
|
+
if (!Number.isFinite(options.duration) || options.duration < 0) {
|
|
65
|
+
throw new Error("EventTrackEditor duration must be a finite, non-negative number.");
|
|
66
|
+
}
|
|
67
|
+
this.clipId = options.clipId;
|
|
68
|
+
this.duration = options.duration;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
addTrack(name: string, type: AnimationClipEventType = "marker"): this {
|
|
72
|
+
if (!this.lanesMap.has(name)) {
|
|
73
|
+
this.lanesMap.set(name, { type, markers: [] });
|
|
74
|
+
this.order.push(name);
|
|
75
|
+
}
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
removeTrack(name: string): this {
|
|
80
|
+
if (this.lanesMap.delete(name)) this.order.splice(this.order.indexOf(name), 1);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Add a marker to a lane (auto-creates the lane). Returns the new marker id. */
|
|
85
|
+
addMarker(trackName: string, time: number, options: AddEventMarkerOptions = {}): string {
|
|
86
|
+
if (!Number.isFinite(time) || time < 0) {
|
|
87
|
+
throw new Error("Event marker time must be a finite, non-negative number.");
|
|
88
|
+
}
|
|
89
|
+
this.addTrack(trackName, options.type);
|
|
90
|
+
const lane = this.lanesMap.get(trackName)!;
|
|
91
|
+
const id = options.id ?? `${trackName}#${this.idCounter++}`;
|
|
92
|
+
lane.markers.push({
|
|
93
|
+
id,
|
|
94
|
+
name: trackName,
|
|
95
|
+
type: options.type ?? lane.type,
|
|
96
|
+
time,
|
|
97
|
+
...(options.duration !== undefined ? { duration: options.duration } : {}),
|
|
98
|
+
...(options.payload !== undefined ? { payload: options.payload } : {}),
|
|
99
|
+
...(options.tags !== undefined ? { tags: options.tags } : {})
|
|
100
|
+
});
|
|
101
|
+
lane.markers.sort((a, b) => a.time - b.time);
|
|
102
|
+
return id;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Move an existing marker to a new time. */
|
|
106
|
+
moveMarker(trackName: string, markerId: string, time: number): this {
|
|
107
|
+
if (!Number.isFinite(time) || time < 0) {
|
|
108
|
+
throw new Error("Event marker time must be a finite, non-negative number.");
|
|
109
|
+
}
|
|
110
|
+
const lane = this.lanesMap.get(trackName);
|
|
111
|
+
const index = lane?.markers.findIndex((m) => m.id === markerId) ?? -1;
|
|
112
|
+
if (!lane || index < 0) throw new Error(`Marker ${markerId} not found on track ${trackName}.`);
|
|
113
|
+
lane.markers[index] = { ...lane.markers[index]!, time };
|
|
114
|
+
lane.markers.sort((a, b) => a.time - b.time);
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Delete a marker. */
|
|
119
|
+
removeMarker(trackName: string, markerId: string): this {
|
|
120
|
+
const lane = this.lanesMap.get(trackName);
|
|
121
|
+
if (!lane) return this;
|
|
122
|
+
const index = lane.markers.findIndex((m) => m.id === markerId);
|
|
123
|
+
if (index >= 0) lane.markers.splice(index, 1);
|
|
124
|
+
if (this.selectedId === markerId) this.selectedId = undefined;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
select(markerId: string | undefined): this {
|
|
129
|
+
this.selectedId = markerId;
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
markerCount(): number {
|
|
134
|
+
let count = 0;
|
|
135
|
+
for (const lane of this.lanesMap.values()) count += lane.markers.length;
|
|
136
|
+
return count;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** View-model for the timeline UI: lanes with marker positions + selection state. */
|
|
140
|
+
lanes(): readonly EventTrackLane[] {
|
|
141
|
+
return this.order.map((name) => {
|
|
142
|
+
const lane = this.lanesMap.get(name)!;
|
|
143
|
+
return {
|
|
144
|
+
name,
|
|
145
|
+
type: lane.type,
|
|
146
|
+
markers: lane.markers.map((m) => ({
|
|
147
|
+
id: m.id!,
|
|
148
|
+
time: m.time,
|
|
149
|
+
...(m.duration !== undefined ? { duration: m.duration } : {}),
|
|
150
|
+
type: m.type ?? lane.type,
|
|
151
|
+
selected: m.id === this.selectedId
|
|
152
|
+
}))
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Serialize to the canonical `animation-event-tracks/v1` shape. */
|
|
158
|
+
serialize(): SerializedAnimationEventTracks {
|
|
159
|
+
const tracks: AnimationEventTrack[] = this.order.map((name) => {
|
|
160
|
+
const lane = this.lanesMap.get(name)!;
|
|
161
|
+
return { name, type: lane.type, markers: lane.markers.map((m) => ({ ...m })) };
|
|
162
|
+
});
|
|
163
|
+
return { schema: "animation-event-tracks/v1", clipId: this.clipId, duration: this.duration, tracks };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function createEventTrackEditor(options: EventTrackEditorOptions): EventTrackEditor {
|
|
168
|
+
return new EventTrackEditor(options);
|
|
169
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { Command } from "./Command";
|
|
2
|
+
import { CommandHistory } from "./CommandHistory";
|
|
3
|
+
import type { TimelineClip } from "./TimelineModel";
|
|
4
|
+
|
|
5
|
+
export type TimelineKeyframeValue = number | string | boolean;
|
|
6
|
+
export type TimelineKeyframeInterpolation = "hold" | "linear" | "bezier";
|
|
7
|
+
|
|
8
|
+
export interface TimelineBezierHandle {
|
|
9
|
+
readonly time: number;
|
|
10
|
+
readonly value: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface TimelineKeyframe {
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly propertyPath: string;
|
|
16
|
+
readonly time: number;
|
|
17
|
+
readonly value: TimelineKeyframeValue;
|
|
18
|
+
readonly interpolation: TimelineKeyframeInterpolation;
|
|
19
|
+
readonly inHandle?: TimelineBezierHandle;
|
|
20
|
+
readonly outHandle?: TimelineBezierHandle;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CreateTimelineKeyframeOptions {
|
|
24
|
+
readonly id?: string;
|
|
25
|
+
readonly propertyPath: string;
|
|
26
|
+
readonly time: number;
|
|
27
|
+
readonly value: TimelineKeyframeValue;
|
|
28
|
+
readonly interpolation?: TimelineKeyframeInterpolation;
|
|
29
|
+
readonly inHandle?: TimelineBezierHandle;
|
|
30
|
+
readonly outHandle?: TimelineBezierHandle;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface PasteTimelineKeyframesOptions {
|
|
34
|
+
readonly timeOffset?: number;
|
|
35
|
+
readonly idPrefix?: string;
|
|
36
|
+
readonly propertyPath?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const KEYFRAME_PROPERTY = "auraKeyframes";
|
|
40
|
+
|
|
41
|
+
export function readTimelineKeyframes(clip: TimelineClip): readonly TimelineKeyframe[] {
|
|
42
|
+
const encoded = clip.properties[KEYFRAME_PROPERTY];
|
|
43
|
+
if (typeof encoded !== "string" || encoded.trim().length === 0) return [];
|
|
44
|
+
const parsed = JSON.parse(encoded) as TimelineKeyframe[];
|
|
45
|
+
if (!Array.isArray(parsed)) {
|
|
46
|
+
throw new Error(`Timeline clip keyframes must decode to an array: ${clip.id}`);
|
|
47
|
+
}
|
|
48
|
+
return parsed.map(normalizeKeyframe).sort(compareKeyframes);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function encodeTimelineKeyframes(keyframes: readonly TimelineKeyframe[]): string {
|
|
52
|
+
return JSON.stringify([...keyframes].map(normalizeKeyframe).sort(compareKeyframes));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function timelineKeyframesByProperty(clip: TimelineClip, propertyPath: string): readonly TimelineKeyframe[] {
|
|
56
|
+
return readTimelineKeyframes(clip).filter((keyframe) => keyframe.propertyPath === propertyPath);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class KeyframeEditor {
|
|
60
|
+
constructor(private readonly history = new CommandHistory()) {}
|
|
61
|
+
|
|
62
|
+
get commandHistory(): CommandHistory {
|
|
63
|
+
return this.history;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
keyframes(clip: TimelineClip, propertyPath?: string): readonly TimelineKeyframe[] {
|
|
67
|
+
const keyframes = readTimelineKeyframes(clip);
|
|
68
|
+
return propertyPath ? keyframes.filter((keyframe) => keyframe.propertyPath === propertyPath) : keyframes;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async addKeyframe(clip: TimelineClip, options: CreateTimelineKeyframeOptions): Promise<TimelineKeyframe> {
|
|
72
|
+
const keyframe = normalizeKeyframe({
|
|
73
|
+
id: options.id ?? stableKeyframeId(options.propertyPath, options.time),
|
|
74
|
+
propertyPath: options.propertyPath,
|
|
75
|
+
time: options.time,
|
|
76
|
+
value: options.value,
|
|
77
|
+
interpolation: options.interpolation ?? "linear",
|
|
78
|
+
inHandle: options.inHandle,
|
|
79
|
+
outHandle: options.outHandle
|
|
80
|
+
});
|
|
81
|
+
const next = [...readTimelineKeyframes(clip).filter((candidate) => candidate.id !== keyframe.id), keyframe];
|
|
82
|
+
await this.applyKeyframes(clip, next, `Add keyframe ${keyframe.id}`);
|
|
83
|
+
return keyframe;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async deleteKeyframes(clip: TimelineClip, ids: readonly string[]): Promise<void> {
|
|
87
|
+
const remove = new Set(ids);
|
|
88
|
+
await this.applyKeyframes(clip, readTimelineKeyframes(clip).filter((keyframe) => !remove.has(keyframe.id)), `Delete ${ids.length} keyframes`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async moveKeyframes(clip: TimelineClip, ids: readonly string[], deltaTime: number): Promise<readonly TimelineKeyframe[]> {
|
|
92
|
+
assertFinite(deltaTime, "Keyframe deltaTime");
|
|
93
|
+
const move = new Set(ids);
|
|
94
|
+
const next = readTimelineKeyframes(clip).map((keyframe) => move.has(keyframe.id)
|
|
95
|
+
? normalizeKeyframe({ ...keyframe, time: Math.max(0, keyframe.time + deltaTime) })
|
|
96
|
+
: keyframe);
|
|
97
|
+
await this.applyKeyframes(clip, next, `Move ${ids.length} keyframes`);
|
|
98
|
+
return next.filter((keyframe) => move.has(keyframe.id));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async scaleKeyframes(clip: TimelineClip, ids: readonly string[], pivotTime: number, scale: number): Promise<readonly TimelineKeyframe[]> {
|
|
102
|
+
assertFinite(pivotTime, "Keyframe pivotTime");
|
|
103
|
+
assertFinite(scale, "Keyframe scale");
|
|
104
|
+
if (scale <= 0) throw new RangeError("Keyframe scale must be positive.");
|
|
105
|
+
const scaleIds = new Set(ids);
|
|
106
|
+
const next = readTimelineKeyframes(clip).map((keyframe) => scaleIds.has(keyframe.id)
|
|
107
|
+
? normalizeKeyframe({ ...keyframe, time: Math.max(0, pivotTime + (keyframe.time - pivotTime) * scale) })
|
|
108
|
+
: keyframe);
|
|
109
|
+
await this.applyKeyframes(clip, next, `Scale ${ids.length} keyframes`);
|
|
110
|
+
return next.filter((keyframe) => scaleIds.has(keyframe.id));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
copyKeyframes(clip: TimelineClip, ids: readonly string[]): readonly TimelineKeyframe[] {
|
|
114
|
+
const copy = new Set(ids);
|
|
115
|
+
return readTimelineKeyframes(clip).filter((keyframe) => copy.has(keyframe.id)).map((keyframe) => ({ ...keyframe }));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async pasteKeyframes(
|
|
119
|
+
clip: TimelineClip,
|
|
120
|
+
keyframes: readonly TimelineKeyframe[],
|
|
121
|
+
options: PasteTimelineKeyframesOptions = {}
|
|
122
|
+
): Promise<readonly TimelineKeyframe[]> {
|
|
123
|
+
const timeOffset = options.timeOffset ?? 0;
|
|
124
|
+
assertFinite(timeOffset, "Paste keyframe timeOffset");
|
|
125
|
+
const prefix = options.idPrefix ?? "pasted";
|
|
126
|
+
const pasted = keyframes.map((keyframe, index) => normalizeKeyframe({
|
|
127
|
+
...keyframe,
|
|
128
|
+
id: `${prefix}-${keyframe.id}-${index}`,
|
|
129
|
+
propertyPath: options.propertyPath ?? keyframe.propertyPath,
|
|
130
|
+
time: Math.max(0, keyframe.time + timeOffset)
|
|
131
|
+
}));
|
|
132
|
+
await this.applyKeyframes(clip, [...readTimelineKeyframes(clip), ...pasted], `Paste ${pasted.length} keyframes`);
|
|
133
|
+
return pasted;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async replaceKeyframes(clip: TimelineClip, keyframes: readonly TimelineKeyframe[], label = "Replace keyframes"): Promise<void> {
|
|
137
|
+
await this.applyKeyframes(clip, keyframes, label);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private async applyKeyframes(clip: TimelineClip, keyframes: readonly TimelineKeyframe[], name: string): Promise<void> {
|
|
141
|
+
await this.history.execute(new SetClipKeyframesCommand(clip, keyframes, name));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
class SetClipKeyframesCommand implements Command {
|
|
146
|
+
readonly name: string;
|
|
147
|
+
private readonly before: readonly TimelineKeyframe[];
|
|
148
|
+
private readonly after: readonly TimelineKeyframe[];
|
|
149
|
+
|
|
150
|
+
constructor(private readonly clip: TimelineClip, keyframes: readonly TimelineKeyframe[], name: string) {
|
|
151
|
+
this.name = name;
|
|
152
|
+
this.before = readTimelineKeyframes(clip);
|
|
153
|
+
this.after = [...keyframes].map(normalizeKeyframe).sort(compareKeyframes);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
execute(): void {
|
|
157
|
+
this.write(this.after);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
undo(): void {
|
|
161
|
+
this.write(this.before);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private write(keyframes: readonly TimelineKeyframe[]): void {
|
|
165
|
+
if (keyframes.length === 0) {
|
|
166
|
+
delete this.clip.properties[KEYFRAME_PROPERTY];
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this.clip.properties[KEYFRAME_PROPERTY] = encodeTimelineKeyframes(keyframes);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function normalizeKeyframe(keyframe: TimelineKeyframe): TimelineKeyframe {
|
|
174
|
+
if (!keyframe.id.trim()) throw new Error("Timeline keyframe id is required.");
|
|
175
|
+
if (!keyframe.propertyPath.trim()) throw new Error("Timeline keyframe propertyPath is required.");
|
|
176
|
+
assertFinite(keyframe.time, "Timeline keyframe time");
|
|
177
|
+
if (keyframe.time < 0) throw new RangeError("Timeline keyframe time must be non-negative.");
|
|
178
|
+
validateKeyframeValue(keyframe.value);
|
|
179
|
+
validateHandle(keyframe.inHandle, "inHandle");
|
|
180
|
+
validateHandle(keyframe.outHandle, "outHandle");
|
|
181
|
+
return {
|
|
182
|
+
id: keyframe.id,
|
|
183
|
+
propertyPath: keyframe.propertyPath,
|
|
184
|
+
time: Number(keyframe.time.toFixed(4)),
|
|
185
|
+
value: keyframe.value,
|
|
186
|
+
interpolation: keyframe.interpolation,
|
|
187
|
+
inHandle: keyframe.inHandle,
|
|
188
|
+
outHandle: keyframe.outHandle
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function validateKeyframeValue(value: TimelineKeyframeValue): void {
|
|
193
|
+
if (typeof value === "number" && !Number.isFinite(value)) {
|
|
194
|
+
throw new Error("Timeline keyframe numeric values must be finite.");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function validateHandle(handle: TimelineBezierHandle | undefined, label: string): void {
|
|
199
|
+
if (!handle) return;
|
|
200
|
+
assertFinite(handle.time, `Timeline keyframe ${label}.time`);
|
|
201
|
+
assertFinite(handle.value, `Timeline keyframe ${label}.value`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function assertFinite(value: number, label: string): void {
|
|
205
|
+
if (!Number.isFinite(value)) throw new RangeError(`${label} must be finite.`);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function compareKeyframes(left: TimelineKeyframe, right: TimelineKeyframe): number {
|
|
209
|
+
return left.time - right.time || left.propertyPath.localeCompare(right.propertyPath) || left.id.localeCompare(right.id);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function stableKeyframeId(propertyPath: string, time: number): string {
|
|
213
|
+
return `key-${propertyPath.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "value"}-${Number(time.toFixed(4)).toString().replace(".", "-")}`;
|
|
214
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
export type ReviewParticipantRole = "owner" | "reviewer" | "animator" | "audio" | "viewer";
|
|
2
|
+
export type ReviewDecisionStatus = "pending" | "approved" | "changes-requested";
|
|
3
|
+
export type ReviewWorkflowStatus = "draft" | "needs-review" | "changes-requested" | "approved";
|
|
4
|
+
|
|
5
|
+
export interface ReviewParticipant {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly role: ReviewParticipantRole;
|
|
9
|
+
readonly active?: boolean | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ReviewThread {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly authorId: string;
|
|
15
|
+
readonly text: string;
|
|
16
|
+
readonly time?: number | undefined;
|
|
17
|
+
readonly frame?: number | undefined;
|
|
18
|
+
readonly assignedTo?: string | undefined;
|
|
19
|
+
readonly resolved: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ReviewDecision {
|
|
23
|
+
readonly reviewerId: string;
|
|
24
|
+
readonly status: ReviewDecisionStatus;
|
|
25
|
+
readonly at: string;
|
|
26
|
+
readonly note?: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface MultiUserReviewWorkflowState {
|
|
30
|
+
readonly packageId: string;
|
|
31
|
+
readonly status?: ReviewWorkflowStatus | undefined;
|
|
32
|
+
readonly requiredReviewerCount?: number | undefined;
|
|
33
|
+
readonly participants: readonly ReviewParticipant[];
|
|
34
|
+
readonly threads: readonly ReviewThread[];
|
|
35
|
+
readonly decisions: readonly ReviewDecision[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface MultiUserReviewWorkflowSnapshot {
|
|
39
|
+
readonly kind: "multi-user-review-workflow";
|
|
40
|
+
readonly packageId: string;
|
|
41
|
+
readonly status: ReviewWorkflowStatus;
|
|
42
|
+
readonly participantCount: number;
|
|
43
|
+
readonly activeParticipantCount: number;
|
|
44
|
+
readonly reviewerCount: number;
|
|
45
|
+
readonly requiredReviewerCount: number;
|
|
46
|
+
readonly approvedReviewerCount: number;
|
|
47
|
+
readonly changeRequestCount: number;
|
|
48
|
+
readonly threadCount: number;
|
|
49
|
+
readonly unresolvedThreadCount: number;
|
|
50
|
+
readonly assignedThreadCount: number;
|
|
51
|
+
readonly canPublish: boolean;
|
|
52
|
+
readonly participants: readonly ReviewParticipant[];
|
|
53
|
+
readonly threads: readonly ReviewThread[];
|
|
54
|
+
readonly decisions: readonly ReviewDecision[];
|
|
55
|
+
readonly evidence: {
|
|
56
|
+
readonly multiUserReview: boolean;
|
|
57
|
+
readonly assignmentWorkflow: boolean;
|
|
58
|
+
readonly reviewerQuorum: boolean;
|
|
59
|
+
readonly publishBlockedByOpenThreads: boolean;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class MultiUserReviewWorkflow {
|
|
64
|
+
private packageId: string;
|
|
65
|
+
private status: ReviewWorkflowStatus;
|
|
66
|
+
private requiredReviewerCount: number;
|
|
67
|
+
private participants = new Map<string, ReviewParticipant>();
|
|
68
|
+
private threads = new Map<string, ReviewThread>();
|
|
69
|
+
private decisions = new Map<string, ReviewDecision>();
|
|
70
|
+
|
|
71
|
+
constructor(state: MultiUserReviewWorkflowState) {
|
|
72
|
+
this.packageId = nonEmpty(state.packageId, "Review package id");
|
|
73
|
+
this.status = state.status ?? "needs-review";
|
|
74
|
+
this.requiredReviewerCount = Math.max(1, Math.floor(state.requiredReviewerCount ?? 1));
|
|
75
|
+
for (const participant of state.participants) this.addParticipant(participant);
|
|
76
|
+
for (const thread of state.threads) this.addThread(thread);
|
|
77
|
+
for (const decision of state.decisions) this.recordDecision(decision);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
addParticipant(participant: ReviewParticipant): MultiUserReviewWorkflowSnapshot {
|
|
81
|
+
const clean = sanitizeParticipant(participant);
|
|
82
|
+
this.participants.set(clean.id, clean);
|
|
83
|
+
return this.snapshot();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
addThread(thread: ReviewThread): MultiUserReviewWorkflowSnapshot {
|
|
87
|
+
const clean = sanitizeThread(thread);
|
|
88
|
+
this.requireParticipant(clean.authorId);
|
|
89
|
+
if (clean.assignedTo) this.requireParticipant(clean.assignedTo);
|
|
90
|
+
this.threads.set(clean.id, clean);
|
|
91
|
+
if (!clean.resolved && this.status === "approved") this.status = "changes-requested";
|
|
92
|
+
return this.snapshot();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
assignThread(threadId: string, participantId: string): MultiUserReviewWorkflowSnapshot {
|
|
96
|
+
this.requireParticipant(participantId);
|
|
97
|
+
const thread = this.requireThread(threadId);
|
|
98
|
+
this.threads.set(threadId, { ...thread, assignedTo: participantId });
|
|
99
|
+
return this.snapshot();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
resolveThread(threadId: string): MultiUserReviewWorkflowSnapshot {
|
|
103
|
+
const thread = this.requireThread(threadId);
|
|
104
|
+
this.threads.set(threadId, { ...thread, resolved: true });
|
|
105
|
+
return this.snapshot();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
recordDecision(decision: ReviewDecision): MultiUserReviewWorkflowSnapshot {
|
|
109
|
+
const clean = sanitizeDecision(decision);
|
|
110
|
+
const participant = this.requireParticipant(clean.reviewerId);
|
|
111
|
+
if (participant.role !== "reviewer" && participant.role !== "owner") {
|
|
112
|
+
throw new Error(`Review participant "${clean.reviewerId}" is not allowed to approve or request changes.`);
|
|
113
|
+
}
|
|
114
|
+
this.decisions.set(clean.reviewerId, clean);
|
|
115
|
+
if (clean.status === "changes-requested") this.status = "changes-requested";
|
|
116
|
+
else if (this.snapshot().canPublish) this.status = "approved";
|
|
117
|
+
return this.snapshot();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
markNeedsReview(): MultiUserReviewWorkflowSnapshot {
|
|
121
|
+
this.status = "needs-review";
|
|
122
|
+
return this.snapshot();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
serialize(): MultiUserReviewWorkflowState {
|
|
126
|
+
return {
|
|
127
|
+
packageId: this.packageId,
|
|
128
|
+
status: this.status,
|
|
129
|
+
requiredReviewerCount: this.requiredReviewerCount,
|
|
130
|
+
participants: [...this.participants.values()],
|
|
131
|
+
threads: [...this.threads.values()],
|
|
132
|
+
decisions: [...this.decisions.values()]
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
snapshot(): MultiUserReviewWorkflowSnapshot {
|
|
137
|
+
const participants = [...this.participants.values()];
|
|
138
|
+
const threads = [...this.threads.values()];
|
|
139
|
+
const decisions = [...this.decisions.values()];
|
|
140
|
+
const reviewerCount = participants.filter((participant) => participant.role === "owner" || participant.role === "reviewer").length;
|
|
141
|
+
const approvedReviewerCount = decisions.filter((decision) => decision.status === "approved").length;
|
|
142
|
+
const changeRequestCount = decisions.filter((decision) => decision.status === "changes-requested").length;
|
|
143
|
+
const unresolvedThreadCount = threads.filter((thread) => !thread.resolved).length;
|
|
144
|
+
const canPublish = approvedReviewerCount >= this.requiredReviewerCount && changeRequestCount === 0 && unresolvedThreadCount === 0;
|
|
145
|
+
const status: ReviewWorkflowStatus = canPublish ? "approved" : changeRequestCount > 0 ? "changes-requested" : this.status === "draft" ? "draft" : "needs-review";
|
|
146
|
+
return {
|
|
147
|
+
kind: "multi-user-review-workflow",
|
|
148
|
+
packageId: this.packageId,
|
|
149
|
+
status,
|
|
150
|
+
participantCount: participants.length,
|
|
151
|
+
activeParticipantCount: participants.filter((participant) => participant.active !== false).length,
|
|
152
|
+
reviewerCount,
|
|
153
|
+
requiredReviewerCount: this.requiredReviewerCount,
|
|
154
|
+
approvedReviewerCount,
|
|
155
|
+
changeRequestCount,
|
|
156
|
+
threadCount: threads.length,
|
|
157
|
+
unresolvedThreadCount,
|
|
158
|
+
assignedThreadCount: threads.filter((thread) => Boolean(thread.assignedTo)).length,
|
|
159
|
+
canPublish,
|
|
160
|
+
participants,
|
|
161
|
+
threads,
|
|
162
|
+
decisions,
|
|
163
|
+
evidence: {
|
|
164
|
+
multiUserReview: participants.length > 1,
|
|
165
|
+
assignmentWorkflow: threads.some((thread) => Boolean(thread.assignedTo)),
|
|
166
|
+
reviewerQuorum: approvedReviewerCount >= this.requiredReviewerCount,
|
|
167
|
+
publishBlockedByOpenThreads: unresolvedThreadCount > 0
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private requireParticipant(id: string): ReviewParticipant {
|
|
173
|
+
const participant = this.participants.get(id);
|
|
174
|
+
if (!participant) throw new Error(`Unknown review participant: ${id}`);
|
|
175
|
+
return participant;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private requireThread(id: string): ReviewThread {
|
|
179
|
+
const thread = this.threads.get(id);
|
|
180
|
+
if (!thread) throw new Error(`Unknown review thread: ${id}`);
|
|
181
|
+
return thread;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function createMultiUserReviewWorkflow(state: MultiUserReviewWorkflowState): MultiUserReviewWorkflow {
|
|
186
|
+
return new MultiUserReviewWorkflow(state);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function sanitizeParticipant(participant: ReviewParticipant): ReviewParticipant {
|
|
190
|
+
return {
|
|
191
|
+
id: nonEmpty(participant.id, "Review participant id"),
|
|
192
|
+
name: nonEmpty(participant.name, "Review participant name"),
|
|
193
|
+
role: participant.role,
|
|
194
|
+
active: participant.active
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function sanitizeThread(thread: ReviewThread): ReviewThread {
|
|
199
|
+
if (thread.time !== undefined && (!Number.isFinite(thread.time) || thread.time < 0)) {
|
|
200
|
+
throw new Error("Review thread time must be a non-negative finite number.");
|
|
201
|
+
}
|
|
202
|
+
if (thread.frame !== undefined && (!Number.isInteger(thread.frame) || thread.frame < 0)) {
|
|
203
|
+
throw new Error("Review thread frame must be a non-negative integer.");
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
id: nonEmpty(thread.id, "Review thread id"),
|
|
207
|
+
authorId: nonEmpty(thread.authorId, "Review thread author"),
|
|
208
|
+
text: nonEmpty(thread.text, "Review thread text"),
|
|
209
|
+
time: thread.time,
|
|
210
|
+
frame: thread.frame,
|
|
211
|
+
assignedTo: thread.assignedTo,
|
|
212
|
+
resolved: thread.resolved
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function sanitizeDecision(decision: ReviewDecision): ReviewDecision {
|
|
217
|
+
return {
|
|
218
|
+
reviewerId: nonEmpty(decision.reviewerId, "Review decision reviewer"),
|
|
219
|
+
status: decision.status,
|
|
220
|
+
at: nonEmpty(decision.at, "Review decision timestamp"),
|
|
221
|
+
note: decision.note
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function nonEmpty(value: string, label: string): string {
|
|
226
|
+
const trimmed = value.trim();
|
|
227
|
+
if (!trimmed) throw new Error(`${label} must be a non-empty string.`);
|
|
228
|
+
return trimmed;
|
|
229
|
+
}
|