Subversion Repositories PHPX

Rev

Rev 37 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37 Rev 38
Line 1... Line 1...
1
<?php
1
<?php
2
2
3
namespace de\pointedears\css\least;
3
namespace de\pointedears\css\least;
4
4
5
/**
5
/**
6
 * Mix-ins for the LEAST extended CSS parser
6
 * Mix-ins for the LEAST CSS preprocessor
7
 *
7
 *
8
 * @author Thomas 'PointedEars' Lahn &lt;php@PointedEars.de&gt;
8
 * @author Thomas 'PointedEars' Lahn &lt;php@PointedEars.de&gt;
9
 */
9
 */
10
abstract class Mixins
10
abstract class Mixins
11
{
11
{
-
 
12
        /** @section General functions */
-
 
13
       
12
  /**
14
  /**
13
   * Generates a CSS property declaration whose value is a
15
   * Generates a CSS section for each keyword prefix.
14
   * <code>linear-gradient()</code> function call for
-
 
15
   * supported function name prefixes.
-
 
16
   *
16
   *
17
   * @param string $property
17
   * @param string $keyword
18
   *   Property to be declared
18
   *  Section keyword
19
   * @param string $params
19
   * @param string $params
20
   *   Parameters to the <code>linear-gradient()</code> function
20
   *   Section parameters (name, medium, etc.)
-
 
21
   * @param string $content
-
 
22
   *   Section content
21
   * @param array $prefixes
23
   * @param array[string] $prefixes
22
   *   Pass to override supported function name prefixes
24
   *   Keyword prefixes
23
   */
25
   */
24
  public static function linear_gradient ($property, $params,
26
        public static function prefix_section ($keyword, $params,
25
    array $prefixes = array('-moz-', '-o-', '-webkit-', ''))
27
          $content, array $prefixes)
26
  {
28
  {
27
    ob_start();
29
    ob_start();
28
    foreach ($prefixes as $prefix)
30
    foreach ($prefixes as $prefix)
29
    {
31
    {
30
      echo "{$property}: {$prefix}linear-gradient({$params});\n";
32
      echo "@{$prefix}{$keyword} {$params} {\n  {$content}\n}\n";
31
    }
33
    }
32
    ob_end_flush();
34
    ob_end_flush();
33
        }
35
        }
34
36
 
35
  /**
37
  /**
36
   * Generates a CSS property declaration whose value is a
38
   * Generates a CSS property declaration whose value is a
37
   * <code>radial-gradient()</code> function call for
-
 
38
   * supported function name prefixes.
39
   * function call, for each function name prefix.
39
   *
40
   *
40
   * @param string $property
41
   * @param string $property
41
   *   Property to be declared
42
   *   Property to be declared
-
 
43
   * @param string $function
-
 
44
   *   CSS function to be called
42
   * @param string $params
45
   * @param string $args
43
   *   Parameters to the <code>radial-gradient()</code> function
46
   *   Arguments to the function
44
   * @param array $prefixes
47
   * @param array[string] $prefixes
45
   *   Pass to override supported function name prefixes
48
   *   Function name prefixes
46
   */
49
   */
47
        public static function radial_gradient ($property, $params,
50
  public static function prefix_function ($property, $function, $args,
-
 
51
    array $prefixes)
-
 
52
  {
-
 
53
    ob_start();
48
    array $prefixes = array('-moz-', '-webkit-'))
54
    foreach ($prefixes as $prefix)
-
 
55
    {
-
 
56
      echo "{$property}: {$prefix}{$function}({$args});\n";
-
 
57
    }
-
 
58
    ob_end_flush();
-
 
59
  }
-
 
60
 
-
 
61
  /**
-
 
62
   * Generates a CSS property declaration for each
-
 
63
   * property name prefix.
-
 
64
   *
-
 
65
   * @param string $suffix
-
 
66
   *   Property name suffix
-
 
67
   * @param string $value
-
 
68
   *   Property value
-
 
69
   * @param array[string] $prefixes
-
 
70
   *   Property name prefixes
-
 
71
   */
-
 
72
  public static function prefix_property ($property, $suffix, $value,
-
 
73
    array $prefixes)
49
  {
74
  {
50
    ob_start();
75
    ob_start();
51
    foreach ($prefixes as $prefix)
76
    foreach ($prefixes as $prefix)
52
    {
77
    {
53
      echo "{$property}: {$prefix}radial-gradient({$params});\n";
78
      echo "{$prefix}{$property}{$suffix}: {$value};\n";
54
    }
79
    }
55
    ob_end_flush();
80
    ob_end_flush();
-
 
81
  }
-
 
82
 
-
 
83
        /** @section Gradients */
-
 
84
       
-
 
85
  /**
-
 
86
   * Generates a CSS property declaration whose value is a
-
 
87
   * <code>linear-gradient()</code> function call for
-
 
88
   * each function name prefix.
-
 
89
   *
-
 
90
   * @param string $property
-
 
91
   *   Property to be declared
-
 
92
   * @param string $args
-
 
93
   *   Arguments to the <code>linear-gradient()</code> function
-
 
94
   * @param array[string] $prefixes (optional)
-
 
95
   *   Pass to override supported function name prefixes
-
 
96
   * @see self::prefix_function()
-
 
97
   */
-
 
98
  public static function linear_gradient ($property, $args,
-
 
99
    array $prefixes = array('-moz-', '-o-', '-webkit-', ''))
-
 
100
  {
-
 
101
    self::prefix_function($property, 'linear-gradient', $args, $prefixes);
-
 
102
        }
-
 
103
-
 
104
  /**
-
 
105
   * Generates a CSS property declaration whose value is a
-
 
106
   * <code>radial-gradient()</code> function call for each
-
 
107
   * function name prefix.
-
 
108
   *
-
 
109
   * @param string $property
-
 
110
   *   Property to be declared
-
 
111
   * @param string $args
-
 
112
   *   Arguments to the <code>radial-gradient()</code> function
-
 
113
   * @param array[string] $prefixes (optional)
-
 
114
   *   Pass to override supported function name prefixes
-
 
115
   * @see self::prefix_function()
-
 
116
   */
-
 
117
        public static function radial_gradient ($property, $args,
-
 
118
    array $prefixes = array('-moz-', '-webkit-'))
-
 
119
  {
-
 
120
    self::prefix_function($property, 'radial-gradient', $args, $prefixes);
56
        }
121
        }
57
       
122
       
58
  /**
123
  /**
59
   * Generates a CSS <code>transition</code> property declaration
124
   * Generates a CSS <code>transition</code> property declaration
60
   * for supported property name prefixes.
125
   * for each property name prefix.
61
   *
126
   *
62
   * @param string $suffix
127
   * @param string $suffix
63
   *   Property name suffix
128
   *   Property name suffix
64
   * @param string $value
129
   * @param string $value
65
   *   Property value
130
   *   Property value
66
   * @param array $prefixes
131
   * @param array[string] $prefixes (optional)
67
   *   Pass to override supported property name prefixes
132
   *   Pass to override supported property name prefixes
-
 
133
   * @see self::prefix_property()
68
   */
134
   */
69
        public static function transition ($suffix, $value,
135
        public static function transition ($suffix, $value,
70
    array $prefixes = array('-moz-', '-webkit-', ''))
136
    array $prefixes = array('-moz-', '-webkit-', ''))
71
  {
137
  {
72
    ob_start();
-
 
73
    foreach ($prefixes as $prefix)
-
 
74
    {
-
 
75
      echo "{$prefix}transition{$suffix}: {$value};\n";
138
    self::prefix_property('transition', $suffix, $value, $prefixes);
76
    }
-
 
77
    ob_end_flush();
-
 
78
        }
139
        }
79
140
-
 
141
        /** @section Animations */
-
 
142
       
80
  /**
143
  /**
81
   * Generates a CSS <code>@keyframes</code> section for
144
   * Generates a CSS <code>@keyframes</code> section for
82
   * supported keyword prefixes.
145
   * each keyword prefix.
83
   *
146
   *
84
   * @param string $name
147
   * @param string $name
85
   *   Animation name as referred by the <code>animation-name</code>
148
   *   Animation name as referred by an <code>animation-name</code>
86
   *   property declaration.
149
   *   property value.
87
   * @param string $data
150
   * @param string $data
88
   *   Keyframes data
151
   *   Keyframes data
89
   * @param array $prefixes
152
   * @param array[string] $prefixes (optional)
90
   *   Pass to override supported keyword prefixes
153
   *   Pass to override supported keyword prefixes
-
 
154
   * @see self::prefix_section()
91
   */
155
   */
92
        public static function keyframes ($name, $data,
156
        public static function keyframes ($name, $data,
93
    array $prefixes = array('-moz-', '-webkit-', ''))
157
    array $prefixes = array('-moz-', '-webkit-', ''))
94
  {
158
  {
95
    ob_start();
-
 
96
    foreach ($prefixes as $prefix)
-
 
97
    {
-
 
98
      echo "@{$prefix}keyframes {$name} {\n  {$data}\n}\n";
159
    self::prefix_section('keyframes', $name, $data, $prefixes);
99
    }
-
 
100
    ob_end_flush();
-
 
101
        }
160
        }
102
161
103
  /**
162
  /**
104
   * Generates a CSS <code>animation</code> property declaration
163
   * Generates a CSS <code>animation</code> property declaration
105
   * for supported property name prefixes.
164
   * for each property name prefix.
106
   *
165
   *
107
   * @param string $suffix
166
   * @param string $suffix
-
 
167
   *   Property name suffix, e.g. <tt>"-name"</tt> for
108
   *   Property name suffix
168
   *   <code>animation-name</code>
109
   * @param string $value
169
   * @param string $value
110
   *   Property value
170
   *   Property value
111
   * @param array $prefixes
171
   * @param array[string] $prefixes (optional)
112
   *   Pass to override supported property name prefixes
172
   *   Pass to override supported property name prefixes
-
 
173
   * @see self::prefix_property()
113
   */
174
   */
114
        public static function animation ($suffix, $value,
175
        public static function animation ($suffix, $value,
115
    array $prefixes = array('-moz-', '-webkit-', ''))
176
    array $prefixes = array('-moz-', '-webkit-', ''))
116
  {
177
  {
117
    ob_start();
-
 
118
    foreach ($prefixes as $prefix)
-
 
119
    {
-
 
120
      echo "{$prefix}animation{$suffix}: {$value};\n";
178
    self::prefix_property('animation', $suffix, $value, $prefixes);
121
    }
-
 
122
    ob_end_flush();
-
 
123
        }
179
        }
124
}
180
}
125
181