Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 10x 10x 10x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x | /**
* html2canvas helpers for the Instagram share cards (SB-1916).
*
* html2canvas drops inline <svg> on our cards: the Fest mesa silhouettes
* were on screen but missing from every exported PNG, so the sun hung over
* an empty dark sky. Swapping each SVG in the capture clone for an <img> of
* the same markup renders it as an ordinary image, which html2canvas draws.
*/
const SVG_NS = 'http://www.w3.org/2000/svg';
/**
* A data URI for one SVG element's markup. Inline styles and classes are
* dropped: in the capture clone html2canvas has written every computed style
* onto each element, and that markup renders as an empty image. The Fest
* SVGs draw with presentation attributes (`fill`), which are kept.
*/
export function svgDataUri(svg) {
const copy = svg.cloneNode(true);
for (const node of [copy, ...copy.querySelectorAll('*')]) {
node.removeAttribute('style');
node.removeAttribute('class');
}
copy.setAttribute('xmlns', SVG_NS);
const markup = new XMLSerializer().serializeToString(copy);
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(markup)}`;
}
/**
* Replace every <svg> under `root` with a <div> painting it as a CSS
* background image, at the same position and size. A background image, not
* an <img>, because that is what the crests and lockup already use and
* html2canvas draws them. Only the box is carried over: in the capture clone
* html2canvas has inlined every computed style onto the element (down to
* `transition: all`), and copying that onto the div left it unpainted.
* Resolves once every image has decoded.
*/
export async function inlineSvgsAsImages(root) {
const doc = root.ownerDocument;
const view = doc.defaultView || window;
const pending = [...root.querySelectorAll('svg')].map(svg => {
const uri = svgDataUri(svg);
const cs = view.getComputedStyle(svg);
// The computed size, or the width/height attributes where there is no
// layout to compute one from.
const size = (prop, attr) =>
/px$/.test(cs[prop]) ? cs[prop] : `${svg.getAttribute(attr) || 0}px`;
const div = doc.createElement('div');
div.setAttribute('aria-hidden', 'true');
div.style.cssText = [
`position: ${cs.position}`,
`left: ${cs.left}`,
`top: ${cs.top}`,
`width: ${size('width', 'width')}`,
`height: ${size('height', 'height')}`,
`background-image: url("${uri}")`,
'background-size: 100% 100%',
'background-repeat: no-repeat',
].join('; ');
svg.replaceWith(div);
const img = new Image();
img.src = uri;
return img.decode ? img.decode().catch(() => {}) : Promise.resolve();
});
await Promise.all(pending);
}
/**
* html2canvas finds each font's baseline by appending a hidden div to the
* page body holding a 1×1 <img> beside a text span, and reading the img's
* offsetTop. Tailwind's preflight makes every <img> `display: block`, so the
* img drops to its own line, the measured baseline is a full line too low,
* and every word on the exported card was drawn ~15px below where the page
* shows it: names spilled off their plates, "U15" sat on its badge's edge.
* This rule puts that probe img back inline for the length of one capture.
*/
const BASELINE_FIX_CSS =
'body > div > img[width="1"][height="1"] { display: inline !important; }';
export async function withHtml2canvasBaselineFix(capture) {
const style = document.createElement('style');
style.setAttribute('data-ig-capture', '');
style.textContent = BASELINE_FIX_CSS;
document.head.appendChild(style);
try {
return await capture();
} finally {
style.remove();
}
}
|