svgo optimization

This commit is contained in:
ritz078 committed 2017-10-30 04:21:45 +05:30
1 parent 10f63c90cf
commit c032c0f4f8
5 files changed
+291 -405

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
{
"presets": ["next/babel"],
"plugins": ["transform-react-remove-prop-types"]
}
+19 -23
View File
@@ -5,7 +5,7 @@ import Head from 'next/head'
import NProgress from 'nprogress'
import Router from 'next/router'
import GithubCorner from 'react-github-corner'
import FuzzyPicker, { FuzzyWrapper } from 'react-fuzzy-picker'
// import FuzzyPicker, { FuzzyWrapper } from 'react-fuzzy-picker'
import Collapse, { Panel } from 'rc-collapse'
import findIndex from 'lodash/findIndex'
import { categorizedRoutes, routes, activeRouteData } from '../utils/routes'
@@ -81,24 +81,24 @@ function trackingScript () {
ga('send', 'pageview')
}
function renderFuzzyPicker (isOpen, onClose) {
return (
<FuzzyPicker
isOpen={isOpen}
onClose={onClose}
onChange={choice => Router.push(choice.path)}
items={routes}
itemValue={item => item.label}
renderItem={item => <span>{item.label}</span>}
/>
)
}
// Here, we check what key must be pressed to open the fuzzy picker
// We'll use the '/' key for this example.
function isCorrectKeyPressed (event) {
return event.metaKey && event.key === 'p'
}
// function renderFuzzyPicker (isOpen, onClose) {
// return (
// <FuzzyPicker
// isOpen={isOpen}
// onClose={onClose}
// onChange={choice => Router.push(choice.path)}
// items={routes}
// itemValue={item => item.label}
// renderItem={item => <span>{item.label}</span>}
// />
// )
// }
//
// // Here, we check what key must be pressed to open the fuzzy picker
// // We'll use the '/' key for this example.
// function isCorrectKeyPressed (event) {
// return event.metaKey && event.key === 'p'
// }
export default class Layout extends PureComponent {
state = {}
@@ -307,10 +307,6 @@ export default class Layout extends PureComponent {
}
`}</style>
<FuzzyWrapper
isKeyPressed={isCorrectKeyPressed}
popup={renderFuzzyPicker}
/>
<div className='sidebar'>
<GithubCorner
href='https://github.com/ritz078/transform-www'
+3 -2
View File
@@ -53,9 +53,9 @@
"promise-worker": "^1.1.1",
"prop-types": "^15.6.0",
"rc-collapse": "^1.7.6",
"react": "^16.0.0",
"react": "16.0.0-rc.2",
"react-codemirror2": "^2.0.2",
"react-dom": "^16.0.0",
"react-dom": "16.0.0-rc.2",
"react-fuzzy-picker": "^0.5.1",
"react-github-corner": "^1.0.0",
"stringify-object": "^3.2.1",
@@ -68,6 +68,7 @@
},
"devDependencies": {
"all-contributors-cli": "^4.5.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.10",
"babili-webpack-plugin": "^0.1.2",
"css-loader": "^0.28.7",
"glob": "^7.1.2",
+15 -3
View File
@@ -4,6 +4,7 @@ import convertSvgString from 'transform-svg-to-native'
import Layout from '../components/Layout'
import ConversionPanel from '../components/ConversionPanel'
import isSvg from 'is-svg'
import svgo from 'transform-svg-to-native/dist/svgo'
const converter = new HTMLtoJSX({
createClass: false
@@ -18,6 +19,17 @@ export default class Css2Js extends PureComponent {
native: false
}
convertHtmlToJsx = html => {
if (isSvg(html)) {
return new Promise(resolve => {
svgo.optimize(html, result => {
resolve(result.data)
})
})
}
return converter.convert(html)
}
getTransformedValue = async (newValue: string) => {
if (this.state.native && !isSvg(newValue)) {
throw new Error(
@@ -27,9 +39,9 @@ export default class Css2Js extends PureComponent {
return this.state.native
? new Promise(resolve =>
convertSvgString(newValue, code => resolve(code))
)
: converter.convert(newValue)
convertSvgString(newValue, code => resolve(code))
)
: this.convertHtmlToJsx(newValue)
}
render () {
+250 -377
View File
File diff suppressed because it is too large. Load diff