mirror of
https://github.com/enso-org/enso.git
synced 2024-12-21 13:11:41 +03:00
0d34126b86
* JSON viz with projections, colors, inlining * Ensure GraphEditor receives keyboard events for newly-selected nodes * Consider positioned, unsized nodes when positioning
26 lines
1.1 KiB
TypeScript
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)
|
|
})
|
|
}
|