How to use the fela-utils.generateCSSRule 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 / createSubscription.js View on Github external
const node = getNodeFromCache(change, renderer, targetDocument)

    switch (change.type) {
      case KEYFRAME_TYPE:
        if (node.textContent.indexOf(change.keyframe) === -1) {
          node.textContent += change.keyframe
        }
        break
      case FONT_TYPE:
        if (node.textContent.indexOf(change.fontFace) === -1) {
          node.textContent += change.fontFace
        }
        break
      case STATIC_TYPE:
        let css = change.selector
          ? generateCSSRule(change.selector, change.css)
          : change.css

        if (node.textContent.indexOf(css) === -1) {
          node.textContent += css
        }
        break
      case RULE_TYPE:
        insertRule(change, renderer, node)
        break
      default:
        // TODO: warning
        break
    }
  }
}
github robinweser / fela / packages / fela-dom / src / dom / connection / insertRule.js View on Github external
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

      for (let i = startIndex, len = cssRules.length; i < len; ++i) {
        if (cssRules[i].score > score) {
          index = i
          break
        }
      }
    }

    const cssRule = generateCSSRule(selector, declaration)

    if (support.length > 0) {
      const cssSupportRule = generateCSSSupportRule(support, cssRule)
      node.sheet.insertRule(cssSupportRule, index)
    } else {
      node.sheet.insertRule(cssRule, index)
    }

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

    cssRules[index].score = score
  } catch (e) {
    // We're disabled these warnings due to false-positive errors with browser prefixes
    // See https://github.com/robinweser/fela/issues/634
github robinweser / fela / packages / fela-dom / src / dom / connection / generateRule.js View on Github external
export default function generateRule(
  selector: string,
  declaration: string,
  support?: string = ''
): string {
  const rule = generateCSSRule(selector, declaration)

  if (support.length > 0) {
    return generateCSSSupportRule(support, rule)
  }

  return rule
}