<commit_before>﻿
/**
 * Timeline Compiler
 * @overview  Compile timeline into json data.
 *
 * @author    <NAME><<EMAIL>>, 2014
 */
var VERSION = "0.5.1";

// JSON
(function() {

  // ----------------------------------------------------------------------------------------------------
  // local variables

  var hasOwn = Object.prototype.hasOwnProperty;
  var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
  var meta = {
    '\b': '\\b',
    '\t': '\\t',
    '\n': '\\n',
    '\f': '\\f',
    '\r': '\\r',
    '"': '\\"',
    '\\': '\\\\'
  };

  /**
   * Helper function to correctly quote nested strings
   * @ignore
   */
  function quoteString(string) {
    if (string.match(escapeable)) {
      return '"' + string.replace(escapeable, function(a) {
        var c = meta[a];
        if (typeof c === 'string') {
          return c;
        }
        c = a.charCodeAt();
        return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
      }) + '"';
    }
    return '"' + string + '"';
  }

  // ----------------------------------------------------------------------------------------------------
  // class

  /* global JSON: true */
  JSON = {
    /**
     * Encodes an Object as a JSON String
     * Non-integer/string keys are skipped in the object, as are keys that point to a function.
     *
     * @name  JSON.encode
     * @param {Object}  obj   The json-serializble *thing* to be converted
     * @returns {String}      A JSON String
     */
    encode: function(obj) {
      if (obj === null) {
        return 'null';
      }

      var type = typeof obj;

      if (type === 'undefined') {
        return undefined;
      }
      if (type === 'number' || type === 'boolean') {
        return '' + obj;
      }
      if (type === 'string') {
        return quoteString(obj);
      }
      if (type === 'object') {
        if (obj.constructor === Date) {
          var month = obj.getUTCMonth() + 1,
            day = obj.getUTCDate(),
            year = obj.getUTCFullYear(),
            hours = obj.getUTCHours(),
            minutes = obj.getUTCMinutes(),
            seconds = obj.getUTCSeconds(),
            milli = obj.getUTCMilliseconds();

          if (month < 10) {
            month = '0' + month;
          }
          if (day < 10) {
            day = '0' + day;
          }
          if (hours < 10) {
            hours = '0' + hours;
          }
          if (minutes < 10) {
            minutes = '0' + minutes;
          }
          if (seconds < 10) {
            seconds = '0' + seconds;
          }
          if (milli < 100) {
            milli = '0' + milli;
          }
          if (milli < 10) {
            milli = '0' + milli;
          }
          return '"' + year + '-' + month + '-' + day + 'T' +
            hours + ':' + minutes + ':' + seconds +
            '.' + milli + 'Z"';
        }
        if (obj.constructor === Array) {
          var ret = [];
          for (var i = 0; i < obj.length; i++) {
            ret.push(JSON.encode(obj[i]) || 'null');
          }
          return '[' + ret.join(',') + ']';
        }
        var name,
          val,
          pairs = [];

        for (var k in obj) {
          // Only include own properties,
          // Filter out inherited prototypes
          if (!hasOwn.call(obj, k)) {
            continue;
          }

          // Keys must be numerical or string. Skip others
          type = typeof k;
          if (type === 'number') {
            name = '"' + k + '"';
          } else if (type === 'string') {
            name = quoteString(k);
          } else {
            continue;
          }
          type = typeof obj[k];

          // Invalid values like these return undefined
          // from toJSON, however those object members
          // shouldn't be included in the JSON string at all.
          if (type === 'function' || type === 'undefined') {
            continue;
          }
          val = JSON.encode(obj[k]);
          pairs.push(name + ':' + val);
        }
        return '{' + pairs.join(',') + '}';
      }

    },

    /**
     * Evaluates a given piece of json source.
     * @param {String}  src
     * @name  JSON.decode
     */
    decode: function(src) {
      if (src !== null && src !== '' && src !== undefined) {
        return eval('(' + src + ')'); // jshint ignore:line
      }
      return null;
    },

    toString: function() {
      return '[class JSON]';
    }

  };

})();


