UNPKG

@contentstack/live-preview-utils

Version:

Contentstack provides the Live Preview SDK to establish a communication channel between the various Contentstack SDKs and your website, transmitting live changes to the preview pane.

1 lines 1.99 kB
{"version":3,"sources":["../../../../src/visualBuilder/utils/getStyleOfAnElement.ts"],"sourcesContent":["/**\n * Retrieves the computed style of an HTML element.\n *\n * @param element - The HTML element to retrieve the style from.\n * @returns An object representing the computed style of the element.\n */\nexport default function getStyleOfAnElement(element: HTMLElement): {\n [key: string]: string;\n} {\n const styleSheetDeclaration = window.getComputedStyle(element);\n const styleSheetArray = Array.from(styleSheetDeclaration);\n\n const FILTER_STYLES = [\n \"position\",\n \"left\",\n \"top\",\n \"right\",\n \"bottom\",\n \"text-overflow\",\n // allows seeing the text from CMS field as-is\n \"text-transform\",\n \"margin\",\n \"margin-block-end\",\n \"margin-block-start\",\n \"margin-inline-end\",\n \"margin-inline-start\",\n \"margin-left\",\n \"margin-right\",\n \"margin-top\",\n \"margin-bottom\",\n \"-webkit-user-modify\",\n \"cursor\",\n ];\n\n const styles: { [key: string]: string } = {};\n styleSheetArray.forEach((style: string) => {\n if (!FILTER_STYLES.includes(style)) {\n const styleValue = styleSheetDeclaration.getPropertyValue(style);\n styles[style] = styleValue;\n }\n });\n\n return styles;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMe,SAAR,oBAAqC,SAE1C;AACE,QAAM,wBAAwB,OAAO,iBAAiB,OAAO;AAC7D,QAAM,kBAAkB,MAAM,KAAK,qBAAqB;AAExD,QAAM,gBAAgB;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AAEA,QAAM,SAAoC,CAAC;AAC3C,kBAAgB,QAAQ,CAAC,UAAkB;AACvC,QAAI,CAAC,cAAc,SAAS,KAAK,GAAG;AAChC,YAAM,aAAa,sBAAsB,iBAAiB,KAAK;AAC/D,aAAO,KAAK,IAAI;AAAA,IACpB;AAAA,EACJ,CAAC;AAED,SAAO;AACX;","names":[]}