Skip to content

Commit f97ece7

Browse files
committed
feat: sprite editor svg support
1 parent 6155f80 commit f97ece7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/pages/apps/SpriteEditorPage.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,31 @@ const SpriteEditorPage = () => {
163163
link.click();
164164
};
165165

166+
const exportSvg = () => {
167+
const svgString = `
168+
<svg width="${gridSize}" height="${gridSize}" viewBox="0 0 ${gridSize} ${gridSize}" xmlns="http://www.w3.org/2000/svg">
169+
${pixels.map((color, i) => {
170+
if (color) {
171+
const x = i % gridSize;
172+
const y = Math.floor(i / gridSize);
173+
return `<rect x="${x}" y="${y}" width="1" height="1" fill="${color}" />`;
174+
}
175+
return '';
176+
}).join('')}
177+
</svg>
178+
`;
179+
180+
const blob = new Blob([svgString], { type: 'image/svg+xml' });
181+
const url = URL.createObjectURL(blob);
182+
const link = document.createElement('a');
183+
link.href = url;
184+
link.download = `sprite.svg`;
185+
document.body.appendChild(link);
186+
link.click();
187+
document.body.removeChild(link);
188+
URL.revokeObjectURL(url);
189+
};
190+
166191
return (
167192
<div
168193
className={`min-h-screen ${currentTheme.pageBg} ${currentTheme.pageText} font-mono selection:bg-[#ff004d] selection:text-white pb-12`}>
@@ -289,6 +314,10 @@ const SpriteEditorPage = () => {
289314
className="flex items-center justify-center gap-2 bg-[#008751] text-white py-2 px-4 rounded text-xs font-bold uppercase hover:bg-[#00a060] transition-colors border-b-4 border-[#005f38] active:border-b-0 active:translate-y-1">
290315
<DownloadSimple weight="bold"/> PNG (2x)
291316
</button>
317+
<button onClick={exportSvg}
318+
className="flex items-center justify-center gap-2 bg-[#008751] text-white py-2 px-4 rounded text-xs font-bold uppercase hover:bg-[#00a060] transition-colors border-b-4 border-[#005f38] active:border-b-0 active:translate-y-1">
319+
<DownloadSimple weight="bold"/> SVG
320+
</button>
292321
</div>
293322
</div>
294323
</div>

0 commit comments

Comments
 (0)