d2/d2cli/export.go

47 lines
1.1 KiB
Go
Raw Normal View History

2023-04-13 13:54:26 +00:00
package d2cli
2023-04-13 21:50:39 +00:00
import (
2023-04-14 22:44:01 +00:00
"fmt"
2023-04-13 21:50:39 +00:00
"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"
const PDF exportExtension = ".pdf"
const SVG exportExtension = ".svg"
2023-04-13 21:50:39 +00:00
2023-04-14 22:44:01 +00:00
var SUPPORTED_EXTENSIONS = []exportExtension{SVG, PNG, PDF, PPTX, GIF}
2023-04-13 13:54:26 +00:00
2023-04-14 22:44:01 +00:00
func getExportExtension(outputPath string) (exportExtension, error) {
2023-04-13 13:54:26 +00:00
ext := filepath.Ext(outputPath)
2023-04-14 22:44:01 +00:00
if ext == ".ppt" {
return "", fmt.Errorf("D2 does not support ppt exports, did you mean \"pptx\"?")
}
for _, kext := range SUPPORTED_EXTENSIONS {
if kext == exportExtension(ext) {
return exportExtension(ext), nil
2023-04-13 13:54:26 +00:00
}
}
// default is svg
2023-04-14 22:44:01 +00:00
return exportExtension(SVG), nil
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
}