Skip to content

Commit 3ebf108

Browse files
committed
Split config into its own file and extended cssdoc.
1 parent 7a78aa0 commit 3ebf108

File tree

3 files changed

+177
-170
lines changed

3 files changed

+177
-170
lines changed

src/autoload.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
\spl_autoload_register(function (string $class) : void {
44
$classes = [
55
'hexydec\\css\\cssdoc' => __DIR__.'/cssdoc.php',
6+
'hexydec\\css\\config' => __DIR__.'/config.php',
67
'hexydec\\css\\document' => __DIR__.'/tokens/document.php',
78
'hexydec\\css\\directive' => __DIR__.'/tokens/directive.php',
89
'hexydec\\css\\rule' => __DIR__.'/tokens/rule.php',

src/config.php

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<?php
2+
declare(strict_types = 1);
3+
namespace hexydec\css;
4+
5+
class config {
6+
7+
/**
8+
* @var array<array> $config Object configuration array
9+
*/
10+
protected array $config = [
11+
'nested' => ['@media', '@supports', '@keyframes', '@-webkit-keyframes', '@-moz-keyframes', '@-o-keyframes', '@document', '@-moz-document', '@container'], // directive that can have nested rules
12+
'spaced' => ['calc', 'min', 'max', 'clamp'], // values where spaces between operators must be retained
13+
'quoted' => ['content', 'format', 'counters', '@charset', 'syntax', 'font-feature-settings', '-webkit-font-feature-settings', '-moz-font-feature-settings', 'quotes', 'text-overflow'], // directives or properties where the contained values must be quoted
14+
'casesensitive' => ['url'], // property values that should not be lowercased
15+
'none' => ['border', 'background', 'outline'], // properties that can be changed to 0 when none
16+
'multiples' => ['margin', 'padding', 'border-width', 'border-style', 'border-color', 'border-radius'],
17+
'colors' => [
18+
'#f0ffff' => 'azure',
19+
'#f5f5dc' => 'beige',
20+
'#ffe4c4' => 'bisque',
21+
'#a52a2a' => 'brown',
22+
'#ff7f50' => 'coral',
23+
'#ffd700' => 'gold',
24+
'#008000' => 'green',
25+
'#808080' => 'grey',
26+
'#4b0082' => 'indigo',
27+
'#fffff0' => 'ivory',
28+
'#f0e68c' => 'khaki',
29+
'#faf0e6' => 'linen',
30+
'#000080' => 'navy',
31+
'#808000' => 'olive',
32+
'#ffa500' => 'orange',
33+
'#da70d6' => 'orchid',
34+
'#cd853f' => 'peru',
35+
'#ffc0cb' => 'pink',
36+
'#dda0dd' => 'plum',
37+
'#f00' => 'red',
38+
'#fa8072' => 'salmon',
39+
'#a0522d' => 'sienna',
40+
'#c0c0c0' => 'silver',
41+
'#fffafa' => 'snow',
42+
'#d2b48c' => 'tan',
43+
'#008080' => 'teal',
44+
'#ff6347' => 'tomato',
45+
'#ee82ee' => 'violet',
46+
'#f5deb3' => 'wheat',
47+
'black' => '#000',
48+
'indianred' => '#cd5c5c',
49+
'lightcoral' => '#f08080',
50+
'darksalmon' => '#e9967a',
51+
'lightsalmon' => '#ffa07a',
52+
'crimson' => '#dc143c',
53+
'firebrick' => '#b22222',
54+
'darkred' => '#8b0000',
55+
'lightpink' => '#ffb6c1',
56+
'hotpink' => '#ff69b4',
57+
'deeppink' => '#ff1493',
58+
'mediumvioletred' => '#c71585',
59+
'palevioletred' => '#db7093',
60+
'orangered' => '#ff4500',
61+
'darkorange' => '#ff8c00',
62+
'lightyellow' => '#ffffe0',
63+
'lemonchiffon' => '#fffacd',
64+
'lightgoldenrodyellow' => '#fafad2',
65+
'papayawhip' => '#ffefd5',
66+
'moccasin' => '#ffe4b5',
67+
'peachpuff' => '#ffdab9',
68+
'palegoldenrod' => '#eee8aa',
69+
'darkkhaki' => '#bdb76b',
70+
'lavender' => '#e6e6fa',
71+
'thistle' => '#d8bfd8',
72+
'fuchsia' => '#ff00ff',
73+
'magenta' => '#ff00ff',
74+
'mediumorchid' => '#ba55d3',
75+
'mediumpurple' => '#9370db',
76+
'rebeccapurple' => '#663399',
77+
'blueviolet' => '#8a2be2',
78+
'darkviolet' => '#9400d3',
79+
'darkorchid' => '#9932cc',
80+
'darkmagenta' => '#8b008b',
81+
'slateblue' => '#6a5acd',
82+
'darkslateblue' => '#483d8b',
83+
'mediumslateblue' => '#7b68ee',
84+
'greenyellow' => '#adff2f',
85+
'chartreuse' => '#7fff00',
86+
'lawngreen' => '#7cfc00',
87+
'limegreen' => '#32cd32',
88+
'palegreen' => '#98fb98',
89+
'lightgreen' => '#90ee90',
90+
'mediumspringgreen' => '#00fa9a',
91+
'springgreen' => '#00ff7f',
92+
'mediumseagreen' => '#3cb371',
93+
'seagreen' => '#2e8b57',
94+
'forestgreen' => '#228b22',
95+
'darkgreen' => '#006400',
96+
'yellowgreen' => '#9acd32',
97+
'olivedrab' => '#6b8e23',
98+
'darkolivegreen' => '#556b2f',
99+
'mediumaquamarine' => '#66cdaa',
100+
'darkseagreen' => '#8fbc8b',
101+
'lightseagreen' => '#20b2aa',
102+
'darkcyan' => '#008b8b',
103+
'lightcyan' => '#e0ffff',
104+
'paleturquoise' => '#afeeee',
105+
'aquamarine' => '#7fffd4',
106+
'turquoise' => '#40e0d0',
107+
'mediumturquoise' => '#48d1cc',
108+
'darkturquoise' => '#00ced1',
109+
'cadetblue' => '#5f9ea0',
110+
'steelblue' => '#4682b4',
111+
'lightsteelblue' => '#b0c4de',
112+
'powderblue' => '#b0e0e6',
113+
'lightblue' => '#add8e6',
114+
'skyblue' => '#87ceeb',
115+
'lightskyblue' => '#87cefa',
116+
'deepskyblue' => '#00bfff',
117+
'dodgerblue' => '#1e90ff',
118+
'cornflowerblue' => '#6495ed',
119+
'royalblue' => '#4169e1',
120+
'mediumblue' => '#0000cd',
121+
'darkblue' => '#00008b',
122+
'midnightblue' => '#191970',
123+
'cornsilk' => '#fff8dc',
124+
'blanchedalmond' => '#ffebcd',
125+
'navajowhite' => '#ffdead',
126+
'burlywood' => '#deb887',
127+
'rosybrown' => '#bc8f8f',
128+
'sandybrown' => '#f4a460',
129+
'goldenrod' => '#daa520',
130+
'darkgoldenrod' => '#b8860b',
131+
'chocolate' => '#d2691e',
132+
'saddlebrown' => '#8b4513',
133+
'honeydew' => '#f0fff0',
134+
'mintcream' => '#f5fffa',
135+
'aliceblue' => '#f0f8ff',
136+
'ghostwhite' => '#f8f8ff',
137+
'whitesmoke' => '#f5f5f5',
138+
'seashell' => '#fff5ee',
139+
'oldlace' => '#fdf5e6',
140+
'floralwhite' => '#fffaf0',
141+
'antiquewhite' => '#faebd7',
142+
'lavenderblush' => '#fff0f5',
143+
'mistyrose' => '#ffe4e1',
144+
'gainsboro' => '#dcdcdc',
145+
'lightgray' => '#d3d3d3',
146+
'darkgray' => '#a9a9a9',
147+
'dimgray' => '#696969',
148+
'lightslategray' => '#778899',
149+
'slategray' => '#708090',
150+
'darkslategray' => '#2f4f4f'
151+
],
152+
'minify' => [
153+
'selectors' => true, // minify selectors where possible
154+
'semicolons' => true, // remove last semi-colon in each rule
155+
'zerounits' => true, // remove the unit from 0 values where possible (0px => 0)
156+
'leadingzeros' => true, // remove leading 0 from fractional values (0.5 => .5)
157+
'trailingzeros' => true, // remove any trailing 0's from fractional values (74.0 => 74)
158+
'decimalplaces' => 4, // maximum number of decimal places for a value
159+
'multiples' => true, // minify multiple values (margin: 20px 10px 20px 10px => margin: 20px 10px)
160+
'quotes' => true, // remove quotes where possible (background: url("test.png") => background: url(test.png))
161+
'convertquotes' => true, // convert single quotes to double quotes (content: '' => content: "")
162+
'colors' => true, // shorten hex values and replace with named values where shorter (color: #FF0000 => color: red)
163+
'time' => true, // shorten time values where possible (500ms => .5s)
164+
'fontweight' => true, // shorten font-weight values (font-weight: bold => font-weight: 700)
165+
'none' => true, // replace none with 0 where possible (border: none => border: 0)
166+
'lowerproperties' => true, // lowercase property names (DISPLAY: BLOCK => display: BLOCK)
167+
'lowervalues' => true, // lowercase values where possible (DISPLAY: BLOCK => DISPLAY: block)
168+
'empty' => true // delete empty rules and @directives
169+
],
170+
'output' => [
171+
'style' => 'minify', // the output style, either 'minify' or 'beautify'
172+
'prefix' => '' // a string to prefix every line with in beautify mode, used for adding indents to
173+
]
174+
];
175+
}

src/cssdoc.php

Lines changed: 1 addition & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace hexydec\css;
44
use \hexydec\tokens\tokenise;
55

6-
class cssdoc implements \ArrayAccess, \Iterator {
6+
class cssdoc extends config implements \ArrayAccess, \Iterator {
77

88
/**
99
* @var array<string> $tokens Regexp components keyed by their corresponding codename for tokenising CSS
@@ -29,175 +29,6 @@ class cssdoc implements \ArrayAccess, \Iterator {
2929
'string' => '(?:[^\\/\\[\\]{}\\(\\):;,\\*>+~\\^$!"\' \\n\\r\\t]++|\\\\.)',
3030
];
3131

32-
/**
33-
* @var array<array> $config Object configuration array
34-
*/
35-
protected array $config = [
36-
'nested' => ['@media', '@supports', '@keyframes', '@-webkit-keyframes', '@-moz-keyframes', '@-o-keyframes', '@document', '@-moz-document', '@container'], // directive that can have nested rules
37-
'spaced' => ['calc', 'min', 'max', 'clamp'], // values where spaces between operators must be retained
38-
'quoted' => ['content', 'format', 'counters', '@charset', 'syntax', 'font-feature-settings', '-webkit-font-feature-settings', '-moz-font-feature-settings', 'quotes', 'text-overflow'], // directives or properties where the contained values must be quoted
39-
'casesensitive' => ['url'], // property values that should not be lowercased
40-
'none' => ['border', 'background', 'outline'], // properties that can be changed to 0 when none
41-
'multiples' => ['margin', 'padding', 'border-width', 'border-style', 'border-color', 'border-radius'],
42-
'colors' => [
43-
'#f0ffff' => 'azure',
44-
'#f5f5dc' => 'beige',
45-
'#ffe4c4' => 'bisque',
46-
'#a52a2a' => 'brown',
47-
'#ff7f50' => 'coral',
48-
'#ffd700' => 'gold',
49-
'#008000' => 'green',
50-
'#808080' => 'grey',
51-
'#4b0082' => 'indigo',
52-
'#fffff0' => 'ivory',
53-
'#f0e68c' => 'khaki',
54-
'#faf0e6' => 'linen',
55-
'#000080' => 'navy',
56-
'#808000' => 'olive',
57-
'#ffa500' => 'orange',
58-
'#da70d6' => 'orchid',
59-
'#cd853f' => 'peru',
60-
'#ffc0cb' => 'pink',
61-
'#dda0dd' => 'plum',
62-
'#f00' => 'red',
63-
'#fa8072' => 'salmon',
64-
'#a0522d' => 'sienna',
65-
'#c0c0c0' => 'silver',
66-
'#fffafa' => 'snow',
67-
'#d2b48c' => 'tan',
68-
'#008080' => 'teal',
69-
'#ff6347' => 'tomato',
70-
'#ee82ee' => 'violet',
71-
'#f5deb3' => 'wheat',
72-
'black' => '#000',
73-
'indianred' => '#cd5c5c',
74-
'lightcoral' => '#f08080',
75-
'darksalmon' => '#e9967a',
76-
'lightsalmon' => '#ffa07a',
77-
'crimson' => '#dc143c',
78-
'firebrick' => '#b22222',
79-
'darkred' => '#8b0000',
80-
'lightpink' => '#ffb6c1',
81-
'hotpink' => '#ff69b4',
82-
'deeppink' => '#ff1493',
83-
'mediumvioletred' => '#c71585',
84-
'palevioletred' => '#db7093',
85-
'orangered' => '#ff4500',
86-
'darkorange' => '#ff8c00',
87-
'lightyellow' => '#ffffe0',
88-
'lemonchiffon' => '#fffacd',
89-
'lightgoldenrodyellow' => '#fafad2',
90-
'papayawhip' => '#ffefd5',
91-
'moccasin' => '#ffe4b5',
92-
'peachpuff' => '#ffdab9',
93-
'palegoldenrod' => '#eee8aa',
94-
'darkkhaki' => '#bdb76b',
95-
'lavender' => '#e6e6fa',
96-
'thistle' => '#d8bfd8',
97-
'fuchsia' => '#ff00ff',
98-
'magenta' => '#ff00ff',
99-
'mediumorchid' => '#ba55d3',
100-
'mediumpurple' => '#9370db',
101-
'rebeccapurple' => '#663399',
102-
'blueviolet' => '#8a2be2',
103-
'darkviolet' => '#9400d3',
104-
'darkorchid' => '#9932cc',
105-
'darkmagenta' => '#8b008b',
106-
'slateblue' => '#6a5acd',
107-
'darkslateblue' => '#483d8b',
108-
'mediumslateblue' => '#7b68ee',
109-
'greenyellow' => '#adff2f',
110-
'chartreuse' => '#7fff00',
111-
'lawngreen' => '#7cfc00',
112-
'limegreen' => '#32cd32',
113-
'palegreen' => '#98fb98',
114-
'lightgreen' => '#90ee90',
115-
'mediumspringgreen' => '#00fa9a',
116-
'springgreen' => '#00ff7f',
117-
'mediumseagreen' => '#3cb371',
118-
'seagreen' => '#2e8b57',
119-
'forestgreen' => '#228b22',
120-
'darkgreen' => '#006400',
121-
'yellowgreen' => '#9acd32',
122-
'olivedrab' => '#6b8e23',
123-
'darkolivegreen' => '#556b2f',
124-
'mediumaquamarine' => '#66cdaa',
125-
'darkseagreen' => '#8fbc8b',
126-
'lightseagreen' => '#20b2aa',
127-
'darkcyan' => '#008b8b',
128-
'lightcyan' => '#e0ffff',
129-
'paleturquoise' => '#afeeee',
130-
'aquamarine' => '#7fffd4',
131-
'turquoise' => '#40e0d0',
132-
'mediumturquoise' => '#48d1cc',
133-
'darkturquoise' => '#00ced1',
134-
'cadetblue' => '#5f9ea0',
135-
'steelblue' => '#4682b4',
136-
'lightsteelblue' => '#b0c4de',
137-
'powderblue' => '#b0e0e6',
138-
'lightblue' => '#add8e6',
139-
'skyblue' => '#87ceeb',
140-
'lightskyblue' => '#87cefa',
141-
'deepskyblue' => '#00bfff',
142-
'dodgerblue' => '#1e90ff',
143-
'cornflowerblue' => '#6495ed',
144-
'royalblue' => '#4169e1',
145-
'mediumblue' => '#0000cd',
146-
'darkblue' => '#00008b',
147-
'midnightblue' => '#191970',
148-
'cornsilk' => '#fff8dc',
149-
'blanchedalmond' => '#ffebcd',
150-
'navajowhite' => '#ffdead',
151-
'burlywood' => '#deb887',
152-
'rosybrown' => '#bc8f8f',
153-
'sandybrown' => '#f4a460',
154-
'goldenrod' => '#daa520',
155-
'darkgoldenrod' => '#b8860b',
156-
'chocolate' => '#d2691e',
157-
'saddlebrown' => '#8b4513',
158-
'honeydew' => '#f0fff0',
159-
'mintcream' => '#f5fffa',
160-
'aliceblue' => '#f0f8ff',
161-
'ghostwhite' => '#f8f8ff',
162-
'whitesmoke' => '#f5f5f5',
163-
'seashell' => '#fff5ee',
164-
'oldlace' => '#fdf5e6',
165-
'floralwhite' => '#fffaf0',
166-
'antiquewhite' => '#faebd7',
167-
'lavenderblush' => '#fff0f5',
168-
'mistyrose' => '#ffe4e1',
169-
'gainsboro' => '#dcdcdc',
170-
'lightgray' => '#d3d3d3',
171-
'darkgray' => '#a9a9a9',
172-
'dimgray' => '#696969',
173-
'lightslategray' => '#778899',
174-
'slategray' => '#708090',
175-
'darkslategray' => '#2f4f4f'
176-
],
177-
'minify' => [
178-
'selectors' => true, // minify selectors where possible
179-
'semicolons' => true, // remove last semi-colon in each rule
180-
'zerounits' => true, // remove the unit from 0 values where possible (0px => 0)
181-
'leadingzeros' => true, // remove leading 0 from fractional values (0.5 => .5)
182-
'trailingzeros' => true, // remove any trailing 0's from fractional values (74.0 => 74)
183-
'decimalplaces' => 4, // maximum number of decimal places for a value
184-
'multiples' => true, // minify multiple values (margin: 20px 10px 20px 10px => margin: 20px 10px)
185-
'quotes' => true, // remove quotes where possible (background: url("test.png") => background: url(test.png))
186-
'convertquotes' => true, // convert single quotes to double quotes (content: '' => content: "")
187-
'colors' => true, // shorten hex values and replace with named values where shorter (color: #FF0000 => color: red)
188-
'time' => true, // shorten time values where possible (500ms => .5s)
189-
'fontweight' => true, // shorten font-weight values (font-weight: bold => font-weight: 700)
190-
'none' => true, // replace none with 0 where possible (border: none => border: 0)
191-
'lowerproperties' => true, // lowercase property names (DISPLAY: BLOCK => display: BLOCK)
192-
'lowervalues' => true, // lowercase values where possible (DISPLAY: BLOCK => DISPLAY: block)
193-
'empty' => true // delete empty rules and @directives
194-
],
195-
'output' => [
196-
'style' => 'minify', // the output style, either 'minify' or 'beautify'
197-
'prefix' => '' // a string to prefix every line with in beautify mode, used for adding indents to
198-
]
199-
];
200-
20132
/**
20233
* @var ?document $document The root document
20334
*/

0 commit comments

Comments
 (0)