p_css 0.1.8 → 0.1.9
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 +9 -2
- data/lib/css/selectors/matcher.rb +7 -3
- data/lib/css/version.rb +1 -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: 7c7c770667eefbfabcfd7543684970c971588c7d31ef7eaa8dfde8dfc71382ec
|
|
4
|
+
data.tar.gz: fe5c819bb338d0417fed4e15fbf85f9c8a158038a0fd9d17e78e308c2e1c949f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cf33855007bc4c7691d7a9c726eb51f85215492643ec54c2510438a4d10da5afefa176cc062c8eab5774b4a86a23049c5b7b5f64f121682581f34aceb826870d
|
|
7
|
+
data.tar.gz: c72b82737b2c24a7585022da646135f743dfc9a59dc918267482f57ae2e68cd79dcfd6da106a14b6962ac2fd325ab09032a40e59148191d4146b08cc057ef37f
|
data/lib/css/cascade.rb
CHANGED
|
@@ -35,8 +35,15 @@ module CSS
|
|
|
35
35
|
# `state:` opts into stateful-pseudo matching — see
|
|
36
36
|
# `Selectors::Matcher#matches?` for the shape. Defaults to the
|
|
37
37
|
# stateless behavior (`:hover`, `:focus`, etc. never match).
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
#
|
|
39
|
+
# `cache:` lets callers share a per-element context cache across many
|
|
40
|
+
# resolves. The default `{}` is local to one call. Pass a persistent
|
|
41
|
+
# Hash when the DOM is stable across many resolves — Context (tag, id,
|
|
42
|
+
# classes) computation runs once per element instead of per resolve.
|
|
43
|
+
# The caller is responsible for clearing/replacing the cache on DOM
|
|
44
|
+
# mutation.
|
|
45
|
+
def resolve(element, inline_style: nil, state: nil, cache: nil)
|
|
46
|
+
cache ||= {}
|
|
40
47
|
candidates = collect_candidate_indexes(element, cache)
|
|
41
48
|
order = 0
|
|
42
49
|
matches = []
|
|
@@ -43,7 +43,7 @@ module CSS
|
|
|
43
43
|
# the duration of a single matcher invocation.
|
|
44
44
|
Context = Data.define(:tag, :id, :classes)
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
EMPTY_CLASSES = [].freeze
|
|
47
47
|
|
|
48
48
|
def matches?(element, selector, cache: nil, state: nil)
|
|
49
49
|
sel = selector.is_a?(String) ? Parser.parse_selector_list(selector) : selector
|
|
@@ -148,11 +148,15 @@ module CSS
|
|
|
148
148
|
)
|
|
149
149
|
end
|
|
150
150
|
|
|
151
|
+
# Returns an Array of class names. We deliberately don't wrap in a Set:
|
|
152
|
+
# construction allocates two objects (Array + Set), and on the typical
|
|
153
|
+
# 1–5 classes per element, Array#include? is fast enough that the
|
|
154
|
+
# construction win dominates the lookup penalty.
|
|
151
155
|
def build_class_set(element)
|
|
152
156
|
v = attr(element, 'class')
|
|
153
|
-
return
|
|
157
|
+
return EMPTY_CLASSES if v.nil? || v.empty?
|
|
154
158
|
|
|
155
|
-
v.to_s.split(
|
|
159
|
+
v.to_s.split(' ')
|
|
156
160
|
end
|
|
157
161
|
|
|
158
162
|
# Attribute matching ----------------------------------------------
|
data/lib/css/version.rb
CHANGED