first commit

This commit is contained in:
Mathieu Bruyen
2022-05-02 15:12:06 +02:00
commit 4ddc04d017
23 changed files with 3849 additions and 0 deletions

2
.dockerignore Normal file
View File

@@ -0,0 +1,2 @@
node_modules
dist

24
.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

19
Dockerfile Normal file
View File

@@ -0,0 +1,19 @@
FROM node:17.9.0-alpine3.14 AS dev
RUN mkdir /app && chown -R node /app
WORKDIR /app
USER node
FROM dev AS builder
COPY --chown=node package.json package-lock.json ./
RUN npm install
COPY --chown=node . .
RUN npm run build
FROM nginx:1.21.6-alpine
EXPOSE 80
COPY --from=builder /app/dist /usr/share/nginx/html

12
README.md Normal file
View File

@@ -0,0 +1,12 @@
# SVG editor
```
docker build -t svg-editor .
docker run --rm -p 8080:80 svg-editor
```
```
docker build -t svg-editor-dev --target dev .
docker run -it --rm -v $(pwd):/app -p 4173:4173 svg-editor-dev npm install
docker run -it --rm -v $(pwd):/app -p 4173:4173 svg-editor-dev npm run dev
```

13
index.html Normal file
View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SVG Editor</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

2265
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

22
package.json Normal file
View File

@@ -0,0 +1,22 @@
{
"name": "svg-editor",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite --host --port 4173",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react": "^1.3.0",
"typescript": "^4.6.3",
"vite": "^2.9.2"
}
}

33
src/App.css Normal file
View File

@@ -0,0 +1,33 @@
.App {
max-width: 80em;
margin: 0 auto;
display: grid;
grid-template-rows: auto auto;
grid-template-columns: 1fr 2fr;
}
.App-general {
grid-area: 1 / 1 / 2 / 3;
}
.App-editor {
grid-area: 2 / 1;
}
.App-renderer {
grid-area: 2 / 2 / 3 / 3;
box-shadow: 2px 2px 5px red;
position: relative;
}
.App-renderer > svg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.App-overlay {
width: 100%;
height: 100%;
}

283
src/App.tsx Normal file
View File

