<commit_before>import warning from 'warning';
import jssVendorPrefixer from 'jss-vendor-prefixer';
import { find, findIndex } from './utils';

const prefixRule = jssVendorPrefixer();
const warned = [];

/**
 * styleManager module. Used to create styleManager objects.
 *
 * @module styleManager
 */

/**
 * Creates a new styleManager
 *
 * @example
 *
 * ```javascript
 * import { createStyleManager } from 'stylishly/styleManager';
 * const styleManager = createStyleManager();
 * ```
 *
 * @param  {Object}  config                    - Config
 * @param  {Object}  config.jss                - Jss instance
 * @param  {Object}  config.theme={}           - Theme object
 * @return {module:styleManager~styleManager}  - styleManager
 */
export function createStyleManager({ jss, theme = {} } = {}) {
  let sheetMap = [];

  /**
   * styleManager description
   *
   * @name styleManager
   * @type {Object}
   */
  const styleManager = {
    get sheetMap() { return sheetMap; },
    jss,
    reset,
    rerender,
    theme,
    render,
    getClasses,
    updateTheme,
    prepareInline,
  };

  function getClasses(styleSheet) {
    const mapping = find(sheetMap, { styleSheet });

    if (mapping) {
      return mapping.classes;
    }

    return undefined;
  }

  /**
   * Some mundane desc
   *
   * @memberOf module:styleManager~styleManager
   * @param  {Object} styleSheet - styleSheet object created by createStyleSheet()
   * @return {Object}            - classNames keyed by styleSheet property names
   */
  function render(styleSheet, ...other) {
    let mapping = find(sheetMap, { styleSheet });

    if (!mapping) {
      const { name, resolveStyles, options } = styleSheet;

      const looseIndex = findIndex(sheetMap, { name });

      if (looseIndex !== -1) {
        sheetMap[looseIndex].jssStyleSheet.detach();
        sheetMap.splice(looseIndex, 1);
        if (process.env.NODE_ENV !== 'production') {
          warning(
            warned.indexOf(name) !== -1,
            `A styleSheet with the name ${name} already exists.`
          );
          warned.push(name);
        }
      }

      const rules = resolveStyles(theme, ...other);
      const jssStyleSheet = jss.createStyleSheet(rules, { meta: name, ...options });
      const { classes } = jssStyleSheet.attach();

      mapping = { name, classes, styleSheet, jssStyleSheet, other };
      sheetMap.push(mapping);
    }

    return mapping.classes;
  }

  /**
   * Replace the current theme with a new theme
   *
   * @param  {Object}  newTheme    - New theme object
   * @param  {boolean} shouldReset - Set to true to rerender the renderer
   */
  function updateTheme(newTheme, shouldReset = true) {
    theme = newTheme;
    if (shouldReset) {
      rerender();
    }
  }

  function reset() {
    sheetMap.forEach(({ jssStyleSheet }) => jssStyleSheet.detach());
    jss.sheets.registry = [];
    sheetMap = [];
  }

  /**
   * Reset and replace all existing stylesheets
   *
   * @memberOf module:styleManager~styleManager
   */
  function rerender() {
    const sheets = [...sheetMap];
    reset();
    sheets.forEach((n) => render(n.styleSheet, ...n.other));
  }

  function prepareInline(declaration) {
    if (typeof declaration === 'function') {
      declaration = declaration(theme);
    }

    const rule = {
      type: 'regular',
      style: declaration,
    };

    prefixRule(rule);

    return rule.style;
  }

  return styleManager;
}
<commit_msg>Temporarily disable name warning till I figure out a better solution for handling HMR<commit_after>import warning from 'warning';
import jssVendorPrefixer from 'jss-vendor-prefixer';
import { find, findIndex } from './utils';

const prefixRule = jssVendorPrefixer();
const warned = [];

/**
 * styleManager module. Used to create styleManager objects.
 *
 * @module styleManager
 */

/**
 * Creates a new styleManager
 *
 * @example
 *
 * ```javascript
 * import { createStyleManager } from 'stylishly/styleManager';
 * const styleManager = createStyleManager();
 * ```
 *
 * @param  {Object}  config                    - Config
 * @param  {Object}  config.jss                - Jss instance
 * @param  {Object}  config.theme={}           - Theme object
 * @return {module:styleManager~styleManager}  - styleManager
 */
export function createStyleManager({ jss, theme = {} } = {}) {
  let sheetMap = [];

  /**
   * styleManager description
   *
   * @name styleManager
   * @type {Object}
   */
  const styleManager = {
    get sheetMap() { return sheetMap; },
    jss,
    reset,
    rerender,
    theme,
    render,
    getClasses,
    updateTheme,
    prepareInline,
  };

  function getClasses(styleSheet) {
    const mapping = find(sheetMap, { styleSheet });

    if (mapping) {
      return mapping.classes;
    }

    return undefined;
  }

  /**
   * Some mundane desc
   *
   * @memberOf module:styleManager~styleManager
   * @param  {Object} styleSheet - styleSheet object created by createStyleSheet()
   * @return {Object}            - classNames keyed by styleSheet property names
   */
  function render(styleSheet, ...other) {
    let mapping = find(sheetMap, { styleSheet });

    if (!mapping) {
      const { name, resolveStyles, options } = styleSheet;

      const looseIndex = findIndex(sheetMap, { name });

      if (looseIndex !== -1) {
        sheetMap[looseIndex].jssStyleSheet.detach();
        sheetMap.splice(looseIndex, 1);
        // if (process.env.NODE_ENV !== 'production') {
        //   warning(
        //     warned.indexOf(name) !== -1,
        //     `A styleSheet with the name ${name} already exists.`
        //   );
        //   warned.push(name);
        // }
      }

      const rules = resolveStyles(theme, ...other);
      const jssStyleSheet = jss.createStyleSheet(rules, { meta: name, ...options });
      const { classes } = jssStyleSheet.attach();

      mapping = { name, classes, styleSheet, jssStyleSheet, other };
      sheetMap.push(mapping);
    }

    return mapping.classes;
  }

  /**
   * Replace the current theme with a new theme
   *
   * @param  {Object}  newTheme    - New theme object
   * @param  {boolean} shouldReset - Set to true to rerender the renderer
   */
  function updateTheme(newTheme, shouldReset = true) {
    theme = newTheme;
    if (shouldReset) {
      rerender();
    }
  }

  function reset() {
    sheetMap.forEach(({ jssStyleSheet }) => jssStyleSheet.detach());
    jss.sheets.registry = [];
    sheetMap = [];
  }

  /**
   * Reset and replace all existing stylesheets
   *
   * @memberOf module:styleManager~styleManager
   */
  function rerender() {
    const sheets = [...sheetMap];
    reset();
    sheets.forEach((n) => render(n.styleSheet, ...n.other));
  }

  function prepareInline(declaration) {
    if (typeof declaration === 'function') {
      declaration = declaration(theme);
    }

    const rule = {
      type: 'regular',
      style: declaration,
    };

    prefixRule(rule);

    return rule.style;
  }

  return styleManager;
}

{'fraction_non_alphanumeric': 0.1293461153240807, 'fraction_numerical': 0.0008584919158677923, 'mean_word_length': 2.5464231354642313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5283116', 'n_tokens_mistral': 2103, 'n_tokens_neox': 2066, 'n_words': 521}