<commit_before>"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const puppeteer_1 = __importDefault(require("puppeteer"));
const delay = require('../delay/delay');
const DEFAULT_OPTIONS = { name: 'chromium', headless: true };
const DEFAULT_VISIBILITY_TIMEOUT = 30000;
const DEFAULT_WAIT_INITIAL_DELAY = 100;
const DEFAULT_WAIT_POLL_INTERVAL = 250;
class Chromium {
    constructor(options) {
        this._options = { ...DEFAULT_OPTIONS, ...options };
        this._browser = null;
        this._page = null;
    }
    get name() {
        return this._options.name;
    }
    async start() {
        this._browser = await puppeteer_1.default.launch({
            headless: this._options.headless,
            defaultViewport: {
                width: this._options.width,
                height: this._options.height,
            },
            ignoreDefaultArgs: ['--enable-automation'],
            args: [
                '--incognito',
                '--start-maximized',
                '--no-default-browser-check',
                '--no-first-run',
                '--disable-translate',
            ],
        });
        this._page = (await this._browser.pages())[0];
        // TODO remove this? or use as consolePipe
        this._page.on('console', event => {
            console.log('ConsolePipe - ', event.type(), event.text());
        });
    }
    async stop() {
        await this._closeAllPages();
        await this._browser.close();
    }
    async _closeAllPages() {
        for (const page of (await this._browser.pages())) {
            await page.close();
        }
    }
    async navigateTo(url) {
        await this._page.goto(url);
    }
    async setViewport(options) {
        await this._page.setViewport(options);
    }
    async click(selector) {
        await this._page.click(selector);
    }
    async focus(selector) {
        await this._page.focus(selector);
    }
    async hover(selector) {
        await this._page.hover(selector);
    }
    async type(selector, text) {
        await this._page.type(selector, text);
    }
    async pressKey(keyName) {
        await this._page.keyboard.press(keyName);
    }
    async scroll(selector, scrollTop) {
        await this._page.evaluate(function (sel, sTop) {
            // @ts-expect-error
            document.querySelector(sel).scrollTop = sTop;
        }, selector, scrollTop);
    }
    async scrollIntoView(selector) {
        await this._page.evaluate(function (sel) {
            // @ts-expect-error
            document.querySelector(sel).scrollIntoView();
        }, selector);
    }
    async execFunction(fn, ...args) {
        // @ts-expect-error
        return this._page.evaluate(fn, ...args);
    }
    async getValue(selector) {
        return this._page.evaluate(function (sel) {
            // @ts-expect-error
            const node = document.querySelector(sel);
            if (node === null) {
                throw new Error(`getValue: selector not found: ${sel}`);
            }
            if (node.tagName === 'INPUT' && node.type === 'checkbox') {
                return node.checked;
            }
            if (node.tagName === 'INPUT' || node.tagName === 'TEXTAREA') {
                return node.value;
            }
            return node.innerText;
        }, selector);
    }
    async screenshot(options) {
        const screenshotOptions = {
            encoding: 'binary',
        };
        // TODO if selector, get boundingclientrect
        return this._page.screenshot({ encoding: 'binary' });
    }
    async isVisible(selector) {
        const result = await this._page.evaluate(function (sel) {
            // @ts-expect-error
            const nodes = document.querySelectorAll(sel);
            if (nodes.length === 0) {
                return false;
            }
            const hasVisible = [...nodes].some(node => {
                // @ts-expect-error
                const computedStyle = window.getComputedStyle(node);
                return computedStyle.getPropertyValue('display') !== 'none' && computedStyle.getPropertyValue('visibility') !== 'hidden';
            });
            if (!hasVisible) {
                return false;
            }
            for (const node of nodes) {
                const rect = node.getBoundingClientRect();
                const centerX = rect.left + rect.width / 2;
                const centerY = rect.top + rect.height / 2;
                // @ts-expect-error
                const elementFromPoint = document.elementFromPoint(centerX, centerY);<commit_msg>Update ts-dist<commit_after>"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const puppeteer_1 = __importDefault(require("puppeteer"));
const delay = require('../delay/delay');
const DEFAULT_OPTIONS = { name: 'chromium', headless: true };
const DEFAULT_VISIBILITY_TIMEOUT = 30000;
const DEFAULT_WAIT_INITIAL_DELAY = 100;
const DEFAULT_WAIT_POLL_INTERVAL = 250;
class Chromium {
    constructor(options) {
        this._options = { ...DEFAULT_OPTIONS, ...options };
        this._browser = null;
        this._page = null;
    }
    get name() {
        return this._options.name;
    }
    async start() {
        this._browser = await puppeteer_1.default.launch({
            headless: this._options.headless,
            defaultViewport: {
                width: this._options.width,
                height: this._options.height,
            },
            ignoreDefaultArgs: ['--enable-automation'],
            args: [
                '--incognito',
                '--start-maximized',
                '--no-default-browser-check',
                '--no-first-run',
                '--disable-translate',
            ],
        });
        this._page = (await this._browser.pages())[0];
        // TODO remove this? or use as consolePipe
        this._page.on('console', event => {
            console.log('ConsolePipe - ', event.type(), event.text());
        });
    }
    async stop() {
        await this._closeAllPages();
        await this._browser.close();
    }
    async _closeAllPages() {
        for (const page of (await this._browser.pages())) {
            await page.close();
        }
    }
    async navigateTo(url) {
        await this._page.goto(url);
    }
    async setViewport(options) {
        await this._page.setViewport(options);
    }
    async click(selector) {
        await this._page.click(selector);
    }
    async focus(selector) {
        await this._page.focus(selector);
    }
    async hover(selector) {
        await this._page.hover(selector);
    }
    async type(selector, text) {
        await this._page.type(selector, text);
    }
    async pressKey(keyName) {
        await this._page.keyboard.press(keyName);
    }
    async scroll(selector, scrollTop) {
        await this._page.evaluate(function (sel, sTop) {
            // @ts-expect-error
            document.querySelector(sel).scrollTop = sTop;
        }, selector, scrollTop);
    }
    async scrollIntoView(selector) {
        await this._page.evaluate(function (sel) {
            // @ts-expect-error
            document.querySelector(sel).scrollIntoView();
        }, selector);
    }
    async execFunction(fn, ...args) {
        // @ts-expect-error
        return this._page.evaluate(fn, ...args);
    }
    async getValue(selector) {
        return this._page.evaluate(function (sel) {
            // @ts-expect-error
            const node = document.querySelector(sel);
            if (node === null) {
                throw new Error(`getValue: selector not found: ${sel}`);
            }
            if (node.tagName === 'INPUT' && node.type === 'checkbox') {
                return node.checked;
            }
            if (node.tagName === 'INPUT' || node.tagName === 'TEXTAREA') {
                return node.value;
            }
            return node.innerText;
        }, selector);
    }
    async screenshot() {
        // TODO implement selector, get boundingclientrect, etc
        return this._page.screenshot({ encoding: 'binary' });
    }
    async isVisible(selector) {
        const result = await this._page.evaluate(function (sel) {
            // @ts-expect-error
            const nodes = document.querySelectorAll(sel);
            if (nodes.length === 0) {
                return false;
            }
            const hasVisible = [...nodes].some(node => {
                // @ts-expect-error
                const computedStyle = window.getComputedStyle(node);
                return computedStyle.getPropertyValue('display') !== 'none' && computedStyle.getPropertyValue('visibility') !== 'hidden';
            });
            if (!hasVisible) {
                return false;
            }
            for (const node of nodes) {
                const rect = node.getBoundingClientRect();
                const centerX = rect.left + rect.width / 2;
                const centerY = rect.top + rect.height / 2;
                // @ts-expect-error
                const elementFromPoint = document.elementFromPoint(centerX, centerY);
{'fraction_non_alphanumeric': 0.13072733098365907, 'fraction_numerical': 0.003631314749546086, 'mean_word_length': 1.840157719138611, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5509226', 'n_tokens_mistral': 2594, 'n_tokens_neox': 2550, 'n_words': 531}