<svg id="svg" width="800" height="600">
<image xlink:href="./2.jpg" width="100%" height="100%" />
</svg>
import pictureNote from 'picture-note'
// 其中的🚀noteData🚀和🚀save🚀的类型具体看下面的🚀types🚀
pictureNote.init({
svg: document.getElementById('svg'), // SVG element
noteData?: NoteData[] | (() => NoteData[]), // 回填数据
// 创建、移动、修改大小和文本框失焦后会触发保存;触发保存后会执行传入的回调
save?: (data: NoteData[], type: DrawingMode) => void,
})
// 数据公共部分
type CommonNoteData = {
id: string,
x: number,
y: number,
width?: number,
height?: number,
color?: string,
size?: number | string,
}
// 线框的点
type CircleType = 't' | 'r' | 'b' | 'l' | 'tl' | 'tr' | 'bl' | 'br'
type Circles = {
pid: string,
type: CircleType,
cx: number,
cy: number,
r: number,
fill: string
}
// 线框
type RectType = CommonNoteData & {
type: 'select',
circles: Circles[]
}
// 画笔
type PathType = CommonNoteData & {
type: 'pen',
d: string,
}
// 文本
type TextType = CommonNoteData & {
type: 'text',
text: string,
}
// 批注的数据
type NoteData = RectType | PathType | TextType
// 画笔、文本、矩形框、空
type DrawingMode = 'pen' | 'text' | 'select' | ''
type Props = {
svg: SVGElement, // SVG element
noteData?: NoteData[] | (() => NoteData[]), // 回填数据
save?: (data: NoteData[], type: DrawingMode) => void, // 创建、移动、修改大小和文本框失焦后会触发保存;触发保存后会执行传入的回调
}
// 删除
type DeleteData = {
data: NoteData;
type: DrawingMode;
}
// 设置模式
type SetDrawingMode = (data: DrawingMode) => void
// 删除
type RemoveChild = () => DeleteData
// 设置颜色
type SetColor = (color: string) => void
// 设置尺寸
type SetSize = (size: number | string) => void
// 重载
type Reload = (data: NoteData[] | (() => NoteData[])) => void
// 初始化
type init = (props: Props) => void
// 卸载
type Distory = () => void