<commit_before>import {Component, Input, Renderer, ViewChild, ElementRef, Output, EventEmitter, Type} from "@angular/core";
import {ImageCropper} from "./imageCropper";
import {CropperSettings} from "./cropperSettings";
import {Exif} from "./exif";

@Component({
    selector: "img-cropper", template: `
    <span class="ng2-imgcrop">
      <input *ngIf="!settings.noFileInput" type="file" (change)="fileChangeListener($event)" >
      <canvas #cropcanvas
              (mousedown)="onMouseDown($event)"
              (mouseup)="onMouseUp($event)"
              (mousemove)="onMouseMove($event)"
              (touchmove)="onTouchMove($event)"
              (touchend)="onTouchEnd($event)"
              (touchstart)="onTouchStart($event)">
      </canvas>
    </span>
  `
})

export class ImageCropperComponent extends Type {

    @ViewChild("cropcanvas", undefined) private cropcanvas: ElementRef;

    @Input() private settings: CropperSettings;
    @Input() private image: any;
    @Input() private cropper: ImageCropper;

    @Output() private onCrop: EventEmitter<any> = new EventEmitter();

    public croppedWidth: number;
    public croppedHeight: number;

    public intervalRef: number;

    public renderer: Renderer;

    constructor(renderer: Renderer) {
        super();
        this.renderer = renderer;
    }

    public ngAfterViewInit() {
        let canvas: HTMLCanvasElement = this.cropcanvas.nativeElement;

        if (!this.settings) {
            this.settings = new CropperSettings();
        }

        this.renderer.setElementAttribute(canvas, "width", this.settings.canvasWidth.toString());
        this.renderer.setElementAttribute(canvas, "height", this.settings.canvasHeight.toString());

        if (!this.cropper) {
            this.cropper = new ImageCropper(this.settings);
        }

        this.cropper.prepare(canvas);
    }

    public onTouchMove(event: TouchEvent): void {
        this.cropper.onTouchMove(event);
    }

    public onTouchStart(event: TouchEvent): void {
        this.cropper.onTouchStart(event);
    }

    public onTouchEnd(event: TouchEvent): void {
        this.cropper.onTouchEnd(event);
        if (this.cropper.isImageSet()) {
            this.image.image = this.cropper.getCroppedImage().src;
            this.onCrop.emit(this.cropper.getCropBounds());
        }
    }

    public onMouseDown(): void {
        this.cropper.onMouseDown();
    }

    public onMouseUp(): void {
        if (this.cropper.isImageSet()) {
            this.cropper.onMouseUp();
            this.image.image = this.cropper.getCroppedImage().src;
            this.onCrop.emit(this.cropper.getCropBounds());
        }
    }

    public onMouseMove(event: MouseEvent): void {
        this.cropper.onMouseMove(event);
    }

    public fileChangeListener($event: any) {
        let file: File = $event.target.files[0];
        if (this.settings.allowedFilesRegex.test(file.name)) {
            let image: any = new Image();
            let fileReader: FileReader = new FileReader();
            let that = this;

            fileReader.addEventListener("loadend", function (loadEvent: any) {
                image.src = loadEvent.target.result;
                that.setImage(image);
            });

            fileReader.readAsDataURL(file);
        }
    }

