/*  var patches = diff(current, previous)

for each NESTED (depth >=1) patch, apply it to current.

Write new current into disk at dirname/npm-shrinkwrap.json
345027
function trimNested(previous, current, opts) {
    // bail early if we want to keep nested dependencies
    if (opts.keepNested) {
        return current;
    }

    // purposes find patches from to
    // apply TO current FROM previous
    var patches = jsonDiff.diff(current, previous);

    if (!patches) {
        return current;
    }

    patches = removeTopLevelPatches(patches);

    if (patches.dependencies) {
        Object.keys(patches.dependencies)
            .forEach(function (key) {
                current.dependencies[key] =
                    previous.dependencies[key];
            });
    }

    return current;
}
511086
function DeepDiff () {
  var self = this

  self.klass = DeepDiff;
  self.klass.super_.apply(self, arguments);

  self.engine = require('deep-diff');
}
286721
function(diff) {
	var ret = [];

	diff.push({ value: '', lines: [] });  // Append an empty value to make cleanup easier

	// Formats a given set of lines for printing as context lines in a patch
	function contextLines(lines) {
		return lines.map(function(entry) { return ' ' + entry; });
	}

	var oldRangeStart = 0;
	var newRangeStart = 0;
	var curRange = [];
	var oldLine = 1;
	var newLine = 1;

	for (var i = 0; i < diff.length; i++) {
		var current = diff[i];
		var lines = current.lines || current.value.replace(/\n$/, '').split('\n');
		current.lines = lines;

		if (current.added || current.removed) {
			// If we have previous context, start with that
			if (!oldRangeStart) {
				var prev = diff[i - 1];
				oldRangeStart = oldLine;
				newRangeStart = newLine;

				if (prev) {
					curRange = contextLines(prev.lines.slice(-4));
					oldRangeStart -= curRange.length;
					newRangeStart -= curRange.length;
				}
			}

			// Output our changes
			curRange.push.apply(curRange, lines.map(function(entry) {
				return (current.added ? '+' : '-') + entry;
			}));

			// Track the updated file position
			if (current.added) {
				newLine += lines.length;
			} else {
				oldLine += lines.length;
			}
		} else {
			// Identical context lines. Track line changes
			if (oldRangeStart) {
				// Close out any changes that have been output (or join overlapping)
				if (lines.length <= 8 && i < diff.length - 2) {
					// Overlapping
					curRange.push.apply(curRange, contextLines(lines));
				} else {
					// end the range and output
					var contextSize = Math.min(lines.length, 4);
					ret.push(
						'@@ -' + oldRangeStart + ',' + (oldLine - oldRangeStart + contextSize)
						+ ' +' + newRangeStart + ',' + (newLine - newRangeStart + contextSize)
						+ ' @@');
					ret.push.apply(ret, curRange);
					ret.push.apply(ret, contextLines(lines.slice(0, contextSize)));

					oldRangeStart = 0;
					newRangeStart = 0;
					curRange = [];
				}
			}
			oldLine += lines.length;
			newLine += lines.length;
		}
	}

	return ret.join('\n') + '\n';
}
950108
function(newnode, oldnode, lastnode, id, ids) {
		var result = true;
		var isSoftUpdate = false;
		var isPluginUpdate = false; // TODO: plugins...
		if ((newnode && !oldnode) || (!newnode && oldnode)) {
			result = false;
		} else if ((result = newnode.nodeType === oldnode.nodeType)) {
			switch (oldnode.nodeType) {
				case Node.TEXT_NODE:
					if (newnode.data !== oldnode.data) {
						result = false;
					}
					break;
				case Node.ELEMENT_NODE:
					if ((result = this._familiar(newnode, oldnode))) {
						if ((result = this._checkatts(newnode, oldnode, ids))) {
							if (this._maybesoft(newnode, oldnode)) {
								if (this._confirmsoft(newnode, oldnode)) {
									this._updatesoft(newnode, oldnode, ids);
									isSoftUpdate = true; // prevents the replace update
								}
								result = false; // crawling continued in _updatesoft
							} else {
								if (oldnode.localName !== "textarea") { // TODO: better forms support!
									result = newnode.childNodes.length === oldnode.childNodes.length;
									if (!result && oldnode.id) {
										lastnode = newnode;
										id = oldnode.id;
									}
								}
							}
						}
					}
					break;
			}
		}
		if (!result && !isSoftUpdate && !isPluginUpdate) {
			this._updates.collect(new edbml.FunctionUpdate(this._doc).setup(id));
			this._updates.collect(new edbml.HardUpdate(this._doc).setup(id, lastnode));
		}
		return result;
	}
174277
function appendRecursively(formData, collection, parentkey, parentIsArray) {
    //console.log(...arguments)

    for (let k in collection) {
        const val = collection[k];

        if (val === undefined) continue;

        if (val instanceof File) {
            let mkey = (parentkey ? parentkey + '.' : '') + k;

            // if(parentIsArray)
            // 	mkey = parentkey
            // else
            // 	mkey = k


            val.foo = 'bar'

            formData.append(mkey, val)
        }
        else if (Array.isArray(val)) {

            let mkey = '';
            if (parentIsArray) {
                mkey = parentkey; //parentKey can/should never be empty if parentISarray
            } else {
                mkey = (parentkey ? parentkey + '.' + k : k);
            }

            appendRecursively(formData, val, mkey, true);
        }
        else if (typeof val === 'object') {
            let mkey = (parentkey ? parentkey + '.' : '') + k;
            appendRecursively(formData, val, mkey, false);
        }
        else {
            let mkey = (parentkey ? parentkey + '.' : '') + k;
            formData.append(mkey, val)
        }

    }
}
614097
function diffusionUpdate () {
    var row, col, ind
    var dum = conv2(u, coeffs)
    for (row = 0; row < height; ++row)
      for (col = 0; col < width; ++col) {
        ind = row * width + col
        un[ind] = u[ind] +  c4 * dum[ind]
        u[ind] = un[ind] // new becomes current
      }
    return u
  }
984925
function revalue(node, depth) {
    var children = node.children,
        v = 0;
    if (children && (n = children.length)) {
      var i = -1,
          n,
          j = depth + 1;
      while (++i < n) v += revalue(children[i], j);
    } else if (value) {
      v = +value.call(hierarchy, d3_layout_hierarchyInline ? node : node.data, depth) || 0;
    }
    if (value) node.value = v;
    return v;
  }
47425
function patch(element, previous, dataset) {
  if (!previous && !dataset) {
    return dataset;
  }
  var name;
  previous = previous || {};
  dataset = dataset || {};

  for (name in previous) {
    if (dataset[name] === undefined) {
      delete element.dataset[name];
    }
  }

  for (name in dataset) {
    if (previous[name] === dataset[name]) {
      continue;
    }
    element.dataset[name] = dataset[name];
  }

  return dataset;
}
374777
function(target, skeleton) {
//            console.log("Applying change: "+JSON.stringify(skeleton));
            if (skeleton == null) {
                return false;
            }
            if (typeof skeleton != typeof target) {
                return false;
            }
            switch (typeof skeleton)
            {
                case 'string':
                case 'number':
                case 'boolean':
                    // gone too far
                    return false;
                case 'object':
                    if (skeleton instanceof Array)
                    {
                        // for now only support direct replacement/mutation of elements, skeleton is insufficient to describe splicing
                        if (target.length != skeleton.length) {
                            return false;
                        }
                        var changed = false;
                        for (var i=0; i<skeleton.length; i++) {
                            if (skeleton[i] == null) {
                                continue;
                            }
                            switch (typeof skeleton[i]) {
                                case 'string':
                                case 'number':
                                case 'boolean':
                                    changed = (target[i] != skeleton[i]) || changed;
                                    target[i] = skeleton[i];
                                    break;
                                case 'object':
                                    changed = deepApply(target[i], skeleton[i]) || changed;
                                    break;
                                default:
                                    throw 'Unrecognized type: '+(typeof skeleton[i]);
                            }
                        }
                        return changed;
                    }
                    else {
                        var changed = false;
                        for (var k in skeleton) {
                            if (skeleton.hasOwnProperty(k)) {
                                if (target.hasOwnProperty(k)) {
                                    if (skeleton[k] == null) {
                                        continue;
                                    }
                                    switch (typeof skeleton[k]) {
                                        case 'string':
                                        case 'number':
                                        case 'boolean':
                                            changed = target[k] != skeleton[k] || changed;
                                            target[k] = skeleton[k];
                                            break;
                                        case 'object':
                                            changed = deepApply(target[k], skeleton[k]) || changed;
                                            break;
                                        default:
                                            throw 'Unrecognized type: '+(typeof skeleton[k]);
                                    }
                                }
                                else {
                                    target[k] = skeleton[k];
                                }
                            }
                        }
                        return changed;
                    }
                    break;
                default:
                    throw 'Unrecognized type: '+(typeof incoming);
            }
        }
325186
function patch(fs) {
    if (fs[NS])
        return;

    const virtualFS = {
        files: {},
        add(options) {
            const file = path.resolve(options.path);
            if (virtualFS.files[file] && virtualFS.files[file].content.equals(options.content)) {
                return;
            }
            virtualFS.files[file] = {
                path: file,
                content: options.content,
            };
        },
    };
    fs[NS] = virtualFS;

    createPatchFn(fs, 'readFile', function (orig, args, file, encoding, cb) {
        const rfile = path.resolve(file);
        const vfile = virtualFS.files[rfile];
        if (vfile) {
            if (typeof encoding === 'function') {
                cb = encoding;
                encoding = null;
            }

            let content = vfile.content;
            if (encoding !== null)
                content = content.toString(encoding);

            cb(null, content);
            return;
        }
        return orig.apply(this, args);
    });
    createPatchFn(fs, 'readFileSync', function (orig, args, file, encoding) {
        const rfile = path.resolve(file);
        const vfile = virtualFS.files[rfile];
        if (vfile) {
            let content = vfile.content;
            if (encoding !== null)
                content = content.toString(encoding);
            return content;
        }
        return orig.apply(this, args);
    });

    createPatchFn(fs, 'stat', function (orig, args, p, cb) {
        const rp = path.resolve(p);
        const vfile = virtualFS.files[rp];
        if (vfile) {
            const vstat = {
                dev: 8675309,
                nlink: 1,
                uid: 501,
                gid: 20,
                rdev: 0,
                blksize: 4096,
                ino: 44700000,
                mode: 33188,
                size: vfile.content.length,
                isFile: function isFile() {
                    return true;
                },
                isDirectory: function isDirectory() {
                    return false;
                },
                isBlockDevice: function isBlockDevice() {
                    return false;
                },
                isCharacterDevice: function isCharacterDevice() {
                    return false;
                },
                isSymbolicLink: function isSymbolicLink() {
                    return false;
                },
                isFIFO: function isFIFO() {
                    return false;
                },
                isSocket: function isSocket() {
                    return false;
                },
            };
            cb(null, vstat);
            return;
        }
        return orig.apply(this, args);
    });
    createPatchFn(fs, 'statSync', function (orig, args, p) {
        const rp = path.resolve(p);
        const vfile = virtualFS.files[rp];
        if (vfile) {
            const vstat = {
                dev: 8675309,
                nlink: 1,
                uid: 501,
                gid: 20,
                rdev: 0,
                blksize: 4096,
                ino: 44700000,
                mode: 33188,
                size: vfile.content.length,
                isFile: function isFile() {
                    return true;
                },
                isDirectory: function isDirectory() {
                    return false;
                },
                isBlockDevice: function isBlockDevice() {
                    return false;
                },
                isCharacterDevice: function isCharacterDevice() {
                    return false;
                },
                isSymbolicLink: function isSymbolicLink() {
                    return false;
                },
                isFIFO: function isFIFO() {
                    return false;
                },
                isSocket: function isSocket() {
                    return false;
                },
            };
            return vstat;
        }
        return orig.apply(this, args);
    });
}
964066
function mergeChildren( from, into, refNode, forward ) {
		var child, itemDir;
		while ( ( child = from[ forward ? 'getLast' : 'getFirst' ]( elementType ) ) ) {
			if ( ( itemDir = child.getDirection( 1 ) ) !== into.getDirection( 1 ) )
				child.setAttribute( 'dir', itemDir );

			child.remove();

			refNode ? child[ forward ? 'insertBefore' : 'insertAfter' ]( refNode ) : into.append( child, forward );
		}
	}
516429
function reduceByDepth(depthTree) {
    var order = 0
      , handled = {}
      , useInOrder = []
      ;

    // it's important to sort and reverse the key listing so that 
    // the most deeply depended on modules are always installed first and listed first in ender.js
    Object.keys(depthTree).sort().reverse().forEach(function (depth) {
      var depNames = depthTree[depth]
        ;

      depNames.forEach(function (depName) {
        if (!handled[depName]) {
          handled[depName] = true;
          useInOrder.push(depName);
        }
      });

    });

    return useInOrder;
  }
806911
def recursively_update(d, d2):
  """"""
  for k, v in d2.items():
    if k in d:
      if isinstance(v, dict):
        recursively_update(d[k], v)
        continue
    d[k] = v
1090926
function addNextNodesToASTObject(ASTObject) {
  const ASTObjectsForDepths = [ASTObject];
  function addNextNodes(ASTObject, depth) {
    const depthPlus1 = depth + 1;
    ASTObjectsForDepths[depthPlus1] = ASTObject;
    if (ASTObject.left)
      addNextNodes(ASTObject.left, depthPlus1);
    if (ASTObject.right)
      addNextNodes(ASTObject.right, depthPlus1);
    if (ASTObject.next) {
      const ASTObjectForDepth = ASTObjectsForDepths[depth];
      if (ASTObjectForDepth.nextNodes)
        ASTObjectForDepth.nextNodes.push(ASTObject.next);
      else
        ASTObjectForDepth.nextNodes = [ASTObject.next];
      addNextNodes(ASTObject.next, depth);
    }
  }
  addNextNodes(ASTObject, 0);
}
618850
function replaceNodeWith(node, newNode) {
    let done = false;
    const parent = node.$parent;
    const keys = Object.keys(parent);
    keys.forEach(function(key) {
        if (parent[key] === node) {
            parent[key] = newNode;
            done = true;
        }
    });

    if (done) {
        return;
    }

    // second pass, now check arrays
    keys.forEach(function(key) {
        if (Array.isArray(parent[key])) {
            const arr = parent[key];
            for (let i = 0; i < arr.length; i++) {
                if (arr[i] === node) {
                    arr[i] = newNode;
                    done = true;
                }
            }
        }
    });

    assert(done);
}
609069
function diff(node) {
		var oldBundle = (cachedData.loader.bundle || []).slice();

		return getDependencies(node.load).then(function(result){
			var newBundle = (cachedData.loader.bundle || []).slice();

			// If the deps are the same we can return the existing graph.
			if(same(node.deps, result.deps) &&
			   same(oldBundle, newBundle)) {
				clean(node, result.source);

				if(result.virtualModules.length) {
					var promises = result.virtualModules.map(function(l){
						var node = cachedData.graph[l.name];
						node.load.source = l.source;
						node.load.metadata.useSource = true;
						return diff(node);
					});

					return Promise.all(promises).then(function(results){
						result.same = results.every(function(res){
							return res.same;
						});
						return result;
					});
				}

				result.same = true;
			}
			return result;
		});

	}
822272
function copy() {
  var result = {}
    , depth = 2
    , seen = [];

  (function worker() {
    each(array(arguments), function each(obj) {
      for (var prop in obj) {
        if (hasOwn.call(obj, prop) && !~index(seen, obj[prop])) {
          if (type(obj[prop]) !== 'object' || !depth) {
            result[prop] = obj[prop];
            seen.push(obj[prop]);
          } else {
            depth--;
            worker(result[prop], obj[prop]);
          }
        }
      }
    });
  }).apply(null, arguments);

  return result;
}