Skip to content

Commit 00bca69

Browse files
feat: Turtle.get/set_TextAnimation ( Fixes PoshWeb#171 )
1 parent a85522b commit 00bca69

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

Types/Turtle/get_TextAnimation.ps1

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

Types/Turtle/set_TextAnimation.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<#
2+
.SYNOPSIS
3+
Sets the Turtle Text Animation
4+
.DESCRIPTION
5+
Sets an animation for the Turtle path.
6+
.EXAMPLE
7+
turtle rotate 90 jump 50 rotate -90 forward 100 text 'Hello World' textAnimation ([Ordered]@{
8+
attributeName = 'fill' ; values = "#4488ff;#224488;#4488ff" ; repeatCount = 'indefinite'; dur = "4.2s"
9+
},[Ordered]@{
10+
attributeName = 'font-size' ; values = "1em;1.3em;1em" ; repeatCount = 'indefinite'; dur = "4.2s"
11+
}) save ./textAnimation.svg
12+
#>
13+
param(
14+
# The text animation object.
15+
# This may be a string containing animation XML, XML, or a dictionary containing animation settings.
16+
[PSObject]
17+
$TextAnimation
18+
)
19+
20+
$newAnimation = @(foreach ($animation in $TextAnimation) {
21+
if ($animation -is [Collections.IDictionary]) {
22+
$animationCopy = [Ordered]@{} + $animation
23+
if (-not $animationCopy['attributeType']) {
24+
$animationCopy['attributeType'] = 'XML'
25+
}
26+
if (-not $animationCopy['attributeName']) {
27+
$animationCopy['attributeName'] = 'transform'
28+
}
29+
if ($animationCopy.values -is [object[]]) {
30+
$animationCopy['values'] = $animationCopy['values'] -join ';'
31+
}
32+
33+
$elementName = 'animate'
34+
if ($animationCopy['attributeName'] -eq 'transform') {
35+
$elementName = 'animateTransform'
36+
}
37+
38+
39+
if (-not $animationCopy['dur'] -and $this.Duration) {
40+
$animationCopy['dur'] = "$($this.Duration.TotalSeconds)s"
41+
}
42+
43+
"<$elementName $(
44+
@(foreach ($key in $animationCopy.Keys) {
45+
" $key='$([Web.HttpUtility]::HtmlAttributeEncode($animationCopy[$key]))'"
46+
}) -join ''
47+
)/>"
48+
}
49+
if ($animation -is [string]) {
50+
$animation
51+
}
52+
if ($animation.OuterXml) {
53+
$animation.OuterXml
54+
}
55+
})
56+
57+
$this | Add-Member -MemberType NoteProperty -Force -Name '.TextAnimation' -Value $newAnimation

0 commit comments

Comments
 (0)