SVG.discard.ps1
function SVG.discard { <# .Synopsis Creates SVG discard elements .Description The **`<discard>`** [SVG](/en-US/docs/Web/SVG) element allows authors to specify the time at which particular elements are to be discarded, thereby reducing the resources required by an SVG user agent. This is particularly useful to help SVG viewers conserve memory while displaying long-running documents. The `<discard>` element may occur wherever the animate element may. #> [Reflection.AssemblyMetadata('SVG.ElementName', 'discard')] [CmdletBinding(PositionalBinding=$false)] param( # The Contents of the discard element [Parameter(Position=0,ValueFromPipelineByPropertyName)] [Alias('InputObject','Text', 'InnerText', 'Contents')] $Content, # [Parameter(ValueFromPipelineByPropertyName)] [Reflection.AssemblyMetaData('SVG.AttributeName','begin')] [Reflection.AssemblyMetaData('SVG.Value', '<begin-value-list>')] [Reflection.AssemblyMetaData('SVG.Default value', '0s')] [Reflection.AssemblyMetaData('SVG.Animatable', 'False')] $Begin, # [Parameter(ValueFromPipelineByPropertyName)] [Reflection.AssemblyMetaData('SVG.AttributeName','href')] [Reflection.AssemblyMetaData('SVG.Value', '<url>')] [Reflection.AssemblyMetaData('SVG.Animatable', 'True')] $Href, # The **`requiredFeatures`** attribute takes a list of feature strings, with the individual strings separated by white space. It determines whether or not all of the named features are supported by the browser; if all of them are supported, the attribute evaluates to `true` end the element is rendered; otherwise, the attribute evaluates to `false` and the current element and its children are skipped and thus will not be rendered. This provides a way to design SVG that gracefully falls back when features aren't available. # # If the attribute is not present, then its implicit evaluated value is `true`. If a null string or empty string value is given to attribute `requiredFeatures`, the attribute is evaluate to `false`. # # `requiredFeatures` is often used in conjunction with the switch element. If `requiredFeatures` is used in other situations, it represents a simple switch on the given element whether to render the element or not. # # To detect availability of an SVG feature from script, there is the (also deprecated) DOMImplementation.hasFeature() method. # # [Parameter(ValueFromPipelineByPropertyName)] [Reflection.AssemblyMetaData('SVG.AttributeName','requiredFeatures')] [Reflection.AssemblyMetaData('SVG.Deprecated',$true)] [Reflection.AssemblyMetaData('SVG.Value', '<list-of-features>')] [Reflection.AssemblyMetaData('SVG.Default value', 'true if not defined, false if null or empty string as value')] [Reflection.AssemblyMetaData('SVG.Animatable', 'False')] $RequiredFeatures, # The **`systemLanguage`** attribute represents a list of supported language tags. This list is matched against the language defined in the user preferences. # # [Parameter(ValueFromPipelineByPropertyName)] [Reflection.AssemblyMetaData('SVG.AttributeName','systemLanguage')] [Reflection.AssemblyMetaData('SVG.Value', '<language-tags>')] [Reflection.AssemblyMetaData('SVG.Animatable', 'False')] $SystemLanguage, # The **`id`** attribute assigns a unique name to an element. # # You can use this attribute with any SVG element. [Parameter(ValueFromPipelineByPropertyName)] [Reflection.AssemblyMetaData('SVG.AttributeName','id')] [Reflection.AssemblyMetaData('SVG.Value', '<id>')] [Reflection.AssemblyMetaData('SVG.Animatable', 'False')] $Id, # The **`lang`** attribute specifies the primary language used in contents and attributes containing text content of particular elements. # # There is also an xml:lang attribute (with namespace). If both of them are defined, the one with namespace is used and the one without is ignored. # # In SVG 1.1 there was a `lang` attribute defined with a different meaning and only applying to glyph elements. That attribute specified a list of languages according to {{RFC(5646, "Tags for Identifying Languages (also known as BCP 47)")}}. The glyph was meant to be used if the `xml:lang` attribute exactly matched one of the languages given in the value of this parameter, or if the `xml:lang` attribute exactly equaled a prefix of one of the languages given in the value of this parameter such that the first tag character following the prefix was "-". # # You can use this attribute with any SVG element. [Parameter(ValueFromPipelineByPropertyName)] [Reflection.AssemblyMetaData('SVG.AttributeName','lang')] [Reflection.AssemblyMetaData('SVG.Value', '<language-tag>')] [Reflection.AssemblyMetaData('SVG.Animatable', 'False')] $Lang, # The **`tabindex`** attribute allows you to control whether an element is focusable and to define the relative order of the element for the purposes of sequential focus navigation. # # You can use this attribute with any SVG element. [Parameter(ValueFromPipelineByPropertyName)] [Reflection.AssemblyMetaData('SVG.AttributeName','tabindex')] [Reflection.AssemblyMetaData('SVG.Value', 'valid integer')] [Reflection.AssemblyMetaData('SVG.Animatable', 'False')] $Tabindex, # The **`xml:base`** attribute specifies a base IRI other than the base IRI of the document or external entity. # # You can use this attribute with any SVG element. [Parameter(ValueFromPipelineByPropertyName)] [Reflection.AssemblyMetaData('SVG.AttributeName','xml:base')] [Reflection.AssemblyMetaData('SVG.Deprecated',$true)] [Reflection.AssemblyMetaData('SVG.Value', '<iri>')] [Reflection.AssemblyMetaData('SVG.Animatable', 'False')] $XmlBase, # The **`xml:lang`** attribute specifies the primary language used in contents and attributes containing text content of particular elements. # # It is a universal attribute allowed in all XML dialects to mark up the natural human language that an element contains. # # There is also a lang attribute (without namespace). If both of them are defined, the one with namespace is used and the one without is ignored. # # You can use this attribute with any SVG element. [Parameter(ValueFromPipelineByPropertyName)] [Reflection.AssemblyMetaData('SVG.AttributeName','xml:lang')] [Reflection.AssemblyMetaData('SVG.Deprecated',$true)] [Reflection.AssemblyMetaData('SVG.Value', '<language-tag>')] [Reflection.AssemblyMetaData('SVG.Animatable', 'False')] $XmlLang, # SVG supports the built-in XML **`xml:space`** attribute to handle whitespace characters inside elements. Child elements inside an element may also have an `xml:space` attribute that overrides the parent's one. # # > **Note:** Instead of using the `xml:space` attribute, use the {{cssxref("white-space")}} CSS property. # # This attribute influences how browsers parse text content and therefore changes the way the DOM is built. Therefore, changing this attribute's value through the DOM API may have no effect. # # You can use this attribute with any SVG element. [Parameter(ValueFromPipelineByPropertyName)] [Reflection.AssemblyMetaData('SVG.AttributeName','xml:space')] [Reflection.AssemblyMetaData('SVG.Deprecated',$true)] [Reflection.AssemblyMetaData('SVG.Value', 'default | preserve')] [ValidateSet('default','preserve')] [Reflection.AssemblyMetaData('SVG.Default value', 'default')] [Reflection.AssemblyMetaData('SVG.Animatable', 'False')] $XmlSpace ) process { $paramCopy = [Ordered]@{} + $PSBoundParameters $myCmd = $MyInvocation.MyCommand $inputObject = $_ $elementName = foreach ($myAttr in $myCmd.ScriptBlock.Attributes) { if ($myAttr.Key -eq 'SVG.ElementName') { $myAttr.Value break } } if (-not $elementName) { return } # If we had an input object, create a copy if ($inputObject) { $inputObject = [PSObject]::new($inputObject) } # (this way, we can take off any properties that were provided by name) if ($paramCopy['Style'] -and $paramCopy['Style'] -isnot [string]) { if ($paramCopy['Style'] -is [Collections.IDictionary]) { $paramCopy['Style'] = @(foreach ($kv in $paramCopy['Style'].GetEnumerator()) { "$($kv.Key):$($kv.Value)" }) -join ';' } else { $paramCopy['Style'] = @(foreach ($prop in $paramCopy['Style'].psobject.properties) { "$($prop.Name):$($kv.Value)" }) -join ';' } } $elementText = "<$elementName " :nextParameter foreach ($kv in $paramCopy.GetEnumerator()) { foreach ($attr in $myCmd.Parameters[$kv.Key].Attributes) { if ($attr.Key -eq 'SVG.AttributeName') { if ($inputObject -and $inputObject.psobject.properties[$attr.Key]) { $inputObject.psobject.properties.Remove($attr.Key) } $elementText += "$($attr.Value)='$([Web.HttpUtility]::HtmlAttributeEncode($kv.Value))' " } } } if ($elementName -eq 'svg') { $elementText += 'xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"' } $elementText = $elementText -replace '\s{0,1}$' if (-not $content) { $elementText += " />" } else { $isCData = $false foreach ($attr in $myCmd.Parameters.Content.Attributes) { if ($attr.Key -eq 'SVG.IsCData' -and $attr.Value -eq 'true') { $isCData = $true } } if ($isCData) { $escapedContent = [Security.SecurityElement]::Escape("$content") $elementText += ">" + "$escapedContent" + "</$elementName>" } else { $elementText += ">" + "$Content" + "</$elementName>" } } if ($elementName -eq 'svg' -and $OutputPath) { $elementText | Set-Content -Path $OutputPath Get-Item $OutputPath } else { $elementText } } } |