<commit_before>// Copyright 2014 Technical Machine, Inc. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

var tessel = require('tessel');
var events = require('events');
var util = require('util');
var vclib = require('vclib');
var Queue = require('sink_q');

var DEBUG = false;
var COMPRESSION_RANGE = 255;

function Camera (hardware, options, callback) {
  // Set the port
  this.hardware = hardware;
  this.queue = new Queue();
  // Reassign the callback if options weren't provided
  if (arguments.length == 2) {
    if (Object.prototype.toString.call(options) == "[object Function]") {
      callback = options;
      options = null;
    }
  }
  // Set a new library for sending/receiving data
  this.vclib = new vclib();
  // Start up UART
  this.uart = hardware.UART({baudrate : 115200});
  // Turn the camera on!
  hardware.digital[2].output().high();

  // Attempt to read the version of firmware
  this._getVersion(function(err, version) {
    // If there was a problem
    if (err || !version) {
      // Report an error
      setImmediate(function() {
        this.emit('error', new Error("Unable to receive responses from module."));
      }.bind(this));
    } else {
      if (options) {
        if (options.compression) {
          this.setCompression(options.compression, function(err) {
            if (err) {
              this.emit('error', err);
            }
          }.bind(this));
        }
        if (options.resolution) {
          this.setResolution(options.resolution, function(err) {
            if (err) {
              this.emit('error', err);
            }
          }.bind(this));
        }
      }
      // Report that we are open for business
      setImmediate(function() {
        this.emit('ready');
        this.queue.ready();
      }.bind(this));
    }

    // Call the callback
    if (callback) {
      callback(err, this);
    }
    return this;

  }.bind(this));
}

util.inherits(Camera, events.EventEmitter);

Camera.prototype._captureImageData = function(imgSize, callback) {

   // Intialize SPI
  var spi = this.hardware.SPI({role:'slave'});

  // Send the command to read the number of bytes
  this._readFrameBuffer(imgSize, function imageReadCommandSent(err) {
    // If there was a problem, report it
    if (err) {
      return callback(err);
    } else {
      // Begin the transfer
      spi.receive(imgSize, function imageDataRead(err, image){
        if (err) {
          if (callback) {
            callback(err);
          }
          return;
        } else {
          // Close SPI
          spi.close();
          if (callback) {
            callback(null, image);
          }
          return;
        }
      }.bind(this));
    }
  }.bind(this));
};

Camera.prototype._getFrameBufferLength = function(callback) {
  this._sendCommand("bufferLength", callback);
};

Camera.prototype._getImageMetaData = function(callback) {
  // Stop the frame buffer (capture the image...)
  this._stopFrameBuffer(function imageFrameStopped(err) {

    if (err) {
      if (callback) {
        callback(err);
      }
      return;
    } else {
      // Get the size of the image to capture
      this._getFrameBufferLength(function imageLengthRead(err, imgSize) {
        // If there was a problem, report it
        if (err) {
          if (callback) {
            callback(err);
          }
          return;
        } else {
          if (callback) {
            callback(null, imgSize);
          }
          return;
        }
      }.bind(this));
    }
  }.bind(this));
};

// Get the version of firmware on the camera. Typically only used for debugging.
Camera.prototype._getVersion = function (callback){
  this._sendCommand("version", callback);
};

Camera.prototype._readFrameBuffer = function(length, callback) {
  this._sendCommand("readFrameSPI", {"length":length}, callback);
};

Camera.prototype._reset = function(callback) {
  // Tell the module to reset
  this._sendCommand('reset', function(err) {
    // If there was a problem
    if (err) {
      // Report it immediately
      callback(err);
    } else {
      // Wait for the camera to reset
      setTimeout(callback, 300);
    }
  });
};

Camera.prototype._resolveCapture = function(image, callback) {
  // Wait for the camera to tell us it's finished
  this._waitForImageReadACK(function ACKed(err) {
    // Report any errors
    if (err) {
      if (callback) {
        callback(err);
      }
      return;
    } else {
      // Resume frame capturing again
      this._resumeFrameBuffer(function frameResumed(err) {
        // Report any errors
        if (err) {
          if (callback) {
            callback(err);
          }
          return;
        } else {
          // Call the callback
          if (callback) {
            callback(null, image);
          }
          // Emit the picture
          setImmediate(function() {
            this.emit('picture', image);
          }.bind(this));
        }
      }.bind(this));
    }
  }.bind(this));
};

Camera.prototype._resumeFrameBuffer = function(callback) {
  this._sendCommand("frameControl", {command:'resume'}, callback);
};

Camera.prototype._sendCommand = function(apiCommand, args, callback) {
  // If Args weren't passed in, correct the callback
  if (typeof args === 'function') {
    callback = args;
    args = {};
  }
  if (!args) {
    args = {};
  }

  var self = this;
  var timeout;

  // Get the command packet for the request api call
  self.vclib.getCommandPacket(apiCommand, args, function(err, command) {

    if (err) {
      if (callback) {
        callback(err);
      }
      return;
    }

    function UARTDataParser(data) {
      // Try to parse the response (might take several calls)
      self.vclib.parseIncoming(command, data, function(err, packet) {

        // Clear no-data timeout
        clearTimeout(timeout);

        // If it was parsed
        if (err || packet) {
          // Grab the response if available
          var response = packet ? packet.response : null;
          // Remove this listener
          self.uart.removeListener('data', UARTDataParser);
          // Call the callback. Transaction complete
          if (callback) callback(err, response);
          return;
        }
      });
    }

    // Set up a temporary listener... listening for response
    self.uart.on('data', UARTDataParser);

    // Send the command data
    self.uart.write(command.buffer);

    timeout = setTimeout(function noResponse() {
      // Remove the listener
      self.uart.removeListener('data', UARTDataParser);

      // Throw an error
      if (callback) {
        callback(new Error("No UART Response..."));
      }
      return;

    }, 2000);
  });
};

Camera.prototype._stopFrameBuffer = function(callback) {
  this._sendCommand("frameControl", {command:'stop'}, callback);
};

Camera.prototype._waitForImageReadACK = function(callback) {
  var self = this;
  self.vclib.getCommandPacket('readFrameSPI', function foundCommand(err, command) {
    self.uart.on('data', function dataACKParsing(data) {
      self.vclib.parseIncoming(command, data, function vclibDataParsed(err, packet) {
        if (err || packet) {

          self.uart.removeListener('data', dataACKParsing);

          if (callback) {
            callback(err);
          }
          return;
        }
      });
    });
  });
};

// Close camera connection
Camera.prototype.disable = function () {
  this.queue.push(function () {
    this.uart.disable();
  }.bind(this));
};

// Set the compression of the images captured. Automatically resets the camera and returns after completion.
Camera.prototype.setCompression = function(compression, callback) {
  this.queue.push(function (callback) {
    this._sendCommand("compression", {
      "ratio": Math.floor(compression*COMPRESSION_RANGE)<0 ? 0 : Math.floor(compression*COMPRESSION_RANGE)>COMPRESSION_RANGE ? COMPRESSION_RANGE : Math.floor(compression*COMPRESSION_RANGE)
    }, function(err) {
      if (err) {
        if (callback) {
          callback(err);
        }
        return;
      } else {
        this._reset(function(err) {
          if (callback) {
            callback(err);
          }

          setImmediate(function() {
            this.emit('compression', compression);
          }.bind(this));

          return;
        }.bind(this));
      }
    }.bind(this));
  }.bind(this), callback);
};

// Gets the compression ratio of the images captured. Returns value from [0, 1].
Camera.prototype.getCompression = function(callback) {
  this.queue.push(function (callback) {
    this._sendCommand("getCompression", function(err, compressionRatioRaw) {
      if (err) {
        if (callback) {
          callback(err);
        }
        return;
      } else {
        this._reset(function(err) {
          var compressionRatio = (compressionRatioRaw * 1/255); // Maps from [0,255] -> [0,1]
          if (err) {
            if (callback) {
              callback(err);
            }
          } else {
            if (callback) {
              callback(null, compressionRatio);
            }
          }
          setImmediate(function() {
            this.emit('getCompression', compressionRatio);
          }.bind(this));

        }.bind(this));
      }
    }.bind(this));
  }.bind(this), callback);
};

// Set the resolution of the images captured. Automatically resets the camera and returns after completion.
Camera.prototype.setResolution = function(resolution, callback) {
  this.queue.push(function (callback) {
    this._sendCommand("resolution", {"size":resolution}, function(err) {
      if (err) {
        if (callback) {
          callback(err);
        }
        return;
      } else {
        this._reset(function(err) {
          if (callback) {
            callback(err);
          }

          setImmediate(function() {
            this.emit('resolution', resolution);
          }.bind(this));

        }.bind(this));
      }
    }.bind(this));
  }.bind(this), callback);
};

// Gets the resolution of the images captured.
Camera.prototype.getResolution = function(callback) {
  this.queue.push(function (callback) {
    this._sendCommand("getResolution", function(err, resolutionRaw) {
      if (err) {
        if (callback) {
          callback(err);
        }
        return;
      } else {
        this._reset(function(err) {
          var resolution = (resolutionRaw == 0x00) ? 'vga' : (resolutionRaw == 0x11) ? 'qvga' : 'qqvga';
          if (err) {
            if (callback) {
              callback(err);
            }
          } else {
            if (callback) {
              callback(null, resolution);
            }
          }

          setImmediate(function() {
            this.emit('getResolution', resolution);
          }.bind(this));

        }.bind(this));
      }
    }.bind(this));
  }.bind(this), callback);
};

// Primary method for capturing an image. Actually transfers the image over SPI Slave as opposed to UART.
Camera.prototype.takePicture = function(callback) {
  // Pictures are placed in a queue so that users can call takePicture before ready event
  this.queue.push(function (callback) {
    // Get data about how many bytes to read
    this._getImageMetaData(function foundMetaData(err, imageLength) {
      if (err) {
        if (callback) {
          callback(err);
        }
        return;
      } else {
        // Capture the actual data
        this._captureImageData(imageLength, function imageCaptured(err, image) {
          // Wait for the camera to be ready to continue
          if (err) {
            if (callback) callback(err);
            return;
          } else {
            this._resolveCapture(image, callback);
          }
        }.bind(this));
      }
    }.bind(this));
  }.bind(this), callback);
};

