@atlaskit/editor-plugin-media-editing
Version:
MediaEditing plugin for @atlaskit/editor-core
86 lines (85 loc) • 2.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useImageRotate = exports.useImageFlip = exports.useImageAspectRatio = void 0;
var ASPECT_RATIOS = {
original: null,
custom: null,
square: {
x: 1,
y: 1
},
circle: {
x: 1,
y: 1
},
landscape: {
x: 4,
y: 3
},
portrait: {
x: 3,
y: 4
},
wide: {
x: 16,
y: 9
}
};
var useImageAspectRatio = exports.useImageAspectRatio = function useImageAspectRatio() {
// no ratio = undefined = custom cropping selection
var getAspectRatioValue = function getAspectRatioValue(ratio) {
var aspectRatioValue = ASPECT_RATIOS[ratio];
if (aspectRatioValue) {
return aspectRatioValue.x / aspectRatioValue.y;
}
return undefined;
};
return {
getAspectRatioValue: getAspectRatioValue
};
};
var useImageFlip = exports.useImageFlip = function useImageFlip(cropperRef) {
var flipHorizontal = function flipHorizontal() {
var _cropperRef$current;
var image = (_cropperRef$current = cropperRef.current) === null || _cropperRef$current === void 0 ? void 0 : _cropperRef$current.getImage();
if (image !== null && image !== void 0 && image.$scale) {
image.$scale(-1, 1);
}
};
var flipVertical = function flipVertical() {
var _cropperRef$current2;
var image = (_cropperRef$current2 = cropperRef.current) === null || _cropperRef$current2 === void 0 ? void 0 : _cropperRef$current2.getImage();
if (image !== null && image !== void 0 && image.$scale) {
image.$scale(1, -1);
}
};
return {
flipHorizontal: flipHorizontal,
flipVertical: flipVertical
};
};
var useImageRotate = exports.useImageRotate = function useImageRotate(cropperRef) {
var rotateRight = function rotateRight() {
var _cropperRef$current3, _cropperRef$current4, _cropperRef$current5;
var canvas = (_cropperRef$current3 = cropperRef.current) === null || _cropperRef$current3 === void 0 ? void 0 : _cropperRef$current3.getCanvas();
var image = (_cropperRef$current4 = cropperRef.current) === null || _cropperRef$current4 === void 0 ? void 0 : _cropperRef$current4.getImage();
if (!canvas || !image) {
return;
}
var selectionEl = canvas.querySelector('cropper-selection');
if (selectionEl instanceof HTMLElement) {
selectionEl.style.opacity = '0';
}
image.$rotate('90deg');
image.$center('contain');
(_cropperRef$current5 = cropperRef.current) === null || _cropperRef$current5 === void 0 || _cropperRef$current5.fitStencilToImage();
if (selectionEl instanceof HTMLElement) {
selectionEl.style.opacity = '1';
}
};
return {
rotateRight: rotateRight
};
};