-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
backgrounds.ts
175 lines (148 loc) · 5.22 KB
/
backgrounds.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import type { Rule } from '@unocss/core'
import { objectKeys } from 'ts-extras'
import type { DocumentationPage } from '@windblade/unocss-docs'
import { encodeString } from '@windblade/unocss-docs'
import { ruleUtils } from '@windblade/core'
import type { Theme } from '@windblade/core'
const { color, logical } = ruleUtils
export function bgColor() {
const rules: Rule<Theme>[] = [
color.colorRule('bg', 'background-color'),
color.colorBgRule('bg'),
color.fgColorRule('bg-fg', 'background-color'),
// TODO: we might need a set-fg rule that is the same as bg but does not actually change background color
]
const docs: DocumentationPage = `
<page>
<h1><title /></h1>
<p>Windblade uses semantic colors.</p>
<h2>Try it</h2>
<try-it selected="$util">
<utils>
<util>
bg-
<select>
<for object="theme.windblade.colors" key-as="$name" value-as="$color">
<option value="$name"/>
</for>
<for object="theme.windblade.miscColors" key-as="$name" value-as="$color">
<option value="$name"/>
</for>
</select>
</util>
<util renderer="fg">
bg-fg-
<input type="integer" />
</util>
</utils>
<renderer for="fg" html="${encodeString(`
<div class="size-i-full aspect-1/1 max-size-i-m max-size-b-m rounded-s p-s bg-accent">
<div class="size-i-full aspect-1/1 rounded-full $util"></div>
</div>
`)}" />
<renderer html="${encodeString(`
<div class="$util size-i-full aspect-1/1 max-size-i-m max-size-b-m rounded-s p-s flex items-center justify-center text-center">
Background color
</div>
`)}" />
<h3>Preview</h3>
<viewport />
<h3>HTML</h3>
<html />
<h3>Generated CSS</h3>
<css />
</try-it>
</page>
`
return { rules, docs }
}
export function backgroundImage() {
const rules: Rule<Theme>[] = [
['bg-none', { 'background-image': 'none' }],
...objectKeys(logical.abbreviations.edges).map((edgeKey): Rule<Theme> => [
`bg-gradient-to-${edgeKey}`,
{
'--wb-gradient-stops': 'var(--wb-gradient-from, transparent), var(--wb-gradient-to, transparent)',
'background-image': `linear-gradient(to var(--${logical.abbreviations.edges[edgeKey]}), var(--wb-gradient-stops))`,
},
]),
...objectKeys(logical.abbreviations.coners).map((cornerKey): Rule<Theme> => [
`bg-gradient-to-${cornerKey}`,
{
'--wb-gradient-stops': 'var(--wb-gradient-from, transparent), var(--wb-gradient-to, transparent)',
'background-image': `linear-gradient(to var(--${logical.abbreviations.coners[cornerKey]}), var(--wb-gradient-stops))`,
},
]),
]
const docs: DocumentationPage = `
<page>
<h1><title /></h1>
<p>Repalced static colors with sematic colors.</p>
<h2>Try it</h2>
<try-it selected="$util">
<utils>
${[
'bg-none',
...Object.keys(logical.abbreviations.edges).map(val => `bg-gradient-to-${val}`),
...Object.keys(logical.abbreviations.coners).map(val => `bg-gradient-to-${val}`),
].map(val => `<util>${val}</util>`).join('')}
</utils>
<renderer html="${encodeString(`
<div class="$util from-accent size-i-full size-b-l.2 rounded-s"></div>
`)}" />
<h3>Preview</h3>
<viewport />
<h3>HTML</h3>
<html />
<h3>Generated CSS</h3>
<css />
</try-it>
</page>
`
return { rules, docs }
}
export function gradientColorStops() {
const rules: Rule<Theme>[] = [
color.colorRule('from', '--wb-gradient-from'),
color.colorRule('to', '--wb-gradient-to'),
// TODO implement 'via'
// colorRule('via', '--wb-gradient-stops', (val) => `var(--wb-gradient-from, transparent), ${val}, var(--wb-gradient-to, transparent)`),
]
const docs: DocumentationPage = `
<page>
<h1><title /></h1>
<p>Repalced static colors with sematic colors. Temporarily missing the \'via\' utilities.</p>
<h2>Try it</h2>
<try-it selected="$util">
<utils>
${['from', 'to'].map(val => `
<util renderer="${val}">
${val}-
<select>
<for object="theme.windblade.colors" key-as="$name" value-as="$color">
<option value="$name"/>
</for>
<for object="theme.windblade.miscColors" key-as="$name" value-as="$color">
<option value="$name"/>
</for>
</select>
</util>
`).join('')}
</utils>
<renderer html="${encodeString(`
<div class="bg-gradient-to-ie $util from-accent-2 size-i-full size-b-l.2 rounded-s"></div>
`)}" />
<renderer for="from" html="${encodeString(`
<div class="bg-gradient-to-ie $util to-accent-2 size-i-full size-b-l.2 rounded-s"></div>
`)}" />
<h3>Preview</h3>
<viewport />
<h3>HTML</h3>
<html />
<h3>Generated CSS</h3>
<css />
</try-it>
</page>
`
return { rules, docs }
}