( cellId: CellId, )
| 71 | * @returns The PNG as a data URL, or undefined if the cell element wasn't found |
| 72 | */ |
| 73 | export async function getImageDataUrlForCell( |
| 74 | cellId: CellId, |
| 75 | ): Promise<string | undefined> { |
| 76 | const element = findElementForCell(cellId); |
| 77 | if (!element) { |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | // TODO: This doesn't handle external iframes + normal elements together (eg. in vstack). |
| 82 | // It will return the iframe only |
| 83 | const externalIframeDataUrl = await captureExternalIframes(element); |
| 84 | if (externalIframeDataUrl) { |
| 85 | return externalIframeDataUrl; |
| 86 | } |
| 87 | |
| 88 | const startTime = Date.now(); |
| 89 | const dataUrl = await toPng(element, { |
| 90 | extraStyleContent: HIDE_SCROLLBAR_STYLES, |
| 91 | // Add these styles so the element output is not clipped |
| 92 | // Width can be clipped since pdf has limited width |
| 93 | style: { |
| 94 | maxHeight: "none", |
| 95 | overflow: "visible", |
| 96 | }, |
| 97 | height: element.scrollHeight, |
| 98 | }); |
| 99 | const timeTaken = Date.now() - startTime; |
| 100 | if (timeTaken > THRESHOLD_TIME_MS) { |
| 101 | Logger.debug( |
| 102 | "toPng operation for element", |
| 103 | element, |
| 104 | `took ${timeTaken} ms (exceeds threshold)`, |
| 105 | ); |
| 106 | } |
| 107 | return dataUrl; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Download a cell output as a PNG image file. |
no test coverage detected
searching dependent graphs…