function use(hardware, options, callback) {
  var camera = new Camera(hardware, options, callback);
  return camera;
}

module.exports.Camera = Camera;
module.exports.use = use;
module.exports.COMPRESSION_RANGE = COMPRESSION_RANGE;
module.exports.resolutions = vclib.resolutions;
<commit_msg>changed magic number 255 to COMPRESSION_RANGE<commit_after>// Copyright 2014 Technical Machine, Inc. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

var tessel = require('tessel');
var events = require('events');
var util = require('util');
var vclib = require('vclib');
var Queue = require('sink_q');

var DEBUG = false;
var COMPRESSION_RANGE = 255;

function Camera (hardware, options, callback) {
  // Set the port
  this.hardware = hardware;
  this.queue = new Queue();
  // Reassign the callback if options weren't provided
  if (arguments.length == 2) {
    if (Object.prototype.toString.call(options) == "[object Function]") {
      callback = options;
      options = null;
    }
  }
  // Set a new library for sending/receiving data
  this.vclib = new vclib();
  // Start up UART
  this.uart = hardware.UART({baudrate : 115200});
  // Turn the camera on!
  hardware.digital[2].output().high();

  // Attempt to read the version of firmware
  this._getVersion(function(err, version) {
    // If there was a problem
    if (err || !version) {
      // Report an error
      setImmediate(function() {
        this.emit('error', new Error("Unable to receive responses from module."));
      }.bind(this));
    } else {
      if (options) {
        if (options.compression) {
          this.setCompression(options.compression, function(err) {
            if (err) {
              this.emit('error', err);
            }
          }.bind(this));
        }
        if (options.resolution) {
          this.setResolution(options.resolution, function(err) {
            if (err) {
              this.emit('error', err);
            }
          }.bind(this));
        }
      }
      // Report that we are open for business
      setImmediate(function() {
        this.emit('ready');
        this.queue.ready();
      }.bind(this));
    }

    // Call the callback
    if (callback) {
      callback(err, this);
    }
    return this;

  }.bind(this));
}

util.inherits(Camera, events.EventEmitter);

Camera.prototype._captureImageData = function(imgSize, callback) {

   // Intialize SPI
  var spi = this.hardware.SPI({role:'slave'});

  // Send the command to read the number of bytes
  this._readFrameBuffer(imgSize, function imageReadCommandSent(err) {
    // If there was a problem, report it
    if (err) {
      return callback(err);
    } else {
      // Begin the transfer
      spi.receive(imgSize, function imageDataRead(err, image){
        if (err) {
          if (callback) {
            callback(err);
          }
          return;
        } else {
          // Close SPI
          spi.close();
          if (callback) {
            callback(null, image);
          }
          return;
        }
      }.bind(this));
    }
  }.bind(this));
};

Camera.prototype._getFrameBufferLength = function(callback) {
  this._sendCommand("bufferLength", callback);
};

Camera.prototype._getImageMetaData = function(callback) {
  // Stop the frame buffer (capture the image...)
  this._stopFrameBuffer(function imageFrameStopped(err) {

    if (err) {
      if (callback) {
        callback(err);
      }
      return;
    } else {
      // Get the size of the image to capture
      this._getFrameBufferLength(function imageLengthRead(err, imgSize) {
        // If there was a problem, report it
        if (err) {
          if (callback) {
            callback(err);
          }
          return;
        } else {
          if (callback) {
            callback(null, imgSize);
          }
          return;
        }
      }.bind(this));
    }
  }.bind(this));
};

// Get the version of firmware on the camera. Typically only used for debugging.
Camera.prototype._getVersion = function (callback){
  this._sendCommand("version", callback);
};

Camera.prototype._readFrameBuffer = function(length, callback) {
  this._sendCommand("readFrameSPI", {"length":length}, callback);
};

Camera.prototype._reset = function(callback) {
  // Tell the module to reset
  this._sendCommand('reset', function(err) {
    // If there was a problem
    if (err) {
      // Report it immediately
      callback(err);
    } else {
      // Wait for the camera to reset
      setTimeout(callback, 300);
    }
  });
};

Camera.prototype._resolveCapture = function(image, callback) {
  // Wait for the camera to tell us it's finished
  this._waitForImageReadACK(function ACKed(err) {
    // Report any errors
    if (err) {
      if (callback) {
        callback(err);
      }
      return;
    } else {
      // Resume frame capturing again
      this._resumeFrameBuffer(function frameResumed(err) {
        // Report any errors
        if (err) {
          if (callback) {
            callback(err);
          }
          return;
        } else {
          // Call the callback
          if (callback) {
            callback(null, image);
          }
          // Emit the picture
          setImmediate(function() {
            this.emit('picture', image);
          }.bind(this));
        }
      }.bind(this));
    }
  }.bind(this));
};

Camera.prototype._resumeFrameBuffer = function(callback) {
  this._sendCommand("frameControl", {command:'resume'}, callback);
};

Camera.prototype._sendCommand = function(apiCommand, args, callback) {
  // If Args weren't passed in, correct the callback
  if (typeof args === 'function') {
    callback = args;
    args = {};
  }
  if (!args) {
    args = {};
  }

  var self = this;
  var timeout;

  // Get the command packet for the request api call
  self.vclib.getCommandPacket(apiCommand, args, function(err, command) {

    if (err) {
      if (callback) {
        callback(err);
      }
      return;
    }

    function UARTDataParser(data) {
      // Try to parse the response (might take several calls)
      self.vclib.parseIncoming(command, data, function(err, packet) {

        // Clear no-data timeout
        clearTimeout(timeout);

        // If it was parsed
        if (err || packet) {
          // Grab the response if available
          var response = packet ? packet.response : null;
          // Remove this listener
          self.uart.removeListener('data', UARTDataParser);
          // Call the callback. Transaction complete
          if (callback) callback(err, response);
          return;
        }
      });
    }

    // Set up a temporary listener... listening for response
    self.uart.on('data', UARTDataParser);

    // Send the command data
    self.uart.write(command.buffer);

    timeout = setTimeout(function noResponse() {
      // Remove the listener
      self.uart.removeListener('data', UARTDataParser);

      // Throw an error
      if (callback) {
        callback(new Error("No UART Response..."));
      }
      return;

    }, 2000);
  });
};

Camera.prototype._stopFrameBuffer = function(callback) {
  this._sendCommand("frameControl", {command:'stop'}, callback);
};

Camera.prototype._waitForImageReadACK = function(callback) {
  var self = this;
  self.vclib.getCommandPacket('readFrameSPI', function foundCommand(err, command) {
    self.uart.on('data', function dataACKParsing(data) {
      self.vclib.parseIncoming(command, data, function vclibDataParsed(err, packet) {
        if (err || packet) {

          self.uart.removeListener('data', dataACKParsing);

          if (callback) {
            callback(err);
          }
          return;
        }
      });
    });
  });
};

// Close camera connection
Camera.prototype.disable = function () {
  this.queue.push(function () {
    this.uart.disable();
  }.bind(this));
};

// Set the compression of the images captured. Automatically resets the camera and returns after completion.
Camera.prototype.setCompression = function(compression, callback) {
  this.queue.push(function (callback) {
    this._sendCommand("compression", {
      "ratio": Math.floor(compression*COMPRESSION_RANGE)<0 ? 0 : Math.floor(compression*COMPRESSION_RANGE)>COMPRESSION_RANGE ? COMPRESSION_RANGE : Math.floor(compression*COMPRESSION_RANGE)
    }, function(err) {
      if (err) {
        if (callback) {
          callback(err);
        }
        return;
      } else {
        this._reset(function(err) {
          if (callback) {
            callback(err);
          }

          setImmediate(function() {
            this.emit('compression', compression);
          }.bind(this));

          return;
        }.bind(this));
      }
    }.bind(this));
  }.bind(this), callback);
};

// Gets the compression ratio of the images captured. Returns value from [0, 1].
Camera.prototype.getCompression = function(callback) {
  this.queue.push(function (callback) {
    this._sendCommand("getCompression", function(err, compressionRatioRaw) {
      if (err) {
        if (callback) {
          callback(err);
        }
        return;
      } else {
        this._reset(function(err) {
          var compressionRatio = (compressionRatioRaw * 1/COMPRESSION_RANGE); // Maps from [0,255] -> [0,1]
          if (err) {
            if (callback) {
              callback(err);
            }
          } else {
            if (callback) {
              callback(null, compressionRatio);
            }
          }
          setImmediate(function() {
            this.emit('getCompression', compressionRatio);
          }.bind(this));

        }.bind(this));
      }
    }.bind(this));
  }.bind(this), callback);
};

// Set the resolution of the images captured. Automatically resets the camera and returns after completion.
Camera.prototype.setResolution = function(resolution, callback) {
  this.queue.push(function (callback) {
    this._sendCommand("resolution", {"size":resolution}, function(err) {
      if (err) {
        if (callback) {
          callback(err);
        }
        return;
      } else {
        this._reset(function(err) {
          if (callback) {
            callback(err);
          }

          setImmediate(function() {
            this.emit('resolution', resolution);
          }.bind(this));

        }.bind(this));
      }
    }.bind(this));
  }.bind(this), callback);
};

// Gets the resolution of the images captured.
Camera.prototype.getResolution = function(callback) {
  this.queue.push(function (callback) {
    this._sendCommand("getResolution", function(err, resolutionRaw) {
      if (err) {
        if (callback) {
          callback(err);
        }
        return;
      } else {
        this._reset(function(err) {
          var resolution = (resolutionRaw == 0x00) ? 'vga' : (resolutionRaw == 0x11) ? 'qvga' : 'qqvga';
          if (err) {
            if (callback) {
              callback(err);
            }
          } else {
            if (callback) {
              callback(null, resolution);
            }
          }

          setImmediate(function() {
            this.emit('getResolution', resolution);
          }.bind(this));

        }.bind(this));
      }
    }.bind(this));
  }.bind(this), callback);
};

// Primary method for capturing an image. Actually transfers the image over SPI Slave as opposed to UART.
Camera.prototype.takePicture = function(callback) {
  // Pictures are placed in a queue so that users can call takePicture before ready event
  this.queue.push(function (callback) {
    // Get data about how many bytes to read
    this._getImageMetaData(function foundMetaData(err, imageLength) {
      if (err) {
        if (callback) {
          callback(err);
        }
        return;
      } else {
        // Capture the actual data
        this._captureImageData(imageLength, function imageCaptured(err, image) {
          // Wait for the camera to be ready to continue
          if (err) {
            if (callback) callback(err);
            return;
          } else {
            this._resolveCapture(image, callback);
          }
        }.bind(this));
      }
    }.bind(this));
  }.bind(this), callback);
};

