d2/d2cli/export.go

39 lines
749 B
Go
Raw Normal View History

2023-04-13 13:54:26 +00:00
package d2cli
2023-04-13 21:50:39 +00:00
import (
"path/filepath"
)
2023-04-13 13:54:26 +00:00
type exportExtension string
2023-04-13 21:50:39 +00:00
const GIF = ".gif"
const PNG = ".png"
const PPTX = ".pptx"
const PDF = ".pdf"
const SVG = ".svg"
var KNOWN_EXTENSIONS = []string{SVG, PNG, PDF, PPTX, GIF}
2023-04-13 13:54:26 +00:00
func getExportExtension(outputPath string) exportExtension {
ext := filepath.Ext(outputPath)
for _, kext := range KNOWN_EXTENSIONS {
if kext == ext {
return exportExtension(ext)
}
}
// default is svg
2023-04-13 21:50:39 +00:00
return exportExtension(SVG)
2023-04-13 13:54:26 +00:00
}
func (ex exportExtension) supportsAnimation() bool {
2023-04-13 21:50:39 +00:00
return ex == SVG || ex == GIF
2023-04-13 13:54:26 +00:00
}
2023-04-13 21:50:39 +00:00
func (ex exportExtension) requiresPNGRenderer() bool {
return ex == PNG || ex == PDF || ex == PPTX || ex == GIF
2023-04-13 13:54:26 +00:00
}
func (ex exportExtension) supportsDarkTheme() bool {
2023-04-13 21:50:39 +00:00
return ex == SVG
2023-04-13 13:54:26 +00:00
}