enso/app/gui2/e2e/css.ts
Kaz Wesley 0d34126b86
New JSON visualization (#9409)
* JSON viz with projections, colors, inlining

* Ensure GraphEditor receives keyboard events for newly-selected nodes

* Consider positioned, unsized nodes when positioning
2024-03-25 12:03:18 -04:00

26 lines
1.1 KiB
TypeScript

import type { ElementHandle } from 'playwright'
/** Returns text content of the element, including CSS ::before and ::after content in the element's tree.
* Currently whitespace produced around pseudo-elements is unspecified; block/inline logic is not implemented.
*/
export function computedContent(element: ElementHandle<HTMLElement | SVGElement>): Promise<string> {
return element.evaluate<string>((element) => {
const getPseudoElement = (element: HTMLElement | SVGElement, pseudo: string) => {
const value = window.getComputedStyle(element, `::${pseudo}`).getPropertyValue('content')
if (value.match(/['"]/)) return value.replace(/['"]/g, '')
}
const recurse = (element: HTMLElement | SVGElement): string => {
return [
getPseudoElement(element, 'before') ?? '',
...Array.from(element.childNodes, (child) =>
child instanceof HTMLElement || child instanceof SVGElement ?
recurse(child)
: child.textContent,
),
getPseudoElement(element, 'after') ?? '',
].join('')
}
return recurse(element)
})
}