Coder Social home page Coder Social logo

startautomating / pssvg Goto Github PK

View Code? Open in Web Editor NEW
24.0 2.0 1.0 47.87 MB

Script SVGs with PowerShell

Home Page: https://pssvg.start-automating.com/

License: MIT License

PowerShell 100.00%
github-actions powershell svg svg-animations svg-icons graphics graphics-programming svg-images

pssvg's Introduction

PowerShell tools for SVG.

PSSVG helps you create Scalable Vector Graphics using PowerShell.

There is a command for every tag of the SVG standard (and then some).

For example, this script generates the image below it.

svg (
    svg.text -X 50% -Y 50% -Fontsize 36 "Hello World" -DominantBaseline middle -TextAnchor middle -Fill '#4488ff'
) -ViewBox 0,0, 200, 100

PSSVG has a lot cooler Examples than hello world:

Example Name Image
Animate Animate.svg
Animate
AnimateColor AnimateColor.svg
AnimateColor
AnimatedShapes AnimatedShapes.svg
AnimatedShapes
AnimateMotion AnimateMotion.svg
AnimateMotion
Blur Blur.svg
Blur
BPMAnimate BPMAnimate.svg
BPMAnimate
BPMMorph BPMMorph.svg
BPMMorph
BPMTriangleMorph BPMTriangleMorph.svg
BPMTriangleMorph
Circles Circles.svg
Circles
CloudAnimation CloudAnimation.svg
CloudAnimation
Clouds Clouds.svg
Clouds
DropShadow DropShadow.svg
DropShadow
Embossed Embossed.svg
Embossed
FadeIn FadeIn.svg
FadeIn
HelloWorld HelloWorld.svg
HelloWorld
HexagonPattern HexagonPattern.svg
HexagonPattern
Index Index.svg
Index
LinearGradient LinearGradient.svg
LinearGradient
LinearGradientAnimated LinearGradientAnimated.svg
LinearGradientAnimated
ManyAnimatedRectangles ManyAnimatedRectangles.svg
ManyAnimatedRectangles
ManyRectangles ManyRectangles.svg
ManyRectangles
Morphing Morphing.svg
Morphing
MovingGradient MovingGradient.svg
MovingGradient
MovingShadows
Pattern Pattern.svg
Pattern
PatternAnimation PatternAnimation.svg
PatternAnimation
PatternMask PatternMask.svg
PatternMask
PowerShellChevron PowerShellChevron.svg
PowerShellChevron
RadialGradient RadialGradient.svg
RadialGradient
RadialGradientAnimated RadialGradientAnimated.svg
RadialGradientAnimated
RepeatedShapes RepeatedShapes3.svg
RepeatedShapes
RepeatedShapes4.svg
RepeatedShapes
RepeatedShapes5.svg
RepeatedShapes
RepeatedShapes6.svg
RepeatedShapes
Shapes Shapes.svg
Shapes
SpinningSpiral SpinningSpiral15.svg
SpinningSpiral
SpinningSpiral636.svg
SpinningSpiral
SpinningSpiral741.svg
SpinningSpiral
SpinningSpiral901.svg
SpinningSpiral
StarRating StarRating.svg
StarRating
Stars Stars.svg
Stars
Stars10.svg
Stars
Stars11.svg
Stars
Stars12.svg
Stars
Stars5.svg
Stars
Stars6.svg
Stars
Stars7.svg
Stars
Stars8.svg
Stars
Stars9.svg
Stars
StartAutomating StartAutomating.svg
StartAutomating
StopUsingGIFs StopUsingGIFs.svg
StopUsingGIFs
SweepCircle SweepCircle.svg
SweepCircle
US-Flag US-Flag.svg
US-Flag
US-FlagAnimated US-FlagAnimated.svg
US-FlagAnimated
VerticalLinearGradient VerticalLinearGradient.svg
VerticalLinearGradient
ViewBoxAnimation ViewBoxAnimation.svg
ViewBoxAnimation

