Skip to content

Commit aa2b57e

Browse files
Merge pull request #29 from StartAutomating/PSSVG-Updates
Pssvg updates
2 parents 8d33599 + ccce145 commit aa2b57e

File tree

210 files changed

+27973
-2357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+27973
-2357
lines changed

Assets/PSSVG.svg

Lines changed: 1 addition & 0 deletions
Loading

Build.PSSVG.ps1 renamed to Build_PSSVG.ps1

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
.SYNOPSIS
77
Generates PSSVG
88
.DESCRIPTION
9-
Generates PSSVG, a module for creating 2d images with PowerShell.
9+
Generates PSSVG, a module for creating svg images with PowerShell.
1010
1111
PSSVG allows you to create Scalable Vector Graphics using PowerShell commands.
1212
@@ -72,13 +72,17 @@ if (-not $svgElements) {
7272

7373
$findSvgElement = [Regex]::new("\{\{SVGElement\(['`"](?<e>[^'`"]+)")
7474
$findSvgAttr = [Regex]::new("\{\{SVGAttr\(['`"](?<a>[^'`"]+)")
75+
$replaceMDNContent = "\{\{\s{0,}(?>$(@('Glossary', 'cssxref', 'domxref', 'HTTPMethod', 'htmlelement','svgelement', 'svgattr','htmlattrxref','cssxref') -join '|')[^\)]{0,})\(" +
76+
'["''](?<s>[^"'']+)["'']\)\s{0,}\}\}'
77+
7578

7679
function ConvertSVGMetadataToParameterAttribute {
7780
param([Parameter(ValueFromPipeline,Position=0)][string]$EdiValue)
7881
$hadNumbers = $false
7982
$hadUri = $false
8083
$hadColor = $false
8184
$hadUnknown = $false
85+
$tabCompletionRedundant = $false
8286
if ($ediValue -notmatch '\|') {
8387
if ($ediValue -match '\<(?<t>[^\>])>') {
8488
if ($matches.t -as [type]) {
@@ -87,7 +91,8 @@ function ConvertSVGMetadataToParameterAttribute {
8791
}
8892
return
8993
}
90-
$validSet = @(foreach ($validValue in $ediValue -split '\|' -replace '^\s{0,}' -replace '\s{0,}$') {
94+
$setDescriptors = @($ediValue -split '\|' -replace '^\s{0,}' -replace '\s{0,}$')
95+
$validSet = @(foreach ($validValue in $setDescriptors) {
9196
if ($validValue -as [int] -or $validValue -match 'number') {
9297
$hadNumbers = $true
9398
}
@@ -105,7 +110,7 @@ function ConvertSVGMetadataToParameterAttribute {
105110
}
106111
else {
107112
$validValue
108-
}
113+
}
109114
}) -join "','"
110115
if ($hadNumbers) {
111116
"[ValidatePattern('(?>$($validSet -split "','" -join '|')|\d+)')]"
@@ -117,8 +122,26 @@ function ConvertSVGMetadataToParameterAttribute {
117122
"[ValidateScript({`$_ -in '$validSet' -or `$_ -match '\#[0-9a-f]{3}' -or `$_ -match '\#[0-9a-f]{6}' -or `$_ -notmatch '\W'})]"
118123
}
119124
elseif ($validSet -and -not $hadUnknown) {
125+
$tabCompletionRedundant = $true
120126
"[ValidateSet('$validSet')]"
121-
}
127+
}
128+
129+
if ($setDescriptors -and -not $tabCompletionRedundant) {
130+
$null = $null
131+
'[ArgumentCompleter({
132+
param ( $commandName,$parameterName,$wordToComplete,$commandAst,$fakeBoundParameters )
133+
' + "
134+
`$validSet = '$($setDescriptors -replace $replaceMDNContent, '<${s}>' -replace "'", "''" -join "','")'
135+
" + @'
136+
if ($wordToComplete) {
137+
$toComplete = $wordToComplete -replace "^'" -replace "'$"
138+
return @($validSet -like "$toComplete*" -replace '^', "'" -replace '$',"'")
139+
} else {
140+
return @($validSet -replace '^', "'" -replace '$',"'")
141+
}
142+
})]
143+
'@
144+
}
122145
}
123146

124147
function ImportSvgAttribute {
@@ -141,9 +164,7 @@ function ImportSvgAttribute {
141164
if (-not $elementMarkdown) {
142165
Write-Verbose "Did not get content for $elementOrSetName"
143166
return
144-
}
145-
$replaceMDNContent = "\{\{\s{0,}(?>$(@('Glossary', 'domxref', 'HTTPMethod', 'htmlelement','svgelement', 'svgattr','htmlattrxref','cssxref') -join '|')[^\)]{0,})\(" +
146-
'["''](?<s>[^"'']+)["'']\)\s{0,}\}\}'
167+
}
147168

148169
$start, $end = 0, 0
149170
$globalAttrStart, $globalAttrEnd = 0, 0
@@ -425,9 +446,7 @@ function InitializeSvgAttributeData {
425446

426447
}
427448

428-
$headingList = $savedMarkdown[$attrUri] | ?<Markdown_Heading> -Split -IncludeMatch
429-
$replaceMDNContent = "\{\{\s{0,}(?>$(@('Glossary', 'domxref', 'HTTPMethod', 'htmlelement','svgelement', 'svgattr','htmlattrxref') -join '|'))\(" +
430-
'["''](?<s>[^"'']+)["'']\)\s{0,}\}\}'
449+
$headingList = $savedMarkdown[$attrUri] | ?<Markdown_Heading> -Split -IncludeMatch
431450

432451
$attrMetadata[$attrKv.key] = [PSCustomObject]@{
433452
Name = $attrKv.Key
@@ -492,7 +511,7 @@ foreach ($elementKV in $svgElementData.GetEnumerator()) {
492511
$newPipeScriptSplat = @{
493512
Synopsis = "Creates SVG $($elementKV.Key) elements"
494513
Description = $elementKV.Value.Description.Trim()
495-
Link = $docsLink, $mdnLink
514+
Link = $docsLink, $mdnLink, 'Write-SVG'
496515
}
497516
$relevantExampleFiles = Get-ChildItem -Filter *.ps1 -Path $examplesRoot |
498517
Select-String "\<svg.$($elementKv.Key)\>" |
@@ -521,8 +540,7 @@ foreach ($elementKV in $svgElementData.GetEnumerator()) {
521540
$parameters.Content = @(
522541
"# The Contents of the $($elementKv.Key) element"
523542
if ($content.Description -eq 'characterDataElementsInAnyOrder') {
524-
"[Reflection.AssemblyMetaData('SVG.IsCData', `$$true)]"
525-
"[string]"
543+
"[Reflection.AssemblyMetaData('SVG.IsCData', `$$true)]"
526544
}
527545
"[Parameter(Position=0,ValueFromPipelineByPropertyName)]"
528546
"[Alias('InputObject','Text', 'InnerText', 'Contents')]"

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### 0.2.1
2+
* Improved Command Help
3+
* Adding More Examples (Fixes #21)
4+
* Adding Example/README.md (Fixes #26)
5+
* Write-SVG: Allowing 2 value ViewBox (Fixes #28)
6+
* All SVG.* commands allow elements (Fixes #25 )
7+
* All SVG.* commands now have argument completers (Fixes #24)
8+
---
9+
110
### 0.2
211
* All SVG. commands now support -Data attributes (Fixes #12)
312
* Improved Command Help

CNAME

Lines changed: 0 additions & 1 deletion
This file was deleted.

Examples/Animate.PSSVG.ps1

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
#requires -Module PSSVG
22

3-
$original = @"
4-
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
5-
<rect width="10" height="10">
6-
<animate attributeName="rx" values="0;5;0" dur="10s" repeatCount="indefinite" />
7-
</rect>
8-
</svg>
9-
"@
10-
113
=<svg> -ViewBox 0,0,10,10 (
124
=<svg.rect> -Width 10 -Height 10 (
135
=<svg.animate> -AttributeName rx -Values "0;5;0" -Dur "10s" -RepeatCount indefinite
14-
)
6+
) -Fill '#4488ff'
157
) -OutputPath (Join-Path $psScriptRoot Animate.svg)
168

Examples/Animate.svg

Lines changed: 1 addition & 1 deletion
Loading

Examples/AnimateColor.PSSVG.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#requires -Module PSSVG
2+
3+
=<svg> -Content @(
4+
=<svg.circle> -cx 50 -cy 50 -r 50 -Fill red @(
5+
=<svg.animate> -AttributeName fill -dur 10s -Values 'red;orange;yellow;green;blue;indigo;violet;red' -RepeatCount indefinite -begin 1s
6+
=<svg.animate> -AttributeName stroke -dur 10s -Values 'orange;yellow;green;blue;indigo;violet;red;orange' -RepeatCount indefinite -begin 1s
7+
) -Stroke orange
8+
) -ViewBox 0,0,100,100 -OutputPath (Join-Path $psScriptRoot AnimateColor.svg)

Examples/AnimateColor.svg

Lines changed: 1 addition & 0 deletions
Loading

Examples/AnimateMotion.PSSVG.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#requires -Module PSSVG
2+
3+
$path = "M20,50 C20,-50 180,150 180,50 C180-50 20,150 20,50 z"
4+
=<svg> -viewBox "0 0 200 100" @(
5+
=<svg.path> -d $path -Fill none -Stroke lightgrey
6+
=<svg.circle> -r 5 -Fill red (
7+
=<svg.animateMotion> -Dur 10s -RepeatCount 'indefinite' -Path $path
8+
)
9+
=<svg.rect> -Width 2 -Height 2 -X -1 -Y -1 -Fill blue @(
10+
=<svg.animateMotion> -Dur 10s -RepeatCount 'indefinite' -Path $path
11+
=<svg.animateTransform> -AttributeName transform -From "0 0 0" -To "360 0 0" -dur "5s" -RepeatCount indefinite -AttributeType xml -type rotate
12+
)
13+
) -OutputPath (Join-Path $psScriptRoot AnimateMotion.svg)
14+

Examples/AnimateMotion.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)