Improve IK-style artifact scanner pipeline

This commit is contained in:
AzuTear
2026-07-07 22:02:24 +02:00
parent 8ebbe91c39
commit f791d1464c
70 changed files with 7408 additions and 445 deletions
+8 -3
View File
@@ -16,6 +16,8 @@ export interface CardReadyOptions {
maxWaitMs?: number;
/** Delay between samples. */
pollIntervalMs?: number;
/** Proceed with changed-but-animated content after this much elapsed time. */
acceptChangedAfterMs?: number;
}
export interface CardReadyDeps {
@@ -53,6 +55,7 @@ export async function waitForCardReady(
const minStable = Math.max(1, options.minStableSamples ?? DEFAULT_MIN_STABLE);
const maxWaitMs = Math.max(0, options.maxWaitMs ?? DEFAULT_MAX_WAIT_MS);
const pollIntervalMs = Math.max(1, options.pollIntervalMs ?? DEFAULT_POLL_MS);
const acceptChangedAfterMs = Math.max(0, options.acceptChangedAfterMs ?? maxWaitMs);
const start = deps.now();
let previousSample = "";
@@ -77,11 +80,13 @@ export async function waitForCardReady(
const changed = Boolean(latest) && latest !== previousFingerprint;
const stable = stableCount >= minStable;
if (changed && stable) {
return { ready: true, changed: true, stable: true, fingerprint: latest, abortReason: "", polls };
const elapsedMs = deps.now() - start;
if (changed && (stable || elapsedMs >= acceptChangedAfterMs)) {
return { ready: true, changed: true, stable, fingerprint: latest, abortReason: "", polls };
}
if (deps.now() - start >= maxWaitMs) {
if (elapsedMs >= maxWaitMs) {
// Budget spent. Proceed if the content has at least changed, even if it is
// still animating (never fully stabilizes).
return { ready: changed, changed, stable, fingerprint: latest, abortReason: "", polls };