function use(hardware, options, callback) {
  var camera = new Camera(hardware, options, callback);
  return camera;
}

module.exports.Camera = Camera;
module.exports.use = use;
module.exports.COMPRESSION_RANGE = COMPRESSION_RANGE;
module.exports.resolutions = vclib.resolutions;
<|endoftext|>


<commit_before>/* global hexo */

'use strict';

const renderer = require('./lib/renderer');

hexo.config.marked = Object.assign({
  gfm: true,
  pedantic: false,
  breaks: true,
  smartLists: true,
  smartypants: true,
  modifyAnchors: 0,
  autolink: true,
  mangle: true,
  sanitizeUrl: false,
  headerIds: true,
  anchorAlias: false,
  lazyload: false,
  // TODO: enable prependRoot by default in v3
  prependRoot: false,
  external_link: {
    enable: false,
    exclude: [],
    nofollow: false
  }
}, hexo.config.marked);

renderer.disableNunjucks = Boolean(hexo.config.marked.disableNunjucks);

hexo.extend.renderer.register('md', 'html', renderer, true);
hexo.extend.renderer.register('markdown', 'html', renderer, true);
hexo.extend.renderer.register('mkd', 'html', renderer, true);
hexo.extend.renderer.register('mkdn', 'html', renderer, true);
hexo.extend.renderer.register('mdwn', 'html', renderer, true);
hexo.extend.renderer.register('mdtxt', 'html', renderer, true);
hexo.extend.renderer.register('mdtext', 'html', renderer, true);
<commit_msg>feat(postAsset): disable by default<commit_after>/* global hexo */

'use strict';

const renderer = require('./lib/renderer');

hexo.config.marked = Object.assign({
  gfm: true,
  pedantic: false,
  breaks: true,
  smartLists: true,
  smartypants: true,
  modifyAnchors: 0,
  autolink: true,
  mangle: true,
  sanitizeUrl: false,
  headerIds: true,
  anchorAlias: false,
  lazyload: false,
  // TODO: enable prependRoot by default in v4
  prependRoot: false,
  postAsset: false,
  external_link: {
    enable: false,
    exclude: [],
    nofollow: false
  }
}, hexo.config.marked);

renderer.disableNunjucks = Boolean(hexo.config.marked.disableNunjucks);

hexo.extend.renderer.register('md', 'html', renderer, true);
hexo.extend.renderer.register('markdown', 'html', renderer, true);
hexo.extend.renderer.register('mkd', 'html', renderer, true);
hexo.extend.renderer.register('mkdn', 'html', renderer, true);
hexo.extend.renderer.register('mdwn', 'html', renderer, true);
hexo.extend.renderer.register('mdtxt', 'html', renderer, true);
hexo.extend.renderer.register('mdtext', 'html', renderer, true);
<|endoftext|>


<commit_before>// Used to detect for Cygwin
var os = require('os');

// Required for Windows/Cygwin support
var root = [__dirname, '/vendor/libgit2/build/shared'].join(''),
  path = process.env.PATH;

if (~os.type().indexOf('CYGWIN') && !~path.indexOf(root)) {
  process.env.PATH = root + ':' + path;
}

// Assign raw api to module
var rawApi;
try {
  rawApi = require('./build/Release/nodegit');
} catch (e) {
  rawApi = require('./build/Debug/nodegit');
}
for (var key in rawApi) {
  exports[key] = rawApi[key];
}

// Import extensions
require('./lib/commit.js');
require('./lib/blob.js');
require('./lib/object.js');
require('./lib/signature.js');
require('./lib/odb.js');
require('./lib/oid.js');
require('./lib/index.js');
require('./lib/repo.js');
require('./lib/reference.js');
require('./lib/revwalk.js');
require('./lib/tree.js');
require('./lib/diff_list.js');
require('./lib/tree_entry.js');
require('./lib/tree_builder.js');

// Set version
exports.version = require('./package').version;

// Initialize threads
exports.Threads.init();
<commit_msg>Set the raw API directly.<commit_after>// Used to detect for Cygwin
var os = require('os');

// Required for Windows/Cygwin support
var root = [__dirname, '/vendor/libgit2/build/shared'].join(''),
  path = process.env.PATH;

if (~os.type().indexOf('CYGWIN') && !~path.indexOf(root)) {
  process.env.PATH = root + ':' + path;
}

// Assign raw api to module
var rawApi;
try {
  rawApi = require('./build/Release/nodegit');
} catch (e) {
  rawApi = require('./build/Debug/nodegit');
}

// Set the exports prototype to the raw API.
exports.__proto__ = rawApi;

// Import extensions
require('./lib/commit.js');
require('./lib/blob.js');
require('./lib/object.js');
require('./lib/signature.js');
require('./lib/odb.js');
require('./lib/oid.js');
require('./lib/index.js');
require('./lib/repo.js');
require('./lib/reference.js');
require('./lib/revwalk.js');
require('./lib/tree.js');
require('./lib/diff_list.js');
require('./lib/tree_entry.js');
require('./lib/tree_builder.js');

// Set version
exports.version = require('./package').version;

// Initialize threads
exports.Threads.init();
<|endoftext|>


<commit_before>"use strict";

