Skip to content

Commit 557191c

Browse files
committed
fix: 修复转换表格时无法转换边框的样式
1 parent ed0547d commit 557191c

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html2sketch",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"author": "arvinxx",
55
"description": "parser HTML to Design Model",
66
"repository": {

src/function/nodeToSketchLayers.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ export const nodeToSketchLayers = (node: Element): AnyLayer[] => {
8383
// 添加后继续执行,不终止
8484
const shape = transferToShape(node);
8585

86-
if (shape) {
87-
console.info('[nodeToSketchLayers]转换为 Rectangle: ', shape);
88-
layers.push(shape);
89-
}
86+
console.info('[nodeToSketchLayers]转换为 Rectangle: ', shape);
87+
layers.push(shape);
9088
}
9189

9290
// 判断一下是否有伪类

src/helpers/shape.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,28 @@ export const isExistPseudoText = (node: Element) =>
1313
export const isExistPseudoShape = (node: Element) =>
1414
!!(pseudoShape(node, 'after') || pseudoShape(node, 'before'));
1515

16+
/**
17+
* 判断是否是不可见的样式
18+
* @param shape
19+
*/
1620
export const isVisibleShape = (shape: Rectangle) => {
17-
const isInvalidFills =
18-
shape.style.fills.length === 0 ||
19-
shape.style.fills.every((fill) => fill.opacity.toString() === '0');
20-
const isInvalidBorders =
21-
shape.style.borders.length === 0 ||
22-
shape.style.borders.every(
23-
(border) => border.opacity === 0 || border.thickness === 0
24-
);
25-
26-
console.log(
27-
shape.name,
28-
'isInvalidFills',
29-
isInvalidFills,
30-
'isInvalidBorders',
31-
isInvalidBorders
32-
);
3321
const isInvisible = shape.style.opacity === 0;
3422

23+
// 透明度为 0 也返回不可见
3524
if (isInvisible) return false;
3625

26+
// 没任何样式的话,就返回不可见
27+
const hasNoStyle =
28+
shape.style.fills.length === 0 && shape.style.borders.length === 0;
29+
if (hasNoStyle) return false;
30+
31+
const isInvalidFills = shape.style.fills.every(
32+
(fill) => fill.opacity.toString() === '0'
33+
);
34+
const isInvalidBorders = shape.style.borders.every(
35+
(border) => border.opacity === 0 || border.thickness === 0
36+
);
37+
3738
if (isInvalidFills && isInvalidBorders) {
3839
return false;
3940
}

src/parser/shape.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ const transferToShape = (node: Element): Group | Rectangle => {
237237
break;
238238
}
239239
}
240-
if (isVisibleShape(rect)) return rect;
240+
return rect;
241241
};
242242

243243
export default transferToShape;

0 commit comments

Comments
 (0)