Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- exports: pptx follows standards more closely, addressing warnings from some Powerpoint software [#2645](https://github.com/terrastruct/d2/pull/2645)
- d2sequence: fix edge case of invalid sequence diagrams [#2660](https://github.com/terrastruct/d2/pull/2660)
- d2svg: Text may overflow legend bounds when monospace font is used [#2674](https://github.com/terrastruct/d2/pull/2674)
- d2svg: animated connections honor reduced motion preferences [#2778](https://github.com/terrastruct/d2/pull/2778)

---

Expand Down
6 changes: 6 additions & 0 deletions d2renderers/d2sketch/testdata/animated/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions d2renderers/d2sketch/testdata/animated_dark/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions d2renderers/d2svg/d2svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,12 @@ func EmbedFonts(buf *bytes.Buffer, diagramHash, source string, fontFamily *d2fon
stroke-dashoffset: 0;
}
}

@media (prefers-reduced-motion: reduce) {
.animated-connection {
animation: none !important;
}
}
`,
)

Expand Down
24 changes: 24 additions & 0 deletions d2renderers/d2svg/d2svg_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
package d2svg

import (
"bytes"
"strings"
"testing"

"oss.terrastruct.com/d2/d2renderers/d2fonts"
"oss.terrastruct.com/d2/d2target"
)

func TestEmbedFontsReducedMotion(t *testing.T) {
var buf bytes.Buffer
fontFamily := d2fonts.SourceSansPro
monoFontFamily := d2fonts.SourceCodePro
EmbedFonts(&buf, "diagram", `<path class="animated-connection" />`, &fontFamily, &monoFontFamily, "")

css := buf.String()
if !strings.Contains(css, "@media (prefers-reduced-motion: reduce)") {
t.Fatal("animated connections should honor the reduced-motion preference")
}
if !strings.Contains(css, "animation: none !important;") {
t.Fatal("reduced-motion rule should override the inline connection animation")
}

buf.Reset()
EmbedFonts(&buf, "diagram", `<path class="connection" />`, &fontFamily, &monoFontFamily, "")
if strings.Contains(buf.String(), "prefers-reduced-motion") {
t.Fatal("static diagrams should not include the reduced-motion rule")
}
}

func TestSortObjects(t *testing.T) {
allObjects := []DiagramObject{
// same zIndex and level, should keep in this order
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions e2etests/testdata/stable/animated/dagre/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions e2etests/testdata/stable/animated/elk/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions e2etests/testdata/txtar/md-tables/dagre/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions e2etests/testdata/txtar/md-tables/elk/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.