<commit_before>import _ from 'lodash';
import {illustratorSwatches} from 'chrys-cli';
import {scaleQuantile} from 'd3-scale';
import autoprefixer from 'autoprefixer';
import chroma from 'chroma-js';
import fs from 'fs-extra';
import jsonSass from 'json-sass';
import log from 'fancy-log';
import nunjucks from 'nunjucks';
import path from 'path';
import postcssColorRgbaFallback from 'postcss-color-rgba-fallback';
import postcssOpacity from 'postcss-opacity';
import Promise from 'bluebird';
import webpack from 'webpack';
import {BOKEH_TO_VEGA, VEGA_TO_BOKEH, config} from '../config';
import webpackConfig from '../webpack.config.prod';
import {name as globalName} from '../package';
import {
  BOKEH_PALETTE_DATA,
  BOKEH_PALETTE_NAMES,
  VEGA_PALETTE_DATA,
  VEGA_PALETTE_NAMES
} from '../cjs/chrys';

const env = new nunjucks.Environment(new nunjucks.FileSystemLoader('.'));

/**
 * Adapted from https://github.com/voxpelli/sass-color-helpers/blob/a32cfd607ca6479318452461a70a7a9ffd886eb1/stylesheets/color-helpers/_contrast.scss#L35
 *
 * @param   {String} base
 * @param   {Array} colors
 * @param   {Number} tolerance
 * @returns {String}
 */
env.addFilter('bestContrast', function(
  base,
  colors = ['#000', '#fff'],
  tolerance = 0
) {
  var bestColor = colors[0];
  var bestContrast = chroma.contrast(base, bestColor);
  var color;
  var contrast;

  for (var i = 1, il = colors.length; i < il; i++) {
    color = colors[i];
    contrast = chroma.contrast(base, color);

    if (contrast - bestContrast > tolerance) {
      bestColor = color;
      bestContrast = contrast;
    }
  }

  return bestColor;
});

// TODO Replace gulp
const gulpCssmin = require('gulp-cssmin');
const gulp = require('gulp');
const gulpPostcss = require('gulp-postcss');
const gulpRename = require('gulp-rename');
const gulpSass = require('gulp-sass');

export function continuousPalette(colors, count) {
  const scale = scaleQuantile(
    _.times(count, i => i),
    colors
  );
  return _.times(count, i => scale(i));
}

export function bokehToVega(name) {
  return BOKEH_TO_VEGA[name];
}

export function vegaToBokeh(name) {
  return VEGA_TO_BOKEH[name];
}

export function jsSerialize(vendor, vars, maxSize, docsMaxSize) {
  const VENDOR_PALETTES = `${vendor.toUpperCase()}_PALETTES`;
  const VENDOR_PALETTE_DATA = `${vendor.toUpperCase()}_PALETTE_DATA`;
  const VENDOR_PALETTE_NAMES = `${vendor.toUpperCase()}_PALETTE_NAMES`;
  const VENDOR_DOCS_PALETTES = `${vendor.toUpperCase()}_DOCS_PALETTES`;
  const VENDOR_DOCS_PALETTE_DATA = `${vendor.toUpperCase()}_DOCS_PALETTE_DATA`;
<commit_msg>Tidy up imports<commit_after>import _ from 'lodash';
import {illustratorSwatches} from 'chrys-cli';
import {scaleQuantile} from 'd3-scale';
import autoprefixer from 'autoprefixer';
import chroma from 'chroma-js';
import fs from 'fs-extra';
import jsonSass from 'json-sass';
import log from 'fancy-log';
import nunjucks from 'nunjucks';
import path from 'path';
import postcssColorRgbaFallback from 'postcss-color-rgba-fallback';
import postcssOpacity from 'postcss-opacity';
import Promise from 'bluebird';
import webpack from 'webpack';
import {BOKEH_TO_VEGA, VEGA_TO_BOKEH, config} from '../config';
import webpackConfig from '../webpack.config.prod';
import {name as globalName} from '../package';
import {
  BOKEH_PALETTE_DATA,
  BOKEH_PALETTE_NAMES,
  VEGA_PALETTE_DATA,
  VEGA_PALETTE_NAMES
} from '../cjs/chrys';

// TODO Replace gulp
const gulpCssmin = require('gulp-cssmin');
const gulp = require('gulp');
const gulpPostcss = require('gulp-postcss');
const gulpRename = require('gulp-rename');
const gulpSass = require('gulp-sass');

const env = new nunjucks.Environment(new nunjucks.FileSystemLoader('.'));

/**
 * Adapted from https://github.com/voxpelli/sass-color-helpers/blob/a32cfd607ca6479318452461a70a7a9ffd886eb1/stylesheets/color-helpers/_contrast.scss#L35
 *
 * @param   {String} base
 * @param   {Array} colors
 * @param   {Number} tolerance
 * @returns {String}
 */
env.addFilter('bestContrast', function(
  base,
  colors = ['#000', '#fff'],
  tolerance = 0
) {
  var bestColor = colors[0];
  var bestContrast = chroma.contrast(base, bestColor);
  var color;
  var contrast;

  for (var i = 1, il = colors.length; i < il; i++) {
    color = colors[i];
    contrast = chroma.contrast(base, color);

    if (contrast - bestContrast > tolerance) {
      bestColor = color;
      bestContrast = contrast;
    }
  }

  return bestColor;
});

export function continuousPalette(colors, count) {
  const scale = scaleQuantile(
    _.times(count, i => i),
    colors
  );
  return _.times(count, i => scale(i));
}

export function bokehToVega(name) {
  return BOKEH_TO_VEGA[name];
}

export function vegaToBokeh(name) {
  return VEGA_TO_BOKEH[name];
}

export function jsSerialize(vendor, vars, maxSize, docsMaxSize) {
  const VENDOR_PALETTES = `${vendor.toUpperCase()}_PALETTES`;
  const VENDOR_PALETTE_DATA = `${vendor.toUpperCase()}_PALETTE_DATA`;
  const VENDOR_PALETTE_NAMES = `${vendor.toUpperCase()}_PALETTE_NAMES`;
  const VENDOR_DOCS_PALETTES = `${vendor.toUpperCase()}_DOCS_PALETTES`;
  const VENDOR_DOCS_PALETTE_DATA = `${vendor.toUpperCase()}_DOCS_PALETTE_DATA`;

{'fraction_non_alphanumeric': 0.13446676970633695, 'fraction_numerical': 0.013523956723338485, 'mean_word_length': 5.040840140023337, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '2832478', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1905, 'n_words': 410}