<commit_before>import { conf } from '../config.js'
import * as Canvas from '../utils/canvas.js'

// --- Config & Local state ----------------------------------------------------

const dom = {
  cursorCanvas: document.getElementById('cursor')
}

// --- Main methods ------------------------------------------------------------

const init = (store) => {
  const context = dom.cursorCanvas.getContext('2d')
  context.fillStyle = '#000'

  const width = 200
  const height = width / 2

  dom.cursorCanvas.width = width
  dom.cursorCanvas.style.width = width + 'px'
  dom.cursorCanvas.height = height
  dom.cursorCanvas.style.height = height + 'px'

  const cursor = conf.cursor.types[2]

  const cursorWidth = cursor.reduce((width, coord) => coord[0] > width ? coord[0] : width, 0) + 1
  const cursorHeight = cursor.reduce((height, coord) => coord[1] > height ? coord[1] : height, 0) + 1

  const cellsX = width / 10
  const cellsY = cellsX / 2

  const offsetX = cellsX / 2 - cursorWidth / 2
  const offsetY = cellsY / 2 - cursorHeight / 2

  const curriedDrawRect = (x, y) => Canvas.drawRect(context, width, height, cellsX, cellsY, x, y)

  Canvas.clearCanvas(context, width, height)
  cursor.forEach(([x, y]) => {
    curriedDrawRect(x + offsetX, y + offsetY)
  })
}

// --- Export ------------------------------------------------------------------

export default init<commit_msg>render arbitrarily large cursor into canvas preview<commit_after>import { conf } from '../config.js'
import * as Canvas from '../utils/canvas.js'

// --- Config & Local state ----------------------------------------------------

const dom = {
  cursorCanvas: document.getElementById('cursor')
}

// --- Main methods ------------------------------------------------------------

const init = (store) => {
  const context = dom.cursorCanvas.getContext('2d')
  context.fillStyle = '#000'

  const width = 200
  const height = width / 2

  dom.cursorCanvas.width = width
  dom.cursorCanvas.style.width = width + 'px'
  dom.cursorCanvas.height = height
  dom.cursorCanvas.style.height = height + 'px'

  const cursor = conf.cursor.types[5]

  const cursorWidth = cursor.reduce((width, coord) => coord[0] > width ? coord[0] : width, 0) + 1
  const cursorHeight = cursor.reduce((height, coord) => coord[1] > height ? coord[1] : height, 0) + 1

  let cellsX = width / 10
  let cellsY = cellsX / 2

  const multiplier = Math.max(
    (cursorWidth + 2) / cellsX,
    (cursorHeight + 2) / cellsY,
  )

  if (multiplier > 1) {
    cellsX = cellsX * multiplier
    const wholeCell = Math.floor(width / cellsX)
    cellsX = width / wholeCell
    cellsY = cellsX / 2
  }

  const offsetX = cellsX / 2 - cursorWidth / 2
  const offsetY = cellsY / 2 - cursorHeight / 2

  const curriedDrawRect = (x, y) => Canvas.drawRect(context, width, height, cellsX, cellsY, x, y)

  Canvas.clearCanvas(context, width, height)
  cursor.forEach(([x, y]) => {
    curriedDrawRect(x + offsetX, y + offsetY)
  })
}

// --- Export ------------------------------------------------------------------

export default init
{'fraction_non_alphanumeric': 0.24078303425774877, 'fraction_numerical': 0.016965742251223492, 'mean_word_length': 2.0236686390532546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '749552', 'n_tokens_mistral': 943, 'n_tokens_neox': 882, 'n_words': 250}