X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/abbfd42a6c33d1c5e90517448add0f5909051d0e..ebf95f637a199fa4493013933fabf073d4113bb4:/resources/js/wysiwyg/utils/dom.ts diff --git a/resources/js/wysiwyg/utils/dom.ts b/resources/js/wysiwyg/utils/dom.ts index 7426ac592..a307bdd75 100644 --- a/resources/js/wysiwyg/utils/dom.ts +++ b/resources/js/wysiwyg/utils/dom.ts @@ -29,4 +29,29 @@ export function formatSizeValue(size: number | string, defaultSuffix: string = ' } return size; +} + +export type StyleMap = Map; + +/** + * Creates a map from an element's styles. + * Uses direct attribute value string handling since attempting to iterate + * over .style will expand out any shorthand properties (like 'padding') making + * rather than being representative of the actual properties set. + */ +export function extractStyleMapFromElement(element: HTMLElement): StyleMap { + const map: StyleMap = new Map(); + const styleText= element.getAttribute('style') || ''; + + const rules = styleText.split(';'); + for (const rule of rules) { + const [name, value] = rule.split(':'); + if (!name || !value) { + continue; + } + + map.set(name.trim().toLowerCase(), value.trim()); + } + + return map; } \ No newline at end of file