Repository navigation
Expand file tree
/
Copy pathColor.php
More file actions
246 lines (195 loc) · 7.47 KB
/
Copy pathColor.php
File metadata and controls
246 lines (195 loc) · 7.47 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?php
declare(strict_types=1);
namespace ItalyStrap\ThemeJsonGenerator\Settings;
use ItalyStrap\ThemeJsonGenerator\Schema\ThemeSchemaCoverage;
use ItalyStrap\ThemeJsonGenerator\Settings;
use ItalyStrap\ThemeJsonGenerator\Settings\Color\Color as ColorPreset;
use ItalyStrap\ThemeJsonGenerator\Settings\Color\Duotone;
use ItalyStrap\ThemeJsonGenerator\Settings\Color\Gradient;
use ItalyStrap\ThemeJsonGenerator\Settings\Color\Values\CssColor;
use ItalyStrap\ThemeJsonGenerator\Settings\Color\Values\CssColorInterface;
use ItalyStrap\ThemeJsonGenerator\Settings\Color\Values\GradientInterface;
final readonly class Color
{
use ScopedSettingsWriterTrait;
public const SECTION = 'color';
public const BACKGROUND = 'background';
public const BUTTON = 'button';
public const CAPTION = 'caption';
public const CUSTOM = 'custom';
public const CUSTOM_DUOTONE = 'customDuotone';
public const CUSTOM_GRADIENT = 'customGradient';
public const DEFAULT_DUOTONE = 'defaultDuotone';
public const DEFAULT_GRADIENTS = 'defaultGradients';
public const DEFAULT_PALETTE = 'defaultPalette';
public const HEADING = 'heading';
public const LINK = 'link';
public const TEXT = 'text';
public function __construct(
private Settings $settings,
) {
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::TEXT])]
public function enableText(): self
{
return $this->setBoolean(self::TEXT, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::TEXT])]
public function disableText(): self
{
return $this->setBoolean(self::TEXT, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::BACKGROUND])]
public function enableBackground(): self
{
return $this->setBoolean(self::BACKGROUND, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::BACKGROUND])]
public function disableBackground(): self
{
return $this->setBoolean(self::BACKGROUND, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::LINK])]
public function enableLink(): self
{
return $this->setBoolean(self::LINK, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::LINK])]
public function disableLink(): self
{
return $this->setBoolean(self::LINK, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::CUSTOM])]
public function enableCustom(): self
{
return $this->setBoolean(self::CUSTOM, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::CUSTOM])]
public function disableCustom(): self
{
return $this->setBoolean(self::CUSTOM, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::CUSTOM_DUOTONE])]
public function enableCustomDuotone(): self
{
return $this->setBoolean(self::CUSTOM_DUOTONE, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::CUSTOM_DUOTONE])]
public function disableCustomDuotone(): self
{
return $this->setBoolean(self::CUSTOM_DUOTONE, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::CUSTOM_GRADIENT])]
public function enableCustomGradient(): self
{
return $this->setBoolean(self::CUSTOM_GRADIENT, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::CUSTOM_GRADIENT])]
public function disableCustomGradient(): self
{
return $this->setBoolean(self::CUSTOM_GRADIENT, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::DEFAULT_DUOTONE])]
public function enableDefaultDuotone(): self
{
return $this->setBoolean(self::DEFAULT_DUOTONE, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::DEFAULT_DUOTONE])]
public function disableDefaultDuotone(): self
{
return $this->setBoolean(self::DEFAULT_DUOTONE, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::DEFAULT_GRADIENTS])]
public function enableDefaultGradients(): self
{
return $this->setBoolean(self::DEFAULT_GRADIENTS, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::DEFAULT_GRADIENTS])]
public function disableDefaultGradients(): self
{
return $this->setBoolean(self::DEFAULT_GRADIENTS, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::DEFAULT_PALETTE])]
public function enableDefaultPalette(): self
{
return $this->setBoolean(self::DEFAULT_PALETTE, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::DEFAULT_PALETTE])]
public function disableDefaultPalette(): self
{
return $this->setBoolean(self::DEFAULT_PALETTE, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::HEADING])]
public function enableHeading(): self
{
return $this->setBoolean(self::HEADING, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::HEADING])]
public function disableHeading(): self
{
return $this->setBoolean(self::HEADING, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::BUTTON])]
public function enableButton(): self
{
return $this->setBoolean(self::BUTTON, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::BUTTON])]
public function disableButton(): self
{
return $this->setBoolean(self::BUTTON, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::CAPTION])]
public function enableCaption(): self
{
return $this->setBoolean(self::CAPTION, true);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, self::CAPTION])]
public function disableCaption(): self
{
return $this->setBoolean(self::CAPTION, false);
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, ColorPreset::SECTION])]
public function addColor(string $slug, string $name, string|CssColorInterface $color): self
{
$this->settings->addPreset(new ColorPreset(
$slug,
$name,
\is_string($color) ? new CssColor($color) : $color
));
return $this;
}
/**
* @param iterable<mixed> $colors
*/
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, ColorPreset::SECTION])]
public function addColors(iterable $colors): self
{
foreach ($colors as $color) {
if (!$color instanceof ColorPreset) {
throw new \InvalidArgumentException(\sprintf(
'Expected an instance of %s, got %s.',
ColorPreset::class,
\get_debug_type($color),
));
}
$this->settings->addPreset($color);
}
return $this;
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, Duotone::SECTION])]
public function addDuotone(string $slug, string $name, ColorPreset ...$colors): self
{
$this->settings->addPreset(new Duotone($slug, $name, ...$colors));
return $this;
}
#[ThemeSchemaCoverage([Settings::SECTION, self::SECTION, Gradient::SECTION])]
public function addGradient(
string $slug,
string $name,
GradientInterface $gradient
): self {
$this->settings->addPreset(new Gradient($slug, $name, $gradient));
return $this;
}
}