csso-rails 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +16 -0
- data/Gemfile +0 -5
- data/Gemfile.lock +13 -4
- data/Rakefile +2 -2
- data/csso-rails.gemspec +1 -0
- data/gemfiles/sprockets_2.gemfile +7 -0
- data/gemfiles/sprockets_2.gemfile.lock +39 -0
- data/gemfiles/sprockets_3.gemfile +7 -0
- data/gemfiles/sprockets_3.gemfile.lock +35 -0
- data/gemfiles/therubyracer.gemfile +5 -0
- data/gemfiles/therubyracer.gemfile.lock +29 -0
- data/lib/csso.rb +1 -1
- data/lib/csso/compressor.rb +22 -2
- data/lib/csso/csso.js.erb +10 -11
- data/lib/csso/version.rb +1 -1
- data/spec/csso/sprockets_integration_spec.rb +51 -0
- data/spec/fixtures/test.css +5 -0
- data/vendor/csso/csso.js +7 -3919
- metadata +28 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38bf321ba8374e47a1f0c899e0d437ee04de5ddd
|
4
|
+
data.tar.gz: 4925f034d8b9fb98cb0fdcb8f3422b433171ed82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9428931300b3a2d07e4abb838351592f11b0df827225ece7448b57d69cb1abbb1a9e98e185f7f98a92b4f1b7e031c593e8ca0fe573f8fe0529601de976bb2ed
|
7
|
+
data.tar.gz: 0a48e62e8b2860c2714714d4960dd948bad2cca2cf4eb591cc43fe71348c6a56903c2081856cacfc586eaf20f11a4e4e49997d44befd23882f1c7a68e038545d
|
data/Appraisals
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# to test against all, run: appraisal rake spec
|
2
|
+
|
3
|
+
# sprockets-1 is unsupported
|
4
|
+
|
5
|
+
appraise "sprockets-2" do
|
6
|
+
gem "sprockets", "~>2.0"
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "sprockets-3" do
|
10
|
+
gem "sprockets", "~>3.0"
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise "therubyracer" do
|
14
|
+
#TODO: currently rubyracer segfaults on my machine, fix that and start testing
|
15
|
+
# gem "therubyracer"
|
16
|
+
end
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,20 +1,29 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
csso-rails (0.
|
4
|
+
csso-rails (0.4.0)
|
5
5
|
execjs (>= 1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
appraisal (2.1.0)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
thor (>= 0.14.0)
|
14
|
+
execjs (2.6.0)
|
15
|
+
minitest (5.8.4)
|
16
|
+
rake (10.5.0)
|
17
|
+
thor (0.19.1)
|
13
18
|
|
14
19
|
PLATFORMS
|
15
20
|
ruby
|
16
21
|
|
17
22
|
DEPENDENCIES
|
23
|
+
appraisal
|
18
24
|
csso-rails!
|
19
25
|
minitest
|
20
26
|
rake
|
27
|
+
|
28
|
+
BUNDLED WITH
|
29
|
+
1.11.2
|
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ file 'csso' do
|
|
21
21
|
`git clone --single-branch --depth 1 --no-hardlinks git://github.com/css/csso`
|
22
22
|
Dir.chdir('csso'){
|
23
23
|
puts 'Now making web-version, just in case.'
|
24
|
-
`
|
24
|
+
`npm install && npm run browserify`
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
@@ -31,7 +31,7 @@ task :update_csso_repo => :csso do
|
|
31
31
|
Dir.chdir('csso'){
|
32
32
|
puts 'Updating csso...'
|
33
33
|
`git pull --rebase`
|
34
|
-
`
|
34
|
+
`npm install && npm run browserify`
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
data/csso-rails.gemspec
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
csso-rails (0.4.0)
|
5
|
+
execjs (>= 1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (2.1.0)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
thor (>= 0.14.0)
|
14
|
+
execjs (2.6.0)
|
15
|
+
hike (1.2.3)
|
16
|
+
minitest (5.8.4)
|
17
|
+
multi_json (1.11.2)
|
18
|
+
rack (1.6.4)
|
19
|
+
rake (10.5.0)
|
20
|
+
sprockets (2.12.4)
|
21
|
+
hike (~> 1.2)
|
22
|
+
multi_json (~> 1.0)
|
23
|
+
rack (~> 1.0)
|
24
|
+
tilt (~> 1.1, != 1.3.0)
|
25
|
+
thor (0.19.1)
|
26
|
+
tilt (1.4.1)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
appraisal
|
33
|
+
csso-rails!
|
34
|
+
minitest
|
35
|
+
rake
|
36
|
+
sprockets (~> 2.0)
|
37
|
+
|
38
|
+
BUNDLED WITH
|
39
|
+
1.11.2
|
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
csso-rails (0.4.0)
|
5
|
+
execjs (>= 1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (2.1.0)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
thor (>= 0.14.0)
|
14
|
+
concurrent-ruby (1.0.0)
|
15
|
+
execjs (2.6.0)
|
16
|
+
minitest (5.8.4)
|
17
|
+
rack (1.6.4)
|
18
|
+
rake (10.5.0)
|
19
|
+
sprockets (3.5.2)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
rack (> 1, < 3)
|
22
|
+
thor (0.19.1)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
appraisal
|
29
|
+
csso-rails!
|
30
|
+
minitest
|
31
|
+
rake
|
32
|
+
sprockets (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.11.2
|
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
csso-rails (0.4.0)
|
5
|
+
execjs (>= 1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (2.1.0)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
thor (>= 0.14.0)
|
14
|
+
execjs (2.6.0)
|
15
|
+
minitest (5.8.4)
|
16
|
+
rake (10.5.0)
|
17
|
+
thor (0.19.1)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
appraisal
|
24
|
+
csso-rails!
|
25
|
+
minitest
|
26
|
+
rake
|
27
|
+
|
28
|
+
BUNDLED WITH
|
29
|
+
1.11.2
|
data/lib/csso.rb
CHANGED
@@ -10,7 +10,7 @@ module Csso
|
|
10
10
|
|
11
11
|
def self.install(sprockets)
|
12
12
|
if sprockets.respond_to? :register_compressor
|
13
|
-
sprockets.register_compressor('text/css', :csso, Compressor
|
13
|
+
sprockets.register_compressor('text/css', :csso, Compressor)
|
14
14
|
sprockets.css_compressor = :csso
|
15
15
|
else
|
16
16
|
Sprockets::Compressors.register_css_compressor(:csso, 'Csso::Compressor', :default => true)
|
data/lib/csso/compressor.rb
CHANGED
@@ -1,9 +1,29 @@
|
|
1
1
|
module Csso
|
2
2
|
class Compressor
|
3
|
-
def
|
3
|
+
def self.call(input)
|
4
4
|
require 'csso'
|
5
5
|
#TODO: settings?
|
6
|
-
|
6
|
+
#TODO: handle metadata somehow?
|
7
|
+
{
|
8
|
+
data: Csso.optimize(input[:data], true)
|
9
|
+
}
|
7
10
|
end
|
11
|
+
|
12
|
+
# sprockets 2:
|
13
|
+
|
14
|
+
def initialize path, &block
|
15
|
+
@block = block
|
16
|
+
end
|
17
|
+
|
18
|
+
def render context, opts={}
|
19
|
+
self.class.call({data: @block.call})[:data]
|
20
|
+
end
|
21
|
+
|
22
|
+
class Legacy
|
23
|
+
def self.compress data
|
24
|
+
Compressor.call(data: data)[:data]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
8
28
|
end
|
9
29
|
end
|
data/lib/csso/csso.js.erb
CHANGED
@@ -5,10 +5,15 @@ def file(filename)
|
|
5
5
|
File.read(filename).strip
|
6
6
|
end
|
7
7
|
|
8
|
+
def version package
|
9
|
+
require 'json'
|
10
|
+
JSON.parse(File.read(package))['version']
|
11
|
+
end
|
12
|
+
|
8
13
|
%>/*
|
9
14
|
<%= " THIS FILE IS AUTOGENERATED! DO NOT EDIT!\n See #{__FILE__} instead." %>
|
10
15
|
|
11
|
-
Based on <%=
|
16
|
+
Based on <%= version 'csso/package.json' %> revision <%= file 'csso/.git/refs/heads/master' %>
|
12
17
|
*/
|
13
18
|
|
14
19
|
console = {
|
@@ -18,16 +23,10 @@ console = {
|
|
18
23
|
}
|
19
24
|
};
|
20
25
|
|
21
|
-
<%= file 'csso/
|
26
|
+
<%= file 'csso/dist/csso-browser.js' %>
|
22
27
|
|
23
28
|
do_compression = function(css, disable_structural){
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
compressor.compress(
|
28
|
-
srcToCSSP(css, 'stylesheet', true),
|
29
|
-
disable_structural
|
30
|
-
)
|
31
|
-
)
|
32
|
-
);
|
29
|
+
return csso.minify(css, {
|
30
|
+
restructuring: !disable_structural
|
31
|
+
});
|
33
32
|
};
|
data/lib/csso/version.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'csso'
|
6
|
+
|
7
|
+
Encoding.default_external = Encoding::UTF_8
|
8
|
+
|
9
|
+
describe Csso do
|
10
|
+
|
11
|
+
subject { Csso }
|
12
|
+
let(:sprockets_env){
|
13
|
+
e = Sprockets::Environment.new(File.expand_path('../', File.dirname(__FILE__)))
|
14
|
+
e.append_path 'fixtures'
|
15
|
+
e.config = e.config.merge(gzip_enabled: false).freeze if e.respond_to? :config
|
16
|
+
e
|
17
|
+
}
|
18
|
+
let(:result_dir){
|
19
|
+
d = File.expand_path('../fixtures/res', File.dirname(__FILE__))
|
20
|
+
FileUtils.mkdir_p(d)
|
21
|
+
d
|
22
|
+
}
|
23
|
+
let(:manifest_file){
|
24
|
+
File.expand_path('manifest.json', result_dir)
|
25
|
+
}
|
26
|
+
let(:manifest){
|
27
|
+
Sprockets::Manifest.new(sprockets_env, result_dir, manifest_file)
|
28
|
+
}
|
29
|
+
|
30
|
+
it "installs" do
|
31
|
+
begin
|
32
|
+
require 'sprockets'
|
33
|
+
rescue LoadError
|
34
|
+
skip "Skipping sprockets integration, as there's no sprockets in this env"
|
35
|
+
end
|
36
|
+
|
37
|
+
subject.install(sprockets_env)
|
38
|
+
sprockets_env.css_compressor.must_equal Csso::Compressor
|
39
|
+
manifest.environment.must_equal(sprockets_env)
|
40
|
+
manifest.clobber
|
41
|
+
res = manifest.compile('test.css')
|
42
|
+
res.size.must_equal 1
|
43
|
+
[File.expand_path('../../fixtures/test.css', __FILE__), 'test.css'].must_include res.first
|
44
|
+
File.read(manifest_file).wont_equal '{}'
|
45
|
+
sprockets_env['test.css'].source.must_equal '.class{color:red}'
|
46
|
+
manifest.clobber
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
end
|
data/vendor/csso/csso.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
THIS FILE IS AUTOGENERATED! DO NOT EDIT!
|
3
3
|
See lib/csso/csso.js.erb instead.
|
4
4
|
|
5
|
-
Based on
|
5
|
+
Based on 1.5.3 revision 9183f49fcbfb2fc1e737896deeeba485edbc52a9
|
6
6
|
*/
|
7
7
|
|
8
8
|
console = {
|
@@ -12,3924 +12,12 @@ console = {
|
|
12
12
|
}
|
13
13
|
};
|
14
14
|
|
15
|
-
var $util = {};
|
16
|
-
|
17
|
-
$util.cleanInfo = function(tree) {
|
18
|
-
var r = [];
|
19
|
-
tree = tree.slice(1);
|
20
|
-
|
21
|
-
tree.forEach(function(e) {
|
22
|
-
r.push(Array.isArray(e) ? $util.cleanInfo(e) : e);
|
23
|
-
});
|
24
|
-
|
25
|
-
return r;
|
26
|
-
};
|
27
|
-
|
28
|
-
$util.treeToString = function(tree, level) {
|
29
|
-
var spaces = $util.dummySpaces(level),
|
30
|
-
level = level ? level : 0,
|
31
|
-
s = (level ? '\n' + spaces : '') + '[';
|
32
|
-
|
33
|
-
tree.forEach(function(e) {
|
34
|
-
s += (Array.isArray(e) ? $util.treeToString(e, level + 1) : e.f !== undefined ? $util.ircToString(e) : ('\'' + e.toString() + '\'')) + ', ';
|
35
|
-
});
|
36
|
-
|
37
|
-
return s.substr(0, s.length - 2) + ']';
|
38
|
-
};
|
39
|
-
|
40
|
-
$util.ircToString = function(o) {
|
41
|
-
return '{' + o.f + ',' + o.l + '}';
|
42
|
-
};
|
43
|
-
|
44
|
-
$util.dummySpaces = function(num) {
|
45
|
-
return ' '.substr(0, num * 2);
|
46
|
-
};
|
47
|
-
function srcToCSSP(s, rule, _needInfo) {
|
48
|
-
var TokenType = {
|
49
|
-
StringSQ: 'StringSQ',
|
50
|
-
StringDQ: 'StringDQ',
|
51
|
-
CommentML: 'CommentML',
|
52
|
-
CommentSL: 'CommentSL',
|
53
|
-
|
54
|
-
Newline: 'Newline',
|
55
|
-
Space: 'Space',
|
56
|
-
Tab: 'Tab',
|
57
|
-
|
58
|
-
ExclamationMark: 'ExclamationMark', // !
|
59
|
-
QuotationMark: 'QuotationMark', // "
|
60
|
-
NumberSign: 'NumberSign', // #
|
61
|
-
DollarSign: 'DollarSign', // $
|
62
|
-
PercentSign: 'PercentSign', // %
|
63
|
-
Ampersand: 'Ampersand', // &
|
64
|
-
Apostrophe: 'Apostrophe', // '
|
65
|
-
LeftParenthesis: 'LeftParenthesis', // (
|
66
|
-
RightParenthesis: 'RightParenthesis', // )
|
67
|
-
Asterisk: 'Asterisk', // *
|
68
|
-
PlusSign: 'PlusSign', // +
|
69
|
-
Comma: 'Comma', // ,
|
70
|
-
HyphenMinus: 'HyphenMinus', // -
|
71
|
-
FullStop: 'FullStop', // .
|
72
|
-
Solidus: 'Solidus', // /
|
73
|
-
Colon: 'Colon', // :
|
74
|
-
Semicolon: 'Semicolon', // ;
|
75
|
-
LessThanSign: 'LessThanSign', // <
|
76
|
-
EqualsSign: 'EqualsSign', // =
|
77
|
-
GreaterThanSign: 'GreaterThanSign', // >
|
78
|
-
QuestionMark: 'QuestionMark', // ?
|
79
|
-
CommercialAt: 'CommercialAt', // @
|
80
|
-
LeftSquareBracket: 'LeftSquareBracket', // [
|
81
|
-
ReverseSolidus: 'ReverseSolidus', // \
|
82
|
-
RightSquareBracket: 'RightSquareBracket', // ]
|
83
|
-
CircumflexAccent: 'CircumflexAccent', // ^
|
84
|
-
LowLine: 'LowLine', // _
|
85
|
-
LeftCurlyBracket: 'LeftCurlyBracket', // {
|
86
|
-
VerticalLine: 'VerticalLine', // |
|
87
|
-
RightCurlyBracket: 'RightCurlyBracket', // }
|
88
|
-
Tilde: 'Tilde', // ~
|
89
|
-
|
90
|
-
Identifier: 'Identifier',
|
91
|
-
DecimalNumber: 'DecimalNumber'
|
92
|
-
};
|
93
|
-
|
94
|
-
function getTokens(s) {
|
95
|
-
var Punctuation,
|
96
|
-
urlMode = false,
|
97
|
-
blockMode = 0;
|
98
|
-
|
99
|
-
Punctuation = {
|
100
|
-
' ': TokenType.Space,
|
101
|
-
'\n': TokenType.Newline,
|
102
|
-
'\r': TokenType.Newline,
|
103
|
-
'\t': TokenType.Tab,
|
104
|
-
'!': TokenType.ExclamationMark,
|
105
|
-
'"': TokenType.QuotationMark,
|
106
|
-
'#': TokenType.NumberSign,
|
107
|
-
'$': TokenType.DollarSign,
|
108
|
-
'%': TokenType.PercentSign,
|
109
|
-
'&': TokenType.Ampersand,
|
110
|
-
'\'': TokenType.Apostrophe,
|
111
|
-
'(': TokenType.LeftParenthesis,
|
112
|
-
')': TokenType.RightParenthesis,
|
113
|
-
'*': TokenType.Asterisk,
|
114
|
-
'+': TokenType.PlusSign,
|
115
|
-
',': TokenType.Comma,
|
116
|
-
'-': TokenType.HyphenMinus,
|
117
|
-
'.': TokenType.FullStop,
|
118
|
-
'/': TokenType.Solidus,
|
119
|
-
':': TokenType.Colon,
|
120
|
-
';': TokenType.Semicolon,
|
121
|
-
'<': TokenType.LessThanSign,
|
122
|
-
'=': TokenType.EqualsSign,
|
123
|
-
'>': TokenType.GreaterThanSign,
|
124
|
-
'?': TokenType.QuestionMark,
|
125
|
-
'@': TokenType.CommercialAt,
|
126
|
-
'[': TokenType.LeftSquareBracket,
|
127
|
-
// '\\': TokenType.ReverseSolidus,
|
128
|
-
']': TokenType.RightSquareBracket,
|
129
|
-
'^': TokenType.CircumflexAccent,
|
130
|
-
'_': TokenType.LowLine,
|
131
|
-
'{': TokenType.LeftCurlyBracket,
|
132
|
-
'|': TokenType.VerticalLine,
|
133
|
-
'}': TokenType.RightCurlyBracket,
|
134
|
-
'~': TokenType.Tilde
|
135
|
-
};
|
136
|
-
|
137
|
-
function isDecimalDigit(c) {
|
138
|
-
return '0123456789'.indexOf(c) >= 0;
|
139
|
-
}
|
140
|
-
|
141
|
-
function throwError(message) {
|
142
|
-
throw message;
|
143
|
-
}
|
144
|
-
|
145
|
-
var buffer = '',
|
146
|
-
tokens = [],
|
147
|
-
pos,
|
148
|
-
tn = 0,
|
149
|
-
ln = 1;
|
150
|
-
|
151
|
-
function _getTokens(s) {
|
152
|
-
if (!s) return [];
|
153
|
-
|
154
|
-
tokens = [];
|
155
|
-
|
156
|
-
var c, cn;
|
157
|
-
|
158
|
-
for (pos = 0; pos < s.length; pos++) {
|
159
|
-
c = s.charAt(pos);
|
160
|
-
cn = s.charAt(pos + 1);
|
161
|
-
|
162
|
-
if (c === '/' && cn === '*') {
|
163
|
-
parseMLComment(s);
|
164
|
-
} else if (!urlMode && c === '/' && cn === '/') {
|
165
|
-
if (blockMode > 0) parseIdentifier(s);
|
166
|
-
else parseSLComment(s);
|
167
|
-
} else if (c === '"' || c === "'") {
|
168
|
-
parseString(s, c);
|
169
|
-
} else if (c === ' ') {
|
170
|
-
parseSpaces(s)
|
171
|
-
} else if (c in Punctuation) {
|
172
|
-
pushToken(Punctuation[c], c);
|
173
|
-
if (c === '\n' || c === '\r') ln++;
|
174
|
-
if (c === ')') urlMode = false;
|
175
|
-
if (c === '{') blockMode++;
|
176
|
-
if (c === '}') blockMode--;
|
177
|
-
} else if (isDecimalDigit(c)) {
|
178
|
-
parseDecimalNumber(s);
|
179
|
-
} else {
|
180
|
-
parseIdentifier(s);
|
181
|
-
}
|
182
|
-
}
|
183
|
-
|
184
|
-
mark();
|
185
|
-
|
186
|
-
return tokens;
|
187
|
-
}
|
188
|
-
|
189
|
-
function pushToken(type, value) {
|
190
|
-
tokens.push({ tn: tn++, ln: ln, type: type, value: value });
|
191
|
-
}
|
192
|
-
|
193
|
-
function parseSpaces(s) {
|
194
|
-
var start = pos;
|
195
|
-
|
196
|
-
for (; pos < s.length; pos++) {
|
197
|
-
if (s.charAt(pos) !== ' ') break;
|
198
|
-
}
|
199
|
-
|
200
|
-
pushToken(TokenType.Space, s.substring(start, pos));
|
201
|
-
pos--;
|
202
|
-
}
|
203
|
-
|
204
|
-
function parseMLComment(s) {
|
205
|
-
var start = pos;
|
206
|
-
|
207
|
-
for (pos = pos + 2; pos < s.length; pos++) {
|
208
|
-
if (s.charAt(pos) === '*') {
|
209
|
-
if (s.charAt(pos + 1) === '/') {
|
210
|
-
pos++;
|
211
|
-
break;
|
212
|
-
}
|
213
|
-
}
|
214
|
-
}
|
215
|
-
|
216
|
-
pushToken(TokenType.CommentML, s.substring(start, pos + 1));
|
217
|
-
}
|
218
|
-
|
219
|
-
function parseSLComment(s) {
|
220
|
-
var start = pos;
|
221
|
-
|
222
|
-
for (pos = pos + 2; pos < s.length; pos++) {
|
223
|
-
if (s.charAt(pos) === '\n' || s.charAt(pos) === '\r') {
|
224
|
-
pos++;
|
225
|
-
break;
|
226
|
-
}
|
227
|
-
}
|
228
|
-
|
229
|
-
pushToken(TokenType.CommentSL, s.substring(start, pos));
|
230
|
-
pos--;
|
231
|
-
}
|
232
|
-
|
233
|
-
function parseString(s, q) {
|
234
|
-
var start = pos;
|
235
|
-
|
236
|
-
for (pos = pos + 1; pos < s.length; pos++) {
|
237
|
-
if (s.charAt(pos) === '\\') pos++;
|
238
|
-
else if (s.charAt(pos) === q) break;
|
239
|
-
}
|
240
|
-
|
241
|
-
pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, s.substring(start, pos + 1));
|
242
|
-
}
|
243
|
-
|
244
|
-
function parseDecimalNumber(s) {
|
245
|
-
var start = pos;
|
246
|
-
|
247
|
-
for (; pos < s.length; pos++) {
|
248
|
-
if (!isDecimalDigit(s.charAt(pos))) break;
|
249
|
-
}
|
250
|
-
|
251
|
-
pushToken(TokenType.DecimalNumber, s.substring(start, pos));
|
252
|
-
pos--;
|
253
|
-
}
|
254
|
-
|
255
|
-
function parseIdentifier(s) {
|
256
|
-
var start = pos;
|
257
|
-
|
258
|
-
while (s.charAt(pos) === '/') pos++;
|
259
|
-
|
260
|
-
for (; pos < s.length; pos++) {
|
261
|
-
if (s.charAt(pos) === '\\') pos++;
|
262
|
-
else if (s.charAt(pos) in Punctuation) break;
|
263
|
-
}
|
264
|
-
|
265
|
-
var ident = s.substring(start, pos);
|
266
|
-
|
267
|
-
urlMode = urlMode || ident === 'url';
|
268
|
-
|
269
|
-
pushToken(TokenType.Identifier, ident);
|
270
|
-
pos--;
|
271
|
-
}
|
272
|
-
|
273
|
-
// ====================================
|
274
|
-
// second run
|
275
|
-
// ====================================
|
276
|
-
|
277
|
-
function mark() {
|
278
|
-
var ps = [], // Parenthesis
|
279
|
-
sbs = [], // SquareBracket
|
280
|
-
cbs = [], // CurlyBracket
|
281
|
-
t;
|
282
|
-
|
283
|
-
for (var i = 0; i < tokens.length; i++) {
|
284
|
-
t = tokens[i];
|
285
|
-
switch(t.type) {
|
286
|
-
case TokenType.LeftParenthesis:
|
287
|
-
ps.push(i);
|
288
|
-
break;
|
289
|
-
case TokenType.RightParenthesis:
|
290
|
-
if (ps.length) {
|
291
|
-
t.left = ps.pop();
|
292
|
-
tokens[t.left].right = i;
|
293
|
-
}
|
294
|
-
break;
|
295
|
-
case TokenType.LeftSquareBracket:
|
296
|
-
sbs.push(i);
|
297
|
-
break;
|
298
|
-
case TokenType.RightSquareBracket:
|
299
|
-
if (sbs.length) {
|
300
|
-
t.left = sbs.pop();
|
301
|
-
tokens[t.left].right = i;
|
302
|
-
}
|
303
|
-
break;
|
304
|
-
case TokenType.LeftCurlyBracket:
|
305
|
-
cbs.push(i);
|
306
|
-
break;
|
307
|
-
case TokenType.RightCurlyBracket:
|
308
|
-
if (cbs.length) {
|
309
|
-
t.left = cbs.pop();
|
310
|
-
tokens[t.left].right = i;
|
311
|
-
}
|
312
|
-
break;
|
313
|
-
}
|
314
|
-
}
|
315
|
-
}
|
316
|
-
|
317
|
-
return _getTokens(s);
|
318
|
-
}
|
319
|
-
// version: 1.0.0
|
320
|
-
|
321
|
-
function getCSSPAST(_tokens, rule, _needInfo) {
|
322
|
-
|
323
|
-
var tokens,
|
324
|
-
pos,
|
325
|
-
failLN = 0,
|
326
|
-
currentBlockLN = 0,
|
327
|
-
needInfo = false;
|
328
|
-
|
329
|
-
var CSSPNodeType,
|
330
|
-
CSSLevel,
|
331
|
-
CSSPRules;
|
332
|
-
|
333
|
-
CSSPNodeType = {
|
334
|
-
IdentType: 'ident',
|
335
|
-
AtkeywordType: 'atkeyword',
|
336
|
-
StringType: 'string',
|
337
|
-
ShashType: 'shash',
|
338
|
-
VhashType: 'vhash',
|
339
|
-
NumberType: 'number',
|
340
|
-
PercentageType: 'percentage',
|
341
|
-
DimensionType: 'dimension',
|
342
|
-
CdoType: 'cdo',
|
343
|
-
CdcType: 'cdc',
|
344
|
-
DecldelimType: 'decldelim',
|
345
|
-
SType: 's',
|
346
|
-
AttrselectorType: 'attrselector',
|
347
|
-
AttribType: 'attrib',
|
348
|
-
NthType: 'nth',
|
349
|
-
NthselectorType: 'nthselector',
|
350
|
-
NamespaceType: 'namespace',
|
351
|
-
ClazzType: 'clazz',
|
352
|
-
PseudoeType: 'pseudoe',
|
353
|
-
PseudocType: 'pseudoc',
|
354
|
-
DelimType: 'delim',
|
355
|
-
StylesheetType: 'stylesheet',
|
356
|
-
AtrulebType: 'atruleb',
|
357
|
-
AtrulesType: 'atrules',
|
358
|
-
AtrulerqType: 'atrulerq',
|
359
|
-
AtrulersType: 'atrulers',
|
360
|
-
AtrulerType: 'atruler',
|
361
|
-
BlockType: 'block',
|
362
|
-
RulesetType: 'ruleset',
|
363
|
-
CombinatorType: 'combinator',
|
364
|
-
SimpleselectorType: 'simpleselector',
|
365
|
-
SelectorType: 'selector',
|
366
|
-
DeclarationType: 'declaration',
|
367
|
-
PropertyType: 'property',
|
368
|
-
ImportantType: 'important',
|
369
|
-
UnaryType: 'unary',
|
370
|
-
OperatorType: 'operator',
|
371
|
-
BracesType: 'braces',
|
372
|
-
ValueType: 'value',
|
373
|
-
ProgidType: 'progid',
|
374
|
-
FiltervType: 'filterv',
|
375
|
-
FilterType: 'filter',
|
376
|
-
CommentType: 'comment',
|
377
|
-
UriType: 'uri',
|
378
|
-
RawType: 'raw',
|
379
|
-
FunctionBodyType: 'functionBody',
|
380
|
-
FunktionType: 'funktion',
|
381
|
-
FunctionExpressionType: 'functionExpression',
|
382
|
-
UnknownType: 'unknown'
|
383
|
-
};
|
384
|
-
|
385
|
-
CSSPRules = {
|
386
|
-
'ident': function() { if (checkIdent(pos)) return getIdent() },
|
387
|
-
'atkeyword': function() { if (checkAtkeyword(pos)) return getAtkeyword() },
|
388
|
-
'string': function() { if (checkString(pos)) return getString() },
|
389
|
-
'shash': function() { if (checkShash(pos)) return getShash() },
|
390
|
-
'vhash': function() { if (checkVhash(pos)) return getVhash() },
|
391
|
-
'number': function() { if (checkNumber(pos)) return getNumber() },
|
392
|
-
'percentage': function() { if (checkPercentage(pos)) return getPercentage() },
|
393
|
-
'dimension': function() { if (checkDimension(pos)) return getDimension() },
|
394
|
-
// 'cdo': function() { if (checkCDO()) return getCDO() },
|
395
|
-
// 'cdc': function() { if (checkCDC()) return getCDC() },
|
396
|
-
'decldelim': function() { if (checkDecldelim(pos)) return getDecldelim() },
|
397
|
-
's': function() { if (checkS(pos)) return getS() },
|
398
|
-
'attrselector': function() { if (checkAttrselector(pos)) return getAttrselector() },
|
399
|
-
'attrib': function() { if (checkAttrib(pos)) return getAttrib() },
|
400
|
-
'nth': function() { if (checkNth(pos)) return getNth() },
|
401
|
-
'nthselector': function() { if (checkNthselector(pos)) return getNthselector() },
|
402
|
-
'namespace': function() { if (checkNamespace(pos)) return getNamespace() },
|
403
|
-
'clazz': function() { if (checkClazz(pos)) return getClazz() },
|
404
|
-
'pseudoe': function() { if (checkPseudoe(pos)) return getPseudoe() },
|
405
|
-
'pseudoc': function() { if (checkPseudoc(pos)) return getPseudoc() },
|
406
|
-
'delim': function() { if (checkDelim(pos)) return getDelim() },
|
407
|
-
'stylesheet': function() { if (checkStylesheet(pos)) return getStylesheet() },
|
408
|
-
'atruleb': function() { if (checkAtruleb(pos)) return getAtruleb() },
|
409
|
-
'atrules': function() { if (checkAtrules(pos)) return getAtrules() },
|
410
|
-
'atrulerq': function() { if (checkAtrulerq(pos)) return getAtrulerq() },
|
411
|
-
'atrulers': function() { if (checkAtrulers(pos)) return getAtrulers() },
|
412
|
-
'atruler': function() { if (checkAtruler(pos)) return getAtruler() },
|
413
|
-
'block': function() { if (checkBlock(pos)) return getBlock() },
|
414
|
-
'ruleset': function() { if (checkRuleset(pos)) return getRuleset() },
|
415
|
-
'combinator': function() { if (checkCombinator(pos)) return getCombinator() },
|
416
|
-
'simpleselector': function() { if (checkSimpleselector(pos)) return getSimpleSelector() },
|
417
|
-
'selector': function() { if (checkSelector(pos)) return getSelector() },
|
418
|
-
'declaration': function() { if (checkDeclaration(pos)) return getDeclaration() },
|
419
|
-
'property': function() { if (checkProperty(pos)) return getProperty() },
|
420
|
-
'important': function() { if (checkImportant(pos)) return getImportant() },
|
421
|
-
'unary': function() { if (checkUnary(pos)) return getUnary() },
|
422
|
-
'operator': function() { if (checkOperator(pos)) return getOperator() },
|
423
|
-
'braces': function() { if (checkBraces(pos)) return getBraces() },
|
424
|
-
'value': function() { if (checkValue(pos)) return getValue() },
|
425
|
-
'progid': function() { if (checkProgid(pos)) return getProgid() },
|
426
|
-
'filterv': function() { if (checkFilterv(pos)) return getFilterv() },
|
427
|
-
'filter': function() { if (checkFilter(pos)) return getFilter() },
|
428
|
-
'comment': function() { if (checkComment(pos)) return getComment() },
|
429
|
-
'uri': function() { if (checkUri(pos)) return getUri() },
|
430
|
-
'raw': function() { if (checkRaw(pos)) return getRaw() },
|
431
|
-
'funktion': function() { if (checkFunktion(pos)) return getFunktion() },
|
432
|
-
'functionExpression': function() { if (checkFunctionExpression(pos)) return getFunctionExpression() },
|
433
|
-
'unknown': function() { if (checkUnknown(pos)) return getUnknown() }
|
434
|
-
};
|
435
|
-
|
436
|
-
function fail(token) {
|
437
|
-
if (token && token.ln > failLN) failLN = token.ln;
|
438
|
-
}
|
439
|
-
|
440
|
-
function throwError() {
|
441
|
-
console.error('Please check the validity of the CSS block starting from the line #' + currentBlockLN);
|
442
|
-
if (process) process.exit(1);
|
443
|
-
throw new Error();
|
444
|
-
}
|
445
|
-
|
446
|
-
function _getAST(_tokens, rule, _needInfo) {
|
447
|
-
tokens = _tokens;
|
448
|
-
needInfo = _needInfo;
|
449
|
-
pos = 0;
|
450
|
-
|
451
|
-
markSC();
|
452
|
-
|
453
|
-
return rule ? CSSPRules[rule]() : CSSPRules['stylesheet']();
|
454
|
-
}
|
455
|
-
|
456
|
-
//any = braces | string | percentage | dimension | number | uri | functionExpression | funktion | ident | unary
|
457
|
-
function checkAny(_i) {
|
458
|
-
return checkBraces(_i) ||
|
459
|
-
checkString(_i) ||
|
460
|
-
checkPercentage(_i) ||
|
461
|
-
checkDimension(_i) ||
|
462
|
-
checkNumber(_i) ||
|
463
|
-
checkUri(_i) ||
|
464
|
-
checkFunctionExpression(_i) ||
|
465
|
-
checkFunktion(_i) ||
|
466
|
-
checkIdent(_i) ||
|
467
|
-
checkUnary(_i);
|
468
|
-
}
|
469
|
-
|
470
|
-
function getAny() {
|
471
|
-
if (checkBraces(pos)) return getBraces();
|
472
|
-
else if (checkString(pos)) return getString();
|
473
|
-
else if (checkPercentage(pos)) return getPercentage();
|
474
|
-
else if (checkDimension(pos)) return getDimension();
|
475
|
-
else if (checkNumber(pos)) return getNumber();
|
476
|
-
else if (checkUri(pos)) return getUri();
|
477
|
-
else if (checkFunctionExpression(pos)) return getFunctionExpression();
|
478
|
-
else if (checkFunktion(pos)) return getFunktion();
|
479
|
-
else if (checkIdent(pos)) return getIdent();
|
480
|
-
else if (checkUnary(pos)) return getUnary();
|
481
|
-
}
|
482
|
-
|
483
|
-
//atkeyword = '@' ident:x -> [#atkeyword, x]
|
484
|
-
function checkAtkeyword(_i) {
|
485
|
-
var l;
|
486
|
-
|
487
|
-
if (tokens[_i++].type !== TokenType.CommercialAt) return fail(tokens[_i - 1]);
|
488
|
-
|
489
|
-
if (l = checkIdent(_i)) return l + 1;
|
490
|
-
|
491
|
-
return fail(tokens[_i]);
|
492
|
-
}
|
493
|
-
|
494
|
-
function getAtkeyword() {
|
495
|
-
var startPos = pos;
|
496
|
-
|
497
|
-
pos++;
|
498
|
-
|
499
|
-
return needInfo?
|
500
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.AtkeywordType, getIdent()]:
|
501
|
-
[CSSPNodeType.AtkeywordType, getIdent()];
|
502
|
-
}
|
503
|
-
|
504
|
-
//attrib = '[' sc*:s0 ident:x sc*:s1 attrselector:a sc*:s2 (ident | string):y sc*:s3 ']' -> this.concat([#attrib], s0, [x], s1, [a], s2, [y], s3)
|
505
|
-
// | '[' sc*:s0 ident:x sc*:s1 ']' -> this.concat([#attrib], s0, [x], s1),
|
506
|
-
function checkAttrib(_i) {
|
507
|
-
if (tokens[_i].type !== TokenType.LeftSquareBracket) return fail(tokens[_i]);
|
508
|
-
|
509
|
-
if (!tokens[_i].right) return fail(tokens[_i]);
|
510
|
-
|
511
|
-
return tokens[_i].right - _i + 1;
|
512
|
-
}
|
513
|
-
|
514
|
-
function checkAttrib1(_i) {
|
515
|
-
var start = _i;
|
516
|
-
|
517
|
-
_i++;
|
518
|
-
|
519
|
-
var l = checkSC(_i); // s0
|
520
|
-
|
521
|
-
if (l) _i += l;
|
522
|
-
|
523
|
-
if (l = checkIdent(_i)) _i += l; // x
|
524
|
-
else return fail(tokens[_i]);
|
525
|
-
|
526
|
-
if (l = checkSC(_i)) _i += l; // s1
|
527
|
-
|
528
|
-
if (l = checkAttrselector(_i)) _i += l; // a
|
529
|
-
else return fail(tokens[_i]);
|
530
|
-
|
531
|
-
if (l = checkSC(_i)) _i += l; // s2
|
532
|
-
|
533
|
-
if ((l = checkIdent(_i)) || (l = checkString(_i))) _i += l; // y
|
534
|
-
else return fail(tokens[_i]);
|
535
|
-
|
536
|
-
if (l = checkSC(_i)) _i += l; // s3
|
537
|
-
|
538
|
-
if (tokens[_i].type === TokenType.RightSquareBracket) return _i - start;
|
539
|
-
|
540
|
-
return fail(tokens[_i]);
|
541
|
-
}
|
542
|
-
|
543
|
-
function getAttrib1() {
|
544
|
-
var startPos = pos;
|
545
|
-
|
546
|
-
pos++;
|
547
|
-
|
548
|
-
var a = (needInfo? [{ ln: tokens[startPos].ln }, CSSPNodeType.AttribType] : [CSSPNodeType.AttribType])
|
549
|
-
.concat(getSC())
|
550
|
-
.concat([getIdent()])
|
551
|
-
.concat(getSC())
|
552
|
-
.concat([getAttrselector()])
|
553
|
-
.concat(getSC())
|
554
|
-
.concat([checkString(pos)? getString() : getIdent()])
|
555
|
-
.concat(getSC());
|
556
|
-
|
557
|
-
pos++;
|
558
|
-
|
559
|
-
return a;
|
560
|
-
}
|
561
|
-
|
562
|
-
function checkAttrib2(_i) {
|
563
|
-
var start = _i;
|
564
|
-
|
565
|
-
_i++;
|
566
|
-
|
567
|
-
var l = checkSC(_i);
|
568
|
-
|
569
|
-
if (l) _i += l;
|
570
|
-
|
571
|
-
if (l = checkIdent(_i)) _i += l;
|
572
|
-
|
573
|
-
if (l = checkSC(_i)) _i += l;
|
574
|
-
|
575
|
-
if (tokens[_i].type === TokenType.RightSquareBracket) return _i - start;
|
576
|
-
|
577
|
-
return fail(tokens[_i]);
|
578
|
-
}
|
579
|
-
|
580
|
-
function getAttrib2() {
|
581
|
-
var startPos = pos;
|
582
|
-
|
583
|
-
pos++;
|
584
|
-
|
585
|
-
var a = (needInfo? [{ ln: tokens[startPos].ln }, CSSPNodeType.AttribType] : [CSSPNodeType.AttribType])
|
586
|
-
.concat(getSC())
|
587
|
-
.concat([getIdent()])
|
588
|
-
.concat(getSC());
|
589
|
-
|
590
|
-
pos++;
|
591
|
-
|
592
|
-
return a;
|
593
|
-
}
|
594
|
-
|
595
|
-
function getAttrib() {
|
596
|
-
if (checkAttrib1(pos)) return getAttrib1();
|
597
|
-
if (checkAttrib2(pos)) return getAttrib2();
|
598
|
-
}
|
599
|
-
|
600
|
-
//attrselector = (seq('=') | seq('~=') | seq('^=') | seq('$=') | seq('*=') | seq('|=')):x -> [#attrselector, x]
|
601
|
-
function checkAttrselector(_i) {
|
602
|
-
if (tokens[_i].type === TokenType.EqualsSign) return 1;
|
603
|
-
if (tokens[_i].type === TokenType.VerticalLine && (!tokens[_i + 1] || tokens[_i + 1].type !== TokenType.EqualsSign)) return 1;
|
604
|
-
|
605
|
-
if (!tokens[_i + 1] || tokens[_i + 1].type !== TokenType.EqualsSign) return fail(tokens[_i]);
|
606
|
-
|
607
|
-
switch(tokens[_i].type) {
|
608
|
-
case TokenType.Tilde:
|
609
|
-
case TokenType.CircumflexAccent:
|
610
|
-
case TokenType.DollarSign:
|
611
|
-
case TokenType.Asterisk:
|
612
|
-
case TokenType.VerticalLine:
|
613
|
-
return 2;
|
614
|
-
}
|
615
|
-
|
616
|
-
return fail(tokens[_i]);
|
617
|
-
}
|
618
|
-
|
619
|
-
function getAttrselector() {
|
620
|
-
var startPos = pos,
|
621
|
-
s = tokens[pos++].value;
|
622
|
-
|
623
|
-
if (tokens[pos] && tokens[pos].type === TokenType.EqualsSign) s += tokens[pos++].value;
|
624
|
-
|
625
|
-
return needInfo?
|
626
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.AttrselectorType, s] :
|
627
|
-
[CSSPNodeType.AttrselectorType, s];
|
628
|
-
}
|
629
|
-
|
630
|
-
//atrule = atruler | atruleb | atrules
|
631
|
-
function checkAtrule(_i) {
|
632
|
-
var start = _i,
|
633
|
-
l;
|
634
|
-
|
635
|
-
if (tokens[start].atrule_l !== undefined) return tokens[start].atrule_l;
|
636
|
-
|
637
|
-
if (l = checkAtruler(_i)) tokens[_i].atrule_type = 1;
|
638
|
-
else if (l = checkAtruleb(_i)) tokens[_i].atrule_type = 2;
|
639
|
-
else if (l = checkAtrules(_i)) tokens[_i].atrule_type = 3;
|
640
|
-
else return fail(tokens[start]);
|
641
|
-
|
642
|
-
tokens[start].atrule_l = l;
|
643
|
-
|
644
|
-
return l;
|
645
|
-
}
|
646
|
-
|
647
|
-
function getAtrule() {
|
648
|
-
switch (tokens[pos].atrule_type) {
|
649
|
-
case 1: return getAtruler();
|
650
|
-
case 2: return getAtruleb();
|
651
|
-
case 3: return getAtrules();
|
652
|
-
}
|
653
|
-
}
|
654
|
-
|
655
|
-
//atruleb = atkeyword:ak tset*:ap block:b -> this.concat([#atruleb, ak], ap, [b])
|
656
|
-
function checkAtruleb(_i) {
|
657
|
-
var start = _i,
|
658
|
-
l;
|
659
|
-
|
660
|
-
if (l = checkAtkeyword(_i)) _i += l;
|
661
|
-
else return fail(tokens[_i]);
|
662
|
-
|
663
|
-
if (l = checkTsets(_i)) _i += l;
|
664
|
-
|
665
|
-
if (l = checkBlock(_i)) _i += l;
|
666
|
-
else return fail(tokens[_i]);
|
667
|
-
|
668
|
-
return _i - start;
|
669
|
-
}
|
670
|
-
|
671
|
-
function getAtruleb() {
|
672
|
-
return (needInfo?
|
673
|
-
[{ ln: tokens[pos].ln }, CSSPNodeType.AtrulebType, getAtkeyword()] :
|
674
|
-
[CSSPNodeType.AtrulebType, getAtkeyword()])
|
675
|
-
.concat(getTsets())
|
676
|
-
.concat([getBlock()]);
|
677
|
-
}
|
678
|
-
|
679
|
-
//atruler = atkeyword:ak atrulerq:x '{' atrulers:y '}' -> [#atruler, ak, x, y]
|
680
|
-
function checkAtruler(_i) {
|
681
|
-
var start = _i,
|
682
|
-
l;
|
683
|
-
|
684
|
-
if (l = checkAtkeyword(_i)) _i += l;
|
685
|
-
else return fail(tokens[_i]);
|
686
|
-
|
687
|
-
if (l = checkAtrulerq(_i)) _i += l;
|
688
|
-
|
689
|
-
if (_i < tokens.length && tokens[_i].type === TokenType.LeftCurlyBracket) _i++;
|
690
|
-
else return fail(tokens[_i]);
|
691
|
-
|
692
|
-
if (l = checkAtrulers(_i)) _i += l;
|
693
|
-
|
694
|
-
if (_i < tokens.length && tokens[_i].type === TokenType.RightCurlyBracket) _i++;
|
695
|
-
else return fail(tokens[_i]);
|
696
|
-
|
697
|
-
return _i - start;
|
698
|
-
}
|
699
|
-
|
700
|
-
function getAtruler() {
|
701
|
-
var atruler = needInfo?
|
702
|
-
[{ ln: tokens[pos].ln }, CSSPNodeType.AtrulerType, getAtkeyword(), getAtrulerq()] :
|
703
|
-
[CSSPNodeType.AtrulerType, getAtkeyword(), getAtrulerq()];
|
704
|
-
|
705
|
-
pos++;
|
706
|
-
|
707
|
-
atruler.push(getAtrulers());
|
708
|
-
|
709
|
-
pos++;
|
710
|
-
|
711
|
-
return atruler;
|
712
|
-
}
|
713
|
-
|
714
|
-
//atrulerq = tset*:ap -> [#atrulerq].concat(ap)
|
715
|
-
function checkAtrulerq(_i) {
|
716
|
-
return checkTsets(_i);
|
717
|
-
}
|
718
|
-
|
719
|
-
function getAtrulerq() {
|
720
|
-
return (needInfo? [{ ln: tokens[pos].ln }, CSSPNodeType.AtrulerqType] : [CSSPNodeType.AtrulerqType]).concat(getTsets());
|
721
|
-
}
|
722
|
-
|
723
|
-
//atrulers = sc*:s0 ruleset*:r sc*:s1 -> this.concat([#atrulers], s0, r, s1)
|
724
|
-
function checkAtrulers(_i) {
|
725
|
-
var start = _i,
|
726
|
-
l;
|
727
|
-
|
728
|
-
if (l = checkSC(_i)) _i += l;
|
729
|
-
|
730
|
-
while ((l = checkRuleset(_i)) || (l = checkAtrule(_i)) || (l = checkSC(_i))) {
|
731
|
-
_i += l;
|
732
|
-
}
|
733
|
-
|
734
|
-
tokens[_i].atrulers_end = 1;
|
735
|
-
|
736
|
-
if (l = checkSC(_i)) _i += l;
|
737
|
-
|
738
|
-
return _i - start;
|
739
|
-
}
|
740
|
-
|
741
|
-
function getAtrulers() {
|
742
|
-
var atrulers = (needInfo? [{ ln: tokens[pos].ln }, CSSPNodeType.AtrulersType] : [CSSPNodeType.AtrulersType]).concat(getSC()),
|
743
|
-
x;
|
744
|
-
|
745
|
-
while (!tokens[pos].atrulers_end) {
|
746
|
-
if (checkSC(pos)) {
|
747
|
-
atrulers = atrulers.concat(getSC());
|
748
|
-
} else if (checkRuleset(pos)) {
|
749
|
-
atrulers.push(getRuleset());
|
750
|
-
} else {
|
751
|
-
atrulers.push(getAtrule());
|
752
|
-
}
|
753
|
-
}
|
754
|
-
|
755
|
-
return atrulers.concat(getSC());
|
756
|
-
}
|
757
|
-
|
758
|
-
//atrules = atkeyword:ak tset*:ap ';' -> this.concat([#atrules, ak], ap)
|
759
|
-
function checkAtrules(_i) {
|
760
|
-
var start = _i,
|
761
|
-
l;
|
762
|
-
|
763
|
-
if (l = checkAtkeyword(_i)) _i += l;
|
764
|
-
else return fail(tokens[_i]);
|
765
|
-
|
766
|
-
if (l = checkTsets(_i)) _i += l;
|
767
|
-
|
768
|
-
if (_i >= tokens.length) return _i - start;
|
769
|
-
|
770
|
-
if (tokens[_i].type === TokenType.Semicolon) _i++;
|
771
|
-
else return fail(tokens[_i]);
|
772
|
-
|
773
|
-
return _i - start;
|
774
|
-
}
|
775
|
-
|
776
|
-
function getAtrules() {
|
777
|
-
var atrules = (needInfo? [{ ln: tokens[pos].ln }, CSSPNodeType.AtrulesType, getAtkeyword()] : [CSSPNodeType.AtrulesType, getAtkeyword()]).concat(getTsets());
|
778
|
-
|
779
|
-
pos++;
|
780
|
-
|
781
|
-
return atrules;
|
782
|
-
}
|
783
|
-
|
784
|
-
//block = '{' blockdecl*:x '}' -> this.concatContent([#block], x)
|
785
|
-
function checkBlock(_i) {
|
786
|
-
if (_i < tokens.length && tokens[_i].type === TokenType.LeftCurlyBracket) return tokens[_i].right - _i + 1;
|
787
|
-
|
788
|
-
return fail(tokens[_i]);
|
789
|
-
}
|
790
|
-
|
791
|
-
function getBlock() {
|
792
|
-
var block = needInfo? [{ ln: tokens[pos].ln }, CSSPNodeType.BlockType] : [CSSPNodeType.BlockType],
|
793
|
-
end = tokens[pos].right;
|
794
|
-
|
795
|
-
pos++;
|
796
|
-
|
797
|
-
while (pos < end) {
|
798
|
-
if (checkBlockdecl(pos)) block = block.concat(getBlockdecl());
|
799
|
-
else throwError();
|
800
|
-
}
|
801
|
-
|
802
|
-
pos = end + 1;
|
803
|
-
|
804
|
-
return block;
|
805
|
-
}
|
806
|
-
|
807
|
-
//blockdecl = sc*:s0 (filter | declaration):x decldelim:y sc*:s1 -> this.concat(s0, [x], [y], s1)
|
808
|
-
// | sc*:s0 (filter | declaration):x sc*:s1 -> this.concat(s0, [x], s1)
|
809
|
-
// | sc*:s0 decldelim:x sc*:s1 -> this.concat(s0, [x], s1)
|
810
|
-
// | sc+:s0 -> s0
|
811
|
-
|
812
|
-
function checkBlockdecl(_i) {
|
813
|
-
var l;
|
814
|
-
|
815
|
-
if (l = _checkBlockdecl0(_i)) tokens[_i].bd_type = 1;
|
816
|
-
else if (l = _checkBlockdecl1(_i)) tokens[_i].bd_type = 2;
|
817
|
-
else if (l = _checkBlockdecl2(_i)) tokens[_i].bd_type = 3;
|
818
|
-
else if (l = _checkBlockdecl3(_i)) tokens[_i].bd_type = 4;
|
819
|
-
else return fail(tokens[_i]);
|
820
|
-
|
821
|
-
return l;
|
822
|
-
}
|
823
|
-
|
824
|
-
function getBlockdecl() {
|
825
|
-
switch (tokens[pos].bd_type) {
|
826
|
-
case 1: return _getBlockdecl0();
|
827
|
-
case 2: return _getBlockdecl1();
|
828
|
-
case 3: return _getBlockdecl2();
|
829
|
-
case 4: return _getBlockdecl3();
|
830
|
-
}
|
831
|
-
}
|
832
|
-
|
833
|
-
//sc*:s0 (filter | declaration):x decldelim:y sc*:s1 -> this.concat(s0, [x], [y], s1)
|
834
|
-
function _checkBlockdecl0(_i) {
|
835
|
-
var start = _i,
|
836
|
-
l;
|
837
|
-
|
838
|
-
if (l = checkSC(_i)) _i += l;
|
839
|
-
|
840
|
-
if (l = checkFilter(_i)) {
|
841
|
-
tokens[_i].bd_filter = 1;
|
842
|
-
_i += l;
|
843
|
-
} else if (l = checkDeclaration(_i)) {
|
844
|
-
tokens[_i].bd_decl = 1;
|
845
|
-
_i += l;
|
846
|
-
} else return fail(tokens[_i]);
|
847
|
-
|
848
|
-
if (_i < tokens.length && (l = checkDecldelim(_i))) _i += l;
|
849
|
-
else return fail(tokens[_i]);
|
850
|
-
|
851
|
-
if (l = checkSC(_i)) _i += l;
|
852
|
-
|
853
|
-
return _i - start;
|
854
|
-
}
|
855
|
-
|
856
|
-
function _getBlockdecl0() {
|
857
|
-
return getSC()
|
858
|
-
.concat([tokens[pos].bd_filter? getFilter() : getDeclaration()])
|
859
|
-
.concat([getDecldelim()])
|
860
|
-
.concat(getSC());
|
861
|
-
}
|
862
|
-
|
863
|
-
//sc*:s0 (filter | declaration):x sc*:s1 -> this.concat(s0, [x], s1)
|
864
|
-
function _checkBlockdecl1(_i) {
|
865
|
-
var start = _i,
|
866
|
-
l;
|
867
|
-
|
868
|
-
if (l = checkSC(_i)) _i += l;
|
869
|
-
|
870
|
-
if (l = checkFilter(_i)) {
|
871
|
-
tokens[_i].bd_filter = 1;
|
872
|
-
_i += l;
|
873
|
-
} else if (l = checkDeclaration(_i)) {
|
874
|
-
tokens[_i].bd_decl = 1;
|
875
|
-
_i += l;
|
876
|
-
} else return fail(tokens[_i]);
|
877
|
-
|
878
|
-
if (l = checkSC(_i)) _i += l;
|
879
|
-
|
880
|
-
return _i - start;
|
881
|
-
}
|
882
|
-
|
883
|
-
function _getBlockdecl1() {
|
884
|
-
return getSC()
|
885
|
-
.concat([tokens[pos].bd_filter? getFilter() : getDeclaration()])
|
886
|
-
.concat(getSC());
|
887
|
-
}
|
888
|
-
|
889
|
-
//sc*:s0 decldelim:x sc*:s1 -> this.concat(s0, [x], s1)
|
890
|
-
function _checkBlockdecl2(_i) {
|
891
|
-
var start = _i,
|
892
|
-
l;
|
893
|
-
|
894
|
-
if (l = checkSC(_i)) _i += l;
|
895
|
-
|
896
|
-
if (l = checkDecldelim(_i)) _i += l;
|
897
|
-
else return fail(tokens[_i]);
|
898
|
-
|
899
|
-
if (l = checkSC(_i)) _i += l;
|
900
|
-
|
901
|
-
return _i - start;
|
902
|
-
}
|
903
|
-
|
904
|
-
function _getBlockdecl2() {
|
905
|
-
return getSC()
|
906
|
-
.concat([getDecldelim()])
|
907
|
-
.concat(getSC());
|
908
|
-
}
|
909
|
-
|
910
|
-
//sc+:s0 -> s0
|
911
|
-
function _checkBlockdecl3(_i) {
|
912
|
-
return checkSC(_i);
|
913
|
-
}
|
914
|
-
|
915
|
-
function _getBlockdecl3() {
|
916
|
-
return getSC();
|
917
|
-
}
|
918
|
-
|
919
|
-
//braces = '(' tset*:x ')' -> this.concat([#braces, '(', ')'], x)
|
920
|
-
// | '[' tset*:x ']' -> this.concat([#braces, '[', ']'], x)
|
921
|
-
function checkBraces(_i) {
|
922
|
-
if (_i >= tokens.length ||
|
923
|
-
(tokens[_i].type !== TokenType.LeftParenthesis &&
|
924
|
-
tokens[_i].type !== TokenType.LeftSquareBracket)
|
925
|
-
) return fail(tokens[_i]);
|
926
|
-
|
927
|
-
return tokens[_i].right - _i + 1;
|
928
|
-
}
|
929
|
-
|
930
|
-
function getBraces() {
|
931
|
-
var startPos = pos,
|
932
|
-
left = pos,
|
933
|
-
right = tokens[pos].right;
|
934
|
-
|
935
|
-
pos++;
|
936
|
-
|
937
|
-
var tsets = getTsets();
|
938
|
-
|
939
|
-
pos++;
|
940
|
-
|
941
|
-
return needInfo?
|
942
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.BracesType, tokens[left].value, tokens[right].value].concat(tsets) :
|
943
|
-
[CSSPNodeType.BracesType, tokens[left].value, tokens[right].value].concat(tsets);
|
944
|
-
}
|
945
|
-
|
946
|
-
function checkCDC(_i) {}
|
947
|
-
|
948
|
-
function checkCDO(_i) {}
|
949
|
-
|
950
|
-
// node: Clazz
|
951
|
-
function checkClazz(_i) {
|
952
|
-
var l;
|
953
|
-
|
954
|
-
if (tokens[_i].clazz_l) return tokens[_i].clazz_l;
|
955
|
-
|
956
|
-
if (tokens[_i].type === TokenType.FullStop) {
|
957
|
-
if (l = checkIdent(_i + 1)) {
|
958
|
-
tokens[_i].clazz_l = l + 1;
|
959
|
-
return l + 1;
|
960
|
-
}
|
961
|
-
}
|
962
|
-
|
963
|
-
return fail(tokens[_i]);
|
964
|
-
}
|
965
|
-
|
966
|
-
function getClazz() {
|
967
|
-
var startPos = pos;
|
968
|
-
|
969
|
-
pos++;
|
970
|
-
|
971
|
-
return needInfo?
|
972
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.ClazzType, getIdent()] :
|
973
|
-
[CSSPNodeType.ClazzType, getIdent()];
|
974
|
-
}
|
975
|
-
|
976
|
-
// node: Combinator
|
977
|
-
function checkCombinator(_i) {
|
978
|
-
if (tokens[_i].type === TokenType.PlusSign ||
|
979
|
-
tokens[_i].type === TokenType.GreaterThanSign ||
|
980
|
-
tokens[_i].type === TokenType.Tilde) return 1;
|
981
|
-
|
982
|
-
return fail(tokens[_i]);
|
983
|
-
}
|
984
|
-
|
985
|
-
function getCombinator() {
|
986
|
-
return needInfo?
|
987
|
-
[{ ln: tokens[pos].ln }, CSSPNodeType.CombinatorType, tokens[pos++].value] :
|
988
|
-
[CSSPNodeType.CombinatorType, tokens[pos++].value];
|
989
|
-
}
|
990
|
-
|
991
|
-
// node: Comment
|
992
|
-
function checkComment(_i) {
|
993
|
-
if (tokens[_i].type === TokenType.CommentML) return 1;
|
994
|
-
|
995
|
-
return fail(tokens[_i]);
|
996
|
-
}
|
997
|
-
|
998
|
-
function getComment() {
|
999
|
-
var startPos = pos,
|
1000
|
-
s = tokens[pos].value.substring(2),
|
1001
|
-
l = s.length;
|
1002
|
-
|
1003
|
-
if (s.charAt(l - 2) === '*' && s.charAt(l - 1) === '/') s = s.substring(0, l - 2);
|
1004
|
-
|
1005
|
-
pos++;
|
1006
|
-
|
1007
|
-
return needInfo?
|
1008
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.CommentType, s] :
|
1009
|
-
[CSSPNodeType.CommentType, s];
|
1010
|
-
}
|
1011
|
-
|
1012
|
-
// declaration = property:x ':' value:y -> [#declaration, x, y]
|
1013
|
-
function checkDeclaration(_i) {
|
1014
|
-
var start = _i,
|
1015
|
-
l;
|
1016
|
-
|
1017
|
-
if (l = checkProperty(_i)) _i += l;
|
1018
|
-
else return fail(tokens[_i]);
|
1019
|
-
|
1020
|
-
if (_i < tokens.length && tokens[_i].type === TokenType.Colon) _i++;
|
1021
|
-
else return fail(tokens[_i]);
|
1022
|
-
|
1023
|
-
if (l = checkValue(_i)) _i += l;
|
1024
|
-
else return fail(tokens[_i]);
|
1025
|
-
|
1026
|
-
return _i - start;
|
1027
|
-
}
|
1028
|
-
|
1029
|
-
function getDeclaration() {
|
1030
|
-
var declaration = needInfo?
|
1031
|
-
[{ ln: tokens[pos].ln }, CSSPNodeType.DeclarationType, getProperty()] :
|
1032
|
-
[CSSPNodeType.DeclarationType, getProperty()];
|
1033
|
-
|
1034
|
-
pos++;
|
1035
|
-
|
1036
|
-
declaration.push(getValue());
|
1037
|
-
|
1038
|
-
return declaration;
|
1039
|
-
}
|
1040
|
-
|
1041
|
-
// node: Decldelim
|
1042
|
-
function checkDecldelim(_i) {
|
1043
|
-
if (_i < tokens.length && tokens[_i].type === TokenType.Semicolon) return 1;
|
1044
|
-
|
1045
|
-
return fail(tokens[_i]);
|
1046
|
-
}
|
1047
|
-
|
1048
|
-
function getDecldelim() {
|
1049
|
-
var startPos = pos;
|
1050
|
-
|
1051
|
-
pos++;
|
1052
|
-
|
1053
|
-
return needInfo?
|
1054
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.DecldelimType] :
|
1055
|
-
[CSSPNodeType.DecldelimType];
|
1056
|
-
}
|
1057
|
-
|
1058
|
-
// node: Delim
|
1059
|
-
function checkDelim(_i) {
|
1060
|
-
if (_i < tokens.length && tokens[_i].type === TokenType.Comma) return 1;
|
1061
|
-
|
1062
|
-
if (_i >= tokens.length) return fail(tokens[tokens.length - 1]);
|
1063
|
-
|
1064
|
-
return fail(tokens[_i]);
|
1065
|
-
}
|
1066
|
-
|
1067
|
-
function getDelim() {
|
1068
|
-
var startPos = pos;
|
1069
|
-
|
1070
|
-
pos++;
|
1071
|
-
|
1072
|
-
return needInfo?
|
1073
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.DelimType] :
|
1074
|
-
[CSSPNodeType.DelimType];
|
1075
|
-
}
|
1076
|
-
|
1077
|
-
// node: Dimension
|
1078
|
-
function checkDimension(_i) {
|
1079
|
-
var ln = checkNumber(_i),
|
1080
|
-
li;
|
1081
|
-
|
1082
|
-
if (!ln || (ln && _i + ln >= tokens.length)) return fail(tokens[_i]);
|
1083
|
-
|
1084
|
-
if (li = checkNmName2(_i + ln)) return ln + li;
|
1085
|
-
|
1086
|
-
return fail(tokens[_i]);
|
1087
|
-
}
|
1088
|
-
|
1089
|
-
function getDimension() {
|
1090
|
-
var startPos = pos,
|
1091
|
-
n = getNumber(),
|
1092
|
-
dimension = needInfo ?
|
1093
|
-
[{ ln: tokens[pos].ln }, CSSPNodeType.IdentType, getNmName2()] :
|
1094
|
-
[CSSPNodeType.IdentType, getNmName2()];
|
1095
|
-
|
1096
|
-
return needInfo?
|
1097
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.DimensionType, n, dimension] :
|
1098
|
-
[CSSPNodeType.DimensionType, n, dimension];
|
1099
|
-
}
|
1100
|
-
|
1101
|
-
//filter = filterp:x ':' filterv:y -> [#filter, x, y]
|
1102
|
-
function checkFilter(_i) {
|
1103
|
-
var start = _i,
|
1104
|
-
l;
|
1105
|
-
|
1106
|
-
if (l = checkFilterp(_i)) _i += l;
|
1107
|
-
else return fail(tokens[_i]);
|
1108
|
-
|
1109
|
-
if (tokens[_i].type === TokenType.Colon) _i++;
|
1110
|
-
else return fail(tokens[_i]);
|
1111
|
-
|
1112
|
-
if (l = checkFilterv(_i)) _i += l;
|
1113
|
-
else return fail(tokens[_i]);
|
1114
|
-
|
1115
|
-
return _i - start;
|
1116
|
-
}
|
1117
|
-
|
1118
|
-
function getFilter() {
|
1119
|
-
var filter = needInfo?
|
1120
|
-
[{ ln: tokens[pos].ln }, CSSPNodeType.FilterType, getFilterp()] :
|
1121
|
-
[CSSPNodeType.FilterType, getFilterp()];
|
1122
|
-
|
1123
|
-
pos++;
|
1124
|
-
|
1125
|
-
filter.push(getFilterv());
|
1126
|
-
|
1127
|
-
return filter;
|
1128
|
-
}
|
1129
|
-
|
1130
|
-
//filterp = (seq('-filter') | seq('_filter') | seq('*filter') | seq('-ms-filter') | seq('filter')):t sc*:s0 -> this.concat([#property, [#ident, t]], s0)
|
1131
|
-
function checkFilterp(_i) {
|
1132
|
-
var start = _i,
|
1133
|
-
l,
|
1134
|
-
x;
|
1135
|
-
|
1136
|
-
if (_i < tokens.length) {
|
1137
|
-
if (tokens[_i].value === 'filter') l = 1;
|
1138
|
-
else {
|
1139
|
-
x = joinValues2(_i, 2);
|
1140
|
-
|
1141
|
-
if (x === '-filter' || x === '_filter' || x === '*filter') l = 2;
|
1142
|
-
else {
|
1143
|
-
x = joinValues2(_i, 4);
|
1144
|
-
|
1145
|
-
if (x === '-ms-filter') l = 4;
|
1146
|
-
else return fail(tokens[_i]);
|
1147
|
-
}
|
1148
|
-
}
|
1149
|
-
|
1150
|
-
tokens[start].filterp_l = l;
|
1151
|
-
|
1152
|
-
_i += l;
|
1153
|
-
|
1154
|
-
if (checkSC(_i)) _i += l;
|
1155
|
-
|
1156
|
-
return _i - start;
|
1157
|
-
}
|
1158
|
-
|
1159
|
-
return fail(tokens[_i]);
|
1160
|
-
}
|
1161
|
-
|
1162
|
-
function getFilterp() {
|
1163
|
-
var startPos = pos,
|
1164
|
-
x = joinValues2(pos, tokens[pos].filterp_l),
|
1165
|
-
ident = needInfo? [{ ln: tokens[startPos].ln }, CSSPNodeType.IdentType, x] : [CSSPNodeType.IdentType, x];
|
1166
|
-
|
1167
|
-
pos += tokens[pos].filterp_l;
|
1168
|
-
|
1169
|
-
return (needInfo? [{ ln: tokens[startPos].ln }, CSSPNodeType.PropertyType, ident] : [CSSPNodeType.PropertyType, ident])
|
1170
|
-
.concat(getSC());
|
1171
|
-
|
1172
|
-
}
|
1173
|
-
|
1174
|
-
//filterv = progid+:x -> [#filterv].concat(x)
|
1175
|
-
function checkFilterv(_i) {
|
1176
|
-
var start = _i,
|
1177
|
-
l;
|
1178
|
-
|
1179
|
-
if (l = checkProgid(_i)) _i += l;
|
1180
|
-
else return fail(tokens[_i]);
|
1181
|
-
|
1182
|
-
while (l = checkProgid(_i)) {
|
1183
|
-
_i += l;
|
1184
|
-
}
|
1185
|
-
|
1186
|
-
tokens[start].last_progid = _i;
|
1187
|
-
|
1188
|
-
if (_i < tokens.length && (l = checkSC(_i))) _i += l;
|
1189
|
-
|
1190
|
-
if (_i < tokens.length && (l = checkImportant(_i))) _i += l;
|
1191
|
-
|
1192
|
-
return _i - start;
|
1193
|
-
}
|
1194
|
-
|
1195
|
-
function getFilterv() {
|
1196
|
-
var filterv = needInfo? [{ ln: tokens[pos].ln }, CSSPNodeType.FiltervType] : [CSSPNodeType.FiltervType],
|
1197
|
-
last_progid = tokens[pos].last_progid;
|
1198
|
-
|
1199
|
-
while (pos < last_progid) {
|
1200
|
-
filterv.push(getProgid());
|
1201
|
-
}
|
1202
|
-
|
1203
|
-
filterv = filterv.concat(checkSC(pos) ? getSC() : []);
|
1204
|
-
|
1205
|
-
if (pos < tokens.length && checkImportant(pos)) filterv.push(getImportant());
|
1206
|
-
|
1207
|
-
return filterv;
|
1208
|
-
}
|
1209
|
-
|
1210
|
-
//functionExpression = ``expression('' functionExpressionBody*:x ')' -> [#functionExpression, x.join('')],
|
1211
|
-
function checkFunctionExpression(_i) {
|
1212
|
-
var start = _i;
|
1213
|
-
|
1214
|
-
if (!tokens[_i] || tokens[_i++].value !== 'expression') return fail(tokens[_i - 1]);
|
1215
|
-
|
1216
|
-
if (!tokens[_i] || tokens[_i].type !== TokenType.LeftParenthesis) return fail(tokens[_i]);
|
1217
|
-
|
1218
|
-
return tokens[_i].right - start + 1;
|
1219
|
-
}
|
1220
|
-
|
1221
|
-
function getFunctionExpression() {
|
1222
|
-
var startPos = pos;
|
1223
|
-
|
1224
|
-
pos++;
|
1225
|
-
|
1226
|
-
var e = joinValues(pos + 1, tokens[pos].right - 1);
|
1227
|
-
|
1228
|
-
pos = tokens[pos].right + 1;
|
1229
|
-
|
1230
|
-
return needInfo?
|
1231
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.FunctionExpressionType, e] :
|
1232
|
-
[CSSPNodeType.FunctionExpressionType, e];
|
1233
|
-
}
|
1234
|
-
|
1235
|
-
//funktion = ident:x '(' functionBody:y ')' -> [#funktion, x, y]
|
1236
|
-
function checkFunktion(_i) {
|
1237
|
-
var start = _i,
|
1238
|
-
l = checkIdent(_i);
|
1239
|
-
|
1240
|
-
if (!l) return fail(tokens[_i]);
|
1241
|
-
|
1242
|
-
_i += l;
|
1243
|
-
|
1244
|
-
if (_i >= tokens.length || tokens[_i].type !== TokenType.LeftParenthesis) return fail(tokens[_i - 1]);
|
1245
|
-
|
1246
|
-
return tokens[_i].right - start + 1;
|
1247
|
-
}
|
1248
|
-
|
1249
|
-
function getFunktion() {
|
1250
|
-
var startPos = pos,
|
1251
|
-
ident = getIdent();
|
1252
|
-
|
1253
|
-
pos++;
|
1254
|
-
|
1255
|
-
var body = ident[needInfo? 2 : 1] !== 'not'?
|
1256
|
-
getFunctionBody() :
|
1257
|
-
getNotFunctionBody(); // ok, here we have CSS3 initial draft: http://dev.w3.org/csswg/selectors3/#negation
|
1258
|
-
|
1259
|
-
return needInfo?
|
1260
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.FunktionType, ident, body] :
|
1261
|
-
[CSSPNodeType.FunktionType, ident, body];
|
1262
|
-
}
|
1263
|
-
|
1264
|
-
function getFunctionBody() {
|
1265
|
-
var startPos = pos,
|
1266
|
-
body = [],
|
1267
|
-
x;
|
1268
|
-
|
1269
|
-
while (tokens[pos].type !== TokenType.RightParenthesis) {
|
1270
|
-
if (checkTset(pos)) {
|
1271
|
-
x = getTset();
|
1272
|
-
if ((needInfo && typeof x[1] === 'string') || typeof x[0] === 'string') body.push(x);
|
1273
|
-
else body = body.concat(x);
|
1274
|
-
} else if (checkClazz(pos)) {
|
1275
|
-
body.push(getClazz());
|
1276
|
-
} else {
|
1277
|
-
throwError();
|
1278
|
-
}
|
1279
|
-
}
|
1280
|
-
|
1281
|
-
pos++;
|
1282
|
-
|
1283
|
-
return (needInfo?
|
1284
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.FunctionBodyType] :
|
1285
|
-
[CSSPNodeType.FunctionBodyType]
|
1286
|
-
).concat(body);
|
1287
|
-
}
|
1288
|
-
|
1289
|
-
function getNotFunctionBody() {
|
1290
|
-
var startPos = pos,
|
1291
|
-
body = [],
|
1292
|
-
x;
|
1293
|
-
|
1294
|
-
while (tokens[pos].type !== TokenType.RightParenthesis) {
|
1295
|
-
if (checkSimpleselector(pos)) {
|
1296
|
-
body.push(getSimpleSelector());
|
1297
|
-
} else {
|
1298
|
-
throwError();
|
1299
|
-
}
|
1300
|
-
}
|
1301
|
-
|
1302
|
-
pos++;
|
1303
|
-
|
1304
|
-
return (needInfo?
|
1305
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.FunctionBodyType] :
|
1306
|
-
[CSSPNodeType.FunctionBodyType]
|
1307
|
-
).concat(body);
|
1308
|
-
}
|
1309
|
-
|
1310
|
-
// node: Ident
|
1311
|
-
function checkIdent(_i) {
|
1312
|
-
var start = _i,
|
1313
|
-
wasIdent = false;
|
1314
|
-
|
1315
|
-
// start char / word
|
1316
|
-
if (_i < tokens.length &&
|
1317
|
-
(tokens[_i].type === TokenType.HyphenMinus ||
|
1318
|
-
tokens[_i].type === TokenType.LowLine ||
|
1319
|
-
tokens[_i].type === TokenType.Identifier ||
|
1320
|
-
tokens[_i].type === TokenType.DollarSign ||
|
1321
|
-
tokens[_i].type === TokenType.Asterisk)) _i++;
|
1322
|
-
else return fail(tokens[_i]);
|
1323
|
-
|
1324
|
-
wasIdent = tokens[_i - 1].type === TokenType.Identifier;
|
1325
|
-
|
1326
|
-
for (; _i < tokens.length; _i++) {
|
1327
|
-
if (tokens[_i].type !== TokenType.HyphenMinus &&
|
1328
|
-
tokens[_i].type !== TokenType.LowLine) {
|
1329
|
-
if (tokens[_i].type !== TokenType.Identifier &&
|
1330
|
-
(tokens[_i].type !== TokenType.DecimalNumber || !wasIdent)
|
1331
|
-
) break;
|
1332
|
-
else wasIdent = true;
|
1333
|
-
}
|
1334
|
-
}
|
1335
|
-
|
1336
|
-
if (!wasIdent && tokens[start].type !== TokenType.Asterisk) return fail(tokens[_i]);
|
1337
|
-
|
1338
|
-
tokens[start].ident_last = _i - 1;
|
1339
|
-
|
1340
|
-
return _i - start;
|
1341
|
-
}
|
1342
|
-
|
1343
|
-
function getIdent() {
|
1344
|
-
var startPos = pos,
|
1345
|
-
s = joinValues(pos, tokens[pos].ident_last);
|
1346
|
-
|
1347
|
-
pos = tokens[pos].ident_last + 1;
|
1348
|
-
|
1349
|
-
return needInfo?
|
1350
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.IdentType, s] :
|
1351
|
-
[CSSPNodeType.IdentType, s];
|
1352
|
-
}
|
1353
|
-
|
1354
|
-
//important = '!' sc*:s0 seq('important') -> [#important].concat(s0)
|
1355
|
-
function checkImportant(_i) {
|
1356
|
-
var start = _i,
|
1357
|
-
l;
|
1358
|
-
|
1359
|
-
if (tokens[_i++].type !== TokenType.ExclamationMark) return fail(tokens[_i - 1]);
|
1360
|
-
|
1361
|
-
if (l = checkSC(_i)) _i += l;
|
1362
|
-
|
1363
|
-
if (tokens[_i].value !== 'important') return fail(tokens[_i]);
|
1364
|
-
|
1365
|
-
return _i - start + 1;
|
1366
|
-
}
|
1367
|
-
|
1368
|
-
function getImportant() {
|
1369
|
-
var startPos = pos;
|
1370
|
-
|
1371
|
-
pos++;
|
1372
|
-
|
1373
|
-
var sc = getSC();
|
1374
|
-
|
1375
|
-
pos++;
|
1376
|
-
|
1377
|
-
return (needInfo? [{ ln: tokens[startPos].ln }, CSSPNodeType.ImportantType] : [CSSPNodeType.ImportantType]).concat(sc);
|
1378
|
-
}
|
1379
|
-
|
1380
|
-
// node: Namespace
|
1381
|
-
function checkNamespace(_i) {
|
1382
|
-
if (tokens[_i].type === TokenType.VerticalLine) return 1;
|
1383
|
-
|
1384
|
-
return fail(tokens[_i]);
|
1385
|
-
}
|
1386
|
-
|
1387
|
-
function getNamespace() {
|
1388
|
-
var startPos = pos;
|
1389
|
-
|
1390
|
-
pos++;
|
1391
|
-
|
1392
|
-
return needInfo?
|
1393
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.NamespaceType] :
|
1394
|
-
[CSSPNodeType.NamespaceType];
|
1395
|
-
}
|
1396
|
-
|
1397
|
-
//nth = (digit | 'n')+:x -> [#nth, x.join('')]
|
1398
|
-
// | (seq('even') | seq('odd')):x -> [#nth, x]
|
1399
|
-
function checkNth(_i) {
|
1400
|
-
return checkNth1(_i) || checkNth2(_i);
|
1401
|
-
}
|
1402
|
-
|
1403
|
-
function checkNth1(_i) {
|
1404
|
-
var start = _i;
|
1405
|
-
|
1406
|
-
for (; _i < tokens.length; _i++) {
|
1407
|
-
if (tokens[_i].type !== TokenType.DecimalNumber && tokens[_i].value !== 'n') break;
|
1408
|
-
}
|
1409
|
-
|
1410
|
-
if (_i !== start) {
|
1411
|
-
tokens[start].nth_last = _i - 1;
|
1412
|
-
return _i - start;
|
1413
|
-
}
|
1414
|
-
|
1415
|
-
return fail(tokens[_i]);
|
1416
|
-
}
|
1417
|
-
|
1418
|
-
function getNth() {
|
1419
|
-
var startPos = pos;
|
1420
|
-
|
1421
|
-
if (tokens[pos].nth_last) {
|
1422
|
-
var n = needInfo?
|
1423
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.NthType, joinValues(pos, tokens[pos].nth_last)] :
|
1424
|
-
[CSSPNodeType.NthType, joinValues(pos, tokens[pos].nth_last)];
|
1425
|
-
|
1426
|
-
pos = tokens[pos].nth_last + 1;
|
1427
|
-
|
1428
|
-
return n;
|
1429
|
-
}
|
1430
|
-
|
1431
|
-
return needInfo?
|
1432
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.NthType, tokens[pos++].value] :
|
1433
|
-
[CSSPNodeType.NthType, tokens[pos++].value];
|
1434
|
-
}
|
1435
|
-
|
1436
|
-
function checkNth2(_i) {
|
1437
|
-
if (tokens[_i].value === 'even' || tokens[_i].value === 'odd') return 1;
|
1438
|
-
|
1439
|
-
return fail(tokens[_i]);
|
1440
|
-
}
|
1441
|
-
|
1442
|
-
//nthf = ':' seq('nth-'):x (seq('child') | seq('last-child') | seq('of-type') | seq('last-of-type')):y -> (x + y)
|
1443
|
-
function checkNthf(_i) {
|
1444
|
-
var start = _i,
|
1445
|
-
l = 0;
|
1446
|
-
|
1447
|
-
if (tokens[_i++].type !== TokenType.Colon) return fail(tokens[_i - 1]); l++;
|
1448
|
-
|
1449
|
-
if (tokens[_i++].value !== 'nth' || tokens[_i++].value !== '-') return fail(tokens[_i - 1]); l += 2;
|
1450
|
-
|
1451
|
-
if ('child' === tokens[_i].value) {
|
1452
|
-
l += 1;
|
1453
|
-
} else if ('last-child' === tokens[_i].value +
|
1454
|
-
tokens[_i + 1].value +
|
1455
|
-
tokens[_i + 2].value) {
|
1456
|
-
l += 3;
|
1457
|
-
} else if ('of-type' === tokens[_i].value +
|
1458
|
-
tokens[_i + 1].value +
|
1459
|
-
tokens[_i + 2].value) {
|
1460
|
-
l += 3;
|
1461
|
-
} else if ('last-of-type' === tokens[_i].value +
|
1462
|
-
tokens[_i + 1].value +
|
1463
|
-
tokens[_i + 2].value +
|
1464
|
-
tokens[_i + 3].value +
|
1465
|
-
tokens[_i + 4].value) {
|
1466
|
-
l += 5;
|
1467
|
-
} else return fail(tokens[_i]);
|
1468
|
-
|
1469
|
-
tokens[start + 1].nthf_last = start + l - 1;
|
1470
|
-
|
1471
|
-
return l;
|
1472
|
-
}
|
1473
|
-
|
1474
|
-
function getNthf() {
|
1475
|
-
pos++;
|
1476
|
-
|
1477
|
-
var s = joinValues(pos, tokens[pos].nthf_last);
|
1478
|
-
|
1479
|
-
pos = tokens[pos].nthf_last + 1;
|
1480
|
-
|
1481
|
-
return s;
|
1482
|
-
}
|
1483
|
-
|
1484
|
-
//nthselector = nthf:x '(' (sc | unary | nth)*:y ')' -> [#nthselector, [#ident, x]].concat(y)
|
1485
|
-
function checkNthselector(_i) {
|
1486
|
-
var start = _i,
|
1487
|
-
l;
|
1488
|
-
|
1489
|
-
if (l = checkNthf(_i)) _i += l;
|
1490
|
-
else return fail(tokens[_i]);
|
1491
|
-
|
1492
|
-
if (tokens[_i].type !== TokenType.LeftParenthesis || !tokens[_i].right) return fail(tokens[_i]);
|
1493
|
-
|
1494
|
-
l++;
|
1495
|
-
|
1496
|
-
var rp = tokens[_i++].right;
|
1497
|
-
|
1498
|
-
while (_i < rp) {
|
1499
|
-
if (l = checkSC(_i)) _i += l;
|
1500
|
-
else if (l = checkUnary(_i)) _i += l;
|
1501
|
-
else if (l = checkNth(_i)) _i += l;
|
1502
|
-
else return fail(tokens[_i]);
|
1503
|
-
}
|
1504
|
-
|
1505
|
-
return rp - start + 1;
|
1506
|
-
}
|
1507
|
-
|
1508
|
-
function getNthselector() {
|
1509
|
-
var startPos = pos,
|
1510
|
-
nthf = needInfo?
|
1511
|
-
[{ ln: tokens[pos].ln }, CSSPNodeType.IdentType, getNthf()] :
|
1512
|
-
[CSSPNodeType.IdentType, getNthf()],
|
1513
|
-
ns = needInfo?
|
1514
|
-
[{ ln: tokens[pos].ln }, CSSPNodeType.NthselectorType, nthf] :
|
1515
|
-
[CSSPNodeType.NthselectorType, nthf];
|
1516
|
-
|
1517
|
-
pos++;
|
1518
|
-
|
1519
|
-
while (tokens[pos].type !== TokenType.RightParenthesis) {
|
1520
|
-
if (checkSC(pos)) ns = ns.concat(getSC());
|
1521
|
-
else if (checkUnary(pos)) ns.push(getUnary());
|
1522
|
-
else if (checkNth(pos)) ns.push(getNth());
|
1523
|
-
}
|
1524
|
-
|
1525
|
-
pos++;
|
1526
|
-
|
1527
|
-
return ns;
|
1528
|
-
}
|
1529
|
-
|
1530
|
-
// node: Number
|
1531
|
-
function checkNumber(_i) {
|
1532
|
-
if (_i < tokens.length && tokens[_i].number_l) return tokens[_i].number_l;
|
1533
|
-
|
1534
|
-
if (_i < tokens.length && tokens[_i].type === TokenType.DecimalNumber &&
|
1535
|
-
(!tokens[_i + 1] ||
|
1536
|
-
(tokens[_i + 1] && tokens[_i + 1].type !== TokenType.FullStop))
|
1537
|
-
) return (tokens[_i].number_l = 1, tokens[_i].number_l); // 10
|
1538
|
-
|
1539
|
-
if (_i < tokens.length &&
|
1540
|
-
tokens[_i].type === TokenType.DecimalNumber &&
|
1541
|
-
tokens[_i + 1] && tokens[_i + 1].type === TokenType.FullStop &&
|
1542
|
-
(!tokens[_i + 2] || (tokens[_i + 2].type !== TokenType.DecimalNumber))
|
1543
|
-
) return (tokens[_i].number_l = 2, tokens[_i].number_l); // 10.
|
1544
|
-
|
1545
|
-
if (_i < tokens.length &&
|
1546
|
-
tokens[_i].type === TokenType.FullStop &&
|
1547
|
-
tokens[_i + 1].type === TokenType.DecimalNumber
|
1548
|
-
) return (tokens[_i].number_l = 2, tokens[_i].number_l); // .10
|
1549
|
-
|
1550
|
-
if (_i < tokens.length &&
|
1551
|
-
tokens[_i].type === TokenType.DecimalNumber &&
|
1552
|
-
tokens[_i + 1] && tokens[_i + 1].type === TokenType.FullStop &&
|
1553
|
-
tokens[_i + 2] && tokens[_i + 2].type === TokenType.DecimalNumber
|
1554
|
-
) return (tokens[_i].number_l = 3, tokens[_i].number_l); // 10.10
|
1555
|
-
|
1556
|
-
return fail(tokens[_i]);
|
1557
|
-
}
|
1558
|
-
|
1559
|
-
function getNumber() {
|
1560
|
-
var s = '',
|
1561
|
-
startPos = pos,
|
1562
|
-
l = tokens[pos].number_l;
|
1563
|
-
|
1564
|
-
for (var i = 0; i < l; i++) {
|
1565
|
-
s += tokens[pos + i].value;
|
1566
|
-
}
|
1567
|
-
|
1568
|
-
pos += l;
|
1569
|
-
|
1570
|
-
return needInfo?
|
1571
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.NumberType, s] :
|
1572
|
-
[CSSPNodeType.NumberType, s];
|
1573
|
-
}
|
1574
|
-
|
1575
|
-
// node: Operator
|
1576
|
-
function checkOperator(_i) {
|
1577
|
-
if (_i < tokens.length &&
|
1578
|
-
(tokens[_i].type === TokenType.Solidus ||
|
1579
|
-
tokens[_i].type === TokenType.Comma ||
|
1580
|
-
tokens[_i].type === TokenType.Colon ||
|
1581
|
-
tokens[_i].type === TokenType.EqualsSign)) return 1;
|
1582
|
-
|
1583
|
-
return fail(tokens[_i]);
|
1584
|
-
}
|
1585
|
-
|
1586
|
-
function getOperator() {
|
1587
|
-
return needInfo?
|
1588
|
-
[{ ln: tokens[pos].ln }, CSSPNodeType.OperatorType, tokens[pos++].value] :
|
1589
|
-
[CSSPNodeType.OperatorType, tokens[pos++].value];
|
1590
|
-
}
|
1591
|
-
|
1592
|
-
// node: Percentage
|
1593
|
-
function checkPercentage(_i) {
|
1594
|
-
var x = checkNumber(_i);
|
1595
|
-
|
1596
|
-
if (!x || (x && _i + x >= tokens.length)) return fail(tokens[_i]);
|
1597
|
-
|
1598
|
-
if (tokens[_i + x].type === TokenType.PercentSign) return x + 1;
|
1599
|
-
|
1600
|
-
return fail(tokens[_i]);
|
1601
|
-
}
|
1602
|
-
|
1603
|
-
function getPercentage() {
|
1604
|
-
var startPos = pos,
|
1605
|
-
n = getNumber();
|
1606
|
-
|
1607
|
-
pos++;
|
1608
|
-
|
1609
|
-
return needInfo?
|
1610
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.PercentageType, n] :
|
1611
|
-
[CSSPNodeType.PercentageType, n];
|
1612
|
-
}
|
1613
|
-
|
1614
|
-
//progid = sc*:s0 seq('progid:DXImageTransform.Microsoft.'):x letter+:y '(' (m_string | m_comment | ~')' char)+:z ')' sc*:s1
|
1615
|
-
// -> this.concat([#progid], s0, [[#raw, x + y.join('') + '(' + z.join('') + ')']], s1),
|
1616
|
-
function checkProgid(_i) {
|
1617
|
-
var start = _i,
|
1618
|
-
l,
|
1619
|
-
x;
|
1620
|
-
|
1621
|
-
if (l = checkSC(_i)) _i += l;
|
1622
|
-
|
1623
|
-
if ((x = joinValues2(_i, 6)) === 'progid:DXImageTransform.Microsoft.') {
|
1624
|
-
_start = _i;
|
1625
|
-
_i += 6;
|
1626
|
-
} else return fail(tokens[_i - 1]);
|
1627
|
-
|
1628
|
-
if (l = checkIdent(_i)) _i += l;
|
1629
|
-
else return fail(tokens[_i]);
|
1630
|
-
|
1631
|
-
if (l = checkSC(_i)) _i += l;
|
1632
|
-
|
1633
|
-
if (tokens[_i].type === TokenType.LeftParenthesis) {
|
1634
|
-
tokens[start].progid_end = tokens[_i].right;
|
1635
|
-
_i = tokens[_i].right + 1;
|
1636
|
-
} else return fail(tokens[_i]);
|
1637
|
-
|
1638
|
-
if (l = checkSC(_i)) _i += l;
|
1639
|
-
|
1640
|
-
return _i - start;
|
1641
|
-
}
|
1642
|
-
|
1643
|
-
function getProgid() {
|
1644
|
-
var startPos = pos,
|
1645
|
-
progid_end = tokens[pos].progid_end;
|
1646
|
-
|
1647
|
-
return (needInfo? [{ ln: tokens[startPos].ln }, CSSPNodeType.ProgidType] : [CSSPNodeType.ProgidType])
|
1648
|
-
.concat(getSC())
|
1649
|
-
.concat([_getProgid(progid_end)])
|
1650
|
-
.concat(getSC());
|
1651
|
-
}
|
1652
|
-
|
1653
|
-
function _getProgid(progid_end) {
|
1654
|
-
var startPos = pos,
|
1655
|
-
x = joinValues(pos, progid_end);
|
1656
|
-
|
1657
|
-
pos = progid_end + 1;
|
1658
|
-
|
1659
|
-
return needInfo?
|
1660
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.RawType, x] :
|
1661
|
-
[CSSPNodeType.RawType, x];
|
1662
|
-
}
|
1663
|
-
|
1664
|
-
//property = ident:x sc*:s0 -> this.concat([#property, x], s0)
|
1665
|
-
function checkProperty(_i) {
|
1666
|
-
var start = _i,
|
1667
|
-
l;
|
1668
|
-
|
1669
|
-
if (l = checkIdent(_i)) _i += l;
|
1670
|
-
else return fail(tokens[_i]);
|
1671
|
-
|
1672
|
-
if (l = checkSC(_i)) _i += l;
|
1673
|
-
return _i - start;
|
1674
|
-
}
|
1675
|
-
|
1676
|
-
function getProperty() {
|
1677
|
-
var startPos = pos;
|
1678
|
-
|
1679
|
-
return (needInfo?
|
1680
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.PropertyType, getIdent()] :
|
1681
|
-
[CSSPNodeType.PropertyType, getIdent()])
|
1682
|
-
.concat(getSC());
|
1683
|
-
}
|
1684
|
-
|
1685
|
-
function checkPseudo(_i) {
|
1686
|
-
return checkPseudoe(_i) ||
|
1687
|
-
checkPseudoc(_i);
|
1688
|
-
}
|
1689
|
-
|
1690
|
-
function getPseudo() {
|
1691
|
-
if (checkPseudoe(pos)) return getPseudoe();
|
1692
|
-
if (checkPseudoc(pos)) return getPseudoc();
|
1693
|
-
}
|
1694
|
-
|
1695
|
-
function checkPseudoe(_i) {
|
1696
|
-
var l;
|
1697
|
-
|
1698
|
-
if (tokens[_i++].type !== TokenType.Colon) return fail(tokens[_i - 1]);
|
1699
|
-
|
1700
|
-
if (tokens[_i++].type !== TokenType.Colon) return fail(tokens[_i - 1]);
|
1701
|
-
|
1702
|
-
if (l = checkIdent(_i)) return l + 2;
|
1703
|
-
|
1704
|
-
return fail(tokens[_i]);
|
1705
|
-
}
|
1706
|
-
|
1707
|
-
function getPseudoe() {
|
1708
|
-
var startPos = pos;
|
1709
|
-
|
1710
|
-
pos += 2;
|
1711
|
-
|
1712
|
-
return needInfo?
|
1713
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.PseudoeType, getIdent()] :
|
1714
|
-
[CSSPNodeType.PseudoeType, getIdent()];
|
1715
|
-
}
|
1716
|
-
|
1717
|
-
//pseudoc = ':' (funktion | ident):x -> [#pseudoc, x]
|
1718
|
-
function checkPseudoc(_i) {
|
1719
|
-
var l;
|
1720
|
-
|
1721
|
-
if (tokens[_i++].type !== TokenType.Colon) return fail(tokens[_i - 1]);
|
1722
|
-
|
1723
|
-
if ((l = checkFunktion(_i)) || (l = checkIdent(_i))) return l + 1;
|
1724
|
-
|
1725
|
-
return fail(tokens[_i]);
|
1726
|
-
}
|
1727
|
-
|
1728
|
-
function getPseudoc() {
|
1729
|
-
var startPos = pos;
|
1730
|
-
|
1731
|
-
pos++;
|
1732
|
-
|
1733
|
-
return needInfo?
|
1734
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.PseudocType, checkFunktion(pos)? getFunktion() : getIdent()] :
|
1735
|
-
[CSSPNodeType.PseudocType, checkFunktion(pos)? getFunktion() : getIdent()];
|
1736
|
-
}
|
1737
|
-
|
1738
|
-
//ruleset = selector*:x block:y -> this.concat([#ruleset], x, [y])
|
1739
|
-
function checkRuleset(_i) {
|
1740
|
-
var start = _i,
|
1741
|
-
l;
|
1742
|
-
|
1743
|
-
if (tokens[start].ruleset_l !== undefined) return tokens[start].ruleset_l;
|
1744
|
-
|
1745
|
-
while (l = checkSelector(_i)) {
|
1746
|
-
_i += l;
|
1747
|
-
}
|
1748
|
-
|
1749
|
-
if (l = checkBlock(_i)) _i += l;
|
1750
|
-
else return fail(tokens[_i]);
|
1751
|
-
|
1752
|
-
tokens[start].ruleset_l = _i - start;
|
1753
|
-
|
1754
|
-
return _i - start;
|
1755
|
-
}
|
1756
|
-
|
1757
|
-
function getRuleset() {
|
1758
|
-
var ruleset = needInfo? [{ ln: tokens[pos].ln }, CSSPNodeType.RulesetType] : [CSSPNodeType.RulesetType];
|
1759
|
-
|
1760
|
-
while (!checkBlock(pos)) {
|
1761
|
-
ruleset.push(getSelector());
|
1762
|
-
}
|
1763
|
-
|
1764
|
-
ruleset.push(getBlock());
|
1765
|
-
|
1766
|
-
return ruleset;
|
1767
|
-
}
|
1768
|
-
|
1769
|
-
// node: S
|
1770
|
-
function checkS(_i) {
|
1771
|
-
if (tokens[_i].ws) return tokens[_i].ws_last - _i + 1;
|
1772
|
-
|
1773
|
-
return fail(tokens[_i]);
|
1774
|
-
}
|
1775
|
-
|
1776
|
-
function getS() {
|
1777
|
-
var startPos = pos,
|
1778
|
-
s = joinValues(pos, tokens[pos].ws_last);
|
1779
|
-
|
1780
|
-
pos = tokens[pos].ws_last + 1;
|
1781
|
-
|
1782
|
-
return needInfo? [{ ln: tokens[startPos].ln }, CSSPNodeType.SType, s] : [CSSPNodeType.SType, s];
|
1783
|
-
}
|
1784
|
-
|
1785
|
-
function checkSC(_i) {
|
1786
|
-
var l,
|
1787
|
-
lsc = 0;
|
1788
|
-
|
1789
|
-
while (_i < tokens.length) {
|
1790
|
-
if (!(l = checkS(_i)) && !(l = checkComment(_i))) break;
|
1791
|
-
_i += l;
|
1792
|
-
lsc += l;
|
1793
|
-
}
|
1794
|
-
|
1795
|
-
if (lsc) return lsc;
|
1796
|
-
|
1797
|
-
if (_i >= tokens.length) return fail(tokens[tokens.length - 1]);
|
1798
|
-
|
1799
|
-
return fail(tokens[_i]);
|
1800
|
-
}
|
1801
|
-
|
1802
|
-
function getSC() {
|
1803
|
-
var sc = [];
|
1804
|
-
|
1805
|
-
while (pos < tokens.length) {
|
1806
|
-
if (checkS(pos)) sc.push(getS());
|
1807
|
-
else if (checkComment(pos)) sc.push(getComment());
|
1808
|
-
else break;
|
1809
|
-
}
|
1810
|
-
|
1811
|
-
return sc;
|
1812
|
-
}
|
1813
|
-
|
1814
|
-
//selector = (simpleselector | delim)+:x -> this.concat([#selector], x)
|
1815
|
-
function checkSelector(_i) {
|
1816
|
-
var start = _i,
|
1817
|
-
l;
|
1818
|
-
|
1819
|
-
if (_i < tokens.length) {
|
1820
|
-
while (l = checkSimpleselector(_i) || checkDelim(_i)) {
|
1821
|
-
_i += l;
|
1822
|
-
}
|
1823
|
-
|
1824
|
-
tokens[start].selector_end = _i - 1;
|
1825
|
-
|
1826
|
-
return _i - start;
|
1827
|
-
}
|
1828
|
-
}
|
1829
|
-
|
1830
|
-
function getSelector() {
|
1831
|
-
var selector = needInfo? [{ ln: tokens[pos].ln }, CSSPNodeType.SelectorType] : [CSSPNodeType.SelectorType],
|
1832
|
-
selector_end = tokens[pos].selector_end;
|
1833
|
-
|
1834
|
-
while (pos <= selector_end) {
|
1835
|
-
selector.push(checkDelim(pos) ? getDelim() : getSimpleSelector());
|
1836
|
-
}
|
1837
|
-
|
1838
|
-
return selector;
|
1839
|
-
}
|
1840
|
-
|
1841
|
-
// node: Shash
|
1842
|
-
function checkShash(_i) {
|
1843
|
-
if (tokens[_i].type !== TokenType.NumberSign) return fail(tokens[_i]);
|
1844
|
-
|
1845
|
-
var l = checkNmName(_i + 1);
|
1846
|
-
|
1847
|
-
if (l) return l + 1;
|
1848
|
-
|
1849
|
-
return fail(tokens[_i]);
|
1850
|
-
}
|
1851
|
-
|
1852
|
-
function getShash() {
|
1853
|
-
var startPos = pos;
|
1854
|
-
|
1855
|
-
pos++;
|
1856
|
-
|
1857
|
-
return needInfo?
|
1858
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.ShashType, getNmName()] :
|
1859
|
-
[CSSPNodeType.ShashType, getNmName()];
|
1860
|
-
}
|
1861
|
-
|
1862
|
-
//simpleselector = (nthselector | combinator | attrib | pseudo | clazz | shash | any | sc | namespace)+:x -> this.concatContent([#simpleselector], [x])
|
1863
|
-
function checkSimpleselector(_i) {
|
1864
|
-
var start = _i,
|
1865
|
-
l;
|
1866
|
-
|
1867
|
-
while (_i < tokens.length) {
|
1868
|
-
if (l = _checkSimpleSelector(_i)) _i += l;
|
1869
|
-
else break;
|
1870
|
-
}
|
1871
|
-
|
1872
|
-
if (_i - start) return _i - start;
|
1873
|
-
|
1874
|
-
if (_i >= tokens.length) return fail(tokens[tokens.length - 1]);
|
1875
|
-
|
1876
|
-
return fail(tokens[_i]);
|
1877
|
-
}
|
1878
|
-
|
1879
|
-
function _checkSimpleSelector(_i) {
|
1880
|
-
return checkNthselector(_i) ||
|
1881
|
-
checkCombinator(_i) ||
|
1882
|
-
checkAttrib(_i) ||
|
1883
|
-
checkPseudo(_i) ||
|
1884
|
-
checkClazz(_i) ||
|
1885
|
-
checkShash(_i) ||
|
1886
|
-
checkAny(_i) ||
|
1887
|
-
checkSC(_i) ||
|
1888
|
-
checkNamespace(_i);
|
1889
|
-
}
|
1890
|
-
|
1891
|
-
function getSimpleSelector() {
|
1892
|
-
var ss = needInfo? [{ ln: tokens[pos].ln }, CSSPNodeType.SimpleselectorType] : [CSSPNodeType.SimpleselectorType],
|
1893
|
-
t;
|
1894
|
-
|
1895
|
-
while (pos < tokens.length && _checkSimpleSelector(pos)) {
|
1896
|
-
t = _getSimpleSelector();
|
1897
|
-
|
1898
|
-
if ((needInfo && typeof t[1] === 'string') || typeof t[0] === 'string') ss.push(t);
|
1899
|
-
else ss = ss.concat(t);
|
1900
|
-
}
|
1901
|
-
|
1902
|
-
return ss;
|
1903
|
-
}
|
1904
|
-
|
1905
|
-
function _getSimpleSelector() {
|
1906
|
-
if (checkNthselector(pos)) return getNthselector();
|
1907
|
-
else if (checkCombinator(pos)) return getCombinator();
|
1908
|
-
else if (checkAttrib(pos)) return getAttrib();
|
1909
|
-
else if (checkPseudo(pos)) return getPseudo();
|
1910
|
-
else if (checkClazz(pos)) return getClazz();
|
1911
|
-
else if (checkShash(pos)) return getShash();
|
1912
|
-
else if (checkAny(pos)) return getAny();
|
1913
|
-
else if (checkSC(pos)) return getSC();
|
1914
|
-
else if (checkNamespace(pos)) return getNamespace();
|
1915
|
-
}
|
1916
|
-
|
1917
|
-
// node: String
|
1918
|
-
function checkString(_i) {
|
1919
|
-
if (_i < tokens.length &&
|
1920
|
-
(tokens[_i].type === TokenType.StringSQ || tokens[_i].type === TokenType.StringDQ)
|
1921
|
-
) return 1;
|
1922
|
-
|
1923
|
-
return fail(tokens[_i]);
|
1924
|
-
}
|
1925
|
-
|
1926
|
-
function getString() {
|
1927
|
-
var startPos = pos;
|
1928
|
-
|
1929
|
-
return needInfo?
|
1930
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.StringType, tokens[pos++].value] :
|
1931
|
-
[CSSPNodeType.StringType, tokens[pos++].value];
|
1932
|
-
}
|
1933
|
-
|
1934
|
-
//stylesheet = (cdo | cdc | sc | statement)*:x -> this.concat([#stylesheet], x)
|
1935
|
-
function checkStylesheet(_i) {
|
1936
|
-
var start = _i,
|
1937
|
-
l;
|
1938
|
-
|
1939
|
-
while (_i < tokens.length) {
|
1940
|
-
if (l = checkSC(_i)) _i += l;
|
1941
|
-
else {
|
1942
|
-
currentBlockLN = tokens[_i].ln;
|
1943
|
-
if (l = checkAtrule(_i)) _i += l;
|
1944
|
-
else if (l = checkRuleset(_i)) _i += l;
|
1945
|
-
else if (l = checkUnknown(_i)) _i += l;
|
1946
|
-
else throwError();
|
1947
|
-
}
|
1948
|
-
}
|
1949
|
-
|
1950
|
-
return _i - start;
|
1951
|
-
}
|
1952
|
-
|
1953
|
-
function getStylesheet(_i) {
|
1954
|
-
var t,
|
1955
|
-
stylesheet = needInfo? [{ ln: tokens[pos].ln }, CSSPNodeType.StylesheetType] : [CSSPNodeType.StylesheetType];
|
1956
|
-
|
1957
|
-
while (pos < tokens.length) {
|
1958
|
-
if (checkSC(pos)) stylesheet = stylesheet.concat(getSC());
|
1959
|
-
else {
|
1960
|
-
currentBlockLN = tokens[pos].ln;
|
1961
|
-
if (checkRuleset(pos)) stylesheet.push(getRuleset());
|
1962
|
-
else if (checkAtrule(pos)) stylesheet.push(getAtrule());
|
1963
|
-
else if (checkUnknown(pos)) stylesheet.push(getUnknown());
|
1964
|
-
else throwError();
|
1965
|
-
}
|
1966
|
-
}
|
1967
|
-
|
1968
|
-
return stylesheet;
|
1969
|
-
}
|
1970
|
-
|
1971
|
-
//tset = vhash | any | sc | operator
|
1972
|
-
function checkTset(_i) {
|
1973
|
-
return checkVhash(_i) ||
|
1974
|
-
checkAny(_i) ||
|
1975
|
-
checkSC(_i) ||
|
1976
|
-
checkOperator(_i);
|
1977
|
-
}
|
1978
|
-
|
1979
|
-
function getTset() {
|
1980
|
-
if (checkVhash(pos)) return getVhash();
|
1981
|
-
else if (checkAny(pos)) return getAny();
|
1982
|
-
else if (checkSC(pos)) return getSC();
|
1983
|
-
else if (checkOperator(pos)) return getOperator();
|
1984
|
-
}
|
1985
|
-
|
1986
|
-
function checkTsets(_i) {
|
1987
|
-
var start = _i,
|
1988
|
-
l;
|
1989
|
-
|
1990
|
-
while (l = checkTset(_i)) {
|
1991
|
-
_i += l;
|
1992
|
-
}
|
1993
|
-
|
1994
|
-
return _i - start;
|
1995
|
-
}
|
1996
|
-
|
1997
|
-
function getTsets() {
|
1998
|
-
var tsets = [],
|
1999
|
-
x;
|
2000
|
-
|
2001
|
-
while (x = getTset()) {
|
2002
|
-
if ((needInfo && typeof x[1] === 'string') || typeof x[0] === 'string') tsets.push(x);
|
2003
|
-
else tsets = tsets.concat(x);
|
2004
|
-
}
|
2005
|
-
|
2006
|
-
return tsets;
|
2007
|
-
}
|
2008
|
-
|
2009
|
-
// node: Unary
|
2010
|
-
function checkUnary(_i) {
|
2011
|
-
if (_i < tokens.length &&
|
2012
|
-
(tokens[_i].type === TokenType.HyphenMinus ||
|
2013
|
-
tokens[_i].type === TokenType.PlusSign)
|
2014
|
-
) return 1;
|
2015
|
-
|
2016
|
-
return fail(tokens[_i]);
|
2017
|
-
}
|
2018
|
-
|
2019
|
-
function getUnary() {
|
2020
|
-
var startPos = pos;
|
2021
|
-
|
2022
|
-
return needInfo?
|
2023
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.UnaryType, tokens[pos++].value] :
|
2024
|
-
[CSSPNodeType.UnaryType, tokens[pos++].value];
|
2025
|
-
}
|
2026
|
-
|
2027
|
-
// node: Unknown
|
2028
|
-
function checkUnknown(_i) {
|
2029
|
-
if (_i < tokens.length && tokens[_i].type === TokenType.CommentSL) return 1;
|
2030
|
-
|
2031
|
-
return fail(tokens[_i]);
|
2032
|
-
}
|
2033
|
-
|
2034
|
-
function getUnknown() {
|
2035
|
-
var startPos = pos;
|
2036
|
-
|
2037
|
-
return needInfo?
|
2038
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.UnknownType, tokens[pos++].value] :
|
2039
|
-
[CSSPNodeType.UnknownType, tokens[pos++].value];
|
2040
|
-
}
|
2041
|
-
|
2042
|
-
// uri = seq('url(') sc*:s0 string:x sc*:s1 ')' -> this.concat([#uri], s0, [x], s1)
|
2043
|
-
// | seq('url(') sc*:s0 (~')' ~m_w char)*:x sc*:s1 ')' -> this.concat([#uri], s0, [[#raw, x.join('')]], s1),
|
2044
|
-
function checkUri(_i) {
|
2045
|
-
var start = _i,
|
2046
|
-
l;
|
2047
|
-
|
2048
|
-
if (_i < tokens.length && tokens[_i++].value !== 'url') return fail(tokens[_i - 1]);
|
2049
|
-
|
2050
|
-
if (!tokens[_i] || tokens[_i].type !== TokenType.LeftParenthesis) return fail(tokens[_i]);
|
2051
|
-
|
2052
|
-
return tokens[_i].right - start + 1;
|
2053
|
-
}
|
2054
|
-
|
2055
|
-
function getUri() {
|
2056
|
-
var startPos = pos,
|
2057
|
-
uriExcluding = {};
|
2058
|
-
|
2059
|
-
pos += 2;
|
2060
|
-
|
2061
|
-
uriExcluding[TokenType.Space] = 1;
|
2062
|
-
uriExcluding[TokenType.Tab] = 1;
|
2063
|
-
uriExcluding[TokenType.Newline] = 1;
|
2064
|
-
uriExcluding[TokenType.LeftParenthesis] = 1;
|
2065
|
-
uriExcluding[TokenType.RightParenthesis] = 1;
|
2066
|
-
|
2067
|
-
if (checkUri1(pos)) {
|
2068
|
-
var uri = (needInfo? [{ ln: tokens[startPos].ln }, CSSPNodeType.UriType] : [CSSPNodeType.UriType])
|
2069
|
-
.concat(getSC())
|
2070
|
-
.concat([getString()])
|
2071
|
-
.concat(getSC());
|
2072
|
-
|
2073
|
-
pos++;
|
2074
|
-
|
2075
|
-
return uri;
|
2076
|
-
} else {
|
2077
|
-
var uri = (needInfo? [{ ln: tokens[startPos].ln }, CSSPNodeType.UriType] : [CSSPNodeType.UriType])
|
2078
|
-
.concat(getSC()),
|
2079
|
-
l = checkExcluding(uriExcluding, pos),
|
2080
|
-
raw = needInfo?
|
2081
|
-
[{ ln: tokens[pos].ln }, CSSPNodeType.RawType, joinValues(pos, pos + l)] :
|
2082
|
-
[CSSPNodeType.RawType, joinValues(pos, pos + l)];
|
2083
|
-
|
2084
|
-
uri.push(raw);
|
2085
|
-
|
2086
|
-
pos += l + 1;
|
2087
|
-
|
2088
|
-
uri = uri.concat(getSC());
|
2089
|
-
|
2090
|
-
pos++;
|
2091
|
-
|
2092
|
-
return uri;
|
2093
|
-
}
|
2094
|
-
}
|
2095
|
-
|
2096
|
-
function checkUri1(_i) {
|
2097
|
-
var start = _i,
|
2098
|
-
l = checkSC(_i);
|
2099
|
-
|
2100
|
-
if (l) _i += l;
|
2101
|
-
|
2102
|
-
if (tokens[_i].type !== TokenType.StringDQ && tokens[_i].type !== TokenType.StringSQ) return fail(tokens[_i]);
|
2103
|
-
|
2104
|
-
_i++;
|
2105
|
-
|
2106
|
-
if (l = checkSC(_i)) _i += l;
|
2107
|
-
|
2108
|
-
return _i - start;
|
2109
|
-
}
|
2110
|
-
|
2111
|
-
// value = (sc | vhash | any | block | atkeyword | operator | important)+:x -> this.concat([#value], x)
|
2112
|
-
function checkValue(_i) {
|
2113
|
-
var start = _i,
|
2114
|
-
l;
|
2115
|
-
|
2116
|
-
while (_i < tokens.length) {
|
2117
|
-
if (l = _checkValue(_i)) _i += l;
|
2118
|
-
else break;
|
2119
|
-
}
|
2120
|
-
|
2121
|
-
if (_i - start) return _i - start;
|
2122
|
-
|
2123
|
-
return fail(tokens[_i]);
|
2124
|
-
}
|
2125
|
-
|
2126
|
-
function _checkValue(_i) {
|
2127
|
-
return checkSC(_i) ||
|
2128
|
-
checkVhash(_i) ||
|
2129
|
-
checkAny(_i) ||
|
2130
|
-
checkBlock(_i) ||
|
2131
|
-
checkAtkeyword(_i) ||
|
2132
|
-
checkOperator(_i) ||
|
2133
|
-
checkImportant(_i);
|
2134
|
-
}
|
2135
|
-
|
2136
|
-
function getValue() {
|
2137
|
-
var ss = needInfo? [{ ln: tokens[pos].ln }, CSSPNodeType.ValueType] : [CSSPNodeType.ValueType],
|
2138
|
-
t;
|
2139
|
-
|
2140
|
-
while (pos < tokens.length && _checkValue(pos)) {
|
2141
|
-
t = _getValue();
|
2142
|
-
|
2143
|
-
if ((needInfo && typeof t[1] === 'string') || typeof t[0] === 'string') ss.push(t);
|
2144
|
-
else ss = ss.concat(t);
|
2145
|
-
}
|
2146
|
-
|
2147
|
-
return ss;
|
2148
|
-
}
|
2149
|
-
|
2150
|
-
function _getValue() {
|
2151
|
-
if (checkSC(pos)) return getSC();
|
2152
|
-
else if (checkVhash(pos)) return getVhash();
|
2153
|
-
else if (checkAny(pos)) return getAny();
|
2154
|
-
else if (checkBlock(pos)) return getBlock();
|
2155
|
-
else if (checkAtkeyword(pos)) return getAtkeyword();
|
2156
|
-
else if (checkOperator(pos)) return getOperator();
|
2157
|
-
else if (checkImportant(pos)) return getImportant();
|
2158
|
-
}
|
2159
|
-
|
2160
|
-
// node: Vhash
|
2161
|
-
function checkVhash(_i) {
|
2162
|
-
if (_i >= tokens.length || tokens[_i].type !== TokenType.NumberSign) return fail(tokens[_i]);
|
2163
|
-
|
2164
|
-
var l = checkNmName2(_i + 1);
|
2165
|
-
|
2166
|
-
if (l) return l + 1;
|
2167
|
-
|
2168
|
-
return fail(tokens[_i]);
|
2169
|
-
}
|
2170
|
-
|
2171
|
-
function getVhash() {
|
2172
|
-
var startPos = pos;
|
2173
|
-
|
2174
|
-
pos++;
|
2175
|
-
|
2176
|
-
return needInfo?
|
2177
|
-
[{ ln: tokens[startPos].ln }, CSSPNodeType.VhashType, getNmName2()] :
|
2178
|
-
[CSSPNodeType.VhashType, getNmName2()];
|
2179
|
-
}
|
2180
|
-
|
2181
|
-
function checkNmName(_i) {
|
2182
|
-
var start = _i;
|
2183
|
-
|
2184
|
-
// start char / word
|
2185
|
-
if (tokens[_i].type === TokenType.HyphenMinus ||
|
2186
|
-
tokens[_i].type === TokenType.LowLine ||
|
2187
|
-
tokens[_i].type === TokenType.Identifier ||
|
2188
|
-
tokens[_i].type === TokenType.DecimalNumber) _i++;
|
2189
|
-
else return fail(tokens[_i]);
|
2190
|
-
|
2191
|
-
for (; _i < tokens.length; _i++) {
|
2192
|
-
if (tokens[_i].type !== TokenType.HyphenMinus &&
|
2193
|
-
tokens[_i].type !== TokenType.LowLine &&
|
2194
|
-
tokens[_i].type !== TokenType.Identifier &&
|
2195
|
-
tokens[_i].type !== TokenType.DecimalNumber) break;
|
2196
|
-
}
|
2197
|
-
|
2198
|
-
tokens[start].nm_name_last = _i - 1;
|
2199
|
-
|
2200
|
-
return _i - start;
|
2201
|
-
}
|
2202
|
-
|
2203
|
-
function getNmName() {
|
2204
|
-
var s = joinValues(pos, tokens[pos].nm_name_last);
|
2205
|
-
|
2206
|
-
pos = tokens[pos].nm_name_last + 1;
|
2207
|
-
|
2208
|
-
return s;
|
2209
|
-
}
|
2210
|
-
|
2211
|
-
function checkNmName2(_i) {
|
2212
|
-
var start = _i;
|
2213
|
-
|
2214
|
-
if (tokens[_i].type === TokenType.Identifier) return 1;
|
2215
|
-
else if (tokens[_i].type !== TokenType.DecimalNumber) return fail(tokens[_i]);
|
2216
|
-
|
2217
|
-
_i++;
|
2218
|
-
|
2219
|
-
if (!tokens[_i] || tokens[_i].type !== TokenType.Identifier) return 1;
|
2220
|
-
|
2221
|
-
return 2;
|
2222
|
-
}
|
2223
|
-
|
2224
|
-
function getNmName2() {
|
2225
|
-
var s = tokens[pos].value;
|
2226
|
-
|
2227
|
-
if (tokens[pos++].type === TokenType.DecimalNumber &&
|
2228
|
-
pos < tokens.length &&
|
2229
|
-
tokens[pos].type === TokenType.Identifier
|
2230
|
-
) s += tokens[pos++].value;
|
2231
|
-
|
2232
|
-
return s;
|
2233
|
-
}
|
2234
|
-
|
2235
|
-
function checkExcluding(exclude, _i) {
|
2236
|
-
var start = _i;
|
2237
|
-
|
2238
|
-
while(_i < tokens.length) {
|
2239
|
-
if (exclude[tokens[_i++].type]) break;
|
2240
|
-
}
|
2241
|
-
|
2242
|
-
return _i - start - 2;
|
2243
|
-
}
|
2244
|
-
|
2245
|
-
function joinValues(start, finish) {
|
2246
|
-
var s = '';
|
2247
|
-
|
2248
|
-
for (var i = start; i < finish + 1; i++) {
|
2249
|
-
s += tokens[i].value;
|
2250
|
-
}
|
2251
|
-
|
2252
|
-
return s;
|
2253
|
-
}
|
2254
|
-
|
2255
|
-
function joinValues2(start, num) {
|
2256
|
-
if (start + num - 1 >= tokens.length) return;
|
2257
|
-
|
2258
|
-
var s = '';
|
2259
|
-
|
2260
|
-
for (var i = 0; i < num; i++) {
|
2261
|
-
s += tokens[start + i].value;
|
2262
|
-
}
|
2263
|
-
|
2264
|
-
return s;
|
2265
|
-
}
|
2266
|
-
|
2267
|
-
function markSC() {
|
2268
|
-
var ws = -1, // whitespaces
|
2269
|
-
sc = -1, // ws and comments
|
2270
|
-
t;
|
2271
|
-
|
2272
|
-
for (var i = 0; i < tokens.length; i++) {
|
2273
|
-
t = tokens[i];
|
2274
|
-
switch (t.type) {
|
2275
|
-
case TokenType.Space:
|
2276
|
-
case TokenType.Tab:
|
2277
|
-
case TokenType.Newline:
|
2278
|
-
t.ws = true;
|
2279
|
-
t.sc = true;
|
2280
|
-
|
2281
|
-
if (ws === -1) ws = i;
|
2282
|
-
if (sc === -1) sc = i;
|
2283
|
-
|
2284
|
-
break;
|
2285
|
-
case TokenType.CommentML:
|
2286
|
-
if (ws !== -1) {
|
2287
|
-
tokens[ws].ws_last = i - 1;
|
2288
|
-
ws = -1;
|
2289
|
-
}
|
2290
|
-
|
2291
|
-
t.sc = true;
|
2292
|
-
|
2293
|
-
break;
|
2294
|
-
default:
|
2295
|
-
if (ws !== -1) {
|
2296
|
-
tokens[ws].ws_last = i - 1;
|
2297
|
-
ws = -1;
|
2298
|
-
}
|
2299
|
-
|
2300
|
-
if (sc !== -1) {
|
2301
|
-
tokens[sc].sc_last = i - 1;
|
2302
|
-
sc = -1;
|
2303
|
-
}
|
2304
|
-
}
|
2305
|
-
}
|
2306
|
-
|
2307
|
-
if (ws !== -1) tokens[ws].ws_last = i - 1;
|
2308
|
-
if (sc !== -1) tokens[sc].sc_last = i - 1;
|
2309
|
-
}
|
2310
|
-
|
2311
|
-
return _getAST(_tokens, rule, _needInfo);
|
2312
|
-
}
|
2313
|
-
|
2314
|
-
return getCSSPAST(getTokens(s), rule, _needInfo);
|
2315
|
-
}
|
2316
|
-
var translator = new CSSOTranslator(),
|
2317
|
-
cleanInfo = $util.cleanInfo;
|
2318
|
-
function TRBL(name, imp) {
|
2319
|
-
this.name = TRBL.extractMain(name);
|
2320
|
-
this.sides = {
|
2321
|
-
'top': null,
|
2322
|
-
'right': null,
|
2323
|
-
'bottom': null,
|
2324
|
-
'left': null
|
2325
|
-
};
|
2326
|
-
this.imp = imp ? 4 : 0;
|
2327
|
-
}
|
2328
|
-
|
2329
|
-
TRBL.props = {
|
2330
|
-
'margin': 1,
|
2331
|
-
'margin-top': 1,
|
2332
|
-
'margin-right': 1,
|
2333
|
-
'margin-bottom': 1,
|
2334
|
-
'margin-left': 1,
|
2335
|
-
'padding': 1,
|
2336
|
-
'padding-top': 1,
|
2337
|
-
'padding-right': 1,
|
2338
|
-
'padding-bottom': 1,
|
2339
|
-
'padding-left': 1
|
2340
|
-
};
|
2341
|
-
|
2342
|
-
TRBL.extractMain = function(name) {
|
2343
|
-
var i = name.indexOf('-');
|
2344
|
-
return i === -1 ? name : name.substr(0, i);
|
2345
|
-
};
|
2346
|
-
|
2347
|
-
TRBL.prototype.impSum = function() {
|
2348
|
-
var imp = 0, n = 0;
|
2349
|
-
for (var k in this.sides) {
|
2350
|
-
if (this.sides[k]) {
|
2351
|
-
n++;
|
2352
|
-
if (this.sides[k].imp) imp++;
|
2353
|
-
}
|
2354
|
-
}
|
2355
|
-
return imp === n ? imp : 0;
|
2356
|
-
};
|
2357
|
-
|
2358
|
-
TRBL.prototype.add = function(name, sValue, tValue, imp) {
|
2359
|
-
var s = this.sides,
|
2360
|
-
currentSide,
|
2361
|
-
i, x, side, a = [], last,
|
2362
|
-
imp = imp ? 1 : 0,
|
2363
|
-
wasUnary = false;
|
2364
|
-
if ((i = name.lastIndexOf('-')) !== -1) {
|
2365
|
-
side = name.substr(i + 1);
|
2366
|
-
if (side in s) {
|
2367
|
-
if (!(currentSide = s[side]) || (imp && !currentSide.imp)) {
|
2368
|
-
s[side] = { s: imp ? sValue.substring(0, sValue.length - 10) : sValue, t: [tValue[0]], imp: imp };
|
2369
|
-
if (tValue[0][1] === 'unary') s[side].t.push(tValue[1]);
|
2370
|
-
}
|
2371
|
-
return true;
|
2372
|
-
}
|
2373
|
-
} else if (name === this.name) {
|
2374
|
-
for (i = 0; i < tValue.length; i++) {
|
2375
|
-
x = tValue[i];
|
2376
|
-
last = a[a.length - 1];
|
2377
|
-
switch(x[1]) {
|
2378
|
-
case 'unary':
|
2379
|
-
a.push({ s: x[2], t: [x], imp: imp });
|
2380
|
-
wasUnary = true;
|
2381
|
-
break;
|
2382
|
-
case 'number':
|
2383
|
-
case 'ident':
|
2384
|
-
if (wasUnary) {
|
2385
|
-
last.t.push(x);
|
2386
|
-
last.s += x[2];
|
2387
|
-
} else {
|
2388
|
-
a.push({ s: x[2], t: [x], imp: imp });
|
2389
|
-
}
|
2390
|
-
wasUnary = false;
|
2391
|
-
break;
|
2392
|
-
case 'percentage':
|
2393
|
-
if (wasUnary) {
|
2394
|
-
last.t.push(x);
|
2395
|
-
last.s += x[2][2] + '%';
|
2396
|
-
} else {
|
2397
|
-
a.push({ s: x[2][2] + '%', t: [x], imp: imp });
|
2398
|
-
}
|
2399
|
-
wasUnary = false;
|
2400
|
-
break;
|
2401
|
-
case 'dimension':
|
2402
|
-
if (wasUnary) {
|
2403
|
-
last.t.push(x);
|
2404
|
-
last.s += x[2][2] + x[3][2];
|
2405
|
-
} else {
|
2406
|
-
a.push({ s: x[2][2] + x[3][2], t: [x], imp: imp });
|
2407
|
-
}
|
2408
|
-
wasUnary = false;
|
2409
|
-
break;
|
2410
|
-
case 's':
|
2411
|
-
case 'comment':
|
2412
|
-
case 'important':
|
2413
|
-
break;
|
2414
|
-
default:
|
2415
|
-
return false;
|
2416
|
-
}
|
2417
|
-
}
|
2418
|
-
|
2419
|
-
if (a.length > 4) return false;
|
2420
|
-
|
2421
|
-
if (!a[1]) a[1] = a[0];
|
2422
|
-
if (!a[2]) a[2] = a[0];
|
2423
|
-
if (!a[3]) a[3] = a[1];
|
2424
|
-
|
2425
|
-
if (!s.top) s.top = a[0];
|
2426
|
-
if (!s.right) s.right = a[1];
|
2427
|
-
if (!s.bottom) s.bottom = a[2];
|
2428
|
-
if (!s.left) s.left = a[3];
|
2429
|
-
|
2430
|
-
return true;
|
2431
|
-
}
|
2432
|
-
};
|
2433
|
-
|
2434
|
-
TRBL.prototype.isOkToMinimize = function() {
|
2435
|
-
var s = this.sides,
|
2436
|
-
imp;
|
2437
|
-
|
2438
|
-
if (!!(s.top && s.right && s.bottom && s.left)) {
|
2439
|
-
imp = s.top.imp + s.right.imp + s.bottom.imp + s.left.imp;
|
2440
|
-
return (imp === 0 || imp === 4 || imp === this.imp);
|
2441
|
-
}
|
2442
|
-
return false;
|
2443
|
-
};
|
2444
|
-
|
2445
|
-
TRBL.prototype.getValue = function() {
|
2446
|
-
var s = this.sides,
|
2447
|
-
a = [s.top, s.right, s.bottom, s.left],
|
2448
|
-
r = [{}, 'value'];
|
2449
|
-
|
2450
|
-
if (s.left.s === s.right.s) {
|
2451
|
-
a.length--;
|
2452
|
-
if (s.bottom.s === s.top.s) {
|
2453
|
-
a.length--;
|
2454
|
-
if (s.right.s === s.top.s) {
|
2455
|
-
a.length--;
|
2456
|
-
}
|
2457
|
-
}
|
2458
|
-
}
|
2459
|
-
|
2460
|
-
for (var i = 0; i < a.length - 1; i++) {
|
2461
|
-
r = r.concat(a[i].t);
|
2462
|
-
r.push([{ s: ' ' }, 's', ' ']);
|
2463
|
-
}
|
2464
|
-
r = r.concat(a[i].t);
|
2465
|
-
|
2466
|
-
if (this.impSum()) r.push([{ s: '!important'}, 'important']);
|
2467
|
-
|
2468
|
-
return r;
|
2469
|
-
};
|
2470
|
-
|
2471
|
-
TRBL.prototype.getProperty = function() {
|
2472
|
-
return [{ s: this.name }, 'property', [{ s: this.name }, 'ident', this.name]];
|
2473
|
-
};
|
2474
|
-
|
2475
|
-
TRBL.prototype.getString = function() {
|
2476
|
-
var p = this.getProperty(),
|
2477
|
-
v = this.getValue().slice(2),
|
2478
|
-
r = p[0].s + ':';
|
2479
|
-
|
2480
|
-
for (var i = 0; i < v.length; i++) r += v[i][0].s;
|
2481
|
-
|
2482
|
-
return r;
|
2483
|
-
};
|
2484
|
-
|
2485
|
-
function CSSOCompressor() {}
|
2486
|
-
|
2487
|
-
CSSOCompressor.prototype.init = function() {
|
2488
|
-
this.props = {};
|
2489
|
-
this.shorts = {};
|
2490
|
-
this.shorts2 = {};
|
2491
|
-
|
2492
|
-
this.ccrules = {}; // clean comment rules — special case to resolve ambiguity
|
2493
|
-
this.crules = {}; // compress rules
|
2494
|
-
this.prules = {}; // prepare rules
|
2495
|
-
this.frrules = {}; // freeze ruleset rules
|
2496
|
-
this.msrules = {}; // mark shorthands rules
|
2497
|
-
this.csrules = {}; // clean shorthands rules
|
2498
|
-
this.rbrules = {}; // restructure block rules
|
2499
|
-
this.rjrules = {}; // rejoin ruleset rules
|
2500
|
-
this.rrrules = {}; // restructure ruleset rules
|
2501
|
-
this.frules = {}; // finalize rules
|
2502
|
-
|
2503
|
-
this.initRules(this.crules, this.defCCfg);
|
2504
|
-
this.initRules(this.ccrules, this.cleanCfg);
|
2505
|
-
this.initRules(this.frrules, this.frCfg);
|
2506
|
-
this.initRules(this.prules, this.preCfg);
|
2507
|
-
this.initRules(this.msrules, this.msCfg);
|
2508
|
-
this.initRules(this.csrules, this.csCfg);
|
2509
|
-
this.initRules(this.rbrules, this.defRBCfg);
|
2510
|
-
this.initRules(this.rjrules, this.defRJCfg);
|
2511
|
-
this.initRules(this.rrrules, this.defRRCfg);
|
2512
|
-
this.initRules(this.frules, this.defFCfg);
|
2513
|
-
|
2514
|
-
this.shortGroupID = 0;
|
2515
|
-
this.lastShortGroupID = 0;
|
2516
|
-
this.lastShortSelector = 0;
|
2517
|
-
};
|
2518
|
-
|
2519
|
-
CSSOCompressor.prototype.initRules = function(r, cfg) {
|
2520
|
-
var o = this.order,
|
2521
|
-
p = this.profile,
|
2522
|
-
x, i, k,
|
2523
|
-
t = [];
|
2524
|
-
|
2525
|
-
for (i = 0; i < o.length; i++) if (o[i] in cfg) t.push(o[i]);
|
2526
|
-
|
2527
|
-
if (!t.length) t = o;
|
2528
|
-
for (i = 0; i < t.length; i++) {
|
2529
|
-
x = p[t[i]];
|
2530
|
-
for (k in x) r[k] ? r[k].push(t[i]) : r[k] = [t[i]];
|
2531
|
-
}
|
2532
|
-
};
|
2533
|
-
|
2534
|
-
CSSOCompressor.prototype.cleanCfg = {
|
2535
|
-
'cleanComment': 1
|
2536
|
-
};
|
2537
|
-
|
2538
|
-
CSSOCompressor.prototype.defCCfg = {
|
2539
|
-
'cleanCharset': 1,
|
2540
|
-
'cleanImport': 1,
|
2541
|
-
'cleanWhitespace': 1,
|
2542
|
-
'cleanDecldelim': 1,
|
2543
|
-
'compressNumber': 1,
|
2544
|
-
'cleanUnary': 1,
|
2545
|
-
'compressColor': 1,
|
2546
|
-
'compressDimension': 1,
|
2547
|
-
'compressString': 1,
|
2548
|
-
'compressFontWeight': 1,
|
2549
|
-
'compressFont': 1,
|
2550
|
-
'compressBackground': 1,
|
2551
|
-
'cleanEmpty': 1
|
2552
|
-
};
|
2553
|
-
|
2554
|
-
CSSOCompressor.prototype.defRBCfg = {
|
2555
|
-
'restructureBlock': 1
|
2556
|
-
};
|
2557
|
-
|
2558
|
-
CSSOCompressor.prototype.defRJCfg = {
|
2559
|
-
'rejoinRuleset': 1,
|
2560
|
-
'cleanEmpty': 1
|
2561
|
-
};
|
2562
|
-
|
2563
|
-
CSSOCompressor.prototype.defRRCfg = {
|
2564
|
-
'restructureRuleset': 1,
|
2565
|
-
'cleanEmpty': 1
|
2566
|
-
};
|
2567
|
-
|
2568
|
-
CSSOCompressor.prototype.defFCfg = {
|
2569
|
-
'cleanEmpty': 1,
|
2570
|
-
'delimSelectors': 1,
|
2571
|
-
'delimBlocks': 1
|
2572
|
-
};
|
2573
|
-
|
2574
|
-
CSSOCompressor.prototype.preCfg = {
|
2575
|
-
'destroyDelims': 1,
|
2576
|
-
'preTranslate': 1
|
2577
|
-
};
|
2578
|
-
|
2579
|
-
CSSOCompressor.prototype.msCfg = {
|
2580
|
-
'markShorthands': 1
|
2581
|
-
};
|
2582
|
-
|
2583
|
-
CSSOCompressor.prototype.frCfg = {
|
2584
|
-
'freezeRulesets': 1
|
2585
|
-
};
|
2586
|
-
|
2587
|
-
CSSOCompressor.prototype.csCfg = {
|
2588
|
-
'cleanShorthands': 1,
|
2589
|
-
'cleanEmpty': 1
|
2590
|
-
};
|
2591
|
-
|
2592
|
-
CSSOCompressor.prototype.order = [
|
2593
|
-
'cleanCharset',
|
2594
|
-
'cleanImport',
|
2595
|
-
'cleanComment',
|
2596
|
-
'cleanWhitespace',
|
2597
|
-
'compressNumber',
|
2598
|
-
'cleanUnary',
|
2599
|
-
'compressColor',
|
2600
|
-
'compressDimension',
|
2601
|
-
'compressString',
|
2602
|
-
'compressFontWeight',
|
2603
|
-
'compressFont',
|
2604
|
-
'compressBackground',
|
2605
|
-
'freezeRulesets',
|
2606
|
-
'destroyDelims',
|
2607
|
-
'preTranslate',
|
2608
|
-
'markShorthands',
|
2609
|
-
'cleanShorthands',
|
2610
|
-
'restructureBlock',
|
2611
|
-
'rejoinRuleset',
|
2612
|
-
'restructureRuleset',
|
2613
|
-
'cleanEmpty',
|
2614
|
-
'delimSelectors',
|
2615
|
-
'delimBlocks'
|
2616
|
-
];
|
2617
|
-
|
2618
|
-
CSSOCompressor.prototype.profile = {
|
2619
|
-
'cleanCharset': {
|
2620
|
-
'atrules': 1
|
2621
|
-
},
|
2622
|
-
'cleanImport': {
|
2623
|
-
'atrules': 1
|
2624
|
-
},
|
2625
|
-
'cleanWhitespace': {
|
2626
|
-
's': 1
|
2627
|
-
},
|
2628
|
-
'compressNumber': {
|
2629
|
-
'number': 1
|
2630
|
-
},
|
2631
|
-
'cleanUnary': {
|
2632
|
-
'unary': 1
|
2633
|
-
},
|
2634
|
-
'compressColor': {
|
2635
|
-
'vhash': 1,
|
2636
|
-
'funktion': 1,
|
2637
|
-
'ident': 1
|
2638
|
-
},
|
2639
|
-
'compressDimension': {
|
2640
|
-
'dimension': 1
|
2641
|
-
},
|
2642
|
-
'compressString': {
|
2643
|
-
'string': 1
|
2644
|
-
},
|
2645
|
-
'compressFontWeight': {
|
2646
|
-
'declaration': 1
|
2647
|
-
},
|
2648
|
-
'compressFont': {
|
2649
|
-
'declaration': 1
|
2650
|
-
},
|
2651
|
-
'compressBackground': {
|
2652
|
-
'declaration': 1
|
2653
|
-
},
|
2654
|
-
'cleanComment': {
|
2655
|
-
'comment': 1
|
2656
|
-
},
|
2657
|
-
'cleanDecldelim': {
|
2658
|
-
'block': 1
|
2659
|
-
},
|
2660
|
-
'cleanEmpty': {
|
2661
|
-
'ruleset': 1,
|
2662
|
-
'atruleb': 1,
|
2663
|
-
'atruler': 1
|
2664
|
-
},
|
2665
|
-
'destroyDelims': {
|
2666
|
-
'decldelim': 1,
|
2667
|
-
'delim': 1
|
2668
|
-
},
|
2669
|
-
'preTranslate': {
|
2670
|
-
'declaration': 1,
|
2671
|
-
'property': 1,
|
2672
|
-
'simpleselector': 1,
|
2673
|
-
'filter': 1,
|
2674
|
-
'value': 1,
|
2675
|
-
'number': 1,
|
2676
|
-
'percentage': 1,
|
2677
|
-
'dimension': 1,
|
2678
|
-
'ident': 1
|
2679
|
-
},
|
2680
|
-
'restructureBlock': {
|
2681
|
-
'block': 1
|
2682
|
-
},
|
2683
|
-
'rejoinRuleset': {
|
2684
|
-
'ruleset': 1
|
2685
|
-
},
|
2686
|
-
'restructureRuleset': {
|
2687
|
-
'ruleset': 1
|
2688
|
-
},
|
2689
|
-
'delimSelectors': {
|
2690
|
-
'selector': 1
|
2691
|
-
},
|
2692
|
-
'delimBlocks': {
|
2693
|
-
'block': 1
|
2694
|
-
},
|
2695
|
-
'markShorthands': {
|
2696
|
-
'block': 1
|
2697
|
-
},
|
2698
|
-
'cleanShorthands': {
|
2699
|
-
'declaration': 1
|
2700
|
-
},
|
2701
|
-
'freezeRulesets': {
|
2702
|
-
'ruleset': 1
|
2703
|
-
}
|
2704
|
-
};
|
2705
|
-
|
2706
|
-
CSSOCompressor.prototype.isContainer = function(o) {
|
2707
|
-
if (Array.isArray(o)) {
|
2708
|
-
for (var i = 0; i < o.length; i++) if (Array.isArray(o[i])) return true;
|
2709
|
-
}
|
2710
|
-
};
|
2711
|
-
|
2712
|
-
CSSOCompressor.prototype.process = function(rules, token, container, i, path) {
|
2713
|
-
var rule = token[1];
|
2714
|
-
if (rule && rules[rule]) {
|
2715
|
-
var r = rules[rule],
|
2716
|
-
x1 = token, x2,
|
2717
|
-
o = this.order, k;
|
2718
|
-
for (var k = 0; k < r.length; k++) {
|
2719
|
-
x2 = this[r[k]](x1, rule, container, i, path);
|
2720
|
-
if (x2 === null) return null;
|
2721
|
-
else if (x2 !== undefined) x1 = x2;
|
2722
|
-
}
|
2723
|
-
}
|
2724
|
-
return x1;
|
2725
|
-
};
|
2726
|
-
|
2727
|
-
CSSOCompressor.prototype.compress = function(tree, ro) {
|
2728
|
-
tree = tree || ['stylesheet'];
|
2729
|
-
this.init();
|
2730
|
-
this.info = true;
|
2731
|
-
|
2732
|
-
var x = (typeof tree[0] !== 'string') ? tree : this.injectInfo([tree])[0],
|
2733
|
-
l0, l1 = 100000000000, ls,
|
2734
|
-
x0, x1, xs,
|
2735
|
-
protectedComment = this.findProtectedComment(tree);
|
2736
|
-
|
2737
|
-
// compression without restructure
|
2738
|
-
x = this.walk(this.ccrules, x, '/0');
|
2739
|
-
x = this.walk(this.crules, x, '/0');
|
2740
|
-
x = this.walk(this.prules, x, '/0');
|
2741
|
-
x = this.walk(this.frrules, x, '/0');
|
2742
|
-
|
2743
|
-
ls = translator.translate(cleanInfo(x)).length;
|
2744
|
-
|
2745
|
-
if (!ro) { // restructure ON
|
2746
|
-
xs = this.copyArray(x);
|
2747
|
-
x = this.walk(this.rjrules, x, '/0');
|
2748
|
-
this.disjoin(x);
|
2749
|
-
x = this.walk(this.msrules, x, '/0');
|
2750
|
-
x = this.walk(this.csrules, x, '/0');
|
2751
|
-
x = this.walk(this.rbrules, x, '/0');
|
2752
|
-
do {
|
2753
|
-
l0 = l1;
|
2754
|
-
x0 = this.copyArray(x);
|
2755
|
-
x = this.walk(this.rjrules, x, '/0');
|
2756
|
-
x = this.walk(this.rrrules, x, '/0');
|
2757
|
-
l1 = translator.translate(cleanInfo(x)).length;
|
2758
|
-
x1 = this.copyArray(x);
|
2759
|
-
} while (l0 > l1);
|
2760
|
-
if (ls < l0 && ls < l1) x = xs;
|
2761
|
-
else if (l0 < l1) x = x0;
|
2762
|
-
}
|
2763
|
-
|
2764
|
-
x = this.walk(this.frules, x, '/0');
|
2765
|
-
|
2766
|
-
if (protectedComment) x.splice(2, 0, protectedComment);
|
2767
|
-
|
2768
|
-
return x;
|
2769
|
-
};
|
2770
|
-
|
2771
|
-
CSSOCompressor.prototype.findProtectedComment = function(tree) {
|
2772
|
-
var token;
|
2773
|
-
for (var i = 2; i < tree.length; i++) {
|
2774
|
-
token = tree[i];
|
2775
|
-
if (token[1] === 'comment' && token[2].length > 0 && token[2].charAt(0) === '!') return token;
|
2776
|
-
if (token[1] !== 's') return;
|
2777
|
-
}
|
2778
|
-
};
|
2779
|
-
|
2780
|
-
CSSOCompressor.prototype.injectInfo = function(token) {
|
2781
|
-
var t;
|
2782
|
-
for (var i = token.length - 1; i > -1; i--) {
|
2783
|
-
t = token[i];
|
2784
|
-
if (t && Array.isArray(t)) {
|
2785
|
-
if (this.isContainer(t)) t = this.injectInfo(t);
|
2786
|
-
t.splice(0, 0, {});
|
2787
|
-
}
|
2788
|
-
}
|
2789
|
-
return token;
|
2790
|
-
};
|
2791
|
-
|
2792
|
-
CSSOCompressor.prototype.disjoin = function(container) {
|
2793
|
-
var t, s, r, sr;
|
2794
|
-
|
2795
|
-
for (var i = container.length - 1; i > -1; i--) {
|
2796
|
-
t = container[i];
|
2797
|
-
if (t && Array.isArray(t)) {
|
2798
|
-
if (t[1] === 'ruleset') {
|
2799
|
-
t[0].shortGroupID = this.shortGroupID++;
|
2800
|
-
s = t[2];
|
2801
|
-
if (s.length > 3) {
|
2802
|
-
sr = s.slice(0, 2);
|
2803
|
-
for (var k = s.length - 1; k > 1; k--) {
|
2804
|
-
r = this.copyArray(t);
|
2805
|
-
r[2] = sr.concat([s[k]]);
|
2806
|
-
r[2][0].s = s[k][0].s;
|
2807
|
-
container.splice(i + 1, 0, r);
|
2808
|
-
}
|
2809
|
-
container.splice(i, 1);
|
2810
|
-
}
|
2811
|
-
}
|
2812
|
-
}
|
2813
|
-
if (this.isContainer(t)) this.disjoin(t);
|
2814
|
-
}
|
2815
|
-
};
|
2816
|
-
|
2817
|
-
CSSOCompressor.prototype.walk = function(rules, container, path) {
|
2818
|
-
var t, x;
|
2819
|
-
for (var i = container.length - 1; i > -1; i--) {
|
2820
|
-
t = container[i];
|
2821
|
-
if (t && Array.isArray(t)) {
|
2822
|
-
t[0].parent = container;
|
2823
|
-
if (this.isContainer(t)) t = this.walk(rules, t, path + '/' + i); // go inside
|
2824
|
-
if (t === null) container.splice(i, 1);
|
2825
|
-
else {
|
2826
|
-
if (x = this.process(rules, t, container, i, path)) container[i] = x; // compressed not null
|
2827
|
-
else if (x === null) container.splice(i, 1); // null is the mark to delete token
|
2828
|
-
}
|
2829
|
-
}
|
2830
|
-
}
|
2831
|
-
return container.length ? container : null;
|
2832
|
-
};
|
2833
|
-
|
2834
|
-
CSSOCompressor.prototype.freezeRulesets = function(token, rule, container, i) {
|
2835
|
-
var info = token[0],
|
2836
|
-
selector = token[2];
|
2837
|
-
|
2838
|
-
info.freeze = this.freezeNeeded(selector);
|
2839
|
-
info.freezeID = this.selectorSignature(selector);
|
2840
|
-
info.pseudoID = this.composePseudoID(selector);
|
2841
|
-
info.pseudoSignature = this.pseudoSelectorSignature(selector, this.allowedPClasses, true);
|
2842
|
-
this.markSimplePseudo(selector);
|
2843
|
-
|
2844
|
-
return token;
|
2845
|
-
};
|
2846
|
-
|
2847
|
-
CSSOCompressor.prototype.markSimplePseudo = function(selector) {
|
2848
|
-
var ss, sg = {};
|
2849
|
-
|
2850
|
-
for (var i = 2; i < selector.length; i++) {
|
2851
|
-
ss = selector[i];
|
2852
|
-
ss[0].pseudo = this.containsPseudo(ss);
|
2853
|
-
ss[0].sg = sg;
|
2854
|
-
sg[ss[0].s] = 1;
|
2855
|
-
}
|
2856
|
-
};
|
2857
|
-
|
2858
|
-
CSSOCompressor.prototype.composePseudoID = function(selector) {
|
2859
|
-
var a = [], ss;
|
2860
|
-
|
2861
|
-
for (var i = 2; i < selector.length; i++) {
|
2862
|
-
ss = selector[i];
|
2863
|
-
if (this.containsPseudo(ss)) {
|
2864
|
-
a.push(ss[0].s);
|
2865
|
-
}
|
2866
|
-
}
|
2867
|
-
|
2868
|
-
a.sort();
|
2869
|
-
|
2870
|
-
return a.join(',');
|
2871
|
-
};
|
2872
|
-
|
2873
|
-
CSSOCompressor.prototype.containsPseudo = function(sselector) {
|
2874
|
-
for (var j = 2; j < sselector.length; j++) {
|
2875
|
-
switch (sselector[j][1]) {
|
2876
|
-
case 'pseudoc':
|
2877
|
-
case 'pseudoe':
|
2878
|
-
case 'nthselector':
|
2879
|
-
if (!(sselector[j][2][2] in this.notFPClasses)) return true;
|
2880
|
-
}
|
2881
|
-
}
|
2882
|
-
};
|
2883
|
-
|
2884
|
-
CSSOCompressor.prototype.selectorSignature = function(selector) {
|
2885
|
-
var a = [];
|
2886
|
-
|
2887
|
-
for (var i = 2; i < selector.length; i++) {
|
2888
|
-
a.push(translator.translate(cleanInfo(selector[i])));
|
2889
|
-
}
|
2890
|
-
|
2891
|
-
a.sort();
|
2892
|
-
|
2893
|
-
return a.join(',');
|
2894
|
-
};
|
2895
|
-
|
2896
|
-
CSSOCompressor.prototype.pseudoSelectorSignature = function(selector, exclude, dontAppendExcludeMark) {
|
2897
|
-
var a = [], b = {}, ss, wasExclude = false;
|
2898
|
-
exclude = exclude || {};
|
2899
|
-
|
2900
|
-
for (var i = 2; i < selector.length; i++) {
|
2901
|
-
ss = selector[i];
|
2902
|
-
for (var j = 2; j < ss.length; j++) {
|
2903
|
-
switch (ss[j][1]) {
|
2904
|
-
case 'pseudoc':
|
2905
|
-
case 'pseudoe':
|
2906
|
-
case 'nthselector':
|
2907
|
-
if (!(ss[j][2][2] in exclude)) b[ss[j][2][2]] = 1;
|
2908
|
-
else wasExclude = true;
|
2909
|
-
break;
|
2910
|
-
}
|
2911
|
-
}
|
2912
|
-
}
|
2913
|
-
|
2914
|
-
for (var k in b) a.push(k);
|
2915
|
-
|
2916
|
-
a.sort();
|
2917
|
-
|
2918
|
-
return a.join(',') + (dontAppendExcludeMark? '' : wasExclude);
|
2919
|
-
};
|
2920
|
-
|
2921
|
-
CSSOCompressor.prototype.notFPClasses = {
|
2922
|
-
'link': 1,
|
2923
|
-
'visited': 1,
|
2924
|
-
'hover': 1,
|
2925
|
-
'active': 1,
|
2926
|
-
'first-letter': 1,
|
2927
|
-
'first-line': 1
|
2928
|
-
};
|
2929
|
-
|
2930
|
-
CSSOCompressor.prototype.notFPElements = {
|
2931
|
-
'first-letter': 1,
|
2932
|
-
'first-line': 1
|
2933
|
-
};
|
2934
|
-
|
2935
|
-
CSSOCompressor.prototype.freezeNeeded = function(selector) {
|
2936
|
-
var ss;
|
2937
|
-
for (var i = 2; i < selector.length; i++) {
|
2938
|
-
ss = selector[i];
|
2939
|
-
for (var j = 2; j < ss.length; j++) {
|
2940
|
-
switch (ss[j][1]) {
|
2941
|
-
case 'pseudoc':
|
2942
|
-
if (!(ss[j][2][2] in this.notFPClasses)) return true;
|
2943
|
-
break;
|
2944
|
-
case 'pseudoe':
|
2945
|
-
if (!(ss[j][2][2] in this.notFPElements)) return true;
|
2946
|
-
break;
|
2947
|
-
case 'nthselector':
|
2948
|
-
return true;
|
2949
|
-
break;
|
2950
|
-
}
|
2951
|
-
}
|
2952
|
-
}
|
2953
|
-
return false;
|
2954
|
-
};
|
2955
|
-
|
2956
|
-
CSSOCompressor.prototype.cleanCharset = function(token, rule, container, i) {
|
2957
|
-
if (token[2][2][2] === 'charset') {
|
2958
|
-
for (i = i - 1; i > 1; i--) {
|
2959
|
-
if (container[i][1] !== 's' && container[i][1] !== 'comment') return null;
|
2960
|
-
}
|
2961
|
-
}
|
2962
|
-
};
|
2963
|
-
|
2964
|
-
CSSOCompressor.prototype.cleanImport = function(token, rule, container, i) {
|
2965
|
-
var x;
|
2966
|
-
for (i = i - 1; i > 1; i--) {
|
2967
|
-
x = container[i][1];
|
2968
|
-
if (x !== 's' && x !== 'comment') {
|
2969
|
-
if (x === 'atrules') {
|
2970
|
-
x = container[i][2][2][2];
|
2971
|
-
if (x !== 'import' && x !== 'charset') return null;
|
2972
|
-
} else return null;
|
2973
|
-
}
|
2974
|
-
}
|
2975
|
-
};
|
2976
|
-
|
2977
|
-
CSSOCompressor.prototype.cleanComment = function(token, rule, container, i) {
|
2978
|
-
var pr = ((container[1] === 'braces' && i === 4) ||
|
2979
|
-
(container[1] !== 'braces' && i === 2)) ? null : container[i - 1][1],
|
2980
|
-
nr = i === container.length - 1 ? null : container[i + 1][1];
|
2981
|
-
|
2982
|
-
if (nr !== null && pr !== null) {
|
2983
|
-
if (this._cleanComment(nr) || this._cleanComment(pr)) return null;
|
2984
|
-
} else return null;
|
2985
|
-
};
|
2986
|
-
|
2987
|
-
CSSOCompressor.prototype._cleanComment = function(r) {
|
2988
|
-
switch(r) {
|
2989
|
-
case 's':
|
2990
|
-
case 'operator':
|
2991
|
-
case 'attrselector':
|
2992
|
-
case 'block':
|
2993
|
-
case 'decldelim':
|
2994
|
-
case 'ruleset':
|
2995
|
-
case 'declaration':
|
2996
|
-
case 'atruleb':
|
2997
|
-
case 'atrules':
|
2998
|
-
case 'atruler':
|
2999
|
-
case 'important':
|
3000
|
-
case 'nth':
|
3001
|
-
case 'combinator':
|
3002
|
-
return true;
|
3003
|
-
}
|
3004
|
-
};
|
3005
|
-
|
3006
|
-
CSSOCompressor.prototype.nextToken = function(container, type, i, exactly) {
|
3007
|
-
var t, r;
|
3008
|
-
for (; i < container.length; i++) {
|
3009
|
-
t = container[i];
|
3010
|
-
if (Array.isArray(t)) {
|
3011
|
-
r = t[1];
|
3012
|
-
if (r === type) return t;
|
3013
|
-
else if (exactly && r !== 's') return;
|
3014
|
-
}
|
3015
|
-
}
|
3016
|
-
};
|
3017
|
-
|
3018
|
-
CSSOCompressor.prototype.cleanWhitespace = function(token, rule, container, i) {
|
3019
|
-
var pr = ((container[1] === 'braces' && i === 4) ||
|
3020
|
-
(container[1] !== 'braces' && i === 2)) ? null : container[i - 1][1],
|
3021
|
-
nr = i === container.length - 1 ? null : container[i + 1][1];
|
3022
|
-
|
3023
|
-
if (nr === 'unknown') token[2] = '\n';
|
3024
|
-
else {
|
3025
|
-
if (!(container[1] === 'atrulerq' && !pr) && !this.issue16(container, i) && !this.issue165(container, pr, nr)) {
|
3026
|
-
if (nr !== null && pr !== null) {
|
3027
|
-
if (this._cleanWhitespace(nr, false) || this._cleanWhitespace(pr, true)) return null;
|
3028
|
-
} else return null;
|
3029
|
-
}
|
3030
|
-
|
3031
|
-
token[2] = ' ';
|
3032
|
-
}
|
3033
|
-
|
3034
|
-
return token;
|
3035
|
-
};
|
3036
|
-
|
3037
|
-
// See https://github.com/afelix/csso/issues/16
|
3038
|
-
CSSOCompressor.prototype.issue16 = function(container, i) {
|
3039
|
-
return (i !== 2 && i !== container.length - 1 && container[i - 1][1] === 'uri');
|
3040
|
-
};
|
3041
|
-
|
3042
|
-
//See https://github.com/css/csso/issues/165
|
3043
|
-
CSSOCompressor.prototype.issue165 = function(container, pr, nr) {
|
3044
|
-
return container[1] === 'atrulerq' && pr === 'braces' && nr === 'ident';
|
3045
|
-
};
|
3046
|
-
|
3047
|
-
CSSOCompressor.prototype._cleanWhitespace = function(r, left) {
|
3048
|
-
switch(r) {
|
3049
|
-
case 's':
|
3050
|
-
case 'operator':
|
3051
|
-
case 'attrselector':
|
3052
|
-
case 'block':
|
3053
|
-
case 'decldelim':
|
3054
|
-
case 'ruleset':
|
3055
|
-
case 'declaration':
|
3056
|
-
case 'atruleb':
|
3057
|
-
case 'atrules':
|
3058
|
-
case 'atruler':
|
3059
|
-
case 'important':
|
3060
|
-
case 'nth':
|
3061
|
-
case 'combinator':
|
3062
|
-
return true;
|
3063
|
-
}
|
3064
|
-
if (left) {
|
3065
|
-
switch(r) {
|
3066
|
-
case 'funktion':
|
3067
|
-
case 'braces':
|
3068
|
-
case 'uri':
|
3069
|
-
return true;
|
3070
|
-
}
|
3071
|
-
}
|
3072
|
-
};
|
3073
|
-
|
3074
|
-
CSSOCompressor.prototype.cleanDecldelim = function(token) {
|
3075
|
-
for (var i = token.length - 1; i > 1; i--) {
|
3076
|
-
if (token[i][1] === 'decldelim' &&
|
3077
|
-
token[i + 1][1] !== 'declaration') token.splice(i, 1);
|
3078
|
-
}
|
3079
|
-
if (token[2][1] === 'decldelim') token.splice(2, 1);
|
3080
|
-
return token;
|
3081
|
-
};
|
3082
|
-
|
3083
|
-
CSSOCompressor.prototype.compressNumber = function(token, rule, container, i) {
|
3084
|
-
var x = token[2];
|
3085
|
-
|
3086
|
-
if (/^0*/.test(x)) x = x.replace(/^0+/, '');
|
3087
|
-
if (/\.0*$/.test(x)) x = x.replace(/\.0*$/, '');
|
3088
|
-
if (/\..*[1-9]+0+$/.test(x)) x = x.replace(/0+$/, '');
|
3089
|
-
if (x === '.' || x === '') x = '0';
|
3090
|
-
|
3091
|
-
token[2] = x;
|
3092
|
-
token[0].s = x;
|
3093
|
-
return token;
|
3094
|
-
};
|
3095
|
-
|
3096
|
-
CSSOCompressor.prototype.findDeclaration = function(token) {
|
3097
|
-
var parent = token;
|
3098
|
-
while ((parent = parent[0].parent) && parent[1] !== 'declaration');
|
3099
|
-
return parent;
|
3100
|
-
};
|
3101
|
-
|
3102
|
-
CSSOCompressor.prototype.cleanUnary = function(token, rule, container, i) {
|
3103
|
-
var next = container[i + 1];
|
3104
|
-
if (next && next[1] === 'number' && next[2] === '0') return null;
|
3105
|
-
return token;
|
3106
|
-
};
|
3107
|
-
|
3108
|
-
CSSOCompressor.prototype.compressColor = function(token, rule, container, i) {
|
3109
|
-
switch(rule) {
|
3110
|
-
case 'vhash':
|
3111
|
-
return this.compressHashColor(token);
|
3112
|
-
case 'funktion':
|
3113
|
-
return this.compressFunctionColor(token);
|
3114
|
-
case 'ident':
|
3115
|
-
return this.compressIdentColor(token, rule, container, i);
|
3116
|
-
}
|
3117
|
-
};
|
3118
|
-
|
3119
|
-
CSSOCompressor.prototype.compressIdentColor = function(token, rule, container) {
|
3120
|
-
var map = { 'yellow': 'ff0',
|
3121
|
-
'fuchsia': 'f0f',
|
3122
|
-
'white': 'fff',
|
3123
|
-
'black': '000',
|
3124
|
-
'blue': '00f',
|
3125
|
-
'aqua': '0ff' },
|
3126
|
-
allow = { 'value': 1, 'functionBody': 1 },
|
3127
|
-
_x = token[2].toLowerCase();
|
3128
|
-
|
3129
|
-
if (container[1] in allow && _x in map) return [{}, 'vhash', map[_x]];
|
3130
|
-
};
|
3131
|
-
|
3132
|
-
CSSOCompressor.prototype.compressHashColor = function(token) {
|
3133
|
-
return this._compressHashColor(token[2], token[0]);
|
3134
|
-
};
|
3135
|
-
|
3136
|
-
CSSOCompressor.prototype._compressHashColor = function(x, info) {
|
3137
|
-
var map = { 'f00': 'red',
|
3138
|
-
'c0c0c0': 'silver',
|
3139
|
-
'808080': 'gray',
|
3140
|
-
'800000': 'maroon',
|
3141
|
-
'800080': 'purple',
|
3142
|
-
'008000': 'green',
|
3143
|
-
'808000': 'olive',
|
3144
|
-
'000080': 'navy',
|
3145
|
-
'008080': 'teal'},
|
3146
|
-
_x = x;
|
3147
|
-
x = x.toLowerCase();
|
3148
|
-
|
3149
|
-
if (x.length === 6 &&
|
3150
|
-
x.charAt(0) === x.charAt(1) &&
|
3151
|
-
x.charAt(2) === x.charAt(3) &&
|
3152
|
-
x.charAt(4) === x.charAt(5)) x = x.charAt(0) + x.charAt(2) + x.charAt(4);
|
3153
|
-
|
3154
|
-
return map[x] ? [info, 'string', map[x]] : [info, 'vhash', (x.length < _x.length ? x : _x)];
|
3155
|
-
};
|
3156
|
-
|
3157
|
-
CSSOCompressor.prototype.compressFunctionColor = function(token) {
|
3158
|
-
var i, v = [], t, h = '', body;
|
3159
|
-
|
3160
|
-
if (token[2][2] === 'rgb') {
|
3161
|
-
body = token[3];
|
3162
|
-
for (i = 2; i < body.length; i++) {
|
3163
|
-
t = body[i][1];
|
3164
|
-
if (t === 'number') v.push(body[i]);
|
3165
|
-
else if (t !== 'operator') { v = []; break }
|
3166
|
-
}
|
3167
|
-
|
3168
|
-
// check if color is followed by number
|
3169
|
-
var parent = token[0].parent;
|
3170
|
-
var parentIx = parent.indexOf(token);
|
3171
|
-
var appendSpace = parent[parentIx + 1] && parent[parentIx + 1][1] != 's';
|
3172
|
-
|
3173
|
-
if (v.length === 3) {
|
3174
|
-
h += (t = Number(v[0][2]).toString(16)).length === 1 ? '0' + t : t;
|
3175
|
-
h += (t = Number(v[1][2]).toString(16)).length === 1 ? '0' + t : t;
|
3176
|
-
h += (t = Number(v[2][2]).toString(16)).length === 1 ? '0' + t : t;
|
3177
|
-
if (h.length === 6) {
|
3178
|
-
var vhash = this._compressHashColor(h, {});
|
3179
|
-
if (appendSpace) {
|
3180
|
-
// che: I guess this is not right: modify color token with
|
3181
|
-
// indentation, but I can't find any better solution right now
|
3182
|
-
vhash[2] += ' ';
|
3183
|
-
}
|
3184
|
-
|
3185
|
-
return vhash;
|
3186
|
-
}
|
3187
|
-
}
|
3188
|
-
}
|
3189
|
-
};
|
3190
|
-
|
3191
|
-
CSSOCompressor.prototype.compressDimension = function(token) {
|
3192
|
-
var declaration;
|
3193
|
-
if (token[2][2] === '0') {
|
3194
|
-
if ((token[3][2] === 's' || token[3][2] === 'ms') && (declaration = this.findDeclaration(token))) {
|
3195
|
-
var declName = declaration[2][2][2];
|
3196
|
-
if (declName === '-moz-transition' || declName === 'transition') return; // https://github.com/css/csso/issues/82, also support recent Fx versions
|
3197
|
-
if (declName === '-moz-animation' || declName === 'animation') return; // https://github.com/css/csso/issues/100
|
3198
|
-
}
|
3199
|
-
return token[2];
|
3200
|
-
}
|
3201
|
-
};
|
3202
|
-
|
3203
|
-
CSSOCompressor.prototype.compressString = function(token, rule, container) {
|
3204
|
-
var s = token[2], r = '', c;
|
3205
|
-
for (var i = 0; i < s.length; i++) {
|
3206
|
-
c = s.charAt(i);
|
3207
|
-
if (c === '\\' && s.charAt(i + 1) === '\n') i++;
|
3208
|
-
else r += c;
|
3209
|
-
}
|
3210
|
-
// if (container[1] === 'attrib' && /^('|")[a-zA-Z0-9]*('|")$/.test(r)) {
|
3211
|
-
// r = r.substring(1, r.length - 1);
|
3212
|
-
// }
|
3213
|
-
if (s.length !== r.length) return [{}, 'string', r];
|
3214
|
-
};
|
3215
|
-
|
3216
|
-
CSSOCompressor.prototype.compressFontWeight = function(token) {
|
3217
|
-
var p = token[2],
|
3218
|
-
v = token[3];
|
3219
|
-
if (p[2][2].indexOf('font-weight') !== -1 && v[2][1] === 'ident') {
|
3220
|
-
if (v[2][2] === 'normal') v[2] = [{}, 'number', '400'];
|
3221
|
-
else if (v[2][2] === 'bold') v[2] = [{}, 'number', '700'];
|
3222
|
-
return token;
|
3223
|
-
}
|
3224
|
-
};
|
3225
|
-
|
3226
|
-
CSSOCompressor.prototype.compressFont = function(token) {
|
3227
|
-
var p = token[2],
|
3228
|
-
v = token[3],
|
3229
|
-
i, x, t;
|
3230
|
-
if (/font$/.test(p[2][2]) && v.length) {
|
3231
|
-
v.splice(2, 0, [{}, 's', '']);
|
3232
|
-
for (i = v.length - 1; i > 2; i--) {
|
3233
|
-
x = v[i];
|
3234
|
-
if (x[1] === 'ident') {
|
3235
|
-
x = x[2];
|
3236
|
-
if (x === 'bold') v[i] = [{}, 'number', '700'];
|
3237
|
-
else if (x === 'normal') {
|
3238
|
-
t = v[i - 1];
|
3239
|
-
if (t[1] === 'operator' && t[2] === '/') v.splice(--i, 2);
|
3240
|
-
else v.splice(i, 1);
|
3241
|
-
if (v[i - 1][1] === 's') v.splice(--i, 1);
|
3242
|
-
}
|
3243
|
-
else if (x === 'medium' && v[i + 1] && v[i + 1][2] !== '/') {
|
3244
|
-
v.splice(i, 1);
|
3245
|
-
if (v[i - 1][1] === 's') v.splice(--i, 1);
|
3246
|
-
}
|
3247
|
-
}
|
3248
|
-
}
|
3249
|
-
if (v.length > 2 && v[2][1] === 's') v.splice(2, 1);
|
3250
|
-
if (v.length === 2) v.push([{}, 'ident', 'normal']);
|
3251
|
-
return token;
|
3252
|
-
}
|
3253
|
-
};
|
3254
|
-
|
3255
|
-
CSSOCompressor.prototype.compressBackground = function(token) {
|
3256
|
-
var p = token[2],
|
3257
|
-
v = token[3],
|
3258
|
-
i, x, t,
|
3259
|
-
n = v[v.length - 1][1] === 'important' ? 3 : 2;
|
3260
|
-
if (/background$/.test(p[2][2]) && v.length) {
|
3261
|
-
v.splice(2, 0, [{}, 's', '']);
|
3262
|
-
for (i = v.length - 1; i > n; i--) {
|
3263
|
-
x = v[i];
|
3264
|
-
if (x[1] === 'ident') {
|
3265
|
-
x = x[2];
|
3266
|
-
if (x === 'transparent' || x === 'none' || x === 'repeat' || x === 'scroll') {
|
3267
|
-
v.splice(i, 1);
|
3268
|
-
if (v[i - 1][1] === 's') v.splice(--i, 1);
|
3269
|
-
}
|
3270
|
-
}
|
3271
|
-
}
|
3272
|
-
if (v.length > 2 && v[2][1] === 's') v.splice(2, 1);
|
3273
|
-
if (v.length === 2) v.splice(2, 0, [{}, 'number', '0'], [{}, 's', ' '], [{}, 'number', '0']);
|
3274
|
-
return token;
|
3275
|
-
}
|
3276
|
-
};
|
3277
|
-
|
3278
|
-
CSSOCompressor.prototype.cleanEmpty = function(token, rule) {
|
3279
|
-
switch(rule) {
|
3280
|
-
case 'ruleset':
|
3281
|
-
if (token[3].length === 2) return null;
|
3282
|
-
break;
|
3283
|
-
case 'atruleb':
|
3284
|
-
if (token[token.length - 1].length < 3) return null;
|
3285
|
-
break;
|
3286
|
-
case 'atruler':
|
3287
|
-
if (token[4].length < 3) return null;
|
3288
|
-
break;
|
3289
|
-
}
|
3290
|
-
};
|
3291
|
-
|
3292
|
-
CSSOCompressor.prototype.destroyDelims = function() {
|
3293
|
-
return null;
|
3294
|
-
};
|
3295
|
-
|
3296
|
-
CSSOCompressor.prototype.preTranslate = function(token) {
|
3297
|
-
token[0].s = translator.translate(cleanInfo(token));
|
3298
|
-
return token;
|
3299
|
-
};
|
3300
|
-
|
3301
|
-
CSSOCompressor.prototype.markShorthands = function(token, rule, container, j, path) {
|
3302
|
-
if (container[1] === 'ruleset') {
|
3303
|
-
var selector = container[2][2][0].s,
|
3304
|
-
freeze = container[0].freeze,
|
3305
|
-
freezeID = container[0].freezeID;
|
3306
|
-
} else {
|
3307
|
-
var selector = '',
|
3308
|
-
freeze = false,
|
3309
|
-
freezeID = 'fake';
|
3310
|
-
}
|
3311
|
-
var x, p, v, imp, s, key, sh,
|
3312
|
-
pre = this.pathUp(path) + '/' + (freeze ? '&' + freezeID + '&' : '') + selector + '/',
|
3313
|
-
createNew, shortsI, shortGroupID = container[0].shortGroupID;
|
3314
|
-
|
3315
|
-
for (var i = token.length - 1; i > -1; i--) {
|
3316
|
-
createNew = true;
|
3317
|
-
x = token[i];
|
3318
|
-
if (x[1] === 'declaration') {
|
3319
|
-
v = x[3];
|
3320
|
-
imp = v[v.length - 1][1] === 'important';
|
3321
|
-
p = x[2][0].s;
|
3322
|
-
x[0].id = path + '/' + i;
|
3323
|
-
if (p in TRBL.props) {
|
3324
|
-
key = pre + TRBL.extractMain(p);
|
3325
|
-
var shorts = this.shorts2[key] || [];
|
3326
|
-
shortsI = shorts.length === 0 ? 0 : shorts.length - 1;
|
3327
|
-
|
3328
|
-
if (!this.lastShortSelector || selector === this.lastShortSelector || shortGroupID === this.lastShortGroupID) {
|
3329
|
-
if (shorts.length) {
|
3330
|
-
sh = shorts[shortsI];
|
3331
|
-
//if (imp && !sh.imp) sh.invalid = true;
|
3332
|
-
createNew = false;
|
3333
|
-
}
|
3334
|
-
}
|
3335
|
-
|
3336
|
-
if (createNew) {
|
3337
|
-
x[0].replaceByShort = true;
|
3338
|
-
x[0].shorthandKey = { key: key, i: shortsI };
|
3339
|
-
sh = new TRBL(p, imp);
|
3340
|
-
shorts.push(sh);
|
3341
|
-
}
|
3342
|
-
|
3343
|
-
if (!sh.invalid) {
|
3344
|
-
x[0].removeByShort = true;
|
3345
|
-
x[0].shorthandKey = { key: key, i: shortsI };
|
3346
|
-
sh.add(p, v[0].s, v.slice(2), imp);
|
3347
|
-
}
|
3348
|
-
|
3349
|
-
this.shorts2[key] = shorts;
|
3350
|
-
|
3351
|
-
this.lastShortSelector = selector;
|
3352
|
-
this.lastShortGroupID = shortGroupID;
|
3353
|
-
}
|
3354
|
-
}
|
3355
|
-
}
|
3356
|
-
|
3357
|
-
|
3358
|
-
return token;
|
3359
|
-
};
|
3360
|
-
|
3361
|
-
CSSOCompressor.prototype.cleanShorthands = function(token) {
|
3362
|
-
if (token[0].removeByShort || token[0].replaceByShort) {
|
3363
|
-
var s, t, sKey = token[0].shorthandKey;
|
3364
|
-
|
3365
|
-
s = this.shorts2[sKey.key][sKey.i];
|
3366
|
-
|
3367
|
-
if (!s.invalid && s.isOkToMinimize()) {
|
3368
|
-
if (token[0].replaceByShort) {
|
3369
|
-
t = [{}, 'declaration', s.getProperty(), s.getValue()];
|
3370
|
-
t[0].s = translator.translate(cleanInfo(t));
|
3371
|
-
return t;
|
3372
|
-
} else return null;
|
3373
|
-
}
|
3374
|
-
}
|
3375
|
-
};
|
3376
|
-
|
3377
|
-
CSSOCompressor.prototype.dontRestructure = {
|
3378
|
-
'src': 1, // https://github.com/afelix/csso/issues/50
|
3379
|
-
'clip': 1, // https://github.com/afelix/csso/issues/57
|
3380
|
-
'display': 1 // https://github.com/afelix/csso/issues/71
|
3381
|
-
};
|
3382
|
-
|
3383
|
-
CSSOCompressor.prototype.restructureBlock = function(token, rule, container, j, path) {
|
3384
|
-
if (container[1] === 'ruleset') {
|
3385
|
-
var props = this.props,
|
3386
|
-
isPseudo = container[2][2][0].pseudo,
|
3387
|
-
selector = container[2][2][0].s,
|
3388
|
-
freeze = container[0].freeze,
|
3389
|
-
freezeID = container[0].freezeID,
|
3390
|
-
pseudoID = container[0].pseudoID,
|
3391
|
-
sg = container[2][2][0].sg;
|
3392
|
-
} else {
|
3393
|
-
var props = {},
|
3394
|
-
isPseudo = false,
|
3395
|
-
selector = '',
|
3396
|
-
freeze = false,
|
3397
|
-
freezeID = 'fake',
|
3398
|
-
pseudoID = 'fake',
|
3399
|
-
sg = {};
|
3400
|
-
}
|
3401
|
-
|
3402
|
-
var x, p, v, imp, t,
|
3403
|
-
pre = this.pathUp(path) + '/' + selector + '/',
|
3404
|
-
ppre;
|
3405
|
-
for (var i = token.length - 1; i > -1; i--) {
|
3406
|
-
x = token[i];
|
3407
|
-
if (x[1] === 'declaration') {
|
3408
|
-
v = x[3];
|
3409
|
-
imp = v[v.length - 1][1] === 'important';
|
3410
|
-
p = x[2][0].s;
|
3411
|
-
ppre = this.buildPPre(pre, p, v, x, freeze);
|
3412
|
-
x[0].id = path + '/' + i;
|
3413
|
-
if (!this.dontRestructure[p] && (t = props[ppre])) {
|
3414
|
-
if ((isPseudo && freezeID === t.freezeID) || // pseudo from equal selectors group
|
3415
|
-
(!isPseudo && pseudoID === t.pseudoID) || // not pseudo from equal pseudo signature group
|
3416
|
-
(isPseudo && pseudoID === t.pseudoID && this.hashInHash(sg, t.sg))) { // pseudo from covered selectors group
|
3417
|
-
if (imp && !t.imp) {
|
3418
|
-
props[ppre] = { block: token, imp: imp, id: x[0].id, sg: sg,
|
3419
|
-
freeze: freeze, path: path, freezeID: freezeID, pseudoID: pseudoID };
|
3420
|
-
this.deleteProperty(t.block, t.id);
|
3421
|
-
} else {
|
3422
|
-
token.splice(i, 1);
|
3423
|
-
}
|
3424
|
-
}
|
3425
|
-
} else if (this.needless(p, props, pre, imp, v, x, freeze)) {
|
3426
|
-
token.splice(i, 1);
|
3427
|
-
} else {
|
3428
|
-
props[ppre] = { block: token, imp: imp, id: x[0].id, sg: sg,
|
3429
|
-
freeze: freeze, path: path, freezeID: freezeID, pseudoID: pseudoID };
|
3430
|
-
}
|
3431
|
-
}
|
3432
|
-
}
|
3433
|
-
return token;
|
3434
|
-
};
|
3435
|
-
|
3436
|
-
CSSOCompressor.prototype.buildPPre = function(pre, p, v, d, freeze) {
|
3437
|
-
var fp = freeze ? 'ft:' : 'ff:';
|
3438
|
-
if (p.indexOf('background') !== -1) return fp + pre + d[0].s;
|
3439
|
-
|
3440
|
-
var _v = v.slice(2),
|
3441
|
-
colorMark = [
|
3442
|
-
0, // ident, vhash, rgb
|
3443
|
-
0, // hsl
|
3444
|
-
0, // hsla
|
3445
|
-
0 // rgba
|
3446
|
-
],
|
3447
|
-
vID = '';
|
3448
|
-
|
3449
|
-
for (var i = 0; i < _v.length; i++) {
|
3450
|
-
if (!vID) vID = this.getVendorIDFromToken(_v[i]);
|
3451
|
-
switch(_v[i][1]) {
|
3452
|
-
case 'vhash':
|
3453
|
-
case 'ident':
|
3454
|
-
colorMark[0] = 1; break;
|
3455
|
-
case 'funktion':
|
3456
|
-
switch(_v[i][2][2]) {
|
3457
|
-
case 'rgb':
|
3458
|
-
colorMark[0] = 1; break;
|
3459
|
-
case 'hsl':
|
3460
|
-
colorMark[1] = 1; break;
|
3461
|
-
case 'hsla':
|
3462
|
-
colorMark[2] = 1; break;
|
3463
|
-
case 'rgba':
|
3464
|
-
colorMark[3] = 1; break;
|
3465
|
-
}
|
3466
|
-
break;
|
3467
|
-
}
|
3468
|
-
}
|
3469
|
-
|
3470
|
-
return fp + pre + p + colorMark.join('') + (vID ? vID : '');
|
3471
|
-
};
|
3472
|
-
|
3473
|
-
CSSOCompressor.prototype.vendorID = {
|
3474
|
-
'-o-': 'o',
|
3475
|
-
'-moz-': 'm',
|
3476
|
-
'-webkit-': 'w',
|
3477
|
-
'-ms-': 'i',
|
3478
|
-
'-epub-': 'e',
|
3479
|
-
'-apple-': 'a',
|
3480
|
-
'-xv-': 'x',
|
3481
|
-
'-wap-': 'p'
|
3482
|
-
};
|
3483
|
-
|
3484
|
-
CSSOCompressor.prototype.getVendorIDFromToken = function(token) {
|
3485
|
-
var vID;
|
3486
|
-
switch(token[1]) {
|
3487
|
-
case 'ident':
|
3488
|
-
if (vID = this.getVendorFromString(token[2])) return this.vendorID[vID];
|
3489
|
-
break;
|
3490
|
-
case 'funktion':
|
3491
|
-
if (vID = this.getVendorFromString(token[2][2])) return this.vendorID[vID];
|
3492
|
-
break;
|
3493
|
-
}
|
3494
|
-
};
|
3495
|
-
|
3496
|
-
CSSOCompressor.prototype.getVendorFromString = function(string) {
|
3497
|
-
var vendor = string.charAt(0), i;
|
3498
|
-
if (vendor === '-') {
|
3499
|
-
if ((i = string.indexOf('-', 2)) !== -1) return string.substr(0, i + 1);
|
3500
|
-
}
|
3501
|
-
return '';
|
3502
|
-
};
|
3503
|
-
|
3504
|
-
CSSOCompressor.prototype.deleteProperty = function(block, id) {
|
3505
|
-
var d;
|
3506
|
-
for (var i = block.length - 1; i > 1; i--) {
|
3507
|
-
d = block[i];
|
3508
|
-
if (Array.isArray(d) && d[1] === 'declaration' && d[0].id === id) {
|
3509
|
-
block.splice(i, 1);
|
3510
|
-
return;
|
3511
|
-
}
|
3512
|
-
}
|
3513
|
-
};
|
3514
|
-
|
3515
|
-
CSSOCompressor.prototype.nlTable = {
|
3516
|
-
'border-width': ['border'],
|
3517
|
-
'border-style': ['border'],
|
3518
|
-
'border-color': ['border'],
|
3519
|
-
'border-top': ['border'],
|
3520
|
-
'border-right': ['border'],
|
3521
|
-
'border-bottom': ['border'],
|
3522
|
-
'border-left': ['border'],
|
3523
|
-
'border-top-width': ['border-top', 'border-width', 'border'],
|
3524
|
-
'border-right-width': ['border-right', 'border-width', 'border'],
|
3525
|
-
'border-bottom-width': ['border-bottom', 'border-width', 'border'],
|
3526
|
-
'border-left-width': ['border-left', 'border-width', 'border'],
|
3527
|
-
'border-top-style': ['border-top', 'border-style', 'border'],
|
3528
|
-
'border-right-style': ['border-right', 'border-style', 'border'],
|
3529
|
-
'border-bottom-style': ['border-bottom', 'border-style', 'border'],
|
3530
|
-
'border-left-style': ['border-left', 'border-style', 'border'],
|
3531
|
-
'border-top-color': ['border-top', 'border-color', 'border'],
|
3532
|
-
'border-right-color': ['border-right', 'border-color', 'border'],
|
3533
|
-
'border-bottom-color': ['border-bottom', 'border-color', 'border'],
|
3534
|
-
'border-left-color': ['border-left', 'border-color', 'border'],
|
3535
|
-
'margin-top': ['margin'],
|
3536
|
-
'margin-right': ['margin'],
|
3537
|
-
'margin-bottom': ['margin'],
|
3538
|
-
'margin-left': ['margin'],
|
3539
|
-
'padding-top': ['padding'],
|
3540
|
-
'padding-right': ['padding'],
|
3541
|
-
'padding-bottom': ['padding'],
|
3542
|
-
'padding-left': ['padding'],
|
3543
|
-
'font-style': ['font'],
|
3544
|
-
'font-variant': ['font'],
|
3545
|
-
'font-weight': ['font'],
|
3546
|
-
'font-size': ['font'],
|
3547
|
-
'font-family': ['font'],
|
3548
|
-
'list-style-type': ['list-style'],
|
3549
|
-
'list-style-position': ['list-style'],
|
3550
|
-
'list-style-image': ['list-style']
|
3551
|
-
};
|
3552
|
-
|
3553
|
-
CSSOCompressor.prototype.needless = function(name, props, pre, imp, v, d, freeze) {
|
3554
|
-
var hack = name.charAt(0);
|
3555
|
-
if (hack === '*' || hack === '_' || hack === '$') name = name.substr(1);
|
3556
|
-
else if (hack === '/' && name.charAt(1) === '/') {
|
3557
|
-
hack = '//';
|
3558
|
-
name = name.substr(2);
|
3559
|
-
} else hack = '';
|
3560
|
-
|
3561
|
-
var vendor = this.getVendorFromString(name),
|
3562
|
-
prop = name.substr(vendor.length),
|
3563
|
-
x, t, ppre;
|
3564
|
-
|
3565
|
-
if (prop in this.nlTable) {
|
3566
|
-
x = this.nlTable[prop];
|
3567
|
-
for (var i = 0; i < x.length; i++) {
|
3568
|
-
ppre = this.buildPPre(pre, hack + vendor + x[i], v, d, freeze);
|
3569
|
-
if (t = props[ppre]) return (!imp || t.imp);
|
3570
|
-
}
|
3571
|
-
}
|
3572
|
-
};
|
3573
|
-
|
3574
|
-
CSSOCompressor.prototype.rejoinRuleset = function(token, rule, container, i) {
|
3575
|
-
var p = (i === 2 || container[i - 1][1] === 'unknown') ? null : container[i - 1],
|
3576
|
-
ps = p ? p[2].slice(2) : [],
|
3577
|
-
pb = p ? p[3].slice(2) : [],
|
3578
|
-
ts = token[2].slice(2),
|
3579
|
-
tb = token[3].slice(2),
|
3580
|
-
ph, th, r;
|
3581
|
-
|
3582
|
-
if (!tb.length) return null;
|
3583
|
-
|
3584
|
-
if (ps.length && pb.length && token[0].pseudoSignature == p[0].pseudoSignature) {
|
3585
|
-
if (token[1] !== p[1]) return;
|
3586
|
-
// try to join by selectors
|
3587
|
-
ph = this.getHash(ps);
|
3588
|
-
th = this.getHash(ts);
|
3589
|
-
|
3590
|
-
if (this.equalHash(th, ph)) {
|
3591
|
-
p[3] = p[3].concat(token[3].splice(2));
|
3592
|
-
return null;
|
3593
|
-
}
|
3594
|
-
if (this.okToJoinByProperties(token, p)) {
|
3595
|
-
// try to join by properties
|
3596
|
-
r = this.analyze(token, p);
|
3597
|
-
if (!r.ne1.length && !r.ne2.length) {
|
3598
|
-
p[2] = this.cleanSelector(p[2].concat(token[2].splice(2)));
|
3599
|
-
p[2][0].s = translator.translate(cleanInfo(p[2]));
|
3600
|
-
return null;
|
3601
|
-
}
|
3602
|
-
}
|
3603
|
-
}
|
3604
|
-
};
|
3605
|
-
|
3606
|
-
CSSOCompressor.prototype.okToJoinByProperties = function(r0, r1) {
|
3607
|
-
var i0 = r0[0], i1 = r1[0];
|
3608
|
-
|
3609
|
-
// same frozen ruleset
|
3610
|
-
if (i0.freezeID === i1.freezeID) return true;
|
3611
|
-
|
3612
|
-
// same pseudo-classes in selectors
|
3613
|
-
if (i0.pseudoID === i1.pseudoID) return true;
|
3614
|
-
|
3615
|
-
// different frozen rulesets
|
3616
|
-
if (i0.freeze && i1.freeze) {
|
3617
|
-
return this.pseudoSelectorSignature(r0[2], this.allowedPClasses) === this.pseudoSelectorSignature(r1[2], this.allowedPClasses);
|
3618
|
-
}
|
3619
|
-
|
3620
|
-
// is it frozen at all?
|
3621
|
-
return !(i0.freeze || i1.freeze);
|
3622
|
-
};
|
3623
|
-
|
3624
|
-
CSSOCompressor.prototype.allowedPClasses = {
|
3625
|
-
'after': 1,
|
3626
|
-
'before': 1
|
3627
|
-
};
|
3628
|
-
|
3629
|
-
CSSOCompressor.prototype.containsOnlyAllowedPClasses = function(selector) {
|
3630
|
-
var ss;
|
3631
|
-
for (var i = 2; i < selector.length; i++) {
|
3632
|
-
ss = selector[i];
|
3633
|
-
for (var j = 2; j < ss.length; j++) {
|
3634
|
-
if (ss[j][1] == 'pseudoc' || ss[j][1] == 'pseudoe') {
|
3635
|
-
if (!(ss[j][2][2] in this.allowedPClasses)) return false;
|
3636
|
-
}
|
3637
|
-
}
|
3638
|
-
}
|
3639
|
-
return true;
|
3640
|
-
};
|
3641
|
-
|
3642
|
-
CSSOCompressor.prototype.restructureRuleset = function(token, rule, container, i) {
|
3643
|
-
var p = (i === 2 || container[i - 1][1] === 'unknown') ? null : container[i - 1],
|
3644
|
-
ps = p ? p[2].slice(2) : [],
|
3645
|
-
pb = p ? p[3].slice(2) : [],
|
3646
|
-
tb = token[3].slice(2),
|
3647
|
-
r, nr;
|
3648
|
-
|
3649
|
-
if (!tb.length) return null;
|
3650
|
-
|
3651
|
-
if (ps.length && pb.length && token[0].pseudoSignature == p[0].pseudoSignature) {
|
3652
|
-
if (token[1] !== p[1]) return;
|
3653
|
-
// try to join by properties
|
3654
|
-
r = this.analyze(token, p);
|
3655
|
-
|
3656
|
-
if (r.eq.length && (r.ne1.length || r.ne2.length)) {
|
3657
|
-
if (r.ne1.length && !r.ne2.length) { // p in token
|
3658
|
-
var ns = token[2].slice(2), // TODO: copypaste
|
3659
|
-
nss = translator.translate(cleanInfo(token[2])),
|
3660
|
-
sl = nss.length + // selector length
|
3661
|
-
ns.length - 1, // delims length
|
3662
|
-
bl = this.calcLength(r.eq) + // declarations length
|
3663
|
-
r.eq.length - 1; // decldelims length
|
3664
|
-
if (sl < bl) {
|
3665
|
-
p[2] = this.cleanSelector(p[2].concat(token[2].slice(2)));
|
3666
|
-
token[3].splice(2);
|
3667
|
-
token[3] = token[3].concat(r.ne1);
|
3668
|
-
return token;
|
3669
|
-
}
|
3670
|
-
} else if (r.ne2.length && !r.ne1.length) { // token in p
|
3671
|
-
var ns = p[2].slice(2),
|
3672
|
-
nss = translator.translate(cleanInfo(p[2])),
|
3673
|
-
sl = nss.length + // selector length
|
3674
|
-
ns.length - 1, // delims length
|
3675
|
-
bl = this.calcLength(r.eq) + // declarations length
|
3676
|
-
r.eq.length - 1; // decldelims length
|
3677
|
-
if (sl < bl) {
|
3678
|
-
token[2] = this.cleanSelector(p[2].concat(token[2].slice(2)));
|
3679
|
-
p[3].splice(2);
|
3680
|
-
p[3] = p[3].concat(r.ne2);
|
3681
|
-
return token;
|
3682
|
-
}
|
3683
|
-
} else { // extract equal block?
|
3684
|
-
var ns = this.cleanSelector(p[2].concat(token[2].slice(2))),
|
3685
|
-
nss = translator.translate(cleanInfo(ns)),
|
3686
|
-
rl = nss.length + // selector length
|
3687
|
-
ns.length - 1 + // delims length
|
3688
|
-
2, // braces length
|
3689
|
-
bl = this.calcLength(r.eq) + // declarations length
|
3690
|
-
r.eq.length - 1; // decldelims length
|
3691
|
-
|
3692
|
-
if (bl >= rl) { // ok, it's good enough to extract
|
3693
|
-
ns[0].s = nss;
|
3694
|
-
nr = [{f:0, l:0}, 'ruleset', ns, [{f:0,l:0}, 'block'].concat(r.eq)];
|
3695
|
-
token[3].splice(2);
|
3696
|
-
token[3] = token[3].concat(r.ne1);
|
3697
|
-
p[3].splice(2);
|
3698
|
-
p[3] = p[3].concat(r.ne2);
|
3699
|
-
container.splice(i, 0, nr);
|
3700
|
-
return nr;
|
3701
|
-
}
|
3702
|
-
}
|
3703
|
-
}
|
3704
|
-
}
|
3705
|
-
};
|
3706
|
-
|
3707
|
-
CSSOCompressor.prototype.calcLength = function(tokens) {
|
3708
|
-
var r = 0;
|
3709
|
-
for (var i = 0; i < tokens.length; i++) r += tokens[i][0].s.length;
|
3710
|
-
return r;
|
3711
|
-
};
|
3712
|
-
|
3713
|
-
CSSOCompressor.prototype.cleanSelector = function(token) {
|
3714
|
-
if (token.length === 2) return null;
|
3715
|
-
var h = {}, s;
|
3716
|
-
for (var i = 2; i < token.length; i++) {
|
3717
|
-
s = token[i][0].s;
|
3718
|
-
if (s in h) token.splice(i, 1), i--;
|
3719
|
-
else h[s] = 1;
|
3720
|
-
}
|
3721
|
-
|
3722
|
-
return token;
|
3723
|
-
};
|
3724
|
-
|
3725
|
-
CSSOCompressor.prototype.analyze = function(r1, r2) {
|
3726
|
-
var r = { eq: [], ne1: [], ne2: [] };
|
3727
|
-
|
3728
|
-
if (r1[1] !== r2[1]) return r;
|
3729
|
-
|
3730
|
-
var b1 = r1[3], b2 = r2[3],
|
3731
|
-
d1 = b1.slice(2), d2 = b2.slice(2),
|
3732
|
-
h1, h2, i, x;
|
3733
|
-
|
3734
|
-
h1 = this.getHash(d1);
|
3735
|
-
h2 = this.getHash(d2);
|
3736
|
-
|
3737
|
-
for (i = 0; i < d1.length; i++) {
|
3738
|
-
x = d1[i];
|
3739
|
-
if (x[0].s in h2) r.eq.push(x);
|
3740
|
-
else r.ne1.push(x);
|
3741
|
-
}
|
3742
|
-
|
3743
|
-
for (i = 0; i < d2.length; i++) {
|
3744
|
-
x = d2[i];
|
3745
|
-
if (!(x[0].s in h1)) r.ne2.push(x);
|
3746
|
-
}
|
3747
|
-
|
3748
|
-
return r;
|
3749
|
-
};
|
3750
|
-
|
3751
|
-
CSSOCompressor.prototype.equalHash = function(h0, h1) {
|
3752
|
-
var k;
|
3753
|
-
for (k in h0) if (!(k in h1)) return false;
|
3754
|
-
for (k in h1) if (!(k in h0)) return false;
|
3755
|
-
return true;
|
3756
|
-
};
|
3757
|
-
|
3758
|
-
CSSOCompressor.prototype.getHash = function(tokens) {
|
3759
|
-
var r = {};
|
3760
|
-
for (var i = 0; i < tokens.length; i++) r[tokens[i][0].s] = 1;
|
3761
|
-
return r;
|
3762
|
-
};
|
3763
|
-
|
3764
|
-
CSSOCompressor.prototype.hashInHash = function(h0, h1) {
|
3765
|
-
for (var k in h0) if (!(k in h1)) return false;
|
3766
|
-
return true;
|
3767
|
-
};
|
3768
|
-
|
3769
|
-
CSSOCompressor.prototype.delimSelectors = function(token) {
|
3770
|
-
for (var i = token.length - 1; i > 2; i--) {
|
3771
|
-
token.splice(i, 0, [{}, 'delim']);
|
3772
|
-
}
|
3773
|
-
};
|
3774
|
-
|
3775
|
-
CSSOCompressor.prototype.delimBlocks = function(token) {
|
3776
|
-
for (var i = token.length - 1; i > 2; i--) {
|
3777
|
-
token.splice(i, 0, [{}, 'decldelim']);
|
3778
|
-
}
|
3779
|
-
};
|
3780
|
-
|
3781
|
-
CSSOCompressor.prototype.copyArray = function(a) {
|
3782
|
-
var r = [], t;
|
3783
|
-
|
3784
|
-
for (var i = 0; i < a.length; i++) {
|
3785
|
-
t = a[i];
|
3786
|
-
if (Array.isArray(t)) r.push(this.copyArray(t));
|
3787
|
-
else if (typeof t === 'object') r.push(this.copyObject(t));
|
3788
|
-
else r.push(t);
|
3789
|
-
}
|
3790
|
-
|
3791
|
-
return r;
|
3792
|
-
};
|
3793
|
-
|
3794
|
-
CSSOCompressor.prototype.copyObject = function(o) {
|
3795
|
-
var r = {};
|
3796
|
-
for (var k in o) r[k] = o[k];
|
3797
|
-
return r;
|
3798
|
-
};
|
3799
|
-
|
3800
|
-
CSSOCompressor.prototype.pathUp = function(path) {
|
3801
|
-
return path.substr(0, path.lastIndexOf('/'));
|
3802
|
-
};
|
3803
|
-
function CSSOTranslator() {}
|
3804
|
-
|
3805
|
-
CSSOTranslator.prototype.translate = function(tree) {
|
3806
|
-
// console.trace('--------');
|
3807
|
-
// console.log(tree);
|
3808
|
-
return this._t(tree);
|
3809
|
-
};
|
3810
|
-
|
3811
|
-
CSSOTranslator.prototype._m_simple = {
|
3812
|
-
'unary': 1, 'nth': 1, 'combinator': 1, 'ident': 1, 'number': 1, 's': 1,
|
3813
|
-
'string': 1, 'attrselector': 1, 'operator': 1, 'raw': 1, 'unknown': 1
|
3814
|
-
};
|
3815
|
-
|
3816
|
-
CSSOTranslator.prototype._m_composite = {
|
3817
|
-
'simpleselector': 1, 'dimension': 1, 'selector': 1, 'property': 1, 'value': 1,
|
3818
|
-
'filterv': 1, 'progid': 1, 'ruleset': 1, 'atruleb': 1, 'atrulerq': 1, 'atrulers': 1,
|
3819
|
-
'stylesheet': 1
|
3820
|
-
};
|
3821
|
-
|
3822
|
-
CSSOTranslator.prototype._m_primitive = {
|
3823
|
-
'cdo': 'cdo', 'cdc': 'cdc', 'decldelim': ';', 'namespace': '|', 'delim': ','
|
3824
|
-
};
|
3825
|
-
|
3826
|
-
CSSOTranslator.prototype._t = function(tree) {
|
3827
|
-
var t = tree[0];
|
3828
|
-
if (t in this._m_primitive) return this._m_primitive[t];
|
3829
|
-
else if (t in this._m_simple) return this._simple(tree);
|
3830
|
-
else if (t in this._m_composite) return this._composite(tree);
|
3831
|
-
return this[t](tree);
|
3832
|
-
};
|
3833
|
-
|
3834
|
-
CSSOTranslator.prototype._composite = function(t, i) {
|
3835
|
-
var s = '';
|
3836
|
-
i = i === undefined ? 1 : i;
|
3837
|
-
for (; i < t.length; i++) s += this._t(t[i]);
|
3838
|
-
return s;
|
3839
|
-
};
|
3840
|
-
|
3841
|
-
CSSOTranslator.prototype._simple = function(t) {
|
3842
|
-
return t[1];
|
3843
|
-
};
|
3844
|
-
|
3845
|
-
CSSOTranslator.prototype.percentage = function(t) {
|
3846
|
-
return this._t(t[1]) + '%';
|
3847
|
-
};
|
3848
|
-
|
3849
|
-
CSSOTranslator.prototype.comment = function(t) {
|
3850
|
-
return '/*' + t[1] + '*/';
|
3851
|
-
};
|
3852
|
-
|
3853
|
-
CSSOTranslator.prototype.clazz = function(t) {
|
3854
|
-
return '.' + this._t(t[1]);
|
3855
|
-
};
|
3856
|
-
|
3857
|
-
CSSOTranslator.prototype.atkeyword = function(t) {
|
3858
|
-
return '@' + this._t(t[1]);
|
3859
|
-
};
|
3860
|
-
|
3861
|
-
CSSOTranslator.prototype.shash = function(t) {
|
3862
|
-
return '#' + t[1];
|
3863
|
-
};
|
3864
|
-
|
3865
|
-
CSSOTranslator.prototype.vhash = function(t) {
|
3866
|
-
return '#' + t[1];
|
3867
|
-
};
|
3868
|
-
|
3869
|
-
CSSOTranslator.prototype.attrib = function(t) {
|
3870
|
-
return '[' + this._composite(t) + ']';
|
3871
|
-
};
|
3872
|
-
|
3873
|
-
CSSOTranslator.prototype.important = function(t) {
|
3874
|
-
return '!' + this._composite(t) + 'important';
|
3875
|
-
};
|
3876
|
-
|
3877
|
-
CSSOTranslator.prototype.nthselector = function(t) {
|
3878
|
-
return ':' + this._simple(t[1]) + '(' + this._composite(t, 2) + ')';
|
3879
|
-
};
|
3880
|
-
|
3881
|
-
CSSOTranslator.prototype.funktion = function(t) {
|
3882
|
-
return this._simple(t[1]) + '(' + this._composite(t[2]) + ')';
|
3883
|
-
};
|
3884
|
-
|
3885
|
-
CSSOTranslator.prototype.declaration = function(t) {
|
3886
|
-
return this._t(t[1]) + ':' + this._t(t[2]);
|
3887
|
-
};
|
3888
|
-
|
3889
|
-
CSSOTranslator.prototype.filter = function(t) {
|
3890
|
-
return this._t(t[1]) + ':' + this._t(t[2]);
|
3891
|
-
};
|
3892
|
-
|
3893
|
-
CSSOTranslator.prototype.block = function(t) {
|
3894
|
-
return '{' + this._composite(t) + '}';
|
3895
|
-
};
|
3896
|
-
|
3897
|
-
CSSOTranslator.prototype.braces = function(t) {
|
3898
|
-
return t[1] + this._composite(t, 3) + t[2];
|
3899
|
-
};
|
3900
|
-
|
3901
|
-
CSSOTranslator.prototype.atrules = function(t) {
|
3902
|
-
return this._composite(t) + ';';
|
3903
|
-
};
|
3904
|
-
|
3905
|
-
CSSOTranslator.prototype.atruler = function(t) {
|
3906
|
-
return this._t(t[1]) + this._t(t[2]) + '{' + this._t(t[3]) + '}';
|
3907
|
-
};
|
3908
|
-
|
3909
|
-
CSSOTranslator.prototype.pseudoe = function(t) {
|
3910
|
-
return '::' + this._t(t[1]);
|
3911
|
-
};
|
3912
|
-
|
3913
|
-
CSSOTranslator.prototype.pseudoc = function(t) {
|
3914
|
-
return ':' + this._t(t[1]);
|
3915
|
-
};
|
3916
|
-
|
3917
|
-
CSSOTranslator.prototype.uri = function(t) {
|
3918
|
-
return 'url(' + this._composite(t) + ')';
|
3919
|
-
};
|
3920
|
-
|
3921
|
-
CSSOTranslator.prototype.functionExpression = function(t) {
|
3922
|
-
return 'expression(' + t[1] + ')';
|
3923
|
-
};
|
15
|
+
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.csso=e()}}(function(){return function e(t,r,n){function o(a,u){if(!r[a]){if(!t[a]){var s="function"==typeof require&&require;if(!u&&s)return s(a,!0);if(i)return i(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var l=r[a]={exports:{}};t[a][0].call(l.exports,function(e){var r=t[a][1][e];return o(r?r:e)},l,l.exports,e,t,r,n)}return r[a].exports}for(var i="function"==typeof require&&require,a=0;a<n.length;a++)o(n[a]);return o}({1:[function(e,t,r){function n(e,t){for(;t<e.length;t++){var r=e[t][1];if("s"!==r&&"comment"!==r)break}return t}function o(e,t,r){for(t=n(e,t);r>=t;r--){var o=e[r][1];if("s"!==o&&"comment"!==o)break}return t>r?[]:e.slice(t,r+1).map(a).filter(Boolean)}function i(e){for(var t=[],r=e,n=2,i=n;i<r.length;i++)"operator"===r[i][1]&&","===r[i][2]&&(t.push({type:"Argument",info:{},sequence:o(r,n,i-1)}),n=i+1);var a=o(r,n,r.length-1);return(a.length||t.length)&&t.push({type:"Argument",info:{},sequence:a}),t}function a(e,t,r){if(e){var n=e[1];if(s.hasOwnProperty(n)&&"function"==typeof s[n])return s[n](e)}return null}var u=function(e){return{type:"StyleSheet",info:e[0],rules:e.filter(function(e,t){return t>=2&&"s"!==e[1]&&"comment"!==e[1]&&"unknown"!==e[1]}).map(a)}},s={atkeyword:!1,atruleb:function(e){return{type:"Atrule",info:e[0],name:e[2][2][2],expression:{type:"AtruleExpression",info:{},sequence:o(e,3,e.length-2)},block:a(e[e.length-1])}},atruler:function(e){return{type:"Atrule",info:e[0],name:e[2][2][2],expression:a(e[3]),block:a(e[4])}},atrulerq:function(e){return{type:"AtruleExpression",info:e[0],sequence:o(e,2,e.length-1)}},atrulers:u,atrules:function(e){return{type:"Atrule",info:e[0],name:e[2][2][2],expression:{type:"AtruleExpression",info:{},sequence:o(e,3,e.length-1)},block:null}},attrib:function(e){var t=2;t=n(e,2);var r=a(e[t]);e[t+1]&&"namespace"===e[t+1][1]&&(r.name+="|"+e[t+2][2],t+=2),t=n(e,t+1);var o=e[t]?e[t][2]:null;t=n(e,t+1);var i=a(e[t]);return{type:"Attribute",info:e[0],name:r,operator:o,value:i}},attrselector:!1,block:function(e){return{type:"Block",info:e[0],declarations:e.filter(function(e,t){return t>=2&&("declaration"===e[1]||"filter"===e[1])}).map(a)}},braces:function(e){return{type:"Braces",info:e[0],open:e[2],close:e[3],sequence:o(e,4,e.length-1)}},clazz:function(e){return{type:"Class",info:e[0],name:e[2][2]}},combinator:function(e){return{type:"Combinator",info:e[0],name:e[2]}},comment:!1,declaration:function(e){return{type:"Declaration",info:e[0],property:a(e[2]),value:a(e[3])}},decldelim:!1,delim:!1,dimension:function(e){return{type:"Dimension",info:e[0],value:e[2][2],unit:e[3][2]}},filter:function(e){return{type:"Declaration",info:e[0],property:a(e[2]),value:a(e[3])}},filterv:function(e){return{type:"Value",info:e[0],sequence:o(e,2,e.length-1)}},functionExpression:function(e){return{type:"Function",name:"expression",arguments:[{type:"Argument",sequence:[{type:"Raw",value:e[2]}]}]}},funktion:function(e){return{type:"Function",info:e[0],name:e[2][2],arguments:i(e[3])}},functionBody:!1,ident:function(e){return{type:"Identifier",info:e[0],name:e[2]}},important:function(e){return{type:"Important",info:e[0]}},namespace:!1,nth:function(e){return{type:"Nth",value:e[2]}},nthselector:function(e){return{type:"FunctionalPseudo",info:e[0],name:e[2][2],arguments:[{type:"Argument",sequence:e.filter(function(e,t){return t>=3&&"s"!==e[1]&&"comment"!==e[1]}).map(a)}]}},number:function(e){return{type:"Number",info:e[0],value:e[2]}},operator:function(e){return{type:"Operator",info:e[0],value:e[2]}},percentage:function(e){return{type:"Percentage",info:e[0],value:e[2][2]}},progid:function(e){return{type:"Progid",info:e[0],value:o(e,2,e.length-1)[0]}},property:function(e){return{type:"Property",info:e[0],name:e[2][2]}},pseudoc:function(e){var t=e[2];if("funktion"===t[1]){var r=t[2][2];return"not"===r?{type:"Negation",sequence:[s.simpleselector(t[3][2])]}:{type:"FunctionalPseudo",info:t[0],name:r,arguments:i(t[3])}}return{type:"PseudoClass",info:e[0],name:t[2]}},pseudoe:function(e){var t=e[2];return{type:"PseudoElement",info:e[0],name:t[2]}},raw:function(e){return{type:"Raw",info:e[0],value:e[2]}},ruleset:function(e){var t,r=a(e[2]);return 4===e.length?t=a(e[3]):(t=r,r=null),{type:"Ruleset",info:e[0],selector:r,block:t}},s:function(e){return{type:"Space",info:e[0]}},selector:function(e){var t="delim",r=!1,n=e.filter(function(e,n){var o=e[1];return("simpleselector"===o||"delim"===o)&&(t===o&&(r=!0),t=o),n>=2&&"simpleselector"===o}).map(a);return r||"delim"===t||0===n.length||0===n[n.length-1].sequence.length?null:{type:"Selector",info:e[0],selectors:n}},shash:function(e){return{type:"Id",info:e[0],name:e[2]}},simpleselector:function(e){for(var t=[],r=n(e,2),o=!1;r<e.length;r++){var i=e[r];switch(i[1]){case"combinator":o=!1,t.push(i);break;case"s":"combinator"!==t[t.length-1][1]&&(o=i);break;case"comment":break;case"namespace":t[t.length-1]=[{},"ident",t[t.length-1][2]+"|"+e[r+1][2]],r++;break;default:o&&t.push([o[0],"combinator"," "]),o=!1,t.push(i)}}return{type:"SimpleSelector",info:e[0],sequence:t.map(a)}},string:function(e){return{type:"String",info:e[0],value:e[2]}},stylesheet:u,unary:function(e){return{type:"Operator",info:e[0],value:e[2]}},unknown:!1,uri:function(e){return{type:"Url",info:e[0],value:o(e,2,e.length-1)[0]}},value:function(e){return{type:"Value",info:e[0],sequence:o(e,2,e.length-1)}},vhash:function(e){return{type:"Hash",info:e[0],value:e[2]}}};t.exports=a},{}],2:[function(e,t,r){function n(e,t,r,n){for(var o=[e.info,t],a=e[r],u=0;u<a.length;u++)o.push(i(a[u])),u!==a.length-1&&o.push(n.slice());return o}function o(e,t){for(var r=0;r<t.length;r++)e.push.apply(e,t[r].sequence.map(i)),r!==t.length-1&&e.push([{},"operator",","])}function i(e){switch(e.type){case"StyleSheet":return[e.info||{},"stylesheet"].concat(e.rules.map(i).filter(Boolean));case"Atrule":var t="atruler";e.block?"Block"===e.block.type&&(t="atruleb"):t="atrules";var r=[e.info,t,[{},"atkeyword",[{},"ident",e.name]]];return e.expression&&e.expression.sequence.length?"atruler"===t?r.push([e.expression.info,"atrulerq",[{},"s"," "]].concat(e.expression.sequence.map(i))):(r.push([{},"s"," "]),r=r.concat(e.expression.sequence.map(i))):"atruler"===t&&r.push([{},"atrulerq"]),e.block&&("atruler"===t?r.push([e.block.info,"atrulers"].concat(e.block.rules.map(i))):r.push(i(e.block))),r;case"Ruleset":return e.selector?[e.info,"ruleset",i(e.selector),i(e.block)]:[e.info,"ruleset",i(e.block)];case"Selector":return n(e,"selector","selectors",[{},"delim"]);case"SimpleSelector":var r=[e.info,"simpleselector"];return e.sequence.forEach(function(e){e=i(e),"ident"===e[1]&&/\|/.test(e[2])?r.push([{},"ident",e[2].split("|")[0]],[{},"namespace"],[{},"ident",e[2].split("|")[1]]):r.push(e)}),r;case"Negation":var a=n(e,"functionBody","sequence",[{},"delim"]);return[e.info,"pseudoc",[{},"funktion",[{},"ident","not"],a]];case"Attribute":var r=[e.info,"attrib"];return/\|/.test(e.name.name)?r=r.concat([[{},"ident",e.name.name.split("|")[0]],[{},"namespace"],[{},"ident",e.name.name.split("|")[1]]]):r.push([{},"ident",e.name.name]),e.operator&&r.push([{},"attrselector",e.operator]),e.value&&r.push(i(e.value)),r;case"FunctionalPseudo":if(/^nth-/.test(e.name)){var r=[e.info,"nthselector",[{},"ident",e.name]];return o(r,e.arguments),r}var a=[{},"functionBody"];return o(a,e.arguments),[e.info,"pseudoc",[{},"funktion",[{},"ident",e.name],a]];case"Function":var a=[{},"functionBody"];return o(a,e.arguments),"expression"===e.name?[{},"functionExpression",a[2][2]]:[e.info,"funktion",[{},"ident",e.name],a];case"Argument":return;case"Block":return n(e,"block","declarations",[{},"decldelim"]);case"Declaration":return[e.info,e.value.sequence.length&&"Progid"===e.value.sequence[0].type&&/(-[a-z]+-|[\*-_])?filter$/.test(e.property.name)?"filter":"declaration",i(e.property),i(e.value)];case"Braces":return[e.info,"braces",e.open,e.close].concat(e.sequence.map(i));case"Value":return[e.info,e.sequence.length&&"Progid"===e.sequence[0].type?"filterv":"value"].concat(e.sequence.map(i));case"Url":return[e.info,"uri",i(e.value)];case"Progid":return[e.info,"progid",i(e.value)];case"Property":return[e.info,"property",[{},"ident",e.name]];case"Combinator":return" "===e.name?[e.info,"s",e.name]:[e.info,"combinator",e.name];case"Identifier":return[e.info,"ident",e.name];case"PseudoElement":return[e.info,"pseudoe",[{},"ident",e.name]];case"PseudoClass":return[e.info,"pseudoc",[{},"ident",e.name]];case"Class":return[e.info,"clazz",[{},"ident",e.name]];case"Id":return[e.info,"shash",e.name];case"Nth":return[e.info,"nth",e.value];case"Hash":return[e.info,"vhash",e.value];case"Number":return[e.info,"number",e.value];case"Dimension":return[e.info,"dimension",[{},"number",e.value],[{},"ident",e.unit]];case"Operator":return[e.info,"+"===e.value||"-"===e.value?"unary":"operator",e.value];case"Raw":return[e.info,e.value&&/\S/.test(e.value)?"raw":"s",e.value];case"String":return[e.info,"string",e.value];case"Important":return[e.info,"important"];case"Percentage":return[e.info,"percentage",[{},"number",e.value]];case"Space":return[e.info,"s"," "];case"Comment":return[e.info,"comment",e.value];default:console.warn("Unknown node type:",e)}}t.exports=function(e){return e?i(e):[]}},{}],3:[function(e,t,r){function n(e,t){for(var r=0;r<e.length;r++)i(e[r],t,e,r)}function o(e,t,r){for(var n=0;n<e.length;n++)i(e[n],t,e,n),n!==e.length-1&&t.push(r)}function i(e,t,r,a){switch(e.type){case"Atrule":t.push("@",e.name),e.expression&&e.expression.sequence.length&&(t.push(" "),i(e.expression,t)),e.block?(t.push("{"),i(e.block,t),t.push("}")):t.push(";");break;case"Declaration":i(e.property,t),t.push(":"),i(e.value,t);break;case"Attribute":t.push("["),i(e.name,t),e.operator&&t.push(e.operator),e.value&&i(e.value,t),t.push("]");break;case"FunctionalPseudo":t.push(":",e.name,"("),o(e.arguments,t,","),t.push(")");break;case"Function":t.push(e.name,"("),o(e.arguments,t,","),t.push(")");break;case"Block":o(e.declarations,t,";");break;case"Ruleset":e.selector&&i(e.selector,t),t.push("{"),i(e.block,t),t.push("}");break;case"Selector":o(e.selectors,t,",");break;case"Negation":t.push(":not("),o(e.sequence,t,","),t.push(")");break;case"Braces":t.push(e.open),n(e.sequence,t),t.push(e.close);break;case"Argument":case"AtruleExpression":case"Value":case"SimpleSelector":n(e.sequence,t);break;case"StyleSheet":n(e.rules,t);break;case"Url":t.push("url("),i(e.value,t),t.push(")");break;case"Progid":i(e.value,t);break;case"Property":case"Combinator":case"Identifier":t.push(e.name);break;case"PseudoClass":t.push(":",e.name);break;case"PseudoElement":t.push("::",e.name);break;case"Class":t.push(".",e.name);break;case"Dimension":t.push(e.value,e.unit);break;case"Id":t.push("#",e.name);break;case"Hash":t.push("#",e.value);break;case"Nth":case"Number":case"String":case"Operator":case"Raw":t.push(e.value);break;case"Important":t.push("!important");break;case"Percentage":t.push(e.value,"%");break;case"Space":t.push(" ");break;case"Comment":t.push("/*",e.value,"*/");break;default:console.warn("Unknown node type:",e)}}t.exports=function(e){var t=[];return i(e,t),t.join("")}},{}],4:[function(e,t,r){function n(e,t,r){for(var n=0;n<e.length;n++){var o=e[n],i=t.call(this,o,r,e,n);null===i?(e.splice(n,1),n--):i&&i!==o&&e.splice(n,1,i)}}function o(e,t,r){for(var n=e.length-1;n>=0;n--){var o=e[n],i=t.call(this,o,r,e,n);null===i?e.splice(n,1):i&&i!==o&&e.splice(n,1,i)}}function i(e,t,r,o){switch(e.type){case"StyleSheet":n.call(this,e.rules,i,e);break;case"Atrule":return e.block&&i.call(this,e.block),this.fn(e,t,r,o);case"Ruleset":return this.fn(e,t,r,o)}}function a(e,t,r,n){switch(e.type){case"StyleSheet":o.call(this,e.rules,a,e);break;case"Atrule":return e.block&&a.call(this,e.block),this.fn(e,t,r,n);case"Ruleset":return this.fn(e,t,r,n)}}function u(e,t,r,o){switch(this.stack.push(e),e.type){case"Atrule":e.expression&&u.call(this,e.expression,e),e.block&&u.call(this,e.block,e);break;case"Declaration":u.call(this,e.property,e),u.call(this,e.value,e);break;case"Attribute":u.call(this,e.name,e),e.value&&u.call(this,e.value,e);break;case"FunctionalPseudo":case"Function":n.call(this,e.arguments,u,e);break;case"Block":n.call(this,e.declarations,u,e);break;case"Ruleset":e.selector&&u.call(this,e.selector,e),u.call(this,e.block,e);break;case"Selector":n.call(this,e.selectors,u,e);break;case"Argument":case"AtruleExpression":case"Braces":case"Negation":case"Value":case"SimpleSelector":n.call(this,e.sequence,u,e);break;case"StyleSheet":n.call(this,e.rules,u,e);break;case"Url":case"Progid":u.call(this,e.value,e);break;case"Property":case"Combinator":case"Dimension":case"Hash":case"Identifier":case"Important":case"Nth":case"Class":case"Id":case"Percentage":case"PseudoClass":case"PseudoElement":case"Space":case"Number":case"String":case"Operator":case"Raw":}return this.stack.pop(e),this.fn(e,t,r,o)}t.exports={all:function(e,t){u.call({fn:t,root:e,stack:[]},e)},rules:function(e,t){i.call({fn:t,root:e,stack:[]},e)},rulesRight:function(e,t){a.call({fn:t,root:e,stack:[]},e)}}},{}],5:[function(e,t,r){t.exports=function(e,t,r,n){if(e.block){if(this.root.firstAtrulesAllowed=!1,"Block"===e.block.type&&!e.block.declarations.length)return null;if("StyleSheet"===e.block.type&&!e.block.rules.length)return null}switch(e.name){case"charset":if(!e.expression.sequence.length)return null;if(n)return null;break;case"import":if(!this.root.firstAtrulesAllowed)return null;for(n-=1;n>=0;n--){var o=r[n];if("Atrule"!==o.type||"import"!==o.name&&"charset"!==o.name)return this.root.firstAtrulesAllowed=!1,null}}}},{}],6:[function(e,t,r){t.exports=function(e){return e.value.sequence.length?void 0:null}},{}],7:[function(e,t,r){t.exports=function(e){return e.selector&&e.block.declarations.length?void 0:null}},{}],8:[function(e,t,r){function n(e,t){switch(e.type){case"Important":case"Nth":return!0;case"Operator":return"+"!==e.value&&"-"!==e.value}if(t)switch(e.type){case"Function":case"Braces":case"Url":return!0}}t.exports=function(e,t,r,o){var i=r[o-1],a=r[o+1],u=i.type,s=a.type;return"Url"===u&&s||"Braces"===u&&"Identifier"===s||"Function"===u&&("Function"===s||"Hash"===s)||"Braces"===u&&"Operator"===s&&("+"===a.value||"-"===a.value)?void 0:"Identifier"===u&&"*"===i.name||"Identifier"===s&&"*"===a.name?null:n(a,!1)||n(i,!0)?null:void 0}},{}],9:[function(e,t,r){var n={Space:e("./Space.js"),Atrule:e("./Atrule.js"),Ruleset:e("./Ruleset.js"),Declaration:e("./Declaration.js")};t.exports=function(e,t,r,o){return n.hasOwnProperty(e.type)?n[e.type].call(this,e,t,r,o):void 0}},{"./Atrule.js":5,"./Declaration.js":6,"./Ruleset.js":7,"./Space.js":8}],10:[function(e,t,r){var n=e("./atrule/keyframes.js");t.exports=function(e,t,r,o){/^(-[a-z\d]+-)?keyframes$/.test(e.name)&&n(e,t,r,o)}},{"./atrule/keyframes.js":16}],11:[function(e,t,r){function n(e){return""!==e&&"-"!==e?(e=e.replace(o,"a"),!i.test(e)):void 0}var o=/\\([0-9A-Fa-f]{1,6})[ \t\n\f\r]?|\\./g,i=/^(-?\d|--)|[\u0000-\u002c\u002e\u002f\u003A-\u0040\u005B-\u005E\u0060\u007B-\u009f]/;t.exports=function(e){var t=e.value;if(t&&"String"===t.type){var r=t.value.replace(/^(.)(.*)\1$/,"$2");n(r)&&(e.value={type:"Identifier",info:t.info,name:r})}}},{}],12:[function(e,t,r){var n=e("./Number.js").pack,o={deg:!0,grad:!0,rad:!0,turn:!0,s:!0,ms:!0,Hz:!0,kHz:!0,dpi:!0,dpcm:!0,dppx:!0};t.exports=function(e,t){var r=n(e.value),i=e.unit;if(e.value=r,"0"===r&&!o[i]){if("Value"===t.type&&"flex"===this.stack[this.stack.length-2].property.name)return;for(var a=this.stack.length-1;a>=0;a--){var u=this.stack[a];if("Function"===u.type&&"calc"===u.name)return;if("Braces"!==u.type&&"Argument"!==u.type)break}return{type:"Number",info:e.info,value:r}}}},{"./Number.js":13}],13:[function(e,t,r){function n(e){return e=String(e).replace(/^(?:\+|(-))?0*(\d*)(?:\.0*|(\.\d*?)0*)?$/,"$1$2$3"),(""===e||"-"===e)&&(e="0"),e}t.exports=function(e){e.value=n(e.value)},t.exports.pack=n},{}],14:[function(e,t,r){t.exports=function(e){var t=e.value;t=t.replace(/\\\n/g,""),e.value=t}},{}],15:[function(e,t,r){var n=e("./property/font.js"),o=e("./property/font-weight.js"),i=e("./property/background.js");t.exports=function(e,t){var r=t.property.name;/background$/.test(r)?i(e):/font$/.test(r)?n(e):/font-weight$/.test(r)&&o(e)}},{"./property/background.js":19,"./property/font-weight.js":20,"./property/font.js":21}],16:[function(e,t,r){t.exports=function(e){e.block.rules.forEach(function(e){e.selector.selectors.forEach(function(e){for(var t=e.sequence,r=0;r<t.length;r++){var n=t[r];"Percentage"===n.type&&"100"===n.value?t[r]={type:"Identifier",info:t[r].info,name:"to"}:"Identifier"===n.type&&"from"===n.name&&(t[r]={type:"Percentage",info:t[r].info,value:"0"})}})})}},{}],17:[function(e,t,r){function n(e,t,r){return 0>r&&(r+=1),r>1&&(r-=1),1/6>r?e+6*(t-e)*r:.5>r?t:2/3>r?e+(t-e)*(2/3-r)*6:e}function o(e,t,r,o){var i,a,u;if(0==t)i=a=u=r;else{var s=.5>r?r*(1+t):r+t-r*t,c=2*r-s;i=n(c,s,e+1/3),a=n(c,s,e),u=n(c,s,e-1/3)}return[Math.round(255*i),Math.round(255*a),Math.round(255*u),o]}function i(e){return e=e.toString(16),1===e.length?"0"+e:e}function a(e,t,r){for(var n=[],o=0;o<e.length;o++)for(var i=e[o].sequence,a=!1,u=0;u<i.length;u++){var s=i[u],c=s.type;switch(c){case"Number":case"Percentage":if(a)return;a=!0,n.push({type:c,value:Number(s.value)});break;case"Operator":if(a||"+"!==s.value)return;break;default:return}}if(n.length===t){if(4===n.length){if("Number"!==n[3].type)return;n[3].type="Alpha"}if(r){if(n[0].type!==n[1].type||n[0].type!==n[2].type)return}else{if("Number"!==n[0].type||"Percentage"!==n[1].type||"Percentage"!==n[2].type)return;n[0].type="Angle"}return n.map(function(e,t){var n=Math.max(0,e.value);switch(e.type){case"Number":n=Math.min(n,255);break;case"Percentage":if(n=Math.min(n,100)/100,!r)return n;n=255*n;break;case"Angle":return(n%360+360)%360/360;case"Alpha":return Math.min(n,1)}return Math.round(n)})}}function u(e,t,r,n){var u,s=e.name;if("rgba"===s||"hsla"===s){if(u=a(e.arguments,4,"rgba"===s),!u)return;if("hsla"===s&&(u=o.apply(null,u),e.name="rgba"),1!==u[3])return void e.arguments.forEach(function(e,t){var r=e.sequence[0];"Operator"===r.type&&(r=e.sequence[1]),e.sequence=[{type:"Number",info:r.info,value:l(u[t])}]});s="rgb"}if("hsl"===s){if(u=u||a(e.arguments,3,!1),!u)return;u=o.apply(null,u),s="rgb"}if("rgb"===s){if(u=u||a(e.arguments,3,!0),!u)return;var f=r&&n<r.length-1?r[n+1]:null;f&&"Space"!==f.type&&r.splice(n+1,0,{type:"Space"});var p={type:"Hash",info:e.info,value:i(u[0])+i(u[1])+i(u[2])};return c(p)||p}}function s(e,t){var r=t.type;if("Value"===r||"Function"===r){var n=e.name.toLowerCase(),o=f[n];if(o){if(o.length+1<=n.length)return{type:"Hash",info:e.info,value:o};"grey"===n&&(n="gray"),e.name=n}}}function c(e){var t=e.value.toLowerCase();return 6===t.length&&t[0]===t[1]&&t[2]===t[3]&&t[4]===t[5]&&(t=t[0]+t[2]+t[4]),p[t]?{type:"Identifier",info:e.info,name:p[t]}:void(e.value=t)}var l=e("./Number.js").pack,f={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgrey:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",grey:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"639",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},p={800000:"maroon",800080:"purple",808000:"olive",808080:"gray","00ffff":"cyan",f0ffff:"azure",f5f5dc:"beige",ffe4c4:"bisque","000000":"black","0000ff":"blue",a52a2a:"brown",ff7f50:"coral",ffd700:"gold","008000":"green","4b0082":"indigo",fffff0:"ivory",f0e68c:"khaki","00ff00":"lime",faf0e6:"linen","000080":"navy",ffa500:"orange",da70d6:"orchid",cd853f:"peru",ffc0cb:"pink",dda0dd:"plum",f00:"red",ff0000:"red",fa8072:"salmon",a0522d:"sienna",c0c0c0:"silver",fffafa:"snow",d2b48c:"tan","008080":"teal",ff6347:"tomato",ee82ee:"violet",f5deb3:"wheat",ffffff:"white",ffff00:"yellow"};t.exports={compressFunction:u,compressIdent:s,compressHex:c}},{"./Number.js":13}],18:[function(e,t,r){var n={Atrule:e("./Atrule.js"),Attribute:e("./Attribute.js"),Value:e("./Value.js"),Dimension:e("./Dimension.js"),Percentage:e("./Number.js"),Number:e("./Number.js"),String:e("./String.js"),Hash:e("./color.js").compressHex,Identifier:e("./color.js").compressIdent,Function:e("./color.js").compressFunction};t.exports=function(e,t,r,o){return n.hasOwnProperty(e.type)?n[e.type].call(this,e,t,r,o):void 0}},{"./Atrule.js":10,"./Attribute.js":11,"./Dimension.js":12,"./Number.js":13,"./String.js":14,"./Value.js":15,"./color.js":17}],19:[function(e,t,r){t.exports=function(e){function t(){return o.length?o[o.length-1].type:void 0}function r(){"Space"===t()&&o.pop(),(!o.length||1===o.length&&"Important"===o[0].type)&&o.unshift({type:"Number",value:"0"},{type:"Space"},{type:"Number",value:"0"}),n.push.apply(n,o),o=[]}var n=[],o=[];e.sequence.forEach(function(e){return"Operator"===e.type&&","===e.value?(r(),void n.push(e)):void(("Identifier"!==e.type||"transparent"!==e.name&&"none"!==e.name&&"repeat"!==e.name&&"scroll"!==e.name)&&("Space"!==e.type||o.length&&"Space"!==t())&&o.push(e))}),r(),e.sequence=n}},{}],20:[function(e,t,r){t.exports=function(e){var t=e.sequence[0];if("Identifier"===t.type)switch(t.name){case"normal":e.sequence[0]={type:"Number",info:t.info,value:"400"};break;case"bold":e.sequence[0]={type:"Number",info:t.info,value:"700"}}}},{}],21:[function(e,t,r){t.exports=function(e){for(var t=e.sequence,r=t.length-1;r>=0;r--){var n=t[r];if("Identifier"===n.type)if("bold"===n.name)t[r]={type:"Number",info:e.info,value:"700"};else if("normal"===n.name){var o=r?t[r-1]:null;o&&"Operator"===o.type&&"/"===o.value?t.splice(--r,2):t.splice(r,1)}else if("medium"===n.name){var i=r<t.length-1?t[r+1]:null;i&&"Operator"===i.type||t.splice(r,1)}}for(var r=0;r<t.length;r++)"Space"===t[r].type&&(r&&r!==t.length-1&&"Space"!==t[r+1].type||(t.splice(r,1),r--));t.length||t.push({type:"Identifier",name:"normal"}),e.sequence=t}},{}],22:[function(e,t,r){function n(e){var t;return e?function(r,n,o){var i=(o?"":"("+((Date.now()-t)/1e3).toFixed(3)+"ms) ")+r;if(e>1&&n){var a=c(n,!0).trim();2===e&&a.length>256&&(a=a.substr(0,256)+"..."),i+="\n "+a+"\n"}console.error(i),t=Date.now()}:function(){}}function o(e){for(var t=e.length-1;t>-1;t--){var r=e[t];Array.isArray(r)&&(o(r),r.unshift({}))}}function i(e,t){for(var r,n=[],o=!1,i=t;i<e.length;i++){var a=e[i];if("comment"!==a[1]||"!"!==a[2].charAt(0))"s"!==a[1]&&(o=!0),n.push(a);else{if(o||r)break;r=a}}return{comment:r,stylesheet:[{},"stylesheet"].concat(n),offset:i}}function a(e,t,r,n){function o(e,t){l(i,t),n(e,i)}n("Compress block #"+r,null,!0);var i=u(e);return n("convertToInternal",i),i.firstAtrulesAllowed=e.firstAtrulesAllowed,o("clean",f),o("compress",p),t&&h(i,n),i}var u=e("./ast/gonzalesToInternal.js"),s=e("./ast/internalToGonzales.js"),c=e("./ast/translate.js"),l=e("./ast/walk.js").all,f=e("./clean"),p=e("./compress"),h=e("./restructure");t.exports=function(e,t){e=e||[{},"stylesheet"],t=t||{};var r=n(t.debug),u=t.restructuring||void 0===t.restructuring,c=[],l={offset:2},f=!0,p=1;"string"==typeof e[0]&&o([e]);do if(l=i(e,l.offset),l.stylesheet.firstAtrulesAllowed=f,l.stylesheet=a(l.stylesheet,u,p++,r),l.comment&&(c.length&&c.push({type:"Raw",value:"\n"}),c.push({type:"Comment",value:l.comment[2]}),l.stylesheet.rules.length&&c.push({type:"Raw",value:"\n"})),c.push.apply(c,l.stylesheet.rules),f&&c.length){var h=c[c.length-1];("Atrule"!==h.type||"import"!==h.name&&"charset"!==h.name)&&(f=!1)}while(l.offset<e.length);return t.outputAst&&"gonzales"!==t.outputAst?{type:"StyleSheet",rules:c}:s({type:"StyleSheet",rules:c})}},{"./ast/gonzalesToInternal.js":1,"./ast/internalToGonzales.js":2,"./ast/translate.js":3,"./ast/walk.js":4,"./clean":9,"./compress":18,"./restructure":24}],23:[function(e,t,r){var n=e("./utils.js");t.exports=function(e,t,r,o){var i=e.selector.selectors;if(i.length>1){for(var a=i.length-1;a>=1;a--)r.splice(o+1,0,{type:"Ruleset",info:n.copyObject(e.info),selector:{type:"Selector",info:n.copyObject(e.selector.info),selectors:[i[a]]},block:{type:"Block",info:n.copyObject(e.block.info),declarations:e.block.declarations.slice()}});e.selector.selectors=[e.selector.selectors[0]]}}},{"./utils.js":35}],24:[function(e,t,r){var n=e("../ast/walk.js").all,o=e("../ast/walk.js").rules,i=e("../ast/walk.js").rulesRight,a=e("./prepare/index.js"),u=e("./markShorthands.js"),s=e("./processShorthands.js"),c=e("./disjoinRuleset.js"),l=e("./rejoinRuleset.js"),f=e("./initialRejoinRuleset.js"),p=e("./rejoinAtrule.js"),h=e("./restructBlock.js"),d=e("./restructRuleset.js");t.exports=function(e,t){function r(r,o){n(e,o),t(r,e)}function y(r,n){o(e,function(e){return"Ruleset"===e.type?n.apply(this,arguments):void 0}),t(r,e)}function m(r,n){i(e,function(e){return"Ruleset"===e.type?n.apply(this,arguments):void 0}),t(r,e)}function g(r,n){i(e,function(e){return"Atrule"===e.type?n.apply(this,arguments):void 0}),t(r,e)}r("prepare",a),m("initialRejoinRuleset",f),g("rejoinAtrule",p),m("disjoin",c);var v=[];m("buildMaps",function(e,t){var r=t.info.selectorsMap;r||(r=t.info.selectorsMap={},t.info.shortDeclarations=v,t.info.lastShortSelector=null);var n=e.selector.selectors[0].info.s;n in r==!1&&(r[n]={props:{},shorts:{}})}),m("markShorthands",u),s(v),t("processShorthand",e),m("restructBlock",h),y("rejoinRuleset",l),m("restructRuleset",d)}},{"../ast/walk.js":4,"./disjoinRuleset.js":23,"./initialRejoinRuleset.js":25,"./markShorthands.js":26,"./prepare/index.js":28,"./processShorthands.js":30,"./rejoinAtrule.js":31,"./rejoinRuleset.js":32,"./restructBlock.js":33,"./restructRuleset.js":34}],25:[function(e,t,r){var n=e("./utils.js");t.exports=function(e,t,r,o){var i=e.selector.selectors,a=e.block;if(!a.declarations.length)return null;for(o-=1;o>=0;o--){var u=r[o];if("Ruleset"!==u.type)return;var s=u.selector.selectors,c=u.block;if(e.info.pseudoSignature!==u.info.pseudoSignature)return;var l=n.getHash(s),f=n.getHash(i);if(n.equalHash(f,l))return c.declarations.push.apply(c.declarations,a.declarations),null;if(!n.isCompatibleSignatures(e,u))return;var p=n.compareRulesets(e,u);if(!p.ne1.length&&!p.ne2.length)return n.addToSelector(s,i),null;for(var h=0;h<s.length;h++)for(var d=0;d<i.length;d++)if(s[h].info.compareMarker===i[d].info.compareMarker)return}}},{"./utils.js":35}],26:[function(e,t,r){function n(e,t){this.name=n.extractMain(e),this.important=t?4:0,this.sides={top:null,right:null,bottom:null,left:null}}var o=/vh|vw|vmin|vmax|vm|rem|\\9/,i=0,a=1,u=2,s=3,c=["top","right","bottom","left"],l={"margin-top":"top","margin-right":"right","margin-bottom":"bottom","margin-left":"left","padding-top":"top","padding-right":"right","padding-bottom":"bottom","padding-left":"left","border-top-color":"top","border-right-color":"right","border-bottom-color":"bottom","border-left-color":"left","border-top-width":"top","border-right-width":"right","border-bottom-width":"bottom","border-left-width":"left","border-top-style":"top","border-right-style":"right","border-bottom-style":"bottom","border-left-style":"left"},f={margin:"margin","margin-top":"margin","margin-right":"margin","margin-bottom":"margin","margin-left":"margin",padding:"padding","padding-top":"padding","padding-right":"padding","padding-bottom":"padding","padding-left":"padding","border-color":"border-color","border-top-color":"border-color","border-right-color":"border-color","border-bottom-color":"border-color","border-left-color":"border-color","border-width":"border-width","border-top-width":"border-width","border-right-width":"border-width","border-bottom-width":"border-width","border-left-width":"border-width","border-style":"border-style","border-top-style":"border-style","border-right-style":"border-style","border-bottom-style":"border-style","border-left-style":"border-style"};n.props=f,n.extractMain=function(e){return f[e]},n.prototype.impSum=function(){var e=0,t=0;for(var r in this.sides)this.sides[r]&&(e++,this.sides[r].important&&t++);return t===e?t:0},n.prototype.add=function(e,t,r,n){function o(e,t){h.push({s:t,node:e,important:n})}var f=this.sides,p=l[e],h=[];if(n=n?1:0,p){if(p in f){var d=f[p];return(!d||n&&!d.important)&&(f[p]={s:n?t.substring(0,t.length-10):t,node:r[0],important:n}),!0}}else if(e===this.name){for(var y=0;y<r.length;y++){var m=r[y];switch(m.type){case"Identifier":o(m,m.name);break;case"Number":o(m,m.value);break;case"Percentage":o(m,m.value+"%");break;case"Dimension":o(m,m.value+m.unit);break;case"Space":case"Important":break;default:return!1}}if(h.length>4)return!1;h[a]||(h[a]=h[i]),h[u]||(h[u]=h[i]),h[s]||(h[s]=h[a]);for(var y=0;4>y;y++)(!f[c[y]]||n&&!f[c[y]].important)&&(f[c[y]]=h[y]);return!0}},n.prototype.isOkToMinimize=function(){var e=this.sides.top,t=this.sides.right,r=this.sides.bottom,n=this.sides.left;if(e&&t&&r&&n){if(o.test([e.s,t.s,r.s,n.s].join(" ")))return!1;var i=e.important+t.important+r.important+n.important;return 0===i||4===i||i===this.important}return!1},n.prototype.getValue=function(){var e={type:"Value",info:{},sequence:[]},t=this.sides,r=[t.top,t.right,t.bottom,t.left];t.left.s===t.right.s&&(r.pop(),t.bottom.s===t.top.s&&(r.pop(),t.right.s===t.top.s&&r.pop())),e.sequence.push(r[i].node);for(var n=1;n<r.length;n++)e.sequence.push({type:"Space"},r[n].node);return this.impSum()&&e.sequence.push({type:"Important"}),e},n.prototype.getProperty=function(){return{type:"Property",info:{s:this.name},name:this.name}},t.exports=function(e,t){for(var r=e.block.declarations,o=e.selector.selectors[0].info.s,i=e.info.freezeID||"",a=t.info.selectorsMap[o].shorts,u=r.length-1;u>=0;u--){
|
16
|
+
var s=r[u];if("Declaration"===s.type){var c=s.info,l=s.property.info.s,f=s.value,p="Important"===f.sequence[f.sequence.length-1].type;if(l in n.props){var h=i+n.extractMain(l),d=null;t.info.lastShortSelector&&o!==t.info.lastShortSelector||h in a&&(d=a[h],c.removeByShort=!0),d||(d=new n(l,p),c.replaceByShort=!0),d.add(l,f.info.s,f.sequence.slice(0),p),a[h]=d,t.info.shortDeclarations.push({info:d,block:r,declaration:s,pos:u}),t.info.lastShortSelector=o}}}}},{}],27:[function(e,t,r){function n(e){return e.sequence.some(function(e){switch(e.type){case"PseudoClass":case"PseudoElement":case"FunctionalPseudo":if(e.name in f==!1)return!0}})}function o(e){return e.selectors.map(function(e){return e.info.s}).sort().join(",")}function i(e){return e.selectors.some(function(e){return e.sequence.some(function(e){switch(e.type){case"PseudoClass":if(e.name in f==!1)return!0;break;case"PseudoElement":if(e.name in l==!1)return!0;break;case"FunctionalPseudo":return!0}})})}function a(e){var t=[];return e.selectors.forEach(function(e){n(e)&&t.push(e.info.s)}),t.sort().join(",")}function u(e,t){var r={},n=!1;return e.selectors.forEach(function(e){e.sequence.forEach(function(e){switch(e.type){case"PseudoClass":case"PseudoElement":case"FunctionalPseudo":t.hasOwnProperty(e.name)?n=!0:r[e.name]=1}})}),Object.keys(r).sort().join(",")+n}function s(e){var t={};e.selectors.forEach(function(e){var r=e.info;r.pseudo=n(e),r.sg=t,t[r.s]=!0})}var c={after:1,before:1},l={"first-letter":!0,"first-line":!0},f={link:!0,visited:!0,hover:!0,active:!0,"first-letter":!0,"first-line":!0};t.exports=function p(e){var t=e.selector,p=i(t);if(p){var r=e.info;r.freeze=p,r.freezeID=o(t),r.pseudoID=a(t),r.pseudoSignature=u(t,c),s(t)}}},{}],28:[function(e,t,r){function n(e){e.info.s=o(e)}var o=e("../../ast/translate.js"),i=e("./specificity.js"),a=e("./freeze.js"),u={Ruleset:a,Atrule:function(e,t){var r=e.name;/^(-[a-z\d]+-)?keyframes$/.test(r)&&e.block.rules.forEach(function(e){e.selector.selectors.forEach(function(e){e.info.compareMarker=e.info.s})})},SimpleSelector:function(e){for(var t,r=e.info,n=e.sequence,a="*",u=n.length-1;u>=0&&"Combinator"!==n[u].type;u--)t=n[u];"Identifier"===t.type&&(a=t.name),r.compareMarker=i(e)+","+a,r.s=o(e)},AtruleExpression:n,Declaration:n,Property:n,Value:n};t.exports=function(e,t){return u[e.type]?u[e.type].call(this,e,t):void 0}},{"../../ast/translate.js":3,"./freeze.js":27,"./specificity.js":29}],29:[function(e,t,r){var n=2,o=1,i=0;t.exports=function a(e){var a=[0,0,0];return e.sequence.forEach(function t(e){switch(e.type){case"SimpleSelector":case"Negation":e.sequence.forEach(t);break;case"Id":a[i]++;break;case"Class":case"Attribute":case"FunctionalPseudo":a[o]++;break;case"Identifier":"*"!==e.name&&a[n]++;break;case"PseudoElement":a[n]++;break;case"PseudoClass":var r=e.name.toLowerCase();"before"===r||"after"===r||"first-line"===r||"first-letter"===r?a[n]++:a[o]++}}),a}},{}],30:[function(e,t,r){function n(e){var t=e.declaration.info;if(t.removeByShort||t.replaceByShort){var r=e.info;if(r.isOkToMinimize())if(t.replaceByShort){var n={type:"Declaration",info:{},property:r.getProperty(),value:r.getValue()};n.info.s=o(n),e.block.splice(e.pos,1,n)}else e.block.splice(e.pos,1)}}var o=e("../ast/translate");t.exports=function(e){e.forEach(n)}},{"../ast/translate":3}],31:[function(e,t,r){function n(e){return"Atrule"===e.type&&"media"===e.name}t.exports=function(e,t,r,o){if(n(e)){var i=o?r[o-1]:null;if(i&&n(i))return e.expression.info.s===i.expression.info.s?(Array.prototype.push.apply(i.block.rules,e.block.rules),null):void 0}}},{}],32:[function(e,t,r){var n=e("./utils.js");t.exports=function(e,t,r,o){var i=e.selector.selectors,a=e.block.declarations;if(!a.length)return null;var u=i[0].info.compareMarker,s={};for(o+=1;o<r.length;o++){var c=r[o];if("Ruleset"!==c.type)return;if(e.info.pseudoSignature!==c.info.pseudoSignature)return;var l=c.selector.selectors[0],f=c.block.declarations,p=l.info.compareMarker;if(p in s)return;if(1!==i.length||i[0].info.s!==l.info.s){if(!n.isCompatibleSignatures(e,c))return;if(a.length===f.length){for(var h=!0,d=0;d<a.length;d++)if(a[d].info.s!==f[d].info.s){h=!1;break}if(h){for(var y=l.info.s,d=i.length;d>=0;d--)if(!d||y>i[d-1].info.s){i.splice(d,0,l);break}r.splice(o,1),o--;continue}}if(p===u)return;s[p]=!0}else a.push.apply(a,f),r.splice(o,1),o--}}},{"./utils.js":35}],33:[function(e,t,r){function n(e){var t;switch(e.type){case"Identifier":case"Function":t=o(e.name)}return t||""}function o(e){if("-"===e[0]){if(e in c)return c[e];var t=e.indexOf("-",2);if(-1!==t)return c[e]=e.substr(0,t+1)}return""}function i(e){if(e in l)return l[e];var t=e[0];"*"===t||"_"===t||"$"===t?e=e.substr(1):"/"===t&&"/"===e[1]?(t="//",e=e.substr(2)):t="";var r=o(e);return l[e]={prefix:t+r,hack:t,vendor:r,table:d[e.substr(r.length)]}}function a(e,t,r,o){var i=o?"freeze:":"";if(-1!==e.indexOf("background")||-1!==e.indexOf("filter")&&"Progid"===t[0].type)return i+r.info.s;for(var a="",u=0,s={},c={},l=0;l<t.length;l++)switch(a||(a=n(t[l])),t[l].type){case"Identifier":var f=t[l].name;"\\9"===f&&(u=1),p.test(e)&&h.test(f)&&(c[f]=!0);break;case"Function":var f=t[l].name;"rect"===f&&t[l].arguments.length<4&&(f="rect-backward"),s[f]=!0;break;case"Dimension":var d=t[l].unit;switch(d){case"rem":case"vw":case"vh":case"vmin":case"vmax":case"vm":c[d]=!0}}return i+e+"["+Object.keys(s)+"]"+Object.keys(c)+u+a}function u(e,t,r,n,o,u){var s=i(e),c=s.table;if(c)for(var l=0;l<c.length;l++){var f=a(s.prefix+c[l],n,o,u),p=t[f];if(p)return!r||p.important}}var s=e("./utils.js"),c={},l={},f={src:1},p=/display$/,h=/table|ruby|flex|-(flex)?box$|grid|contents|run-in/,d={"border-width":["border"],"border-style":["border"],"border-color":["border"],"border-top":["border"],"border-right":["border"],"border-bottom":["border"],"border-left":["border"],"border-top-width":["border-top","border-width","border"],"border-right-width":["border-right","border-width","border"],"border-bottom-width":["border-bottom","border-width","border"],"border-left-width":["border-left","border-width","border"],"border-top-style":["border-top","border-style","border"],"border-right-style":["border-right","border-style","border"],"border-bottom-style":["border-bottom","border-style","border"],"border-left-style":["border-left","border-style","border"],"border-top-color":["border-top","border-color","border"],"border-right-color":["border-right","border-color","border"],"border-bottom-color":["border-bottom","border-color","border"],"border-left-color":["border-left","border-color","border"],"margin-top":["margin"],"margin-right":["margin"],"margin-bottom":["margin"],"margin-left":["margin"],"padding-top":["padding"],"padding-right":["padding"],"padding-bottom":["padding"],"padding-left":["padding"],"font-style":["font"],"font-variant":["font"],"font-weight":["font"],"font-size":["font"],"font-family":["font"],"list-style-type":["list-style"],"list-style-position":["list-style"],"list-style-image":["list-style"]};t.exports=function(e,t){for(var r=e.info,n=e.selector.selectors[0].info,o=e.block.declarations,i=r.freeze,c=r.freezeID,l=r.pseudoID,p=n.pseudo,h=n.sg,d=t.info.selectorsMap[n.s].props,y=o.length-1;y>=0;y--){var m=o[y];if("Declaration"===m.type){var g=m.value.sequence,v="Important"===g[g.length-1].type,b=m.property.info.s,k=a(b,g,m,i),S=d[k];!f[b]&&S?(p&&c===S.freezeID||!p&&l===S.pseudoID||p&&l===S.pseudoID&&s.hashInHash(h,S.sg))&&(v&&!S.important?(d[k]={block:o,child:m,important:v,sg:h,freezeID:c,pseudoID:l},S.block.splice(S.block.indexOf(S.child),1)):o.splice(y,1)):u(b,d,v,g,m,i)?o.splice(y,1):(m.info.fingerprint=k,d[k]={block:o,child:m,important:v,sg:h,freezeID:c,pseudoID:l})}}return o.length?void 0:null}},{"./utils.js":35}],34:[function(e,t,r){function n(e){for(var t=0,r=0;r<e.length;r++)t+=e[r].info.s.length;return t}var o=e("./utils.js");t.exports=function(e,t,r,i){var a=e.selector.selectors,u=e.block;for(i-=1;i>=0;i--){var s=r[i];if("Ruleset"!==s.type)return;var c=s.selector.selectors,l=s.block;if(e.info.pseudoSignature!==s.info.pseudoSignature)return;var f=o.getHash(c),p=o.getHash(a);if(o.equalHash(p,f))return l.declarations.push.apply(l.declarations,u.declarations),null;var h=o.compareRulesets(e,s);if(h.eq.length)if(h.ne1.length||h.ne2.length)if(h.ne1.length&&!h.ne2.length){var d=a.length-2,y=n(a)+d-1,m=n(h.eq)+h.eq.length-1;m>y&&(o.addToSelector(c,a),e.block={type:"Block",info:u.info,declarations:h.ne1})}else if(!h.ne1.length&&h.ne2.length){var d=c.length-2,y=n(c)+d-1,m=n(h.eq)+h.eq.length-1;m>y&&(o.addToSelector(a,c),s.block={type:"Block",info:l.info,declarations:h.ne2})}else{var g={type:"Selector",info:{},selectors:o.addToSelector(c.slice(),a)},v=n(g.selectors)+g.selectors.length-1+2,m=n(h.eq)+h.eq.length-1;if(m>=v){var b={type:"Ruleset",info:{},selector:g,block:{type:"Block",info:{},declarations:h.eq}};return e.block={type:"Block",info:u.info,declarations:h.ne1},s.block={type:"Block",info:l.info,declarations:h.ne2.concat(h.ne2overrided)},void r.splice(i,0,b)}}else if(o.isCompatibleSignatures(e,s))return o.addToSelector(c,a),null;for(var k=0;k<c.length;k++)for(var S=0;S<a.length;S++)if(c[k].info.compareMarker===a[S].info.compareMarker)return}}},{"./utils.js":35}],35:[function(e,t,r){function n(e){var t={};for(var r in e)t[r]=e[r];return t}function o(e,t){for(var r in e)if(r in t==!1)return!1;for(var r in t)if(r in e==!1)return!1;return!0}function i(e){for(var t={},r=0;r<e.length;r++)t[e[r].info.s]=!0;return t}function a(e,t){for(var r in e)if(r in t==!1)return!1;return!0}function u(e,t){for(var r={eq:[],ne1:[],ne2:[],ne2overrided:[]},n=e.block.declarations,o=t.block.declarations,a=i(n),u=i(o),s={},c=0;c<n.length;c++)n[c].info.fingerprint&&(s[n[c].info.fingerprint]=!0);for(var c=0;c<n.length;c++){var l=n[c];l.info.s in u?r.eq.push(l):r.ne1.push(l)}for(var c=0;c<o.length;c++){var l=o[c];l.info.s in a==!1&&(l.info.fingerprint in s==!1?r.ne2.push(l):r.ne2overrided.push(l))}return r}function s(e,t){e:for(var r=0;r<t.length;r++){for(var n=t[r].info.s,o=e.length;o>0;o--){var i=e[o-1].info.s;if(i===n)continue e;if(n>i)break}e.splice(o,0,t[r])}return e}function c(e,t){var r=e.info,n=t.info;if(r.freezeID===n.freezeID)return!0;if(r.pseudoID===n.pseudoID)return!0;if(r.freeze&&n.freeze){var o=r.pseudoSignature,i=n.pseudoSignature;return o===i}return!r.freeze&&!n.freeze}t.exports={copyObject:n,equalHash:o,getHash:i,hashInHash:a,isCompatibleSignatures:c,compareRulesets:u,addToSelector:s}},{}],36:[function(e,t,r){var n=e("./parser"),o=e("./compressor"),i=e("./compressor/ast/translate"),a=e("./utils/walker"),u=e("./utils/translate"),s=e("./utils/stringify"),c=e("./utils/cleanInfo"),l=function(e,t,r){console.warn("`csso.justDoIt()` method is deprecated, use `csso.minify()` instead");var a=n(e,"stylesheet",r),u=o(a,{restructuring:!t,outputAst:"internal"});return i(u)},f=function(e,t){var r={outputAst:"internal"};if(t)for(var a in t)r[a]=t[a];var u=Date.now(),s=n(e,"stylesheet",!0);r.debug&&console.error("## parsing done in %d ms\n",Date.now()-u);var u=Date.now(),c=o(s,r);return r.debug&&console.error("## compressing done in %d ms\n",Date.now()-u),i(c)};t.exports={version:e("../package.json").version,minify:f,parse:n,compress:o,translate:u,walk:a,stringify:s,cleanInfo:c,justDoIt:l}},{"../package.json":44,"./compressor":22,"./compressor/ast/translate":3,"./parser":38,"./utils/cleanInfo":40,"./utils/stringify":41,"./utils/translate":42,"./utils/walker":43}],37:[function(e,t,r){t.exports={StringSQ:"StringSQ",StringDQ:"StringDQ",CommentML:"CommentML",CommentSL:"CommentSL",Newline:"Newline",Space:"Space",Tab:"Tab",ExclamationMark:"ExclamationMark",QuotationMark:"QuotationMark",NumberSign:"NumberSign",DollarSign:"DollarSign",PercentSign:"PercentSign",Ampersand:"Ampersand",Apostrophe:"Apostrophe",LeftParenthesis:"LeftParenthesis",RightParenthesis:"RightParenthesis",Asterisk:"Asterisk",PlusSign:"PlusSign",Comma:"Comma",HyphenMinus:"HyphenMinus",FullStop:"FullStop",Solidus:"Solidus",Colon:"Colon",Semicolon:"Semicolon",LessThanSign:"LessThanSign",EqualsSign:"EqualsSign",GreaterThanSign:"GreaterThanSign",QuestionMark:"QuestionMark",CommercialAt:"CommercialAt",LeftSquareBracket:"LeftSquareBracket",ReverseSolidus:"ReverseSolidus",RightSquareBracket:"RightSquareBracket",CircumflexAccent:"CircumflexAccent",LowLine:"LowLine",LeftCurlyBracket:"LeftCurlyBracket",VerticalLine:"VerticalLine",RightCurlyBracket:"RightCurlyBracket",Tilde:"Tilde",Identifier:"Identifier",DecimalNumber:"DecimalNumber"}},{}],38:[function(e,t,r){function n(e){e&&e.line>Ot&&(Ot=e.line)}function o(){throw new Error("Please check the validity of the CSS block starting from the line #"+Ht)}function i(e){var t=Et[e];return{offset:t.offset,line:t.line,column:t.column}}function a(e){var t;return t=Mt?[i(Ft),e]:[e]}function u(e){return V(e)||lt(e)||ze(e)||ne(e)||_e(e)||Tt(e)||fe(e)||he(e)||ve(e)||vt(e)}function s(){return V(Ft)?U():lt(Ft)?ft():ze(Ft)?Ee():ne(Ft)?oe():_e(Ft)?Re():Tt(Ft)?wt():fe(Ft)?pe():he(Ft)?de():ve(Ft)?ke():vt(Ft)?bt():void 0}function c(e){var t;return Et[e++].type!==Vt.CommercialAt?n(Et[e-1]):(t=ve(e))?t+1:n(Et[e])}function l(){var e=Ft;return Ft++,Mt?[i(e),Qt.AtkeywordType,ke()]:[Qt.AtkeywordType,ke()]}function f(e){return Et[e].type!==Vt.LeftSquareBracket?n(Et[e]):Et[e].right?Et[e].right-e+1:n(Et[e])}function p(e){var t=e;e++;var r=et(e);if(r&&(e+=r),!(r=ve(e,!0)))return n(Et[e]);if(e+=r,Et[e].type===Vt.VerticalLine&&Et[e+1].type!==Vt.EqualsSign){if(e++,!(r=ve(e,!0)))return n(Et[e]);e+=r}return(r=et(e))&&(e+=r),(r=g(e))?(e+=r,(r=et(e))&&(e+=r),(r=ve(e))||(r=lt(e))?(e+=r,(r=et(e))&&(e+=r),Et[e].type===Vt.RightSquareBracket?e-t:n(Et[e])):n(Et[e])):n(Et[e])}function h(){var e=Ft;Ft++;var t=Mt?[i(e),Qt.AttribType]:[Qt.AttribType];return t=t.concat(tt(),[ke()]),Et[Ft].type===Vt.VerticalLine&&Et[Ft+1].type!==Vt.EqualsSign&&t.push(Ae(),ke()),t=t.concat(tt(),[v()],tt(),[lt(Ft)?ft():ke()],tt()),Ft++,t}function d(e){var t=e;e++;var r=et(e);if(r&&(e+=r),(r=ve(e,!0))&&(e+=r),Et[e].type===Vt.VerticalLine&&Et[e+1].type!==Vt.EqualsSign){if(e++,!(r=ve(e,!0)))return n(Et[e]);e+=r}return(r=et(e))&&(e+=r),Et[e].type===Vt.RightSquareBracket?e-t:n(Et[e])}function y(){var e=Ft;Ft++;var t=(Mt?[i(e),Qt.AttribType]:[Qt.AttribType]).concat(tt(),[ke()]);return Et[Ft].type===Vt.VerticalLine&&Et[Ft+1].type!==Vt.EqualsSign&&t.push(Ae(),ke()),t=t.concat(tt()),Ft++,t}function m(){return p(Ft)?h():d(Ft)?y():void 0}function g(e){if(Et[e].type===Vt.EqualsSign)return 1;if(Et[e].type===Vt.VerticalLine&&(!Et[e+1]||Et[e+1].type!==Vt.EqualsSign))return 1;if(!Et[e+1]||Et[e+1].type!==Vt.EqualsSign)return n(Et[e]);switch(Et[e].type){case Vt.Tilde:case Vt.CircumflexAccent:case Vt.DollarSign:case Vt.Asterisk:case Vt.VerticalLine:return 2}return n(Et[e])}function v(){var e=Ft,t=Et[Ft++].value;return Et[Ft]&&Et[Ft].type===Vt.EqualsSign&&(t+=Et[Ft++].value),Mt?[i(e),Qt.AttrselectorType,t]:[Qt.AttrselectorType,t]}function b(e){var t,r=e;if(void 0!==Et[r].atrule_l)return Et[r].atrule_l;if(t=w(e))Et[e].atrule_type=1;else if(t=S(e))Et[e].atrule_type=2;else{if(!(t=I(e)))return n(Et[r]);Et[e].atrule_type=3}return Et[r].atrule_l=t,t}function k(){switch(Et[Ft].atrule_type){case 1:return A();case 2:return T();case 3:return D()}}function S(e){var t,r=e;return(t=c(e))?(e+=t,(t=mt(e))&&(e+=t),(t=C(e))?(e+=t,e-r):n(Et[e])):n(Et[e])}function T(){return(Mt?[i(Ft),Qt.AtrulebType,l()]:[Qt.AtrulebType,l()]).concat(gt()).concat([N()])}function w(e){var t,r=e;return(t=c(e))?(e+=t,(t=j(e))&&(e+=t),e<Et.length&&Et[e].type===Vt.LeftCurlyBracket?(e++,(t=q(e))&&(e+=t),e<Et.length&&Et[e].type===Vt.RightCurlyBracket?(e++,e-r):n(Et[e])):n(Et[e])):n(Et[e])}function A(){var e=Mt?[i(Ft),Qt.AtrulerType,l(),x()]:[Qt.AtrulerType,l(),x()];return Ft++,e.push(P()),Ft++,e}function j(e){return mt(e)}function x(){return a(Qt.AtrulerqType).concat(gt())}function q(e){var t,r=e;for((t=et(e))&&(e+=t);(t=Ye(e))||(t=b(e))||(t=et(e));)e+=t;return Et[e].atrulers_end=1,(t=et(e))&&(e+=t),e-r}function P(){for(var e=a(Qt.AtrulersType).concat(tt());!Et[Ft].atrulers_end;)et(Ft)?e=e.concat(tt()):Ye(Ft)?e.push(Je()):e.push(k());return e.concat(tt())}function I(e){var t,r=e;return(t=c(e))?(e+=t,(t=mt(e))&&(e+=t),e>=Et.length?e-r:Et[e].type!==Vt.Semicolon?n(Et[e]):(e++,e-r)):n(Et[e])}function D(){var e=(Mt?[i(Ft),Qt.AtrulesType,l()]:[Qt.AtrulesType,l()]).concat(gt());return Ft++,e}function C(e){return e<Et.length&&Et[e].type===Vt.LeftCurlyBracket?Et[e].right-e+1:n(Et[e])}function N(){var e=a(Qt.BlockType),t=Et[Ft].right;for(Ft++;t>Ft;)_(Ft)?e=e.concat(R()):o();return Ft=t+1,e}function _(e){var t;if(t=B(e))Et[e].bd_type=1;else if(t=z(e))Et[e].bd_type=2;else if(t=M(e))Et[e].bd_type=3;else{if(!(t=O(e)))return n(Et[e]);Et[e].bd_type=4}return t}function R(){switch(Et[Ft].bd_type){case 1:return L();case 2:return E();case 3:return F();case 4:return H()}}function B(e){var t,r=e;if((t=et(e))&&(e+=t),t=ie(e))Et[e].bd_filter=1,e+=t;else{if(!(t=J(e)))return n(Et[e]);Et[e].bd_decl=1,e+=t}return e<Et.length&&(t=Z(e))?(e+=t,(t=et(e))&&(e+=t),e-r):n(Et[e])}function L(){return tt().concat([Et[Ft].bd_filter?ae():W()]).concat([ee()]).concat(tt())}function z(e){var t,r=e;if((t=et(e))&&(e+=t),t=ie(e))Et[e].bd_filter=1,e+=t;else{if(!(t=J(e)))return n(Et[e]);Et[e].bd_decl=1,e+=t}return(t=et(e))&&(e+=t),e-r}function E(){return tt().concat([Et[Ft].bd_filter?ae():W()]).concat(tt())}function M(e){var t,r=e;return(t=et(e))&&(e+=t),(t=Z(e))?(e+=t,(t=et(e))&&(e+=t),e-r):n(Et[e])}function F(){return tt().concat([ee()]).concat(tt())}function O(e){return et(e)}function H(){return tt()}function V(e){return e>=Et.length||Et[e].type!==Vt.LeftParenthesis&&Et[e].type!==Vt.LeftSquareBracket?n(Et[e]):Et[e].right-e+1}function U(){var e=Ft,t=Ft,r=Et[Ft].right;Ft++;var n=gt();return Ft++,Mt?[i(e),Qt.BracesType,Et[t].value,Et[r].value].concat(n):[Qt.BracesType,Et[t].value,Et[r].value].concat(n)}function Q(e){var t,r=Et[e];return r.clazz_l?r.clazz_l:r.type===Vt.FullStop&&("DecimalNumber"!==Et[e+1].type||/\D/.test(Et[e+1].value)||e++,t=ve(e+1))?(r.clazz_l=t+1,t+1):n(r)}function $(){var e=Ft,t=Ft+Et[Ft].clazz_l;Ft++;var r=a(Qt.IdentType).concat(Lt(Ft,t-1));return Ft=t,Mt?[i(e),Qt.ClazzType,r]:[Qt.ClazzType,r]}function G(e){return Et[e].type===Vt.PlusSign||Et[e].type===Vt.GreaterThanSign||Et[e].type===Vt.Tilde?1:Et[e+0].type===Vt.Solidus&&Et[e+1].type===Vt.Identifier&&"deep"===Et[e+1].value&&Et[e+2].type===Vt.Solidus?3:n(Et[e])}function K(){var e=Et[Ft].value;return Et[Ft].type===Vt.Solidus?(e="/deep/",Ft+=3):Ft+=1,Mt?[i(Ft),Qt.CombinatorType,e]:[Qt.CombinatorType,e]}function X(e){return Et[e].type===Vt.CommentML?1:n(Et[e])}function Y(){var e=Ft,t=Et[Ft].value.substring(2),r=t.length;return"*"===t.charAt(r-2)&&"/"===t.charAt(r-1)&&(t=t.substring(0,r-2)),Ft++,Mt?[i(e),Qt.CommentType,t]:[Qt.CommentType,t]}function J(e){var t,r=e;return(t=He(e))?(e+=t,e<Et.length&&Et[e].type===Vt.Colon?(e++,(t=jt(e))?(e+=t,e-r):n(Et[e])):n(Et[e])):n(Et[e])}function W(){var e=Mt?[i(Ft),Qt.DeclarationType,Ve()]:[Qt.DeclarationType,Ve()];return Ft++,e.push(qt()),e}function Z(e){return e<Et.length&&Et[e].type===Vt.Semicolon?1:n(Et[e])}function ee(){var e=Ft;return Ft++,Mt?[i(e),Qt.DecldelimType]:[Qt.DecldelimType]}function te(e){return e<Et.length&&Et[e].type===Vt.Comma?1:n(e>=Et.length?Et[Et.length-1]:Et[e])}function re(){var e=Ft;return Ft++,Mt?[i(e),Qt.DelimType]:[Qt.DelimType]}function ne(e){var t,r=_e(e);return!r||r&&e+r>=Et.length?n(Et[e]):(t=_t(e+r))?r+t:n(Et[e])}function oe(){var e=Ft,t=Re(),r=Mt?[i(Ft),Qt.IdentType,Rt()]:[Qt.IdentType,Rt()];return Mt?[i(e),Qt.DimensionType,t,r]:[Qt.DimensionType,t,r]}function ie(e){var t,r=e;return(t=ue(e))?(e+=t,Et[e].type!==Vt.Colon?n(Et[e]):(e++,(t=ce(e))?(e+=t,e-r):n(Et[e]))):n(Et[e])}function ae(){var e=Mt?[i(Ft),Qt.FilterType,se()]:[Qt.FilterType,se()];return Ft++,e.push(le()),e}function ue(e){var t,r,o=e;if(e<Et.length){if("filter"===Et[e].value)t=1;else if(r=zt(e,2),"-filter"===r||"_filter"===r||"*filter"===r)t=2;else{if(r=zt(e,4),"-ms-filter"!==r)return n(Et[e]);t=4}return Et[o].filterp_l=t,e+=t,et(e)&&(e+=t),e-o}return n(Et[e])}function se(){var e=Ft,t=zt(Ft,Et[Ft].filterp_l),r=Mt?[i(e),Qt.IdentType,t]:[Qt.IdentType,t];return Ft+=Et[Ft].filterp_l,(Mt?[i(e),Qt.PropertyType,r]:[Qt.PropertyType,r]).concat(tt())}function ce(e){var t,r=e;if(!(t=Me(e)))return n(Et[e]);for(e+=t;t=Me(e);)e+=t;return Et[r].last_progid=e,e<Et.length&&(t=et(e))&&(e+=t),e<Et.length&&(t=Se(e))&&(e+=t),e-r}function le(){for(var e=a(Qt.FiltervType),t=Et[Ft].last_progid;t>Ft;)e.push(Fe());return e=e.concat(et(Ft)?tt():[]),Ft<Et.length&&Se(Ft)&&e.push(Te()),e}function fe(e){var t=e;return Et[e]&&"expression"===Et[e++].value?Et[e]&&Et[e].type===Vt.LeftParenthesis?Et[e].right-t+1:n(Et[e]):n(Et[e-1])}function pe(){var e=Ft;Ft++;var t=Lt(Ft+1,Et[Ft].right-1);return Ft=Et[Ft].right+1,Mt?[i(e),Qt.FunctionExpressionType,t]:[Qt.FunctionExpressionType,t]}function he(e){var t=e,r=ve(e);return r?(e+=r,e>=Et.length||Et[e].type!==Vt.LeftParenthesis?n(Et[e-1]):Et[e].right-t+1):n(Et[e])}function de(){var e=Ft,t=ke();Ft++;var r="not"!==t[Mt?2:1]?ye():me();return Mt?[i(e),Qt.FunktionType,t,r]:[Qt.FunktionType,t,r]}function ye(){for(var e,t=Ft,r=[];Et[Ft].type!==Vt.RightParenthesis;)dt(Ft)?(e=yt(),Mt&&"string"==typeof e[1]||"string"==typeof e[0]?r.push(e):r=r.concat(e)):Q(Ft)?r.push($()):o();return Ft++,(Mt?[i(t),Qt.FunctionBodyType]:[Qt.FunctionBodyType]).concat(r)}function me(){for(var e=Ft,t=[];Et[Ft].type!==Vt.RightParenthesis;)at(Ft)?t.push(st()):o();return Ft++,(Mt?[i(e),Qt.FunctionBodyType]:[Qt.FunctionBodyType]).concat(t)}function ge(e,t){for(var r="";e<Et.length&&(Et[e].type===Vt.DecimalNumber||Et[e].type===Vt.Identifier);e++)r+=Et[e].value;if(/^[0-9a-f]{1,6}$/i.test(r)){if(t)for(;r.length<6&&e<Et.length&&Et[e].type===Vt.QuestionMark;e++)r+=Et[e].value,t=!1;if(t&&Et[e]&&Et[e].type===Vt.HyphenMinus){var n=ge(e+1);if(n)return n}return e}}function ve(e,t){if(e>=Et.length)return n(Et[e]);var r=e,o=!1;if(Et[e].type===Vt.Identifier&&("U"===Et[e].value||"u"===Et[e].value)&&Et[e+1].type===Vt.PlusSign){var i=ge(e+2,!0);if(i)return Et[r].ident_last=i-1,i-r}if(Et[e].type===Vt.LowLine)return be(e,t);if(Et[e].type!==Vt.HyphenMinus&&Et[e].type!==Vt.Identifier&&Et[e].type!==Vt.DollarSign&&Et[e].type!==Vt.Asterisk)return n(Et[e]);for(e++,o=Et[e-1].type===Vt.Identifier;e<Et.length;e++)if(Et[e].type!==Vt.HyphenMinus&&Et[e].type!==Vt.LowLine){if(!(Et[e].type===Vt.Identifier||t&&Et[e].type===Vt.Colon||o&&Et[e].type===Vt.DecimalNumber))break;o=!0}return o||Et[r].type===Vt.Asterisk?(Et[r].ident_last=e-1,e-r):n(Et[e])}function be(e,t){var r=e;for(e++;e<Et.length&&(Et[e].type===Vt.HyphenMinus||Et[e].type===Vt.DecimalNumber||Et[e].type===Vt.LowLine||Et[e].type===Vt.Identifier||t&&Et[e].type===Vt.Colon);e++);return Et[r].ident_last=e-1,e-r}function ke(){var e=Ft,t=Lt(Ft,Et[Ft].ident_last);return Ft=Et[Ft].ident_last+1,Mt?[i(e),Qt.IdentType,t]:[Qt.IdentType,t]}function Se(e){var t,r=e;return Et[e++].type!==Vt.ExclamationMark?n(Et[e-1]):((t=et(e))&&(e+=t),"important"!==Et[e].value.toLowerCase()?n(Et[e]):e-r+1)}function Te(){var e=Ft;Ft++;var t=tt();return Ft++,(Mt?[i(e),Qt.ImportantType]:[Qt.ImportantType]).concat(t)}function we(e){return Et[e].type===Vt.VerticalLine?1:n(Et[e])}function Ae(){var e=Ft;return Ft++,Mt?[i(e),Qt.NamespaceType]:[Qt.NamespaceType]}function je(e){return xe(e)||Pe(e)}function xe(e){for(var t=e;e<Et.length&&(Et[e].type===Vt.DecimalNumber||"n"===Et[e].value);e++);return e!==t?(Et[t].nth_last=e-1,e-t):n(Et[e])}function qe(){var e=Ft;if(Et[Ft].nth_last){var t=Mt?[i(e),Qt.NthType,Lt(Ft,Et[Ft].nth_last)]:[Qt.NthType,Lt(Ft,Et[Ft].nth_last)];return Ft=Et[Ft].nth_last+1,t}return Mt?[i(e),Qt.NthType,Et[Ft++].value]:[Qt.NthType,Et[Ft++].value]}function Pe(e){return"even"===Et[e].value||"odd"===Et[e].value?1:n(Et[e])}function Ie(e){var t=e,r=0;if(Et[e++].type!==Vt.Colon)return n(Et[e-1]);if(r++,"nth"!==Et[e++].value||"-"!==Et[e++].value)return n(Et[e-1]);if(r+=2,"child"===Et[e].value)r+=1;else if("last-child"===Et[e].value+Et[e+1].value+Et[e+2].value)r+=3;else if("of-type"===Et[e].value+Et[e+1].value+Et[e+2].value)r+=3;else{if("last-of-type"!==Et[e].value+Et[e+1].value+Et[e+2].value+Et[e+3].value+Et[e+4].value)return n(Et[e]);r+=5}return Et[t+1].nthf_last=t+r-1,r}function De(){Ft++;var e=Lt(Ft,Et[Ft].nthf_last);return Ft=Et[Ft].nthf_last+1,e}function Ce(e){var t,r=e;if(!(t=Ie(e)))return n(Et[e]);if(e+=t,Et[e].type!==Vt.LeftParenthesis||!Et[e].right)return n(Et[e]);t++;for(var o=Et[e++].right;o>e;)if(t=et(e))e+=t;else if(t=vt(e))e+=t;else{if(!(t=je(e)))return n(Et[e]);e+=t}return o-r+1}function Ne(){var e=Mt?[i(Ft),Qt.IdentType,De()]:[Qt.IdentType,De()],t=Mt?[i(Ft),Qt.NthselectorType,e]:[Qt.NthselectorType,e];for(Ft++;Et[Ft].type!==Vt.RightParenthesis;)et(Ft)?t=t.concat(tt()):vt(Ft)?t.push(bt()):je(Ft)&&t.push(qe());return Ft++,t}function _e(e,t){if(e<Et.length&&Et[e].number_l)return Et[e].number_l;if(!t&&e<Et.length&&Et[e].type===Vt.HyphenMinus){var r=_e(e+1,!0);if(r)return Et[e].number_l=r+1,Et[e].number_l;n(Et[e])}return e<Et.length&&Et[e].type===Vt.DecimalNumber&&(!Et[e+1]||Et[e+1]&&Et[e+1].type!==Vt.FullStop)?(Et[e].number_l=1,Et[e].number_l):e<Et.length&&Et[e].type===Vt.DecimalNumber&&Et[e+1]&&Et[e+1].type===Vt.FullStop&&(!Et[e+2]||Et[e+2].type!==Vt.DecimalNumber)?(Et[e].number_l=2,Et[e].number_l):e<Et.length&&Et[e].type===Vt.FullStop&&Et[e+1].type===Vt.DecimalNumber?(Et[e].number_l=2,Et[e].number_l):e<Et.length&&Et[e].type===Vt.DecimalNumber&&Et[e+1]&&Et[e+1].type===Vt.FullStop&&Et[e+2]&&Et[e+2].type===Vt.DecimalNumber?(Et[e].number_l=3,Et[e].number_l):n(Et[e])}function Re(){for(var e="",t=Ft,r=Et[Ft].number_l,n=0;r>n;n++)e+=Et[Ft+n].value;return Ft+=r,Mt?[i(t),Qt.NumberType,e]:[Qt.NumberType,e]}function Be(e){return e<Et.length&&(Et[e].type===Vt.Solidus||Et[e].type===Vt.Comma||Et[e].type===Vt.Colon||Et[e].type===Vt.EqualsSign)?1:n(Et[e])}function Le(){return Mt?[i(Ft),Qt.OperatorType,Et[Ft++].value]:[Qt.OperatorType,Et[Ft++].value]}function ze(e){var t=_e(e);return!t||t&&e+t>=Et.length?n(Et[e]):Et[e+t].type===Vt.PercentSign?t+1:n(Et[e])}function Ee(){var e=Ft,t=Re();return Ft++,Mt?[i(e),Qt.PercentageType,t]:[Qt.PercentageType,t]}function Me(e){var t,r,o=e;return(t=et(e))&&(e+=t),e<Et.length-1&&"progid"===Et[e].value&&Et[e+1].type===Vt.Colon?(e+=2,(t=et(e))&&(e+=t),"DXImageTransform.Microsoft."!==(r=zt(e,4))?n(Et[e-1]):(e+=4,(t=ve(e))?(e+=t,(t=et(e))&&(e+=t),Et[e].type!==Vt.LeftParenthesis?n(Et[e]):(Et[o].progid_end=Et[e].right,e=Et[e].right+1,(t=et(e))&&(e+=t),e-o)):n(Et[e]))):n(Et[e])}function Fe(){var e=Ft,t=Et[Ft].progid_end;return(Mt?[i(e),Qt.ProgidType]:[Qt.ProgidType]).concat(tt()).concat([Oe(t)]).concat(tt())}function Oe(e){var t=Ft,r=Lt(Ft,e);return Ft=e+1,Mt?[i(t),Qt.RawType,r]:[Qt.RawType,r]}function He(e){var t,r=e;return(t=ve(e))?(e+=t,(t=et(e))&&(e+=t),e-r):n(Et[e])}function Ve(){var e=Ft;return(Mt?[i(e),Qt.PropertyType,ke()]:[Qt.PropertyType,ke()]).concat(tt())}function Ue(e){return $e(e)||Ke(e)}function Qe(){return $e(Ft)?Ge():Ke(Ft)?Xe():void 0}function $e(e){var t;return Et[e++].type!==Vt.Colon?n(Et[e-1]):Et[e++].type!==Vt.Colon?n(Et[e-1]):(t=ve(e))?t+2:n(Et[e])}function Ge(){var e=Ft;return Ft+=2,Mt?[i(e),Qt.PseudoeType,ke()]:[Qt.PseudoeType,ke()]}function Ke(e){var t;return Et[e++].type!==Vt.Colon?n(Et[e-1]):(t=he(e))||(t=ve(e))?t+1:n(Et[e])}function Xe(){var e=Ft;return Ft++,Mt?[i(e),Qt.PseudocType,he(Ft)?de():ke()]:[Qt.PseudocType,he(Ft)?de():ke()]}function Ye(e){var t,r=e;if(void 0!==Et[r].ruleset_l)return Et[r].ruleset_l;for(;t=rt(e);)e+=t;return(t=C(e))?(e+=t,Et[r].ruleset_l=e-r,e-r):n(Et[e])}function Je(){for(var e=a(Qt.RulesetType);!C(Ft);)e.push(nt());return e.push(N()),e}function We(e){return Et[e].type===Vt.Space?1:n(Et[e])}function Ze(){var e=Ft,t=Et[Ft].value;return Ft++,Mt?[i(e),Qt.SType,t]:[Qt.SType,t]}function et(e){for(var t,r=0;e<Et.length&&((t=We(e))||(t=X(e)));)e+=t,r+=t;return r?r:n(e>=Et.length?Et[Et.length-1]:Et[e])}function tt(){for(var e=[];Ft<Et.length;)if(We(Ft))e.push(Ze());else{if(!X(Ft))break;e.push(Y())}return e}function rt(e){var t,r=e;if(e<Et.length){for(;t=at(e)||te(e);)e+=t;return Et[r].selector_end=e-1,e-r}}function nt(){for(var e=a(Qt.SelectorType),t=Et[Ft].selector_end;t>=Ft;)e.push(te(Ft)?re():st());return e}function ot(e){if(Et[e].type!==Vt.NumberSign)return n(Et[e]);var t=Ct(e+1);return t?t+1:n(Et[e])}function it(){var e=Ft;return Ft++,Mt?[i(e),Qt.ShashType,Nt()]:[Qt.ShashType,Nt()]}function at(e){for(var t,r=e;e<Et.length&&(t=ut(e));)e+=t;return e-r?e-r:n(e>=Et.length?Et[Et.length-1]:Et[e])}function ut(e){return Ce(e)||G(e)||f(e)||Ue(e)||Q(e)||ot(e)||u(e)||et(e)||we(e)}function st(){for(var e,t=a(Qt.SimpleselectorType);Ft<Et.length&&ut(Ft);)e=ct(),e||o(),Mt&&"string"==typeof e[1]||"string"==typeof e[0]?t.push(e):t=t.concat(e);return t}function ct(){return Ce(Ft)?Ne():G(Ft)?K():f(Ft)?m():Ue(Ft)?Qe():Q(Ft)?$():ot(Ft)?it():u(Ft)?s():et(Ft)?tt():we(Ft)?Ae():void 0}function lt(e){return e<Et.length&&(Et[e].type===Vt.StringSQ||Et[e].type===Vt.StringDQ)?1:n(Et[e])}function ft(){var e=Ft;return Mt?[i(e),Qt.StringType,Et[Ft++].value]:[Qt.StringType,Et[Ft++].value]}function pt(e){for(var t,r=e;e<Et.length;)(t=et(e))?e+=t:(Ht=Et[e].line,(t=b(e))?e+=t:(t=Ye(e))?e+=t:(t=kt(e))?e+=t:o());return e-r}function ht(){for(var e=a(Qt.StylesheetType);Ft<Et.length;)et(Ft)?e=e.concat(tt()):(Ht=Et[Ft].line,Ye(Ft)?e.push(Je()):b(Ft)?e.push(k()):kt(Ft)?e.push(St()):o());return e}function dt(e){return It(e)||u(e)||et(e)||Be(e)}function yt(){return It(Ft)?Dt():u(Ft)?s():et(Ft)?tt():Be(Ft)?Le():void 0}function mt(e){for(var t,r=e;t=dt(e);)e+=t;return e-r}function gt(){for(var e,t=[];e=yt();)Mt&&"string"==typeof e[1]||"string"==typeof e[0]?t.push(e):t=t.concat(e);return t}function vt(e){return e<Et.length&&(Et[e].type===Vt.HyphenMinus||Et[e].type===Vt.PlusSign)?1:n(Et[e])}function bt(){var e=Ft;return Mt?[i(e),Qt.UnaryType,Et[Ft++].value]:[Qt.UnaryType,Et[Ft++].value]}function kt(e){return e<Et.length&&Et[e].type===Vt.CommentSL?1:n(Et[e])}function St(){var e=Ft;return Mt?[i(e),Qt.UnknownType,Et[Ft++].value]:[Qt.UnknownType,Et[Ft++].value]}function Tt(e){var t=e;return e<Et.length&&"url"!==Et[e++].value?n(Et[e-1]):Et[e]&&Et[e].type===Vt.LeftParenthesis?Et[e].right-t+1:n(Et[e])}function wt(){var e=Ft;if(Ft+=2,At(Ft)){var t=(Mt?[i(e),Qt.UriType]:[Qt.UriType]).concat(tt()).concat([ft()]).concat(tt());return Ft++,t}var t=(Mt?[i(e),Qt.UriType]:[Qt.UriType]).concat(tt()),r=Bt(Ft),n=Mt?[i(Ft),Qt.RawType,Lt(Ft,Ft+r)]:[Qt.RawType,Lt(Ft,Ft+r)];return t.push(n),Ft+=r+1,t=t.concat(tt()),Ft++,t}function At(e){var t=e,r=et(e);return r&&(e+=r),Et[e].type!==Vt.StringDQ&&Et[e].type!==Vt.StringSQ?n(Et[e]):(e++,(r=et(e))&&(e+=r),e-t)}function jt(e){for(var t,r=e;e<Et.length&&(t=xt(e));)e+=t;return e-r?e-r:n(Et[e])}function xt(e){return et(e)||It(e)||u(e)||C(e)||c(e)||Be(e)||Se(e)}function qt(){for(var e,t=a(Qt.ValueType);Ft<Et.length&&xt(Ft);)e=Pt(),Mt&&"string"==typeof e[1]||"string"==typeof e[0]?t.push(e):t=t.concat(e);return t}function Pt(){return et(Ft)?tt():It(Ft)?Dt():u(Ft)?s():C(Ft)?N():c(Ft)?l():Be(Ft)?Le():Se(Ft)?Te():void 0}function It(e){if(e>=Et.length||Et[e].type!==Vt.NumberSign)return n(Et[e]);var t=_t(e+1);return t?t+1:n(Et[e])}function Dt(){var e=Ft;return Ft++,Mt?[i(e),Qt.VhashType,Rt()]:[Qt.VhashType,Rt()]}function Ct(e){var t=e;if(Et[e].type!==Vt.HyphenMinus&&Et[e].type!==Vt.LowLine&&Et[e].type!==Vt.Identifier&&Et[e].type!==Vt.DecimalNumber)return n(Et[e]);for(e++;e<Et.length&&(Et[e].type===Vt.HyphenMinus||Et[e].type===Vt.LowLine||Et[e].type===Vt.Identifier||Et[e].type===Vt.DecimalNumber);e++);return Et[t].nm_name_last=e-1,e-t}function Nt(){var e=Lt(Ft,Et[Ft].nm_name_last);return Ft=Et[Ft].nm_name_last+1,e}function _t(e){return Et[e].type===Vt.Identifier?1:Et[e].type!==Vt.DecimalNumber?n(Et[e]):(e++,Et[e]&&Et[e].type===Vt.Identifier?2:1)}function Rt(){var e=Et[Ft].value;return Et[Ft++].type===Vt.DecimalNumber&&Ft<Et.length&&Et[Ft].type===Vt.Identifier&&(e+=Et[Ft++].value),e}function Bt(e){for(var t=e;e<Et.length;){var r=Et[e++].type;if(r===Vt.Space||r===Vt.LeftParenthesis||r===Vt.RightParenthesis)break}return e-t-2}function Lt(e,t){
|
17
|
+
for(var r="",n=e;t>=n;n++)r+=Et[n].value;return r}function zt(e,t){if(!(e+t-1>=Et.length)){for(var r="",n=0;t>n;n++)r+=Et[e+n].value;return r}}var Et,Mt,Ft,Ot,Ht,Vt=e("./const.js"),Ut=e("./tokenize.js"),Qt={IdentType:"ident",AtkeywordType:"atkeyword",StringType:"string",ShashType:"shash",VhashType:"vhash",NumberType:"number",PercentageType:"percentage",DimensionType:"dimension",DecldelimType:"decldelim",SType:"s",AttrselectorType:"attrselector",AttribType:"attrib",NthType:"nth",NthselectorType:"nthselector",NamespaceType:"namespace",ClazzType:"clazz",PseudoeType:"pseudoe",PseudocType:"pseudoc",DelimType:"delim",StylesheetType:"stylesheet",AtrulebType:"atruleb",AtrulesType:"atrules",AtrulerqType:"atrulerq",AtrulersType:"atrulers",AtrulerType:"atruler",BlockType:"block",RulesetType:"ruleset",CombinatorType:"combinator",SimpleselectorType:"simpleselector",SelectorType:"selector",DeclarationType:"declaration",PropertyType:"property",ImportantType:"important",UnaryType:"unary",OperatorType:"operator",BracesType:"braces",ValueType:"value",ProgidType:"progid",FiltervType:"filterv",FilterType:"filter",CommentType:"comment",UriType:"uri",RawType:"raw",FunctionBodyType:"functionBody",FunktionType:"funktion",FunctionExpressionType:"functionExpression",UnknownType:"unknown"},$t={ident:function(){return ve(Ft)?ke():void 0},atkeyword:function(){return c(Ft)?l():void 0},string:function(){return lt(Ft)?ft():void 0},shash:function(){return ot(Ft)?it():void 0},vhash:function(){return It(Ft)?Dt():void 0},number:function(){return _e(Ft)?Re():void 0},percentage:function(){return ze(Ft)?Ee():void 0},dimension:function(){return ne(Ft)?oe():void 0},decldelim:function(){return Z(Ft)?ee():void 0},s:function(){return We(Ft)?Ze():void 0},attrselector:function(){return g(Ft)?v():void 0},attrib:function(){return f(Ft)?m():void 0},nth:function(){return je(Ft)?qe():void 0},nthselector:function(){return Ce(Ft)?Ne():void 0},namespace:function(){return we(Ft)?Ae():void 0},clazz:function(){return Q(Ft)?$():void 0},pseudoe:function(){return $e(Ft)?Ge():void 0},pseudoc:function(){return Ke(Ft)?Xe():void 0},delim:function(){return te(Ft)?re():void 0},stylesheet:function(){return pt(Ft)?ht():void 0},atruleb:function(){return S(Ft)?T():void 0},atrules:function(){return I(Ft)?D():void 0},atrulerq:function(){return j(Ft)?x():void 0},atrulers:function(){return q(Ft)?P():void 0},atruler:function(){return w(Ft)?A():void 0},block:function(){return C(Ft)?N():void 0},ruleset:function(){return Ye(Ft)?Je():void 0},combinator:function(){return G(Ft)?K():void 0},simpleselector:function(){return at(Ft)?st():void 0},selector:function(){return rt(Ft)?nt():void 0},declaration:function(){return J(Ft)?W():void 0},property:function(){return He(Ft)?Ve():void 0},important:function(){return Se(Ft)?Te():void 0},unary:function(){return vt(Ft)?bt():void 0},operator:function(){return Be(Ft)?Le():void 0},braces:function(){return V(Ft)?U():void 0},value:function(){return jt(Ft)?qt():void 0},progid:function(){return Me(Ft)?Fe():void 0},filterv:function(){return ce(Ft)?le():void 0},filter:function(){return ie(Ft)?ae():void 0},comment:function(){return X(Ft)?Y():void 0},uri:function(){return Tt(Ft)?wt():void 0},funktion:function(){return he(Ft)?de():void 0},functionExpression:function(){return fe(Ft)?pe():void 0},unknown:function(){return kt(Ft)?St():void 0}};t.exports=function(e,t,r){Et=Ut(e),t=t||"stylesheet",Mt=r,Ft=0,Ot=0;var n=$t[t]();return n||"stylesheet"!==t?n:Mt?[{},t]:[t]}},{"./const.js":37,"./tokenize.js":39}],39:[function(e,t,r){function n(e){return-1!=="0123456789".indexOf(e)}function o(e){function t(e,t,n,o){r.push({type:e,value:o,offset:g,line:t,column:n}),g=p}if(!e)return[];var r=[],o=!1;p=65279===e.charCodeAt(0)?1:0;var g=p;d=1,h=-1;for(var v,b,k,S=0;p<e.length;p++)v=e.charAt(p),b=e.charAt(p+1),"/"===v&&"*"===b?t(y.CommentML,d,p-h,a(e)):o||"/"!==v||"/"!==b?'"'===v||"'"===v?t('"'===v?y.StringDQ:y.StringSQ,d,p-h,s(e,v)):" "===v||"\n"===v||"\r"===v||" "===v||"\f"===v?t(y.Space,d,p-h,i(e)):v in m?(t(m[v],d,p-h,v),")"===v&&(o=!1),"{"===v&&S++,"}"===v&&S--):n(v)?t(y.DecimalNumber,d,p-h,c(e)):(t(y.Identifier,d,p-h,k=l(e)),o=o||"url"===k):S>0?(t(y.Identifier,d,p-h,k=l(e)),o=o||"url"===k):t(y.CommentSL,d,p-h,u(e));return f(r),r}function i(e){for(var t=p;p<e.length;p++){var r=e.charAt(p);if("\n"===r||"\f"===r)d++,h=p;else if("\r"===r)d++,"\n"===e.charAt(p+1)&&p++,h=p;else if(" "!==r&&" "!==r)break}return p--,e.substring(t,p+1)}function a(e){var t=p;for(p+=2;p<e.length;p++){if("*"===e.charAt(p)&&"/"===e.charAt(p+1)){p++;break}"\n"===e.charAt(p)&&(d++,h=p)}return e.substring(t,p+1)}function u(e){var t=p;for(p+=2;p<e.length&&("\n"!==e.charAt(p)&&"\r"!==e.charAt(p));p++);return e.substring(t,p+1)}function s(e,t){var r=p,n="";for(p+=1;p<e.length;p++)if("\\"===e.charAt(p)){var o=e.charAt(p+1);"\n"===o||"\f"===o?(n+=e.substring(r,p),r=p+2,p++):"\r"===o?(n+=e.substring(r,p),"\n"===e.charAt(p+2)&&p++,r=p+2,p++):p++}else if(e.charAt(p)===t)break;return n+e.substring(r,p+1)}function c(e){for(var t=p;p<e.length&&n(e.charAt(p));p++);return p--,e.substring(t,p+1)}function l(e){for(var t=p;"/"===e.charAt(p);)p++;for(;p<e.length;p++){var r=e.charAt(p);if("\\"===r)p++;else if(r in m&&"_"!==r)break}return p--,e.substring(t,p+1)}function f(e){for(var t,r=[],n=[],o=[],i=0;i<e.length;i++)switch(t=e[i],t.type){case y.LeftParenthesis:r.push(i);break;case y.RightParenthesis:r.length&&(e[r.pop()].right=i);break;case y.LeftSquareBracket:n.push(i);break;case y.RightSquareBracket:n.length&&(e[n.pop()].right=i);break;case y.LeftCurlyBracket:o.push(i);break;case y.RightCurlyBracket:o.length&&(e[o.pop()].right=i)}}var p,h,d,y=e("./const.js"),m={" ":y.Space,"\n":y.Newline,"\r":y.Newline," ":y.Tab,"!":y.ExclamationMark,'"':y.QuotationMark,"#":y.NumberSign,$:y.DollarSign,"%":y.PercentSign,"&":y.Ampersand,"'":y.Apostrophe,"(":y.LeftParenthesis,")":y.RightParenthesis,"*":y.Asterisk,"+":y.PlusSign,",":y.Comma,"-":y.HyphenMinus,".":y.FullStop,"/":y.Solidus,":":y.Colon,";":y.Semicolon,"<":y.LessThanSign,"=":y.EqualsSign,">":y.GreaterThanSign,"?":y.QuestionMark,"@":y.CommercialAt,"[":y.LeftSquareBracket,"]":y.RightSquareBracket,"^":y.CircumflexAccent,_:y.LowLine,"{":y.LeftCurlyBracket,"|":y.VerticalLine,"}":y.RightCurlyBracket,"~":y.Tilde};t.exports=o},{"./const.js":37}],40:[function(e,t,r){t.exports=function n(e){for(var t,r=e.slice(1),o=1;t=r[o];o++)Array.isArray(t)&&(r[o]=n(t));return r}},{}],41:[function(e,t,r){function n(e){return new Array(e+1).join(" ")}function o(e){return e.replace(/\\/g,"\\\\").replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/"/g,'\\"')}t.exports=function i(e,t){if(t=t||0,"string"==typeof e)return'"'+o(e)+'"';if(e&&e.constructor===Object){var r=Object.keys(e).map(function(r){return n(t+1)+'"'+o(r)+'": '+i(e[r],t+1)}).join(",\n");return"{"+(r?"\n"+r+"\n"+n(t):"")+"}"}if(Array.isArray(e)){var a=!0,r=e.map(function(e,r){var o=r?" ":"";return!Array.isArray(e)||a&&e.some(Array.isArray)||(o="\n"+n(t+1),a=!1),o+i(e,t+1)}).join(",");return/\n/.test(r)&&(r="\n"+n(t+1)+r+"\n"+n(t)),"["+r+"]"}return String(e)}},{}],42:[function(e,t,r){function n(e){P.push(e[q+1])}function o(e){for(var t=q+1;t<e.length;t++)x(e[t])}function i(e,t){for(;t<e.length;t++)x(e[t])}function a(e){x(e[q+1]),P.push("%")}function u(e){P.push("/*",e[q+1],"*/")}function s(e){P.push("."),x(e[q+1])}function c(e){P.push("@"),x(e[q+1])}function l(e){P.push("#",e[q+1])}function f(e){P.push("#",e[q+1])}function p(e){P.push("["),o(e),P.push("]")}function h(e){P.push("!"),o(e),P.push("important")}function d(e){P.push(":"),n(e[q+1]),P.push("("),i(e,q+2),P.push(")")}function y(e){n(e[q+1]),P.push("("),o(e[q+2]),P.push(")")}function m(e){x(e[q+1]),P.push(":"),x(e[q+2])}function g(e){x(e[q+1]),P.push(":"),x(e[q+2])}function v(e){P.push("{"),o(e),P.push("}")}function b(e){P.push(e[q+1]),i(e,q+3),P.push(e[q+2])}function k(e){o(e),P.push(";")}function S(e){x(e[q+1]),x(e[q+2]),P.push("{"),x(e[q+3]),P.push("}")}function T(e){P.push("::"),x(e[q+1])}function w(e){P.push(":"),x(e[q+1])}function A(e){P.push("url("),o(e),P.push(")")}function j(e){P.push("expression(",e[q+1],")")}function x(e){I[e[q]](e)}var q,P,I={unary:n,nth:n,combinator:n,ident:n,number:n,s:n,string:n,attrselector:n,operator:n,raw:n,unknown:n,simpleselector:o,dimension:o,selector:o,property:o,value:o,filterv:o,progid:o,ruleset:o,atruleb:o,atrulerq:o,atrulers:o,stylesheet:o,percentage:a,comment:u,clazz:s,atkeyword:c,shash:l,vhash:f,attrib:p,important:h,nthselector:d,funktion:y,declaration:m,filter:g,block:v,braces:b,atrules:k,atruler:S,pseudoe:T,pseudoc:w,uri:A,functionExpression:j,cdo:function(){P.push("cdo")},cdc:function(){P.push("cdc")},decldelim:function(){P.push(";")},namespace:function(){P.push("|")},delim:function(){P.push(",")}};t.exports=function(e,t){return q=t?1:0,P=[],x(e),P.join("")}},{}],43:[function(e,t,r){function n(e,t,r){switch(i(e,t,r),r.push(e),e[o+0]){case"simpleselector":case"dimension":case"selector":case"property":case"value":case"filterv":case"progid":case"ruleset":case"atruleb":case"atrulerq":case"atrulers":case"stylesheet":case"attrib":case"important":case"block":case"atrules":case"uri":for(var a=o+1;a<e.length;a++)n(e[a],e,r);break;case"percentage":case"clazz":case"atkeyword":case"pseudoe":case"pseudoc":n(e[o+1],e,r);break;case"declaration":case"filter":n(e[o+1],e,r),n(e[o+2],e,r);break;case"atruler":n(e[o+1],e,r),n(e[o+2],e,r),n(e[o+3],e,r);break;case"braces":for(var a=o+3;a<e.length;a++)n(e[a],e,r);break;case"nthselector":i(e[o+1],e,r);for(var a=o+2;a<e.length;a++)n(e[a],e,r);break;case"funktion":i(e[o+1],e,r),i(e[o+2],e,r),e=e[o+2],r.push(e);for(var a=o+1;a<e.length;a++)n(e[a],e,r);r.pop()}r.pop()}var o,i;t.exports=function(e,t,r){o=r?1:0,"function"==typeof t&&(i=t,n(e,null,[]))}},{}],44:[function(e,t,r){t.exports={name:"csso",description:"CSSO — CSS optimizer",version:"1.5.3",homepage:"https://github.com/css/csso",author:"Sergey Kryzhanovsky <skryzhanovsky@ya.ru> (https://github.com/afelix)",maintainers:[{name:"Roman Dvornov",email:"rdvornov@gmail.com","github-username":"lahmatiy"}],license:"MIT",repository:"css/csso",bugs:{url:"https://github.com/css/csso/issues"},bin:{csso:"./bin/csso"},main:"./lib/index",scripts:{test:"jscs . && mocha --reporter dot",browserify:"browserify --standalone csso lib/index.js | uglifyjs --compress --mangle -o dist/csso-browser.js","gh-pages":'git clone -b gh-pages https://github.com/css/csso.git .gh-pages && npm run browserify && cp dist/csso-browser.js .gh-pages/ && cd .gh-pages && git commit -am "update" && git push && cd .. && rm -rf .gh-pages',prepublish:"npm run browserify"},dependencies:{clap:"^1.0.9"},devDependencies:{browserify:"^13.0.0",jscs:"^2.6.0",mocha:"~2.3.3","uglify-js":"^2.6.1"},engines:{node:">=0.12.0"},files:["bin","dist/csso-browser.js","lib","HISTORY.md","LICENSE","README.md"]}},{}]},{},[36])(36)});
|
3924
18
|
|
3925
19
|
do_compression = function(css, disable_structural){
|
3926
|
-
|
3927
|
-
|
3928
|
-
|
3929
|
-
compressor.compress(
|
3930
|
-
srcToCSSP(css, 'stylesheet', true),
|
3931
|
-
disable_structural
|
3932
|
-
)
|
3933
|
-
)
|
3934
|
-
);
|
20
|
+
return csso.minify(css, {
|
21
|
+
restructuring: !disable_structural
|
22
|
+
});
|
3935
23
|
};
|