vega 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +29 -0
- data/README.md +304 -0
- data/lib/vega.rb +36 -0
- data/lib/vega/base_chart.rb +51 -0
- data/lib/vega/chart.rb +25 -0
- data/lib/vega/engine.rb +5 -0
- data/lib/vega/lite_chart.rb +24 -0
- data/lib/vega/method_helpers.rb +41 -0
- data/lib/vega/spec.rb +101 -0
- data/lib/vega/version.rb +3 -0
- data/licenses/LICENSE-vega-embed.txt +27 -0
- data/licenses/LICENSE-vega-lite.txt +27 -0
- data/licenses/LICENSE-vega.txt +27 -0
- data/vendor/assets/javascripts/vega-embed.js +4398 -0
- data/vendor/assets/javascripts/vega-lite.js +25480 -0
- data/vendor/assets/javascripts/vega.js +45147 -0
- metadata +101 -0
data/lib/vega/engine.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Vega
|
2
|
+
class LiteChart < BaseChart
|
3
|
+
# https://vega.github.io/vega-lite/docs/spec.html
|
4
|
+
scalar_methods \
|
5
|
+
:background, :padding, :autosize, :title, :name, :description, :width, :height, :mark
|
6
|
+
|
7
|
+
hash_methods \
|
8
|
+
:config, :usermeta, :projection, :datasets, :encoding
|
9
|
+
|
10
|
+
array_methods \
|
11
|
+
:transform, :layer
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@schema = "https://vega.github.io/schema/vega-lite/v4.json"
|
15
|
+
super()
|
16
|
+
end
|
17
|
+
|
18
|
+
def data!(value)
|
19
|
+
@spec[:data] = data_value(value)
|
20
|
+
self
|
21
|
+
end
|
22
|
+
immutable_method :data
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Vega
|
2
|
+
module MethodHelpers
|
3
|
+
private
|
4
|
+
|
5
|
+
def scalar_methods(*methods)
|
6
|
+
methods.each do |method|
|
7
|
+
define_method("#{method}!") do |value|
|
8
|
+
@spec[method] = value
|
9
|
+
self
|
10
|
+
end
|
11
|
+
immutable_method(method)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def hash_methods(*methods)
|
16
|
+
methods.each do |method|
|
17
|
+
define_method("#{method}!") do |value|
|
18
|
+
(@spec[method] ||= {}).merge!(value)
|
19
|
+
self
|
20
|
+
end
|
21
|
+
immutable_method(method)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def array_methods(*methods)
|
26
|
+
methods.each do |method|
|
27
|
+
define_method("#{method}!") do |value|
|
28
|
+
(@spec[method] ||= []) << value
|
29
|
+
self
|
30
|
+
end
|
31
|
+
immutable_method(method)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def immutable_method(method)
|
36
|
+
define_method(method) do |value|
|
37
|
+
dup.send("#{method}!", value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/vega/spec.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
module Vega
|
2
|
+
class Spec
|
3
|
+
def initialize(spec)
|
4
|
+
spec = spec.spec if spec.respond_to?(:spec)
|
5
|
+
raise ArgumentError, "Expected Hash, not #{spec.class.name}" unless spec.is_a?(Hash)
|
6
|
+
@spec = spec.transform_keys!(&:to_s)
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
html, js = generate_output
|
11
|
+
output = <<~EOS
|
12
|
+
#{html}
|
13
|
+
<script>
|
14
|
+
#{js}
|
15
|
+
</script>
|
16
|
+
EOS
|
17
|
+
output.respond_to?(:html_safe) ? output.html_safe : output
|
18
|
+
end
|
19
|
+
|
20
|
+
# TODO only load vega-lite if $schema requires it
|
21
|
+
def to_iruby
|
22
|
+
html, js = generate_output
|
23
|
+
output = <<~EOS
|
24
|
+
#{html}
|
25
|
+
<script>
|
26
|
+
require.config({
|
27
|
+
paths: {
|
28
|
+
'vega': 'https://cdn.jsdelivr.net/npm/vega@5.16.1?noext',
|
29
|
+
'vega-lite': 'https://cdn.jsdelivr.net/npm/vega-lite@4.16.2?noext',
|
30
|
+
'vega-embed': 'https://cdn.jsdelivr.net/npm/vega-embed@6.12.2?noext'
|
31
|
+
}
|
32
|
+
});
|
33
|
+
require(['vega', 'vega-lite', 'vega-embed'], function(vega, vegaLite, vegaEmbed) {
|
34
|
+
#{js}
|
35
|
+
});
|
36
|
+
</script>
|
37
|
+
EOS
|
38
|
+
["text/html", output]
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def generate_output
|
44
|
+
id = "chart-#{SecureRandom.hex(16)}" # 2**128 values
|
45
|
+
width = @spec["width"].is_a?(Integer) ? "#{@spec["width"]}px" : "100%"
|
46
|
+
height = @spec["height"].is_a?(Integer) ? "#{@spec["height"]}px" : "300px"
|
47
|
+
|
48
|
+
# user can override with usermeta: {embedOptions: ...}
|
49
|
+
embed_options = {actions: false}
|
50
|
+
|
51
|
+
# html vars
|
52
|
+
html_vars = {
|
53
|
+
id: id
|
54
|
+
}
|
55
|
+
html_vars.each_key do |k|
|
56
|
+
html_vars[k] = ERB::Util.html_escape(html_vars[k])
|
57
|
+
end
|
58
|
+
|
59
|
+
# css vars
|
60
|
+
css_vars = {
|
61
|
+
height: height,
|
62
|
+
width: width
|
63
|
+
}
|
64
|
+
css_vars.each_key do |k|
|
65
|
+
# limit to alphanumeric and % for simplicity
|
66
|
+
# this prevents things like calc() but safety is the priority
|
67
|
+
raise ArgumentError, "Invalid #{k}" unless css_vars[k] =~ /\A[a-zA-Z0-9%]*\z/
|
68
|
+
# we limit above, but escape for safety as fail-safe
|
69
|
+
# to prevent XSS injection in worse-case scenario
|
70
|
+
css_vars[k] = ERB::Util.html_escape(css_vars[k])
|
71
|
+
end
|
72
|
+
|
73
|
+
# js vars
|
74
|
+
js_vars = {
|
75
|
+
el: "##{id}",
|
76
|
+
spec: @spec,
|
77
|
+
opt: embed_options
|
78
|
+
}
|
79
|
+
js_vars.each_key do |k|
|
80
|
+
js_vars[k] = json_escape(js_vars[k].to_json)
|
81
|
+
end
|
82
|
+
|
83
|
+
# needs width to be set for vegaEmbed to work
|
84
|
+
html = %(<div id="%{id}" style="width: %{width}; height: %{height};"></div>) % html_vars.merge(css_vars)
|
85
|
+
js = "vegaEmbed(%{el}, %{spec}, %{opt});" % js_vars
|
86
|
+
|
87
|
+
[html, js]
|
88
|
+
end
|
89
|
+
|
90
|
+
# from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/output_safety.rb
|
91
|
+
JSON_ESCAPE = { "&" => '\u0026', ">" => '\u003e', "<" => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
|
92
|
+
JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/u
|
93
|
+
def json_escape(s)
|
94
|
+
if ERB::Util.respond_to?(:json_escape)
|
95
|
+
ERB::Util.json_escape(s)
|
96
|
+
else
|
97
|
+
s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/vega/version.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Copyright (c) 2015, University of Washington Interactive Data Lab
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
15
|
+
may be used to endorse or promote products derived from this software
|
16
|
+
without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Copyright (c) 2015, University of Washington Interactive Data Lab.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
15
|
+
may be used to endorse or promote products derived from this software
|
16
|
+
without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Copyright (c) 2015-2018, University of Washington Interactive Data Lab
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
15
|
+
may be used to endorse or promote products derived from this software
|
16
|
+
without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,4398 @@
|
|
1
|
+
(function (global, factory) {
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vega'), require('vega-lite')) :
|
3
|
+
typeof define === 'function' && define.amd ? define(['vega', 'vega-lite'], factory) :
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.vegaEmbed = factory(global.vega, global.vegaLite));
|
5
|
+
}(this, (function (vegaImport, vegaLiteImport) { 'use strict';
|
6
|
+
|
7
|
+
function _interopNamespace(e) {
|
8
|
+
if (e && e.__esModule) { return e; } else {
|
9
|
+
var n = Object.create(null);
|
10
|
+
if (e) {
|
11
|
+
Object.keys(e).forEach(function (k) {
|
12
|
+
if (k !== 'default') {
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
15
|
+
enumerable: true,
|
16
|
+
get: function () {
|
17
|
+
return e[k];
|
18
|
+
}
|
19
|
+
});
|
20
|
+
}
|
21
|
+
});
|
22
|
+
}
|
23
|
+
n['default'] = e;
|
24
|
+
return Object.freeze(n);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
var vegaImport__namespace = /*#__PURE__*/_interopNamespace(vegaImport);
|
29
|
+
var vegaLiteImport__namespace = /*#__PURE__*/_interopNamespace(vegaLiteImport);
|
30
|
+
|
31
|
+
var version = "6.12.2";
|
32
|
+
|
33
|
+
/*! *****************************************************************************
|
34
|
+
Copyright (c) Microsoft Corporation.
|
35
|
+
|
36
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
37
|
+
purpose with or without fee is hereby granted.
|
38
|
+
|
39
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
40
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
41
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
42
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
43
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
44
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
45
|
+
PERFORMANCE OF THIS SOFTWARE.
|
46
|
+
***************************************************************************** */
|
47
|
+
|
48
|
+
var __assign = function() {
|
49
|
+
__assign = Object.assign || function __assign(t) {
|
50
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
51
|
+
s = arguments[i];
|
52
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
53
|
+
}
|
54
|
+
return t;
|
55
|
+
};
|
56
|
+
return __assign.apply(this, arguments);
|
57
|
+
};
|
58
|
+
|
59
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
60
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
61
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
62
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
63
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
64
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
65
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
66
|
+
});
|
67
|
+
}
|
68
|
+
|
69
|
+
function __generator(thisArg, body) {
|
70
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
71
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
72
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
73
|
+
function step(op) {
|
74
|
+
if (f) throw new TypeError("Generator is already executing.");
|
75
|
+
while (_) try {
|
76
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
77
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
78
|
+
switch (op[0]) {
|
79
|
+
case 0: case 1: t = op; break;
|
80
|
+
case 4: _.label++; return { value: op[1], done: false };
|
81
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
82
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
83
|
+
default:
|
84
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
85
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
86
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
87
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
88
|
+
if (t[2]) _.ops.pop();
|
89
|
+
_.trys.pop(); continue;
|
90
|
+
}
|
91
|
+
op = body.call(thisArg, _);
|
92
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
93
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
/*!
|
98
|
+
* https://github.com/Starcounter-Jack/JSON-Patch
|
99
|
+
* (c) 2017 Joachim Wester
|
100
|
+
* MIT license
|
101
|
+
*/
|
102
|
+
var __extends = (undefined && undefined.__extends) || (function () {
|
103
|
+
var extendStatics = function (d, b) {
|
104
|
+
extendStatics = Object.setPrototypeOf ||
|
105
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
106
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
107
|
+
return extendStatics(d, b);
|
108
|
+
};
|
109
|
+
return function (d, b) {
|
110
|
+
extendStatics(d, b);
|
111
|
+
function __() { this.constructor = d; }
|
112
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
113
|
+
};
|
114
|
+
})();
|
115
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
116
|
+
function hasOwnProperty(obj, key) {
|
117
|
+
return _hasOwnProperty.call(obj, key);
|
118
|
+
}
|
119
|
+
function _objectKeys(obj) {
|
120
|
+
if (Array.isArray(obj)) {
|
121
|
+
var keys = new Array(obj.length);
|
122
|
+
for (var k = 0; k < keys.length; k++) {
|
123
|
+
keys[k] = "" + k;
|
124
|
+
}
|
125
|
+
return keys;
|
126
|
+
}
|
127
|
+
if (Object.keys) {
|
128
|
+
return Object.keys(obj);
|
129
|
+
}
|
130
|
+
var keys = [];
|
131
|
+
for (var i in obj) {
|
132
|
+
if (hasOwnProperty(obj, i)) {
|
133
|
+
keys.push(i);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
return keys;
|
137
|
+
}
|
138
|
+
/**
|
139
|
+
* Deeply clone the object.
|
140
|
+
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
|
141
|
+
* @param {any} obj value to clone
|
142
|
+
* @return {any} cloned obj
|
143
|
+
*/
|
144
|
+
function _deepClone(obj) {
|
145
|
+
switch (typeof obj) {
|
146
|
+
case "object":
|
147
|
+
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
|
148
|
+
case "undefined":
|
149
|
+
return null; //this is how JSON.stringify behaves for array items
|
150
|
+
default:
|
151
|
+
return obj; //no need to clone primitives
|
152
|
+
}
|
153
|
+
}
|
154
|
+
//3x faster than cached /^\d+$/.test(str)
|
155
|
+
function isInteger(str) {
|
156
|
+
var i = 0;
|
157
|
+
var len = str.length;
|
158
|
+
var charCode;
|
159
|
+
while (i < len) {
|
160
|
+
charCode = str.charCodeAt(i);
|
161
|
+
if (charCode >= 48 && charCode <= 57) {
|
162
|
+
i++;
|
163
|
+
continue;
|
164
|
+
}
|
165
|
+
return false;
|
166
|
+
}
|
167
|
+
return true;
|
168
|
+
}
|
169
|
+
/**
|
170
|
+
* Escapes a json pointer path
|
171
|
+
* @param path The raw pointer
|
172
|
+
* @return the Escaped path
|
173
|
+
*/
|
174
|
+
function escapePathComponent(path) {
|
175
|
+
if (path.indexOf('/') === -1 && path.indexOf('~') === -1)
|
176
|
+
return path;
|
177
|
+
return path.replace(/~/g, '~0').replace(/\//g, '~1');
|
178
|
+
}
|
179
|
+
/**
|
180
|
+
* Unescapes a json pointer path
|
181
|
+
* @param path The escaped pointer
|
182
|
+
* @return The unescaped path
|
183
|
+
*/
|
184
|
+
function unescapePathComponent(path) {
|
185
|
+
return path.replace(/~1/g, '/').replace(/~0/g, '~');
|
186
|
+
}
|
187
|
+
/**
|
188
|
+
* Recursively checks whether an object has any undefined values inside.
|
189
|
+
*/
|
190
|
+
function hasUndefined(obj) {
|
191
|
+
if (obj === undefined) {
|
192
|
+
return true;
|
193
|
+
}
|
194
|
+
if (obj) {
|
195
|
+
if (Array.isArray(obj)) {
|
196
|
+
for (var i = 0, len = obj.length; i < len; i++) {
|
197
|
+
if (hasUndefined(obj[i])) {
|
198
|
+
return true;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}
|
202
|
+
else if (typeof obj === "object") {
|
203
|
+
var objKeys = _objectKeys(obj);
|
204
|
+
var objKeysLength = objKeys.length;
|
205
|
+
for (var i = 0; i < objKeysLength; i++) {
|
206
|
+
if (hasUndefined(obj[objKeys[i]])) {
|
207
|
+
return true;
|
208
|
+
}
|
209
|
+
}
|
210
|
+
}
|
211
|
+
}
|
212
|
+
return false;
|
213
|
+
}
|
214
|
+
function patchErrorMessageFormatter(message, args) {
|
215
|
+
var messageParts = [message];
|
216
|
+
for (var key in args) {
|
217
|
+
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
|
218
|
+
if (typeof value !== 'undefined') {
|
219
|
+
messageParts.push(key + ": " + value);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
return messageParts.join('\n');
|
223
|
+
}
|
224
|
+
var PatchError = /** @class */ (function (_super) {
|
225
|
+
__extends(PatchError, _super);
|
226
|
+
function PatchError(message, name, index, operation, tree) {
|
227
|
+
var _newTarget = this.constructor;
|
228
|
+
var _this = _super.call(this, patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree })) || this;
|
229
|
+
_this.name = name;
|
230
|
+
_this.index = index;
|
231
|
+
_this.operation = operation;
|
232
|
+
_this.tree = tree;
|
233
|
+
Object.setPrototypeOf(_this, _newTarget.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359
|
234
|
+
_this.message = patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree });
|
235
|
+
return _this;
|
236
|
+
}
|
237
|
+
return PatchError;
|
238
|
+
}(Error));
|
239
|
+
|
240
|
+
var JsonPatchError = PatchError;
|
241
|
+
var deepClone = _deepClone;
|
242
|
+
/* We use a Javascript hash to store each
|
243
|
+
function. Each hash entry (property) uses
|
244
|
+
the operation identifiers specified in rfc6902.
|
245
|
+
In this way, we can map each patch operation
|
246
|
+
to its dedicated function in efficient way.
|
247
|
+
*/
|
248
|
+
/* The operations applicable to an object */
|
249
|
+
var objOps = {
|
250
|
+
add: function (obj, key, document) {
|
251
|
+
obj[key] = this.value;
|
252
|
+
return { newDocument: document };
|
253
|
+
},
|
254
|
+
remove: function (obj, key, document) {
|
255
|
+
var removed = obj[key];
|
256
|
+
delete obj[key];
|
257
|
+
return { newDocument: document, removed: removed };
|
258
|
+
},
|
259
|
+
replace: function (obj, key, document) {
|
260
|
+
var removed = obj[key];
|
261
|
+
obj[key] = this.value;
|
262
|
+
return { newDocument: document, removed: removed };
|
263
|
+
},
|
264
|
+
move: function (obj, key, document) {
|
265
|
+
/* in case move target overwrites an existing value,
|
266
|
+
return the removed value, this can be taxing performance-wise,
|
267
|
+
and is potentially unneeded */
|
268
|
+
var removed = getValueByPointer(document, this.path);
|
269
|
+
if (removed) {
|
270
|
+
removed = _deepClone(removed);
|
271
|
+
}
|
272
|
+
var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
|
273
|
+
applyOperation(document, { op: "add", path: this.path, value: originalValue });
|
274
|
+
return { newDocument: document, removed: removed };
|
275
|
+
},
|
276
|
+
copy: function (obj, key, document) {
|
277
|
+
var valueToCopy = getValueByPointer(document, this.from);
|
278
|
+
// enforce copy by value so further operations don't affect source (see issue #177)
|
279
|
+
applyOperation(document, { op: "add", path: this.path, value: _deepClone(valueToCopy) });
|
280
|
+
return { newDocument: document };
|
281
|
+
},
|
282
|
+
test: function (obj, key, document) {
|
283
|
+
return { newDocument: document, test: _areEquals(obj[key], this.value) };
|
284
|
+
},
|
285
|
+
_get: function (obj, key, document) {
|
286
|
+
this.value = obj[key];
|
287
|
+
return { newDocument: document };
|
288
|
+
}
|
289
|
+
};
|
290
|
+
/* The operations applicable to an array. Many are the same as for the object */
|
291
|
+
var arrOps = {
|
292
|
+
add: function (arr, i, document) {
|
293
|
+
if (isInteger(i)) {
|
294
|
+
arr.splice(i, 0, this.value);
|
295
|
+
}
|
296
|
+
else { // array props
|
297
|
+
arr[i] = this.value;
|
298
|
+
}
|
299
|
+
// this may be needed when using '-' in an array
|
300
|
+
return { newDocument: document, index: i };
|
301
|
+
},
|
302
|
+
remove: function (arr, i, document) {
|
303
|
+
var removedList = arr.splice(i, 1);
|
304
|
+
return { newDocument: document, removed: removedList[0] };
|
305
|
+
},
|
306
|
+
replace: function (arr, i, document) {
|
307
|
+
var removed = arr[i];
|
308
|
+
arr[i] = this.value;
|
309
|
+
return { newDocument: document, removed: removed };
|
310
|
+
},
|
311
|
+
move: objOps.move,
|
312
|
+
copy: objOps.copy,
|
313
|
+
test: objOps.test,
|
314
|
+
_get: objOps._get
|
315
|
+
};
|
316
|
+
/**
|
317
|
+
* Retrieves a value from a JSON document by a JSON pointer.
|
318
|
+
* Returns the value.
|
319
|
+
*
|
320
|
+
* @param document The document to get the value from
|
321
|
+
* @param pointer an escaped JSON pointer
|
322
|
+
* @return The retrieved value
|
323
|
+
*/
|
324
|
+
function getValueByPointer(document, pointer) {
|
325
|
+
if (pointer == '') {
|
326
|
+
return document;
|
327
|
+
}
|
328
|
+
var getOriginalDestination = { op: "_get", path: pointer };
|
329
|
+
applyOperation(document, getOriginalDestination);
|
330
|
+
return getOriginalDestination.value;
|
331
|
+
}
|
332
|
+
/**
|
333
|
+
* Apply a single JSON Patch Operation on a JSON document.
|
334
|
+
* Returns the {newDocument, result} of the operation.
|
335
|
+
* It modifies the `document` and `operation` objects - it gets the values by reference.
|
336
|
+
* If you would like to avoid touching your values, clone them:
|
337
|
+
* `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.
|
338
|
+
*
|
339
|
+
* @param document The document to patch
|
340
|
+
* @param operation The operation to apply
|
341
|
+
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
342
|
+
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
343
|
+
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
344
|
+
* @return `{newDocument, result}` after the operation
|
345
|
+
*/
|
346
|
+
function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {
|
347
|
+
if (validateOperation === void 0) { validateOperation = false; }
|
348
|
+
if (mutateDocument === void 0) { mutateDocument = true; }
|
349
|
+
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
|
350
|
+
if (index === void 0) { index = 0; }
|
351
|
+
if (validateOperation) {
|
352
|
+
if (typeof validateOperation == 'function') {
|
353
|
+
validateOperation(operation, 0, document, operation.path);
|
354
|
+
}
|
355
|
+
else {
|
356
|
+
validator(operation, 0);
|
357
|
+
}
|
358
|
+
}
|
359
|
+
/* ROOT OPERATIONS */
|
360
|
+
if (operation.path === "") {
|
361
|
+
var returnValue = { newDocument: document };
|
362
|
+
if (operation.op === 'add') {
|
363
|
+
returnValue.newDocument = operation.value;
|
364
|
+
return returnValue;
|
365
|
+
}
|
366
|
+
else if (operation.op === 'replace') {
|
367
|
+
returnValue.newDocument = operation.value;
|
368
|
+
returnValue.removed = document; //document we removed
|
369
|
+
return returnValue;
|
370
|
+
}
|
371
|
+
else if (operation.op === 'move' || operation.op === 'copy') { // it's a move or copy to root
|
372
|
+
returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field
|
373
|
+
if (operation.op === 'move') { // report removed item
|
374
|
+
returnValue.removed = document;
|
375
|
+
}
|
376
|
+
return returnValue;
|
377
|
+
}
|
378
|
+
else if (operation.op === 'test') {
|
379
|
+
returnValue.test = _areEquals(document, operation.value);
|
380
|
+
if (returnValue.test === false) {
|
381
|
+
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
382
|
+
}
|
383
|
+
returnValue.newDocument = document;
|
384
|
+
return returnValue;
|
385
|
+
}
|
386
|
+
else if (operation.op === 'remove') { // a remove on root
|
387
|
+
returnValue.removed = document;
|
388
|
+
returnValue.newDocument = null;
|
389
|
+
return returnValue;
|
390
|
+
}
|
391
|
+
else if (operation.op === '_get') {
|
392
|
+
operation.value = document;
|
393
|
+
return returnValue;
|
394
|
+
}
|
395
|
+
else { /* bad operation */
|
396
|
+
if (validateOperation) {
|
397
|
+
throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
|
398
|
+
}
|
399
|
+
else {
|
400
|
+
return returnValue;
|
401
|
+
}
|
402
|
+
}
|
403
|
+
} /* END ROOT OPERATIONS */
|
404
|
+
else {
|
405
|
+
if (!mutateDocument) {
|
406
|
+
document = _deepClone(document);
|
407
|
+
}
|
408
|
+
var path = operation.path || "";
|
409
|
+
var keys = path.split('/');
|
410
|
+
var obj = document;
|
411
|
+
var t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift
|
412
|
+
var len = keys.length;
|
413
|
+
var existingPathFragment = undefined;
|
414
|
+
var key = void 0;
|
415
|
+
var validateFunction = void 0;
|
416
|
+
if (typeof validateOperation == 'function') {
|
417
|
+
validateFunction = validateOperation;
|
418
|
+
}
|
419
|
+
else {
|
420
|
+
validateFunction = validator;
|
421
|
+
}
|
422
|
+
while (true) {
|
423
|
+
key = keys[t];
|
424
|
+
if (banPrototypeModifications && key == '__proto__') {
|
425
|
+
throw new TypeError('JSON-Patch: modifying `__proto__` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');
|
426
|
+
}
|
427
|
+
if (validateOperation) {
|
428
|
+
if (existingPathFragment === undefined) {
|
429
|
+
if (obj[key] === undefined) {
|
430
|
+
existingPathFragment = keys.slice(0, t).join('/');
|
431
|
+
}
|
432
|
+
else if (t == len - 1) {
|
433
|
+
existingPathFragment = operation.path;
|
434
|
+
}
|
435
|
+
if (existingPathFragment !== undefined) {
|
436
|
+
validateFunction(operation, 0, document, existingPathFragment);
|
437
|
+
}
|
438
|
+
}
|
439
|
+
}
|
440
|
+
t++;
|
441
|
+
if (Array.isArray(obj)) {
|
442
|
+
if (key === '-') {
|
443
|
+
key = obj.length;
|
444
|
+
}
|
445
|
+
else {
|
446
|
+
if (validateOperation && !isInteger(key)) {
|
447
|
+
throw new JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", index, operation, document);
|
448
|
+
} // only parse key when it's an integer for `arr.prop` to work
|
449
|
+
else if (isInteger(key)) {
|
450
|
+
key = ~~key;
|
451
|
+
}
|
452
|
+
}
|
453
|
+
if (t >= len) {
|
454
|
+
if (validateOperation && operation.op === "add" && key > obj.length) {
|
455
|
+
throw new JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", index, operation, document);
|
456
|
+
}
|
457
|
+
var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch
|
458
|
+
if (returnValue.test === false) {
|
459
|
+
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
460
|
+
}
|
461
|
+
return returnValue;
|
462
|
+
}
|
463
|
+
}
|
464
|
+
else {
|
465
|
+
if (key && key.indexOf('~') != -1) {
|
466
|
+
key = unescapePathComponent(key);
|
467
|
+
}
|
468
|
+
if (t >= len) {
|
469
|
+
var returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch
|
470
|
+
if (returnValue.test === false) {
|
471
|
+
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
472
|
+
}
|
473
|
+
return returnValue;
|
474
|
+
}
|
475
|
+
}
|
476
|
+
obj = obj[key];
|
477
|
+
}
|
478
|
+
}
|
479
|
+
}
|
480
|
+
/**
|
481
|
+
* Apply a full JSON Patch array on a JSON document.
|
482
|
+
* Returns the {newDocument, result} of the patch.
|
483
|
+
* It modifies the `document` object and `patch` - it gets the values by reference.
|
484
|
+
* If you would like to avoid touching your values, clone them:
|
485
|
+
* `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.
|
486
|
+
*
|
487
|
+
* @param document The document to patch
|
488
|
+
* @param patch The patch to apply
|
489
|
+
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
490
|
+
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
491
|
+
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
492
|
+
* @return An array of `{newDocument, result}` after the patch
|
493
|
+
*/
|
494
|
+
function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
|
495
|
+
if (mutateDocument === void 0) { mutateDocument = true; }
|
496
|
+
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
|
497
|
+
if (validateOperation) {
|
498
|
+
if (!Array.isArray(patch)) {
|
499
|
+
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
|
500
|
+
}
|
501
|
+
}
|
502
|
+
if (!mutateDocument) {
|
503
|
+
document = _deepClone(document);
|
504
|
+
}
|
505
|
+
var results = new Array(patch.length);
|
506
|
+
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
|
507
|
+
// we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`
|
508
|
+
results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
|
509
|
+
document = results[i].newDocument; // in case root was replaced
|
510
|
+
}
|
511
|
+
results.newDocument = document;
|
512
|
+
return results;
|
513
|
+
}
|
514
|
+
/**
|
515
|
+
* Apply a single JSON Patch Operation on a JSON document.
|
516
|
+
* Returns the updated document.
|
517
|
+
* Suitable as a reducer.
|
518
|
+
*
|
519
|
+
* @param document The document to patch
|
520
|
+
* @param operation The operation to apply
|
521
|
+
* @return The updated document
|
522
|
+
*/
|
523
|
+
function applyReducer(document, operation, index) {
|
524
|
+
var operationResult = applyOperation(document, operation);
|
525
|
+
if (operationResult.test === false) { // failed test
|
526
|
+
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
527
|
+
}
|
528
|
+
return operationResult.newDocument;
|
529
|
+
}
|
530
|
+
/**
|
531
|
+
* Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.
|
532
|
+
* @param {object} operation - operation object (patch)
|
533
|
+
* @param {number} index - index of operation in the sequence
|
534
|
+
* @param {object} [document] - object where the operation is supposed to be applied
|
535
|
+
* @param {string} [existingPathFragment] - comes along with `document`
|
536
|
+
*/
|
537
|
+
function validator(operation, index, document, existingPathFragment) {
|
538
|
+
if (typeof operation !== 'object' || operation === null || Array.isArray(operation)) {
|
539
|
+
throw new JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document);
|
540
|
+
}
|
541
|
+
else if (!objOps[operation.op]) {
|
542
|
+
throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
|
543
|
+
}
|
544
|
+
else if (typeof operation.path !== 'string') {
|
545
|
+
throw new JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document);
|
546
|
+
}
|
547
|
+
else if (operation.path.indexOf('/') !== 0 && operation.path.length > 0) {
|
548
|
+
// paths that aren't empty string should start with "/"
|
549
|
+
throw new JsonPatchError('Operation `path` property must start with "/"', 'OPERATION_PATH_INVALID', index, operation, document);
|
550
|
+
}
|
551
|
+
else if ((operation.op === 'move' || operation.op === 'copy') && typeof operation.from !== 'string') {
|
552
|
+
throw new JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document);
|
553
|
+
}
|
554
|
+
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) {
|
555
|
+
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document);
|
556
|
+
}
|
557
|
+
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && hasUndefined(operation.value)) {
|
558
|
+
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document);
|
559
|
+
}
|
560
|
+
else if (document) {
|
561
|
+
if (operation.op == "add") {
|
562
|
+
var pathLen = operation.path.split("/").length;
|
563
|
+
var existingPathLen = existingPathFragment.split("/").length;
|
564
|
+
if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {
|
565
|
+
throw new JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document);
|
566
|
+
}
|
567
|
+
}
|
568
|
+
else if (operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') {
|
569
|
+
if (operation.path !== existingPathFragment) {
|
570
|
+
throw new JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
|
571
|
+
}
|
572
|
+
}
|
573
|
+
else if (operation.op === 'move' || operation.op === 'copy') {
|
574
|
+
var existingValue = { op: "_get", path: operation.from, value: undefined };
|
575
|
+
var error = validate([existingValue], document);
|
576
|
+
if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') {
|
577
|
+
throw new JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document);
|
578
|
+
}
|
579
|
+
}
|
580
|
+
}
|
581
|
+
}
|
582
|
+
/**
|
583
|
+
* Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.
|
584
|
+
* If error is encountered, returns a JsonPatchError object
|
585
|
+
* @param sequence
|
586
|
+
* @param document
|
587
|
+
* @returns {JsonPatchError|undefined}
|
588
|
+
*/
|
589
|
+
function validate(sequence, document, externalValidator) {
|
590
|
+
try {
|
591
|
+
if (!Array.isArray(sequence)) {
|
592
|
+
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
|
593
|
+
}
|
594
|
+
if (document) {
|
595
|
+
//clone document and sequence so that we can safely try applying operations
|
596
|
+
applyPatch(_deepClone(document), _deepClone(sequence), externalValidator || true);
|
597
|
+
}
|
598
|
+
else {
|
599
|
+
externalValidator = externalValidator || validator;
|
600
|
+
for (var i = 0; i < sequence.length; i++) {
|
601
|
+
externalValidator(sequence[i], i, document, undefined);
|
602
|
+
}
|
603
|
+
}
|
604
|
+
}
|
605
|
+
catch (e) {
|
606
|
+
if (e instanceof JsonPatchError) {
|
607
|
+
return e;
|
608
|
+
}
|
609
|
+
else {
|
610
|
+
throw e;
|
611
|
+
}
|
612
|
+
}
|
613
|
+
}
|
614
|
+
// based on https://github.com/epoberezkin/fast-deep-equal
|
615
|
+
// MIT License
|
616
|
+
// Copyright (c) 2017 Evgeny Poberezkin
|
617
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
618
|
+
// of this software and associated documentation files (the "Software"), to deal
|
619
|
+
// in the Software without restriction, including without limitation the rights
|
620
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
621
|
+
// copies of the Software, and to permit persons to whom the Software is
|
622
|
+
// furnished to do so, subject to the following conditions:
|
623
|
+
// The above copyright notice and this permission notice shall be included in all
|
624
|
+
// copies or substantial portions of the Software.
|
625
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
626
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
627
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
628
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
629
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
630
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
631
|
+
// SOFTWARE.
|
632
|
+
function _areEquals(a, b) {
|
633
|
+
if (a === b)
|
634
|
+
return true;
|
635
|
+
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
636
|
+
var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;
|
637
|
+
if (arrA && arrB) {
|
638
|
+
length = a.length;
|
639
|
+
if (length != b.length)
|
640
|
+
return false;
|
641
|
+
for (i = length; i-- !== 0;)
|
642
|
+
if (!_areEquals(a[i], b[i]))
|
643
|
+
return false;
|
644
|
+
return true;
|
645
|
+
}
|
646
|
+
if (arrA != arrB)
|
647
|
+
return false;
|
648
|
+
var keys = Object.keys(a);
|
649
|
+
length = keys.length;
|
650
|
+
if (length !== Object.keys(b).length)
|
651
|
+
return false;
|
652
|
+
for (i = length; i-- !== 0;)
|
653
|
+
if (!b.hasOwnProperty(keys[i]))
|
654
|
+
return false;
|
655
|
+
for (i = length; i-- !== 0;) {
|
656
|
+
key = keys[i];
|
657
|
+
if (!_areEquals(a[key], b[key]))
|
658
|
+
return false;
|
659
|
+
}
|
660
|
+
return true;
|
661
|
+
}
|
662
|
+
return a !== a && b !== b;
|
663
|
+
}
|
664
|
+
|
665
|
+
var core = /*#__PURE__*/Object.freeze({
|
666
|
+
__proto__: null,
|
667
|
+
JsonPatchError: JsonPatchError,
|
668
|
+
deepClone: deepClone,
|
669
|
+
getValueByPointer: getValueByPointer,
|
670
|
+
applyOperation: applyOperation,
|
671
|
+
applyPatch: applyPatch,
|
672
|
+
applyReducer: applyReducer,
|
673
|
+
validator: validator,
|
674
|
+
validate: validate,
|
675
|
+
_areEquals: _areEquals
|
676
|
+
});
|
677
|
+
|
678
|
+
/*!
|
679
|
+
* https://github.com/Starcounter-Jack/JSON-Patch
|
680
|
+
* (c) 2017 Joachim Wester
|
681
|
+
* MIT license
|
682
|
+
*/
|
683
|
+
var beforeDict = new WeakMap();
|
684
|
+
var Mirror = /** @class */ (function () {
|
685
|
+
function Mirror(obj) {
|
686
|
+
this.observers = new Map();
|
687
|
+
this.obj = obj;
|
688
|
+
}
|
689
|
+
return Mirror;
|
690
|
+
}());
|
691
|
+
var ObserverInfo = /** @class */ (function () {
|
692
|
+
function ObserverInfo(callback, observer) {
|
693
|
+
this.callback = callback;
|
694
|
+
this.observer = observer;
|
695
|
+
}
|
696
|
+
return ObserverInfo;
|
697
|
+
}());
|
698
|
+
function getMirror(obj) {
|
699
|
+
return beforeDict.get(obj);
|
700
|
+
}
|
701
|
+
function getObserverFromMirror(mirror, callback) {
|
702
|
+
return mirror.observers.get(callback);
|
703
|
+
}
|
704
|
+
function removeObserverFromMirror(mirror, observer) {
|
705
|
+
mirror.observers.delete(observer.callback);
|
706
|
+
}
|
707
|
+
/**
|
708
|
+
* Detach an observer from an object
|
709
|
+
*/
|
710
|
+
function unobserve(root, observer) {
|
711
|
+
observer.unobserve();
|
712
|
+
}
|
713
|
+
/**
|
714
|
+
* Observes changes made to an object, which can then be retrieved using generate
|
715
|
+
*/
|
716
|
+
function observe(obj, callback) {
|
717
|
+
var patches = [];
|
718
|
+
var observer;
|
719
|
+
var mirror = getMirror(obj);
|
720
|
+
if (!mirror) {
|
721
|
+
mirror = new Mirror(obj);
|
722
|
+
beforeDict.set(obj, mirror);
|
723
|
+
}
|
724
|
+
else {
|
725
|
+
var observerInfo = getObserverFromMirror(mirror, callback);
|
726
|
+
observer = observerInfo && observerInfo.observer;
|
727
|
+
}
|
728
|
+
if (observer) {
|
729
|
+
return observer;
|
730
|
+
}
|
731
|
+
observer = {};
|
732
|
+
mirror.value = _deepClone(obj);
|
733
|
+
if (callback) {
|
734
|
+
observer.callback = callback;
|
735
|
+
observer.next = null;
|
736
|
+
var dirtyCheck = function () {
|
737
|
+
generate(observer);
|
738
|
+
};
|
739
|
+
var fastCheck = function () {
|
740
|
+
clearTimeout(observer.next);
|
741
|
+
observer.next = setTimeout(dirtyCheck);
|
742
|
+
};
|
743
|
+
if (typeof window !== 'undefined') { //not Node
|
744
|
+
window.addEventListener('mouseup', fastCheck);
|
745
|
+
window.addEventListener('keyup', fastCheck);
|
746
|
+
window.addEventListener('mousedown', fastCheck);
|
747
|
+
window.addEventListener('keydown', fastCheck);
|
748
|
+
window.addEventListener('change', fastCheck);
|
749
|
+
}
|
750
|
+
}
|
751
|
+
observer.patches = patches;
|
752
|
+
observer.object = obj;
|
753
|
+
observer.unobserve = function () {
|
754
|
+
generate(observer);
|
755
|
+
clearTimeout(observer.next);
|
756
|
+
removeObserverFromMirror(mirror, observer);
|
757
|
+
if (typeof window !== 'undefined') {
|
758
|
+
window.removeEventListener('mouseup', fastCheck);
|
759
|
+
window.removeEventListener('keyup', fastCheck);
|
760
|
+
window.removeEventListener('mousedown', fastCheck);
|
761
|
+
window.removeEventListener('keydown', fastCheck);
|
762
|
+
window.removeEventListener('change', fastCheck);
|
763
|
+
}
|
764
|
+
};
|
765
|
+
mirror.observers.set(callback, new ObserverInfo(callback, observer));
|
766
|
+
return observer;
|
767
|
+
}
|
768
|
+
/**
|
769
|
+
* Generate an array of patches from an observer
|
770
|
+
*/
|
771
|
+
function generate(observer, invertible) {
|
772
|
+
if (invertible === void 0) { invertible = false; }
|
773
|
+
var mirror = beforeDict.get(observer.object);
|
774
|
+
_generate(mirror.value, observer.object, observer.patches, "", invertible);
|
775
|
+
if (observer.patches.length) {
|
776
|
+
applyPatch(mirror.value, observer.patches);
|
777
|
+
}
|
778
|
+
var temp = observer.patches;
|
779
|
+
if (temp.length > 0) {
|
780
|
+
observer.patches = [];
|
781
|
+
if (observer.callback) {
|
782
|
+
observer.callback(temp);
|
783
|
+
}
|
784
|
+
}
|
785
|
+
return temp;
|
786
|
+
}
|
787
|
+
// Dirty check if obj is different from mirror, generate patches and update mirror
|
788
|
+
function _generate(mirror, obj, patches, path, invertible) {
|
789
|
+
if (obj === mirror) {
|
790
|
+
return;
|
791
|
+
}
|
792
|
+
if (typeof obj.toJSON === "function") {
|
793
|
+
obj = obj.toJSON();
|
794
|
+
}
|
795
|
+
var newKeys = _objectKeys(obj);
|
796
|
+
var oldKeys = _objectKeys(mirror);
|
797
|
+
var deleted = false;
|
798
|
+
//if ever "move" operation is implemented here, make sure this test runs OK: "should not generate the same patch twice (move)"
|
799
|
+
for (var t = oldKeys.length - 1; t >= 0; t--) {
|
800
|
+
var key = oldKeys[t];
|
801
|
+
var oldVal = mirror[key];
|
802
|
+
if (hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
|
803
|
+
var newVal = obj[key];
|
804
|
+
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null) {
|
805
|
+
_generate(oldVal, newVal, patches, path + "/" + escapePathComponent(key), invertible);
|
806
|
+
}
|
807
|
+
else {
|
808
|
+
if (oldVal !== newVal) {
|
809
|
+
if (invertible) {
|
810
|
+
patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
|
811
|
+
}
|
812
|
+
patches.push({ op: "replace", path: path + "/" + escapePathComponent(key), value: _deepClone(newVal) });
|
813
|
+
}
|
814
|
+
}
|
815
|
+
}
|
816
|
+
else if (Array.isArray(mirror) === Array.isArray(obj)) {
|
817
|
+
if (invertible) {
|
818
|
+
patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
|
819
|
+
}
|
820
|
+
patches.push({ op: "remove", path: path + "/" + escapePathComponent(key) });
|
821
|
+
deleted = true; // property has been deleted
|
822
|
+
}
|
823
|
+
else {
|
824
|
+
if (invertible) {
|
825
|
+
patches.push({ op: "test", path: path, value: mirror });
|
826
|
+
}
|
827
|
+
patches.push({ op: "replace", path: path, value: obj });
|
828
|
+
}
|
829
|
+
}
|
830
|
+
if (!deleted && newKeys.length == oldKeys.length) {
|
831
|
+
return;
|
832
|
+
}
|
833
|
+
for (var t = 0; t < newKeys.length; t++) {
|
834
|
+
var key = newKeys[t];
|
835
|
+
if (!hasOwnProperty(mirror, key) && obj[key] !== undefined) {
|
836
|
+
patches.push({ op: "add", path: path + "/" + escapePathComponent(key), value: _deepClone(obj[key]) });
|
837
|
+
}
|
838
|
+
}
|
839
|
+
}
|
840
|
+
/**
|
841
|
+
* Create an array of patches from the differences in two objects
|
842
|
+
*/
|
843
|
+
function compare(tree1, tree2, invertible) {
|
844
|
+
if (invertible === void 0) { invertible = false; }
|
845
|
+
var patches = [];
|
846
|
+
_generate(tree1, tree2, patches, '', invertible);
|
847
|
+
return patches;
|
848
|
+
}
|
849
|
+
|
850
|
+
var duplex = /*#__PURE__*/Object.freeze({
|
851
|
+
__proto__: null,
|
852
|
+
unobserve: unobserve,
|
853
|
+
observe: observe,
|
854
|
+
generate: generate,
|
855
|
+
compare: compare
|
856
|
+
});
|
857
|
+
|
858
|
+
Object.assign({}, core, duplex, {
|
859
|
+
JsonPatchError: PatchError,
|
860
|
+
deepClone: _deepClone,
|
861
|
+
escapePathComponent,
|
862
|
+
unescapePathComponent
|
863
|
+
});
|
864
|
+
|
865
|
+
// Note: This regex matches even invalid JSON strings, but since we’re
|
866
|
+
// working on the output of `JSON.stringify` we know that only valid strings
|
867
|
+
// are present (unless the user supplied a weird `options.indent` but in
|
868
|
+
// that case we don’t care since the output would be invalid anyway).
|
869
|
+
var stringOrChar = /("(?:[^\\"]|\\.)*")|[:,]/g;
|
870
|
+
|
871
|
+
var jsonStringifyPrettyCompact = function stringify(passedObj, options) {
|
872
|
+
var indent, maxLength, replacer;
|
873
|
+
|
874
|
+
options = options || {};
|
875
|
+
indent = JSON.stringify(
|
876
|
+
[1],
|
877
|
+
undefined,
|
878
|
+
options.indent === undefined ? 2 : options.indent
|
879
|
+
).slice(2, -3);
|
880
|
+
maxLength =
|
881
|
+
indent === ""
|
882
|
+
? Infinity
|
883
|
+
: options.maxLength === undefined
|
884
|
+
? 80
|
885
|
+
: options.maxLength;
|
886
|
+
replacer = options.replacer;
|
887
|
+
|
888
|
+
return (function _stringify(obj, currentIndent, reserved) {
|
889
|
+
// prettier-ignore
|
890
|
+
var end, index, items, key, keyPart, keys, length, nextIndent, prettified, start, string, value;
|
891
|
+
|
892
|
+
if (obj && typeof obj.toJSON === "function") {
|
893
|
+
obj = obj.toJSON();
|
894
|
+
}
|
895
|
+
|
896
|
+
string = JSON.stringify(obj, replacer);
|
897
|
+
|
898
|
+
if (string === undefined) {
|
899
|
+
return string;
|
900
|
+
}
|
901
|
+
|
902
|
+
length = maxLength - currentIndent.length - reserved;
|
903
|
+
|
904
|
+
if (string.length <= length) {
|
905
|
+
prettified = string.replace(stringOrChar, function(match, stringLiteral) {
|
906
|
+
return stringLiteral || match + " ";
|
907
|
+
});
|
908
|
+
if (prettified.length <= length) {
|
909
|
+
return prettified;
|
910
|
+
}
|
911
|
+
}
|
912
|
+
|
913
|
+
if (replacer != null) {
|
914
|
+
obj = JSON.parse(string);
|
915
|
+
replacer = undefined;
|
916
|
+
}
|
917
|
+
|
918
|
+
if (typeof obj === "object" && obj !== null) {
|
919
|
+
nextIndent = currentIndent + indent;
|
920
|
+
items = [];
|
921
|
+
index = 0;
|
922
|
+
|
923
|
+
if (Array.isArray(obj)) {
|
924
|
+
start = "[";
|
925
|
+
end = "]";
|
926
|
+
length = obj.length;
|
927
|
+
for (; index < length; index++) {
|
928
|
+
items.push(
|
929
|
+
_stringify(obj[index], nextIndent, index === length - 1 ? 0 : 1) ||
|
930
|
+
"null"
|
931
|
+
);
|
932
|
+
}
|
933
|
+
} else {
|
934
|
+
start = "{";
|
935
|
+
end = "}";
|
936
|
+
keys = Object.keys(obj);
|
937
|
+
length = keys.length;
|
938
|
+
for (; index < length; index++) {
|
939
|
+
key = keys[index];
|
940
|
+
keyPart = JSON.stringify(key) + ": ";
|
941
|
+
value = _stringify(
|
942
|
+
obj[key],
|
943
|
+
nextIndent,
|
944
|
+
keyPart.length + (index === length - 1 ? 0 : 1)
|
945
|
+
);
|
946
|
+
if (value !== undefined) {
|
947
|
+
items.push(keyPart + value);
|
948
|
+
}
|
949
|
+
}
|
950
|
+
}
|
951
|
+
|
952
|
+
if (items.length > 0) {
|
953
|
+
return [start, indent + items.join(",\n" + nextIndent), end].join(
|
954
|
+
"\n" + currentIndent
|
955
|
+
);
|
956
|
+
}
|
957
|
+
}
|
958
|
+
|
959
|
+
return string;
|
960
|
+
})(passedObj, "", 0);
|
961
|
+
};
|
962
|
+
|
963
|
+
function createCommonjsModule(fn, basedir, module) {
|
964
|
+
return module = {
|
965
|
+
path: basedir,
|
966
|
+
exports: {},
|
967
|
+
require: function (path, base) {
|
968
|
+
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
|
969
|
+
}
|
970
|
+
}, fn(module, module.exports), module.exports;
|
971
|
+
}
|
972
|
+
|
973
|
+
function commonjsRequire () {
|
974
|
+
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
975
|
+
}
|
976
|
+
|
977
|
+
// Note: this is the semver.org version of the spec that it implements
|
978
|
+
// Not necessarily the package version of this code.
|
979
|
+
const SEMVER_SPEC_VERSION = '2.0.0';
|
980
|
+
|
981
|
+
const MAX_LENGTH = 256;
|
982
|
+
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
|
983
|
+
/* istanbul ignore next */ 9007199254740991;
|
984
|
+
|
985
|
+
// Max safe segment length for coercion.
|
986
|
+
const MAX_SAFE_COMPONENT_LENGTH = 16;
|
987
|
+
|
988
|
+
var constants = {
|
989
|
+
SEMVER_SPEC_VERSION,
|
990
|
+
MAX_LENGTH,
|
991
|
+
MAX_SAFE_INTEGER,
|
992
|
+
MAX_SAFE_COMPONENT_LENGTH
|
993
|
+
};
|
994
|
+
|
995
|
+
const debug = (
|
996
|
+
typeof process === 'object' &&
|
997
|
+
process.env &&
|
998
|
+
process.env.NODE_DEBUG &&
|
999
|
+
/\bsemver\b/i.test(process.env.NODE_DEBUG)
|
1000
|
+
) ? (...args) => console.error('SEMVER', ...args)
|
1001
|
+
: () => {};
|
1002
|
+
|
1003
|
+
var debug_1 = debug;
|
1004
|
+
|
1005
|
+
var re_1 = createCommonjsModule(function (module, exports) {
|
1006
|
+
const { MAX_SAFE_COMPONENT_LENGTH } = constants;
|
1007
|
+
|
1008
|
+
exports = module.exports = {};
|
1009
|
+
|
1010
|
+
// The actual regexps go on exports.re
|
1011
|
+
const re = exports.re = [];
|
1012
|
+
const src = exports.src = [];
|
1013
|
+
const t = exports.t = {};
|
1014
|
+
let R = 0;
|
1015
|
+
|
1016
|
+
const createToken = (name, value, isGlobal) => {
|
1017
|
+
const index = R++;
|
1018
|
+
debug_1(index, value);
|
1019
|
+
t[name] = index;
|
1020
|
+
src[index] = value;
|
1021
|
+
re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
|
1022
|
+
};
|
1023
|
+
|
1024
|
+
// The following Regular Expressions can be used for tokenizing,
|
1025
|
+
// validating, and parsing SemVer version strings.
|
1026
|
+
|
1027
|
+
// ## Numeric Identifier
|
1028
|
+
// A single `0`, or a non-zero digit followed by zero or more digits.
|
1029
|
+
|
1030
|
+
createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
|
1031
|
+
createToken('NUMERICIDENTIFIERLOOSE', '[0-9]+');
|
1032
|
+
|
1033
|
+
// ## Non-numeric Identifier
|
1034
|
+
// Zero or more digits, followed by a letter or hyphen, and then zero or
|
1035
|
+
// more letters, digits, or hyphens.
|
1036
|
+
|
1037
|
+
createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*');
|
1038
|
+
|
1039
|
+
// ## Main Version
|
1040
|
+
// Three dot-separated numeric identifiers.
|
1041
|
+
|
1042
|
+
createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
|
1043
|
+
`(${src[t.NUMERICIDENTIFIER]})\\.` +
|
1044
|
+
`(${src[t.NUMERICIDENTIFIER]})`);
|
1045
|
+
|
1046
|
+
createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
|
1047
|
+
`(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
|
1048
|
+
`(${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
1049
|
+
|
1050
|
+
// ## Pre-release Version Identifier
|
1051
|
+
// A numeric identifier, or a non-numeric identifier.
|
1052
|
+
|
1053
|
+
createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NUMERICIDENTIFIER]
|
1054
|
+
}|${src[t.NONNUMERICIDENTIFIER]})`);
|
1055
|
+
|
1056
|
+
createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE]
|
1057
|
+
}|${src[t.NONNUMERICIDENTIFIER]})`);
|
1058
|
+
|
1059
|
+
// ## Pre-release Version
|
1060
|
+
// Hyphen, followed by one or more dot-separated pre-release version
|
1061
|
+
// identifiers.
|
1062
|
+
|
1063
|
+
createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
|
1064
|
+
}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
|
1065
|
+
|
1066
|
+
createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
|
1067
|
+
}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
|
1068
|
+
|
1069
|
+
// ## Build Metadata Identifier
|
1070
|
+
// Any combination of digits, letters, or hyphens.
|
1071
|
+
|
1072
|
+
createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+');
|
1073
|
+
|
1074
|
+
// ## Build Metadata
|
1075
|
+
// Plus sign, followed by one or more period-separated build metadata
|
1076
|
+
// identifiers.
|
1077
|
+
|
1078
|
+
createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
|
1079
|
+
}(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
|
1080
|
+
|
1081
|
+
// ## Full Version String
|
1082
|
+
// A main version, followed optionally by a pre-release version and
|
1083
|
+
// build metadata.
|
1084
|
+
|
1085
|
+
// Note that the only major, minor, patch, and pre-release sections of
|
1086
|
+
// the version string are capturing groups. The build metadata is not a
|
1087
|
+
// capturing group, because it should not ever be used in version
|
1088
|
+
// comparison.
|
1089
|
+
|
1090
|
+
createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
|
1091
|
+
}${src[t.PRERELEASE]}?${
|
1092
|
+
src[t.BUILD]}?`);
|
1093
|
+
|
1094
|
+
createToken('FULL', `^${src[t.FULLPLAIN]}$`);
|
1095
|
+
|
1096
|
+
// like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
|
1097
|
+
// also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
|
1098
|
+
// common in the npm registry.
|
1099
|
+
createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
|
1100
|
+
}${src[t.PRERELEASELOOSE]}?${
|
1101
|
+
src[t.BUILD]}?`);
|
1102
|
+
|
1103
|
+
createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
|
1104
|
+
|
1105
|
+
createToken('GTLT', '((?:<|>)?=?)');
|
1106
|
+
|
1107
|
+
// Something like "2.*" or "1.2.x".
|
1108
|
+
// Note that "x.x" is a valid xRange identifer, meaning "any version"
|
1109
|
+
// Only the first item is strictly required.
|
1110
|
+
createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
|
1111
|
+
createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
|
1112
|
+
|
1113
|
+
createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
|
1114
|
+
`(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
|
1115
|
+
`(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
|
1116
|
+
`(?:${src[t.PRERELEASE]})?${
|
1117
|
+
src[t.BUILD]}?` +
|
1118
|
+
`)?)?`);
|
1119
|
+
|
1120
|
+
createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
|
1121
|
+
`(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
|
1122
|
+
`(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
|
1123
|
+
`(?:${src[t.PRERELEASELOOSE]})?${
|
1124
|
+
src[t.BUILD]}?` +
|
1125
|
+
`)?)?`);
|
1126
|
+
|
1127
|
+
createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
|
1128
|
+
createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
|
1129
|
+
|
1130
|
+
// Coercion.
|
1131
|
+
// Extract anything that could conceivably be a part of a valid semver
|
1132
|
+
createToken('COERCE', `${'(^|[^\\d])' +
|
1133
|
+
'(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
|
1134
|
+
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
|
1135
|
+
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
|
1136
|
+
`(?:$|[^\\d])`);
|
1137
|
+
createToken('COERCERTL', src[t.COERCE], true);
|
1138
|
+
|
1139
|
+
// Tilde ranges.
|
1140
|
+
// Meaning is "reasonably at or greater than"
|
1141
|
+
createToken('LONETILDE', '(?:~>?)');
|
1142
|
+
|
1143
|
+
createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
|
1144
|
+
exports.tildeTrimReplace = '$1~';
|
1145
|
+
|
1146
|
+
createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
|
1147
|
+
createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
|
1148
|
+
|
1149
|
+
// Caret ranges.
|
1150
|
+
// Meaning is "at least and backwards compatible with"
|
1151
|
+
createToken('LONECARET', '(?:\\^)');
|
1152
|
+
|
1153
|
+
createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
|
1154
|
+
exports.caretTrimReplace = '$1^';
|
1155
|
+
|
1156
|
+
createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
|
1157
|
+
createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
|
1158
|
+
|
1159
|
+
// A simple gt/lt/eq thing, or just "" to indicate "any version"
|
1160
|
+
createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
|
1161
|
+
createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
|
1162
|
+
|
1163
|
+
// An expression to strip any whitespace between the gtlt and the thing
|
1164
|
+
// it modifies, so that `> 1.2.3` ==> `>1.2.3`
|
1165
|
+
createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
|
1166
|
+
}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
|
1167
|
+
exports.comparatorTrimReplace = '$1$2$3';
|
1168
|
+
|
1169
|
+
// Something like `1.2.3 - 1.2.4`
|
1170
|
+
// Note that these all use the loose form, because they'll be
|
1171
|
+
// checked against either the strict or loose comparator form
|
1172
|
+
// later.
|
1173
|
+
createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
|
1174
|
+
`\\s+-\\s+` +
|
1175
|
+
`(${src[t.XRANGEPLAIN]})` +
|
1176
|
+
`\\s*$`);
|
1177
|
+
|
1178
|
+
createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
|
1179
|
+
`\\s+-\\s+` +
|
1180
|
+
`(${src[t.XRANGEPLAINLOOSE]})` +
|
1181
|
+
`\\s*$`);
|
1182
|
+
|
1183
|
+
// Star ranges basically just allow anything at all.
|
1184
|
+
createToken('STAR', '(<|>)?=?\\s*\\*');
|
1185
|
+
// >=0.0.0 is like a star
|
1186
|
+
createToken('GTE0', '^\\s*>=\\s*0\.0\.0\\s*$');
|
1187
|
+
createToken('GTE0PRE', '^\\s*>=\\s*0\.0\.0-0\\s*$');
|
1188
|
+
});
|
1189
|
+
|
1190
|
+
const numeric = /^[0-9]+$/;
|
1191
|
+
const compareIdentifiers = (a, b) => {
|
1192
|
+
const anum = numeric.test(a);
|
1193
|
+
const bnum = numeric.test(b);
|
1194
|
+
|
1195
|
+
if (anum && bnum) {
|
1196
|
+
a = +a;
|
1197
|
+
b = +b;
|
1198
|
+
}
|
1199
|
+
|
1200
|
+
return a === b ? 0
|
1201
|
+
: (anum && !bnum) ? -1
|
1202
|
+
: (bnum && !anum) ? 1
|
1203
|
+
: a < b ? -1
|
1204
|
+
: 1
|
1205
|
+
};
|
1206
|
+
|
1207
|
+
const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
|
1208
|
+
|
1209
|
+
var identifiers = {
|
1210
|
+
compareIdentifiers,
|
1211
|
+
rcompareIdentifiers
|
1212
|
+
};
|
1213
|
+
|
1214
|
+
const { MAX_LENGTH: MAX_LENGTH$1, MAX_SAFE_INTEGER: MAX_SAFE_INTEGER$1 } = constants;
|
1215
|
+
const { re, t } = re_1;
|
1216
|
+
|
1217
|
+
const { compareIdentifiers: compareIdentifiers$1 } = identifiers;
|
1218
|
+
class SemVer {
|
1219
|
+
constructor (version, options) {
|
1220
|
+
if (!options || typeof options !== 'object') {
|
1221
|
+
options = {
|
1222
|
+
loose: !!options,
|
1223
|
+
includePrerelease: false
|
1224
|
+
};
|
1225
|
+
}
|
1226
|
+
if (version instanceof SemVer) {
|
1227
|
+
if (version.loose === !!options.loose &&
|
1228
|
+
version.includePrerelease === !!options.includePrerelease) {
|
1229
|
+
return version
|
1230
|
+
} else {
|
1231
|
+
version = version.version;
|
1232
|
+
}
|
1233
|
+
} else if (typeof version !== 'string') {
|
1234
|
+
throw new TypeError(`Invalid Version: ${version}`)
|
1235
|
+
}
|
1236
|
+
|
1237
|
+
if (version.length > MAX_LENGTH$1) {
|
1238
|
+
throw new TypeError(
|
1239
|
+
`version is longer than ${MAX_LENGTH$1} characters`
|
1240
|
+
)
|
1241
|
+
}
|
1242
|
+
|
1243
|
+
debug_1('SemVer', version, options);
|
1244
|
+
this.options = options;
|
1245
|
+
this.loose = !!options.loose;
|
1246
|
+
// this isn't actually relevant for versions, but keep it so that we
|
1247
|
+
// don't run into trouble passing this.options around.
|
1248
|
+
this.includePrerelease = !!options.includePrerelease;
|
1249
|
+
|
1250
|
+
const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
|
1251
|
+
|
1252
|
+
if (!m) {
|
1253
|
+
throw new TypeError(`Invalid Version: ${version}`)
|
1254
|
+
}
|
1255
|
+
|
1256
|
+
this.raw = version;
|
1257
|
+
|
1258
|
+
// these are actually numbers
|
1259
|
+
this.major = +m[1];
|
1260
|
+
this.minor = +m[2];
|
1261
|
+
this.patch = +m[3];
|
1262
|
+
|
1263
|
+
if (this.major > MAX_SAFE_INTEGER$1 || this.major < 0) {
|
1264
|
+
throw new TypeError('Invalid major version')
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
if (this.minor > MAX_SAFE_INTEGER$1 || this.minor < 0) {
|
1268
|
+
throw new TypeError('Invalid minor version')
|
1269
|
+
}
|
1270
|
+
|
1271
|
+
if (this.patch > MAX_SAFE_INTEGER$1 || this.patch < 0) {
|
1272
|
+
throw new TypeError('Invalid patch version')
|
1273
|
+
}
|
1274
|
+
|
1275
|
+
// numberify any prerelease numeric ids
|
1276
|
+
if (!m[4]) {
|
1277
|
+
this.prerelease = [];
|
1278
|
+
} else {
|
1279
|
+
this.prerelease = m[4].split('.').map((id) => {
|
1280
|
+
if (/^[0-9]+$/.test(id)) {
|
1281
|
+
const num = +id;
|
1282
|
+
if (num >= 0 && num < MAX_SAFE_INTEGER$1) {
|
1283
|
+
return num
|
1284
|
+
}
|
1285
|
+
}
|
1286
|
+
return id
|
1287
|
+
});
|
1288
|
+
}
|
1289
|
+
|
1290
|
+
this.build = m[5] ? m[5].split('.') : [];
|
1291
|
+
this.format();
|
1292
|
+
}
|
1293
|
+
|
1294
|
+
format () {
|
1295
|
+
this.version = `${this.major}.${this.minor}.${this.patch}`;
|
1296
|
+
if (this.prerelease.length) {
|
1297
|
+
this.version += `-${this.prerelease.join('.')}`;
|
1298
|
+
}
|
1299
|
+
return this.version
|
1300
|
+
}
|
1301
|
+
|
1302
|
+
toString () {
|
1303
|
+
return this.version
|
1304
|
+
}
|
1305
|
+
|
1306
|
+
compare (other) {
|
1307
|
+
debug_1('SemVer.compare', this.version, this.options, other);
|
1308
|
+
if (!(other instanceof SemVer)) {
|
1309
|
+
if (typeof other === 'string' && other === this.version) {
|
1310
|
+
return 0
|
1311
|
+
}
|
1312
|
+
other = new SemVer(other, this.options);
|
1313
|
+
}
|
1314
|
+
|
1315
|
+
if (other.version === this.version) {
|
1316
|
+
return 0
|
1317
|
+
}
|
1318
|
+
|
1319
|
+
return this.compareMain(other) || this.comparePre(other)
|
1320
|
+
}
|
1321
|
+
|
1322
|
+
compareMain (other) {
|
1323
|
+
if (!(other instanceof SemVer)) {
|
1324
|
+
other = new SemVer(other, this.options);
|
1325
|
+
}
|
1326
|
+
|
1327
|
+
return (
|
1328
|
+
compareIdentifiers$1(this.major, other.major) ||
|
1329
|
+
compareIdentifiers$1(this.minor, other.minor) ||
|
1330
|
+
compareIdentifiers$1(this.patch, other.patch)
|
1331
|
+
)
|
1332
|
+
}
|
1333
|
+
|
1334
|
+
comparePre (other) {
|
1335
|
+
if (!(other instanceof SemVer)) {
|
1336
|
+
other = new SemVer(other, this.options);
|
1337
|
+
}
|
1338
|
+
|
1339
|
+
// NOT having a prerelease is > having one
|
1340
|
+
if (this.prerelease.length && !other.prerelease.length) {
|
1341
|
+
return -1
|
1342
|
+
} else if (!this.prerelease.length && other.prerelease.length) {
|
1343
|
+
return 1
|
1344
|
+
} else if (!this.prerelease.length && !other.prerelease.length) {
|
1345
|
+
return 0
|
1346
|
+
}
|
1347
|
+
|
1348
|
+
let i = 0;
|
1349
|
+
do {
|
1350
|
+
const a = this.prerelease[i];
|
1351
|
+
const b = other.prerelease[i];
|
1352
|
+
debug_1('prerelease compare', i, a, b);
|
1353
|
+
if (a === undefined && b === undefined) {
|
1354
|
+
return 0
|
1355
|
+
} else if (b === undefined) {
|
1356
|
+
return 1
|
1357
|
+
} else if (a === undefined) {
|
1358
|
+
return -1
|
1359
|
+
} else if (a === b) {
|
1360
|
+
continue
|
1361
|
+
} else {
|
1362
|
+
return compareIdentifiers$1(a, b)
|
1363
|
+
}
|
1364
|
+
} while (++i)
|
1365
|
+
}
|
1366
|
+
|
1367
|
+
compareBuild (other) {
|
1368
|
+
if (!(other instanceof SemVer)) {
|
1369
|
+
other = new SemVer(other, this.options);
|
1370
|
+
}
|
1371
|
+
|
1372
|
+
let i = 0;
|
1373
|
+
do {
|
1374
|
+
const a = this.build[i];
|
1375
|
+
const b = other.build[i];
|
1376
|
+
debug_1('prerelease compare', i, a, b);
|
1377
|
+
if (a === undefined && b === undefined) {
|
1378
|
+
return 0
|
1379
|
+
} else if (b === undefined) {
|
1380
|
+
return 1
|
1381
|
+
} else if (a === undefined) {
|
1382
|
+
return -1
|
1383
|
+
} else if (a === b) {
|
1384
|
+
continue
|
1385
|
+
} else {
|
1386
|
+
return compareIdentifiers$1(a, b)
|
1387
|
+
}
|
1388
|
+
} while (++i)
|
1389
|
+
}
|
1390
|
+
|
1391
|
+
// preminor will bump the version up to the next minor release, and immediately
|
1392
|
+
// down to pre-release. premajor and prepatch work the same way.
|
1393
|
+
inc (release, identifier) {
|
1394
|
+
switch (release) {
|
1395
|
+
case 'premajor':
|
1396
|
+
this.prerelease.length = 0;
|
1397
|
+
this.patch = 0;
|
1398
|
+
this.minor = 0;
|
1399
|
+
this.major++;
|
1400
|
+
this.inc('pre', identifier);
|
1401
|
+
break
|
1402
|
+
case 'preminor':
|
1403
|
+
this.prerelease.length = 0;
|
1404
|
+
this.patch = 0;
|
1405
|
+
this.minor++;
|
1406
|
+
this.inc('pre', identifier);
|
1407
|
+
break
|
1408
|
+
case 'prepatch':
|
1409
|
+
// If this is already a prerelease, it will bump to the next version
|
1410
|
+
// drop any prereleases that might already exist, since they are not
|
1411
|
+
// relevant at this point.
|
1412
|
+
this.prerelease.length = 0;
|
1413
|
+
this.inc('patch', identifier);
|
1414
|
+
this.inc('pre', identifier);
|
1415
|
+
break
|
1416
|
+
// If the input is a non-prerelease version, this acts the same as
|
1417
|
+
// prepatch.
|
1418
|
+
case 'prerelease':
|
1419
|
+
if (this.prerelease.length === 0) {
|
1420
|
+
this.inc('patch', identifier);
|
1421
|
+
}
|
1422
|
+
this.inc('pre', identifier);
|
1423
|
+
break
|
1424
|
+
|
1425
|
+
case 'major':
|
1426
|
+
// If this is a pre-major version, bump up to the same major version.
|
1427
|
+
// Otherwise increment major.
|
1428
|
+
// 1.0.0-5 bumps to 1.0.0
|
1429
|
+
// 1.1.0 bumps to 2.0.0
|
1430
|
+
if (
|
1431
|
+
this.minor !== 0 ||
|
1432
|
+
this.patch !== 0 ||
|
1433
|
+
this.prerelease.length === 0
|
1434
|
+
) {
|
1435
|
+
this.major++;
|
1436
|
+
}
|
1437
|
+
this.minor = 0;
|
1438
|
+
this.patch = 0;
|
1439
|
+
this.prerelease = [];
|
1440
|
+
break
|
1441
|
+
case 'minor':
|
1442
|
+
// If this is a pre-minor version, bump up to the same minor version.
|
1443
|
+
// Otherwise increment minor.
|
1444
|
+
// 1.2.0-5 bumps to 1.2.0
|
1445
|
+
// 1.2.1 bumps to 1.3.0
|
1446
|
+
if (this.patch !== 0 || this.prerelease.length === 0) {
|
1447
|
+
this.minor++;
|
1448
|
+
}
|
1449
|
+
this.patch = 0;
|
1450
|
+
this.prerelease = [];
|
1451
|
+
break
|
1452
|
+
case 'patch':
|
1453
|
+
// If this is not a pre-release version, it will increment the patch.
|
1454
|
+
// If it is a pre-release it will bump up to the same patch version.
|
1455
|
+
// 1.2.0-5 patches to 1.2.0
|
1456
|
+
// 1.2.0 patches to 1.2.1
|
1457
|
+
if (this.prerelease.length === 0) {
|
1458
|
+
this.patch++;
|
1459
|
+
}
|
1460
|
+
this.prerelease = [];
|
1461
|
+
break
|
1462
|
+
// This probably shouldn't be used publicly.
|
1463
|
+
// 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
|
1464
|
+
case 'pre':
|
1465
|
+
if (this.prerelease.length === 0) {
|
1466
|
+
this.prerelease = [0];
|
1467
|
+
} else {
|
1468
|
+
let i = this.prerelease.length;
|
1469
|
+
while (--i >= 0) {
|
1470
|
+
if (typeof this.prerelease[i] === 'number') {
|
1471
|
+
this.prerelease[i]++;
|
1472
|
+
i = -2;
|
1473
|
+
}
|
1474
|
+
}
|
1475
|
+
if (i === -1) {
|
1476
|
+
// didn't increment anything
|
1477
|
+
this.prerelease.push(0);
|
1478
|
+
}
|
1479
|
+
}
|
1480
|
+
if (identifier) {
|
1481
|
+
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,
|
1482
|
+
// 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
|
1483
|
+
if (this.prerelease[0] === identifier) {
|
1484
|
+
if (isNaN(this.prerelease[1])) {
|
1485
|
+
this.prerelease = [identifier, 0];
|
1486
|
+
}
|
1487
|
+
} else {
|
1488
|
+
this.prerelease = [identifier, 0];
|
1489
|
+
}
|
1490
|
+
}
|
1491
|
+
break
|
1492
|
+
|
1493
|
+
default:
|
1494
|
+
throw new Error(`invalid increment argument: ${release}`)
|
1495
|
+
}
|
1496
|
+
this.format();
|
1497
|
+
this.raw = this.version;
|
1498
|
+
return this
|
1499
|
+
}
|
1500
|
+
}
|
1501
|
+
|
1502
|
+
var semver = SemVer;
|
1503
|
+
|
1504
|
+
const {MAX_LENGTH: MAX_LENGTH$2} = constants;
|
1505
|
+
const { re: re$1, t: t$1 } = re_1;
|
1506
|
+
|
1507
|
+
|
1508
|
+
const parse = (version, options) => {
|
1509
|
+
if (!options || typeof options !== 'object') {
|
1510
|
+
options = {
|
1511
|
+
loose: !!options,
|
1512
|
+
includePrerelease: false
|
1513
|
+
};
|
1514
|
+
}
|
1515
|
+
|
1516
|
+
if (version instanceof semver) {
|
1517
|
+
return version
|
1518
|
+
}
|
1519
|
+
|
1520
|
+
if (typeof version !== 'string') {
|
1521
|
+
return null
|
1522
|
+
}
|
1523
|
+
|
1524
|
+
if (version.length > MAX_LENGTH$2) {
|
1525
|
+
return null
|
1526
|
+
}
|
1527
|
+
|
1528
|
+
const r = options.loose ? re$1[t$1.LOOSE] : re$1[t$1.FULL];
|
1529
|
+
if (!r.test(version)) {
|
1530
|
+
return null
|
1531
|
+
}
|
1532
|
+
|
1533
|
+
try {
|
1534
|
+
return new semver(version, options)
|
1535
|
+
} catch (er) {
|
1536
|
+
return null
|
1537
|
+
}
|
1538
|
+
};
|
1539
|
+
|
1540
|
+
var parse_1 = parse;
|
1541
|
+
|
1542
|
+
const valid = (version, options) => {
|
1543
|
+
const v = parse_1(version, options);
|
1544
|
+
return v ? v.version : null
|
1545
|
+
};
|
1546
|
+
var valid_1 = valid;
|
1547
|
+
|
1548
|
+
const clean = (version, options) => {
|
1549
|
+
const s = parse_1(version.trim().replace(/^[=v]+/, ''), options);
|
1550
|
+
return s ? s.version : null
|
1551
|
+
};
|
1552
|
+
var clean_1 = clean;
|
1553
|
+
|
1554
|
+
const inc = (version, release, options, identifier) => {
|
1555
|
+
if (typeof (options) === 'string') {
|
1556
|
+
identifier = options;
|
1557
|
+
options = undefined;
|
1558
|
+
}
|
1559
|
+
|
1560
|
+
try {
|
1561
|
+
return new semver(version, options).inc(release, identifier).version
|
1562
|
+
} catch (er) {
|
1563
|
+
return null
|
1564
|
+
}
|
1565
|
+
};
|
1566
|
+
var inc_1 = inc;
|
1567
|
+
|
1568
|
+
const compare$1 = (a, b, loose) =>
|
1569
|
+
new semver(a, loose).compare(new semver(b, loose));
|
1570
|
+
|
1571
|
+
var compare_1 = compare$1;
|
1572
|
+
|
1573
|
+
const eq = (a, b, loose) => compare_1(a, b, loose) === 0;
|
1574
|
+
var eq_1 = eq;
|
1575
|
+
|
1576
|
+
const diff = (version1, version2) => {
|
1577
|
+
if (eq_1(version1, version2)) {
|
1578
|
+
return null
|
1579
|
+
} else {
|
1580
|
+
const v1 = parse_1(version1);
|
1581
|
+
const v2 = parse_1(version2);
|
1582
|
+
const hasPre = v1.prerelease.length || v2.prerelease.length;
|
1583
|
+
const prefix = hasPre ? 'pre' : '';
|
1584
|
+
const defaultResult = hasPre ? 'prerelease' : '';
|
1585
|
+
for (const key in v1) {
|
1586
|
+
if (key === 'major' || key === 'minor' || key === 'patch') {
|
1587
|
+
if (v1[key] !== v2[key]) {
|
1588
|
+
return prefix + key
|
1589
|
+
}
|
1590
|
+
}
|
1591
|
+
}
|
1592
|
+
return defaultResult // may be undefined
|
1593
|
+
}
|
1594
|
+
};
|
1595
|
+
var diff_1 = diff;
|
1596
|
+
|
1597
|
+
const major = (a, loose) => new semver(a, loose).major;
|
1598
|
+
var major_1 = major;
|
1599
|
+
|
1600
|
+
const minor = (a, loose) => new semver(a, loose).minor;
|
1601
|
+
var minor_1 = minor;
|
1602
|
+
|
1603
|
+
const patch = (a, loose) => new semver(a, loose).patch;
|
1604
|
+
var patch_1 = patch;
|
1605
|
+
|
1606
|
+
const prerelease = (version, options) => {
|
1607
|
+
const parsed = parse_1(version, options);
|
1608
|
+
return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
|
1609
|
+
};
|
1610
|
+
var prerelease_1 = prerelease;
|
1611
|
+
|
1612
|
+
const rcompare = (a, b, loose) => compare_1(b, a, loose);
|
1613
|
+
var rcompare_1 = rcompare;
|
1614
|
+
|
1615
|
+
const compareLoose = (a, b) => compare_1(a, b, true);
|
1616
|
+
var compareLoose_1 = compareLoose;
|
1617
|
+
|
1618
|
+
const compareBuild = (a, b, loose) => {
|
1619
|
+
const versionA = new semver(a, loose);
|
1620
|
+
const versionB = new semver(b, loose);
|
1621
|
+
return versionA.compare(versionB) || versionA.compareBuild(versionB)
|
1622
|
+
};
|
1623
|
+
var compareBuild_1 = compareBuild;
|
1624
|
+
|
1625
|
+
const sort = (list, loose) => list.sort((a, b) => compareBuild_1(a, b, loose));
|
1626
|
+
var sort_1 = sort;
|
1627
|
+
|
1628
|
+
const rsort = (list, loose) => list.sort((a, b) => compareBuild_1(b, a, loose));
|
1629
|
+
var rsort_1 = rsort;
|
1630
|
+
|
1631
|
+
const gt = (a, b, loose) => compare_1(a, b, loose) > 0;
|
1632
|
+
var gt_1 = gt;
|
1633
|
+
|
1634
|
+
const lt = (a, b, loose) => compare_1(a, b, loose) < 0;
|
1635
|
+
var lt_1 = lt;
|
1636
|
+
|
1637
|
+
const neq = (a, b, loose) => compare_1(a, b, loose) !== 0;
|
1638
|
+
var neq_1 = neq;
|
1639
|
+
|
1640
|
+
const gte = (a, b, loose) => compare_1(a, b, loose) >= 0;
|
1641
|
+
var gte_1 = gte;
|
1642
|
+
|
1643
|
+
const lte = (a, b, loose) => compare_1(a, b, loose) <= 0;
|
1644
|
+
var lte_1 = lte;
|
1645
|
+
|
1646
|
+
const cmp = (a, op, b, loose) => {
|
1647
|
+
switch (op) {
|
1648
|
+
case '===':
|
1649
|
+
if (typeof a === 'object')
|
1650
|
+
a = a.version;
|
1651
|
+
if (typeof b === 'object')
|
1652
|
+
b = b.version;
|
1653
|
+
return a === b
|
1654
|
+
|
1655
|
+
case '!==':
|
1656
|
+
if (typeof a === 'object')
|
1657
|
+
a = a.version;
|
1658
|
+
if (typeof b === 'object')
|
1659
|
+
b = b.version;
|
1660
|
+
return a !== b
|
1661
|
+
|
1662
|
+
case '':
|
1663
|
+
case '=':
|
1664
|
+
case '==':
|
1665
|
+
return eq_1(a, b, loose)
|
1666
|
+
|
1667
|
+
case '!=':
|
1668
|
+
return neq_1(a, b, loose)
|
1669
|
+
|
1670
|
+
case '>':
|
1671
|
+
return gt_1(a, b, loose)
|
1672
|
+
|
1673
|
+
case '>=':
|
1674
|
+
return gte_1(a, b, loose)
|
1675
|
+
|
1676
|
+
case '<':
|
1677
|
+
return lt_1(a, b, loose)
|
1678
|
+
|
1679
|
+
case '<=':
|
1680
|
+
return lte_1(a, b, loose)
|
1681
|
+
|
1682
|
+
default:
|
1683
|
+
throw new TypeError(`Invalid operator: ${op}`)
|
1684
|
+
}
|
1685
|
+
};
|
1686
|
+
var cmp_1 = cmp;
|
1687
|
+
|
1688
|
+
const {re: re$2, t: t$2} = re_1;
|
1689
|
+
|
1690
|
+
const coerce = (version, options) => {
|
1691
|
+
if (version instanceof semver) {
|
1692
|
+
return version
|
1693
|
+
}
|
1694
|
+
|
1695
|
+
if (typeof version === 'number') {
|
1696
|
+
version = String(version);
|
1697
|
+
}
|
1698
|
+
|
1699
|
+
if (typeof version !== 'string') {
|
1700
|
+
return null
|
1701
|
+
}
|
1702
|
+
|
1703
|
+
options = options || {};
|
1704
|
+
|
1705
|
+
let match = null;
|
1706
|
+
if (!options.rtl) {
|
1707
|
+
match = version.match(re$2[t$2.COERCE]);
|
1708
|
+
} else {
|
1709
|
+
// Find the right-most coercible string that does not share
|
1710
|
+
// a terminus with a more left-ward coercible string.
|
1711
|
+
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
|
1712
|
+
//
|
1713
|
+
// Walk through the string checking with a /g regexp
|
1714
|
+
// Manually set the index so as to pick up overlapping matches.
|
1715
|
+
// Stop when we get a match that ends at the string end, since no
|
1716
|
+
// coercible string can be more right-ward without the same terminus.
|
1717
|
+
let next;
|
1718
|
+
while ((next = re$2[t$2.COERCERTL].exec(version)) &&
|
1719
|
+
(!match || match.index + match[0].length !== version.length)
|
1720
|
+
) {
|
1721
|
+
if (!match ||
|
1722
|
+
next.index + next[0].length !== match.index + match[0].length) {
|
1723
|
+
match = next;
|
1724
|
+
}
|
1725
|
+
re$2[t$2.COERCERTL].lastIndex = next.index + next[1].length + next[2].length;
|
1726
|
+
}
|
1727
|
+
// leave it in a clean state
|
1728
|
+
re$2[t$2.COERCERTL].lastIndex = -1;
|
1729
|
+
}
|
1730
|
+
|
1731
|
+
if (match === null)
|
1732
|
+
return null
|
1733
|
+
|
1734
|
+
return parse_1(`${match[2]}.${match[3] || '0'}.${match[4] || '0'}`, options)
|
1735
|
+
};
|
1736
|
+
var coerce_1 = coerce;
|
1737
|
+
|
1738
|
+
// hoisted class for cyclic dependency
|
1739
|
+
class Range {
|
1740
|
+
constructor (range, options) {
|
1741
|
+
if (!options || typeof options !== 'object') {
|
1742
|
+
options = {
|
1743
|
+
loose: !!options,
|
1744
|
+
includePrerelease: false
|
1745
|
+
};
|
1746
|
+
}
|
1747
|
+
|
1748
|
+
if (range instanceof Range) {
|
1749
|
+
if (
|
1750
|
+
range.loose === !!options.loose &&
|
1751
|
+
range.includePrerelease === !!options.includePrerelease
|
1752
|
+
) {
|
1753
|
+
return range
|
1754
|
+
} else {
|
1755
|
+
return new Range(range.raw, options)
|
1756
|
+
}
|
1757
|
+
}
|
1758
|
+
|
1759
|
+
if (range instanceof comparator) {
|
1760
|
+
// just put it in the set and return
|
1761
|
+
this.raw = range.value;
|
1762
|
+
this.set = [[range]];
|
1763
|
+
this.format();
|
1764
|
+
return this
|
1765
|
+
}
|
1766
|
+
|
1767
|
+
this.options = options;
|
1768
|
+
this.loose = !!options.loose;
|
1769
|
+
this.includePrerelease = !!options.includePrerelease;
|
1770
|
+
|
1771
|
+
// First, split based on boolean or ||
|
1772
|
+
this.raw = range;
|
1773
|
+
this.set = range
|
1774
|
+
.split(/\s*\|\|\s*/)
|
1775
|
+
// map the range to a 2d array of comparators
|
1776
|
+
.map(range => this.parseRange(range.trim()))
|
1777
|
+
// throw out any comparator lists that are empty
|
1778
|
+
// this generally means that it was not a valid range, which is allowed
|
1779
|
+
// in loose mode, but will still throw if the WHOLE range is invalid.
|
1780
|
+
.filter(c => c.length);
|
1781
|
+
|
1782
|
+
if (!this.set.length) {
|
1783
|
+
throw new TypeError(`Invalid SemVer Range: ${range}`)
|
1784
|
+
}
|
1785
|
+
|
1786
|
+
this.format();
|
1787
|
+
}
|
1788
|
+
|
1789
|
+
format () {
|
1790
|
+
this.range = this.set
|
1791
|
+
.map((comps) => {
|
1792
|
+
return comps.join(' ').trim()
|
1793
|
+
})
|
1794
|
+
.join('||')
|
1795
|
+
.trim();
|
1796
|
+
return this.range
|
1797
|
+
}
|
1798
|
+
|
1799
|
+
toString () {
|
1800
|
+
return this.range
|
1801
|
+
}
|
1802
|
+
|
1803
|
+
parseRange (range) {
|
1804
|
+
const loose = this.options.loose;
|
1805
|
+
range = range.trim();
|
1806
|
+
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
1807
|
+
const hr = loose ? re$3[t$3.HYPHENRANGELOOSE] : re$3[t$3.HYPHENRANGE];
|
1808
|
+
range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
|
1809
|
+
debug_1('hyphen replace', range);
|
1810
|
+
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
1811
|
+
range = range.replace(re$3[t$3.COMPARATORTRIM], comparatorTrimReplace);
|
1812
|
+
debug_1('comparator trim', range, re$3[t$3.COMPARATORTRIM]);
|
1813
|
+
|
1814
|
+
// `~ 1.2.3` => `~1.2.3`
|
1815
|
+
range = range.replace(re$3[t$3.TILDETRIM], tildeTrimReplace);
|
1816
|
+
|
1817
|
+
// `^ 1.2.3` => `^1.2.3`
|
1818
|
+
range = range.replace(re$3[t$3.CARETTRIM], caretTrimReplace);
|
1819
|
+
|
1820
|
+
// normalize spaces
|
1821
|
+
range = range.split(/\s+/).join(' ');
|
1822
|
+
|
1823
|
+
// At this point, the range is completely trimmed and
|
1824
|
+
// ready to be split into comparators.
|
1825
|
+
|
1826
|
+
const compRe = loose ? re$3[t$3.COMPARATORLOOSE] : re$3[t$3.COMPARATOR];
|
1827
|
+
return range
|
1828
|
+
.split(' ')
|
1829
|
+
.map(comp => parseComparator(comp, this.options))
|
1830
|
+
.join(' ')
|
1831
|
+
.split(/\s+/)
|
1832
|
+
.map(comp => replaceGTE0(comp, this.options))
|
1833
|
+
// in loose mode, throw out any that are not valid comparators
|
1834
|
+
.filter(this.options.loose ? comp => !!comp.match(compRe) : () => true)
|
1835
|
+
.map(comp => new comparator(comp, this.options))
|
1836
|
+
}
|
1837
|
+
|
1838
|
+
intersects (range, options) {
|
1839
|
+
if (!(range instanceof Range)) {
|
1840
|
+
throw new TypeError('a Range is required')
|
1841
|
+
}
|
1842
|
+
|
1843
|
+
return this.set.some((thisComparators) => {
|
1844
|
+
return (
|
1845
|
+
isSatisfiable(thisComparators, options) &&
|
1846
|
+
range.set.some((rangeComparators) => {
|
1847
|
+
return (
|
1848
|
+
isSatisfiable(rangeComparators, options) &&
|
1849
|
+
thisComparators.every((thisComparator) => {
|
1850
|
+
return rangeComparators.every((rangeComparator) => {
|
1851
|
+
return thisComparator.intersects(rangeComparator, options)
|
1852
|
+
})
|
1853
|
+
})
|
1854
|
+
)
|
1855
|
+
})
|
1856
|
+
)
|
1857
|
+
})
|
1858
|
+
}
|
1859
|
+
|
1860
|
+
// if ANY of the sets match ALL of its comparators, then pass
|
1861
|
+
test (version) {
|
1862
|
+
if (!version) {
|
1863
|
+
return false
|
1864
|
+
}
|
1865
|
+
|
1866
|
+
if (typeof version === 'string') {
|
1867
|
+
try {
|
1868
|
+
version = new semver(version, this.options);
|
1869
|
+
} catch (er) {
|
1870
|
+
return false
|
1871
|
+
}
|
1872
|
+
}
|
1873
|
+
|
1874
|
+
for (let i = 0; i < this.set.length; i++) {
|
1875
|
+
if (testSet(this.set[i], version, this.options)) {
|
1876
|
+
return true
|
1877
|
+
}
|
1878
|
+
}
|
1879
|
+
return false
|
1880
|
+
}
|
1881
|
+
}
|
1882
|
+
var range = Range;
|
1883
|
+
|
1884
|
+
|
1885
|
+
|
1886
|
+
|
1887
|
+
const {
|
1888
|
+
re: re$3,
|
1889
|
+
t: t$3,
|
1890
|
+
comparatorTrimReplace,
|
1891
|
+
tildeTrimReplace,
|
1892
|
+
caretTrimReplace
|
1893
|
+
} = re_1;
|
1894
|
+
|
1895
|
+
// take a set of comparators and determine whether there
|
1896
|
+
// exists a version which can satisfy it
|
1897
|
+
const isSatisfiable = (comparators, options) => {
|
1898
|
+
let result = true;
|
1899
|
+
const remainingComparators = comparators.slice();
|
1900
|
+
let testComparator = remainingComparators.pop();
|
1901
|
+
|
1902
|
+
while (result && remainingComparators.length) {
|
1903
|
+
result = remainingComparators.every((otherComparator) => {
|
1904
|
+
return testComparator.intersects(otherComparator, options)
|
1905
|
+
});
|
1906
|
+
|
1907
|
+
testComparator = remainingComparators.pop();
|
1908
|
+
}
|
1909
|
+
|
1910
|
+
return result
|
1911
|
+
};
|
1912
|
+
|
1913
|
+
// comprised of xranges, tildes, stars, and gtlt's at this point.
|
1914
|
+
// already replaced the hyphen ranges
|
1915
|
+
// turn into a set of JUST comparators.
|
1916
|
+
const parseComparator = (comp, options) => {
|
1917
|
+
debug_1('comp', comp, options);
|
1918
|
+
comp = replaceCarets(comp, options);
|
1919
|
+
debug_1('caret', comp);
|
1920
|
+
comp = replaceTildes(comp, options);
|
1921
|
+
debug_1('tildes', comp);
|
1922
|
+
comp = replaceXRanges(comp, options);
|
1923
|
+
debug_1('xrange', comp);
|
1924
|
+
comp = replaceStars(comp, options);
|
1925
|
+
debug_1('stars', comp);
|
1926
|
+
return comp
|
1927
|
+
};
|
1928
|
+
|
1929
|
+
const isX = id => !id || id.toLowerCase() === 'x' || id === '*';
|
1930
|
+
|
1931
|
+
// ~, ~> --> * (any, kinda silly)
|
1932
|
+
// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
|
1933
|
+
// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
|
1934
|
+
// ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
|
1935
|
+
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
|
1936
|
+
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
|
1937
|
+
const replaceTildes = (comp, options) =>
|
1938
|
+
comp.trim().split(/\s+/).map((comp) => {
|
1939
|
+
return replaceTilde(comp, options)
|
1940
|
+
}).join(' ');
|
1941
|
+
|
1942
|
+
const replaceTilde = (comp, options) => {
|
1943
|
+
const r = options.loose ? re$3[t$3.TILDELOOSE] : re$3[t$3.TILDE];
|
1944
|
+
return comp.replace(r, (_, M, m, p, pr) => {
|
1945
|
+
debug_1('tilde', comp, _, M, m, p, pr);
|
1946
|
+
let ret;
|
1947
|
+
|
1948
|
+
if (isX(M)) {
|
1949
|
+
ret = '';
|
1950
|
+
} else if (isX(m)) {
|
1951
|
+
ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
|
1952
|
+
} else if (isX(p)) {
|
1953
|
+
// ~1.2 == >=1.2.0 <1.3.0-0
|
1954
|
+
ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
|
1955
|
+
} else if (pr) {
|
1956
|
+
debug_1('replaceTilde pr', pr);
|
1957
|
+
ret = `>=${M}.${m}.${p}-${pr
|
1958
|
+
} <${M}.${+m + 1}.0-0`;
|
1959
|
+
} else {
|
1960
|
+
// ~1.2.3 == >=1.2.3 <1.3.0-0
|
1961
|
+
ret = `>=${M}.${m}.${p
|
1962
|
+
} <${M}.${+m + 1}.0-0`;
|
1963
|
+
}
|
1964
|
+
|
1965
|
+
debug_1('tilde return', ret);
|
1966
|
+
return ret
|
1967
|
+
})
|
1968
|
+
};
|
1969
|
+
|
1970
|
+
// ^ --> * (any, kinda silly)
|
1971
|
+
// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
|
1972
|
+
// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
|
1973
|
+
// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
|
1974
|
+
// ^1.2.3 --> >=1.2.3 <2.0.0-0
|
1975
|
+
// ^1.2.0 --> >=1.2.0 <2.0.0-0
|
1976
|
+
const replaceCarets = (comp, options) =>
|
1977
|
+
comp.trim().split(/\s+/).map((comp) => {
|
1978
|
+
return replaceCaret(comp, options)
|
1979
|
+
}).join(' ');
|
1980
|
+
|
1981
|
+
const replaceCaret = (comp, options) => {
|
1982
|
+
debug_1('caret', comp, options);
|
1983
|
+
const r = options.loose ? re$3[t$3.CARETLOOSE] : re$3[t$3.CARET];
|
1984
|
+
const z = options.includePrerelease ? '-0' : '';
|
1985
|
+
return comp.replace(r, (_, M, m, p, pr) => {
|
1986
|
+
debug_1('caret', comp, _, M, m, p, pr);
|
1987
|
+
let ret;
|
1988
|
+
|
1989
|
+
if (isX(M)) {
|
1990
|
+
ret = '';
|
1991
|
+
} else if (isX(m)) {
|
1992
|
+
ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
1993
|
+
} else if (isX(p)) {
|
1994
|
+
if (M === '0') {
|
1995
|
+
ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
1996
|
+
} else {
|
1997
|
+
ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
|
1998
|
+
}
|
1999
|
+
} else if (pr) {
|
2000
|
+
debug_1('replaceCaret pr', pr);
|
2001
|
+
if (M === '0') {
|
2002
|
+
if (m === '0') {
|
2003
|
+
ret = `>=${M}.${m}.${p}-${pr
|
2004
|
+
} <${M}.${m}.${+p + 1}-0`;
|
2005
|
+
} else {
|
2006
|
+
ret = `>=${M}.${m}.${p}-${pr
|
2007
|
+
} <${M}.${+m + 1}.0-0`;
|
2008
|
+
}
|
2009
|
+
} else {
|
2010
|
+
ret = `>=${M}.${m}.${p}-${pr
|
2011
|
+
} <${+M + 1}.0.0-0`;
|
2012
|
+
}
|
2013
|
+
} else {
|
2014
|
+
debug_1('no pr');
|
2015
|
+
if (M === '0') {
|
2016
|
+
if (m === '0') {
|
2017
|
+
ret = `>=${M}.${m}.${p
|
2018
|
+
}${z} <${M}.${m}.${+p + 1}-0`;
|
2019
|
+
} else {
|
2020
|
+
ret = `>=${M}.${m}.${p
|
2021
|
+
}${z} <${M}.${+m + 1}.0-0`;
|
2022
|
+
}
|
2023
|
+
} else {
|
2024
|
+
ret = `>=${M}.${m}.${p
|
2025
|
+
} <${+M + 1}.0.0-0`;
|
2026
|
+
}
|
2027
|
+
}
|
2028
|
+
|
2029
|
+
debug_1('caret return', ret);
|
2030
|
+
return ret
|
2031
|
+
})
|
2032
|
+
};
|
2033
|
+
|
2034
|
+
const replaceXRanges = (comp, options) => {
|
2035
|
+
debug_1('replaceXRanges', comp, options);
|
2036
|
+
return comp.split(/\s+/).map((comp) => {
|
2037
|
+
return replaceXRange(comp, options)
|
2038
|
+
}).join(' ')
|
2039
|
+
};
|
2040
|
+
|
2041
|
+
const replaceXRange = (comp, options) => {
|
2042
|
+
comp = comp.trim();
|
2043
|
+
const r = options.loose ? re$3[t$3.XRANGELOOSE] : re$3[t$3.XRANGE];
|
2044
|
+
return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
|
2045
|
+
debug_1('xRange', comp, ret, gtlt, M, m, p, pr);
|
2046
|
+
const xM = isX(M);
|
2047
|
+
const xm = xM || isX(m);
|
2048
|
+
const xp = xm || isX(p);
|
2049
|
+
const anyX = xp;
|
2050
|
+
|
2051
|
+
if (gtlt === '=' && anyX) {
|
2052
|
+
gtlt = '';
|
2053
|
+
}
|
2054
|
+
|
2055
|
+
// if we're including prereleases in the match, then we need
|
2056
|
+
// to fix this to -0, the lowest possible prerelease value
|
2057
|
+
pr = options.includePrerelease ? '-0' : '';
|
2058
|
+
|
2059
|
+
if (xM) {
|
2060
|
+
if (gtlt === '>' || gtlt === '<') {
|
2061
|
+
// nothing is allowed
|
2062
|
+
ret = '<0.0.0-0';
|
2063
|
+
} else {
|
2064
|
+
// nothing is forbidden
|
2065
|
+
ret = '*';
|
2066
|
+
}
|
2067
|
+
} else if (gtlt && anyX) {
|
2068
|
+
// we know patch is an x, because we have any x at all.
|
2069
|
+
// replace X with 0
|
2070
|
+
if (xm) {
|
2071
|
+
m = 0;
|
2072
|
+
}
|
2073
|
+
p = 0;
|
2074
|
+
|
2075
|
+
if (gtlt === '>') {
|
2076
|
+
// >1 => >=2.0.0
|
2077
|
+
// >1.2 => >=1.3.0
|
2078
|
+
gtlt = '>=';
|
2079
|
+
if (xm) {
|
2080
|
+
M = +M + 1;
|
2081
|
+
m = 0;
|
2082
|
+
p = 0;
|
2083
|
+
} else {
|
2084
|
+
m = +m + 1;
|
2085
|
+
p = 0;
|
2086
|
+
}
|
2087
|
+
} else if (gtlt === '<=') {
|
2088
|
+
// <=0.7.x is actually <0.8.0, since any 0.7.x should
|
2089
|
+
// pass. Similarly, <=7.x is actually <8.0.0, etc.
|
2090
|
+
gtlt = '<';
|
2091
|
+
if (xm) {
|
2092
|
+
M = +M + 1;
|
2093
|
+
} else {
|
2094
|
+
m = +m + 1;
|
2095
|
+
}
|
2096
|
+
}
|
2097
|
+
|
2098
|
+
if (gtlt === '<')
|
2099
|
+
pr = '-0';
|
2100
|
+
|
2101
|
+
ret = `${gtlt + M}.${m}.${p}${pr}`;
|
2102
|
+
} else if (xm) {
|
2103
|
+
ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
|
2104
|
+
} else if (xp) {
|
2105
|
+
ret = `>=${M}.${m}.0${pr
|
2106
|
+
} <${M}.${+m + 1}.0-0`;
|
2107
|
+
}
|
2108
|
+
|
2109
|
+
debug_1('xRange return', ret);
|
2110
|
+
|
2111
|
+
return ret
|
2112
|
+
})
|
2113
|
+
};
|
2114
|
+
|
2115
|
+
// Because * is AND-ed with everything else in the comparator,
|
2116
|
+
// and '' means "any version", just remove the *s entirely.
|
2117
|
+
const replaceStars = (comp, options) => {
|
2118
|
+
debug_1('replaceStars', comp, options);
|
2119
|
+
// Looseness is ignored here. star is always as loose as it gets!
|
2120
|
+
return comp.trim().replace(re$3[t$3.STAR], '')
|
2121
|
+
};
|
2122
|
+
|
2123
|
+
const replaceGTE0 = (comp, options) => {
|
2124
|
+
debug_1('replaceGTE0', comp, options);
|
2125
|
+
return comp.trim()
|
2126
|
+
.replace(re$3[options.includePrerelease ? t$3.GTE0PRE : t$3.GTE0], '')
|
2127
|
+
};
|
2128
|
+
|
2129
|
+
// This function is passed to string.replace(re[t.HYPHENRANGE])
|
2130
|
+
// M, m, patch, prerelease, build
|
2131
|
+
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
|
2132
|
+
// 1.2.3 - 3.4 => >=1.2.0 <3.5.0-0 Any 3.4.x will do
|
2133
|
+
// 1.2 - 3.4 => >=1.2.0 <3.5.0-0
|
2134
|
+
const hyphenReplace = incPr => ($0,
|
2135
|
+
from, fM, fm, fp, fpr, fb,
|
2136
|
+
to, tM, tm, tp, tpr, tb) => {
|
2137
|
+
if (isX(fM)) {
|
2138
|
+
from = '';
|
2139
|
+
} else if (isX(fm)) {
|
2140
|
+
from = `>=${fM}.0.0${incPr ? '-0' : ''}`;
|
2141
|
+
} else if (isX(fp)) {
|
2142
|
+
from = `>=${fM}.${fm}.0${incPr ? '-0' : ''}`;
|
2143
|
+
} else if (fpr) {
|
2144
|
+
from = `>=${from}`;
|
2145
|
+
} else {
|
2146
|
+
from = `>=${from}${incPr ? '-0' : ''}`;
|
2147
|
+
}
|
2148
|
+
|
2149
|
+
if (isX(tM)) {
|
2150
|
+
to = '';
|
2151
|
+
} else if (isX(tm)) {
|
2152
|
+
to = `<${+tM + 1}.0.0-0`;
|
2153
|
+
} else if (isX(tp)) {
|
2154
|
+
to = `<${tM}.${+tm + 1}.0-0`;
|
2155
|
+
} else if (tpr) {
|
2156
|
+
to = `<=${tM}.${tm}.${tp}-${tpr}`;
|
2157
|
+
} else if (incPr) {
|
2158
|
+
to = `<${tM}.${tm}.${+tp + 1}-0`;
|
2159
|
+
} else {
|
2160
|
+
to = `<=${to}`;
|
2161
|
+
}
|
2162
|
+
|
2163
|
+
return (`${from} ${to}`).trim()
|
2164
|
+
};
|
2165
|
+
|
2166
|
+
const testSet = (set, version, options) => {
|
2167
|
+
for (let i = 0; i < set.length; i++) {
|
2168
|
+
if (!set[i].test(version)) {
|
2169
|
+
return false
|
2170
|
+
}
|
2171
|
+
}
|
2172
|
+
|
2173
|
+
if (version.prerelease.length && !options.includePrerelease) {
|
2174
|
+
// Find the set of versions that are allowed to have prereleases
|
2175
|
+
// For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
|
2176
|
+
// That should allow `1.2.3-pr.2` to pass.
|
2177
|
+
// However, `1.2.4-alpha.notready` should NOT be allowed,
|
2178
|
+
// even though it's within the range set by the comparators.
|
2179
|
+
for (let i = 0; i < set.length; i++) {
|
2180
|
+
debug_1(set[i].semver);
|
2181
|
+
if (set[i].semver === comparator.ANY) {
|
2182
|
+
continue
|
2183
|
+
}
|
2184
|
+
|
2185
|
+
if (set[i].semver.prerelease.length > 0) {
|
2186
|
+
const allowed = set[i].semver;
|
2187
|
+
if (allowed.major === version.major &&
|
2188
|
+
allowed.minor === version.minor &&
|
2189
|
+
allowed.patch === version.patch) {
|
2190
|
+
return true
|
2191
|
+
}
|
2192
|
+
}
|
2193
|
+
}
|
2194
|
+
|
2195
|
+
// Version has a -pre, but it's not one of the ones we like.
|
2196
|
+
return false
|
2197
|
+
}
|
2198
|
+
|
2199
|
+
return true
|
2200
|
+
};
|
2201
|
+
|
2202
|
+
const ANY = Symbol('SemVer ANY');
|
2203
|
+
// hoisted class for cyclic dependency
|
2204
|
+
class Comparator {
|
2205
|
+
static get ANY () {
|
2206
|
+
return ANY
|
2207
|
+
}
|
2208
|
+
constructor (comp, options) {
|
2209
|
+
if (!options || typeof options !== 'object') {
|
2210
|
+
options = {
|
2211
|
+
loose: !!options,
|
2212
|
+
includePrerelease: false
|
2213
|
+
};
|
2214
|
+
}
|
2215
|
+
|
2216
|
+
if (comp instanceof Comparator) {
|
2217
|
+
if (comp.loose === !!options.loose) {
|
2218
|
+
return comp
|
2219
|
+
} else {
|
2220
|
+
comp = comp.value;
|
2221
|
+
}
|
2222
|
+
}
|
2223
|
+
|
2224
|
+
debug_1('comparator', comp, options);
|
2225
|
+
this.options = options;
|
2226
|
+
this.loose = !!options.loose;
|
2227
|
+
this.parse(comp);
|
2228
|
+
|
2229
|
+
if (this.semver === ANY) {
|
2230
|
+
this.value = '';
|
2231
|
+
} else {
|
2232
|
+
this.value = this.operator + this.semver.version;
|
2233
|
+
}
|
2234
|
+
|
2235
|
+
debug_1('comp', this);
|
2236
|
+
}
|
2237
|
+
|
2238
|
+
parse (comp) {
|
2239
|
+
const r = this.options.loose ? re$4[t$4.COMPARATORLOOSE] : re$4[t$4.COMPARATOR];
|
2240
|
+
const m = comp.match(r);
|
2241
|
+
|
2242
|
+
if (!m) {
|
2243
|
+
throw new TypeError(`Invalid comparator: ${comp}`)
|
2244
|
+
}
|
2245
|
+
|
2246
|
+
this.operator = m[1] !== undefined ? m[1] : '';
|
2247
|
+
if (this.operator === '=') {
|
2248
|
+
this.operator = '';
|
2249
|
+
}
|
2250
|
+
|
2251
|
+
// if it literally is just '>' or '' then allow anything.
|
2252
|
+
if (!m[2]) {
|
2253
|
+
this.semver = ANY;
|
2254
|
+
} else {
|
2255
|
+
this.semver = new semver(m[2], this.options.loose);
|
2256
|
+
}
|
2257
|
+
}
|
2258
|
+
|
2259
|
+
toString () {
|
2260
|
+
return this.value
|
2261
|
+
}
|
2262
|
+
|
2263
|
+
test (version) {
|
2264
|
+
debug_1('Comparator.test', version, this.options.loose);
|
2265
|
+
|
2266
|
+
if (this.semver === ANY || version === ANY) {
|
2267
|
+
return true
|
2268
|
+
}
|
2269
|
+
|
2270
|
+
if (typeof version === 'string') {
|
2271
|
+
try {
|
2272
|
+
version = new semver(version, this.options);
|
2273
|
+
} catch (er) {
|
2274
|
+
return false
|
2275
|
+
}
|
2276
|
+
}
|
2277
|
+
|
2278
|
+
return cmp_1(version, this.operator, this.semver, this.options)
|
2279
|
+
}
|
2280
|
+
|
2281
|
+
intersects (comp, options) {
|
2282
|
+
if (!(comp instanceof Comparator)) {
|
2283
|
+
throw new TypeError('a Comparator is required')
|
2284
|
+
}
|
2285
|
+
|
2286
|
+
if (!options || typeof options !== 'object') {
|
2287
|
+
options = {
|
2288
|
+
loose: !!options,
|
2289
|
+
includePrerelease: false
|
2290
|
+
};
|
2291
|
+
}
|
2292
|
+
|
2293
|
+
if (this.operator === '') {
|
2294
|
+
if (this.value === '') {
|
2295
|
+
return true
|
2296
|
+
}
|
2297
|
+
return new range(comp.value, options).test(this.value)
|
2298
|
+
} else if (comp.operator === '') {
|
2299
|
+
if (comp.value === '') {
|
2300
|
+
return true
|
2301
|
+
}
|
2302
|
+
return new range(this.value, options).test(comp.semver)
|
2303
|
+
}
|
2304
|
+
|
2305
|
+
const sameDirectionIncreasing =
|
2306
|
+
(this.operator === '>=' || this.operator === '>') &&
|
2307
|
+
(comp.operator === '>=' || comp.operator === '>');
|
2308
|
+
const sameDirectionDecreasing =
|
2309
|
+
(this.operator === '<=' || this.operator === '<') &&
|
2310
|
+
(comp.operator === '<=' || comp.operator === '<');
|
2311
|
+
const sameSemVer = this.semver.version === comp.semver.version;
|
2312
|
+
const differentDirectionsInclusive =
|
2313
|
+
(this.operator === '>=' || this.operator === '<=') &&
|
2314
|
+
(comp.operator === '>=' || comp.operator === '<=');
|
2315
|
+
const oppositeDirectionsLessThan =
|
2316
|
+
cmp_1(this.semver, '<', comp.semver, options) &&
|
2317
|
+
(this.operator === '>=' || this.operator === '>') &&
|
2318
|
+
(comp.operator === '<=' || comp.operator === '<');
|
2319
|
+
const oppositeDirectionsGreaterThan =
|
2320
|
+
cmp_1(this.semver, '>', comp.semver, options) &&
|
2321
|
+
(this.operator === '<=' || this.operator === '<') &&
|
2322
|
+
(comp.operator === '>=' || comp.operator === '>');
|
2323
|
+
|
2324
|
+
return (
|
2325
|
+
sameDirectionIncreasing ||
|
2326
|
+
sameDirectionDecreasing ||
|
2327
|
+
(sameSemVer && differentDirectionsInclusive) ||
|
2328
|
+
oppositeDirectionsLessThan ||
|
2329
|
+
oppositeDirectionsGreaterThan
|
2330
|
+
)
|
2331
|
+
}
|
2332
|
+
}
|
2333
|
+
|
2334
|
+
var comparator = Comparator;
|
2335
|
+
|
2336
|
+
const {re: re$4, t: t$4} = re_1;
|
2337
|
+
|
2338
|
+
const satisfies = (version, range$1, options) => {
|
2339
|
+
try {
|
2340
|
+
range$1 = new range(range$1, options);
|
2341
|
+
} catch (er) {
|
2342
|
+
return false
|
2343
|
+
}
|
2344
|
+
return range$1.test(version)
|
2345
|
+
};
|
2346
|
+
var satisfies_1 = satisfies;
|
2347
|
+
|
2348
|
+
// Mostly just for testing and legacy API reasons
|
2349
|
+
const toComparators = (range$1, options) =>
|
2350
|
+
new range(range$1, options).set
|
2351
|
+
.map(comp => comp.map(c => c.value).join(' ').trim().split(' '));
|
2352
|
+
|
2353
|
+
var toComparators_1 = toComparators;
|
2354
|
+
|
2355
|
+
const maxSatisfying = (versions, range$1, options) => {
|
2356
|
+
let max = null;
|
2357
|
+
let maxSV = null;
|
2358
|
+
let rangeObj = null;
|
2359
|
+
try {
|
2360
|
+
rangeObj = new range(range$1, options);
|
2361
|
+
} catch (er) {
|
2362
|
+
return null
|
2363
|
+
}
|
2364
|
+
versions.forEach((v) => {
|
2365
|
+
if (rangeObj.test(v)) {
|
2366
|
+
// satisfies(v, range, options)
|
2367
|
+
if (!max || maxSV.compare(v) === -1) {
|
2368
|
+
// compare(max, v, true)
|
2369
|
+
max = v;
|
2370
|
+
maxSV = new semver(max, options);
|
2371
|
+
}
|
2372
|
+
}
|
2373
|
+
});
|
2374
|
+
return max
|
2375
|
+
};
|
2376
|
+
var maxSatisfying_1 = maxSatisfying;
|
2377
|
+
|
2378
|
+
const minSatisfying = (versions, range$1, options) => {
|
2379
|
+
let min = null;
|
2380
|
+
let minSV = null;
|
2381
|
+
let rangeObj = null;
|
2382
|
+
try {
|
2383
|
+
rangeObj = new range(range$1, options);
|
2384
|
+
} catch (er) {
|
2385
|
+
return null
|
2386
|
+
}
|
2387
|
+
versions.forEach((v) => {
|
2388
|
+
if (rangeObj.test(v)) {
|
2389
|
+
// satisfies(v, range, options)
|
2390
|
+
if (!min || minSV.compare(v) === 1) {
|
2391
|
+
// compare(min, v, true)
|
2392
|
+
min = v;
|
2393
|
+
minSV = new semver(min, options);
|
2394
|
+
}
|
2395
|
+
}
|
2396
|
+
});
|
2397
|
+
return min
|
2398
|
+
};
|
2399
|
+
var minSatisfying_1 = minSatisfying;
|
2400
|
+
|
2401
|
+
const minVersion = (range$1, loose) => {
|
2402
|
+
range$1 = new range(range$1, loose);
|
2403
|
+
|
2404
|
+
let minver = new semver('0.0.0');
|
2405
|
+
if (range$1.test(minver)) {
|
2406
|
+
return minver
|
2407
|
+
}
|
2408
|
+
|
2409
|
+
minver = new semver('0.0.0-0');
|
2410
|
+
if (range$1.test(minver)) {
|
2411
|
+
return minver
|
2412
|
+
}
|
2413
|
+
|
2414
|
+
minver = null;
|
2415
|
+
for (let i = 0; i < range$1.set.length; ++i) {
|
2416
|
+
const comparators = range$1.set[i];
|
2417
|
+
|
2418
|
+
comparators.forEach((comparator) => {
|
2419
|
+
// Clone to avoid manipulating the comparator's semver object.
|
2420
|
+
const compver = new semver(comparator.semver.version);
|
2421
|
+
switch (comparator.operator) {
|
2422
|
+
case '>':
|
2423
|
+
if (compver.prerelease.length === 0) {
|
2424
|
+
compver.patch++;
|
2425
|
+
} else {
|
2426
|
+
compver.prerelease.push(0);
|
2427
|
+
}
|
2428
|
+
compver.raw = compver.format();
|
2429
|
+
/* fallthrough */
|
2430
|
+
case '':
|
2431
|
+
case '>=':
|
2432
|
+
if (!minver || gt_1(minver, compver)) {
|
2433
|
+
minver = compver;
|
2434
|
+
}
|
2435
|
+
break
|
2436
|
+
case '<':
|
2437
|
+
case '<=':
|
2438
|
+
/* Ignore maximum versions */
|
2439
|
+
break
|
2440
|
+
/* istanbul ignore next */
|
2441
|
+
default:
|
2442
|
+
throw new Error(`Unexpected operation: ${comparator.operator}`)
|
2443
|
+
}
|
2444
|
+
});
|
2445
|
+
}
|
2446
|
+
|
2447
|
+
if (minver && range$1.test(minver)) {
|
2448
|
+
return minver
|
2449
|
+
}
|
2450
|
+
|
2451
|
+
return null
|
2452
|
+
};
|
2453
|
+
var minVersion_1 = minVersion;
|
2454
|
+
|
2455
|
+
const validRange = (range$1, options) => {
|
2456
|
+
try {
|
2457
|
+
// Return '*' instead of '' so that truthiness works.
|
2458
|
+
// This will throw if it's invalid anyway
|
2459
|
+
return new range(range$1, options).range || '*'
|
2460
|
+
} catch (er) {
|
2461
|
+
return null
|
2462
|
+
}
|
2463
|
+
};
|
2464
|
+
var valid$1 = validRange;
|
2465
|
+
|
2466
|
+
const {ANY: ANY$1} = comparator;
|
2467
|
+
|
2468
|
+
|
2469
|
+
|
2470
|
+
|
2471
|
+
|
2472
|
+
|
2473
|
+
|
2474
|
+
const outside = (version, range$1, hilo, options) => {
|
2475
|
+
version = new semver(version, options);
|
2476
|
+
range$1 = new range(range$1, options);
|
2477
|
+
|
2478
|
+
let gtfn, ltefn, ltfn, comp, ecomp;
|
2479
|
+
switch (hilo) {
|
2480
|
+
case '>':
|
2481
|
+
gtfn = gt_1;
|
2482
|
+
ltefn = lte_1;
|
2483
|
+
ltfn = lt_1;
|
2484
|
+
comp = '>';
|
2485
|
+
ecomp = '>=';
|
2486
|
+
break
|
2487
|
+
case '<':
|
2488
|
+
gtfn = lt_1;
|
2489
|
+
ltefn = gte_1;
|
2490
|
+
ltfn = gt_1;
|
2491
|
+
comp = '<';
|
2492
|
+
ecomp = '<=';
|
2493
|
+
break
|
2494
|
+
default:
|
2495
|
+
throw new TypeError('Must provide a hilo val of "<" or ">"')
|
2496
|
+
}
|
2497
|
+
|
2498
|
+
// If it satisifes the range it is not outside
|
2499
|
+
if (satisfies_1(version, range$1, options)) {
|
2500
|
+
return false
|
2501
|
+
}
|
2502
|
+
|
2503
|
+
// From now on, variable terms are as if we're in "gtr" mode.
|
2504
|
+
// but note that everything is flipped for the "ltr" function.
|
2505
|
+
|
2506
|
+
for (let i = 0; i < range$1.set.length; ++i) {
|
2507
|
+
const comparators = range$1.set[i];
|
2508
|
+
|
2509
|
+
let high = null;
|
2510
|
+
let low = null;
|
2511
|
+
|
2512
|
+
comparators.forEach((comparator$1) => {
|
2513
|
+
if (comparator$1.semver === ANY$1) {
|
2514
|
+
comparator$1 = new comparator('>=0.0.0');
|
2515
|
+
}
|
2516
|
+
high = high || comparator$1;
|
2517
|
+
low = low || comparator$1;
|
2518
|
+
if (gtfn(comparator$1.semver, high.semver, options)) {
|
2519
|
+
high = comparator$1;
|
2520
|
+
} else if (ltfn(comparator$1.semver, low.semver, options)) {
|
2521
|
+
low = comparator$1;
|
2522
|
+
}
|
2523
|
+
});
|
2524
|
+
|
2525
|
+
// If the edge version comparator has a operator then our version
|
2526
|
+
// isn't outside it
|
2527
|
+
if (high.operator === comp || high.operator === ecomp) {
|
2528
|
+
return false
|
2529
|
+
}
|
2530
|
+
|
2531
|
+
// If the lowest version comparator has an operator and our version
|
2532
|
+
// is less than it then it isn't higher than the range
|
2533
|
+
if ((!low.operator || low.operator === comp) &&
|
2534
|
+
ltefn(version, low.semver)) {
|
2535
|
+
return false
|
2536
|
+
} else if (low.operator === ecomp && ltfn(version, low.semver)) {
|
2537
|
+
return false
|
2538
|
+
}
|
2539
|
+
}
|
2540
|
+
return true
|
2541
|
+
};
|
2542
|
+
|
2543
|
+
var outside_1 = outside;
|
2544
|
+
|
2545
|
+
// Determine if version is greater than all the versions possible in the range.
|
2546
|
+
|
2547
|
+
const gtr = (version, range, options) => outside_1(version, range, '>', options);
|
2548
|
+
var gtr_1 = gtr;
|
2549
|
+
|
2550
|
+
// Determine if version is less than all the versions possible in the range
|
2551
|
+
const ltr = (version, range, options) => outside_1(version, range, '<', options);
|
2552
|
+
var ltr_1 = ltr;
|
2553
|
+
|
2554
|
+
const intersects = (r1, r2, options) => {
|
2555
|
+
r1 = new range(r1, options);
|
2556
|
+
r2 = new range(r2, options);
|
2557
|
+
return r1.intersects(r2)
|
2558
|
+
};
|
2559
|
+
var intersects_1 = intersects;
|
2560
|
+
|
2561
|
+
// given a set of versions and a range, create a "simplified" range
|
2562
|
+
// that includes the same versions that the original range does
|
2563
|
+
// If the original range is shorter than the simplified one, return that.
|
2564
|
+
|
2565
|
+
|
2566
|
+
var simplify = (versions, range, options) => {
|
2567
|
+
const set = [];
|
2568
|
+
let min = null;
|
2569
|
+
let prev = null;
|
2570
|
+
const v = versions.sort((a, b) => compare_1(a, b, options));
|
2571
|
+
for (const version of v) {
|
2572
|
+
const included = satisfies_1(version, range, options);
|
2573
|
+
if (included) {
|
2574
|
+
prev = version;
|
2575
|
+
if (!min)
|
2576
|
+
min = version;
|
2577
|
+
} else {
|
2578
|
+
if (prev) {
|
2579
|
+
set.push([min, prev]);
|
2580
|
+
}
|
2581
|
+
prev = null;
|
2582
|
+
min = null;
|
2583
|
+
}
|
2584
|
+
}
|
2585
|
+
if (min)
|
2586
|
+
set.push([min, null]);
|
2587
|
+
|
2588
|
+
const ranges = [];
|
2589
|
+
for (const [min, max] of set) {
|
2590
|
+
if (min === max)
|
2591
|
+
ranges.push(min);
|
2592
|
+
else if (!max && min === v[0])
|
2593
|
+
ranges.push('*');
|
2594
|
+
else if (!max)
|
2595
|
+
ranges.push(`>=${min}`);
|
2596
|
+
else if (min === v[0])
|
2597
|
+
ranges.push(`<=${max}`);
|
2598
|
+
else
|
2599
|
+
ranges.push(`${min} - ${max}`);
|
2600
|
+
}
|
2601
|
+
const simplified = ranges.join(' || ');
|
2602
|
+
const original = typeof range.raw === 'string' ? range.raw : String(range);
|
2603
|
+
return simplified.length < original.length ? simplified : range
|
2604
|
+
};
|
2605
|
+
|
2606
|
+
const { ANY: ANY$2 } = comparator;
|
2607
|
+
|
2608
|
+
|
2609
|
+
|
2610
|
+
// Complex range `r1 || r2 || ...` is a subset of `R1 || R2 || ...` iff:
|
2611
|
+
// - Every simple range `r1, r2, ...` is a subset of some `R1, R2, ...`
|
2612
|
+
//
|
2613
|
+
// Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff:
|
2614
|
+
// - If c is only the ANY comparator
|
2615
|
+
// - If C is only the ANY comparator, return true
|
2616
|
+
// - Else return false
|
2617
|
+
// - Let EQ be the set of = comparators in c
|
2618
|
+
// - If EQ is more than one, return true (null set)
|
2619
|
+
// - Let GT be the highest > or >= comparator in c
|
2620
|
+
// - Let LT be the lowest < or <= comparator in c
|
2621
|
+
// - If GT and LT, and GT.semver > LT.semver, return true (null set)
|
2622
|
+
// - If EQ
|
2623
|
+
// - If GT, and EQ does not satisfy GT, return true (null set)
|
2624
|
+
// - If LT, and EQ does not satisfy LT, return true (null set)
|
2625
|
+
// - If EQ satisfies every C, return true
|
2626
|
+
// - Else return false
|
2627
|
+
// - If GT
|
2628
|
+
// - If GT is lower than any > or >= comp in C, return false
|
2629
|
+
// - If GT is >=, and GT.semver does not satisfy every C, return false
|
2630
|
+
// - If LT
|
2631
|
+
// - If LT.semver is greater than that of any > comp in C, return false
|
2632
|
+
// - If LT is <=, and LT.semver does not satisfy every C, return false
|
2633
|
+
// - If any C is a = range, and GT or LT are set, return false
|
2634
|
+
// - Else return true
|
2635
|
+
|
2636
|
+
const subset = (sub, dom, options) => {
|
2637
|
+
sub = new range(sub, options);
|
2638
|
+
dom = new range(dom, options);
|
2639
|
+
let sawNonNull = false;
|
2640
|
+
|
2641
|
+
OUTER: for (const simpleSub of sub.set) {
|
2642
|
+
for (const simpleDom of dom.set) {
|
2643
|
+
const isSub = simpleSubset(simpleSub, simpleDom, options);
|
2644
|
+
sawNonNull = sawNonNull || isSub !== null;
|
2645
|
+
if (isSub)
|
2646
|
+
continue OUTER
|
2647
|
+
}
|
2648
|
+
// the null set is a subset of everything, but null simple ranges in
|
2649
|
+
// a complex range should be ignored. so if we saw a non-null range,
|
2650
|
+
// then we know this isn't a subset, but if EVERY simple range was null,
|
2651
|
+
// then it is a subset.
|
2652
|
+
if (sawNonNull)
|
2653
|
+
return false
|
2654
|
+
}
|
2655
|
+
return true
|
2656
|
+
};
|
2657
|
+
|
2658
|
+
const simpleSubset = (sub, dom, options) => {
|
2659
|
+
if (sub.length === 1 && sub[0].semver === ANY$2)
|
2660
|
+
return dom.length === 1 && dom[0].semver === ANY$2
|
2661
|
+
|
2662
|
+
const eqSet = new Set();
|
2663
|
+
let gt, lt;
|
2664
|
+
for (const c of sub) {
|
2665
|
+
if (c.operator === '>' || c.operator === '>=')
|
2666
|
+
gt = higherGT(gt, c, options);
|
2667
|
+
else if (c.operator === '<' || c.operator === '<=')
|
2668
|
+
lt = lowerLT(lt, c, options);
|
2669
|
+
else
|
2670
|
+
eqSet.add(c.semver);
|
2671
|
+
}
|
2672
|
+
|
2673
|
+
if (eqSet.size > 1)
|
2674
|
+
return null
|
2675
|
+
|
2676
|
+
let gtltComp;
|
2677
|
+
if (gt && lt) {
|
2678
|
+
gtltComp = compare_1(gt.semver, lt.semver, options);
|
2679
|
+
if (gtltComp > 0)
|
2680
|
+
return null
|
2681
|
+
else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<='))
|
2682
|
+
return null
|
2683
|
+
}
|
2684
|
+
|
2685
|
+
// will iterate one or zero times
|
2686
|
+
for (const eq of eqSet) {
|
2687
|
+
if (gt && !satisfies_1(eq, String(gt), options))
|
2688
|
+
return null
|
2689
|
+
|
2690
|
+
if (lt && !satisfies_1(eq, String(lt), options))
|
2691
|
+
return null
|
2692
|
+
|
2693
|
+
for (const c of dom) {
|
2694
|
+
if (!satisfies_1(eq, String(c), options))
|
2695
|
+
return false
|
2696
|
+
}
|
2697
|
+
return true
|
2698
|
+
}
|
2699
|
+
|
2700
|
+
let higher, lower;
|
2701
|
+
let hasDomLT, hasDomGT;
|
2702
|
+
for (const c of dom) {
|
2703
|
+
hasDomGT = hasDomGT || c.operator === '>' || c.operator === '>=';
|
2704
|
+
hasDomLT = hasDomLT || c.operator === '<' || c.operator === '<=';
|
2705
|
+
if (gt) {
|
2706
|
+
if (c.operator === '>' || c.operator === '>=') {
|
2707
|
+
higher = higherGT(gt, c, options);
|
2708
|
+
if (higher === c)
|
2709
|
+
return false
|
2710
|
+
} else if (gt.operator === '>=' && !satisfies_1(gt.semver, String(c), options))
|
2711
|
+
return false
|
2712
|
+
}
|
2713
|
+
if (lt) {
|
2714
|
+
if (c.operator === '<' || c.operator === '<=') {
|
2715
|
+
lower = lowerLT(lt, c, options);
|
2716
|
+
if (lower === c)
|
2717
|
+
return false
|
2718
|
+
} else if (lt.operator === '<=' && !satisfies_1(lt.semver, String(c), options))
|
2719
|
+
return false
|
2720
|
+
}
|
2721
|
+
if (!c.operator && (lt || gt) && gtltComp !== 0)
|
2722
|
+
return false
|
2723
|
+
}
|
2724
|
+
|
2725
|
+
// if there was a < or >, and nothing in the dom, then must be false
|
2726
|
+
// UNLESS it was limited by another range in the other direction.
|
2727
|
+
// Eg, >1.0.0 <1.0.1 is still a subset of <2.0.0
|
2728
|
+
if (gt && hasDomLT && !lt && gtltComp !== 0)
|
2729
|
+
return false
|
2730
|
+
|
2731
|
+
if (lt && hasDomGT && !gt && gtltComp !== 0)
|
2732
|
+
return false
|
2733
|
+
|
2734
|
+
return true
|
2735
|
+
};
|
2736
|
+
|
2737
|
+
// >=1.2.3 is lower than >1.2.3
|
2738
|
+
const higherGT = (a, b, options) => {
|
2739
|
+
if (!a)
|
2740
|
+
return b
|
2741
|
+
const comp = compare_1(a.semver, b.semver, options);
|
2742
|
+
return comp > 0 ? a
|
2743
|
+
: comp < 0 ? b
|
2744
|
+
: b.operator === '>' && a.operator === '>=' ? b
|
2745
|
+
: a
|
2746
|
+
};
|
2747
|
+
|
2748
|
+
// <=1.2.3 is higher than <1.2.3
|
2749
|
+
const lowerLT = (a, b, options) => {
|
2750
|
+
if (!a)
|
2751
|
+
return b
|
2752
|
+
const comp = compare_1(a.semver, b.semver, options);
|
2753
|
+
return comp < 0 ? a
|
2754
|
+
: comp > 0 ? b
|
2755
|
+
: b.operator === '<' && a.operator === '<=' ? b
|
2756
|
+
: a
|
2757
|
+
};
|
2758
|
+
|
2759
|
+
var subset_1 = subset;
|
2760
|
+
|
2761
|
+
// just pre-load all the stuff that index.js lazily exports
|
2762
|
+
|
2763
|
+
var semver$1 = {
|
2764
|
+
re: re_1.re,
|
2765
|
+
src: re_1.src,
|
2766
|
+
tokens: re_1.t,
|
2767
|
+
SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
|
2768
|
+
SemVer: semver,
|
2769
|
+
compareIdentifiers: identifiers.compareIdentifiers,
|
2770
|
+
rcompareIdentifiers: identifiers.rcompareIdentifiers,
|
2771
|
+
parse: parse_1,
|
2772
|
+
valid: valid_1,
|
2773
|
+
clean: clean_1,
|
2774
|
+
inc: inc_1,
|
2775
|
+
diff: diff_1,
|
2776
|
+
major: major_1,
|
2777
|
+
minor: minor_1,
|
2778
|
+
patch: patch_1,
|
2779
|
+
prerelease: prerelease_1,
|
2780
|
+
compare: compare_1,
|
2781
|
+
rcompare: rcompare_1,
|
2782
|
+
compareLoose: compareLoose_1,
|
2783
|
+
compareBuild: compareBuild_1,
|
2784
|
+
sort: sort_1,
|
2785
|
+
rsort: rsort_1,
|
2786
|
+
gt: gt_1,
|
2787
|
+
lt: lt_1,
|
2788
|
+
eq: eq_1,
|
2789
|
+
neq: neq_1,
|
2790
|
+
gte: gte_1,
|
2791
|
+
lte: lte_1,
|
2792
|
+
cmp: cmp_1,
|
2793
|
+
coerce: coerce_1,
|
2794
|
+
Comparator: comparator,
|
2795
|
+
Range: range,
|
2796
|
+
satisfies: satisfies_1,
|
2797
|
+
toComparators: toComparators_1,
|
2798
|
+
maxSatisfying: maxSatisfying_1,
|
2799
|
+
minSatisfying: minSatisfying_1,
|
2800
|
+
minVersion: minVersion_1,
|
2801
|
+
validRange: valid$1,
|
2802
|
+
outside: outside_1,
|
2803
|
+
gtr: gtr_1,
|
2804
|
+
ltr: ltr_1,
|
2805
|
+
intersects: intersects_1,
|
2806
|
+
simplifyRange: simplify,
|
2807
|
+
subset: subset_1,
|
2808
|
+
};
|
2809
|
+
|
2810
|
+
function schemaParser(e){const[n,r]=/\/schema\/([\w-]+)\/([\w\.\-]+)\.json$/g.exec(e).slice(1,3);return {library:n,version:r}}
|
2811
|
+
|
2812
|
+
var name = "vega-themes";
|
2813
|
+
var version$1 = "2.9.0";
|
2814
|
+
var description = "Themes for stylized Vega and Vega-Lite visualizations.";
|
2815
|
+
var keywords = [
|
2816
|
+
"vega",
|
2817
|
+
"vega-lite",
|
2818
|
+
"themes",
|
2819
|
+
"style"
|
2820
|
+
];
|
2821
|
+
var license = "BSD-3-Clause";
|
2822
|
+
var author = {
|
2823
|
+
name: "UW Interactive Data Lab",
|
2824
|
+
url: "https://idl.cs.washington.edu"
|
2825
|
+
};
|
2826
|
+
var contributors = [
|
2827
|
+
{
|
2828
|
+
name: "Emily Gu",
|
2829
|
+
url: "https://github.com/emilygu"
|
2830
|
+
},
|
2831
|
+
{
|
2832
|
+
name: "Arvind Satyanarayan",
|
2833
|
+
url: "http://arvindsatya.com"
|
2834
|
+
},
|
2835
|
+
{
|
2836
|
+
name: "Jeffrey Heer",
|
2837
|
+
url: "https://idl.cs.washington.edu"
|
2838
|
+
},
|
2839
|
+
{
|
2840
|
+
name: "Dominik Moritz",
|
2841
|
+
url: "https://www.domoritz.de"
|
2842
|
+
}
|
2843
|
+
];
|
2844
|
+
var main = "build/vega-themes.js";
|
2845
|
+
var module = "build/vega-themes.module.js";
|
2846
|
+
var unpkg = "build/vega-themes.min.js";
|
2847
|
+
var jsdelivr = "build/vega-themes.min.js";
|
2848
|
+
var types = "build/vega-themes.module.d.ts";
|
2849
|
+
var repository = {
|
2850
|
+
type: "git",
|
2851
|
+
url: "https://github.com/vega/vega-themes.git"
|
2852
|
+
};
|
2853
|
+
var files = [
|
2854
|
+
"src",
|
2855
|
+
"build"
|
2856
|
+
];
|
2857
|
+
var scripts = {
|
2858
|
+
prebuild: "yarn clean",
|
2859
|
+
build: "rollup -c",
|
2860
|
+
clean: "rimraf build && rimraf examples/build",
|
2861
|
+
"copy:data": "rsync -r node_modules/vega-datasets/data/* examples/data",
|
2862
|
+
"copy:build": "rsync -r build/* examples/build",
|
2863
|
+
"deploy:gh": "yarn build && mkdir -p examples/build && rsync -r build/* examples/build && gh-pages -d examples",
|
2864
|
+
prepublishOnly: "yarn clean && yarn build",
|
2865
|
+
preversion: "yarn lint",
|
2866
|
+
serve: "browser-sync start -s -f build examples --serveStatic examples",
|
2867
|
+
start: "yarn build && concurrently --kill-others -n Server,Rollup 'yarn serve' 'rollup -c -w'",
|
2868
|
+
prepare: "beemo create-config",
|
2869
|
+
eslintbase: "beemo eslint .",
|
2870
|
+
format: "yarn eslintbase --fix",
|
2871
|
+
lint: "yarn eslintbase"
|
2872
|
+
};
|
2873
|
+
var devDependencies = {
|
2874
|
+
"@rollup/plugin-json": "^4.1.0",
|
2875
|
+
"@rollup/plugin-node-resolve": "^9.0.0",
|
2876
|
+
"@wessberg/rollup-plugin-ts": "^1.3.4",
|
2877
|
+
"browser-sync": "^2.26.7",
|
2878
|
+
concurrently: "^5.2.0",
|
2879
|
+
"gh-pages": "^3.1.0",
|
2880
|
+
rollup: "^2.26.10",
|
2881
|
+
"rollup-plugin-bundle-size": "^1.0.3",
|
2882
|
+
"rollup-plugin-terser": "^7.0.2",
|
2883
|
+
typescript: "^4.0.2",
|
2884
|
+
vega: "^5.10.0",
|
2885
|
+
"vega-lite": "^4.8.1",
|
2886
|
+
"vega-lite-dev-config": "^0.14.2"
|
2887
|
+
};
|
2888
|
+
var peerDependencies = {
|
2889
|
+
vega: "*",
|
2890
|
+
"vega-lite": "*"
|
2891
|
+
};
|
2892
|
+
var beemo = {
|
2893
|
+
module: "vega-lite-dev-config",
|
2894
|
+
drivers: [
|
2895
|
+
"typescript",
|
2896
|
+
"prettier",
|
2897
|
+
"eslint"
|
2898
|
+
]
|
2899
|
+
};
|
2900
|
+
var pkg = {
|
2901
|
+
name: name,
|
2902
|
+
version: version$1,
|
2903
|
+
description: description,
|
2904
|
+
keywords: keywords,
|
2905
|
+
license: license,
|
2906
|
+
author: author,
|
2907
|
+
contributors: contributors,
|
2908
|
+
main: main,
|
2909
|
+
module: module,
|
2910
|
+
unpkg: unpkg,
|
2911
|
+
jsdelivr: jsdelivr,
|
2912
|
+
types: types,
|
2913
|
+
repository: repository,
|
2914
|
+
files: files,
|
2915
|
+
scripts: scripts,
|
2916
|
+
devDependencies: devDependencies,
|
2917
|
+
peerDependencies: peerDependencies,
|
2918
|
+
beemo: beemo
|
2919
|
+
};
|
2920
|
+
|
2921
|
+
const lightColor = '#fff';
|
2922
|
+
const medColor = '#888';
|
2923
|
+
const darkTheme = {
|
2924
|
+
background: '#333',
|
2925
|
+
title: { color: lightColor },
|
2926
|
+
style: {
|
2927
|
+
'guide-label': {
|
2928
|
+
fill: lightColor,
|
2929
|
+
},
|
2930
|
+
'guide-title': {
|
2931
|
+
fill: lightColor,
|
2932
|
+
},
|
2933
|
+
},
|
2934
|
+
axis: {
|
2935
|
+
domainColor: lightColor,
|
2936
|
+
gridColor: medColor,
|
2937
|
+
tickColor: lightColor,
|
2938
|
+
},
|
2939
|
+
};
|
2940
|
+
|
2941
|
+
const markColor = '#4572a7';
|
2942
|
+
const excelTheme = {
|
2943
|
+
background: '#fff',
|
2944
|
+
arc: { fill: markColor },
|
2945
|
+
area: { fill: markColor },
|
2946
|
+
line: { stroke: markColor, strokeWidth: 2 },
|
2947
|
+
path: { stroke: markColor },
|
2948
|
+
rect: { fill: markColor },
|
2949
|
+
shape: { stroke: markColor },
|
2950
|
+
symbol: { fill: markColor, strokeWidth: 1.5, size: 50 },
|
2951
|
+
axis: {
|
2952
|
+
bandPosition: 0.5,
|
2953
|
+
grid: true,
|
2954
|
+
gridColor: '#000000',
|
2955
|
+
gridOpacity: 1,
|
2956
|
+
gridWidth: 0.5,
|
2957
|
+
labelPadding: 10,
|
2958
|
+
tickSize: 5,
|
2959
|
+
tickWidth: 0.5,
|
2960
|
+
},
|
2961
|
+
axisBand: {
|
2962
|
+
grid: false,
|
2963
|
+
tickExtra: true,
|
2964
|
+
},
|
2965
|
+
legend: {
|
2966
|
+
labelBaseline: 'middle',
|
2967
|
+
labelFontSize: 11,
|
2968
|
+
symbolSize: 50,
|
2969
|
+
symbolType: 'square',
|
2970
|
+
},
|
2971
|
+
range: {
|
2972
|
+
category: [
|
2973
|
+
'#4572a7',
|
2974
|
+
'#aa4643',
|
2975
|
+
'#8aa453',
|
2976
|
+
'#71598e',
|
2977
|
+
'#4598ae',
|
2978
|
+
'#d98445',
|
2979
|
+
'#94aace',
|
2980
|
+
'#d09393',
|
2981
|
+
'#b9cc98',
|
2982
|
+
'#a99cbc',
|
2983
|
+
],
|
2984
|
+
},
|
2985
|
+
};
|
2986
|
+
|
2987
|
+
const markColor$1 = '#30a2da';
|
2988
|
+
const axisColor = '#cbcbcb';
|
2989
|
+
const guideLabelColor = '#999';
|
2990
|
+
const guideTitleColor = '#333';
|
2991
|
+
const backgroundColor = '#f0f0f0';
|
2992
|
+
const blackTitle = '#333';
|
2993
|
+
const fiveThirtyEightTheme = {
|
2994
|
+
arc: { fill: markColor$1 },
|
2995
|
+
area: { fill: markColor$1 },
|
2996
|
+
axis: {
|
2997
|
+
domainColor: axisColor,
|
2998
|
+
grid: true,
|
2999
|
+
gridColor: axisColor,
|
3000
|
+
gridWidth: 1,
|
3001
|
+
labelColor: guideLabelColor,
|
3002
|
+
labelFontSize: 10,
|
3003
|
+
titleColor: guideTitleColor,
|
3004
|
+
tickColor: axisColor,
|
3005
|
+
tickSize: 10,
|
3006
|
+
titleFontSize: 14,
|
3007
|
+
titlePadding: 10,
|
3008
|
+
labelPadding: 4,
|
3009
|
+
},
|
3010
|
+
axisBand: {
|
3011
|
+
grid: false,
|
3012
|
+
},
|
3013
|
+
background: backgroundColor,
|
3014
|
+
group: {
|
3015
|
+
fill: backgroundColor,
|
3016
|
+
},
|
3017
|
+
legend: {
|
3018
|
+
labelColor: blackTitle,
|
3019
|
+
labelFontSize: 11,
|
3020
|
+
padding: 1,
|
3021
|
+
symbolSize: 30,
|
3022
|
+
symbolType: 'square',
|
3023
|
+
titleColor: blackTitle,
|
3024
|
+
titleFontSize: 14,
|
3025
|
+
titlePadding: 10,
|
3026
|
+
},
|
3027
|
+
line: {
|
3028
|
+
stroke: markColor$1,
|
3029
|
+
strokeWidth: 2,
|
3030
|
+
},
|
3031
|
+
path: { stroke: markColor$1, strokeWidth: 0.5 },
|
3032
|
+
rect: { fill: markColor$1 },
|
3033
|
+
range: {
|
3034
|
+
category: [
|
3035
|
+
'#30a2da',
|
3036
|
+
'#fc4f30',
|
3037
|
+
'#e5ae38',
|
3038
|
+
'#6d904f',
|
3039
|
+
'#8b8b8b',
|
3040
|
+
'#b96db8',
|
3041
|
+
'#ff9e27',
|
3042
|
+
'#56cc60',
|
3043
|
+
'#52d2ca',
|
3044
|
+
'#52689e',
|
3045
|
+
'#545454',
|
3046
|
+
'#9fe4f8',
|
3047
|
+
],
|
3048
|
+
diverging: ['#cc0020', '#e77866', '#f6e7e1', '#d6e8ed', '#91bfd9', '#1d78b5'],
|
3049
|
+
heatmap: ['#d6e8ed', '#cee0e5', '#91bfd9', '#549cc6', '#1d78b5'],
|
3050
|
+
},
|
3051
|
+
point: {
|
3052
|
+
filled: true,
|
3053
|
+
shape: 'circle',
|
3054
|
+
},
|
3055
|
+
shape: { stroke: markColor$1 },
|
3056
|
+
bar: {
|
3057
|
+
binSpacing: 2,
|
3058
|
+
fill: markColor$1,
|
3059
|
+
stroke: null,
|
3060
|
+
},
|
3061
|
+
title: {
|
3062
|
+
anchor: 'start',
|
3063
|
+
fontSize: 24,
|
3064
|
+
fontWeight: 600,
|
3065
|
+
offset: 20,
|
3066
|
+
},
|
3067
|
+
};
|
3068
|
+
|
3069
|
+
const markColor$2 = '#000';
|
3070
|
+
const ggplot2Theme = {
|
3071
|
+
group: {
|
3072
|
+
fill: '#e5e5e5',
|
3073
|
+
},
|
3074
|
+
arc: { fill: markColor$2 },
|
3075
|
+
area: { fill: markColor$2 },
|
3076
|
+
line: { stroke: markColor$2 },
|
3077
|
+
path: { stroke: markColor$2 },
|
3078
|
+
rect: { fill: markColor$2 },
|
3079
|
+
shape: { stroke: markColor$2 },
|
3080
|
+
symbol: { fill: markColor$2, size: 40 },
|
3081
|
+
axis: {
|
3082
|
+
domain: false,
|
3083
|
+
grid: true,
|
3084
|
+
gridColor: '#FFFFFF',
|
3085
|
+
gridOpacity: 1,
|
3086
|
+
labelColor: '#7F7F7F',
|
3087
|
+
labelPadding: 4,
|
3088
|
+
tickColor: '#7F7F7F',
|
3089
|
+
tickSize: 5.67,
|
3090
|
+
titleFontSize: 16,
|
3091
|
+
titleFontWeight: 'normal',
|
3092
|
+
},
|
3093
|
+
legend: {
|
3094
|
+
labelBaseline: 'middle',
|
3095
|
+
labelFontSize: 11,
|
3096
|
+
symbolSize: 40,
|
3097
|
+
},
|
3098
|
+
range: {
|
3099
|
+
category: [
|
3100
|
+
'#000000',
|
3101
|
+
'#7F7F7F',
|
3102
|
+
'#1A1A1A',
|
3103
|
+
'#999999',
|
3104
|
+
'#333333',
|
3105
|
+
'#B0B0B0',
|
3106
|
+
'#4D4D4D',
|
3107
|
+
'#C9C9C9',
|
3108
|
+
'#666666',
|
3109
|
+
'#DCDCDC',
|
3110
|
+
],
|
3111
|
+
},
|
3112
|
+
};
|
3113
|
+
|
3114
|
+
const headlineFontSize = 22;
|
3115
|
+
const headlineFontWeight = 'normal';
|
3116
|
+
const labelFont = 'Benton Gothic, sans-serif';
|
3117
|
+
const labelFontSize = 11.5;
|
3118
|
+
const labelFontWeight = 'normal';
|
3119
|
+
const markColor$3 = '#82c6df';
|
3120
|
+
// const markHighlight = '#006d8f';
|
3121
|
+
// const markDemocrat = '#5789b8';
|
3122
|
+
// const markRepublican = '#d94f54';
|
3123
|
+
const titleFont = 'Benton Gothic Bold, sans-serif';
|
3124
|
+
const titleFontWeight = 'normal';
|
3125
|
+
const titleFontSize = 13;
|
3126
|
+
const colorSchemes = {
|
3127
|
+
'category-6': ['#ec8431', '#829eb1', '#c89d29', '#3580b1', '#adc839', '#ab7fb4'],
|
3128
|
+
'fire-7': ['#fbf2c7', '#f9e39c', '#f8d36e', '#f4bb6a', '#e68a4f', '#d15a40', '#ab4232'],
|
3129
|
+
'fireandice-6': ['#e68a4f', '#f4bb6a', '#f9e39c', '#dadfe2', '#a6b7c6', '#849eae'],
|
3130
|
+
'ice-7': ['#edefee', '#dadfe2', '#c4ccd2', '#a6b7c6', '#849eae', '#607785', '#47525d'],
|
3131
|
+
};
|
3132
|
+
const latimesTheme = {
|
3133
|
+
background: '#ffffff',
|
3134
|
+
title: {
|
3135
|
+
anchor: 'start',
|
3136
|
+
color: '#000000',
|
3137
|
+
font: titleFont,
|
3138
|
+
fontSize: headlineFontSize,
|
3139
|
+
fontWeight: headlineFontWeight,
|
3140
|
+
},
|
3141
|
+
arc: { fill: markColor$3 },
|
3142
|
+
area: { fill: markColor$3 },
|
3143
|
+
line: { stroke: markColor$3, strokeWidth: 2 },
|
3144
|
+
path: { stroke: markColor$3 },
|
3145
|
+
rect: { fill: markColor$3 },
|
3146
|
+
shape: { stroke: markColor$3 },
|
3147
|
+
symbol: { fill: markColor$3, size: 30 },
|
3148
|
+
axis: {
|
3149
|
+
labelFont,
|
3150
|
+
labelFontSize,
|
3151
|
+
labelFontWeight,
|
3152
|
+
titleFont,
|
3153
|
+
titleFontSize,
|
3154
|
+
titleFontWeight,
|
3155
|
+
},
|
3156
|
+
axisX: {
|
3157
|
+
labelAngle: 0,
|
3158
|
+
labelPadding: 4,
|
3159
|
+
tickSize: 3,
|
3160
|
+
},
|
3161
|
+
axisY: {
|
3162
|
+
labelBaseline: 'middle',
|
3163
|
+
maxExtent: 45,
|
3164
|
+
minExtent: 45,
|
3165
|
+
tickSize: 2,
|
3166
|
+
titleAlign: 'left',
|
3167
|
+
titleAngle: 0,
|
3168
|
+
titleX: -45,
|
3169
|
+
titleY: -11,
|
3170
|
+
},
|
3171
|
+
legend: {
|
3172
|
+
labelFont,
|
3173
|
+
labelFontSize,
|
3174
|
+
symbolType: 'square',
|
3175
|
+
titleFont,
|
3176
|
+
titleFontSize,
|
3177
|
+
titleFontWeight,
|
3178
|
+
},
|
3179
|
+
range: {
|
3180
|
+
category: colorSchemes['category-6'],
|
3181
|
+
diverging: colorSchemes['fireandice-6'],
|
3182
|
+
heatmap: colorSchemes['fire-7'],
|
3183
|
+
ordinal: colorSchemes['fire-7'],
|
3184
|
+
ramp: colorSchemes['fire-7'],
|
3185
|
+
},
|
3186
|
+
};
|
3187
|
+
|
3188
|
+
const markColor$4 = '#ab5787';
|
3189
|
+
const axisColor$1 = '#979797';
|
3190
|
+
const quartzTheme = {
|
3191
|
+
background: '#f9f9f9',
|
3192
|
+
arc: { fill: markColor$4 },
|
3193
|
+
area: { fill: markColor$4 },
|
3194
|
+
line: { stroke: markColor$4 },
|
3195
|
+
path: { stroke: markColor$4 },
|
3196
|
+
rect: { fill: markColor$4 },
|
3197
|
+
shape: { stroke: markColor$4 },
|
3198
|
+
symbol: { fill: markColor$4, size: 30 },
|
3199
|
+
axis: {
|
3200
|
+
domainColor: axisColor$1,
|
3201
|
+
domainWidth: 0.5,
|
3202
|
+
gridWidth: 0.2,
|
3203
|
+
labelColor: axisColor$1,
|
3204
|
+
tickColor: axisColor$1,
|
3205
|
+
tickWidth: 0.2,
|
3206
|
+
titleColor: axisColor$1,
|
3207
|
+
},
|
3208
|
+
axisBand: {
|
3209
|
+
grid: false,
|
3210
|
+
},
|
3211
|
+
axisX: {
|
3212
|
+
grid: true,
|
3213
|
+
tickSize: 10,
|
3214
|
+
},
|
3215
|
+
axisY: {
|
3216
|
+
domain: false,
|
3217
|
+
grid: true,
|
3218
|
+
tickSize: 0,
|
3219
|
+
},
|
3220
|
+
legend: {
|
3221
|
+
labelFontSize: 11,
|
3222
|
+
padding: 1,
|
3223
|
+
symbolSize: 30,
|
3224
|
+
symbolType: 'square',
|
3225
|
+
},
|
3226
|
+
range: {
|
3227
|
+
category: [
|
3228
|
+
'#ab5787',
|
3229
|
+
'#51b2e5',
|
3230
|
+
'#703c5c',
|
3231
|
+
'#168dd9',
|
3232
|
+
'#d190b6',
|
3233
|
+
'#00609f',
|
3234
|
+
'#d365ba',
|
3235
|
+
'#154866',
|
3236
|
+
'#666666',
|
3237
|
+
'#c4c4c4',
|
3238
|
+
],
|
3239
|
+
},
|
3240
|
+
};
|
3241
|
+
|
3242
|
+
const markColor$5 = '#3e5c69';
|
3243
|
+
const voxTheme = {
|
3244
|
+
background: '#fff',
|
3245
|
+
arc: { fill: markColor$5 },
|
3246
|
+
area: { fill: markColor$5 },
|
3247
|
+
line: { stroke: markColor$5 },
|
3248
|
+
path: { stroke: markColor$5 },
|
3249
|
+
rect: { fill: markColor$5 },
|
3250
|
+
shape: { stroke: markColor$5 },
|
3251
|
+
symbol: { fill: markColor$5 },
|
3252
|
+
axis: {
|
3253
|
+
domainWidth: 0.5,
|
3254
|
+
grid: true,
|
3255
|
+
labelPadding: 2,
|
3256
|
+
tickSize: 5,
|
3257
|
+
tickWidth: 0.5,
|
3258
|
+
titleFontWeight: 'normal',
|
3259
|
+
},
|
3260
|
+
axisBand: {
|
3261
|
+
grid: false,
|
3262
|
+
},
|
3263
|
+
axisX: {
|
3264
|
+
gridWidth: 0.2,
|
3265
|
+
},
|
3266
|
+
axisY: {
|
3267
|
+
gridDash: [3],
|
3268
|
+
gridWidth: 0.4,
|
3269
|
+
},
|
3270
|
+
legend: {
|
3271
|
+
labelFontSize: 11,
|
3272
|
+
padding: 1,
|
3273
|
+
symbolType: 'square',
|
3274
|
+
},
|
3275
|
+
range: {
|
3276
|
+
category: ['#3e5c69', '#6793a6', '#182429', '#0570b0', '#3690c0', '#74a9cf', '#a6bddb', '#e2ddf2'],
|
3277
|
+
},
|
3278
|
+
};
|
3279
|
+
|
3280
|
+
const markColor$6 = '#1696d2';
|
3281
|
+
const axisColor$2 = '#000000';
|
3282
|
+
const backgroundColor$1 = '#FFFFFF';
|
3283
|
+
const font = 'Lato';
|
3284
|
+
const labelFont$1 = 'Lato';
|
3285
|
+
const sourceFont = 'Lato';
|
3286
|
+
const gridColor = '#DEDDDD';
|
3287
|
+
const titleFontSize$1 = 18;
|
3288
|
+
const colorSchemes$1 = {
|
3289
|
+
'main-colors': ['#1696d2', '#d2d2d2', '#000000', '#fdbf11', '#ec008b', '#55b748', '#5c5859', '#db2b27'],
|
3290
|
+
'shades-blue': ['#CFE8F3', '#A2D4EC', '#73BFE2', '#46ABDB', '#1696D2', '#12719E', '#0A4C6A', '#062635'],
|
3291
|
+
'shades-gray': ['#F5F5F5', '#ECECEC', '#E3E3E3', '#DCDBDB', '#D2D2D2', '#9D9D9D', '#696969', '#353535'],
|
3292
|
+
'shades-yellow': ['#FFF2CF', '#FCE39E', '#FDD870', '#FCCB41', '#FDBF11', '#E88E2D', '#CA5800', '#843215'],
|
3293
|
+
'shades-magenta': ['#F5CBDF', '#EB99C2', '#E46AA7', '#E54096', '#EC008B', '#AF1F6B', '#761548', '#351123'],
|
3294
|
+
'shades-green': ['#DCEDD9', '#BCDEB4', '#98CF90', '#78C26D', '#55B748', '#408941', '#2C5C2D', '#1A2E19'],
|
3295
|
+
'shades-black': ['#D5D5D4', '#ADABAC', '#848081', '#5C5859', '#332D2F', '#262223', '#1A1717', '#0E0C0D'],
|
3296
|
+
'shades-red': ['#F8D5D4', '#F1AAA9', '#E9807D', '#E25552', '#DB2B27', '#A4201D', '#6E1614', '#370B0A'],
|
3297
|
+
'one-group': ['#1696d2', '#000000'],
|
3298
|
+
'two-groups-cat-1': ['#1696d2', '#000000'],
|
3299
|
+
'two-groups-cat-2': ['#1696d2', '#fdbf11'],
|
3300
|
+
'two-groups-cat-3': ['#1696d2', '#db2b27'],
|
3301
|
+
'two-groups-seq': ['#a2d4ec', '#1696d2'],
|
3302
|
+
'three-groups-cat': ['#1696d2', '#fdbf11', '#000000'],
|
3303
|
+
'three-groups-seq': ['#a2d4ec', '#1696d2', '#0a4c6a'],
|
3304
|
+
'four-groups-cat-1': ['#000000', '#d2d2d2', '#fdbf11', '#1696d2'],
|
3305
|
+
'four-groups-cat-2': ['#1696d2', '#ec0008b', '#fdbf11', '#5c5859'],
|
3306
|
+
'four-groups-seq': ['#cfe8f3', '#73bf42', '#1696d2', '#0a4c6a'],
|
3307
|
+
'five-groups-cat-1': ['#1696d2', '#fdbf11', '#d2d2d2', '#ec008b', '#000000'],
|
3308
|
+
'five-groups-cat-2': ['#1696d2', '#0a4c6a', '#d2d2d2', '#fdbf11', '#332d2f'],
|
3309
|
+
'five-groups-seq': ['#cfe8f3', '#73bf42', '#1696d2', '#0a4c6a', '#000000'],
|
3310
|
+
'six-groups-cat-1': ['#1696d2', '#ec008b', '#fdbf11', '#000000', '#d2d2d2', '#55b748'],
|
3311
|
+
'six-groups-cat-2': ['#1696d2', '#d2d2d2', '#ec008b', '#fdbf11', '#332d2f', '#0a4c6a'],
|
3312
|
+
'six-groups-seq': ['#cfe8f3', '#a2d4ec', '#73bfe2', '#46abdb', '#1696d2', '#12719e'],
|
3313
|
+
'diverging-colors': ['#ca5800', '#fdbf11', '#fdd870', '#fff2cf', '#cfe8f3', '#73bfe2', '#1696d2', '#0a4c6a'],
|
3314
|
+
};
|
3315
|
+
const urbanInstituteTheme = {
|
3316
|
+
background: backgroundColor$1,
|
3317
|
+
title: {
|
3318
|
+
anchor: 'start',
|
3319
|
+
fontSize: titleFontSize$1,
|
3320
|
+
font: font,
|
3321
|
+
},
|
3322
|
+
axisX: {
|
3323
|
+
domain: true,
|
3324
|
+
domainColor: axisColor$2,
|
3325
|
+
domainWidth: 1,
|
3326
|
+
grid: false,
|
3327
|
+
labelFontSize: 12,
|
3328
|
+
labelFont: labelFont$1,
|
3329
|
+
labelAngle: 0,
|
3330
|
+
tickColor: axisColor$2,
|
3331
|
+
tickSize: 5,
|
3332
|
+
titleFontSize: 12,
|
3333
|
+
titlePadding: 10,
|
3334
|
+
titleFont: font,
|
3335
|
+
},
|
3336
|
+
axisY: {
|
3337
|
+
domain: false,
|
3338
|
+
domainWidth: 1,
|
3339
|
+
grid: true,
|
3340
|
+
gridColor: gridColor,
|
3341
|
+
gridWidth: 1,
|
3342
|
+
labelFontSize: 12,
|
3343
|
+
labelFont: labelFont$1,
|
3344
|
+
labelPadding: 8,
|
3345
|
+
ticks: false,
|
3346
|
+
titleFontSize: 12,
|
3347
|
+
titlePadding: 10,
|
3348
|
+
titleFont: font,
|
3349
|
+
titleAngle: 0,
|
3350
|
+
titleY: -10,
|
3351
|
+
titleX: 18,
|
3352
|
+
},
|
3353
|
+
legend: {
|
3354
|
+
labelFontSize: 12,
|
3355
|
+
labelFont: labelFont$1,
|
3356
|
+
symbolSize: 100,
|
3357
|
+
titleFontSize: 12,
|
3358
|
+
titlePadding: 10,
|
3359
|
+
titleFont: font,
|
3360
|
+
orient: 'right',
|
3361
|
+
offset: 10,
|
3362
|
+
},
|
3363
|
+
view: {
|
3364
|
+
stroke: 'transparent',
|
3365
|
+
},
|
3366
|
+
range: {
|
3367
|
+
category: colorSchemes$1['six-groups-cat-1'],
|
3368
|
+
diverging: colorSchemes$1['diverging-colors'],
|
3369
|
+
heatmap: colorSchemes$1['diverging-colors'],
|
3370
|
+
ordinal: colorSchemes$1['six-groups-seq'],
|
3371
|
+
ramp: colorSchemes$1['shades-blue'],
|
3372
|
+
},
|
3373
|
+
area: {
|
3374
|
+
fill: markColor$6,
|
3375
|
+
},
|
3376
|
+
rect: {
|
3377
|
+
fill: markColor$6,
|
3378
|
+
},
|
3379
|
+
line: {
|
3380
|
+
color: markColor$6,
|
3381
|
+
stroke: markColor$6,
|
3382
|
+
strokeWidth: 5,
|
3383
|
+
},
|
3384
|
+
trail: {
|
3385
|
+
color: markColor$6,
|
3386
|
+
stroke: markColor$6,
|
3387
|
+
strokeWidth: 0,
|
3388
|
+
size: 1,
|
3389
|
+
},
|
3390
|
+
path: {
|
3391
|
+
stroke: markColor$6,
|
3392
|
+
strokeWidth: 0.5,
|
3393
|
+
},
|
3394
|
+
point: {
|
3395
|
+
filled: true,
|
3396
|
+
},
|
3397
|
+
text: {
|
3398
|
+
font: sourceFont,
|
3399
|
+
color: markColor$6,
|
3400
|
+
fontSize: 11,
|
3401
|
+
align: 'center',
|
3402
|
+
fontWeight: 400,
|
3403
|
+
size: 11,
|
3404
|
+
},
|
3405
|
+
style: {
|
3406
|
+
bar: {
|
3407
|
+
fill: markColor$6,
|
3408
|
+
stroke: null,
|
3409
|
+
},
|
3410
|
+
},
|
3411
|
+
arc: { fill: markColor$6 },
|
3412
|
+
shape: { stroke: markColor$6 },
|
3413
|
+
symbol: { fill: markColor$6, size: 30 },
|
3414
|
+
};
|
3415
|
+
|
3416
|
+
/**
|
3417
|
+
* Copyright 2020 Google LLC.
|
3418
|
+
*
|
3419
|
+
* Use of this source code is governed by a BSD-style
|
3420
|
+
* license that can be found in the LICENSE file or at
|
3421
|
+
* https://developers.google.com/open-source/licenses/bsd
|
3422
|
+
*/
|
3423
|
+
const markColor$7 = '#3366CC';
|
3424
|
+
const gridColor$1 = '#ccc';
|
3425
|
+
const defaultFont = 'Arial, sans-serif';
|
3426
|
+
const googlechartsTheme = {
|
3427
|
+
arc: { fill: markColor$7 },
|
3428
|
+
area: { fill: markColor$7 },
|
3429
|
+
path: { stroke: markColor$7 },
|
3430
|
+
rect: { fill: markColor$7 },
|
3431
|
+
shape: { stroke: markColor$7 },
|
3432
|
+
symbol: { stroke: markColor$7 },
|
3433
|
+
circle: { fill: markColor$7 },
|
3434
|
+
background: '#fff',
|
3435
|
+
padding: {
|
3436
|
+
top: 10,
|
3437
|
+
right: 10,
|
3438
|
+
bottom: 10,
|
3439
|
+
left: 10,
|
3440
|
+
},
|
3441
|
+
style: {
|
3442
|
+
'guide-label': {
|
3443
|
+
font: defaultFont,
|
3444
|
+
fontSize: 12,
|
3445
|
+
},
|
3446
|
+
'guide-title': {
|
3447
|
+
font: defaultFont,
|
3448
|
+
fontSize: 12,
|
3449
|
+
},
|
3450
|
+
'group-title': {
|
3451
|
+
font: defaultFont,
|
3452
|
+
fontSize: 12,
|
3453
|
+
},
|
3454
|
+
},
|
3455
|
+
title: {
|
3456
|
+
font: defaultFont,
|
3457
|
+
fontSize: 14,
|
3458
|
+
fontWeight: 'bold',
|
3459
|
+
dy: -3,
|
3460
|
+
anchor: 'start',
|
3461
|
+
},
|
3462
|
+
axis: {
|
3463
|
+
gridColor: gridColor$1,
|
3464
|
+
tickColor: gridColor$1,
|
3465
|
+
domain: false,
|
3466
|
+
grid: true,
|
3467
|
+
},
|
3468
|
+
range: {
|
3469
|
+
category: [
|
3470
|
+
'#4285F4',
|
3471
|
+
'#DB4437',
|
3472
|
+
'#F4B400',
|
3473
|
+
'#0F9D58',
|
3474
|
+
'#AB47BC',
|
3475
|
+
'#00ACC1',
|
3476
|
+
'#FF7043',
|
3477
|
+
'#9E9D24',
|
3478
|
+
'#5C6BC0',
|
3479
|
+
'#F06292',
|
3480
|
+
'#00796B',
|
3481
|
+
'#C2185B',
|
3482
|
+
],
|
3483
|
+
heatmap: ['#c6dafc', '#5e97f6', '#2a56c6'],
|
3484
|
+
},
|
3485
|
+
};
|
3486
|
+
|
3487
|
+
const version$1$1 = pkg.version;
|
3488
|
+
|
3489
|
+
var themes = /*#__PURE__*/Object.freeze({
|
3490
|
+
__proto__: null,
|
3491
|
+
dark: darkTheme,
|
3492
|
+
excel: excelTheme,
|
3493
|
+
fivethirtyeight: fiveThirtyEightTheme,
|
3494
|
+
ggplot2: ggplot2Theme,
|
3495
|
+
googlecharts: googlechartsTheme,
|
3496
|
+
latimes: latimesTheme,
|
3497
|
+
quartz: quartzTheme,
|
3498
|
+
urbaninstitute: urbanInstituteTheme,
|
3499
|
+
version: version$1$1,
|
3500
|
+
vox: voxTheme
|
3501
|
+
});
|
3502
|
+
|
3503
|
+
function accessor(fn, fields, name) {
|
3504
|
+
fn.fields = fields || [];
|
3505
|
+
fn.fname = name;
|
3506
|
+
return fn;
|
3507
|
+
}
|
3508
|
+
|
3509
|
+
function getter(path) {
|
3510
|
+
return path.length === 1 ? get1(path[0]) : getN(path);
|
3511
|
+
}
|
3512
|
+
|
3513
|
+
const get1 = field => function(obj) {
|
3514
|
+
return obj[field];
|
3515
|
+
};
|
3516
|
+
|
3517
|
+
const getN = path => {
|
3518
|
+
const len = path.length;
|
3519
|
+
return function(obj) {
|
3520
|
+
for (let i = 0; i < len; ++i) {
|
3521
|
+
obj = obj[path[i]];
|
3522
|
+
}
|
3523
|
+
return obj;
|
3524
|
+
};
|
3525
|
+
};
|
3526
|
+
|
3527
|
+
function error(message) {
|
3528
|
+
throw Error(message);
|
3529
|
+
}
|
3530
|
+
|
3531
|
+
function splitAccessPath(p) {
|
3532
|
+
const path = [],
|
3533
|
+
n = p.length;
|
3534
|
+
|
3535
|
+
let q = null,
|
3536
|
+
b = 0,
|
3537
|
+
s = '',
|
3538
|
+
i, j, c;
|
3539
|
+
|
3540
|
+
p = p + '';
|
3541
|
+
|
3542
|
+
function push() {
|
3543
|
+
path.push(s + p.substring(i, j));
|
3544
|
+
s = '';
|
3545
|
+
i = j + 1;
|
3546
|
+
}
|
3547
|
+
|
3548
|
+
for (i=j=0; j<n; ++j) {
|
3549
|
+
c = p[j];
|
3550
|
+
if (c === '\\') {
|
3551
|
+
s += p.substring(i, j);
|
3552
|
+
s += p.substring(++j, ++j);
|
3553
|
+
i = j;
|
3554
|
+
} else if (c === q) {
|
3555
|
+
push();
|
3556
|
+
q = null;
|
3557
|
+
b = -1;
|
3558
|
+
} else if (q) {
|
3559
|
+
continue;
|
3560
|
+
} else if (i === b && c === '"') {
|
3561
|
+
i = j + 1;
|
3562
|
+
q = c;
|
3563
|
+
} else if (i === b && c === "'") {
|
3564
|
+
i = j + 1;
|
3565
|
+
q = c;
|
3566
|
+
} else if (c === '.' && !b) {
|
3567
|
+
if (j > i) {
|
3568
|
+
push();
|
3569
|
+
} else {
|
3570
|
+
i = j + 1;
|
3571
|
+
}
|
3572
|
+
} else if (c === '[') {
|
3573
|
+
if (j > i) push();
|
3574
|
+
b = i = j + 1;
|
3575
|
+
} else if (c === ']') {
|
3576
|
+
if (!b) error('Access path missing open bracket: ' + p);
|
3577
|
+
if (b > 0) push();
|
3578
|
+
b = 0;
|
3579
|
+
i = j + 1;
|
3580
|
+
}
|
3581
|
+
}
|
3582
|
+
|
3583
|
+
if (b) error('Access path missing closing bracket: ' + p);
|
3584
|
+
if (q) error('Access path missing closing quote: ' + p);
|
3585
|
+
|
3586
|
+
if (j > i) {
|
3587
|
+
j++;
|
3588
|
+
push();
|
3589
|
+
}
|
3590
|
+
|
3591
|
+
return path;
|
3592
|
+
}
|
3593
|
+
|
3594
|
+
function field(field, name, opt) {
|
3595
|
+
const path = splitAccessPath(field);
|
3596
|
+
field = path.length === 1 ? path[0] : field;
|
3597
|
+
return accessor(
|
3598
|
+
(opt && opt.get || getter)(path),
|
3599
|
+
[field],
|
3600
|
+
name || field
|
3601
|
+
);
|
3602
|
+
}
|
3603
|
+
|
3604
|
+
const id = field('id');
|
3605
|
+
|
3606
|
+
const identity = accessor(_ => _, [], 'identity');
|
3607
|
+
|
3608
|
+
const zero = accessor(() => 0, [], 'zero');
|
3609
|
+
|
3610
|
+
const one = accessor(() => 1, [], 'one');
|
3611
|
+
|
3612
|
+
const truthy = accessor(() => true, [], 'true');
|
3613
|
+
|
3614
|
+
const falsy = accessor(() => false, [], 'false');
|
3615
|
+
|
3616
|
+
var isArray = Array.isArray;
|
3617
|
+
|
3618
|
+
function isObject(_) {
|
3619
|
+
return _ === Object(_);
|
3620
|
+
}
|
3621
|
+
|
3622
|
+
function isString(_) {
|
3623
|
+
return typeof _ === 'string';
|
3624
|
+
}
|
3625
|
+
|
3626
|
+
// generated with build-style.sh
|
3627
|
+
var defaultStyle = `#vg-tooltip-element {
|
3628
|
+
visibility: hidden;
|
3629
|
+
padding: 8px;
|
3630
|
+
position: fixed;
|
3631
|
+
z-index: 1000;
|
3632
|
+
font-family: sans-serif;
|
3633
|
+
font-size: 11px;
|
3634
|
+
border-radius: 3px;
|
3635
|
+
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
|
3636
|
+
/* The default theme is the light theme. */
|
3637
|
+
background-color: rgba(255, 255, 255, 0.95);
|
3638
|
+
border: 1px solid #d9d9d9;
|
3639
|
+
color: black; }
|
3640
|
+
#vg-tooltip-element.visible {
|
3641
|
+
visibility: visible; }
|
3642
|
+
#vg-tooltip-element h2 {
|
3643
|
+
margin-top: 0;
|
3644
|
+
margin-bottom: 10px;
|
3645
|
+
font-size: 13px; }
|
3646
|
+
#vg-tooltip-element img {
|
3647
|
+
max-width: 200px;
|
3648
|
+
max-height: 200px; }
|
3649
|
+
#vg-tooltip-element table {
|
3650
|
+
border-spacing: 0; }
|
3651
|
+
#vg-tooltip-element table tr {
|
3652
|
+
border: none; }
|
3653
|
+
#vg-tooltip-element table tr td {
|
3654
|
+
overflow: hidden;
|
3655
|
+
text-overflow: ellipsis;
|
3656
|
+
padding-top: 2px;
|
3657
|
+
padding-bottom: 2px; }
|
3658
|
+
#vg-tooltip-element table tr td.key {
|
3659
|
+
color: #808080;
|
3660
|
+
max-width: 150px;
|
3661
|
+
text-align: right;
|
3662
|
+
padding-right: 4px; }
|
3663
|
+
#vg-tooltip-element table tr td.value {
|
3664
|
+
display: block;
|
3665
|
+
max-width: 300px;
|
3666
|
+
max-height: 7em;
|
3667
|
+
text-align: left; }
|
3668
|
+
#vg-tooltip-element.dark-theme {
|
3669
|
+
background-color: rgba(32, 32, 32, 0.9);
|
3670
|
+
border: 1px solid #f5f5f5;
|
3671
|
+
color: white; }
|
3672
|
+
#vg-tooltip-element.dark-theme td.key {
|
3673
|
+
color: #bfbfbf; }
|
3674
|
+
`;
|
3675
|
+
|
3676
|
+
const EL_ID = 'vg-tooltip-element';
|
3677
|
+
const DEFAULT_OPTIONS = {
|
3678
|
+
/**
|
3679
|
+
* X offset.
|
3680
|
+
*/
|
3681
|
+
offsetX: 10,
|
3682
|
+
/**
|
3683
|
+
* Y offset.
|
3684
|
+
*/
|
3685
|
+
offsetY: 10,
|
3686
|
+
/**
|
3687
|
+
* ID of the tooltip element.
|
3688
|
+
*/
|
3689
|
+
id: EL_ID,
|
3690
|
+
/**
|
3691
|
+
* ID of the tooltip CSS style.
|
3692
|
+
*/
|
3693
|
+
styleId: 'vega-tooltip-style',
|
3694
|
+
/**
|
3695
|
+
* The name of the theme. You can use the CSS class called [THEME]-theme to style the tooltips.
|
3696
|
+
*
|
3697
|
+
* There are two predefined themes: "light" (default) and "dark".
|
3698
|
+
*/
|
3699
|
+
theme: 'light',
|
3700
|
+
/**
|
3701
|
+
* Do not use the default styles provided by Vega Tooltip. If you enable this option, you need to use your own styles. It is not necessary to disable the default style when using a custom theme.
|
3702
|
+
*/
|
3703
|
+
disableDefaultStyle: false,
|
3704
|
+
/**
|
3705
|
+
* HTML sanitizer function that removes dangerous HTML to prevent XSS.
|
3706
|
+
*
|
3707
|
+
* This should be a function from string to string. You may replace it with a formatter such as a markdown formatter.
|
3708
|
+
*/
|
3709
|
+
sanitize: escapeHTML,
|
3710
|
+
/**
|
3711
|
+
* The maximum recursion depth when printing objects in the tooltip.
|
3712
|
+
*/
|
3713
|
+
maxDepth: 2,
|
3714
|
+
};
|
3715
|
+
/**
|
3716
|
+
* Escape special HTML characters.
|
3717
|
+
*
|
3718
|
+
* @param value A value to convert to string and HTML-escape.
|
3719
|
+
*/
|
3720
|
+
function escapeHTML(value) {
|
3721
|
+
return String(value).replace(/&/g, '&').replace(/</g, '<');
|
3722
|
+
}
|
3723
|
+
function createDefaultStyle(id) {
|
3724
|
+
// Just in case this id comes from a user, ensure these is no security issues
|
3725
|
+
if (!/^[A-Za-z]+[-:.\w]*$/.test(id)) {
|
3726
|
+
throw new Error('Invalid HTML ID');
|
3727
|
+
}
|
3728
|
+
return defaultStyle.toString().replace(EL_ID, id);
|
3729
|
+
}
|
3730
|
+
|
3731
|
+
/*! *****************************************************************************
|
3732
|
+
Copyright (c) Microsoft Corporation.
|
3733
|
+
|
3734
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
3735
|
+
purpose with or without fee is hereby granted.
|
3736
|
+
|
3737
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
3738
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
3739
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
3740
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
3741
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
3742
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
3743
|
+
PERFORMANCE OF THIS SOFTWARE.
|
3744
|
+
***************************************************************************** */
|
3745
|
+
|
3746
|
+
function __rest(s, e) {
|
3747
|
+
var t = {};
|
3748
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
3749
|
+
t[p] = s[p];
|
3750
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
3751
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
3752
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
3753
|
+
t[p[i]] = s[p[i]];
|
3754
|
+
}
|
3755
|
+
return t;
|
3756
|
+
}
|
3757
|
+
|
3758
|
+
/**
|
3759
|
+
* Format the value to be shown in the tooltip.
|
3760
|
+
*
|
3761
|
+
* @param value The value to show in the tooltip.
|
3762
|
+
* @param valueToHtml Function to convert a single cell value to an HTML string
|
3763
|
+
*/
|
3764
|
+
function formatValue(value, valueToHtml, maxDepth) {
|
3765
|
+
if (isArray(value)) {
|
3766
|
+
return `[${value.map((v) => valueToHtml(isString(v) ? v : stringify(v, maxDepth))).join(', ')}]`;
|
3767
|
+
}
|
3768
|
+
if (isObject(value)) {
|
3769
|
+
let content = '';
|
3770
|
+
const _a = value, { title, image } = _a, rest = __rest(_a, ["title", "image"]);
|
3771
|
+
if (title) {
|
3772
|
+
content += `<h2>${valueToHtml(title)}</h2>`;
|
3773
|
+
}
|
3774
|
+
if (image) {
|
3775
|
+
content += `<img src="${valueToHtml(image)}">`;
|
3776
|
+
}
|
3777
|
+
const keys = Object.keys(rest);
|
3778
|
+
if (keys.length > 0) {
|
3779
|
+
content += '<table>';
|
3780
|
+
for (const key of keys) {
|
3781
|
+
let val = rest[key];
|
3782
|
+
// ignore undefined properties
|
3783
|
+
if (val === undefined) {
|
3784
|
+
continue;
|
3785
|
+
}
|
3786
|
+
if (isObject(val)) {
|
3787
|
+
val = stringify(val, maxDepth);
|
3788
|
+
}
|
3789
|
+
content += `<tr><td class="key">${valueToHtml(key)}:</td><td class="value">${valueToHtml(val)}</td></tr>`;
|
3790
|
+
}
|
3791
|
+
content += `</table>`;
|
3792
|
+
}
|
3793
|
+
return content || '{}'; // show empty object if there are no properties
|
3794
|
+
}
|
3795
|
+
return valueToHtml(value);
|
3796
|
+
}
|
3797
|
+
function replacer(maxDepth) {
|
3798
|
+
const stack = [];
|
3799
|
+
return function (key, value) {
|
3800
|
+
if (typeof value !== 'object' || value === null) {
|
3801
|
+
return value;
|
3802
|
+
}
|
3803
|
+
const pos = stack.indexOf(this) + 1;
|
3804
|
+
stack.length = pos;
|
3805
|
+
if (stack.length > maxDepth) {
|
3806
|
+
return '[Object]';
|
3807
|
+
}
|
3808
|
+
if (stack.indexOf(value) >= 0) {
|
3809
|
+
return '[Circular]';
|
3810
|
+
}
|
3811
|
+
stack.push(value);
|
3812
|
+
return value;
|
3813
|
+
};
|
3814
|
+
}
|
3815
|
+
/**
|
3816
|
+
* Stringify any JS object to valid JSON
|
3817
|
+
*/
|
3818
|
+
function stringify(obj, maxDepth) {
|
3819
|
+
return JSON.stringify(obj, replacer(maxDepth));
|
3820
|
+
}
|
3821
|
+
|
3822
|
+
/**
|
3823
|
+
* Position the tooltip
|
3824
|
+
*
|
3825
|
+
* @param event The mouse event.
|
3826
|
+
* @param tooltipBox
|
3827
|
+
* @param offsetX Horizontal offset.
|
3828
|
+
* @param offsetY Vertical offset.
|
3829
|
+
*/
|
3830
|
+
function calculatePosition(event, tooltipBox, offsetX, offsetY) {
|
3831
|
+
let x = event.clientX + offsetX;
|
3832
|
+
if (x + tooltipBox.width > window.innerWidth) {
|
3833
|
+
x = +event.clientX - offsetX - tooltipBox.width;
|
3834
|
+
}
|
3835
|
+
let y = event.clientY + offsetY;
|
3836
|
+
if (y + tooltipBox.height > window.innerHeight) {
|
3837
|
+
y = +event.clientY - offsetY - tooltipBox.height;
|
3838
|
+
}
|
3839
|
+
return { x, y };
|
3840
|
+
}
|
3841
|
+
|
3842
|
+
/**
|
3843
|
+
* The tooltip handler class.
|
3844
|
+
*/
|
3845
|
+
class Handler {
|
3846
|
+
/**
|
3847
|
+
* Create the tooltip handler and initialize the element and style.
|
3848
|
+
*
|
3849
|
+
* @param options Tooltip Options
|
3850
|
+
*/
|
3851
|
+
constructor(options) {
|
3852
|
+
this.options = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options);
|
3853
|
+
const elementId = this.options.id;
|
3854
|
+
// bind this to call
|
3855
|
+
this.call = this.tooltipHandler.bind(this);
|
3856
|
+
// prepend a default stylesheet for tooltips to the head
|
3857
|
+
if (!this.options.disableDefaultStyle && !document.getElementById(this.options.styleId)) {
|
3858
|
+
const style = document.createElement('style');
|
3859
|
+
style.setAttribute('id', this.options.styleId);
|
3860
|
+
style.innerHTML = createDefaultStyle(elementId);
|
3861
|
+
const head = document.head;
|
3862
|
+
if (head.childNodes.length > 0) {
|
3863
|
+
head.insertBefore(style, head.childNodes[0]);
|
3864
|
+
}
|
3865
|
+
else {
|
3866
|
+
head.appendChild(style);
|
3867
|
+
}
|
3868
|
+
}
|
3869
|
+
// append a div element that we use as a tooltip unless it already exists
|
3870
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
3871
|
+
this.el = document.getElementById(elementId);
|
3872
|
+
if (!this.el) {
|
3873
|
+
this.el = document.createElement('div');
|
3874
|
+
this.el.setAttribute('id', elementId);
|
3875
|
+
this.el.classList.add('vg-tooltip');
|
3876
|
+
document.body.appendChild(this.el);
|
3877
|
+
}
|
3878
|
+
}
|
3879
|
+
/**
|
3880
|
+
* The tooltip handler function.
|
3881
|
+
*/
|
3882
|
+
tooltipHandler(handler, event, item, value) {
|
3883
|
+
// console.log(handler, event, item, value);
|
3884
|
+
// hide tooltip for null, undefined, or empty string values
|
3885
|
+
if (value == null || value === '') {
|
3886
|
+
this.el.classList.remove('visible', `${this.options.theme}-theme`);
|
3887
|
+
return;
|
3888
|
+
}
|
3889
|
+
// set the tooltip content
|
3890
|
+
this.el.innerHTML = formatValue(value, this.options.sanitize, this.options.maxDepth);
|
3891
|
+
// make the tooltip visible
|
3892
|
+
this.el.classList.add('visible', `${this.options.theme}-theme`);
|
3893
|
+
const { x, y } = calculatePosition(event, this.el.getBoundingClientRect(), this.options.offsetX, this.options.offsetY);
|
3894
|
+
this.el.setAttribute('style', `top: ${y}px; left: ${x}px`);
|
3895
|
+
}
|
3896
|
+
}
|
3897
|
+
|
3898
|
+
/**
|
3899
|
+
* Open editor url in a new window, and pass a message.
|
3900
|
+
*/
|
3901
|
+
function post (window, url, data) {
|
3902
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
3903
|
+
var editor = window.open(url);
|
3904
|
+
var wait = 10000;
|
3905
|
+
var step = 250;
|
3906
|
+
var origin = new URL(url).origin;
|
3907
|
+
// eslint-disable-next-line no-bitwise
|
3908
|
+
var count = ~~(wait / step);
|
3909
|
+
function listen(evt) {
|
3910
|
+
if (evt.source === editor) {
|
3911
|
+
count = 0;
|
3912
|
+
window.removeEventListener('message', listen, false);
|
3913
|
+
}
|
3914
|
+
}
|
3915
|
+
window.addEventListener('message', listen, false);
|
3916
|
+
// send message
|
3917
|
+
// periodically resend until ack received or timeout
|
3918
|
+
function send() {
|
3919
|
+
if (count <= 0) {
|
3920
|
+
return;
|
3921
|
+
}
|
3922
|
+
editor.postMessage(data, origin);
|
3923
|
+
setTimeout(send, step);
|
3924
|
+
count -= 1;
|
3925
|
+
}
|
3926
|
+
setTimeout(send, step);
|
3927
|
+
}
|
3928
|
+
|
3929
|
+
// generated with build-style.sh
|
3930
|
+
var embedStyle = ".vega-embed {\n position: relative;\n display: inline-block;\n box-sizing: border-box; }\n .vega-embed.has-actions {\n padding-right: 38px; }\n .vega-embed details:not([open]) > :not(summary) {\n display: none !important; }\n .vega-embed summary {\n list-style: none;\n position: absolute;\n top: 0;\n right: 0;\n padding: 6px;\n z-index: 1000;\n background: white;\n box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);\n color: #1b1e23;\n border: 1px solid #aaa;\n border-radius: 999px;\n opacity: 0.2;\n transition: opacity 0.4s ease-in;\n outline: none;\n cursor: pointer;\n line-height: 0px; }\n .vega-embed summary::-webkit-details-marker {\n display: none; }\n .vega-embed summary:active {\n box-shadow: #aaa 0px 0px 0px 1px inset; }\n .vega-embed summary svg {\n width: 14px;\n height: 14px; }\n .vega-embed details[open] summary {\n opacity: 0.7; }\n .vega-embed:hover summary,\n .vega-embed:focus summary {\n opacity: 1 !important;\n transition: opacity 0.2s ease; }\n .vega-embed .vega-actions {\n position: absolute;\n z-index: 1001;\n top: 35px;\n right: -9px;\n display: flex;\n flex-direction: column;\n padding-bottom: 8px;\n padding-top: 8px;\n border-radius: 4px;\n box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.2);\n border: 1px solid #d9d9d9;\n background: white;\n animation-duration: 0.15s;\n animation-name: scale-in;\n animation-timing-function: cubic-bezier(0.2, 0, 0.13, 1.5);\n text-align: left; }\n .vega-embed .vega-actions a {\n padding: 8px 16px;\n font-family: sans-serif;\n font-size: 14px;\n font-weight: 600;\n white-space: nowrap;\n color: #434a56;\n text-decoration: none; }\n .vega-embed .vega-actions a:hover {\n background-color: #f7f7f9;\n color: black; }\n .vega-embed .vega-actions::before, .vega-embed .vega-actions::after {\n content: \"\";\n display: inline-block;\n position: absolute; }\n .vega-embed .vega-actions::before {\n left: auto;\n right: 14px;\n top: -16px;\n border: 8px solid #0000;\n border-bottom-color: #d9d9d9; }\n .vega-embed .vega-actions::after {\n left: auto;\n right: 15px;\n top: -14px;\n border: 7px solid #0000;\n border-bottom-color: #fff; }\n .vega-embed .chart-wrapper {\n width: 100%;\n height: 100%; }\n\n.vega-embed-wrapper {\n max-width: 100%;\n overflow: scroll;\n padding-right: 14px; }\n\n@keyframes scale-in {\n from {\n opacity: 0;\n transform: scale(0.6); }\n to {\n opacity: 1;\n transform: scale(1); } }\n";
|
3931
|
+
|
3932
|
+
// polyfill for IE
|
3933
|
+
if (!String.prototype.startsWith) {
|
3934
|
+
// eslint-disable-next-line no-extend-native,func-names
|
3935
|
+
String.prototype.startsWith = function (search, pos) {
|
3936
|
+
return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
|
3937
|
+
};
|
3938
|
+
}
|
3939
|
+
function isURL(s) {
|
3940
|
+
return s.startsWith('http://') || s.startsWith('https://') || s.startsWith('//');
|
3941
|
+
}
|
3942
|
+
function mergeDeep(dest) {
|
3943
|
+
var src = [];
|
3944
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
3945
|
+
src[_i - 1] = arguments[_i];
|
3946
|
+
}
|
3947
|
+
for (var _a = 0, src_1 = src; _a < src_1.length; _a++) {
|
3948
|
+
var s = src_1[_a];
|
3949
|
+
deepMerge_(dest, s);
|
3950
|
+
}
|
3951
|
+
return dest;
|
3952
|
+
}
|
3953
|
+
function deepMerge_(dest, src) {
|
3954
|
+
for (var _i = 0, _a = Object.keys(src); _i < _a.length; _i++) {
|
3955
|
+
var property = _a[_i];
|
3956
|
+
vegaImport.writeConfig(dest, property, src[property], true);
|
3957
|
+
}
|
3958
|
+
}
|
3959
|
+
|
3960
|
+
var _a;
|
3961
|
+
var vega = vegaImport__namespace;
|
3962
|
+
var vegaLite = vegaLiteImport__namespace;
|
3963
|
+
// For backwards compatibility with Vega-Lite before v4.
|
3964
|
+
var w = (typeof window !== 'undefined' ? window : undefined);
|
3965
|
+
if (vegaLite === undefined && ((_a = w === null || w === void 0 ? void 0 : w['vl']) === null || _a === void 0 ? void 0 : _a.compile)) {
|
3966
|
+
vegaLite = w['vl'];
|
3967
|
+
}
|
3968
|
+
var DEFAULT_ACTIONS = { "export": { svg: true, png: true }, source: true, compiled: true, editor: true };
|
3969
|
+
var I18N = {
|
3970
|
+
CLICK_TO_VIEW_ACTIONS: 'Click to view actions',
|
3971
|
+
COMPILED_ACTION: 'View Compiled Vega',
|
3972
|
+
EDITOR_ACTION: 'Open in Vega Editor',
|
3973
|
+
PNG_ACTION: 'Save as PNG',
|
3974
|
+
SOURCE_ACTION: 'View Source',
|
3975
|
+
SVG_ACTION: 'Save as SVG'
|
3976
|
+
};
|
3977
|
+
var NAMES = {
|
3978
|
+
vega: 'Vega',
|
3979
|
+
'vega-lite': 'Vega-Lite'
|
3980
|
+
};
|
3981
|
+
var VERSION = {
|
3982
|
+
vega: vega.version,
|
3983
|
+
'vega-lite': vegaLite ? vegaLite.version : 'not available'
|
3984
|
+
};
|
3985
|
+
var PREPROCESSOR = {
|
3986
|
+
vega: function (vgSpec) { return vgSpec; },
|
3987
|
+
'vega-lite': function (vlSpec, config) { return vegaLite.compile(vlSpec, { config: config }).spec; }
|
3988
|
+
};
|
3989
|
+
var SVG_CIRCLES = "\n<svg viewBox=\"0 0 16 16\" fill=\"currentColor\" stroke=\"none\" stroke-width=\"1\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle r=\"2\" cy=\"8\" cx=\"2\"></circle>\n <circle r=\"2\" cy=\"8\" cx=\"8\"></circle>\n <circle r=\"2\" cy=\"8\" cx=\"14\"></circle>\n</svg>";
|
3990
|
+
var CHART_WRAPPER_CLASS = 'chart-wrapper';
|
3991
|
+
function isTooltipHandler(h) {
|
3992
|
+
return typeof h === 'function';
|
3993
|
+
}
|
3994
|
+
function viewSource(source, sourceHeader, sourceFooter, mode) {
|
3995
|
+
var header = "<html><head>" + sourceHeader + "</head><body><pre><code class=\"json\">";
|
3996
|
+
var footer = "</code></pre>" + sourceFooter + "</body></html>";
|
3997
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
3998
|
+
var win = window.open('');
|
3999
|
+
win.document.write(header + source + footer);
|
4000
|
+
win.document.title = NAMES[mode] + " JSON Source";
|
4001
|
+
}
|
4002
|
+
/**
|
4003
|
+
* Try to guess the type of spec.
|
4004
|
+
*
|
4005
|
+
* @param spec Vega or Vega-Lite spec.
|
4006
|
+
*/
|
4007
|
+
function guessMode(spec, providedMode) {
|
4008
|
+
var _a;
|
4009
|
+
// Decide mode
|
4010
|
+
if (spec.$schema) {
|
4011
|
+
var parsed = schemaParser(spec.$schema);
|
4012
|
+
if (providedMode && providedMode !== parsed.library) {
|
4013
|
+
console.warn("The given visualization spec is written in " + NAMES[parsed.library] + ", but mode argument sets " + ((_a = NAMES[providedMode]) !== null && _a !== void 0 ? _a : providedMode) + ".");
|
4014
|
+
}
|
4015
|
+
var mode = parsed.library;
|
4016
|
+
if (!semver$1.satisfies(VERSION[mode], "^" + parsed.version.slice(1))) {
|
4017
|
+
console.warn("The input spec uses " + NAMES[mode] + " " + parsed.version + ", but the current version of " + NAMES[mode] + " is v" + VERSION[mode] + ".");
|
4018
|
+
}
|
4019
|
+
return mode;
|
4020
|
+
}
|
4021
|
+
// try to guess from the provided spec
|
4022
|
+
if ('mark' in spec ||
|
4023
|
+
'encoding' in spec ||
|
4024
|
+
'layer' in spec ||
|
4025
|
+
'hconcat' in spec ||
|
4026
|
+
'vconcat' in spec ||
|
4027
|
+
'facet' in spec ||
|
4028
|
+
'repeat' in spec) {
|
4029
|
+
return 'vega-lite';
|
4030
|
+
}
|
4031
|
+
if ('marks' in spec || 'signals' in spec || 'scales' in spec || 'axes' in spec) {
|
4032
|
+
return 'vega';
|
4033
|
+
}
|
4034
|
+
return providedMode !== null && providedMode !== void 0 ? providedMode : 'vega';
|
4035
|
+
}
|
4036
|
+
function isLoader(o) {
|
4037
|
+
return !!(o && 'load' in o);
|
4038
|
+
}
|
4039
|
+
/**
|
4040
|
+
* Embed a Vega visualization component in a web page. This function returns a promise.
|
4041
|
+
*
|
4042
|
+
* @param el DOM element in which to place component (DOM node or CSS selector).
|
4043
|
+
* @param spec String : A URL string from which to load the Vega specification.
|
4044
|
+
* Object : The Vega/Vega-Lite specification as a parsed JSON object.
|
4045
|
+
* @param opts A JavaScript object containing options for embedding.
|
4046
|
+
*/
|
4047
|
+
function embed(el, spec, opts) {
|
4048
|
+
var _a, _b, _c;
|
4049
|
+
if (opts === void 0) { opts = {}; }
|
4050
|
+
return __awaiter(this, void 0, void 0, function () {
|
4051
|
+
var loader, parsedSpec, _d, _e, _f, usermetaOpts, parsedOpts, mergedOpts;
|
4052
|
+
return __generator(this, function (_g) {
|
4053
|
+
switch (_g.label) {
|
4054
|
+
case 0:
|
4055
|
+
loader = isLoader(opts.loader) ? opts.loader : vega.loader(opts.loader);
|
4056
|
+
if (!vegaImport.isString(spec)) return [3 /*break*/, 2];
|
4057
|
+
_f = (_e = JSON).parse;
|
4058
|
+
return [4 /*yield*/, loader.load(spec)];
|
4059
|
+
case 1:
|
4060
|
+
_d = _f.apply(_e, [_g.sent()]);
|
4061
|
+
return [3 /*break*/, 3];
|
4062
|
+
case 2:
|
4063
|
+
_d = spec;
|
4064
|
+
_g.label = 3;
|
4065
|
+
case 3:
|
4066
|
+
parsedSpec = _d;
|
4067
|
+
return [4 /*yield*/, loadOpts((_a = (parsedSpec.usermeta && parsedSpec.usermeta['embedOptions'])) !== null && _a !== void 0 ? _a : {}, loader)];
|
4068
|
+
case 4:
|
4069
|
+
usermetaOpts = _g.sent();
|
4070
|
+
return [4 /*yield*/, loadOpts(opts, loader)];
|
4071
|
+
case 5:
|
4072
|
+
parsedOpts = _g.sent();
|
4073
|
+
mergedOpts = __assign(__assign({}, mergeDeep(parsedOpts, usermetaOpts)), { config: vegaImport.mergeConfig((_b = parsedOpts.config) !== null && _b !== void 0 ? _b : {}, (_c = usermetaOpts.config) !== null && _c !== void 0 ? _c : {}) });
|
4074
|
+
return [4 /*yield*/, _embed(el, parsedSpec, mergedOpts, loader)];
|
4075
|
+
case 6: return [2 /*return*/, _g.sent()];
|
4076
|
+
}
|
4077
|
+
});
|
4078
|
+
});
|
4079
|
+
}
|
4080
|
+
function loadOpts(opt, loader) {
|
4081
|
+
var _a;
|
4082
|
+
return __awaiter(this, void 0, void 0, function () {
|
4083
|
+
var config, _b, _c, _d, patch, _e, _f, _g;
|
4084
|
+
return __generator(this, function (_h) {
|
4085
|
+
switch (_h.label) {
|
4086
|
+
case 0:
|
4087
|
+
if (!vegaImport.isString(opt.config)) return [3 /*break*/, 2];
|
4088
|
+
_d = (_c = JSON).parse;
|
4089
|
+
return [4 /*yield*/, loader.load(opt.config)];
|
4090
|
+
case 1:
|
4091
|
+
_b = _d.apply(_c, [_h.sent()]);
|
4092
|
+
return [3 /*break*/, 3];
|
4093
|
+
case 2:
|
4094
|
+
_b = (_a = opt.config) !== null && _a !== void 0 ? _a : {};
|
4095
|
+
_h.label = 3;
|
4096
|
+
case 3:
|
4097
|
+
config = _b;
|
4098
|
+
if (!vegaImport.isString(opt.patch)) return [3 /*break*/, 5];
|
4099
|
+
_g = (_f = JSON).parse;
|
4100
|
+
return [4 /*yield*/, loader.load(opt.patch)];
|
4101
|
+
case 4:
|
4102
|
+
_e = _g.apply(_f, [_h.sent()]);
|
4103
|
+
return [3 /*break*/, 6];
|
4104
|
+
case 5:
|
4105
|
+
_e = opt.patch;
|
4106
|
+
_h.label = 6;
|
4107
|
+
case 6:
|
4108
|
+
patch = _e;
|
4109
|
+
return [2 /*return*/, __assign(__assign(__assign({}, opt), (patch ? { patch: patch } : {})), (config ? { config: config } : {}))];
|
4110
|
+
}
|
4111
|
+
});
|
4112
|
+
});
|
4113
|
+
}
|
4114
|
+
function getRoot(el) {
|
4115
|
+
var _a;
|
4116
|
+
var possibleRoot = el.getRootNode ? el.getRootNode() : document;
|
4117
|
+
if (possibleRoot instanceof ShadowRoot) {
|
4118
|
+
return { root: possibleRoot, rootContainer: possibleRoot };
|
4119
|
+
}
|
4120
|
+
else {
|
4121
|
+
return { root: document, rootContainer: (_a = document.head) !== null && _a !== void 0 ? _a : document.body };
|
4122
|
+
}
|
4123
|
+
}
|
4124
|
+
function _embed(el, spec, opts, loader) {
|
4125
|
+
var _a, _b, _c, _d, _e, _f;
|
4126
|
+
if (opts === void 0) { opts = {}; }
|
4127
|
+
return __awaiter(this, void 0, void 0, function () {
|
4128
|
+
function finalize() {
|
4129
|
+
if (documentClickHandler) {
|
4130
|
+
document.removeEventListener('click', documentClickHandler);
|
4131
|
+
}
|
4132
|
+
view.finalize();
|
4133
|
+
}
|
4134
|
+
var config, actions, i18n, renderer, logLevel, downloadFileName, div, ID, _g, root, rootContainer, style, mode, vgSpec, parsed, target, chartWrapper, patch, ast, runtime, view, handler, hover, _h, hoverSet, updateSet, documentClickHandler, wrapper, details_1, summary, ctrl, _loop_1, _i, _j, ext, viewSourceLink, compileLink, editorUrl_1, editorLink;
|
4135
|
+
return __generator(this, function (_k) {
|
4136
|
+
switch (_k.label) {
|
4137
|
+
case 0:
|
4138
|
+
config = opts.theme ? vegaImport.mergeConfig(themes[opts.theme], (_a = opts.config) !== null && _a !== void 0 ? _a : {}) : opts.config;
|
4139
|
+
actions = vegaImport.isBoolean(opts.actions) ? opts.actions : mergeDeep({}, DEFAULT_ACTIONS, (_b = opts.actions) !== null && _b !== void 0 ? _b : {});
|
4140
|
+
i18n = __assign(__assign({}, I18N), opts.i18n);
|
4141
|
+
renderer = (_c = opts.renderer) !== null && _c !== void 0 ? _c : 'canvas';
|
4142
|
+
logLevel = (_d = opts.logLevel) !== null && _d !== void 0 ? _d : vega.Warn;
|
4143
|
+
downloadFileName = (_e = opts.downloadFileName) !== null && _e !== void 0 ? _e : 'visualization';
|
4144
|
+
div = typeof el === 'string' ? document.querySelector(el) : el;
|
4145
|
+
if (!div) {
|
4146
|
+
throw new Error(el + " does not exist");
|
4147
|
+
}
|
4148
|
+
if (opts.defaultStyle !== false) {
|
4149
|
+
ID = 'vega-embed-style';
|
4150
|
+
_g = getRoot(div), root = _g.root, rootContainer = _g.rootContainer;
|
4151
|
+
if (!root.getElementById(ID)) {
|
4152
|
+
style = document.createElement('style');
|
4153
|
+
style.id = ID;
|
4154
|
+
style.innerText =
|
4155
|
+
opts.defaultStyle === undefined || opts.defaultStyle === true
|
4156
|
+
? ( embedStyle ).toString()
|
4157
|
+
: opts.defaultStyle;
|
4158
|
+
rootContainer.appendChild(style);
|
4159
|
+
}
|
4160
|
+
}
|
4161
|
+
mode = guessMode(spec, opts.mode);
|
4162
|
+
vgSpec = PREPROCESSOR[mode](spec, config);
|
4163
|
+
if (mode === 'vega-lite') {
|
4164
|
+
if (vgSpec.$schema) {
|
4165
|
+
parsed = schemaParser(vgSpec.$schema);
|
4166
|
+
if (!semver$1.satisfies(VERSION.vega, "^" + parsed.version.slice(1))) {
|
4167
|
+
console.warn("The compiled spec uses Vega " + parsed.version + ", but current version is v" + VERSION.vega + ".");
|
4168
|
+
}
|
4169
|
+
}
|
4170
|
+
}
|
4171
|
+
div.classList.add('vega-embed');
|
4172
|
+
if (actions) {
|
4173
|
+
div.classList.add('has-actions');
|
4174
|
+
}
|
4175
|
+
div.innerHTML = ''; // clear container
|
4176
|
+
target = div;
|
4177
|
+
if (actions) {
|
4178
|
+
chartWrapper = document.createElement('div');
|
4179
|
+
chartWrapper.classList.add(CHART_WRAPPER_CLASS);
|
4180
|
+
div.appendChild(chartWrapper);
|
4181
|
+
target = chartWrapper;
|
4182
|
+
}
|
4183
|
+
patch = opts.patch;
|
4184
|
+
if (patch) {
|
4185
|
+
if (patch instanceof Function) {
|
4186
|
+
vgSpec = patch(vgSpec);
|
4187
|
+
}
|
4188
|
+
else {
|
4189
|
+
vgSpec = applyPatch(vgSpec, patch, true, false).newDocument;
|
4190
|
+
}
|
4191
|
+
}
|
4192
|
+
// Set locale. Note that this is a global setting.
|
4193
|
+
if (opts.formatLocale) {
|
4194
|
+
vega.formatLocale(opts.formatLocale);
|
4195
|
+
}
|
4196
|
+
if (opts.timeFormatLocale) {
|
4197
|
+
vega.timeFormatLocale(opts.timeFormatLocale);
|
4198
|
+
}
|
4199
|
+
ast = opts.ast;
|
4200
|
+
runtime = vega.parse(vgSpec, mode === 'vega-lite' ? {} : config, { ast: ast });
|
4201
|
+
view = new vega.View(runtime, __assign({ loader: loader,
|
4202
|
+
logLevel: logLevel,
|
4203
|
+
renderer: renderer }, (ast ? { expr: vega.expressionInterpreter } : {})));
|
4204
|
+
if (opts.tooltip !== false) {
|
4205
|
+
handler = void 0;
|
4206
|
+
if (isTooltipHandler(opts.tooltip)) {
|
4207
|
+
handler = opts.tooltip;
|
4208
|
+
}
|
4209
|
+
else {
|
4210
|
+
// user provided boolean true or tooltip options
|
4211
|
+
handler = new Handler(opts.tooltip === true ? {} : opts.tooltip).call;
|
4212
|
+
}
|
4213
|
+
view.tooltip(handler);
|
4214
|
+
}
|
4215
|
+
hover = opts.hover;
|
4216
|
+
if (hover === undefined) {
|
4217
|
+
hover = mode === 'vega';
|
4218
|
+
}
|
4219
|
+
if (hover) {
|
4220
|
+
_h = (typeof hover === 'boolean' ? {} : hover), hoverSet = _h.hoverSet, updateSet = _h.updateSet;
|
4221
|
+
view.hover(hoverSet, updateSet);
|
4222
|
+
}
|
4223
|
+
if (opts) {
|
4224
|
+
if (opts.width != null) {
|
4225
|
+
view.width(opts.width);
|
4226
|
+
}
|
4227
|
+
if (opts.height != null) {
|
4228
|
+
view.height(opts.height);
|
4229
|
+
}
|
4230
|
+
if (opts.padding != null) {
|
4231
|
+
view.padding(opts.padding);
|
4232
|
+
}
|
4233
|
+
}
|
4234
|
+
return [4 /*yield*/, view.initialize(target).runAsync()];
|
4235
|
+
case 1:
|
4236
|
+
_k.sent();
|
4237
|
+
if (actions !== false) {
|
4238
|
+
wrapper = div;
|
4239
|
+
if (opts.defaultStyle !== false) {
|
4240
|
+
details_1 = document.createElement('details');
|
4241
|
+
details_1.title = i18n.CLICK_TO_VIEW_ACTIONS;
|
4242
|
+
div.append(details_1);
|
4243
|
+
wrapper = details_1;
|
4244
|
+
summary = document.createElement('summary');
|
4245
|
+
summary.innerHTML = SVG_CIRCLES;
|
4246
|
+
details_1.append(summary);
|
4247
|
+
documentClickHandler = function (ev) {
|
4248
|
+
if (!details_1.contains(ev.target)) {
|
4249
|
+
details_1.removeAttribute('open');
|
4250
|
+
}
|
4251
|
+
};
|
4252
|
+
document.addEventListener('click', documentClickHandler);
|
4253
|
+
}
|
4254
|
+
ctrl = document.createElement('div');
|
4255
|
+
wrapper.append(ctrl);
|
4256
|
+
ctrl.classList.add('vega-actions');
|
4257
|
+
// add 'Export' action
|
4258
|
+
if (actions === true || actions["export"] !== false) {
|
4259
|
+
_loop_1 = function (ext) {
|
4260
|
+
if (actions === true || actions["export"] === true || actions["export"][ext]) {
|
4261
|
+
var i18nExportAction = i18n[ext.toUpperCase() + "_ACTION"];
|
4262
|
+
var exportLink = document.createElement('a');
|
4263
|
+
exportLink.text = i18nExportAction;
|
4264
|
+
exportLink.href = '#';
|
4265
|
+
exportLink.target = '_blank';
|
4266
|
+
exportLink.download = downloadFileName + "." + ext;
|
4267
|
+
// add link on mousedown so that it's correct when the click happens
|
4268
|
+
exportLink.addEventListener('mousedown', function (e) {
|
4269
|
+
return __awaiter(this, void 0, void 0, function () {
|
4270
|
+
var url;
|
4271
|
+
return __generator(this, function (_a) {
|
4272
|
+
switch (_a.label) {
|
4273
|
+
case 0:
|
4274
|
+
e.preventDefault();
|
4275
|
+
return [4 /*yield*/, view.toImageURL(ext, opts.scaleFactor)];
|
4276
|
+
case 1:
|
4277
|
+
url = _a.sent();
|
4278
|
+
this.href = url;
|
4279
|
+
return [2 /*return*/];
|
4280
|
+
}
|
4281
|
+
});
|
4282
|
+
});
|
4283
|
+
});
|
4284
|
+
ctrl.append(exportLink);
|
4285
|
+
}
|
4286
|
+
};
|
4287
|
+
for (_i = 0, _j = ['svg', 'png']; _i < _j.length; _i++) {
|
4288
|
+
ext = _j[_i];
|
4289
|
+
_loop_1(ext);
|
4290
|
+
}
|
4291
|
+
}
|
4292
|
+
// add 'View Source' action
|
4293
|
+
if (actions === true || actions.source !== false) {
|
4294
|
+
viewSourceLink = document.createElement('a');
|
4295
|
+
viewSourceLink.text = i18n.SOURCE_ACTION;
|
4296
|
+
viewSourceLink.href = '#';
|
4297
|
+
viewSourceLink.addEventListener('click', function (e) {
|
4298
|
+
var _a, _b;
|
4299
|
+
viewSource(jsonStringifyPrettyCompact(spec), (_a = opts.sourceHeader) !== null && _a !== void 0 ? _a : '', (_b = opts.sourceFooter) !== null && _b !== void 0 ? _b : '', mode);
|
4300
|
+
e.preventDefault();
|
4301
|
+
});
|
4302
|
+
ctrl.append(viewSourceLink);
|
4303
|
+
}
|
4304
|
+
// add 'View Compiled' action
|
4305
|
+
if (mode === 'vega-lite' && (actions === true || actions.compiled !== false)) {
|
4306
|
+
compileLink = document.createElement('a');
|
4307
|
+
compileLink.text = i18n.COMPILED_ACTION;
|
4308
|
+
compileLink.href = '#';
|
4309
|
+
compileLink.addEventListener('click', function (e) {
|
4310
|
+
var _a, _b;
|
4311
|
+
viewSource(jsonStringifyPrettyCompact(vgSpec), (_a = opts.sourceHeader) !== null && _a !== void 0 ? _a : '', (_b = opts.sourceFooter) !== null && _b !== void 0 ? _b : '', 'vega');
|
4312
|
+
e.preventDefault();
|
4313
|
+
});
|
4314
|
+
ctrl.append(compileLink);
|
4315
|
+
}
|
4316
|
+
// add 'Open in Vega Editor' action
|
4317
|
+
if (actions === true || actions.editor !== false) {
|
4318
|
+
editorUrl_1 = (_f = opts.editorUrl) !== null && _f !== void 0 ? _f : 'https://vega.github.io/editor/';
|
4319
|
+
editorLink = document.createElement('a');
|
4320
|
+
editorLink.text = i18n.EDITOR_ACTION;
|
4321
|
+
editorLink.href = '#';
|
4322
|
+
editorLink.addEventListener('click', function (e) {
|
4323
|
+
post(window, editorUrl_1, {
|
4324
|
+
config: config,
|
4325
|
+
mode: mode,
|
4326
|
+
renderer: renderer,
|
4327
|
+
spec: jsonStringifyPrettyCompact(spec)
|
4328
|
+
});
|
4329
|
+
e.preventDefault();
|
4330
|
+
});
|
4331
|
+
ctrl.append(editorLink);
|
4332
|
+
}
|
4333
|
+
}
|
4334
|
+
return [2 /*return*/, { view: view, spec: spec, vgSpec: vgSpec, finalize: finalize }];
|
4335
|
+
}
|
4336
|
+
});
|
4337
|
+
});
|
4338
|
+
}
|
4339
|
+
|
4340
|
+
/**
|
4341
|
+
* Create a promise to an HTML Div element with an embedded Vega-Lite or Vega visualization.
|
4342
|
+
* The element has a value property with the view. By default all actions except for the editor action are disabled.
|
4343
|
+
*
|
4344
|
+
* The main use case is in [Observable](https://observablehq.com/).
|
4345
|
+
*/
|
4346
|
+
function container (spec, opt) {
|
4347
|
+
var _a;
|
4348
|
+
if (opt === void 0) { opt = {}; }
|
4349
|
+
return __awaiter(this, void 0, void 0, function () {
|
4350
|
+
var wrapper, div, actions, result;
|
4351
|
+
return __generator(this, function (_b) {
|
4352
|
+
switch (_b.label) {
|
4353
|
+
case 0:
|
4354
|
+
wrapper = document.createElement('div');
|
4355
|
+
wrapper.classList.add('vega-embed-wrapper');
|
4356
|
+
div = document.createElement('div');
|
4357
|
+
wrapper.appendChild(div);
|
4358
|
+
actions = opt.actions === true || opt.actions === false
|
4359
|
+
? opt.actions
|
4360
|
+
: __assign({ "export": true, source: false, compiled: true, editor: true }, ((_a = opt.actions) !== null && _a !== void 0 ? _a : {}));
|
4361
|
+
return [4 /*yield*/, embed(div, spec, __assign({ actions: actions }, (opt !== null && opt !== void 0 ? opt : {})))];
|
4362
|
+
case 1:
|
4363
|
+
result = _b.sent();
|
4364
|
+
wrapper.value = result.view;
|
4365
|
+
return [2 /*return*/, wrapper];
|
4366
|
+
}
|
4367
|
+
});
|
4368
|
+
});
|
4369
|
+
}
|
4370
|
+
|
4371
|
+
/**
|
4372
|
+
* Returns true if the object is an HTML element.
|
4373
|
+
*/
|
4374
|
+
function isElement(obj) {
|
4375
|
+
return obj instanceof HTMLElement;
|
4376
|
+
}
|
4377
|
+
var wrapper = function () {
|
4378
|
+
var args = [];
|
4379
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
4380
|
+
args[_i] = arguments[_i];
|
4381
|
+
}
|
4382
|
+
if (args.length > 1 && ((vegaImport.isString(args[0]) && !isURL(args[0])) || isElement(args[0]) || args.length === 3)) {
|
4383
|
+
return embed(args[0], args[1], args[2]);
|
4384
|
+
}
|
4385
|
+
return container(args[0], args[1]);
|
4386
|
+
};
|
4387
|
+
wrapper.vegaLite = vegaLite;
|
4388
|
+
wrapper.vl = vegaLite; // backwards compatibility
|
4389
|
+
wrapper.container = container;
|
4390
|
+
wrapper.embed = embed;
|
4391
|
+
wrapper.vega = vega;
|
4392
|
+
wrapper["default"] = embed;
|
4393
|
+
wrapper.version = version;
|
4394
|
+
|
4395
|
+
return wrapper;
|
4396
|
+
|
4397
|
+
})));
|
4398
|
+
//# sourceMappingURL=vega-embed.js.map
|