<commit_before>import * as control from '../control';
import * as side from './side';
import theme from './theme';
import changeColorHandle from 'common/coordsColor';
import chessground from './chessground';
import feedbackView from './feedback';
import { Controller } from '../interfaces';
import { h } from 'snabbdom'
import { onInsert, bind, bindMobileMousedown } from '../util';
import { render as treeView } from './tree';
import { view as cevalView } from 'ceval';
import { VNode } from 'snabbdom/vnode'

function renderAnalyse(ctrl: Controller): VNode {
  return h('div.puzzle__moves.areplay', [
    treeView(ctrl)
  ]);
}

function wheel(ctrl: Controller, e: WheelEvent): false | undefined {
  const target = e.target as HTMLElement;
  if (target.tagName !== 'PIECE' && target.tagName !== 'SQUARE' && target.tagName !== 'CG-BOARD') return;
  e.preventDefault();
  if (e.deltaY > 0) control.next(ctrl);
  else if (e.deltaY < 0) control.prev(ctrl);
  ctrl.redraw();
  return false;
}

function dataAct(e: Event): string | null {
  const target = e.target as HTMLElement;
  return target.getAttribute('data-act') || (target.parentNode as HTMLElement).getAttribute('data-act');
}

function jumpButton(icon: string, effect: string): VNode {
  return h('button.fbt', {
    attrs: {
      'data-act': effect,
      'data-icon': icon
    }
  });
}

function controls(ctrl: Controller): VNode {
  return h('div.puzzle__controls.analyse-controls', {
    hook: onInsert(el => {
      bindMobileMousedown(el, e => {
        const action = dataAct(e);
        if (action === 'prev') control.prev(ctrl);
        else if (action === 'next') control.next(ctrl);
        else if (action === 'first') control.first(ctrl);
        else if (action === 'last') control.last(ctrl);
      }, ctrl.redraw);
    })
  }, [
    h('div.jumps', [
      jumpButton('W', 'first'),
      jumpButton('Y', 'prev'),
      jumpButton('X', 'next'),
      jumpButton('V', 'last')
    ])
  ]);
}

let cevalShown = false;

export default function(ctrl: Controller): VNode {
  const showCeval = ctrl.vm.showComputer(),
    gaugeOn = ctrl.showEvalGauge();
  if (cevalShown !== showCeval) {
    if (!cevalShown) ctrl.vm.autoScrollNow = true;
    cevalShown = showCeval;
  }
  return h('main.puzzle', {
    class: { 'gauge-on': gaugeOn },<commit_msg>improve puzzle controls<commit_after>import * as control from '../control';
import * as side from './side';
import theme from './theme';
import changeColorHandle from 'common/coordsColor';
import chessground from './chessground';
import feedbackView from './feedback';
import { Controller } from '../interfaces';
import { h } from 'snabbdom'
import { onInsert, bind, bindMobileMousedown } from '../util';
import { render as treeView } from './tree';
import { view as cevalView } from 'ceval';
import { VNode } from 'snabbdom/vnode'

function renderAnalyse(ctrl: Controller): VNode {
  return h('div.puzzle__moves.areplay', [
    treeView(ctrl)
  ]);
}

function wheel(ctrl: Controller, e: WheelEvent): false | undefined {
  const target = e.target as HTMLElement;
  if (target.tagName !== 'PIECE' && target.tagName !== 'SQUARE' && target.tagName !== 'CG-BOARD') return;
  e.preventDefault();
  if (e.deltaY > 0) control.next(ctrl);
  else if (e.deltaY < 0) control.prev(ctrl);
  ctrl.redraw();
  return false;
}

function dataAct(e: Event): string | null {
  const target = e.target as HTMLElement;
  return target.getAttribute('data-act') || (target.parentNode as HTMLElement).getAttribute('data-act');
}

function jumpButton(icon: string, effect: string, disabled: boolean): VNode {
  return h('button.fbt', {
    class: { disabled },
    attrs: {
      'data-act': effect,
      'data-icon': icon
    }
  });
}

function controls(ctrl: Controller): VNode {
  const node = ctrl.vm.node;
  return h('div.puzzle__controls.analyse-controls', {
    hook: onInsert(el => {
      bindMobileMousedown(el, e => {
        const action = dataAct(e);
        if (action === 'prev') control.prev(ctrl);
        else if (action === 'next') control.next(ctrl);
        else if (action === 'first') control.first(ctrl);
        else if (action === 'last') control.last(ctrl);
      }, ctrl.redraw);
    })
  }, [
    h('div.jumps', [
      jumpButton('W', 'first', !node.ply),
      jumpButton('Y', 'prev', !node.ply),
      jumpButton('X', 'next', !node.children[0]),
      jumpButton('V', 'last', !node.children[0])
    ])
  ]);
}

let cevalShown = false;

export default function(ctrl: Controller): VNode {
  const showCeval = ctrl.vm.showComputer(),
    gaugeOn = ctrl.showEvalGauge();
  if (cevalShown !== showCeval) {
    if (!cevalShown) ctrl.vm.autoScrollNow = true;
    cevalShown = showCeval;
  }
  return h('main.puzzle', {
    class: { 'gauge-on': gaugeOn },
{'fraction_non_alphanumeric': 0.16642213372458603, 'fraction_numerical': 0.0012575979878432194, 'mean_word_length': 3.6285160038797284, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1523417', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1550, 'n_words': 399}