All files / roosterjs-editor-dom/lib/style setGlobalCssStyles.ts

100% Statements 8/8
87.5% Branches 7/8
100% Functions 1/1
100% Lines 8/8

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              1x 149x 148x 148x 141x 141x 141x   148x      
/**
 * Add global css styles
 * @param doc The document object
 * @param cssRule The css rule that must added to the selection
 * @param styleId The id of the style tag
 */
 
export default function setGlobalCssStyles(doc: Document, cssRule: string, styleId: string) {
    if (cssRule) {
        let styleTag = doc.getElementById(styleId) as HTMLStyleElement;
        if (!styleTag) {
            styleTag = doc.createElement('style');
            styleTag.id = styleId;
            doc.head.appendChild(styleTag);
        }
        styleTag.sheet?.insertRule(cssRule);
    }
}