How to use the fela-utils.getRuleScore function in fela-utils

To help you get started, we’ve selected a few fela-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github robinweser / fela / packages / fela-dom / src / dom / connection / insertRule.js View on Github external
export default function insertRule(
  { selector, declaration, support, media, pseudo }: Object,
  renderer: DOMRenderer,
  node: Object
) {
  const nodeReference = media + support
  // only use insertRule in production as browser devtools might have
  // weird behavior if used together with insertRule at runtime
  if (renderer.devMode) {
    insertRuleInDevMode(renderer, node)
    return
  }

  try {
    const score = getRuleScore(renderer.ruleOrder, pseudo)
    const { cssRules } = node.sheet

    let index = cssRules.length

    // This heavily optimises the amount of rule iterations we need
    // due to most rules having a score=0 anyways
    if (score === 0) {
      if (renderer.scoreIndex[nodeReference] === undefined) {
        index = 0
      } else {
        index = renderer.scoreIndex[nodeReference] + 1
      }
    } else {
      // we start iterating from the last score=0 entry
      // to correctly inject pseudo classes etc.
      const startIndex = renderer.scoreIndex[nodeReference] || 0
github robinweser / fela / packages / fela-dom / src / dom / rehydrate.js View on Github external
arrayEach(node.sheet.cssRules, (rule, index) => {
            const selectorText = rule.conditionText
              ? rule.cssRules[0].selectorText
              : rule.selectorText

            const score = getRuleScore(
              renderer.ruleOrder,
              selectorText.split(CLASSNAME_REGEX)[1]
            )

            if (score === 0) {
              renderer.scoreIndex[nodeReference] = index
            }

            rule.score = score
          })
        }