C:\xampp\htdocs\landing\wp-content\plugins\amp\vendor\ampproject\optimizer\src\CssRules.php


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
<?php

namespace AmpProject\Optimizer;

/**
 * Collection of CSS rules.
 *
 * This is used in conjunction with CssRule for deduplication of CSS when adding styles during transformations.
 *
 * Note: This is a simplistic representation of CSS rules built for a specific purpose.
 * Make sure it supports a given use case before including in new code!
 *
 * @package ampproject/optimizer
 */
final class CssRules
{

    
/**
     * Internal array of CssRule objects.
     *
     * @var CssRule[]
     */
    
private $cssRules = [];

    
/**
     * Rendered CSS cache.
     *
     * @var string|null
     */
    
private $renderedCss;

    
/**
     * Byte count cache.
     *
     * @var int|null
     */
    
private $byteCount;

    
/**
     * Create a new CssRules collection from an array of CssRule objects.
     *
     * @param CssRule[] $cssRuleArray Array of CssRule objects.
     * @return CssRules CSS rules collection.
     */
    
public static function fromCssRuleArray($cssRuleArray)
    {
        
$cssRules = new self();

        
array_walk(
            
$cssRuleArray,
            static function (
CssRule $cssRule) use (&$cssRules) {
                
$cssRules $cssRules->add($cssRule);
            }
        );

        return 
$cssRules;
    }

    
/**
     * Add a CSS rule to the collection.
     *
     * @param CssRule $cssRule
     * @return CssRules Adapted collection with the added CSS rule.
     */
    
public function add(CssRule $cssRule)
    {
        
$clone = clone $this;

        if (empty(
$clone->cssRules)) {
            
$clone->cssRules = [$cssRule];

            return 
$clone;
        }

        foreach (
$clone->cssRules as $index => $existingCssRule) {
            if (
$existingCssRule->canBeMerged($cssRule)) {
                
$clone->cssRules[$index] = $existingCssRule->mergeWith($cssRule);
                
// Rendered CSS and byte count need to be rebuilt, as some previously rendered CSS rule has changed.
                
$clone->renderedCss null;
                
$clone->byteCount   null;

                return 
$clone;
            }
        }

        
$clone->cssRules[] = $cssRule;

        if (
$clone->renderedCss !== null) {
            
// As we didn't merge, we can save rerendering and just concat the single rule.
            
$clone->renderedCss .= $cssRule->getCss();
        }

        if (
$clone->byteCount !== null) {
            
// As we didn't merge, we can save recounting and just add the bytes of the single rule.
            
$clone->byteCount += $cssRule->getByteCount();
        }

        return 
$clone;
    }

    
/**
     * Get the CSS for the entire collection of CSS rules.
     *
     * @return string String representation of the collection of CSS rules.
     */
    
public function getCss()
    {
        if (
$this->renderedCss === null) {
            
$this->renderedCss array_reduce(
                
$this->cssRules,
                static function (
$cssCssRule $cssRule) {
                    return 
$css $cssRule->getCss();
                },
                
''
            
);
        }

        return 
$this->renderedCss;
    }

    
/**
     * Get the byte count for the entire collection of CSS rules.
     *
     * @return int Byte count of the collection of CSS rules.
     */
    
public function getByteCount()
    {
        if (
$this->byteCount === null) {
            
$this->byteCount array_reduce(
                
$this->cssRules,
                static function (
$byteCountCssRule $cssRule) {
                    return 
$byteCount $cssRule->getByteCount();
                },
                
0
            
);
        }

        return 
$this->byteCount;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586