()
| 193 | } |
| 194 | |
| 195 | function main() { |
| 196 | const { inputPath, forcedFps, forcedMaxDuration } = parseArgs(); |
| 197 | if (!inputPath) { |
| 198 | console.error("Usage: bun run debug:timeline <path-to-html> [--fps 30] [--max-duration 1800]"); |
| 199 | process.exit(2); |
| 200 | } |
| 201 | |
| 202 | const resolvedPath = path.resolve(process.cwd(), inputPath); |
| 203 | if (!fs.existsSync(resolvedPath)) { |
| 204 | console.error(`File not found: ${resolvedPath}`); |
| 205 | process.exit(2); |
| 206 | } |
| 207 | |
| 208 | const html = fs.readFileSync(resolvedPath, "utf-8"); |
| 209 | const tags = parseTags(html); |
| 210 | const root = resolveRootTag(tags); |
| 211 | const rootCompositionId = root?.attrs["data-composition-id"] ?? null; |
| 212 | |
| 213 | const maxDuration = |
| 214 | (forcedMaxDuration != null && forcedMaxDuration > 0 |
| 215 | ? forcedMaxDuration |
| 216 | : extractWindowNumber(html, "window.__HF_MAX_DURATION_SEC")) ?? 1800; |
| 217 | const canonicalFps = |
| 218 | (forcedFps != null && forcedFps > 0 |
| 219 | ? forcedFps |
| 220 | : (parseNum(root?.attrs["data-fps"]) ?? extractWindowNumber(html, "window.__HF_FPS"))) ?? 30; |
| 221 | |
| 222 | const rootDurationRaw = |
| 223 | parseNum(root?.attrs["data-composition-duration"]) ?? |
| 224 | parseNum(root?.attrs["data-duration"]) ?? |
| 225 | parseNum( |
| 226 | tags.find((tag) => tag.tagName === "html")?.attrs["data-composition-duration"] ?? null, |
| 227 | ); |
| 228 | const rootDuration = normalizeDurationSeconds(rootDurationRaw, null, maxDuration); |
| 229 | |
| 230 | const nodes = tags.filter((tag) => shouldIncludeTimelineNode(tag, rootCompositionId)); |
| 231 | const clips: TimelineClip[] = []; |
| 232 | let maxEnd = 0; |
| 233 | let unresolvedClipCount = 0; |
| 234 | |
| 235 | for (let i = 0; i < nodes.length; i += 1) { |
| 236 | const node = nodes[i]; |
| 237 | const attrs = node.attrs; |
| 238 | const start = Math.max(0, parseNum(attrs["data-start"]) ?? 0); |
| 239 | const inferredDuration = inferClipDuration(node, start, maxDuration); |
| 240 | const hasDeterministicDuration = inferredDuration != null && inferredDuration > 0; |
| 241 | let duration = hasDeterministicDuration |
| 242 | ? normalizeDurationSeconds(inferredDuration, 0, maxDuration) |
| 243 | : 0; |
| 244 | let durationSource: "deterministic" | "fallback" = "deterministic"; |
| 245 | if (duration <= 0 && rootDuration > start) { |
| 246 | duration = normalizeDurationSeconds(rootDuration - start, 0, maxDuration); |
| 247 | durationSource = "fallback"; |
| 248 | } |
| 249 | if (duration <= 0) { |
| 250 | unresolvedClipCount += 1; |
| 251 | continue; |
| 252 | } |
no test coverage detected