(function(window, undefined){

function SplineCommandMoveTo(x, y)
{
    this.id = 0;
    this.x = x;
    this.y = y;
}

function SplineCommandLineTo(x, y)
{
    this.id = 1;
    this.x = x;
    this.y = y;
    this.changeLastPoint = function(x, y)
    {
        this.x = x;
        this.y = y;
    }
}

function SplineCommandBezier(x1, y1, x2, y2, x3, y3)
{
    this.id = 2;
    this.x1 = x1;
    this.y1 = y1;
    this.x2 = x2;
    this.y2 = y2;
    this.x3 = x3;
    this.y3 = y3;

    this.changeLastPoint = function(x, y)
    {
        this.x3 = x;
        this.y3 = y;
        this.x2 = this.x1 + (this.x3 - this.x1)*0.5;
        this.y2 = this.y1 + (this.y3 - this.y1)*0.5;
    }
}

function Spline(drawingObjects, theme, master, layout, slide, pageIndex)
{

    AscFormat.ExecuteNoHistory(function(){
        this.pageIndex = pageIndex;
        this.path = [];

        this.drawingObjects = drawingObjects;

        this.Matrix = new AscCommon.CMatrix();
        this.TransformMatrix = new AscCommon.CMatrix();

        this.style  = AscFormat.CreateDefaultShapeStyle();

        var style = this.style;
        style.fillRef.Color.Calculate(theme, slide, layout, master, {R:0, G: 0, B:0, A:255});
        var RGBA = style.fillRef.Color.RGBA;
        var pen = theme.getLnStyle(style.lnRef.idx, style.lnRef.Color);
        style.lnRef.Color.Calculate(theme, slide, layout, master);
        RGBA = style.lnRef.Color.RGBA;

        if(pen.Fill)
        {
            pen.Fill.calculate(theme, slide, layout, master, RGBA);
        }

        this.pen = pen;
        this.splineForDraw = new SplineForDrawer(this);
    }, this, []);
    this.Draw = function(graphics)
    {
        graphics.SetIntegerGrid(false);
        graphics.transform3(this.Matrix);

        var shape_drawer = new AscCommon.CShapeDrawer();
        shape_drawer.fromShape(this, graphics);
        shape_drawer.draw(this);
    };
    this.draw = function(g)
    {
        if(AscFormat.isRealNumber(this.pageIndex) && g.SetCurrentPage)
        {
            g.SetCurrentPage(this.pageIndex);
        }
        this.splineForDraw.Draw(g);
        return;
        for(var i = 0; i < this.path.length; ++i)
        {
            var lastX, lastY;
            switch (this.path[i].id )
            {
                case 0 :
                {
                    g._m(this.path[i].x, this.path[i].y);
                    lastX = this.path[i].x;
                    lastY = this.path[i].y;
                    break;
                }
                case 1 :
                {
                    g._l(this.path[i].x, this.path[i].y);
                    lastX = this.path[i].x;
                    lastY = this.path[i].y;
                    break;
                }
                case 2 :
                {
                    g._c(this.path[i].x1, this.path[i].y1, this.path[i].x2, this.path[i].y2, this.path[i].x3, this.path[i].y3);
                    lastX = this.path[i].x3;
                    lastY = this.path[i].y3;
                    break;
                }
            }
        }
        g.ds();
    };

    this.getShape =  function(bWord, drawingDocument, drawingObjects)
    {
        var xMax = this.path[0].x, yMax = this.path[0].y, xMin = xMax, yMin = yMax;
        var i;

        var bClosed = false;
        if(this.path.length > 2)
        {
            var dx = this.path[0].x - this.path[this.path.length-1].x3;
            var dy = this.path[0].y - this.path[this.path.length-1].y3;
            if(Math.sqrt(dx*dx +dy*dy) < 3)
            {
                bClosed = true;
                this.path[this.path.length-1].x3 = this.path[0].x;
                this.path[this.path.length-1].y3 = this.path[0].y;
                if(this.path.length > 3)
                {
                    var vx = (this.path[1].x3 - this.path[this.path.length-2].x3)/6;
                    var vy = (this.path[1].y3 - this.path[this.path.length-2].y3)/6;
                }
                else
                {
                    vx = -(this.path[1].y3 - this.path[0].y)/6;
                    vy = (this.path[1].x3 - this.path[0].x)/6;
                }

                this.path[1].x1 = this.path[0].x +vx;
                this.path[1].y1 = this.path[0].y +vy;
                this.path[this.path.length-1].x2 = this.path[0].x -vx;
                this.path[this.path.length-1].y2 = this.path[0].y -vy;
            }
        }

        var min_x = this.path[0].x;
        var max_x = min_x;
        var min_y = this.path[0].y;
        var max_y = min_y;
        var last_x = this.path[0].x, last_y = this.path[0].y;
        for(var index = 1; index < this.path.length; ++index)
        {
            var path_command = this.path[index];
            if(path_command.id === 1)
            {
                if(min_x > path_command.x)
                    min_x = path_command.x;
                if(max_x < path_command.x)
                    max_x = path_command.x;
                if(min_y > path_command.y)
                    min_y = path_command.y;
                if(max_y < path_command.y)
                    max_y = path_command.y;

                last_x = path_command.x;
                last_y = path_command.y;
            }
            else
            {
                var bezier_polygon = AscFormat.partition_bezier4(last_x, last_y, path_command.x1, path_command.y1, path_command.x2, path_command.y2, path_command.x3, path_command.y3, AscFormat.APPROXIMATE_EPSILON);
                for(var point_index = 1; point_index < bezier_polygon.length; ++point_index)
                {
                    var cur_point = bezier_polygon[point_index];
                    if(min_x > cur_point.x)
                        min_x = cur_point.x;
                    if(max_x < cur_point.x)
                        max_x = cur_point.x;
                    if(min_y > cur_point.y)
                        min_y = cur_point.y;
                    if(max_y < cur_point.y)
                        max_y = cur_point.y;

                    last_x = path_command.x3;
                    last_y = path_command.y3;
                }
            }
        }

        xMin = min_x;
        xMax = max_x;
        yMin = min_y;
        yMax = max_y;
        var shape = new CShape();
        //if(drawingObjects)
        //{
        //    shape.setWorksheet(drawingObjects.getWorksheetModel());
        //    shape.addToDrawingObjects();
        //}
        shape.setSpPr(new AscFormat.CSpPr());
        shape.spPr.setParent(shape);
        shape.spPr.setXfrm(new AscFormat.CXfrm());
        shape.spPr.xfrm.setParent(shape.spPr);
        if(!bWord)
        {
            shape.spPr.xfrm.setOffX(xMin);
            shape.spPr.xfrm.setOffY(yMin);
        }
        else
        {
            shape.setWordShape(true);
            shape.spPr.xfrm.setOffX(0);
            shape.spPr.xfrm.setOffY(0);
        }
        shape.spPr.xfrm.setExtX(xMax-xMin);
        shape.spPr.xfrm.setExtY(yMax - yMin);
        shape.setStyle(AscFormat.CreateDefaultShapeStyle());

        var geometry = new AscFormat.Geometry();
        var w = xMax - xMin, h = yMax-yMin;
        var kw, kh, pathW, pathH;
        if(w > 0)
        {
            pathW = 43200;
            kw = 43200/ w
        }
        else
        {
            pathW = 0;
            kw = 0;
        }
        if(h > 0)
        {
            pathH = 43200;
            kh = 43200 / h;
        }
        else
        {
            pathH = 0;
            kh = 0;
        }
        geometry.AddPathCommand(0, undefined, bClosed ? "norm": "none", undefined, pathW, pathH);
        geometry.AddRect("l", "t", "r", "b");
        for(i = 0;  i< this.path.length; ++i)
        {
            switch (this.path[i].id)
            {
                case 0 :
                {
                    geometry.AddPathCommand(1, (((this.path[i].x - xMin) * kw) >> 0) + "", (((this.path[i].y - yMin) * kh) >> 0) + "");
                    break;
                }
                case 1 :
                {
                    geometry.AddPathCommand(2, (((this.path[i].x - xMin) * kw) >> 0) + "", (((this.path[i].y - yMin) * kh) >> 0) + "");
                    break;
                }
                case 2:
                {
                    geometry.AddPathCommand(5, (((this.path[i].x1 - xMin) * kw) >> 0) + "", (((this.path[i].y1 - yMin) * kh) >> 0) + "", (((this.path[i].x2 - xMin)* kw) >> 0) + "", (((this.path[i].y2 - yMin) * kh) >> 0) + "", (((this.path[i].x3 - xMin) * kw) >> 0) + "", (((this.path[i].y3 - yMin) * kh) >> 0) + "");
                    break;
                }
            }
        }
        if(bClosed)
        {
            geometry.AddPathCommand(6);
        }
        shape.spPr.setGeometry(geometry);
        shape.setBDeleted(false);
        shape.recalculate();
        shape.x = xMin;
        shape.y = yMin;
        return shape;
    };

    this.addPathCommand = function(pathCommand)
    {
        this.path.push(pathCommand);
    };
    this.getBounds = function()
    {
        var boundsChecker = new  AscFormat.CSlideBoundsChecker();
        this.draw(boundsChecker);
        boundsChecker.Bounds.posX = boundsChecker.Bounds.min_x;
        boundsChecker.Bounds.posY = boundsChecker.Bounds.min_y;
        boundsChecker.Bounds.extX = boundsChecker.Bounds.max_x - boundsChecker.Bounds.min_x;
        boundsChecker.Bounds.extY = boundsChecker.Bounds.max_y - boundsChecker.Bounds.min_y;
        return boundsChecker.Bounds;
    };
}

function SplineForDrawer(spline)
{
    this.spline = spline;
    this.pen = spline.pen;
    this.brush = spline.brush;
    this.TransformMatrix = spline.TransformMatrix;
    this.Matrix = spline.Matrix;

    this.Draw = function(graphics)
    {
        graphics.SetIntegerGrid(false);
        graphics.transform3(this.Matrix);

        var shape_drawer = new AscCommon.CShapeDrawer();
        shape_drawer.fromShape(this, graphics);
        shape_drawer.draw(this);
    };

    this.draw = function(g)
    {
        g._e();
        for(var i = 0; i < this.spline.path.length; ++i)
        {
            var lastX, lastY;
            switch (this.spline.path[i].id )
            {
                case 0 :
                {
                    g._m(this.spline.path[i].x, this.spline.path[i].y);
                    lastX = this.spline.path[i].x;
                    lastY = this.spline.path[i].y;
                    break;
                }
                case 1 :
                {
                    g._l(this.spline.path[i].x, this.spline.path[i].y);
                    lastX = this.spline.path[i].x;
                    lastY = this.spline.path[i].y;
                    break;
                }
                case 2 :
                {
                    g._c(this.spline.path[i].x1, this.spline.path[i].y1, this.spline.path[i].x2, this.spline.path[i].y2, this.spline.path[i].x3, this.spline.path[i].y3);
                    lastX = this.spline.path[i].x3;
                    lastY = this.spline.path[i].y3;
                    break;
                }
            }
        }
        g.ds();
    }
}

    //--------------------------------------------------------export----------------------------------------------------
    window['AscFormat'] = window['AscFormat'] || {};
    window['AscFormat'].SplineCommandMoveTo = SplineCommandMoveTo;
    window['AscFormat'].SplineCommandLineTo = SplineCommandLineTo;
    window['AscFormat'].SplineCommandBezier = SplineCommandBezier;
    window['AscFormat'].Spline = Spline;
})(window);
<commit_msg>fix bug 32424<commit_after>"use strict";

