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>
                        &lt;#
.SYNOPSIS
    Stringifies the gradient
.DESCRIPTION
    Gets the gradient as a string. By default, returns the CSS gradient.
#&gt;
return "$($this.CSS)"
                    </Script>
      </ScriptMethod>
      <ScriptProperty>
        <Name>CSS</Name>
        <GetScriptBlock>
                        &lt;#
.SYNOPSIS
    Gets Gradient CSS
.DESCRIPTION
    Gets the Gradient as CSS.
.EXAMPLE
    gradient '#4488ff', '#224488' |
        Select-Object -Expand CSS
#&gt;
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>
                        &lt;#
.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.
#&gt;

$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>
                        &lt;#
.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
#&gt;
'(?:repeating-)?(?&gt;conic|linear|radial)(?:-gradient)?$'
                    </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>SVG</Name>
        <GetScriptBlock>
                        &lt;#
.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.

#&gt;
$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.
    "&lt;${gradientTypeHint}$(
        # propagate our attributes
        " id='${gradientTypeHint}-$($gradientValues -replace '#' -join '-')'"
    )&gt;"
    @(
        # and put in our stop colors
        for ($StopNumber = 0; $StopNumber -lt $gradientValues.Count; $StopNumber++) {
            "&lt;stop offset='$($offsetStep * $StopNumber * 100)%' stop-color='$($gradientValues[$StopNumber])' /&gt;"
        }
    )
    "&lt;/${gradientTypeHint}&gt;"
) -join [Environment]::NewLine
                    </GetScriptBlock>
      </ScriptProperty>
      <NoteProperty>
        <Name>DefaultDisplay</Name>
        <Value>Input
CSS</Value>
      </NoteProperty>
    </Members>
  </Type>
</Types>