Claude Code के साथ SVG
Claude Code का उपयोग करके svg सीखें। Practical tips और code examples शामिल हैं।
SVGの操作とoptimizationको Claude Code से Efficient बनाना
SVGはicon、イラスト、グラフ आदि幅広い用途で使われるベクター形式 है।Claude Code का उपयोग करके、SVGのgenerate、操作、optimizationを素早くimplementationでき है।
SVGiconシステムのbuild
> 再利用possibleなSVGiconcomponentをबनाओ。
> size、色、accessibilityにsupportして。
// components/Icon.tsx
interface IconProps {
name: string;
size?: number;
color?: string;
className?: string;
label?: string;
}
const icons: Record<string, string> = {
search: 'M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z',
menu: 'M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5',
close: 'M6 18L18 6M6 6l12 12',
arrow: 'M8.25 4.5l7.5 7.5-7.5 7.5',
check: 'M4.5 12.75l6 6 9-13.5',
};
export function Icon({ name, size = 24, color = 'currentColor', className, label }: IconProps) {
const path = icons[name];
if (!path) return null;
return (
<svg
width={size}
height={size}
viewBox="0 0 24 24"
fill="none"
stroke={color}
strokeWidth={2}
strokeLinecap="round"
strokeLinejoin="round"
className={className}
role={label ? 'img' : 'presentation'}
aria-label={label}
aria-hidden={!label}
>
<path d={path} />
</svg>
);
}
SVGスプlightのimplementation
// components/SvgSprite.tsx
export function SvgSprite() {
return (
<svg xmlns="http://www.w3.org/2000/svg" style={{ display: 'none' }}>
<symbol id="icon-home" viewBox="0 0 24 24">
<path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z" />
</symbol>
<symbol id="icon-mail" viewBox="0 0 24 24">
<path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z" />
<polyline points="22,6 12,13 2,6" />
</symbol>
</svg>
);
}
// 使用方法
function NavIcon({ icon, label }: { icon: string; label: string }) {
return (
<svg width="24" height="24" aria-label={label}>
<use href={`#icon-${icon}`} />
</svg>
);
}
SVGanimation
<!-- ローディングスピナー -->
<svg width="48" height="48" viewBox="0 0 48 48">
<circle cx="24" cy="24" r="20" fill="none" stroke="#e5e7eb" stroke-width="4" />
<circle cx="24" cy="24" r="20" fill="none" stroke="#3b82f6" stroke-width="4"
stroke-dasharray="80 45"
stroke-linecap="round">
<animateTransform
attributeName="transform"
type="rotate"
from="0 24 24"
to="360 24 24"
dur="1s"
repeatCount="indefinite" />
</circle>
</svg>
/* CSSによるSVGanimation */
.svg-draw path {
stroke-dasharray: 1000;
stroke-dashoffset: 1000;
animation: draw 2s ease forwards;
}
@keyframes draw {
to { stroke-dashoffset: 0; }
}
/* ホバーでicon変化 */
.icon-hover {
transition: transform 0.2s ease, color 0.2s ease;
}
.icon-hover:hover {
transform: scale(1.1);
color: var(--color-accent);
}
JavaScriptによるSVGgenerate
// 動的にSVGチャート generate
function createBarChart(data: { label: string; value: number }[]): string {
const width = 400;
const height = 200;
const barWidth = width / data.length - 10;
const maxValue = Math.max(...data.map(d => d.value));
const bars = data.map((d, i) => {
const barHeight = (d.value / maxValue) * (height - 40);
const x = i * (barWidth + 10) + 5;
const y = height - barHeight - 20;
return `
<rect x="${x}" y="${y}" width="${barWidth}" height="${barHeight}"
fill="#3b82f6" rx="4" />
<text x="${x + barWidth / 2}" y="${height - 5}"
text-anchor="middle" font-size="11">${d.label}</text>
`;
}).join('');
return `<svg viewBox="0 0 ${width} ${height}" xmlns="http://www.w3.org/2000/svg">
${bars}
</svg>`;
}
SVGのoptimization
> SVGfileをoptimizationするスクリプトをबनाओ。
> 不要な属性やメタdata deleteして、filesizeを削減して。
// scripts/optimize-svg.ts
import { optimize } from 'svgo';
import { readFileSync, writeFileSync } from 'fs';
import { globSync } from 'glob';
const svgFiles = globSync('src/assets/icons/**/*.svg');
for (const file of svgFiles) {
const svg = readFileSync(file, 'utf-8');
const result = optimize(svg, {
plugins: [
'preset-default',
'removeDimensions',
{ name: 'removeAttrs', params: { attrs: ['data-name', 'class'] } },
{ name: 'addAttributesToSVGElement', params: {
attributes: [{ 'aria-hidden': 'true' }]
}},
],
});
writeFileSync(file, result.data);
const savings = ((1 - result.data.length / svg.length) * 100).toFixed(1);
console.log(`${file}: ${savings}% 削減`);
}
accessibility
// 装飾的SVG
<svg aria-hidden="true" focusable="false">...</svg>
// 意味のあるSVG
<svg role="img" aria-label="searchicon">
<title>search</title>
...
</svg>
// link内SVG
<a href="/search" aria-label="searchpageへ">
<svg aria-hidden="true" focusable="false">...</svg>
</a>
Summary
SVGの操作とoptimizationは、performanceとuser体験の両面でimportant है।Claude Code का उपयोग करके、iconシステムのbuild सेSVGOoptimizationスクリプト तक、一貫したimplementationをefficiently進められ है।CSSanimation के साथ combineる बातで、リッチなビジュアル表現も実現でき है।SVGの仕様はW3C SVG Specificationをदेखें。
मुफ़्त PDF: 5 मिनट में Claude Code चीटशीट
बस अपना ईमेल दर्ज करें और हम तुरंत A4 एक-पृष्ठ चीटशीट PDF भेज देंगे।
हम आपकी व्यक्तिगत जानकारी की सुरक्षा करते हैं और स्पैम नहीं भेजते।
लेखक के बारे में
Masa
Claude Code का गहराई से उपयोग करने वाले इंजीनियर। claudecode-lab.com चलाते हैं, जो 10 भाषाओं में 2,000 से अधिक पेजों वाला टेक मीडिया है।
संबंधित लेख
Claude Code ke liye 7 CLAUDE.md templates jo aap real projects me copy kar sakte hain
Solo app, content site, API, team repo aur legacy codebase ke liye 7 practical CLAUDE.md templates, plus common failure cases.
Claude Code Approval aur Sandbox Guide | Roz ke kaam ke liye safe settings
Claude Code me allow, ask, deny aur sandbox ko kaise baantna chahiye - practical settings, hooks aur real workflow examples ke saath.
Claude Code की सम्पूर्ण शुरुआती गाइड 2026 | शून्य से प्रोफेशनल उपयोग तक 7 स्टेप्स में
पहली बार Claude Code उपयोग करने वालों के लिए पूरी गाइड। इंस्टॉलेशन से लेकर असली डेवलपमेंट वर्कफ्लो में शामिल करने तक — Masa के शुरुआती अनुभव के आधार पर।