PSSVG is designed to act as a fairly complete domain specific language: every aspect of the SVG standard should be reflected in the commands of PSSVG.

The following commands are supported:

Element Function Aliases
a SVG.a =<svg.a>
animate SVG.animate =<svg.animate>
animateMotion SVG.animateMotion =<svg.animateMotion>
animateTransform SVG.animateTransform =<svg.animateTransform>
ANSI SVG.ANSI =<svg.ANSI>
ArcPath SVG.ArcPath =<SVG.ArcedPath> =<svg.ArcPath> SVG.ArcedPath
circle SVG.circle =<svg.circle>
clipPath SVG.clipPath =<svg.clipPath>
ConvexPolygon SVG.ConvexPolygon =<svg.ConvexPolygon> SVG.Decagon SVG.Dodecagon SVG.Enneadecagon SVG.Hendecagon SVG.Heptadecagon SVG.Heptagon SVG.Hexadecagon SVG.Hexagon SVG.Icosagon SVG.Icosikaidigon SVG.Icosikaienneagon SVG.Icosikaihenagon SVG.Icosikaiheptagon SVG.Icosikaihexagon SVG.Icosikaioctagon SVG.Icosikaipentagon SVG.Icositetragon SVG.Icositrigon SVG.Nonagon SVG.Octadecagon SVG.Octagon SVG.Pentadecagon SVG.Pentagon SVG.Tetradecagon SVG.Triacontagon SVG.Tridecagon
CurvePath SVG.CurvePath =<SVG.CurvedPath> =<svg.CurvePath> SVG.CurvedPath
defs SVG.defs =<svg.defs>
desc SVG.desc =<svg.desc>
discard SVG.discard =<svg.discard>
DropShadow SVG.DropShadow =<svg.DropShadow>
ellipse SVG.ellipse =<svg.ellipse>
feBlend SVG.feBlend =<svg.feBlend>
feColorMatrix SVG.feColorMatrix =<svg.feColorMatrix>
feComponentTransfer SVG.feComponentTransfer =<svg.feComponentTransfer>
feComposite SVG.feComposite =<svg.feComposite>
feConvolveMatrix SVG.feConvolveMatrix =<svg.feConvolveMatrix>
feDiffuseLighting SVG.feDiffuseLighting =<svg.feDiffuseLighting>
feDisplacementMap SVG.feDisplacementMap =<svg.feDisplacementMap>
feDistantLight SVG.feDistantLight =<svg.feDistantLight>
feDropShadow SVG.feDropShadow =<svg.feDropShadow>
feFlood SVG.feFlood =<svg.feFlood>
feFuncA SVG.feFuncA =<svg.feFuncA>
feFuncB SVG.feFuncB =<svg.feFuncB>
feFuncG SVG.feFuncG =<svg.feFuncG>
feFuncR SVG.feFuncR =<svg.feFuncR>
feGaussianBlur SVG.feGaussianBlur =<svg.feGaussianBlur>
feImage SVG.feImage =<svg.feImage>
feMerge SVG.feMerge =<svg.feMerge>
feMergeNode SVG.feMergeNode =<svg.feMergeNode>
feMorphology SVG.feMorphology =<svg.feMorphology>
feOffset SVG.feOffset =<svg.feOffset>
fePointLight SVG.fePointLight =<svg.fePointLight>
feSpecularLighting SVG.feSpecularLighting =<svg.feSpecularLighting>
feSpotLight SVG.feSpotLight =<svg.feSpotLight>
feTile SVG.feTile =<svg.feTile>
feTurbulence SVG.feTurbulence =<svg.feTurbulence>
filter SVG.filter =<svg.filter>
foreignObject SVG.foreignObject =<svg.foreignObject>
g SVG.g =<svg.g>
GoogleFont SVG.GoogleFont =<svg.GoogleFont>
image SVG.image =<svg.image>
Kite SVG.Kite =<svg.Kite> SVG.Rhombuses
line SVG.line =<svg.line>
linearGradient SVG.linearGradient =<svg.linearGradient>
LinePath SVG.LinePath =<SVG.LinedPath> =<svg.LinePath> SVG.LinedPath
marker SVG.marker =<svg.marker>
mask SVG.mask =<svg.mask>
metadata SVG.metadata =<svg.metadata>
mpath SVG.mpath =<svg.mpath>
path SVG.path =<svg.path>
pattern SVG.pattern =<svg.pattern>
polygon SVG.polygon =<svg.polygon>
polyline SVG.polyline =<svg.polyline>
radialGradient SVG.radialGradient =<svg.radialGradient>
rect SVG.rect =<svg.rect>
Rhombus SVG.Rhombus =<svg.Rhombus> SVG.Rhombi
script SVG.script =<svg.script>
set SVG.set =<svg.set>
Spiral SVG.Spiral =<svg.Spiral>
Star SVG.Star =<svg.Star>
stop SVG.stop =<svg.stop>
style SVG.style =<svg.style>
StyleSheet SVG.StyleSheet =<svg.StyleSheet>
svg SVG.svg =<svg> svg
switch SVG.switch =<svg.switch>
symbol SVG.symbol =<svg.symbol>
text SVG.text =<svg.text>
textPath SVG.textPath =<svg.textPath>
title SVG.title =<svg.title>
Triangle SVG.Triangle =<svg.Triangle>
tspan SVG.tspan =<svg.tspan>
use SVG.use =<svg.use>
view SVG.view =<svg.view>