@@ -0,0 +1,283 @@
import {useState, useCallback, useId, useRef, useEffect} from 'react';
import {v4 as uuidv4} from 'uuid';
import {SortableItems} from './Editor';
import {PathRender, PathEditor, PathOverlayDOM, PathOverlaySVG, normalizePath} from './Path';
import {CircleRender, CircleEditor, CircleOverlayDOM, CircleOverlaySVG, normalizeCircle} from './Circle';
import {arrayWith} from './array';
import type {Action} from './Editor';
import type {Path} from './Path';
import type {Circle} from './Circle';
import logo from './logo.svg';
import './App.css';
export type SvgItem = Path | Circle;
type SvgDescription = {
width: number,
height: number,
items: SvgItem[],
}
export function App() {
const [svgDescription, setSvgDescriptionInState] = useState<SvgDescription>({
width: 100,
height: 100,
items: [],
});
useEffect(() => {
const storedString = window.localStorage.getItem('svg-content');
if (storedString) {
const stored = JSON.parse(storedString);
const width = typeof stored.width === 'number' && stored.width >= 1 ? stored.width : 100;
const height = typeof stored.height === 'number' && stored.height >= 1 ? stored.height : 100;
function normalizeItem(rawItem: any): SvgItem[] {
if (rawItem && rawItem.type === 'path') {
const path = normalizePath(rawItem);
if (path) {
return [path];
} else {
return [];
}
} else if (rawItem && rawItem.type === 'circle') {
const circle = normalizeCircle(rawItem);
if (circle) {
return [circle];
} else {
return [];
}
} else {
return [];
}
}
const items = Array.isArray(stored.items) ? (stored.items as any[]).flatMap((item) => normalizeItem(item)) : [];
setSvgDescriptionInState({width, height, items});
}
}, []);
const setSvgDescription = useCallback((action: (svgDescription: SvgDescription) => SvgDescription) => {
setSvgDescriptionInState((previous) => {
const current = action(previous);
window.localStorage.setItem('svg-content', JSON.stringify(current));
return current;
});
}, []);
const widthId = useId();
const onWidthChange = useCallback((e: React.FormEvent<HTMLInputElement>) => {
e.preventDefault();
setSvgDescription((previous) => {
return {
...previous,
width: e.currentTarget.valueAsNumber || 1,
};
});
}, []);
const heightId = useId();
const onHeightChange = useCallback((e: React.FormEvent<HTMLInputElement>) => {
e.preventDefault();
setSvgDescription((previous) => {
return {
...previous,
height: e.currentTarget.valueAsNumber || 1,
};
});
}, []);
const overlayImageId = useId();
const [overlayImage, setOverlayImage] = useState<string>();
const onOverlayImageChange = useCallback((e: React.FormEvent<HTMLInputElement>) => {
if (e.currentTarget.files && e.currentTarget.files.length > 0) {
const file = e.currentTarget.files[0];
if (file) {
setOverlayImage((previous) => {
if (previous) {
URL.revokeObjectURL(previous);
}
return URL.createObjectURL(file);
});
}
}
}, []);
const onDeleteOverlayImage = useCallback((e: React.MouseEvent<HTMLButtonElement>) => {
setOverlayImage((previous) => {
if (previous) {
URL.revokeObjectURL(previous);
}
return undefined;
});
}, []);
useEffect(() => {
return () => {
if (overlayImage) {
URL.revokeObjectURL(overlayImage);
}
}
}, [overlayImage]);
const [svgElement, setSvgElement] = useState<SVGSVGElement | null>(null);
const onItemsChange = useCallback((action: (items: SvgItem[]) => SvgItem[]) => {
setSvgDescription((previous) => {
return {
...previous,
items: action(previous.items),
};
});
}, []);
const onItemChange = useCallback((id: string, action: (item: SvgItem) => SvgItem) => {
setSvgDescription((previous) => {
const index = previous.items.findIndex((i) => i.id === id);
if (index < 0) {
return previous;
}
return {
...previous,
items: arrayWith(previous.items, index, action(previous.items[index])),
};
});
}, []);
const onDownload = useCallback(() => {
if (!svgElement) {
return;
}
const element = document.createElement('a');
const file = new Blob([svgElement.outerHTML], {type: 'image/svg+xml'});
element.href = URL.createObjectURL(file);
element.download = 'image.svg';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}, [svgElement]);
const onAddCircle = useCallback(() => {
setSvgDescription((previous) => {
return {
...previous,
items: previous.items.concat({
type: 'circle',
id: uuidv4(),
cx: previous.width / 2,
cy: previous.height / 2,
r: Math.min(previous.width, previous.height) / 2,
stroke: 'black',
strokeWidth: 1,
}),
};
});
}, []);
const onAddPath = useCallback(() => {
setSvgDescription((previous) => {
return {
...previous,
items: previous.items.concat({
type: 'path',
id: uuidv4(),
description: [{
type: 'move-to',
id: uuidv4(),
x: previous.width / 3,
y: previous.height / 3,
}, {
type: 'line-to',
id: uuidv4(),
x: 2 * previous.width / 3,
y: 2 * previous.height / 3,
}],
stroke: 'black',
strokeWidth: 1,
}),
};
});
}, []);
return <div className="App">
<section className="App-general">
<div>
<label htmlFor={widthId}>Width:</label><input onChange={onWidthChange} value={svgDescription.width} type="number" min="1" step="1" id={widthId} />
</div>
<div>
<label htmlFor={heightId}>Height:</label><input onChange={onHeightChange} value={svgDescription.height} type="number" min="1" step="1" id={heightId} />
</div>
<div>
<label htmlFor={overlayImageId}>Overlay image:</label>
<input onChange={onOverlayImageChange} type="file" id={overlayImageId} accept="image/*" />
{!!overlayImage && <button onClick={onDeleteOverlayImage}>Remove</button>}
</div>
<div>
<button onClick={onDownload} disabled={!svgElement}>Download</button>
</div>
</section>
<div className="App-editor">
<SortableItems items={svgDescription.items} onChange={onItemsChange} Component={ItemEditor} />
<div>
<button onClick={onAddPath}>Add Path</button>
<button onClick={onAddCircle}>Add circle</button>
</div>
</div>
<div className="App-renderer" style={{aspectRatio: `${svgDescription.width} / ${svgDescription.height}`, minHeight: 0}}>
{!!overlayImage && <img style={{width: '100%'}} src={overlayImage} />}
<svg viewBox={`0 0 ${svgDescription.width} ${svgDescription.height}`} ref={(node) => setSvgElement(node)}>
{svgDescription.items.map((item) => {
if (item.type === 'path') {
return <PathRender key={item.id} path={item} />;
} else if (item.type === 'circle') {
return <CircleRender key={item.id} circle={item} />;
} else {
const neverItem : never = item;
throw new Error(`Invalid SVG item: ${JSON.stringify(neverItem)}`);
}
})}
</svg>
<svg viewBox={`0 0 ${svgDescription.width} ${svgDescription.height}`}>
{svgDescription.items.map((item) => {
if (item.type === 'path') {
return <PathOverlaySVG key={item.id} path={item} />
} else if (item.type === 'circle') {
return <CircleOverlaySVG key={item.id} circle={item} />
} else {
const neverItem : never = item;
throw new Error(`Invalid SVG item: ${JSON.stringify(neverItem)}`);
}
})}
</svg>
<div className="App-overlay">
{svgDescription.items.map((item, index) => {
return <ItemOverlay key={item.id} item={item} onItemChange={onItemChange} svgDescription={svgDescription} />;
})}
</div>
</div>
</div>;
}
type ItemOverlayProps = {
item: SvgItem,
onItemChange: (id: string, action: (item: SvgItem) => SvgItem) => void,
svgDescription: SvgDescription,
};
function ItemOverlay({item, onItemChange, svgDescription}: ItemOverlayProps) {
const onChange = useCallback(onItemChange.bind(null, item.id), [onItemChange, item.id]);
if (item.type === 'path') {
return <PathOverlayDOM path={item} onChange={onChange} width={svgDescription.width} height={svgDescription.height} />
} else if (item.type === 'circle') {
return <CircleOverlayDOM circle={item} onChange={onChange} width={svgDescription.width} height={svgDescription.height} />
} else {
const neverItem : never = item;
throw new Error(`Invalid SVG item: ${JSON.stringify(neverItem)}`);
}
}
function ItemEditor({item, onChange}: {item: SvgItem, onChange: Action<SvgItem>}) {
if (item.type === 'path') {
return <PathEditor path={item} onChange={onChange} />
} else if (item.type === 'circle') {
return <CircleEditor circle={item} onChange={onChange} />
} else {
const neverItem : never = item;
throw new Error(`Invalid SVG item: ${JSON.stringify(neverItem)}`);
}
}

163
src/Circle.tsx Normal file
View File

