<commit_before>/**
 * @author NHN Ent. FE Development Team <<EMAIL>>
 * @fileoverview Image crop module (start cropping, end cropping)
 */
import snippet from 'tui-code-snippet';
import fabric from 'fabric';
import Component from '../interface/component';
import Cropzone from '../extension/cropzone';
import {keyCodes, componentNames, CROPZONE_DEFAULT_OPTIONS} from '../consts';
import {clamp, fixFloatingPoint} from '../util';

const MOUSE_MOVE_THRESHOLD = 10;
const DEFAULT_OPTION = {
    presetRatio: null,
    top: -10,
    left: -10,
    height: 1,
    width: 1
};

/**
 * Cropper components
 * @param {Graphics} graphics - Graphics instance
 * @extends {Component}
 * @class Cropper
 * @ignore
 */
class Cropper extends Component {
    constructor(graphics) {
        super(componentNames.CROPPER, graphics);

        /**
         * Cropzone
         * @type {Cropzone}
         * @private
         */
        this._cropzone = null;

        /**
         * StartX of Cropzone
         * @type {number}
         * @private
         */
        this._startX = null;

        /**
         * StartY of Cropzone
         * @type {number}
         * @private
         */
        this._startY = null;

        /**
         * State whether shortcut key is pressed or not
         * @type {boolean}
         * @private
         */
        this._withShiftKey = false;

        /**
         * Listeners
         * @type {object.<string, function>}
         * @private
         */
        this._listeners = {
            keydown: this._onKeyDown.bind(this),
            keyup: this._onKeyUp.bind(this),
            mousedown: this._onFabricMouseDown.bind(this),
            mousemove: this._onFabricMouseMove.bind(this),
            mouseup: this._onFabricMouseUp.bind(this)
        };
    }

    /**
     * Start cropping
     */
    start() {
        if (this._cropzone) {
            return;
        }
        const canvas = this.getCanvas();

        canvas.forEachObject(obj => { // {@link http://fabricjs.com/docs/fabric.Object.html#evented}
            obj.evented = false;
        });

        this._cropzone = new Cropzone(canvas, {
            left: 0,
            top: 0,
            width: 0.5,
            height: 0.5,
            strokeWidth: 0, // {@link https://github.com/kangax/fabric.js/issues/2860}
            cornerSize: 10,
            cornerColor: 'black',
            fill: 'transparent'
        }, CROPZONE_DEFAULT_OPTIONS, this.graphics.cropSelectionStyle);

        canvas.discardActiveObject();
        canvas.add(this._cropzone);
        canvas.on('mouse:down', this._listeners.mousedown);
        canvas.selection = false;
        canvas.defaultCursor = 'crosshair';

        fabric.util.addListener(document, 'keydown', this._listeners.keydown);
        fabric.util.addListener(document, 'keyup', this._listeners.keyup);
    }

    /**
     * End cropping
     */
    end() {
        const canvas = this.getCanvas();
        const cropzone = this._cropzone;

        if (!cropzone) {<commit_msg>fix: missing cropzone style<commit_after>/**
 * @author NHN Ent. FE Development Team <<EMAIL>>
 * @fileoverview Image crop module (start cropping, end cropping)
 */
import snippet from 'tui-code-snippet';
import fabric from 'fabric';
import Component from '../interface/component';
import Cropzone from '../extension/cropzone';
import {keyCodes, componentNames, CROPZONE_DEFAULT_OPTIONS} from '../consts';
import {clamp, fixFloatingPoint} from '../util';

const MOUSE_MOVE_THRESHOLD = 10;
const DEFAULT_OPTION = {
    presetRatio: null,
    top: -10,
    left: -10,
    height: 1,
    width: 1
};

/**
 * Cropper components
 * @param {Graphics} graphics - Graphics instance
 * @extends {Component}
 * @class Cropper
 * @ignore
 */
class Cropper extends Component {
    constructor(graphics) {
        super(componentNames.CROPPER, graphics);

        /**
         * Cropzone
         * @type {Cropzone}
         * @private
         */
        this._cropzone = null;

        /**
         * StartX of Cropzone
         * @type {number}
         * @private
         */
        this._startX = null;

        /**
         * StartY of Cropzone
         * @type {number}
         * @private
         */
        this._startY = null;

        /**
         * State whether shortcut key is pressed or not
         * @type {boolean}
         * @private
         */
        this._withShiftKey = false;

        /**
         * Listeners
         * @type {object.<string, function>}
         * @private
         */
        this._listeners = {
            keydown: this._onKeyDown.bind(this),
            keyup: this._onKeyUp.bind(this),
            mousedown: this._onFabricMouseDown.bind(this),
            mousemove: this._onFabricMouseMove.bind(this),
            mouseup: this._onFabricMouseUp.bind(this)
        };
    }

    /**
     * Start cropping
     */
    start() {
        if (this._cropzone) {
            return;
        }
        const canvas = this.getCanvas();

        canvas.forEachObject(obj => { // {@link http://fabricjs.com/docs/fabric.Object.html#evented}
            obj.evented = false;
        });

        this._cropzone = new Cropzone(canvas, snippet.extend({
            left: 0,
            top: 0,
            width: 0.5,
            height: 0.5,
            strokeWidth: 0, // {@link https://github.com/kangax/fabric.js/issues/2860}
            cornerSize: 10,
            cornerColor: 'black',
            fill: 'transparent'
        }, CROPZONE_DEFAULT_OPTIONS, this.graphics.cropSelectionStyle));

        canvas.discardActiveObject();
        canvas.add(this._cropzone);
        canvas.on('mouse:down', this._listeners.mousedown);
        canvas.selection = false;
        canvas.defaultCursor = 'crosshair';

        fabric.util.addListener(document, 'keydown', this._listeners.keydown);
        fabric.util.addListener(document, 'keyup', this._listeners.keyup);
    }

    /**
     * End cropping
     */
    end() {
        const canvas = this.getCanvas();
        const cropzone = this._cropzone;

        if (!cropzone) {
{'fraction_non_alphanumeric': 0.12582345191040845, 'fraction_numerical': 0.00691699604743083, 'mean_word_length': 1.8877793628150261, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3192296', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1788, 'n_words': 384}