Gradient.types.ps1xml
|
<!-- Generated with EZOut 2.0.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut --> <Types> <Type> <Name>Gradient</Name> <Members> <MemberSet> <Name>PSStandardMembers</Name> <Members> <PropertySet> <Name>DefaultDisplayPropertySet</Name> <ReferencedProperties> <Name>Input</Name> <Name>CSS</Name> </ReferencedProperties> </PropertySet> </Members> </MemberSet> <AliasProperty> <Name>GradientTypes</Name> <ReferencedMemberName>GradientType</ReferencedMemberName> </AliasProperty> <ScriptMethod> <Name>ToString</Name> <Script> <# .SYNOPSIS Stringifies the gradient .DESCRIPTION Gets the gradient as a string. By default, returns the CSS gradient. #> return "$($this.CSS)" </Script> </ScriptMethod> <ScriptProperty> <Name>CSS</Name> <GetScriptBlock> <# .SYNOPSIS Gets Gradient CSS .DESCRIPTION Gets the Gradient as CSS. .EXAMPLE gradient '#4488ff', '#224488' | Select-Object -Expand CSS #> param() # Get our gradient type $gradientTypes = $this.GradientTypes $gradientValues = @(foreach ($in in $this.input) { if ($in -notmatch $this.GradientTypePattern) { $in } }) if (-not $gradientTypes) { $gradientTypes = 'radial-gradient'} @(foreach ($gradientType in $gradientTypes) { "$gradientType($( @( $gradientValues ) -join ', ' ))" }) -join ', ' </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>GradientType</Name> <GetScriptBlock> <# .SYNOPSIS Gets the Gradient Type .DESCRIPTION Gets the Gradient Types found in the Gradient's input. If no type is found, radial-gradient is the default. #> $foundTypes = @(foreach ($in in $this.input) { if ($in -match $this.GradientTypePattern) { $in -replace '(?:-gradient)?$', '-gradient' } }) if (-not $foundTypes) { $foundTypes = @('radial-gradient') } return $foundTypes </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>GradientTypePattern</Name> <GetScriptBlock> <# .SYNOPSIS Gets the gradient type pattern .DESCRIPTION Gets the regular expression used to identify a gradient type .EXAMPLE Get-Gradiant '#4488ff' ,'#224488' | Select-Object -Expand GradientTypePattern #> '(?:repeating-)?(?>conic|linear|radial)(?:-gradient)?$' </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>SVG</Name> <GetScriptBlock> <# .SYNOPSIS Gets a SVG gradient .DESCRIPTION Gets the gradient as SVG. SVG Gradients are a bit more picky than their CSS counterpart, and do not support conic gradients. #> $gradientTypeHint = $this.GradientType if (-not $gradientTypeHint) { $gradientTypeHint = 'radial' } if ($gradientTypeHint) { $gradientTypeHint = $gradientTypeHint -replace '-gradient', 'Gradient' $gradientTypeHint = $gradientTypeHint.Substring(0,1).ToLower() + $gradientTypeHint.Substring(1) } # AFAIK, SVG does not support conic gradients. if ($gradientTypeHint -match 'conic') { return } $gradientValues = @(foreach ($in in $this.input) { if ($in -match '\#[a-f0-9]{6}') { $matches.0 } }) if (-not $gradientValues) { return } if ($gradientValues.Count -eq 1) { $gradientValues = @($gradientValues) * 2 } # Now we have at least two colors we want to be a gradient # We need to make sure the offset starts at 0% an ends at 100% # and so we actually need to divide by one less than our fill color, so we end at 100%. $offsetStep = 1 / ($gradientValues.Count - 1) @( # Construct our gradient element. "<${gradientTypeHint}$( # propagate our attributes " id='${gradientTypeHint}-$($gradientValues -replace '#' -join '-')'" )>" @( # and put in our stop colors for ($StopNumber = 0; $StopNumber -lt $gradientValues.Count; $StopNumber++) { "<stop offset='$($offsetStep * $StopNumber * 100)%' stop-color='$($gradientValues[$StopNumber])' />" } ) "</${gradientTypeHint}>" ) -join [Environment]::NewLine </GetScriptBlock> </ScriptProperty> <NoteProperty> <Name>DefaultDisplay</Name> <Value>Input CSS</Value> </NoteProperty> </Members> </Type> </Types> |