From cc3852baec0c4582456fe93dd00dfa701ac18e75 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Tue, 4 Feb 2020 15:39:38 -0800 Subject: [PATCH 1/2] change babel plugin to use import map as source of truth --- .gitignore | 2 +- .../__fixtures__/addVersion/options.json | 3 - .../__fixtures__/addVersion/output.js | 1 - .../__fixtures__/dir/options.json | 3 - .../babel-plugin/__fixtures__/dir/output.js | 1 - .../__fixtures__/optionalExtensions/code.js | 1 - .../__fixtures__/optionalExtensions/output.js | 1 - .../node_modules/example-dep/package.json | 0 .../node_modules/example-dep/test.cjs | 0 .../node_modules/example-dep/test.mjs | 0 .../cwd/web_modules/import-map.json | 5 + .../cwd/web_modules/import-map.test.json | 5 + .../web_modules_custom_dir/import-map.json | 5 + .../addVersion => fixtures/dir}/code.js | 0 .../babel-plugin/fixtures/dir/options.json | 3 + __tests__/babel-plugin/fixtures/dir/output.js | 1 + .../dir => fixtures/importMap}/code.js | 0 .../fixtures/importMap/options.json | 3 + .../babel-plugin/fixtures/importMap/output.js | 1 + .../noOption/code.js | 0 .../noOption/options.json | 0 .../noOption/output.js | 0 .../fixtures/optionalExtensions/code.js | 3 + .../optionalExtensions/options.json | 0 .../fixtures/optionalExtensions/output.js | 3 + __tests__/babel-plugin/runner.js | 4 +- .../expected-install/import-map.json | 2 +- .../dep-list-complex/web_modules/dat.gui.js | 2522 ---- .../web_modules/import-map.json | 5 - .../expected-install/import-map.json | 2 +- .../dep-list-simple/web_modules/async.js | 4736 ------ .../web_modules/import-map.json | 5 - .../exclude/expected-install/import-map.json | 4 +- .../exclude/web_modules/import-map.json | 6 - .../exclude/web_modules/vue-router.js | 2882 ---- .../integration/exclude/web_modules/vue.js | 8424 ----------- .../expected-install/import-map.json | 8 +- .../web_modules/array-flatten.js | 24 - .../http-vue-loader/src/httpVueLoader.js | 482 - .../web_modules/import-map.json | 8 - .../web_modules/vue-router.js | 2882 ---- .../web_modules/vue/dist/vue.esm.browser.js | 11995 ---------------- .../expected-install/import-map.json | 2 +- .../web_modules/array-flatten.js | 24 - .../web_modules/import-map.json | 5 - .../include/expected-install/import-map.json | 8 +- .../nomodule/expected-install/import-map.json | 8 +- __tests__/integration/runner.js | 11 +- assets/babel-plugin.js | 96 +- package-lock.json | 20 +- package.json | 4 +- src/index.ts | 9 +- 52 files changed, 143 insertions(+), 34076 deletions(-) delete mode 100644 __tests__/babel-plugin/__fixtures__/addVersion/options.json delete mode 100644 __tests__/babel-plugin/__fixtures__/addVersion/output.js delete mode 100644 __tests__/babel-plugin/__fixtures__/dir/options.json delete mode 100644 __tests__/babel-plugin/__fixtures__/dir/output.js delete mode 100644 __tests__/babel-plugin/__fixtures__/optionalExtensions/code.js delete mode 100644 __tests__/babel-plugin/__fixtures__/optionalExtensions/output.js rename __tests__/babel-plugin/{ => cwd}/node_modules/example-dep/package.json (100%) rename __tests__/babel-plugin/{ => cwd}/node_modules/example-dep/test.cjs (100%) rename __tests__/babel-plugin/{ => cwd}/node_modules/example-dep/test.mjs (100%) create mode 100644 __tests__/babel-plugin/cwd/web_modules/import-map.json create mode 100644 __tests__/babel-plugin/cwd/web_modules/import-map.test.json create mode 100644 __tests__/babel-plugin/cwd/web_modules_custom_dir/import-map.json rename __tests__/babel-plugin/{__fixtures__/addVersion => fixtures/dir}/code.js (100%) create mode 100644 __tests__/babel-plugin/fixtures/dir/options.json create mode 100644 __tests__/babel-plugin/fixtures/dir/output.js rename __tests__/babel-plugin/{__fixtures__/dir => fixtures/importMap}/code.js (100%) create mode 100644 __tests__/babel-plugin/fixtures/importMap/options.json create mode 100644 __tests__/babel-plugin/fixtures/importMap/output.js rename __tests__/babel-plugin/{__fixtures__ => fixtures}/noOption/code.js (100%) rename __tests__/babel-plugin/{__fixtures__ => fixtures}/noOption/options.json (100%) rename __tests__/babel-plugin/{__fixtures__ => fixtures}/noOption/output.js (100%) create mode 100644 __tests__/babel-plugin/fixtures/optionalExtensions/code.js rename __tests__/babel-plugin/{__fixtures__ => fixtures}/optionalExtensions/options.json (100%) create mode 100644 __tests__/babel-plugin/fixtures/optionalExtensions/output.js delete mode 100644 __tests__/integration/dep-list-complex/web_modules/dat.gui.js delete mode 100644 __tests__/integration/dep-list-complex/web_modules/import-map.json delete mode 100644 __tests__/integration/dep-list-simple/web_modules/async.js delete mode 100644 __tests__/integration/dep-list-simple/web_modules/import-map.json delete mode 100644 __tests__/integration/exclude/web_modules/import-map.json delete mode 100644 __tests__/integration/exclude/web_modules/vue-router.js delete mode 100644 __tests__/integration/exclude/web_modules/vue.js delete mode 100644 __tests__/integration/include-with-import-map/web_modules/array-flatten.js delete mode 100644 __tests__/integration/include-with-import-map/web_modules/http-vue-loader/src/httpVueLoader.js delete mode 100644 __tests__/integration/include-with-import-map/web_modules/import-map.json delete mode 100644 __tests__/integration/include-with-import-map/web_modules/vue-router.js delete mode 100644 __tests__/integration/include-with-import-map/web_modules/vue/dist/vue.esm.browser.js delete mode 100644 __tests__/integration/include-with-querystring/web_modules/array-flatten.js delete mode 100644 __tests__/integration/include-with-querystring/web_modules/import-map.json diff --git a/.gitignore b/.gitignore index 1c7e370f4f..26b5ea34c4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ www/index.md www/dist /node_modules /web_modules -__tests__/**/*/web_modules +__tests__/integration/*/web_modules diff --git a/__tests__/babel-plugin/__fixtures__/addVersion/options.json b/__tests__/babel-plugin/__fixtures__/addVersion/options.json deleted file mode 100644 index 5815eaa593..0000000000 --- a/__tests__/babel-plugin/__fixtures__/addVersion/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "addVersion": true -} \ No newline at end of file diff --git a/__tests__/babel-plugin/__fixtures__/addVersion/output.js b/__tests__/babel-plugin/__fixtures__/addVersion/output.js deleted file mode 100644 index aa4974813d..0000000000 --- a/__tests__/babel-plugin/__fixtures__/addVersion/output.js +++ /dev/null @@ -1 +0,0 @@ -import module from '/web_modules/example-dep.js?v=1.2.3'; diff --git a/__tests__/babel-plugin/__fixtures__/dir/options.json b/__tests__/babel-plugin/__fixtures__/dir/options.json deleted file mode 100644 index de40b2ed42..0000000000 --- a/__tests__/babel-plugin/__fixtures__/dir/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "dir": "test_modules" -} \ No newline at end of file diff --git a/__tests__/babel-plugin/__fixtures__/dir/output.js b/__tests__/babel-plugin/__fixtures__/dir/output.js deleted file mode 100644 index 650efc46a8..0000000000 --- a/__tests__/babel-plugin/__fixtures__/dir/output.js +++ /dev/null @@ -1 +0,0 @@ -import module from '/test_modules/example-dep.js'; diff --git a/__tests__/babel-plugin/__fixtures__/optionalExtensions/code.js b/__tests__/babel-plugin/__fixtures__/optionalExtensions/code.js deleted file mode 100644 index 082011b980..0000000000 --- a/__tests__/babel-plugin/__fixtures__/optionalExtensions/code.js +++ /dev/null @@ -1 +0,0 @@ -import module from 'any/local/file'; diff --git a/__tests__/babel-plugin/__fixtures__/optionalExtensions/output.js b/__tests__/babel-plugin/__fixtures__/optionalExtensions/output.js deleted file mode 100644 index 9f5b27048b..0000000000 --- a/__tests__/babel-plugin/__fixtures__/optionalExtensions/output.js +++ /dev/null @@ -1 +0,0 @@ -import module from '/web_modules/any/local/file.js'; diff --git a/__tests__/babel-plugin/node_modules/example-dep/package.json b/__tests__/babel-plugin/cwd/node_modules/example-dep/package.json similarity index 100% rename from __tests__/babel-plugin/node_modules/example-dep/package.json rename to __tests__/babel-plugin/cwd/node_modules/example-dep/package.json diff --git a/__tests__/babel-plugin/node_modules/example-dep/test.cjs b/__tests__/babel-plugin/cwd/node_modules/example-dep/test.cjs similarity index 100% rename from __tests__/babel-plugin/node_modules/example-dep/test.cjs rename to __tests__/babel-plugin/cwd/node_modules/example-dep/test.cjs diff --git a/__tests__/babel-plugin/node_modules/example-dep/test.mjs b/__tests__/babel-plugin/cwd/node_modules/example-dep/test.mjs similarity index 100% rename from __tests__/babel-plugin/node_modules/example-dep/test.mjs rename to __tests__/babel-plugin/cwd/node_modules/example-dep/test.mjs diff --git a/__tests__/babel-plugin/cwd/web_modules/import-map.json b/__tests__/babel-plugin/cwd/web_modules/import-map.json new file mode 100644 index 0000000000..d093cabfa8 --- /dev/null +++ b/__tests__/babel-plugin/cwd/web_modules/import-map.json @@ -0,0 +1,5 @@ +{ + "imports": { + "example-dep": "./example-dep.js" + } +} \ No newline at end of file diff --git a/__tests__/babel-plugin/cwd/web_modules/import-map.test.json b/__tests__/babel-plugin/cwd/web_modules/import-map.test.json new file mode 100644 index 0000000000..b138a3b0b2 --- /dev/null +++ b/__tests__/babel-plugin/cwd/web_modules/import-map.test.json @@ -0,0 +1,5 @@ +{ + "imports": { + "example-dep": "./example-dep.js?from=import-map.test.json" + } +} \ No newline at end of file diff --git a/__tests__/babel-plugin/cwd/web_modules_custom_dir/import-map.json b/__tests__/babel-plugin/cwd/web_modules_custom_dir/import-map.json new file mode 100644 index 0000000000..93186e4a6b --- /dev/null +++ b/__tests__/babel-plugin/cwd/web_modules_custom_dir/import-map.json @@ -0,0 +1,5 @@ +{ + "imports": { + "example-dep": "./test_val/example-dep.js" + } +} \ No newline at end of file diff --git a/__tests__/babel-plugin/__fixtures__/addVersion/code.js b/__tests__/babel-plugin/fixtures/dir/code.js similarity index 100% rename from __tests__/babel-plugin/__fixtures__/addVersion/code.js rename to __tests__/babel-plugin/fixtures/dir/code.js diff --git a/__tests__/babel-plugin/fixtures/dir/options.json b/__tests__/babel-plugin/fixtures/dir/options.json new file mode 100644 index 0000000000..f48c559d3a --- /dev/null +++ b/__tests__/babel-plugin/fixtures/dir/options.json @@ -0,0 +1,3 @@ +{ + "dir": "web_modules_custom_dir" +} \ No newline at end of file diff --git a/__tests__/babel-plugin/fixtures/dir/output.js b/__tests__/babel-plugin/fixtures/dir/output.js new file mode 100644 index 0000000000..a7b34ac0a1 --- /dev/null +++ b/__tests__/babel-plugin/fixtures/dir/output.js @@ -0,0 +1 @@ +import module from '/web_modules_custom_dir/test_val/example-dep.js'; diff --git a/__tests__/babel-plugin/__fixtures__/dir/code.js b/__tests__/babel-plugin/fixtures/importMap/code.js similarity index 100% rename from __tests__/babel-plugin/__fixtures__/dir/code.js rename to __tests__/babel-plugin/fixtures/importMap/code.js diff --git a/__tests__/babel-plugin/fixtures/importMap/options.json b/__tests__/babel-plugin/fixtures/importMap/options.json new file mode 100644 index 0000000000..f359d1b84e --- /dev/null +++ b/__tests__/babel-plugin/fixtures/importMap/options.json @@ -0,0 +1,3 @@ +{ + "importMap": "import-map.test.json" +} \ No newline at end of file diff --git a/__tests__/babel-plugin/fixtures/importMap/output.js b/__tests__/babel-plugin/fixtures/importMap/output.js new file mode 100644 index 0000000000..9cc45ee074 --- /dev/null +++ b/__tests__/babel-plugin/fixtures/importMap/output.js @@ -0,0 +1 @@ +import module from '/web_modules/example-dep.js?from=import-map.test.json'; diff --git a/__tests__/babel-plugin/__fixtures__/noOption/code.js b/__tests__/babel-plugin/fixtures/noOption/code.js similarity index 100% rename from __tests__/babel-plugin/__fixtures__/noOption/code.js rename to __tests__/babel-plugin/fixtures/noOption/code.js diff --git a/__tests__/babel-plugin/__fixtures__/noOption/options.json b/__tests__/babel-plugin/fixtures/noOption/options.json similarity index 100% rename from __tests__/babel-plugin/__fixtures__/noOption/options.json rename to __tests__/babel-plugin/fixtures/noOption/options.json diff --git a/__tests__/babel-plugin/__fixtures__/noOption/output.js b/__tests__/babel-plugin/fixtures/noOption/output.js similarity index 100% rename from __tests__/babel-plugin/__fixtures__/noOption/output.js rename to __tests__/babel-plugin/fixtures/noOption/output.js diff --git a/__tests__/babel-plugin/fixtures/optionalExtensions/code.js b/__tests__/babel-plugin/fixtures/optionalExtensions/code.js new file mode 100644 index 0000000000..00e5480246 --- /dev/null +++ b/__tests__/babel-plugin/fixtures/optionalExtensions/code.js @@ -0,0 +1,3 @@ +import moduleA from 'example-dep'; +import moduleB from './any/local/file'; +import moduleC from '../any/local/file'; diff --git a/__tests__/babel-plugin/__fixtures__/optionalExtensions/options.json b/__tests__/babel-plugin/fixtures/optionalExtensions/options.json similarity index 100% rename from __tests__/babel-plugin/__fixtures__/optionalExtensions/options.json rename to __tests__/babel-plugin/fixtures/optionalExtensions/options.json diff --git a/__tests__/babel-plugin/fixtures/optionalExtensions/output.js b/__tests__/babel-plugin/fixtures/optionalExtensions/output.js new file mode 100644 index 0000000000..96cd811ebb --- /dev/null +++ b/__tests__/babel-plugin/fixtures/optionalExtensions/output.js @@ -0,0 +1,3 @@ +import moduleA from '/web_modules/example-dep.js'; +import moduleB from './any/local/file.js'; +import moduleC from '../any/local/file.js'; diff --git a/__tests__/babel-plugin/runner.js b/__tests__/babel-plugin/runner.js index e74df2340f..ea7df9ddd4 100644 --- a/__tests__/babel-plugin/runner.js +++ b/__tests__/babel-plugin/runner.js @@ -2,10 +2,10 @@ const path = require('path'); const pluginTester = require('babel-plugin-tester').default; const babelPlugin = require('../../assets/babel-plugin.js'); -process.chdir(__dirname); +process.chdir(path.join(__dirname, 'cwd')); pluginTester({ plugin: babelPlugin, pluginName: 'snowpack/assets/babel-plugin.js', - fixtures: path.join(__dirname, '__fixtures__'), + fixtures: path.join(__dirname, 'fixtures'), }); diff --git a/__tests__/integration/dep-list-complex/expected-install/import-map.json b/__tests__/integration/dep-list-complex/expected-install/import-map.json index a31fb0b445..a9a1689b7a 100644 --- a/__tests__/integration/dep-list-complex/expected-install/import-map.json +++ b/__tests__/integration/dep-list-complex/expected-install/import-map.json @@ -1,5 +1,5 @@ { "imports": { - "dat.gui": "./dat.gui.js" + "dat.gui": "./dat.gui.js?rev=XXXXXXXXXX" } } \ No newline at end of file diff --git a/__tests__/integration/dep-list-complex/web_modules/dat.gui.js b/__tests__/integration/dep-list-complex/web_modules/dat.gui.js deleted file mode 100644 index 2beb3b5dc9..0000000000 --- a/__tests__/integration/dep-list-complex/web_modules/dat.gui.js +++ /dev/null @@ -1,2522 +0,0 @@ -/** - * dat-gui JavaScript Controller Library - * http://code.google.com/p/dat-gui - * - * Copyright 2011 Data Arts Team, Google Creative Lab - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - */ - -function ___$insertStyle(css) { - if (!css) { - return; - } - if (typeof window === 'undefined') { - return; - } - - var style = document.createElement('style'); - - style.setAttribute('type', 'text/css'); - style.innerHTML = css; - document.head.appendChild(style); - - return css; -} - -function colorToString (color, forceCSSHex) { - var colorFormat = color.__state.conversionName.toString(); - var r = Math.round(color.r); - var g = Math.round(color.g); - var b = Math.round(color.b); - var a = color.a; - var h = Math.round(color.h); - var s = color.s.toFixed(1); - var v = color.v.toFixed(1); - if (forceCSSHex || colorFormat === 'THREE_CHAR_HEX' || colorFormat === 'SIX_CHAR_HEX') { - var str = color.hex.toString(16); - while (str.length < 6) { - str = '0' + str; - } - return '#' + str; - } else if (colorFormat === 'CSS_RGB') { - return 'rgb(' + r + ',' + g + ',' + b + ')'; - } else if (colorFormat === 'CSS_RGBA') { - return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')'; - } else if (colorFormat === 'HEX') { - return '0x' + color.hex.toString(16); - } else if (colorFormat === 'RGB_ARRAY') { - return '[' + r + ',' + g + ',' + b + ']'; - } else if (colorFormat === 'RGBA_ARRAY') { - return '[' + r + ',' + g + ',' + b + ',' + a + ']'; - } else if (colorFormat === 'RGB_OBJ') { - return '{r:' + r + ',g:' + g + ',b:' + b + '}'; - } else if (colorFormat === 'RGBA_OBJ') { - return '{r:' + r + ',g:' + g + ',b:' + b + ',a:' + a + '}'; - } else if (colorFormat === 'HSV_OBJ') { - return '{h:' + h + ',s:' + s + ',v:' + v + '}'; - } else if (colorFormat === 'HSVA_OBJ') { - return '{h:' + h + ',s:' + s + ',v:' + v + ',a:' + a + '}'; - } - return 'unknown format'; -} - -var ARR_EACH = Array.prototype.forEach; -var ARR_SLICE = Array.prototype.slice; -var Common = { - BREAK: {}, - extend: function extend(target) { - this.each(ARR_SLICE.call(arguments, 1), function (obj) { - var keys = this.isObject(obj) ? Object.keys(obj) : []; - keys.forEach(function (key) { - if (!this.isUndefined(obj[key])) { - target[key] = obj[key]; - } - }.bind(this)); - }, this); - return target; - }, - defaults: function defaults(target) { - this.each(ARR_SLICE.call(arguments, 1), function (obj) { - var keys = this.isObject(obj) ? Object.keys(obj) : []; - keys.forEach(function (key) { - if (this.isUndefined(target[key])) { - target[key] = obj[key]; - } - }.bind(this)); - }, this); - return target; - }, - compose: function compose() { - var toCall = ARR_SLICE.call(arguments); - return function () { - var args = ARR_SLICE.call(arguments); - for (var i = toCall.length - 1; i >= 0; i--) { - args = [toCall[i].apply(this, args)]; - } - return args[0]; - }; - }, - each: function each(obj, itr, scope) { - if (!obj) { - return; - } - if (ARR_EACH && obj.forEach && obj.forEach === ARR_EACH) { - obj.forEach(itr, scope); - } else if (obj.length === obj.length + 0) { - var key = void 0; - var l = void 0; - for (key = 0, l = obj.length; key < l; key++) { - if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) { - return; - } - } - } else { - for (var _key in obj) { - if (itr.call(scope, obj[_key], _key) === this.BREAK) { - return; - } - } - } - }, - defer: function defer(fnc) { - setTimeout(fnc, 0); - }, - debounce: function debounce(func, threshold, callImmediately) { - var timeout = void 0; - return function () { - var obj = this; - var args = arguments; - function delayed() { - timeout = null; - if (!callImmediately) func.apply(obj, args); - } - var callNow = callImmediately || !timeout; - clearTimeout(timeout); - timeout = setTimeout(delayed, threshold); - if (callNow) { - func.apply(obj, args); - } - }; - }, - toArray: function toArray(obj) { - if (obj.toArray) return obj.toArray(); - return ARR_SLICE.call(obj); - }, - isUndefined: function isUndefined(obj) { - return obj === undefined; - }, - isNull: function isNull(obj) { - return obj === null; - }, - isNaN: function (_isNaN) { - function isNaN(_x) { - return _isNaN.apply(this, arguments); - } - isNaN.toString = function () { - return _isNaN.toString(); - }; - return isNaN; - }(function (obj) { - return isNaN(obj); - }), - isArray: Array.isArray || function (obj) { - return obj.constructor === Array; - }, - isObject: function isObject(obj) { - return obj === Object(obj); - }, - isNumber: function isNumber(obj) { - return obj === obj + 0; - }, - isString: function isString(obj) { - return obj === obj + ''; - }, - isBoolean: function isBoolean(obj) { - return obj === false || obj === true; - }, - isFunction: function isFunction(obj) { - return Object.prototype.toString.call(obj) === '[object Function]'; - } -}; - -var INTERPRETATIONS = [ -{ - litmus: Common.isString, - conversions: { - THREE_CHAR_HEX: { - read: function read(original) { - var test = original.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i); - if (test === null) { - return false; - } - return { - space: 'HEX', - hex: parseInt('0x' + test[1].toString() + test[1].toString() + test[2].toString() + test[2].toString() + test[3].toString() + test[3].toString(), 0) - }; - }, - write: colorToString - }, - SIX_CHAR_HEX: { - read: function read(original) { - var test = original.match(/^#([A-F0-9]{6})$/i); - if (test === null) { - return false; - } - return { - space: 'HEX', - hex: parseInt('0x' + test[1].toString(), 0) - }; - }, - write: colorToString - }, - CSS_RGB: { - read: function read(original) { - var test = original.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/); - if (test === null) { - return false; - } - return { - space: 'RGB', - r: parseFloat(test[1]), - g: parseFloat(test[2]), - b: parseFloat(test[3]) - }; - }, - write: colorToString - }, - CSS_RGBA: { - read: function read(original) { - var test = original.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/); - if (test === null) { - return false; - } - return { - space: 'RGB', - r: parseFloat(test[1]), - g: parseFloat(test[2]), - b: parseFloat(test[3]), - a: parseFloat(test[4]) - }; - }, - write: colorToString - } - } -}, -{ - litmus: Common.isNumber, - conversions: { - HEX: { - read: function read(original) { - return { - space: 'HEX', - hex: original, - conversionName: 'HEX' - }; - }, - write: function write(color) { - return color.hex; - } - } - } -}, -{ - litmus: Common.isArray, - conversions: { - RGB_ARRAY: { - read: function read(original) { - if (original.length !== 3) { - return false; - } - return { - space: 'RGB', - r: original[0], - g: original[1], - b: original[2] - }; - }, - write: function write(color) { - return [color.r, color.g, color.b]; - } - }, - RGBA_ARRAY: { - read: function read(original) { - if (original.length !== 4) return false; - return { - space: 'RGB', - r: original[0], - g: original[1], - b: original[2], - a: original[3] - }; - }, - write: function write(color) { - return [color.r, color.g, color.b, color.a]; - } - } - } -}, -{ - litmus: Common.isObject, - conversions: { - RGBA_OBJ: { - read: function read(original) { - if (Common.isNumber(original.r) && Common.isNumber(original.g) && Common.isNumber(original.b) && Common.isNumber(original.a)) { - return { - space: 'RGB', - r: original.r, - g: original.g, - b: original.b, - a: original.a - }; - } - return false; - }, - write: function write(color) { - return { - r: color.r, - g: color.g, - b: color.b, - a: color.a - }; - } - }, - RGB_OBJ: { - read: function read(original) { - if (Common.isNumber(original.r) && Common.isNumber(original.g) && Common.isNumber(original.b)) { - return { - space: 'RGB', - r: original.r, - g: original.g, - b: original.b - }; - } - return false; - }, - write: function write(color) { - return { - r: color.r, - g: color.g, - b: color.b - }; - } - }, - HSVA_OBJ: { - read: function read(original) { - if (Common.isNumber(original.h) && Common.isNumber(original.s) && Common.isNumber(original.v) && Common.isNumber(original.a)) { - return { - space: 'HSV', - h: original.h, - s: original.s, - v: original.v, - a: original.a - }; - } - return false; - }, - write: function write(color) { - return { - h: color.h, - s: color.s, - v: color.v, - a: color.a - }; - } - }, - HSV_OBJ: { - read: function read(original) { - if (Common.isNumber(original.h) && Common.isNumber(original.s) && Common.isNumber(original.v)) { - return { - space: 'HSV', - h: original.h, - s: original.s, - v: original.v - }; - } - return false; - }, - write: function write(color) { - return { - h: color.h, - s: color.s, - v: color.v - }; - } - } - } -}]; -var result = void 0; -var toReturn = void 0; -var interpret = function interpret() { - toReturn = false; - var original = arguments.length > 1 ? Common.toArray(arguments) : arguments[0]; - Common.each(INTERPRETATIONS, function (family) { - if (family.litmus(original)) { - Common.each(family.conversions, function (conversion, conversionName) { - result = conversion.read(original); - if (toReturn === false && result !== false) { - toReturn = result; - result.conversionName = conversionName; - result.conversion = conversion; - return Common.BREAK; - } - }); - return Common.BREAK; - } - }); - return toReturn; -}; - -var tmpComponent = void 0; -var ColorMath = { - hsv_to_rgb: function hsv_to_rgb(h, s, v) { - var hi = Math.floor(h / 60) % 6; - var f = h / 60 - Math.floor(h / 60); - var p = v * (1.0 - s); - var q = v * (1.0 - f * s); - var t = v * (1.0 - (1.0 - f) * s); - var c = [[v, t, p], [q, v, p], [p, v, t], [p, q, v], [t, p, v], [v, p, q]][hi]; - return { - r: c[0] * 255, - g: c[1] * 255, - b: c[2] * 255 - }; - }, - rgb_to_hsv: function rgb_to_hsv(r, g, b) { - var min = Math.min(r, g, b); - var max = Math.max(r, g, b); - var delta = max - min; - var h = void 0; - var s = void 0; - if (max !== 0) { - s = delta / max; - } else { - return { - h: NaN, - s: 0, - v: 0 - }; - } - if (r === max) { - h = (g - b) / delta; - } else if (g === max) { - h = 2 + (b - r) / delta; - } else { - h = 4 + (r - g) / delta; - } - h /= 6; - if (h < 0) { - h += 1; - } - return { - h: h * 360, - s: s, - v: max / 255 - }; - }, - rgb_to_hex: function rgb_to_hex(r, g, b) { - var hex = this.hex_with_component(0, 2, r); - hex = this.hex_with_component(hex, 1, g); - hex = this.hex_with_component(hex, 0, b); - return hex; - }, - component_from_hex: function component_from_hex(hex, componentIndex) { - return hex >> componentIndex * 8 & 0xFF; - }, - hex_with_component: function hex_with_component(hex, componentIndex, value) { - return value << (tmpComponent = componentIndex * 8) | hex & ~(0xFF << tmpComponent); - } -}; - -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { - return typeof obj; -} : function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; -}; - - - - - - - - - - - -var classCallCheck = function (instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } -}; - -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 get = function get(object, property, receiver) { - if (object === null) object = Function.prototype; - var desc = Object.getOwnPropertyDescriptor(object, property); - - if (desc === undefined) { - var parent = Object.getPrototypeOf(object); - - if (parent === null) { - return undefined; - } else { - return get(parent, property, receiver); - } - } else if ("value" in desc) { - return desc.value; - } else { - var getter = desc.get; - - if (getter === undefined) { - return undefined; - } - - return getter.call(receiver); - } -}; - -var inherits = function (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 possibleConstructorReturn = function (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; -}; - -var Color = function () { - function Color() { - classCallCheck(this, Color); - this.__state = interpret.apply(this, arguments); - if (this.__state === false) { - throw new Error('Failed to interpret color arguments'); - } - this.__state.a = this.__state.a || 1; - } - createClass(Color, [{ - key: 'toString', - value: function toString() { - return colorToString(this); - } - }, { - key: 'toHexString', - value: function toHexString() { - return colorToString(this, true); - } - }, { - key: 'toOriginal', - value: function toOriginal() { - return this.__state.conversion.write(this); - } - }]); - return Color; -}(); -function defineRGBComponent(target, component, componentHexIndex) { - Object.defineProperty(target, component, { - get: function get$$1() { - if (this.__state.space === 'RGB') { - return this.__state[component]; - } - Color.recalculateRGB(this, component, componentHexIndex); - return this.__state[component]; - }, - set: function set$$1(v) { - if (this.__state.space !== 'RGB') { - Color.recalculateRGB(this, component, componentHexIndex); - this.__state.space = 'RGB'; - } - this.__state[component] = v; - } - }); -} -function defineHSVComponent(target, component) { - Object.defineProperty(target, component, { - get: function get$$1() { - if (this.__state.space === 'HSV') { - return this.__state[component]; - } - Color.recalculateHSV(this); - return this.__state[component]; - }, - set: function set$$1(v) { - if (this.__state.space !== 'HSV') { - Color.recalculateHSV(this); - this.__state.space = 'HSV'; - } - this.__state[component] = v; - } - }); -} -Color.recalculateRGB = function (color, component, componentHexIndex) { - if (color.__state.space === 'HEX') { - color.__state[component] = ColorMath.component_from_hex(color.__state.hex, componentHexIndex); - } else if (color.__state.space === 'HSV') { - Common.extend(color.__state, ColorMath.hsv_to_rgb(color.__state.h, color.__state.s, color.__state.v)); - } else { - throw new Error('Corrupted color state'); - } -}; -Color.recalculateHSV = function (color) { - var result = ColorMath.rgb_to_hsv(color.r, color.g, color.b); - Common.extend(color.__state, { - s: result.s, - v: result.v - }); - if (!Common.isNaN(result.h)) { - color.__state.h = result.h; - } else if (Common.isUndefined(color.__state.h)) { - color.__state.h = 0; - } -}; -Color.COMPONENTS = ['r', 'g', 'b', 'h', 's', 'v', 'hex', 'a']; -defineRGBComponent(Color.prototype, 'r', 2); -defineRGBComponent(Color.prototype, 'g', 1); -defineRGBComponent(Color.prototype, 'b', 0); -defineHSVComponent(Color.prototype, 'h'); -defineHSVComponent(Color.prototype, 's'); -defineHSVComponent(Color.prototype, 'v'); -Object.defineProperty(Color.prototype, 'a', { - get: function get$$1() { - return this.__state.a; - }, - set: function set$$1(v) { - this.__state.a = v; - } -}); -Object.defineProperty(Color.prototype, 'hex', { - get: function get$$1() { - if (!this.__state.space !== 'HEX') { - this.__state.hex = ColorMath.rgb_to_hex(this.r, this.g, this.b); - } - return this.__state.hex; - }, - set: function set$$1(v) { - this.__state.space = 'HEX'; - this.__state.hex = v; - } -}); - -var Controller = function () { - function Controller(object, property) { - classCallCheck(this, Controller); - this.initialValue = object[property]; - this.domElement = document.createElement('div'); - this.object = object; - this.property = property; - this.__onChange = undefined; - this.__onFinishChange = undefined; - } - createClass(Controller, [{ - key: 'onChange', - value: function onChange(fnc) { - this.__onChange = fnc; - return this; - } - }, { - key: 'onFinishChange', - value: function onFinishChange(fnc) { - this.__onFinishChange = fnc; - return this; - } - }, { - key: 'setValue', - value: function setValue(newValue) { - this.object[this.property] = newValue; - if (this.__onChange) { - this.__onChange.call(this, newValue); - } - this.updateDisplay(); - return this; - } - }, { - key: 'getValue', - value: function getValue() { - return this.object[this.property]; - } - }, { - key: 'updateDisplay', - value: function updateDisplay() { - return this; - } - }, { - key: 'isModified', - value: function isModified() { - return this.initialValue !== this.getValue(); - } - }]); - return Controller; -}(); - -var EVENT_MAP = { - HTMLEvents: ['change'], - MouseEvents: ['click', 'mousemove', 'mousedown', 'mouseup', 'mouseover'], - KeyboardEvents: ['keydown'] -}; -var EVENT_MAP_INV = {}; -Common.each(EVENT_MAP, function (v, k) { - Common.each(v, function (e) { - EVENT_MAP_INV[e] = k; - }); -}); -var CSS_VALUE_PIXELS = /(\d+(\.\d+)?)px/; -function cssValueToPixels(val) { - if (val === '0' || Common.isUndefined(val)) { - return 0; - } - var match = val.match(CSS_VALUE_PIXELS); - if (!Common.isNull(match)) { - return parseFloat(match[1]); - } - return 0; -} -var dom = { - makeSelectable: function makeSelectable(elem, selectable) { - if (elem === undefined || elem.style === undefined) return; - elem.onselectstart = selectable ? function () { - return false; - } : function () {}; - elem.style.MozUserSelect = selectable ? 'auto' : 'none'; - elem.style.KhtmlUserSelect = selectable ? 'auto' : 'none'; - elem.unselectable = selectable ? 'on' : 'off'; - }, - makeFullscreen: function makeFullscreen(elem, hor, vert) { - var vertical = vert; - var horizontal = hor; - if (Common.isUndefined(horizontal)) { - horizontal = true; - } - if (Common.isUndefined(vertical)) { - vertical = true; - } - elem.style.position = 'absolute'; - if (horizontal) { - elem.style.left = 0; - elem.style.right = 0; - } - if (vertical) { - elem.style.top = 0; - elem.style.bottom = 0; - } - }, - fakeEvent: function fakeEvent(elem, eventType, pars, aux) { - var params = pars || {}; - var className = EVENT_MAP_INV[eventType]; - if (!className) { - throw new Error('Event type ' + eventType + ' not supported.'); - } - var evt = document.createEvent(className); - switch (className) { - case 'MouseEvents': - { - var clientX = params.x || params.clientX || 0; - var clientY = params.y || params.clientY || 0; - evt.initMouseEvent(eventType, params.bubbles || false, params.cancelable || true, window, params.clickCount || 1, 0, - 0, - clientX, - clientY, - false, false, false, false, 0, null); - break; - } - case 'KeyboardEvents': - { - var init = evt.initKeyboardEvent || evt.initKeyEvent; - Common.defaults(params, { - cancelable: true, - ctrlKey: false, - altKey: false, - shiftKey: false, - metaKey: false, - keyCode: undefined, - charCode: undefined - }); - init(eventType, params.bubbles || false, params.cancelable, window, params.ctrlKey, params.altKey, params.shiftKey, params.metaKey, params.keyCode, params.charCode); - break; - } - default: - { - evt.initEvent(eventType, params.bubbles || false, params.cancelable || true); - break; - } - } - Common.defaults(evt, aux); - elem.dispatchEvent(evt); - }, - bind: function bind(elem, event, func, newBool) { - var bool = newBool || false; - if (elem.addEventListener) { - elem.addEventListener(event, func, bool); - } else if (elem.attachEvent) { - elem.attachEvent('on' + event, func); - } - return dom; - }, - unbind: function unbind(elem, event, func, newBool) { - var bool = newBool || false; - if (elem.removeEventListener) { - elem.removeEventListener(event, func, bool); - } else if (elem.detachEvent) { - elem.detachEvent('on' + event, func); - } - return dom; - }, - addClass: function addClass(elem, className) { - if (elem.className === undefined) { - elem.className = className; - } else if (elem.className !== className) { - var classes = elem.className.split(/ +/); - if (classes.indexOf(className) === -1) { - classes.push(className); - elem.className = classes.join(' ').replace(/^\s+/, '').replace(/\s+$/, ''); - } - } - return dom; - }, - removeClass: function removeClass(elem, className) { - if (className) { - if (elem.className === className) { - elem.removeAttribute('class'); - } else { - var classes = elem.className.split(/ +/); - var index = classes.indexOf(className); - if (index !== -1) { - classes.splice(index, 1); - elem.className = classes.join(' '); - } - } - } else { - elem.className = undefined; - } - return dom; - }, - hasClass: function hasClass(elem, className) { - return new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)').test(elem.className) || false; - }, - getWidth: function getWidth(elem) { - var style = getComputedStyle(elem); - return cssValueToPixels(style['border-left-width']) + cssValueToPixels(style['border-right-width']) + cssValueToPixels(style['padding-left']) + cssValueToPixels(style['padding-right']) + cssValueToPixels(style.width); - }, - getHeight: function getHeight(elem) { - var style = getComputedStyle(elem); - return cssValueToPixels(style['border-top-width']) + cssValueToPixels(style['border-bottom-width']) + cssValueToPixels(style['padding-top']) + cssValueToPixels(style['padding-bottom']) + cssValueToPixels(style.height); - }, - getOffset: function getOffset(el) { - var elem = el; - var offset = { left: 0, top: 0 }; - if (elem.offsetParent) { - do { - offset.left += elem.offsetLeft; - offset.top += elem.offsetTop; - elem = elem.offsetParent; - } while (elem); - } - return offset; - }, - isActive: function isActive(elem) { - return elem === document.activeElement && (elem.type || elem.href); - } -}; - -var BooleanController = function (_Controller) { - inherits(BooleanController, _Controller); - function BooleanController(object, property) { - classCallCheck(this, BooleanController); - var _this2 = possibleConstructorReturn(this, (BooleanController.__proto__ || Object.getPrototypeOf(BooleanController)).call(this, object, property)); - var _this = _this2; - _this2.__prev = _this2.getValue(); - _this2.__checkbox = document.createElement('input'); - _this2.__checkbox.setAttribute('type', 'checkbox'); - function onChange() { - _this.setValue(!_this.__prev); - } - dom.bind(_this2.__checkbox, 'change', onChange, false); - _this2.domElement.appendChild(_this2.__checkbox); - _this2.updateDisplay(); - return _this2; - } - createClass(BooleanController, [{ - key: 'setValue', - value: function setValue(v) { - var toReturn = get(BooleanController.prototype.__proto__ || Object.getPrototypeOf(BooleanController.prototype), 'setValue', this).call(this, v); - if (this.__onFinishChange) { - this.__onFinishChange.call(this, this.getValue()); - } - this.__prev = this.getValue(); - return toReturn; - } - }, { - key: 'updateDisplay', - value: function updateDisplay() { - if (this.getValue() === true) { - this.__checkbox.setAttribute('checked', 'checked'); - this.__checkbox.checked = true; - this.__prev = true; - } else { - this.__checkbox.checked = false; - this.__prev = false; - } - return get(BooleanController.prototype.__proto__ || Object.getPrototypeOf(BooleanController.prototype), 'updateDisplay', this).call(this); - } - }]); - return BooleanController; -}(Controller); - -var OptionController = function (_Controller) { - inherits(OptionController, _Controller); - function OptionController(object, property, opts) { - classCallCheck(this, OptionController); - var _this2 = possibleConstructorReturn(this, (OptionController.__proto__ || Object.getPrototypeOf(OptionController)).call(this, object, property)); - var options = opts; - var _this = _this2; - _this2.__select = document.createElement('select'); - if (Common.isArray(options)) { - var map = {}; - Common.each(options, function (element) { - map[element] = element; - }); - options = map; - } - Common.each(options, function (value, key) { - var opt = document.createElement('option'); - opt.innerHTML = key; - opt.setAttribute('value', value); - _this.__select.appendChild(opt); - }); - _this2.updateDisplay(); - dom.bind(_this2.__select, 'change', function () { - var desiredValue = this.options[this.selectedIndex].value; - _this.setValue(desiredValue); - }); - _this2.domElement.appendChild(_this2.__select); - return _this2; - } - createClass(OptionController, [{ - key: 'setValue', - value: function setValue(v) { - var toReturn = get(OptionController.prototype.__proto__ || Object.getPrototypeOf(OptionController.prototype), 'setValue', this).call(this, v); - if (this.__onFinishChange) { - this.__onFinishChange.call(this, this.getValue()); - } - return toReturn; - } - }, { - key: 'updateDisplay', - value: function updateDisplay() { - if (dom.isActive(this.__select)) return this; - this.__select.value = this.getValue(); - return get(OptionController.prototype.__proto__ || Object.getPrototypeOf(OptionController.prototype), 'updateDisplay', this).call(this); - } - }]); - return OptionController; -}(Controller); - -var StringController = function (_Controller) { - inherits(StringController, _Controller); - function StringController(object, property) { - classCallCheck(this, StringController); - var _this2 = possibleConstructorReturn(this, (StringController.__proto__ || Object.getPrototypeOf(StringController)).call(this, object, property)); - var _this = _this2; - function onChange() { - _this.setValue(_this.__input.value); - } - function onBlur() { - if (_this.__onFinishChange) { - _this.__onFinishChange.call(_this, _this.getValue()); - } - } - _this2.__input = document.createElement('input'); - _this2.__input.setAttribute('type', 'text'); - dom.bind(_this2.__input, 'keyup', onChange); - dom.bind(_this2.__input, 'change', onChange); - dom.bind(_this2.__input, 'blur', onBlur); - dom.bind(_this2.__input, 'keydown', function (e) { - if (e.keyCode === 13) { - this.blur(); - } - }); - _this2.updateDisplay(); - _this2.domElement.appendChild(_this2.__input); - return _this2; - } - createClass(StringController, [{ - key: 'updateDisplay', - value: function updateDisplay() { - if (!dom.isActive(this.__input)) { - this.__input.value = this.getValue(); - } - return get(StringController.prototype.__proto__ || Object.getPrototypeOf(StringController.prototype), 'updateDisplay', this).call(this); - } - }]); - return StringController; -}(Controller); - -function numDecimals(x) { - var _x = x.toString(); - if (_x.indexOf('.') > -1) { - return _x.length - _x.indexOf('.') - 1; - } - return 0; -} -var NumberController = function (_Controller) { - inherits(NumberController, _Controller); - function NumberController(object, property, params) { - classCallCheck(this, NumberController); - var _this = possibleConstructorReturn(this, (NumberController.__proto__ || Object.getPrototypeOf(NumberController)).call(this, object, property)); - var _params = params || {}; - _this.__min = _params.min; - _this.__max = _params.max; - _this.__step = _params.step; - if (Common.isUndefined(_this.__step)) { - if (_this.initialValue === 0) { - _this.__impliedStep = 1; - } else { - _this.__impliedStep = Math.pow(10, Math.floor(Math.log(Math.abs(_this.initialValue)) / Math.LN10)) / 10; - } - } else { - _this.__impliedStep = _this.__step; - } - _this.__precision = numDecimals(_this.__impliedStep); - return _this; - } - createClass(NumberController, [{ - key: 'setValue', - value: function setValue(v) { - var _v = v; - if (this.__min !== undefined && _v < this.__min) { - _v = this.__min; - } else if (this.__max !== undefined && _v > this.__max) { - _v = this.__max; - } - if (this.__step !== undefined && _v % this.__step !== 0) { - _v = Math.round(_v / this.__step) * this.__step; - } - return get(NumberController.prototype.__proto__ || Object.getPrototypeOf(NumberController.prototype), 'setValue', this).call(this, _v); - } - }, { - key: 'min', - value: function min(minValue) { - this.__min = minValue; - return this; - } - }, { - key: 'max', - value: function max(maxValue) { - this.__max = maxValue; - return this; - } - }, { - key: 'step', - value: function step(stepValue) { - this.__step = stepValue; - this.__impliedStep = stepValue; - this.__precision = numDecimals(stepValue); - return this; - } - }]); - return NumberController; -}(Controller); - -function roundToDecimal(value, decimals) { - var tenTo = Math.pow(10, decimals); - return Math.round(value * tenTo) / tenTo; -} -var NumberControllerBox = function (_NumberController) { - inherits(NumberControllerBox, _NumberController); - function NumberControllerBox(object, property, params) { - classCallCheck(this, NumberControllerBox); - var _this2 = possibleConstructorReturn(this, (NumberControllerBox.__proto__ || Object.getPrototypeOf(NumberControllerBox)).call(this, object, property, params)); - _this2.__truncationSuspended = false; - var _this = _this2; - var prevY = void 0; - function onChange() { - var attempted = parseFloat(_this.__input.value); - if (!Common.isNaN(attempted)) { - _this.setValue(attempted); - } - } - function onFinish() { - if (_this.__onFinishChange) { - _this.__onFinishChange.call(_this, _this.getValue()); - } - } - function onBlur() { - onFinish(); - } - function onMouseDrag(e) { - var diff = prevY - e.clientY; - _this.setValue(_this.getValue() + diff * _this.__impliedStep); - prevY = e.clientY; - } - function onMouseUp() { - dom.unbind(window, 'mousemove', onMouseDrag); - dom.unbind(window, 'mouseup', onMouseUp); - onFinish(); - } - function onMouseDown(e) { - dom.bind(window, 'mousemove', onMouseDrag); - dom.bind(window, 'mouseup', onMouseUp); - prevY = e.clientY; - } - _this2.__input = document.createElement('input'); - _this2.__input.setAttribute('type', 'text'); - dom.bind(_this2.__input, 'change', onChange); - dom.bind(_this2.__input, 'blur', onBlur); - dom.bind(_this2.__input, 'mousedown', onMouseDown); - dom.bind(_this2.__input, 'keydown', function (e) { - if (e.keyCode === 13) { - _this.__truncationSuspended = true; - this.blur(); - _this.__truncationSuspended = false; - onFinish(); - } - }); - _this2.updateDisplay(); - _this2.domElement.appendChild(_this2.__input); - return _this2; - } - createClass(NumberControllerBox, [{ - key: 'updateDisplay', - value: function updateDisplay() { - this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal(this.getValue(), this.__precision); - return get(NumberControllerBox.prototype.__proto__ || Object.getPrototypeOf(NumberControllerBox.prototype), 'updateDisplay', this).call(this); - } - }]); - return NumberControllerBox; -}(NumberController); - -function map(v, i1, i2, o1, o2) { - return o1 + (o2 - o1) * ((v - i1) / (i2 - i1)); -} -var NumberControllerSlider = function (_NumberController) { - inherits(NumberControllerSlider, _NumberController); - function NumberControllerSlider(object, property, min, max, step) { - classCallCheck(this, NumberControllerSlider); - var _this2 = possibleConstructorReturn(this, (NumberControllerSlider.__proto__ || Object.getPrototypeOf(NumberControllerSlider)).call(this, object, property, { min: min, max: max, step: step })); - var _this = _this2; - _this2.__background = document.createElement('div'); - _this2.__foreground = document.createElement('div'); - dom.bind(_this2.__background, 'mousedown', onMouseDown); - dom.bind(_this2.__background, 'touchstart', onTouchStart); - dom.addClass(_this2.__background, 'slider'); - dom.addClass(_this2.__foreground, 'slider-fg'); - function onMouseDown(e) { - document.activeElement.blur(); - dom.bind(window, 'mousemove', onMouseDrag); - dom.bind(window, 'mouseup', onMouseUp); - onMouseDrag(e); - } - function onMouseDrag(e) { - e.preventDefault(); - var bgRect = _this.__background.getBoundingClientRect(); - _this.setValue(map(e.clientX, bgRect.left, bgRect.right, _this.__min, _this.__max)); - return false; - } - function onMouseUp() { - dom.unbind(window, 'mousemove', onMouseDrag); - dom.unbind(window, 'mouseup', onMouseUp); - if (_this.__onFinishChange) { - _this.__onFinishChange.call(_this, _this.getValue()); - } - } - function onTouchStart(e) { - if (e.touches.length !== 1) { - return; - } - dom.bind(window, 'touchmove', onTouchMove); - dom.bind(window, 'touchend', onTouchEnd); - onTouchMove(e); - } - function onTouchMove(e) { - var clientX = e.touches[0].clientX; - var bgRect = _this.__background.getBoundingClientRect(); - _this.setValue(map(clientX, bgRect.left, bgRect.right, _this.__min, _this.__max)); - } - function onTouchEnd() { - dom.unbind(window, 'touchmove', onTouchMove); - dom.unbind(window, 'touchend', onTouchEnd); - if (_this.__onFinishChange) { - _this.__onFinishChange.call(_this, _this.getValue()); - } - } - _this2.updateDisplay(); - _this2.__background.appendChild(_this2.__foreground); - _this2.domElement.appendChild(_this2.__background); - return _this2; - } - createClass(NumberControllerSlider, [{ - key: 'updateDisplay', - value: function updateDisplay() { - var pct = (this.getValue() - this.__min) / (this.__max - this.__min); - this.__foreground.style.width = pct * 100 + '%'; - return get(NumberControllerSlider.prototype.__proto__ || Object.getPrototypeOf(NumberControllerSlider.prototype), 'updateDisplay', this).call(this); - } - }]); - return NumberControllerSlider; -}(NumberController); - -var FunctionController = function (_Controller) { - inherits(FunctionController, _Controller); - function FunctionController(object, property, text) { - classCallCheck(this, FunctionController); - var _this2 = possibleConstructorReturn(this, (FunctionController.__proto__ || Object.getPrototypeOf(FunctionController)).call(this, object, property)); - var _this = _this2; - _this2.__button = document.createElement('div'); - _this2.__button.innerHTML = text === undefined ? 'Fire' : text; - dom.bind(_this2.__button, 'click', function (e) { - e.preventDefault(); - _this.fire(); - return false; - }); - dom.addClass(_this2.__button, 'button'); - _this2.domElement.appendChild(_this2.__button); - return _this2; - } - createClass(FunctionController, [{ - key: 'fire', - value: function fire() { - if (this.__onChange) { - this.__onChange.call(this); - } - this.getValue().call(this.object); - if (this.__onFinishChange) { - this.__onFinishChange.call(this, this.getValue()); - } - } - }]); - return FunctionController; -}(Controller); - -var ColorController = function (_Controller) { - inherits(ColorController, _Controller); - function ColorController(object, property) { - classCallCheck(this, ColorController); - var _this2 = possibleConstructorReturn(this, (ColorController.__proto__ || Object.getPrototypeOf(ColorController)).call(this, object, property)); - _this2.__color = new Color(_this2.getValue()); - _this2.__temp = new Color(0); - var _this = _this2; - _this2.domElement = document.createElement('div'); - dom.makeSelectable(_this2.domElement, false); - _this2.__selector = document.createElement('div'); - _this2.__selector.className = 'selector'; - _this2.__saturation_field = document.createElement('div'); - _this2.__saturation_field.className = 'saturation-field'; - _this2.__field_knob = document.createElement('div'); - _this2.__field_knob.className = 'field-knob'; - _this2.__field_knob_border = '2px solid '; - _this2.__hue_knob = document.createElement('div'); - _this2.__hue_knob.className = 'hue-knob'; - _this2.__hue_field = document.createElement('div'); - _this2.__hue_field.className = 'hue-field'; - _this2.__input = document.createElement('input'); - _this2.__input.type = 'text'; - _this2.__input_textShadow = '0 1px 1px '; - dom.bind(_this2.__input, 'keydown', function (e) { - if (e.keyCode === 13) { - onBlur.call(this); - } - }); - dom.bind(_this2.__input, 'blur', onBlur); - dom.bind(_this2.__selector, 'mousedown', function () { - dom.addClass(this, 'drag').bind(window, 'mouseup', function () { - dom.removeClass(_this.__selector, 'drag'); - }); - }); - dom.bind(_this2.__selector, 'touchstart', function () { - dom.addClass(this, 'drag').bind(window, 'touchend', function () { - dom.removeClass(_this.__selector, 'drag'); - }); - }); - var valueField = document.createElement('div'); - Common.extend(_this2.__selector.style, { - width: '122px', - height: '102px', - padding: '3px', - backgroundColor: '#222', - boxShadow: '0px 1px 3px rgba(0,0,0,0.3)' - }); - Common.extend(_this2.__field_knob.style, { - position: 'absolute', - width: '12px', - height: '12px', - border: _this2.__field_knob_border + (_this2.__color.v < 0.5 ? '#fff' : '#000'), - boxShadow: '0px 1px 3px rgba(0,0,0,0.5)', - borderRadius: '12px', - zIndex: 1 - }); - Common.extend(_this2.__hue_knob.style, { - position: 'absolute', - width: '15px', - height: '2px', - borderRight: '4px solid #fff', - zIndex: 1 - }); - Common.extend(_this2.__saturation_field.style, { - width: '100px', - height: '100px', - border: '1px solid #555', - marginRight: '3px', - display: 'inline-block', - cursor: 'pointer' - }); - Common.extend(valueField.style, { - width: '100%', - height: '100%', - background: 'none' - }); - linearGradient(valueField, 'top', 'rgba(0,0,0,0)', '#000'); - Common.extend(_this2.__hue_field.style, { - width: '15px', - height: '100px', - border: '1px solid #555', - cursor: 'ns-resize', - position: 'absolute', - top: '3px', - right: '3px' - }); - hueGradient(_this2.__hue_field); - Common.extend(_this2.__input.style, { - outline: 'none', - textAlign: 'center', - color: '#fff', - border: 0, - fontWeight: 'bold', - textShadow: _this2.__input_textShadow + 'rgba(0,0,0,0.7)' - }); - dom.bind(_this2.__saturation_field, 'mousedown', fieldDown); - dom.bind(_this2.__saturation_field, 'touchstart', fieldDown); - dom.bind(_this2.__field_knob, 'mousedown', fieldDown); - dom.bind(_this2.__field_knob, 'touchstart', fieldDown); - dom.bind(_this2.__hue_field, 'mousedown', fieldDownH); - dom.bind(_this2.__hue_field, 'touchstart', fieldDownH); - function fieldDown(e) { - setSV(e); - dom.bind(window, 'mousemove', setSV); - dom.bind(window, 'touchmove', setSV); - dom.bind(window, 'mouseup', fieldUpSV); - dom.bind(window, 'touchend', fieldUpSV); - } - function fieldDownH(e) { - setH(e); - dom.bind(window, 'mousemove', setH); - dom.bind(window, 'touchmove', setH); - dom.bind(window, 'mouseup', fieldUpH); - dom.bind(window, 'touchend', fieldUpH); - } - function fieldUpSV() { - dom.unbind(window, 'mousemove', setSV); - dom.unbind(window, 'touchmove', setSV); - dom.unbind(window, 'mouseup', fieldUpSV); - dom.unbind(window, 'touchend', fieldUpSV); - onFinish(); - } - function fieldUpH() { - dom.unbind(window, 'mousemove', setH); - dom.unbind(window, 'touchmove', setH); - dom.unbind(window, 'mouseup', fieldUpH); - dom.unbind(window, 'touchend', fieldUpH); - onFinish(); - } - function onBlur() { - var i = interpret(this.value); - if (i !== false) { - _this.__color.__state = i; - _this.setValue(_this.__color.toOriginal()); - } else { - this.value = _this.__color.toString(); - } - } - function onFinish() { - if (_this.__onFinishChange) { - _this.__onFinishChange.call(_this, _this.__color.toOriginal()); - } - } - _this2.__saturation_field.appendChild(valueField); - _this2.__selector.appendChild(_this2.__field_knob); - _this2.__selector.appendChild(_this2.__saturation_field); - _this2.__selector.appendChild(_this2.__hue_field); - _this2.__hue_field.appendChild(_this2.__hue_knob); - _this2.domElement.appendChild(_this2.__input); - _this2.domElement.appendChild(_this2.__selector); - _this2.updateDisplay(); - function setSV(e) { - if (e.type.indexOf('touch') === -1) { - e.preventDefault(); - } - var fieldRect = _this.__saturation_field.getBoundingClientRect(); - var _ref = e.touches && e.touches[0] || e, - clientX = _ref.clientX, - clientY = _ref.clientY; - var s = (clientX - fieldRect.left) / (fieldRect.right - fieldRect.left); - var v = 1 - (clientY - fieldRect.top) / (fieldRect.bottom - fieldRect.top); - if (v > 1) { - v = 1; - } else if (v < 0) { - v = 0; - } - if (s > 1) { - s = 1; - } else if (s < 0) { - s = 0; - } - _this.__color.v = v; - _this.__color.s = s; - _this.setValue(_this.__color.toOriginal()); - return false; - } - function setH(e) { - if (e.type.indexOf('touch') === -1) { - e.preventDefault(); - } - var fieldRect = _this.__hue_field.getBoundingClientRect(); - var _ref2 = e.touches && e.touches[0] || e, - clientY = _ref2.clientY; - var h = 1 - (clientY - fieldRect.top) / (fieldRect.bottom - fieldRect.top); - if (h > 1) { - h = 1; - } else if (h < 0) { - h = 0; - } - _this.__color.h = h * 360; - _this.setValue(_this.__color.toOriginal()); - return false; - } - return _this2; - } - createClass(ColorController, [{ - key: 'updateDisplay', - value: function updateDisplay() { - var i = interpret(this.getValue()); - if (i !== false) { - var mismatch = false; - Common.each(Color.COMPONENTS, function (component) { - if (!Common.isUndefined(i[component]) && !Common.isUndefined(this.__color.__state[component]) && i[component] !== this.__color.__state[component]) { - mismatch = true; - return {}; - } - }, this); - if (mismatch) { - Common.extend(this.__color.__state, i); - } - } - Common.extend(this.__temp.__state, this.__color.__state); - this.__temp.a = 1; - var flip = this.__color.v < 0.5 || this.__color.s > 0.5 ? 255 : 0; - var _flip = 255 - flip; - Common.extend(this.__field_knob.style, { - marginLeft: 100 * this.__color.s - 7 + 'px', - marginTop: 100 * (1 - this.__color.v) - 7 + 'px', - backgroundColor: this.__temp.toHexString(), - border: this.__field_knob_border + 'rgb(' + flip + ',' + flip + ',' + flip + ')' - }); - this.__hue_knob.style.marginTop = (1 - this.__color.h / 360) * 100 + 'px'; - this.__temp.s = 1; - this.__temp.v = 1; - linearGradient(this.__saturation_field, 'left', '#fff', this.__temp.toHexString()); - this.__input.value = this.__color.toString(); - Common.extend(this.__input.style, { - backgroundColor: this.__color.toHexString(), - color: 'rgb(' + flip + ',' + flip + ',' + flip + ')', - textShadow: this.__input_textShadow + 'rgba(' + _flip + ',' + _flip + ',' + _flip + ',.7)' - }); - } - }]); - return ColorController; -}(Controller); -var vendors = ['-moz-', '-o-', '-webkit-', '-ms-', '']; -function linearGradient(elem, x, a, b) { - elem.style.background = ''; - Common.each(vendors, function (vendor) { - elem.style.cssText += 'background: ' + vendor + 'linear-gradient(' + x + ', ' + a + ' 0%, ' + b + ' 100%); '; - }); -} -function hueGradient(elem) { - elem.style.background = ''; - elem.style.cssText += 'background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);'; - elem.style.cssText += 'background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; - elem.style.cssText += 'background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; - elem.style.cssText += 'background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; - elem.style.cssText += 'background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; -} - -var css = { - load: function load(url, indoc) { - var doc = indoc || document; - var link = doc.createElement('link'); - link.type = 'text/css'; - link.rel = 'stylesheet'; - link.href = url; - doc.getElementsByTagName('head')[0].appendChild(link); - }, - inject: function inject(cssContent, indoc) { - var doc = indoc || document; - var injected = document.createElement('style'); - injected.type = 'text/css'; - injected.innerHTML = cssContent; - var head = doc.getElementsByTagName('head')[0]; - try { - head.appendChild(injected); - } catch (e) { - } - } -}; - -var saveDialogContents = "
\n\n Here's the new load parameter for your GUI's constructor:\n\n \n\n
\n\n Automatically save\n values to localStorage on exit.\n\n
The values saved to localStorage will\n override those passed to dat.GUI's constructor. This makes it\n easier to work incrementally, but localStorage is fragile,\n and your friends may not see the same values you do.\n\n
\n\n
\n\n
"; - -var ControllerFactory = function ControllerFactory(object, property) { - var initialValue = object[property]; - if (Common.isArray(arguments[2]) || Common.isObject(arguments[2])) { - return new OptionController(object, property, arguments[2]); - } - if (Common.isNumber(initialValue)) { - if (Common.isNumber(arguments[2]) && Common.isNumber(arguments[3])) { - if (Common.isNumber(arguments[4])) { - return new NumberControllerSlider(object, property, arguments[2], arguments[3], arguments[4]); - } - return new NumberControllerSlider(object, property, arguments[2], arguments[3]); - } - if (Common.isNumber(arguments[4])) { - return new NumberControllerBox(object, property, { min: arguments[2], max: arguments[3], step: arguments[4] }); - } - return new NumberControllerBox(object, property, { min: arguments[2], max: arguments[3] }); - } - if (Common.isString(initialValue)) { - return new StringController(object, property); - } - if (Common.isFunction(initialValue)) { - return new FunctionController(object, property, ''); - } - if (Common.isBoolean(initialValue)) { - return new BooleanController(object, property); - } - return null; -}; - -function requestAnimationFrame(callback) { - setTimeout(callback, 1000 / 60); -} -var requestAnimationFrame$1 = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || requestAnimationFrame; - -var CenteredDiv = function () { - function CenteredDiv() { - classCallCheck(this, CenteredDiv); - this.backgroundElement = document.createElement('div'); - Common.extend(this.backgroundElement.style, { - backgroundColor: 'rgba(0,0,0,0.8)', - top: 0, - left: 0, - display: 'none', - zIndex: '1000', - opacity: 0, - WebkitTransition: 'opacity 0.2s linear', - transition: 'opacity 0.2s linear' - }); - dom.makeFullscreen(this.backgroundElement); - this.backgroundElement.style.position = 'fixed'; - this.domElement = document.createElement('div'); - Common.extend(this.domElement.style, { - position: 'fixed', - display: 'none', - zIndex: '1001', - opacity: 0, - WebkitTransition: '-webkit-transform 0.2s ease-out, opacity 0.2s linear', - transition: 'transform 0.2s ease-out, opacity 0.2s linear' - }); - document.body.appendChild(this.backgroundElement); - document.body.appendChild(this.domElement); - var _this = this; - dom.bind(this.backgroundElement, 'click', function () { - _this.hide(); - }); - } - createClass(CenteredDiv, [{ - key: 'show', - value: function show() { - var _this = this; - this.backgroundElement.style.display = 'block'; - this.domElement.style.display = 'block'; - this.domElement.style.opacity = 0; - this.domElement.style.webkitTransform = 'scale(1.1)'; - this.layout(); - Common.defer(function () { - _this.backgroundElement.style.opacity = 1; - _this.domElement.style.opacity = 1; - _this.domElement.style.webkitTransform = 'scale(1)'; - }); - } - }, { - key: 'hide', - value: function hide() { - var _this = this; - var hide = function hide() { - _this.domElement.style.display = 'none'; - _this.backgroundElement.style.display = 'none'; - dom.unbind(_this.domElement, 'webkitTransitionEnd', hide); - dom.unbind(_this.domElement, 'transitionend', hide); - dom.unbind(_this.domElement, 'oTransitionEnd', hide); - }; - dom.bind(this.domElement, 'webkitTransitionEnd', hide); - dom.bind(this.domElement, 'transitionend', hide); - dom.bind(this.domElement, 'oTransitionEnd', hide); - this.backgroundElement.style.opacity = 0; - this.domElement.style.opacity = 0; - this.domElement.style.webkitTransform = 'scale(1.1)'; - } - }, { - key: 'layout', - value: function layout() { - this.domElement.style.left = window.innerWidth / 2 - dom.getWidth(this.domElement) / 2 + 'px'; - this.domElement.style.top = window.innerHeight / 2 - dom.getHeight(this.domElement) / 2 + 'px'; - } - }]); - return CenteredDiv; -}(); - -var styleSheet = ___$insertStyle(".dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1 !important}.dg.main:hover .close-button,.dg.main .close-button.drag{opacity:1}.dg.main .close-button{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear;border:0;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button.close-top{position:relative}.dg.main .close-button.close-bottom{position:absolute}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-y:visible}.dg.a.has-save>ul.close-top{margin-top:0}.dg.a.has-save>ul.close-bottom{margin-top:27px}.dg.a.has-save>ul.closed{margin-top:0}.dg.a .save-row{top:0;z-index:1002}.dg.a .save-row.close-top{position:relative}.dg.a .save-row.close-bottom{position:fixed}.dg li{-webkit-transition:height .1s ease-out;-o-transition:height .1s ease-out;-moz-transition:height .1s ease-out;transition:height .1s ease-out;-webkit-transition:overflow .1s linear;-o-transition:overflow .1s linear;-moz-transition:overflow .1s linear;transition:overflow .1s linear}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid rgba(0,0,0,0)}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li>*{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px;overflow:hidden}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%;position:relative}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:7px}.dg .c select{margin-top:5px}.dg .cr.function,.dg .cr.function .property-name,.dg .cr.function *,.dg .cr.boolean,.dg .cr.boolean *{cursor:pointer}.dg .cr.color{overflow:visible}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0px 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco, monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px 'Lucida Grande', sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px 4px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid rgba(255,255,255,0.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.color{border-left:3px solid}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2FA1D6}.dg .cr.number input[type=text]{color:#2FA1D6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.function:hover,.dg .cr.boolean:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2FA1D6;max-width:100%}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n"); - -css.inject(styleSheet); -var CSS_NAMESPACE = 'dg'; -var HIDE_KEY_CODE = 72; -var CLOSE_BUTTON_HEIGHT = 20; -var DEFAULT_DEFAULT_PRESET_NAME = 'Default'; -var SUPPORTS_LOCAL_STORAGE = function () { - try { - return !!window.localStorage; - } catch (e) { - return false; - } -}(); -var SAVE_DIALOGUE = void 0; -var autoPlaceVirgin = true; -var autoPlaceContainer = void 0; -var hide = false; -var hideableGuis = []; -var GUI = function GUI(pars) { - var _this = this; - var params = pars || {}; - this.domElement = document.createElement('div'); - this.__ul = document.createElement('ul'); - this.domElement.appendChild(this.__ul); - dom.addClass(this.domElement, CSS_NAMESPACE); - this.__folders = {}; - this.__controllers = []; - this.__rememberedObjects = []; - this.__rememberedObjectIndecesToControllers = []; - this.__listening = []; - params = Common.defaults(params, { - closeOnTop: false, - autoPlace: true, - width: GUI.DEFAULT_WIDTH - }); - params = Common.defaults(params, { - resizable: params.autoPlace, - hideable: params.autoPlace - }); - if (!Common.isUndefined(params.load)) { - if (params.preset) { - params.load.preset = params.preset; - } - } else { - params.load = { preset: DEFAULT_DEFAULT_PRESET_NAME }; - } - if (Common.isUndefined(params.parent) && params.hideable) { - hideableGuis.push(this); - } - params.resizable = Common.isUndefined(params.parent) && params.resizable; - if (params.autoPlace && Common.isUndefined(params.scrollable)) { - params.scrollable = true; - } - var useLocalStorage = SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true'; - var saveToLocalStorage = void 0; - var titleRow = void 0; - Object.defineProperties(this, - { - parent: { - get: function get$$1() { - return params.parent; - } - }, - scrollable: { - get: function get$$1() { - return params.scrollable; - } - }, - autoPlace: { - get: function get$$1() { - return params.autoPlace; - } - }, - closeOnTop: { - get: function get$$1() { - return params.closeOnTop; - } - }, - preset: { - get: function get$$1() { - if (_this.parent) { - return _this.getRoot().preset; - } - return params.load.preset; - }, - set: function set$$1(v) { - if (_this.parent) { - _this.getRoot().preset = v; - } else { - params.load.preset = v; - } - setPresetSelectIndex(this); - _this.revert(); - } - }, - width: { - get: function get$$1() { - return params.width; - }, - set: function set$$1(v) { - params.width = v; - setWidth(_this, v); - } - }, - name: { - get: function get$$1() { - return params.name; - }, - set: function set$$1(v) { - params.name = v; - if (titleRow) { - titleRow.innerHTML = params.name; - } - } - }, - closed: { - get: function get$$1() { - return params.closed; - }, - set: function set$$1(v) { - params.closed = v; - if (params.closed) { - dom.addClass(_this.__ul, GUI.CLASS_CLOSED); - } else { - dom.removeClass(_this.__ul, GUI.CLASS_CLOSED); - } - this.onResize(); - if (_this.__closeButton) { - _this.__closeButton.innerHTML = v ? GUI.TEXT_OPEN : GUI.TEXT_CLOSED; - } - } - }, - load: { - get: function get$$1() { - return params.load; - } - }, - useLocalStorage: { - get: function get$$1() { - return useLocalStorage; - }, - set: function set$$1(bool) { - if (SUPPORTS_LOCAL_STORAGE) { - useLocalStorage = bool; - if (bool) { - dom.bind(window, 'unload', saveToLocalStorage); - } else { - dom.unbind(window, 'unload', saveToLocalStorage); - } - localStorage.setItem(getLocalStorageHash(_this, 'isLocal'), bool); - } - } - } - }); - if (Common.isUndefined(params.parent)) { - this.closed = params.closed || false; - dom.addClass(this.domElement, GUI.CLASS_MAIN); - dom.makeSelectable(this.domElement, false); - if (SUPPORTS_LOCAL_STORAGE) { - if (useLocalStorage) { - _this.useLocalStorage = true; - var savedGui = localStorage.getItem(getLocalStorageHash(this, 'gui')); - if (savedGui) { - params.load = JSON.parse(savedGui); - } - } - } - this.__closeButton = document.createElement('div'); - this.__closeButton.innerHTML = GUI.TEXT_CLOSED; - dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BUTTON); - if (params.closeOnTop) { - dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_TOP); - this.domElement.insertBefore(this.__closeButton, this.domElement.childNodes[0]); - } else { - dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BOTTOM); - this.domElement.appendChild(this.__closeButton); - } - dom.bind(this.__closeButton, 'click', function () { - _this.closed = !_this.closed; - }); - } else { - if (params.closed === undefined) { - params.closed = true; - } - var titleRowName = document.createTextNode(params.name); - dom.addClass(titleRowName, 'controller-name'); - titleRow = addRow(_this, titleRowName); - var onClickTitle = function onClickTitle(e) { - e.preventDefault(); - _this.closed = !_this.closed; - return false; - }; - dom.addClass(this.__ul, GUI.CLASS_CLOSED); - dom.addClass(titleRow, 'title'); - dom.bind(titleRow, 'click', onClickTitle); - if (!params.closed) { - this.closed = false; - } - } - if (params.autoPlace) { - if (Common.isUndefined(params.parent)) { - if (autoPlaceVirgin) { - autoPlaceContainer = document.createElement('div'); - dom.addClass(autoPlaceContainer, CSS_NAMESPACE); - dom.addClass(autoPlaceContainer, GUI.CLASS_AUTO_PLACE_CONTAINER); - document.body.appendChild(autoPlaceContainer); - autoPlaceVirgin = false; - } - autoPlaceContainer.appendChild(this.domElement); - dom.addClass(this.domElement, GUI.CLASS_AUTO_PLACE); - } - if (!this.parent) { - setWidth(_this, params.width); - } - } - this.__resizeHandler = function () { - _this.onResizeDebounced(); - }; - dom.bind(window, 'resize', this.__resizeHandler); - dom.bind(this.__ul, 'webkitTransitionEnd', this.__resizeHandler); - dom.bind(this.__ul, 'transitionend', this.__resizeHandler); - dom.bind(this.__ul, 'oTransitionEnd', this.__resizeHandler); - this.onResize(); - if (params.resizable) { - addResizeHandle(this); - } - saveToLocalStorage = function saveToLocalStorage() { - if (SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(_this, 'isLocal')) === 'true') { - localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject())); - } - }; - this.saveToLocalStorageIfPossible = saveToLocalStorage; - function resetWidth() { - var root = _this.getRoot(); - root.width += 1; - Common.defer(function () { - root.width -= 1; - }); - } - if (!params.parent) { - resetWidth(); - } -}; -GUI.toggleHide = function () { - hide = !hide; - Common.each(hideableGuis, function (gui) { - gui.domElement.style.display = hide ? 'none' : ''; - }); -}; -GUI.CLASS_AUTO_PLACE = 'a'; -GUI.CLASS_AUTO_PLACE_CONTAINER = 'ac'; -GUI.CLASS_MAIN = 'main'; -GUI.CLASS_CONTROLLER_ROW = 'cr'; -GUI.CLASS_TOO_TALL = 'taller-than-window'; -GUI.CLASS_CLOSED = 'closed'; -GUI.CLASS_CLOSE_BUTTON = 'close-button'; -GUI.CLASS_CLOSE_TOP = 'close-top'; -GUI.CLASS_CLOSE_BOTTOM = 'close-bottom'; -GUI.CLASS_DRAG = 'drag'; -GUI.DEFAULT_WIDTH = 245; -GUI.TEXT_CLOSED = 'Close Controls'; -GUI.TEXT_OPEN = 'Open Controls'; -GUI._keydownHandler = function (e) { - if (document.activeElement.type !== 'text' && (e.which === HIDE_KEY_CODE || e.keyCode === HIDE_KEY_CODE)) { - GUI.toggleHide(); - } -}; -dom.bind(window, 'keydown', GUI._keydownHandler, false); -Common.extend(GUI.prototype, -{ - add: function add(object, property) { - return _add(this, object, property, { - factoryArgs: Array.prototype.slice.call(arguments, 2) - }); - }, - addColor: function addColor(object, property) { - return _add(this, object, property, { - color: true - }); - }, - remove: function remove(controller) { - this.__ul.removeChild(controller.__li); - this.__controllers.splice(this.__controllers.indexOf(controller), 1); - var _this = this; - Common.defer(function () { - _this.onResize(); - }); - }, - destroy: function destroy() { - if (this.parent) { - throw new Error('Only the root GUI should be removed with .destroy(). ' + 'For subfolders, use gui.removeFolder(folder) instead.'); - } - if (this.autoPlace) { - autoPlaceContainer.removeChild(this.domElement); - } - var _this = this; - Common.each(this.__folders, function (subfolder) { - _this.removeFolder(subfolder); - }); - dom.unbind(window, 'keydown', GUI._keydownHandler, false); - removeListeners(this); - }, - addFolder: function addFolder(name) { - if (this.__folders[name] !== undefined) { - throw new Error('You already have a folder in this GUI by the' + ' name "' + name + '"'); - } - var newGuiParams = { name: name, parent: this }; - newGuiParams.autoPlace = this.autoPlace; - if (this.load && - this.load.folders && - this.load.folders[name]) { - newGuiParams.closed = this.load.folders[name].closed; - newGuiParams.load = this.load.folders[name]; - } - var gui = new GUI(newGuiParams); - this.__folders[name] = gui; - var li = addRow(this, gui.domElement); - dom.addClass(li, 'folder'); - return gui; - }, - removeFolder: function removeFolder(folder) { - this.__ul.removeChild(folder.domElement.parentElement); - delete this.__folders[folder.name]; - if (this.load && - this.load.folders && - this.load.folders[folder.name]) { - delete this.load.folders[folder.name]; - } - removeListeners(folder); - var _this = this; - Common.each(folder.__folders, function (subfolder) { - folder.removeFolder(subfolder); - }); - Common.defer(function () { - _this.onResize(); - }); - }, - open: function open() { - this.closed = false; - }, - close: function close() { - this.closed = true; - }, - hide: function hide() { - this.domElement.style.display = 'none'; - }, - show: function show() { - this.domElement.style.display = ''; - }, - onResize: function onResize() { - var root = this.getRoot(); - if (root.scrollable) { - var top = dom.getOffset(root.__ul).top; - var h = 0; - Common.each(root.__ul.childNodes, function (node) { - if (!(root.autoPlace && node === root.__save_row)) { - h += dom.getHeight(node); - } - }); - if (window.innerHeight - top - CLOSE_BUTTON_HEIGHT < h) { - dom.addClass(root.domElement, GUI.CLASS_TOO_TALL); - root.__ul.style.height = window.innerHeight - top - CLOSE_BUTTON_HEIGHT + 'px'; - } else { - dom.removeClass(root.domElement, GUI.CLASS_TOO_TALL); - root.__ul.style.height = 'auto'; - } - } - if (root.__resize_handle) { - Common.defer(function () { - root.__resize_handle.style.height = root.__ul.offsetHeight + 'px'; - }); - } - if (root.__closeButton) { - root.__closeButton.style.width = root.width + 'px'; - } - }, - onResizeDebounced: Common.debounce(function () { - this.onResize(); - }, 50), - remember: function remember() { - if (Common.isUndefined(SAVE_DIALOGUE)) { - SAVE_DIALOGUE = new CenteredDiv(); - SAVE_DIALOGUE.domElement.innerHTML = saveDialogContents; - } - if (this.parent) { - throw new Error('You can only call remember on a top level GUI.'); - } - var _this = this; - Common.each(Array.prototype.slice.call(arguments), function (object) { - if (_this.__rememberedObjects.length === 0) { - addSaveMenu(_this); - } - if (_this.__rememberedObjects.indexOf(object) === -1) { - _this.__rememberedObjects.push(object); - } - }); - if (this.autoPlace) { - setWidth(this, this.width); - } - }, - getRoot: function getRoot() { - var gui = this; - while (gui.parent) { - gui = gui.parent; - } - return gui; - }, - getSaveObject: function getSaveObject() { - var toReturn = this.load; - toReturn.closed = this.closed; - if (this.__rememberedObjects.length > 0) { - toReturn.preset = this.preset; - if (!toReturn.remembered) { - toReturn.remembered = {}; - } - toReturn.remembered[this.preset] = getCurrentPreset(this); - } - toReturn.folders = {}; - Common.each(this.__folders, function (element, key) { - toReturn.folders[key] = element.getSaveObject(); - }); - return toReturn; - }, - save: function save() { - if (!this.load.remembered) { - this.load.remembered = {}; - } - this.load.remembered[this.preset] = getCurrentPreset(this); - markPresetModified(this, false); - this.saveToLocalStorageIfPossible(); - }, - saveAs: function saveAs(presetName) { - if (!this.load.remembered) { - this.load.remembered = {}; - this.load.remembered[DEFAULT_DEFAULT_PRESET_NAME] = getCurrentPreset(this, true); - } - this.load.remembered[presetName] = getCurrentPreset(this); - this.preset = presetName; - addPresetOption(this, presetName, true); - this.saveToLocalStorageIfPossible(); - }, - revert: function revert(gui) { - Common.each(this.__controllers, function (controller) { - if (!this.getRoot().load.remembered) { - controller.setValue(controller.initialValue); - } else { - recallSavedValue(gui || this.getRoot(), controller); - } - if (controller.__onFinishChange) { - controller.__onFinishChange.call(controller, controller.getValue()); - } - }, this); - Common.each(this.__folders, function (folder) { - folder.revert(folder); - }); - if (!gui) { - markPresetModified(this.getRoot(), false); - } - }, - listen: function listen(controller) { - var init = this.__listening.length === 0; - this.__listening.push(controller); - if (init) { - updateDisplays(this.__listening); - } - }, - updateDisplay: function updateDisplay() { - Common.each(this.__controllers, function (controller) { - controller.updateDisplay(); - }); - Common.each(this.__folders, function (folder) { - folder.updateDisplay(); - }); - } -}); -function addRow(gui, newDom, liBefore) { - var li = document.createElement('li'); - if (newDom) { - li.appendChild(newDom); - } - if (liBefore) { - gui.__ul.insertBefore(li, liBefore); - } else { - gui.__ul.appendChild(li); - } - gui.onResize(); - return li; -} -function removeListeners(gui) { - dom.unbind(window, 'resize', gui.__resizeHandler); - if (gui.saveToLocalStorageIfPossible) { - dom.unbind(window, 'unload', gui.saveToLocalStorageIfPossible); - } -} -function markPresetModified(gui, modified) { - var opt = gui.__preset_select[gui.__preset_select.selectedIndex]; - if (modified) { - opt.innerHTML = opt.value + '*'; - } else { - opt.innerHTML = opt.value; - } -} -function augmentController(gui, li, controller) { - controller.__li = li; - controller.__gui = gui; - Common.extend(controller, { - options: function options(_options) { - if (arguments.length > 1) { - var nextSibling = controller.__li.nextElementSibling; - controller.remove(); - return _add(gui, controller.object, controller.property, { - before: nextSibling, - factoryArgs: [Common.toArray(arguments)] - }); - } - if (Common.isArray(_options) || Common.isObject(_options)) { - var _nextSibling = controller.__li.nextElementSibling; - controller.remove(); - return _add(gui, controller.object, controller.property, { - before: _nextSibling, - factoryArgs: [_options] - }); - } - }, - name: function name(_name) { - controller.__li.firstElementChild.firstElementChild.innerHTML = _name; - return controller; - }, - listen: function listen() { - controller.__gui.listen(controller); - return controller; - }, - remove: function remove() { - controller.__gui.remove(controller); - return controller; - } - }); - if (controller instanceof NumberControllerSlider) { - var box = new NumberControllerBox(controller.object, controller.property, { min: controller.__min, max: controller.__max, step: controller.__step }); - Common.each(['updateDisplay', 'onChange', 'onFinishChange', 'step', 'min', 'max'], function (method) { - var pc = controller[method]; - var pb = box[method]; - controller[method] = box[method] = function () { - var args = Array.prototype.slice.call(arguments); - pb.apply(box, args); - return pc.apply(controller, args); - }; - }); - dom.addClass(li, 'has-slider'); - controller.domElement.insertBefore(box.domElement, controller.domElement.firstElementChild); - } else if (controller instanceof NumberControllerBox) { - var r = function r(returned) { - if (Common.isNumber(controller.__min) && Common.isNumber(controller.__max)) { - var oldName = controller.__li.firstElementChild.firstElementChild.innerHTML; - var wasListening = controller.__gui.__listening.indexOf(controller) > -1; - controller.remove(); - var newController = _add(gui, controller.object, controller.property, { - before: controller.__li.nextElementSibling, - factoryArgs: [controller.__min, controller.__max, controller.__step] - }); - newController.name(oldName); - if (wasListening) newController.listen(); - return newController; - } - return returned; - }; - controller.min = Common.compose(r, controller.min); - controller.max = Common.compose(r, controller.max); - } else if (controller instanceof BooleanController) { - dom.bind(li, 'click', function () { - dom.fakeEvent(controller.__checkbox, 'click'); - }); - dom.bind(controller.__checkbox, 'click', function (e) { - e.stopPropagation(); - }); - } else if (controller instanceof FunctionController) { - dom.bind(li, 'click', function () { - dom.fakeEvent(controller.__button, 'click'); - }); - dom.bind(li, 'mouseover', function () { - dom.addClass(controller.__button, 'hover'); - }); - dom.bind(li, 'mouseout', function () { - dom.removeClass(controller.__button, 'hover'); - }); - } else if (controller instanceof ColorController) { - dom.addClass(li, 'color'); - controller.updateDisplay = Common.compose(function (val) { - li.style.borderLeftColor = controller.__color.toString(); - return val; - }, controller.updateDisplay); - controller.updateDisplay(); - } - controller.setValue = Common.compose(function (val) { - if (gui.getRoot().__preset_select && controller.isModified()) { - markPresetModified(gui.getRoot(), true); - } - return val; - }, controller.setValue); -} -function recallSavedValue(gui, controller) { - var root = gui.getRoot(); - var matchedIndex = root.__rememberedObjects.indexOf(controller.object); - if (matchedIndex !== -1) { - var controllerMap = root.__rememberedObjectIndecesToControllers[matchedIndex]; - if (controllerMap === undefined) { - controllerMap = {}; - root.__rememberedObjectIndecesToControllers[matchedIndex] = controllerMap; - } - controllerMap[controller.property] = controller; - if (root.load && root.load.remembered) { - var presetMap = root.load.remembered; - var preset = void 0; - if (presetMap[gui.preset]) { - preset = presetMap[gui.preset]; - } else if (presetMap[DEFAULT_DEFAULT_PRESET_NAME]) { - preset = presetMap[DEFAULT_DEFAULT_PRESET_NAME]; - } else { - return; - } - if (preset[matchedIndex] && preset[matchedIndex][controller.property] !== undefined) { - var value = preset[matchedIndex][controller.property]; - controller.initialValue = value; - controller.setValue(value); - } - } - } -} -function _add(gui, object, property, params) { - if (object[property] === undefined) { - throw new Error('Object "' + object + '" has no property "' + property + '"'); - } - var controller = void 0; - if (params.color) { - controller = new ColorController(object, property); - } else { - var factoryArgs = [object, property].concat(params.factoryArgs); - controller = ControllerFactory.apply(gui, factoryArgs); - } - if (params.before instanceof Controller) { - params.before = params.before.__li; - } - recallSavedValue(gui, controller); - dom.addClass(controller.domElement, 'c'); - var name = document.createElement('span'); - dom.addClass(name, 'property-name'); - name.innerHTML = controller.property; - var container = document.createElement('div'); - container.appendChild(name); - container.appendChild(controller.domElement); - var li = addRow(gui, container, params.before); - dom.addClass(li, GUI.CLASS_CONTROLLER_ROW); - if (controller instanceof ColorController) { - dom.addClass(li, 'color'); - } else { - dom.addClass(li, _typeof(controller.getValue())); - } - augmentController(gui, li, controller); - gui.__controllers.push(controller); - return controller; -} -function getLocalStorageHash(gui, key) { - return document.location.href + '.' + key; -} -function addPresetOption(gui, name, setSelected) { - var opt = document.createElement('option'); - opt.innerHTML = name; - opt.value = name; - gui.__preset_select.appendChild(opt); - if (setSelected) { - gui.__preset_select.selectedIndex = gui.__preset_select.length - 1; - } -} -function showHideExplain(gui, explain) { - explain.style.display = gui.useLocalStorage ? 'block' : 'none'; -} -function addSaveMenu(gui) { - var div = gui.__save_row = document.createElement('li'); - dom.addClass(gui.domElement, 'has-save'); - gui.__ul.insertBefore(div, gui.__ul.firstChild); - dom.addClass(div, 'save-row'); - var gears = document.createElement('span'); - gears.innerHTML = ' '; - dom.addClass(gears, 'button gears'); - var button = document.createElement('span'); - button.innerHTML = 'Save'; - dom.addClass(button, 'button'); - dom.addClass(button, 'save'); - var button2 = document.createElement('span'); - button2.innerHTML = 'New'; - dom.addClass(button2, 'button'); - dom.addClass(button2, 'save-as'); - var button3 = document.createElement('span'); - button3.innerHTML = 'Revert'; - dom.addClass(button3, 'button'); - dom.addClass(button3, 'revert'); - var select = gui.__preset_select = document.createElement('select'); - if (gui.load && gui.load.remembered) { - Common.each(gui.load.remembered, function (value, key) { - addPresetOption(gui, key, key === gui.preset); - }); - } else { - addPresetOption(gui, DEFAULT_DEFAULT_PRESET_NAME, false); - } - dom.bind(select, 'change', function () { - for (var index = 0; index < gui.__preset_select.length; index++) { - gui.__preset_select[index].innerHTML = gui.__preset_select[index].value; - } - gui.preset = this.value; - }); - div.appendChild(select); - div.appendChild(gears); - div.appendChild(button); - div.appendChild(button2); - div.appendChild(button3); - if (SUPPORTS_LOCAL_STORAGE) { - var explain = document.getElementById('dg-local-explain'); - var localStorageCheckBox = document.getElementById('dg-local-storage'); - var saveLocally = document.getElementById('dg-save-locally'); - saveLocally.style.display = 'block'; - if (localStorage.getItem(getLocalStorageHash(gui, 'isLocal')) === 'true') { - localStorageCheckBox.setAttribute('checked', 'checked'); - } - showHideExplain(gui, explain); - dom.bind(localStorageCheckBox, 'change', function () { - gui.useLocalStorage = !gui.useLocalStorage; - showHideExplain(gui, explain); - }); - } - var newConstructorTextArea = document.getElementById('dg-new-constructor'); - dom.bind(newConstructorTextArea, 'keydown', function (e) { - if (e.metaKey && (e.which === 67 || e.keyCode === 67)) { - SAVE_DIALOGUE.hide(); - } - }); - dom.bind(gears, 'click', function () { - newConstructorTextArea.innerHTML = JSON.stringify(gui.getSaveObject(), undefined, 2); - SAVE_DIALOGUE.show(); - newConstructorTextArea.focus(); - newConstructorTextArea.select(); - }); - dom.bind(button, 'click', function () { - gui.save(); - }); - dom.bind(button2, 'click', function () { - var presetName = prompt('Enter a new preset name.'); - if (presetName) { - gui.saveAs(presetName); - } - }); - dom.bind(button3, 'click', function () { - gui.revert(); - }); -} -function addResizeHandle(gui) { - var pmouseX = void 0; - gui.__resize_handle = document.createElement('div'); - Common.extend(gui.__resize_handle.style, { - width: '6px', - marginLeft: '-3px', - height: '200px', - cursor: 'ew-resize', - position: 'absolute' - }); - function drag(e) { - e.preventDefault(); - gui.width += pmouseX - e.clientX; - gui.onResize(); - pmouseX = e.clientX; - return false; - } - function dragStop() { - dom.removeClass(gui.__closeButton, GUI.CLASS_DRAG); - dom.unbind(window, 'mousemove', drag); - dom.unbind(window, 'mouseup', dragStop); - } - function dragStart(e) { - e.preventDefault(); - pmouseX = e.clientX; - dom.addClass(gui.__closeButton, GUI.CLASS_DRAG); - dom.bind(window, 'mousemove', drag); - dom.bind(window, 'mouseup', dragStop); - return false; - } - dom.bind(gui.__resize_handle, 'mousedown', dragStart); - dom.bind(gui.__closeButton, 'mousedown', dragStart); - gui.domElement.insertBefore(gui.__resize_handle, gui.domElement.firstElementChild); -} -function setWidth(gui, w) { - gui.domElement.style.width = w + 'px'; - if (gui.__save_row && gui.autoPlace) { - gui.__save_row.style.width = w + 'px'; - } - if (gui.__closeButton) { - gui.__closeButton.style.width = w + 'px'; - } -} -function getCurrentPreset(gui, useInitialValues) { - var toReturn = {}; - Common.each(gui.__rememberedObjects, function (val, index) { - var savedValues = {}; - var controllerMap = gui.__rememberedObjectIndecesToControllers[index]; - Common.each(controllerMap, function (controller, property) { - savedValues[property] = useInitialValues ? controller.initialValue : controller.getValue(); - }); - toReturn[index] = savedValues; - }); - return toReturn; -} -function setPresetSelectIndex(gui) { - for (var index = 0; index < gui.__preset_select.length; index++) { - if (gui.__preset_select[index].value === gui.preset) { - gui.__preset_select.selectedIndex = index; - } - } -} -function updateDisplays(controllerArray) { - if (controllerArray.length !== 0) { - requestAnimationFrame$1.call(window, function () { - updateDisplays(controllerArray); - }); - } - Common.each(controllerArray, function (c) { - c.updateDisplay(); - }); -} - -var color = { - Color: Color, - math: ColorMath, - interpret: interpret -}; -var controllers = { - Controller: Controller, - BooleanController: BooleanController, - OptionController: OptionController, - StringController: StringController, - NumberController: NumberController, - NumberControllerBox: NumberControllerBox, - NumberControllerSlider: NumberControllerSlider, - FunctionController: FunctionController, - ColorController: ColorController -}; -var dom$1 = { dom: dom }; -var gui = { GUI: GUI }; -var GUI$1 = GUI; -var index = { - color: color, - controllers: controllers, - dom: dom$1, - gui: gui, - GUI: GUI$1 -}; - -export default index; -export { GUI$1 as GUI, color, controllers, dom$1 as dom, gui }; diff --git a/__tests__/integration/dep-list-complex/web_modules/import-map.json b/__tests__/integration/dep-list-complex/web_modules/import-map.json deleted file mode 100644 index a31fb0b445..0000000000 --- a/__tests__/integration/dep-list-complex/web_modules/import-map.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "imports": { - "dat.gui": "./dat.gui.js" - } -} \ No newline at end of file diff --git a/__tests__/integration/dep-list-simple/expected-install/import-map.json b/__tests__/integration/dep-list-simple/expected-install/import-map.json index d3882b6e08..2d55495ac9 100644 --- a/__tests__/integration/dep-list-simple/expected-install/import-map.json +++ b/__tests__/integration/dep-list-simple/expected-install/import-map.json @@ -1,5 +1,5 @@ { "imports": { - "async": "./async.js" + "async": "./async.js?rev=XXXXXXXXXX" } } \ No newline at end of file diff --git a/__tests__/integration/dep-list-simple/web_modules/async.js b/__tests__/integration/dep-list-simple/web_modules/async.js deleted file mode 100644 index a5cfac1932..0000000000 --- a/__tests__/integration/dep-list-simple/web_modules/async.js +++ /dev/null @@ -1,4736 +0,0 @@ -/** - * Creates a continuation function with some arguments already applied. - * - * Useful as a shorthand when combined with other control flow functions. Any - * arguments passed to the returned function are added to the arguments - * originally passed to apply. - * - * @name apply - * @static - * @memberOf module:Utils - * @method - * @category Util - * @param {Function} fn - The function you want to eventually apply all - * arguments to. Invokes with (arguments...). - * @param {...*} arguments... - Any number of arguments to automatically apply - * when the continuation is called. - * @returns {Function} the partially-applied function - * @example - * - * // using apply - * async.parallel([ - * async.apply(fs.writeFile, 'testfile1', 'test1'), - * async.apply(fs.writeFile, 'testfile2', 'test2') - * ]); - * - * - * // the same process without using apply - * async.parallel([ - * function(callback) { - * fs.writeFile('testfile1', 'test1', callback); - * }, - * function(callback) { - * fs.writeFile('testfile2', 'test2', callback); - * } - * ]); - * - * // It's possible to pass any number of additional arguments when calling the - * // continuation: - * - * node> var fn = async.apply(sys.puts, 'one'); - * node> fn('two', 'three'); - * one - * two - * three - */ -function apply(fn, ...args) { - return (...callArgs) => fn(...args,...callArgs); -} - -function initialParams (fn) { - return function (...args/*, callback*/) { - var callback = args.pop(); - return fn.call(this, args, callback); - }; -} - -/* istanbul ignore file */ - -var hasSetImmediate = typeof setImmediate === 'function' && setImmediate; -var hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function'; - -function fallback(fn) { - setTimeout(fn, 0); -} - -function wrap(defer) { - return (fn, ...args) => defer(() => fn(...args)); -} - -var _defer; - -if (hasSetImmediate) { - _defer = setImmediate; -} else if (hasNextTick) { - _defer = process.nextTick; -} else { - _defer = fallback; -} - -var setImmediate$1 = wrap(_defer); - -/** - * Take a sync function and make it async, passing its return value to a - * callback. This is useful for plugging sync functions into a waterfall, - * series, or other async functions. Any arguments passed to the generated - * function will be passed to the wrapped function (except for the final - * callback argument). Errors thrown will be passed to the callback. - * - * If the function passed to `asyncify` returns a Promise, that promises's - * resolved/rejected state will be used to call the callback, rather than simply - * the synchronous return value. - * - * This also means you can asyncify ES2017 `async` functions. - * - * @name asyncify - * @static - * @memberOf module:Utils - * @method - * @alias wrapSync - * @category Util - * @param {Function} func - The synchronous function, or Promise-returning - * function to convert to an {@link AsyncFunction}. - * @returns {AsyncFunction} An asynchronous wrapper of the `func`. To be - * invoked with `(args..., callback)`. - * @example - * - * // passing a regular synchronous function - * async.waterfall([ - * async.apply(fs.readFile, filename, "utf8"), - * async.asyncify(JSON.parse), - * function (data, next) { - * // data is the result of parsing the text. - * // If there was a parsing error, it would have been caught. - * } - * ], callback); - * - * // passing a function returning a promise - * async.waterfall([ - * async.apply(fs.readFile, filename, "utf8"), - * async.asyncify(function (contents) { - * return db.model.create(contents); - * }), - * function (model, next) { - * // `model` is the instantiated model object. - * // If there was an error, this function would be skipped. - * } - * ], callback); - * - * // es2017 example, though `asyncify` is not needed if your JS environment - * // supports async functions out of the box - * var q = async.queue(async.asyncify(async function(file) { - * var intermediateStep = await processFile(file); - * return await somePromise(intermediateStep) - * })); - * - * q.push(files); - */ -function asyncify(func) { - if (isAsync(func)) { - return function (...args/*, callback*/) { - const callback = args.pop(); - const promise = func.apply(this, args); - return handlePromise(promise, callback) - } - } - - return initialParams(function (args, callback) { - var result; - try { - result = func.apply(this, args); - } catch (e) { - return callback(e); - } - // if result is Promise object - if (result && typeof result.then === 'function') { - return handlePromise(result, callback) - } else { - callback(null, result); - } - }); -} - -function handlePromise(promise, callback) { - return promise.then(value => { - invokeCallback(callback, null, value); - }, err => { - invokeCallback(callback, err && err.message ? err : new Error(err)); - }); -} - -function invokeCallback(callback, error, value) { - try { - callback(error, value); - } catch (err) { - setImmediate$1(e => { throw e }, err); - } -} - -function isAsync(fn) { - return fn[Symbol.toStringTag] === 'AsyncFunction'; -} - -function isAsyncGenerator(fn) { - return fn[Symbol.toStringTag] === 'AsyncGenerator'; -} - -function isAsyncIterable(obj) { - return typeof obj[Symbol.asyncIterator] === 'function'; -} - -function wrapAsync(asyncFn) { - if (typeof asyncFn !== 'function') throw new Error('expected a function') - return isAsync(asyncFn) ? asyncify(asyncFn) : asyncFn; -} - -// conditionally promisify a function. -// only return a promise if a callback is omitted -function awaitify (asyncFn, arity = asyncFn.length) { - if (!arity) throw new Error('arity is undefined') - function awaitable (...args) { - if (typeof args[arity - 1] === 'function') { - return asyncFn.apply(this, args) - } - - return new Promise((resolve, reject) => { - args[arity - 1] = (err, ...cbArgs) => { - if (err) return reject(err) - resolve(cbArgs.length > 1 ? cbArgs : cbArgs[0]); - }; - asyncFn.apply(this, args); - }) - } - - Object.defineProperty(awaitable, 'name', { - value: `awaitable(${asyncFn.name})` - }); - - return awaitable -} - -function applyEach (eachfn) { - return function applyEach(fns, ...callArgs) { - const go = awaitify(function (callback) { - var that = this; - return eachfn(fns, (fn, cb) => { - wrapAsync(fn).apply(that, callArgs.concat(cb)); - }, callback); - }); - return go; - }; -} - -function _asyncMap(eachfn, arr, iteratee, callback) { - arr = arr || []; - var results = []; - var counter = 0; - var _iteratee = wrapAsync(iteratee); - - return eachfn(arr, (value, _, iterCb) => { - var index = counter++; - _iteratee(value, (err, v) => { - results[index] = v; - iterCb(err); - }); - }, err => { - callback(err, results); - }); -} - -function isArrayLike(value) { - return value && - typeof value.length === 'number' && - value.length >= 0 && - value.length % 1 === 0; -} - -// A temporary value used to identify if the loop should be broken. -// See #1064, #1293 -const breakLoop = {}; - -function once(fn) { - function wrapper (...args) { - if (fn === null) return; - var callFn = fn; - fn = null; - callFn.apply(this, args); - } - Object.assign(wrapper, fn); - return wrapper -} - -function getIterator (coll) { - return coll[Symbol.iterator] && coll[Symbol.iterator](); -} - -function createArrayIterator(coll) { - var i = -1; - var len = coll.length; - return function next() { - return ++i < len ? {value: coll[i], key: i} : null; - } -} - -function createES2015Iterator(iterator) { - var i = -1; - return function next() { - var item = iterator.next(); - if (item.done) - return null; - i++; - return {value: item.value, key: i}; - } -} - -function createObjectIterator(obj) { - var okeys = obj ? Object.keys(obj) : []; - var i = -1; - var len = okeys.length; - return function next() { - var key = okeys[++i]; - return i < len ? {value: obj[key], key} : null; - }; -} - -function createIterator(coll) { - if (isArrayLike(coll)) { - return createArrayIterator(coll); - } - - var iterator = getIterator(coll); - return iterator ? createES2015Iterator(iterator) : createObjectIterator(coll); -} - -function onlyOnce(fn) { - return function (...args) { - if (fn === null) throw new Error("Callback was already called."); - var callFn = fn; - fn = null; - callFn.apply(this, args); - }; -} - -// for async generators -function asyncEachOfLimit(generator, limit, iteratee, callback) { - let done = false; - let canceled = false; - let awaiting = false; - let running = 0; - let idx = 0; - - function replenish() { - //console.log('replenish') - if (running >= limit || awaiting || done) return - //console.log('replenish awaiting') - awaiting = true; - generator.next().then(({value, done: iterDone}) => { - //console.log('got value', value) - if (canceled || done) return - awaiting = false; - if (iterDone) { - done = true; - if (running <= 0) { - //console.log('done nextCb') - callback(null); - } - return; - } - running++; - iteratee(value, idx, iterateeCallback); - idx++; - replenish(); - }).catch(handleError); - } - - function iterateeCallback(err, result) { - //console.log('iterateeCallback') - running -= 1; - if (canceled) return - if (err) return handleError(err) - - if (err === false) { - done = true; - canceled = true; - return - } - - if (result === breakLoop || (done && running <= 0)) { - done = true; - //console.log('done iterCb') - return callback(null); - } - replenish(); - } - - function handleError(err) { - if (canceled) return - awaiting = false; - done = true; - callback(err); - } - - replenish(); -} - -var eachOfLimit = (limit) => { - return (obj, iteratee, callback) => { - callback = once(callback); - if (limit <= 0) { - throw new RangeError('concurrency limit cannot be less than 1') - } - if (!obj) { - return callback(null); - } - if (isAsyncGenerator(obj)) { - return asyncEachOfLimit(obj, limit, iteratee, callback) - } - if (isAsyncIterable(obj)) { - return asyncEachOfLimit(obj[Symbol.asyncIterator](), limit, iteratee, callback) - } - var nextElem = createIterator(obj); - var done = false; - var canceled = false; - var running = 0; - var looping = false; - - function iterateeCallback(err, value) { - if (canceled) return - running -= 1; - if (err) { - done = true; - callback(err); - } - else if (err === false) { - done = true; - canceled = true; - } - else if (value === breakLoop || (done && running <= 0)) { - done = true; - return callback(null); - } - else if (!looping) { - replenish(); - } - } - - function replenish () { - looping = true; - while (running < limit && !done) { - var elem = nextElem(); - if (elem === null) { - done = true; - if (running <= 0) { - callback(null); - } - return; - } - running += 1; - iteratee(elem.value, elem.key, onlyOnce(iterateeCallback)); - } - looping = false; - } - - replenish(); - }; -}; - -/** - * The same as [`eachOf`]{@link module:Collections.eachOf} but runs a maximum of `limit` async operations at a - * time. - * - * @name eachOfLimit - * @static - * @memberOf module:Collections - * @method - * @see [async.eachOf]{@link module:Collections.eachOf} - * @alias forEachOfLimit - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {number} limit - The maximum number of async operations at a time. - * @param {AsyncFunction} iteratee - An async function to apply to each - * item in `coll`. The `key` is the item's key, or index in the case of an - * array. - * Invoked with (item, key, callback). - * @param {Function} [callback] - A callback which is called when all - * `iteratee` functions have finished, or an error occurs. Invoked with (err). - * @returns {Promise} a promise, if a callback is omitted - */ -function eachOfLimit$1(coll, limit, iteratee, callback) { - return eachOfLimit(limit)(coll, wrapAsync(iteratee), callback); -} - -var eachOfLimit$2 = awaitify(eachOfLimit$1, 4); - -// eachOf implementation optimized for array-likes -function eachOfArrayLike(coll, iteratee, callback) { - callback = once(callback); - var index = 0, - completed = 0, - {length} = coll, - canceled = false; - if (length === 0) { - callback(null); - } - - function iteratorCallback(err, value) { - if (err === false) { - canceled = true; - } - if (canceled === true) return - if (err) { - callback(err); - } else if ((++completed === length) || value === breakLoop) { - callback(null); - } - } - - for (; index < length; index++) { - iteratee(coll[index], index, onlyOnce(iteratorCallback)); - } -} - -// a generic version of eachOf which can handle array, object, and iterator cases. -function eachOfGeneric (coll, iteratee, callback) { - return eachOfLimit$2(coll, Infinity, iteratee, callback); -} - -/** - * Like [`each`]{@link module:Collections.each}, except that it passes the key (or index) as the second argument - * to the iteratee. - * - * @name eachOf - * @static - * @memberOf module:Collections - * @method - * @alias forEachOf - * @category Collection - * @see [async.each]{@link module:Collections.each} - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - A function to apply to each - * item in `coll`. - * The `key` is the item's key, or index in the case of an array. - * Invoked with (item, key, callback). - * @param {Function} [callback] - A callback which is called when all - * `iteratee` functions have finished, or an error occurs. Invoked with (err). - * @returns {Promise} a promise, if a callback is omitted - * @example - * - * var obj = {dev: "/dev.json", test: "/test.json", prod: "/prod.json"}; - * var configs = {}; - * - * async.forEachOf(obj, function (value, key, callback) { - * fs.readFile(__dirname + value, "utf8", function (err, data) { - * if (err) return callback(err); - * try { - * configs[key] = JSON.parse(data); - * } catch (e) { - * return callback(e); - * } - * callback(); - * }); - * }, function (err) { - * if (err) console.error(err.message); - * // configs is now a map of JSON data - * doSomethingWith(configs); - * }); - */ -function eachOf(coll, iteratee, callback) { - var eachOfImplementation = isArrayLike(coll) ? eachOfArrayLike : eachOfGeneric; - return eachOfImplementation(coll, wrapAsync(iteratee), callback); -} - -var eachOf$1 = awaitify(eachOf, 3); - -/** - * Produces a new collection of values by mapping each value in `coll` through - * the `iteratee` function. The `iteratee` is called with an item from `coll` - * and a callback for when it has finished processing. Each of these callback - * takes 2 arguments: an `error`, and the transformed item from `coll`. If - * `iteratee` passes an error to its callback, the main `callback` (for the - * `map` function) is immediately called with the error. - * - * Note, that since this function applies the `iteratee` to each item in - * parallel, there is no guarantee that the `iteratee` functions will complete - * in order. However, the results array will be in the same order as the - * original `coll`. - * - * If `map` is passed an Object, the results will be an Array. The results - * will roughly be in the order of the original Objects' keys (but this can - * vary across JavaScript engines). - * - * @name map - * @static - * @memberOf module:Collections - * @method - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async function to apply to each item in - * `coll`. - * The iteratee should complete with the transformed item. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called when all `iteratee` - * functions have finished, or an error occurs. Results is an Array of the - * transformed items from the `coll`. Invoked with (err, results). - * @returns {Promise} a promise, if no callback is passed - * @example - * - * async.map(['file1','file2','file3'], fs.stat, function(err, results) { - * // results is now an array of stats for each file - * }); - */ -function map (coll, iteratee, callback) { - return _asyncMap(eachOf$1, coll, iteratee, callback) -} -var map$1 = awaitify(map, 3); - -/** - * Applies the provided arguments to each function in the array, calling - * `callback` after all functions have completed. If you only provide the first - * argument, `fns`, then it will return a function which lets you pass in the - * arguments as if it were a single function call. If more arguments are - * provided, `callback` is required while `args` is still optional. The results - * for each of the applied async functions are passed to the final callback - * as an array. - * - * @name applyEach - * @static - * @memberOf module:ControlFlow - * @method - * @category Control Flow - * @param {Array|Iterable|AsyncIterable|Object} fns - A collection of {@link AsyncFunction}s - * to all call with the same arguments - * @param {...*} [args] - any number of separate arguments to pass to the - * function. - * @param {Function} [callback] - the final argument should be the callback, - * called when all functions have completed processing. - * @returns {AsyncFunction} - Returns a function that takes no args other than - * an optional callback, that is the result of applying the `args` to each - * of the functions. - * @example - * - * const appliedFn = async.applyEach([enableSearch, updateSchema], 'bucket') - * - * appliedFn((err, results) => { - * // results[0] is the results for `enableSearch` - * // results[1] is the results for `updateSchema` - * }); - * - * // partial application example: - * async.each( - * buckets, - * async (bucket) => async.applyEach([enableSearch, updateSchema], bucket)(), - * callback - * ); - */ -var applyEach$1 = applyEach(map$1); - -/** - * The same as [`eachOf`]{@link module:Collections.eachOf} but runs only a single async operation at a time. - * - * @name eachOfSeries - * @static - * @memberOf module:Collections - * @method - * @see [async.eachOf]{@link module:Collections.eachOf} - * @alias forEachOfSeries - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async function to apply to each item in - * `coll`. - * Invoked with (item, key, callback). - * @param {Function} [callback] - A callback which is called when all `iteratee` - * functions have finished, or an error occurs. Invoked with (err). - * @returns {Promise} a promise, if a callback is omitted - */ -function eachOfSeries(coll, iteratee, callback) { - return eachOfLimit$2(coll, 1, iteratee, callback) -} -var eachOfSeries$1 = awaitify(eachOfSeries, 3); - -/** - * The same as [`map`]{@link module:Collections.map} but runs only a single async operation at a time. - * - * @name mapSeries - * @static - * @memberOf module:Collections - * @method - * @see [async.map]{@link module:Collections.map} - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async function to apply to each item in - * `coll`. - * The iteratee should complete with the transformed item. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called when all `iteratee` - * functions have finished, or an error occurs. Results is an array of the - * transformed items from the `coll`. Invoked with (err, results). - * @returns {Promise} a promise, if no callback is passed - */ -function mapSeries (coll, iteratee, callback) { - return _asyncMap(eachOfSeries$1, coll, iteratee, callback) -} -var mapSeries$1 = awaitify(mapSeries, 3); - -/** - * The same as [`applyEach`]{@link module:ControlFlow.applyEach} but runs only a single async operation at a time. - * - * @name applyEachSeries - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.applyEach]{@link module:ControlFlow.applyEach} - * @category Control Flow - * @param {Array|Iterable|AsyncIterable|Object} fns - A collection of {@link AsyncFunction}s to all - * call with the same arguments - * @param {...*} [args] - any number of separate arguments to pass to the - * function. - * @param {Function} [callback] - the final argument should be the callback, - * called when all functions have completed processing. - * @returns {AsyncFunction} - A function, that when called, is the result of - * appling the `args` to the list of functions. It takes no args, other than - * a callback. - */ -var applyEachSeries = applyEach(mapSeries$1); - -const PROMISE_SYMBOL = Symbol('promiseCallback'); - -function promiseCallback () { - let resolve, reject; - function callback (err, ...args) { - if (err) return reject(err) - resolve(args.length > 1 ? args : args[0]); - } - - callback[PROMISE_SYMBOL] = new Promise((res, rej) => { - resolve = res, - reject = rej; - }); - - return callback -} - -/** - * Determines the best order for running the {@link AsyncFunction}s in `tasks`, based on - * their requirements. Each function can optionally depend on other functions - * being completed first, and each function is run as soon as its requirements - * are satisfied. - * - * If any of the {@link AsyncFunction}s pass an error to their callback, the `auto` sequence - * will stop. Further tasks will not execute (so any other functions depending - * on it will not run), and the main `callback` is immediately called with the - * error. - * - * {@link AsyncFunction}s also receive an object containing the results of functions which - * have completed so far as the first argument, if they have dependencies. If a - * task function has no dependencies, it will only be passed a callback. - * - * @name auto - * @static - * @memberOf module:ControlFlow - * @method - * @category Control Flow - * @param {Object} tasks - An object. Each of its properties is either a - * function or an array of requirements, with the {@link AsyncFunction} itself the last item - * in the array. The object's key of a property serves as the name of the task - * defined by that property, i.e. can be used when specifying requirements for - * other tasks. The function receives one or two arguments: - * * a `results` object, containing the results of the previously executed - * functions, only passed if the task has any dependencies, - * * a `callback(err, result)` function, which must be called when finished, - * passing an `error` (which can be `null`) and the result of the function's - * execution. - * @param {number} [concurrency=Infinity] - An optional `integer` for - * determining the maximum number of tasks that can be run in parallel. By - * default, as many as possible. - * @param {Function} [callback] - An optional callback which is called when all - * the tasks have been completed. It receives the `err` argument if any `tasks` - * pass an error to their callback. Results are always returned; however, if an - * error occurs, no further `tasks` will be performed, and the results object - * will only contain partial results. Invoked with (err, results). - * @returns {Promise} a promise, if a callback is not passed - * @example - * - * async.auto({ - * // this function will just be passed a callback - * readData: async.apply(fs.readFile, 'data.txt', 'utf-8'), - * showData: ['readData', function(results, cb) { - * // results.readData is the file's contents - * // ... - * }] - * }, callback); - * - * async.auto({ - * get_data: function(callback) { - * console.log('in get_data'); - * // async code to get some data - * callback(null, 'data', 'converted to array'); - * }, - * make_folder: function(callback) { - * console.log('in make_folder'); - * // async code to create a directory to store a file in - * // this is run at the same time as getting the data - * callback(null, 'folder'); - * }, - * write_file: ['get_data', 'make_folder', function(results, callback) { - * console.log('in write_file', JSON.stringify(results)); - * // once there is some data and the directory exists, - * // write the data to a file in the directory - * callback(null, 'filename'); - * }], - * email_link: ['write_file', function(results, callback) { - * console.log('in email_link', JSON.stringify(results)); - * // once the file is written let's email a link to it... - * // results.write_file contains the filename returned by write_file. - * callback(null, {'file':results.write_file, 'email':'user@example.com'}); - * }] - * }, function(err, results) { - * console.log('err = ', err); - * console.log('results = ', results); - * }); - */ -function auto(tasks, concurrency, callback) { - if (typeof concurrency !== 'number') { - // concurrency is optional, shift the args. - callback = concurrency; - concurrency = null; - } - callback = once(callback || promiseCallback()); - var numTasks = Object.keys(tasks).length; - if (!numTasks) { - return callback(null); - } - if (!concurrency) { - concurrency = numTasks; - } - - var results = {}; - var runningTasks = 0; - var canceled = false; - var hasError = false; - - var listeners = Object.create(null); - - var readyTasks = []; - - // for cycle detection: - var readyToCheck = []; // tasks that have been identified as reachable - // without the possibility of returning to an ancestor task - var uncheckedDependencies = {}; - - Object.keys(tasks).forEach(key => { - var task = tasks[key]; - if (!Array.isArray(task)) { - // no dependencies - enqueueTask(key, [task]); - readyToCheck.push(key); - return; - } - - var dependencies = task.slice(0, task.length - 1); - var remainingDependencies = dependencies.length; - if (remainingDependencies === 0) { - enqueueTask(key, task); - readyToCheck.push(key); - return; - } - uncheckedDependencies[key] = remainingDependencies; - - dependencies.forEach(dependencyName => { - if (!tasks[dependencyName]) { - throw new Error('async.auto task `' + key + - '` has a non-existent dependency `' + - dependencyName + '` in ' + - dependencies.join(', ')); - } - addListener(dependencyName, () => { - remainingDependencies--; - if (remainingDependencies === 0) { - enqueueTask(key, task); - } - }); - }); - }); - - checkForDeadlocks(); - processQueue(); - - function enqueueTask(key, task) { - readyTasks.push(() => runTask(key, task)); - } - - function processQueue() { - if (canceled) return - if (readyTasks.length === 0 && runningTasks === 0) { - return callback(null, results); - } - while(readyTasks.length && runningTasks < concurrency) { - var run = readyTasks.shift(); - run(); - } - - } - - function addListener(taskName, fn) { - var taskListeners = listeners[taskName]; - if (!taskListeners) { - taskListeners = listeners[taskName] = []; - } - - taskListeners.push(fn); - } - - function taskComplete(taskName) { - var taskListeners = listeners[taskName] || []; - taskListeners.forEach(fn => fn()); - processQueue(); - } - - - function runTask(key, task) { - if (hasError) return; - - var taskCallback = onlyOnce((err, ...result) => { - runningTasks--; - if (err === false) { - canceled = true; - return - } - if (result.length < 2) { - [result] = result; - } - if (err) { - var safeResults = {}; - Object.keys(results).forEach(rkey => { - safeResults[rkey] = results[rkey]; - }); - safeResults[key] = result; - hasError = true; - listeners = Object.create(null); - if (canceled) return - callback(err, safeResults); - } else { - results[key] = result; - taskComplete(key); - } - }); - - runningTasks++; - var taskFn = wrapAsync(task[task.length - 1]); - if (task.length > 1) { - taskFn(results, taskCallback); - } else { - taskFn(taskCallback); - } - } - - function checkForDeadlocks() { - // Kahn's algorithm - // https://en.wikipedia.org/wiki/Topological_sorting#Kahn.27s_algorithm - // http://connalle.blogspot.com/2013/10/topological-sortingkahn-algorithm.html - var currentTask; - var counter = 0; - while (readyToCheck.length) { - currentTask = readyToCheck.pop(); - counter++; - getDependents(currentTask).forEach(dependent => { - if (--uncheckedDependencies[dependent] === 0) { - readyToCheck.push(dependent); - } - }); - } - - if (counter !== numTasks) { - throw new Error( - 'async.auto cannot execute tasks due to a recursive dependency' - ); - } - } - - function getDependents(taskName) { - var result = []; - Object.keys(tasks).forEach(key => { - const task = tasks[key]; - if (Array.isArray(task) && task.indexOf(taskName) >= 0) { - result.push(key); - } - }); - return result; - } - - return callback[PROMISE_SYMBOL] -} - -var FN_ARGS = /^(?:async\s+)?(?:function)?\s*\w*\s*\(\s*([^)]+)\s*\)(?:\s*{)/; -var ARROW_FN_ARGS = /^(?:async\s+)?\(?\s*([^)=]+)\s*\)?(?:\s*=>)/; -var FN_ARG_SPLIT = /,/; -var FN_ARG = /(=.+)?(\s*)$/; -var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; - -function parseParams(func) { - const src = func.toString().replace(STRIP_COMMENTS, ''); - let match = src.match(FN_ARGS); - if (!match) { - match = src.match(ARROW_FN_ARGS); - } - if (!match) throw new Error('could not parse args in autoInject\nSource:\n' + src) - let [, args] = match; - return args - .replace(/\s/g, '') - .split(FN_ARG_SPLIT) - .map((arg) => arg.replace(FN_ARG, '').trim()); -} - -/** - * A dependency-injected version of the [async.auto]{@link module:ControlFlow.auto} function. Dependent - * tasks are specified as parameters to the function, after the usual callback - * parameter, with the parameter names matching the names of the tasks it - * depends on. This can provide even more readable task graphs which can be - * easier to maintain. - * - * If a final callback is specified, the task results are similarly injected, - * specified as named parameters after the initial error parameter. - * - * The autoInject function is purely syntactic sugar and its semantics are - * otherwise equivalent to [async.auto]{@link module:ControlFlow.auto}. - * - * @name autoInject - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.auto]{@link module:ControlFlow.auto} - * @category Control Flow - * @param {Object} tasks - An object, each of whose properties is an {@link AsyncFunction} of - * the form 'func([dependencies...], callback). The object's key of a property - * serves as the name of the task defined by that property, i.e. can be used - * when specifying requirements for other tasks. - * * The `callback` parameter is a `callback(err, result)` which must be called - * when finished, passing an `error` (which can be `null`) and the result of - * the function's execution. The remaining parameters name other tasks on - * which the task is dependent, and the results from those tasks are the - * arguments of those parameters. - * @param {Function} [callback] - An optional callback which is called when all - * the tasks have been completed. It receives the `err` argument if any `tasks` - * pass an error to their callback, and a `results` object with any completed - * task results, similar to `auto`. - * @returns {Promise} a promise, if no callback is passed - * @example - * - * // The example from `auto` can be rewritten as follows: - * async.autoInject({ - * get_data: function(callback) { - * // async code to get some data - * callback(null, 'data', 'converted to array'); - * }, - * make_folder: function(callback) { - * // async code to create a directory to store a file in - * // this is run at the same time as getting the data - * callback(null, 'folder'); - * }, - * write_file: function(get_data, make_folder, callback) { - * // once there is some data and the directory exists, - * // write the data to a file in the directory - * callback(null, 'filename'); - * }, - * email_link: function(write_file, callback) { - * // once the file is written let's email a link to it... - * // write_file contains the filename returned by write_file. - * callback(null, {'file':write_file, 'email':'user@example.com'}); - * } - * }, function(err, results) { - * console.log('err = ', err); - * console.log('email_link = ', results.email_link); - * }); - * - * // If you are using a JS minifier that mangles parameter names, `autoInject` - * // will not work with plain functions, since the parameter names will be - * // collapsed to a single letter identifier. To work around this, you can - * // explicitly specify the names of the parameters your task function needs - * // in an array, similar to Angular.js dependency injection. - * - * // This still has an advantage over plain `auto`, since the results a task - * // depends on are still spread into arguments. - * async.autoInject({ - * //... - * write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) { - * callback(null, 'filename'); - * }], - * email_link: ['write_file', function(write_file, callback) { - * callback(null, {'file':write_file, 'email':'user@example.com'}); - * }] - * //... - * }, function(err, results) { - * console.log('err = ', err); - * console.log('email_link = ', results.email_link); - * }); - */ -function autoInject(tasks, callback) { - var newTasks = {}; - - Object.keys(tasks).forEach(key => { - var taskFn = tasks[key]; - var params; - var fnIsAsync = isAsync(taskFn); - var hasNoDeps = - (!fnIsAsync && taskFn.length === 1) || - (fnIsAsync && taskFn.length === 0); - - if (Array.isArray(taskFn)) { - params = [...taskFn]; - taskFn = params.pop(); - - newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn); - } else if (hasNoDeps) { - // no dependencies, use the function as-is - newTasks[key] = taskFn; - } else { - params = parseParams(taskFn); - if ((taskFn.length === 0 && !fnIsAsync) && params.length === 0) { - throw new Error("autoInject task functions require explicit parameters."); - } - - // remove callback param - if (!fnIsAsync) params.pop(); - - newTasks[key] = params.concat(newTask); - } - - function newTask(results, taskCb) { - var newArgs = params.map(name => results[name]); - newArgs.push(taskCb); - wrapAsync(taskFn)(...newArgs); - } - }); - - return auto(newTasks, callback); -} - -// Simple doubly linked list (https://en.wikipedia.org/wiki/Doubly_linked_list) implementation -// used for queues. This implementation assumes that the node provided by the user can be modified -// to adjust the next and last properties. We implement only the minimal functionality -// for queue support. -class DLL { - constructor() { - this.head = this.tail = null; - this.length = 0; - } - - removeLink(node) { - if (node.prev) node.prev.next = node.next; - else this.head = node.next; - if (node.next) node.next.prev = node.prev; - else this.tail = node.prev; - - node.prev = node.next = null; - this.length -= 1; - return node; - } - - empty () { - while(this.head) this.shift(); - return this; - } - - insertAfter(node, newNode) { - newNode.prev = node; - newNode.next = node.next; - if (node.next) node.next.prev = newNode; - else this.tail = newNode; - node.next = newNode; - this.length += 1; - } - - insertBefore(node, newNode) { - newNode.prev = node.prev; - newNode.next = node; - if (node.prev) node.prev.next = newNode; - else this.head = newNode; - node.prev = newNode; - this.length += 1; - } - - unshift(node) { - if (this.head) this.insertBefore(this.head, node); - else setInitial(this, node); - } - - push(node) { - if (this.tail) this.insertAfter(this.tail, node); - else setInitial(this, node); - } - - shift() { - return this.head && this.removeLink(this.head); - } - - pop() { - return this.tail && this.removeLink(this.tail); - } - - toArray() { - return [...this] - } - - *[Symbol.iterator] () { - var cur = this.head; - while (cur) { - yield cur.data; - cur = cur.next; - } - } - - remove (testFn) { - var curr = this.head; - while(curr) { - var {next} = curr; - if (testFn(curr)) { - this.removeLink(curr); - } - curr = next; - } - return this; - } -} - -function setInitial(dll, node) { - dll.length = 1; - dll.head = dll.tail = node; -} - -function queue(worker, concurrency, payload) { - if (concurrency == null) { - concurrency = 1; - } - else if(concurrency === 0) { - throw new RangeError('Concurrency must not be zero'); - } - - var _worker = wrapAsync(worker); - var numRunning = 0; - var workersList = []; - const events = { - error: [], - drain: [], - saturated: [], - unsaturated: [], - empty: [] - }; - - function on (event, handler) { - events[event].push(handler); - } - - function once (event, handler) { - const handleAndRemove = (...args) => { - off(event, handleAndRemove); - handler(...args); - }; - events[event].push(handleAndRemove); - } - - function off (event, handler) { - if (!event) return Object.keys(events).forEach(ev => events[ev] = []) - if (!handler) return events[event] = [] - events[event] = events[event].filter(ev => ev !== handler); - } - - function trigger (event, ...args) { - events[event].forEach(handler => handler(...args)); - } - - var processingScheduled = false; - function _insert(data, insertAtFront, rejectOnError, callback) { - if (callback != null && typeof callback !== 'function') { - throw new Error('task callback must be a function'); - } - q.started = true; - - var res, rej; - function promiseCallback (err, ...args) { - // we don't care about the error, let the global error handler - // deal with it - if (err) return rejectOnError ? rej(err) : res() - if (args.length <= 1) return res(args[0]) - res(args); - } - - var item = { - data, - callback: rejectOnError ? - promiseCallback : - (callback || promiseCallback) - }; - - if (insertAtFront) { - q._tasks.unshift(item); - } else { - q._tasks.push(item); - } - - if (!processingScheduled) { - processingScheduled = true; - setImmediate$1(() => { - processingScheduled = false; - q.process(); - }); - } - - if (rejectOnError || !callback) { - return new Promise((resolve, reject) => { - res = resolve; - rej = reject; - }) - } - } - - function _createCB(tasks) { - return function (err, ...args) { - numRunning -= 1; - - for (var i = 0, l = tasks.length; i < l; i++) { - var task = tasks[i]; - - var index = workersList.indexOf(task); - if (index === 0) { - workersList.shift(); - } else if (index > 0) { - workersList.splice(index, 1); - } - - task.callback(err, ...args); - - if (err != null) { - trigger('error', err, task.data); - } - } - - if (numRunning <= (q.concurrency - q.buffer) ) { - trigger('unsaturated'); - } - - if (q.idle()) { - trigger('drain'); - } - q.process(); - }; - } - - function _maybeDrain(data) { - if (data.length === 0 && q.idle()) { - // call drain immediately if there are no tasks - setImmediate$1(() => trigger('drain')); - return true - } - return false - } - - const eventMethod = (name) => (handler) => { - if (!handler) { - return new Promise((resolve, reject) => { - once(name, (err, data) => { - if (err) return reject(err) - resolve(data); - }); - }) - } - off(name); - on(name, handler); - - }; - - var isProcessing = false; - var q = { - _tasks: new DLL(), - *[Symbol.iterator] () { - yield* q._tasks[Symbol.iterator](); - }, - concurrency, - payload, - buffer: concurrency / 4, - started: false, - paused: false, - push (data, callback) { - if (Array.isArray(data)) { - if (_maybeDrain(data)) return - return data.map(datum => _insert(datum, false, false, callback)) - } - return _insert(data, false, false, callback); - }, - pushAsync (data, callback) { - if (Array.isArray(data)) { - if (_maybeDrain(data)) return - return data.map(datum => _insert(datum, false, true, callback)) - } - return _insert(data, false, true, callback); - }, - kill () { - off(); - q._tasks.empty(); - }, - unshift (data, callback) { - if (Array.isArray(data)) { - if (_maybeDrain(data)) return - return data.map(datum => _insert(datum, true, false, callback)) - } - return _insert(data, true, false, callback); - }, - unshiftAsync (data, callback) { - if (Array.isArray(data)) { - if (_maybeDrain(data)) return - return data.map(datum => _insert(datum, true, true, callback)) - } - return _insert(data, true, true, callback); - }, - remove (testFn) { - q._tasks.remove(testFn); - }, - process () { - // Avoid trying to start too many processing operations. This can occur - // when callbacks resolve synchronously (#1267). - if (isProcessing) { - return; - } - isProcessing = true; - while(!q.paused && numRunning < q.concurrency && q._tasks.length){ - var tasks = [], data = []; - var l = q._tasks.length; - if (q.payload) l = Math.min(l, q.payload); - for (var i = 0; i < l; i++) { - var node = q._tasks.shift(); - tasks.push(node); - workersList.push(node); - data.push(node.data); - } - - numRunning += 1; - - if (q._tasks.length === 0) { - trigger('empty'); - } - - if (numRunning === q.concurrency) { - trigger('saturated'); - } - - var cb = onlyOnce(_createCB(tasks)); - _worker(data, cb); - } - isProcessing = false; - }, - length () { - return q._tasks.length; - }, - running () { - return numRunning; - }, - workersList () { - return workersList; - }, - idle() { - return q._tasks.length + numRunning === 0; - }, - pause () { - q.paused = true; - }, - resume () { - if (q.paused === false) { return; } - q.paused = false; - setImmediate$1(q.process); - } - }; - // define these as fixed properties, so people get useful errors when updating - Object.defineProperties(q, { - saturated: { - writable: false, - value: eventMethod('saturated') - }, - unsaturated: { - writable: false, - value: eventMethod('unsaturated') - }, - empty: { - writable: false, - value: eventMethod('empty') - }, - drain: { - writable: false, - value: eventMethod('drain') - }, - error: { - writable: false, - value: eventMethod('error') - }, - }); - return q; -} - -/** - * Creates a `cargo` object with the specified payload. Tasks added to the - * cargo will be processed altogether (up to the `payload` limit). If the - * `worker` is in progress, the task is queued until it becomes available. Once - * the `worker` has completed some tasks, each callback of those tasks is - * called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966) - * for how `cargo` and `queue` work. - * - * While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers - * at a time, cargo passes an array of tasks to a single worker, repeating - * when the worker is finished. - * - * @name cargo - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.queue]{@link module:ControlFlow.queue} - * @category Control Flow - * @param {AsyncFunction} worker - An asynchronous function for processing an array - * of queued tasks. Invoked with `(tasks, callback)`. - * @param {number} [payload=Infinity] - An optional `integer` for determining - * how many tasks should be processed per round; if omitted, the default is - * unlimited. - * @returns {module:ControlFlow.QueueObject} A cargo object to manage the tasks. Callbacks can - * attached as certain properties to listen for specific events during the - * lifecycle of the cargo and inner queue. - * @example - * - * // create a cargo object with payload 2 - * var cargo = async.cargo(function(tasks, callback) { - * for (var i=0; i { - _iteratee(memo, x, (err, v) => { - memo = v; - iterCb(err); - }); - }, err => callback(err, memo)); -} -var reduce$1 = awaitify(reduce, 4); - -/** - * Version of the compose function that is more natural to read. Each function - * consumes the return value of the previous function. It is the equivalent of - * [compose]{@link module:ControlFlow.compose} with the arguments reversed. - * - * Each function is executed with the `this` binding of the composed function. - * - * @name seq - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.compose]{@link module:ControlFlow.compose} - * @category Control Flow - * @param {...AsyncFunction} functions - the asynchronous functions to compose - * @returns {Function} a function that composes the `functions` in order - * @example - * - * // Requires lodash (or underscore), express3 and dresende's orm2. - * // Part of an app, that fetches cats of the logged user. - * // This example uses `seq` function to avoid overnesting and error - * // handling clutter. - * app.get('/cats', function(request, response) { - * var User = request.models.User; - * async.seq( - * _.bind(User.get, User), // 'User.get' has signature (id, callback(err, data)) - * function(user, fn) { - * user.getCats(fn); // 'getCats' has signature (callback(err, data)) - * } - * )(req.session.user_id, function (err, cats) { - * if (err) { - * console.error(err); - * response.json({ status: 'error', message: err.message }); - * } else { - * response.json({ status: 'ok', message: 'Cats found', data: cats }); - * } - * }); - * }); - */ -function seq(...functions) { - var _functions = functions.map(wrapAsync); - return function (...args) { - var that = this; - - var cb = args[args.length - 1]; - if (typeof cb == 'function') { - args.pop(); - } else { - cb = promiseCallback(); - } - - reduce$1(_functions, args, (newargs, fn, iterCb) => { - fn.apply(that, newargs.concat((err, ...nextargs) => { - iterCb(err, nextargs); - })); - }, - (err, results) => cb(err, ...results)); - - return cb[PROMISE_SYMBOL] - }; -} - -/** - * Creates a function which is a composition of the passed asynchronous - * functions. Each function consumes the return value of the function that - * follows. Composing functions `f()`, `g()`, and `h()` would produce the result - * of `f(g(h()))`, only this version uses callbacks to obtain the return values. - * - * If the last argument to the composed function is not a function, a promise - * is returned when you call it. - * - * Each function is executed with the `this` binding of the composed function. - * - * @name compose - * @static - * @memberOf module:ControlFlow - * @method - * @category Control Flow - * @param {...AsyncFunction} functions - the asynchronous functions to compose - * @returns {Function} an asynchronous function that is the composed - * asynchronous `functions` - * @example - * - * function add1(n, callback) { - * setTimeout(function () { - * callback(null, n + 1); - * }, 10); - * } - * - * function mul3(n, callback) { - * setTimeout(function () { - * callback(null, n * 3); - * }, 10); - * } - * - * var add1mul3 = async.compose(mul3, add1); - * add1mul3(4, function (err, result) { - * // result now equals 15 - * }); - */ -function compose(...args) { - return seq(...args.reverse()); -} - -/** - * The same as [`map`]{@link module:Collections.map} but runs a maximum of `limit` async operations at a time. - * - * @name mapLimit - * @static - * @memberOf module:Collections - * @method - * @see [async.map]{@link module:Collections.map} - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {number} limit - The maximum number of async operations at a time. - * @param {AsyncFunction} iteratee - An async function to apply to each item in - * `coll`. - * The iteratee should complete with the transformed item. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called when all `iteratee` - * functions have finished, or an error occurs. Results is an array of the - * transformed items from the `coll`. Invoked with (err, results). - * @returns {Promise} a promise, if no callback is passed - */ -function mapLimit (coll, limit, iteratee, callback) { - return _asyncMap(eachOfLimit(limit), coll, iteratee, callback) -} -var mapLimit$1 = awaitify(mapLimit, 4); - -/** - * The same as [`concat`]{@link module:Collections.concat} but runs a maximum of `limit` async operations at a time. - * - * @name concatLimit - * @static - * @memberOf module:Collections - * @method - * @see [async.concat]{@link module:Collections.concat} - * @category Collection - * @alias flatMapLimit - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {number} limit - The maximum number of async operations at a time. - * @param {AsyncFunction} iteratee - A function to apply to each item in `coll`, - * which should use an array as its result. Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished, or an error occurs. Results is an array - * containing the concatenated results of the `iteratee` function. Invoked with - * (err, results). - * @returns A Promise, if no callback is passed - */ -function concatLimit(coll, limit, iteratee, callback) { - var _iteratee = wrapAsync(iteratee); - return mapLimit$1(coll, limit, (val, iterCb) => { - _iteratee(val, (err, ...args) => { - if (err) return iterCb(err); - return iterCb(err, args); - }); - }, (err, mapResults) => { - var result = []; - for (var i = 0; i < mapResults.length; i++) { - if (mapResults[i]) { - result = result.concat(...mapResults[i]); - } - } - - return callback(err, result); - }); -} -var concatLimit$1 = awaitify(concatLimit, 4); - -/** - * Applies `iteratee` to each item in `coll`, concatenating the results. Returns - * the concatenated list. The `iteratee`s are called in parallel, and the - * results are concatenated as they return. The results array will be returned in - * the original order of `coll` passed to the `iteratee` function. - * - * @name concat - * @static - * @memberOf module:Collections - * @method - * @category Collection - * @alias flatMap - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - A function to apply to each item in `coll`, - * which should use an array as its result. Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished, or an error occurs. Results is an array - * containing the concatenated results of the `iteratee` function. Invoked with - * (err, results). - * @returns A Promise, if no callback is passed - * @example - * - * async.concat(['dir1','dir2','dir3'], fs.readdir, function(err, files) { - * // files is now a list of filenames that exist in the 3 directories - * }); - */ -function concat(coll, iteratee, callback) { - return concatLimit$1(coll, Infinity, iteratee, callback) -} -var concat$1 = awaitify(concat, 3); - -/** - * The same as [`concat`]{@link module:Collections.concat} but runs only a single async operation at a time. - * - * @name concatSeries - * @static - * @memberOf module:Collections - * @method - * @see [async.concat]{@link module:Collections.concat} - * @category Collection - * @alias flatMapSeries - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - A function to apply to each item in `coll`. - * The iteratee should complete with an array an array of results. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished, or an error occurs. Results is an array - * containing the concatenated results of the `iteratee` function. Invoked with - * (err, results). - * @returns A Promise, if no callback is passed - */ -function concatSeries(coll, iteratee, callback) { - return concatLimit$1(coll, 1, iteratee, callback) -} -var concatSeries$1 = awaitify(concatSeries, 3); - -/** - * Returns a function that when called, calls-back with the values provided. - * Useful as the first function in a [`waterfall`]{@link module:ControlFlow.waterfall}, or for plugging values in to - * [`auto`]{@link module:ControlFlow.auto}. - * - * @name constant - * @static - * @memberOf module:Utils - * @method - * @category Util - * @param {...*} arguments... - Any number of arguments to automatically invoke - * callback with. - * @returns {AsyncFunction} Returns a function that when invoked, automatically - * invokes the callback with the previous given arguments. - * @example - * - * async.waterfall([ - * async.constant(42), - * function (value, next) { - * // value === 42 - * }, - * //... - * ], callback); - * - * async.waterfall([ - * async.constant(filename, "utf8"), - * fs.readFile, - * function (fileData, next) { - * //... - * } - * //... - * ], callback); - * - * async.auto({ - * hostname: async.constant("https://server.net/"), - * port: findFreePort, - * launchServer: ["hostname", "port", function (options, cb) { - * startServer(options, cb); - * }], - * //... - * }, callback); - */ -function constant(...args) { - return function (...ignoredArgs/*, callback*/) { - var callback = ignoredArgs.pop(); - return callback(null, ...args); - }; -} - -function _createTester(check, getResult) { - return (eachfn, arr, _iteratee, cb) => { - var testPassed = false; - var testResult; - const iteratee = wrapAsync(_iteratee); - eachfn(arr, (value, _, callback) => { - iteratee(value, (err, result) => { - if (err || err === false) return callback(err); - - if (check(result) && !testResult) { - testPassed = true; - testResult = getResult(true, value); - return callback(null, breakLoop); - } - callback(); - }); - }, err => { - if (err) return cb(err); - cb(null, testPassed ? testResult : getResult(false)); - }); - }; -} - -/** - * Returns the first value in `coll` that passes an async truth test. The - * `iteratee` is applied in parallel, meaning the first iteratee to return - * `true` will fire the detect `callback` with that result. That means the - * result might not be the first item in the original `coll` (in terms of order) - * that passes the test. - - * If order within the original `coll` is important, then look at - * [`detectSeries`]{@link module:Collections.detectSeries}. - * - * @name detect - * @static - * @memberOf module:Collections - * @method - * @alias find - * @category Collections - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`. - * The iteratee must complete with a boolean value as its result. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon as any - * iteratee returns `true`, or after all the `iteratee` functions have finished. - * Result will be the first item in the array that passes the truth test - * (iteratee) or the value `undefined` if none passed. Invoked with - * (err, result). - * @returns A Promise, if no callback is passed - * @example - * - * async.detect(['file1','file2','file3'], function(filePath, callback) { - * fs.access(filePath, function(err) { - * callback(null, !err) - * }); - * }, function(err, result) { - * // result now equals the first file in the list that exists - * }); - */ -function detect(coll, iteratee, callback) { - return _createTester(bool => bool, (res, item) => item)(eachOf$1, coll, iteratee, callback) -} -var detect$1 = awaitify(detect, 3); - -/** - * The same as [`detect`]{@link module:Collections.detect} but runs a maximum of `limit` async operations at a - * time. - * - * @name detectLimit - * @static - * @memberOf module:Collections - * @method - * @see [async.detect]{@link module:Collections.detect} - * @alias findLimit - * @category Collections - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {number} limit - The maximum number of async operations at a time. - * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`. - * The iteratee must complete with a boolean value as its result. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon as any - * iteratee returns `true`, or after all the `iteratee` functions have finished. - * Result will be the first item in the array that passes the truth test - * (iteratee) or the value `undefined` if none passed. Invoked with - * (err, result). - * @returns a Promise if no callback is passed - */ -function detectLimit(coll, limit, iteratee, callback) { - return _createTester(bool => bool, (res, item) => item)(eachOfLimit(limit), coll, iteratee, callback) -} -var detectLimit$1 = awaitify(detectLimit, 4); - -/** - * The same as [`detect`]{@link module:Collections.detect} but runs only a single async operation at a time. - * - * @name detectSeries - * @static - * @memberOf module:Collections - * @method - * @see [async.detect]{@link module:Collections.detect} - * @alias findSeries - * @category Collections - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`. - * The iteratee must complete with a boolean value as its result. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon as any - * iteratee returns `true`, or after all the `iteratee` functions have finished. - * Result will be the first item in the array that passes the truth test - * (iteratee) or the value `undefined` if none passed. Invoked with - * (err, result). - * @returns a Promise if no callback is passed - */ -function detectSeries(coll, iteratee, callback) { - return _createTester(bool => bool, (res, item) => item)(eachOfLimit(1), coll, iteratee, callback) -} - -var detectSeries$1 = awaitify(detectSeries, 3); - -function consoleFunc(name) { - return (fn, ...args) => wrapAsync(fn)(...args, (err, ...resultArgs) => { - if (typeof console === 'object') { - if (err) { - if (console.error) { - console.error(err); - } - } else if (console[name]) { - resultArgs.forEach(x => console[name](x)); - } - } - }) -} - -/** - * Logs the result of an [`async` function]{@link AsyncFunction} to the - * `console` using `console.dir` to display the properties of the resulting object. - * Only works in Node.js or in browsers that support `console.dir` and - * `console.error` (such as FF and Chrome). - * If multiple arguments are returned from the async function, - * `console.dir` is called on each argument in order. - * - * @name dir - * @static - * @memberOf module:Utils - * @method - * @category Util - * @param {AsyncFunction} function - The function you want to eventually apply - * all arguments to. - * @param {...*} arguments... - Any number of arguments to apply to the function. - * @example - * - * // in a module - * var hello = function(name, callback) { - * setTimeout(function() { - * callback(null, {hello: name}); - * }, 1000); - * }; - * - * // in the node repl - * node> async.dir(hello, 'world'); - * {hello: 'world'} - */ -var dir = consoleFunc('dir'); - -/** - * The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in - * the order of operations, the arguments `test` and `iteratee` are switched. - * - * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript. - * - * @name doWhilst - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.whilst]{@link module:ControlFlow.whilst} - * @category Control Flow - * @param {AsyncFunction} iteratee - A function which is called each time `test` - * passes. Invoked with (callback). - * @param {AsyncFunction} test - asynchronous truth test to perform after each - * execution of `iteratee`. Invoked with (...args, callback), where `...args` are the - * non-error args from the previous callback of `iteratee`. - * @param {Function} [callback] - A callback which is called after the test - * function has failed and repeated execution of `iteratee` has stopped. - * `callback` will be passed an error and any arguments passed to the final - * `iteratee`'s callback. Invoked with (err, [results]); - * @returns {Promise} a promise, if no callback is passed - */ -function doWhilst(iteratee, test, callback) { - callback = onlyOnce(callback); - var _fn = wrapAsync(iteratee); - var _test = wrapAsync(test); - var results; - - function next(err, ...args) { - if (err) return callback(err); - if (err === false) return; - results = args; - _test(...args, check); - } - - function check(err, truth) { - if (err) return callback(err); - if (err === false) return; - if (!truth) return callback(null, ...results); - _fn(next); - } - - return check(null, true); -} - -var doWhilst$1 = awaitify(doWhilst, 3); - -/** - * Like ['doWhilst']{@link module:ControlFlow.doWhilst}, except the `test` is inverted. Note the - * argument ordering differs from `until`. - * - * @name doUntil - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.doWhilst]{@link module:ControlFlow.doWhilst} - * @category Control Flow - * @param {AsyncFunction} iteratee - An async function which is called each time - * `test` fails. Invoked with (callback). - * @param {AsyncFunction} test - asynchronous truth test to perform after each - * execution of `iteratee`. Invoked with (...args, callback), where `...args` are the - * non-error args from the previous callback of `iteratee` - * @param {Function} [callback] - A callback which is called after the test - * function has passed and repeated execution of `iteratee` has stopped. `callback` - * will be passed an error and any arguments passed to the final `iteratee`'s - * callback. Invoked with (err, [results]); - * @returns {Promise} a promise, if no callback is passed - */ -function doUntil(iteratee, test, callback) { - const _test = wrapAsync(test); - return doWhilst$1(iteratee, (...args) => { - const cb = args.pop(); - _test(...args, (err, truth) => cb (err, !truth)); - }, callback); -} - -function _withoutIndex(iteratee) { - return (value, index, callback) => iteratee(value, callback); -} - -/** - * Applies the function `iteratee` to each item in `coll`, in parallel. - * The `iteratee` is called with an item from the list, and a callback for when - * it has finished. If the `iteratee` passes an error to its `callback`, the - * main `callback` (for the `each` function) is immediately called with the - * error. - * - * Note, that since this function applies `iteratee` to each item in parallel, - * there is no guarantee that the iteratee functions will complete in order. - * - * @name each - * @static - * @memberOf module:Collections - * @method - * @alias forEach - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async function to apply to - * each item in `coll`. Invoked with (item, callback). - * The array index is not passed to the iteratee. - * If you need the index, use `eachOf`. - * @param {Function} [callback] - A callback which is called when all - * `iteratee` functions have finished, or an error occurs. Invoked with (err). - * @returns {Promise} a promise, if a callback is omitted - * @example - * - * // assuming openFiles is an array of file names and saveFile is a function - * // to save the modified contents of that file: - * - * async.each(openFiles, saveFile, function(err){ - * // if any of the saves produced an error, err would equal that error - * }); - * - * // assuming openFiles is an array of file names - * async.each(openFiles, function(file, callback) { - * - * // Perform operation on file here. - * console.log('Processing file ' + file); - * - * if( file.length > 32 ) { - * console.log('This file name is too long'); - * callback('File name too long'); - * } else { - * // Do work to process file here - * console.log('File processed'); - * callback(); - * } - * }, function(err) { - * // if any of the file processing produced an error, err would equal that error - * if( err ) { - * // One of the iterations produced an error. - * // All processing will now stop. - * console.log('A file failed to process'); - * } else { - * console.log('All files have been processed successfully'); - * } - * }); - */ -function eachLimit(coll, iteratee, callback) { - return eachOf$1(coll, _withoutIndex(wrapAsync(iteratee)), callback); -} - -var each = awaitify(eachLimit, 3); - -/** - * The same as [`each`]{@link module:Collections.each} but runs a maximum of `limit` async operations at a time. - * - * @name eachLimit - * @static - * @memberOf module:Collections - * @method - * @see [async.each]{@link module:Collections.each} - * @alias forEachLimit - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {number} limit - The maximum number of async operations at a time. - * @param {AsyncFunction} iteratee - An async function to apply to each item in - * `coll`. - * The array index is not passed to the iteratee. - * If you need the index, use `eachOfLimit`. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called when all - * `iteratee` functions have finished, or an error occurs. Invoked with (err). - * @returns {Promise} a promise, if a callback is omitted - */ -function eachLimit$1(coll, limit, iteratee, callback) { - return eachOfLimit(limit)(coll, _withoutIndex(wrapAsync(iteratee)), callback); -} -var eachLimit$2 = awaitify(eachLimit$1, 4); - -/** - * The same as [`each`]{@link module:Collections.each} but runs only a single async operation at a time. - * - * Note, that unlike [`each`]{@link module:Collections.each}, this function applies iteratee to each item - * in series and therefore the iteratee functions will complete in order. - - * @name eachSeries - * @static - * @memberOf module:Collections - * @method - * @see [async.each]{@link module:Collections.each} - * @alias forEachSeries - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async function to apply to each - * item in `coll`. - * The array index is not passed to the iteratee. - * If you need the index, use `eachOfSeries`. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called when all - * `iteratee` functions have finished, or an error occurs. Invoked with (err). - * @returns {Promise} a promise, if a callback is omitted - */ -function eachSeries(coll, iteratee, callback) { - return eachLimit$2(coll, 1, iteratee, callback) -} -var eachSeries$1 = awaitify(eachSeries, 3); - -/** - * Wrap an async function and ensure it calls its callback on a later tick of - * the event loop. If the function already calls its callback on a next tick, - * no extra deferral is added. This is useful for preventing stack overflows - * (`RangeError: Maximum call stack size exceeded`) and generally keeping - * [Zalgo](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony) - * contained. ES2017 `async` functions are returned as-is -- they are immune - * to Zalgo's corrupting influences, as they always resolve on a later tick. - * - * @name ensureAsync - * @static - * @memberOf module:Utils - * @method - * @category Util - * @param {AsyncFunction} fn - an async function, one that expects a node-style - * callback as its last argument. - * @returns {AsyncFunction} Returns a wrapped function with the exact same call - * signature as the function passed in. - * @example - * - * function sometimesAsync(arg, callback) { - * if (cache[arg]) { - * return callback(null, cache[arg]); // this would be synchronous!! - * } else { - * doSomeIO(arg, callback); // this IO would be asynchronous - * } - * } - * - * // this has a risk of stack overflows if many results are cached in a row - * async.mapSeries(args, sometimesAsync, done); - * - * // this will defer sometimesAsync's callback if necessary, - * // preventing stack overflows - * async.mapSeries(args, async.ensureAsync(sometimesAsync), done); - */ -function ensureAsync(fn) { - if (isAsync(fn)) return fn; - return function (...args/*, callback*/) { - var callback = args.pop(); - var sync = true; - args.push((...innerArgs) => { - if (sync) { - setImmediate$1(() => callback(...innerArgs)); - } else { - callback(...innerArgs); - } - }); - fn.apply(this, args); - sync = false; - }; -} - -/** - * Returns `true` if every element in `coll` satisfies an async test. If any - * iteratee call returns `false`, the main `callback` is immediately called. - * - * @name every - * @static - * @memberOf module:Collections - * @method - * @alias all - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async truth test to apply to each item - * in the collection in parallel. - * The iteratee must complete with a boolean result value. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished. Result will be either `true` or `false` - * depending on the values of the async tests. Invoked with (err, result). - * @returns {Promise} a promise, if no callback provided - * @example - * - * async.every(['file1','file2','file3'], function(filePath, callback) { - * fs.access(filePath, function(err) { - * callback(null, !err) - * }); - * }, function(err, result) { - * // if result is true then every file exists - * }); - */ -function every(coll, iteratee, callback) { - return _createTester(bool => !bool, res => !res)(eachOf$1, coll, iteratee, callback) -} -var every$1 = awaitify(every, 3); - -/** - * The same as [`every`]{@link module:Collections.every} but runs a maximum of `limit` async operations at a time. - * - * @name everyLimit - * @static - * @memberOf module:Collections - * @method - * @see [async.every]{@link module:Collections.every} - * @alias allLimit - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {number} limit - The maximum number of async operations at a time. - * @param {AsyncFunction} iteratee - An async truth test to apply to each item - * in the collection in parallel. - * The iteratee must complete with a boolean result value. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished. Result will be either `true` or `false` - * depending on the values of the async tests. Invoked with (err, result). - * @returns {Promise} a promise, if no callback provided - */ -function everyLimit(coll, limit, iteratee, callback) { - return _createTester(bool => !bool, res => !res)(eachOfLimit(limit), coll, iteratee, callback) -} -var everyLimit$1 = awaitify(everyLimit, 4); - -/** - * The same as [`every`]{@link module:Collections.every} but runs only a single async operation at a time. - * - * @name everySeries - * @static - * @memberOf module:Collections - * @method - * @see [async.every]{@link module:Collections.every} - * @alias allSeries - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async truth test to apply to each item - * in the collection in series. - * The iteratee must complete with a boolean result value. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished. Result will be either `true` or `false` - * depending on the values of the async tests. Invoked with (err, result). - * @returns {Promise} a promise, if no callback provided - */ -function everySeries(coll, iteratee, callback) { - return _createTester(bool => !bool, res => !res)(eachOfSeries$1, coll, iteratee, callback) -} -var everySeries$1 = awaitify(everySeries, 3); - -function filterArray(eachfn, arr, iteratee, callback) { - var truthValues = new Array(arr.length); - eachfn(arr, (x, index, iterCb) => { - iteratee(x, (err, v) => { - truthValues[index] = !!v; - iterCb(err); - }); - }, err => { - if (err) return callback(err); - var results = []; - for (var i = 0; i < arr.length; i++) { - if (truthValues[i]) results.push(arr[i]); - } - callback(null, results); - }); -} - -function filterGeneric(eachfn, coll, iteratee, callback) { - var results = []; - eachfn(coll, (x, index, iterCb) => { - iteratee(x, (err, v) => { - if (err) return iterCb(err); - if (v) { - results.push({index, value: x}); - } - iterCb(err); - }); - }, err => { - if (err) return callback(err); - callback(null, results - .sort((a, b) => a.index - b.index) - .map(v => v.value)); - }); -} - -function _filter(eachfn, coll, iteratee, callback) { - var filter = isArrayLike(coll) ? filterArray : filterGeneric; - return filter(eachfn, coll, wrapAsync(iteratee), callback); -} - -/** - * Returns a new array of all the values in `coll` which pass an async truth - * test. This operation is performed in parallel, but the results array will be - * in the same order as the original. - * - * @name filter - * @static - * @memberOf module:Collections - * @method - * @alias select - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {Function} iteratee - A truth test to apply to each item in `coll`. - * The `iteratee` is passed a `callback(err, truthValue)`, which must be called - * with a boolean argument once it has completed. Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished. Invoked with (err, results). - * @returns {Promise} a promise, if no callback provided - * @example - * - * async.filter(['file1','file2','file3'], function(filePath, callback) { - * fs.access(filePath, function(err) { - * callback(null, !err) - * }); - * }, function(err, results) { - * // results now equals an array of the existing files - * }); - */ -function filter (coll, iteratee, callback) { - return _filter(eachOf$1, coll, iteratee, callback) -} -var filter$1 = awaitify(filter, 3); - -/** - * The same as [`filter`]{@link module:Collections.filter} but runs a maximum of `limit` async operations at a - * time. - * - * @name filterLimit - * @static - * @memberOf module:Collections - * @method - * @see [async.filter]{@link module:Collections.filter} - * @alias selectLimit - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {number} limit - The maximum number of async operations at a time. - * @param {Function} iteratee - A truth test to apply to each item in `coll`. - * The `iteratee` is passed a `callback(err, truthValue)`, which must be called - * with a boolean argument once it has completed. Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished. Invoked with (err, results). - * @returns {Promise} a promise, if no callback provided - */ -function filterLimit (coll, limit, iteratee, callback) { - return _filter(eachOfLimit(limit), coll, iteratee, callback) -} -var filterLimit$1 = awaitify(filterLimit, 4); - -/** - * The same as [`filter`]{@link module:Collections.filter} but runs only a single async operation at a time. - * - * @name filterSeries - * @static - * @memberOf module:Collections - * @method - * @see [async.filter]{@link module:Collections.filter} - * @alias selectSeries - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {Function} iteratee - A truth test to apply to each item in `coll`. - * The `iteratee` is passed a `callback(err, truthValue)`, which must be called - * with a boolean argument once it has completed. Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished. Invoked with (err, results) - * @returns {Promise} a promise, if no callback provided - */ -function filterSeries (coll, iteratee, callback) { - return _filter(eachOfSeries$1, coll, iteratee, callback) -} -var filterSeries$1 = awaitify(filterSeries, 3); - -/** - * Calls the asynchronous function `fn` with a callback parameter that allows it - * to call itself again, in series, indefinitely. - - * If an error is passed to the callback then `errback` is called with the - * error, and execution stops, otherwise it will never be called. - * - * @name forever - * @static - * @memberOf module:ControlFlow - * @method - * @category Control Flow - * @param {AsyncFunction} fn - an async function to call repeatedly. - * Invoked with (next). - * @param {Function} [errback] - when `fn` passes an error to it's callback, - * this function will be called, and execution stops. Invoked with (err). - * @returns {Promise} a promise that rejects if an error occurs and an errback - * is not passed - * @example - * - * async.forever( - * function(next) { - * // next is suitable for passing to things that need a callback(err [, whatever]); - * // it will result in this function being called again. - * }, - * function(err) { - * // if next is called with a value in its first parameter, it will appear - * // in here as 'err', and execution will stop. - * } - * ); - */ -function forever(fn, errback) { - var done = onlyOnce(errback); - var task = wrapAsync(ensureAsync(fn)); - - function next(err) { - if (err) return done(err); - if (err === false) return; - task(next); - } - return next(); -} -var forever$1 = awaitify(forever, 2); - -/** - * The same as [`groupBy`]{@link module:Collections.groupBy} but runs a maximum of `limit` async operations at a time. - * - * @name groupByLimit - * @static - * @memberOf module:Collections - * @method - * @see [async.groupBy]{@link module:Collections.groupBy} - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {number} limit - The maximum number of async operations at a time. - * @param {AsyncFunction} iteratee - An async function to apply to each item in - * `coll`. - * The iteratee should complete with a `key` to group the value under. - * Invoked with (value, callback). - * @param {Function} [callback] - A callback which is called when all `iteratee` - * functions have finished, or an error occurs. Result is an `Object` whoses - * properties are arrays of values which returned the corresponding key. - * @returns {Promise} a promise, if no callback is passed - */ -function groupByLimit(coll, limit, iteratee, callback) { - var _iteratee = wrapAsync(iteratee); - return mapLimit$1(coll, limit, (val, iterCb) => { - _iteratee(val, (err, key) => { - if (err) return iterCb(err); - return iterCb(err, {key, val}); - }); - }, (err, mapResults) => { - var result = {}; - // from MDN, handle object having an `hasOwnProperty` prop - var {hasOwnProperty} = Object.prototype; - - for (var i = 0; i < mapResults.length; i++) { - if (mapResults[i]) { - var {key} = mapResults[i]; - var {val} = mapResults[i]; - - if (hasOwnProperty.call(result, key)) { - result[key].push(val); - } else { - result[key] = [val]; - } - } - } - - return callback(err, result); - }); -} - -var groupByLimit$1 = awaitify(groupByLimit, 4); - -/** - * Returns a new object, where each value corresponds to an array of items, from - * `coll`, that returned the corresponding key. That is, the keys of the object - * correspond to the values passed to the `iteratee` callback. - * - * Note: Since this function applies the `iteratee` to each item in parallel, - * there is no guarantee that the `iteratee` functions will complete in order. - * However, the values for each key in the `result` will be in the same order as - * the original `coll`. For Objects, the values will roughly be in the order of - * the original Objects' keys (but this can vary across JavaScript engines). - * - * @name groupBy - * @static - * @memberOf module:Collections - * @method - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async function to apply to each item in - * `coll`. - * The iteratee should complete with a `key` to group the value under. - * Invoked with (value, callback). - * @param {Function} [callback] - A callback which is called when all `iteratee` - * functions have finished, or an error occurs. Result is an `Object` whoses - * properties are arrays of values which returned the corresponding key. - * @returns {Promise} a promise, if no callback is passed - * @example - * - * async.groupBy(['userId1', 'userId2', 'userId3'], function(userId, callback) { - * db.findById(userId, function(err, user) { - * if (err) return callback(err); - * return callback(null, user.age); - * }); - * }, function(err, result) { - * // result is object containing the userIds grouped by age - * // e.g. { 30: ['userId1', 'userId3'], 42: ['userId2']}; - * }); - */ -function groupBy (coll, iteratee, callback) { - return groupByLimit$1(coll, Infinity, iteratee, callback) -} - -/** - * The same as [`groupBy`]{@link module:Collections.groupBy} but runs only a single async operation at a time. - * - * @name groupBySeries - * @static - * @memberOf module:Collections - * @method - * @see [async.groupBy]{@link module:Collections.groupBy} - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async function to apply to each item in - * `coll`. - * The iteratee should complete with a `key` to group the value under. - * Invoked with (value, callback). - * @param {Function} [callback] - A callback which is called when all `iteratee` - * functions have finished, or an error occurs. Result is an `Object` whoses - * properties are arrays of values which returned the corresponding key. - * @returns {Promise} a promise, if no callback is passed - */ -function groupBySeries (coll, iteratee, callback) { - return groupByLimit$1(coll, 1, iteratee, callback) -} - -/** - * Logs the result of an `async` function to the `console`. Only works in - * Node.js or in browsers that support `console.log` and `console.error` (such - * as FF and Chrome). If multiple arguments are returned from the async - * function, `console.log` is called on each argument in order. - * - * @name log - * @static - * @memberOf module:Utils - * @method - * @category Util - * @param {AsyncFunction} function - The function you want to eventually apply - * all arguments to. - * @param {...*} arguments... - Any number of arguments to apply to the function. - * @example - * - * // in a module - * var hello = function(name, callback) { - * setTimeout(function() { - * callback(null, 'hello ' + name); - * }, 1000); - * }; - * - * // in the node repl - * node> async.log(hello, 'world'); - * 'hello world' - */ -var log = consoleFunc('log'); - -/** - * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a - * time. - * - * @name mapValuesLimit - * @static - * @memberOf module:Collections - * @method - * @see [async.mapValues]{@link module:Collections.mapValues} - * @category Collection - * @param {Object} obj - A collection to iterate over. - * @param {number} limit - The maximum number of async operations at a time. - * @param {AsyncFunction} iteratee - A function to apply to each value and key - * in `coll`. - * The iteratee should complete with the transformed value as its result. - * Invoked with (value, key, callback). - * @param {Function} [callback] - A callback which is called when all `iteratee` - * functions have finished, or an error occurs. `result` is a new object consisting - * of each key from `obj`, with each transformed value on the right-hand side. - * Invoked with (err, result). - * @returns {Promise} a promise, if no callback is passed - */ -function mapValuesLimit(obj, limit, iteratee, callback) { - callback = once(callback); - var newObj = {}; - var _iteratee = wrapAsync(iteratee); - return eachOfLimit(limit)(obj, (val, key, next) => { - _iteratee(val, key, (err, result) => { - if (err) return next(err); - newObj[key] = result; - next(err); - }); - }, err => callback(err, newObj)); -} - -var mapValuesLimit$1 = awaitify(mapValuesLimit, 4); - -/** - * A relative of [`map`]{@link module:Collections.map}, designed for use with objects. - * - * Produces a new Object by mapping each value of `obj` through the `iteratee` - * function. The `iteratee` is called each `value` and `key` from `obj` and a - * callback for when it has finished processing. Each of these callbacks takes - * two arguments: an `error`, and the transformed item from `obj`. If `iteratee` - * passes an error to its callback, the main `callback` (for the `mapValues` - * function) is immediately called with the error. - * - * Note, the order of the keys in the result is not guaranteed. The keys will - * be roughly in the order they complete, (but this is very engine-specific) - * - * @name mapValues - * @static - * @memberOf module:Collections - * @method - * @category Collection - * @param {Object} obj - A collection to iterate over. - * @param {AsyncFunction} iteratee - A function to apply to each value and key - * in `coll`. - * The iteratee should complete with the transformed value as its result. - * Invoked with (value, key, callback). - * @param {Function} [callback] - A callback which is called when all `iteratee` - * functions have finished, or an error occurs. `result` is a new object consisting - * of each key from `obj`, with each transformed value on the right-hand side. - * Invoked with (err, result). - * @returns {Promise} a promise, if no callback is passed - * @example - * - * async.mapValues({ - * f1: 'file1', - * f2: 'file2', - * f3: 'file3' - * }, function (file, key, callback) { - * fs.stat(file, callback); - * }, function(err, result) { - * // result is now a map of stats for each file, e.g. - * // { - * // f1: [stats for file1], - * // f2: [stats for file2], - * // f3: [stats for file3] - * // } - * }); - */ -function mapValues(obj, iteratee, callback) { - return mapValuesLimit$1(obj, Infinity, iteratee, callback) -} - -/** - * The same as [`mapValues`]{@link module:Collections.mapValues} but runs only a single async operation at a time. - * - * @name mapValuesSeries - * @static - * @memberOf module:Collections - * @method - * @see [async.mapValues]{@link module:Collections.mapValues} - * @category Collection - * @param {Object} obj - A collection to iterate over. - * @param {AsyncFunction} iteratee - A function to apply to each value and key - * in `coll`. - * The iteratee should complete with the transformed value as its result. - * Invoked with (value, key, callback). - * @param {Function} [callback] - A callback which is called when all `iteratee` - * functions have finished, or an error occurs. `result` is a new object consisting - * of each key from `obj`, with each transformed value on the right-hand side. - * Invoked with (err, result). - * @returns {Promise} a promise, if no callback is passed - */ -function mapValuesSeries(obj, iteratee, callback) { - return mapValuesLimit$1(obj, 1, iteratee, callback) -} - -/** - * Caches the results of an async function. When creating a hash to store - * function results against, the callback is omitted from the hash and an - * optional hash function can be used. - * - * **Note: if the async function errs, the result will not be cached and - * subsequent calls will call the wrapped function.** - * - * If no hash function is specified, the first argument is used as a hash key, - * which may work reasonably if it is a string or a data type that converts to a - * distinct string. Note that objects and arrays will not behave reasonably. - * Neither will cases where the other arguments are significant. In such cases, - * specify your own hash function. - * - * The cache of results is exposed as the `memo` property of the function - * returned by `memoize`. - * - * @name memoize - * @static - * @memberOf module:Utils - * @method - * @category Util - * @param {AsyncFunction} fn - The async function to proxy and cache results from. - * @param {Function} hasher - An optional function for generating a custom hash - * for storing results. It has all the arguments applied to it apart from the - * callback, and must be synchronous. - * @returns {AsyncFunction} a memoized version of `fn` - * @example - * - * var slow_fn = function(name, callback) { - * // do something - * callback(null, result); - * }; - * var fn = async.memoize(slow_fn); - * - * // fn can now be used as if it were slow_fn - * fn('some name', function() { - * // callback - * }); - */ -function memoize(fn, hasher = v => v) { - var memo = Object.create(null); - var queues = Object.create(null); - var _fn = wrapAsync(fn); - var memoized = initialParams((args, callback) => { - var key = hasher(...args); - if (key in memo) { - setImmediate$1(() => callback(null, ...memo[key])); - } else if (key in queues) { - queues[key].push(callback); - } else { - queues[key] = [callback]; - _fn(...args, (err, ...resultArgs) => { - // #1465 don't memoize if an error occurred - if (!err) { - memo[key] = resultArgs; - } - var q = queues[key]; - delete queues[key]; - for (var i = 0, l = q.length; i < l; i++) { - q[i](err, ...resultArgs); - } - }); - } - }); - memoized.memo = memo; - memoized.unmemoized = fn; - return memoized; -} - -/** - * Calls `callback` on a later loop around the event loop. In Node.js this just - * calls `process.nextTick`. In the browser it will use `setImmediate` if - * available, otherwise `setTimeout(callback, 0)`, which means other higher - * priority events may precede the execution of `callback`. - * - * This is used internally for browser-compatibility purposes. - * - * @name nextTick - * @static - * @memberOf module:Utils - * @method - * @see [async.setImmediate]{@link module:Utils.setImmediate} - * @category Util - * @param {Function} callback - The function to call on a later loop around - * the event loop. Invoked with (args...). - * @param {...*} args... - any number of additional arguments to pass to the - * callback on the next tick. - * @example - * - * var call_order = []; - * async.nextTick(function() { - * call_order.push('two'); - * // call_order now equals ['one','two'] - * }); - * call_order.push('one'); - * - * async.setImmediate(function (a, b, c) { - * // a, b, and c equal 1, 2, and 3 - * }, 1, 2, 3); - */ -var _defer$1; - -if (hasNextTick) { - _defer$1 = process.nextTick; -} else if (hasSetImmediate) { - _defer$1 = setImmediate; -} else { - _defer$1 = fallback; -} - -var nextTick = wrap(_defer$1); - -var _parallel = awaitify((eachfn, tasks, callback) => { - var results = isArrayLike(tasks) ? [] : {}; - - eachfn(tasks, (task, key, taskCb) => { - wrapAsync(task)((err, ...result) => { - if (result.length < 2) { - [result] = result; - } - results[key] = result; - taskCb(err); - }); - }, err => callback(err, results)); -}, 3); - -/** - * Run the `tasks` collection of functions in parallel, without waiting until - * the previous function has completed. If any of the functions pass an error to - * its callback, the main `callback` is immediately called with the value of the - * error. Once the `tasks` have completed, the results are passed to the final - * `callback` as an array. - * - * **Note:** `parallel` is about kicking-off I/O tasks in parallel, not about - * parallel execution of code. If your tasks do not use any timers or perform - * any I/O, they will actually be executed in series. Any synchronous setup - * sections for each task will happen one after the other. JavaScript remains - * single-threaded. - * - * **Hint:** Use [`reflect`]{@link module:Utils.reflect} to continue the - * execution of other tasks when a task fails. - * - * It is also possible to use an object instead of an array. Each property will - * be run as a function and the results will be passed to the final `callback` - * as an object instead of an array. This can be a more readable way of handling - * results from {@link async.parallel}. - * - * @name parallel - * @static - * @memberOf module:ControlFlow - * @method - * @category Control Flow - * @param {Array|Iterable|AsyncIterable|Object} tasks - A collection of - * [async functions]{@link AsyncFunction} to run. - * Each async function can complete with any number of optional `result` values. - * @param {Function} [callback] - An optional callback to run once all the - * functions have completed successfully. This function gets a results array - * (or object) containing all the result arguments passed to the task callbacks. - * Invoked with (err, results). - * @returns {Promise} a promise, if a callback is not passed - * - * @example - * async.parallel([ - * function(callback) { - * setTimeout(function() { - * callback(null, 'one'); - * }, 200); - * }, - * function(callback) { - * setTimeout(function() { - * callback(null, 'two'); - * }, 100); - * } - * ], - * // optional callback - * function(err, results) { - * // the results array will equal ['one','two'] even though - * // the second function had a shorter timeout. - * }); - * - * // an example using an object instead of an array - * async.parallel({ - * one: function(callback) { - * setTimeout(function() { - * callback(null, 1); - * }, 200); - * }, - * two: function(callback) { - * setTimeout(function() { - * callback(null, 2); - * }, 100); - * } - * }, function(err, results) { - * // results is now equals to: {one: 1, two: 2} - * }); - */ -function parallel(tasks, callback) { - return _parallel(eachOf$1, tasks, callback); -} - -/** - * The same as [`parallel`]{@link module:ControlFlow.parallel} but runs a maximum of `limit` async operations at a - * time. - * - * @name parallelLimit - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.parallel]{@link module:ControlFlow.parallel} - * @category Control Flow - * @param {Array|Iterable|AsyncIterable|Object} tasks - A collection of - * [async functions]{@link AsyncFunction} to run. - * Each async function can complete with any number of optional `result` values. - * @param {number} limit - The maximum number of async operations at a time. - * @param {Function} [callback] - An optional callback to run once all the - * functions have completed successfully. This function gets a results array - * (or object) containing all the result arguments passed to the task callbacks. - * Invoked with (err, results). - * @returns {Promise} a promise, if a callback is not passed - */ -function parallelLimit(tasks, limit, callback) { - return _parallel(eachOfLimit(limit), tasks, callback); -} - -/** - * A queue of tasks for the worker function to complete. - * @typedef {Iterable} QueueObject - * @memberOf module:ControlFlow - * @property {Function} length - a function returning the number of items - * waiting to be processed. Invoke with `queue.length()`. - * @property {boolean} started - a boolean indicating whether or not any - * items have been pushed and processed by the queue. - * @property {Function} running - a function returning the number of items - * currently being processed. Invoke with `queue.running()`. - * @property {Function} workersList - a function returning the array of items - * currently being processed. Invoke with `queue.workersList()`. - * @property {Function} idle - a function returning false if there are items - * waiting or being processed, or true if not. Invoke with `queue.idle()`. - * @property {number} concurrency - an integer for determining how many `worker` - * functions should be run in parallel. This property can be changed after a - * `queue` is created to alter the concurrency on-the-fly. - * @property {number} payload - an integer that specifies how many items are - * passed to the worker function at a time. only applies if this is a - * [cargo]{@link module:ControlFlow.cargo} object - * @property {AsyncFunction} push - add a new task to the `queue`. Calls `callback` - * once the `worker` has finished processing the task. Instead of a single task, - * a `tasks` array can be submitted. The respective callback is used for every - * task in the list. Invoke with `queue.push(task, [callback])`, - * @property {AsyncFunction} unshift - add a new task to the front of the `queue`. - * Invoke with `queue.unshift(task, [callback])`. - * @property {AsyncFunction} pushAsync - the same as `q.push`, except this returns - * a promise that rejects if an error occurs. - * @property {AsyncFunction} unshirtAsync - the same as `q.unshift`, except this returns - * a promise that rejects if an error occurs. - * @property {Function} remove - remove items from the queue that match a test - * function. The test function will be passed an object with a `data` property, - * and a `priority` property, if this is a - * [priorityQueue]{@link module:ControlFlow.priorityQueue} object. - * Invoked with `queue.remove(testFn)`, where `testFn` is of the form - * `function ({data, priority}) {}` and returns a Boolean. - * @property {Function} saturated - a function that sets a callback that is - * called when the number of running workers hits the `concurrency` limit, and - * further tasks will be queued. If the callback is omitted, `q.saturated()` - * returns a promise for the next occurrence. - * @property {Function} unsaturated - a function that sets a callback that is - * called when the number of running workers is less than the `concurrency` & - * `buffer` limits, and further tasks will not be queued. If the callback is - * omitted, `q.unsaturated()` returns a promise for the next occurrence. - * @property {number} buffer - A minimum threshold buffer in order to say that - * the `queue` is `unsaturated`. - * @property {Function} empty - a function that sets a callback that is called - * when the last item from the `queue` is given to a `worker`. If the callback - * is omitted, `q.empty()` returns a promise for the next occurrence. - * @property {Function} drain - a function that sets a callback that is called - * when the last item from the `queue` has returned from the `worker`. If the - * callback is omitted, `q.drain()` returns a promise for the next occurrence. - * @property {Function} error - a function that sets a callback that is called - * when a task errors. Has the signature `function(error, task)`. If the - * callback is omitted, `error()` returns a promise that rejects on the next - * error. - * @property {boolean} paused - a boolean for determining whether the queue is - * in a paused state. - * @property {Function} pause - a function that pauses the processing of tasks - * until `resume()` is called. Invoke with `queue.pause()`. - * @property {Function} resume - a function that resumes the processing of - * queued tasks when the queue is paused. Invoke with `queue.resume()`. - * @property {Function} kill - a function that removes the `drain` callback and - * empties remaining tasks from the queue forcing it to go idle. No more tasks - * should be pushed to the queue after calling this function. Invoke with `queue.kill()`. - * - * @example - * const q = aync.queue(worker, 2) - * q.push(item1) - * q.push(item2) - * q.push(item3) - * // queues are iterable, spread into an array to inspect - * const items = [...q] // [item1, item2, item3] - * // or use for of - * for (let item of q) { - * console.log(item) - * } - * - * q.drain(() => { - * console.log('all done') - * }) - * // or - * await q.drain() - */ - -/** - * Creates a `queue` object with the specified `concurrency`. Tasks added to the - * `queue` are processed in parallel (up to the `concurrency` limit). If all - * `worker`s are in progress, the task is queued until one becomes available. - * Once a `worker` completes a `task`, that `task`'s callback is called. - * - * @name queue - * @static - * @memberOf module:ControlFlow - * @method - * @category Control Flow - * @param {AsyncFunction} worker - An async function for processing a queued task. - * If you want to handle errors from an individual task, pass a callback to - * `q.push()`. Invoked with (task, callback). - * @param {number} [concurrency=1] - An `integer` for determining how many - * `worker` functions should be run in parallel. If omitted, the concurrency - * defaults to `1`. If the concurrency is `0`, an error is thrown. - * @returns {module:ControlFlow.QueueObject} A queue object to manage the tasks. Callbacks can be - * attached as certain properties to listen for specific events during the - * lifecycle of the queue. - * @example - * - * // create a queue object with concurrency 2 - * var q = async.queue(function(task, callback) { - * console.log('hello ' + task.name); - * callback(); - * }, 2); - * - * // assign a callback - * q.drain(function() { - * console.log('all items have been processed'); - * }); - * // or await the end - * await q.drain() - * - * // assign an error callback - * q.error(function(err, task) { - * console.error('task experienced an error'); - * }); - * - * // add some items to the queue - * q.push({name: 'foo'}, function(err) { - * console.log('finished processing foo'); - * }); - * // callback is optional - * q.push({name: 'bar'}); - * - * // add some items to the queue (batch-wise) - * q.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function(err) { - * console.log('finished processing item'); - * }); - * - * // add some items to the front of the queue - * q.unshift({name: 'bar'}, function (err) { - * console.log('finished processing bar'); - * }); - */ -function queue$1 (worker, concurrency) { - var _worker = wrapAsync(worker); - return queue((items, cb) => { - _worker(items[0], cb); - }, concurrency, 1); -} - -// Binary min-heap implementation used for priority queue. -// Implementation is stable, i.e. push time is considered for equal priorities -class Heap { - constructor() { - this.heap = []; - this.pushCount = Number.MIN_SAFE_INTEGER; - } - - get length() { - return this.heap.length; - } - - empty () { - this.heap = []; - return this; - } - - percUp(index) { - let p; - - while (index > 0 && smaller(this.heap[index], this.heap[p=parent(index)])) { - let t = this.heap[index]; - this.heap[index] = this.heap[p]; - this.heap[p] = t; - - index = p; - } - } - - percDown(index) { - let l; - - while ((l=leftChi(index)) < this.heap.length) { - if (l+1 < this.heap.length && smaller(this.heap[l+1], this.heap[l])) { - l = l+1; - } - - if (smaller(this.heap[index], this.heap[l])) { - break; - } - - let t = this.heap[index]; - this.heap[index] = this.heap[l]; - this.heap[l] = t; - - index = l; - } - } - - push(node) { - node.pushCount = ++this.pushCount; - this.heap.push(node); - this.percUp(this.heap.length-1); - } - - unshift(node) { - return this.heap.push(node); - } - - shift() { - let [top] = this.heap; - - this.heap[0] = this.heap[this.heap.length-1]; - this.heap.pop(); - this.percDown(0); - - return top; - } - - toArray() { - return [...this]; - } - - *[Symbol.iterator] () { - for (let i = 0; i < this.heap.length; i++) { - yield this.heap[i].data; - } - } - - remove (testFn) { - let j = 0; - for (let i = 0; i < this.heap.length; i++) { - if (!testFn(this.heap[i])) { - this.heap[j] = this.heap[i]; - j++; - } - } - - this.heap.splice(j); - - for (let i = parent(this.heap.length-1); i >= 0; i--) { - this.percDown(i); - } - - return this; - } -} - -function leftChi(i) { - return (i<<1)+1; -} - -function parent(i) { - return ((i+1)>>1)-1; -} - -function smaller(x, y) { - if (x.priority !== y.priority) { - return x.priority < y.priority; - } - else { - return x.pushCount < y.pushCount; - } -} - -/** - * The same as [async.queue]{@link module:ControlFlow.queue} only tasks are assigned a priority and - * completed in ascending priority order. - * - * @name priorityQueue - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.queue]{@link module:ControlFlow.queue} - * @category Control Flow - * @param {AsyncFunction} worker - An async function for processing a queued task. - * If you want to handle errors from an individual task, pass a callback to - * `q.push()`. - * Invoked with (task, callback). - * @param {number} concurrency - An `integer` for determining how many `worker` - * functions should be run in parallel. If omitted, the concurrency defaults to - * `1`. If the concurrency is `0`, an error is thrown. - * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are two - * differences between `queue` and `priorityQueue` objects: - * * `push(task, priority, [callback])` - `priority` should be a number. If an - * array of `tasks` is given, all tasks will be assigned the same priority. - * * The `unshift` method was removed. - */ -function priorityQueue(worker, concurrency) { - // Start with a normal queue - var q = queue$1(worker, concurrency); - - q._tasks = new Heap(); - - // Override push to accept second parameter representing priority - q.push = function(data, priority = 0, callback = () => {}) { - if (typeof callback !== 'function') { - throw new Error('task callback must be a function'); - } - q.started = true; - if (!Array.isArray(data)) { - data = [data]; - } - if (data.length === 0 && q.idle()) { - // call drain immediately if there are no tasks - return setImmediate$1(() => q.drain()); - } - - for (var i = 0, l = data.length; i < l; i++) { - var item = { - data: data[i], - priority, - callback - }; - - q._tasks.push(item); - } - - setImmediate$1(q.process); - }; - - // Remove unshift function - delete q.unshift; - - return q; -} - -/** - * Runs the `tasks` array of functions in parallel, without waiting until the - * previous function has completed. Once any of the `tasks` complete or pass an - * error to its callback, the main `callback` is immediately called. It's - * equivalent to `Promise.race()`. - * - * @name race - * @static - * @memberOf module:ControlFlow - * @method - * @category Control Flow - * @param {Array} tasks - An array containing [async functions]{@link AsyncFunction} - * to run. Each function can complete with an optional `result` value. - * @param {Function} callback - A callback to run once any of the functions have - * completed. This function gets an error or result from the first function that - * completed. Invoked with (err, result). - * @returns undefined - * @example - * - * async.race([ - * function(callback) { - * setTimeout(function() { - * callback(null, 'one'); - * }, 200); - * }, - * function(callback) { - * setTimeout(function() { - * callback(null, 'two'); - * }, 100); - * } - * ], - * // main callback - * function(err, result) { - * // the result will be equal to 'two' as it finishes earlier - * }); - */ -function race(tasks, callback) { - callback = once(callback); - if (!Array.isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions')); - if (!tasks.length) return callback(); - for (var i = 0, l = tasks.length; i < l; i++) { - wrapAsync(tasks[i])(callback); - } -} - -var race$1 = awaitify(race, 2); - -/** - * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order. - * - * @name reduceRight - * @static - * @memberOf module:Collections - * @method - * @see [async.reduce]{@link module:Collections.reduce} - * @alias foldr - * @category Collection - * @param {Array} array - A collection to iterate over. - * @param {*} memo - The initial state of the reduction. - * @param {AsyncFunction} iteratee - A function applied to each item in the - * array to produce the next step in the reduction. - * The `iteratee` should complete with the next state of the reduction. - * If the iteratee complete with an error, the reduction is stopped and the - * main `callback` is immediately called with the error. - * Invoked with (memo, item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished. Result is the reduced value. Invoked with - * (err, result). - * @returns {Promise} a promise, if no callback is passed - */ -function reduceRight (array, memo, iteratee, callback) { - var reversed = [...array].reverse(); - return reduce$1(reversed, memo, iteratee, callback); -} - -/** - * Wraps the async function in another function that always completes with a - * result object, even when it errors. - * - * The result object has either the property `error` or `value`. - * - * @name reflect - * @static - * @memberOf module:Utils - * @method - * @category Util - * @param {AsyncFunction} fn - The async function you want to wrap - * @returns {Function} - A function that always passes null to it's callback as - * the error. The second argument to the callback will be an `object` with - * either an `error` or a `value` property. - * @example - * - * async.parallel([ - * async.reflect(function(callback) { - * // do some stuff ... - * callback(null, 'one'); - * }), - * async.reflect(function(callback) { - * // do some more stuff but error ... - * callback('bad stuff happened'); - * }), - * async.reflect(function(callback) { - * // do some more stuff ... - * callback(null, 'two'); - * }) - * ], - * // optional callback - * function(err, results) { - * // values - * // results[0].value = 'one' - * // results[1].error = 'bad stuff happened' - * // results[2].value = 'two' - * }); - */ -function reflect(fn) { - var _fn = wrapAsync(fn); - return initialParams(function reflectOn(args, reflectCallback) { - args.push((error, ...cbArgs) => { - let retVal = {}; - if (error) { - retVal.error = error; - } - if (cbArgs.length > 0){ - var value = cbArgs; - if (cbArgs.length <= 1) { - [value] = cbArgs; - } - retVal.value = value; - } - reflectCallback(null, retVal); - }); - - return _fn.apply(this, args); - }); -} - -/** - * A helper function that wraps an array or an object of functions with `reflect`. - * - * @name reflectAll - * @static - * @memberOf module:Utils - * @method - * @see [async.reflect]{@link module:Utils.reflect} - * @category Util - * @param {Array|Object|Iterable} tasks - The collection of - * [async functions]{@link AsyncFunction} to wrap in `async.reflect`. - * @returns {Array} Returns an array of async functions, each wrapped in - * `async.reflect` - * @example - * - * let tasks = [ - * function(callback) { - * setTimeout(function() { - * callback(null, 'one'); - * }, 200); - * }, - * function(callback) { - * // do some more stuff but error ... - * callback(new Error('bad stuff happened')); - * }, - * function(callback) { - * setTimeout(function() { - * callback(null, 'two'); - * }, 100); - * } - * ]; - * - * async.parallel(async.reflectAll(tasks), - * // optional callback - * function(err, results) { - * // values - * // results[0].value = 'one' - * // results[1].error = Error('bad stuff happened') - * // results[2].value = 'two' - * }); - * - * // an example using an object instead of an array - * let tasks = { - * one: function(callback) { - * setTimeout(function() { - * callback(null, 'one'); - * }, 200); - * }, - * two: function(callback) { - * callback('two'); - * }, - * three: function(callback) { - * setTimeout(function() { - * callback(null, 'three'); - * }, 100); - * } - * }; - * - * async.parallel(async.reflectAll(tasks), - * // optional callback - * function(err, results) { - * // values - * // results.one.value = 'one' - * // results.two.error = 'two' - * // results.three.value = 'three' - * }); - */ -function reflectAll(tasks) { - var results; - if (Array.isArray(tasks)) { - results = tasks.map(reflect); - } else { - results = {}; - Object.keys(tasks).forEach(key => { - results[key] = reflect.call(this, tasks[key]); - }); - } - return results; -} - -function reject(eachfn, arr, _iteratee, callback) { - const iteratee = wrapAsync(_iteratee); - return _filter(eachfn, arr, (value, cb) => { - iteratee(value, (err, v) => { - cb(err, !v); - }); - }, callback); -} - -/** - * The opposite of [`filter`]{@link module:Collections.filter}. Removes values that pass an `async` truth test. - * - * @name reject - * @static - * @memberOf module:Collections - * @method - * @see [async.filter]{@link module:Collections.filter} - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {Function} iteratee - An async truth test to apply to each item in - * `coll`. - * The should complete with a boolean value as its `result`. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished. Invoked with (err, results). - * @returns {Promise} a promise, if no callback is passed - * @example - * - * async.reject(['file1','file2','file3'], function(filePath, callback) { - * fs.access(filePath, function(err) { - * callback(null, !err) - * }); - * }, function(err, results) { - * // results now equals an array of missing files - * createFiles(results); - * }); - */ -function reject$1 (coll, iteratee, callback) { - return reject(eachOf$1, coll, iteratee, callback) -} -var reject$2 = awaitify(reject$1, 3); - -/** - * The same as [`reject`]{@link module:Collections.reject} but runs a maximum of `limit` async operations at a - * time. - * - * @name rejectLimit - * @static - * @memberOf module:Collections - * @method - * @see [async.reject]{@link module:Collections.reject} - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {number} limit - The maximum number of async operations at a time. - * @param {Function} iteratee - An async truth test to apply to each item in - * `coll`. - * The should complete with a boolean value as its `result`. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished. Invoked with (err, results). - * @returns {Promise} a promise, if no callback is passed - */ -function rejectLimit (coll, limit, iteratee, callback) { - return reject(eachOfLimit(limit), coll, iteratee, callback) -} -var rejectLimit$1 = awaitify(rejectLimit, 4); - -/** - * The same as [`reject`]{@link module:Collections.reject} but runs only a single async operation at a time. - * - * @name rejectSeries - * @static - * @memberOf module:Collections - * @method - * @see [async.reject]{@link module:Collections.reject} - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {Function} iteratee - An async truth test to apply to each item in - * `coll`. - * The should complete with a boolean value as its `result`. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished. Invoked with (err, results). - * @returns {Promise} a promise, if no callback is passed - */ -function rejectSeries (coll, iteratee, callback) { - return reject(eachOfSeries$1, coll, iteratee, callback) -} -var rejectSeries$1 = awaitify(rejectSeries, 3); - -function constant$1(value) { - return function () { - return value; - } -} - -/** - * Attempts to get a successful response from `task` no more than `times` times - * before returning an error. If the task is successful, the `callback` will be - * passed the result of the successful task. If all attempts fail, the callback - * will be passed the error and result (if any) of the final attempt. - * - * @name retry - * @static - * @memberOf module:ControlFlow - * @method - * @category Control Flow - * @see [async.retryable]{@link module:ControlFlow.retryable} - * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - Can be either an - * object with `times` and `interval` or a number. - * * `times` - The number of attempts to make before giving up. The default - * is `5`. - * * `interval` - The time to wait between retries, in milliseconds. The - * default is `0`. The interval may also be specified as a function of the - * retry count (see example). - * * `errorFilter` - An optional synchronous function that is invoked on - * erroneous result. If it returns `true` the retry attempts will continue; - * if the function returns `false` the retry flow is aborted with the current - * attempt's error and result being returned to the final callback. - * Invoked with (err). - * * If `opts` is a number, the number specifies the number of times to retry, - * with the default interval of `0`. - * @param {AsyncFunction} task - An async function to retry. - * Invoked with (callback). - * @param {Function} [callback] - An optional callback which is called when the - * task has succeeded, or after the final failed attempt. It receives the `err` - * and `result` arguments of the last attempt at completing the `task`. Invoked - * with (err, results). - * @returns {Promise} a promise if no callback provided - * - * @example - * - * // The `retry` function can be used as a stand-alone control flow by passing - * // a callback, as shown below: - * - * // try calling apiMethod 3 times - * async.retry(3, apiMethod, function(err, result) { - * // do something with the result - * }); - * - * // try calling apiMethod 3 times, waiting 200 ms between each retry - * async.retry({times: 3, interval: 200}, apiMethod, function(err, result) { - * // do something with the result - * }); - * - * // try calling apiMethod 10 times with exponential backoff - * // (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds) - * async.retry({ - * times: 10, - * interval: function(retryCount) { - * return 50 * Math.pow(2, retryCount); - * } - * }, apiMethod, function(err, result) { - * // do something with the result - * }); - * - * // try calling apiMethod the default 5 times no delay between each retry - * async.retry(apiMethod, function(err, result) { - * // do something with the result - * }); - * - * // try calling apiMethod only when error condition satisfies, all other - * // errors will abort the retry control flow and return to final callback - * async.retry({ - * errorFilter: function(err) { - * return err.message === 'Temporary error'; // only retry on a specific error - * } - * }, apiMethod, function(err, result) { - * // do something with the result - * }); - * - * // to retry individual methods that are not as reliable within other - * // control flow functions, use the `retryable` wrapper: - * async.auto({ - * users: api.getUsers.bind(api), - * payments: async.retryable(3, api.getPayments.bind(api)) - * }, function(err, results) { - * // do something with the results - * }); - * - */ -const DEFAULT_TIMES = 5; -const DEFAULT_INTERVAL = 0; - -function retry(opts, task, callback) { - var options = { - times: DEFAULT_TIMES, - intervalFunc: constant$1(DEFAULT_INTERVAL) - }; - - if (arguments.length < 3 && typeof opts === 'function') { - callback = task || promiseCallback(); - task = opts; - } else { - parseTimes(options, opts); - callback = callback || promiseCallback(); - } - - if (typeof task !== 'function') { - throw new Error("Invalid arguments for async.retry"); - } - - var _task = wrapAsync(task); - - var attempt = 1; - function retryAttempt() { - _task((err, ...args) => { - if (err === false) return - if (err && attempt++ < options.times && - (typeof options.errorFilter != 'function' || - options.errorFilter(err))) { - setTimeout(retryAttempt, options.intervalFunc(attempt - 1)); - } else { - callback(err, ...args); - } - }); - } - - retryAttempt(); - return callback[PROMISE_SYMBOL] -} - -function parseTimes(acc, t) { - if (typeof t === 'object') { - acc.times = +t.times || DEFAULT_TIMES; - - acc.intervalFunc = typeof t.interval === 'function' ? - t.interval : - constant$1(+t.interval || DEFAULT_INTERVAL); - - acc.errorFilter = t.errorFilter; - } else if (typeof t === 'number' || typeof t === 'string') { - acc.times = +t || DEFAULT_TIMES; - } else { - throw new Error("Invalid arguments for async.retry"); - } -} - -/** - * A close relative of [`retry`]{@link module:ControlFlow.retry}. This method - * wraps a task and makes it retryable, rather than immediately calling it - * with retries. - * - * @name retryable - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.retry]{@link module:ControlFlow.retry} - * @category Control Flow - * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - optional - * options, exactly the same as from `retry`, except for a `opts.arity` that - * is the arity of the `task` function, defaulting to `task.length` - * @param {AsyncFunction} task - the asynchronous function to wrap. - * This function will be passed any arguments passed to the returned wrapper. - * Invoked with (...args, callback). - * @returns {AsyncFunction} The wrapped function, which when invoked, will - * retry on an error, based on the parameters specified in `opts`. - * This function will accept the same parameters as `task`. - * @example - * - * async.auto({ - * dep1: async.retryable(3, getFromFlakyService), - * process: ["dep1", async.retryable(3, function (results, cb) { - * maybeProcessData(results.dep1, cb); - * })] - * }, callback); - */ -function retryable (opts, task) { - if (!task) { - task = opts; - opts = null; - } - let arity = (opts && opts.arity) || task.length; - if (isAsync(task)) { - arity += 1; - } - var _task = wrapAsync(task); - return initialParams((args, callback) => { - if (args.length < arity - 1 || callback == null) { - args.push(callback); - callback = promiseCallback(); - } - function taskFn(cb) { - _task(...args, cb); - } - - if (opts) retry(opts, taskFn, callback); - else retry(taskFn, callback); - - return callback[PROMISE_SYMBOL] - }); -} - -/** - * Run the functions in the `tasks` collection in series, each one running once - * the previous function has completed. If any functions in the series pass an - * error to its callback, no more functions are run, and `callback` is - * immediately called with the value of the error. Otherwise, `callback` - * receives an array of results when `tasks` have completed. - * - * It is also possible to use an object instead of an array. Each property will - * be run as a function, and the results will be passed to the final `callback` - * as an object instead of an array. This can be a more readable way of handling - * results from {@link async.series}. - * - * **Note** that while many implementations preserve the order of object - * properties, the [ECMAScript Language Specification](http://www.ecma-international.org/ecma-262/5.1/#sec-8.6) - * explicitly states that - * - * > The mechanics and order of enumerating the properties is not specified. - * - * So if you rely on the order in which your series of functions are executed, - * and want this to work on all platforms, consider using an array. - * - * @name series - * @static - * @memberOf module:ControlFlow - * @method - * @category Control Flow - * @param {Array|Iterable|AsyncIterable|Object} tasks - A collection containing - * [async functions]{@link AsyncFunction} to run in series. - * Each function can complete with any number of optional `result` values. - * @param {Function} [callback] - An optional callback to run once all the - * functions have completed. This function gets a results array (or object) - * containing all the result arguments passed to the `task` callbacks. Invoked - * with (err, result). - * @return {Promise} a promise, if no callback is passed - * @example - * async.series([ - * function(callback) { - * // do some stuff ... - * callback(null, 'one'); - * }, - * function(callback) { - * // do some more stuff ... - * callback(null, 'two'); - * } - * ], - * // optional callback - * function(err, results) { - * // results is now equal to ['one', 'two'] - * }); - * - * async.series({ - * one: function(callback) { - * setTimeout(function() { - * callback(null, 1); - * }, 200); - * }, - * two: function(callback){ - * setTimeout(function() { - * callback(null, 2); - * }, 100); - * } - * }, function(err, results) { - * // results is now equal to: {one: 1, two: 2} - * }); - */ -function series(tasks, callback) { - return _parallel(eachOfSeries$1, tasks, callback); -} - -/** - * Returns `true` if at least one element in the `coll` satisfies an async test. - * If any iteratee call returns `true`, the main `callback` is immediately - * called. - * - * @name some - * @static - * @memberOf module:Collections - * @method - * @alias any - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async truth test to apply to each item - * in the collections in parallel. - * The iteratee should complete with a boolean `result` value. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon as any - * iteratee returns `true`, or after all the iteratee functions have finished. - * Result will be either `true` or `false` depending on the values of the async - * tests. Invoked with (err, result). - * @returns {Promise} a promise, if no callback provided - * @example - * - * async.some(['file1','file2','file3'], function(filePath, callback) { - * fs.access(filePath, function(err) { - * callback(null, !err) - * }); - * }, function(err, result) { - * // if result is true then at least one of the files exists - * }); - */ -function some(coll, iteratee, callback) { - return _createTester(Boolean, res => res)(eachOf$1, coll, iteratee, callback) -} -var some$1 = awaitify(some, 3); - -/** - * The same as [`some`]{@link module:Collections.some} but runs a maximum of `limit` async operations at a time. - * - * @name someLimit - * @static - * @memberOf module:Collections - * @method - * @see [async.some]{@link module:Collections.some} - * @alias anyLimit - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {number} limit - The maximum number of async operations at a time. - * @param {AsyncFunction} iteratee - An async truth test to apply to each item - * in the collections in parallel. - * The iteratee should complete with a boolean `result` value. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon as any - * iteratee returns `true`, or after all the iteratee functions have finished. - * Result will be either `true` or `false` depending on the values of the async - * tests. Invoked with (err, result). - * @returns {Promise} a promise, if no callback provided - */ -function someLimit(coll, limit, iteratee, callback) { - return _createTester(Boolean, res => res)(eachOfLimit(limit), coll, iteratee, callback) -} -var someLimit$1 = awaitify(someLimit, 4); - -/** - * The same as [`some`]{@link module:Collections.some} but runs only a single async operation at a time. - * - * @name someSeries - * @static - * @memberOf module:Collections - * @method - * @see [async.some]{@link module:Collections.some} - * @alias anySeries - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async truth test to apply to each item - * in the collections in series. - * The iteratee should complete with a boolean `result` value. - * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon as any - * iteratee returns `true`, or after all the iteratee functions have finished. - * Result will be either `true` or `false` depending on the values of the async - * tests. Invoked with (err, result). - * @returns {Promise} a promise, if no callback provided - */ -function someSeries(coll, iteratee, callback) { - return _createTester(Boolean, res => res)(eachOfSeries$1, coll, iteratee, callback) -} -var someSeries$1 = awaitify(someSeries, 3); - -/** - * Sorts a list by the results of running each `coll` value through an async - * `iteratee`. - * - * @name sortBy - * @static - * @memberOf module:Collections - * @method - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {AsyncFunction} iteratee - An async function to apply to each item in - * `coll`. - * The iteratee should complete with a value to use as the sort criteria as - * its `result`. - * Invoked with (item, callback). - * @param {Function} callback - A callback which is called after all the - * `iteratee` functions have finished, or an error occurs. Results is the items - * from the original `coll` sorted by the values returned by the `iteratee` - * calls. Invoked with (err, results). - * @returns {Promise} a promise, if no callback passed - * @example - * - * async.sortBy(['file1','file2','file3'], function(file, callback) { - * fs.stat(file, function(err, stats) { - * callback(err, stats.mtime); - * }); - * }, function(err, results) { - * // results is now the original array of files sorted by - * // modified date - * }); - * - * // By modifying the callback parameter the - * // sorting order can be influenced: - * - * // ascending order - * async.sortBy([1,9,3,5], function(x, callback) { - * callback(null, x); - * }, function(err,result) { - * // result callback - * }); - * - * // descending order - * async.sortBy([1,9,3,5], function(x, callback) { - * callback(null, x*-1); //<- x*-1 instead of x, turns the order around - * }, function(err,result) { - * // result callback - * }); - */ -function sortBy (coll, iteratee, callback) { - var _iteratee = wrapAsync(iteratee); - return map$1(coll, (x, iterCb) => { - _iteratee(x, (err, criteria) => { - if (err) return iterCb(err); - iterCb(err, {value: x, criteria}); - }); - }, (err, results) => { - if (err) return callback(err); - callback(null, results.sort(comparator).map(v => v.value)); - }); - - function comparator(left, right) { - var a = left.criteria, b = right.criteria; - return a < b ? -1 : a > b ? 1 : 0; - } -} -var sortBy$1 = awaitify(sortBy, 3); - -/** - * Sets a time limit on an asynchronous function. If the function does not call - * its callback within the specified milliseconds, it will be called with a - * timeout error. The code property for the error object will be `'ETIMEDOUT'`. - * - * @name timeout - * @static - * @memberOf module:Utils - * @method - * @category Util - * @param {AsyncFunction} asyncFn - The async function to limit in time. - * @param {number} milliseconds - The specified time limit. - * @param {*} [info] - Any variable you want attached (`string`, `object`, etc) - * to timeout Error for more information.. - * @returns {AsyncFunction} Returns a wrapped function that can be used with any - * of the control flow functions. - * Invoke this function with the same parameters as you would `asyncFunc`. - * @example - * - * function myFunction(foo, callback) { - * doAsyncTask(foo, function(err, data) { - * // handle errors - * if (err) return callback(err); - * - * // do some stuff ... - * - * // return processed data - * return callback(null, data); - * }); - * } - * - * var wrapped = async.timeout(myFunction, 1000); - * - * // call `wrapped` as you would `myFunction` - * wrapped({ bar: 'bar' }, function(err, data) { - * // if `myFunction` takes < 1000 ms to execute, `err` - * // and `data` will have their expected values - * - * // else `err` will be an Error with the code 'ETIMEDOUT' - * }); - */ -function timeout(asyncFn, milliseconds, info) { - var fn = wrapAsync(asyncFn); - - return initialParams((args, callback) => { - var timedOut = false; - var timer; - - function timeoutCallback() { - var name = asyncFn.name || 'anonymous'; - var error = new Error('Callback function "' + name + '" timed out.'); - error.code = 'ETIMEDOUT'; - if (info) { - error.info = info; - } - timedOut = true; - callback(error); - } - - args.push((...cbArgs) => { - if (!timedOut) { - callback(...cbArgs); - clearTimeout(timer); - } - }); - - // setup timer and call original function - timer = setTimeout(timeoutCallback, milliseconds); - fn(...args); - }); -} - -function range(size) { - var result = Array(size); - while (size--) { - result[size] = size; - } - return result; -} - -/** - * The same as [times]{@link module:ControlFlow.times} but runs a maximum of `limit` async operations at a - * time. - * - * @name timesLimit - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.times]{@link module:ControlFlow.times} - * @category Control Flow - * @param {number} count - The number of times to run the function. - * @param {number} limit - The maximum number of async operations at a time. - * @param {AsyncFunction} iteratee - The async function to call `n` times. - * Invoked with the iteration index and a callback: (n, next). - * @param {Function} callback - see [async.map]{@link module:Collections.map}. - * @returns {Promise} a promise, if no callback is provided - */ -function timesLimit(count, limit, iteratee, callback) { - var _iteratee = wrapAsync(iteratee); - return mapLimit$1(range(count), limit, _iteratee, callback); -} - -/** - * Calls the `iteratee` function `n` times, and accumulates results in the same - * manner you would use with [map]{@link module:Collections.map}. - * - * @name times - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.map]{@link module:Collections.map} - * @category Control Flow - * @param {number} n - The number of times to run the function. - * @param {AsyncFunction} iteratee - The async function to call `n` times. - * Invoked with the iteration index and a callback: (n, next). - * @param {Function} callback - see {@link module:Collections.map}. - * @returns {Promise} a promise, if no callback is provided - * @example - * - * // Pretend this is some complicated async factory - * var createUser = function(id, callback) { - * callback(null, { - * id: 'user' + id - * }); - * }; - * - * // generate 5 users - * async.times(5, function(n, next) { - * createUser(n, function(err, user) { - * next(err, user); - * }); - * }, function(err, users) { - * // we should now have 5 users - * }); - */ -function times (n, iteratee, callback) { - return timesLimit(n, Infinity, iteratee, callback) -} - -/** - * The same as [times]{@link module:ControlFlow.times} but runs only a single async operation at a time. - * - * @name timesSeries - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.times]{@link module:ControlFlow.times} - * @category Control Flow - * @param {number} n - The number of times to run the function. - * @param {AsyncFunction} iteratee - The async function to call `n` times. - * Invoked with the iteration index and a callback: (n, next). - * @param {Function} callback - see {@link module:Collections.map}. - * @returns {Promise} a promise, if no callback is provided - */ -function timesSeries (n, iteratee, callback) { - return timesLimit(n, 1, iteratee, callback) -} - -/** - * A relative of `reduce`. Takes an Object or Array, and iterates over each - * element in parallel, each step potentially mutating an `accumulator` value. - * The type of the accumulator defaults to the type of collection passed in. - * - * @name transform - * @static - * @memberOf module:Collections - * @method - * @category Collection - * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. - * @param {*} [accumulator] - The initial state of the transform. If omitted, - * it will default to an empty Object or Array, depending on the type of `coll` - * @param {AsyncFunction} iteratee - A function applied to each item in the - * collection that potentially modifies the accumulator. - * Invoked with (accumulator, item, key, callback). - * @param {Function} [callback] - A callback which is called after all the - * `iteratee` functions have finished. Result is the transformed accumulator. - * Invoked with (err, result). - * @returns {Promise} a promise, if no callback provided - * @example - * - * async.transform([1,2,3], function(acc, item, index, callback) { - * // pointless async: - * process.nextTick(function() { - * acc[index] = item * 2 - * callback(null) - * }); - * }, function(err, result) { - * // result is now equal to [2, 4, 6] - * }); - * - * @example - * - * async.transform({a: 1, b: 2, c: 3}, function (obj, val, key, callback) { - * setImmediate(function () { - * obj[key] = val * 2; - * callback(); - * }) - * }, function (err, result) { - * // result is equal to {a: 2, b: 4, c: 6} - * }) - */ -function transform (coll, accumulator, iteratee, callback) { - if (arguments.length <= 3 && typeof accumulator === 'function') { - callback = iteratee; - iteratee = accumulator; - accumulator = Array.isArray(coll) ? [] : {}; - } - callback = once(callback || promiseCallback()); - var _iteratee = wrapAsync(iteratee); - - eachOf$1(coll, (v, k, cb) => { - _iteratee(accumulator, v, k, cb); - }, err => callback(err, accumulator)); - return callback[PROMISE_SYMBOL] -} - -/** - * It runs each task in series but stops whenever any of the functions were - * successful. If one of the tasks were successful, the `callback` will be - * passed the result of the successful task. If all tasks fail, the callback - * will be passed the error and result (if any) of the final attempt. - * - * @name tryEach - * @static - * @memberOf module:ControlFlow - * @method - * @category Control Flow - * @param {Array|Iterable|AsyncIterable|Object} tasks - A collection containing functions to - * run, each function is passed a `callback(err, result)` it must call on - * completion with an error `err` (which can be `null`) and an optional `result` - * value. - * @param {Function} [callback] - An optional callback which is called when one - * of the tasks has succeeded, or all have failed. It receives the `err` and - * `result` arguments of the last attempt at completing the `task`. Invoked with - * (err, results). - * @returns {Promise} a promise, if no callback is passed - * @example - * async.tryEach([ - * function getDataFromFirstWebsite(callback) { - * // Try getting the data from the first website - * callback(err, data); - * }, - * function getDataFromSecondWebsite(callback) { - * // First website failed, - * // Try getting the data from the backup website - * callback(err, data); - * } - * ], - * // optional callback - * function(err, results) { - * Now do something with the data. - * }); - * - */ -function tryEach(tasks, callback) { - var error = null; - var result; - return eachSeries$1(tasks, (task, taskCb) => { - wrapAsync(task)((err, ...args) => { - if (err === false) return taskCb(err); - - if (args.length < 2) { - [result] = args; - } else { - result = args; - } - error = err; - taskCb(err ? null : {}); - }); - }, () => callback(error, result)); -} - -var tryEach$1 = awaitify(tryEach); - -/** - * Undoes a [memoize]{@link module:Utils.memoize}d function, reverting it to the original, - * unmemoized form. Handy for testing. - * - * @name unmemoize - * @static - * @memberOf module:Utils - * @method - * @see [async.memoize]{@link module:Utils.memoize} - * @category Util - * @param {AsyncFunction} fn - the memoized function - * @returns {AsyncFunction} a function that calls the original unmemoized function - */ -function unmemoize(fn) { - return (...args) => { - return (fn.unmemoized || fn)(...args); - }; -} - -/** - * Repeatedly call `iteratee`, while `test` returns `true`. Calls `callback` when - * stopped, or an error occurs. - * - * @name whilst - * @static - * @memberOf module:ControlFlow - * @method - * @category Control Flow - * @param {AsyncFunction} test - asynchronous truth test to perform before each - * execution of `iteratee`. Invoked with (). - * @param {AsyncFunction} iteratee - An async function which is called each time - * `test` passes. Invoked with (callback). - * @param {Function} [callback] - A callback which is called after the test - * function has failed and repeated execution of `iteratee` has stopped. `callback` - * will be passed an error and any arguments passed to the final `iteratee`'s - * callback. Invoked with (err, [results]); - * @returns {Promise} a promise, if no callback is passed - * @example - * - * var count = 0; - * async.whilst( - * function test(cb) { cb(null, count < 5;) }, - * function iter(callback) { - * count++; - * setTimeout(function() { - * callback(null, count); - * }, 1000); - * }, - * function (err, n) { - * // 5 seconds have passed, n = 5 - * } - * ); - */ -function whilst(test, iteratee, callback) { - callback = onlyOnce(callback); - var _fn = wrapAsync(iteratee); - var _test = wrapAsync(test); - var results = []; - - function next(err, ...rest) { - if (err) return callback(err); - results = rest; - if (err === false) return; - _test(check); - } - - function check(err, truth) { - if (err) return callback(err); - if (err === false) return; - if (!truth) return callback(null, ...results); - _fn(next); - } - - return _test(check); -} -var whilst$1 = awaitify(whilst, 3); - -/** - * Repeatedly call `iteratee` until `test` returns `true`. Calls `callback` when - * stopped, or an error occurs. `callback` will be passed an error and any - * arguments passed to the final `iteratee`'s callback. - * - * The inverse of [whilst]{@link module:ControlFlow.whilst}. - * - * @name until - * @static - * @memberOf module:ControlFlow - * @method - * @see [async.whilst]{@link module:ControlFlow.whilst} - * @category Control Flow - * @param {AsyncFunction} test - asynchronous truth test to perform before each - * execution of `iteratee`. Invoked with (callback). - * @param {AsyncFunction} iteratee - An async function which is called each time - * `test` fails. Invoked with (callback). - * @param {Function} [callback] - A callback which is called after the test - * function has passed and repeated execution of `iteratee` has stopped. `callback` - * will be passed an error and any arguments passed to the final `iteratee`'s - * callback. Invoked with (err, [results]); - * @returns {Promise} a promise, if a callback is not passed - * - * @example - * const results = [] - * async.until(function test(page, cb) { - * cb(null, page.next == null) - * }, function iter(next) { - * fetchPage(url, (err, body) => { - * if (err) return next(err) - * results = results.concat(body.objects) - * next(err, body) - * }) - * }, function done (err) { - * // all pages have been fetched - * }) - */ -function until(test, iteratee, callback) { - const _test = wrapAsync(test); - return whilst$1((cb) => _test((err, truth) => cb (err, !truth)), iteratee, callback); -} - -/** - * Runs the `tasks` array of functions in series, each passing their results to - * the next in the array. However, if any of the `tasks` pass an error to their - * own callback, the next function is not executed, and the main `callback` is - * immediately called with the error. - * - * @name waterfall - * @static - * @memberOf module:ControlFlow - * @method - * @category Control Flow - * @param {Array} tasks - An array of [async functions]{@link AsyncFunction} - * to run. - * Each function should complete with any number of `result` values. - * The `result` values will be passed as arguments, in order, to the next task. - * @param {Function} [callback] - An optional callback to run once all the - * functions have completed. This will be passed the results of the last task's - * callback. Invoked with (err, [results]). - * @returns undefined - * @example - * - * async.waterfall([ - * function(callback) { - * callback(null, 'one', 'two'); - * }, - * function(arg1, arg2, callback) { - * // arg1 now equals 'one' and arg2 now equals 'two' - * callback(null, 'three'); - * }, - * function(arg1, callback) { - * // arg1 now equals 'three' - * callback(null, 'done'); - * } - * ], function (err, result) { - * // result now equals 'done' - * }); - * - * // Or, with named functions: - * async.waterfall([ - * myFirstFunction, - * mySecondFunction, - * myLastFunction, - * ], function (err, result) { - * // result now equals 'done' - * }); - * function myFirstFunction(callback) { - * callback(null, 'one', 'two'); - * } - * function mySecondFunction(arg1, arg2, callback) { - * // arg1 now equals 'one' and arg2 now equals 'two' - * callback(null, 'three'); - * } - * function myLastFunction(arg1, callback) { - * // arg1 now equals 'three' - * callback(null, 'done'); - * } - */ -function waterfall (tasks, callback) { - callback = once(callback); - if (!Array.isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions')); - if (!tasks.length) return callback(); - var taskIndex = 0; - - function nextTask(args) { - var task = wrapAsync(tasks[taskIndex++]); - task(...args, onlyOnce(next)); - } - - function next(err, ...args) { - if (err === false) return - if (err || taskIndex === tasks.length) { - return callback(err, ...args); - } - nextTask(args); - } - - nextTask([]); -} - -var waterfall$1 = awaitify(waterfall); - -/** - * An "async function" in the context of Async is an asynchronous function with - * a variable number of parameters, with the final parameter being a callback. - * (`function (arg1, arg2, ..., callback) {}`) - * The final callback is of the form `callback(err, results...)`, which must be - * called once the function is completed. The callback should be called with a - * Error as its first argument to signal that an error occurred. - * Otherwise, if no error occurred, it should be called with `null` as the first - * argument, and any additional `result` arguments that may apply, to signal - * successful completion. - * The callback must be called exactly once, ideally on a later tick of the - * JavaScript event loop. - * - * This type of function is also referred to as a "Node-style async function", - * or a "continuation passing-style function" (CPS). Most of the methods of this - * library are themselves CPS/Node-style async functions, or functions that - * return CPS/Node-style async functions. - * - * Wherever we accept a Node-style async function, we also directly accept an - * [ES2017 `async` function]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function}. - * In this case, the `async` function will not be passed a final callback - * argument, and any thrown error will be used as the `err` argument of the - * implicit callback, and the return value will be used as the `result` value. - * (i.e. a `rejected` of the returned Promise becomes the `err` callback - * argument, and a `resolved` value becomes the `result`.) - * - * Note, due to JavaScript limitations, we can only detect native `async` - * functions and not transpilied implementations. - * Your environment must have `async`/`await` support for this to work. - * (e.g. Node > v7.6, or a recent version of a modern browser). - * If you are using `async` functions through a transpiler (e.g. Babel), you - * must still wrap the function with [asyncify]{@link module:Utils.asyncify}, - * because the `async function` will be compiled to an ordinary function that - * returns a promise. - * - * @typedef {Function} AsyncFunction - * @static - */ - -var index = { - apply, - applyEach: applyEach$1, - applyEachSeries, - asyncify, - auto, - autoInject, - cargo, - cargoQueue: cargo$1, - compose, - concat: concat$1, - concatLimit: concatLimit$1, - concatSeries: concatSeries$1, - constant, - detect: detect$1, - detectLimit: detectLimit$1, - detectSeries: detectSeries$1, - dir, - doUntil, - doWhilst: doWhilst$1, - each, - eachLimit: eachLimit$2, - eachOf: eachOf$1, - eachOfLimit: eachOfLimit$2, - eachOfSeries: eachOfSeries$1, - eachSeries: eachSeries$1, - ensureAsync, - every: every$1, - everyLimit: everyLimit$1, - everySeries: everySeries$1, - filter: filter$1, - filterLimit: filterLimit$1, - filterSeries: filterSeries$1, - forever: forever$1, - groupBy, - groupByLimit: groupByLimit$1, - groupBySeries, - log, - map: map$1, - mapLimit: mapLimit$1, - mapSeries: mapSeries$1, - mapValues, - mapValuesLimit: mapValuesLimit$1, - mapValuesSeries, - memoize, - nextTick, - parallel, - parallelLimit, - priorityQueue, - queue: queue$1, - race: race$1, - reduce: reduce$1, - reduceRight, - reflect, - reflectAll, - reject: reject$2, - rejectLimit: rejectLimit$1, - rejectSeries: rejectSeries$1, - retry, - retryable, - seq, - series, - setImmediate: setImmediate$1, - some: some$1, - someLimit: someLimit$1, - someSeries: someSeries$1, - sortBy: sortBy$1, - timeout, - times, - timesLimit, - timesSeries, - transform, - tryEach: tryEach$1, - unmemoize, - until, - waterfall: waterfall$1, - whilst: whilst$1, - - // aliases - all: every$1, - allLimit: everyLimit$1, - allSeries: everySeries$1, - any: some$1, - anyLimit: someLimit$1, - anySeries: someSeries$1, - find: detect$1, - findLimit: detectLimit$1, - findSeries: detectSeries$1, - flatMap: concat$1, - flatMapLimit: concatLimit$1, - flatMapSeries: concatSeries$1, - forEach: each, - forEachSeries: eachSeries$1, - forEachLimit: eachLimit$2, - forEachOf: eachOf$1, - forEachOfSeries: eachOfSeries$1, - forEachOfLimit: eachOfLimit$2, - inject: reduce$1, - foldl: reduce$1, - foldr: reduceRight, - select: filter$1, - selectLimit: filterLimit$1, - selectSeries: filterSeries$1, - wrapSync: asyncify, - during: whilst$1, - doDuring: doWhilst$1 -}; - -export default index; -export { every$1 as all, everyLimit$1 as allLimit, everySeries$1 as allSeries, some$1 as any, someLimit$1 as anyLimit, someSeries$1 as anySeries, apply, applyEach$1 as applyEach, applyEachSeries, asyncify, auto, autoInject, cargo, cargo$1 as cargoQueue, compose, concat$1 as concat, concatLimit$1 as concatLimit, concatSeries$1 as concatSeries, constant, detect$1 as detect, detectLimit$1 as detectLimit, detectSeries$1 as detectSeries, dir, doWhilst$1 as doDuring, doUntil, doWhilst$1 as doWhilst, whilst$1 as during, each, eachLimit$2 as eachLimit, eachOf$1 as eachOf, eachOfLimit$2 as eachOfLimit, eachOfSeries$1 as eachOfSeries, eachSeries$1 as eachSeries, ensureAsync, every$1 as every, everyLimit$1 as everyLimit, everySeries$1 as everySeries, filter$1 as filter, filterLimit$1 as filterLimit, filterSeries$1 as filterSeries, detect$1 as find, detectLimit$1 as findLimit, detectSeries$1 as findSeries, concat$1 as flatMap, concatLimit$1 as flatMapLimit, concatSeries$1 as flatMapSeries, reduce$1 as foldl, reduceRight as foldr, each as forEach, eachLimit$2 as forEachLimit, eachOf$1 as forEachOf, eachOfLimit$2 as forEachOfLimit, eachOfSeries$1 as forEachOfSeries, eachSeries$1 as forEachSeries, forever$1 as forever, groupBy, groupByLimit$1 as groupByLimit, groupBySeries, reduce$1 as inject, log, map$1 as map, mapLimit$1 as mapLimit, mapSeries$1 as mapSeries, mapValues, mapValuesLimit$1 as mapValuesLimit, mapValuesSeries, memoize, nextTick, parallel, parallelLimit, priorityQueue, queue$1 as queue, race$1 as race, reduce$1 as reduce, reduceRight, reflect, reflectAll, reject$2 as reject, rejectLimit$1 as rejectLimit, rejectSeries$1 as rejectSeries, retry, retryable, filter$1 as select, filterLimit$1 as selectLimit, filterSeries$1 as selectSeries, seq, series, setImmediate$1 as setImmediate, some$1 as some, someLimit$1 as someLimit, someSeries$1 as someSeries, sortBy$1 as sortBy, timeout, times, timesLimit, timesSeries, transform, tryEach$1 as tryEach, unmemoize, until, waterfall$1 as waterfall, whilst$1 as whilst, asyncify as wrapSync }; diff --git a/__tests__/integration/dep-list-simple/web_modules/import-map.json b/__tests__/integration/dep-list-simple/web_modules/import-map.json deleted file mode 100644 index d3882b6e08..0000000000 --- a/__tests__/integration/dep-list-simple/web_modules/import-map.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "imports": { - "async": "./async.js" - } -} \ No newline at end of file diff --git a/__tests__/integration/exclude/expected-install/import-map.json b/__tests__/integration/exclude/expected-install/import-map.json index 59de14a185..64ed2d1415 100644 --- a/__tests__/integration/exclude/expected-install/import-map.json +++ b/__tests__/integration/exclude/expected-install/import-map.json @@ -1,6 +1,6 @@ { "imports": { - "vue": "./vue.js", - "vue-router": "./vue-router.js" + "vue": "./vue.js?rev=XXXXXXXXXX", + "vue-router": "./vue-router.js?rev=XXXXXXXXXX" } } \ No newline at end of file diff --git a/__tests__/integration/exclude/web_modules/import-map.json b/__tests__/integration/exclude/web_modules/import-map.json deleted file mode 100644 index 59de14a185..0000000000 --- a/__tests__/integration/exclude/web_modules/import-map.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "imports": { - "vue": "./vue.js", - "vue-router": "./vue-router.js" - } -} \ No newline at end of file diff --git a/__tests__/integration/exclude/web_modules/vue-router.js b/__tests__/integration/exclude/web_modules/vue-router.js deleted file mode 100644 index 7c53961819..0000000000 --- a/__tests__/integration/exclude/web_modules/vue-router.js +++ /dev/null @@ -1,2882 +0,0 @@ -/*! - * vue-router v3.1.3 - * (c) 2019 Evan You - * @license MIT - */ -/* */ - -function assert (condition, message) { - if (!condition) { - throw new Error(("[vue-router] " + message)) - } -} - -function warn (condition, message) { - if ( !condition) { - typeof console !== 'undefined' && console.warn(("[vue-router] " + message)); - } -} - -function isError (err) { - return Object.prototype.toString.call(err).indexOf('Error') > -1 -} - -function isExtendedError (constructor, err) { - return ( - err instanceof constructor || - // _name is to support IE9 too - (err && (err.name === constructor.name || err._name === constructor._name)) - ) -} - -function extend (a, b) { - for (var key in b) { - a[key] = b[key]; - } - return a -} - -var View = { - name: 'RouterView', - functional: true, - props: { - name: { - type: String, - default: 'default' - } - }, - render: function render (_, ref) { - var props = ref.props; - var children = ref.children; - var parent = ref.parent; - var data = ref.data; - - // used by devtools to display a router-view badge - data.routerView = true; - - // directly use parent context's createElement() function - // so that components rendered by router-view can resolve named slots - var h = parent.$createElement; - var name = props.name; - var route = parent.$route; - var cache = parent._routerViewCache || (parent._routerViewCache = {}); - - // determine current view depth, also check to see if the tree - // has been toggled inactive but kept-alive. - var depth = 0; - var inactive = false; - while (parent && parent._routerRoot !== parent) { - var vnodeData = parent.$vnode && parent.$vnode.data; - if (vnodeData) { - if (vnodeData.routerView) { - depth++; - } - if (vnodeData.keepAlive && parent._inactive) { - inactive = true; - } - } - parent = parent.$parent; - } - data.routerViewDepth = depth; - - // render previous view if the tree is inactive and kept-alive - if (inactive) { - return h(cache[name], data, children) - } - - var matched = route.matched[depth]; - // render empty node if no matched route - if (!matched) { - cache[name] = null; - return h() - } - - var component = cache[name] = matched.components[name]; - - // attach instance registration hook - // this will be called in the instance's injected lifecycle hooks - data.registerRouteInstance = function (vm, val) { - // val could be undefined for unregistration - var current = matched.instances[name]; - if ( - (val && current !== vm) || - (!val && current === vm) - ) { - matched.instances[name] = val; - } - } - - // also register instance in prepatch hook - // in case the same component instance is reused across different routes - ;(data.hook || (data.hook = {})).prepatch = function (_, vnode) { - matched.instances[name] = vnode.componentInstance; - }; - - // register instance in init hook - // in case kept-alive component be actived when routes changed - data.hook.init = function (vnode) { - if (vnode.data.keepAlive && - vnode.componentInstance && - vnode.componentInstance !== matched.instances[name] - ) { - matched.instances[name] = vnode.componentInstance; - } - }; - - // resolve props - var propsToPass = data.props = resolveProps(route, matched.props && matched.props[name]); - if (propsToPass) { - // clone to prevent mutation - propsToPass = data.props = extend({}, propsToPass); - // pass non-declared props as attrs - var attrs = data.attrs = data.attrs || {}; - for (var key in propsToPass) { - if (!component.props || !(key in component.props)) { - attrs[key] = propsToPass[key]; - delete propsToPass[key]; - } - } - } - - return h(component, data, children) - } -}; - -function resolveProps (route, config) { - switch (typeof config) { - case 'undefined': - return - case 'object': - return config - case 'function': - return config(route) - case 'boolean': - return config ? route.params : undefined - default: - { - warn( - false, - "props in \"" + (route.path) + "\" is a " + (typeof config) + ", " + - "expecting an object, function or boolean." - ); - } - } -} - -/* */ - -var encodeReserveRE = /[!'()*]/g; -var encodeReserveReplacer = function (c) { return '%' + c.charCodeAt(0).toString(16); }; -var commaRE = /%2C/g; - -// fixed encodeURIComponent which is more conformant to RFC3986: -// - escapes [!'()*] -// - preserve commas -var encode = function (str) { return encodeURIComponent(str) - .replace(encodeReserveRE, encodeReserveReplacer) - .replace(commaRE, ','); }; - -var decode = decodeURIComponent; - -function resolveQuery ( - query, - extraQuery, - _parseQuery -) { - if ( extraQuery === void 0 ) extraQuery = {}; - - var parse = _parseQuery || parseQuery; - var parsedQuery; - try { - parsedQuery = parse(query || ''); - } catch (e) { - warn(false, e.message); - parsedQuery = {}; - } - for (var key in extraQuery) { - parsedQuery[key] = extraQuery[key]; - } - return parsedQuery -} - -function parseQuery (query) { - var res = {}; - - query = query.trim().replace(/^(\?|#|&)/, ''); - - if (!query) { - return res - } - - query.split('&').forEach(function (param) { - var parts = param.replace(/\+/g, ' ').split('='); - var key = decode(parts.shift()); - var val = parts.length > 0 - ? decode(parts.join('=')) - : null; - - if (res[key] === undefined) { - res[key] = val; - } else if (Array.isArray(res[key])) { - res[key].push(val); - } else { - res[key] = [res[key], val]; - } - }); - - return res -} - -function stringifyQuery (obj) { - var res = obj ? Object.keys(obj).map(function (key) { - var val = obj[key]; - - if (val === undefined) { - return '' - } - - if (val === null) { - return encode(key) - } - - if (Array.isArray(val)) { - var result = []; - val.forEach(function (val2) { - if (val2 === undefined) { - return - } - if (val2 === null) { - result.push(encode(key)); - } else { - result.push(encode(key) + '=' + encode(val2)); - } - }); - return result.join('&') - } - - return encode(key) + '=' + encode(val) - }).filter(function (x) { return x.length > 0; }).join('&') : null; - return res ? ("?" + res) : '' -} - -/* */ - -var trailingSlashRE = /\/?$/; - -function createRoute ( - record, - location, - redirectedFrom, - router -) { - var stringifyQuery = router && router.options.stringifyQuery; - - var query = location.query || {}; - try { - query = clone(query); - } catch (e) {} - - var route = { - name: location.name || (record && record.name), - meta: (record && record.meta) || {}, - path: location.path || '/', - hash: location.hash || '', - query: query, - params: location.params || {}, - fullPath: getFullPath(location, stringifyQuery), - matched: record ? formatMatch(record) : [] - }; - if (redirectedFrom) { - route.redirectedFrom = getFullPath(redirectedFrom, stringifyQuery); - } - return Object.freeze(route) -} - -function clone (value) { - if (Array.isArray(value)) { - return value.map(clone) - } else if (value && typeof value === 'object') { - var res = {}; - for (var key in value) { - res[key] = clone(value[key]); - } - return res - } else { - return value - } -} - -// the starting route that represents the initial state -var START = createRoute(null, { - path: '/' -}); - -function formatMatch (record) { - var res = []; - while (record) { - res.unshift(record); - record = record.parent; - } - return res -} - -function getFullPath ( - ref, - _stringifyQuery -) { - var path = ref.path; - var query = ref.query; if ( query === void 0 ) query = {}; - var hash = ref.hash; if ( hash === void 0 ) hash = ''; - - var stringify = _stringifyQuery || stringifyQuery; - return (path || '/') + stringify(query) + hash -} - -function isSameRoute (a, b) { - if (b === START) { - return a === b - } else if (!b) { - return false - } else if (a.path && b.path) { - return ( - a.path.replace(trailingSlashRE, '') === b.path.replace(trailingSlashRE, '') && - a.hash === b.hash && - isObjectEqual(a.query, b.query) - ) - } else if (a.name && b.name) { - return ( - a.name === b.name && - a.hash === b.hash && - isObjectEqual(a.query, b.query) && - isObjectEqual(a.params, b.params) - ) - } else { - return false - } -} - -function isObjectEqual (a, b) { - if ( a === void 0 ) a = {}; - if ( b === void 0 ) b = {}; - - // handle null value #1566 - if (!a || !b) { return a === b } - var aKeys = Object.keys(a); - var bKeys = Object.keys(b); - if (aKeys.length !== bKeys.length) { - return false - } - return aKeys.every(function (key) { - var aVal = a[key]; - var bVal = b[key]; - // check nested equality - if (typeof aVal === 'object' && typeof bVal === 'object') { - return isObjectEqual(aVal, bVal) - } - return String(aVal) === String(bVal) - }) -} - -function isIncludedRoute (current, target) { - return ( - current.path.replace(trailingSlashRE, '/').indexOf( - target.path.replace(trailingSlashRE, '/') - ) === 0 && - (!target.hash || current.hash === target.hash) && - queryIncludes(current.query, target.query) - ) -} - -function queryIncludes (current, target) { - for (var key in target) { - if (!(key in current)) { - return false - } - } - return true -} - -/* */ - -function resolvePath ( - relative, - base, - append -) { - var firstChar = relative.charAt(0); - if (firstChar === '/') { - return relative - } - - if (firstChar === '?' || firstChar === '#') { - return base + relative - } - - var stack = base.split('/'); - - // remove trailing segment if: - // - not appending - // - appending to trailing slash (last segment is empty) - if (!append || !stack[stack.length - 1]) { - stack.pop(); - } - - // resolve relative path - var segments = relative.replace(/^\//, '').split('/'); - for (var i = 0; i < segments.length; i++) { - var segment = segments[i]; - if (segment === '..') { - stack.pop(); - } else if (segment !== '.') { - stack.push(segment); - } - } - - // ensure leading slash - if (stack[0] !== '') { - stack.unshift(''); - } - - return stack.join('/') -} - -function parsePath (path) { - var hash = ''; - var query = ''; - - var hashIndex = path.indexOf('#'); - if (hashIndex >= 0) { - hash = path.slice(hashIndex); - path = path.slice(0, hashIndex); - } - - var queryIndex = path.indexOf('?'); - if (queryIndex >= 0) { - query = path.slice(queryIndex + 1); - path = path.slice(0, queryIndex); - } - - return { - path: path, - query: query, - hash: hash - } -} - -function cleanPath (path) { - return path.replace(/\/\//g, '/') -} - -var isarray = Array.isArray || function (arr) { - return Object.prototype.toString.call(arr) == '[object Array]'; -}; - -/** - * Expose `pathToRegexp`. - */ -var pathToRegexp_1 = pathToRegexp; -var parse_1 = parse; -var compile_1 = compile; -var tokensToFunction_1 = tokensToFunction; -var tokensToRegExp_1 = tokensToRegExp; - -/** - * The main path matching regexp utility. - * - * @type {RegExp} - */ -var PATH_REGEXP = new RegExp([ - // Match escaped characters that would otherwise appear in future matches. - // This allows the user to escape special characters that won't transform. - '(\\\\.)', - // Match Express-style parameters and un-named parameters with a prefix - // and optional suffixes. Matches appear as: - // - // "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined] - // "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined] - // "/*" => ["/", undefined, undefined, undefined, undefined, "*"] - '([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))' -].join('|'), 'g'); - -/** - * Parse a string for the raw tokens. - * - * @param {string} str - * @param {Object=} options - * @return {!Array} - */ -function parse (str, options) { - var tokens = []; - var key = 0; - var index = 0; - var path = ''; - var defaultDelimiter = options && options.delimiter || '/'; - var res; - - while ((res = PATH_REGEXP.exec(str)) != null) { - var m = res[0]; - var escaped = res[1]; - var offset = res.index; - path += str.slice(index, offset); - index = offset + m.length; - - // Ignore already escaped sequences. - if (escaped) { - path += escaped[1]; - continue - } - - var next = str[index]; - var prefix = res[2]; - var name = res[3]; - var capture = res[4]; - var group = res[5]; - var modifier = res[6]; - var asterisk = res[7]; - - // Push the current path onto the tokens. - if (path) { - tokens.push(path); - path = ''; - } - - var partial = prefix != null && next != null && next !== prefix; - var repeat = modifier === '+' || modifier === '*'; - var optional = modifier === '?' || modifier === '*'; - var delimiter = res[2] || defaultDelimiter; - var pattern = capture || group; - - tokens.push({ - name: name || key++, - prefix: prefix || '', - delimiter: delimiter, - optional: optional, - repeat: repeat, - partial: partial, - asterisk: !!asterisk, - pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?') - }); - } - - // Match any characters still remaining. - if (index < str.length) { - path += str.substr(index); - } - - // If the path exists, push it onto the end. - if (path) { - tokens.push(path); - } - - return tokens -} - -/** - * Compile a string to a template function for the path. - * - * @param {string} str - * @param {Object=} options - * @return {!function(Object=, Object=)} - */ -function compile (str, options) { - return tokensToFunction(parse(str, options)) -} - -/** - * Prettier encoding of URI path segments. - * - * @param {string} - * @return {string} - */ -function encodeURIComponentPretty (str) { - return encodeURI(str).replace(/[\/?#]/g, function (c) { - return '%' + c.charCodeAt(0).toString(16).toUpperCase() - }) -} - -/** - * Encode the asterisk parameter. Similar to `pretty`, but allows slashes. - * - * @param {string} - * @return {string} - */ -function encodeAsterisk (str) { - return encodeURI(str).replace(/[?#]/g, function (c) { - return '%' + c.charCodeAt(0).toString(16).toUpperCase() - }) -} - -/** - * Expose a method for transforming tokens into the path function. - */ -function tokensToFunction (tokens) { - // Compile all the tokens into regexps. - var matches = new Array(tokens.length); - - // Compile all the patterns before compilation. - for (var i = 0; i < tokens.length; i++) { - if (typeof tokens[i] === 'object') { - matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$'); - } - } - - return function (obj, opts) { - var path = ''; - var data = obj || {}; - var options = opts || {}; - var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent; - - for (var i = 0; i < tokens.length; i++) { - var token = tokens[i]; - - if (typeof token === 'string') { - path += token; - - continue - } - - var value = data[token.name]; - var segment; - - if (value == null) { - if (token.optional) { - // Prepend partial segment prefixes. - if (token.partial) { - path += token.prefix; - } - - continue - } else { - throw new TypeError('Expected "' + token.name + '" to be defined') - } - } - - if (isarray(value)) { - if (!token.repeat) { - throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`') - } - - if (value.length === 0) { - if (token.optional) { - continue - } else { - throw new TypeError('Expected "' + token.name + '" to not be empty') - } - } - - for (var j = 0; j < value.length; j++) { - segment = encode(value[j]); - - if (!matches[i].test(segment)) { - throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`') - } - - path += (j === 0 ? token.prefix : token.delimiter) + segment; - } - - continue - } - - segment = token.asterisk ? encodeAsterisk(value) : encode(value); - - if (!matches[i].test(segment)) { - throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"') - } - - path += token.prefix + segment; - } - - return path - } -} - -/** - * Escape a regular expression string. - * - * @param {string} str - * @return {string} - */ -function escapeString (str) { - return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1') -} - -/** - * Escape the capturing group by escaping special characters and meaning. - * - * @param {string} group - * @return {string} - */ -function escapeGroup (group) { - return group.replace(/([=!:$\/()])/g, '\\$1') -} - -/** - * Attach the keys as a property of the regexp. - * - * @param {!RegExp} re - * @param {Array} keys - * @return {!RegExp} - */ -function attachKeys (re, keys) { - re.keys = keys; - return re -} - -/** - * Get the flags for a regexp from the options. - * - * @param {Object} options - * @return {string} - */ -function flags (options) { - return options.sensitive ? '' : 'i' -} - -/** - * Pull out keys from a regexp. - * - * @param {!RegExp} path - * @param {!Array} keys - * @return {!RegExp} - */ -function regexpToRegexp (path, keys) { - // Use a negative lookahead to match only capturing groups. - var groups = path.source.match(/\((?!\?)/g); - - if (groups) { - for (var i = 0; i < groups.length; i++) { - keys.push({ - name: i, - prefix: null, - delimiter: null, - optional: false, - repeat: false, - partial: false, - asterisk: false, - pattern: null - }); - } - } - - return attachKeys(path, keys) -} - -/** - * Transform an array into a regexp. - * - * @param {!Array} path - * @param {Array} keys - * @param {!Object} options - * @return {!RegExp} - */ -function arrayToRegexp (path, keys, options) { - var parts = []; - - for (var i = 0; i < path.length; i++) { - parts.push(pathToRegexp(path[i], keys, options).source); - } - - var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options)); - - return attachKeys(regexp, keys) -} - -/** - * Create a path regexp from string input. - * - * @param {string} path - * @param {!Array} keys - * @param {!Object} options - * @return {!RegExp} - */ -function stringToRegexp (path, keys, options) { - return tokensToRegExp(parse(path, options), keys, options) -} - -/** - * Expose a function for taking tokens and returning a RegExp. - * - * @param {!Array} tokens - * @param {(Array|Object)=} keys - * @param {Object=} options - * @return {!RegExp} - */ -function tokensToRegExp (tokens, keys, options) { - if (!isarray(keys)) { - options = /** @type {!Object} */ (keys || options); - keys = []; - } - - options = options || {}; - - var strict = options.strict; - var end = options.end !== false; - var route = ''; - - // Iterate over the tokens and create our regexp string. - for (var i = 0; i < tokens.length; i++) { - var token = tokens[i]; - - if (typeof token === 'string') { - route += escapeString(token); - } else { - var prefix = escapeString(token.prefix); - var capture = '(?:' + token.pattern + ')'; - - keys.push(token); - - if (token.repeat) { - capture += '(?:' + prefix + capture + ')*'; - } - - if (token.optional) { - if (!token.partial) { - capture = '(?:' + prefix + '(' + capture + '))?'; - } else { - capture = prefix + '(' + capture + ')?'; - } - } else { - capture = prefix + '(' + capture + ')'; - } - - route += capture; - } - } - - var delimiter = escapeString(options.delimiter || '/'); - var endsWithDelimiter = route.slice(-delimiter.length) === delimiter; - - // In non-strict mode we allow a slash at the end of match. If the path to - // match already ends with a slash, we remove it for consistency. The slash - // is valid at the end of a path match, not in the middle. This is important - // in non-ending mode, where "/test/" shouldn't match "/test//route". - if (!strict) { - route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?'; - } - - if (end) { - route += '$'; - } else { - // In non-ending mode, we need the capturing groups to match as much as - // possible by using a positive lookahead to the end or next path segment. - route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)'; - } - - return attachKeys(new RegExp('^' + route, flags(options)), keys) -} - -/** - * Normalize the given path string, returning a regular expression. - * - * An empty array can be passed in for the keys, which will hold the - * placeholder key descriptions. For example, using `/user/:id`, `keys` will - * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`. - * - * @param {(string|RegExp|Array)} path - * @param {(Array|Object)=} keys - * @param {Object=} options - * @return {!RegExp} - */ -function pathToRegexp (path, keys, options) { - if (!isarray(keys)) { - options = /** @type {!Object} */ (keys || options); - keys = []; - } - - options = options || {}; - - if (path instanceof RegExp) { - return regexpToRegexp(path, /** @type {!Array} */ (keys)) - } - - if (isarray(path)) { - return arrayToRegexp(/** @type {!Array} */ (path), /** @type {!Array} */ (keys), options) - } - - return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options) -} -pathToRegexp_1.parse = parse_1; -pathToRegexp_1.compile = compile_1; -pathToRegexp_1.tokensToFunction = tokensToFunction_1; -pathToRegexp_1.tokensToRegExp = tokensToRegExp_1; - -/* */ - -// $flow-disable-line -var regexpCompileCache = Object.create(null); - -function fillParams ( - path, - params, - routeMsg -) { - params = params || {}; - try { - var filler = - regexpCompileCache[path] || - (regexpCompileCache[path] = pathToRegexp_1.compile(path)); - - // Fix #2505 resolving asterisk routes { name: 'not-found', params: { pathMatch: '/not-found' }} - if (params.pathMatch) { params[0] = params.pathMatch; } - - return filler(params, { pretty: true }) - } catch (e) { - { - warn(false, ("missing param for " + routeMsg + ": " + (e.message))); - } - return '' - } finally { - // delete the 0 if it was added - delete params[0]; - } -} - -/* */ - -function normalizeLocation ( - raw, - current, - append, - router -) { - var next = typeof raw === 'string' ? { path: raw } : raw; - // named target - if (next._normalized) { - return next - } else if (next.name) { - return extend({}, raw) - } - - // relative params - if (!next.path && next.params && current) { - next = extend({}, next); - next._normalized = true; - var params = extend(extend({}, current.params), next.params); - if (current.name) { - next.name = current.name; - next.params = params; - } else if (current.matched.length) { - var rawPath = current.matched[current.matched.length - 1].path; - next.path = fillParams(rawPath, params, ("path " + (current.path))); - } else { - warn(false, "relative params navigation requires a current route."); - } - return next - } - - var parsedPath = parsePath(next.path || ''); - var basePath = (current && current.path) || '/'; - var path = parsedPath.path - ? resolvePath(parsedPath.path, basePath, append || next.append) - : basePath; - - var query = resolveQuery( - parsedPath.query, - next.query, - router && router.options.parseQuery - ); - - var hash = next.hash || parsedPath.hash; - if (hash && hash.charAt(0) !== '#') { - hash = "#" + hash; - } - - return { - _normalized: true, - path: path, - query: query, - hash: hash - } -} - -/* */ - -// work around weird flow bug -var toTypes = [String, Object]; -var eventTypes = [String, Array]; - -var noop = function () {}; - -var Link = { - name: 'RouterLink', - props: { - to: { - type: toTypes, - required: true - }, - tag: { - type: String, - default: 'a' - }, - exact: Boolean, - append: Boolean, - replace: Boolean, - activeClass: String, - exactActiveClass: String, - event: { - type: eventTypes, - default: 'click' - } - }, - render: function render (h) { - var this$1 = this; - - var router = this.$router; - var current = this.$route; - var ref = router.resolve( - this.to, - current, - this.append - ); - var location = ref.location; - var route = ref.route; - var href = ref.href; - - var classes = {}; - var globalActiveClass = router.options.linkActiveClass; - var globalExactActiveClass = router.options.linkExactActiveClass; - // Support global empty active class - var activeClassFallback = - globalActiveClass == null ? 'router-link-active' : globalActiveClass; - var exactActiveClassFallback = - globalExactActiveClass == null - ? 'router-link-exact-active' - : globalExactActiveClass; - var activeClass = - this.activeClass == null ? activeClassFallback : this.activeClass; - var exactActiveClass = - this.exactActiveClass == null - ? exactActiveClassFallback - : this.exactActiveClass; - - var compareTarget = route.redirectedFrom - ? createRoute(null, normalizeLocation(route.redirectedFrom), null, router) - : route; - - classes[exactActiveClass] = isSameRoute(current, compareTarget); - classes[activeClass] = this.exact - ? classes[exactActiveClass] - : isIncludedRoute(current, compareTarget); - - var handler = function (e) { - if (guardEvent(e)) { - if (this$1.replace) { - router.replace(location, noop); - } else { - router.push(location, noop); - } - } - }; - - var on = { click: guardEvent }; - if (Array.isArray(this.event)) { - this.event.forEach(function (e) { - on[e] = handler; - }); - } else { - on[this.event] = handler; - } - - var data = { class: classes }; - - var scopedSlot = - !this.$scopedSlots.$hasNormal && - this.$scopedSlots.default && - this.$scopedSlots.default({ - href: href, - route: route, - navigate: handler, - isActive: classes[activeClass], - isExactActive: classes[exactActiveClass] - }); - - if (scopedSlot) { - if (scopedSlot.length === 1) { - return scopedSlot[0] - } else if (scopedSlot.length > 1 || !scopedSlot.length) { - { - warn( - false, - ("RouterLink with to=\"" + (this.props.to) + "\" is trying to use a scoped slot but it didn't provide exactly one child.") - ); - } - return scopedSlot.length === 0 ? h() : h('span', {}, scopedSlot) - } - } - - if (this.tag === 'a') { - data.on = on; - data.attrs = { href: href }; - } else { - // find the first child and apply listener and href - var a = findAnchor(this.$slots.default); - if (a) { - // in case the is a static node - a.isStatic = false; - var aData = (a.data = extend({}, a.data)); - aData.on = aData.on || {}; - // transform existing events in both objects into arrays so we can push later - for (var event in aData.on) { - var handler$1 = aData.on[event]; - if (event in on) { - aData.on[event] = Array.isArray(handler$1) ? handler$1 : [handler$1]; - } - } - // append new listeners for router-link - for (var event$1 in on) { - if (event$1 in aData.on) { - // on[event] is always a function - aData.on[event$1].push(on[event$1]); - } else { - aData.on[event$1] = handler; - } - } - - var aAttrs = (a.data.attrs = extend({}, a.data.attrs)); - aAttrs.href = href; - } else { - // doesn't have child, apply listener to self - data.on = on; - } - } - - return h(this.tag, data, this.$slots.default) - } -}; - -function guardEvent (e) { - // don't redirect with control keys - if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) { return } - // don't redirect when preventDefault called - if (e.defaultPrevented) { return } - // don't redirect on right click - if (e.button !== undefined && e.button !== 0) { return } - // don't redirect if `target="_blank"` - if (e.currentTarget && e.currentTarget.getAttribute) { - var target = e.currentTarget.getAttribute('target'); - if (/\b_blank\b/i.test(target)) { return } - } - // this may be a Weex event which doesn't have this method - if (e.preventDefault) { - e.preventDefault(); - } - return true -} - -function findAnchor (children) { - if (children) { - var child; - for (var i = 0; i < children.length; i++) { - child = children[i]; - if (child.tag === 'a') { - return child - } - if (child.children && (child = findAnchor(child.children))) { - return child - } - } - } -} - -var _Vue; - -function install (Vue) { - if (install.installed && _Vue === Vue) { return } - install.installed = true; - - _Vue = Vue; - - var isDef = function (v) { return v !== undefined; }; - - var registerInstance = function (vm, callVal) { - var i = vm.$options._parentVnode; - if (isDef(i) && isDef(i = i.data) && isDef(i = i.registerRouteInstance)) { - i(vm, callVal); - } - }; - - Vue.mixin({ - beforeCreate: function beforeCreate () { - if (isDef(this.$options.router)) { - this._routerRoot = this; - this._router = this.$options.router; - this._router.init(this); - Vue.util.defineReactive(this, '_route', this._router.history.current); - } else { - this._routerRoot = (this.$parent && this.$parent._routerRoot) || this; - } - registerInstance(this, this); - }, - destroyed: function destroyed () { - registerInstance(this); - } - }); - - Object.defineProperty(Vue.prototype, '$router', { - get: function get () { return this._routerRoot._router } - }); - - Object.defineProperty(Vue.prototype, '$route', { - get: function get () { return this._routerRoot._route } - }); - - Vue.component('RouterView', View); - Vue.component('RouterLink', Link); - - var strats = Vue.config.optionMergeStrategies; - // use the same hook merging strategy for route hooks - strats.beforeRouteEnter = strats.beforeRouteLeave = strats.beforeRouteUpdate = strats.created; -} - -/* */ - -var inBrowser = typeof window !== 'undefined'; - -/* */ - -function createRouteMap ( - routes, - oldPathList, - oldPathMap, - oldNameMap -) { - // the path list is used to control path matching priority - var pathList = oldPathList || []; - // $flow-disable-line - var pathMap = oldPathMap || Object.create(null); - // $flow-disable-line - var nameMap = oldNameMap || Object.create(null); - - routes.forEach(function (route) { - addRouteRecord(pathList, pathMap, nameMap, route); - }); - - // ensure wildcard routes are always at the end - for (var i = 0, l = pathList.length; i < l; i++) { - if (pathList[i] === '*') { - pathList.push(pathList.splice(i, 1)[0]); - l--; - i--; - } - } - - { - // warn if routes do not include leading slashes - var found = pathList - // check for missing leading slash - .filter(function (path) { return path && path.charAt(0) !== '*' && path.charAt(0) !== '/'; }); - - if (found.length > 0) { - var pathNames = found.map(function (path) { return ("- " + path); }).join('\n'); - warn(false, ("Non-nested routes must include a leading slash character. Fix the following routes: \n" + pathNames)); - } - } - - return { - pathList: pathList, - pathMap: pathMap, - nameMap: nameMap - } -} - -function addRouteRecord ( - pathList, - pathMap, - nameMap, - route, - parent, - matchAs -) { - var path = route.path; - var name = route.name; - { - assert(path != null, "\"path\" is required in a route configuration."); - assert( - typeof route.component !== 'string', - "route config \"component\" for path: " + (String( - path || name - )) + " cannot be a " + "string id. Use an actual component instead." - ); - } - - var pathToRegexpOptions = - route.pathToRegexpOptions || {}; - var normalizedPath = normalizePath(path, parent, pathToRegexpOptions.strict); - - if (typeof route.caseSensitive === 'boolean') { - pathToRegexpOptions.sensitive = route.caseSensitive; - } - - var record = { - path: normalizedPath, - regex: compileRouteRegex(normalizedPath, pathToRegexpOptions), - components: route.components || { default: route.component }, - instances: {}, - name: name, - parent: parent, - matchAs: matchAs, - redirect: route.redirect, - beforeEnter: route.beforeEnter, - meta: route.meta || {}, - props: - route.props == null - ? {} - : route.components - ? route.props - : { default: route.props } - }; - - if (route.children) { - // Warn if route is named, does not redirect and has a default child route. - // If users navigate to this route by name, the default child will - // not be rendered (GH Issue #629) - { - if ( - route.name && - !route.redirect && - route.children.some(function (child) { return /^\/?$/.test(child.path); }) - ) { - warn( - false, - "Named Route '" + (route.name) + "' has a default child route. " + - "When navigating to this named route (:to=\"{name: '" + (route.name) + "'\"), " + - "the default child route will not be rendered. Remove the name from " + - "this route and use the name of the default child route for named " + - "links instead." - ); - } - } - route.children.forEach(function (child) { - var childMatchAs = matchAs - ? cleanPath((matchAs + "/" + (child.path))) - : undefined; - addRouteRecord(pathList, pathMap, nameMap, child, record, childMatchAs); - }); - } - - if (!pathMap[record.path]) { - pathList.push(record.path); - pathMap[record.path] = record; - } - - if (route.alias !== undefined) { - var aliases = Array.isArray(route.alias) ? route.alias : [route.alias]; - for (var i = 0; i < aliases.length; ++i) { - var alias = aliases[i]; - if ( alias === path) { - warn( - false, - ("Found an alias with the same value as the path: \"" + path + "\". You have to remove that alias. It will be ignored in development.") - ); - // skip in dev to make it work - continue - } - - var aliasRoute = { - path: alias, - children: route.children - }; - addRouteRecord( - pathList, - pathMap, - nameMap, - aliasRoute, - parent, - record.path || '/' // matchAs - ); - } - } - - if (name) { - if (!nameMap[name]) { - nameMap[name] = record; - } else if ( !matchAs) { - warn( - false, - "Duplicate named routes definition: " + - "{ name: \"" + name + "\", path: \"" + (record.path) + "\" }" - ); - } - } -} - -function compileRouteRegex ( - path, - pathToRegexpOptions -) { - var regex = pathToRegexp_1(path, [], pathToRegexpOptions); - { - var keys = Object.create(null); - regex.keys.forEach(function (key) { - warn( - !keys[key.name], - ("Duplicate param keys in route with path: \"" + path + "\"") - ); - keys[key.name] = true; - }); - } - return regex -} - -function normalizePath ( - path, - parent, - strict -) { - if (!strict) { path = path.replace(/\/$/, ''); } - if (path[0] === '/') { return path } - if (parent == null) { return path } - return cleanPath(((parent.path) + "/" + path)) -} - -/* */ - - - -function createMatcher ( - routes, - router -) { - var ref = createRouteMap(routes); - var pathList = ref.pathList; - var pathMap = ref.pathMap; - var nameMap = ref.nameMap; - - function addRoutes (routes) { - createRouteMap(routes, pathList, pathMap, nameMap); - } - - function match ( - raw, - currentRoute, - redirectedFrom - ) { - var location = normalizeLocation(raw, currentRoute, false, router); - var name = location.name; - - if (name) { - var record = nameMap[name]; - { - warn(record, ("Route with name '" + name + "' does not exist")); - } - if (!record) { return _createRoute(null, location) } - var paramNames = record.regex.keys - .filter(function (key) { return !key.optional; }) - .map(function (key) { return key.name; }); - - if (typeof location.params !== 'object') { - location.params = {}; - } - - if (currentRoute && typeof currentRoute.params === 'object') { - for (var key in currentRoute.params) { - if (!(key in location.params) && paramNames.indexOf(key) > -1) { - location.params[key] = currentRoute.params[key]; - } - } - } - - location.path = fillParams(record.path, location.params, ("named route \"" + name + "\"")); - return _createRoute(record, location, redirectedFrom) - } else if (location.path) { - location.params = {}; - for (var i = 0; i < pathList.length; i++) { - var path = pathList[i]; - var record$1 = pathMap[path]; - if (matchRoute(record$1.regex, location.path, location.params)) { - return _createRoute(record$1, location, redirectedFrom) - } - } - } - // no match - return _createRoute(null, location) - } - - function redirect ( - record, - location - ) { - var originalRedirect = record.redirect; - var redirect = typeof originalRedirect === 'function' - ? originalRedirect(createRoute(record, location, null, router)) - : originalRedirect; - - if (typeof redirect === 'string') { - redirect = { path: redirect }; - } - - if (!redirect || typeof redirect !== 'object') { - { - warn( - false, ("invalid redirect option: " + (JSON.stringify(redirect))) - ); - } - return _createRoute(null, location) - } - - var re = redirect; - var name = re.name; - var path = re.path; - var query = location.query; - var hash = location.hash; - var params = location.params; - query = re.hasOwnProperty('query') ? re.query : query; - hash = re.hasOwnProperty('hash') ? re.hash : hash; - params = re.hasOwnProperty('params') ? re.params : params; - - if (name) { - // resolved named direct - var targetRecord = nameMap[name]; - { - assert(targetRecord, ("redirect failed: named route \"" + name + "\" not found.")); - } - return match({ - _normalized: true, - name: name, - query: query, - hash: hash, - params: params - }, undefined, location) - } else if (path) { - // 1. resolve relative redirect - var rawPath = resolveRecordPath(path, record); - // 2. resolve params - var resolvedPath = fillParams(rawPath, params, ("redirect route with path \"" + rawPath + "\"")); - // 3. rematch with existing query and hash - return match({ - _normalized: true, - path: resolvedPath, - query: query, - hash: hash - }, undefined, location) - } else { - { - warn(false, ("invalid redirect option: " + (JSON.stringify(redirect)))); - } - return _createRoute(null, location) - } - } - - function alias ( - record, - location, - matchAs - ) { - var aliasedPath = fillParams(matchAs, location.params, ("aliased route with path \"" + matchAs + "\"")); - var aliasedMatch = match({ - _normalized: true, - path: aliasedPath - }); - if (aliasedMatch) { - var matched = aliasedMatch.matched; - var aliasedRecord = matched[matched.length - 1]; - location.params = aliasedMatch.params; - return _createRoute(aliasedRecord, location) - } - return _createRoute(null, location) - } - - function _createRoute ( - record, - location, - redirectedFrom - ) { - if (record && record.redirect) { - return redirect(record, redirectedFrom || location) - } - if (record && record.matchAs) { - return alias(record, location, record.matchAs) - } - return createRoute(record, location, redirectedFrom, router) - } - - return { - match: match, - addRoutes: addRoutes - } -} - -function matchRoute ( - regex, - path, - params -) { - var m = path.match(regex); - - if (!m) { - return false - } else if (!params) { - return true - } - - for (var i = 1, len = m.length; i < len; ++i) { - var key = regex.keys[i - 1]; - var val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i]; - if (key) { - // Fix #1994: using * with props: true generates a param named 0 - params[key.name || 'pathMatch'] = val; - } - } - - return true -} - -function resolveRecordPath (path, record) { - return resolvePath(path, record.parent ? record.parent.path : '/', true) -} - -/* */ - -// use User Timing api (if present) for more accurate key precision -var Time = - inBrowser && window.performance && window.performance.now - ? window.performance - : Date; - -function genStateKey () { - return Time.now().toFixed(3) -} - -var _key = genStateKey(); - -function getStateKey () { - return _key -} - -function setStateKey (key) { - return (_key = key) -} - -/* */ - -var positionStore = Object.create(null); - -function setupScroll () { - // Fix for #1585 for Firefox - // Fix for #2195 Add optional third attribute to workaround a bug in safari https://bugs.webkit.org/show_bug.cgi?id=182678 - // Fix for #2774 Support for apps loaded from Windows file shares not mapped to network drives: replaced location.origin with - // window.location.protocol + '//' + window.location.host - // location.host contains the port and location.hostname doesn't - var protocolAndPath = window.location.protocol + '//' + window.location.host; - var absolutePath = window.location.href.replace(protocolAndPath, ''); - window.history.replaceState({ key: getStateKey() }, '', absolutePath); - window.addEventListener('popstate', function (e) { - saveScrollPosition(); - if (e.state && e.state.key) { - setStateKey(e.state.key); - } - }); -} - -function handleScroll ( - router, - to, - from, - isPop -) { - if (!router.app) { - return - } - - var behavior = router.options.scrollBehavior; - if (!behavior) { - return - } - - { - assert(typeof behavior === 'function', "scrollBehavior must be a function"); - } - - // wait until re-render finishes before scrolling - router.app.$nextTick(function () { - var position = getScrollPosition(); - var shouldScroll = behavior.call( - router, - to, - from, - isPop ? position : null - ); - - if (!shouldScroll) { - return - } - - if (typeof shouldScroll.then === 'function') { - shouldScroll - .then(function (shouldScroll) { - scrollToPosition((shouldScroll), position); - }) - .catch(function (err) { - { - assert(false, err.toString()); - } - }); - } else { - scrollToPosition(shouldScroll, position); - } - }); -} - -function saveScrollPosition () { - var key = getStateKey(); - if (key) { - positionStore[key] = { - x: window.pageXOffset, - y: window.pageYOffset - }; - } -} - -function getScrollPosition () { - var key = getStateKey(); - if (key) { - return positionStore[key] - } -} - -function getElementPosition (el, offset) { - var docEl = document.documentElement; - var docRect = docEl.getBoundingClientRect(); - var elRect = el.getBoundingClientRect(); - return { - x: elRect.left - docRect.left - offset.x, - y: elRect.top - docRect.top - offset.y - } -} - -function isValidPosition (obj) { - return isNumber(obj.x) || isNumber(obj.y) -} - -function normalizePosition (obj) { - return { - x: isNumber(obj.x) ? obj.x : window.pageXOffset, - y: isNumber(obj.y) ? obj.y : window.pageYOffset - } -} - -function normalizeOffset (obj) { - return { - x: isNumber(obj.x) ? obj.x : 0, - y: isNumber(obj.y) ? obj.y : 0 - } -} - -function isNumber (v) { - return typeof v === 'number' -} - -var hashStartsWithNumberRE = /^#\d/; - -function scrollToPosition (shouldScroll, position) { - var isObject = typeof shouldScroll === 'object'; - if (isObject && typeof shouldScroll.selector === 'string') { - // getElementById would still fail if the selector contains a more complicated query like #main[data-attr] - // but at the same time, it doesn't make much sense to select an element with an id and an extra selector - var el = hashStartsWithNumberRE.test(shouldScroll.selector) // $flow-disable-line - ? document.getElementById(shouldScroll.selector.slice(1)) // $flow-disable-line - : document.querySelector(shouldScroll.selector); - - if (el) { - var offset = - shouldScroll.offset && typeof shouldScroll.offset === 'object' - ? shouldScroll.offset - : {}; - offset = normalizeOffset(offset); - position = getElementPosition(el, offset); - } else if (isValidPosition(shouldScroll)) { - position = normalizePosition(shouldScroll); - } - } else if (isObject && isValidPosition(shouldScroll)) { - position = normalizePosition(shouldScroll); - } - - if (position) { - window.scrollTo(position.x, position.y); - } -} - -/* */ - -var supportsPushState = - inBrowser && - (function () { - var ua = window.navigator.userAgent; - - if ( - (ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) && - ua.indexOf('Mobile Safari') !== -1 && - ua.indexOf('Chrome') === -1 && - ua.indexOf('Windows Phone') === -1 - ) { - return false - } - - return window.history && 'pushState' in window.history - })(); - -function pushState (url, replace) { - saveScrollPosition(); - // try...catch the pushState call to get around Safari - // DOM Exception 18 where it limits to 100 pushState calls - var history = window.history; - try { - if (replace) { - history.replaceState({ key: getStateKey() }, '', url); - } else { - history.pushState({ key: setStateKey(genStateKey()) }, '', url); - } - } catch (e) { - window.location[replace ? 'replace' : 'assign'](url); - } -} - -function replaceState (url) { - pushState(url, true); -} - -/* */ - -function runQueue (queue, fn, cb) { - var step = function (index) { - if (index >= queue.length) { - cb(); - } else { - if (queue[index]) { - fn(queue[index], function () { - step(index + 1); - }); - } else { - step(index + 1); - } - } - }; - step(0); -} - -/* */ - -function resolveAsyncComponents (matched) { - return function (to, from, next) { - var hasAsync = false; - var pending = 0; - var error = null; - - flatMapComponents(matched, function (def, _, match, key) { - // if it's a function and doesn't have cid attached, - // assume it's an async component resolve function. - // we are not using Vue's default async resolving mechanism because - // we want to halt the navigation until the incoming component has been - // resolved. - if (typeof def === 'function' && def.cid === undefined) { - hasAsync = true; - pending++; - - var resolve = once(function (resolvedDef) { - if (isESModule(resolvedDef)) { - resolvedDef = resolvedDef.default; - } - // save resolved on async factory in case it's used elsewhere - def.resolved = typeof resolvedDef === 'function' - ? resolvedDef - : _Vue.extend(resolvedDef); - match.components[key] = resolvedDef; - pending--; - if (pending <= 0) { - next(); - } - }); - - var reject = once(function (reason) { - var msg = "Failed to resolve async component " + key + ": " + reason; - warn(false, msg); - if (!error) { - error = isError(reason) - ? reason - : new Error(msg); - next(error); - } - }); - - var res; - try { - res = def(resolve, reject); - } catch (e) { - reject(e); - } - if (res) { - if (typeof res.then === 'function') { - res.then(resolve, reject); - } else { - // new syntax in Vue 2.3 - var comp = res.component; - if (comp && typeof comp.then === 'function') { - comp.then(resolve, reject); - } - } - } - } - }); - - if (!hasAsync) { next(); } - } -} - -function flatMapComponents ( - matched, - fn -) { - return flatten(matched.map(function (m) { - return Object.keys(m.components).map(function (key) { return fn( - m.components[key], - m.instances[key], - m, key - ); }) - })) -} - -function flatten (arr) { - return Array.prototype.concat.apply([], arr) -} - -var hasSymbol = - typeof Symbol === 'function' && - typeof Symbol.toStringTag === 'symbol'; - -function isESModule (obj) { - return obj.__esModule || (hasSymbol && obj[Symbol.toStringTag] === 'Module') -} - -// in Webpack 2, require.ensure now also returns a Promise -// so the resolve/reject functions may get called an extra time -// if the user uses an arrow function shorthand that happens to -// return that Promise. -function once (fn) { - var called = false; - return function () { - var args = [], len = arguments.length; - while ( len-- ) args[ len ] = arguments[ len ]; - - if (called) { return } - called = true; - return fn.apply(this, args) - } -} - -var NavigationDuplicated = /*@__PURE__*/(function (Error) { - function NavigationDuplicated (normalizedLocation) { - Error.call(this); - this.name = this._name = 'NavigationDuplicated'; - // passing the message to super() doesn't seem to work in the transpiled version - this.message = "Navigating to current location (\"" + (normalizedLocation.fullPath) + "\") is not allowed"; - // add a stack property so services like Sentry can correctly display it - Object.defineProperty(this, 'stack', { - value: new Error().stack, - writable: true, - configurable: true - }); - // we could also have used - // Error.captureStackTrace(this, this.constructor) - // but it only exists on node and chrome - } - - if ( Error ) NavigationDuplicated.__proto__ = Error; - NavigationDuplicated.prototype = Object.create( Error && Error.prototype ); - NavigationDuplicated.prototype.constructor = NavigationDuplicated; - - return NavigationDuplicated; -}(Error)); - -// support IE9 -NavigationDuplicated._name = 'NavigationDuplicated'; - -/* */ - -var History = function History (router, base) { - this.router = router; - this.base = normalizeBase(base); - // start with a route object that stands for "nowhere" - this.current = START; - this.pending = null; - this.ready = false; - this.readyCbs = []; - this.readyErrorCbs = []; - this.errorCbs = []; -}; - -History.prototype.listen = function listen (cb) { - this.cb = cb; -}; - -History.prototype.onReady = function onReady (cb, errorCb) { - if (this.ready) { - cb(); - } else { - this.readyCbs.push(cb); - if (errorCb) { - this.readyErrorCbs.push(errorCb); - } - } -}; - -History.prototype.onError = function onError (errorCb) { - this.errorCbs.push(errorCb); -}; - -History.prototype.transitionTo = function transitionTo ( - location, - onComplete, - onAbort -) { - var this$1 = this; - - var route = this.router.match(location, this.current); - this.confirmTransition( - route, - function () { - this$1.updateRoute(route); - onComplete && onComplete(route); - this$1.ensureURL(); - - // fire ready cbs once - if (!this$1.ready) { - this$1.ready = true; - this$1.readyCbs.forEach(function (cb) { - cb(route); - }); - } - }, - function (err) { - if (onAbort) { - onAbort(err); - } - if (err && !this$1.ready) { - this$1.ready = true; - this$1.readyErrorCbs.forEach(function (cb) { - cb(err); - }); - } - } - ); -}; - -History.prototype.confirmTransition = function confirmTransition (route, onComplete, onAbort) { - var this$1 = this; - - var current = this.current; - var abort = function (err) { - // after merging https://github.com/vuejs/vue-router/pull/2771 we - // When the user navigates through history through back/forward buttons - // we do not want to throw the error. We only throw it if directly calling - // push/replace. That's why it's not included in isError - if (!isExtendedError(NavigationDuplicated, err) && isError(err)) { - if (this$1.errorCbs.length) { - this$1.errorCbs.forEach(function (cb) { - cb(err); - }); - } else { - warn(false, 'uncaught error during route navigation:'); - console.error(err); - } - } - onAbort && onAbort(err); - }; - if ( - isSameRoute(route, current) && - // in the case the route map has been dynamically appended to - route.matched.length === current.matched.length - ) { - this.ensureURL(); - return abort(new NavigationDuplicated(route)) - } - - var ref = resolveQueue( - this.current.matched, - route.matched - ); - var updated = ref.updated; - var deactivated = ref.deactivated; - var activated = ref.activated; - - var queue = [].concat( - // in-component leave guards - extractLeaveGuards(deactivated), - // global before hooks - this.router.beforeHooks, - // in-component update hooks - extractUpdateHooks(updated), - // in-config enter guards - activated.map(function (m) { return m.beforeEnter; }), - // async components - resolveAsyncComponents(activated) - ); - - this.pending = route; - var iterator = function (hook, next) { - if (this$1.pending !== route) { - return abort() - } - try { - hook(route, current, function (to) { - if (to === false || isError(to)) { - // next(false) -> abort navigation, ensure current URL - this$1.ensureURL(true); - abort(to); - } else if ( - typeof to === 'string' || - (typeof to === 'object' && - (typeof to.path === 'string' || typeof to.name === 'string')) - ) { - // next('/') or next({ path: '/' }) -> redirect - abort(); - if (typeof to === 'object' && to.replace) { - this$1.replace(to); - } else { - this$1.push(to); - } - } else { - // confirm transition and pass on the value - next(to); - } - }); - } catch (e) { - abort(e); - } - }; - - runQueue(queue, iterator, function () { - var postEnterCbs = []; - var isValid = function () { return this$1.current === route; }; - // wait until async components are resolved before - // extracting in-component enter guards - var enterGuards = extractEnterGuards(activated, postEnterCbs, isValid); - var queue = enterGuards.concat(this$1.router.resolveHooks); - runQueue(queue, iterator, function () { - if (this$1.pending !== route) { - return abort() - } - this$1.pending = null; - onComplete(route); - if (this$1.router.app) { - this$1.router.app.$nextTick(function () { - postEnterCbs.forEach(function (cb) { - cb(); - }); - }); - } - }); - }); -}; - -History.prototype.updateRoute = function updateRoute (route) { - var prev = this.current; - this.current = route; - this.cb && this.cb(route); - this.router.afterHooks.forEach(function (hook) { - hook && hook(route, prev); - }); -}; - -function normalizeBase (base) { - if (!base) { - if (inBrowser) { - // respect tag - var baseEl = document.querySelector('base'); - base = (baseEl && baseEl.getAttribute('href')) || '/'; - // strip full URL origin - base = base.replace(/^https?:\/\/[^\/]+/, ''); - } else { - base = '/'; - } - } - // make sure there's the starting slash - if (base.charAt(0) !== '/') { - base = '/' + base; - } - // remove trailing slash - return base.replace(/\/$/, '') -} - -function resolveQueue ( - current, - next -) { - var i; - var max = Math.max(current.length, next.length); - for (i = 0; i < max; i++) { - if (current[i] !== next[i]) { - break - } - } - return { - updated: next.slice(0, i), - activated: next.slice(i), - deactivated: current.slice(i) - } -} - -function extractGuards ( - records, - name, - bind, - reverse -) { - var guards = flatMapComponents(records, function (def, instance, match, key) { - var guard = extractGuard(def, name); - if (guard) { - return Array.isArray(guard) - ? guard.map(function (guard) { return bind(guard, instance, match, key); }) - : bind(guard, instance, match, key) - } - }); - return flatten(reverse ? guards.reverse() : guards) -} - -function extractGuard ( - def, - key -) { - if (typeof def !== 'function') { - // extend now so that global mixins are applied. - def = _Vue.extend(def); - } - return def.options[key] -} - -function extractLeaveGuards (deactivated) { - return extractGuards(deactivated, 'beforeRouteLeave', bindGuard, true) -} - -function extractUpdateHooks (updated) { - return extractGuards(updated, 'beforeRouteUpdate', bindGuard) -} - -function bindGuard (guard, instance) { - if (instance) { - return function boundRouteGuard () { - return guard.apply(instance, arguments) - } - } -} - -function extractEnterGuards ( - activated, - cbs, - isValid -) { - return extractGuards( - activated, - 'beforeRouteEnter', - function (guard, _, match, key) { - return bindEnterGuard(guard, match, key, cbs, isValid) - } - ) -} - -function bindEnterGuard ( - guard, - match, - key, - cbs, - isValid -) { - return function routeEnterGuard (to, from, next) { - return guard(to, from, function (cb) { - if (typeof cb === 'function') { - cbs.push(function () { - // #750 - // if a router-view is wrapped with an out-in transition, - // the instance may not have been registered at this time. - // we will need to poll for registration until current route - // is no longer valid. - poll(cb, match.instances, key, isValid); - }); - } - next(cb); - }) - } -} - -function poll ( - cb, // somehow flow cannot infer this is a function - instances, - key, - isValid -) { - if ( - instances[key] && - !instances[key]._isBeingDestroyed // do not reuse being destroyed instance - ) { - cb(instances[key]); - } else if (isValid()) { - setTimeout(function () { - poll(cb, instances, key, isValid); - }, 16); - } -} - -/* */ - -var HTML5History = /*@__PURE__*/(function (History) { - function HTML5History (router, base) { - var this$1 = this; - - History.call(this, router, base); - - var expectScroll = router.options.scrollBehavior; - var supportsScroll = supportsPushState && expectScroll; - - if (supportsScroll) { - setupScroll(); - } - - var initLocation = getLocation(this.base); - window.addEventListener('popstate', function (e) { - var current = this$1.current; - - // Avoiding first `popstate` event dispatched in some browsers but first - // history route not updated since async guard at the same time. - var location = getLocation(this$1.base); - if (this$1.current === START && location === initLocation) { - return - } - - this$1.transitionTo(location, function (route) { - if (supportsScroll) { - handleScroll(router, route, current, true); - } - }); - }); - } - - if ( History ) HTML5History.__proto__ = History; - HTML5History.prototype = Object.create( History && History.prototype ); - HTML5History.prototype.constructor = HTML5History; - - HTML5History.prototype.go = function go (n) { - window.history.go(n); - }; - - HTML5History.prototype.push = function push (location, onComplete, onAbort) { - var this$1 = this; - - var ref = this; - var fromRoute = ref.current; - this.transitionTo(location, function (route) { - pushState(cleanPath(this$1.base + route.fullPath)); - handleScroll(this$1.router, route, fromRoute, false); - onComplete && onComplete(route); - }, onAbort); - }; - - HTML5History.prototype.replace = function replace (location, onComplete, onAbort) { - var this$1 = this; - - var ref = this; - var fromRoute = ref.current; - this.transitionTo(location, function (route) { - replaceState(cleanPath(this$1.base + route.fullPath)); - handleScroll(this$1.router, route, fromRoute, false); - onComplete && onComplete(route); - }, onAbort); - }; - - HTML5History.prototype.ensureURL = function ensureURL (push) { - if (getLocation(this.base) !== this.current.fullPath) { - var current = cleanPath(this.base + this.current.fullPath); - push ? pushState(current) : replaceState(current); - } - }; - - HTML5History.prototype.getCurrentLocation = function getCurrentLocation () { - return getLocation(this.base) - }; - - return HTML5History; -}(History)); - -function getLocation (base) { - var path = decodeURI(window.location.pathname); - if (base && path.indexOf(base) === 0) { - path = path.slice(base.length); - } - return (path || '/') + window.location.search + window.location.hash -} - -/* */ - -var HashHistory = /*@__PURE__*/(function (History) { - function HashHistory (router, base, fallback) { - History.call(this, router, base); - // check history fallback deeplinking - if (fallback && checkFallback(this.base)) { - return - } - ensureSlash(); - } - - if ( History ) HashHistory.__proto__ = History; - HashHistory.prototype = Object.create( History && History.prototype ); - HashHistory.prototype.constructor = HashHistory; - - // this is delayed until the app mounts - // to avoid the hashchange listener being fired too early - HashHistory.prototype.setupListeners = function setupListeners () { - var this$1 = this; - - var router = this.router; - var expectScroll = router.options.scrollBehavior; - var supportsScroll = supportsPushState && expectScroll; - - if (supportsScroll) { - setupScroll(); - } - - window.addEventListener( - supportsPushState ? 'popstate' : 'hashchange', - function () { - var current = this$1.current; - if (!ensureSlash()) { - return - } - this$1.transitionTo(getHash(), function (route) { - if (supportsScroll) { - handleScroll(this$1.router, route, current, true); - } - if (!supportsPushState) { - replaceHash(route.fullPath); - } - }); - } - ); - }; - - HashHistory.prototype.push = function push (location, onComplete, onAbort) { - var this$1 = this; - - var ref = this; - var fromRoute = ref.current; - this.transitionTo( - location, - function (route) { - pushHash(route.fullPath); - handleScroll(this$1.router, route, fromRoute, false); - onComplete && onComplete(route); - }, - onAbort - ); - }; - - HashHistory.prototype.replace = function replace (location, onComplete, onAbort) { - var this$1 = this; - - var ref = this; - var fromRoute = ref.current; - this.transitionTo( - location, - function (route) { - replaceHash(route.fullPath); - handleScroll(this$1.router, route, fromRoute, false); - onComplete && onComplete(route); - }, - onAbort - ); - }; - - HashHistory.prototype.go = function go (n) { - window.history.go(n); - }; - - HashHistory.prototype.ensureURL = function ensureURL (push) { - var current = this.current.fullPath; - if (getHash() !== current) { - push ? pushHash(current) : replaceHash(current); - } - }; - - HashHistory.prototype.getCurrentLocation = function getCurrentLocation () { - return getHash() - }; - - return HashHistory; -}(History)); - -function checkFallback (base) { - var location = getLocation(base); - if (!/^\/#/.test(location)) { - window.location.replace(cleanPath(base + '/#' + location)); - return true - } -} - -function ensureSlash () { - var path = getHash(); - if (path.charAt(0) === '/') { - return true - } - replaceHash('/' + path); - return false -} - -function getHash () { - // We can't use window.location.hash here because it's not - // consistent across browsers - Firefox will pre-decode it! - var href = window.location.href; - var index = href.indexOf('#'); - // empty path - if (index < 0) { return '' } - - href = href.slice(index + 1); - // decode the hash but not the search or hash - // as search(query) is already decoded - // https://github.com/vuejs/vue-router/issues/2708 - var searchIndex = href.indexOf('?'); - if (searchIndex < 0) { - var hashIndex = href.indexOf('#'); - if (hashIndex > -1) { - href = decodeURI(href.slice(0, hashIndex)) + href.slice(hashIndex); - } else { href = decodeURI(href); } - } else { - if (searchIndex > -1) { - href = decodeURI(href.slice(0, searchIndex)) + href.slice(searchIndex); - } - } - - return href -} - -function getUrl (path) { - var href = window.location.href; - var i = href.indexOf('#'); - var base = i >= 0 ? href.slice(0, i) : href; - return (base + "#" + path) -} - -function pushHash (path) { - if (supportsPushState) { - pushState(getUrl(path)); - } else { - window.location.hash = path; - } -} - -function replaceHash (path) { - if (supportsPushState) { - replaceState(getUrl(path)); - } else { - window.location.replace(getUrl(path)); - } -} - -/* */ - -var AbstractHistory = /*@__PURE__*/(function (History) { - function AbstractHistory (router, base) { - History.call(this, router, base); - this.stack = []; - this.index = -1; - } - - if ( History ) AbstractHistory.__proto__ = History; - AbstractHistory.prototype = Object.create( History && History.prototype ); - AbstractHistory.prototype.constructor = AbstractHistory; - - AbstractHistory.prototype.push = function push (location, onComplete, onAbort) { - var this$1 = this; - - this.transitionTo( - location, - function (route) { - this$1.stack = this$1.stack.slice(0, this$1.index + 1).concat(route); - this$1.index++; - onComplete && onComplete(route); - }, - onAbort - ); - }; - - AbstractHistory.prototype.replace = function replace (location, onComplete, onAbort) { - var this$1 = this; - - this.transitionTo( - location, - function (route) { - this$1.stack = this$1.stack.slice(0, this$1.index).concat(route); - onComplete && onComplete(route); - }, - onAbort - ); - }; - - AbstractHistory.prototype.go = function go (n) { - var this$1 = this; - - var targetIndex = this.index + n; - if (targetIndex < 0 || targetIndex >= this.stack.length) { - return - } - var route = this.stack[targetIndex]; - this.confirmTransition( - route, - function () { - this$1.index = targetIndex; - this$1.updateRoute(route); - }, - function (err) { - if (isExtendedError(NavigationDuplicated, err)) { - this$1.index = targetIndex; - } - } - ); - }; - - AbstractHistory.prototype.getCurrentLocation = function getCurrentLocation () { - var current = this.stack[this.stack.length - 1]; - return current ? current.fullPath : '/' - }; - - AbstractHistory.prototype.ensureURL = function ensureURL () { - // noop - }; - - return AbstractHistory; -}(History)); - -/* */ - - - -var VueRouter = function VueRouter (options) { - if ( options === void 0 ) options = {}; - - this.app = null; - this.apps = []; - this.options = options; - this.beforeHooks = []; - this.resolveHooks = []; - this.afterHooks = []; - this.matcher = createMatcher(options.routes || [], this); - - var mode = options.mode || 'hash'; - this.fallback = mode === 'history' && !supportsPushState && options.fallback !== false; - if (this.fallback) { - mode = 'hash'; - } - if (!inBrowser) { - mode = 'abstract'; - } - this.mode = mode; - - switch (mode) { - case 'history': - this.history = new HTML5History(this, options.base); - break - case 'hash': - this.history = new HashHistory(this, options.base, this.fallback); - break - case 'abstract': - this.history = new AbstractHistory(this, options.base); - break - default: - { - assert(false, ("invalid mode: " + mode)); - } - } -}; - -var prototypeAccessors = { currentRoute: { configurable: true } }; - -VueRouter.prototype.match = function match ( - raw, - current, - redirectedFrom -) { - return this.matcher.match(raw, current, redirectedFrom) -}; - -prototypeAccessors.currentRoute.get = function () { - return this.history && this.history.current -}; - -VueRouter.prototype.init = function init (app /* Vue component instance */) { - var this$1 = this; - - assert( - install.installed, - "not installed. Make sure to call `Vue.use(VueRouter)` " + - "before creating root instance." - ); - - this.apps.push(app); - - // set up app destroyed handler - // https://github.com/vuejs/vue-router/issues/2639 - app.$once('hook:destroyed', function () { - // clean out app from this.apps array once destroyed - var index = this$1.apps.indexOf(app); - if (index > -1) { this$1.apps.splice(index, 1); } - // ensure we still have a main app or null if no apps - // we do not release the router so it can be reused - if (this$1.app === app) { this$1.app = this$1.apps[0] || null; } - }); - - // main app previously initialized - // return as we don't need to set up new history listener - if (this.app) { - return - } - - this.app = app; - - var history = this.history; - - if (history instanceof HTML5History) { - history.transitionTo(history.getCurrentLocation()); - } else if (history instanceof HashHistory) { - var setupHashListener = function () { - history.setupListeners(); - }; - history.transitionTo( - history.getCurrentLocation(), - setupHashListener, - setupHashListener - ); - } - - history.listen(function (route) { - this$1.apps.forEach(function (app) { - app._route = route; - }); - }); -}; - -VueRouter.prototype.beforeEach = function beforeEach (fn) { - return registerHook(this.beforeHooks, fn) -}; - -VueRouter.prototype.beforeResolve = function beforeResolve (fn) { - return registerHook(this.resolveHooks, fn) -}; - -VueRouter.prototype.afterEach = function afterEach (fn) { - return registerHook(this.afterHooks, fn) -}; - -VueRouter.prototype.onReady = function onReady (cb, errorCb) { - this.history.onReady(cb, errorCb); -}; - -VueRouter.prototype.onError = function onError (errorCb) { - this.history.onError(errorCb); -}; - -VueRouter.prototype.push = function push (location, onComplete, onAbort) { - var this$1 = this; - - // $flow-disable-line - if (!onComplete && !onAbort && typeof Promise !== 'undefined') { - return new Promise(function (resolve, reject) { - this$1.history.push(location, resolve, reject); - }) - } else { - this.history.push(location, onComplete, onAbort); - } -}; - -VueRouter.prototype.replace = function replace (location, onComplete, onAbort) { - var this$1 = this; - - // $flow-disable-line - if (!onComplete && !onAbort && typeof Promise !== 'undefined') { - return new Promise(function (resolve, reject) { - this$1.history.replace(location, resolve, reject); - }) - } else { - this.history.replace(location, onComplete, onAbort); - } -}; - -VueRouter.prototype.go = function go (n) { - this.history.go(n); -}; - -VueRouter.prototype.back = function back () { - this.go(-1); -}; - -VueRouter.prototype.forward = function forward () { - this.go(1); -}; - -VueRouter.prototype.getMatchedComponents = function getMatchedComponents (to) { - var route = to - ? to.matched - ? to - : this.resolve(to).route - : this.currentRoute; - if (!route) { - return [] - } - return [].concat.apply([], route.matched.map(function (m) { - return Object.keys(m.components).map(function (key) { - return m.components[key] - }) - })) -}; - -VueRouter.prototype.resolve = function resolve ( - to, - current, - append -) { - current = current || this.history.current; - var location = normalizeLocation( - to, - current, - append, - this - ); - var route = this.match(location, current); - var fullPath = route.redirectedFrom || route.fullPath; - var base = this.history.base; - var href = createHref(base, fullPath, this.mode); - return { - location: location, - route: route, - href: href, - // for backwards compat - normalizedTo: location, - resolved: route - } -}; - -VueRouter.prototype.addRoutes = function addRoutes (routes) { - this.matcher.addRoutes(routes); - if (this.history.current !== START) { - this.history.transitionTo(this.history.getCurrentLocation()); - } -}; - -Object.defineProperties( VueRouter.prototype, prototypeAccessors ); - -function registerHook (list, fn) { - list.push(fn); - return function () { - var i = list.indexOf(fn); - if (i > -1) { list.splice(i, 1); } - } -} - -function createHref (base, fullPath, mode) { - var path = mode === 'hash' ? '#' + fullPath : fullPath; - return base ? cleanPath(base + '/' + path) : path -} - -VueRouter.install = install; -VueRouter.version = '3.1.3'; - -if (inBrowser && window.Vue) { - window.Vue.use(VueRouter); -} - -export default VueRouter; diff --git a/__tests__/integration/exclude/web_modules/vue.js b/__tests__/integration/exclude/web_modules/vue.js deleted file mode 100644 index 2f06f9c483..0000000000 --- a/__tests__/integration/exclude/web_modules/vue.js +++ /dev/null @@ -1,8424 +0,0 @@ -/*! - * Vue.js v2.6.10 - * (c) 2014-2019 Evan You - * Released under the MIT License. - */ -/* */ - -var emptyObject = Object.freeze({}); - -// These helpers produce better VM code in JS engines due to their -// explicitness and function inlining. -function isUndef (v) { - return v === undefined || v === null -} - -function isDef (v) { - return v !== undefined && v !== null -} - -function isTrue (v) { - return v === true -} - -function isFalse (v) { - return v === false -} - -/** - * Check if value is primitive. - */ -function isPrimitive (value) { - return ( - typeof value === 'string' || - typeof value === 'number' || - // $flow-disable-line - typeof value === 'symbol' || - typeof value === 'boolean' - ) -} - -/** - * Quick object check - this is primarily used to tell - * Objects from primitive values when we know the value - * is a JSON-compliant type. - */ -function isObject (obj) { - return obj !== null && typeof obj === 'object' -} - -/** - * Get the raw type string of a value, e.g., [object Object]. - */ -var _toString = Object.prototype.toString; - -function toRawType (value) { - return _toString.call(value).slice(8, -1) -} - -/** - * Strict object type check. Only returns true - * for plain JavaScript objects. - */ -function isPlainObject (obj) { - return _toString.call(obj) === '[object Object]' -} - -function isRegExp (v) { - return _toString.call(v) === '[object RegExp]' -} - -/** - * Check if val is a valid array index. - */ -function isValidArrayIndex (val) { - var n = parseFloat(String(val)); - return n >= 0 && Math.floor(n) === n && isFinite(val) -} - -function isPromise (val) { - return ( - isDef(val) && - typeof val.then === 'function' && - typeof val.catch === 'function' - ) -} - -/** - * Convert a value to a string that is actually rendered. - */ -function toString (val) { - return val == null - ? '' - : Array.isArray(val) || (isPlainObject(val) && val.toString === _toString) - ? JSON.stringify(val, null, 2) - : String(val) -} - -/** - * Convert an input value to a number for persistence. - * If the conversion fails, return original string. - */ -function toNumber (val) { - var n = parseFloat(val); - return isNaN(n) ? val : n -} - -/** - * Make a map and return a function for checking if a key - * is in that map. - */ -function makeMap ( - str, - expectsLowerCase -) { - var map = Object.create(null); - var list = str.split(','); - for (var i = 0; i < list.length; i++) { - map[list[i]] = true; - } - return expectsLowerCase - ? function (val) { return map[val.toLowerCase()]; } - : function (val) { return map[val]; } -} - -/** - * Check if a tag is a built-in tag. - */ -var isBuiltInTag = makeMap('slot,component', true); - -/** - * Check if an attribute is a reserved attribute. - */ -var isReservedAttribute = makeMap('key,ref,slot,slot-scope,is'); - -/** - * Remove an item from an array. - */ -function remove (arr, item) { - if (arr.length) { - var index = arr.indexOf(item); - if (index > -1) { - return arr.splice(index, 1) - } - } -} - -/** - * Check whether an object has the property. - */ -var hasOwnProperty = Object.prototype.hasOwnProperty; -function hasOwn (obj, key) { - return hasOwnProperty.call(obj, key) -} - -/** - * Create a cached version of a pure function. - */ -function cached (fn) { - var cache = Object.create(null); - return (function cachedFn (str) { - var hit = cache[str]; - return hit || (cache[str] = fn(str)) - }) -} - -/** - * Camelize a hyphen-delimited string. - */ -var camelizeRE = /-(\w)/g; -var camelize = cached(function (str) { - return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; }) -}); - -/** - * Capitalize a string. - */ -var capitalize = cached(function (str) { - return str.charAt(0).toUpperCase() + str.slice(1) -}); - -/** - * Hyphenate a camelCase string. - */ -var hyphenateRE = /\B([A-Z])/g; -var hyphenate = cached(function (str) { - return str.replace(hyphenateRE, '-$1').toLowerCase() -}); - -/** - * Simple bind polyfill for environments that do not support it, - * e.g., PhantomJS 1.x. Technically, we don't need this anymore - * since native bind is now performant enough in most browsers. - * But removing it would mean breaking code that was able to run in - * PhantomJS 1.x, so this must be kept for backward compatibility. - */ - -/* istanbul ignore next */ -function polyfillBind (fn, ctx) { - function boundFn (a) { - var l = arguments.length; - return l - ? l > 1 - ? fn.apply(ctx, arguments) - : fn.call(ctx, a) - : fn.call(ctx) - } - - boundFn._length = fn.length; - return boundFn -} - -function nativeBind (fn, ctx) { - return fn.bind(ctx) -} - -var bind = Function.prototype.bind - ? nativeBind - : polyfillBind; - -/** - * Convert an Array-like object to a real Array. - */ -function toArray (list, start) { - start = start || 0; - var i = list.length - start; - var ret = new Array(i); - while (i--) { - ret[i] = list[i + start]; - } - return ret -} - -/** - * Mix properties into target object. - */ -function extend (to, _from) { - for (var key in _from) { - to[key] = _from[key]; - } - return to -} - -/** - * Merge an Array of Objects into a single Object. - */ -function toObject (arr) { - var res = {}; - for (var i = 0; i < arr.length; i++) { - if (arr[i]) { - extend(res, arr[i]); - } - } - return res -} - -/* eslint-disable no-unused-vars */ - -/** - * Perform no operation. - * Stubbing args to make Flow happy without leaving useless transpiled code - * with ...rest (https://flow.org/blog/2017/05/07/Strict-Function-Call-Arity/). - */ -function noop (a, b, c) {} - -/** - * Always return false. - */ -var no = function (a, b, c) { return false; }; - -/* eslint-enable no-unused-vars */ - -/** - * Return the same value. - */ -var identity = function (_) { return _; }; - -/** - * Check if two values are loosely equal - that is, - * if they are plain objects, do they have the same shape? - */ -function looseEqual (a, b) { - if (a === b) { return true } - var isObjectA = isObject(a); - var isObjectB = isObject(b); - if (isObjectA && isObjectB) { - try { - var isArrayA = Array.isArray(a); - var isArrayB = Array.isArray(b); - if (isArrayA && isArrayB) { - return a.length === b.length && a.every(function (e, i) { - return looseEqual(e, b[i]) - }) - } else if (a instanceof Date && b instanceof Date) { - return a.getTime() === b.getTime() - } else if (!isArrayA && !isArrayB) { - var keysA = Object.keys(a); - var keysB = Object.keys(b); - return keysA.length === keysB.length && keysA.every(function (key) { - return looseEqual(a[key], b[key]) - }) - } else { - /* istanbul ignore next */ - return false - } - } catch (e) { - /* istanbul ignore next */ - return false - } - } else if (!isObjectA && !isObjectB) { - return String(a) === String(b) - } else { - return false - } -} - -/** - * Return the first index at which a loosely equal value can be - * found in the array (if value is a plain object, the array must - * contain an object of the same shape), or -1 if it is not present. - */ -function looseIndexOf (arr, val) { - for (var i = 0; i < arr.length; i++) { - if (looseEqual(arr[i], val)) { return i } - } - return -1 -} - -/** - * Ensure a function is called only once. - */ -function once (fn) { - var called = false; - return function () { - if (!called) { - called = true; - fn.apply(this, arguments); - } - } -} - -var SSR_ATTR = 'data-server-rendered'; - -var ASSET_TYPES = [ - 'component', - 'directive', - 'filter' -]; - -var LIFECYCLE_HOOKS = [ - 'beforeCreate', - 'created', - 'beforeMount', - 'mounted', - 'beforeUpdate', - 'updated', - 'beforeDestroy', - 'destroyed', - 'activated', - 'deactivated', - 'errorCaptured', - 'serverPrefetch' -]; - -/* */ - - - -var config = ({ - /** - * Option merge strategies (used in core/util/options) - */ - // $flow-disable-line - optionMergeStrategies: Object.create(null), - - /** - * Whether to suppress warnings. - */ - silent: false, - - /** - * Show production mode tip message on boot? - */ - productionTip: "development" !== 'production', - - /** - * Whether to enable devtools - */ - devtools: "development" !== 'production', - - /** - * Whether to record perf - */ - performance: false, - - /** - * Error handler for watcher errors - */ - errorHandler: null, - - /** - * Warn handler for watcher warns - */ - warnHandler: null, - - /** - * Ignore certain custom elements - */ - ignoredElements: [], - - /** - * Custom user key aliases for v-on - */ - // $flow-disable-line - keyCodes: Object.create(null), - - /** - * Check if a tag is reserved so that it cannot be registered as a - * component. This is platform-dependent and may be overwritten. - */ - isReservedTag: no, - - /** - * Check if an attribute is reserved so that it cannot be used as a component - * prop. This is platform-dependent and may be overwritten. - */ - isReservedAttr: no, - - /** - * Check if a tag is an unknown element. - * Platform-dependent. - */ - isUnknownElement: no, - - /** - * Get the namespace of an element - */ - getTagNamespace: noop, - - /** - * Parse the real tag name for the specific platform. - */ - parsePlatformTagName: identity, - - /** - * Check if an attribute must be bound using property, e.g. value - * Platform-dependent. - */ - mustUseProp: no, - - /** - * Perform updates asynchronously. Intended to be used by Vue Test Utils - * This will significantly reduce performance if set to false. - */ - async: true, - - /** - * Exposed for legacy reasons - */ - _lifecycleHooks: LIFECYCLE_HOOKS -}); - -/* */ - -/** - * unicode letters used for parsing html tags, component names and property paths. - * using https://www.w3.org/TR/html53/semantics-scripting.html#potentialcustomelementname - * skipping \u10000-\uEFFFF due to it freezing up PhantomJS - */ -var unicodeRegExp = /a-zA-Z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD/; - -/** - * Check if a string starts with $ or _ - */ -function isReserved (str) { - var c = (str + '').charCodeAt(0); - return c === 0x24 || c === 0x5F -} - -/** - * Define a property. - */ -function def (obj, key, val, enumerable) { - Object.defineProperty(obj, key, { - value: val, - enumerable: !!enumerable, - writable: true, - configurable: true - }); -} - -/** - * Parse simple path. - */ -var bailRE = new RegExp(("[^" + (unicodeRegExp.source) + ".$_\\d]")); -function parsePath (path) { - if (bailRE.test(path)) { - return - } - var segments = path.split('.'); - return function (obj) { - for (var i = 0; i < segments.length; i++) { - if (!obj) { return } - obj = obj[segments[i]]; - } - return obj - } -} - -/* */ - -// can we use __proto__? -var hasProto = '__proto__' in {}; - -// Browser environment sniffing -var inBrowser = typeof window !== 'undefined'; -var inWeex = typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform; -var weexPlatform = inWeex && WXEnvironment.platform.toLowerCase(); -var UA = inBrowser && window.navigator.userAgent.toLowerCase(); -var isIE = UA && /msie|trident/.test(UA); -var isIE9 = UA && UA.indexOf('msie 9.0') > 0; -var isEdge = UA && UA.indexOf('edge/') > 0; -var isAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === 'android'); -var isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios'); -var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; -var isPhantomJS = UA && /phantomjs/.test(UA); -var isFF = UA && UA.match(/firefox\/(\d+)/); - -// Firefox has a "watch" function on Object.prototype... -var nativeWatch = ({}).watch; - -var supportsPassive = false; -if (inBrowser) { - try { - var opts = {}; - Object.defineProperty(opts, 'passive', ({ - get: function get () { - /* istanbul ignore next */ - supportsPassive = true; - } - })); // https://github.com/facebook/flow/issues/285 - window.addEventListener('test-passive', null, opts); - } catch (e) {} -} - -// this needs to be lazy-evaled because vue may be required before -// vue-server-renderer can set VUE_ENV -var _isServer; -var isServerRendering = function () { - if (_isServer === undefined) { - /* istanbul ignore if */ - if (!inBrowser && !inWeex && typeof global !== 'undefined') { - // detect presence of vue-server-renderer and avoid - // Webpack shimming the process - _isServer = global['process'] && global['process'].env.VUE_ENV === 'server'; - } else { - _isServer = false; - } - } - return _isServer -}; - -// detect devtools -var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__; - -/* istanbul ignore next */ -function isNative (Ctor) { - return typeof Ctor === 'function' && /native code/.test(Ctor.toString()) -} - -var hasSymbol = - typeof Symbol !== 'undefined' && isNative(Symbol) && - typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys); - -var _Set; -/* istanbul ignore if */ // $flow-disable-line -if (typeof Set !== 'undefined' && isNative(Set)) { - // use native Set when available. - _Set = Set; -} else { - // a non-standard Set polyfill that only works with primitive keys. - _Set = /*@__PURE__*/(function () { - function Set () { - this.set = Object.create(null); - } - Set.prototype.has = function has (key) { - return this.set[key] === true - }; - Set.prototype.add = function add (key) { - this.set[key] = true; - }; - Set.prototype.clear = function clear () { - this.set = Object.create(null); - }; - - return Set; - }()); -} - -/* */ - -var warn = noop; -var tip = noop; -var generateComponentTrace = (noop); // work around flow check -var formatComponentName = (noop); - -{ - var hasConsole = typeof console !== 'undefined'; - var classifyRE = /(?:^|[-_])(\w)/g; - var classify = function (str) { return str - .replace(classifyRE, function (c) { return c.toUpperCase(); }) - .replace(/[-_]/g, ''); }; - - warn = function (msg, vm) { - var trace = vm ? generateComponentTrace(vm) : ''; - - if (config.warnHandler) { - config.warnHandler.call(null, msg, vm, trace); - } else if (hasConsole && (!config.silent)) { - console.error(("[Vue warn]: " + msg + trace)); - } - }; - - tip = function (msg, vm) { - if (hasConsole && (!config.silent)) { - console.warn("[Vue tip]: " + msg + ( - vm ? generateComponentTrace(vm) : '' - )); - } - }; - - formatComponentName = function (vm, includeFile) { - if (vm.$root === vm) { - return '' - } - var options = typeof vm === 'function' && vm.cid != null - ? vm.options - : vm._isVue - ? vm.$options || vm.constructor.options - : vm; - var name = options.name || options._componentTag; - var file = options.__file; - if (!name && file) { - var match = file.match(/([^/\\]+)\.vue$/); - name = match && match[1]; - } - - return ( - (name ? ("<" + (classify(name)) + ">") : "") + - (file && includeFile !== false ? (" at " + file) : '') - ) - }; - - var repeat = function (str, n) { - var res = ''; - while (n) { - if (n % 2 === 1) { res += str; } - if (n > 1) { str += str; } - n >>= 1; - } - return res - }; - - generateComponentTrace = function (vm) { - if (vm._isVue && vm.$parent) { - var tree = []; - var currentRecursiveSequence = 0; - while (vm) { - if (tree.length > 0) { - var last = tree[tree.length - 1]; - if (last.constructor === vm.constructor) { - currentRecursiveSequence++; - vm = vm.$parent; - continue - } else if (currentRecursiveSequence > 0) { - tree[tree.length - 1] = [last, currentRecursiveSequence]; - currentRecursiveSequence = 0; - } - } - tree.push(vm); - vm = vm.$parent; - } - return '\n\nfound in\n\n' + tree - .map(function (vm, i) { return ("" + (i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + (Array.isArray(vm) - ? ((formatComponentName(vm[0])) + "... (" + (vm[1]) + " recursive calls)") - : formatComponentName(vm))); }) - .join('\n') - } else { - return ("\n\n(found in " + (formatComponentName(vm)) + ")") - } - }; -} - -/* */ - -var uid = 0; - -/** - * A dep is an observable that can have multiple - * directives subscribing to it. - */ -var Dep = function Dep () { - this.id = uid++; - this.subs = []; -}; - -Dep.prototype.addSub = function addSub (sub) { - this.subs.push(sub); -}; - -Dep.prototype.removeSub = function removeSub (sub) { - remove(this.subs, sub); -}; - -Dep.prototype.depend = function depend () { - if (Dep.target) { - Dep.target.addDep(this); - } -}; - -Dep.prototype.notify = function notify () { - // stabilize the subscriber list first - var subs = this.subs.slice(); - if ( !config.async) { - // subs aren't sorted in scheduler if not running async - // we need to sort them now to make sure they fire in correct - // order - subs.sort(function (a, b) { return a.id - b.id; }); - } - for (var i = 0, l = subs.length; i < l; i++) { - subs[i].update(); - } -}; - -// The current target watcher being evaluated. -// This is globally unique because only one watcher -// can be evaluated at a time. -Dep.target = null; -var targetStack = []; - -function pushTarget (target) { - targetStack.push(target); - Dep.target = target; -} - -function popTarget () { - targetStack.pop(); - Dep.target = targetStack[targetStack.length - 1]; -} - -/* */ - -var VNode = function VNode ( - tag, - data, - children, - text, - elm, - context, - componentOptions, - asyncFactory -) { - this.tag = tag; - this.data = data; - this.children = children; - this.text = text; - this.elm = elm; - this.ns = undefined; - this.context = context; - this.fnContext = undefined; - this.fnOptions = undefined; - this.fnScopeId = undefined; - this.key = data && data.key; - this.componentOptions = componentOptions; - this.componentInstance = undefined; - this.parent = undefined; - this.raw = false; - this.isStatic = false; - this.isRootInsert = true; - this.isComment = false; - this.isCloned = false; - this.isOnce = false; - this.asyncFactory = asyncFactory; - this.asyncMeta = undefined; - this.isAsyncPlaceholder = false; -}; - -var prototypeAccessors = { child: { configurable: true } }; - -// DEPRECATED: alias for componentInstance for backwards compat. -/* istanbul ignore next */ -prototypeAccessors.child.get = function () { - return this.componentInstance -}; - -Object.defineProperties( VNode.prototype, prototypeAccessors ); - -var createEmptyVNode = function (text) { - if ( text === void 0 ) text = ''; - - var node = new VNode(); - node.text = text; - node.isComment = true; - return node -}; - -function createTextVNode (val) { - return new VNode(undefined, undefined, undefined, String(val)) -} - -// optimized shallow clone -// used for static nodes and slot nodes because they may be reused across -// multiple renders, cloning them avoids errors when DOM manipulations rely -// on their elm reference. -function cloneVNode (vnode) { - var cloned = new VNode( - vnode.tag, - vnode.data, - // #7975 - // clone children array to avoid mutating original in case of cloning - // a child. - vnode.children && vnode.children.slice(), - vnode.text, - vnode.elm, - vnode.context, - vnode.componentOptions, - vnode.asyncFactory - ); - cloned.ns = vnode.ns; - cloned.isStatic = vnode.isStatic; - cloned.key = vnode.key; - cloned.isComment = vnode.isComment; - cloned.fnContext = vnode.fnContext; - cloned.fnOptions = vnode.fnOptions; - cloned.fnScopeId = vnode.fnScopeId; - cloned.asyncMeta = vnode.asyncMeta; - cloned.isCloned = true; - return cloned -} - -/* - * not type checking this file because flow doesn't play well with - * dynamically accessing methods on Array prototype - */ - -var arrayProto = Array.prototype; -var arrayMethods = Object.create(arrayProto); - -var methodsToPatch = [ - 'push', - 'pop', - 'shift', - 'unshift', - 'splice', - 'sort', - 'reverse' -]; - -/** - * Intercept mutating methods and emit events - */ -methodsToPatch.forEach(function (method) { - // cache original method - var original = arrayProto[method]; - def(arrayMethods, method, function mutator () { - var args = [], len = arguments.length; - while ( len-- ) args[ len ] = arguments[ len ]; - - var result = original.apply(this, args); - var ob = this.__ob__; - var inserted; - switch (method) { - case 'push': - case 'unshift': - inserted = args; - break - case 'splice': - inserted = args.slice(2); - break - } - if (inserted) { ob.observeArray(inserted); } - // notify change - ob.dep.notify(); - return result - }); -}); - -/* */ - -var arrayKeys = Object.getOwnPropertyNames(arrayMethods); - -/** - * In some cases we may want to disable observation inside a component's - * update computation. - */ -var shouldObserve = true; - -function toggleObserving (value) { - shouldObserve = value; -} - -/** - * Observer class that is attached to each observed - * object. Once attached, the observer converts the target - * object's property keys into getter/setters that - * collect dependencies and dispatch updates. - */ -var Observer = function Observer (value) { - this.value = value; - this.dep = new Dep(); - this.vmCount = 0; - def(value, '__ob__', this); - if (Array.isArray(value)) { - if (hasProto) { - protoAugment(value, arrayMethods); - } else { - copyAugment(value, arrayMethods, arrayKeys); - } - this.observeArray(value); - } else { - this.walk(value); - } -}; - -/** - * Walk through all properties and convert them into - * getter/setters. This method should only be called when - * value type is Object. - */ -Observer.prototype.walk = function walk (obj) { - var keys = Object.keys(obj); - for (var i = 0; i < keys.length; i++) { - defineReactive$$1(obj, keys[i]); - } -}; - -/** - * Observe a list of Array items. - */ -Observer.prototype.observeArray = function observeArray (items) { - for (var i = 0, l = items.length; i < l; i++) { - observe(items[i]); - } -}; - -// helpers - -/** - * Augment a target Object or Array by intercepting - * the prototype chain using __proto__ - */ -function protoAugment (target, src) { - /* eslint-disable no-proto */ - target.__proto__ = src; - /* eslint-enable no-proto */ -} - -/** - * Augment a target Object or Array by defining - * hidden properties. - */ -/* istanbul ignore next */ -function copyAugment (target, src, keys) { - for (var i = 0, l = keys.length; i < l; i++) { - var key = keys[i]; - def(target, key, src[key]); - } -} - -/** - * Attempt to create an observer instance for a value, - * returns the new observer if successfully observed, - * or the existing observer if the value already has one. - */ -function observe (value, asRootData) { - if (!isObject(value) || value instanceof VNode) { - return - } - var ob; - if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) { - ob = value.__ob__; - } else if ( - shouldObserve && - !isServerRendering() && - (Array.isArray(value) || isPlainObject(value)) && - Object.isExtensible(value) && - !value._isVue - ) { - ob = new Observer(value); - } - if (asRootData && ob) { - ob.vmCount++; - } - return ob -} - -/** - * Define a reactive property on an Object. - */ -function defineReactive$$1 ( - obj, - key, - val, - customSetter, - shallow -) { - var dep = new Dep(); - - var property = Object.getOwnPropertyDescriptor(obj, key); - if (property && property.configurable === false) { - return - } - - // cater for pre-defined getter/setters - var getter = property && property.get; - var setter = property && property.set; - if ((!getter || setter) && arguments.length === 2) { - val = obj[key]; - } - - var childOb = !shallow && observe(val); - Object.defineProperty(obj, key, { - enumerable: true, - configurable: true, - get: function reactiveGetter () { - var value = getter ? getter.call(obj) : val; - if (Dep.target) { - dep.depend(); - if (childOb) { - childOb.dep.depend(); - if (Array.isArray(value)) { - dependArray(value); - } - } - } - return value - }, - set: function reactiveSetter (newVal) { - var value = getter ? getter.call(obj) : val; - /* eslint-disable no-self-compare */ - if (newVal === value || (newVal !== newVal && value !== value)) { - return - } - /* eslint-enable no-self-compare */ - if ( customSetter) { - customSetter(); - } - // #7981: for accessor properties without setter - if (getter && !setter) { return } - if (setter) { - setter.call(obj, newVal); - } else { - val = newVal; - } - childOb = !shallow && observe(newVal); - dep.notify(); - } - }); -} - -/** - * Set a property on an object. Adds the new property and - * triggers change notification if the property doesn't - * already exist. - */ -function set (target, key, val) { - if ( - (isUndef(target) || isPrimitive(target)) - ) { - warn(("Cannot set reactive property on undefined, null, or primitive value: " + ((target)))); - } - if (Array.isArray(target) && isValidArrayIndex(key)) { - target.length = Math.max(target.length, key); - target.splice(key, 1, val); - return val - } - if (key in target && !(key in Object.prototype)) { - target[key] = val; - return val - } - var ob = (target).__ob__; - if (target._isVue || (ob && ob.vmCount)) { - warn( - 'Avoid adding reactive properties to a Vue instance or its root $data ' + - 'at runtime - declare it upfront in the data option.' - ); - return val - } - if (!ob) { - target[key] = val; - return val - } - defineReactive$$1(ob.value, key, val); - ob.dep.notify(); - return val -} - -/** - * Delete a property and trigger change if necessary. - */ -function del (target, key) { - if ( - (isUndef(target) || isPrimitive(target)) - ) { - warn(("Cannot delete reactive property on undefined, null, or primitive value: " + ((target)))); - } - if (Array.isArray(target) && isValidArrayIndex(key)) { - target.splice(key, 1); - return - } - var ob = (target).__ob__; - if (target._isVue || (ob && ob.vmCount)) { - warn( - 'Avoid deleting properties on a Vue instance or its root $data ' + - '- just set it to null.' - ); - return - } - if (!hasOwn(target, key)) { - return - } - delete target[key]; - if (!ob) { - return - } - ob.dep.notify(); -} - -/** - * Collect dependencies on array elements when the array is touched, since - * we cannot intercept array element access like property getters. - */ -function dependArray (value) { - for (var e = (void 0), i = 0, l = value.length; i < l; i++) { - e = value[i]; - e && e.__ob__ && e.__ob__.dep.depend(); - if (Array.isArray(e)) { - dependArray(e); - } - } -} - -/* */ - -/** - * Option overwriting strategies are functions that handle - * how to merge a parent option value and a child option - * value into the final value. - */ -var strats = config.optionMergeStrategies; - -/** - * Options with restrictions - */ -{ - strats.el = strats.propsData = function (parent, child, vm, key) { - if (!vm) { - warn( - "option \"" + key + "\" can only be used during instance " + - 'creation with the `new` keyword.' - ); - } - return defaultStrat(parent, child) - }; -} - -/** - * Helper that recursively merges two data objects together. - */ -function mergeData (to, from) { - if (!from) { return to } - var key, toVal, fromVal; - - var keys = hasSymbol - ? Reflect.ownKeys(from) - : Object.keys(from); - - for (var i = 0; i < keys.length; i++) { - key = keys[i]; - // in case the object is already observed... - if (key === '__ob__') { continue } - toVal = to[key]; - fromVal = from[key]; - if (!hasOwn(to, key)) { - set(to, key, fromVal); - } else if ( - toVal !== fromVal && - isPlainObject(toVal) && - isPlainObject(fromVal) - ) { - mergeData(toVal, fromVal); - } - } - return to -} - -/** - * Data - */ -function mergeDataOrFn ( - parentVal, - childVal, - vm -) { - if (!vm) { - // in a Vue.extend merge, both should be functions - if (!childVal) { - return parentVal - } - if (!parentVal) { - return childVal - } - // when parentVal & childVal are both present, - // we need to return a function that returns the - // merged result of both functions... no need to - // check if parentVal is a function here because - // it has to be a function to pass previous merges. - return function mergedDataFn () { - return mergeData( - typeof childVal === 'function' ? childVal.call(this, this) : childVal, - typeof parentVal === 'function' ? parentVal.call(this, this) : parentVal - ) - } - } else { - return function mergedInstanceDataFn () { - // instance merge - var instanceData = typeof childVal === 'function' - ? childVal.call(vm, vm) - : childVal; - var defaultData = typeof parentVal === 'function' - ? parentVal.call(vm, vm) - : parentVal; - if (instanceData) { - return mergeData(instanceData, defaultData) - } else { - return defaultData - } - } - } -} - -strats.data = function ( - parentVal, - childVal, - vm -) { - if (!vm) { - if (childVal && typeof childVal !== 'function') { - warn( - 'The "data" option should be a function ' + - 'that returns a per-instance value in component ' + - 'definitions.', - vm - ); - - return parentVal - } - return mergeDataOrFn(parentVal, childVal) - } - - return mergeDataOrFn(parentVal, childVal, vm) -}; - -/** - * Hooks and props are merged as arrays. - */ -function mergeHook ( - parentVal, - childVal -) { - var res = childVal - ? parentVal - ? parentVal.concat(childVal) - : Array.isArray(childVal) - ? childVal - : [childVal] - : parentVal; - return res - ? dedupeHooks(res) - : res -} - -function dedupeHooks (hooks) { - var res = []; - for (var i = 0; i < hooks.length; i++) { - if (res.indexOf(hooks[i]) === -1) { - res.push(hooks[i]); - } - } - return res -} - -LIFECYCLE_HOOKS.forEach(function (hook) { - strats[hook] = mergeHook; -}); - -/** - * Assets - * - * When a vm is present (instance creation), we need to do - * a three-way merge between constructor options, instance - * options and parent options. - */ -function mergeAssets ( - parentVal, - childVal, - vm, - key -) { - var res = Object.create(parentVal || null); - if (childVal) { - assertObjectType(key, childVal, vm); - return extend(res, childVal) - } else { - return res - } -} - -ASSET_TYPES.forEach(function (type) { - strats[type + 's'] = mergeAssets; -}); - -/** - * Watchers. - * - * Watchers hashes should not overwrite one - * another, so we merge them as arrays. - */ -strats.watch = function ( - parentVal, - childVal, - vm, - key -) { - // work around Firefox's Object.prototype.watch... - if (parentVal === nativeWatch) { parentVal = undefined; } - if (childVal === nativeWatch) { childVal = undefined; } - /* istanbul ignore if */ - if (!childVal) { return Object.create(parentVal || null) } - { - assertObjectType(key, childVal, vm); - } - if (!parentVal) { return childVal } - var ret = {}; - extend(ret, parentVal); - for (var key$1 in childVal) { - var parent = ret[key$1]; - var child = childVal[key$1]; - if (parent && !Array.isArray(parent)) { - parent = [parent]; - } - ret[key$1] = parent - ? parent.concat(child) - : Array.isArray(child) ? child : [child]; - } - return ret -}; - -/** - * Other object hashes. - */ -strats.props = -strats.methods = -strats.inject = -strats.computed = function ( - parentVal, - childVal, - vm, - key -) { - if (childVal && "development" !== 'production') { - assertObjectType(key, childVal, vm); - } - if (!parentVal) { return childVal } - var ret = Object.create(null); - extend(ret, parentVal); - if (childVal) { extend(ret, childVal); } - return ret -}; -strats.provide = mergeDataOrFn; - -/** - * Default strategy. - */ -var defaultStrat = function (parentVal, childVal) { - return childVal === undefined - ? parentVal - : childVal -}; - -/** - * Validate component names - */ -function checkComponents (options) { - for (var key in options.components) { - validateComponentName(key); - } -} - -function validateComponentName (name) { - if (!new RegExp(("^[a-zA-Z][\\-\\.0-9_" + (unicodeRegExp.source) + "]*$")).test(name)) { - warn( - 'Invalid component name: "' + name + '". Component names ' + - 'should conform to valid custom element name in html5 specification.' - ); - } - if (isBuiltInTag(name) || config.isReservedTag(name)) { - warn( - 'Do not use built-in or reserved HTML elements as component ' + - 'id: ' + name - ); - } -} - -/** - * Ensure all props option syntax are normalized into the - * Object-based format. - */ -function normalizeProps (options, vm) { - var props = options.props; - if (!props) { return } - var res = {}; - var i, val, name; - if (Array.isArray(props)) { - i = props.length; - while (i--) { - val = props[i]; - if (typeof val === 'string') { - name = camelize(val); - res[name] = { type: null }; - } else { - warn('props must be strings when using array syntax.'); - } - } - } else if (isPlainObject(props)) { - for (var key in props) { - val = props[key]; - name = camelize(key); - res[name] = isPlainObject(val) - ? val - : { type: val }; - } - } else { - warn( - "Invalid value for option \"props\": expected an Array or an Object, " + - "but got " + (toRawType(props)) + ".", - vm - ); - } - options.props = res; -} - -/** - * Normalize all injections into Object-based format - */ -function normalizeInject (options, vm) { - var inject = options.inject; - if (!inject) { return } - var normalized = options.inject = {}; - if (Array.isArray(inject)) { - for (var i = 0; i < inject.length; i++) { - normalized[inject[i]] = { from: inject[i] }; - } - } else if (isPlainObject(inject)) { - for (var key in inject) { - var val = inject[key]; - normalized[key] = isPlainObject(val) - ? extend({ from: key }, val) - : { from: val }; - } - } else { - warn( - "Invalid value for option \"inject\": expected an Array or an Object, " + - "but got " + (toRawType(inject)) + ".", - vm - ); - } -} - -/** - * Normalize raw function directives into object format. - */ -function normalizeDirectives (options) { - var dirs = options.directives; - if (dirs) { - for (var key in dirs) { - var def$$1 = dirs[key]; - if (typeof def$$1 === 'function') { - dirs[key] = { bind: def$$1, update: def$$1 }; - } - } - } -} - -function assertObjectType (name, value, vm) { - if (!isPlainObject(value)) { - warn( - "Invalid value for option \"" + name + "\": expected an Object, " + - "but got " + (toRawType(value)) + ".", - vm - ); - } -} - -/** - * Merge two option objects into a new one. - * Core utility used in both instantiation and inheritance. - */ -function mergeOptions ( - parent, - child, - vm -) { - { - checkComponents(child); - } - - if (typeof child === 'function') { - child = child.options; - } - - normalizeProps(child, vm); - normalizeInject(child, vm); - normalizeDirectives(child); - - // Apply extends and mixins on the child options, - // but only if it is a raw options object that isn't - // the result of another mergeOptions call. - // Only merged options has the _base property. - if (!child._base) { - if (child.extends) { - parent = mergeOptions(parent, child.extends, vm); - } - if (child.mixins) { - for (var i = 0, l = child.mixins.length; i < l; i++) { - parent = mergeOptions(parent, child.mixins[i], vm); - } - } - } - - var options = {}; - var key; - for (key in parent) { - mergeField(key); - } - for (key in child) { - if (!hasOwn(parent, key)) { - mergeField(key); - } - } - function mergeField (key) { - var strat = strats[key] || defaultStrat; - options[key] = strat(parent[key], child[key], vm, key); - } - return options -} - -/** - * Resolve an asset. - * This function is used because child instances need access - * to assets defined in its ancestor chain. - */ -function resolveAsset ( - options, - type, - id, - warnMissing -) { - /* istanbul ignore if */ - if (typeof id !== 'string') { - return - } - var assets = options[type]; - // check local registration variations first - if (hasOwn(assets, id)) { return assets[id] } - var camelizedId = camelize(id); - if (hasOwn(assets, camelizedId)) { return assets[camelizedId] } - var PascalCaseId = capitalize(camelizedId); - if (hasOwn(assets, PascalCaseId)) { return assets[PascalCaseId] } - // fallback to prototype chain - var res = assets[id] || assets[camelizedId] || assets[PascalCaseId]; - if ( warnMissing && !res) { - warn( - 'Failed to resolve ' + type.slice(0, -1) + ': ' + id, - options - ); - } - return res -} - -/* */ - - - -function validateProp ( - key, - propOptions, - propsData, - vm -) { - var prop = propOptions[key]; - var absent = !hasOwn(propsData, key); - var value = propsData[key]; - // boolean casting - var booleanIndex = getTypeIndex(Boolean, prop.type); - if (booleanIndex > -1) { - if (absent && !hasOwn(prop, 'default')) { - value = false; - } else if (value === '' || value === hyphenate(key)) { - // only cast empty string / same name to boolean if - // boolean has higher priority - var stringIndex = getTypeIndex(String, prop.type); - if (stringIndex < 0 || booleanIndex < stringIndex) { - value = true; - } - } - } - // check default value - if (value === undefined) { - value = getPropDefaultValue(vm, prop, key); - // since the default value is a fresh copy, - // make sure to observe it. - var prevShouldObserve = shouldObserve; - toggleObserving(true); - observe(value); - toggleObserving(prevShouldObserve); - } - { - assertProp(prop, key, value, vm, absent); - } - return value -} - -/** - * Get the default value of a prop. - */ -function getPropDefaultValue (vm, prop, key) { - // no default, return undefined - if (!hasOwn(prop, 'default')) { - return undefined - } - var def = prop.default; - // warn against non-factory defaults for Object & Array - if ( isObject(def)) { - warn( - 'Invalid default value for prop "' + key + '": ' + - 'Props with type Object/Array must use a factory function ' + - 'to return the default value.', - vm - ); - } - // the raw prop value was also undefined from previous render, - // return previous default value to avoid unnecessary watcher trigger - if (vm && vm.$options.propsData && - vm.$options.propsData[key] === undefined && - vm._props[key] !== undefined - ) { - return vm._props[key] - } - // call factory function for non-Function types - // a value is Function if its prototype is function even across different execution context - return typeof def === 'function' && getType(prop.type) !== 'Function' - ? def.call(vm) - : def -} - -/** - * Assert whether a prop is valid. - */ -function assertProp ( - prop, - name, - value, - vm, - absent -) { - if (prop.required && absent) { - warn( - 'Missing required prop: "' + name + '"', - vm - ); - return - } - if (value == null && !prop.required) { - return - } - var type = prop.type; - var valid = !type || type === true; - var expectedTypes = []; - if (type) { - if (!Array.isArray(type)) { - type = [type]; - } - for (var i = 0; i < type.length && !valid; i++) { - var assertedType = assertType(value, type[i]); - expectedTypes.push(assertedType.expectedType || ''); - valid = assertedType.valid; - } - } - - if (!valid) { - warn( - getInvalidTypeMessage(name, value, expectedTypes), - vm - ); - return - } - var validator = prop.validator; - if (validator) { - if (!validator(value)) { - warn( - 'Invalid prop: custom validator check failed for prop "' + name + '".', - vm - ); - } - } -} - -var simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/; - -function assertType (value, type) { - var valid; - var expectedType = getType(type); - if (simpleCheckRE.test(expectedType)) { - var t = typeof value; - valid = t === expectedType.toLowerCase(); - // for primitive wrapper objects - if (!valid && t === 'object') { - valid = value instanceof type; - } - } else if (expectedType === 'Object') { - valid = isPlainObject(value); - } else if (expectedType === 'Array') { - valid = Array.isArray(value); - } else { - valid = value instanceof type; - } - return { - valid: valid, - expectedType: expectedType - } -} - -/** - * Use function string name to check built-in types, - * because a simple equality check will fail when running - * across different vms / iframes. - */ -function getType (fn) { - var match = fn && fn.toString().match(/^\s*function (\w+)/); - return match ? match[1] : '' -} - -function isSameType (a, b) { - return getType(a) === getType(b) -} - -function getTypeIndex (type, expectedTypes) { - if (!Array.isArray(expectedTypes)) { - return isSameType(expectedTypes, type) ? 0 : -1 - } - for (var i = 0, len = expectedTypes.length; i < len; i++) { - if (isSameType(expectedTypes[i], type)) { - return i - } - } - return -1 -} - -function getInvalidTypeMessage (name, value, expectedTypes) { - var message = "Invalid prop: type check failed for prop \"" + name + "\"." + - " Expected " + (expectedTypes.map(capitalize).join(', ')); - var expectedType = expectedTypes[0]; - var receivedType = toRawType(value); - var expectedValue = styleValue(value, expectedType); - var receivedValue = styleValue(value, receivedType); - // check if we need to specify expected value - if (expectedTypes.length === 1 && - isExplicable(expectedType) && - !isBoolean(expectedType, receivedType)) { - message += " with value " + expectedValue; - } - message += ", got " + receivedType + " "; - // check if we need to specify received value - if (isExplicable(receivedType)) { - message += "with value " + receivedValue + "."; - } - return message -} - -function styleValue (value, type) { - if (type === 'String') { - return ("\"" + value + "\"") - } else if (type === 'Number') { - return ("" + (Number(value))) - } else { - return ("" + value) - } -} - -function isExplicable (value) { - var explicitTypes = ['string', 'number', 'boolean']; - return explicitTypes.some(function (elem) { return value.toLowerCase() === elem; }) -} - -function isBoolean () { - var args = [], len = arguments.length; - while ( len-- ) args[ len ] = arguments[ len ]; - - return args.some(function (elem) { return elem.toLowerCase() === 'boolean'; }) -} - -/* */ - -function handleError (err, vm, info) { - // Deactivate deps tracking while processing error handler to avoid possible infinite rendering. - // See: https://github.com/vuejs/vuex/issues/1505 - pushTarget(); - try { - if (vm) { - var cur = vm; - while ((cur = cur.$parent)) { - var hooks = cur.$options.errorCaptured; - if (hooks) { - for (var i = 0; i < hooks.length; i++) { - try { - var capture = hooks[i].call(cur, err, vm, info) === false; - if (capture) { return } - } catch (e) { - globalHandleError(e, cur, 'errorCaptured hook'); - } - } - } - } - } - globalHandleError(err, vm, info); - } finally { - popTarget(); - } -} - -function invokeWithErrorHandling ( - handler, - context, - args, - vm, - info -) { - var res; - try { - res = args ? handler.apply(context, args) : handler.call(context); - if (res && !res._isVue && isPromise(res) && !res._handled) { - res.catch(function (e) { return handleError(e, vm, info + " (Promise/async)"); }); - // issue #9511 - // avoid catch triggering multiple times when nested calls - res._handled = true; - } - } catch (e) { - handleError(e, vm, info); - } - return res -} - -function globalHandleError (err, vm, info) { - if (config.errorHandler) { - try { - return config.errorHandler.call(null, err, vm, info) - } catch (e) { - // if the user intentionally throws the original error in the handler, - // do not log it twice - if (e !== err) { - logError(e, null, 'config.errorHandler'); - } - } - } - logError(err, vm, info); -} - -function logError (err, vm, info) { - { - warn(("Error in " + info + ": \"" + (err.toString()) + "\""), vm); - } - /* istanbul ignore else */ - if ((inBrowser || inWeex) && typeof console !== 'undefined') { - console.error(err); - } else { - throw err - } -} - -/* */ - -var isUsingMicroTask = false; - -var callbacks = []; -var pending = false; - -function flushCallbacks () { - pending = false; - var copies = callbacks.slice(0); - callbacks.length = 0; - for (var i = 0; i < copies.length; i++) { - copies[i](); - } -} - -// Here we have async deferring wrappers using microtasks. -// In 2.5 we used (macro) tasks (in combination with microtasks). -// However, it has subtle problems when state is changed right before repaint -// (e.g. #6813, out-in transitions). -// Also, using (macro) tasks in event handler would cause some weird behaviors -// that cannot be circumvented (e.g. #7109, #7153, #7546, #7834, #8109). -// So we now use microtasks everywhere, again. -// A major drawback of this tradeoff is that there are some scenarios -// where microtasks have too high a priority and fire in between supposedly -// sequential events (e.g. #4521, #6690, which have workarounds) -// or even between bubbling of the same event (#6566). -var timerFunc; - -// The nextTick behavior leverages the microtask queue, which can be accessed -// via either native Promise.then or MutationObserver. -// MutationObserver has wider support, however it is seriously bugged in -// UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It -// completely stops working after triggering a few times... so, if native -// Promise is available, we will use it: -/* istanbul ignore next, $flow-disable-line */ -if (typeof Promise !== 'undefined' && isNative(Promise)) { - var p = Promise.resolve(); - timerFunc = function () { - p.then(flushCallbacks); - // In problematic UIWebViews, Promise.then doesn't completely break, but - // it can get stuck in a weird state where callbacks are pushed into the - // microtask queue but the queue isn't being flushed, until the browser - // needs to do some other work, e.g. handle a timer. Therefore we can - // "force" the microtask queue to be flushed by adding an empty timer. - if (isIOS) { setTimeout(noop); } - }; - isUsingMicroTask = true; -} else if (!isIE && typeof MutationObserver !== 'undefined' && ( - isNative(MutationObserver) || - // PhantomJS and iOS 7.x - MutationObserver.toString() === '[object MutationObserverConstructor]' -)) { - // Use MutationObserver where native Promise is not available, - // e.g. PhantomJS, iOS7, Android 4.4 - // (#6466 MutationObserver is unreliable in IE11) - var counter = 1; - var observer = new MutationObserver(flushCallbacks); - var textNode = document.createTextNode(String(counter)); - observer.observe(textNode, { - characterData: true - }); - timerFunc = function () { - counter = (counter + 1) % 2; - textNode.data = String(counter); - }; - isUsingMicroTask = true; -} else if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) { - // Fallback to setImmediate. - // Techinically it leverages the (macro) task queue, - // but it is still a better choice than setTimeout. - timerFunc = function () { - setImmediate(flushCallbacks); - }; -} else { - // Fallback to setTimeout. - timerFunc = function () { - setTimeout(flushCallbacks, 0); - }; -} - -function nextTick (cb, ctx) { - var _resolve; - callbacks.push(function () { - if (cb) { - try { - cb.call(ctx); - } catch (e) { - handleError(e, ctx, 'nextTick'); - } - } else if (_resolve) { - _resolve(ctx); - } - }); - if (!pending) { - pending = true; - timerFunc(); - } - // $flow-disable-line - if (!cb && typeof Promise !== 'undefined') { - return new Promise(function (resolve) { - _resolve = resolve; - }) - } -} - -/* */ - -/* not type checking this file because flow doesn't play well with Proxy */ - -var initProxy; - -{ - var allowedGlobals = makeMap( - 'Infinity,undefined,NaN,isFinite,isNaN,' + - 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' + - 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' + - 'require' // for Webpack/Browserify - ); - - var warnNonPresent = function (target, key) { - warn( - "Property or method \"" + key + "\" is not defined on the instance but " + - 'referenced during render. Make sure that this property is reactive, ' + - 'either in the data option, or for class-based components, by ' + - 'initializing the property. ' + - 'See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.', - target - ); - }; - - var warnReservedPrefix = function (target, key) { - warn( - "Property \"" + key + "\" must be accessed with \"$data." + key + "\" because " + - 'properties starting with "$" or "_" are not proxied in the Vue instance to ' + - 'prevent conflicts with Vue internals' + - 'See: https://vuejs.org/v2/api/#data', - target - ); - }; - - var hasProxy = - typeof Proxy !== 'undefined' && isNative(Proxy); - - if (hasProxy) { - var isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta,exact'); - config.keyCodes = new Proxy(config.keyCodes, { - set: function set (target, key, value) { - if (isBuiltInModifier(key)) { - warn(("Avoid overwriting built-in modifier in config.keyCodes: ." + key)); - return false - } else { - target[key] = value; - return true - } - } - }); - } - - var hasHandler = { - has: function has (target, key) { - var has = key in target; - var isAllowed = allowedGlobals(key) || - (typeof key === 'string' && key.charAt(0) === '_' && !(key in target.$data)); - if (!has && !isAllowed) { - if (key in target.$data) { warnReservedPrefix(target, key); } - else { warnNonPresent(target, key); } - } - return has || !isAllowed - } - }; - - var getHandler = { - get: function get (target, key) { - if (typeof key === 'string' && !(key in target)) { - if (key in target.$data) { warnReservedPrefix(target, key); } - else { warnNonPresent(target, key); } - } - return target[key] - } - }; - - initProxy = function initProxy (vm) { - if (hasProxy) { - // determine which proxy handler to use - var options = vm.$options; - var handlers = options.render && options.render._withStripped - ? getHandler - : hasHandler; - vm._renderProxy = new Proxy(vm, handlers); - } else { - vm._renderProxy = vm; - } - }; -} - -/* */ - -var seenObjects = new _Set(); - -/** - * Recursively traverse an object to evoke all converted - * getters, so that every nested property inside the object - * is collected as a "deep" dependency. - */ -function traverse (val) { - _traverse(val, seenObjects); - seenObjects.clear(); -} - -function _traverse (val, seen) { - var i, keys; - var isA = Array.isArray(val); - if ((!isA && !isObject(val)) || Object.isFrozen(val) || val instanceof VNode) { - return - } - if (val.__ob__) { - var depId = val.__ob__.dep.id; - if (seen.has(depId)) { - return - } - seen.add(depId); - } - if (isA) { - i = val.length; - while (i--) { _traverse(val[i], seen); } - } else { - keys = Object.keys(val); - i = keys.length; - while (i--) { _traverse(val[keys[i]], seen); } - } -} - -var mark; -var measure; - -{ - var perf = inBrowser && window.performance; - /* istanbul ignore if */ - if ( - perf && - perf.mark && - perf.measure && - perf.clearMarks && - perf.clearMeasures - ) { - mark = function (tag) { return perf.mark(tag); }; - measure = function (name, startTag, endTag) { - perf.measure(name, startTag, endTag); - perf.clearMarks(startTag); - perf.clearMarks(endTag); - // perf.clearMeasures(name) - }; - } -} - -/* */ - -var normalizeEvent = cached(function (name) { - var passive = name.charAt(0) === '&'; - name = passive ? name.slice(1) : name; - var once$$1 = name.charAt(0) === '~'; // Prefixed last, checked first - name = once$$1 ? name.slice(1) : name; - var capture = name.charAt(0) === '!'; - name = capture ? name.slice(1) : name; - return { - name: name, - once: once$$1, - capture: capture, - passive: passive - } -}); - -function createFnInvoker (fns, vm) { - function invoker () { - var arguments$1 = arguments; - - var fns = invoker.fns; - if (Array.isArray(fns)) { - var cloned = fns.slice(); - for (var i = 0; i < cloned.length; i++) { - invokeWithErrorHandling(cloned[i], null, arguments$1, vm, "v-on handler"); - } - } else { - // return handler return value for single handlers - return invokeWithErrorHandling(fns, null, arguments, vm, "v-on handler") - } - } - invoker.fns = fns; - return invoker -} - -function updateListeners ( - on, - oldOn, - add, - remove$$1, - createOnceHandler, - vm -) { - var name, def$$1, cur, old, event; - for (name in on) { - def$$1 = cur = on[name]; - old = oldOn[name]; - event = normalizeEvent(name); - if (isUndef(cur)) { - warn( - "Invalid handler for event \"" + (event.name) + "\": got " + String(cur), - vm - ); - } else if (isUndef(old)) { - if (isUndef(cur.fns)) { - cur = on[name] = createFnInvoker(cur, vm); - } - if (isTrue(event.once)) { - cur = on[name] = createOnceHandler(event.name, cur, event.capture); - } - add(event.name, cur, event.capture, event.passive, event.params); - } else if (cur !== old) { - old.fns = cur; - on[name] = old; - } - } - for (name in oldOn) { - if (isUndef(on[name])) { - event = normalizeEvent(name); - remove$$1(event.name, oldOn[name], event.capture); - } - } -} - -/* */ - -function mergeVNodeHook (def, hookKey, hook) { - if (def instanceof VNode) { - def = def.data.hook || (def.data.hook = {}); - } - var invoker; - var oldHook = def[hookKey]; - - function wrappedHook () { - hook.apply(this, arguments); - // important: remove merged hook to ensure it's called only once - // and prevent memory leak - remove(invoker.fns, wrappedHook); - } - - if (isUndef(oldHook)) { - // no existing hook - invoker = createFnInvoker([wrappedHook]); - } else { - /* istanbul ignore if */ - if (isDef(oldHook.fns) && isTrue(oldHook.merged)) { - // already a merged invoker - invoker = oldHook; - invoker.fns.push(wrappedHook); - } else { - // existing plain hook - invoker = createFnInvoker([oldHook, wrappedHook]); - } - } - - invoker.merged = true; - def[hookKey] = invoker; -} - -/* */ - -function extractPropsFromVNodeData ( - data, - Ctor, - tag -) { - // we are only extracting raw values here. - // validation and default values are handled in the child - // component itself. - var propOptions = Ctor.options.props; - if (isUndef(propOptions)) { - return - } - var res = {}; - var attrs = data.attrs; - var props = data.props; - if (isDef(attrs) || isDef(props)) { - for (var key in propOptions) { - var altKey = hyphenate(key); - { - var keyInLowerCase = key.toLowerCase(); - if ( - key !== keyInLowerCase && - attrs && hasOwn(attrs, keyInLowerCase) - ) { - tip( - "Prop \"" + keyInLowerCase + "\" is passed to component " + - (formatComponentName(tag || Ctor)) + ", but the declared prop name is" + - " \"" + key + "\". " + - "Note that HTML attributes are case-insensitive and camelCased " + - "props need to use their kebab-case equivalents when using in-DOM " + - "templates. You should probably use \"" + altKey + "\" instead of \"" + key + "\"." - ); - } - } - checkProp(res, props, key, altKey, true) || - checkProp(res, attrs, key, altKey, false); - } - } - return res -} - -function checkProp ( - res, - hash, - key, - altKey, - preserve -) { - if (isDef(hash)) { - if (hasOwn(hash, key)) { - res[key] = hash[key]; - if (!preserve) { - delete hash[key]; - } - return true - } else if (hasOwn(hash, altKey)) { - res[key] = hash[altKey]; - if (!preserve) { - delete hash[altKey]; - } - return true - } - } - return false -} - -/* */ - -// The template compiler attempts to minimize the need for normalization by -// statically analyzing the template at compile time. -// -// For plain HTML markup, normalization can be completely skipped because the -// generated render function is guaranteed to return Array. There are -// two cases where extra normalization is needed: - -// 1. When the children contains components - because a functional component -// may return an Array instead of a single root. In this case, just a simple -// normalization is needed - if any child is an Array, we flatten the whole -// thing with Array.prototype.concat. It is guaranteed to be only 1-level deep -// because functional components already normalize their own children. -function simpleNormalizeChildren (children) { - for (var i = 0; i < children.length; i++) { - if (Array.isArray(children[i])) { - return Array.prototype.concat.apply([], children) - } - } - return children -} - -// 2. When the children contains constructs that always generated nested Arrays, -// e.g.