text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.diffSources = diffSources;
  exports.diffLayers = diffLayers;
  exports.default = diffStyle;
  
  // Copyright (c) 2015 Uber Technologies, Inc.
  // Permission is hereby granted, free of charge, to any person obtaining a copy
  // of this software and associated documentation files (the "Software"), to deal
  // in the Software without restriction, including without limitation the rights
  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  // copies of the Software, and to permit persons to whom the Software is
  // furnished to do so, subject to the following conditions:
  // The above copyright notice and this permission notice shall be included in
  // all copies or substantial portions of the Software.
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  // THE SOFTWARE.
  
  /* eslint-disable max-statements */
  function diffSources(prevStyle, nextStyle) {
    var prevSources = prevStyle.get('sources');
    var nextSources = nextStyle.get('sources');
    var enter = [];
    var update = [];
    var exit = [];
    var prevIds = prevSources.keySeq().toArray();
    var nextIds = nextSources.keySeq().toArray();
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;
  
    try {
      for (var _iterator = prevIds[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var id = _step.value;
        var nextSource = nextSources.get(id);
  
        if (nextSource) {
          if (!nextSource.equals(prevSources.get(id))) {
            update.push({
              id: id,
              source: nextSources.get(id)
            });
          }
        } else {
          exit.push({
            id: id,
            source: prevSources.get(id)
          });
        }
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return != null) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }
  
    var _iteratorNormalCompletion2 = true;
    var _didIteratorError2 = false;
    var _iteratorError2 = undefined;
  
    try {
      for (var _iterator2 = nextIds[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
        var _id = _step2.value;
        var prevSource = prevSources.get(_id);
  
        if (!prevSource) {
          enter.push({
            id: _id,
            source: nextSources.get(_id)
          });
        }
      }
    } catch (err) {
      _didIteratorError2 = true;
      _iteratorError2 = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
          _iterator2.return();
        }
      } finally {
        if (_didIteratorError2) {
          throw _iteratorError2;
        }
      }
    }
  
    return {
      enter: enter,
      update: update,
      exit: exit
    };
  }
  /* eslint-enable max-statements */
  
  
  function diffLayers(prevStyle, nextStyle) {
    var prevLayers = prevStyle.get('layers');
    var nextLayers = nextStyle.get('layers');
    var updates = [];
    var exiting = [];
    var prevMap = {};
    var nextMap = {};
    nextLayers.forEach(function (layer, index) {
      var id = layer.get('id');
      var layerImBehind = nextLayers.get(index + 1);
      nextMap[id] = {
        layer: layer,
        id: id,
        // The `id` of the layer before this one.
        before: layerImBehind ? layerImBehind.get('id') : null,
        enter: true
      };
    });
    prevLayers.forEach(function (layer, index) {
      var id = layer.get('id');
      var layerImBehind = prevLayers.get(index + 1);
      prevMap[id] = {
        layer: layer,
        id: id,
        before: layerImBehind ? layerImBehind.get('id') : null
      };
  
      if (nextMap[id]) {
        // Not a new layer.
        nextMap[id].enter = false;
      } else {
        // This layer is being removed.
        exiting.push(prevMap[id]);
      }
    });
    var _iteratorNormalCompletion3 = true;
    var _didIteratorError3 = false;
    var _iteratorError3 = undefined;
  
    try {
      for (var _iterator3 = nextLayers.reverse()[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
        var layer = _step3.value;
        var id = layer.get('id');
  
        if (!prevMap[id] || !prevMap[id].layer.equals(nextMap[id].layer) || prevMap[id].before !== nextMap[id].before) {
          // This layer is being changed.
          updates.push(nextMap[id]);
        }
      }
    } catch (err) {
      _didIteratorError3 = true;
      _iteratorError3 = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
          _iterator3.return();
        }
      } finally {
        if (_didIteratorError3) {
          throw _iteratorError3;
        }
      }
    }
  
    return {
      updates: updates,
      exiting: exiting
    };
  }
  
  function diffStyle(prevStyle, nextStyle) {
    return {
      sourcesDiff: diffSources(prevStyle, nextStyle),
      layersDiff: diffLayers(prevStyle, nextStyle)
    };
  }
  //# sourceMappingURL=diff-styles.js.map