jobsidian/model.go
Evgenii Stratonikov 3fdaad8e86
initial commit
Signed-off-by: Evgenii Stratonikov <stratonikov@runbox.com>
2024-10-28 14:02:04 +03:00

75 lines
1.7 KiB
Go

package main
import "fmt"
// Canvas represents obsidian canvas.
// The format is described at https://jsoncanvas.org/.
type Canvas struct {
Nodes []Node `json:"nodes,omitempty"`
Edges []Edge `json:"edges,omitempty"`
}
// NodeType represents type type of a canvas node.
type NodeType string
// Presets for NodeType.
const (
Text NodeType = "text"
File NodeType = "file"
Link NodeType = "link"
Group NodeType = "group"
)
// Color represents item color.
type Color string
// Preset colors.
const (
Red = "1"
Orange = "2"
Yellow = "3"
Green = "4"
Cyan = "5"
Purple = "6"
)
// RGB builds custom Color from RGB representation.
func RGB(r, g, b int) Color {
return Color(fmt.Sprintf("#%02X%02X%02X", r, g, b))
}
// Node represents a basic building block, containing text.
type Node struct {
ID string `json:"id"`
Type NodeType `json:"type"`
X int `json:"x"`
Y int `json:"y"`
Width int `json:"width"`
Height int `json:"height"`
Color Color `json:"color,omitempty"`
// Text type.
Text string `json:"text"`
// File type.
File string `json:"file"`
Subpath string `json:"subpath,omitempty"`
// Link type.
URL string `json:"url"`
// Group type.
Label string `json:"label,omitempty"`
Background string `json:"background,omitempty"`
BackgroundStyle string `json:"backgroundStyle,omitempty"`
}
// Edge represents an edge between two nodes.
type Edge struct {
ID string `json:"id"`
FromNode string `json:"fromNode"`
FromSide string `json:"fromSide"`
FromEnd string `json:"fromEnd,omitempty"`
ToNode string `json:"toNode"`
ToSide string `json:"toSide"`
ToEnd string `json:"toEnd,omitempty"`
Color Color `json:"color,omitempty"`
Label string `json:"label,omitempty"`
}