(function(window, undefined){

function SplineCommandMoveTo(x, y)
{
    this.id = 0;
    this.x = x;
    this.y = y;
}

function SplineCommandLineTo(x, y)
{
    this.id = 1;
    this.x = x;
    this.y = y;
    this.changeLastPoint = function(x, y)
    {
        this.x = x;
        this.y = y;
    }
}

function SplineCommandBezier(x1, y1, x2, y2, x3, y3)
{
    this.id = 2;
    this.x1 = x1;
    this.y1 = y1;
    this.x2 = x2;
    this.y2 = y2;
    this.x3 = x3;
    this.y3 = y3;

    this.changeLastPoint = function(x, y)
    {
        this.x3 = x;
        this.y3 = y;
        this.x2 = this.x1 + (this.x3 - this.x1)*0.5;
        this.y2 = this.y1 + (this.y3 - this.y1)*0.5;
    }
}

function Spline(drawingObjects, theme, master, layout, slide, pageIndex)
{

    AscFormat.ExecuteNoHistory(function(){
        this.pageIndex = pageIndex;
        this.path = [];

        this.drawingObjects = drawingObjects;

        this.Matrix = new AscCommon.CMatrix();
        this.TransformMatrix = new AscCommon.CMatrix();

        this.style  = AscFormat.CreateDefaultShapeStyle();

        var style = this.style;
        style.fillRef.Color.Calculate(theme, slide, layout, master, {R:0, G: 0, B:0, A:255});
        var RGBA = style.fillRef.Color.RGBA;
        var pen = theme.getLnStyle(style.lnRef.idx, style.lnRef.Color);
        style.lnRef.Color.Calculate(theme, slide, layout, master);
        RGBA = style.lnRef.Color.RGBA;

        if(pen.Fill)
        {
            pen.Fill.calculate(theme, slide, layout, master, RGBA);
        }

        this.pen = pen;
        this.splineForDraw = new SplineForDrawer(this);
    }, this, []);
    this.Draw = function(graphics)
    {
        graphics.SetIntegerGrid(false);
        graphics.transform3(this.Matrix);

        var shape_drawer = new AscCommon.CShapeDrawer();
        shape_drawer.fromShape(this, graphics);
        shape_drawer.draw(this);
    };
    this.draw = function(g)
    {
        if(AscFormat.isRealNumber(this.pageIndex) && g.SetCurrentPage)
        {
            g.SetCurrentPage(this.pageIndex);
        }
        this.splineForDraw.Draw(g);
        return;
        for(var i = 0; i < this.path.length; ++i)
        {
            var lastX, lastY;
            switch (this.path[i].id )
            {
                case 0 :
                {
                    g._m(this.path[i].x, this.path[i].y);
                    lastX = this.path[i].x;
                    lastY = this.path[i].y;
                    break;
                }
                case 1 :
                {
                    g._l(this.path[i].x, this.path[i].y);
                    lastX = this.path[i].x;
                    lastY = this.path[i].y;
                    break;
                }
                case 2 :
                {
                    g._c(this.path[i].x1, this.path[i].y1, this.path[i].x2, this.path[i].y2, this.path[i].x3, this.path[i].y3);
                    lastX = this.path[i].x3;
                    lastY = this.path[i].y3;
                    break;
                }
            }
        }
        g.ds();
    };

    this.getShape =  function(bWord, drawingDocument, drawingObjects)
    {
        var xMax = this.path[0].x, yMax = this.path[0].y, xMin = xMax, yMin = yMax;
        var i;

        var bClosed = false;
        if(this.path.length > 2)
        {
            var dx = this.path[0].x - this.path[this.path.length-1].x3;
            var dy = this.path[0].y - this.path[this.path.length-1].y3;
            if(Math.sqrt(dx*dx +dy*dy) < 3)
            {
                bClosed = true;
                this.path[this.path.length-1].x3 = this.path[0].x;
                this.path[this.path.length-1].y3 = this.path[0].y;
                if(this.path.length > 3)
                {
                    var vx = (this.path[1].x3 - this.path[this.path.length-2].x3)/6;
                    var vy = (this.path[1].y3 - this.path[this.path.length-2].y3)/6;
                }
                else
                {
                    vx = -(this.path[1].y3 - this.path[0].y)/6;
                    vy = (this.path[1].x3 - this.path[0].x)/6;
                }

                this.path[1].x1 = this.path[0].x +vx;
                this.path[1].y1 = this.path[0].y +vy;
                this.path[this.path.length-1].x2 = this.path[0].x -vx;
                this.path[this.path.length-1].y2 = this.path[0].y -vy;
            }
        }

        var min_x = this.path[0].x;
        var max_x = min_x;
        var min_y = this.path[0].y;
        var max_y = min_y;
        var last_x = this.path[0].x, last_y = this.path[0].y;
        for(var index = 1; index < this.path.length; ++index)
        {
            var path_command = this.path[index];
            if(path_command.id === 1)
            {
                if(min_x > path_command.x)
                    min_x = path_command.x;
                if(max_x < path_command.x)
                    max_x = path_command.x;
                if(min_y > path_command.y)
                    min_y = path_command.y;
                if(max_y < path_command.y)
                    max_y = path_command.y;

                last_x = path_command.x;
                last_y = path_command.y;
            }
            else
            {
                var bezier_polygon = AscFormat.partition_bezier4(last_x, last_y, path_command.x1, path_command.y1, path_command.x2, path_command.y2, path_command.x3, path_command.y3, AscFormat.APPROXIMATE_EPSILON);
                for(var point_index = 1; point_index < bezier_polygon.length; ++point_index)
                {
                    var cur_point = bezier_polygon[point_index];
                    if(min_x > cur_point.x)
                        min_x = cur_point.x;
                    if(max_x < cur_point.x)
                        max_x = cur_point.x;
                    if(min_y > cur_point.y)
                        min_y = cur_point.y;
                    if(max_y < cur_point.y)
                        max_y = cur_point.y;

                    last_x = path_command.x3;
                    last_y = path_command.y3;
                }
            }
        }

        xMin = min_x;
        xMax = max_x;
        yMin = min_y;
        yMax = max_y;
        var shape = new AscFormat.CShape();
        //if(drawingObjects)
        //{
        //    shape.setWorksheet(drawingObjects.getWorksheetModel());
        //    shape.addToDrawingObjects();
        //}
        shape.setSpPr(new AscFormat.CSpPr());
        shape.spPr.setParent(shape);
        shape.spPr.setXfrm(new AscFormat.CXfrm());
        shape.spPr.xfrm.setParent(shape.spPr);
        if(!bWord)
        {
            shape.spPr.xfrm.setOffX(xMin);
            shape.spPr.xfrm.setOffY(yMin);
        }
        else
        {
            shape.setWordShape(true);
            shape.spPr.xfrm.setOffX(0);
            shape.spPr.xfrm.setOffY(0);
        }
        shape.spPr.xfrm.setExtX(xMax-xMin);
        shape.spPr.xfrm.setExtY(yMax - yMin);
        shape.setStyle(AscFormat.CreateDefaultShapeStyle());

        var geometry = new AscFormat.Geometry();
        var w = xMax - xMin, h = yMax-yMin;
        var kw, kh, pathW, pathH;
        if(w > 0)
        {
            pathW = 43200;
            kw = 43200/ w
        }
        else
        {
            pathW = 0;
            kw = 0;
        }
        if(h > 0)
        {
            pathH = 43200;
            kh = 43200 / h;
        }
        else
        {
            pathH = 0;
            kh = 0;
        }
        geometry.AddPathCommand(0, undefined, bClosed ? "norm": "none", undefined, pathW, pathH);
        geometry.AddRect("l", "t", "r", "b");
        for(i = 0;  i< this.path.length; ++i)
        {
            switch (this.path[i].id)
            {
                case 0 :
                {
                    geometry.AddPathCommand(1, (((this.path[i].x - xMin) * kw) >> 0) + "", (((this.path[i].y - yMin) * kh) >> 0) + "");
                    break;
                }
                case 1 :
                {
                    geometry.AddPathCommand(2, (((this.path[i].x - xMin) * kw) >> 0) + "", (((this.path[i].y - yMin) * kh) >> 0) + "");
                    break;
                }
                case 2:
                {
                    geometry.AddPathCommand(5, (((this.path[i].x1 - xMin) * kw) >> 0) + "", (((this.path[i].y1 - yMin) * kh) >> 0) + "", (((this.path[i].x2 - xMin)* kw) >> 0) + "", (((this.path[i].y2 - yMin) * kh) >> 0) + "", (((this.path[i].x3 - xMin) * kw) >> 0) + "", (((this.path[i].y3 - yMin) * kh) >> 0) + "");
                    break;
                }
            }
        }
        if(bClosed)
        {
            geometry.AddPathCommand(6);
        }
        shape.spPr.setGeometry(geometry);
        shape.setBDeleted(false);
        shape.recalculate();
        shape.x = xMin;
        shape.y = yMin;
        return shape;
    };

    this.addPathCommand = function(pathCommand)
    {
        this.path.push(pathCommand);
    };
    this.getBounds = function()
    {
        var boundsChecker = new  AscFormat.CSlideBoundsChecker();
        this.draw(boundsChecker);
        boundsChecker.Bounds.posX = boundsChecker.Bounds.min_x;
        boundsChecker.Bounds.posY = boundsChecker.Bounds.min_y;
        boundsChecker.Bounds.extX = boundsChecker.Bounds.max_x - boundsChecker.Bounds.min_x;
        boundsChecker.Bounds.extY = boundsChecker.Bounds.max_y - boundsChecker.Bounds.min_y;
        return boundsChecker.Bounds;
    };
}

function SplineForDrawer(spline)
{
    this.spline = spline;
    this.pen = spline.pen;
    this.brush = spline.brush;
    this.TransformMatrix = spline.TransformMatrix;
    this.Matrix = spline.Matrix;

    this.Draw = function(graphics)
    {
        graphics.SetIntegerGrid(false);
        graphics.transform3(this.Matrix);

        var shape_drawer = new AscCommon.CShapeDrawer();
        shape_drawer.fromShape(this, graphics);
        shape_drawer.draw(this);
    };

    this.draw = function(g)
    {
        g._e();
        for(var i = 0; i < this.spline.path.length; ++i)
        {
            var lastX, lastY;
            switch (this.spline.path[i].id )
            {
                case 0 :
                {
                    g._m(this.spline.path[i].x, this.spline.path[i].y);
                    lastX = this.spline.path[i].x;
                    lastY = this.spline.path[i].y;
                    break;
                }
                case 1 :
                {
                    g._l(this.spline.path[i].x, this.spline.path[i].y);
                    lastX = this.spline.path[i].x;
                    lastY = this.spline.path[i].y;
                    break;
                }
                case 2 :
                {
                    g._c(this.spline.path[i].x1, this.spline.path[i].y1, this.spline.path[i].x2, this.spline.path[i].y2, this.spline.path[i].x3, this.spline.path[i].y3);
                    lastX = this.spline.path[i].x3;
                    lastY = this.spline.path[i].y3;
                    break;
                }
            }
        }
        g.ds();
    }
}

    //--------------------------------------------------------export----------------------------------------------------
    window['AscFormat'] = window['AscFormat'] || {};
    window['AscFormat'].SplineCommandMoveTo = SplineCommandMoveTo;
    window['AscFormat'].SplineCommandLineTo = SplineCommandLineTo;
    window['AscFormat'].SplineCommandBezier = SplineCommandBezier;
    window['AscFormat'].Spline = Spline;
})(window);
<|endoftext|>


<commit_before>'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _lodash = require('lodash');

require('./index.css');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var ReactMapboxAutocomplete = function (_React$Component) {
  _inherits(ReactMapboxAutocomplete, _React$Component);

  function ReactMapboxAutocomplete() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, ReactMapboxAutocomplete);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ReactMapboxAutocomplete.__proto__ || Object.getPrototypeOf(ReactMapboxAutocomplete)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
      error: false,
      errorMsg: '',
      query: _this.props.query ? _this.props.query : '',
      queryResults: [],
      publicKey: _this.props.publicKey,
      resetSearch: _this.props.resetSearch ? _this.props.resetSearch : false
    }, _this._updateQuery = function (event) {
      _this.setState({ query: event.target.value });
      var header = { 'Content-Type': 'application/json' };
      var path = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + _this.state.query + '.json?access_token=' + _this.state.publicKey;

      if (_this.props.country) {
        path = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + _this.state.query + '.json?access_token=' + _this.state.publicKey + '&country=' + _this.props.country;
      }

      if (_this.state.query.length > 2) {
        return fetch(path, {
          headers: header
        }).then(function (res) {
          if (!res.ok) throw Error(res.statusText);
          return res.json();
        }).then(function (json) {
          _this.setState({
            error: false,
            queryResults: json.features
          });
        }).catch(function (err) {
          _this.setState({
            error: true,
            errorMsg: 'There was a problem retrieving data from mapbox',
            queryResults: []
          });
        });
      } else {
        _this.setState({
          error: false,
          queryResults: []
        });
      }
    }, _this._resetSearch = function () {
      if (_this.state.resetSearch) {
        _this.setState({
          query: '',
          queryResults: []
        });
      } else {
        _this.setState({ queryResults: [] });
      }
    }, _this._onSuggestionSelect = function (event) {
      if (_this.state.resetSearch === false) {
        _this.setState({ query: event.target.getAttribute('data-suggestion') });
      }

      _this.props.onSuggestionSelect(event.target.getAttribute('data-suggestion'), event.target.getAttribute('data-lat'), event.target.getAttribute('data-lng'), event.target.getAttribute('data-text'));
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(ReactMapboxAutocomplete, [{
    key: 'render',
    value: function render() {
      var _this2 = this;

      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement('input', { placeholder: this.props.placeholder || 'Search',
          className: this.props.inputClass ? this.props.inputClass + ' react-mapbox-ac-input' : 'react-mapbox-ac-input',
          onChange: this._updateQuery,
          value: this.state.query,
          type: 'text' }),
        _react2.default.createElement(
          'span',
          null,
          _react2.default.createElement(
            'div',
            { className: 'react-mapbox-ac-menu',
              style: this.state.queryResults.length > 0 || this.state.error ? { display: 'block' } : { display: 'none' },
              onClick: this._resetSearch },
            (0, _lodash.map)(this.state.queryResults, function (place, i) {
              return _react2.default.createElement(
                'div',
                { className: 'react-mapbox-ac-suggestion',
                  onClick: _this2._onSuggestionSelect,
                  key: i,
                  'data-suggestion': place.place_name,
                  'data-lng': place.center[0],
                  'data-lat': place.center[1],
                  'data-text': place.text },
                place.place_name
              );
            }),
            this.state.error && _react2.default.createElement(
              'div',
              { className: 'react-mapbox-ac-suggestion' },
              this.state.errorMsg
            )
          )
        )
      );
    }
  }]);

  return ReactMapboxAutocomplete;
}(_react2.default.Component);