@@ -0,0 +1,163 @@
import {useCallback, Fragment} from 'react';
import {v4 as uuidv4} from 'uuid';
import {Editor, StringField, NumberField, OverlayHandle} from './Editor';
import type {SvgItem} from './App';
import type {Action} from './Editor';
export type Circle = {
type: 'circle',
id: string,
stroke: string,
strokeWidth: number,
cx: number,
cy: number,
r: number,
}
type CircleRenderProps = {
circle: Circle,
}
export function CircleRender({circle}: CircleRenderProps) {
return <circle
cx={circle.cx}
cy={circle.cy}
r={circle.r}
stroke={circle.stroke}
strokeWidth={circle.strokeWidth}
fill="none" />;
}
export function CircleOverlaySVG({circle}: CircleRenderProps) {
return <path
d={`M${circle.cx} ${circle.cy} L${circle.cx + circle.r} ${circle.cy}`}
stroke="grey"
strokeWidth={circle.strokeWidth}
strokeDasharray="2 1" />;
}
type CircleEditorProps = {
circle: Circle,
onChange: Action<SvgItem>,
}
export function CircleEditor({circle, onChange}: CircleEditorProps) {
const onCxChange = useCallback((cx: number) => {
onChange((item) => {
if (item.type !== 'circle') {
return item;
}
return {
...item,
cx,
};
});
}, [onChange]);
const onCyChange = useCallback((cy: number) => {
onChange((item) => {
if (item.type !== 'circle') {
return item;
}
return {
...item,
cy,
};
});
}, [onChange]);
const onRChange = useCallback((r: number) => {
onChange((item) => {
if (item.type !== 'circle') {
return item;
}
return {
...item,
r,
};
});
}, [onChange]);
const onStrokeChange = useCallback((stroke: string) => {
onChange((item) => {
if (item.type !== 'circle') {
return item;
}
return {
...item,
stroke,
};
});
}, [onChange]);
const onStrokeWidthChange = useCallback((strokeWidth: number) => {
onChange((item) => {
if (item.type !== 'circle') {
return item;
}
return {
...item,
strokeWidth,
};
});
}, [onChange]);
return <Editor tag="circle">
<NumberField name="cx" value={circle.cx} onChange={onCxChange} step={0.1} />
<NumberField name="cy" value={circle.cy} onChange={onCyChange} step={0.1} />
<NumberField name="r" value={circle.r} onChange={onRChange} step={0.1} />
<StringField name="stroke" value={circle.stroke} onChange={onStrokeChange} />
<NumberField name="stroke-width" value={circle.strokeWidth} onChange={onStrokeWidthChange} step={0.1} />
</Editor>;
}
type CircleOverlayDOMProps = {
circle: Circle,
width: number,
height: number,
onChange: Action<SvgItem>,
}
export function CircleOverlayDOM({circle, width, height, onChange}: CircleOverlayDOMProps) {
const onCChange = useCallback((cx: number, cy: number) => {
onChange((item) => {
if (item.type !== 'circle') {
return item;
}
return {
...item,
cx,
cy,
};
});
}, [ onChange]);
const onRChange = useCallback((rx: number, ry: number) => {
onChange((item) => {
if (item.type !== 'circle') {
return item;
}
const r = Math.sqrt((rx - circle.cx) * (rx - circle.cx) + (ry - circle.cy) * (ry - circle.cy));
return {
...item,
r,
};
});
}, [onChange]);
return <Fragment>
<OverlayHandle x={circle.cx} y={circle.cy} width={width} height={height} onChange={onCChange} />
<OverlayHandle x={circle.cx + circle.r} y={circle.cy} width={width} height={height} onChange={onRChange} />
</Fragment>;
}
export function normalizeCircle(circle: any): Circle | null {
if (!circle) {
return null;
}
return {
type: 'circle',
id: typeof circle.id === 'string' ? circle.id : uuidv4(),
cx: typeof circle.cx === 'number' ? circle.cx : 0,
cy: typeof circle.cy === 'number' ? circle.cy : 0,
r: typeof circle.r === 'number' ? circle.r : 0,
stroke: typeof circle.stroke === 'string' ? circle.stroke : 'black',
strokeWidth: typeof circle.strokeWidth === 'number' ? circle.strokeWidth : 0,
};
}

27
src/Editor.css Normal file
View File

