Skip to content

Commit eefccdb

Browse files
committed
fix: 修复部分样式解析错误
1 parent 83c671e commit eefccdb

File tree

8 files changed

+435
-12
lines changed

8 files changed

+435
-12
lines changed

example/components/Test.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
import React, { FC } from 'react';
22
import { Radio, Button, Tag, Space } from 'antd';
3-
import { UpCircleOutlined } from '@ant-design/icons';
4-
// import { WelcomeHeader } from '@alipay/tech-ui';
3+
import styles from './test.less';
54

65
/**
76
*
87
*/
98
export const Test: FC = () => {
109
return (
11-
<div>
10+
<div id={'x-tag'}>
1211
<Tag className="test" symbolName="1.Tag 标签/1.Default默认/1.Off关">
1312
内容
1413
</Tag>
14+
<a>
15+
展开
16+
<span
17+
role="img"
18+
aria-label="down"
19+
className="anticon anticon-down"
20+
style={{ marginLeft: '0.5em', transform: 'rotate(0turn)' }}
21+
>
22+
<svg
23+
viewBox="64 64 896 896"
24+
focusable="false"
25+
className=""
26+
data-icon="down"
27+
width="1em"
28+
height="1em"
29+
fill="currentColor"
30+
aria-hidden="true"
31+
>
32+
<path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path>
33+
</svg>
34+
</span>
35+
</a>
1536
{/*<WelcomeHeader*/}
1637
{/* className="test"*/}
1738
{/* title="页面标题"*/}

example/components/test.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.label {
2+
position: relative;
3+
display: inline-flex;
4+
align-items: center;
5+
height: 32px;
6+
color: rgba(0, 0, 0, 0.85);
7+
font-size: 14px;
8+
}

example/pages/index.tsx

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
} from '../components';
1111

1212
import copy from 'copy-to-clipboard';
13-
import styles from './style.less';
14-
import { nodeToSketchSymbol, svgNodeToSvg } from '../../lib';
13+
import { nodeToSketchSymbol, svgNodeToSvg, nodeToSketchGroup } from '../../lib';
1514
import { SMART_LAYOUT } from '../../lib/helpers/layout';
15+
import styles from './style.less';
1616

1717
const { TabPane } = Tabs;
1818
export default () => {
@@ -27,7 +27,7 @@ export default () => {
2727
const els = document.getElementsByClassName(classname);
2828
const json: Object[] = [];
2929

30-
Array.from(els).forEach((el) => {
30+
Array.from(els).forEach(el => {
3131
const smartLayout = el.getAttribute(
3232
'smartLayout',
3333
) as keyof typeof SMART_LAYOUT;
@@ -46,12 +46,15 @@ export default () => {
4646
setJSON(json);
4747
};
4848

49+
/**
50+
* 生成 Svg
51+
*/
4952
const generateSvg = () => {
5053
const els = document.getElementsByTagName('svg');
5154

5255
const json: Object[] = [];
5356

54-
Array.from(els).map((el) => {
57+
Array.from(els).map(el => {
5558
const svg = svgNodeToSvg(el).toSketchJSON();
5659
console.log(svg);
5760
json.push(svg);
@@ -61,14 +64,33 @@ export default () => {
6164

6265
setJSON(json);
6366
};
67+
68+
/**
69+
* 生成 Group
70+
*/
71+
const generateGroup = () => {
72+
try {
73+
const el = document.getElementById('x-tag');
74+
if (el) {
75+
const group = nodeToSketchGroup(el);
76+
console.log('-------转换结束--------');
77+
console.log(group);
78+
79+
const data = group.toSketchJSON();
80+
copy(JSON.stringify(data));
81+
}
82+
} catch (e) {
83+
message.error('解析失败,配置项可能存在错误!');
84+
}
85+
};
6486
return (
6587
<div className={styles.container}>
6688
<Row gutter={[0, 24]}>
6789
<Col span={24}>
6890
<Card>
6991
<Tabs
7092
activeKey={activeKey}
71-
onChange={(key) => {
93+
onChange={key => {
7294
setActiveKey(key);
7395
}}
7496
tabPosition={'left'}
@@ -104,6 +126,7 @@ export default () => {
104126
<Col>
105127
<Space>
106128
<Button onClick={() => generateSvg()}>解析 Svg</Button>
129+
<Button onClick={() => generateGroup()}>转换为 Group</Button>
107130
<Button
108131
type={'primary'}
109132
onClick={() => generateSymbol(activeKey)}
@@ -122,7 +145,9 @@ export default () => {
122145
<ReactJson src={json || {}} />
123146
</Card>
124147
</Col>
125-
) : undefined}
148+
) : (
149+
undefined
150+
)}
126151
</Row>
127152
</div>
128153
);

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html2sketch",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"author": "arvinxx",
55
"description": "parser html to sketch json",
66
"repository": {
@@ -45,10 +45,11 @@
4545
"konva": "^7.0.3",
4646
"lint-staged": "^10.0.7",
4747
"prettier": "^1.18.2",
48+
"puppeteer": "^5.2.1",
4849
"react": "^16.12.0",
4950
"react-dom": "^16.12.0",
5051
"react-json-view": "^1.19.1",
51-
"react-konva": "^16.13.0-3",
52+
"react-konva": "^16.13.0-5",
5253
"ts-jest": "^24.0.2",
5354
"tslint": "^5.18.0",
5455
"tslint-config-prettier": "^1.18.0",

src/function/__test__/node2SketchGroup/button.spec.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)