mirror of
https://github.com/AykutSarac/jsoncrack.com.git
synced 2025-01-12 19:02:53 +08:00
add jpeg download option
This commit is contained in:
parent
1445ba86d4
commit
0b7fa80ca6
@ -11,6 +11,7 @@
|
||||
"linebreak-style": ["error", "unix"],
|
||||
"quotes": ["error", "double", { "avoidEscape": true }],
|
||||
"semi": ["error", "always"],
|
||||
"prefer-const": "error",
|
||||
"space-before-function-paren": [
|
||||
"error",
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ import {
|
||||
ColorInput,
|
||||
Stack,
|
||||
} from "@mantine/core";
|
||||
import { toBlob, toPng, toSvg } from "html-to-image";
|
||||
import { toBlob, toJpeg, toPng, toSvg } from "html-to-image";
|
||||
import { event } from "react-ga";
|
||||
import toast from "react-hot-toast";
|
||||
import { FiCopy, FiDownload } from "react-icons/fi";
|
||||
@ -20,8 +20,20 @@ import { FiCopy, FiDownload } from "react-icons/fi";
|
||||
enum Extensions {
|
||||
SVG = "svg",
|
||||
PNG = "png",
|
||||
JPEG = "jpeg",
|
||||
}
|
||||
|
||||
const getDownloadFormat = (format: Extensions) => {
|
||||
switch (format) {
|
||||
case Extensions.SVG:
|
||||
return toSvg;
|
||||
case Extensions.PNG:
|
||||
return toPng;
|
||||
case Extensions.JPEG:
|
||||
return toJpeg;
|
||||
}
|
||||
};
|
||||
|
||||
const swatches = [
|
||||
"#B80000",
|
||||
"#DB3E00",
|
||||
@ -95,9 +107,7 @@ export const DownloadModal: React.FC<ModalProps> = ({ opened, onClose }) => {
|
||||
|
||||
const imageElement = document.querySelector("svg[id*='ref']") as HTMLElement;
|
||||
|
||||
let exportImage = extension === Extensions.SVG ? toSvg : toPng;
|
||||
|
||||
const dataURI = await exportImage(imageElement, {
|
||||
const dataURI = await getDownloadFormat(extension)(imageElement, {
|
||||
quality: fileDetails.quality,
|
||||
backgroundColor: fileDetails.backgroundColor,
|
||||
});
|
||||
@ -129,11 +139,12 @@ export const DownloadModal: React.FC<ModalProps> = ({ opened, onClose }) => {
|
||||
<SegmentedControl
|
||||
value={extension}
|
||||
onChange={e => setExtension(e as Extensions)}
|
||||
fullWidth
|
||||
data={[
|
||||
{ label: "SVG", value: Extensions.SVG },
|
||||
{ label: "PNG", value: Extensions.PNG },
|
||||
{ label: "JPEG", value: Extensions.JPEG },
|
||||
]}
|
||||
fullWidth
|
||||
/>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
|
@ -245,7 +245,7 @@ export const traverse = ({
|
||||
parentType,
|
||||
}: Traverse) => {
|
||||
const graph = states.graph;
|
||||
let { type, children, value } = objectToTraverse;
|
||||
const { type, children, value } = objectToTraverse;
|
||||
|
||||
if (!children) {
|
||||
handleNoChildren(value, states, graph, myParentId, parentType, nextType);
|
||||
|
@ -76,7 +76,7 @@ const debouncedUpdateJson = debounce(
|
||||
const filterArrayAndObjectFields = (obj: object) => {
|
||||
const result = {};
|
||||
|
||||
for (let key in obj) {
|
||||
for (const key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
if (Array.isArray(obj[key]) || typeof obj[key] === "object") {
|
||||
result[key] = obj[key];
|
||||
|
@ -89,7 +89,7 @@ const useGraph = create<Graph & GraphActions>((set, get) => ({
|
||||
);
|
||||
const childrenEdges = getChildrenEdges(childrenNodes, get().edges);
|
||||
|
||||
let nodesConnectedToParent = childrenEdges.reduce((nodes: string[], edge) => {
|
||||
const nodesConnectedToParent = childrenEdges.reduce((nodes: string[], edge) => {
|
||||
edge.from && !nodes.includes(edge.from) && nodes.push(edge.from);
|
||||
edge.to && !nodes.includes(edge.to) && nodes.push(edge.to);
|
||||
return nodes;
|
||||
|
Loading…
x
Reference in New Issue
Block a user