All files / roosterjs-content-model-api/lib/publicApi/image setImageBoxShadow.ts

100% Statements 15/15
75% Branches 3/4
100% Functions 2/2
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 281x                 1x 5x   5x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x        
import { formatImageWithContentModel } from '../utils/formatImageWithContentModel';
import type { ContentModelImage, IEditor } from 'roosterjs-content-model-types';
 
/**
 * Set image box shadow for all selected images at selection.
 * @param editor The editor instance
 * @param boxShadow The image box boxShadow
 * @param margin The image margin for all sides (eg. "4px"), null to remove margin
 */
export function setImageBoxShadow(editor: IEditor, boxShadow: string, margin?: string | null) {
    editor.focus();
 
    formatImageWithContentModel(editor, 'setImageBoxShadow', (image: ContentModelImage) => {
        image.format.boxShadow = boxShadow;
        if (margin) {
            image.format.marginBottom = margin;
            image.format.marginLeft = margin;
            image.format.marginRight = margin;
            image.format.marginTop = margin;
        } else Eif (margin === null) {
            delete image.format.marginBottom;
            delete image.format.marginLeft;
            delete image.format.marginRight;
            delete image.format.marginTop;
        }
    });
}