-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix cycle dependency error * checkpoint * types and everything * finish svgo funcitonality * update version * quick configuration * updates
- Loading branch information
Showing
21 changed files
with
690 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "svg-gobbler", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"author": "rossmoody <[email protected]>", | ||
"description": "SVG Gobbler is a simple browser extension that highlights any available SVG content in your current window and lets you download it.", | ||
"license": "apache-2.0", | ||
|
@@ -17,7 +17,8 @@ | |
"eslint-config-rossmoody" | ||
], | ||
"ignorePatterns": [ | ||
"*.config.js" | ||
"*.config.js", | ||
"*.d.ts" | ||
], | ||
"env": { | ||
"webextensions": true | ||
|
@@ -41,6 +42,7 @@ | |
"jszip": "^3.6.0", | ||
"prettier": "^2.3.2", | ||
"prettier-config-rossmoody": "^1.0.2", | ||
"pretty-bytes": "^5.6.0", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"react-icons": "^4.2.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react' | ||
import { Button, Box, Flex, Text } from '@chakra-ui/react' | ||
import prettyBytes from 'pretty-bytes' | ||
|
||
const getStringSize = (string: string) => { | ||
const bytes = new Blob([string]).size | ||
return prettyBytes(bytes) | ||
} | ||
|
||
interface CodeViewHeaderProps { | ||
originalString: string | ||
newString: string | ||
} | ||
|
||
function CodeViewHeader({ originalString, newString }: CodeViewHeaderProps) { | ||
const originalSize = getStringSize(originalString) | ||
const newSize = getStringSize(newString) | ||
|
||
const sizeString = | ||
originalSize === newSize ? originalSize : `${originalSize} -> ${newSize}` | ||
|
||
return ( | ||
<Flex justifyContent="space-between" p={3} alignItems="center"> | ||
<Box w="32px" /> | ||
<Text color="gray.400" fontSize="12px"> | ||
{sizeString} | ||
</Text> | ||
<Button | ||
size="xs" | ||
onClick={(event) => { | ||
navigator.clipboard.writeText(newString) | ||
;(event.target as HTMLButtonElement).textContent = 'Copied' | ||
|
||
setTimeout(() => { | ||
;(event.target as HTMLButtonElement).textContent = 'Copy' | ||
}, 1500) | ||
}} | ||
> | ||
Copy | ||
</Button> | ||
</Flex> | ||
) | ||
} | ||
|
||
export { CodeViewHeader } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React from 'react' | ||
import { Box, Center, Flex, Stack, Divider } from '@chakra-ui/react' | ||
|
||
import { SVGHighlighter } from './syntax-highlighter' | ||
import { runSvgo, defaultConfig } from './process-strings' | ||
import { SVGOConfig } from './svgo-types' | ||
import { Option } from './option' | ||
import { optionsData } from './options-data' | ||
import { CodeViewHeader } from './code-view-header' | ||
import { Subhead } from './form-category-subhead' | ||
import { QuickConfiguration } from './quick-configurations' | ||
|
||
interface DrawerContent { | ||
svgString: string | ||
} | ||
|
||
function DrawerContent({ svgString }: DrawerContent) { | ||
const svgoDefault: SVGOConfig = React.useMemo( | ||
() => JSON.parse(JSON.stringify(defaultConfig)), | ||
[] | ||
) | ||
|
||
const [originalString] = React.useState(svgString) | ||
const [string, setString] = React.useState(svgString) | ||
const [config, setConfig] = React.useState<SVGOConfig>(svgoDefault) | ||
const [radioGroup, setRadioGroup] = React.useState('default') | ||
|
||
React.useEffect(() => { | ||
const newString = runSvgo(originalString, config) | ||
setString(newString) | ||
}, [originalString, config]) | ||
|
||
return ( | ||
<Box display="block" height="100%" width="100%"> | ||
<Flex height="100%"> | ||
<Flex flex={8} flexDir="column" maxW="65%" bg="rgb(40, 42, 54)"> | ||
<CodeViewHeader originalString={originalString} newString={string} /> | ||
<Box minHeight="100%" height="50px" overflow="auto"> | ||
<SVGHighlighter>{string}</SVGHighlighter> | ||
</Box> | ||
</Flex> | ||
<Flex flex={4} flexDir="column"> | ||
<Center | ||
minHeight="140px" | ||
maxHeight="140px" | ||
p={4} | ||
dangerouslySetInnerHTML={{ __html: string }} | ||
overflow="hidden" | ||
sx={{ | ||
'& > svg': { | ||
height: '90%', | ||
width: '90%', | ||
overflow: 'visible', | ||
}, | ||
}} | ||
/> | ||
<Box position="relative" width="100%" height="100%"> | ||
<Box | ||
position="absolute" | ||
top={0} | ||
right={0} | ||
bottom={0} | ||
left={0} | ||
overflow="auto" | ||
> | ||
<Box px={5} paddingTop={4} paddingBottom={6} marginBottom={12}> | ||
<Subhead>Quick Configuration</Subhead> | ||
<QuickConfiguration | ||
setConfig={setConfig} | ||
setRadioGroup={setRadioGroup} | ||
radioGroup={radioGroup} | ||
/> | ||
<Divider my={8} /> | ||
<Subhead>Optimizations</Subhead> | ||
<Stack spacing="4"> | ||
{optionsData.map((option) => ( | ||
<Option | ||
key={option.pluginName} | ||
title={option.title} | ||
pluginName={option.pluginName} | ||
description={option.description} | ||
setConfig={setConfig} | ||
config={config} | ||
setRadioGroup={setRadioGroup} | ||
/> | ||
))} | ||
</Stack> | ||
</Box> | ||
</Box> | ||
</Box> | ||
</Flex> | ||
</Flex> | ||
</Box> | ||
) | ||
} | ||
|
||
export { DrawerContent } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
import { Box, Text } from '@chakra-ui/react' | ||
|
||
const Subhead: React.FC = ({ children }) => { | ||
return ( | ||
<Box mb="4"> | ||
<Text | ||
as="h3" | ||
fontWeight="bold" | ||
fontSize="xs" | ||
color="gray.400" | ||
textTransform="uppercase" | ||
> | ||
{children} | ||
</Text> | ||
</Box> | ||
) | ||
} | ||
|
||
export { Subhead } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.