    public setImage(image: HTMLImageElement) {
        let self = this;

        this.intervalRef = setInterval(function () {
            if (this.intervalRef) {
                clearInterval(this.intervalRef);
            }
            if (image.naturalHeight > 0) {

                image.height = image.naturalHeight;
                image.width = image.naturalWidth;

                clearInterval(self.intervalRef);
                self.getOrientedImage(image, function (img: HTMLImageElement) {
                    self.cropper.setImage(img);
                    self.image.original = img;
                    self.image.image = self.cropper.getCroppedImage().src;
                    self.onCrop.emit(self.cropper.getCropBounds());
                });
            }<commit_msg>setInterval timer has wrong type<commit_after>import {Component, Input, Renderer, ViewChild, ElementRef, Output, EventEmitter, Type} from "@angular/core";
import {ImageCropper} from "./imageCropper";
import {CropperSettings} from "./cropperSettings";
import {Exif} from "./exif";

@Component({
    selector: "img-cropper", template: `
    <span class="ng2-imgcrop">
      <input *ngIf="!settings.noFileInput" type="file" (change)="fileChangeListener($event)" >
      <canvas #cropcanvas
              (mousedown)="onMouseDown($event)"
              (mouseup)="onMouseUp($event)"
              (mousemove)="onMouseMove($event)"
              (touchmove)="onTouchMove($event)"
              (touchend)="onTouchEnd($event)"
              (touchstart)="onTouchStart($event)">
      </canvas>
    </span>
  `
})

export class ImageCropperComponent extends Type {

    @ViewChild("cropcanvas", undefined) private cropcanvas: ElementRef;

    @Input() private settings: CropperSettings;
    @Input() private image: any;
    @Input() private cropper: ImageCropper;

    @Output() private onCrop: EventEmitter<any> = new EventEmitter();

    public croppedWidth: number;
    public croppedHeight: number;

    public intervalRef: number;

    public renderer: Renderer;

    constructor(renderer: Renderer) {
        super();
        this.renderer = renderer;
    }

    public ngAfterViewInit() {
        let canvas: HTMLCanvasElement = this.cropcanvas.nativeElement;

        if (!this.settings) {
            this.settings = new CropperSettings();
        }

        this.renderer.setElementAttribute(canvas, "width", this.settings.canvasWidth.toString());
        this.renderer.setElementAttribute(canvas, "height", this.settings.canvasHeight.toString());

        if (!this.cropper) {
            this.cropper = new ImageCropper(this.settings);
        }

        this.cropper.prepare(canvas);
    }

    public onTouchMove(event: TouchEvent): void {
        this.cropper.onTouchMove(event);
    }

    public onTouchStart(event: TouchEvent): void {
        this.cropper.onTouchStart(event);
    }

    public onTouchEnd(event: TouchEvent): void {
        this.cropper.onTouchEnd(event);
        if (this.cropper.isImageSet()) {
            this.image.image = this.cropper.getCroppedImage().src;
            this.onCrop.emit(this.cropper.getCropBounds());
        }
    }

    public onMouseDown(): void {
        this.cropper.onMouseDown();
    }

    public onMouseUp(): void {
        if (this.cropper.isImageSet()) {
            this.cropper.onMouseUp();
            this.image.image = this.cropper.getCroppedImage().src;
            this.onCrop.emit(this.cropper.getCropBounds());
        }
    }

    public onMouseMove(event: MouseEvent): void {
        this.cropper.onMouseMove(event);
    }

    public fileChangeListener($event: any) {
        let file: File = $event.target.files[0];
        if (this.settings.allowedFilesRegex.test(file.name)) {
            let image: any = new Image();
            let fileReader: FileReader = new FileReader();
            let that = this;

            fileReader.addEventListener("loadend", function (loadEvent: any) {
                image.src = loadEvent.target.result;
                that.setImage(image);
            });

            fileReader.readAsDataURL(file);
        }
    }

    public setImage(image: HTMLImageElement) {
        let self = this;

        this.intervalRef = window.setInterval(function () {
            if (this.intervalRef) {
                clearInterval(this.intervalRef);
            }
            if (image.naturalHeight > 0) {

                image.height = image.naturalHeight;
                image.width = image.naturalWidth;

                clearInterval(self.intervalRef);
                self.getOrientedImage(image, function (img: HTMLImageElement) {
                    self.cropper.setImage(img);
                    self.image.original = img;
                    self.image.image = self.cropper.getCroppedImage().src;
                    self.onCrop.emit(self.cropper.getCropBounds());
                });
            }
{'fraction_non_alphanumeric': 0.12307879970724567, 'fraction_numerical': 0.0007318858258111735, 'mean_word_length': 2.3248175182481754, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '3802331', 'n_tokens_mistral': 2402, 'n_tokens_neox': 2284, 'n_words': 420}