ReactMapboxAutocomplete.propTypes = {
  inputClass: _propTypes2.default.string,
  publicKey: _propTypes2.default.string.isRequired,
  placeholder: _propTypes2.default.string,
  onSuggestionSelect: _propTypes2.default.func.isRequired,
  country: _propTypes2.default.string,
  query: _propTypes2.default.string,
  resetSearch: _propTypes2.default.bool
};

exports.default = ReactMapboxAutocomplete;
<commit_msg>updated build bump<commit_after>'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _lodash = require('lodash');

require('./index.css');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var ReactMapboxAutocomplete = function (_React$Component) {
  _inherits(ReactMapboxAutocomplete, _React$Component);

  function ReactMapboxAutocomplete() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, ReactMapboxAutocomplete);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ReactMapboxAutocomplete.__proto__ || Object.getPrototypeOf(ReactMapboxAutocomplete)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
      error: false,
      errorMsg: '',
      query: _this.props.query ? _this.props.query : '',
      queryResults: [],
      publicKey: _this.props.publicKey,
      resetSearch: _this.props.resetSearch ? _this.props.resetSearch : false
    }, _this._updateQuery = function (event) {
      _this.setState({ query: event.target.value });
      var header = { 'Content-Type': 'application/json' };
      var path = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + _this.state.query + '.json?access_token=' + _this.state.publicKey;

      if (_this.props.country) {
        path = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + _this.state.query + '.json?access_token=' + _this.state.publicKey + '&country=' + _this.props.country;
      }

      if (_this.state.query.length > 2) {
        return fetch(path, {
          headers: header
        }).then(function (res) {
          if (!res.ok) throw Error(res.statusText);
          return res.json();
        }).then(function (json) {
          _this.setState({
            error: false,
            queryResults: json.features
          });
        }).catch(function (err) {
          _this.setState({
            error: true,
            errorMsg: 'There was a problem retrieving data from mapbox',
            queryResults: []
          });
        });
      } else {
        _this.setState({
          error: false,
          queryResults: []
        });
      }
    }, _this._resetSearch = function () {
      if (_this.state.resetSearch) {
        _this.setState({
          query: '',
          queryResults: []
        });
      } else {
        _this.setState({ queryResults: [] });
      }
    }, _this._onSuggestionSelect = function (event) {
      if (_this.state.resetSearch === false) {
        _this.setState({ query: event.target.getAttribute('data-suggestion') });
      }

      _this.props.onSuggestionSelect(event.target.getAttribute('data-suggestion'), event.target.getAttribute('data-lat'), event.target.getAttribute('data-lng'), event.target.getAttribute('data-text'));
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(ReactMapboxAutocomplete, [{
    key: 'render',
    value: function render() {
      var _this2 = this;

      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement('input', { placeholder: this.props.placeholder || 'Search',
          id: this.props.inputId,
          onClick: this.props.inputOnClick,
          onBlur: this.props.inputOnBlur,
          onFocus: this.props.inputOnFocus,
          className: this.props.inputClass ? this.props.inputClass + ' react-mapbox-ac-input' : 'react-mapbox-ac-input',
          onChange: this._updateQuery,
          value: this.state.query,
          type: 'text' }),
        _react2.default.createElement(
          'span',
          null,
          _react2.default.createElement(
            'div',
            { className: 'react-mapbox-ac-menu',
              style: this.state.queryResults.length > 0 || this.state.error ? { display: 'block' } : { display: 'none' },
              onClick: this._resetSearch },
            (0, _lodash.map)(this.state.queryResults, function (place, i) {
              return _react2.default.createElement(
                'div',
                { className: 'react-mapbox-ac-suggestion',
                  onClick: _this2._onSuggestionSelect,
                  key: i,
                  'data-suggestion': place.place_name,
                  'data-lng': place.center[0],
                  'data-lat': place.center[1],
                  'data-text': place.text },
                place.place_name
              );
            }),
            this.state.error && _react2.default.createElement(
              'div',
              { className: 'react-mapbox-ac-suggestion' },
              this.state.errorMsg
            )
          )
        )
      );
    }
  }]);

  return ReactMapboxAutocomplete;
}(_react2.default.Component);

ReactMapboxAutocomplete.defaultProps = {
  inputId: null,
  inputOnFocus: null,
  inputOnBlur: null,
  inputOnClick: null
};

ReactMapboxAutocomplete.propTypes = {
  inputId: _propTypes2.default.string,
  inputOnFocus: _propTypes2.default.func,
  inputOnBlur: _propTypes2.default.func,
  inputOnClick: _propTypes2.default.func,
  inputClass: _propTypes2.default.string,
  publicKey: _propTypes2.default.string.isRequired,
  placeholder: _propTypes2.default.string,
  onSuggestionSelect: _propTypes2.default.func.isRequired,
  country: _propTypes2.default.string,
  query: _propTypes2.default.string,
  resetSearch: _propTypes2.default.bool
};

exports.default = ReactMapboxAutocomplete;
<|endoftext|>


<commit_before>/*global describe, it, beforeEach, expect, xit, jasmine */

describe("namespace utility", function () {
    "use strict";

    var namespace = window.jermaine.util.namespace;

    it("should throw an error on a malformed namespace string", function () {
        expect(function () {
            namespace("not;a;namespace", function () {});
        }).toThrow("namespace: not;a;namespace is a malformed namespace string");

        expect(function () {
            namespace("window.this.is.a.namespace", function () { });
        }).not.toThrow();

        expect(function () {
            namespace("aliases.testOne", function () {});
        }).not.toThrow();

        expect(function () {
            namespace("window", function () {});
        }).toThrow("namespace: window is a malformed namespace string");
    });

    it("should throw an error if the last parameter exists and is not a function", function () {
        expect(function () {
            namespace("this.is.a.test", "namespace");
        }).toThrow("namespace: second argument must be an object of aliased local namespaces");

        expect(function () {
            namespace("this.is.a.test", {}, function () {});
        }).not.toThrow();
    });

    it("should throw an error if the second argument exists, and a third function argument does not exist", function () {
        expect(function () {
            namespace("this.is.a.test", {});
        }).toThrow("namespace: if second argument exists, final function argument must exist");
    });

    it("should throw an error if the second parameter exists and is not an object when the last parameter is a function", function () {
        expect(function () {
            namespace("this.is.a.test", "string", function () {});
        }).toThrow("namespace: second argument must be an object of aliased local namespaces");
    });

    it("should create the appropriate namespace", function () {
        var ns = namespace("window.test", function (exports) {
            exports.message = "this is a message in the namespace";
        });

        expect(window.test).not.toBeUndefined();
        expect(window.test.message).not.toBeUndefined();
        expect(window.test.message).toBe("this is a message in the namespace");
    });

    it("should not throw an error on a single argument", function () {
        var ns = namespace("this.is.a.test");
    });

    it("should add the namespace to the window if it is not explicitly the first part of the namespace string", function () {
        var ns = namespace("newNameSpace", function (exports) {
            exports.message = "another test namespace";
        });

        expect(window.newNameSpace).not.toBeUndefined();
        expect(window.newNameSpace.message).toBe("another test namespace");
        expect(ns).toBe(window.newNameSpace);
        expect(ns.message).toBe("another test namespace");
    });

    it("should not overwrite an existing namespace on multiple calls", function () {
        var ns1, ns2;
        ns1 = namespace("test", function (exports) {
            exports.Test1 = function () {};
            exports.message1 = "hello world!";
        });

        ns2 = namespace("test", function (exports) {
            exports.Test2 = function () {};
            exports.message2 = "greetings planet!";
        });

        expect(window.test.Test1).not.toBeUndefined();
        expect(window.test.Test2).not.toBeUndefined();
        expect(window.test.message1).not.toBeUndefined();
        expect(window.test.message2).not.toBeUndefined();
    });

    it("should make the aliases accessible in the namespace function", function () {
        var ns1, ns2, ns3, nsFunction;

        nsFunction = function (ns) {
            expect(this.ns1).toBe(namespace("aliases.testOne"));
            expect(this.ns2).toBe(namespace("aliases.testTwo"));
            expect(this.ns2.Thing).not.toBeUndefined();
            ns.thing = this.ns2.Thing;
            ns.whatever = "hello world";
        };

        ns1 = namespace("aliases.testOne");
        ns2 = namespace("aliases.testTwo", function (exports) {
            exports.Thing = function () {};
        });

        ns3 = namespace("aliases.testThree",
                        { ns1: "aliases.testOne",
                          ns2: "aliases.testTwo" },
                        nsFunction);

        expect(ns3.whatever).not.toBeUndefined();
        expect(ns3.thing).not.toBeUndefined();
        expect(ns3.thing).toBe(ns2.Thing);
    });
});<commit_msg>add some assertions to one of the namespace specs to ensure better coverage<commit_after>/*global describe, it, beforeEach, expect, xit, jasmine */

