ant-design / ant-design/html2sketch
🐛[BUG]svg转换过程中遇到的问题以及我现在的临时解决方式
- Dominant language
- TypeScript
- Stars
- 179
- Forks
- 27
- PR merge metrics
- No merged PRs in 30d
Description
### 🐛 bug 描述
在转换svg时,转换如下svgString时,优化代码部分报错,因为依赖的是三方,对此我没有继续向下追代码,所以简单做了兼容
```js
const svg = await svgo.optimize(svgStr).catch((err)=>{
console.log('svgerr',err);
});
if(svg){
return svg.data
}
return svgStr;
```
报错的svgString如下
``
另一个问题,如果svg设置了`fill=currentColor`,转换后的json `style`相关内容是默认值,我追了下代码,发现在此处的代码中
```js
// 如果存在currentColor 则采用 inline Style 的 fill
if (fillStr === 'currentColor' && styleObj?.fill) {
style.addColorFill(styleObj.fill);
}
```
fillStr始终为空,所以导致代码不能执行,我暂时屏蔽了`fillStr === 'currentColor'`的判断,转换后颜色信息是可以转换出来了,但是并不知道会引起其他的什么后果,另一个issue也提到了这个问题
### © 版本信息
- html2sketch 版本: [0.4.6]
- 浏览器环境 chrome
- 开发环境 [mac OS11.2.2]
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the failure with the SVG string in the issue and inspect the optimization call and the currentColor handling shown in the report. Trace why fillStr is empty and determine whether the third-party optimizer error is expected. Done means the SVG converts without an exception and currentColor style data is handled correctly without regressing other SVGs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- design, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100