lib/hacks/grid-utils.js
function shouldInheritGap (selA, selB) {
  let result

  // get arrays of selector split in 3-deep array
  let splitSelectorArrA = splitSelector(selA)
  let splitSelectorArrB = splitSelector(selB)

  if (splitSelectorArrA[0].length < splitSelectorArrB[0].length) {
    // abort if selectorA has lower descendant specificity then selectorB
    // (e.g '.grid' and '.hello .world .grid')
    return false
  } else if (splitSelectorArrA[0].length > splitSelectorArrB[0].length) {
    // if selectorA has higher descendant specificity then selectorB
    // (e.g '.foo .bar .grid' and '.grid')

    let idx = splitSelectorArrA[0].reduce((res, [item], index) => {
      let firstSelectorPart = splitSelectorArrB[0][0][0]
      if (item === firstSelectorPart) {
        return index
      }
      return false
    }, false)

    if (idx) {
      result = splitSelectorArrB[0].every((arr, index) => {
        return arr.every((part, innerIndex) =>
          // because selectorA has more space elements, we need to slice
          // selectorA array by 'idx' number to compare them
          splitSelectorArrA[0].slice(idx)[index][innerIndex] === part)
      })
    }
  } else {
    // if selectorA has the same descendant specificity as selectorB
    // this condition covers cases such as: '.grid.foo.bar' and '.grid'
    result = splitSelectorArrB.some(byCommaArr => {
      return byCommaArr.every((bySpaceArr, index) => {
        return bySpaceArr.every(
          (part, innerIndex) => splitSelectorArrA[0][index][innerIndex] === part
        )
      })
    })
  }

  return result
}
function shouldInheritGap (selA, selB) {
  let result

  // get arrays of selector split in 3-deep array
  let splitSelectorArrA = splitSelector(selA)
  let splitSelectorArrB = splitSelector(selB)

  if (splitSelectorArrA[0].length < splitSelectorArrB[0].length) {
    // abort if selectorA has lower descendant specificity then selectorB
    // (e.g '.grid' and '.hello .world .grid')
    return false
  } else if (splitSelectorArrA[0].length > splitSelectorArrB[0].length) {
    // if selectorA has higher descendant specificity then selectorB
    // (e.g '.foo .bar .grid' and '.grid')

    let idx = splitSelectorArrA[0].reduce((res, [item], index) => {
      let firstSelectorPart = splitSelectorArrB[0][0][0]
      if (item === firstSelectorPart) {
        return index
      }
      return false
    }, false)

    if (idx) {
      result = splitSelectorArrB[0].every((arr, index) => {
        return arr.every((part, innerIndex) =>
          // because selectorA has more space elements, we need to slice
          // selectorA array by 'idx' number to compare them
          splitSelectorArrA[0].slice(idx)[index][innerIndex] === part)
      })
    }
  } else {
    // if selectorA has the same descendant specificity as selectorB
    // this condition covers cases such as: '.grid.foo.bar' and '.grid'
    result = splitSelectorArrB.some(byCommaArr => {
      return byCommaArr.every((bySpaceArr, index) => {
        return bySpaceArr.every(
          (part, innerIndex) => splitSelectorArrA[0][index][innerIndex] === part
        )
      })
    })
  }

  return result
}
function shouldInheritGap ( selA , selB ) { let result // get arrays of selector split in 3-deep array let splitSelectorArrA = splitSelector ( selA ) let splitSelectorArrB = splitSelector ( selB ) if ( splitSelectorArrA [ 0 ] . length < splitSelectorArrB [ 0 ] . length ) { // abort if selectorA has lower descendant specificity then selectorB // (e.g '.grid' and '.hello .world .grid') return false } else if ( splitSelectorArrA [ 0 ] . length > splitSelectorArrB [ 0 ] . length ) { // if selectorA has higher descendant specificity then selectorB // (e.g '.foo .bar .grid' and '.grid') let idx = splitSelectorArrA [ 0 ] . reduce ( ( res , [ item ] , index ) => { let firstSelectorPart = splitSelectorArrB [ 0 ] [ 0 ] [ 0 ] if ( item === firstSelectorPart ) { return index } return false } , false ) if ( idx ) { result = splitSelectorArrB [ 0 ] . every ( ( arr , index ) => { return arr . every ( ( part , innerIndex ) => // because selectorA has more space elements, we need to slice // selectorA array by 'idx' number to compare them splitSelectorArrA [ 0 ] . slice ( idx ) [ index ] [ innerIndex ] === part ) } ) } } else { // if selectorA has the same descendant specificity as selectorB // this condition covers cases such as: '.grid.foo.bar' and '.grid' result = splitSelectorArrB . some ( byCommaArr => { return byCommaArr . every ( ( bySpaceArr , index ) => { return bySpaceArr . every ( ( part , innerIndex ) => splitSelectorArrA [ 0 ] [ index ] [ innerIndex ] === part ) } ) } ) } return result }
Compare the selectors and decide if we
need to inherit gap from compared selector or not.
@type {String} selA
@type {String} selB
@return {Boolean}
Compare the selectors and decide if we need to inherit gap from compared selector or not .