describe("namespace utility", function () {
    "use strict";

    var namespace = window.jermaine.util.namespace;

    it("should throw an error on a malformed namespace string", function () {
        expect(function () {
            namespace("not;a;namespace", function () {});
        }).toThrow("namespace: not;a;namespace is a malformed namespace string");

        expect(function () {
            namespace("window.this.is.a.namespace", function () { });
        }).not.toThrow();

        expect(function () {
            namespace("aliases.testOne", function () {});
        }).not.toThrow();

        expect(function () {
            namespace("window", function () {});
        }).toThrow("namespace: window is a malformed namespace string");
    });

    it("should throw an error if the last parameter exists and is not a function", function () {
        expect(function () {
            namespace("this.is.a.test", "namespace");
        }).toThrow("namespace: second argument must be an object of aliased local namespaces");

        expect(function () {
            namespace("this.is.a.test", {}, function () {});
        }).not.toThrow();
    });

    it("should throw an error if the second argument exists, and a third function argument does not exist", function () {
        expect(function () {
            namespace("this.is.a.test", {});
        }).toThrow("namespace: if second argument exists, final function argument must exist");
    });

    it("should throw an error if the second parameter exists and is not an object when the last parameter is a function", function () {
        expect(function () {
            namespace("this.is.a.test", "string", function () {});
        }).toThrow("namespace: second argument must be an object of aliased local namespaces");
    });

    it("should create the appropriate namespace", function () {
        var ns = namespace("window.test", function (exports) {
            exports.message = "this is a message in the namespace";
        });

        expect(window.test).not.toBeUndefined();
        expect(window.test.message).not.toBeUndefined();
        expect(window.test.message).toBe("this is a message in the namespace");
    });

    it("should not throw an error on a single argument", function () {
        var ns = namespace("this.is.a.test");
    });

    it("should add the namespace to the window if it is not explicitly the first part of the namespace string", function () {
        var ns = namespace("newNameSpace", function (exports) {
            exports.message = "another test namespace";
        });

        expect(window.newNameSpace).not.toBeUndefined();
        expect(window.newNameSpace.message).toBe("another test namespace");
        expect(ns).toBe(window.newNameSpace);
        expect(ns.message).toBe("another test namespace");
    });

    it("should not overwrite an existing namespace on multiple calls", function () {
        var ns1, ns2;
        ns1 = namespace("test", function (exports) {
            exports.Test1 = function () {};
            exports.message1 = "hello world!";
        });

        ns2 = namespace("test", function (exports) {
            exports.Test2 = function () {};
            exports.message2 = "greetings planet!";
        });

        expect(window.test.Test1).not.toBeUndefined();
        expect(window.test.Test2).not.toBeUndefined();
        expect(window.test.message1).not.toBeUndefined();
        expect(window.test.message2).not.toBeUndefined();
    });

    it("should make the aliases accessible in the namespace function", function () {
        var ns1, ns2, ns3, nsFunction;

        nsFunction = function (ns) {
            var t = new this.Thing();

            expect(this.ns1).toBe(namespace("aliases.testOne"));
            expect(this.ns2).toBe(namespace("aliases.testTwo"));
            expect(this.ns2.Thing).not.toBeUndefined();
            expect(this.Thing).not.toBeUndefined();
            expect(t).not.toBeUndefined();
            ns.thing = this.ns2.Thing;
            ns.whatever = "hello world";
        };

        ns1 = namespace("aliases.testOne");
        ns2 = namespace("aliases.testTwo", function (exports) {
            exports.Thing = function () {};
        });

        ns3 = namespace("aliases.testThree",
                        { ns1: "aliases.testOne",
                          ns2: "aliases.testTwo",
                          Thing: "aliases.testTwo.Thing"
                        },
                        nsFunction);

        expect(ns3.whatever).not.toBeUndefined();
        expect(ns3.thing).not.toBeUndefined();
        expect(ns3.thing).toBe(ns2.Thing);
    });
});<|endoftext|>


<commit_before>// Define functions and methods used for simulating class like structures
// including inheritance.  An important feature of this system is that it
// enables one to define a class like structure while controlling all bindings
// to the outside world.  This approach allows a class to be instantiated
// multiple times, which enables a more compositional approach to inheritance.

module.__proto__.defineClass = function(classConstructor) {
  var self = this;
  var classes = {};

  // Private class constructor
  function _createClass(bindings) {
    var answer = classConstructor(bindings || {});
    answer.inherit = function(parent) {
      if(arguments.length > 1) {
        // this allows chaining multiple classes in the call
        parent.inherit(Array.prototype.slice.call(arguments, 1));
      }
      this._super = parent;
      Object.defineProperty(this.prototype, '_constructor', {enumerable: false, value: this});
      this.prototype.__proto__ = parent.prototype;
      this.__proto__ = parent;
    };
    answer.super = function(receiver, method, args) {
      if(!this._super) return;
      if(typeof method == 'string') {
        return this._super.prototype[method].apply(receiver, args);
      } else {
        return this._super.apply(receiver, method);
      }
    };
    if(answer.superclass) answer.inherit(answer.superclass);
    return answer;
  };

  // Private class wrapper (we wrap classes to enable cyclic references)
  function _wrapClass(wrapper, cls) {
    wrapper.prototype = cls.prototype;
    wrapper.prototype._constructor = wrapper;
    wrapper._super = cls._super;
    wrapper.inherit = cls.inherit;
    wrapper.super = cls.super;
    return wrapper;
  };

  // Public createClass() function - creates a new class with the given
  // bindings and an optional name...the name, if given, can be used to
  // later recall the same class instance using class())
  this.exports.createClass = function(name, bindings) {
    if(typeof name != 'string') return _createClass(bindings);
    classes[name] = function() {return tmp.apply(this, arguments);};
    var tmp = _createClass(bindings);
    return _wrapClass(classes[name], tmp);
  };

  // Public class() function - Return the class for the given name if
  // it has already been created, otherwise create it (note, you cannot
  // override the default bindings with this method, use createClass() if
  // you need to override the default bindings).  If the name is omitted,
  // use 'default'
  this.exports.class = function(name) {
    name = name || 'default';
    if(classes[name]) return classes[name];
    return this.createClass(name);
  };

  // Public new() method - This is a conventience function to create a
  // new instance of the "default" class instance
  this.exports.new = function() {
    var ClassInstance = this.class();
    var answer = Object.create(ClassInstance.prototype);
    ClassInstance.apply(answer, arguments);
    return answer;
  };
};
<commit_msg>clone static methods to wrapp & fix bug in handling bindings argument<commit_after>// Define functions and methods used for simulating class like structures
// including inheritance.  An important feature of this system is that it
// enables one to define a class like structure while controlling all bindings
// to the outside world.  This approach allows a class to be instantiated
// multiple times, which enables a more compositional approach to inheritance.

module.__proto__.defineClass = function(classConstructor) {
  var self = this;
  var classes = {};

  // Private class constructor
  function _createClass(bindings) {
    var answer = classConstructor(bindings || {});
    answer.inherit = function(parent) {
      if(arguments.length > 1) {
        // this allows chaining multiple classes in the call
        parent.inherit(Array.prototype.slice.call(arguments, 1));
      }
      this._super = parent;
      Object.defineProperty(this.prototype, '_constructor', {enumerable: false, value: this});
      this.prototype.__proto__ = parent.prototype;
      this.__proto__ = parent;
    };
    answer.super = function(receiver, method, args) {
      if(!this._super) return;
      if(typeof method == 'string') {
        return this._super.prototype[method].apply(receiver, args);
      } else {
        return this._super.apply(receiver, method);
      }
    };
    if(answer.superclass) answer.inherit(answer.superclass);
    return answer;
  };

  // Private class wrapper (we wrap classes to enable cyclic references)
  function _wrapClass(wrapper, cls) {
    wrapper.prototype = cls.prototype;
    wrapper.prototype._constructor = wrapper;
    wrapper._super = cls._super;
    wrapper.inherit = cls.inherit;
    wrapper.super = cls.super;
    for(x in cls) {
      wrapper[x] = cls[x];
    }
    return wrapper;
  };

  // Public createClass() function - creates a new class with the given
  // bindings and an optional name...the name, if given, can be used to
  // later recall the same class instance using class())
  this.exports.createClass = function(name, bindings) {
    if(typeof name != 'string') return _createClass(name);
    classes[name] = function() {return tmp.apply(this, arguments);};
    var tmp = _createClass(bindings);
    return _wrapClass(classes[name], tmp);
  };

  // Public class() function - Return the class for the given name if
  // it has already been created, otherwise create it (note, you cannot
  // override the default bindings with this method, use createClass() if
  // you need to override the default bindings).  If the name is omitted,
  // use 'default'
  this.exports.class = function(name) {
    name = name || 'default';
    if(classes[name]) return classes[name];
    return this.createClass(name);
  };

  // Public new() method - This is a conventience function to create a
  // new instance of the "default" class instance
  this.exports.new = function() {
    var ClassInstance = this.class();
    var answer = Object.create(ClassInstance.prototype);
    ClassInstance.apply(answer, arguments);
    return answer;
  };
};
<|endoftext|>


<commit_before>'use strict';

