<commit_before>import {combineLatestObj} from './obsUtils'


export function clearCursor(element=document.body){
  element.style.cursor = 'default' 
}

//ui utils
export function toggleCursor(toggle, cursorName, element=document.body){
  if(toggle)
  {
    element.style.cursor = cursorName
  }else{
    element.style.cursor = 'default'
  }
  return toggle
}

export function getXY(e){
  var posx = 0;
  var posy = 0;
  if (!e) var e = window.event;
  if (e.pageX || e.pageY)     {
      posx = e.pageX;
      posy = e.pageY;
  }
  else if (e.clientX || e.clientY)     {
      posx = e.clientX + document.body.scrollLeft
          + document.documentElement.scrollLeft;
      posy = e.clientY + document.body.scrollTop
          + document.documentElement.scrollTop;
  }
  // posx and posy contain the mouse position relative to the document
  // Do something with this information
  let {x,y} = getOffset(e.target)

  return {  x:x+posx, y:y+posy }
}

/*from http://stackoverflow.com/questions/442404/retrieve-the-position-x-y-of-an-html-element#answer-442474*/
export function getOffset( el ) {
  var el2 = el;
  var curtop = 0;
  var curleft = 0;
  if (document.getElementById || document.all) {
      do  {
          curleft += el.offsetLeft-el.scrollLeft;
          curtop += el.offsetTop-el.scrollTop;
          el = el.offsetParent;
          el2 = el2.parentNode;
          while (el2 != el) {
              curleft -= el2.scrollLeft;
              curtop -= el2.scrollTop;
              el2 = el2.parentNode;
          }
      } while (el.offsetParent);

  } else if (document.layers) {
      curtop += el.y;
      curleft += el.x;
  }
    return { top: curtop, left: curleft, x:curleft, y:curtop }
}

/*prepare observables for rendering , by extracting the DOM object*/
export function prepForRender(params, suffix)
{
  suffix = suffix || "Ui"

  const DOMS = Object.keys(params)
    .reduce(function(prev,cur){
      let key = cur.replace(suffix,"")
      if("DOM" in params[cur]){
        prev[key] = params[cur].DOM
      }else{
        prev[key] = params[cur]
      }
      console.log("prev",prev)
      return prev
    },{})<commit_msg>- minor cleanup of uiUtils<commit_after>import {combineLatestObj} from './obsUtils'


export function clearCursor(element=document.body){
  element.style.cursor = 'default' 
}

//ui utils
export function toggleCursor(toggle, cursorName, element=document.body){
  if(toggle)
  {
    element.style.cursor = cursorName
  }else{
    element.style.cursor = 'default'
  }
  return toggle
}

export function getXY(e){
  var posx = 0;
  var posy = 0;
  if (!e) var e = window.event;
  if (e.pageX || e.pageY)     {
      posx = e.pageX;
      posy = e.pageY;
  }
  else if (e.clientX || e.clientY)     {
      posx = e.clientX + document.body.scrollLeft
          + document.documentElement.scrollLeft;
      posy = e.clientY + document.body.scrollTop
          + document.documentElement.scrollTop;
  }
  // posx and posy contain the mouse position relative to the document
  // Do something with this information
  let {x,y} = getOffset(e.target)

  return {  x:x+posx, y:y+posy }
}

/*from http://stackoverflow.com/questions/442404/retrieve-the-position-x-y-of-an-html-element#answer-442474*/
export function getOffset( el ) {
  var el2 = el;
  var curtop = 0;
  var curleft = 0;
  if (document.getElementById || document.all) {
      do  {
          curleft += el.offsetLeft-el.scrollLeft;
          curtop += el.offsetTop-el.scrollTop;
          el = el.offsetParent;
          el2 = el2.parentNode;
          while (el2 != el) {
              curleft -= el2.scrollLeft;
              curtop -= el2.scrollTop;
              el2 = el2.parentNode;
          }
      } while (el.offsetParent);

  } else if (document.layers) {
      curtop += el.y;
      curleft += el.x;
  }
    return { top: curtop, left: curleft, x:curleft, y:curtop }
}

/*prepare observables for rendering , by extracting the DOM object*/
export function prepForRender(params, suffix)
{
  suffix = suffix || "Ui"

  const DOMS = Object.keys(params)
    .reduce(function(prev,cur){
      let key = cur.replace(suffix,"")
      if("DOM" in params[cur]){
        prev[key] = params[cur].DOM
      }else{
        prev[key] = params[cur]
      }
      return prev
    },{})
{'fraction_non_alphanumeric': 0.12995800279981334, 'fraction_numerical': 0.011199253383107793, 'mean_word_length': 2.462843295638126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4471946', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1426, 'n_words': 333}