<commit_before>class Jax.Input.Mouse extends Jax.Input
  @eventTypes:
    press:   'mousedown'
    release: 'mouseup'
    move:    'mousemove'
    over:    'mouseover'
    wheel:   'mousewheel'
    exit:    'mouseout'
    
  ###
  Click speed, in seconds. The lower this number, the faster the
  mouse must be pressed and released in order to result in a single click.
  Defaults to 0.25.
  ###
  @define 'clickSpeed',
    get: -> @_clickSpeed or= 0.25
    set: (speed) -> @_clickSpeed = speed
  
  constructor: (element) ->
    super element
    @_pendingClicks = {}
    @_clickCount = {}
    @_buttonState = {}
  
  ###
  Programmatically triggers an event. Note that because Jax uses
  `addEventListener`, you can't trigger events using jQuery. Instead,
  you have to either trigger events through the DOM methods, or use this 
  method.
  ###
  trigger: (type, evt = {}) ->
    if type is 'click'
      @trigger 'mousedown', evt
      @trigger 'mouseup',   evt
      return
    event = document.createEvent 'MouseEvents'
    event.initMouseEvent type, true,               \ # type, bubbles, 
                         true,                     \ # cancelable,
                         window,                   \ # windowObject
                         1,                        \ # detail
                         evt.screenX, evt.screenY, \ # screenX, screenY
                         evt.clientX, evt.clientY, \ # clientX, clientY
                         false, false,             \ # ctrlKey, altKey
                         false, false,             \ # shiftKey, metaKey
                         evt.button, null            # button, relatedTarget
    @receiver.dispatchEvent event
    
  processEvent: (type, evt) ->
    evt = @normalizeEvent evt
    super type, evt
    
  ###
  Preprocesses the mouse event, adding the following attributes:
  
  * `x`: the X coordinate of the mouse event, relative to the
         @receiver element, in pixels, scaled from the element's
         actual size to the size of the element's render buffer.
  * `y`: the Y coordinate of the mouse event, relative to the
         @receiver element, in pixels, scaled from the element's
         actual size to the size of the element's render buffer.
  * `diffx`: the change in `x` between the last event and this
  * `diffy`: the change in `y` between the last event and this
  
  Returns the normalized event.
  ###
  normalizeEvent: (evt) ->
    rect = @receiver.getBoundingClientRect()
    root = document.documentElement
    evt =
      base: evt
      button: evt.button
      x: evt.clientX - rect.left
      y: evt.clientY - rect.top
    evt.x *= @receiver.width / rect.width
    evt.y *= @receiver.height/ rect.height
    if @_lastx is undefined
      evt.diffx = evt.diffy = 0
    else
      [evt.diffx, evt.diffy] = [evt.x - @_lastx, evt.y - @_lasty]
    [@_lastx, @_lasty] = [evt.x, evt.y]
    evt
  
  update: (timechange) ->
    for button of @_pendingClicks
      @_pendingClicks[button] += timechange
      if @_pendingClicks[button] >= @clickSpeed
        @clearClick button
    true
    
  logClickStart: (button) ->
    @_pendingClicks[button] = 0
    @_clickCount[button] = (@_clickCount[button] || 0) + 1
    
  clearClick: (button) ->
    delete @_pendingClicks[button]
    delete @_clickCount[button]
  
  listen: (type, callback) ->
    switch type
      when 'enter'
        super 'over'
        super 'exit'
        @addEventListener 'enter', callback if callback
      when 'move', 'click', 'wheel'
        super 'move'
        super 'press'
        super 'release'
        @addEventListener type, callback if callback
      when 'drag'
        super 'move'
        super 'press'
        super 'release'
        super 'exit'
        @addEventListener type, callback if callback
      else super type, callback
      
  press: (e) ->
    @fireEvent 'press', e
    @logClickStart e.button
    @_buttonState[e.button] = true
    
  release: (e) ->
    @fireEvent 'release', e
    @_buttonState[e.button] = false
    if @_pendingClicks[e.button] isnt undefined
      e.clickCount = @_clickCount[e.button]<commit_msg>reflexion required...<commit_after>class Jax.Input.Mouse extends Jax.Input
  @eventTypes:
    press:   'mousedown'
    release: 'mouseup'
    move:    'mousemove'
    over:    'mouseover'
    wheel:   'mousewheel'
    exit:    'mouseout'
    
  ###
  Click speed, in seconds. The lower this number, the faster the
  mouse must be pressed and released in order to result in a single click.
  Defaults to 0.25.
  ###
  @define 'clickSpeed',
    get: -> @_clickSpeed or= 0.25
    set: (speed) -> @_clickSpeed = speed
  
  constructor: (element) ->
    super element
    @_pendingClicks = {}
    @_clickCount = {}
    @_buttonState = {}
  
  ###
  Programmatically triggers an event. Note that because Jax uses
  `addEventListener`, you can't trigger events using jQuery. Instead,
  you have to either trigger events through the DOM methods, or use this 
  method.
  ###
  trigger: (type, evt = {}) ->
    if type is 'click'
      @trigger 'mousedown', evt
      @trigger 'mouseup',   evt
      return
    event = document.createEvent 'MouseEvents'
    event.initMouseEvent type, true,               \ # type, bubbles, 
                         true,                     \ # cancelable,
                         window,                   \ # windowObject
                         1,                        \ # detail
                         evt.screenX, evt.screenY, \ # screenX, screenY
                         evt.clientX, evt.clientY, \ # clientX, clientY
                         false, false,             \ # ctrlKey, altKey
                         false, false,             \ # shiftKey, metaKey
                         evt.button, null            # button, relatedTarget
    @receiver.dispatchEvent event
    
  processEvent: (type, evt) ->
    evt = @normalizeEvent evt
    super type, evt
    
  ###
  Preprocesses the mouse event, adding the following attributes:
  
  * `x`: the X coordinate of the mouse event, relative to the
         @receiver element, in pixels, scaled from the element's
         actual size to the size of the element's render buffer.
  * `y`: the Y coordinate of the mouse event, relative to the
         @receiver element, in pixels, scaled from the element's
         actual size to the size of the element's render buffer.
  * `diffx`: the change in `x` between the last event and this
  * `diffy`: the change in `y` between the last event and this
  
  Returns the normalized event.
  ###
  normalizeEvent: (evt) ->
    rect = @receiver.getBoundingClientRect()
    root = document.documentElement
    evt =
      base: evt
      button: evt.button
      x: evt.clientX - rect.left
      y: evt.clientY - rect.top
    evt.x *= @receiver.width / rect.width
    evt.y *= @receiver.height/ rect.height
    if @_lastx is undefined
      evt.diffx = evt.diffy = 0
    else
      [evt.diffx, evt.diffy] = [evt.x - @_lastx, evt.y - @_lasty]
    [@_lastx, @_lasty] = [evt.x, evt.y]
    evt
  
  update: (timechange) ->
    for button of @_pendingClicks
      @_pendingClicks[button] += timechange
      if @_pendingClicks[button] >= @clickSpeed
        @clearClick button
    true
    
  logClickStart: (button) ->
    @_pendingClicks[button] = 0
    @_clickCount[button] = (@_clickCount[button] || 0) + 1
    
  clearClick: (button) ->
    delete @_pendingClicks[button]
    delete @_clickCount[button]
  
  listen: (type, callback) ->
    switch type
      when 'enter'
        super 'over'
        super 'exit'
        @addEventListener 'enter', callback if callback
      when 'move', 'click'
        super 'move'
        super 'press'
        super 'release'
        @addEventListener type, callback if callback
      when 'drag'
        super 'move'
        super 'press'
        super 'release'
        super 'exit'
        @addEventListener type, callback if callback
      else super type, callback
      
  press: (e) ->
    @fireEvent 'press', e
    @logClickStart e.button
    @_buttonState[e.button] = true
    
  release: (e) ->
    @fireEvent 'release', e
    @_buttonState[e.button] = false
    if @_pendingClicks[e.button] isnt undefined
      e.clickCount = @_clickCount[e.button]
{'fraction_non_alphanumeric': 0.1000363328085261, 'fraction_numerical': 0.0026644059585805985, 'mean_word_length': 2.0029090909090908, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6195088', 'n_tokens_mistral': 2481, 'n_tokens_neox': 2460, 'n_words': 771}