Commit cb9eb363 authored by rockyl's avatar rockyl

修改脚本

parent 5b16ae67
{
"name": "html-shot",
"version": "1.0.6",
"version": "1.0.10",
"main": "dist/index.js",
"types": "types/index.d.ts",
"license": "MIT",
......
......@@ -19,6 +19,10 @@ const styleKeys = [
'fontStyle',
]
const includeStyleKeys = [
'fontSize',
]
export function parseDom(el: HTMLElement = document.body) {
const {left: pX, top: pY, width, height} = el.getBoundingClientRect();
......@@ -28,16 +32,18 @@ export function parseDom(el: HTMLElement = document.body) {
switch (childNode.nodeName) {
case 'IMG':
node = childNode;
vNode = {
type: 2,
src: childNode.src,
if (node.src) { //过滤src为空的图片
vNode = {
type: 2,
src: node.src,
}
}
break;
case 'CANVAS':
node = childNode;
vNode = {
type: 3,
img: childNode,
img: node,
}
break;
case '#text':
......@@ -64,7 +70,7 @@ export function parseDom(el: HTMLElement = document.body) {
bound = childNode.getBoundingClientRect();
}
let styles = getStylesWithoutDefaults(node || childNode);
let styles = getStylesWithoutDefaults(node || childNode, includeStyleKeys);
if (!isText) {
for (let skey of commonStyleKeys) {
......@@ -115,7 +121,7 @@ function walkNode(root, callback) {
}
}
function getStylesWithoutDefaults(element): any {
function getStylesWithoutDefaults(element, includes: string[] = []): any {
let dummy = document.createElement('element-' + (new Date().getTime()));
document.body.appendChild(dummy);
......@@ -124,8 +130,7 @@ function getStylesWithoutDefaults(element): any {
let diff = {};
for (let key in elementStyles) {
if (elementStyles.hasOwnProperty(key)
&& defaultStyles[key] !== elementStyles[key]) {
if (includes.indexOf(key) >= 0 || (elementStyles.hasOwnProperty(key) && defaultStyles[key] !== elementStyles[key])) {
diff[key] = elementStyles[key];
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment