Skip to content

Commit 22a52eb

Browse files
committed
refactor(core): prime a tween at its start in one helper
1 parent 14aff01 commit 22a52eb

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

  • packages/core/src/runtime/adapters

‎packages/core/src/runtime/adapters/gsap.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,22 @@ const playsForward = (value: unknown): value is GsapAnimation => {
116116
);
117117
};
118118

119+
function primedAtItsStart(tween: GsapAnimation): boolean {
120+
if (tween.vars?.keyframes) {
121+
tween.render(BELOW_GSAP_TIME_RESOLUTION, true);
122+
tween.render(-BELOW_GSAP_TIME_RESOLUTION, true);
123+
return true;
124+
}
125+
if (!tween._startAt) return false;
126+
tween._startAt.render(BELOW_GSAP_TIME_RESOLUTION, true, true);
127+
return true;
128+
}
129+
119130
function primeTweensStartingAt(children: unknown[], time: number): void {
120131
for (const child of children.filter(playsForward)) {
121132
const local = (time - child.startTime()) * child.timeScale();
122-
if (Math.abs(local) < 1e-9 && child.vars?.keyframes) {
123-
child.render(BELOW_GSAP_TIME_RESOLUTION, true);
124-
child.render(-BELOW_GSAP_TIME_RESOLUTION, true);
125-
} else if (Math.abs(local) < 1e-9 && child._startAt) {
126-
child._startAt.render(BELOW_GSAP_TIME_RESOLUTION, true, true);
127-
} else if (child.getChildren && local > 0 && local <= child.totalDuration()) {
133+
if (Math.abs(local) < 1e-9 && primedAtItsStart(child)) continue;
134+
if (child.getChildren && local > 0 && local <= child.totalDuration()) {
128135
primeTweensStartingAt(child.getChildren(false, true, true), local);
129136
}
130137
}

0 commit comments

Comments
 (0)