<commit_before>type Size = { width: number, height: number };

export class HdpiCanvas {
    constructor(width = 300, height = 150) {
        this.updatePixelRatio(0, false);
        this.resize(width, height);
    }

    remove() {
        const parent = this.canvas.parentNode;

        if (parent !== null) {
            parent.removeChild(this.canvas);
        }
    }

    _canvas = document.createElement('canvas');
    get canvas(): HTMLCanvasElement {
        return this._canvas;
    }

    destroy() {
        this._canvas.remove();
        (this as any)._canvas = undefined;
        Object.freeze(this);
    }

    // `NaN` is deliberate here, so that overrides are always applied
    // and the `resetTransform` inside the `resize` method works in IE11.
    _pixelRatio: number = NaN;
    get pixelRatio(): number {
        return this._pixelRatio;
    }

    private overrides: any;

    /**
     * Updates the pixel ratio of the Canvas element with the given value,
     * or uses the window.devicePixelRatio (default), then resizes the Canvas
     * element accordingly (default).
     * @param ratio
     * @param resize
     */
    updatePixelRatio(ratio = 0, resize = true) {
        const pixelRatio = ratio || window.devicePixelRatio;

        if (pixelRatio === this.pixelRatio) {
            return;
        }

        const canvas = this._canvas;
        const ctx = canvas.getContext('2d')!;
        const overrides = this.overrides = HdpiCanvas.makeHdpiOverrides(pixelRatio);
        for (const name in overrides) {
            if (overrides.hasOwnProperty(name)) {<commit_msg>HdpiCanvas: 'parent' and 'context' properties, make 'remove' method private.<commit_after>type Size = { width: number, height: number };

/**
 * Wraps the native Canvas element and overrides its CanvasRenderingContext2D to
 * provide resolution independent rendering based on `window.devicePixelRatio`.
 */
export class HdpiCanvas {
    // The width/height attributes of the Canvas element default to
    // 300/150 according to w3.org.
    constructor(width = 300, height = 150) {
        this.updatePixelRatio(0, false);
        this.resize(width, height);
    }

    private _parent: HTMLElement | null = null;
    set parent(value: HTMLElement | null) {
        if (this._parent !== value) {
            this.remove();
            if (value) {
                value.appendChild(this.canvas);
            }
            this._parent = value;
        }

    }
    get parent(): HTMLElement | null {
        return this._parent;
    }

    private remove() {
        const parent = this.canvas.parentNode;

        if (parent !== null) {
            parent.removeChild(this.canvas);
        }
    }

    readonly canvas = document.createElement('canvas');

    readonly context = this.canvas.getContext('2d')!;

    destroy() {
        this.canvas.remove();
        (this as any)._canvas = undefined;
        Object.freeze(this);
    }

    // `NaN` is deliberate here, so that overrides are always applied
    // and the `resetTransform` inside the `resize` method works in IE11.
    _pixelRatio: number = NaN;
    get pixelRatio(): number {
        return this._pixelRatio;
    }

    private overrides: any;

    /**
     * Updates the pixel ratio of the Canvas element with the given value,
     * or uses the window.devicePixelRatio (default), then resizes the Canvas
     * element accordingly (default).
     * @param ratio
     * @param resize
     */
    updatePixelRatio(ratio = 0, resize = true) {
        const pixelRatio = ratio || window.devicePixelRatio;

        if (pixelRatio === this.pixelRatio) {
            return;
        }

        const canvas = this.canvas;
        const ctx = this.context;
        const overrides = this.overrides = HdpiCanvas.makeHdpiOverrides(pixelRatio);
        for (const name in overrides) {
            if (overrides.hasOwnProperty(name)) {
{'fraction_non_alphanumeric': 0.10503338469440164, 'fraction_numerical': 0.007704160246533128, 'mean_word_length': 2.3177172061328792, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2766625', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1068, 'n_words': 316}