vega-interpreter 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/vega-interpreter.js +298 -288
- package/build/vega-interpreter.js.map +1 -0
- package/index.js +1 -1
- package/package.json +14 -9
- package/rollup.config.js +1 -0
- package/src/expression.js +2 -2
- package/src/functions.js +10 -3
- package/src/interpret.js +4 -4
- package/build/vega-interpreter.min.js +0 -2
- package/build/vega-interpreter.min.js.map +0 -1
- package/build/vega-interpreter.module.js +0 -301
- package/rollup.config.mjs +0 -1
|
@@ -1,305 +1,315 @@
|
|
|
1
|
-
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-util')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'vega-util'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vega = global.vega || {}, global.vega));
|
|
5
|
-
})(this, (function (exports, vegaUtil) { 'use strict';
|
|
1
|
+
import { ascending, isString } from 'vega-util';
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
item.width = item.x2 - item.x;
|
|
17
|
-
} else {
|
|
18
|
-
item.x = item.x2 - (item.width || 0);
|
|
3
|
+
function adjustSpatial (item, encode, swap) {
|
|
4
|
+
let t;
|
|
5
|
+
if (encode.x2) {
|
|
6
|
+
if (encode.x) {
|
|
7
|
+
if (swap && item.x > item.x2) {
|
|
8
|
+
t = item.x;
|
|
9
|
+
item.x = item.x2;
|
|
10
|
+
item.x2 = t;
|
|
19
11
|
}
|
|
12
|
+
item.width = item.x2 - item.x;
|
|
13
|
+
} else {
|
|
14
|
+
item.x = item.x2 - (item.width || 0);
|
|
20
15
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
item.height = item.y2 - item.y;
|
|
32
|
-
} else {
|
|
33
|
-
item.y = item.y2 - (item.height || 0);
|
|
16
|
+
}
|
|
17
|
+
if (encode.xc) {
|
|
18
|
+
item.x = item.xc - (item.width || 0) / 2;
|
|
19
|
+
}
|
|
20
|
+
if (encode.y2) {
|
|
21
|
+
if (encode.y) {
|
|
22
|
+
if (swap && item.y > item.y2) {
|
|
23
|
+
t = item.y;
|
|
24
|
+
item.y = item.y2;
|
|
25
|
+
item.y2 = t;
|
|
34
26
|
}
|
|
27
|
+
item.height = item.y2 - item.y;
|
|
28
|
+
} else {
|
|
29
|
+
item.y = item.y2 - (item.height || 0);
|
|
35
30
|
}
|
|
36
|
-
if (encode.yc) {
|
|
37
|
-
item.y = item.yc - (item.height || 0) / 2;
|
|
38
|
-
}
|
|
39
31
|
}
|
|
32
|
+
if (encode.yc) {
|
|
33
|
+
item.y = item.yc - (item.height || 0) / 2;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
var Constants = {
|
|
38
|
+
NaN: NaN,
|
|
39
|
+
E: Math.E,
|
|
40
|
+
LN2: Math.LN2,
|
|
41
|
+
LN10: Math.LN10,
|
|
42
|
+
LOG2E: Math.LOG2E,
|
|
43
|
+
LOG10E: Math.LOG10E,
|
|
44
|
+
PI: Math.PI,
|
|
45
|
+
SQRT1_2: Math.SQRT1_2,
|
|
46
|
+
SQRT2: Math.SQRT2,
|
|
47
|
+
MIN_VALUE: Number.MIN_VALUE,
|
|
48
|
+
MAX_VALUE: Number.MAX_VALUE
|
|
49
|
+
};
|
|
54
50
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
51
|
+
var Ops = {
|
|
52
|
+
'*': (a, b) => a * b,
|
|
53
|
+
'+': (a, b) => a + b,
|
|
54
|
+
'-': (a, b) => a - b,
|
|
55
|
+
'/': (a, b) => a / b,
|
|
56
|
+
'%': (a, b) => a % b,
|
|
57
|
+
'>': (a, b) => a > b,
|
|
58
|
+
'<': (a, b) => a < b,
|
|
59
|
+
'<=': (a, b) => a <= b,
|
|
60
|
+
'>=': (a, b) => a >= b,
|
|
61
|
+
'==': (a, b) => a == b,
|
|
62
|
+
'!=': (a, b) => a != b,
|
|
63
|
+
'===': (a, b) => a === b,
|
|
64
|
+
'!==': (a, b) => a !== b,
|
|
65
|
+
'&': (a, b) => a & b,
|
|
66
|
+
'|': (a, b) => a | b,
|
|
67
|
+
'^': (a, b) => a ^ b,
|
|
68
|
+
'<<': (a, b) => a << b,
|
|
69
|
+
'>>': (a, b) => a >> b,
|
|
70
|
+
'>>>': (a, b) => a >>> b
|
|
71
|
+
};
|
|
76
72
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
var Unary = {
|
|
74
|
+
'+': a => +a,
|
|
75
|
+
'-': a => -a,
|
|
76
|
+
'~': a => ~a,
|
|
77
|
+
'!': a => !a
|
|
78
|
+
};
|
|
83
79
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
80
|
+
const slice = Array.prototype.slice;
|
|
81
|
+
const apply = (m, args, cast) => {
|
|
82
|
+
const obj = cast ? cast(args[0]) : args[0];
|
|
83
|
+
return obj[m].apply(obj, slice.call(args, 1));
|
|
84
|
+
};
|
|
85
|
+
const datetime = function (yearOrTimestring) {
|
|
86
|
+
let m = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
87
|
+
let d = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
88
|
+
let H = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
89
|
+
let M = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
90
|
+
let S = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
91
|
+
let ms = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;
|
|
92
|
+
return isString(yearOrTimestring) ? new Date(yearOrTimestring) : new Date(yearOrTimestring, m, d, H, M, S, ms);
|
|
93
|
+
};
|
|
94
|
+
var Functions = {
|
|
95
|
+
// math functions
|
|
96
|
+
isNaN: Number.isNaN,
|
|
97
|
+
isFinite: Number.isFinite,
|
|
98
|
+
abs: Math.abs,
|
|
99
|
+
acos: Math.acos,
|
|
100
|
+
asin: Math.asin,
|
|
101
|
+
atan: Math.atan,
|
|
102
|
+
atan2: Math.atan2,
|
|
103
|
+
ceil: Math.ceil,
|
|
104
|
+
cos: Math.cos,
|
|
105
|
+
exp: Math.exp,
|
|
106
|
+
floor: Math.floor,
|
|
107
|
+
log: Math.log,
|
|
108
|
+
max: Math.max,
|
|
109
|
+
min: Math.min,
|
|
110
|
+
pow: Math.pow,
|
|
111
|
+
random: Math.random,
|
|
112
|
+
round: Math.round,
|
|
113
|
+
sin: Math.sin,
|
|
114
|
+
sqrt: Math.sqrt,
|
|
115
|
+
tan: Math.tan,
|
|
116
|
+
clamp: (a, b, c) => Math.max(b, Math.min(c, a)),
|
|
117
|
+
// date functions
|
|
118
|
+
now: Date.now,
|
|
119
|
+
utc: Date.UTC,
|
|
120
|
+
datetime: datetime,
|
|
121
|
+
date: d => new Date(d).getDate(),
|
|
122
|
+
day: d => new Date(d).getDay(),
|
|
123
|
+
year: d => new Date(d).getFullYear(),
|
|
124
|
+
month: d => new Date(d).getMonth(),
|
|
125
|
+
hours: d => new Date(d).getHours(),
|
|
126
|
+
minutes: d => new Date(d).getMinutes(),
|
|
127
|
+
seconds: d => new Date(d).getSeconds(),
|
|
128
|
+
milliseconds: d => new Date(d).getMilliseconds(),
|
|
129
|
+
time: d => new Date(d).getTime(),
|
|
130
|
+
timezoneoffset: d => new Date(d).getTimezoneOffset(),
|
|
131
|
+
utcdate: d => new Date(d).getUTCDate(),
|
|
132
|
+
utcday: d => new Date(d).getUTCDay(),
|
|
133
|
+
utcyear: d => new Date(d).getUTCFullYear(),
|
|
134
|
+
utcmonth: d => new Date(d).getUTCMonth(),
|
|
135
|
+
utchours: d => new Date(d).getUTCHours(),
|
|
136
|
+
utcminutes: d => new Date(d).getUTCMinutes(),
|
|
137
|
+
utcseconds: d => new Date(d).getUTCSeconds(),
|
|
138
|
+
utcmilliseconds: d => new Date(d).getUTCMilliseconds(),
|
|
139
|
+
// sequence functions
|
|
140
|
+
length: x => x.length,
|
|
141
|
+
join: function () {
|
|
142
|
+
return apply('join', arguments);
|
|
143
|
+
},
|
|
144
|
+
indexof: function () {
|
|
145
|
+
return apply('indexOf', arguments);
|
|
146
|
+
},
|
|
147
|
+
lastindexof: function () {
|
|
148
|
+
return apply('lastIndexOf', arguments);
|
|
149
|
+
},
|
|
150
|
+
slice: function () {
|
|
151
|
+
return apply('slice', arguments);
|
|
152
|
+
},
|
|
153
|
+
reverse: x => x.slice().reverse(),
|
|
154
|
+
sort: x => x.slice().sort(ascending),
|
|
155
|
+
// string functions
|
|
156
|
+
parseFloat: parseFloat,
|
|
157
|
+
parseInt: parseInt,
|
|
158
|
+
upper: x => String(x).toUpperCase(),
|
|
159
|
+
lower: x => String(x).toLowerCase(),
|
|
160
|
+
substring: function () {
|
|
161
|
+
return apply('substring', arguments, String);
|
|
162
|
+
},
|
|
163
|
+
split: function () {
|
|
164
|
+
return apply('split', arguments, String);
|
|
165
|
+
},
|
|
166
|
+
replace: function () {
|
|
167
|
+
return apply('replace', arguments, String);
|
|
168
|
+
},
|
|
169
|
+
trim: x => String(x).trim(),
|
|
170
|
+
// Base64 encode/decode
|
|
171
|
+
// Convert binary string to base64-encoded ascii
|
|
172
|
+
btoa: x => btoa(x),
|
|
173
|
+
// Convert base64-encoded ascii to binary string
|
|
174
|
+
atob: x => atob(x),
|
|
175
|
+
// regexp functions
|
|
176
|
+
regexp: RegExp,
|
|
177
|
+
test: (r, t) => RegExp(r).test(t)
|
|
178
|
+
};
|
|
170
179
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
180
|
+
const EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];
|
|
181
|
+
const DisallowedMethods = new Set([Function, eval, setTimeout, setInterval]);
|
|
182
|
+
if (typeof setImmediate === 'function') DisallowedMethods.add(setImmediate);
|
|
183
|
+
const Visitors = {
|
|
184
|
+
Literal: ($, n) => n.value,
|
|
185
|
+
Identifier: ($, n) => {
|
|
186
|
+
const id = n.name;
|
|
187
|
+
return $.memberDepth > 0 ? id : id === 'datum' ? $.datum : id === 'event' ? $.event : id === 'item' ? $.item : Constants[id] || $.params['$' + id];
|
|
188
|
+
},
|
|
189
|
+
MemberExpression: ($, n) => {
|
|
190
|
+
const d = !n.computed,
|
|
191
|
+
o = $(n.object);
|
|
192
|
+
if (d) $.memberDepth += 1;
|
|
193
|
+
const p = $(n.property);
|
|
194
|
+
if (d) $.memberDepth -= 1;
|
|
195
|
+
if (DisallowedMethods.has(o[p])) {
|
|
196
|
+
// eslint-disable-next-line no-console
|
|
197
|
+
console.error(`Prevented interpretation of member "${p}" which could lead to insecure code execution`);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
return o[p];
|
|
201
|
+
},
|
|
202
|
+
CallExpression: ($, n) => {
|
|
203
|
+
const args = n.arguments;
|
|
204
|
+
let name = n.callee.name;
|
|
196
205
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
206
|
+
// handle special internal functions used by encoders
|
|
207
|
+
// re-route to corresponding standard function
|
|
208
|
+
if (name.startsWith('_')) {
|
|
209
|
+
name = name.slice(1);
|
|
210
|
+
}
|
|
202
211
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
212
|
+
// special case "if" due to conditional evaluation of branches
|
|
213
|
+
return name === 'if' ? $(args[0]) ? $(args[1]) : $(args[2]) : ($.fn[name] || Functions[name]).apply($.fn, args.map($));
|
|
214
|
+
},
|
|
215
|
+
ArrayExpression: ($, n) => n.elements.map($),
|
|
216
|
+
BinaryExpression: ($, n) => Ops[n.operator]($(n.left), $(n.right)),
|
|
217
|
+
UnaryExpression: ($, n) => Unary[n.operator]($(n.argument)),
|
|
218
|
+
ConditionalExpression: ($, n) => $(n.test) ? $(n.consequent) : $(n.alternate),
|
|
219
|
+
LogicalExpression: ($, n) => n.operator === '&&' ? $(n.left) && $(n.right) : $(n.left) || $(n.right),
|
|
220
|
+
ObjectExpression: ($, n) => n.properties.reduce((o, p) => {
|
|
221
|
+
$.memberDepth += 1;
|
|
222
|
+
const k = $(p.key);
|
|
223
|
+
$.memberDepth -= 1;
|
|
224
|
+
if (DisallowedMethods.has($(p.value))) {
|
|
225
|
+
// eslint-disable-next-line no-console
|
|
226
|
+
console.error(`Prevented interpretation of property "${k}" which could lead to insecure code execution`);
|
|
227
|
+
} else {
|
|
228
|
+
o[k] = $(p.value);
|
|
229
|
+
}
|
|
230
|
+
return o;
|
|
231
|
+
}, {})
|
|
232
|
+
};
|
|
233
|
+
function interpret (ast, fn, params, datum, event, item) {
|
|
234
|
+
const $ = n => Visitors[n.type]($, n);
|
|
235
|
+
$.memberDepth = 0;
|
|
236
|
+
$.fn = Object.create(fn);
|
|
237
|
+
$.params = params;
|
|
238
|
+
$.datum = datum;
|
|
239
|
+
$.event = event;
|
|
240
|
+
$.item = item;
|
|
232
241
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return
|
|
236
|
-
}
|
|
242
|
+
// route event functions to annotated vega event context
|
|
243
|
+
EventFunctions.forEach(f => $.fn[f] = function () {
|
|
244
|
+
return event.vega[f](...arguments);
|
|
245
|
+
});
|
|
246
|
+
return $(ast);
|
|
247
|
+
}
|
|
237
248
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (marktype !== 'rule') {
|
|
296
|
-
adjustSpatial(item, channels, swap);
|
|
249
|
+
var expression = {
|
|
250
|
+
/**
|
|
251
|
+
* Parse an expression used to update an operator value.
|
|
252
|
+
*/
|
|
253
|
+
operator(ctx, expr) {
|
|
254
|
+
const ast = expr.ast,
|
|
255
|
+
fn = ctx.functions;
|
|
256
|
+
return _ => interpret(ast, fn, _);
|
|
257
|
+
},
|
|
258
|
+
/**
|
|
259
|
+
* Parse an expression provided as an operator parameter value.
|
|
260
|
+
*/
|
|
261
|
+
parameter(ctx, expr) {
|
|
262
|
+
const ast = expr.ast,
|
|
263
|
+
fn = ctx.functions;
|
|
264
|
+
return (datum, _) => interpret(ast, fn, _, datum);
|
|
265
|
+
},
|
|
266
|
+
/**
|
|
267
|
+
* Parse an expression applied to an event stream.
|
|
268
|
+
*/
|
|
269
|
+
event(ctx, expr) {
|
|
270
|
+
const ast = expr.ast,
|
|
271
|
+
fn = ctx.functions;
|
|
272
|
+
return event => interpret(ast, fn, undefined, undefined, event);
|
|
273
|
+
},
|
|
274
|
+
/**
|
|
275
|
+
* Parse an expression used to handle an event-driven operator update.
|
|
276
|
+
*/
|
|
277
|
+
handler(ctx, expr) {
|
|
278
|
+
const ast = expr.ast,
|
|
279
|
+
fn = ctx.functions;
|
|
280
|
+
return (_, event) => {
|
|
281
|
+
const datum = event.item && event.item.datum;
|
|
282
|
+
return interpret(ast, fn, _, datum, event);
|
|
283
|
+
};
|
|
284
|
+
},
|
|
285
|
+
/**
|
|
286
|
+
* Parse an expression that performs visual encoding.
|
|
287
|
+
*/
|
|
288
|
+
encode(ctx, encode) {
|
|
289
|
+
const {
|
|
290
|
+
marktype,
|
|
291
|
+
channels
|
|
292
|
+
} = encode,
|
|
293
|
+
fn = ctx.functions,
|
|
294
|
+
swap = marktype === 'group' || marktype === 'image' || marktype === 'rect';
|
|
295
|
+
return (item, _) => {
|
|
296
|
+
const datum = item.datum;
|
|
297
|
+
let m = 0,
|
|
298
|
+
v;
|
|
299
|
+
for (const name in channels) {
|
|
300
|
+
v = interpret(channels[name].ast, fn, _, datum, undefined, item);
|
|
301
|
+
if (item[name] !== v) {
|
|
302
|
+
item[name] = v;
|
|
303
|
+
m = 1;
|
|
297
304
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
305
|
+
}
|
|
306
|
+
if (marktype !== 'rule') {
|
|
307
|
+
adjustSpatial(item, channels, swap);
|
|
308
|
+
}
|
|
309
|
+
return m;
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
};
|
|
304
313
|
|
|
305
|
-
}
|
|
314
|
+
export { expression as expressionInterpreter };
|
|
315
|
+
//# sourceMappingURL=vega-interpreter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vega-interpreter.js","sources":["../src/adjust-spatial.js","../src/constants.js","../src/ops-binary.js","../src/ops-unary.js","../src/functions.js","../src/interpret.js","../src/expression.js"],"sourcesContent":["export default function(item, encode, swap) {\n let t;\n\n if (encode.x2) {\n if (encode.x) {\n if (swap && item.x > item.x2) {\n t = item.x;\n item.x = item.x2;\n item.x2 = t;\n }\n item.width = item.x2 - item.x;\n } else {\n item.x = item.x2 - (item.width || 0);\n }\n }\n\n if (encode.xc) {\n item.x = item.xc - (item.width || 0) / 2;\n }\n\n if (encode.y2) {\n if (encode.y) {\n if (swap && item.y > item.y2) {\n t = item.y;\n item.y = item.y2;\n item.y2 = t;\n }\n item.height = item.y2 - item.y;\n } else {\n item.y = item.y2 - (item.height || 0);\n }\n }\n\n if (encode.yc) {\n item.y = item.yc - (item.height || 0) / 2;\n }\n}\n","export default {\n NaN: NaN,\n E: Math.E,\n LN2: Math.LN2,\n LN10: Math.LN10,\n LOG2E: Math.LOG2E,\n LOG10E: Math.LOG10E,\n PI: Math.PI,\n SQRT1_2: Math.SQRT1_2,\n SQRT2: Math.SQRT2,\n MIN_VALUE: Number.MIN_VALUE,\n MAX_VALUE: Number.MAX_VALUE\n};\n","export default {\n '*': (a, b) => a * b,\n '+': (a, b) => a + b,\n '-': (a, b) => a - b,\n '/': (a, b) => a / b,\n '%': (a, b) => a % b,\n '>': (a, b) => a > b,\n '<': (a, b) => a < b,\n '<=': (a, b) => a <= b,\n '>=': (a, b) => a >= b,\n '==': (a, b) => a == b,\n '!=': (a, b) => a != b,\n '===': (a, b) => a === b,\n '!==': (a, b) => a !== b,\n '&': (a, b) => a & b,\n '|': (a, b) => a | b,\n '^': (a, b) => a ^ b,\n '<<': (a, b) => a << b,\n '>>': (a, b) => a >> b,\n '>>>': (a, b) => a >>> b\n};\n","export default {\n '+': a => +a,\n '-': a => -a,\n '~': a => ~a,\n '!': a => !a\n};\n","import { ascending, isString } from 'vega-util';\n\nconst slice = Array.prototype.slice;\n\nconst apply = (m, args, cast) => {\n const obj = cast ? cast(args[0]) : args[0];\n return obj[m].apply(obj, slice.call(args, 1));\n};\n\nconst datetime = (yearOrTimestring, m = 0, d = 1, H = 0, M = 0, S = 0, ms = 0) =>\n isString(yearOrTimestring)\n ? new Date(yearOrTimestring)\n : new Date(yearOrTimestring, m, d, H, M, S, ms);\n\nexport default {\n // math functions\n isNaN: Number.isNaN,\n isFinite: Number.isFinite,\n abs: Math.abs,\n acos: Math.acos,\n asin: Math.asin,\n atan: Math.atan,\n atan2: Math.atan2,\n ceil: Math.ceil,\n cos: Math.cos,\n exp: Math.exp,\n floor: Math.floor,\n log: Math.log,\n max: Math.max,\n min: Math.min,\n pow: Math.pow,\n random: Math.random,\n round: Math.round,\n sin: Math.sin,\n sqrt: Math.sqrt,\n tan: Math.tan,\n clamp: (a, b, c) => Math.max(b, Math.min(c, a)),\n\n // date functions\n now: Date.now,\n utc: Date.UTC,\n datetime: datetime,\n date: d => new Date(d).getDate(),\n day: d => new Date(d).getDay(),\n year: d => new Date(d).getFullYear(),\n month: d => new Date(d).getMonth(),\n hours: d => new Date(d).getHours(),\n minutes: d => new Date(d).getMinutes(),\n seconds: d => new Date(d).getSeconds(),\n milliseconds: d => new Date(d).getMilliseconds(),\n time: d => new Date(d).getTime(),\n timezoneoffset: d => new Date(d).getTimezoneOffset(),\n utcdate: d => new Date(d).getUTCDate(),\n utcday: d => new Date(d).getUTCDay(),\n utcyear: d => new Date(d).getUTCFullYear(),\n utcmonth: d => new Date(d).getUTCMonth(),\n utchours: d => new Date(d).getUTCHours(),\n utcminutes: d => new Date(d).getUTCMinutes(),\n utcseconds: d => new Date(d).getUTCSeconds(),\n utcmilliseconds: d => new Date(d).getUTCMilliseconds(),\n\n // sequence functions\n length: x => x.length,\n join: function() { return apply('join', arguments); },\n indexof: function() { return apply('indexOf', arguments); },\n lastindexof: function() { return apply('lastIndexOf', arguments); },\n slice: function() { return apply('slice', arguments); },\n reverse: x => x.slice().reverse(),\n sort: x => x.slice().sort(ascending),\n\n // string functions\n parseFloat: parseFloat,\n parseInt: parseInt,\n upper: x => String(x).toUpperCase(),\n lower: x => String(x).toLowerCase(),\n substring: function() { return apply('substring', arguments, String); },\n split: function() { return apply('split', arguments, String); },\n replace: function() { return apply('replace', arguments, String); },\n trim: x => String(x).trim(),\n // Base64 encode/decode\n // Convert binary string to base64-encoded ascii\n btoa: x => btoa(x),\n // Convert base64-encoded ascii to binary string\n atob: x => atob(x),\n\n // regexp functions\n regexp: RegExp,\n test: (r, t) => RegExp(r).test(t)\n};\n","import Constants from './constants.js';\nimport Ops from './ops-binary.js';\nimport Unary from './ops-unary.js';\nimport Functions from './functions.js';\n\nconst EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];\nconst DisallowedMethods = new Set([\n Function,\n eval,\n setTimeout,\n setInterval\n]);\n\nif (typeof setImmediate === 'function') DisallowedMethods.add(setImmediate);\n\nconst Visitors = {\n Literal: ($, n) => n.value,\n\n Identifier: ($, n) => {\n const id = n.name;\n return $.memberDepth > 0 ? id\n : id === 'datum' ? $.datum\n : id === 'event' ? $.event\n : id === 'item' ? $.item\n : Constants[id] || $.params['$' + id];\n },\n\n MemberExpression: ($, n) => {\n const d = !n.computed,\n o = $(n.object);\n if (d) $.memberDepth += 1;\n const p = $(n.property);\n if (d) $.memberDepth -= 1;\n if (DisallowedMethods.has(o[p])) {\n // eslint-disable-next-line no-console\n console.error(`Prevented interpretation of member \"${p}\" which could lead to insecure code execution`);\n return;\n }\n return o[p];\n },\n\n CallExpression: ($, n) => {\n const args = n.arguments;\n let name = n.callee.name;\n\n // handle special internal functions used by encoders\n // re-route to corresponding standard function\n if (name.startsWith('_')) {\n name = name.slice(1);\n }\n\n // special case \"if\" due to conditional evaluation of branches\n return name === 'if'\n ? ($(args[0]) ? $(args[1]) : $(args[2]))\n : ($.fn[name] || Functions[name]).apply($.fn, args.map($));\n },\n\n ArrayExpression: ($, n) => n.elements.map($),\n\n BinaryExpression: ($, n) => Ops[n.operator]($(n.left), $(n.right)),\n\n UnaryExpression: ($, n) => Unary[n.operator]($(n.argument)),\n\n ConditionalExpression: ($, n) => $(n.test)\n ? $(n.consequent)\n : $(n.alternate),\n\n LogicalExpression: ($, n) => n.operator === '&&'\n ? $(n.left) && $(n.right)\n : $(n.left) || $(n.right),\n\n ObjectExpression: ($, n) => n.properties.reduce((o, p) => {\n $.memberDepth += 1;\n const k = $(p.key);\n $.memberDepth -= 1;\n if (DisallowedMethods.has($(p.value))) {\n // eslint-disable-next-line no-console\n console.error(`Prevented interpretation of property \"${k}\" which could lead to insecure code execution`);\n } else {\n o[k] = $(p.value);\n }\n return o;\n }, {})\n};\n\nexport default function(ast, fn, params, datum, event, item) {\n const $ = n => Visitors[n.type]($, n);\n $.memberDepth = 0;\n $.fn = Object.create(fn);\n $.params = params;\n $.datum = datum;\n $.event = event;\n $.item = item;\n\n // route event functions to annotated vega event context\n EventFunctions.forEach(f => $.fn[f] = (...args) => event.vega[f](...args));\n\n return $(ast);\n}\n","import adjustSpatial from './adjust-spatial.js';\nimport interpret from './interpret.js';\n\nexport default {\n /**\n * Parse an expression used to update an operator value.\n */\n operator(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return _ => interpret(ast, fn, _);\n },\n\n /**\n * Parse an expression provided as an operator parameter value.\n */\n parameter(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return (datum, _) => interpret(ast, fn, _, datum);\n },\n\n /**\n * Parse an expression applied to an event stream.\n */\n event(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return event => interpret(ast, fn, undefined, undefined, event);\n },\n\n /**\n * Parse an expression used to handle an event-driven operator update.\n */\n handler(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return (_, event) => {\n const datum = event.item && event.item.datum;\n return interpret(ast, fn, _, datum, event);\n };\n },\n\n /**\n * Parse an expression that performs visual encoding.\n */\n encode(ctx, encode) {\n const {marktype, channels} = encode,\n fn = ctx.functions,\n swap = marktype === 'group'\n || marktype === 'image'\n || marktype === 'rect';\n\n return (item, _) => {\n const datum = item.datum;\n let m = 0, v;\n\n for (const name in channels) {\n v = interpret(channels[name].ast, fn, _, datum, undefined, item);\n if (item[name] !== v) {\n item[name] = v;\n m = 1;\n }\n }\n\n if (marktype !== 'rule') {\n adjustSpatial(item, channels, swap);\n }\n return m;\n };\n }\n};\n"],"names":["item","encode","swap","t","x2","x","width","xc","y2","y","height","yc","NaN","E","Math","LN2","LN10","LOG2E","LOG10E","PI","SQRT1_2","SQRT2","MIN_VALUE","Number","MAX_VALUE","*","a","b","+","-","/","%",">","<","<=",">=","==","!=","===","!==","&","|","^","<<",">>",">>>","slice","Array","prototype","apply","m","args","cast","obj","call","datetime","yearOrTimestring","arguments","length","undefined","d","H","M","S","ms","isString","Date","isNaN","isFinite","abs","acos","asin","atan","atan2","ceil","cos","exp","floor","log","max","min","pow","random","round","sin","sqrt","tan","clamp","c","now","utc","UTC","date","getDate","day","getDay","year","getFullYear","month","getMonth","hours","getHours","minutes","getMinutes","seconds","getSeconds","milliseconds","getMilliseconds","time","getTime","timezoneoffset","getTimezoneOffset","utcdate","getUTCDate","utcday","getUTCDay","utcyear","getUTCFullYear","utcmonth","getUTCMonth","utchours","getUTCHours","utcminutes","getUTCMinutes","utcseconds","getUTCSeconds","utcmilliseconds","getUTCMilliseconds","join","indexof","lastindexof","reverse","sort","ascending","parseFloat","parseInt","upper","String","toUpperCase","lower","toLowerCase","substring","split","replace","trim","btoa","atob","regexp","RegExp","test","r","EventFunctions","DisallowedMethods","Set","Function","eval","setTimeout","setInterval","setImmediate","add","Visitors","Literal","$","n","value","Identifier","id","name","memberDepth","datum","event","Constants","params","MemberExpression","computed","o","object","p","property","has","console","error","CallExpression","callee","startsWith","fn","Functions","map","ArrayExpression","elements","BinaryExpression","Ops","operator","left","right","UnaryExpression","Unary","argument","ConditionalExpression","consequent","alternate","LogicalExpression","ObjectExpression","properties","reduce","k","key","ast","type","Object","create","forEach","f","vega","ctx","expr","functions","_","interpret","parameter","handler","marktype","channels","v","adjustSpatial"],"mappings":";;AAAe,wBAASA,IAAI,EAAEC,MAAM,EAAEC,IAAI,EAAE;AAC1C,EAAA,IAAIC,CAAC;EAEL,IAAIF,MAAM,CAACG,EAAE,EAAE;IACb,IAAIH,MAAM,CAACI,CAAC,EAAE;MACZ,IAAIH,IAAI,IAAIF,IAAI,CAACK,CAAC,GAAGL,IAAI,CAACI,EAAE,EAAE;QAC5BD,CAAC,GAAGH,IAAI,CAACK,CAAC;AACVL,QAAAA,IAAI,CAACK,CAAC,GAAGL,IAAI,CAACI,EAAE;QAChBJ,IAAI,CAACI,EAAE,GAAGD,CAAC;AACb;MACAH,IAAI,CAACM,KAAK,GAAGN,IAAI,CAACI,EAAE,GAAGJ,IAAI,CAACK,CAAC;AAC/B,KAAC,MAAM;AACLL,MAAAA,IAAI,CAACK,CAAC,GAAGL,IAAI,CAACI,EAAE,IAAIJ,IAAI,CAACM,KAAK,IAAI,CAAC,CAAC;AACtC;AACF;EAEA,IAAIL,MAAM,CAACM,EAAE,EAAE;AACbP,IAAAA,IAAI,CAACK,CAAC,GAAGL,IAAI,CAACO,EAAE,GAAG,CAACP,IAAI,CAACM,KA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CAAC,CAACwC,GAAG,EAAEtB,EAAE,EAAEgC,CAAC,EAAEhD,KAAK,EAAE9G,SAAS,EAAE3D,IAAI,CAAC;AAChE,QAAA,IAAIA,IAAI,CAACuK,IAAI,CAAC,KAAKwD,CAAC,EAAE;AACpB/N,UAAAA,IAAI,CAACuK,IAAI,CAAC,GAAGwD,CAAC;AACd7K,UAAAA,CAAC,GAAG,CAAC;AACP;AACF;MAEA,IAAI2K,QAAQ,KAAK,MAAM,EAAE;AACvBG,QAAAA,aAAa,CAAChO,IAAI,EAAE8N,QAAQ,EAAE5N,IAAI,CAAC;AACrC;AACA,MAAA,OAAOgD,CAAC;KACT;AACH;AACF,CAAC;;;;"}
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {default as expressionInterpreter} from './src/expression';
|
|
1
|
+
export {default as expressionInterpreter} from './src/expression.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vega-interpreter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "CSP-compliant interpreter for Vega expressions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vega",
|
|
@@ -9,24 +9,29 @@
|
|
|
9
9
|
"runtime"
|
|
10
10
|
],
|
|
11
11
|
"license": "BSD-3-Clause",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
"type": "module",
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "Vega",
|
|
15
|
+
"url": "https://vega.github.io"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
"types": "./index.d.ts",
|
|
19
|
+
"default": "./build/vega-interpreter.js"
|
|
20
|
+
},
|
|
16
21
|
"types": "index.d.ts",
|
|
17
22
|
"repository": "vega/vega",
|
|
18
23
|
"scripts": {
|
|
19
|
-
"prebuild": "
|
|
20
|
-
"build": "rollup -c rollup.config.
|
|
24
|
+
"prebuild": "del-cli build",
|
|
25
|
+
"build": "rollup -c rollup.config.js --extend",
|
|
21
26
|
"pretest": "yarn build --config-test",
|
|
22
27
|
"test": "TZ=America/Los_Angeles tape 'test/**/*-test.js'",
|
|
23
28
|
"prepublishOnly": "yarn test && yarn build"
|
|
24
29
|
},
|
|
25
30
|
"dependencies": {
|
|
26
|
-
"vega-util": "^
|
|
31
|
+
"vega-util": "^2.0.0"
|
|
27
32
|
},
|
|
28
33
|
"devDependencies": {
|
|
29
34
|
"vega": "*"
|
|
30
35
|
},
|
|
31
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "45ce7657f6212c448be409887018b693a8103fd4"
|
|
32
37
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../../rollup.config.js';
|
package/src/expression.js
CHANGED
package/src/functions.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ascending } from 'vega-util';
|
|
1
|
+
import { ascending, isString } from 'vega-util';
|
|
2
2
|
|
|
3
3
|
const slice = Array.prototype.slice;
|
|
4
4
|
|
|
@@ -7,8 +7,10 @@ const apply = (m, args, cast) => {
|
|
|
7
7
|
return obj[m].apply(obj, slice.call(args, 1));
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
const datetime = (
|
|
11
|
-
|
|
10
|
+
const datetime = (yearOrTimestring, m = 0, d = 1, H = 0, M = 0, S = 0, ms = 0) =>
|
|
11
|
+
isString(yearOrTimestring)
|
|
12
|
+
? new Date(yearOrTimestring)
|
|
13
|
+
: new Date(yearOrTimestring, m, d, H, M, S, ms);
|
|
12
14
|
|
|
13
15
|
export default {
|
|
14
16
|
// math functions
|
|
@@ -75,6 +77,11 @@ export default {
|
|
|
75
77
|
split: function() { return apply('split', arguments, String); },
|
|
76
78
|
replace: function() { return apply('replace', arguments, String); },
|
|
77
79
|
trim: x => String(x).trim(),
|
|
80
|
+
// Base64 encode/decode
|
|
81
|
+
// Convert binary string to base64-encoded ascii
|
|
82
|
+
btoa: x => btoa(x),
|
|
83
|
+
// Convert base64-encoded ascii to binary string
|
|
84
|
+
atob: x => atob(x),
|
|
78
85
|
|
|
79
86
|
// regexp functions
|
|
80
87
|
regexp: RegExp,
|
package/src/interpret.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import Constants from './constants';
|
|
2
|
-
import Ops from './ops-binary';
|
|
3
|
-
import Unary from './ops-unary';
|
|
4
|
-
import Functions from './functions';
|
|
1
|
+
import Constants from './constants.js';
|
|
2
|
+
import Ops from './ops-binary.js';
|
|
3
|
+
import Unary from './ops-unary.js';
|
|
4
|
+
import Functions from './functions.js';
|
|
5
5
|
|
|
6
6
|
const EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];
|
|
7
7
|
const DisallowedMethods = new Set([
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-util")):"function"==typeof define&&define.amd?define(["exports","vega-util"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).vega=e.vega||{},e.vega)}(this,(function(e,t){"use strict";var n={NaN:NaN,E:Math.E,LN2:Math.LN2,LN10:Math.LN10,LOG2E:Math.LOG2E,LOG10E:Math.LOG10E,PI:Math.PI,SQRT1_2:Math.SQRT1_2,SQRT2:Math.SQRT2,MIN_VALUE:Number.MIN_VALUE,MAX_VALUE:Number.MAX_VALUE},r={"*":(e,t)=>e*t,"+":(e,t)=>e+t,"-":(e,t)=>e-t,"/":(e,t)=>e/t,"%":(e,t)=>e%t,">":(e,t)=>e>t,"<":(e,t)=>e<t,"<=":(e,t)=>e<=t,">=":(e,t)=>e>=t,"==":(e,t)=>e==t,"!=":(e,t)=>e!=t,"===":(e,t)=>e===t,"!==":(e,t)=>e!==t,"&":(e,t)=>e&t,"|":(e,t)=>e|t,"^":(e,t)=>e^t,"<<":(e,t)=>e<<t,">>":(e,t)=>e>>t,">>>":(e,t)=>e>>>t},a={"+":e=>+e,"-":e=>-e,"~":e=>~e,"!":e=>!e};const o=Array.prototype.slice,i=(e,t,n)=>{const r=n?n(t[0]):t[0];return r[e].apply(r,o.call(t,1))};var s={isNaN:Number.isNaN,isFinite:Number.isFinite,abs:Math.abs,acos:Math.acos,asin:Math.asin,atan:Math.atan,atan2:Math.atan2,ceil:Math.ceil,cos:Math.cos,exp:Math.exp,floor:Math.floor,log:Math.log,max:Math.max,min:Math.min,pow:Math.pow,random:Math.random,round:Math.round,sin:Math.sin,sqrt:Math.sqrt,tan:Math.tan,clamp:(e,t,n)=>Math.max(t,Math.min(n,e)),now:Date.now,utc:Date.UTC,datetime:(e,t,n,r,a,o,i)=>new Date(e,t||0,null!=n?n:1,r||0,a||0,o||0,i||0),date:e=>new Date(e).getDate(),day:e=>new Date(e).getDay(),year:e=>new Date(e).getFullYear(),month:e=>new Date(e).getMonth(),hours:e=>new Date(e).getHours(),minutes:e=>new Date(e).getMinutes(),seconds:e=>new Date(e).getSeconds(),milliseconds:e=>new Date(e).getMilliseconds(),time:e=>new Date(e).getTime(),timezoneoffset:e=>new Date(e).getTimezoneOffset(),utcdate:e=>new Date(e).getUTCDate(),utcday:e=>new Date(e).getUTCDay(),utcyear:e=>new Date(e).getUTCFullYear(),utcmonth:e=>new Date(e).getUTCMonth(),utchours:e=>new Date(e).getUTCHours(),utcminutes:e=>new Date(e).getUTCMinutes(),utcseconds:e=>new Date(e).getUTCSeconds(),utcmilliseconds:e=>new Date(e).getUTCMilliseconds(),length:e=>e.length,join:function(){return i("join",arguments)},indexof:function(){return i("indexOf",arguments)},lastindexof:function(){return i("lastIndexOf",arguments)},slice:function(){return i("slice",arguments)},reverse:e=>e.slice().reverse(),sort:e=>e.slice().sort(t.ascending),parseFloat:parseFloat,parseInt:parseInt,upper:e=>String(e).toUpperCase(),lower:e=>String(e).toLowerCase(),substring:function(){return i("substring",arguments,String)},split:function(){return i("split",arguments,String)},replace:function(){return i("replace",arguments,String)},trim:e=>String(e).trim(),regexp:RegExp,test:(e,t)=>RegExp(e).test(t)};const c=["view","item","group","xy","x","y"],u=new Set([Function,eval,setTimeout,setInterval]);"function"==typeof setImmediate&&u.add(setImmediate);const l={Literal:(e,t)=>t.value,Identifier:(e,t)=>{const r=t.name;return e.memberDepth>0?r:"datum"===r?e.datum:"event"===r?e.event:"item"===r?e.item:n[r]||e.params["$"+r]},MemberExpression:(e,t)=>{const n=!t.computed,r=e(t.object);n&&(e.memberDepth+=1);const a=e(t.property);if(n&&(e.memberDepth-=1),!u.has(r[a]))return r[a];console.error(`Prevented interpretation of member "${a}" which could lead to insecure code execution`)},CallExpression:(e,t)=>{const n=t.arguments;let r=t.callee.name;return r.startsWith("_")&&(r=r.slice(1)),"if"===r?e(n[0])?e(n[1]):e(n[2]):(e.fn[r]||s[r]).apply(e.fn,n.map(e))},ArrayExpression:(e,t)=>t.elements.map(e),BinaryExpression:(e,t)=>r[t.operator](e(t.left),e(t.right)),UnaryExpression:(e,t)=>a[t.operator](e(t.argument)),ConditionalExpression:(e,t)=>e(t.test)?e(t.consequent):e(t.alternate),LogicalExpression:(e,t)=>"&&"===t.operator?e(t.left)&&e(t.right):e(t.left)||e(t.right),ObjectExpression:(e,t)=>t.properties.reduce(((t,n)=>{e.memberDepth+=1;const r=e(n.key);return e.memberDepth-=1,u.has(e(n.value))?console.error(`Prevented interpretation of property "${r}" which could lead to insecure code execution`):t[r]=e(n.value),t}),{})};function m(e,t,n,r,a,o){const i=e=>l[e.type](i,e);return i.memberDepth=0,i.fn=Object.create(t),i.params=n,i.datum=r,i.event=a,i.item=o,c.forEach((e=>i.fn[e]=function(){return a.vega[e](...arguments)})),i(e)}var p={operator(e,t){const n=t.ast,r=e.functions;return e=>m(n,r,e)},parameter(e,t){const n=t.ast,r=e.functions;return(e,t)=>m(n,r,t,e)},event(e,t){const n=t.ast,r=e.functions;return e=>m(n,r,void 0,void 0,e)},handler(e,t){const n=t.ast,r=e.functions;return(e,t)=>{const a=t.item&&t.item.datum;return m(n,r,e,a,t)}},encode(e,t){const{marktype:n,channels:r}=t,a=e.functions,o="group"===n||"image"===n||"rect"===n;return(e,t)=>{const i=e.datum;let s,c=0;for(const n in r)s=m(r[n].ast,a,t,i,void 0,e),e[n]!==s&&(e[n]=s,c=1);return"rule"!==n&&function(e,t,n){let r;t.x2&&(t.x?(n&&e.x>e.x2&&(r=e.x,e.x=e.x2,e.x2=r),e.width=e.x2-e.x):e.x=e.x2-(e.width||0)),t.xc&&(e.x=e.xc-(e.width||0)/2),t.y2&&(t.y?(n&&e.y>e.y2&&(r=e.y,e.y=e.y2,e.y2=r),e.height=e.y2-e.y):e.y=e.y2-(e.height||0)),t.yc&&(e.y=e.yc-(e.height||0)/2)}(e,r,o),c}}};e.expressionInterpreter=p}));
|
|
2
|
-
//# sourceMappingURL=vega-interpreter.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vega-interpreter.min.js","sources":["../src/constants.js","../src/ops-binary.js","../src/ops-unary.js","../src/functions.js","../src/interpret.js","../src/expression.js","../src/adjust-spatial.js"],"sourcesContent":["export default {\n NaN: NaN,\n E: Math.E,\n LN2: Math.LN2,\n LN10: Math.LN10,\n LOG2E: Math.LOG2E,\n LOG10E: Math.LOG10E,\n PI: Math.PI,\n SQRT1_2: Math.SQRT1_2,\n SQRT2: Math.SQRT2,\n MIN_VALUE: Number.MIN_VALUE,\n MAX_VALUE: Number.MAX_VALUE\n};\n","export default {\n '*': (a, b) => a * b,\n '+': (a, b) => a + b,\n '-': (a, b) => a - b,\n '/': (a, b) => a / b,\n '%': (a, b) => a % b,\n '>': (a, b) => a > b,\n '<': (a, b) => a < b,\n '<=': (a, b) => a <= b,\n '>=': (a, b) => a >= b,\n '==': (a, b) => a == b,\n '!=': (a, b) => a != b,\n '===': (a, b) => a === b,\n '!==': (a, b) => a !== b,\n '&': (a, b) => a & b,\n '|': (a, b) => a | b,\n '^': (a, b) => a ^ b,\n '<<': (a, b) => a << b,\n '>>': (a, b) => a >> b,\n '>>>': (a, b) => a >>> b\n};\n","export default {\n '+': a => +a,\n '-': a => -a,\n '~': a => ~a,\n '!': a => !a\n};\n","import { ascending } from 'vega-util';\n\nconst slice = Array.prototype.slice;\n\nconst apply = (m, args, cast) => {\n const obj = cast ? cast(args[0]) : args[0];\n return obj[m].apply(obj, slice.call(args, 1));\n};\n\nconst datetime = (y, m, d, H, M, S, ms) =>\n new Date(y, m || 0, d != null ? d : 1, H || 0, M || 0, S || 0, ms || 0);\n\nexport default {\n // math functions\n isNaN: Number.isNaN,\n isFinite: Number.isFinite,\n abs: Math.abs,\n acos: Math.acos,\n asin: Math.asin,\n atan: Math.atan,\n atan2: Math.atan2,\n ceil: Math.ceil,\n cos: Math.cos,\n exp: Math.exp,\n floor: Math.floor,\n log: Math.log,\n max: Math.max,\n min: Math.min,\n pow: Math.pow,\n random: Math.random,\n round: Math.round,\n sin: Math.sin,\n sqrt: Math.sqrt,\n tan: Math.tan,\n clamp: (a, b, c) => Math.max(b, Math.min(c, a)),\n\n // date functions\n now: Date.now,\n utc: Date.UTC,\n datetime: datetime,\n date: d => new Date(d).getDate(),\n day: d => new Date(d).getDay(),\n year: d => new Date(d).getFullYear(),\n month: d => new Date(d).getMonth(),\n hours: d => new Date(d).getHours(),\n minutes: d => new Date(d).getMinutes(),\n seconds: d => new Date(d).getSeconds(),\n milliseconds: d => new Date(d).getMilliseconds(),\n time: d => new Date(d).getTime(),\n timezoneoffset: d => new Date(d).getTimezoneOffset(),\n utcdate: d => new Date(d).getUTCDate(),\n utcday: d => new Date(d).getUTCDay(),\n utcyear: d => new Date(d).getUTCFullYear(),\n utcmonth: d => new Date(d).getUTCMonth(),\n utchours: d => new Date(d).getUTCHours(),\n utcminutes: d => new Date(d).getUTCMinutes(),\n utcseconds: d => new Date(d).getUTCSeconds(),\n utcmilliseconds: d => new Date(d).getUTCMilliseconds(),\n\n // sequence functions\n length: x => x.length,\n join: function() { return apply('join', arguments); },\n indexof: function() { return apply('indexOf', arguments); },\n lastindexof: function() { return apply('lastIndexOf', arguments); },\n slice: function() { return apply('slice', arguments); },\n reverse: x => x.slice().reverse(),\n sort: x => x.slice().sort(ascending),\n\n // string functions\n parseFloat: parseFloat,\n parseInt: parseInt,\n upper: x => String(x).toUpperCase(),\n lower: x => String(x).toLowerCase(),\n substring: function() { return apply('substring', arguments, String); },\n split: function() { return apply('split', arguments, String); },\n replace: function() { return apply('replace', arguments, String); },\n trim: x => String(x).trim(),\n\n // regexp functions\n regexp: RegExp,\n test: (r, t) => RegExp(r).test(t)\n};\n","import Constants from './constants';\nimport Ops from './ops-binary';\nimport Unary from './ops-unary';\nimport Functions from './functions';\n\nconst EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];\nconst DisallowedMethods = new Set([\n Function,\n eval,\n setTimeout,\n setInterval\n]);\n\nif (typeof setImmediate === 'function') DisallowedMethods.add(setImmediate);\n\nconst Visitors = {\n Literal: ($, n) => n.value,\n\n Identifier: ($, n) => {\n const id = n.name;\n return $.memberDepth > 0 ? id\n : id === 'datum' ? $.datum\n : id === 'event' ? $.event\n : id === 'item' ? $.item\n : Constants[id] || $.params['$' + id];\n },\n\n MemberExpression: ($, n) => {\n const d = !n.computed,\n o = $(n.object);\n if (d) $.memberDepth += 1;\n const p = $(n.property);\n if (d) $.memberDepth -= 1;\n if (DisallowedMethods.has(o[p])) {\n // eslint-disable-next-line no-console\n console.error(`Prevented interpretation of member \"${p}\" which could lead to insecure code execution`);\n return;\n }\n return o[p];\n },\n\n CallExpression: ($, n) => {\n const args = n.arguments;\n let name = n.callee.name;\n\n // handle special internal functions used by encoders\n // re-route to corresponding standard function\n if (name.startsWith('_')) {\n name = name.slice(1);\n }\n\n // special case \"if\" due to conditional evaluation of branches\n return name === 'if'\n ? ($(args[0]) ? $(args[1]) : $(args[2]))\n : ($.fn[name] || Functions[name]).apply($.fn, args.map($));\n },\n\n ArrayExpression: ($, n) => n.elements.map($),\n\n BinaryExpression: ($, n) => Ops[n.operator]($(n.left), $(n.right)),\n\n UnaryExpression: ($, n) => Unary[n.operator]($(n.argument)),\n\n ConditionalExpression: ($, n) => $(n.test)\n ? $(n.consequent)\n : $(n.alternate),\n\n LogicalExpression: ($, n) => n.operator === '&&'\n ? $(n.left) && $(n.right)\n : $(n.left) || $(n.right),\n\n ObjectExpression: ($, n) => n.properties.reduce((o, p) => {\n $.memberDepth += 1;\n const k = $(p.key);\n $.memberDepth -= 1;\n if (DisallowedMethods.has($(p.value))) {\n // eslint-disable-next-line no-console\n console.error(`Prevented interpretation of property \"${k}\" which could lead to insecure code execution`);\n } else {\n o[k] = $(p.value);\n }\n return o;\n }, {})\n};\n\nexport default function(ast, fn, params, datum, event, item) {\n const $ = n => Visitors[n.type]($, n);\n $.memberDepth = 0;\n $.fn = Object.create(fn);\n $.params = params;\n $.datum = datum;\n $.event = event;\n $.item = item;\n\n // route event functions to annotated vega event context\n EventFunctions.forEach(f => $.fn[f] = (...args) => event.vega[f](...args));\n\n return $(ast);\n}\n","import adjustSpatial from './adjust-spatial';\nimport interpret from './interpret';\n\nexport default {\n /**\n * Parse an expression used to update an operator value.\n */\n operator(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return _ => interpret(ast, fn, _);\n },\n\n /**\n * Parse an expression provided as an operator parameter value.\n */\n parameter(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return (datum, _) => interpret(ast, fn, _, datum);\n },\n\n /**\n * Parse an expression applied to an event stream.\n */\n event(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return event => interpret(ast, fn, undefined, undefined, event);\n },\n\n /**\n * Parse an expression used to handle an event-driven operator update.\n */\n handler(ctx, expr) {\n const ast = expr.ast, fn = ctx.functions;\n return (_, event) => {\n const datum = event.item && event.item.datum;\n return interpret(ast, fn, _, datum, event);\n };\n },\n\n /**\n * Parse an expression that performs visual encoding.\n */\n encode(ctx, encode) {\n const {marktype, channels} = encode,\n fn = ctx.functions,\n swap = marktype === 'group'\n || marktype === 'image'\n || marktype === 'rect';\n\n return (item, _) => {\n const datum = item.datum;\n let m = 0, v;\n\n for (const name in channels) {\n v = interpret(channels[name].ast, fn, _, datum, undefined, item);\n if (item[name] !== v) {\n item[name] = v;\n m = 1;\n }\n }\n\n if (marktype !== 'rule') {\n adjustSpatial(item, channels, swap);\n }\n return m;\n };\n }\n};\n","export default function(item, encode, swap) {\n let t;\n\n if (encode.x2) {\n if (encode.x) {\n if (swap && item.x > item.x2) {\n t = item.x;\n item.x = item.x2;\n item.x2 = t;\n }\n item.width = item.x2 - item.x;\n } else {\n item.x = item.x2 - (item.width || 0);\n }\n }\n\n if (encode.xc) {\n item.x = item.xc - (item.width || 0) / 2;\n }\n\n if (encode.y2) {\n if (encode.y) {\n if (swap && item.y > item.y2) {\n t = item.y;\n item.y = item.y2;\n item.y2 = t;\n }\n item.height = item.y2 - item.y;\n } else {\n item.y = item.y2 - (item.height || 0);\n }\n }\n\n if (encode.yc) {\n item.y = item.yc - (item.height || 0) / 2;\n }\n}\n"],"names":["Constants","NaN","E","Math","LN2","LN10","LOG2E","LOG10E","PI","SQRT1_2","SQRT2","MIN_VALUE","Number","MAX_VALUE","Ops","*","a","b","+","-","/","%",">","<","<=",">=","==","!=","===","!==","&","|","^","<<",">>",">>>","Unary","slice","Array","prototype","apply","m","args","cast","obj","call","Functions","isNaN","isFinite","abs","acos","asin","atan","atan2","ceil","cos","exp","floor","log","max","min","pow","random","round","sin","sqrt","tan","clamp","c","now","Date","utc","UTC","datetime","y","d","H","M","S","ms","date","getDate","day","getDay","year","getFullYear","month","getMonth","hours","getHours","minutes","getMinutes","seconds","getSeconds","milliseconds","getMilliseconds","time","getTime","timezoneoffset","getTimezoneOffset","utcdate","getUTCDate","utcday","getUTCDay","utcyear","getUTCFullYear","utcmonth","getUTCMonth","utchours","getUTCHours","utcminutes","getUTCMinutes","utcseconds","getUTCSeconds","utcmilliseconds","getUTCMilliseconds","length","x","join","arguments","indexof","lastindexof","reverse","sort","ascending","parseFloat","parseInt","upper","String","toUpperCase","lower","toLowerCase","substring","split","replace","trim","regexp","RegExp","test","r","t","EventFunctions","DisallowedMethods","Set","Function","eval","setTimeout","setInterval","setImmediate","add","Visitors","Literal","$","n","value","Identifier","id","name","memberDepth","datum","event","item","params","MemberExpression","computed","o","object","p","property","has","console","error","CallExpression","callee","startsWith","fn","map","ArrayExpression","elements","BinaryExpression","operator","left","right","UnaryExpression","argument","ConditionalExpression","consequent","alternate","LogicalExpression","ObjectExpression","properties","reduce","k","key","interpret","ast","type","Object","create","forEach","f","vega","expression","ctx","expr","functions","_","parameter","undefined","handler","encode","marktype","channels","swap","v","x2","width","xc","y2","height","yc","adjustSpatial"],"mappings":"8RAAe,IAAAA,EAAA,CACbC,IAAYA,IACZC,EAAYC,KAAKD,EACjBE,IAAYD,KAAKC,IACjBC,KAAYF,KAAKE,KACjBC,MAAYH,KAAKG,MACjBC,OAAYJ,KAAKI,OACjBC,GAAYL,KAAKK,GACjBC,QAAYN,KAAKM,QACjBC,MAAYP,KAAKO,MACjBC,UAAYC,OAAOD,UACnBE,UAAYD,OAAOC,WCXNC,EAAA,CACb,IAAKC,CAACC,EAAGC,IAAMD,EAAIC,EACnB,IAAKC,CAACF,EAAGC,IAAMD,EAAIC,EACnB,IAAKE,CAACH,EAAGC,IAAMD,EAAIC,EACnB,IAAKG,CAACJ,EAAGC,IAAMD,EAAIC,EACnB,IAAKI,CAACL,EAAGC,IAAMD,EAAIC,EACnB,IAAKK,CAACN,EAAGC,IAAMD,EAAIC,EACnB,IAAKM,CAACP,EAAGC,IAAMD,EAAIC,EACnB,KAAMO,CAACR,EAAGC,IAAMD,GAAKC,EACrB,KAAMQ,CAACT,EAAGC,IAAMD,GAAKC,EACrB,KAAMS,CAACV,EAAGC,IAAMD,GAAKC,EACrB,KAAMU,CAACX,EAAGC,IAAMD,GAAKC,EACrB,MAAOW,CAACZ,EAAGC,IAAMD,IAAMC,EACvB,MAAOY,CAACb,EAAGC,IAAMD,IAAMC,EACvB,IAAKa,CAACd,EAAGC,IAAMD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EAAKJ,GAAQyD,EACb7K,EAAI,GAOR,MAHiB,SAAb0K,GC7DK,SAASlD,EAAMiD,EAAQG,GACpC,IAAIzE,EAEAsE,EAAOK,KACLL,EAAO7F,GACLgG,GAAQpD,EAAK5C,EAAI4C,EAAKsD,KACxB3E,EAAIqB,EAAK5C,EACT4C,EAAK5C,EAAI4C,EAAKsD,GACdtD,EAAKsD,GAAK3E,GAEZqB,EAAKuD,MAAQvD,EAAKsD,GAAKtD,EAAK5C,GAE5B4C,EAAK5C,EAAI4C,EAAKsD,IAAMtD,EAAKuD,OAAS,IAIlCN,EAAOO,KACTxD,EAAK5C,EAAI4C,EAAKwD,IAAMxD,EAAKuD,OAAS,GAAK,GAGrCN,EAAOQ,KACLR,EAAOxI,GACL2I,GAAQpD,EAAKvF,EAAIuF,EAAKyD,KACxB9E,EAAIqB,EAAKvF,EACTuF,EAAKvF,EAAIuF,EAAKyD,GACdzD,EAAKyD,GAAK9E,GAEZqB,EAAK0D,OAAS1D,EAAKyD,GAAKzD,EAAKvF,GAE7BuF,EAAKvF,EAAIuF,EAAKyD,IAAMzD,EAAK0D,QAAU,IAInCT,EAAOU,KACT3D,EAAKvF,EAAIuF,EAAK2D,IAAM3D,EAAK0D,QAAU,GAAK,EAE5C,CD0BQE,CAAc5D,EAAMmD,EAAUC,GAEzB5K,CAAC,CAEZ"}
|
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
import { ascending } from 'vega-util';
|
|
2
|
-
|
|
3
|
-
function adjustSpatial (item, encode, swap) {
|
|
4
|
-
let t;
|
|
5
|
-
if (encode.x2) {
|
|
6
|
-
if (encode.x) {
|
|
7
|
-
if (swap && item.x > item.x2) {
|
|
8
|
-
t = item.x;
|
|
9
|
-
item.x = item.x2;
|
|
10
|
-
item.x2 = t;
|
|
11
|
-
}
|
|
12
|
-
item.width = item.x2 - item.x;
|
|
13
|
-
} else {
|
|
14
|
-
item.x = item.x2 - (item.width || 0);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (encode.xc) {
|
|
18
|
-
item.x = item.xc - (item.width || 0) / 2;
|
|
19
|
-
}
|
|
20
|
-
if (encode.y2) {
|
|
21
|
-
if (encode.y) {
|
|
22
|
-
if (swap && item.y > item.y2) {
|
|
23
|
-
t = item.y;
|
|
24
|
-
item.y = item.y2;
|
|
25
|
-
item.y2 = t;
|
|
26
|
-
}
|
|
27
|
-
item.height = item.y2 - item.y;
|
|
28
|
-
} else {
|
|
29
|
-
item.y = item.y2 - (item.height || 0);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (encode.yc) {
|
|
33
|
-
item.y = item.yc - (item.height || 0) / 2;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var Constants = {
|
|
38
|
-
NaN: NaN,
|
|
39
|
-
E: Math.E,
|
|
40
|
-
LN2: Math.LN2,
|
|
41
|
-
LN10: Math.LN10,
|
|
42
|
-
LOG2E: Math.LOG2E,
|
|
43
|
-
LOG10E: Math.LOG10E,
|
|
44
|
-
PI: Math.PI,
|
|
45
|
-
SQRT1_2: Math.SQRT1_2,
|
|
46
|
-
SQRT2: Math.SQRT2,
|
|
47
|
-
MIN_VALUE: Number.MIN_VALUE,
|
|
48
|
-
MAX_VALUE: Number.MAX_VALUE
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
var Ops = {
|
|
52
|
-
'*': (a, b) => a * b,
|
|
53
|
-
'+': (a, b) => a + b,
|
|
54
|
-
'-': (a, b) => a - b,
|
|
55
|
-
'/': (a, b) => a / b,
|
|
56
|
-
'%': (a, b) => a % b,
|
|
57
|
-
'>': (a, b) => a > b,
|
|
58
|
-
'<': (a, b) => a < b,
|
|
59
|
-
'<=': (a, b) => a <= b,
|
|
60
|
-
'>=': (a, b) => a >= b,
|
|
61
|
-
'==': (a, b) => a == b,
|
|
62
|
-
'!=': (a, b) => a != b,
|
|
63
|
-
'===': (a, b) => a === b,
|
|
64
|
-
'!==': (a, b) => a !== b,
|
|
65
|
-
'&': (a, b) => a & b,
|
|
66
|
-
'|': (a, b) => a | b,
|
|
67
|
-
'^': (a, b) => a ^ b,
|
|
68
|
-
'<<': (a, b) => a << b,
|
|
69
|
-
'>>': (a, b) => a >> b,
|
|
70
|
-
'>>>': (a, b) => a >>> b
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
var Unary = {
|
|
74
|
-
'+': a => +a,
|
|
75
|
-
'-': a => -a,
|
|
76
|
-
'~': a => ~a,
|
|
77
|
-
'!': a => !a
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const slice = Array.prototype.slice;
|
|
81
|
-
const apply = (m, args, cast) => {
|
|
82
|
-
const obj = cast ? cast(args[0]) : args[0];
|
|
83
|
-
return obj[m].apply(obj, slice.call(args, 1));
|
|
84
|
-
};
|
|
85
|
-
const datetime = (y, m, d, H, M, S, ms) => new Date(y, m || 0, d != null ? d : 1, H || 0, M || 0, S || 0, ms || 0);
|
|
86
|
-
var Functions = {
|
|
87
|
-
// math functions
|
|
88
|
-
isNaN: Number.isNaN,
|
|
89
|
-
isFinite: Number.isFinite,
|
|
90
|
-
abs: Math.abs,
|
|
91
|
-
acos: Math.acos,
|
|
92
|
-
asin: Math.asin,
|
|
93
|
-
atan: Math.atan,
|
|
94
|
-
atan2: Math.atan2,
|
|
95
|
-
ceil: Math.ceil,
|
|
96
|
-
cos: Math.cos,
|
|
97
|
-
exp: Math.exp,
|
|
98
|
-
floor: Math.floor,
|
|
99
|
-
log: Math.log,
|
|
100
|
-
max: Math.max,
|
|
101
|
-
min: Math.min,
|
|
102
|
-
pow: Math.pow,
|
|
103
|
-
random: Math.random,
|
|
104
|
-
round: Math.round,
|
|
105
|
-
sin: Math.sin,
|
|
106
|
-
sqrt: Math.sqrt,
|
|
107
|
-
tan: Math.tan,
|
|
108
|
-
clamp: (a, b, c) => Math.max(b, Math.min(c, a)),
|
|
109
|
-
// date functions
|
|
110
|
-
now: Date.now,
|
|
111
|
-
utc: Date.UTC,
|
|
112
|
-
datetime: datetime,
|
|
113
|
-
date: d => new Date(d).getDate(),
|
|
114
|
-
day: d => new Date(d).getDay(),
|
|
115
|
-
year: d => new Date(d).getFullYear(),
|
|
116
|
-
month: d => new Date(d).getMonth(),
|
|
117
|
-
hours: d => new Date(d).getHours(),
|
|
118
|
-
minutes: d => new Date(d).getMinutes(),
|
|
119
|
-
seconds: d => new Date(d).getSeconds(),
|
|
120
|
-
milliseconds: d => new Date(d).getMilliseconds(),
|
|
121
|
-
time: d => new Date(d).getTime(),
|
|
122
|
-
timezoneoffset: d => new Date(d).getTimezoneOffset(),
|
|
123
|
-
utcdate: d => new Date(d).getUTCDate(),
|
|
124
|
-
utcday: d => new Date(d).getUTCDay(),
|
|
125
|
-
utcyear: d => new Date(d).getUTCFullYear(),
|
|
126
|
-
utcmonth: d => new Date(d).getUTCMonth(),
|
|
127
|
-
utchours: d => new Date(d).getUTCHours(),
|
|
128
|
-
utcminutes: d => new Date(d).getUTCMinutes(),
|
|
129
|
-
utcseconds: d => new Date(d).getUTCSeconds(),
|
|
130
|
-
utcmilliseconds: d => new Date(d).getUTCMilliseconds(),
|
|
131
|
-
// sequence functions
|
|
132
|
-
length: x => x.length,
|
|
133
|
-
join: function () {
|
|
134
|
-
return apply('join', arguments);
|
|
135
|
-
},
|
|
136
|
-
indexof: function () {
|
|
137
|
-
return apply('indexOf', arguments);
|
|
138
|
-
},
|
|
139
|
-
lastindexof: function () {
|
|
140
|
-
return apply('lastIndexOf', arguments);
|
|
141
|
-
},
|
|
142
|
-
slice: function () {
|
|
143
|
-
return apply('slice', arguments);
|
|
144
|
-
},
|
|
145
|
-
reverse: x => x.slice().reverse(),
|
|
146
|
-
sort: x => x.slice().sort(ascending),
|
|
147
|
-
// string functions
|
|
148
|
-
parseFloat: parseFloat,
|
|
149
|
-
parseInt: parseInt,
|
|
150
|
-
upper: x => String(x).toUpperCase(),
|
|
151
|
-
lower: x => String(x).toLowerCase(),
|
|
152
|
-
substring: function () {
|
|
153
|
-
return apply('substring', arguments, String);
|
|
154
|
-
},
|
|
155
|
-
split: function () {
|
|
156
|
-
return apply('split', arguments, String);
|
|
157
|
-
},
|
|
158
|
-
replace: function () {
|
|
159
|
-
return apply('replace', arguments, String);
|
|
160
|
-
},
|
|
161
|
-
trim: x => String(x).trim(),
|
|
162
|
-
// regexp functions
|
|
163
|
-
regexp: RegExp,
|
|
164
|
-
test: (r, t) => RegExp(r).test(t)
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];
|
|
168
|
-
const DisallowedMethods = new Set([Function, eval, setTimeout, setInterval]);
|
|
169
|
-
if (typeof setImmediate === 'function') DisallowedMethods.add(setImmediate);
|
|
170
|
-
const Visitors = {
|
|
171
|
-
Literal: ($, n) => n.value,
|
|
172
|
-
Identifier: ($, n) => {
|
|
173
|
-
const id = n.name;
|
|
174
|
-
return $.memberDepth > 0 ? id : id === 'datum' ? $.datum : id === 'event' ? $.event : id === 'item' ? $.item : Constants[id] || $.params['$' + id];
|
|
175
|
-
},
|
|
176
|
-
MemberExpression: ($, n) => {
|
|
177
|
-
const d = !n.computed,
|
|
178
|
-
o = $(n.object);
|
|
179
|
-
if (d) $.memberDepth += 1;
|
|
180
|
-
const p = $(n.property);
|
|
181
|
-
if (d) $.memberDepth -= 1;
|
|
182
|
-
if (DisallowedMethods.has(o[p])) {
|
|
183
|
-
// eslint-disable-next-line no-console
|
|
184
|
-
console.error(`Prevented interpretation of member "${p}" which could lead to insecure code execution`);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
return o[p];
|
|
188
|
-
},
|
|
189
|
-
CallExpression: ($, n) => {
|
|
190
|
-
const args = n.arguments;
|
|
191
|
-
let name = n.callee.name;
|
|
192
|
-
|
|
193
|
-
// handle special internal functions used by encoders
|
|
194
|
-
// re-route to corresponding standard function
|
|
195
|
-
if (name.startsWith('_')) {
|
|
196
|
-
name = name.slice(1);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// special case "if" due to conditional evaluation of branches
|
|
200
|
-
return name === 'if' ? $(args[0]) ? $(args[1]) : $(args[2]) : ($.fn[name] || Functions[name]).apply($.fn, args.map($));
|
|
201
|
-
},
|
|
202
|
-
ArrayExpression: ($, n) => n.elements.map($),
|
|
203
|
-
BinaryExpression: ($, n) => Ops[n.operator]($(n.left), $(n.right)),
|
|
204
|
-
UnaryExpression: ($, n) => Unary[n.operator]($(n.argument)),
|
|
205
|
-
ConditionalExpression: ($, n) => $(n.test) ? $(n.consequent) : $(n.alternate),
|
|
206
|
-
LogicalExpression: ($, n) => n.operator === '&&' ? $(n.left) && $(n.right) : $(n.left) || $(n.right),
|
|
207
|
-
ObjectExpression: ($, n) => n.properties.reduce((o, p) => {
|
|
208
|
-
$.memberDepth += 1;
|
|
209
|
-
const k = $(p.key);
|
|
210
|
-
$.memberDepth -= 1;
|
|
211
|
-
if (DisallowedMethods.has($(p.value))) {
|
|
212
|
-
// eslint-disable-next-line no-console
|
|
213
|
-
console.error(`Prevented interpretation of property "${k}" which could lead to insecure code execution`);
|
|
214
|
-
} else {
|
|
215
|
-
o[k] = $(p.value);
|
|
216
|
-
}
|
|
217
|
-
return o;
|
|
218
|
-
}, {})
|
|
219
|
-
};
|
|
220
|
-
function interpret (ast, fn, params, datum, event, item) {
|
|
221
|
-
const $ = n => Visitors[n.type]($, n);
|
|
222
|
-
$.memberDepth = 0;
|
|
223
|
-
$.fn = Object.create(fn);
|
|
224
|
-
$.params = params;
|
|
225
|
-
$.datum = datum;
|
|
226
|
-
$.event = event;
|
|
227
|
-
$.item = item;
|
|
228
|
-
|
|
229
|
-
// route event functions to annotated vega event context
|
|
230
|
-
EventFunctions.forEach(f => $.fn[f] = function () {
|
|
231
|
-
return event.vega[f](...arguments);
|
|
232
|
-
});
|
|
233
|
-
return $(ast);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
var expression = {
|
|
237
|
-
/**
|
|
238
|
-
* Parse an expression used to update an operator value.
|
|
239
|
-
*/
|
|
240
|
-
operator(ctx, expr) {
|
|
241
|
-
const ast = expr.ast,
|
|
242
|
-
fn = ctx.functions;
|
|
243
|
-
return _ => interpret(ast, fn, _);
|
|
244
|
-
},
|
|
245
|
-
/**
|
|
246
|
-
* Parse an expression provided as an operator parameter value.
|
|
247
|
-
*/
|
|
248
|
-
parameter(ctx, expr) {
|
|
249
|
-
const ast = expr.ast,
|
|
250
|
-
fn = ctx.functions;
|
|
251
|
-
return (datum, _) => interpret(ast, fn, _, datum);
|
|
252
|
-
},
|
|
253
|
-
/**
|
|
254
|
-
* Parse an expression applied to an event stream.
|
|
255
|
-
*/
|
|
256
|
-
event(ctx, expr) {
|
|
257
|
-
const ast = expr.ast,
|
|
258
|
-
fn = ctx.functions;
|
|
259
|
-
return event => interpret(ast, fn, undefined, undefined, event);
|
|
260
|
-
},
|
|
261
|
-
/**
|
|
262
|
-
* Parse an expression used to handle an event-driven operator update.
|
|
263
|
-
*/
|
|
264
|
-
handler(ctx, expr) {
|
|
265
|
-
const ast = expr.ast,
|
|
266
|
-
fn = ctx.functions;
|
|
267
|
-
return (_, event) => {
|
|
268
|
-
const datum = event.item && event.item.datum;
|
|
269
|
-
return interpret(ast, fn, _, datum, event);
|
|
270
|
-
};
|
|
271
|
-
},
|
|
272
|
-
/**
|
|
273
|
-
* Parse an expression that performs visual encoding.
|
|
274
|
-
*/
|
|
275
|
-
encode(ctx, encode) {
|
|
276
|
-
const {
|
|
277
|
-
marktype,
|
|
278
|
-
channels
|
|
279
|
-
} = encode,
|
|
280
|
-
fn = ctx.functions,
|
|
281
|
-
swap = marktype === 'group' || marktype === 'image' || marktype === 'rect';
|
|
282
|
-
return (item, _) => {
|
|
283
|
-
const datum = item.datum;
|
|
284
|
-
let m = 0,
|
|
285
|
-
v;
|
|
286
|
-
for (const name in channels) {
|
|
287
|
-
v = interpret(channels[name].ast, fn, _, datum, undefined, item);
|
|
288
|
-
if (item[name] !== v) {
|
|
289
|
-
item[name] = v;
|
|
290
|
-
m = 1;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
if (marktype !== 'rule') {
|
|
294
|
-
adjustSpatial(item, channels, swap);
|
|
295
|
-
}
|
|
296
|
-
return m;
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
export { expression as expressionInterpreter };
|
package/rollup.config.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '../../rollup.config.mjs';
|