konva
Build interactive 2D canvas applications with Konva. Use when a user asks to create drawing tools, image editors, interactive graphics, drag-and-drop interfaces, or canvas-based UIs using Konva or react-konva.
What this skill does
# Konva — 2D Canvas Graphics Framework
## Overview
You are an expert in Konva, the 2D canvas library for building interactive graphics applications with React. You help developers create design editors, image annotators, flowchart builders, and interactive canvases with drag-and-drop, transformations, layering, and event handling — all rendered on HTML5 Canvas for high performance.
## Instructions
### React Integration (react-konva)
```tsx
import { Stage, Layer, Rect, Circle, Text, Image, Transformer, Group } from "react-konva";
import { useState, useRef } from "react";
function DesignEditor() {
const [shapes, setShapes] = useState([
{ id: "1", type: "rect", x: 50, y: 50, width: 200, height: 100, fill: "#4f46e5" },
{ id: "2", type: "circle", x: 400, y: 150, radius: 60, fill: "#22c55e" },
{ id: "3", type: "text", x: 100, y: 200, text: "Hello World", fontSize: 24, fill: "#000" },
]);
const [selectedId, setSelectedId] = useState(null);
const transformerRef = useRef(null);
const handleDragEnd = (id, e) => {
setShapes(shapes.map(s =>
s.id === id ? { ...s, x: e.target.x(), y: e.target.y() } : s
));
};
return (
<Stage width={800} height={600} onMouseDown={(e) => {
// Deselect when clicking on empty area
if (e.target === e.target.getStage()) setSelectedId(null);
}}>
<Layer>
{shapes.map((shape) => {
const Component = shape.type === "rect" ? Rect
: shape.type === "circle" ? Circle : Text;
return (
<Component
key={shape.id}
{...shape}
draggable
onClick={() => setSelectedId(shape.id)}
onDragEnd={(e) => handleDragEnd(shape.id, e)}
/>
);
})}
{/* Transformer for resize/rotate */}
{selectedId && (
<Transformer
ref={transformerRef}
boundBoxFunc={(oldBox, newBox) => {
// Limit minimum size
if (newBox.width < 20 || newBox.height < 20) return oldBox;
return newBox;
}}
/>
)}
</Layer>
</Stage>
);
}
```
### Image Annotation
```tsx
function ImageAnnotator({ imageUrl }) {
const [annotations, setAnnotations] = useState([]);
const [isDrawing, setIsDrawing] = useState(false);
const [newRect, setNewRect] = useState(null);
const handleMouseDown = (e) => {
const pos = e.target.getStage().getPointerPosition();
setIsDrawing(true);
setNewRect({ x: pos.x, y: pos.y, width: 0, height: 0, id: Date.now().toString() });
};
const handleMouseMove = (e) => {
if (!isDrawing || !newRect) return;
const pos = e.target.getStage().getPointerPosition();
setNewRect({
...newRect,
width: pos.x - newRect.x,
height: pos.y - newRect.y,
});
};
const handleMouseUp = () => {
if (newRect && Math.abs(newRect.width) > 10) {
setAnnotations([...annotations, { ...newRect, label: "New Label" }]);
}
setIsDrawing(false);
setNewRect(null);
};
return (
<Stage width={800} height={600}
onMouseDown={handleMouseDown}
onMouseMove={handleMouseMove}
onMouseUp={handleMouseUp}>
<Layer>
<KonvaImage image={loadedImage} />
{annotations.map((ann) => (
<Group key={ann.id}>
<Rect {...ann} stroke="#ef4444" strokeWidth={2} fill="rgba(239,68,68,0.1)" />
<Text x={ann.x} y={ann.y - 20} text={ann.label} fill="#ef4444" fontSize={14} />
</Group>
))}
{newRect && <Rect {...newRect} stroke="#4f46e5" strokeWidth={2} dash={[5, 5]} />}
</Layer>
</Stage>
);
}
```
### Export
```typescript
// Export canvas as image
const stage = stageRef.current;
const dataUrl = stage.toDataURL({ pixelRatio: 2 }); // 2x for retina
// Export as blob for upload
stage.toBlob({
callback: (blob) => {
const formData = new FormData();
formData.append("image", blob, "design.png");
fetch("/api/upload", { method: "POST", body: formData });
},
pixelRatio: 2,
});
```
## Installation
```bash
npm install konva react-konva
```
## Examples
**Example 1: User asks to set up konva**
User: "Help me set up konva for my project"
The agent should:
1. Check system requirements and prerequisites
2. Install or configure konva
3. Set up initial project structure
4. Verify the setup works correctly
**Example 2: User asks to build a feature with konva**
User: "Create a dashboard using konva"
The agent should:
1. Scaffold the component or configuration
2. Connect to the appropriate data source
3. Implement the requested feature
4. Test and validate the output
## Guidelines
1. **react-konva for React** — Use `react-konva` for declarative canvas rendering; maps React's component model to Konva shapes
2. **Layers for performance** — Separate static content (background, grid) from interactive content (draggable shapes) into different `<Layer>` components
3. **Transformer for manipulation** — Use `<Transformer>` for resize/rotate handles; it provides standard design tool interactions
4. **Hit detection** — Konva handles pixel-perfect hit detection; complex shapes respond correctly to clicks and hovers
5. **Virtual canvas for large scenes** — Use stage dragging and zooming for infinite canvas experiences; only render visible shapes
6. **Export at 2x** — Use `pixelRatio: 2` when exporting for retina displays; images look crisp on all screens
7. **Undo/redo with state** — Store shape state in an array; implement undo/redo by navigating the state history
8. **Performance** — Konva handles thousands of shapes on Canvas; for 10K+ shapes, use `listening: false` on static elements
Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.