All files index.js

91.18% Statements 31/34
72% Branches 18/25
100% Functions 10/10
90.91% Lines 30/33
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 661x 1x 1x     1x       2x       2x 2x 1x     2x 2x       2x       2x 2x   2x 1x 1x             2x 2x     1x 2x     13x 13x 13x 13x 13x 13x 13x     13x 13x     13x          
var _id = 0
var sheet = document.head.appendChild(document.createElement("style")).sheet
var serialize = JSON.stringify.bind(null)
 
function hyphenate(str) {
  return str.replace(/[A-Z]/g, "-$&").toLowerCase()
}
 
function insert(rule) {
  sheet.insertRule(rule, 0)
}
 
function createRule(className, decls, media) {
  var newDecls = []
  for (var property in decls) {
    typeof decls[property] !== "object" &&
      newDecls.push(hyphenate(property) + ":" + decls[property] + ";")
  }
  var rule = "." + className + "{" + newDecls.join("") + "}"
  return media ? media + "{" + rule + "}" : rule
}
 
function concat(str1, str2) {
  return str1 + (/^\w/.test(str2) ? " " : "") + str2
}
 
function parse(decls, child, media, className) {
  child = child || ""
  className = className || "p" + (_id++).toString(36)
 
  for (var property in decls) {
    var value = decls[property]
    Iif (typeof value === "object") {
      var nextMedia = /^@/.test(property) ? property : null
      var nextChild = nextMedia ? child : concat(child, property)
      parse(value, nextChild, nextMedia, className)
    }
  }
 
  insert(createRule(concat(className, child), decls, media))
  return className
}
 
var cache = {}
var isDeclsFunction = decls => typeof decls === "function"
 
export default function(h) {
  return function(nodeName) {
    return function(decls) {
      return function(attributes, children) {
        attributes = attributes || {}
        children = attributes.children || children
        var key = serialize(attributes)
        cache[key] ||
          (cache[key] =
            (isDeclsFunction(decls) && parse(decls(attributes))) || parse(decls))
        var node = h(nodeName, attributes, children)
        node.attributes.class = [attributes.class, cache[key]]
          .filter(Boolean)
          .join(" ")
        return node
      }
    }
  }
}