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"],
|
"linebreak-style": ["error", "unix"],
|
||||||
"quotes": ["error", "double", { "avoidEscape": true }],
|
"quotes": ["error", "double", { "avoidEscape": true }],
|
||||||
"semi": ["error", "always"],
|
"semi": ["error", "always"],
|
||||||
|
"prefer-const": "error",
|
||||||
"space-before-function-paren": [
|
"space-before-function-paren": [
|
||||||
"error",
|
"error",
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ import {
|
|||||||
ColorInput,
|
ColorInput,
|
||||||
Stack,
|
Stack,
|
||||||
} from "@mantine/core";
|
} 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 { event } from "react-ga";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { FiCopy, FiDownload } from "react-icons/fi";
|
import { FiCopy, FiDownload } from "react-icons/fi";
|
||||||
@ -20,8 +20,20 @@ import { FiCopy, FiDownload } from "react-icons/fi";
|
|||||||
enum Extensions {
|
enum Extensions {
|
||||||
SVG = "svg",
|
SVG = "svg",
|
||||||
PNG = "png",
|
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 = [
|
const swatches = [
|
||||||
"#B80000",
|
"#B80000",
|
||||||
"#DB3E00",
|
"#DB3E00",
|
||||||
@ -95,9 +107,7 @@ export const DownloadModal: React.FC<ModalProps> = ({ opened, onClose }) => {
|
|||||||
|
|
||||||
const imageElement = document.querySelector("svg[id*='ref']") as HTMLElement;
|
const imageElement = document.querySelector("svg[id*='ref']") as HTMLElement;
|
||||||
|
|
||||||
let exportImage = extension === Extensions.SVG ? toSvg : toPng;
|
const dataURI = await getDownloadFormat(extension)(imageElement, {
|
||||||
|
|
||||||
const dataURI = await exportImage(imageElement, {
|
|
||||||
quality: fileDetails.quality,
|
quality: fileDetails.quality,
|
||||||
backgroundColor: fileDetails.backgroundColor,
|
backgroundColor: fileDetails.backgroundColor,
|
||||||
});
|
});
|
||||||
@ -129,11 +139,12 @@ export const DownloadModal: React.FC<ModalProps> = ({ opened, onClose }) => {
|
|||||||
<SegmentedControl
|
<SegmentedControl
|
||||||
value={extension}
|
value={extension}
|
||||||
onChange={e => setExtension(e as Extensions)}
|
onChange={e => setExtension(e as Extensions)}
|
||||||
|
fullWidth
|
||||||
data={[
|
data={[
|
||||||
{ label: "SVG", value: Extensions.SVG },
|
{ label: "SVG", value: Extensions.SVG },
|
||||||
{ label: "PNG", value: Extensions.PNG },
|
{ label: "PNG", value: Extensions.PNG },
|
||||||
|
{ label: "JPEG", value: Extensions.JPEG },
|
||||||
]}
|
]}
|
||||||
fullWidth
|
|
||||||
/>
|
/>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -245,7 +245,7 @@ export const traverse = ({
|
|||||||
parentType,
|
parentType,
|
||||||
}: Traverse) => {
|
}: Traverse) => {
|
||||||
const graph = states.graph;
|
const graph = states.graph;
|
||||||
let { type, children, value } = objectToTraverse;
|
const { type, children, value } = objectToTraverse;
|
||||||
|
|
||||||
if (!children) {
|
if (!children) {
|
||||||
handleNoChildren(value, states, graph, myParentId, parentType, nextType);
|
handleNoChildren(value, states, graph, myParentId, parentType, nextType);
|
||||||
|
@ -76,7 +76,7 @@ const debouncedUpdateJson = debounce(
|
|||||||
const filterArrayAndObjectFields = (obj: object) => {
|
const filterArrayAndObjectFields = (obj: object) => {
|
||||||
const result = {};
|
const result = {};
|
||||||
|
|
||||||
for (let key in obj) {
|
for (const key in obj) {
|
||||||
if (obj.hasOwnProperty(key)) {
|
if (obj.hasOwnProperty(key)) {
|
||||||
if (Array.isArray(obj[key]) || typeof obj[key] === "object") {
|
if (Array.isArray(obj[key]) || typeof obj[key] === "object") {
|
||||||
result[key] = obj[key];
|
result[key] = obj[key];
|
||||||
|
@ -89,7 +89,7 @@ const useGraph = create<Graph & GraphActions>((set, get) => ({
|
|||||||
);
|
);
|
||||||
const childrenEdges = getChildrenEdges(childrenNodes, get().edges);
|
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.from && !nodes.includes(edge.from) && nodes.push(edge.from);
|
||||||
edge.to && !nodes.includes(edge.to) && nodes.push(edge.to);
|
edge.to && !nodes.includes(edge.to) && nodes.push(edge.to);
|
||||||
return nodes;
|
return nodes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user