()
| 163 | |
| 164 | // fallow-ignore-next-line complexity |
| 165 | getElementTimings(): Record<HfId, ElementTimingSnapshot> { |
| 166 | const script = getGsapScript(this.parsed.document); |
| 167 | |
| 168 | // Extract all addLabel("name", position) calls from the GSAP script (see cache note above). |
| 169 | let allLabels: ReturnType<typeof extractGsapLabels>; |
| 170 | if (script && this._gsapLabelCache?.script === script) { |
| 171 | allLabels = this._gsapLabelCache.labels; |
| 172 | } else { |
| 173 | allLabels = script ? extractGsapLabels(script) : []; |
| 174 | this._gsapLabelCache = script ? { script, labels: allLabels } : null; |
| 175 | } |
| 176 | |
| 177 | const result: Record<HfId, ElementTimingSnapshot> = {}; |
| 178 | const elements = this.getElements(); |
| 179 | for (const el of elements) { |
| 180 | const domEl = resolveScoped(this.parsed.document, el.scopedId); |
| 181 | if (!domEl) continue; |
| 182 | |
| 183 | const startStr = domEl.getAttribute("data-start"); |
| 184 | const endStr = domEl.getAttribute("data-end"); |
| 185 | const durationStr = domEl.getAttribute("data-duration"); |
| 186 | |
| 187 | // Same preference as handleSetTiming: prefer data-duration, fall back to end - start. |
| 188 | const start = startStr !== null ? parseFloat(startStr) : 0; |
| 189 | const durationAttr = durationStr !== null ? parseFloat(durationStr) : null; |
| 190 | const endAttr = endStr !== null ? parseFloat(endStr) : null; |
| 191 | |
| 192 | let duration: number; |
| 193 | if (durationAttr !== null && Number.isFinite(durationAttr)) { |
| 194 | duration = durationAttr; |
| 195 | } else if (endAttr !== null && Number.isFinite(endAttr)) { |
| 196 | duration = endAttr - start; |
| 197 | } else { |
| 198 | // No timing info — skip non-timed elements. |
| 199 | continue; |
| 200 | } |
| 201 | |
| 202 | const enterAt = Number.isFinite(start) ? start : 0; |
| 203 | const exitAt = enterAt + (Number.isFinite(duration) ? duration : 0); |
| 204 | |
| 205 | // Labels whose position falls within [enterAt, exitAt] (end-inclusive: a |
| 206 | // label exactly at exitAt is treated as within the element's window). |
| 207 | const labels = allLabels |
| 208 | .filter(({ position }) => position >= enterAt && position <= exitAt) |
| 209 | .map(({ name }) => name); |
| 210 | |
| 211 | result[el.scopedId] = { enterAt, exitAt, labels }; |
| 212 | } |
| 213 | |
| 214 | return result; |
| 215 | } |
| 216 | |
| 217 | setElementTiming( |
| 218 | map: Record<HfId, { start?: number; duration?: number; trackIndex?: number }>, |
nothing calls this directly
no test coverage detected