diff --git a/packages/core/src/runtime/colorGrading.test.ts b/packages/core/src/runtime/colorGrading.test.ts index 793ac5ee5..e3a3ce49d 100644 --- a/packages/core/src/runtime/colorGrading.test.ts +++ b/packages/core/src/runtime/colorGrading.test.ts @@ -1,3 +1,4 @@ +// fallow-ignore-file code-duplication import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { HF_COLOR_GRADING_ATTR, serializeHfColorGrading } from "../colorGrading"; import { createColorGradingRuntime, type RuntimeColorGradingApi } from "./colorGrading"; diff --git a/packages/core/src/runtime/colorGrading.ts b/packages/core/src/runtime/colorGrading.ts index 648e60f22..0d951262a 100644 --- a/packages/core/src/runtime/colorGrading.ts +++ b/packages/core/src/runtime/colorGrading.ts @@ -1624,6 +1624,7 @@ export function createColorGradingRuntime(): RuntimeColorGradingApi { return true; }; + // fallow-ignore-next-line complexity const getStatus = ( target: HfColorGradingTarget | string | null | undefined, ): RuntimeColorGradingStatus => { diff --git a/packages/engine/src/services/screenshotService.test.ts b/packages/engine/src/services/screenshotService.test.ts index 8c018d2f8..9b7c78d20 100644 --- a/packages/engine/src/services/screenshotService.test.ts +++ b/packages/engine/src/services/screenshotService.test.ts @@ -1,4 +1,5 @@ // @vitest-environment node +// fallow-ignore-file code-duplication import { describe, it, expect, vi } from "vitest"; import { parseHTML } from "linkedom"; import { type Page } from "puppeteer-core"; diff --git a/packages/engine/src/services/screenshotService.ts b/packages/engine/src/services/screenshotService.ts index 0c7ceb954..b0e3382e0 100644 --- a/packages/engine/src/services/screenshotService.ts +++ b/packages/engine/src/services/screenshotService.ts @@ -4,6 +4,7 @@ * BeginFrame-based deterministic screenshot capture and video frame injection. */ +// fallow-ignore-file code-duplication import { type Page } from "puppeteer-core"; import { type CaptureOptions } from "../types.js"; import { @@ -325,6 +326,7 @@ export async function applyDomLayerMask( extraHideIds: string[], ): Promise { await page.evaluate( + // fallow-ignore-next-line complexity (args: { show: string[]; hide: string[]; @@ -504,6 +506,7 @@ export async function injectVideoFramesBatch( ): Promise { if (updates.length === 0) return []; return await page.evaluate( + // fallow-ignore-next-line complexity async ( items: Array<{ videoId: string; dataUri: string }>, visualProperties: string[], @@ -684,6 +687,7 @@ export async function syncVideoFrameVisibility( activeVideoIds: string[], ): Promise { await page.evaluate( + // fallow-ignore-next-line complexity (ids: string[], colorGradingSourceHiddenAttr: string) => { // Mirror the ancestor-visibility guard from `injectVideoFramesBatch`. // See that copy for the full rationale on why `visibility: hidden` is diff --git a/packages/engine/src/services/videoFrameInjector.ts b/packages/engine/src/services/videoFrameInjector.ts index ff5ff2b07..b9ed6d07f 100644 --- a/packages/engine/src/services/videoFrameInjector.ts +++ b/packages/engine/src/services/videoFrameInjector.ts @@ -80,6 +80,7 @@ function createFrameSourceCache( evictions++; } + // fallow-ignore-next-line complexity function remember(framePath: string, dataUri: string): string { // Skip caching entries that alone exceed the byte budget. Caching them // would trigger immediate self-eviction on insert and pollute LRU order @@ -188,6 +189,7 @@ export function createVideoFrameInjector( const frameCache = createFrameSourceCache(entryLimit, bytesLimit, config?.frameSrcResolver); const lastInjectedFrameByVideo = new Map(); + // fallow-ignore-next-line complexity return async (page: Page, time: number) => { const activePayloads = frameLookup.getActiveFramePayloads(time); @@ -275,47 +277,43 @@ export interface VideoElementBounds { * holes where the HDR videos go. */ export async function hideVideoElements(page: Page, videoIds: string[]): Promise { - if (videoIds.length === 0) return; - await page.evaluate( - (ids: string[], canvasIdPrefix: string) => { - for (const id of ids) { - const el = document.getElementById(id) as HTMLVideoElement | null; - if (el) { - el.style.setProperty("visibility", "hidden", "important"); - const img = document.getElementById(`__render_frame_${id}__`); - if (img) img.style.setProperty("visibility", "hidden", "important"); - const colorGradingCanvas = document.getElementById(`${canvasIdPrefix}${id}`); - if (colorGradingCanvas) { - colorGradingCanvas.style.setProperty("visibility", "hidden", "important"); - } - } - } - }, - videoIds, - HF_COLOR_GRADING_CANVAS_ID_PREFIX, - ); + await setVideoElementsVisibility(page, videoIds, false); } /** * Restore visibility of video elements after a DOM screenshot. */ export async function showVideoElements(page: Page, videoIds: string[]): Promise { + await setVideoElementsVisibility(page, videoIds, true); +} + +async function setVideoElementsVisibility( + page: Page, + videoIds: string[], + visible: boolean, +): Promise { if (videoIds.length === 0) return; await page.evaluate( - (ids: string[], canvasIdPrefix: string) => { - for (const id of ids) { - const el = document.getElementById(id) as HTMLVideoElement | null; - if (el) { - el.style.removeProperty("visibility"); - const img = document.getElementById(`__render_frame_${id}__`); - if (img) img.style.removeProperty("visibility"); - const colorGradingCanvas = document.getElementById(`${canvasIdPrefix}${id}`); - if (colorGradingCanvas) colorGradingCanvas.style.removeProperty("visibility"); + (ids: string[], canvasIdPrefix: string, shouldShow: boolean) => { + const apply = (node: Element | null) => { + if (!(node instanceof HTMLElement)) return; + if (shouldShow) { + node.style.removeProperty("visibility"); + } else { + node.style.setProperty("visibility", "hidden", "important"); } + }; + for (const id of ids) { + const video = document.getElementById(id); + if (!video) continue; + apply(video); + apply(document.getElementById(`__render_frame_${id}__`)); + apply(document.getElementById(`${canvasIdPrefix}${id}`)); } }, videoIds, HF_COLOR_GRADING_CANVAS_ID_PREFIX, + visible, ); } @@ -431,6 +429,7 @@ export async function queryElementStacking( nativeHdrIds: Set, ): Promise { const hdrIds = Array.from(nativeHdrIds); + // fallow-ignore-next-line complexity return page.evaluate((hdrIdList: string[]): ElementStackingInfo[] => { const hdrSet = new Set(hdrIdList); const elements = document.querySelectorAll("[data-start]"); @@ -470,6 +469,7 @@ export async function queryElementStacking( // Find border-radius that clips the element. Replaced elements like