vega-event-selector
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -5,30 +5,31 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vega = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
})(this, (function (exports) { 'use strict'; | ||
const VIEW = 'view', | ||
LBRACK = '[', | ||
RBRACK = ']', | ||
LBRACE = '{', | ||
RBRACE = '}', | ||
COLON = ':', | ||
COMMA = ',', | ||
NAME = '@', | ||
GT = '>', | ||
ILLEGAL = /[[\]{}]/, | ||
DEFAULT_MARKS = { | ||
'*': 1, | ||
arc: 1, | ||
area: 1, | ||
group: 1, | ||
image: 1, | ||
line: 1, | ||
path: 1, | ||
rect: 1, | ||
rule: 1, | ||
shape: 1, | ||
symbol: 1, | ||
text: 1, | ||
trail: 1 | ||
}; | ||
LBRACK = '[', | ||
RBRACK = ']', | ||
LBRACE = '{', | ||
RBRACE = '}', | ||
COLON = ':', | ||
COMMA = ',', | ||
NAME = '@', | ||
GT = '>', | ||
ILLEGAL = /[[\]{}]/, | ||
DEFAULT_MARKS = { | ||
'*': 1, | ||
arc: 1, | ||
area: 1, | ||
group: 1, | ||
image: 1, | ||
line: 1, | ||
path: 1, | ||
rect: 1, | ||
rule: 1, | ||
shape: 1, | ||
symbol: 1, | ||
text: 1, | ||
trail: 1 | ||
}; | ||
let DEFAULT_SOURCE, MARKS; | ||
/** | ||
@@ -38,3 +39,2 @@ * Parse an event selector string. | ||
*/ | ||
function eventSelector (selector, source, marks) { | ||
@@ -45,12 +45,9 @@ DEFAULT_SOURCE = source || VIEW; | ||
} | ||
function isMarkType(type) { | ||
return MARKS[type]; | ||
} | ||
function find(s, i, endChar, pushChar, popChar) { | ||
const n = s.length; | ||
let count = 0, | ||
c; | ||
c; | ||
for (; i < n; ++i) { | ||
@@ -60,12 +57,9 @@ c = s[i]; | ||
} | ||
return i; | ||
} | ||
function parseMerge(s) { | ||
const output = [], | ||
n = s.length; | ||
n = s.length; | ||
let start = 0, | ||
i = 0; | ||
i = 0; | ||
while (i < n) { | ||
@@ -76,39 +70,28 @@ i = find(s, i, COMMA, LBRACK + LBRACE, RBRACK + RBRACE); | ||
} | ||
if (output.length === 0) { | ||
throw 'Empty event selector: ' + s; | ||
} | ||
return output; | ||
} | ||
function parseSelector(s) { | ||
return s[0] === '[' ? parseBetween(s) : parseStream(s); | ||
} | ||
function parseBetween(s) { | ||
const n = s.length; | ||
let i = 1, | ||
b; | ||
b; | ||
i = find(s, i, RBRACK, LBRACK, RBRACK); | ||
if (i === n) { | ||
throw 'Empty between selector: ' + s; | ||
} | ||
b = parseMerge(s.substring(1, i)); | ||
if (b.length !== 2) { | ||
throw 'Between selector must have two elements: ' + s; | ||
} | ||
s = s.slice(i + 1).trim(); | ||
if (s[0] !== GT) { | ||
throw 'Expected \'>\' after between selector: ' + s; | ||
} | ||
b = b.map(parseSelector); | ||
const stream = parseSelector(s.slice(1).trim()); | ||
if (stream.between) { | ||
@@ -122,22 +105,20 @@ return { | ||
} | ||
return stream; | ||
} | ||
function parseStream(s) { | ||
const stream = { | ||
source: DEFAULT_SOURCE | ||
}, | ||
source = []; | ||
source: DEFAULT_SOURCE | ||
}, | ||
source = []; | ||
let throttle = [0, 0], | ||
markname = 0, | ||
start = 0, | ||
n = s.length, | ||
i = 0, | ||
j, | ||
filter; // extract throttle from end | ||
markname = 0, | ||
start = 0, | ||
n = s.length, | ||
i = 0, | ||
j, | ||
filter; | ||
// extract throttle from end | ||
if (s[n - 1] === RBRACE) { | ||
i = s.lastIndexOf(LBRACE); | ||
if (i >= 0) { | ||
@@ -149,24 +130,21 @@ try { | ||
} | ||
s = s.slice(0, i).trim(); | ||
n = s.length; | ||
} else throw 'Unmatched right brace: ' + s; | ||
i = 0; | ||
} | ||
if (!n) throw s; | ||
if (!n) throw s; // set name flag based on first char | ||
// set name flag based on first char | ||
if (s[0] === NAME) markname = ++i; | ||
if (s[0] === NAME) markname = ++i; // extract first part of multi-part stream selector | ||
// extract first part of multi-part stream selector | ||
j = find(s, i, COLON); | ||
if (j < n) { | ||
source.push(s.substring(start, j).trim()); | ||
start = i = ++j; | ||
} // extract remaining part of stream selector | ||
} | ||
// extract remaining part of stream selector | ||
i = find(s, i, LBRACK); | ||
if (i === n) { | ||
@@ -179,5 +157,5 @@ source.push(s.substring(start, n).trim()); | ||
if (start === n) throw 'Unmatched left bracket: ' + s; | ||
} // extract filters | ||
} | ||
// extract filters | ||
while (i < n) { | ||
@@ -189,12 +167,10 @@ i = find(s, i, RBRACK); | ||
start = ++i; | ||
} // marshall event stream specification | ||
} | ||
// marshall event stream specification | ||
if (!(n = source.length) || ILLEGAL.test(source[n - 1])) { | ||
throw 'Invalid event selector: ' + s; | ||
} | ||
if (n > 1) { | ||
stream.type = source[1]; | ||
if (markname) { | ||
@@ -210,3 +186,2 @@ stream.markname = source[0].slice(1); | ||
} | ||
if (stream.type.slice(-1) === '!') { | ||
@@ -216,3 +191,2 @@ stream.consume = true; | ||
} | ||
if (filter != null) stream.filter = filter; | ||
@@ -223,3 +197,2 @@ if (throttle[0]) stream.throttle = throttle[0]; | ||
} | ||
function parseThrottle(s) { | ||
@@ -237,4 +210,2 @@ const a = s.split(COMMA); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
})); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).vega={})}(this,(function(e){"use strict";const t="[",r="]",n=/[[\]{}]/,i={"*":1,arc:1,area:1,group:1,image:1,line:1,path:1,rect:1,rule:1,shape:1,symbol:1,text:1,trail:1};let o,s;function l(e,t,r,n,i){const o=e.length;let s,l=0;for(;t<o;++t){if(s=e[t],!l&&s===r)return t;i&&i.indexOf(s)>=0?--l:n&&n.indexOf(s)>=0&&++l}return t}function c(e){const t=[],r=e.length;let n=0,i=0;for(;i<r;)i=l(e,i,",","[{","]}"),t.push(e.substring(n,i).trim()),n=++i;if(0===t.length)throw"Empty event selector: "+e;return t}function f(e){return"["===e[0]?function(e){const n=e.length;let i,o=1;if(o=l(e,o,r,t,r),o===n)throw"Empty between selector: "+e;if(i=c(e.substring(1,o)),2!==i.length)throw"Between selector must have two elements: "+e;if(">"!==(e=e.slice(o+1).trim())[0])throw"Expected '>' after between selector: "+e;i=i.map(f);const s=f(e.slice(1).trim());if(s.between)return{between:i,stream:s};s.between=i;return s}(e):function(e){const i={source:o},c=[];let f,u,h=[0,0],a=0,p=0,m=e.length,g=0;if("}"===e[m-1]){if(g=e.lastIndexOf("{"),!(g>=0))throw"Unmatched right brace: "+e;try{h=function(e){const t=e.split(",");if(!e.length||t.length>2)throw e;return t.map((t=>{const r=+t;if(r!=r)throw e;return r}))}(e.substring(g+1,m-1))}catch(t){throw"Invalid throttle specification: "+e}m=(e=e.slice(0,g).trim()).length,g=0}if(!m)throw e;"@"===e[0]&&(a=++g);f=l(e,g,":"),f<m&&(c.push(e.substring(p,f).trim()),p=g=++f);if(g=l(e,g,t),g===m)c.push(e.substring(p,m).trim());else if(c.push(e.substring(p,g).trim()),u=[],p=++g,p===m)throw"Unmatched left bracket: "+e;for(;g<m;){if(g=l(e,g,r),g===m)throw"Unmatched left bracket: "+e;if(u.push(e.substring(p,g).trim()),g<m-1&&e[++g]!==t)throw"Expected left bracket: "+e;p=++g}if(!(m=c.length)||n.test(c[m-1]))throw"Invalid event selector: "+e;m>1?(i.type=c[1],a?i.markname=c[0].slice(1):(b=c[0],s[b]?i.marktype=c[0]:i.source=c[0])):i.type=c[0];var b;"!"===i.type.slice(-1)&&(i.consume=!0,i.type=i.type.slice(0,-1));null!=u&&(i.filter=u);h[0]&&(i.throttle=h[0]);h[1]&&(i.debounce=h[1]);return i}(e)}e.parseSelector=function(e,t,r){return o=t||"view",s=r||i,c(e.trim()).map(f)},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).vega={})}(this,(function(t){"use strict";const e="view",n="[",r="]",i="{",o="}",s=":",c=",",l="@",f=">",u=/[[\]{}]/,h={"*":1,arc:1,area:1,group:1,image:1,line:1,path:1,rect:1,rule:1,shape:1,symbol:1,text:1,trail:1};let a,p;function m(t,e,n,r,i){const o=t.length;let s,c=0;for(;e<o;++e){if(s=t[e],!c&&s===n)return e;i&&i.indexOf(s)>=0?--c:r&&r.indexOf(s)>=0&&++c}return e}function g(t){const e=[],s=t.length;let l=0,f=0;for(;f<s;)f=m(t,f,c,n+i,r+o),e.push(t.substring(l,f).trim()),l=++f;if(0===e.length)throw"Empty event selector: "+t;return e}function b(t){return"["===t[0]?function(t){const e=t.length;let i,o=1;if(o=m(t,o,r,n,r),o===e)throw"Empty between selector: "+t;if(i=g(t.substring(1,o)),2!==i.length)throw"Between selector must have two elements: "+t;if(t=t.slice(o+1).trim(),t[0]!==f)throw"Expected '>' after between selector: "+t;i=i.map(b);const s=b(t.slice(1).trim());if(s.between)return{between:i,stream:s};s.between=i;return s}(t):function(t){const e={source:a},f=[];let h,g,b=[0,0],w=0,d=0,y=t.length,x=0;if(t[y-1]===o){if(x=t.lastIndexOf(i),!(x>=0))throw"Unmatched right brace: "+t;try{b=function(t){const e=t.split(c);if(!t.length||e.length>2)throw t;return e.map((e=>{const n=+e;if(n!=n)throw t;return n}))}(t.substring(x+1,y-1))}catch(e){throw"Invalid throttle specification: "+t}y=(t=t.slice(0,x).trim()).length,x=0}if(!y)throw t;t[0]===l&&(w=++x);h=m(t,x,s),h<y&&(f.push(t.substring(d,h).trim()),d=x=++h);if(x=m(t,x,n),x===y)f.push(t.substring(d,y).trim());else if(f.push(t.substring(d,x).trim()),g=[],d=++x,d===y)throw"Unmatched left bracket: "+t;for(;x<y;){if(x=m(t,x,r),x===y)throw"Unmatched left bracket: "+t;if(g.push(t.substring(d,x).trim()),x<y-1&&t[++x]!==n)throw"Expected left bracket: "+t;d=++x}if(!(y=f.length)||u.test(f[y-1]))throw"Invalid event selector: "+t;y>1?(e.type=f[1],w?e.markname=f[0].slice(1):(v=f[0],p[v]?e.marktype=f[0]:e.source=f[0])):e.type=f[0];var v;"!"===e.type.slice(-1)&&(e.consume=!0,e.type=e.type.slice(0,-1));null!=g&&(e.filter=g);b[0]&&(e.throttle=b[0]);b[1]&&(e.debounce=b[1]);return e}(t)}t.parseSelector=function(t,n,r){return a=n||e,p=r||h,g(t.trim()).map(b)}})); | ||
//# sourceMappingURL=vega-event-selector.min.js.map |
const VIEW = 'view', | ||
LBRACK = '[', | ||
RBRACK = ']', | ||
LBRACE = '{', | ||
RBRACE = '}', | ||
COLON = ':', | ||
COMMA = ',', | ||
NAME = '@', | ||
GT = '>', | ||
ILLEGAL = /[[\]{}]/, | ||
DEFAULT_MARKS = { | ||
'*': 1, | ||
arc: 1, | ||
area: 1, | ||
group: 1, | ||
image: 1, | ||
line: 1, | ||
path: 1, | ||
rect: 1, | ||
rule: 1, | ||
shape: 1, | ||
symbol: 1, | ||
text: 1, | ||
trail: 1 | ||
}; | ||
LBRACK = '[', | ||
RBRACK = ']', | ||
LBRACE = '{', | ||
RBRACE = '}', | ||
COLON = ':', | ||
COMMA = ',', | ||
NAME = '@', | ||
GT = '>', | ||
ILLEGAL = /[[\]{}]/, | ||
DEFAULT_MARKS = { | ||
'*': 1, | ||
arc: 1, | ||
area: 1, | ||
group: 1, | ||
image: 1, | ||
line: 1, | ||
path: 1, | ||
rect: 1, | ||
rule: 1, | ||
shape: 1, | ||
symbol: 1, | ||
text: 1, | ||
trail: 1 | ||
}; | ||
let DEFAULT_SOURCE, MARKS; | ||
/** | ||
@@ -31,3 +32,2 @@ * Parse an event selector string. | ||
*/ | ||
function eventSelector (selector, source, marks) { | ||
@@ -38,12 +38,9 @@ DEFAULT_SOURCE = source || VIEW; | ||
} | ||
function isMarkType(type) { | ||
return MARKS[type]; | ||
} | ||
function find(s, i, endChar, pushChar, popChar) { | ||
const n = s.length; | ||
let count = 0, | ||
c; | ||
c; | ||
for (; i < n; ++i) { | ||
@@ -53,12 +50,9 @@ c = s[i]; | ||
} | ||
return i; | ||
} | ||
function parseMerge(s) { | ||
const output = [], | ||
n = s.length; | ||
n = s.length; | ||
let start = 0, | ||
i = 0; | ||
i = 0; | ||
while (i < n) { | ||
@@ -69,39 +63,28 @@ i = find(s, i, COMMA, LBRACK + LBRACE, RBRACK + RBRACE); | ||
} | ||
if (output.length === 0) { | ||
throw 'Empty event selector: ' + s; | ||
} | ||
return output; | ||
} | ||
function parseSelector(s) { | ||
return s[0] === '[' ? parseBetween(s) : parseStream(s); | ||
} | ||
function parseBetween(s) { | ||
const n = s.length; | ||
let i = 1, | ||
b; | ||
b; | ||
i = find(s, i, RBRACK, LBRACK, RBRACK); | ||
if (i === n) { | ||
throw 'Empty between selector: ' + s; | ||
} | ||
b = parseMerge(s.substring(1, i)); | ||
if (b.length !== 2) { | ||
throw 'Between selector must have two elements: ' + s; | ||
} | ||
s = s.slice(i + 1).trim(); | ||
if (s[0] !== GT) { | ||
throw 'Expected \'>\' after between selector: ' + s; | ||
} | ||
b = b.map(parseSelector); | ||
const stream = parseSelector(s.slice(1).trim()); | ||
if (stream.between) { | ||
@@ -115,22 +98,20 @@ return { | ||
} | ||
return stream; | ||
} | ||
function parseStream(s) { | ||
const stream = { | ||
source: DEFAULT_SOURCE | ||
}, | ||
source = []; | ||
source: DEFAULT_SOURCE | ||
}, | ||
source = []; | ||
let throttle = [0, 0], | ||
markname = 0, | ||
start = 0, | ||
n = s.length, | ||
i = 0, | ||
j, | ||
filter; // extract throttle from end | ||
markname = 0, | ||
start = 0, | ||
n = s.length, | ||
i = 0, | ||
j, | ||
filter; | ||
// extract throttle from end | ||
if (s[n - 1] === RBRACE) { | ||
i = s.lastIndexOf(LBRACE); | ||
if (i >= 0) { | ||
@@ -142,24 +123,21 @@ try { | ||
} | ||
s = s.slice(0, i).trim(); | ||
n = s.length; | ||
} else throw 'Unmatched right brace: ' + s; | ||
i = 0; | ||
} | ||
if (!n) throw s; | ||
if (!n) throw s; // set name flag based on first char | ||
// set name flag based on first char | ||
if (s[0] === NAME) markname = ++i; | ||
if (s[0] === NAME) markname = ++i; // extract first part of multi-part stream selector | ||
// extract first part of multi-part stream selector | ||
j = find(s, i, COLON); | ||
if (j < n) { | ||
source.push(s.substring(start, j).trim()); | ||
start = i = ++j; | ||
} // extract remaining part of stream selector | ||
} | ||
// extract remaining part of stream selector | ||
i = find(s, i, LBRACK); | ||
if (i === n) { | ||
@@ -172,5 +150,5 @@ source.push(s.substring(start, n).trim()); | ||
if (start === n) throw 'Unmatched left bracket: ' + s; | ||
} // extract filters | ||
} | ||
// extract filters | ||
while (i < n) { | ||
@@ -182,12 +160,10 @@ i = find(s, i, RBRACK); | ||
start = ++i; | ||
} // marshall event stream specification | ||
} | ||
// marshall event stream specification | ||
if (!(n = source.length) || ILLEGAL.test(source[n - 1])) { | ||
throw 'Invalid event selector: ' + s; | ||
} | ||
if (n > 1) { | ||
stream.type = source[1]; | ||
if (markname) { | ||
@@ -203,3 +179,2 @@ stream.markname = source[0].slice(1); | ||
} | ||
if (stream.type.slice(-1) === '!') { | ||
@@ -209,3 +184,2 @@ stream.consume = true; | ||
} | ||
if (filter != null) stream.filter = filter; | ||
@@ -216,3 +190,2 @@ if (throttle[0]) stream.throttle = throttle[0]; | ||
} | ||
function parseThrottle(s) { | ||
@@ -219,0 +192,0 @@ const a = s.split(COMMA); |
{ | ||
"name": "vega-event-selector", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "A CSS-inspired language to select, sequence, and compose DOM events.", | ||
@@ -19,3 +19,3 @@ "keywords": [ | ||
"prebuild": "rimraf build", | ||
"build": "rollup -c", | ||
"build": "rollup -c rollup.config.mjs", | ||
"pretest": "yarn build --config-test", | ||
@@ -25,3 +25,3 @@ "test": "tape 'test/**/*-test.js'", | ||
}, | ||
"gitHead": "774165e29850b66ec8b79ba52a7955f1ab936ea6" | ||
"gitHead": "fb1092f6b931d450f9c210b67ae4752bd3dd461b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28416
562