<commit_before>import reportError from '../lib/reportError'
import niceStyles from 'flint-nice-styles'

const isLowerCase = s => s.toLowerCase() == s

const mergeStyles = (obj, ...styles)  => {
  return styles.reduce((acc, style) => {
    if (style && style.constructor === Array)
     for (var i = 0; i < style.length; i++)
       acc = mergeStyles(acc, style[i])
    else if (typeof style === 'object' && style !== null) {
      if (!acc) acc = {}
      Object.assign(acc, style)
    }

    return acc
  }, obj)
}

const prefix = '$'

// TODO remove <name-tag />
// originalTag || tag
// key, index, repeatItem, name, tag
export default function elementStyles(el, view, props) {
  if (typeof el.name !== 'string') return

  let styles, parentStyles, parentStylesStatic, parentStylesStaticView, parentStylesRoot

  // attach view styles from $ to element matching view name lowercase
  const tag = el.name
  const Flint = view.Flint
  const isRootName = view.name && view.name.toLowerCase() == el.name
  const hasOneRender = view.renders.length <= 1
  const isWrapperOrRoot = props && (props.__flintIsWrapper || props.root)
  const deservesRootStyles = !!(isRootName && hasOneRender || isWrapperOrRoot)

  function addClassName(name) {
    props.className = props.className ? `${props.className} ${name}` : name
  }

  if (view.name === 'Page.Sidebar')
    console.log(el.name, deservesRootStyles)

  if (deservesRootStyles) {
    if (view.props.__flint) {
      const parentName = view.props.__flint.parentName
      parentStyles = view.props.__flint.parentStyles
      parentStylesStatic = Flint.styleObjects[parentName]
      parentStylesStaticView = parentStylesStatic && parentStylesStatic[`$${view.name}`]

      const parentRoot = Flint.viewRoots[parentName]

      // parent $={} styles pass to child
      //    view Main { <Child root />  $ = { background: 'red' }  }   <-- makes these styles work!
      //    view Child { <child /> $ = { background: 'yellow' } }
      if (parentRoot === view.name) {
        parentStylesRoot = parentStylesStatic && parentStylesStatic.$
      }
    }<commit_msg>remove log<commit_after>import reportError from '../lib/reportError'
import niceStyles from 'flint-nice-styles'

const isLowerCase = s => s.toLowerCase() == s

const mergeStyles = (obj, ...styles)  => {
  return styles.reduce((acc, style) => {
    if (style && style.constructor === Array)
     for (var i = 0; i < style.length; i++)
       acc = mergeStyles(acc, style[i])
    else if (typeof style === 'object' && style !== null) {
      if (!acc) acc = {}
      Object.assign(acc, style)
    }

    return acc
  }, obj)
}

const prefix = '$'

// TODO remove <name-tag />
// originalTag || tag
// key, index, repeatItem, name, tag
export default function elementStyles(el, view, props) {
  if (typeof el.name !== 'string') return

  let styles, parentStyles, parentStylesStatic, parentStylesStaticView, parentStylesRoot

  // attach view styles from $ to element matching view name lowercase
  const tag = el.name
  const Flint = view.Flint
  const isRootName = view.name && view.name.toLowerCase() == el.name
  const hasOneRender = view.renders.length <= 1
  const isWrapperOrRoot = props && (props.__flintIsWrapper || props.root)
  const deservesRootStyles = !!(isRootName && hasOneRender || isWrapperOrRoot)

  function addClassName(name) {
    props.className = props.className ? `${props.className} ${name}` : name
  }

  if (deservesRootStyles) {
    if (view.props.__flint) {
      const parentName = view.props.__flint.parentName
      parentStyles = view.props.__flint.parentStyles
      parentStylesStatic = Flint.styleObjects[parentName]
      parentStylesStaticView = parentStylesStatic && parentStylesStatic[`$${view.name}`]

      const parentRoot = Flint.viewRoots[parentName]

      // parent $={} styles pass to child
      //    view Main { <Child root />  $ = { background: 'red' }  }   <-- makes these styles work!
      //    view Child { <child /> $ = { background: 'yellow' } }
      if (parentRoot === view.name) {
        parentStylesRoot = parentStylesStatic && parentStylesStatic.$
      }
    }
{'fraction_non_alphanumeric': 0.13597870796031938, 'fraction_numerical': 0.0009678199854827002, 'mean_word_length': 3.248715313463515, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2350627', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1259, 'n_words': 332}