d2/d2cli/export.go

44 lines
985 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-14 22:44:01 +00:00
const GIF exportExtension = ".gif"
const PNG exportExtension = ".png"
const PPTX exportExtension = ".pptx"
2023-04-17 13:15:52 +00:00
const PPT exportExtension = ".ppt"
2023-04-14 22:44:01 +00:00
const PDF exportExtension = ".pdf"
const SVG exportExtension = ".svg"
2023-04-13 21:50:39 +00:00
2023-04-17 13:15:52 +00:00
var SUPPORTED_EXTENSIONS = []exportExtension{SVG, PNG, PDF, PPTX, GIF, PPT}
2023-04-13 13:54:26 +00:00
2023-04-17 13:15:52 +00:00
func getExportExtension(outputPath string) exportExtension {
2023-04-13 13:54:26 +00:00
ext := filepath.Ext(outputPath)
2023-04-14 22:44:01 +00:00
for _, kext := range SUPPORTED_EXTENSIONS {
if kext == exportExtension(ext) {
2023-04-17 13:15:52 +00:00
return exportExtension(ext)
2023-04-13 13:54:26 +00:00
}
}
// default is svg
2023-04-17 13:15:52 +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-14 22:44:01 +00:00
func (ex exportExtension) requiresAnimationInterval() bool {
return ex == GIF
}
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
}