Skip to content

Commit a79c861

Browse files
feat: Turtle.get/set_PathAnimation ( Fixes #117 )
1 parent 641f6f9 commit a79c861

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

Types/Turtle/get_PathAnimation.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if ($this.'.PathAnimation') {
2+
return $this.'.PathAnimation'
3+
}

Types/Turtle/get_PathElement.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
if ($this.StrokeWidth) { $this.StrokeWidth } else { '0.1%' }
66
)' fill='$($this.Fill)' class='$(
77
$this.PathClass -join ' '
8-
)' $(
8+
)' transform-origin='50% 50%' $(
99
foreach ($pathAttributeName in $this.PathAttribute.Keys) {
1010
" $pathAttributeName='$($this.PathAttribute[$pathAttributeName])'"
1111
}
12-
) />"
12+
)>"
13+
if ($this.PathAnimation) {$this.PathAnimation}
14+
"</path>"
1315
) -as [xml]

Types/Turtle/set_PathAnimation.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
param(
2+
[PSObject]
3+
$PathAnimation
4+
)
5+
6+
$newAnimation = @(foreach ($animation in $PathAnimation) {
7+
if ($animation -is [Collections.IDictionary]) {
8+
$animationCopy = [Ordered]@{} + $animation
9+
if (-not $animationCopy['attributeType']) {
10+
$animationCopy['attributeType'] = 'XML'
11+
}
12+
if (-not $animationCopy['attributeName']) {
13+
$animationCopy['attributeName'] = 'transform'
14+
}
15+
if ($animationCopy.values -is [object[]]) {
16+
$animationCopy['values'] = $animationCopy['values'] -join ';'
17+
}
18+
19+
$elementName = 'animate'
20+
if ($animationCopy['attributeName'] -eq 'transform') {
21+
$elementName = 'animateTransform'
22+
}
23+
24+
"<$elementName $(
25+
@(foreach ($key in $animationCopy.Keys) {
26+
" $key='$([Web.HttpUtility]::HtmlAttributeEncode($animationCopy[$key]))'"
27+
}) -join ''
28+
)/>"
29+
}
30+
if ($animation -is [string]) {
31+
$animation
32+
}
33+
})
34+
35+
$this | Add-Member -MemberType NoteProperty -Force -Name '.PathAnimation' -Value $newAnimation

0 commit comments

Comments
 (0)