<commit_before>import { Atom, Options } from '@fower/atom'
import { store } from '@fower/store'
import { formatColor } from '@fower/color-helper'
import { styleSheet } from '@fower/sheet'
import { Props, PropItem } from '@fower/types'
import { parse } from '@fower/css-object-processor'
import {
  isEmptyObj,
  objectToClassName,
  jsKeyToCssKey,
  isPercentNumber,
  isNumber,
} from '@fower/utils'
import { isUnitProp } from './is-unit-prop'

type Dict = Record<string, any>

/**
 * @example p2,mx4,left10,spaceX4...
 * @example p-20,opacity-80
 */
export const digitReg =
  /^([mp][xytrbl]?|space[xy]?|top|right|bottom|left|[wh]|square|circle|min[hw]|max[hw]|opacity|delay|duration|translate[xyz]|scale[xy]?|rotate[xy]?|skew[xy]?|text|zIndex|leading|stroke|fontWeight|outlineOffset|order|flex(Grow|Shrink|Basis)?|(row|column)?Gap|gridTemplateColumns|border[trbl]?|rounded(Top(Left|Right)?|Right|Bottom(Left|Right)?|Left)?)(-?-?\d+[a-z]*?|-auto)$/i

//  high-frequency used props in react
const reactProps = ['children', 'onClick', 'onChange', 'onBlur', 'className', 'placeholder']

/**
 * An Abstract tool to handle atomic props
 */
export class Parser {
  constructor(public props = {} as Props) {
    this.traverseProps(props)

    if (store.config.autoDarkMode) {
      this.autoDarkMode()
    }
  }

  /**
   * atom parsed from props
   */
  atoms: Atom[] = []

  propList: PropItem[] = []

  get uniqueClassName() {
    return objectToClassName(Object.keys(this.props))
  }

  get hasResponsive() {
    return !!this.atoms.find((i) => !!i.meta.breakpoint)
  }

  get config(): any {
    return store.config
  }

  get plugins(): any[] {
    return store.config.plugins
  }

  /**
   * traverse Props to init atoms
   */
  traverseProps(props: Props): void {
    if (isEmptyObj(props)) return

    const { pseudos = [], theme } = this.config
    const { breakpoints, modes } = theme || {}
    const breakpointKeys = Object.keys(breakpoints)
    const modeKeys: string[] = modes || []
    const pseudoKeys: string[] = pseudos

    const { excludedProps = [] } = props
    const entries = Object.entries<any>(props)

    if (props?.className) {
      for (const item of props.className.split(/\s+/)) {
        entries.push([item, true])
      }
    }

    console.log('entries====:', entries)

    // traverse Props
    for (let [propKey, propValue] of entries) {
      // the prop should be excluded by user setting<commit_msg>style: remove console log<commit_after>import { Atom, Options } from '@fower/atom'
import { store } from '@fower/store'
import { formatColor } from '@fower/color-helper'
import { styleSheet } from '@fower/sheet'
import { Props, PropItem } from '@fower/types'
import { parse } from '@fower/css-object-processor'
import {
  isEmptyObj,
  objectToClassName,
  jsKeyToCssKey,
  isPercentNumber,
  isNumber,
} from '@fower/utils'
import { isUnitProp } from './is-unit-prop'

type Dict = Record<string, any>

/**
 * @example p2,mx4,left10,spaceX4...
 * @example p-20,opacity-80
 */
export const digitReg =
  /^([mp][xytrbl]?|space[xy]?|top|right|bottom|left|[wh]|square|circle|min[hw]|max[hw]|opacity|delay|duration|translate[xyz]|scale[xy]?|rotate[xy]?|skew[xy]?|text|zIndex|leading|stroke|fontWeight|outlineOffset|order|flex(Grow|Shrink|Basis)?|(row|column)?Gap|gridTemplateColumns|border[trbl]?|rounded(Top(Left|Right)?|Right|Bottom(Left|Right)?|Left)?)(-?-?\d+[a-z]*?|-auto)$/i

//  high-frequency used props in react
const reactProps = ['children', 'onClick', 'onChange', 'onBlur', 'className', 'placeholder']

/**
 * An Abstract tool to handle atomic props
 */
export class Parser {
  constructor(public props = {} as Props) {
    this.traverseProps(props)

    if (store.config.autoDarkMode) {
      this.autoDarkMode()
    }
  }

  /**
   * atom parsed from props
   */
  atoms: Atom[] = []

  propList: PropItem[] = []

  get uniqueClassName() {
    return objectToClassName(Object.keys(this.props))
  }

  get hasResponsive() {
    return !!this.atoms.find((i) => !!i.meta.breakpoint)
  }

  get config(): any {
    return store.config
  }

  get plugins(): any[] {
    return store.config.plugins
  }

  /**
   * traverse Props to init atoms
   */
  traverseProps(props: Props): void {
    if (isEmptyObj(props)) return

    const { pseudos = [], theme } = this.config
    const { breakpoints, modes } = theme || {}
    const breakpointKeys = Object.keys(breakpoints)
    const modeKeys: string[] = modes || []
    const pseudoKeys: string[] = pseudos

    const { excludedProps = [] } = props
    const entries = Object.entries<any>(props)

    if (props?.className) {
      for (const item of props.className.split(/\s+/)) {
        entries.push([item, true])
      }
    }

    // traverse Props
    for (let [propKey, propValue] of entries) {
      // the prop should be excluded by user setting
{'fraction_non_alphanumeric': 0.16370400992145515, 'fraction_numerical': 0.0037205456800330715, 'mean_word_length': 3.800595238095238, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2242283', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1624, 'n_words': 342}