@atlaskit/editor-plugin-media
Version:
Media plugin for @atlaskit/editor-core
26 lines (25 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.computeReplacementDisplayWidth = void 0;
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
var MIN_MEDIA_DISPLAY_WIDTH = 24;
/**
* Computes the new mediaSingle display width that preserves the original display height
* when a media node is replaced with a file of a different aspect ratio, clamped to valid bounds.
*
* @param targetDisplayHeight - The display height to preserve (from the old image)
* @param newIntrinsicWidth - The new file's intrinsic pixel width
* @param newIntrinsicHeight - The new file's intrinsic pixel height
* @param layout - The mediaSingle layout (affects max width)
* @param lineLength - The editor content column width in pixels
*/
var computeReplacementDisplayWidth = exports.computeReplacementDisplayWidth = function computeReplacementDisplayWidth(targetDisplayHeight, newIntrinsicWidth, newIntrinsicHeight, layout, lineLength) {
if (newIntrinsicHeight <= 0) {
return MIN_MEDIA_DISPLAY_WIDTH;
}
var unclamped = targetDisplayHeight * (newIntrinsicWidth / newIntrinsicHeight);
var maxWidth = layout === 'full-width' ? _editorSharedStyles.akEditorFullWidthLayoutWidth : layout === 'wide' ? _editorSharedStyles.akEditorWideLayoutWidth : lineLength;
return Math.max(MIN_MEDIA_DISPLAY_WIDTH, Math.min(unclamped, maxWidth));
};