mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* feat(studio): track completed preview editing gestures * fix(studio): preserve gesture receipts and suppress duplicate usage * fix(studio): count semantic keyframe writes once per gesture * fix(studio): isolate recording state during pending saves * fix(studio): count marquee selection changes from owner receipts * fix(studio): retain accurate empty marquee receipts * refactor(studio): simplify recording transitions and selection tests * refactor(studio): share recording timing and marquee fixtures * fix(studio): preserve recording targets and batch attribution * fix(studio): retain per-member telemetry suppression * style(studio): format batch receipt attribution * test(studio): match writer receipts and animation metadata * docs(studio): clarify paused position save rejection * fix(studio): replace telemetry route names with route identity * style(studio): format route identity regression * Use random tab-local route identities in Studio telemetry * Preserve route identities inherited through session storage * Separate route storage validation from token creation
80 lines
2.7 KiB
TypeScript
80 lines
2.7 KiB
TypeScript
import type { CommitMutationOptions, MutationResult } from "../hooks/gsapScriptCommitTypes";
|
|
import { trackStudioEvent } from "./studioTelemetry";
|
|
|
|
export type KeyframeUsageAction = "add" | "convert" | "remove_all" | "reset";
|
|
|
|
export function keyframeUsageActions(
|
|
mutations: ReadonlyArray<Record<string, unknown>>,
|
|
semanticActions?: ReadonlyArray<KeyframeUsageAction | undefined>,
|
|
): Set<KeyframeUsageAction> {
|
|
const actions = new Set<KeyframeUsageAction>();
|
|
for (const [index, mutation] of mutations.entries()) {
|
|
const semanticAction = semanticActions?.[index];
|
|
if (semanticAction) {
|
|
actions.add(semanticAction);
|
|
continue;
|
|
}
|
|
switch (mutation.type) {
|
|
case "add-keyframe":
|
|
case "add-with-keyframes":
|
|
actions.add("add");
|
|
break;
|
|
case "convert-to-keyframes":
|
|
actions.add("convert");
|
|
break;
|
|
case "remove-all-keyframes":
|
|
actions.add("remove_all");
|
|
break;
|
|
}
|
|
}
|
|
return actions;
|
|
}
|
|
|
|
export function trackKeyframeUsage(action: KeyframeUsageAction, property?: string): void {
|
|
trackStudioEvent("keyframe", property === undefined ? { action } : { action, property });
|
|
}
|
|
|
|
export function primaryKeyframeAction(
|
|
actions: ReadonlySet<KeyframeUsageAction>,
|
|
): KeyframeUsageAction | undefined {
|
|
return (["add", "convert", "remove_all", "reset"] as const).find((action) => actions.has(action));
|
|
}
|
|
|
|
export function changedMutationIndices(
|
|
result: MutationResult,
|
|
count: number,
|
|
options?: ReadonlyArray<Pick<CommitMutationOptions, "keyframeTelemetry">>,
|
|
): number[] {
|
|
if (!result.ok || result.changed !== true) return [];
|
|
const changes = count === 1 ? [true] : result.mutationChanges;
|
|
if (
|
|
!Array.isArray(changes) ||
|
|
changes.length !== count ||
|
|
changes.some((value) => typeof value !== "boolean")
|
|
)
|
|
return [];
|
|
return changes.flatMap((changed, index) =>
|
|
changed && options?.[index]?.keyframeTelemetry !== false ? [index] : [],
|
|
);
|
|
}
|
|
|
|
export function trackKeyframeCommit(
|
|
mutations: ReadonlyArray<Record<string, unknown>>,
|
|
result: MutationResult,
|
|
options: CommitMutationOptions,
|
|
memberOptions?: ReadonlyArray<CommitMutationOptions>,
|
|
): void {
|
|
if (!result.ok || result.changed !== true || options.keyframeTelemetry === false) return;
|
|
const indices = changedMutationIndices(result, mutations.length, memberOptions);
|
|
const actions = keyframeUsageActions(
|
|
indices.map((index) => mutations[index]!),
|
|
indices.map(
|
|
(index) =>
|
|
memberOptions?.[index]?.keyframeAction ??
|
|
(mutations.length === 1 ? options.keyframeAction : undefined),
|
|
),
|
|
);
|
|
const action = primaryKeyframeAction(actions);
|
|
if (action) trackKeyframeUsage(action, action === "add" ? options.keyframeProperty : undefined);
|
|
}
|