refactor: optimize selection capture and remove dead code
- Removed Node.js export from capture.js (browser-only code) - Simplified selection capture to avoid expensive getComputedStyle() calls - Added performance notes for selection clipping - Aligned content.js with capture.js implementation Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -45,6 +45,8 @@ function captureFullPage() {
|
||||
|
||||
/**
|
||||
* Capture selected content from the page
|
||||
* Note: For performance, uses basic HTML structure without per-element computed styles.
|
||||
* The resulting PDF will use browser default styles.
|
||||
*/
|
||||
function captureSelection() {
|
||||
const selection = window.getSelection();
|
||||
@@ -57,27 +59,6 @@ function captureSelection() {
|
||||
const container = document.createElement('div');
|
||||
container.appendChild(range.cloneContents());
|
||||
|
||||
// Get computed styles for the selection
|
||||
const elements = container.querySelectorAll('*');
|
||||
elements.forEach(el => {
|
||||
const computed = window.getComputedStyle(el);
|
||||
// Only preserve essential styles
|
||||
const essentialStyles = [
|
||||
'font-family', 'font-size', 'font-weight', 'color',
|
||||
'background-color', 'text-align', 'margin', 'padding'
|
||||
];
|
||||
let styleStr = '';
|
||||
essentialStyles.forEach(prop => {
|
||||
const value = computed.getPropertyValue(prop);
|
||||
if (value) {
|
||||
styleStr += `${prop}: ${value}; `;
|
||||
}
|
||||
});
|
||||
if (styleStr) {
|
||||
el.setAttribute('style', styleStr);
|
||||
}
|
||||
});
|
||||
|
||||
const html = `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -99,6 +80,8 @@ function captureSelection() {
|
||||
<hr>
|
||||
${container.innerHTML}
|
||||
</body>
|
||||
</html>`;
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user