p_css 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/css/cascade.rb +8 -4
- data/lib/css/code_points.rb +32 -9
- data/lib/css/selectors/matcher.rb +71 -28
- data/lib/css/token.rb +35 -6
- data/lib/css/tokenizer.rb +6 -25
- data/lib/css/version.rb +1 -1
- data/lib/css.rb +1 -1
- data/sig/css/cascade.rbs +1 -1
- data/sig/css/selectors.rbs +4 -1
- data/sig/css/token.rbs +1 -1
- data/sig/css.rbs +6 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 965047de25f5fe1719b2d2b4c59d2fa2d74550249e2ffa23d4175ae88dc09ba9
|
|
4
|
+
data.tar.gz: ab8078d7209427b3f23cd774492fae69543bd8910b812a1a87fc7da38b8df89c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '069d1c89de282155ee708b19aee7cc61226a68bd7ad662a869536b823bb99d58c6b8b1dae2567fa9f27d337fda392ea52f62592a718580aead69e1ded17cbf47'
|
|
7
|
+
data.tar.gz: 2d0ec3fd003f145859790f3140ec808e5ba1d1273dc2e78e379d7ef5eec3dd44c9c031cd8e5db22f5b1b63b27d52f9973cc18f19b0f184ebd6a882d73b24ac36
|
data/lib/css/cascade.rb
CHANGED
|
@@ -31,7 +31,11 @@ module CSS
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
# Returns Hash<String, Declaration> of winning declarations.
|
|
34
|
-
|
|
34
|
+
#
|
|
35
|
+
# `state:` opts into stateful-pseudo matching — see
|
|
36
|
+
# `Selectors::Matcher#matches?` for the shape. Defaults to the
|
|
37
|
+
# stateless behavior (`:hover`, `:focus`, etc. never match).
|
|
38
|
+
def resolve(element, inline_style: nil, state: nil)
|
|
35
39
|
cache = {}
|
|
36
40
|
candidates = collect_candidate_indexes(element, cache)
|
|
37
41
|
order = 0
|
|
@@ -39,7 +43,7 @@ module CSS
|
|
|
39
43
|
|
|
40
44
|
candidates.each do |idx|
|
|
41
45
|
entry = @entries[idx]
|
|
42
|
-
spec = best_matching_specificity(element, entry.selector_pairs, cache)
|
|
46
|
+
spec = best_matching_specificity(element, entry.selector_pairs, cache, state)
|
|
43
47
|
|
|
44
48
|
next if spec.nil?
|
|
45
49
|
|
|
@@ -204,11 +208,11 @@ module CSS
|
|
|
204
208
|
out
|
|
205
209
|
end
|
|
206
210
|
|
|
207
|
-
def best_matching_specificity(element, selector_pairs, cache)
|
|
211
|
+
def best_matching_specificity(element, selector_pairs, cache, state)
|
|
208
212
|
best = nil
|
|
209
213
|
|
|
210
214
|
selector_pairs.each do |sel, spec|
|
|
211
|
-
next unless Selectors::Matcher.matches?(element, sel, cache: cache)
|
|
215
|
+
next unless Selectors::Matcher.matches?(element, sel, cache: cache, state: state)
|
|
212
216
|
|
|
213
217
|
best = spec if best.nil? || spec > best
|
|
214
218
|
end
|
data/lib/css/code_points.rb
CHANGED
|
@@ -1,36 +1,59 @@
|
|
|
1
1
|
module CSS
|
|
2
2
|
# Character class predicates from CSS Syntax §4.2 Definitions, plus the
|
|
3
3
|
# U+FFFD replacement character used both during tokenization and
|
|
4
|
-
# serialization.
|
|
5
|
-
#
|
|
4
|
+
# serialization.
|
|
5
|
+
#
|
|
6
|
+
# ASCII bytes are looked up in a precomputed boolean table (one Array
|
|
7
|
+
# access + one branch); non-ASCII code points (>= 0x80) are always
|
|
8
|
+
# ident-cp / ident-start per spec, so the helpers fall back to a single
|
|
9
|
+
# `c.ord >= 0x80` check. Avoids the chain of `String#<=>` calls a
|
|
10
|
+
# range-style predicate would dispatch.
|
|
6
11
|
module CodePoints
|
|
7
12
|
REPLACEMENT = "�".freeze
|
|
8
13
|
|
|
14
|
+
def self.build_table(*ranges_or_ints)
|
|
15
|
+
Array.new(128, false).tap {|a|
|
|
16
|
+
ranges_or_ints.each {|r|
|
|
17
|
+
if r.is_a?(Range) then r.each { a[it] = true }
|
|
18
|
+
else a[r] = true
|
|
19
|
+
end
|
|
20
|
+
}
|
|
21
|
+
}.freeze
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
DIGIT_TABLE = build_table(0x30..0x39)
|
|
25
|
+
HEX_DIGIT_TABLE = build_table(0x30..0x39, 0x41..0x46, 0x61..0x66)
|
|
26
|
+
IDENT_START_TABLE = build_table(0x41..0x5A, 0x61..0x7A, 0x5F)
|
|
27
|
+
IDENT_CP_TABLE = build_table(0x30..0x39, 0x41..0x5A, 0x61..0x7A, 0x5F, 0x2D)
|
|
28
|
+
|
|
9
29
|
module_function
|
|
10
30
|
|
|
11
31
|
def digit?(c)
|
|
12
|
-
|
|
32
|
+
return false if c.nil?
|
|
33
|
+
|
|
34
|
+
o = c.ord
|
|
35
|
+
o < 128 && DIGIT_TABLE[o]
|
|
13
36
|
end
|
|
14
37
|
|
|
15
38
|
def hex_digit?(c)
|
|
16
39
|
return false if c.nil?
|
|
17
40
|
|
|
18
|
-
|
|
41
|
+
o = c.ord
|
|
42
|
+
o < 128 && HEX_DIGIT_TABLE[o]
|
|
19
43
|
end
|
|
20
44
|
|
|
21
45
|
def ident_start_code_point?(c)
|
|
22
46
|
return false if c.nil?
|
|
23
|
-
return true if c == '_' || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
|
|
24
47
|
|
|
25
|
-
c.ord
|
|
48
|
+
o = c.ord
|
|
49
|
+
o >= 128 || IDENT_START_TABLE[o]
|
|
26
50
|
end
|
|
27
51
|
|
|
28
52
|
def ident_code_point?(c)
|
|
29
53
|
return false if c.nil?
|
|
30
|
-
return true if c == '_' || c == '-' || (c >= '0' && c <= '9')
|
|
31
|
-
return true if (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
|
|
32
54
|
|
|
33
|
-
c.ord
|
|
55
|
+
o = c.ord
|
|
56
|
+
o >= 128 || IDENT_CP_TABLE[o]
|
|
34
57
|
end
|
|
35
58
|
end
|
|
36
59
|
end
|
|
@@ -16,8 +16,9 @@ module CSS
|
|
|
16
16
|
# protocol out of the box.
|
|
17
17
|
#
|
|
18
18
|
# Pseudo-classes that depend on user-agent state (`:hover`, `:focus`,
|
|
19
|
-
# `:visited`,
|
|
20
|
-
#
|
|
19
|
+
# `:visited`, etc.) return false by default; pass an explicit `state:`
|
|
20
|
+
# mapping to opt into stateful matching. Validity-API and viewport-
|
|
21
|
+
# only states (`:fullscreen`, `:valid`, …) are not exposed.
|
|
21
22
|
module Matcher
|
|
22
23
|
extend self
|
|
23
24
|
|
|
@@ -26,6 +27,16 @@ module CSS
|
|
|
26
27
|
LINK_TAGS = %w[a area link].freeze
|
|
27
28
|
RO_INPUT_TYPES = %w[hidden range color checkbox radio file submit image reset button].freeze
|
|
28
29
|
|
|
30
|
+
# User-agent state pseudos. The matcher returns `false` for these
|
|
31
|
+
# unless the caller passes a `state:` Hash describing which
|
|
32
|
+
# elements (or "all") should match.
|
|
33
|
+
STATEFUL_PSEUDOS = %w[hover focus focus-within focus-visible active visited target].to_set.freeze
|
|
34
|
+
|
|
35
|
+
# Per spec these states propagate up the ancestor chain — if a
|
|
36
|
+
# descendant is hovered/active/contains-focus, the ancestors
|
|
37
|
+
# share the state for selector-matching purposes.
|
|
38
|
+
PROPAGATING_STATEFUL_PSEUDOS = %w[hover active focus-within].to_set.freeze
|
|
39
|
+
|
|
29
40
|
# Per-element cache used to avoid recomputing tag / id / class set
|
|
30
41
|
# for every selector in a hot loop (e.g. `Cascade#resolve` against
|
|
31
42
|
# hundreds of rules). Keyed by `Object#object_id`; only valid for
|
|
@@ -34,16 +45,16 @@ module CSS
|
|
|
34
45
|
|
|
35
46
|
EMPTY_CLASS_SET = Set.new.freeze
|
|
36
47
|
|
|
37
|
-
def matches?(element, selector, cache: nil)
|
|
48
|
+
def matches?(element, selector, cache: nil, state: nil)
|
|
38
49
|
sel = selector.is_a?(String) ? Parser.parse_selector_list(selector) : selector
|
|
39
50
|
|
|
40
51
|
case sel
|
|
41
52
|
when SelectorList
|
|
42
|
-
sel.selectors.any? { match_complex(element, it, cache) }
|
|
53
|
+
sel.selectors.any? { match_complex(element, it, cache, state) }
|
|
43
54
|
when ComplexSelector
|
|
44
|
-
match_complex(element, sel, cache)
|
|
55
|
+
match_complex(element, sel, cache, state)
|
|
45
56
|
when CompoundSelector
|
|
46
|
-
match_compound(element, sel, cache)
|
|
57
|
+
match_compound(element, sel, cache, state)
|
|
47
58
|
else
|
|
48
59
|
raise ArgumentError, "expected a selector node or string, got #{sel.class}"
|
|
49
60
|
end
|
|
@@ -54,32 +65,32 @@ module CSS
|
|
|
54
65
|
# Walks the complex selector right-to-left starting at the rightmost
|
|
55
66
|
# compound. Each combinator either succeeds against ancestors /
|
|
56
67
|
# siblings of the current candidate or fails the whole match.
|
|
57
|
-
def match_complex(element, complex, cache)
|
|
58
|
-
match_at(element, complex, complex.compounds.size - 1, cache)
|
|
68
|
+
def match_complex(element, complex, cache, state)
|
|
69
|
+
match_at(element, complex, complex.compounds.size - 1, cache, state)
|
|
59
70
|
end
|
|
60
71
|
|
|
61
|
-
def match_at(element, complex, index, cache)
|
|
72
|
+
def match_at(element, complex, index, cache, state)
|
|
62
73
|
return false if element.nil?
|
|
63
|
-
return false unless match_compound(element, complex.compounds[index], cache)
|
|
74
|
+
return false unless match_compound(element, complex.compounds[index], cache, state)
|
|
64
75
|
return true if index.zero?
|
|
65
76
|
|
|
66
77
|
prev = index - 1
|
|
67
78
|
|
|
68
79
|
case complex.combinators[prev]
|
|
69
|
-
when :descendant then walk_until_match(element, complex, prev, :parent_element,
|
|
70
|
-
when :child then match_at(parent_element(element), complex, prev, cache)
|
|
71
|
-
when :next_sibling then match_at(previous_element(element), complex, prev, cache)
|
|
72
|
-
when :subsequent_sibling then walk_until_match(element, complex, prev, :previous_element, cache)
|
|
80
|
+
when :descendant then walk_until_match(element, complex, prev, :parent_element, cache, state)
|
|
81
|
+
when :child then match_at(parent_element(element), complex, prev, cache, state)
|
|
82
|
+
when :next_sibling then match_at(previous_element(element), complex, prev, cache, state)
|
|
83
|
+
when :subsequent_sibling then walk_until_match(element, complex, prev, :previous_element, cache, state)
|
|
73
84
|
end
|
|
74
85
|
end
|
|
75
86
|
|
|
76
87
|
# Steps along the DOM via `direction` until a candidate matches the
|
|
77
88
|
# remaining complex selector or the chain runs out.
|
|
78
|
-
def walk_until_match(element, complex, index, direction, cache)
|
|
89
|
+
def walk_until_match(element, complex, index, direction, cache, state)
|
|
79
90
|
candidate = send(direction, element)
|
|
80
91
|
|
|
81
92
|
while candidate
|
|
82
|
-
return true if match_at(candidate, complex, index, cache)
|
|
93
|
+
return true if match_at(candidate, complex, index, cache, state)
|
|
83
94
|
|
|
84
95
|
candidate = send(direction, candidate)
|
|
85
96
|
end
|
|
@@ -87,18 +98,18 @@ module CSS
|
|
|
87
98
|
false
|
|
88
99
|
end
|
|
89
100
|
|
|
90
|
-
def match_compound(element, compound, cache)
|
|
91
|
-
compound.components.all? { match_simple(element, it, cache) }
|
|
101
|
+
def match_compound(element, compound, cache, state)
|
|
102
|
+
compound.components.all? { match_simple(element, it, cache, state) }
|
|
92
103
|
end
|
|
93
104
|
|
|
94
|
-
def match_simple(element, simple, cache)
|
|
105
|
+
def match_simple(element, simple, cache, state)
|
|
95
106
|
case simple
|
|
96
107
|
when TypeSelector then tag_of(element, cache).casecmp?(simple.name)
|
|
97
108
|
when UniversalSelector then true
|
|
98
109
|
when IdSelector then id_of(element, cache) == simple.name
|
|
99
110
|
when ClassSelector then classes_of(element, cache).include?(simple.name)
|
|
100
111
|
when AttributeSelector then match_attribute(element, simple)
|
|
101
|
-
when PseudoClass then match_pseudo_class(element, simple, cache)
|
|
112
|
+
when PseudoClass then match_pseudo_class(element, simple, cache, state)
|
|
102
113
|
when PseudoElement then false
|
|
103
114
|
when NestingSelector then false
|
|
104
115
|
else false
|
|
@@ -172,10 +183,14 @@ module CSS
|
|
|
172
183
|
|
|
173
184
|
# Pseudo-class matching -------------------------------------------
|
|
174
185
|
|
|
175
|
-
def match_pseudo_class(element, pc, cache)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
186
|
+
def match_pseudo_class(element, pc, cache, state)
|
|
187
|
+
name = pc.name.downcase
|
|
188
|
+
|
|
189
|
+
return match_stateful_pseudo?(name, element, state) if STATEFUL_PSEUDOS.include?(name)
|
|
190
|
+
|
|
191
|
+
case name
|
|
192
|
+
when 'is', 'where', 'matches' then match_selector_list_arg(element, pc.argument, cache, state)
|
|
193
|
+
when 'not' then negate_selector_list_arg(element, pc.argument, cache, state)
|
|
179
194
|
when 'has' then false
|
|
180
195
|
when 'root' then parent_element(element).nil?
|
|
181
196
|
when 'scope' then parent_element(element).nil?
|
|
@@ -206,12 +221,40 @@ module CSS
|
|
|
206
221
|
end
|
|
207
222
|
end
|
|
208
223
|
|
|
209
|
-
|
|
210
|
-
|
|
224
|
+
# `:hover` / `:active` / `:focus-within` propagate up the ancestor
|
|
225
|
+
# chain per Selectors §10 — the Set members are the *source* nodes
|
|
226
|
+
# (e.g. the deepest hovered element) and any of their ancestors
|
|
227
|
+
# also matches. Other stateful pseudos match only the explicit
|
|
228
|
+
# elements in the Set.
|
|
229
|
+
def match_stateful_pseudo?(name, element, state)
|
|
230
|
+
return false if state.nil?
|
|
231
|
+
|
|
232
|
+
value = state[name.to_sym] || state[name]
|
|
233
|
+
|
|
234
|
+
return false if value.nil? || value == false
|
|
235
|
+
return true if value == true
|
|
236
|
+
|
|
237
|
+
return value.include?(element) unless PROPAGATING_STATEFUL_PSEUDOS.include?(name)
|
|
238
|
+
|
|
239
|
+
value.each do |source|
|
|
240
|
+
cur = source
|
|
241
|
+
|
|
242
|
+
while cur
|
|
243
|
+
return true if cur == element
|
|
244
|
+
|
|
245
|
+
cur = parent_element(cur)
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
false
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def match_selector_list_arg(element, arg, cache, state)
|
|
253
|
+
arg.is_a?(SelectorList) && matches?(element, arg, cache: cache, state: state)
|
|
211
254
|
end
|
|
212
255
|
|
|
213
|
-
def negate_selector_list_arg(element, arg, cache)
|
|
214
|
-
arg.is_a?(SelectorList) && !matches?(element, arg, cache: cache)
|
|
256
|
+
def negate_selector_list_arg(element, arg, cache, state)
|
|
257
|
+
arg.is_a?(SelectorList) && !matches?(element, arg, cache: cache, state: state)
|
|
215
258
|
end
|
|
216
259
|
|
|
217
260
|
def match_nth(element, anb, of_type:, from_end:)
|
data/lib/css/token.rb
CHANGED
|
@@ -17,7 +17,7 @@ module CSS
|
|
|
17
17
|
eof
|
|
18
18
|
].freeze
|
|
19
19
|
|
|
20
|
-
attr_reader :type, :value, :flag, :unit
|
|
20
|
+
attr_reader :type, :value, :flag, :unit
|
|
21
21
|
|
|
22
22
|
def initialize(type, value = nil, flag: nil, unit: nil, position: nil)
|
|
23
23
|
raise ArgumentError, "unknown token type: #{type.inspect}" unless TYPES.include?(type)
|
|
@@ -58,21 +58,50 @@ module CSS
|
|
|
58
58
|
type == :whitespace || type == :comment
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
#
|
|
62
|
-
#
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
# Most tokens never have their `position` read after parsing, so the
|
|
62
|
+
# tokenizer plants raw offsets + a shared `@newlines` reference here
|
|
63
|
+
# via this method, and `Token#position` materializes the `Position`
|
|
64
|
+
# Data on first read.
|
|
65
|
+
def assign_source!(start_offset, end_offset, newlines)
|
|
66
|
+
@start_offset = start_offset
|
|
67
|
+
@end_offset = end_offset
|
|
68
|
+
@newlines = newlines
|
|
65
69
|
self
|
|
66
70
|
end
|
|
67
71
|
|
|
72
|
+
# Returns nil for tokens built without source info (i.e. tokens
|
|
73
|
+
# constructed by hand or via `Token.new(:eof)`).
|
|
74
|
+
def position
|
|
75
|
+
return @position if @position
|
|
76
|
+
return nil unless instance_variable_defined?(:@start_offset)
|
|
77
|
+
|
|
78
|
+
@position = compute_position
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Reads `@position` directly so debug-style introspection doesn't
|
|
82
|
+
# materialize a `Position` as a side effect.
|
|
68
83
|
def inspect
|
|
69
84
|
parts = ["type=#{type.inspect}"]
|
|
70
85
|
parts << "value=#{value.inspect}" unless value.nil?
|
|
71
86
|
parts << "flag=#{flag.inspect}" unless flag.nil?
|
|
72
87
|
parts << "unit=#{unit.inspect}" unless unit.nil?
|
|
73
|
-
parts << "@#{position}"
|
|
88
|
+
parts << "@#{@position}" if @position
|
|
74
89
|
|
|
75
90
|
"#<CSS::Token #{parts.join(' ')}>"
|
|
76
91
|
end
|
|
92
|
+
|
|
93
|
+
private
|
|
94
|
+
|
|
95
|
+
def compute_position
|
|
96
|
+
idx = @newlines.bsearch_index { it >= @start_offset } || @newlines.size
|
|
97
|
+
prev_nl = idx.zero? ? -1 : @newlines[idx - 1]
|
|
98
|
+
|
|
99
|
+
Position.new(
|
|
100
|
+
line: idx + 1,
|
|
101
|
+
column: @start_offset - prev_nl,
|
|
102
|
+
offset: @start_offset,
|
|
103
|
+
end_offset: @end_offset
|
|
104
|
+
)
|
|
105
|
+
end
|
|
77
106
|
end
|
|
78
107
|
end
|
data/lib/css/tokenizer.rb
CHANGED
|
@@ -2,9 +2,8 @@ module CSS
|
|
|
2
2
|
# Tokenizer based on CSS Syntax Module Level 3/4 §4.
|
|
3
3
|
# https://www.w3.org/TR/css-syntax-3/#tokenization
|
|
4
4
|
#
|
|
5
|
-
# Not thread-safe: an instance carries mutable
|
|
6
|
-
#
|
|
7
|
-
# tokenizer per thread.
|
|
5
|
+
# Not thread-safe: an instance carries a mutable cursor (`@pos`) that
|
|
6
|
+
# advances over the input. Allocate one tokenizer per thread.
|
|
8
7
|
class Tokenizer
|
|
9
8
|
include CodePoints
|
|
10
9
|
|
|
@@ -26,9 +25,9 @@ module CSS
|
|
|
26
25
|
|
|
27
26
|
def initialize(input, preserve_comments: false)
|
|
28
27
|
@chars = preprocess(input)
|
|
28
|
+
@length = @chars.length
|
|
29
29
|
@pos = 0
|
|
30
30
|
@newlines = collect_newline_offsets(@chars)
|
|
31
|
-
@newline_cursor = 0
|
|
32
31
|
@preserve_comments = preserve_comments
|
|
33
32
|
end
|
|
34
33
|
|
|
@@ -48,13 +47,12 @@ module CSS
|
|
|
48
47
|
def next_token
|
|
49
48
|
consume_comments unless @preserve_comments
|
|
50
49
|
|
|
51
|
-
return Token.new(:eof) if @pos >= @
|
|
50
|
+
return Token.new(:eof) if @pos >= @length
|
|
52
51
|
|
|
53
52
|
start_offset = @pos
|
|
54
53
|
tok = consume_one_token
|
|
55
|
-
line, column = line_column_at(start_offset)
|
|
56
54
|
|
|
57
|
-
tok.
|
|
55
|
+
tok.assign_source!(start_offset, @pos, @newlines)
|
|
58
56
|
end
|
|
59
57
|
|
|
60
58
|
private
|
|
@@ -174,23 +172,6 @@ module CSS
|
|
|
174
172
|
offsets
|
|
175
173
|
end
|
|
176
174
|
|
|
177
|
-
# Newline characters themselves are reported as belonging to the
|
|
178
|
-
# line they terminate (col = offset + 1 on line 1, etc).
|
|
179
|
-
#
|
|
180
|
-
# Tokens are emitted in order, so the offsets passed in are
|
|
181
|
-
# monotonically non-decreasing. We keep a running cursor into
|
|
182
|
-
# `@newlines` and advance linearly — amortized O(1) per call,
|
|
183
|
-
# vs. O(log n) per call with a fresh `bsearch`.
|
|
184
|
-
def line_column_at(offset)
|
|
185
|
-
while @newline_cursor < @newlines.size && @newlines[@newline_cursor] < offset
|
|
186
|
-
@newline_cursor += 1
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
prev_nl = @newline_cursor.zero? ? -1 : @newlines[@newline_cursor - 1]
|
|
190
|
-
|
|
191
|
-
[@newline_cursor + 1, offset - prev_nl]
|
|
192
|
-
end
|
|
193
|
-
|
|
194
175
|
def whitespace?(c)
|
|
195
176
|
c == ' ' || c == "\n" || c == "\t"
|
|
196
177
|
end
|
|
@@ -267,7 +248,7 @@ module CSS
|
|
|
267
248
|
end
|
|
268
249
|
|
|
269
250
|
def eof?
|
|
270
|
-
@pos >= @
|
|
251
|
+
@pos >= @length
|
|
271
252
|
end
|
|
272
253
|
|
|
273
254
|
def consume_whitespace
|
data/lib/css/version.rb
CHANGED
data/lib/css.rb
CHANGED
|
@@ -50,7 +50,7 @@ module CSS
|
|
|
50
50
|
|
|
51
51
|
def specificity(selector) = Selectors::SpecificityCalculator.calculate(selector)
|
|
52
52
|
|
|
53
|
-
def matches?(element, selector) = Selectors::Matcher.matches?(element, selector)
|
|
53
|
+
def matches?(element, selector, state: nil) = Selectors::Matcher.matches?(element, selector, state: state)
|
|
54
54
|
|
|
55
55
|
def parse_media_query_list(input) = MediaQueries::Parser.parse(input)
|
|
56
56
|
|
data/sig/css/cascade.rbs
CHANGED
|
@@ -17,6 +17,6 @@ module CSS
|
|
|
17
17
|
# Returns Hash<String, Declaration> of winning declarations after
|
|
18
18
|
# !important > inline > stylesheet > specificity > source-order
|
|
19
19
|
# sorting.
|
|
20
|
-
def resolve: (untyped element, ?inline_style: inline_style?) -> Hash[String, Nodes::Declaration]
|
|
20
|
+
def resolve: (untyped element, ?inline_style: inline_style?, ?state: matcher_state?) -> Hash[String, Nodes::Declaration]
|
|
21
21
|
end
|
|
22
22
|
end
|
data/sig/css/selectors.rbs
CHANGED
|
@@ -151,7 +151,10 @@ module CSS
|
|
|
151
151
|
end
|
|
152
152
|
|
|
153
153
|
module Matcher
|
|
154
|
-
|
|
154
|
+
STATEFUL_PSEUDOS: Set[String]
|
|
155
|
+
PROPAGATING_STATEFUL_PSEUDOS: Set[String]
|
|
156
|
+
|
|
157
|
+
def self.matches?: (untyped element, untyped selector, ?cache: Hash[Integer, untyped], ?state: matcher_state?) -> bool
|
|
155
158
|
|
|
156
159
|
def self.tag_of: (untyped element, ?Hash[Integer, untyped]?) -> String
|
|
157
160
|
def self.id_of: (untyped element, ?Hash[Integer, untyped]?) -> String?
|
data/sig/css/token.rbs
CHANGED
|
@@ -22,7 +22,7 @@ module CSS
|
|
|
22
22
|
def comment?: () -> bool
|
|
23
23
|
def trivia?: () -> bool
|
|
24
24
|
|
|
25
|
-
def
|
|
25
|
+
def assign_source!: (Integer start_offset, Integer end_offset, Array[Integer] newlines) -> self
|
|
26
26
|
|
|
27
27
|
def ==: (untyped other) -> bool
|
|
28
28
|
def eql?: (untyped other) -> bool
|
data/sig/css.rbs
CHANGED
|
@@ -68,7 +68,12 @@ module CSS
|
|
|
68
68
|
|
|
69
69
|
type selector = Selectors::SelectorList | Selectors::ComplexSelector | Selectors::CompoundSelector
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
# Per-pseudo state. Keys are pseudo-class names (Symbol or String);
|
|
72
|
+
# values are `true` (match every element), a `Set` / `Array` of the
|
|
73
|
+
# specific elements in that state, or falsy (no match).
|
|
74
|
+
type matcher_state = Hash[Symbol | String, bool | Set[untyped] | Array[untyped]]
|
|
75
|
+
|
|
76
|
+
def self.matches?: (untyped element, String | selector selector, ?cache: Hash[Integer, untyped], ?state: matcher_state?) -> bool
|
|
72
77
|
|
|
73
78
|
# Media queries (Media Queries 4)
|
|
74
79
|
# ---------------------------------------------------------------
|