codeplay-common 4.11.6 → 4.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/files/take-screen-image.js +40 -10
- package/package.json +1 -1
|
@@ -1413,6 +1413,45 @@ async function capturePageSnapshot(client) {
|
|
|
1413
1413
|
}
|
|
1414
1414
|
}
|
|
1415
1415
|
|
|
1416
|
+
// Replay runs outside the WebView origin. Preserve imported icon styles and
|
|
1417
|
+
// embed fonts so native localhost URLs and font CORS cannot break ligatures.
|
|
1418
|
+
const fontResources = new Map();
|
|
1419
|
+
const serializeCss = async (cssText, baseUrl, ancestors = []) => {
|
|
1420
|
+
const imports = [...cssText.matchAll(/@import\\s+(?:url\\(\\s*(['"]?)([^'"\\)]+)\\1\\s*\\)|(['"])([^'"]+)\\3)\\s*([^;]*);/gi)];
|
|
1421
|
+
for (const match of imports) {
|
|
1422
|
+
const importUrl = new URL((match[2] || match[4]).trim(), baseUrl).href;
|
|
1423
|
+
if (ancestors.includes(importUrl)) continue;
|
|
1424
|
+
const response = await fetch(importUrl);
|
|
1425
|
+
if (!response.ok) throw new Error('Could not capture stylesheet: ' + importUrl);
|
|
1426
|
+
const importedCss = await serializeCss(await response.text(), importUrl, [...ancestors, importUrl]);
|
|
1427
|
+
cssText = cssText.replace(match[0], match[5].trim()
|
|
1428
|
+
? '@media ' + match[5].trim() + '{' + importedCss + '}'
|
|
1429
|
+
: importedCss);
|
|
1430
|
+
}
|
|
1431
|
+
const resources = [...cssText.matchAll(/url\\(\\s*(['"]?)(?!data:|#)([^'"\\)]+)\\1\\s*\\)/gi)];
|
|
1432
|
+
for (const match of resources) {
|
|
1433
|
+
const resourceUrl = new URL(match[2].trim(), baseUrl).href;
|
|
1434
|
+
let replayUrl = resourceUrl;
|
|
1435
|
+
if (/\\.(?:woff2?|ttf|otf)(?:[?#]|$)/i.test(resourceUrl) || resourceUrl.startsWith('blob:')) {
|
|
1436
|
+
if (!fontResources.has(resourceUrl)) {
|
|
1437
|
+
fontResources.set(resourceUrl, (async () => {
|
|
1438
|
+
const response = await fetch(resourceUrl);
|
|
1439
|
+
if (!response.ok) throw new Error('Could not capture font: ' + resourceUrl);
|
|
1440
|
+
return blobToDataUrl(await response.blob());
|
|
1441
|
+
})());
|
|
1442
|
+
}
|
|
1443
|
+
replayUrl = await fontResources.get(resourceUrl);
|
|
1444
|
+
}
|
|
1445
|
+
cssText = cssText.replace(match[0], 'url("' + replayUrl + '")');
|
|
1446
|
+
}
|
|
1447
|
+
return cssText;
|
|
1448
|
+
};
|
|
1449
|
+
|
|
1450
|
+
await Promise.all(originalElements.map(async (element, index) => {
|
|
1451
|
+
if (element.tagName?.toLowerCase() !== 'style') return;
|
|
1452
|
+
clonedElements[index].textContent = await serializeCss(element.textContent, sourceDocument.baseURI);
|
|
1453
|
+
}));
|
|
1454
|
+
|
|
1416
1455
|
const stylesheetLinks = [...sourceDocument.querySelectorAll('link[rel="stylesheet"]')];
|
|
1417
1456
|
const clonedStylesheetLinks = [...clonedRoot.querySelectorAll('link[rel="stylesheet"]')];
|
|
1418
1457
|
|
|
@@ -1421,16 +1460,7 @@ async function capturePageSnapshot(client) {
|
|
|
1421
1460
|
const response = await fetch(link.href);
|
|
1422
1461
|
if (!response.ok) return;
|
|
1423
1462
|
|
|
1424
|
-
const cssText = (await response.text())
|
|
1425
|
-
/url\\(\\s*(['"]?)(?!data:|blob:|#)([^'"\\)]+)\\1\\s*\\)/gi,
|
|
1426
|
-
(match, quote, resourceUrl) => {
|
|
1427
|
-
try {
|
|
1428
|
-
return 'url("' + new URL(resourceUrl.trim(), link.href).href + '")';
|
|
1429
|
-
} catch {
|
|
1430
|
-
return match;
|
|
1431
|
-
}
|
|
1432
|
-
},
|
|
1433
|
-
);
|
|
1463
|
+
const cssText = await serializeCss(await response.text(), link.href);
|
|
1434
1464
|
const style = sourceDocument.createElement('style');
|
|
1435
1465
|
style.textContent = cssText;
|
|
1436
1466
|
clonedStylesheetLinks[index].replaceWith(style);
|