renderThumbnail method
Implementation
Future<HTMLImageElement?> renderThumbnail({
String? renderedHTML,
bool includeDocumentStyles = true,
String? styles,
int? width = 800,
int? height = 600,
}) async {
renderedHTML ??= renderDomGenerator.generatedHTMLTrees.join('\n');
if (isEmptyObject(renderedHTML)) return null;
var svgStyles = '';
if (includeDocumentStyles) {
// `rules` is a JS `CSSRuleList` (not a Dart `List`, so a
// `whereType<List<CSSRule>>()` dropped every style sheet):
var rules = getAllCssStyleSheet()
.expand((e) => e.rules.toList())
.toList();
svgStyles = rules.map((e) => e.cssText).join('\n');
}
if (isNotEmptyObject(styles)) {
// Appended to the document styles (it used to replace them):
svgStyles += '\n$styles';
}
var svg = htmlAsSvgContent(
renderedHTML,
width: width,
height: height,
style: svgStyles,
);
var thumbnail = UISVG(
parent,
svgContent: svg,
width: '${width}px',
height: '${height}px',
);
var renderedImage = await thumbnail.buildRenderedImage();
return renderedImage;
}