@aura3d/editor-runtime 1.0.6 → 1.1.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/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/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 +30 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/AssetDropZone.ts +144 -0
- package/src/CameraPathEditor.ts +223 -0
- package/src/CartoonSceneEditor.ts +368 -0
- package/src/CurveEditor.ts +152 -0
- package/src/EpisodeReviewPanel.ts +236 -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 +53 -0
- package/tests/editor-runtime.test.ts +490 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
export type EpisodeReviewStatus = "draft" | "needs-review" | "approved" | "rejected";
|
|
2
|
+
|
|
3
|
+
export interface EpisodeReviewRejectedFrame {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly time: number;
|
|
6
|
+
readonly reason: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface EpisodeReviewNote {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly author: string;
|
|
12
|
+
readonly text: string;
|
|
13
|
+
readonly time?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface EpisodeReviewWaveformLane {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly label: string;
|
|
19
|
+
readonly startTime: number;
|
|
20
|
+
readonly duration: number;
|
|
21
|
+
readonly peakCount: number;
|
|
22
|
+
readonly pathPointCount: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface EpisodeReviewManualVisemeEdit {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly characterId: string;
|
|
28
|
+
readonly visemeId: string;
|
|
29
|
+
readonly startTime: number;
|
|
30
|
+
readonly endTime: number;
|
|
31
|
+
readonly reason?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface EpisodeReviewPanelState {
|
|
35
|
+
readonly packageId: string;
|
|
36
|
+
readonly packageHash?: string;
|
|
37
|
+
readonly status: EpisodeReviewStatus;
|
|
38
|
+
readonly reviewer?: string;
|
|
39
|
+
readonly approvedAt?: string;
|
|
40
|
+
readonly notes: readonly EpisodeReviewNote[];
|
|
41
|
+
readonly rejectedFrames: readonly EpisodeReviewRejectedFrame[];
|
|
42
|
+
readonly waveformLanes?: readonly EpisodeReviewWaveformLane[];
|
|
43
|
+
readonly manualVisemeEdits?: readonly EpisodeReviewManualVisemeEdit[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface EpisodeReviewPanelSnapshot extends EpisodeReviewPanelState {
|
|
47
|
+
readonly kind: "episode-review-panel";
|
|
48
|
+
readonly approvalRecorded: boolean;
|
|
49
|
+
readonly rejectedFrameCount: number;
|
|
50
|
+
readonly noteCount: number;
|
|
51
|
+
readonly waveformLaneCount: number;
|
|
52
|
+
readonly manualVisemeEditCount: number;
|
|
53
|
+
readonly reviewUiEvidence: {
|
|
54
|
+
readonly waveformReview: boolean;
|
|
55
|
+
readonly manualVisemeEdits: boolean;
|
|
56
|
+
readonly visualFrameReview: boolean;
|
|
57
|
+
readonly reviewerNotes: boolean;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class EpisodeReviewPanel {
|
|
62
|
+
private state: EpisodeReviewPanelState;
|
|
63
|
+
|
|
64
|
+
constructor(state: EpisodeReviewPanelState) {
|
|
65
|
+
this.state = sanitizeReviewState(state);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
addNote(note: EpisodeReviewNote): EpisodeReviewPanelSnapshot {
|
|
69
|
+
this.state = sanitizeReviewState({
|
|
70
|
+
...this.state,
|
|
71
|
+
notes: [...this.state.notes, sanitizeReviewNote(note)]
|
|
72
|
+
});
|
|
73
|
+
return this.snapshot();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
rejectFrame(frame: EpisodeReviewRejectedFrame): EpisodeReviewPanelSnapshot {
|
|
77
|
+
this.state = sanitizeReviewState({
|
|
78
|
+
...this.state,
|
|
79
|
+
status: "rejected",
|
|
80
|
+
rejectedFrames: [...this.state.rejectedFrames, sanitizeRejectedFrame(frame)]
|
|
81
|
+
});
|
|
82
|
+
return this.snapshot();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setWaveformLanes(waveformLanes: readonly EpisodeReviewWaveformLane[]): EpisodeReviewPanelSnapshot {
|
|
86
|
+
this.state = sanitizeReviewState({
|
|
87
|
+
...this.state,
|
|
88
|
+
waveformLanes: waveformLanes.map(sanitizeWaveformLane)
|
|
89
|
+
});
|
|
90
|
+
return this.snapshot();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
applyManualVisemeEdit(edit: EpisodeReviewManualVisemeEdit): EpisodeReviewPanelSnapshot {
|
|
94
|
+
const sanitized = sanitizeManualVisemeEdit(edit);
|
|
95
|
+
this.state = sanitizeReviewState({
|
|
96
|
+
...this.state,
|
|
97
|
+
manualVisemeEdits: [
|
|
98
|
+
...((this.state.manualVisemeEdits ?? []).filter((candidate) => candidate.id !== sanitized.id)),
|
|
99
|
+
sanitized
|
|
100
|
+
]
|
|
101
|
+
});
|
|
102
|
+
return this.snapshot();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
approve(reviewer: string, approvedAt = new Date(0).toISOString()): EpisodeReviewPanelSnapshot {
|
|
106
|
+
const name = nonEmpty(reviewer, "Episode review reviewer");
|
|
107
|
+
if (this.state.rejectedFrames.length > 0) {
|
|
108
|
+
throw new Error("Episode review cannot be approved while rejected frames are present.");
|
|
109
|
+
}
|
|
110
|
+
this.state = sanitizeReviewState({
|
|
111
|
+
...this.state,
|
|
112
|
+
status: "approved",
|
|
113
|
+
reviewer: name,
|
|
114
|
+
approvedAt
|
|
115
|
+
});
|
|
116
|
+
return this.snapshot();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
markNeedsReview(): EpisodeReviewPanelSnapshot {
|
|
120
|
+
this.state = sanitizeReviewState({
|
|
121
|
+
...this.state,
|
|
122
|
+
status: "needs-review",
|
|
123
|
+
reviewer: undefined,
|
|
124
|
+
approvedAt: undefined
|
|
125
|
+
});
|
|
126
|
+
return this.snapshot();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
serialize(): EpisodeReviewPanelState {
|
|
130
|
+
return sanitizeReviewState(this.state);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
snapshot(): EpisodeReviewPanelSnapshot {
|
|
134
|
+
const waveformLanes = this.state.waveformLanes ?? [];
|
|
135
|
+
const manualVisemeEdits = this.state.manualVisemeEdits ?? [];
|
|
136
|
+
return {
|
|
137
|
+
kind: "episode-review-panel",
|
|
138
|
+
...this.serialize(),
|
|
139
|
+
approvalRecorded: this.state.status === "approved" && Boolean(this.state.reviewer),
|
|
140
|
+
rejectedFrameCount: this.state.rejectedFrames.length,
|
|
141
|
+
noteCount: this.state.notes.length,
|
|
142
|
+
waveformLaneCount: waveformLanes.length,
|
|
143
|
+
manualVisemeEditCount: manualVisemeEdits.length,
|
|
144
|
+
reviewUiEvidence: {
|
|
145
|
+
waveformReview: waveformLanes.length > 0,
|
|
146
|
+
manualVisemeEdits: manualVisemeEdits.length > 0,
|
|
147
|
+
visualFrameReview: this.state.rejectedFrames.length > 0,
|
|
148
|
+
reviewerNotes: this.state.notes.length > 0
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function createEpisodeReviewPanel(state: EpisodeReviewPanelState): EpisodeReviewPanel {
|
|
155
|
+
return new EpisodeReviewPanel(state);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function sanitizeReviewState(state: EpisodeReviewPanelState): EpisodeReviewPanelState {
|
|
159
|
+
return {
|
|
160
|
+
packageId: nonEmpty(state.packageId, "Episode review packageId"),
|
|
161
|
+
packageHash: state.packageHash,
|
|
162
|
+
status: state.status,
|
|
163
|
+
reviewer: state.reviewer,
|
|
164
|
+
approvedAt: state.approvedAt,
|
|
165
|
+
notes: state.notes.map(sanitizeReviewNote),
|
|
166
|
+
rejectedFrames: state.rejectedFrames.map(sanitizeRejectedFrame),
|
|
167
|
+
waveformLanes: (state.waveformLanes ?? []).map(sanitizeWaveformLane),
|
|
168
|
+
manualVisemeEdits: (state.manualVisemeEdits ?? []).map(sanitizeManualVisemeEdit)
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function sanitizeReviewNote(note: EpisodeReviewNote): EpisodeReviewNote {
|
|
173
|
+
return {
|
|
174
|
+
id: nonEmpty(note.id, "Episode review note id"),
|
|
175
|
+
author: nonEmpty(note.author, "Episode review note author"),
|
|
176
|
+
text: nonEmpty(note.text, "Episode review note text"),
|
|
177
|
+
time: note.time
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function sanitizeRejectedFrame(frame: EpisodeReviewRejectedFrame): EpisodeReviewRejectedFrame {
|
|
182
|
+
if (!Number.isFinite(frame.time) || frame.time < 0) {
|
|
183
|
+
throw new Error("Episode review rejected frame time must be a non-negative finite number.");
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
id: nonEmpty(frame.id, "Episode review rejected frame id"),
|
|
187
|
+
time: frame.time,
|
|
188
|
+
reason: nonEmpty(frame.reason, "Episode review rejected frame reason")
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function sanitizeWaveformLane(lane: EpisodeReviewWaveformLane): EpisodeReviewWaveformLane {
|
|
193
|
+
if (!Number.isFinite(lane.startTime) || lane.startTime < 0) {
|
|
194
|
+
throw new Error("Episode review waveform lane startTime must be a non-negative finite number.");
|
|
195
|
+
}
|
|
196
|
+
if (!Number.isFinite(lane.duration) || lane.duration < 0) {
|
|
197
|
+
throw new Error("Episode review waveform lane duration must be a non-negative finite number.");
|
|
198
|
+
}
|
|
199
|
+
if (!Number.isInteger(lane.peakCount) || lane.peakCount < 0) {
|
|
200
|
+
throw new Error("Episode review waveform lane peakCount must be a non-negative integer.");
|
|
201
|
+
}
|
|
202
|
+
if (!Number.isInteger(lane.pathPointCount) || lane.pathPointCount < 0) {
|
|
203
|
+
throw new Error("Episode review waveform lane pathPointCount must be a non-negative integer.");
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
id: nonEmpty(lane.id, "Episode review waveform lane id"),
|
|
207
|
+
label: nonEmpty(lane.label, "Episode review waveform lane label"),
|
|
208
|
+
startTime: lane.startTime,
|
|
209
|
+
duration: lane.duration,
|
|
210
|
+
peakCount: lane.peakCount,
|
|
211
|
+
pathPointCount: lane.pathPointCount
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function sanitizeManualVisemeEdit(edit: EpisodeReviewManualVisemeEdit): EpisodeReviewManualVisemeEdit {
|
|
216
|
+
if (!Number.isFinite(edit.startTime) || edit.startTime < 0) {
|
|
217
|
+
throw new Error("Episode review manual viseme startTime must be a non-negative finite number.");
|
|
218
|
+
}
|
|
219
|
+
if (!Number.isFinite(edit.endTime) || edit.endTime <= edit.startTime) {
|
|
220
|
+
throw new Error("Episode review manual viseme endTime must be greater than startTime.");
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
id: nonEmpty(edit.id, "Episode review manual viseme id"),
|
|
224
|
+
characterId: nonEmpty(edit.characterId, "Episode review manual viseme characterId"),
|
|
225
|
+
visemeId: nonEmpty(edit.visemeId, "Episode review manual viseme visemeId"),
|
|
226
|
+
startTime: edit.startTime,
|
|
227
|
+
endTime: edit.endTime,
|
|
228
|
+
reason: edit.reason
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function nonEmpty(value: string, label: string): string {
|
|
233
|
+
const trimmed = value.trim();
|
|
234
|
+
if (!trimmed) throw new Error(`${label} must be a non-empty string.`);
|
|
235
|
+
return trimmed;
|
|
236
|
+
}
|
|
@@ -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
|
+
}
|