format code
This commit is contained in:
@@ -99,7 +99,7 @@ function buildNode(
|
|||||||
}
|
}
|
||||||
for (const name in n.attributes) {
|
for (const name in n.attributes) {
|
||||||
if (!n.attributes.hasOwnProperty(name)) {
|
if (!n.attributes.hasOwnProperty(name)) {
|
||||||
continue
|
continue;
|
||||||
}
|
}
|
||||||
let value = n.attributes[name];
|
let value = n.attributes[name];
|
||||||
value = typeof value === 'boolean' ? '' : value;
|
value = typeof value === 'boolean' ? '' : value;
|
||||||
@@ -137,14 +137,14 @@ function buildNode(
|
|||||||
} else {
|
} else {
|
||||||
// handle internal attributes
|
// handle internal attributes
|
||||||
if (tagName === 'canvas' && name === 'rr_dataURL') {
|
if (tagName === 'canvas' && name === 'rr_dataURL') {
|
||||||
const image = document.createElement('img')
|
const image = document.createElement('img');
|
||||||
image.src = value
|
image.src = value;
|
||||||
image.onload = () => {
|
image.onload = () => {
|
||||||
const ctx = (node as HTMLCanvasElement).getContext('2d')
|
const ctx = (node as HTMLCanvasElement).getContext('2d');
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
ctx.drawImage(image, 0, 0, image.width, image.height)
|
ctx.drawImage(image, 0, 0, image.width, image.height);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (name === 'rr_width') {
|
if (name === 'rr_width') {
|
||||||
(node as HTMLElement).style.width = value;
|
(node as HTMLElement).style.width = value;
|
||||||
|
|||||||
@@ -86,34 +86,36 @@ export function absoluteToStylesheet(cssText: string, href: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getAbsoluteSrcsetString(doc: Document, attributeValue: string) {
|
function getAbsoluteSrcsetString(doc: Document, attributeValue: string) {
|
||||||
if(attributeValue.trim() === "") {
|
if (attributeValue.trim() === '') {
|
||||||
return attributeValue
|
return attributeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const srcsetValues = attributeValue.split(",")
|
const srcsetValues = attributeValue.split(',');
|
||||||
// srcset attributes is defined as such:
|
// srcset attributes is defined as such:
|
||||||
// srcset = "url size,url1 size1"
|
// srcset = "url size,url1 size1"
|
||||||
const resultingSrcsetString = srcsetValues.map((srcItem) => {
|
const resultingSrcsetString = srcsetValues
|
||||||
|
.map(srcItem => {
|
||||||
// removing all but middle spaces
|
// removing all but middle spaces
|
||||||
const trimmedSrcItem = srcItem.trimLeft().trimRight()
|
const trimmedSrcItem = srcItem.trimLeft().trimRight();
|
||||||
const urlAndSize = trimmedSrcItem.split(" ")
|
const urlAndSize = trimmedSrcItem.split(' ');
|
||||||
// this means we have both 0:url and 1:size
|
// this means we have both 0:url and 1:size
|
||||||
if (urlAndSize.length === 2) {
|
if (urlAndSize.length === 2) {
|
||||||
const absUrl = absoluteToDoc(doc, urlAndSize[0])
|
const absUrl = absoluteToDoc(doc, urlAndSize[0]);
|
||||||
return `${absUrl} ${urlAndSize[1]}`
|
return `${absUrl} ${urlAndSize[1]}`;
|
||||||
} else if(urlAndSize.length === 1){
|
} else if (urlAndSize.length === 1) {
|
||||||
const absUrl = absoluteToDoc(doc, urlAndSize[0])
|
const absUrl = absoluteToDoc(doc, urlAndSize[0]);
|
||||||
return `${absUrl}`
|
return `${absUrl}`;
|
||||||
}
|
}
|
||||||
return ""
|
return '';
|
||||||
}).join(',')
|
})
|
||||||
|
.join(',');
|
||||||
|
|
||||||
return resultingSrcsetString
|
return resultingSrcsetString;
|
||||||
}
|
}
|
||||||
|
|
||||||
function absoluteToDoc(doc: Document, attributeValue: string): string {
|
function absoluteToDoc(doc: Document, attributeValue: string): string {
|
||||||
if (attributeValue.trim() === ""){
|
if (attributeValue.trim() === '') {
|
||||||
return attributeValue
|
return attributeValue;
|
||||||
}
|
}
|
||||||
const a: HTMLAnchorElement = doc.createElement('a');
|
const a: HTMLAnchorElement = doc.createElement('a');
|
||||||
a.href = attributeValue;
|
a.href = attributeValue;
|
||||||
@@ -161,8 +163,8 @@ function serializeNode(
|
|||||||
// relative path in attribute
|
// relative path in attribute
|
||||||
if (name === 'src' || name === 'href') {
|
if (name === 'src' || name === 'href') {
|
||||||
attributes[name] = absoluteToDoc(doc, value);
|
attributes[name] = absoluteToDoc(doc, value);
|
||||||
} else if (name == 'srcset') {
|
} else if (name === 'srcset') {
|
||||||
attributes[name] = getAbsoluteSrcsetString(doc, value)
|
attributes[name] = getAbsoluteSrcsetString(doc, value);
|
||||||
} else if (name === 'style') {
|
} else if (name === 'style') {
|
||||||
attributes[name] = absoluteToStylesheet(value, location.href);
|
attributes[name] = absoluteToStylesheet(value, location.href);
|
||||||
} else {
|
} else {
|
||||||
@@ -226,7 +228,7 @@ function serializeNode(
|
|||||||
}
|
}
|
||||||
// canvas image data
|
// canvas image data
|
||||||
if (tagName === 'canvas') {
|
if (tagName === 'canvas') {
|
||||||
attributes.rr_dataURL = (n as HTMLCanvasElement).toDataURL()
|
attributes.rr_dataURL = (n as HTMLCanvasElement).toDataURL();
|
||||||
}
|
}
|
||||||
if (needBlock) {
|
if (needBlock) {
|
||||||
const { width, height } = (n as HTMLElement).getBoundingClientRect();
|
const { width, height } = (n as HTMLElement).getBoundingClientRect();
|
||||||
|
|||||||
Reference in New Issue
Block a user