-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.types.ps1xml
More file actions
159 lines (146 loc) · 5.13 KB
/
Shape.types.ps1xml
File metadata and controls
159 lines (146 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!-- Generated with EZOut 2.0.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Types>
<Type>
<Name>Shape</Name>
<Members>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<PropertySet>
<Name>DefaultDisplayPropertySet</Name>
<ReferencedProperties>
<Name>CSS</Name>
</ReferencedProperties>
</PropertySet>
</Members>
</MemberSet>
<ScriptMethod>
<Name>ToString</Name>
<Script>
<#
.SYNOPSIS
Stringifies the shape
.DESCRIPTION
Gets the shape as a string by returning the shape's `.css`
#>
return "$($this.CSS)"
</Script>
</ScriptMethod>
<ScriptProperty>
<Name>CSS</Name>
<GetScriptBlock>
<#
.SYNOPSIS
Gets Shapes as CSS
.DESCRIPTION
Gets the Shape as CSS.
.EXAMPLE
shape circle 50% |
Select-Object -Expand CSS
#>
param()
$ShapeType = 'shape'
# Get our gradient type
$ShapeType = $this.ShapeType
$shapeValues = @(foreach ($in in $this.input) {
if ($in -notmatch $this.ShapeTypePattern) {
$in
}
})
if (-not $ShapeType) { $ShapeType = 'shape'}
@(
"$shapeType("
switch ($shapeType) {
path {
# Only paths need to be quoted
"'$($shapeValues -join ' ' -replace "'", "\'" -replace [Environment]::NewLine, '\')'"
}
polygon {
# Polygons need to be in comma separated pairs,
# and could come as pairs or comma separated pairs
$shapeValues = @($shapeValues -replace ',' -ne '')
@(for ($valueIndex = 0; $valueIndex -lt $shapeValues.Count; $valueIndex += 2) {
@(if ($null -ne $shapeValues[$valueIndex + 1]) {
$shapeValues[$valueIndex]
$shapeValues[$valueIndex + 1]
} else {
$shapeValues[$valueIndex]
$shapeValues[$valueIndex]
}) -join ' '
}) -join ', '
}
shape {
# Shapes segments start with keywords, and each segment should be separated by commas
$keyPattern = "^(?>$(
'arc', 'curve', 'close', 'move', '[hv]?line', 'smooth' -join '|'
))"
$buffer = @()
@(
for ($valueIndex = 0; $valueIndex -lt $shapeValues.Count; $valueIndex++) {
if ($shapeValues[$valueIndex] -match $keyPattern) {
if ($buffer) { $buffer -join ' ' }
$buffer = @()
}
if ($shapeValues[$valueIndex] -eq ',') {
continue
}
$buffer+= $shapeValues[$valueIndex]
}
if ($buffer) {$buffer -join ' '}
) -join ', '
}
default {
# all other shapes simply join their values with spaces
$shapeValues -join ' '
}
}
")"
) -join ''
</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Help</Name>
<GetScriptBlock>
return [Ordered]@{
'circle' = 'https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/circle'
'ellipse' = 'https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/ellipse'
'inset' = 'https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/inset'
'path' = 'https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/path'
'polygon' = 'https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/polygon'
'rect' = 'https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/rect'
'shape' = 'https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/shape'
'xywh' = 'https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/xywh'
}
</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>ShapeType</Name>
<GetScriptBlock>
$shapeTypes = @(foreach ($in in $this.input) {
if ($in -match $this.ShapeTypePattern) {
$matches.0
}
})
if (-not $shapeTypes) {
return "shape"
}
if ($shapeTypes.Count -gt 1) {
Write-Warning "There can be only one (shape type). Using $($shapeTypes[0])"
}
return $shapeTypes[0].ToLower()
</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>ShapeTypePattern</Name>
<GetScriptBlock>
$shapeHelp = $this.Help
"(?>$($shapeHelp.Keys -join '|'))"
</GetScriptBlock>
</ScriptProperty>
<NoteProperty>
<Name>DefaultDisplay</Name>
<Value>CSS</Value>
</NoteProperty>
</Members>
</Type>
</Types>