How to use the emotion.sheet.sheet function in emotion

To help you get started, we’ve selected a few emotion 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 emotion-js / next / packages / server / src / index.js View on Github external
export function extractCritical(html) {
  // parse out ids from html
  // reconstruct css/rules/cache to pass
  const RGX = /css(?:[a-zA-Z0-9-]*)-([a-zA-Z0-9]+)/gm

  let o = { html, ids: [], css: '', rules: [] }
  let match
  let ids = {}
  while ((match = RGX.exec(html)) !== null) {
    if (!ids[match[1]]) {
      ids[match[1]] = true
    }
  }

  o.rules = sheet.sheet.cssRules.slice().filter(x => {
    RGX.lastIndex = 0
    let match = RGX.exec(x.cssText)
    const ret = match == null || ids[match[1]] || false
    return ret
  })

  o.ids = keys(inserted).filter(id => {
    return !!ids[id] || !registered[`css-${id}`]
  })
  let css = ''
  forEach(o.rules, x => (css += x.cssText))
  o.css = css

  return o
}