class Sass::Selector::Sequence
def subweave(seq1, seq2)
-
(Array
->)
Parameters:
-
seq2
(Array
) -- -
seq1
(Array
) --
def subweave(seq1, seq2) return [seq2] if seq1.empty? return [seq1] if seq2.empty? seq1, seq2 = seq1.dup, seq2.dup return unless (init = merge_initial_ops(seq1, seq2)) return unless (fin = merge_final_ops(seq1, seq2)) # Make sure there's only one root selector in the output. root1 = has_root?(seq1.first) && seq1.shift root2 = has_root?(seq2.first) && seq2.shift if root1 && root2 return unless (root = root1.unify(root2)) seq1.unshift root seq2.unshift root elsif root1 seq2.unshift root1 elsif root2 seq1.unshift root2 end seq1 = group_selectors(seq1) seq2 = group_selectors(seq2) lcs = Sass::Util.lcs(seq2, seq1) do |s1, s2| next s1 if s1 == s2 next unless s1.first.is_a?(SimpleSequence) && s2.first.is_a?(SimpleSequence) next s2 if parent_superselector?(s1, s2) next s1 if parent_superselector?(s2, s1) next unless must_unify?(s1, s2) next unless (unified = Sequence.new(s1).unify(Sequence.new(s2))) unified.members.first.members if unified.members.length == 1 end diff = [[init]] until lcs.empty? diff << chunks(seq1, seq2) {|s| parent_superselector?(s.first, lcs.first)} << [lcs.shift] seq1.shift seq2.shift end diff << chunks(seq1, seq2) {|s| s.empty?} diff += fin.map {|sel| sel.is_a?(Array) ? sel : [sel]} diff.reject! {|c| c.empty?} Sass::Util.paths(diff).map {|p| p.flatten}.reject {|p| path_has_two_subjects?(p)} end