@@ -0,0 +1,27 @@
.Editor-handle {
position: absolute;
transform: translate(-50%, -50%);
width: 20px;
height: 20px;
background: grey;
border-radius: 10px;
}
.Editor-handle-drop {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.Editor-sortable-item-drop, .Editor-sortable-item-trash {
margin: 5px;
border-width: 3px;
border-style: dashed;
height: 1em;
}
.Editor-field {
display: flex;
}

330
src/Editor.tsx Normal file
View File

@@ -0,0 +1,330 @@
import {useId, useCallback, useState, useEffect, useRef, Fragment} from 'react';
import {arrayWith} from './array';
import './Editor.css';
export type Action<T> = (action: (previous: T) => T) => void;
type EditorProps = {
tag: string,
children: React.ReactNode,
}
export function Editor({tag, children}: EditorProps) {
const [collapsed, setCollapsed] = useState(true);
if (collapsed) {
return <div>
<div>
<code>{'<'}{tag}</code>
<button onClick={() => setCollapsed(false)}>+</button>
<code>{'/>'}</code>
</div>
</div>;
}
return <div>
<div>
<code>{'<'}{tag}</code>
<button onClick={() => setCollapsed(true)}>-</button>
</div>
{children}
<div>
<code>{'/>'}</code>
</div>
</div>;
}
type FieldProps = {
name: string,
id: string,
children: React.ReactNode,
}
export function Field({name, id, children}: FieldProps) {
return <div className="Editor-field">
<label htmlFor={id}>{name}=</label>
<div>{children}</div>
</div>;
}
type StringFieldProps = {
name: string,
value: string,
onChange: (value: string) => void,
}
export function StringField({name, value, onChange}: StringFieldProps) {
const id = useId();
const onFieldChange = useCallback((e: React.FormEvent<HTMLInputElement>) => {
e.preventDefault();
onChange(e.currentTarget.value);
}, [onChange]);
return <Field id={id} name={name}>
<input id={id} value={value} onChange={onFieldChange} />
</Field>;
}
type NumberFieldProps = {
name: string,
step: number,
value: number,
onChange: (value: number) => void,
}
export function NumberField({name, value, step, onChange}: NumberFieldProps) {
const id = useId();
const [displayedValue, setDisplayedValue] = useState({
valueAsString: value.toString(),
valueAsNumber: value,
});
const onFieldChange = useCallback((e: React.FormEvent<HTMLInputElement>) => {
e.preventDefault();
setDisplayedValue({
valueAsString: e.currentTarget.value,
valueAsNumber: e.currentTarget.valueAsNumber,
});
if (typeof e.currentTarget.valueAsNumber === 'number') {
onChange(e.currentTarget.valueAsNumber);
}
}, [onChange]);
const onFieldRoundUnit = useCallback(() => {
onChange(Math.round(value));
}, [onChange, value]);
const onFieldRoundDecimal = useCallback(() => {
onChange(Math.round(value * 10) / 10);
}, [onChange, value]);
const onFieldRoundPercent = useCallback(() => {
onChange(Math.round(value * 100) / 100);
}, [onChange, value]);
useEffect(() => {
if (displayedValue.valueAsNumber !== value) {
setDisplayedValue({
valueAsString: value.toString(),
valueAsNumber: value,
});
}
}, [value, displayedValue]);
return <Field id={id} name={name}>
<input id={id} value={displayedValue.valueAsString} onChange={onFieldChange} type="number" step={step} />
<button onClick={onFieldRoundUnit}>/1</button>
<button onClick={onFieldRoundDecimal}>/10</button>
<button onClick={onFieldRoundPercent}>/100</button>
</Field>;
}
type OverlayHandleProps = {
x: number,
y: number,
width: number,
height: number,
onChange: (x: number, y: number) => void,
}
export function OverlayHandle({x, y, width, height, onChange}: OverlayHandleProps) {
const onChangeRef = useRef<(xRatio: number, yRatio: number) => void>();
onChangeRef.current = useCallback((xRatio: number, yRatio: number) => {
onChange(xRatio * width, yRatio * height);
}, [width, height, onChange]);
const dragOver = useRef<Element>();
const onDragEnd = useCallback((e: React.DragEvent<HTMLDivElement>) => {
if (dragOver.current && dragOver.current.parentElement) {
dragOver.current.parentElement.removeChild(dragOver.current);
}
}, []);
const onDragStart = useCallback((e: React.DragEvent<HTMLDivElement>) => {
e.dataTransfer.setData('text/html', 'ok');
const overlay = e.currentTarget.closest('.App-overlay');
if (!overlay) {
return;
}
const div = document.createElement('div');
div.classList.add('Editor-handle-drop');
div.addEventListener('dragenter', (e2) => {
e2.preventDefault();
});
div.addEventListener('dragover', (e2) => {
e2.preventDefault();
const rect = div.getBoundingClientRect();
if (!onChangeRef.current) {
return;
}
onChangeRef.current((e2.pageX - rect.left) / rect.width, (e2.pageY - rect.top) / rect.height);
});
dragOver.current = div;
overlay.appendChild(div);
}, [width, height]);
if (!(0 <= x && x <= width && 0 <= y && y <= height)) {
return null;
}
return <div draggable={true} onDragStart={onDragStart} onDragEnd={onDragEnd} className="Editor-handle" style={{
left: `${100 * x / width}%`,
top: `${100 * y / height}%`,
}} />;
}
type SortableItemsProps<T extends {id: string}, P> = {
items: T[],
onChange: Action<T[]>,
Component: React.ComponentType<{item: T, onChange: Action<T>}>,
}
export function SortableItems<T extends {id: string}, P>({items, onChange, Component}: SortableItemsProps<T, P>) {
const [dragging, setDragging] = useState(false);
const onDropLast = useCallback((e: React.DragEvent<HTMLDivElement>) => {
e.preventDefault();
const itemId = e.dataTransfer.getData('text/plain');
onChange((previous) => {
const itemIndex = previous.findIndex((i) => i.id === itemId);
if (itemIndex < 0) {
return previous;
}
const copy = previous.slice();
copy.splice(itemIndex, 1);
copy.push(previous[itemIndex]);
return copy;
});
setDragging(false);
}, [onChange]);
const onDrop = useCallback((beforeId: string, e: React.DragEvent<HTMLDivElement>) => {
e.preventDefault();
const itemId = e.dataTransfer.getData('text/plain');
onChange((previous) => {
const itemIndex = previous.findIndex((i) => i.id === itemId);
const beforeIndex = previous.findIndex((i) => i.id === beforeId);
if (itemIndex < 0 || beforeIndex < 0) {
return previous;
}
const copy = previous.slice();
copy.splice(itemIndex, 1);
copy.splice(itemIndex < beforeIndex ? beforeIndex - 1 : beforeIndex, 0, previous[itemIndex]);
return copy;
});
setDragging(false);
}, [onChange]);
const onDropTrash = useCallback((e: React.DragEvent<HTMLDivElement>) => {
e.preventDefault();
const itemId = e.dataTransfer.getData('text/plain');
onChange((previous) => {
const itemIndex = previous.findIndex((i) => i.id === itemId);
if (itemIndex < 0) {
return previous;
}
const copy = items.slice();
copy.splice(itemIndex, 1);
return copy;
});
setDragging(false);
}, [onChange]);
const onItemChange = useCallback((id: string, action: (item: T) => T) => {
onChange((previous) => {
const index = previous.findIndex((i) => i.id === id);
if (index < 0) {
return previous;
}
return arrayWith(previous, index, action(previous[index]));
});
}, []);
return <div>
{items.map((item) => {
return <SortableItemRender<T, P>
key={item.id}
item={item}
dragging={dragging}
setDragging={setDragging}
onItemChange={onItemChange}
onDrop={onDrop}
Component={Component} />;
})}
{dragging && <SortableItemDrop onDrop={onDropLast} />}
{dragging && <SortableItemTrash onDrop={onDropTrash} />}
</div>;
}
type SortableItemRenderProps<T extends {id: string}, P> = {
item: T,
dragging: boolean,
setDragging: (dragging: boolean) => void,
onItemChange: (id: string, action: (previous: T) => T) => void,
onDrop: (beforeId: string, e: React.DragEvent<HTMLDivElement>) => void,
Component: React.ComponentType<{item: T, onChange: Action<T>}>,
}
function SortableItemRender<T extends {id: string}, P>({item, dragging, setDragging, onItemChange, onDrop, Component} : SortableItemRenderProps<T, P>) {
const onChange = useCallback(onItemChange.bind(null, item.id), [onItemChange, item.id]);
const onDropBefore = useCallback(onDrop.bind(null, item.id), [onDrop, item.id]);
const onDragStart = useCallback((e: React.DragEvent<HTMLDivElement>) => {
e.stopPropagation();
e.dataTransfer.setData('text/plain', item.id);
setDragging(true);
}, [setDragging]);
const onDragEnd = useCallback(() => {
setDragging(false);
}, [setDragging]);
return <Fragment key={item.id}>
{dragging && <SortableItemDrop onDrop={onDropBefore} />}
<div draggable={true} onDragStart={onDragStart} onDragEnd={onDragEnd}>
<Component item={item} onChange={onChange} />
</div>
</Fragment>;
}
function SortableItemDrop({onDrop}: {onDrop: (e: React.DragEvent<HTMLDivElement>) => void}) {
const [inside, setInside] = useState(false);
const onDragEnter = useCallback((e: React.DragEvent<HTMLDivElement>) => {
e.preventDefault();
setInside(true);
}, []);
const onDragOver = useCallback((e: React.DragEvent<HTMLDivElement>) => {
e.preventDefault();
}, []);
const onDragLeave = useCallback((e: React.DragEvent<HTMLDivElement>) => {
e.preventDefault();
setInside(false);
}, []);
return <div
onDragEnter={onDragEnter}
onDragOver={onDragOver}
onDragLeave={onDragLeave}
onDrop={onDrop}
className="Editor-sortable-item-drop"
style={{borderColor: `${inside ? 'green' : 'grey'}`}} />;
}
function SortableItemTrash({onDrop}: {onDrop: (e: React.DragEvent<HTMLDivElement>) => void}) {
const [inside, setInside] = useState(false);
const onDragEnter = useCallback((e: React.DragEvent<HTMLDivElement>) => {
e.preventDefault();
setInside(true);
}, []);
const onDragOver = useCallback((e: React.DragEvent<HTMLDivElement>) => {
e.preventDefault();
}, []);
const onDragLeave = useCallback((e: React.DragEvent<HTMLDivElement>) => {
e.preventDefault();
setInside(false);
}, []);
return <div
onDragEnter={onDragEnter}
onDragOver={onDragOver}
onDragLeave={onDragLeave}
onDrop={onDrop}
className="Editor-sortable-item-trash"
style={{borderColor: `${inside ? 'red' : 'grey'}`}} />;
}

565
src/Path.tsx Normal file
View File

@@ -0,0 +1,565 @@
import {useCallback, Fragment, useId} from 'react';
import {v4 as uuidv4} from 'uuid';
import {Editor, StringField, NumberField, OverlayHandle, Field, SortableItems} from './Editor';
import {arrayWith} from './array';
import type {SvgItem} from './App';
import type {Action} from './Editor';
type PathMoveTo = {
type: 'move-to',
id: string,
x: number,
y: number,
}
type PathLineTo = {
type: 'line-to',
id: string,
x: number,
y: number,
}
type PathCubicBezierTo = {
type: 'cubic-bezier-to',
id: string,
x1: number,
y1: number,
x2: number,
y2: number,
x: number,
y: number,
}
type PathItem = PathMoveTo | PathLineTo | PathCubicBezierTo;
export type Path = {
type: 'path',
id: string,
description: PathItem[],
stroke: string,
strokeWidth: number,
}
type PathRenderProps = {
path: Path,
}
export function PathRender({path}: PathRenderProps) {
const description = path.description.reduce((acc, item) => `${acc} ${getItemDescription(item)}`, '');
return <path
stroke={path.stroke}
strokeWidth={path.strokeWidth}
d={description}
fill="none" />
}
export function PathOverlaySVG({path}: PathRenderProps) {
// TODO no mutable in array.map() => reduce
let currentX: number | null = null;
let currentY: number | null = null;
return <Fragment>
{path.description.map((item) => {
if (item.type === 'move-to') {
currentX = item.x;
currentY = item.y;
return null;
} else if (item.type === 'line-to') {
if (typeof currentX === 'number' && typeof currentY === 'number') {
currentX = item.x;
currentY = item.y;
return null;
} else {
return null;
}
} else if (item.type === 'cubic-bezier-to') {
if (typeof currentX === 'number' && typeof currentY === 'number') {
const startX = currentX;
const startY = currentY;
currentX = item.x;
currentY = item.y;
return <Fragment key={item.id}>
<path
d={`M${startX} ${startY} L${item.x1} ${item.y1}`}
stroke="grey"
strokeWidth={path.strokeWidth}
strokeDasharray="2 1" />
<path
d={`M${item.x} ${item.y} L${item.x2} ${item.y2}`}
stroke="grey"
strokeWidth={path.strokeWidth}
strokeDasharray="2 1" />
</Fragment>;
} else {
return null;
}
} else {
const neverItem: never = item;
throw new Error(`Unhandled path item: ${JSON.stringify(neverItem)}`);
}
})}
</Fragment>;
}
export function normalizePath(path: any): Path | null {
if (!path) {
return null;
}
return {
type: 'path',
id: typeof path.id === 'string' ? path.id : uuidv4(),
description: Array.isArray(path.description) ? (path.description as any[]).flatMap((pathItem) => normalizePathItem(pathItem)) : [],
stroke: typeof path.stroke === 'string' ? path.stroke : 'black',
strokeWidth: typeof path.strokeWidth === 'number' ? path.strokeWidth : 0,
};
}
function normalizePathItem(rawItem: any): PathItem[] {
if (rawItem && rawItem.type === 'move-to') {
return [{
type: 'move-to',
id: typeof rawItem.id === 'string' ? rawItem.id : uuidv4(),
x: typeof rawItem.x === 'number' ? rawItem.x : 0,
y: typeof rawItem.y === 'number' ? rawItem.y : 0,
}];
} else if (rawItem && rawItem.type === 'line-to') {
return [{
type: 'line-to',
id: typeof rawItem.id === 'string' ? rawItem.id : uuidv4(),
x: typeof rawItem.x === 'number' ? rawItem.x : 0,
y: typeof rawItem.y === 'number' ? rawItem.y : 0,
}];
} else if (rawItem && rawItem.type === 'cubic-bezier-to') {
return [{
type: 'cubic-bezier-to',
id: typeof rawItem.id === 'string' ? rawItem.id : uuidv4(),
x1: typeof rawItem.x1 === 'number' ? rawItem.x1 : 0,
y1: typeof rawItem.y1 === 'number' ? rawItem.y1 : 0,
x2: typeof rawItem.x2 === 'number' ? rawItem.x2 : 0,
y2: typeof rawItem.y2 === 'number' ? rawItem.y2 : 0,
x: typeof rawItem.x === 'number' ? rawItem.x : 0,
y: typeof rawItem.y === 'number' ? rawItem.y : 0,
}];
} else {
return [];
}
}
type PathEditorProps = {
path: Path,
onChange: Action<SvgItem>,
}
export function PathEditor({path, onChange}: PathEditorProps) {
const descriptionId = useId();
const onDescriptionChange = useCallback((action: (items: PathItem[]) => PathItem[]) => {
onChange((item) => {
if (item.type !== 'path') {
return item;
}
return {
...item,
description: action(item.description),
};
});
}, [onChange]);
const onStrokeChange = useCallback((stroke: string) => {
onChange((item) => {
if (item.type !== 'path') {
return item;
}
return {
...item,
stroke,
};
});
}, [onChange]);
const onStrokeWidthChange = useCallback((strokeWidth: number) => {
onChange((item) => {
if (item.type !== 'path') {
return item;
}
return {
...item,
strokeWidth,
};
});
}, [onChange]);
const onAddMoveTo = useCallback(() => {
onChange((item) => {
if (item.type !== 'path') {
return item;
}
return {
...item,
description: item.description.concat({
type: 'move-to',
id: uuidv4(),
x: 0,
y: 0,
}),
};
});
}, [path, onChange]);
const onAddLineTo = useCallback(() => {
onChange((item) => {
if (item.type !== 'path') {
return item;
}
return {
...item,
description: item.description.concat({
type: 'line-to',
id: uuidv4(),
x: 0,
y: 0,
}),
};
});
}, [onChange]);
const onAddCubicBezierTo = useCallback(() => {
onChange((item) => {
if (item.type !== 'path') {
return item;
}
return {
...item,
description: item.description.concat({
type: 'cubic-bezier-to',
id: uuidv4(),
x1: 0,
y1: 0,
x2: 0,
y2: 0,
x: 0,
y: 0,
}),
};
});
}, [onChange]);
return <Editor tag="path">
<Field name="d" id={descriptionId}>
<SortableItems items={path.description} onChange={onDescriptionChange} Component={PathItemEditor} />
</Field>
<button onClick={onAddMoveTo}>Move to</button>
<button onClick={onAddLineTo}>Line to</button>
<button onClick={onAddCubicBezierTo}>Cubic Bezier to</button>
<StringField name="stroke" value={path.stroke} onChange={onStrokeChange} />
<NumberField name="stroke-width" value={path.strokeWidth} onChange={onStrokeWidthChange} step={0.1} />
</Editor>;
}
function PathItemEditor({item, onChange}: {item: PathItem, onChange: Action<PathItem>}) {
if (item.type === 'move-to') {
return <MoveToEditor moveTo={item} onChange={onChange} />;
} else if (item.type === 'line-to') {
return <LineToEditor lineTo={item} onChange={onChange} />;
} else if (item.type === 'cubic-bezier-to') {
return <CubicBezierToEditor cubicBezierTo={item} onChange={onChange} />;
} else {
const neverItem : never = item;
throw new Error(`Unhandled path item: ${JSON.stringify(neverItem)}`);
}
}
function MoveToEditor({moveTo, onChange}: {moveTo: PathMoveTo, onChange: Action<PathItem>}) {
const onXChange = useCallback((x: number) => {
onChange((item) => {
if (item.type !== 'move-to') {
return item;
}
return {
...item,
x,
};
});
}, [onChange]);
const onYChange = useCallback((y: number) => {
onChange((item) => {
if (item.type !== 'move-to') {
return item;
}
return {
...item,
y,
};
});
}, [onChange]);
return <div>
<div>M</div>
<NumberField name="x" value={moveTo.x} step={0.1} onChange={onXChange} />
<NumberField name="y" value={moveTo.y} step={0.1} onChange={onYChange} />
</div>;
}
function LineToEditor({lineTo, onChange}: {lineTo: PathLineTo, onChange: Action<PathItem>}) {
const onXChange = useCallback((x: number) => {
onChange((item) => {
if (item.type !== 'line-to') {
return item;
}
return {
...item,
x,
};
});
}, [onChange]);
const onYChange = useCallback((y: number) => {
onChange((item) => {
if (item.type !== 'line-to') {
return item;
}
return {
...item,
y,
};
});
}, [onChange]);
return <div>
<div>L</div>
<NumberField name="x" value={lineTo.x} step={0.1} onChange={onXChange} />
<NumberField name="y" value={lineTo.y} step={0.1} onChange={onYChange} />
</div>;
}
function CubicBezierToEditor({cubicBezierTo, onChange}: {cubicBezierTo: PathCubicBezierTo, onChange: Action<PathItem>}) {
const onX1Change = useCallback((x1: number) => {
onChange((item) => {
if (item.type !== 'cubic-bezier-to') {
return item;
}
return {
...item,
x1,
};
});
}, [onChange]);
const onY1Change = useCallback((y1: number) => {
onChange((item) => {
if (item.type !== 'cubic-bezier-to') {
return item;
}
return {
...item,
y1,
};
});
}, [onChange]);
const onX2Change = useCallback((x2: number) => {
onChange((item) => {
if (item.type !== 'cubic-bezier-to') {
return item;
}
return {
...item,
x2,
};
});
}, [onChange]);
const onY2Change = useCallback((y2: number) => {
onChange((item) => {
if (item.type !== 'cubic-bezier-to') {
return item;
}
return {
...item,
y2,
};
});
}, [onChange]);
const onXChange = useCallback((x: number) => {
onChange((item) => {
if (item.type !== 'cubic-bezier-to') {
return item;
}
return {
...item,
x,
};
});
}, [onChange]);
const onYChange = useCallback((y: number) => {
onChange((item) => {
if (item.type !== 'cubic-bezier-to') {
return item;
}
return {
...item,
y,
};
});
}, [onChange]);
return <div>
<div>C</div>
<NumberField name="x1" value={cubicBezierTo.x1} step={0.1} onChange={onX1Change} />
<NumberField name="y1" value={cubicBezierTo.y1} step={0.1} onChange={onY1Change} />
<NumberField name="x2" value={cubicBezierTo.x2} step={0.1} onChange={onX2Change} />
<NumberField name="y2" value={cubicBezierTo.y2} step={0.1} onChange={onY2Change} />
<NumberField name="x" value={cubicBezierTo.x} step={0.1} onChange={onXChange} />
<NumberField name="y" value={cubicBezierTo.y} step={0.1} onChange={onYChange} />
</div>;
}
type PathOverlayDOMProps = {
path: Path,
width: number,
height: number,
onChange: Action<SvgItem>,
}
export function PathOverlayDOM({path, onChange, width, height}: PathOverlayDOMProps) {
const onItemChange = useCallback((id: string, action: (item: PathItem) => PathItem) => {
onChange((previous) => {
if (previous.type !== 'path') {
return previous;
}
const index = previous.description.findIndex((d) => d.id === id);
if (index < 0) {
return previous;
}
return {
...previous,
description: arrayWith(previous.description, index, action(previous.description[index])),
};
});
}, []);
let initialized = false;
const overlays: React.ReactNode[] = [];
for (const item of path.description) {
if (item.type === 'move-to') {
initialized = true;
overlays.push(<MoveToOverlayDOM key={item.id} moveTo={item} onItemChange={onItemChange} width={width} height={height} />);
} else if (item.type === 'line-to') {
if (initialized) {
overlays.push(<LineToOverlayDOM key={item.id} lineTo={item} onItemChange={onItemChange} width={width} height={height} />);
}
} else if (item.type === 'cubic-bezier-to') {
if (initialized) {
overlays.push(<CubicBezierToOverlayDOM key={item.id} cubicBezierTo={item} onItemChange={onItemChange} width={width} height={height} />);
}
} else {
const neverItem : never = item;
throw new Error(`Unhandled path item: ${JSON.stringify(neverItem)}`);
}
}
return <Fragment>{overlays}</Fragment>;
}
type MoveToOverlayDOMProps = {
moveTo: PathMoveTo,
onItemChange: (id: string, action: (item: PathItem) => PathItem) => void,
width: number,
height: number,
};
function MoveToOverlayDOM({moveTo, width, height, onItemChange} : MoveToOverlayDOMProps) {
const onChange = useCallback((x: number, y: number) => {
onItemChange(moveTo.id, (previous) => {
if (previous.type !== 'move-to') {
return previous;
}
return {
...previous,
x,
y,
};
});
}, [onItemChange, moveTo.id]);
return <OverlayHandle x={moveTo.x} y={moveTo.y} width={width} height={height} onChange={onChange} />;
}
type LineToOverlayDOMProps = {
lineTo: PathLineTo,
onItemChange: (id: string, action: (item: PathItem) => PathItem) => void,
width: number,
height: number,
};
function LineToOverlayDOM({lineTo, width, height, onItemChange} : LineToOverlayDOMProps) {
const onChange = useCallback((x: number, y: number) => {
onItemChange(lineTo.id, (previous) => {
if (previous.type !== 'line-to') {
return previous;
}
return {
...previous,
x,
y,
};
});
}, [onItemChange, lineTo.id]);
return <OverlayHandle x={lineTo.x} y={lineTo.y} width={width} height={height} onChange={onChange} />;
}
type CubicBezierToOverlayDOMProps = {
cubicBezierTo: PathCubicBezierTo,
onItemChange: (id: string, action: (item: PathItem) => PathItem) => void,
width: number,
height: number,
};
function CubicBezierToOverlayDOM({cubicBezierTo, width, height, onItemChange} : CubicBezierToOverlayDOMProps) {
const onHandle1Change = useCallback((x1: number, y1: number) => {
onItemChange(cubicBezierTo.id, (previous) => {
if (previous.type !== 'cubic-bezier-to') {
return previous;
}
return {
...previous,
x1,
y1,
};
});
}, [onItemChange, cubicBezierTo.id]);
const onHandle2Change = useCallback((x2: number, y2: number) => {
onItemChange(cubicBezierTo.id, (previous) => {
if (previous.type !== 'cubic-bezier-to') {
return previous;
}
return {
...previous,
x2,
y2,
};
});
}, [onItemChange, cubicBezierTo.id]);
const onEndChange = useCallback((x: number, y: number) => {
onItemChange(cubicBezierTo.id, (previous) => {
if (previous.type !== 'cubic-bezier-to') {
return previous;
}
return {
...previous,
x,
y,
};
});
}, [onItemChange, cubicBezierTo.id]);
return <Fragment>
<OverlayHandle x={cubicBezierTo.x1} y={cubicBezierTo.y1} width={width} height={height} onChange={onHandle1Change} />
<OverlayHandle x={cubicBezierTo.x2} y={cubicBezierTo.y2} width={width} height={height} onChange={onHandle2Change} />
<OverlayHandle x={cubicBezierTo.x} y={cubicBezierTo.y} width={width} height={height} onChange={onEndChange} />
</Fragment>;
}
function getItemDescription(item: PathItem): string {
if (item.type === 'move-to') {
return `M${item.x} ${item.y}`;
} else if (item.type === 'line-to') {
return `L${item.x} ${item.y}`;
} else if (item.type === 'cubic-bezier-to') {
return `C${item.x1} ${item.y1} ${item.x2} ${item.y2} ${item.x} ${item.y}`;
} else {
const neverItem : never = item;
throw new Error(`Unhandled path item: ${JSON.stringify(neverItem)}`);
}
}

6
src/array.ts Normal file
View File

@@ -0,0 +1,6 @@
// https://github.com/tc39/proposal-change-array-by-copy
export function arrayWith<T>(array: T[], index: number, item: T): T[] {
const copy = array.slice();
copy[index] = item;
return copy;
}

15
src/favicon.svg Normal file
View File

@@ -0,0 +1,15 @@
<svg width="410" height="404" viewBox="0 0 410 404" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z" fill="url(#paint0_linear)"/>
<path d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z" fill="url(#paint1_linear)"/>
<defs>
<linearGradient id="paint0_linear" x1="6.00017" y1="32.9999" x2="235" y2="344" gradientUnits="userSpaceOnUse">
<stop stop-color="#41D1FF"/>
<stop offset="1" stop-color="#BD34FE"/>
</linearGradient>
<linearGradient id="paint1_linear" x1="194.651" y1="8.81818" x2="236.076" y2="292.989" gradientUnits="userSpaceOnUse">
<stop stop-color="#FFEA83"/>
<stop offset="0.0833333" stop-color="#FFDD35"/>
<stop offset="1" stop-color="#FFA800"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

13
src/index.css Normal file
View File

@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

7
src/logo.svg Normal file
View File

@@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3">
<g fill="#61DAFB">
<path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/>
<circle cx="420.9" cy="296.5" r="45.7"/>
<path d="M520.5 78.1z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

10
src/main.tsx Normal file
View File

@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import {App} from './App';
import './index.css';
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);

3
src/uuid.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
declare module 'uuid' {
export function v4(): string;
}

1
src/vite-env.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
/// <reference types="vite/client" />

21
tsconfig.json Normal file
View File

@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}

8
tsconfig.node.json Normal file
View File

@@ -0,0 +1,8 @@
{
"compilerOptions": {
"composite": true,
"module": "esnext",
"moduleResolution": "node"
},
"include": ["vite.config.ts"]
}

7
vite.config.ts Normal file
View File

@@ -0,0 +1,7 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()]
});