cataract 0.2.3 → 0.2.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/.rubocop.yml +8 -3
- data/BENCHMARKS.md +50 -32
- data/CHANGELOG.md +21 -1
- data/Gemfile +3 -0
- data/ext/cataract/cataract.c +219 -112
- data/ext/cataract/cataract.h +5 -1
- data/ext/cataract/css_parser.c +875 -50
- 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/error.rb +49 -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 +15 -0
- data/lib/cataract/pure/flatten.rb +127 -15
- data/lib/cataract/pure/parser.rb +800 -271
- data/lib/cataract/pure/serializer.rb +216 -115
- data/lib/cataract/pure.rb +8 -7
- data/lib/cataract/rule.rb +9 -5
- data/lib/cataract/stylesheet.rb +345 -101
- data/lib/cataract/stylesheet_scope.rb +10 -7
- data/lib/cataract/version.rb +1 -1
- data/lib/cataract.rb +5 -8
- data/lib/tasks/profile.rake +210 -0
- metadata +5 -2
- data/lib/cataract/pure/imports.rb +0 -268
data/lib/cataract/pure.rb
CHANGED
|
@@ -25,13 +25,17 @@ module Cataract
|
|
|
25
25
|
class SizeError < Error; end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
require_relative 'error'
|
|
29
|
+
|
|
28
30
|
require_relative 'version'
|
|
31
|
+
require_relative 'constants'
|
|
29
32
|
|
|
30
33
|
# Load struct definitions and supporting files
|
|
31
34
|
# (These are also loaded by lib/cataract.rb, but we need them here for direct require)
|
|
32
35
|
require_relative 'declaration'
|
|
33
36
|
require_relative 'rule'
|
|
34
37
|
require_relative 'at_rule'
|
|
38
|
+
require_relative 'media_query'
|
|
35
39
|
require_relative 'import_statement'
|
|
36
40
|
require_relative 'stylesheet_scope'
|
|
37
41
|
require_relative 'stylesheet'
|
|
@@ -61,7 +65,6 @@ end
|
|
|
61
65
|
require_relative 'pure/byte_constants'
|
|
62
66
|
require_relative 'pure/helpers'
|
|
63
67
|
require_relative 'pure/specificity'
|
|
64
|
-
require_relative 'pure/imports'
|
|
65
68
|
require_relative 'pure/serializer'
|
|
66
69
|
require_relative 'pure/parser'
|
|
67
70
|
require_relative 'pure/flatten'
|
|
@@ -99,10 +102,8 @@ module Cataract
|
|
|
99
102
|
|
|
100
103
|
# NOTE: Copied from cataract.rb
|
|
101
104
|
# Need to untangle this eventually
|
|
102
|
-
def self.parse_css(css,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
Stylesheet.parse(css)
|
|
105
|
+
def self.parse_css(css, **options)
|
|
106
|
+
Stylesheet.parse(css, **options)
|
|
106
107
|
end
|
|
107
108
|
|
|
108
109
|
# Flatten stylesheet rules according to CSS cascade rules
|
|
@@ -139,8 +140,8 @@ module Cataract
|
|
|
139
140
|
# @param decl [Declaration] Declaration to expand
|
|
140
141
|
# @return [Array<Declaration>] Array of expanded longhand declarations
|
|
141
142
|
# @api private
|
|
142
|
-
def self.
|
|
143
|
-
Flatten.
|
|
143
|
+
def self.expand_shorthand(decl)
|
|
144
|
+
Flatten.expand_shorthand(decl)
|
|
144
145
|
end
|
|
145
146
|
|
|
146
147
|
# 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
|