<commit_before>/**
 * @author <NAME> from Ubrainians for imCode
 * 27.03.18
 */
const editImage = require('imcms-editable-image');
const sizeControls = require('imcms-image-edit-size-controls');

const angleNorth = {
    name: "NORTH",
    proportionsInverted: false,
    degrees: 0
};

const angleEast = angleNorth.next = {
    name: "EAST",
    proportionsInverted: true,
    degrees: 90,
    prev: angleNorth
};

const angleSouth = angleEast.next = {
    name: "SOUTH",
    proportionsInverted: false,
    degrees: 180,
    prev: angleEast
};

const angleWest = angleSouth.next = angleNorth.prev = {
    name: "WEST",
    proportionsInverted: true,
    degrees: 270,
    prev: angleSouth,
    next: angleNorth
};

const anglesByDirection = {
    "NORTH": angleNorth,
    "EAST": angleEast,
    "SOUTH": angleSouth,
    "WEST": angleWest
};

let currentAngle = angleNorth;

const anglesByDegrees = {
    0: angleNorth,
    90: angleEast,
    180: angleSouth,
    270: angleWest,
};

function getRotateCss(angle) {
    const degrees = angle.degrees;
    let transform = "rotate(" + degrees + "deg)";

    switch (degrees) {
        case 90:
            transform += " translateY(-100%)";
            break;
        case 180:
            transform += " translate(-100%, -100%)";
            break;
        case 270:
            transform += " translateX(-100%)";
            break;
    }

    return {
        "transform": transform,
        "transform-origin": "top left"
    };
}

function rotate(newAngle) {
    const sameAngle = (newAngle === currentAngle);
    if (sameAngle) return;

    currentAngle = newAngle || angleNorth;

    const style = getRotateCss(currentAngle);
    editImage.getImage().css(style);

    sizeControls.swapControls(currentAngle.proportionsInverted);
}

module.exports = {
    rotateLeft: () => {
        rotate(currentAngle.prev);
    },
    rotateRight: () => {
        rotate(currentAngle.next);
    },
    rotateImageByDegrees: (degrees) => rotate(anglesByDegrees[degrees]),
    rotateImage: direction => {
        rotate(anglesByDirection[direction]);
    },
    isProportionsInverted: () => currentAngle.proportionsInverted,
    getCurrentAngle: () => currentAngle,
    getCurrentRotateCss: () => getRotateCss(currentAngle || angleNorth),
    destroy: () => {
        currentAngle = angleNorth;
    }
};<commit_msg>Issue IMCMS-509: Edit image in text field doesn't work any more. - Change data image;<commit_after>/**
 * @author <NAME> from Ubrainians for imCode
 * 27.03.18
 */
const previewImage = require('imcms-preview-image-area')
const sizeControls = require('imcms-image-edit-size-controls');

const angleNorth = {
    name: "NORTH",
    proportionsInverted: false,
    degrees: 0
};

const angleEast = angleNorth.next = {
    name: "EAST",
    proportionsInverted: true,
    degrees: 90,
    prev: angleNorth
};

const angleSouth = angleEast.next = {
    name: "SOUTH",
    proportionsInverted: false,
    degrees: 180,
    prev: angleEast
};

const angleWest = angleSouth.next = angleNorth.prev = {
    name: "WEST",
    proportionsInverted: true,
    degrees: 270,
    prev: angleSouth,
    next: angleNorth
};

const anglesByDirection = {
    "NORTH": angleNorth,
    "EAST": angleEast,
    "SOUTH": angleSouth,
    "WEST": angleWest
};

let currentAngle = angleNorth;

const anglesByDegrees = {
    0: angleNorth,
    90: angleEast,
    180: angleSouth,
    270: angleWest,
};

function getRotateCss(angle) {
    const degrees = angle.degrees;
    let transform = "rotate(" + degrees + "deg)";

    switch (degrees) {
        case 90:
            transform += " translateY(-100%)";
            break;
        case 180:
            transform += " translate(-100%, -100%)";
            break;
        case 270:
            transform += " translateX(-100%)";
            break;
    }

    return {
        "transform": transform,
        "transform-origin": "top left"
    };
}

function rotate(newAngle) {
    const sameAngle = (newAngle === currentAngle);
    if (sameAngle) return;

    currentAngle = newAngle || angleNorth;

    const style = getRotateCss(currentAngle);
    previewImage.getPreviewImage().css(style);

    sizeControls.swapControls(currentAngle.proportionsInverted);
}

module.exports = {
    rotateLeft: () => {
        rotate(currentAngle.prev);
    },
    rotateRight: () => {
        rotate(currentAngle.next);
    },
    rotateImageByDegrees: (degrees) => rotate(anglesByDegrees[degrees]),
    rotateImage: direction => {
        rotate(anglesByDirection[direction]);
    },
    isProportionsInverted: () => currentAngle.proportionsInverted,
    getCurrentAngle: () => currentAngle,
    getCurrentRotateCss: () => getRotateCss(currentAngle || angleNorth),
    destroy: () => {
        currentAngle = angleNorth;
    }
};
{'fraction_non_alphanumeric': 0.13141426783479349, 'fraction_numerical': 0.01898206090947017, 'mean_word_length': 2.8576025744167337, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 21, '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': '1568818', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1481, 'n_words': 319}