jpskill.com
🎨 デザイン コミュニティ

konva

Konvaまたはreact-konvaを用いて、描画ツール、画像エディタ、インタラクティブなグラフィック、ドラッグ&ドロップインターフェースなど、CanvasベースのUIを構築する際に、インタラクティブな2D Canvasアプリケーションを作成するSkill。

📜 元の英語説明(参考)

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.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Konvaまたはreact-konvaを用いて、描画ツール、画像エディタ、インタラクティブなグラフィック、ドラッグ&ドロップインターフェースなど、CanvasベースのUIを構築する際に、インタラクティブな2D Canvasアプリケーションを作成するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o konva.zip https://jpskill.com/download/15044.zip && unzip -o konva.zip && rm konva.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15044.zip -OutFile "$d\konva.zip"; Expand-Archive "$d\konva.zip" -DestinationPath $d -Force; ri "$d\konva.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して konva.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → konva フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Konva — 2D Canvas グラフィックスフレームワーク

概要

あなたは Konva のエキスパートです。Konva は、React でインタラクティブなグラフィックスアプリケーションを構築するための 2D canvas ライブラリです。あなたは、開発者がデザインエディタ、画像アノテーター、フローチャートビルダー、ドラッグアンドドロップ、変形、レイヤー、イベント処理を備えたインタラクティブな canvas を作成するのを支援します。これらはすべて、高いパフォーマンスのために HTML5 Canvas 上にレンダリングされます。

指示

React 統合 (react-konva)

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>
  );
}

画像アノテーション

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 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,
});

インストール

npm install konva react-konva

例 1: ユーザーが konva のセットアップを依頼

ユーザー: "プロジェクトのために konva をセットアップするのを手伝ってください"

エージェントは以下を行う必要があります:

  1. システム要件と前提条件を確認する
  2. konva をインストールまたは構成する
  3. 初期プロジェクト構造をセットアップする
  4. セットアップが正しく動作することを確認する

例 2: ユーザーが konva で機能を構築することを依頼

ユーザー: "konva を使用してダッシュボードを作成する"

エージェントは以下を行う必要があります:

  1. コンポーネントまたは構成をスキャフォールドする
  2. 適切なデータソースに接続する
  3. 要求された機能を実装する
  4. 出力をテストおよび検証する

ガイドライン

  1. React 向けの react-konva — 宣言的な canvas レンダリングには react-konva を使用します。React のコンポーネントモデルを Konva のシェイプにマッピングします。
  2. パフォーマンスのためのレイヤー — 静的なコンテンツ (背景、グリッド) とインタラクティブなコンテンツ (ドラッグ可能なシェイプ) を異なる <Layer> コンポーネントに分離します。
  3. 操作のための Transformer — リサイズ/回転ハンドルには <Transformer> を使用します。標準的なデザインツールインタラクションを提供します。
  4. ヒット検出 — Konva はピクセルパーフェクトなヒット検出を処理します。複雑なシェイプはクリックやホバーに正しく応答します。
  5. 大規模なシーンのための仮想 canvas — 無限の canvas エクスペリエンスのために、ステージのドラッグとズームを使用します。表示されているシェイプのみをレンダリングします。
  6. 2 倍でエクスポート — Retina ディスプレイ用にエクスポートする場合は pixelRatio: 2 を使用します。すべての画面で画像が鮮明に見えます。
  7. ステートによるアンドゥ/リドゥ — シェイプのステートを配列に格納します。ステート履歴をナビゲートして、アンドゥ/リドゥを実装します。
  8. パフォーマンス — Konva は Canvas 上で数千のシェイプを処理します。10K 以上のシェイプの場合は、静的な要素で listening: false を使用します。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

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)

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

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

// 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

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