(function() {

  // ----------------------------------------------------------------------------------------------------
  // local variables
  var supported_instance_type = {
    "symbol": true,
    "bitmap": true
  };

  var supported_symbol_type = {
    "graphic": true,
    "bitmap": true,
    "movie clip": true
  };

  var supported_layer_type = {
    "normal": true,
    "mask": true,
    "masked": true
  };

  var tween_rotate_shortern = {
    "none": "none",
    "auto": "auto",
    "clockwise": "cw",
    "counter-clockwise": "ccw"
  };
  var EPSILON;
  function fpeq(a, b)
  {

    if (!EPSILON) {
      var eps = 1.0;
      do {
        eps /= 2.0;
      }
      while (1.0 + (eps / 2.0) != 1.0);
      EPSILON = eps;
    }


    return Math.abs(a - b) < EPSILON;
  }

  function matrix(mat) {
    var transonly = fpeq(mat.a, 1) && fpeq(mat.d, 1) && fpeq(mat.b, 0) && fpeq(mat.c, 0);


    return transonly ? [mat.tx, mat.ty] :
          [mat.tx, mat.ty,
            mat.a, mat.b,
            mat.c, mat.d];
  }

  function rotation(frame) {
    // [none|auto|ccw|cw],<times>
    return tween_rotate_shortern[frame.motionTweenRotate] + "," + frame.motionTweenRotateTimes;
  }

  function baseCommand(ctx, index, name, o) {
    o = o || {};
    o.cmd = name;
    o.index = index;

    if (ctx.frame.tweenType === "motion") {
      o.tween = ctx.frame.tweenType;
      o.rotate = rotation(ctx.frame);
    }

    return o;
  }

  function nameOrUndefined(instance) {
    return (0 === instance.name.length) ? undefined : instance.name;
  }

  function libraryName(inst)
  {
    return inst.libraryItem.name.replace(/^parts\//, '');
  }

  Command = {
    place: function(ctx, index, instance) {
      if (!supported_instance_type[instance.instanceType])
        return;

      if (!supported_symbol_type[instance.symbolType])
        return;

      return baseCommand(ctx, index, "Place", {
        "duration": ctx.frame.duration,
        "matrix": matrix(instance.matrix),
        "name": nameOrUndefined(instance),
        "character": libraryName(instance)
      });
    },
    remove: function(ctx, index, oldinstance) {
      return baseCommand(ctx, index, "Remove");
    },
    move: function(ctx, index, instance) // for motion tween...
    {
      return baseCommand(ctx, index, "Move", {
        "duration": ctx.frame.duration,
        "matrix": matrix(instance.matrix),
        "name": nameOrUndefined(instance)
      });
    },
    replace: function(ctx, index, instance) {
      return baseCommand(ctx, index, "Replace", {
        "duration": ctx.frame.duration,
        "matrix": matrix(instance.matrix),
        "name": nameOrUndefined(instance),
        "character": libraryName(instance)
      });
    }
  };

  function sameItem(a, b) {
    return a.libraryItem == b.libraryItem;
  }

  function depthMap(elements) {
    var rv = {};
    for (var i = 0; i < elements.length; i++) {
      var e = elements[i];
      rv[e.depth.toString()] = e;
    }
    return rv;
  }


  /* global Set: true */
  Set = {
    union: function(a, b) {<commit_msg>Lowercase command name and make tween as a array.<commit_after>﻿
/**
 * Timeline Compiler
 * @overview  Compile timeline into json data.
 *
 * @author    <NAME><<EMAIL>>, 2014
 */
var VERSION = "0.5.1";

// JSON
(function() {

  // ----------------------------------------------------------------------------------------------------
  // local variables

  var hasOwn = Object.prototype.hasOwnProperty;
  var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
  var meta = {
    '\b': '\\b',
    '\t': '\\t',
    '\n': '\\n',
    '\f': '\\f',
    '\r': '\\r',
    '"': '\\"',
    '\\': '\\\\'
  };

  /**
   * Helper function to correctly quote nested strings
   * @ignore
   */
  function quoteString(string) {
    if (string.match(escapeable)) {
      return '"' + string.replace(escapeable, function(a) {
        var c = meta[a];
        if (typeof c === 'string') {
          return c;
        }
        c = a.charCodeAt();
        return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
      }) + '"';
    }
    return '"' + string + '"';
  }

  // ----------------------------------------------------------------------------------------------------
  // class

  /* global JSON: true */
  JSON = {
    /**
     * Encodes an Object as a JSON String
     * Non-integer/string keys are skipped in the object, as are keys that point to a function.
     *
     * @name  JSON.encode
     * @param {Object}  obj   The json-serializble *thing* to be converted
     * @returns {String}      A JSON String
     */
    encode: function(obj) {
      if (obj === null) {
        return 'null';
      }

      var type = typeof obj;

      if (type === 'undefined') {
        return undefined;
      }
      if (type === 'number' || type === 'boolean') {
        return '' + obj;
      }
      if (type === 'string') {
        return quoteString(obj);
      }
      if (type === 'object') {
        if (obj.constructor === Date) {
          var month = obj.getUTCMonth() + 1,
            day = obj.getUTCDate(),
            year = obj.getUTCFullYear(),
            hours = obj.getUTCHours(),
            minutes = obj.getUTCMinutes(),
            seconds = obj.getUTCSeconds(),
            milli = obj.getUTCMilliseconds();

          if (month < 10) {
            month = '0' + month;
          }
          if (day < 10) {
            day = '0' + day;
          }
          if (hours < 10) {
            hours = '0' + hours;
          }
          if (minutes < 10) {
            minutes = '0' + minutes;
          }
          if (seconds < 10) {
            seconds = '0' + seconds;
          }
          if (milli < 100) {
            milli = '0' + milli;
          }
          if (milli < 10) {
            milli = '0' + milli;
          }
          return '"' + year + '-' + month + '-' + day + 'T' +
            hours + ':' + minutes + ':' + seconds +
            '.' + milli + 'Z"';
        }
        if (obj.constructor === Array) {
          var ret = [];
          for (var i = 0; i < obj.length; i++) {
            ret.push(JSON.encode(obj[i]) || 'null');
          }
          return '[' + ret.join(',') + ']';
        }
        var name,
          val,
          pairs = [];

        for (var k in obj) {
          // Only include own properties,
          // Filter out inherited prototypes
          if (!hasOwn.call(obj, k)) {
            continue;
          }

          // Keys must be numerical or string. Skip others
          type = typeof k;
          if (type === 'number') {
            name = '"' + k + '"';
          } else if (type === 'string') {
            name = quoteString(k);
          } else {
            continue;
          }
          type = typeof obj[k];

          // Invalid values like these return undefined
          // from toJSON, however those object members
          // shouldn't be included in the JSON string at all.
          if (type === 'function' || type === 'undefined') {
            continue;
          }
          val = JSON.encode(obj[k]);
          pairs.push(name + ':' + val);
        }
        return '{' + pairs.join(',') + '}';
      }

    },

    /**
     * Evaluates a given piece of json source.
     * @param {String}  src
     * @name  JSON.decode
     */
    decode: function(src) {
      if (src !== null && src !== '' && src !== undefined) {
        return eval('(' + src + ')'); // jshint ignore:line
      }
      return null;
    },

    toString: function() {
      return '[class JSON]';
    }

  };

})();


(function() {

  // ----------------------------------------------------------------------------------------------------
  // local variables
  var supported_instance_type = {
    "symbol": true,
    "bitmap": true
  };

  var supported_symbol_type = {
    "graphic": true,
    "bitmap": true,
    "movie clip": true
  };

  var supported_layer_type = {
    "normal": true,
    "mask": true,
    "masked": true
  };

  var tween_rotate_shortern = {
    "none": "none",
    "auto": "auto",
    "clockwise": "cw",
    "counter-clockwise": "ccw"
  };
  var EPSILON;
  function fpeq(a, b)
  {

    if (!EPSILON) {
      var eps = 1.0;
      do {
        eps /= 2.0;
      }
      while (1.0 + (eps / 2.0) != 1.0);
      EPSILON = eps;
    }


    return Math.abs(a - b) < EPSILON;
  }

  function matrix(mat) {
    var transonly = fpeq(mat.a, 1) && fpeq(mat.d, 1) && fpeq(mat.b, 0) && fpeq(mat.c, 0);


    return transonly ? [mat.tx, mat.ty] :
          [mat.tx, mat.ty,
            mat.a, mat.b,
            mat.c, mat.d];
  }

  function rotation(frame) {
    // [none|auto|ccw|cw],<times>
    return tween_rotate_shortern[frame.motionTweenRotate];
  }

  function baseCommand(ctx, index, name, o) {
    o = o || {};
    o.cmd = name;
    o.index = index;

    if (ctx.frame.tweenType === "motion") {
      o.tween = [true];
      var ro = rotation(ctx.frame),
          t = frame.motionTweenRotateTimes;
      if (ro !== "none")
        o.tween.push(ro);
      if (t !== 0)
        o.tween.push(t);
    }

    return o;
  }

  function nameOrUndefined(instance) {
    return (0 === instance.name.length) ? undefined : instance.name;
  }

  function libraryName(inst)
  {
    return inst.libraryItem.name.replace(/^parts\//, '');
  }

  Command = {
    place: function(ctx, index, instance) {
      if (!supported_instance_type[instance.instanceType])
        return;

      if (!supported_symbol_type[instance.symbolType])
        return;

      return baseCommand(ctx, index, "place", {
        "duration": ctx.frame.duration,
        "matrix": matrix(instance.matrix),
        "name": nameOrUndefined(instance),
        "character": libraryName(instance)
      });
    },
    remove: function(ctx, index, oldinstance) {
      return baseCommand(ctx, index, "remove");
    },
    move: function(ctx, index, instance) // for motion tween...
    {
      return baseCommand(ctx, index, "move", {
        "duration": ctx.frame.duration,
        "matrix": matrix(instance.matrix),
        "name": nameOrUndefined(instance)
      });
    },
    replace: function(ctx, index, instance) {
      return baseCommand(ctx, index, "replace", {
        "duration": ctx.frame.duration,
        "matrix": matrix(instance.matrix),
        "name": nameOrUndefined(instance),
        "character": libraryName(instance)
      });
    }
  };

  function sameItem(a, b) {
    return a.libraryItem == b.libraryItem;
  }

  function depthMap(elements) {
    var rv = {};
    for (var i = 0; i < elements.length; i++) {
      var e = elements[i];
      rv[e.depth.toString()] = e;
    }
    return rv;
  }


  /* global Set: true */
  Set = {
    union: function(a, b) {
{'fraction_non_alphanumeric': 0.19849495016172686, 'fraction_numerical': 0.008251369727374743, 'mean_word_length': 1.5078629365999008, 'pattern_counts': {'":': 46, '<': 31, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1714890', 'n_tokens_mistral': 4878, 'n_tokens_neox': 4708, 'n_words': 1136}