(elements marked deprecated are not supported)

Goals

PSSVG hopes to be a useful toolkit for generating SVG images from PowerShell.

SVG has many benefits as an image file format, for example:

  • File Size
  • Scalability
  • Animations
  • Clickability
  • HTML/JavaScript/CSS integration
  • OS Integration

However, it is not a complete programming language.

Thus the primary goal is to make SVG creation scriptable.

Limitations

At current, PSSVG does not support aria attributes. Events can be generically specified with the parameter -On.

How PSSVG is Built

In order to provide an ideal PowerShell experience with rich help,
PSSVG is currently built by reading the contents of the Mozilla Developer Network's content repository.

It uses two PowerShell modules to read the repository and create the commands:

  • Irregular is used to help parse the markdown contents of the repository
  • PipeScript is used to create the functions from the parsed data.

pssvg's People

Contributors

startautomating avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

marbx

pssvg's Issues

Include example of BPM Animation

Splatting and simple math can make for musically synchonized animations.

Include an example that generates a pattern that repeats based off of a beat.

Self-host action

As PSSVG has an action, it should use this to build it's examples

Introducing PSSVG

PSSVG is a PowerShell Module for scalable vector graphics. It allows you to build SVG elements using simple PowerShell functions, and it has a function for every element in the SVG standard.

PSSVG

Attributes with many sets of metadata present problems in generation.

Some SVG attributes have multiple property tables, with different valid values for different elements.

This presents a bit of a blocking problem, since this presents all but the first alphabetical element from having the correct set of attributes.

To work around this, we will need to parse multiple tables and associate them with the elements they apply to.

PSSVG should correct markdown links

Because PSSVG is built atop of MDN's documentation, it contains various markdown links that would become invalid.

They can be corrected by linking to developer.mozilla.org.

Making a Visual Leitmotif for PowerShell with PSSVG

Because Start-Automating is a PowerShell shop, we have to make a lot of logos that visually hint at the relation between this project on PowerShell.

Doing this consistently across projects is a big benefit of building your assets with scripts. Essentially, what we can do is create a reusable part of a design and reuse that part in project after project.

I call this sort of technique a "Visual Leitmotif" (a Leitmotif is a recurrent theme throughout a composition).

The SVG standard provides something that can make this a little easier, a Symbol.

Using PSSVG, we can create our Visual Leitmotif with just a few lines of code.

