export class RenderStateInspector {
    capture(source) {
        return new Map(source.captureState());
    }
    diff(before, after) {
        const keys = new Set([...before.keys(), ...after.keys()]);
        const diffs = [];
        for (const key of keys) {
            const beforeValue = before.get(key);
            const afterValue = after.get(key);
            if (beforeValue !== afterValue) {
                diffs.push({ key, before: beforeValue, after: afterValue });
            }
        }
        return diffs;
    }
    assertNoLeak(before, after, ignoredKeys = []) {
        const ignored = new Set(ignoredKeys);
        const leaks = this.diff(before, after).filter((diff) => !ignored.has(diff.key));
        if (leaks.length > 0) {
            throw new RenderStateLeakError("Render state leak detected", leaks);
        }
    }
}
export class RenderStateLeakError extends Error {
    leaks;
    constructor(message, leaks) {
        super(message);
        this.leaks = leaks;
        this.name = "RenderStateLeakError";
    }
}
//# sourceMappingURL=RenderStateInspector.js.map