cataract 0.2.3 → 0.2.4
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/.rubocop.yml +7 -3
- data/BENCHMARKS.md +32 -32
- data/CHANGELOG.md +10 -0
- data/Gemfile +3 -0
- data/ext/cataract/cataract.c +219 -112
- data/ext/cataract/cataract.h +5 -1
- data/ext/cataract/css_parser.c +523 -33
- data/ext/cataract/flatten.c +233 -91
- data/ext/cataract/shorthand_expander.c +7 -0
- data/lib/cataract/at_rule.rb +2 -1
- data/lib/cataract/constants.rb +10 -0
- data/lib/cataract/import_resolver.rb +18 -87
- data/lib/cataract/import_statement.rb +29 -5
- data/lib/cataract/media_query.rb +98 -0
- data/lib/cataract/pure/byte_constants.rb +11 -0
- data/lib/cataract/pure/flatten.rb +127 -15
- data/lib/cataract/pure/parser.rb +637 -270
- data/lib/cataract/pure/serializer.rb +216 -115
- data/lib/cataract/pure.rb +6 -7
- data/lib/cataract/rule.rb +9 -5
- data/lib/cataract/stylesheet.rb +321 -99
- data/lib/cataract/stylesheet_scope.rb +10 -7
- data/lib/cataract/version.rb +1 -1
- data/lib/cataract.rb +4 -8
- data/lib/tasks/profile.rake +210 -0
- metadata +4 -2
- data/lib/cataract/pure/imports.rb +0 -268
data/lib/cataract/pure.rb
CHANGED
|
@@ -26,12 +26,14 @@ module Cataract
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
require_relative 'version'
|
|
29
|
+
require_relative 'constants'
|
|
29
30
|
|
|
30
31
|
# Load struct definitions and supporting files
|
|
31
32
|
# (These are also loaded by lib/cataract.rb, but we need them here for direct require)
|
|
32
33
|
require_relative 'declaration'
|
|
33
34
|
require_relative 'rule'
|
|
34
35
|
require_relative 'at_rule'
|
|
36
|
+
require_relative 'media_query'
|
|
35
37
|
require_relative 'import_statement'
|
|
36
38
|
require_relative 'stylesheet_scope'
|
|
37
39
|
require_relative 'stylesheet'
|
|
@@ -61,7 +63,6 @@ end
|
|
|
61
63
|
require_relative 'pure/byte_constants'
|
|
62
64
|
require_relative 'pure/helpers'
|
|
63
65
|
require_relative 'pure/specificity'
|
|
64
|
-
require_relative 'pure/imports'
|
|
65
66
|
require_relative 'pure/serializer'
|
|
66
67
|
require_relative 'pure/parser'
|
|
67
68
|
require_relative 'pure/flatten'
|
|
@@ -99,10 +100,8 @@ module Cataract
|
|
|
99
100
|
|
|
100
101
|
# NOTE: Copied from cataract.rb
|
|
101
102
|
# Need to untangle this eventually
|
|
102
|
-
def self.parse_css(css,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
Stylesheet.parse(css)
|
|
103
|
+
def self.parse_css(css, **options)
|
|
104
|
+
Stylesheet.parse(css, **options)
|
|
106
105
|
end
|
|
107
106
|
|
|
108
107
|
# Flatten stylesheet rules according to CSS cascade rules
|
|
@@ -139,8 +138,8 @@ module Cataract
|
|
|
139
138
|
# @param decl [Declaration] Declaration to expand
|
|
140
139
|
# @return [Array<Declaration>] Array of expanded longhand declarations
|
|
141
140
|
# @api private
|
|
142
|
-
def self.
|
|
143
|
-
Flatten.
|
|
141
|
+
def self.expand_shorthand(decl)
|
|
142
|
+
Flatten.expand_shorthand(decl)
|
|
144
143
|
end
|
|
145
144
|
|
|
146
145
|
# Add stub method to Stylesheet for pure Ruby implementation
|
data/lib/cataract/rule.rb
CHANGED
|
@@ -25,6 +25,7 @@ module Cataract
|
|
|
25
25
|
# @attr [Integer, nil] parent_rule_id Parent rule ID for nested rules
|
|
26
26
|
# @attr [Integer, nil] nesting_style 0=implicit, 1=explicit, nil=not nested
|
|
27
27
|
# @attr [Integer, nil] selector_list_id ID linking rules from same selector list (e.g., "h1, h2")
|
|
28
|
+
# @attr [Integer, nil] media_query_id ID of the MediaQuery this rule belongs to (nil if not in media query)
|
|
28
29
|
Rule = Struct.new(
|
|
29
30
|
:id,
|
|
30
31
|
:selector,
|
|
@@ -32,7 +33,8 @@ module Cataract
|
|
|
32
33
|
:specificity,
|
|
33
34
|
:parent_rule_id,
|
|
34
35
|
:nesting_style,
|
|
35
|
-
:selector_list_id
|
|
36
|
+
:selector_list_id,
|
|
37
|
+
:media_query_id
|
|
36
38
|
)
|
|
37
39
|
|
|
38
40
|
class Rule
|
|
@@ -46,6 +48,7 @@ module Cataract
|
|
|
46
48
|
# @param parent_rule_id [Integer, nil] Parent rule ID for nested rules
|
|
47
49
|
# @param nesting_style [Integer, nil] Nesting style (0=implicit, 1=explicit, nil=not nested)
|
|
48
50
|
# @param selector_list_id [Integer, nil] Selector list ID for grouping
|
|
51
|
+
# @param media_query_id [Integer, nil] MediaQuery ID for rules in media queries
|
|
49
52
|
# @return [Rule] New rule instance
|
|
50
53
|
#
|
|
51
54
|
# @example Create a rule with keyword arguments
|
|
@@ -56,10 +59,11 @@ module Cataract
|
|
|
56
59
|
# specificity: 10,
|
|
57
60
|
# parent_rule_id: nil,
|
|
58
61
|
# nesting_style: nil,
|
|
59
|
-
# selector_list_id: nil
|
|
62
|
+
# selector_list_id: nil,
|
|
63
|
+
# media_query_id: nil
|
|
60
64
|
# )
|
|
61
|
-
def self.make(id:, selector:, declarations:, specificity: nil, parent_rule_id: nil, nesting_style: nil, selector_list_id: nil)
|
|
62
|
-
new(id, selector, declarations, specificity, parent_rule_id, nesting_style, selector_list_id)
|
|
65
|
+
def self.make(id:, selector:, declarations:, specificity: nil, parent_rule_id: nil, nesting_style: nil, selector_list_id: nil, media_query_id: nil)
|
|
66
|
+
new(id, selector, declarations, specificity, parent_rule_id, nesting_style, selector_list_id, media_query_id)
|
|
63
67
|
end
|
|
64
68
|
|
|
65
69
|
# Silence warning about method redefinition. We redefine below to lazily calculate
|
|
@@ -211,7 +215,7 @@ module Cataract
|
|
|
211
215
|
# rubocop:disable Naming/MemoizedInstanceVariableName
|
|
212
216
|
def expanded_declarations
|
|
213
217
|
@_expanded_declarations ||= begin
|
|
214
|
-
expanded = declarations.flat_map { |decl| Cataract.
|
|
218
|
+
expanded = declarations.flat_map { |decl| Cataract.expand_shorthand(decl) }
|
|
215
219
|
expanded.sort_by! { |d| [d.property, d.value, d.important ? 1 : 0] }
|
|
216
220
|
expanded
|
|
217
221
|
end
|