vega-interpreter 2.2.0 → 2.3.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/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2015-2023, 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,314 @@
1
+ (function (global, factory) {
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';
6
+
7
+ function adjustSpatial (item, encode, swap) {
8
+ let t;
9
+ if (encode.x2) {
10
+ if (encode.x) {
11
+ if (swap && item.x > item.x2) {
12
+ t = item.x;
13
+ item.x = item.x2;
14
+ item.x2 = t;
15
+ }
16
+ item.width = item.x2 - item.x;
17
+ } else {
18
+ item.x = item.x2 - (item.width || 0);
19
+ }
20
+ }
21
+ if (encode.xc) {
22
+ item.x = item.xc - (item.width || 0) / 2;
23
+ }
24
+ if (encode.y2) {
25
+ if (encode.y) {
26
+ if (swap && item.y > item.y2) {
27
+ t = item.y;
28
+ item.y = item.y2;
29
+ item.y2 = t;
30
+ }
31
+ item.height = item.y2 - item.y;
32
+ } else {
33
+ item.y = item.y2 - (item.height || 0);
34
+ }
35
+ }
36
+ if (encode.yc) {
37
+ item.y = item.yc - (item.height || 0) / 2;
38
+ }
39
+ }
40
+
41
+ var Constants = {
42
+ NaN: NaN,
43
+ E: Math.E,
44
+ LN2: Math.LN2,
45
+ LN10: Math.LN10,
46
+ LOG2E: Math.LOG2E,
47
+ LOG10E: Math.LOG10E,
48
+ PI: Math.PI,
49
+ SQRT1_2: Math.SQRT1_2,
50
+ SQRT2: Math.SQRT2,
51
+ MIN_VALUE: Number.MIN_VALUE,
52
+ MAX_VALUE: Number.MAX_VALUE
53
+ };
54
+
55
+ var Ops = {
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
+ '^': (a, b) => a ^ b,
72
+ '<<': (a, b) => a << b,
73
+ '>>': (a, b) => a >> b,
74
+ '>>>': (a, b) => a >>> b
75
+ };
76
+
77
+ var Unary = {
78
+ '+': a => +a,
79
+ '-': a => -a,
80
+ '~': a => ~a,
81
+ '!': a => !a
82
+ };
83
+
84
+ const slice = Array.prototype.slice;
85
+ const apply = (m, args, cast) => {
86
+ const obj = cast ? cast(args[0]) : args[0];
87
+ return obj[m].apply(obj, slice.call(args, 1));
88
+ };
89
+ 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);
90
+ var Functions = {
91
+ // math functions
92
+ isNaN: Number.isNaN,
93
+ isFinite: Number.isFinite,
94
+ abs: Math.abs,
95
+ acos: Math.acos,
96
+ asin: Math.asin,
97
+ atan: Math.atan,
98
+ atan2: Math.atan2,
99
+ ceil: Math.ceil,
100
+ cos: Math.cos,
101
+ exp: Math.exp,
102
+ floor: Math.floor,
103
+ log: Math.log,
104
+ max: Math.max,
105
+ min: Math.min,
106
+ pow: Math.pow,
107
+ random: Math.random,
108
+ round: Math.round,
109
+ sin: Math.sin,
110
+ sqrt: Math.sqrt,
111
+ tan: Math.tan,
112
+ clamp: (a, b, c) => Math.max(b, Math.min(c, a)),
113
+ // date functions
114
+ now: Date.now,
115
+ utc: Date.UTC,
116
+ datetime: datetime,
117
+ date: d => new Date(d).getDate(),
118
+ day: d => new Date(d).getDay(),
119
+ year: d => new Date(d).getFullYear(),
120
+ month: d => new Date(d).getMonth(),
121
+ hours: d => new Date(d).getHours(),
122
+ minutes: d => new Date(d).getMinutes(),
123
+ seconds: d => new Date(d).getSeconds(),
124
+ milliseconds: d => new Date(d).getMilliseconds(),
125
+ time: d => new Date(d).getTime(),
126
+ timezoneoffset: d => new Date(d).getTimezoneOffset(),
127
+ utcdate: d => new Date(d).getUTCDate(),
128
+ utcday: d => new Date(d).getUTCDay(),
129
+ utcyear: d => new Date(d).getUTCFullYear(),
130
+ utcmonth: d => new Date(d).getUTCMonth(),
131
+ utchours: d => new Date(d).getUTCHours(),
132
+ utcminutes: d => new Date(d).getUTCMinutes(),
133
+ utcseconds: d => new Date(d).getUTCSeconds(),
134
+ utcmilliseconds: d => new Date(d).getUTCMilliseconds(),
135
+ // sequence functions
136
+ length: x => x.length,
137
+ join: function () {
138
+ return apply('join', arguments);
139
+ },
140
+ indexof: function () {
141
+ return apply('indexOf', arguments);
142
+ },
143
+ lastindexof: function () {
144
+ return apply('lastIndexOf', arguments);
145
+ },
146
+ slice: function () {
147
+ return apply('slice', arguments);
148
+ },
149
+ reverse: x => x.slice().reverse(),
150
+ sort: x => x.slice().sort(vegaUtil.ascending),
151
+ // string functions
152
+ parseFloat: parseFloat,
153
+ parseInt: parseInt,
154
+ upper: x => String(x).toUpperCase(),
155
+ lower: x => String(x).toLowerCase(),
156
+ substring: function () {
157
+ return apply('substring', arguments, String);
158
+ },
159
+ split: function () {
160
+ return apply('split', arguments, String);
161
+ },
162
+ replace: function () {
163
+ return apply('replace', arguments, String);
164
+ },
165
+ trim: x => String(x).trim(),
166
+ // Base64 encode/decode
167
+ // Convert binary string to base64-encoded ascii
168
+ btoa: x => btoa(x),
169
+ // Convert base64-encoded ascii to binary string
170
+ atob: x => atob(x),
171
+ // regexp functions
172
+ regexp: RegExp,
173
+ test: (r, t) => RegExp(r).test(t)
174
+ };
175
+
176
+ const EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];
177
+ const DisallowedMethods = new Set([Function, eval, setTimeout, setInterval]);
178
+ if (typeof setImmediate === 'function') DisallowedMethods.add(setImmediate);
179
+ const Visitors = {
180
+ Literal: ($, n) => n.value,
181
+ Identifier: ($, n) => {
182
+ const id = n.name;
183
+ return $.memberDepth > 0 ? id : id === 'datum' ? $.datum : id === 'event' ? $.event : id === 'item' ? $.item : Constants[id] || $.params['$' + id];
184
+ },
185
+ MemberExpression: ($, n) => {
186
+ const d = !n.computed,
187
+ o = $(n.object);
188
+ if (d) $.memberDepth += 1;
189
+ const p = $(n.property);
190
+ if (d) $.memberDepth -= 1;
191
+ if (DisallowedMethods.has(o[p])) {
192
+ // eslint-disable-next-line no-console
193
+ console.error(`Prevented interpretation of member "${p}" which could lead to insecure code execution`);
194
+ return;
195
+ }
196
+ return o[p];
197
+ },
198
+ CallExpression: ($, n) => {
199
+ const args = n.arguments;
200
+ let name = n.callee.name;
201
+
202
+ // handle special internal functions used by encoders
203
+ // re-route to corresponding standard function
204
+ if (name.startsWith('_')) {
205
+ name = name.slice(1);
206
+ }
207
+
208
+ // special case "if" due to conditional evaluation of branches
209
+ return name === 'if' ? $(args[0]) ? $(args[1]) : $(args[2]) : ($.fn[name] || Functions[name]).apply($.fn, args.map($));
210
+ },
211
+ ArrayExpression: ($, n) => n.elements.map($),
212
+ BinaryExpression: ($, n) => Ops[n.operator]($(n.left), $(n.right)),
213
+ UnaryExpression: ($, n) => Unary[n.operator]($(n.argument)),
214
+ ConditionalExpression: ($, n) => $(n.test) ? $(n.consequent) : $(n.alternate),
215
+ LogicalExpression: ($, n) => n.operator === '&&' ? $(n.left) && $(n.right) : $(n.left) || $(n.right),
216
+ ObjectExpression: ($, n) => n.properties.reduce((o, p) => {
217
+ $.memberDepth += 1;
218
+ const k = $(p.key);
219
+ $.memberDepth -= 1;
220
+ const v = $(p.value);
221
+ if (vegaUtil.DisallowedObjectProperties.has(k)) {
222
+ // eslint-disable-next-line no-console
223
+ console.error(`Prevented interpretation of property "${k}" which could lead to insecure code execution`);
224
+ } else if (DisallowedMethods.has(v)) {
225
+ // eslint-disable-next-line no-console
226
+ console.error(`Prevented interpretation of method "${v}" which could lead to insecure code execution`);
227
+ } else {
228
+ o[k] = v;
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;
241
+
242
+ // route event functions to annotated vega event context
243
+ EventFunctions.forEach(f => $.fn[f] = (...args) => event.vega[f](...args));
244
+ return $(ast);
245
+ }
246
+
247
+ var expression = {
248
+ /**
249
+ * Parse an expression used to update an operator value.
250
+ */
251
+ operator(ctx, expr) {
252
+ const ast = expr.ast,
253
+ fn = ctx.functions;
254
+ return _ => interpret(ast, fn, _);
255
+ },
256
+ /**
257
+ * Parse an expression provided as an operator parameter value.
258
+ */
259
+ parameter(ctx, expr) {
260
+ const ast = expr.ast,
261
+ fn = ctx.functions;
262
+ return (datum, _) => interpret(ast, fn, _, datum);
263
+ },
264
+ /**
265
+ * Parse an expression applied to an event stream.
266
+ */
267
+ event(ctx, expr) {
268
+ const ast = expr.ast,
269
+ fn = ctx.functions;
270
+ return event => interpret(ast, fn, undefined, undefined, event);
271
+ },
272
+ /**
273
+ * Parse an expression used to handle an event-driven operator update.
274
+ */
275
+ handler(ctx, expr) {
276
+ const ast = expr.ast,
277
+ fn = ctx.functions;
278
+ return (_, event) => {
279
+ const datum = event.item && event.item.datum;
280
+ return interpret(ast, fn, _, datum, event);
281
+ };
282
+ },
283
+ /**
284
+ * Parse an expression that performs visual encoding.
285
+ */
286
+ encode(ctx, encode) {
287
+ const {
288
+ marktype,
289
+ channels
290
+ } = encode,
291
+ fn = ctx.functions,
292
+ swap = marktype === 'group' || marktype === 'image' || marktype === 'rect';
293
+ return (item, _) => {
294
+ const datum = item.datum;
295
+ let m = 0,
296
+ v;
297
+ for (const name in channels) {
298
+ v = interpret(channels[name].ast, fn, _, datum, undefined, item);
299
+ if (item[name] !== v) {
300
+ item[name] = v;
301
+ m = 1;
302
+ }
303
+ }
304
+ if (marktype !== 'rule') {
305
+ adjustSpatial(item, channels, swap);
306
+ }
307
+ return m;
308
+ };
309
+ }
310
+ };
311
+
312
+ exports.expressionInterpreter = expression;
313
+
314
+ }));
@@ -0,0 +1,2 @@
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(),btoa:e=>btoa(e),atob:e=>atob(e),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,n)=>n.properties.reduce(((n,r)=>{e.memberDepth+=1;const a=e(r.key);e.memberDepth-=1;const o=e(r.value);return t.DisallowedObjectProperties.has(a)?console.error(`Prevented interpretation of property "${a}" which could lead to insecure code execution`):u.has(o)?console.error(`Prevented interpretation of method "${o}" which could lead to insecure code execution`):n[a]=o,n}),{})};function p(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 m={operator(e,t){const n=t.ast,r=e.functions;return e=>p(n,r,e)},parameter(e,t){const n=t.ast,r=e.functions;return(e,t)=>p(n,r,t,e)},event(e,t){const n=t.ast,r=e.functions;return e=>p(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 p(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=p(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=m}));
2
+ //# sourceMappingURL=vega-interpreter.min.js.map
@@ -0,0 +1 @@
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 // 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';\nimport Ops from './ops-binary';\nimport Unary from './ops-unary';\nimport Functions from './functions';\nimport {DisallowedObjectProperties} from 'vega-util';\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 const v = $(p.value);\n if (DisallowedObjectProperties.has(k)) { // eslint-disable-next-line no-console\n console.error(`Prevented interpretation of property \"${k}\" which could lead to insecure code execution`);\n } else if (DisallowedMethods.has(v)) { // eslint-disable-next-line no-console\n console.error(`Prevented interpretation of method \"${v}\" which could lead to insecure code execution`);\n } else {\n o[k] = v;\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","btoa","atob","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","v","DisallowedObjectProperties","interpret","ast","type","Object","create","forEach","f","vega","expression","ctx","expr","functions","_","parameter","undefined","handler","encode","marktype","channels","swap","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,EAAIC,EACnB,IAAKc,CAACf,EAAGC,IAAMD,EAAIC,EACnB,IAAKe,CAAChB,EAAGC,IAAMD,EAAIC,EACnB,KAAMgB,CAACjB,EAAGC,IAAMD,GAAKC,EACrB,KAAMiB,CAAClB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QqC,EACb3J,EAAI,GAOR,MAHiB,SAAb8K,GC7DK,SAASpD,EAAMmD,EAAQG,GACpC,IAAI3E,EAEAwE,EAAOI,KACLJ,EAAOjG,GACLoG,GAAQtD,EAAK9C,EAAI8C,EAAKuD,KACxB5E,EAAIqB,EAAK9C,EACT8C,EAAK9C,EAAI8C,EAAKuD,GACdvD,EAAKuD,GAAK5E,GAEZqB,EAAKwD,MAAQxD,EAAKuD,GAAKvD,EAAK9C,GAE5B8C,EAAK9C,EAAI8C,EAAKuD,IAAMvD,EAAKwD,OAAS,IAIlCL,EAAOM,KACTzD,EAAK9C,EAAI8C,EAAKyD,IAAMzD,EAAKwD,OAAS,GAAK,GAGrCL,EAAOO,KACLP,EAAO5I,GACL+I,GAAQtD,EAAKzF,EAAIyF,EAAK0D,KACxB/E,EAAIqB,EAAKzF,EACTyF,EAAKzF,EAAIyF,EAAK0D,GACd1D,EAAK0D,GAAK/E,GAEZqB,EAAK2D,OAAS3D,EAAK0D,GAAK1D,EAAKzF,GAE7ByF,EAAKzF,EAAIyF,EAAK0D,IAAM1D,EAAK2D,QAAU,IAInCR,EAAOS,KACT5D,EAAKzF,EAAIyF,EAAK4D,IAAM5D,EAAK2D,QAAU,GAAK,EAE5C,CD0BQE,CAAc7D,EAAMqD,EAAUC,GAEzBhL,CAAC,CAEZ"}
@@ -0,0 +1,310 @@
1
+ import { ascending, DisallowedObjectProperties } 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
+ // Base64 encode/decode
163
+ // Convert binary string to base64-encoded ascii
164
+ btoa: x => btoa(x),
165
+ // Convert base64-encoded ascii to binary string
166
+ atob: x => atob(x),
167
+ // regexp functions
168
+ regexp: RegExp,
169
+ test: (r, t) => RegExp(r).test(t)
170
+ };
171
+
172
+ const EventFunctions = ['view', 'item', 'group', 'xy', 'x', 'y'];
173
+ const DisallowedMethods = new Set([Function, eval, setTimeout, setInterval]);
174
+ if (typeof setImmediate === 'function') DisallowedMethods.add(setImmediate);
175
+ const Visitors = {
176
+ Literal: ($, n) => n.value,
177
+ Identifier: ($, n) => {
178
+ const id = n.name;
179
+ return $.memberDepth > 0 ? id : id === 'datum' ? $.datum : id === 'event' ? $.event : id === 'item' ? $.item : Constants[id] || $.params['$' + id];
180
+ },
181
+ MemberExpression: ($, n) => {
182
+ const d = !n.computed,
183
+ o = $(n.object);
184
+ if (d) $.memberDepth += 1;
185
+ const p = $(n.property);
186
+ if (d) $.memberDepth -= 1;
187
+ if (DisallowedMethods.has(o[p])) {
188
+ // eslint-disable-next-line no-console
189
+ console.error(`Prevented interpretation of member "${p}" which could lead to insecure code execution`);
190
+ return;
191
+ }
192
+ return o[p];
193
+ },
194
+ CallExpression: ($, n) => {
195
+ const args = n.arguments;
196
+ let name = n.callee.name;
197
+
198
+ // handle special internal functions used by encoders
199
+ // re-route to corresponding standard function
200
+ if (name.startsWith('_')) {
201
+ name = name.slice(1);
202
+ }
203
+
204
+ // special case "if" due to conditional evaluation of branches
205
+ return name === 'if' ? $(args[0]) ? $(args[1]) : $(args[2]) : ($.fn[name] || Functions[name]).apply($.fn, args.map($));
206
+ },
207
+ ArrayExpression: ($, n) => n.elements.map($),
208
+ BinaryExpression: ($, n) => Ops[n.operator]($(n.left), $(n.right)),
209
+ UnaryExpression: ($, n) => Unary[n.operator]($(n.argument)),
210
+ ConditionalExpression: ($, n) => $(n.test) ? $(n.consequent) : $(n.alternate),
211
+ LogicalExpression: ($, n) => n.operator === '&&' ? $(n.left) && $(n.right) : $(n.left) || $(n.right),
212
+ ObjectExpression: ($, n) => n.properties.reduce((o, p) => {
213
+ $.memberDepth += 1;
214
+ const k = $(p.key);
215
+ $.memberDepth -= 1;
216
+ const v = $(p.value);
217
+ if (DisallowedObjectProperties.has(k)) {
218
+ // eslint-disable-next-line no-console
219
+ console.error(`Prevented interpretation of property "${k}" which could lead to insecure code execution`);
220
+ } else if (DisallowedMethods.has(v)) {
221
+ // eslint-disable-next-line no-console
222
+ console.error(`Prevented interpretation of method "${v}" which could lead to insecure code execution`);
223
+ } else {
224
+ o[k] = v;
225
+ }
226
+ return o;
227
+ }, {})
228
+ };
229
+ function interpret (ast, fn, params, datum, event, item) {
230
+ const $ = n => Visitors[n.type]($, n);
231
+ $.memberDepth = 0;
232
+ $.fn = Object.create(fn);
233
+ $.params = params;
234
+ $.datum = datum;
235
+ $.event = event;
236
+ $.item = item;
237
+
238
+ // route event functions to annotated vega event context
239
+ EventFunctions.forEach(f => $.fn[f] = function () {
240
+ return event.vega[f](...arguments);
241
+ });
242
+ return $(ast);
243
+ }
244
+
245
+ var expression = {
246
+ /**
247
+ * Parse an expression used to update an operator value.
248
+ */
249
+ operator(ctx, expr) {
250
+ const ast = expr.ast,
251
+ fn = ctx.functions;
252
+ return _ => interpret(ast, fn, _);
253
+ },
254
+ /**
255
+ * Parse an expression provided as an operator parameter value.
256
+ */
257
+ parameter(ctx, expr) {
258
+ const ast = expr.ast,
259
+ fn = ctx.functions;
260
+ return (datum, _) => interpret(ast, fn, _, datum);
261
+ },
262
+ /**
263
+ * Parse an expression applied to an event stream.
264
+ */
265
+ event(ctx, expr) {
266
+ const ast = expr.ast,
267
+ fn = ctx.functions;
268
+ return event => interpret(ast, fn, undefined, undefined, event);
269
+ },
270
+ /**
271
+ * Parse an expression used to handle an event-driven operator update.
272
+ */
273
+ handler(ctx, expr) {
274
+ const ast = expr.ast,
275
+ fn = ctx.functions;
276
+ return (_, event) => {
277
+ const datum = event.item && event.item.datum;
278
+ return interpret(ast, fn, _, datum, event);
279
+ };
280
+ },
281
+ /**
282
+ * Parse an expression that performs visual encoding.
283
+ */
284
+ encode(ctx, encode) {
285
+ const {
286
+ marktype,
287
+ channels
288
+ } = encode,
289
+ fn = ctx.functions,
290
+ swap = marktype === 'group' || marktype === 'image' || marktype === 'rect';
291
+ return (item, _) => {
292
+ const datum = item.datum;
293
+ let m = 0,
294
+ v;
295
+ for (const name in channels) {
296
+ v = interpret(channels[name].ast, fn, _, datum, undefined, item);
297
+ if (item[name] !== v) {
298
+ item[name] = v;
299
+ m = 1;
300
+ }
301
+ }
302
+ if (marktype !== 'rule') {
303
+ adjustSpatial(item, channels, swap);
304
+ }
305
+ return m;
306
+ };
307
+ }
308
+ };
309
+
310
+ export { expression as expressionInterpreter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vega-interpreter",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "CSP-compliant interpreter for Vega expressions.",
5
5
  "keywords": [
6
6
  "vega",
@@ -23,6 +23,10 @@
23
23
  "type": "git",
24
24
  "url": "git+https://github.com/vega/vega.git"
25
25
  },
26
+ "homepage": "https://github.com/vega/vega/tree/main/packages/vega-interpreter#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/vega/vega/issues"
29
+ },
26
30
  "scripts": {
27
31
  "prebuild": "del-cli build",
28
32
  "build": "rollup -c rollup.config.js --extend",
@@ -35,5 +39,6 @@
35
39
  },
36
40
  "devDependencies": {
37
41
  "vega": "*"
38
- }
42
+ },
43
+ "gitHead": "b72409b4cab26a6e5db11ce21851043ef389f761"
39
44
  }
package/src/functions.js CHANGED
@@ -82,6 +82,8 @@ export default {
82
82
  btoa: x => btoa(x),
83
83
  // Convert base64-encoded ascii to binary string
84
84
  atob: x => atob(x),
85
+ // URI encoding
86
+ encodeURIComponent: x => encodeURIComponent(x),
85
87
 
86
88
  // regexp functions
87
89
  regexp: RegExp,