|
| 1 | + |
1 | 2 | # Shape |
2 | | -CSS Shapes with PowerShell |
| 3 | + |
| 4 | +## CSS Shapes with PowerShell |
| 5 | + |
| 6 | +[CSS Shapes](https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Shapes) are pretty amazing! |
| 7 | + |
| 8 | +There are 8 shape types: |
| 9 | + |
| 10 | +* [circle](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/circle) |
| 11 | +* [ellipse](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/ellipse) |
| 12 | +* [inset](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/inset) |
| 13 | +* [path](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/path) |
| 14 | +* [polygon](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/polygon) |
| 15 | +* [rect](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/rect) |
| 16 | +* [shape](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/shape) |
| 17 | +* [xywh](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/xywh) |
| 18 | +Unfortunately, that also means there are 8 _slightly_ different ways to write a shape. |
| 19 | + |
| 20 | +Polygons work in pairs. Paths must be quoted. |
| 21 | + |
| 22 | +Most others need to be joined with spaces, |
| 23 | +but shape itself needs to be joined with spaces and commas before keywords. |
| 24 | + |
| 25 | +This module exists in order to make it _slightly_ easier to generate shapes. |
| 26 | + |
| 27 | +## Installing and Importing |
| 28 | + |
| 29 | +You can install the module from the PowerShell Gallery: |
| 30 | + |
| 31 | +~~~PowerShell |
| 32 | +Install-Module Shape |
| 33 | +~~~ |
| 34 | + |
| 35 | +After it is installed, you can simply import it: |
| 36 | + |
| 37 | +~~~PowerShell |
| 38 | +Import-Module Shape -PassThru |
| 39 | +~~~ |
| 40 | + |
| 41 | +### Cloning and importing |
| 42 | + |
| 43 | +You can also clone this repository and import the module locally: |
| 44 | + |
| 45 | +~~~PowerShell |
| 46 | +git clone https://github.com/PowerShellWeb/Shape |
| 47 | +cd ./Shape |
| 48 | +Import-Module ./ -PassThru |
| 49 | +~~~ |
| 50 | + |
| 51 | + |
| 52 | +## Getting Started |
| 53 | + |
| 54 | +Shape tries to have simple syntax. |
| 55 | + |
| 56 | +After importing, we can create any CSS shape with simple syntax |
| 57 | + |
| 58 | +~~~PowerShell |
| 59 | +circle 50% |
| 60 | +ellipse 4rem 50% at right center |
| 61 | +~~~ |
| 62 | + |
| 63 | + |
| 64 | +## Using Shapes |
| 65 | + |
| 66 | +To use a shape in a page, we simply make it into a string. |
| 67 | + |
| 68 | +~~~PowerShell |
| 69 | +".circle { width: 100%; height: 100%; clip-path:$(circle 50%) }" |
| 70 | +~~~ |
| 71 | + |
| 72 | +Here's a page with nothing but an ellipse. |
| 73 | + |
| 74 | +We need to provide a background color to see the shape. |
| 75 | + |
| 76 | +~~~PowerShell |
| 77 | +@( |
| 78 | + "<html>" |
| 79 | + "<head><style>" |
| 80 | + "body { max-width: 100vw; height: 100vh}" |
| 81 | + ".ellipse { background-color: #4488ff;width: 100%; height:100%; clip-path:$(ellipse 50% 50%); }" |
| 82 | + "</style></head>" |
| 83 | + "<body><div class='ellipse'></div></body>" |
| 84 | + "</html>" |
| 85 | +) > ./ellipse.html |
| 86 | +~~~ |
| 87 | + |
| 88 | +Here's a page with nothing but an inset path: |
| 89 | + |
| 90 | +~~~PowerShell |
| 91 | +@( |
| 92 | + "<html>" |
| 93 | + "<head><style>" |
| 94 | + "body { max-width: 100vw; height: 100vh}" |
| 95 | + ".inset { background-color: #4488ff;width: 100%; height:100%; clip-path:$(inset 5%); }" |
| 96 | + "</style></head>" |
| 97 | + "<body><div class='inset'></div></body>" |
| 98 | + "</html>" |
| 99 | +) > ./inset.html |
| 100 | +~~~ |
| 101 | + |
| 102 | +You can use the shape module to generate any CSS shape. |
| 103 | + |
| 104 | +Have Fun! |
0 commit comments