Skip to content

Commit afb6f1a

Browse files
feat: Prebulding palette files ( Fixes #130, Fixes #131 )
Adding _views/Palette.ps1
1 parent dd7fbcc commit afb6f1a

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

4bitcss.com/_views/Palette.ps1

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
2+
<#
3+
#>
4+
#requires -Module Turtle
5+
param(
6+
[PSObject]
7+
$Palette
8+
)
9+
10+
if ($palette -is [string] -and $site.Palettes[$palette]) {
11+
$palette = $site.Palettes[$palette]
12+
}
13+
if (-not $palette) { return }
14+
if ($palette -is [string]) { return $palette }
15+
16+
if ($page -isnot [Collections.IDictionary]) {
17+
$page = [Ordered]@{}
18+
}
19+
20+
$page.PaletteName = "/css/$($palette.FileName)"
21+
22+
@"
23+
<style>
24+
h1, h2, h3 { text-align: center }
25+
.paletteName { text-align: center }
26+
.paletteFileName { text-align: center }
27+
.palettePreview { text-align: center }
28+
.imageContainer { max-height: 33.3%; }
29+
.example-output {
30+
text-align: center;
31+
margin-left: auto;
32+
margin-right: auto;
33+
width: 66vw;
34+
}
35+
.colorGrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 2.5em; margin: 2.5em}
36+
.colorLabel {text-align:center; }
37+
</style>
38+
"@
39+
40+
"<h1>
41+
<a class='paletteLink' href='#'>
42+
<span class='paletteName'></span>
43+
</a>
44+
</h1>"
45+
46+
@"
47+
<h2>
48+
<a class='paletteFileLink' href='#'>
49+
<span class='paletteFileName'></span>
50+
</a>
51+
</h2>
52+
"@
53+
54+
@"
55+
<h3>
56+
$($site.Palettes.Count) CSS color palettes for web or terminal
57+
</h3>
58+
"@
59+
60+
@"
61+
<script>
62+
function UpdatePaletteLinks() {
63+
document.
64+
querySelectorAll('.paletteLink').
65+
forEach(
66+
(link) => {
67+
var paletteName = getComputedStyle(link).getPropertyValue('--PaletteFileName');
68+
link.href = '/' + paletteName
69+
}
70+
)
71+
72+
document.
73+
querySelectorAll('.paletteFileLink').
74+
forEach(
75+
(link) => {
76+
var paletteName = getComputedStyle(link).getPropertyValue('--PaletteFileName');
77+
link.href = '/css/' + paletteName + '.css'
78+
}
79+
)
80+
}
81+
82+
UpdatePaletteLinks()
83+
</script>
84+
"@
85+
86+
$colorOrder =
87+
'Black','Red','Green','Yellow','Blue','Purple','Cyan','White',
88+
'BrightBlack','BrightRed','BrightGreen','BrightYellow','BrightBlue','BrightPurple','BrightCyan','BrightWhite'
89+
<#
90+
if (-not $script:MulticolorTurtles) {
91+
$script:MulticolorTurtles = [Ordered]@{
92+
triangle = turtle SierpinskiTriangle 42 5
93+
}
94+
}
95+
#>
96+
97+
"<div class='example-output'>"
98+
$site.includes.'4bitpreview.svg'.OuterXml
99+
"</div>"
100+
"<div class='example-output'>"
101+
$site.includes.'Animated-Palette.svg'.OuterXml
102+
"</div>"
103+
104+
"<div class='colorGrid'>"
105+
106+
foreach ($color in $colorOrder) {
107+
"<div>"
108+
"<svg>"
109+
"<rect width='100%' height='100%' class='$($color)Fill' />"
110+
"</svg>"
111+
"<div class='colorLabel'>$color</div>"
112+
"<div class='colorHex'></div>"
113+
"</div>"
114+
}
115+
"</div>"
116+
117+
<#
118+
foreach ($shapeName in $script:MulticolorTurtles.Keys) {
119+
$shape = $script:MulticolorTurtles[$shapeName]
120+
foreach ($color in $colorOrder) {
121+
$shape.PathClass = "$color-stroke"
122+
$shape.Id = "$shapeName-$color"
123+
"<div class='imageContainer example-output'>"
124+
"$shape"
125+
"</div>"
126+
}
127+
}
128+
"</div>"
129+
130+
131+
132+
133+
#>

0 commit comments

Comments
 (0)