var data = module.exports = {
  jquery: {
    versions: ['2.1.4', '2.1.3', '2.1.2', '2.1.1', '2.1.0', '2.0.3', '2.0.2', '2.0.1', '2.0.0', '1.11.1', '1.11.0', '1.10.2', '1.10.1', '1.10.0', '1.9.1', '1.9.0', '1.8.3', '1.8.2', '1.8.1', '1.8.0', '1.7.2', '1.7.1', '1.7.0', '1.6.4', '1.6.3', '1.6.2', '1.6.1', '1.6.0', '1.5.2', '1.5.1', '1.5.0', '1.4.4', '1.4.3', '1.4.2', '1.4.1', '1.4.0', '1.3.2', '1.3.1', '1.3.0', '1.2.6', '1.2.3'],
    url: function (version) {
      return '//ajax.googleapis.com/ajax/libs/jquery/' + version + '/jquery.min.js';
    }
  },
  'jquery-ui': {
    versions: ['1.11.4', '1.11.3', '1.11.2', '1.11.1', '1.11.0', '1.10.4', '1.10.3', '1.10.2', '1.10.1', '1.10.0', '1.9.2', '1.9.1', '1.9.0', '1.8.24', '1.8.23', '1.8.22', '1.8.21', '1.8.20', '1.8.19', '1.8.18', '1.8.17', '1.8.16', '1.8.15', '1.8.14', '1.8.13', '1.8.12', '1.8.11', '1.8.10', '1.8.9', '1.8.8', '1.8.7', '1.8.6', '1.8.5', '1.8.4', '1.8.2', '1.8.1', '1.8.0', '1.7.3', '1.7.2', '1.7.1', '1.7.0', '1.6.0', '1.5.3', '1.5.2'],
    url: function (version) {
      return '//ajax.googleapis.com/ajax/libs/jqueryui/' + version + '/jquery-ui.min.js';
    }
  },
  dojo: {
    versions: ['1.10.4', '1.10.3', '1.10.2', '1.10.1', '1.10.0', '1.9.3', '1.9.2', '1.9.1', '1.9.0', '1.8.5', '1.8.4', '1.8.3', '1.8.2', '1.8.1', '1.8.0', '1.7.5', '1.7.4', '1.7.3', '1.7.2', '1.7.1', '1.7.0', '1.6.1', '1.6.0', '1.5.2', '1.5.1', '1.5.0', '1.4.4', '1.4.3', '1.4.1', '1.4.0', '1.3.2', '1.3.1', '1.3.0', '1.2.3', '1.2.0', '1.1.1'],
    url: function (version) {
      return '//ajax.googleapis.com/ajax/libs/dojo/' + version + '/dojo/dojo.js';
    }
  },
  swfobject: {
    versions: ['2.2', '2.1'],
    url: function (version) {
      return '//ajax.googleapis.com/ajax/libs/swfobject/' + version + '/swfobject.js';
    }
  },
  'angular-material': {
    versions: ['0.10.0', '0.9.4', '0.9.0', '0.8.3', '0.8.2', '0.8.1', '0.8.0', '0.7.1', '0.7.0', '0.6.1'],
    url: function (version) {
      return '//ajax.googleapis.com/ajax/libs/angular_material/' + version + '/angular-material.min.js';
    }
  }
};

// AngularJS

var angularFiles = [
  'angular',
  'angular-animate',
  'angular-aria',
  'angular-cookies',
  'angular-loader',
  'angular-messages',
  'angular-resource',
  'angular-route',
  'angular-sanitize',
  'angular-touch'
];

angularFiles.forEach(function (item) {
  var stableVersions = ['1.4.3', '1.4.2', '1.4.1', '1.4.0', '1.3.15', '1.3.14', '1.3.13', '1.3.12', '1.3.11', '1.3.10', '1.3.9', '1.3.8', '1.3.7', '1.3.6', '1.3.5', '1.3.4', '1.3.3', '1.3.2', '1.3.1', '1.3.0', '1.2.28', '1.2.27', '1.2.26', '1.2.25', '1.2.24', '1.2.23', '1.2.22', '1.2.21', '1.2.20', '1.2.19', '1.2.18', '1.2.17', '1.2.16', '1.2.15', '1.2.14', '1.2.13', '1.2.12', '1.2.11', '1.2.10', '1.2.9', '1.2.8', '1.2.7', '1.2.6', '1.2.5', '1.2.4', '1.2.3', '1.2.2', '1.2.1', '1.2.0', '1.0.8', '1.0.7', '1.0.6', '1.0.5', '1.0.4', '1.0.3', '1.0.2', '1.0.1'];
  var unstableVersions = ['1.4.0-rc.2', '1.4.0-rc.1', '1.4.0-rc.0', '1.4.0-beta.6', '1.4.0-beta.5', '1.4.0-beta.4', '1.4.0-beta.3', '1.4.0-beta.2', '1.4.0-beta.1', '1.4.0-beta.0', '1.3.0-rc.5', '1.3.0-rc.4', '1.3.0-rc.3', '1.3.0-rc.2', '1.3.0-rc.1', '1.3.0-rc.0', '1.3.0-beta.19', '1.3.0-beta.18', '1.3.0-beta.17', '1.3.0-beta.16', '1.3.0-beta.15', '1.3.0-beta.14', '1.3.0-beta.13', '1.3.0-beta.12', '1.3.0-beta.11', '1.3.0-beta.10', '1.3.0-beta.9', '1.3.0-beta.8', '1.3.0-beta.7', '1.3.0-beta.6', '1.3.0-beta.5', '1.3.0-beta.4', '1.3.0-beta.3', '1.3.0-beta.2', '1.3.0-beta.1'];
  data[item] = {
    versions: [].concat(stableVersions).concat(unstableVersions),
    url: function (version) {
      return '//ajax.googleapis.com/ajax/libs/angularjs/' + version + '/' + item + '.min.js';
    }
  };
});
<commit_msg>feat(data): add angular 1.4.4<commit_after>'use strict';

var data = module.exports = {
  jquery: {
    versions: ['2.1.4', '2.1.3', '2.1.2', '2.1.1', '2.1.0', '2.0.3', '2.0.2', '2.0.1', '2.0.0', '1.11.1', '1.11.0', '1.10.2', '1.10.1', '1.10.0', '1.9.1', '1.9.0', '1.8.3', '1.8.2', '1.8.1', '1.8.0', '1.7.2', '1.7.1', '1.7.0', '1.6.4', '1.6.3', '1.6.2', '1.6.1', '1.6.0', '1.5.2', '1.5.1', '1.5.0', '1.4.4', '1.4.3', '1.4.2', '1.4.1', '1.4.0', '1.3.2', '1.3.1', '1.3.0', '1.2.6', '1.2.3'],
    url: function (version) {
      return '//ajax.googleapis.com/ajax/libs/jquery/' + version + '/jquery.min.js';
    }
  },
  'jquery-ui': {
    versions: ['1.11.4', '1.11.3', '1.11.2', '1.11.1', '1.11.0', '1.10.4', '1.10.3', '1.10.2', '1.10.1', '1.10.0', '1.9.2', '1.9.1', '1.9.0', '1.8.24', '1.8.23', '1.8.22', '1.8.21', '1.8.20', '1.8.19', '1.8.18', '1.8.17', '1.8.16', '1.8.15', '1.8.14', '1.8.13', '1.8.12', '1.8.11', '1.8.10', '1.8.9', '1.8.8', '1.8.7', '1.8.6', '1.8.5', '1.8.4', '1.8.2', '1.8.1', '1.8.0', '1.7.3', '1.7.2', '1.7.1', '1.7.0', '1.6.0', '1.5.3', '1.5.2'],
    url: function (version) {
      return '//ajax.googleapis.com/ajax/libs/jqueryui/' + version + '/jquery-ui.min.js';
    }
  },
  dojo: {
    versions: ['1.10.4', '1.10.3', '1.10.2', '1.10.1', '1.10.0', '1.9.3', '1.9.2', '1.9.1', '1.9.0', '1.8.5', '1.8.4', '1.8.3', '1.8.2', '1.8.1', '1.8.0', '1.7.5', '1.7.4', '1.7.3', '1.7.2', '1.7.1', '1.7.0', '1.6.1', '1.6.0', '1.5.2', '1.5.1', '1.5.0', '1.4.4', '1.4.3', '1.4.1', '1.4.0', '1.3.2', '1.3.1', '1.3.0', '1.2.3', '1.2.0', '1.1.1'],
    url: function (version) {
      return '//ajax.googleapis.com/ajax/libs/dojo/' + version + '/dojo/dojo.js';
    }
  },
  swfobject: {
    versions: ['2.2', '2.1'],
    url: function (version) {
      return '//ajax.googleapis.com/ajax/libs/swfobject/' + version + '/swfobject.js';
    }
  },
  'angular-material': {
    versions: ['0.10.0', '0.9.4', '0.9.0', '0.8.3', '0.8.2', '0.8.1', '0.8.0', '0.7.1', '0.7.0', '0.6.1'],
    url: function (version) {
      return '//ajax.googleapis.com/ajax/libs/angular_material/' + version + '/angular-material.min.js';
    }
  }
};

// AngularJS

var angularFiles = [
  'angular',
  'angular-animate',
  'angular-aria',
  'angular-cookies',
  'angular-loader',
  'angular-messages',
  'angular-resource',
  'angular-route',
  'angular-sanitize',
  'angular-touch'
];

angularFiles.forEach(function (item) {
  var stableVersions = ['1.4.4', '1.4.3', '1.4.2', '1.4.1', '1.4.0', '1.3.15', '1.3.14', '1.3.13', '1.3.12', '1.3.11', '1.3.10', '1.3.9', '1.3.8', '1.3.7', '1.3.6', '1.3.5', '1.3.4', '1.3.3', '1.3.2', '1.3.1', '1.3.0', '1.2.28', '1.2.27', '1.2.26', '1.2.25', '1.2.24', '1.2.23', '1.2.22', '1.2.21', '1.2.20', '1.2.19', '1.2.18', '1.2.17', '1.2.16', '1.2.15', '1.2.14', '1.2.13', '1.2.12', '1.2.11', '1.2.10', '1.2.9', '1.2.8', '1.2.7', '1.2.6', '1.2.5', '1.2.4', '1.2.3', '1.2.2', '1.2.1', '1.2.0', '1.0.8', '1.0.7', '1.0.6', '1.0.5', '1.0.4', '1.0.3', '1.0.2', '1.0.1'];
  var unstableVersions = ['1.4.0-rc.2', '1.4.0-rc.1', '1.4.0-rc.0', '1.4.0-beta.6', '1.4.0-beta.5', '1.4.0-beta.4', '1.4.0-beta.3', '1.4.0-beta.2', '1.4.0-beta.1', '1.4.0-beta.0', '1.3.0-rc.5', '1.3.0-rc.4', '1.3.0-rc.3', '1.3.0-rc.2', '1.3.0-rc.1', '1.3.0-rc.0', '1.3.0-beta.19', '1.3.0-beta.18', '1.3.0-beta.17', '1.3.0-beta.16', '1.3.0-beta.15', '1.3.0-beta.14', '1.3.0-beta.13', '1.3.0-beta.12', '1.3.0-beta.11', '1.3.0-beta.10', '1.3.0-beta.9', '1.3.0-beta.8', '1.3.0-beta.7', '1.3.0-beta.6', '1.3.0-beta.5', '1.3.0-beta.4', '1.3.0-beta.3', '1.3.0-beta.2', '1.3.0-beta.1'];
  data[item] = {
    versions: [].concat(stableVersions).concat(unstableVersions),
    url: function (version) {
      return '//ajax.googleapis.com/ajax/libs/angularjs/' + version + '/' + item + '.min.js';
    }
  };
});
<|endoftext|>