MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / normalizeKeyframes

Function normalizeKeyframes

packages/parsers/src/htmlParser.ts:486–533  ·  view source on GitHub ↗
(
  keyframes: Keyframe[],
  baseX: number,
  baseY: number,
  baseScale: number,
)

Source from the content-addressed store, hash-verified

484}
485
486function normalizeKeyframes(
487 keyframes: Keyframe[],
488 baseX: number,
489 baseY: number,
490 baseScale: number,
491): Keyframe[] {
492 const timeEpsilon = 0.001;
493 const valueEpsilon = 0.00001;
494
495 const hasBaseCheck = (value: number | undefined, base: number): boolean =>
496 value !== undefined && Math.abs(value - base) <= valueEpsilon && Math.abs(base) > valueEpsilon;
497
498 const timeZeroKeyframes = keyframes.filter((kf) => Math.abs(kf.time) <= timeEpsilon);
499
500 const treatAsAbsolute = timeZeroKeyframes.some((kf) => {
501 const props = kf.properties || {};
502 if (
503 hasBaseCheck(props.x, baseX) ||
504 hasBaseCheck(props.y, baseY) ||
505 (baseScale !== 1 && hasBaseCheck(props.scale, baseScale))
506 ) {
507 return true;
508 }
509 return false;
510 });
511
512 return keyframes.map((kf) => {
513 const normalizedProps: Partial<KeyframeProperties> = {};
514 for (const [key, value] of Object.entries(kf.properties || {})) {
515 if (typeof value !== "number") continue;
516 if (treatAsAbsolute && key === "x") {
517 normalizedProps.x = value - baseX;
518 } else if (treatAsAbsolute && key === "y") {
519 normalizedProps.y = value - baseY;
520 } else if (treatAsAbsolute && key === "scale") {
521 normalizedProps.scale = baseScale !== 0 ? value / baseScale : value;
522 } else {
523 (normalizedProps as Record<string, number>)[key] = value;
524 }
525 }
526
527 return {
528 ...kf,
529 time: Math.max(0, kf.time),
530 properties: normalizedProps,
531 };
532 });
533}
534
535export function updateElementInHtml(
536 html: string,

Callers 1

parseHtmlFunction · 0.85

Calls 3

hasBaseCheckFunction · 0.85
absMethod · 0.80
entriesMethod · 0.80

Tested by

no test coverage detected