mirror of
https://github.com/ritz078/transform.git
synced 2026-11-21 00:32:56 +03:00
* remove svg-to-dataurl dependency * chore: update package.json for build command and node version - Modified the build command to include NODE_OPTIONS for legacy OpenSSL support. - Updated the Node.js engine requirement to >=20.17.0. - Added packageManager field for Yarn version. * chore: update now.json for build environment and Node.js version - Added NODE_OPTIONS for OpenSSL legacy support in the build environment. - Specified Node.js engine version to 20.x. * chore: remove Node.js engine specification from now.json - Removed the Node.js engine version specification from the configuration file. * chore: remove now.json configuration file - Deleted the now.json file, which contained build environment settings and redirects. --------- Co-authored-by: madflow <madflow@web.de> Co-authored-by: Ritesh Kumar <ritz078@users.noreply.github.com>
138 lines
3.6 KiB
TypeScript
138 lines
3.6 KiB
TypeScript
import { Settings } from "@constants/svgoConfig";
|
|
import { default as React, useCallback } from "react";
|
|
import { EditorPanelProps } from "@components/EditorPanel";
|
|
import Form from "@components/Form";
|
|
import ConversionPanel, { Transformer } from "@components/ConversionPanel";
|
|
import { Alert, Badge, Heading, Pane } from "evergreen-ui";
|
|
|
|
const svgToDataUrl = (svgStr: string) => {
|
|
const encoded = encodeURIComponent(svgStr)
|
|
.replace(/'/g, "%27")
|
|
.replace(/"/g, "%22");
|
|
|
|
const header = "data:image/svg+xml,";
|
|
const dataUrl = header + encoded;
|
|
|
|
return dataUrl;
|
|
};
|
|
|
|
interface SvgConverterProps {
|
|
name: string;
|
|
babelWorker?: any;
|
|
transformer: Transformer;
|
|
formFields: any;
|
|
resultTitle: string;
|
|
optimizedValue: string;
|
|
settings: any;
|
|
setSettings: (settings: any) => void;
|
|
}
|
|
|
|
export const SvgConverter: React.FunctionComponent<SvgConverterProps> = ({
|
|
transformer,
|
|
resultTitle,
|
|
formFields,
|
|
optimizedValue,
|
|
settings,
|
|
setSettings
|
|
}) => {
|
|
const getSettingsPanel = useCallback<EditorPanelProps["settingElement"]>(
|
|
({ open, toggle }) => {
|
|
return (
|
|
<Form<Partial<Settings>>
|
|
initialValues={settings}
|
|
open={open}
|
|
toggle={toggle}
|
|
title={"SVGO Settings"}
|
|
onSubmit={setSettings}
|
|
formsFields={formFields}
|
|
/>
|
|
);
|
|
},
|
|
[]
|
|
);
|
|
|
|
return (
|
|
<ConversionPanel
|
|
transformer={transformer}
|
|
editorTitle="SVG"
|
|
resultLanguage="javascript"
|
|
resultTitle={resultTitle}
|
|
editorLanguage="html"
|
|
editorDefaultValue="svg"
|
|
settings={settings}
|
|
editorProps={{
|
|
settingElement: getSettingsPanel,
|
|
topNotifications: ({ toggleSettings }) =>
|
|
settings.optimizeSvg && (
|
|
<Alert
|
|
intent="warning"
|
|
backgroundColor="#FEF8E7"
|
|
title={
|
|
<>
|
|
SVGO optimization is turned on. You can turn it off or
|
|
configure it in{" "}
|
|
<Heading
|
|
size={400}
|
|
is="a"
|
|
color={"blue"}
|
|
onClick={toggleSettings}
|
|
>
|
|
settings
|
|
</Heading>
|
|
</>
|
|
}
|
|
/>
|
|
),
|
|
previewElement: value => (
|
|
<Pane display="flex" flexDirection="row" flex={1}>
|
|
<Pane display={"flex"} flex={1} position="relative">
|
|
<img
|
|
style={{
|
|
flex: 1,
|
|
width: "100%",
|
|
borderRight: "1px solid #eee"
|
|
}}
|
|
src={svgToDataUrl(value)}
|
|
alt="original"
|
|
/>
|
|
|
|
<Badge
|
|
position="absolute"
|
|
bottom={10}
|
|
right={10}
|
|
color="green"
|
|
isSolid
|
|
>
|
|
Original
|
|
</Badge>
|
|
</Pane>
|
|
<Pane display={"flex"} flex={1} position="relative">
|
|
{optimizedValue && (
|
|
<img
|
|
style={{
|
|
flex: 1,
|
|
width: "100%"
|
|
}}
|
|
src={svgToDataUrl(optimizedValue)}
|
|
alt="optimized"
|
|
/>
|
|
)}
|
|
|
|
<Badge
|
|
position="absolute"
|
|
bottom={10}
|
|
right={10}
|
|
color="green"
|
|
isSolid
|
|
>
|
|
Result
|
|
</Badge>
|
|
</Pane>
|
|
</Pane>
|
|
),
|
|
acceptFiles: "image/svg+xml"
|
|
}}
|
|
/>
|
|
);
|
|
};
|