konva
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "konva":https://skillpi.com/zh/skills/deepskill-d7a5ee76945b4f627a95a4daf22aa3036729db2ff88b2486628c3afc16254241。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
使用 Konva 构建交互式 2D 画布应用:适用于创建绘图工具、图像编辑器、交互式图形、拖放界面或基于画布的用户界面,且使用 Konva 或 react-konva 的场景。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 实测状态
- 未测试
文件浏览
Frontmatter
name: konva
description: >-
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.
license: Apache-2.0
compatibility: "No special requirements"
metadata:
author: terminal-skills
version: "1.0.0"
category: data-ai
tags: ["canvas", "2d", "graphics", "interactive", "react"]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:
- Check system requirements and prerequisites
- Install or configure konva
- Set up initial project structure
- Verify the setup works correctly
Example 2: User asks to build a feature with konva
User: "Create a dashboard using konva"
The agent should:
- Scaffold the component or configuration
- Connect to the appropriate data source
- Implement the requested feature
- Test and validate the output
Guidelines
- react-konva for React — Use
react-konvafor declarative canvas rendering; maps React's component model to Konva shapes - Layers for performance — Separate static content (background, grid) from interactive content (draggable shapes) into different
<Layer>components - Transformer for manipulation — Use
<Transformer>for resize/rotate handles; it provides standard design tool interactions - Hit detection — Konva handles pixel-perfect hit detection; complex shapes respond correctly to clicks and hovers
- Virtual canvas for large scenes — Use stage dragging and zooming for infinite canvas experiences; only render visible shapes
- Export at 2x — Use
pixelRatio: 2when exporting for retina displays; images look crisp on all screens - Undo/redo with state — Store shape state in an array; implement undo/redo by navigating the state history
- Performance — Konva handles thousands of shapes on Canvas; for 10K+ shapes, use
listening: falseon static elements
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供完整的 Konva 和 react-konva 使用指南,涵盖设计编辑器、图像标注、导出等核心功能
- 包含多个端到端代码示例,可直接用于实际项目开发
- 针对性能优化、交互设计等提供了专业建议
亮点
- 触发词精准覆盖绘图工具、图像编辑器、交互式图形等核心场景
- 明确指定了使用 Konva 或 react-konva 的技术栈要求
- 边界清晰,不易与其他 Skill 混淆
亮点
- 文档结构清晰,包含 Overview、Instructions、Installation、Examples、Guidelines 等完整部分
- frontmatter 信息齐全,包含 name、description、license、compatibility、metadata 等
- 代码示例完整且可直接运行
亮点
- 工具来源明确(npm install konva react-konva)
- 参数使用正确,如 pixelRatio: 2 用于高清导出
- 提供了性能优化建议,如使用 listening: false 处理大量静态元素
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 153 行
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。