<commit_before>
import ATTRIBUTE = require('../attribute/attribute');

export function map(targets: HTMLElement[], callback: (elem: HTMLElement, shiftKey: boolean) => any) {
  if (targets.length === 0) { return []; }
  
  const scrollTop = window.scrollY,
        scrollLeft = window.scrollX;
  const keys = '<KEY>'),
        container = document.createElement('div'),
        observer = document.createElement('input'),
        table = <{ [key: string]: HTMLElement }>{};
  observer.style.cssText = [
    'position: fixed;',
    'width: 0px;',
    'height: 0px;',
    'bottom: 0px;',
    'right: 0px;',
    'margin: 0px;',
    'border-width: 0px;',
    'padding: 0px;',
    'z-index: -1;'
  ]
  .map(str => str.split(';')[0] + ' !important;')
  .join('');
  observer.addEventListener('input', handler);
  observer.addEventListener('blur', handler);
  document.body.appendChild(observer);
  observer.focus();
  setTimeout(() => observer.focus(), 1000);
  document.body.appendChild(container);
  return targets.slice(0, keys.length)
    .map(target => {
      const marker = document.createElement('span'),
            key = keys.shift(),
            offset = calOffset(target);
      marker.classList.add(ATTRIBUTE.MARKER_TAG);
      marker.classList.add(ATTRIBUTE.MARKER_TAG + '-' + key);
      marker.style.cssText = [
        'position: absolute;',
        'overflow: visible;',
        'z-index: 9999;',
        'top: ' + (offset.top - 3) + 'px;',
        'left: ' + (offset.left - 12) + 'px;',
        'min-width: 5px;',
        'margin: 0px;',
        'border: 0px;',
        'padding: 1px 3px;',
        'border-radius: 3px;',
        'box-shadow: 1px 1px 1px 0px;',
        'background-color: gold;',
        'font-family: Helvetica, Arial, sans-serif;',
        'font-size: 13px;',
        'font-weight: bold;',
        'line-height: normal;',
        'color: black;'
      ]
      .map(str => str.split(';')[0] + ' !important;')
      .join('');
      marker.textContent = key;
      table[key] = target;
      container.appendChild(marker);
      return target;
    });

  function handler(event: KeyboardEvent) {
    event.preventDefault();
    event.stopImmediatePropagation();

    const key = ja2en((<any>event.target).value),<commit_msg>Improve content key map performance<commit_after>
import ATTRIBUTE = require('../attribute/attribute');

export function map(targets: HTMLElement[], callback: (elem: HTMLElement, shiftKey: boolean) => any) {
  if (targets.length === 0) { return []; }
  
  const scrollTop = window.scrollY,
        scrollLeft = window.scrollX;
  const keys = '<KEY>'),
        container = document.createElement('div'),
        observer = document.createElement('input'),
        table = <{ [key: string]: HTMLElement }>{};
  observer.style.cssText = [
    'position: fixed;',
    'width: 0px;',
    'height: 0px;',
    'bottom: 0px;',
    'right: 0px;',
    'margin: 0px;',
    'border-width: 0px;',
    'padding: 0px;',
    'z-index: -1;'
  ]
  .map(str => str.split(';')[0] + ' !important;')
  .join('');
  observer.addEventListener('input', handler);
  observer.addEventListener('blur', handler);
  document.body.appendChild(observer);
  observer.focus();
  setTimeout(() => observer.focus(), 1000);
  const markers = targets.slice(0, keys.length)
    .map(target => {
      const marker = document.createElement('span'),
            key = keys.shift(),
            offset = calOffset(target);
      marker.classList.add(ATTRIBUTE.MARKER_TAG);
      marker.classList.add(ATTRIBUTE.MARKER_TAG + '-' + key);
      marker.style.cssText = [
        'position: absolute;',
        'overflow: visible;',
        'z-index: 9999;',
        'top: ' + (offset.top - 3) + 'px;',
        'left: ' + (offset.left - 12) + 'px;',
        'min-width: 5px;',
        'margin: 0px;',
        'border: 0px;',
        'padding: 1px 3px;',
        'border-radius: 3px;',
        'box-shadow: 1px 1px 1px 0px;',
        'background-color: gold;',
        'font-family: Helvetica, Arial, sans-serif;',
        'font-size: 13px;',
        'font-weight: bold;',
        'line-height: normal;',
        'color: black;'
      ]
      .map(str => str.split(';')[0] + ' !important;')
      .join('');
      marker.textContent = key;
      table[key] = target;
      container.appendChild(marker);
      return target;
    });
  document.body.appendChild(container);
  return markers;

  function handler(event: KeyboardEvent) {
    event.preventDefault();
    event.stopImmediatePropagation();

    const key = ja2en((<any>event.target).value),
{'fraction_non_alphanumeric': 0.18221734357848518, 'fraction_numerical': 0.015806805708013173, 'mean_word_length': 2.7313677313677314, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '2180312', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1484, 'n_words': 296}