=<svg> -ViewBox 100,100 -Content @(
    =<svg.symbol> -Id psChevron -Content @(
        =<svg.polygon> -Points (@(
            "40,20"
            "45,20"
            "60,50"
            "35,80"
            "32.5,80"
            "55,50"
        ) -join ' ')
    ) -ViewBox 100, 100

    =<svg.use> -Href '#psChevron' -Fill '#4488ff'
)

The above code produces this little nifty graphic:

PowerShell Cheron SVG

That's a nifty little image we can use again and again.


Here's the ScriptDeck logo, which makes pretty prominent use of the PowerShell Chevron:

ScriptDeck Logo


Here it is again in the GitPub logo:

GitPub Logo


And again in the ugit logo:
ugit Logo


And again in PSDevOps PSDevOps logo:
PSDevOps Logo


And, of course, in an updated PSSVG logo:
PSSVG logo


As a design technique, visual leitmotifs are a great way to remind people of a central brand without drawing too much attention to it.

With scripting, it's easy to establish that visual leitmotif and reuse it moving forward.

Just get it right once and include or copy and paste between project to project.

Hope this Helps

SVG functions should include examples

Since the /Examples directory contains a number of examples, any given function could include the contents files that reference that command as examples.

Scripting Existing SVGs with ConvertTo-PSSVG

ConvertTo-PSSVG

PSSVG would be much more useful if it could easily convert any SVG off of the internet into a PSSVG file.

So, as of PSSVG 0.2.4, you can ConvertTo-PSSVG

What it does

ConvertTo-PSSVG takes an SVG from a file, url, string, or xml document and converts it into a PSSVG script.

For example, if I download the feather icon for anchor and then run

ConvertTo-PSSVG Anchor.svg

It will output:

=<SVG> -width '24' -height '24' -viewBox '0 0 24 24' -fill 'none' -stroke 'currentColor' -strokewidth '2' -strokelinecap 'round' -strokelinejoin 'round' -class 'feather feather-anchor' -Content @(
    =<SVG.circle> -cx '12' -cy '5' -r '3'
    =<SVG.line> -x1 '12' -y1 '22' -x2 '12' -y2 '8'
    =<SVG.path> -d 'M5 12H2a10 10 0 0 0 20 0h-3'
)

How it works

This is actually fairly trivial.

First we get the XML form of the input, then we:

  1. Go thru to the first node
  2. Replace text nodes with their text.
  3. Find the appropriate command
  4. Replace attributes with parameters (if found)
  5. Replace child nodes recursively (effectively goto step 1).

For bonus points, we indent.

What we can do with this

Being able to ConvertTo-PSSVG gives you an easy way to integrate any existing design into your scripts. This can help, say, establish a visual leitmotif.

Hope this Helps

ConvertTo-PSSVG should try to handle slightly malformed XML.

As ConvertTo-PSSVG doesn't control the whole internet, it's important we handle the unexpected.

Thus:

When ConvertTo-PSSVG attempts to reach a RESTful URL and it receives a string, it should:

  1. Trim any leading content before the first tag
  2. Attempt to coerce it to XML.

Write-SVG should output objects

In order to improve the module experience and make PSSVG more useful, one should be able to use the elements created at each step as objects.

These objects should be decorated to allow for formatting.

SVG.Element should have a formatter

SVG.Elements should have a formatter.

A very ideal version of this would show colorized XML for the SVG content.

Luckily, EZOut already has one. We should be able to make some minor modifications to this to produce an ideal experience.

Elements should always allow tags as -Content

Even when the standard indicates that the content will be text, there are scenarios where the content should be text and elements.

Thus -Content should be escaped if it does not start with a tag, and all -Content parameters should be untyped.

Build Script should include argumentcompleters

In some cases, there are several fixed arguments and one or more types of input (for instance, with -FontWeight).

Making the best PowerShell experience for these parameters requires making an ArgumentCompleter.

Expand Example Coverage

Now that examples are automatically included (#16), it's important to expand coverage of the examples so that more commands have them.

Add SVG.Spiral

SVG.Spiral should inherit from SVG.Path and create a spiral.

It should exclude the parameters: D, Fill

Fill should always be transparent.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.