| 2 | // a plain card. Two limits the card is built around: pseudo-elements are not |
| 3 | // cloned, and an SVG foreignObject cannot reach the page's webfonts. |
| 4 | const inline = (source: Element, clone: Element): void => { |
| 5 | const computed = getComputedStyle(source); |
| 6 | let css = ''; |
| 7 | |
| 8 | for (let index = 0; index < computed.length; index += 1) { |
| 9 | const property = computed.item(index); |
| 10 | |
| 11 | css += `${property}:${computed.getPropertyValue(property)};`; |
| 12 | } |
| 13 | |
| 14 | clone.setAttribute('style', css); |
| 15 | |
| 16 | const sources = Array.from(source.children); |
| 17 | const clones = Array.from(clone.children); |
| 18 | |
| 19 | sources.forEach((child, index) => { |
| 20 | const pair = clones[index]; |
| 21 | |
| 22 | if (pair) { |
| 23 | inline(child, pair); |
| 24 | } |
| 25 | }); |
| 26 | }; |
| 27 | |
| 28 | export const nodeToPng = async ( |
| 29 | node: HTMLElement, |