Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@visactor/vgrammar-util

Package Overview
Dependencies
Maintainers
15
Versions
242
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@visactor/vgrammar-util - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

4

cjs/error.js

@@ -7,4 +7,4 @@ "use strict";

const error = message => {
if (__DEV__) throw Error(message);
const logger_1 = require("./logger"), error = message => {
(0, logger_1.getLogger)().error(message);
};

@@ -11,0 +11,0 @@

@@ -43,3 +43,3 @@ "use strict";

var _a;
return (this._level >= LoggerLevel.Error || __DEV__) && log(null !== (_a = this._method) && void 0 !== _a ? _a : "error", "ERROR", args),
return this._level >= LoggerLevel.Error && log(null !== (_a = this._method) && void 0 !== _a ? _a : "error", "ERROR", args),
this;

@@ -46,0 +46,0 @@ }

@@ -1,1 +0,886 @@

!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).VGrammar=e.VGrammar||{},e.VGrammar.Util={}))}(this,(function(e){"use strict";!function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,r,s,i){if("function"!=typeof r)throw new TypeError("The listener must be a function");var c=new o(r,s||e,i),u=n?n+t:t;return e._events[u]?e._events[u].fn?e._events[u]=[e._events[u],c]:e._events[u].push(c):(e._events[u]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function c(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,r,o=[];if(0===this._eventsCount)return o;for(r in e=this._events)t.call(e,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},c.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,s=r.length,i=new Array(s);o<s;o++)i[o]=r[o].fn;return i},c.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},c.prototype.emit=function(e,t,r,o,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var u,l,f=this._events[c],a=arguments.length;if(f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),a){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,t),!0;case 3:return f.fn.call(f.context,t,r),!0;case 4:return f.fn.call(f.context,t,r,o),!0;case 5:return f.fn.call(f.context,t,r,o,s),!0;case 6:return f.fn.call(f.context,t,r,o,s,i),!0}for(l=1,u=new Array(a-1);l<a;l++)u[l-1]=arguments[l];f.fn.apply(f.context,u)}else{var h,p=f.length;for(l=0;l<p;l++)switch(f[l].once&&this.removeListener(e,f[l].fn,void 0,!0),a){case 1:f[l].fn.call(f[l].context);break;case 2:f[l].fn.call(f[l].context,t);break;case 3:f[l].fn.call(f[l].context,t,r);break;case 4:f[l].fn.call(f[l].context,t,r,o);break;default:if(!u)for(h=1,u=new Array(a-1);h<a;h++)u[h-1]=arguments[h];f[l].fn.apply(f[l].context,u)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,r,o){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||o&&!c.once||r&&c.context!==r||i(this,s);else{for(var u=0,l=[],f=c.length;u<f;u++)(c[u].fn!==t||o&&!c[u].once||r&&c[u].context!==r)&&l.push(c[u]);l.length?this._events[s]=1===l.length?l[0]:l:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&i(this,t)):(this._events=new r,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c}({exports:{}});var t=function(e,t){return toString.call(e)==="[object ".concat(t,"]")},n=function(e){return"function"==typeof e},r=function(e){return null==e};function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}var s=function(e){var t=o(e);return null!==e&&"object"===t||"function"===t},i=function(e){return"object"==o(e)&&null!==e},c=function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=o(e);return n?"string"===r:"string"===r||t(e,"String")},u=function(e){return Array.isArray?Array.isArray(e):t(e,"Array")};function l(e){return null!=e?u(e)?e:[e]:[]}var f;try{"function"==typeof requestAnimationFrame&&"function"==typeof cancelAnimationFrame}catch(e){!1}(function(e){e[e.NONE=0]="NONE",e[e.BBOX1=1]="BBOX1",e[e.BBOX2=2]="BBOX2"})(f||(f={}));const a=(e,t,n)=>(e.fields=t||[],e.fname=n,e);function h(e){return r(e)?null:e.fields}const p=e=>t=>function(e,t,n){for(var r=c(t)?t.split("."):t,o=0;o<r.length;o++)e=e?e[r[o]]:void 0;return void 0===e?n:e}(t,e),v=e=>{if(__DEV__)throw Error(e)},g=e=>{const t=[],n=e.length;let r,o,s,i=null,c=0,u="";e+="";const l=()=>{t.push(u+e.substring(r,o)),u="",r=o+1};for(r=0,o=0;o<n;o+=1)if(s=e[o],"\\"===s)u+=e.substring(r,o),u+=e.substring(++o,++o),r=o;else if(s===i)l(),i=null,c=-1;else{if(i)continue;r===c&&'"'===s||r===c&&"'"===s?(r=o+1,i=s):"."!==s||c?"["===s?(o>r&&l(),r=o+1,c=r):"]"===s&&(c||v("Access path missing open bracket: "+e),c>0&&l(),c=0,r=o+1):o>r?l():r=o+1}return c&&v("Access path missing closing bracket: "+e),i&&v("Access path missing closing quote: "+e),o>r&&(o+=1,l()),t},y=(e,t,n={})=>{const r=g(e),o=1===r.length?r[0]:e;return a((n&&n.get||p)(r),[o],t||o)},m=y("id"),_=a((function(e){return e}),[],"identity"),b=a((function(){return 0}),[],"zero"),d=a((function(){return 1}),[],"one"),N=a((function(){return!0}),[],"true"),O=a((function(){return!1}),[],"false"),E=a((function(){return{}}),[],"emptyObject");function x(e,t,n){const r=[t].concat([].slice.call(n));console[e].apply(console,r)}var w;!function(e){e[e.None=0]="None",e[e.Error=1]="Error",e[e.Warn=2]="Warn",e[e.Info=3]="Info",e[e.Debug=4]="Debug"}(w||(w={}));class j{_level;_method;constructor(e=w.None,t){this._level=e,this._method=t}canLogInfo(){return this._level>=w.Info}canLogDebug(){return this._level>=w.Debug}canLogError(){return this._level>=w.Error}canLogWarn(){return this._level>=w.Error}level(e){return arguments.length?(this._level=+e,this):this._level}error(...e){return(this._level>=w.Error||__DEV__)&&x(this._method??"error","ERROR",e),this}warn(...e){return this._level>=w.Warn&&x(this._method||"warn","WARN",e),this}info(...e){return this._level>=w.Info&&x(this._method||"log","INFO",e),this}debug(...e){return this._level>=w.Debug&&x(this._method||"log","DEBUG",e),this}}let L=null;const A=e=>"__proto__"!==e,k=(e,t,r,o)=>{if(A(t))if(!s(r)||u(r)||n(r))e[t]=r;else{s(e[t])||(e[t]={});const n=e[t];Object.keys(r).forEach((e=>{o&&(!0===o||o[e])?k(n,e,r[e]):A(e)&&(n[e]=r[e])}))}};const S=(e,t)=>{if((e<t||r(e))&&!r(t))return-1;if((e>t||r(t))&&!r(e))return 1;const n=t instanceof Date?+t:t,o=e instanceof Date?+e:e;return Number.isNaN(o)&&!Number.isNaN(n)?-1:Number.isNaN(n)&&!Number.isNaN(o)?1:0},C=(e,t)=>{return 1===e.length?(n=e[0],r=t[0],(e,t)=>S(n(e),n(t))*r):((e,t,n)=>(t.push(0),(r,o)=>{let s,i=0,c=-1;for(;0===i&&c+1<n;)c+=1,s=e[c],i=S(s(r),s(o));return i*t[c]}))(e,t,e.length);var n,r},D=(e,t,n,o=!0)=>{if(t===n)return!0;if(r(t)||r(n))return r(t)&&r(n);if(!i(t)&&!i(n))return t===n;const c=u(t)?t:t[e],l=u(n)?n:n[e];return c===l||!1!==o&&(u(l)?!(!u(c)||l.length!==c.length||!l.every(((e,t)=>e===c[t]))):!!s(l)&&!(!s(c)||Object.keys(l).length!==Object.keys(c).length||!Object.keys(l).every((e=>D(e,l,c)))))};var B=Object.freeze({__proto__:null,black:"#000",defaultColor:"#4c78a8",defaultFont:"sans-serif",defaultFontSize:11,defaultStrokeWidth:2,defaultSymbolSize:30,gray:"#888",lightGray:"#ddd"});function F(e,t,n,o){let s,i,c=-1;e.forEach((e=>{s=t(e),i=n(e),!r(s)&&(s=+s)>=s&&!r(i)&&(i=+i)>=i&&o(s,i,++c)}))}function G(e,t,n,r,o){let s=0,i=0;return F(e,t,n,((e,t)=>{const n=t-o(e),c=t-r;s+=n*n,i+=c*c})),1-s/i}e.Logger=j,e.accessor=a,e.accessorFields=h,e.accessorName=function(e){return r(e)?null:e.fname},e.ascending=S,e.clearLogger=()=>{L=null},e.compare=(e,t,o={})=>{const s=l(t)||[],i=[],c=[],u={},f=o.comparator||C;return l(e).forEach(((e,t)=>{if(r(e))return;i.push("desc"===s[t]?-1:1);const l=n(e)?e:y(e,null,o);c.push(l),(h(l)||[]).forEach((e=>{u[e]=1}))})),0===c.length?null:a(f(c,i),Object.keys(u))},e.emptyObject=E,e.error=v,e.extent=(e,t)=>{const o=n(t)?t:e=>e;let s,i;if(e&&e.length){const t=e.length;for(let n=0;n<t;n+=1){const t=o(e[n]);r(t)||Number.isNaN(t)||(r(s)?(s=t,i=t):(s=Math.min(s,t),i=Math.max(i,t)))}return[s,i]}return[s,i]},e.falsy=O,e.field=y,e.getLogger=(e,n)=>(L&&function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=o(e);return n?"number"===r:"number"===r||t(e,"Number")}(e)?L.level(e):L||(L=new j(e,n)),L),e.getter=p,e.id=m,e.identity=_,e.isEqual=D,e.mergeConfig=(...e)=>e.reduce(((e,t)=>t?(Object.keys(t).forEach((n=>{if("signals"===n)e.signals=function(e,t){if(r(e))return t;const n={},o=[],s=e=>{n[e.name]||(n[e.name]=1,o.push(e))};return t.forEach(s),e.forEach(s),o}(e.signals,t.signals);else{const r="legend"===n?{layout:1}:"style"===n||null;k(e,n,t[n],r)}})),e):e),{}),e.one=d,e.regressionLinear=function(e,t,n){let r=0,o=0,s=0,i=0,c=0;F(e,t,n,((e,t)=>{++c,r+=(e-r)/c,o+=(t-o)/c,s+=(e*t-s)/c,i+=(e*e-i)/c}));const u=function(e,t,n,r){const o=r-e*e,s=Math.abs(o)<1e-24?0:(n-e*t)/o;return[t-s*e,s]}(r,o,s,i),l=e=>u[0]+u[1]*e;return{coef:u,predict:l,rSquared:G(e,t,n,o,l)}},e.setLogLevel=e=>{L?L.level(e):L=new j(e)},e.setLogger=e=>{L=e},e.splitAccessPath=g,e.toPercent=(e,t)=>r(e)?t:Math.min(c(e)?t*parseFloat(e)/100:e,t),e.truthy=N,e.vGrammarConstants=B,e.writeConfig=k,e.zero=b}));
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.VGrammar = global.VGrammar || {}, global.VGrammar.Util = {})));
})(this, (function (exports) { 'use strict';
var eventemitter3 = {exports: {}};
(function (module) {
var has = Object.prototype.hasOwnProperty,
prefix = '~';
/**
* Constructor to create a storage for our `EE` objects.
* An `Events` instance is a plain object whose properties are event names.
*
* @constructor
* @private
*/
function Events() {}
//
// We try to not inherit from `Object.prototype`. In some engines creating an
// instance in this way is faster than calling `Object.create(null)` directly.
// If `Object.create(null)` is not supported we prefix the event names with a
// character to make sure that the built-in object properties are not
// overridden or used as an attack vector.
//
if (Object.create) {
Events.prototype = Object.create(null);
//
// This hack is needed because the `__proto__` property is still inherited in
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
//
if (!new Events().__proto__) prefix = false;
}
/**
* Representation of a single event listener.
*
* @param {Function} fn The listener function.
* @param {*} context The context to invoke the listener with.
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
* @constructor
* @private
*/
function EE(fn, context, once) {
this.fn = fn;
this.context = context;
this.once = once || false;
}
/**
* Add a listener for a given event.
*
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} context The context to invoke the listener with.
* @param {Boolean} once Specify if the listener is a one-time listener.
* @returns {EventEmitter}
* @private
*/
function addListener(emitter, event, fn, context, once) {
if (typeof fn !== 'function') {
throw new TypeError('The listener must be a function');
}
var listener = new EE(fn, context || emitter, once),
evt = prefix ? prefix + event : event;
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);else emitter._events[evt] = [emitter._events[evt], listener];
return emitter;
}
/**
* Clear event by name.
*
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
* @param {(String|Symbol)} evt The Event name.
* @private
*/
function clearEvent(emitter, evt) {
if (--emitter._eventsCount === 0) emitter._events = new Events();else delete emitter._events[evt];
}
/**
* Minimal `EventEmitter` interface that is molded against the Node.js
* `EventEmitter` interface.
*
* @constructor
* @public
*/
function EventEmitter() {
this._events = new Events();
this._eventsCount = 0;
}
/**
* Return an array listing the events for which the emitter has registered
* listeners.
*
* @returns {Array}
* @public
*/
EventEmitter.prototype.eventNames = function eventNames() {
var names = [],
events,
name;
if (this._eventsCount === 0) return names;
for (name in events = this._events) {
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
}
if (Object.getOwnPropertySymbols) {
return names.concat(Object.getOwnPropertySymbols(events));
}
return names;
};
/**
* Return the listeners registered for a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Array} The registered listeners.
* @public
*/
EventEmitter.prototype.listeners = function listeners(event) {
var evt = prefix ? prefix + event : event,
handlers = this._events[evt];
if (!handlers) return [];
if (handlers.fn) return [handlers.fn];
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
ee[i] = handlers[i].fn;
}
return ee;
};
/**
* Return the number of listeners listening to a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Number} The number of listeners.
* @public
*/
EventEmitter.prototype.listenerCount = function listenerCount(event) {
var evt = prefix ? prefix + event : event,
listeners = this._events[evt];
if (!listeners) return 0;
if (listeners.fn) return 1;
return listeners.length;
};
/**
* Calls each of the listeners registered for a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Boolean} `true` if the event had listeners, else `false`.
* @public
*/
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
var evt = prefix ? prefix + event : event;
if (!this._events[evt]) return false;
var listeners = this._events[evt],
len = arguments.length,
args,
i;
if (listeners.fn) {
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
switch (len) {
case 1:
return listeners.fn.call(listeners.context), true;
case 2:
return listeners.fn.call(listeners.context, a1), true;
case 3:
return listeners.fn.call(listeners.context, a1, a2), true;
case 4:
return listeners.fn.call(listeners.context, a1, a2, a3), true;
case 5:
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
case 6:
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
}
for (i = 1, args = new Array(len - 1); i < len; i++) {
args[i - 1] = arguments[i];
}
listeners.fn.apply(listeners.context, args);
} else {
var length = listeners.length,
j;
for (i = 0; i < length; i++) {
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
switch (len) {
case 1:
listeners[i].fn.call(listeners[i].context);
break;
case 2:
listeners[i].fn.call(listeners[i].context, a1);
break;
case 3:
listeners[i].fn.call(listeners[i].context, a1, a2);
break;
case 4:
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
break;
default:
if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
args[j - 1] = arguments[j];
}
listeners[i].fn.apply(listeners[i].context, args);
}
}
}
return true;
};
/**
* Add a listener for a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} [context=this] The context to invoke the listener with.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.on = function on(event, fn, context) {
return addListener(this, event, fn, context, false);
};
/**
* Add a one-time listener for a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} [context=this] The context to invoke the listener with.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.once = function once(event, fn, context) {
return addListener(this, event, fn, context, true);
};
/**
* Remove the listeners of a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn Only remove the listeners that match this function.
* @param {*} context Only remove the listeners that have this context.
* @param {Boolean} once Only remove one-time listeners.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
var evt = prefix ? prefix + event : event;
if (!this._events[evt]) return this;
if (!fn) {
clearEvent(this, evt);
return this;
}
var listeners = this._events[evt];
if (listeners.fn) {
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
clearEvent(this, evt);
}
} else {
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
events.push(listeners[i]);
}
}
//
// Reset the array, or remove it completely if we have no more listeners.
//
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;else clearEvent(this, evt);
}
return this;
};
/**
* Remove all listeners, or those of the specified event.
*
* @param {(String|Symbol)} [event] The event name.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
var evt;
if (event) {
evt = prefix ? prefix + event : event;
if (this._events[evt]) clearEvent(this, evt);
} else {
this._events = new Events();
this._eventsCount = 0;
}
return this;
};
//
// Alias methods names because people roll like that.
//
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
//
// Expose the prefix.
//
EventEmitter.prefixed = prefix;
//
// Allow `EventEmitter` to be imported as module namespace.
//
EventEmitter.EventEmitter = EventEmitter;
//
// Expose the module.
//
{
module.exports = EventEmitter;
}
})(eventemitter3);
var isType = function isType(value, type) {
return toString.call(value) === "[object ".concat(type, "]");
};
var isFunction = function isFunction(value) {
return "function" == typeof value;
};
var isNil = function isNil(value) {
return null == value;
};
var isValid = function isValid(value) {
return null != value;
};
function _typeof(obj) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
var isObject = function isObject(value) {
var type = _typeof(value);
return null !== value && "object" === type || "function" === type;
};
var isObjectLike = function isObjectLike(value) {
return "object" == _typeof(value) && null !== value;
};
var isString = function isString(value) {
var fuzzy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
var type = _typeof(value);
return fuzzy ? "string" === type : "string" === type || isType(value, "String");
};
var isArray = function isArray(value) {
return Array.isArray ? Array.isArray(value) : isType(value, "Array");
};
var isNumber = function isNumber(value) {
var fuzzy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
var type = _typeof(value);
return fuzzy ? "number" === type : "number" === type || isType(value, "Number");
};
var get = function get(obj, path, defaultValue) {
var paths = isString(path) ? path.split(".") : path;
for (var p = 0; p < paths.length; p++) obj = obj ? obj[paths[p]] : void 0;
return void 0 === obj ? defaultValue : obj;
};
function array(arr) {
return isValid(arr) ? isArray(arr) ? arr : [arr] : [];
}
var hasRaf = !1;
try {
hasRaf = "function" == typeof requestAnimationFrame && "function" == typeof cancelAnimationFrame;
} catch (err) {
hasRaf = !1;
}
hasRaf = !1;
var InnerBBox;
!function (InnerBBox) {
InnerBBox[InnerBBox.NONE = 0] = "NONE", InnerBBox[InnerBBox.BBOX1 = 1] = "BBOX1", InnerBBox[InnerBBox.BBOX2 = 2] = "BBOX2";
}(InnerBBox || (InnerBBox = {}));
const accessor = (fn, fields, name) => {
fn.fields = fields || [];
fn.fname = name;
return fn;
};
function accessorName(fn) {
return isNil(fn) ? null : fn.fname;
}
function accessorFields(fn) {
return isNil(fn) ? null : fn.fields;
}
const getter = (path) => {
return (obj) => get(obj, path);
};
function log(method, level, input) {
const args = [level].concat([].slice.call(input));
console[method].apply(console, args);
}
var LoggerLevel;
(function (LoggerLevel) {
LoggerLevel[LoggerLevel["None"] = 0] = "None";
LoggerLevel[LoggerLevel["Error"] = 1] = "Error";
LoggerLevel[LoggerLevel["Warn"] = 2] = "Warn";
LoggerLevel[LoggerLevel["Info"] = 3] = "Info";
LoggerLevel[LoggerLevel["Debug"] = 4] = "Debug";
})(LoggerLevel || (LoggerLevel = {}));
class Logger {
_level;
_method;
constructor(level = LoggerLevel.None, method) {
this._level = level;
this._method = method;
}
canLogInfo() {
return this._level >= LoggerLevel.Info;
}
canLogDebug() {
return this._level >= LoggerLevel.Debug;
}
canLogError() {
return this._level >= LoggerLevel.Error;
}
canLogWarn() {
return this._level >= LoggerLevel.Error;
}
level(levelValue) {
if (arguments.length) {
this._level = +levelValue;
return this;
}
return this._level;
}
error(...args) {
if (this._level >= LoggerLevel.Error) {
log(this._method ?? 'error', 'ERROR', args);
}
return this;
}
warn(...args) {
if (this._level >= LoggerLevel.Warn) {
log(this._method || 'warn', 'WARN', args);
}
return this;
}
info(...args) {
if (this._level >= LoggerLevel.Info) {
log(this._method || 'log', 'INFO', args);
}
return this;
}
debug(...args) {
if (this._level >= LoggerLevel.Debug) {
log(this._method || 'log', 'DEBUG', args);
}
return this;
}
}
let defaultLogger = null;
const setLogger = (logger) => {
defaultLogger = logger;
};
const setLogLevel = (level) => {
if (defaultLogger) {
defaultLogger.level(level);
}
else {
defaultLogger = new Logger(level);
}
};
const clearLogger = () => {
defaultLogger = null;
};
const getLogger = (level, method) => {
if (defaultLogger && isNumber(level)) {
defaultLogger.level(level);
}
else if (!defaultLogger) {
defaultLogger = new Logger(level, method);
}
return defaultLogger;
};
const error = (message) => {
const logger = getLogger();
logger.error(message);
};
const splitAccessPath = (p) => {
const path = [];
const n = p.length;
let q = null;
let b = 0;
let s = '';
let i;
let j;
let c;
p += '';
const push = () => {
path.push(s + p.substring(i, j));
s = '';
i = j + 1;
};
for (i = 0, j = 0; j < n; j += 1) {
c = p[j];
if (c === '\\') {
s += p.substring(i, j);
s += p.substring(++j, ++j);
i = j;
}
else if (c === q) {
push();
q = null;
b = -1;
}
else if (q) {
continue;
}
else if (i === b && c === '"') {
i = j + 1;
q = c;
}
else if (i === b && c === "'") {
i = j + 1;
q = c;
}
else if (c === '.' && !b) {
if (j > i) {
push();
}
else {
i = j + 1;
}
}
else if (c === '[') {
if (j > i) {
push();
}
i = j + 1;
b = i;
}
else if (c === ']') {
if (!b) {
error('Access path missing open bracket: ' + p);
}
if (b > 0) {
push();
}
b = 0;
i = j + 1;
}
}
if (b) {
error('Access path missing closing bracket: ' + p);
}
if (q) {
error('Access path missing closing quote: ' + p);
}
if (j > i) {
j += 1;
push();
}
return path;
};
const field = (fieldStr, name, opt = {}) => {
const path = splitAccessPath(fieldStr);
const parsedField = path.length === 1 ? path[0] : fieldStr;
return accessor(((opt && opt.get) || getter)(path), [parsedField], name || parsedField);
};
const id = field('id');
const identity = accessor(function (_) {
return _;
}, [], 'identity');
const zero = accessor(function () {
return 0;
}, [], 'zero');
const one = accessor(function () {
return 1;
}, [], 'one');
const truthy = accessor(function () {
return true;
}, [], 'true');
const falsy = accessor(function () {
return false;
}, [], 'false');
const emptyObject = accessor(function () {
return {};
}, [], 'emptyObject');
const isLegalKey = (key) => key !== '__proto__';
const writeConfig = (output, key, value, recurse) => {
if (!isLegalKey(key)) {
return;
}
if (isObject(value) && !isArray(value) && !isFunction(value)) {
if (!isObject(output[key])) {
output[key] = {};
}
const outputValue = output[key];
Object.keys(value).forEach((subKey) => {
if (recurse && (recurse === true || recurse[subKey])) {
writeConfig(outputValue, subKey, value[subKey]);
}
else if (isLegalKey(subKey)) {
outputValue[subKey] = value[subKey];
}
});
}
else {
output[key] = value;
}
};
function mergeNamed(a, b) {
if (isNil(a)) {
return b;
}
const map = {};
const out = [];
const add = (_) => {
if (!map[_.name]) {
map[_.name] = 1;
out.push(_);
}
};
b.forEach(add);
a.forEach(add);
return out;
}
const mergeConfig = (...configs) => {
return configs.reduce((out, source) => {
if (!source) {
return out;
}
Object.keys(source).forEach(key => {
if (key === 'signals') {
out.signals = mergeNamed(out.signals, source.signals);
}
else {
const r = key === 'legend' ? { layout: 1 } : key === 'style' ? true : null;
writeConfig(out, key, source[key], r);
}
});
return out;
}, {});
};
const DESCENDING = 'desc';
const ascending = (u, v) => {
if ((u < v || isNil(u)) && !isNil(v)) {
return -1;
}
if ((u > v || isNil(v)) && !isNil(u)) {
return 1;
}
const numericV = v instanceof Date ? +v : v;
const numericU = u instanceof Date ? +u : u;
if (Number.isNaN(numericU) && !Number.isNaN(numericV)) {
return -1;
}
if (Number.isNaN(numericV) && !Number.isNaN(numericU)) {
return 1;
}
return 0;
};
const compare1 = (fieldGetter, order) => (a, b) => {
return ascending(fieldGetter(a), fieldGetter(b)) * order;
};
const compareN = (fields, orders, n) => {
orders.push(0);
return (a, b) => {
let f;
let c = 0;
let i = -1;
while (c === 0 && i + 1 < n) {
i += 1;
f = fields[i];
c = ascending(f(a), f(b));
}
return c * orders[i];
};
};
const comparator = (fields, orders) => fields.length === 1 ? compare1(fields[0], orders[0]) : compareN(fields, orders, fields.length);
const compare = (fields, orders, opt = {}) => {
const arrayOrders = array(orders) || [];
const ord = [];
const get = [];
const fmap = {};
const gen = opt.comparator || comparator;
array(fields).forEach((f, i) => {
if (isNil(f)) {
return;
}
ord.push(arrayOrders[i] === DESCENDING ? -1 : 1);
const fieldGetter = isFunction(f) ? f : field(f, null, opt);
get.push(fieldGetter);
(accessorFields(fieldGetter) || []).forEach((fieldStr) => {
fmap[fieldStr] = 1;
});
});
return get.length === 0 ? null : accessor(gen(get, ord), Object.keys(fmap));
};
const extent = (array, func) => {
const valueGetter = isFunction(func) ? func : (val) => val;
let min;
let max;
if (array && array.length) {
const n = array.length;
for (let i = 0; i < n; i += 1) {
const value = valueGetter(array[i]);
if (!isNil(value) && !Number.isNaN(value)) {
if (isNil(min)) {
min = value;
max = value;
}
else {
min = Math.min(min, value);
max = Math.max(max, value);
}
}
}
return [min, max];
}
return [min, max];
};
const isEqual = (key, current, target, deep = true) => {
if (current === target) {
return true;
}
if (isNil(current) || isNil(target)) {
return isNil(current) && isNil(target);
}
if (!isObjectLike(current) && !isObjectLike(target)) {
return current === target;
}
const c = isArray(current) ? current : current[key];
const t = isArray(target) ? target : target[key];
if (c === t) {
return true;
}
if (deep === false) {
return false;
}
if (isArray(t)) {
if (isArray(c) && t.length === c.length && t.every((v, i) => v === c[i])) {
return true;
}
return false;
}
if (isObject(t)) {
if (isObject(c) && Object.keys(t).length === Object.keys(c).length && Object.keys(t).every(k => isEqual(k, t, c))) {
return true;
}
return false;
}
return false;
};
const toPercent = (percent, total) => {
if (isNil(percent)) {
return total;
}
return Math.min(isString(percent) ? (total * parseFloat(percent)) / 100 : percent, total);
};
const defaultFont = 'sans-serif';
const defaultFontSize = 11;
const defaultSymbolSize = 30;
const defaultStrokeWidth = 2;
const defaultColor = '#4c78a8';
const black = '#000';
const gray = '#888';
const lightGray = '#ddd';
var constants = /*#__PURE__*/Object.freeze({
__proto__: null,
black: black,
defaultColor: defaultColor,
defaultFont: defaultFont,
defaultFontSize: defaultFontSize,
defaultStrokeWidth: defaultStrokeWidth,
defaultSymbolSize: defaultSymbolSize,
gray: gray,
lightGray: lightGray
});
function ordinaryLeastSquares(uX, uY, uXY, uX2) {
const delta = uX2 - uX * uX;
const slope = Math.abs(delta) < 1e-24 ? 0 : (uXY - uX * uY) / delta;
const intercept = uY - slope * uX;
return [intercept, slope];
}
function visitPoints(data, x, y, callback) {
let i = -1;
let u;
let v;
data.forEach(d => {
u = x(d);
v = y(d);
if (!isNil(u) && (u = +u) >= u && !isNil(v) && (v = +v) >= v) {
callback(u, v, ++i);
}
});
}
function rSquared(data, x, y, uY, predict) {
let SSE = 0;
let SST = 0;
visitPoints(data, x, y, (dx, dy) => {
const sse = dy - predict(dx);
const sst = dy - uY;
SSE += sse * sse;
SST += sst * sst;
});
return 1 - SSE / SST;
}
function regressionLinear(data, x, y) {
let X = 0;
let Y = 0;
let XY = 0;
let X2 = 0;
let n = 0;
visitPoints(data, x, y, (dx, dy) => {
++n;
X += (dx - X) / n;
Y += (dy - Y) / n;
XY += (dx * dy - XY) / n;
X2 += (dx * dx - X2) / n;
});
const coef = ordinaryLeastSquares(X, Y, XY, X2);
const predict = (x) => coef[0] + coef[1] * x;
return {
coef: coef,
predict: predict,
rSquared: rSquared(data, x, y, Y, predict)
};
}
exports.Logger = Logger;
exports.accessor = accessor;
exports.accessorFields = accessorFields;
exports.accessorName = accessorName;
exports.ascending = ascending;
exports.clearLogger = clearLogger;
exports.compare = compare;
exports.emptyObject = emptyObject;
exports.error = error;
exports.extent = extent;
exports.falsy = falsy;
exports.field = field;
exports.getLogger = getLogger;
exports.getter = getter;
exports.id = id;
exports.identity = identity;
exports.isEqual = isEqual;
exports.mergeConfig = mergeConfig;
exports.one = one;
exports.regressionLinear = regressionLinear;
exports.setLogLevel = setLogLevel;
exports.setLogger = setLogger;
exports.splitAccessPath = splitAccessPath;
exports.toPercent = toPercent;
exports.truthy = truthy;
exports.vGrammarConstants = constants;
exports.writeConfig = writeConfig;
exports.zero = zero;
}));

@@ -1,1 +0,1 @@

!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).VGrammar=e.VGrammar||{},e.VGrammar.Util={}))}(this,(function(e){"use strict";!function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,r,s,i){if("function"!=typeof r)throw new TypeError("The listener must be a function");var c=new o(r,s||e,i),u=n?n+t:t;return e._events[u]?e._events[u].fn?e._events[u]=[e._events[u],c]:e._events[u].push(c):(e._events[u]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function c(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,r,o=[];if(0===this._eventsCount)return o;for(r in e=this._events)t.call(e,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},c.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,s=r.length,i=new Array(s);o<s;o++)i[o]=r[o].fn;return i},c.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},c.prototype.emit=function(e,t,r,o,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var u,l,f=this._events[c],a=arguments.length;if(f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),a){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,t),!0;case 3:return f.fn.call(f.context,t,r),!0;case 4:return f.fn.call(f.context,t,r,o),!0;case 5:return f.fn.call(f.context,t,r,o,s),!0;case 6:return f.fn.call(f.context,t,r,o,s,i),!0}for(l=1,u=new Array(a-1);l<a;l++)u[l-1]=arguments[l];f.fn.apply(f.context,u)}else{var h,p=f.length;for(l=0;l<p;l++)switch(f[l].once&&this.removeListener(e,f[l].fn,void 0,!0),a){case 1:f[l].fn.call(f[l].context);break;case 2:f[l].fn.call(f[l].context,t);break;case 3:f[l].fn.call(f[l].context,t,r);break;case 4:f[l].fn.call(f[l].context,t,r,o);break;default:if(!u)for(h=1,u=new Array(a-1);h<a;h++)u[h-1]=arguments[h];f[l].fn.apply(f[l].context,u)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,r,o){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||o&&!c.once||r&&c.context!==r||i(this,s);else{for(var u=0,l=[],f=c.length;u<f;u++)(c[u].fn!==t||o&&!c[u].once||r&&c[u].context!==r)&&l.push(c[u]);l.length?this._events[s]=1===l.length?l[0]:l:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&i(this,t)):(this._events=new r,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c}({exports:{}});var t=function(e,t){return toString.call(e)==="[object ".concat(t,"]")},n=function(e){return"function"==typeof e},r=function(e){return null==e};function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}var s=function(e){var t=o(e);return null!==e&&"object"===t||"function"===t},i=function(e){return"object"==o(e)&&null!==e},c=function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=o(e);return n?"string"===r:"string"===r||t(e,"String")},u=function(e){return Array.isArray?Array.isArray(e):t(e,"Array")};function l(e){return null!=e?u(e)?e:[e]:[]}var f;try{"function"==typeof requestAnimationFrame&&"function"==typeof cancelAnimationFrame}catch(e){!1}(function(e){e[e.NONE=0]="NONE",e[e.BBOX1=1]="BBOX1",e[e.BBOX2=2]="BBOX2"})(f||(f={}));const a=(e,t,n)=>(e.fields=t||[],e.fname=n,e);function h(e){return r(e)?null:e.fields}const p=e=>t=>function(e,t,n){for(var r=c(t)?t.split("."):t,o=0;o<r.length;o++)e=e?e[r[o]]:void 0;return void 0===e?n:e}(t,e),v=e=>{if(__DEV__)throw Error(e)},g=e=>{const t=[],n=e.length;let r,o,s,i=null,c=0,u="";e+="";const l=()=>{t.push(u+e.substring(r,o)),u="",r=o+1};for(r=0,o=0;o<n;o+=1)if(s=e[o],"\\"===s)u+=e.substring(r,o),u+=e.substring(++o,++o),r=o;else if(s===i)l(),i=null,c=-1;else{if(i)continue;r===c&&'"'===s||r===c&&"'"===s?(r=o+1,i=s):"."!==s||c?"["===s?(o>r&&l(),r=o+1,c=r):"]"===s&&(c||v("Access path missing open bracket: "+e),c>0&&l(),c=0,r=o+1):o>r?l():r=o+1}return c&&v("Access path missing closing bracket: "+e),i&&v("Access path missing closing quote: "+e),o>r&&(o+=1,l()),t},y=(e,t,n={})=>{const r=g(e),o=1===r.length?r[0]:e;return a((n&&n.get||p)(r),[o],t||o)},m=y("id"),_=a((function(e){return e}),[],"identity"),b=a((function(){return 0}),[],"zero"),d=a((function(){return 1}),[],"one"),N=a((function(){return!0}),[],"true"),O=a((function(){return!1}),[],"false"),E=a((function(){return{}}),[],"emptyObject");function x(e,t,n){const r=[t].concat([].slice.call(n));console[e].apply(console,r)}var w;!function(e){e[e.None=0]="None",e[e.Error=1]="Error",e[e.Warn=2]="Warn",e[e.Info=3]="Info",e[e.Debug=4]="Debug"}(w||(w={}));class j{_level;_method;constructor(e=w.None,t){this._level=e,this._method=t}canLogInfo(){return this._level>=w.Info}canLogDebug(){return this._level>=w.Debug}canLogError(){return this._level>=w.Error}canLogWarn(){return this._level>=w.Error}level(e){return arguments.length?(this._level=+e,this):this._level}error(...e){return(this._level>=w.Error||__DEV__)&&x(this._method??"error","ERROR",e),this}warn(...e){return this._level>=w.Warn&&x(this._method||"warn","WARN",e),this}info(...e){return this._level>=w.Info&&x(this._method||"log","INFO",e),this}debug(...e){return this._level>=w.Debug&&x(this._method||"log","DEBUG",e),this}}let L=null;const A=e=>"__proto__"!==e,k=(e,t,r,o)=>{if(A(t))if(!s(r)||u(r)||n(r))e[t]=r;else{s(e[t])||(e[t]={});const n=e[t];Object.keys(r).forEach((e=>{o&&(!0===o||o[e])?k(n,e,r[e]):A(e)&&(n[e]=r[e])}))}};const S=(e,t)=>{if((e<t||r(e))&&!r(t))return-1;if((e>t||r(t))&&!r(e))return 1;const n=t instanceof Date?+t:t,o=e instanceof Date?+e:e;return Number.isNaN(o)&&!Number.isNaN(n)?-1:Number.isNaN(n)&&!Number.isNaN(o)?1:0},C=(e,t)=>{return 1===e.length?(n=e[0],r=t[0],(e,t)=>S(n(e),n(t))*r):((e,t,n)=>(t.push(0),(r,o)=>{let s,i=0,c=-1;for(;0===i&&c+1<n;)c+=1,s=e[c],i=S(s(r),s(o));return i*t[c]}))(e,t,e.length);var n,r},D=(e,t,n,o=!0)=>{if(t===n)return!0;if(r(t)||r(n))return r(t)&&r(n);if(!i(t)&&!i(n))return t===n;const c=u(t)?t:t[e],l=u(n)?n:n[e];return c===l||!1!==o&&(u(l)?!(!u(c)||l.length!==c.length||!l.every(((e,t)=>e===c[t]))):!!s(l)&&!(!s(c)||Object.keys(l).length!==Object.keys(c).length||!Object.keys(l).every((e=>D(e,l,c)))))};var B=Object.freeze({__proto__:null,black:"#000",defaultColor:"#4c78a8",defaultFont:"sans-serif",defaultFontSize:11,defaultStrokeWidth:2,defaultSymbolSize:30,gray:"#888",lightGray:"#ddd"});function F(e,t,n,o){let s,i,c=-1;e.forEach((e=>{s=t(e),i=n(e),!r(s)&&(s=+s)>=s&&!r(i)&&(i=+i)>=i&&o(s,i,++c)}))}function G(e,t,n,r,o){let s=0,i=0;return F(e,t,n,((e,t)=>{const n=t-o(e),c=t-r;s+=n*n,i+=c*c})),1-s/i}e.Logger=j,e.accessor=a,e.accessorFields=h,e.accessorName=function(e){return r(e)?null:e.fname},e.ascending=S,e.clearLogger=()=>{L=null},e.compare=(e,t,o={})=>{const s=l(t)||[],i=[],c=[],u={},f=o.comparator||C;return l(e).forEach(((e,t)=>{if(r(e))return;i.push("desc"===s[t]?-1:1);const l=n(e)?e:y(e,null,o);c.push(l),(h(l)||[]).forEach((e=>{u[e]=1}))})),0===c.length?null:a(f(c,i),Object.keys(u))},e.emptyObject=E,e.error=v,e.extent=(e,t)=>{const o=n(t)?t:e=>e;let s,i;if(e&&e.length){const t=e.length;for(let n=0;n<t;n+=1){const t=o(e[n]);r(t)||Number.isNaN(t)||(r(s)?(s=t,i=t):(s=Math.min(s,t),i=Math.max(i,t)))}return[s,i]}return[s,i]},e.falsy=O,e.field=y,e.getLogger=(e,n)=>(L&&function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=o(e);return n?"number"===r:"number"===r||t(e,"Number")}(e)?L.level(e):L||(L=new j(e,n)),L),e.getter=p,e.id=m,e.identity=_,e.isEqual=D,e.mergeConfig=(...e)=>e.reduce(((e,t)=>t?(Object.keys(t).forEach((n=>{if("signals"===n)e.signals=function(e,t){if(r(e))return t;const n={},o=[],s=e=>{n[e.name]||(n[e.name]=1,o.push(e))};return t.forEach(s),e.forEach(s),o}(e.signals,t.signals);else{const r="legend"===n?{layout:1}:"style"===n||null;k(e,n,t[n],r)}})),e):e),{}),e.one=d,e.regressionLinear=function(e,t,n){let r=0,o=0,s=0,i=0,c=0;F(e,t,n,((e,t)=>{++c,r+=(e-r)/c,o+=(t-o)/c,s+=(e*t-s)/c,i+=(e*e-i)/c}));const u=function(e,t,n,r){const o=r-e*e,s=Math.abs(o)<1e-24?0:(n-e*t)/o;return[t-s*e,s]}(r,o,s,i),l=e=>u[0]+u[1]*e;return{coef:u,predict:l,rSquared:G(e,t,n,o,l)}},e.setLogLevel=e=>{L?L.level(e):L=new j(e)},e.setLogger=e=>{L=e},e.splitAccessPath=g,e.toPercent=(e,t)=>r(e)?t:Math.min(c(e)?t*parseFloat(e)/100:e,t),e.truthy=N,e.vGrammarConstants=B,e.writeConfig=k,e.zero=b}));
!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).VGrammar=e.VGrammar||{},e.VGrammar.Util={}))}(this,(function(e){"use strict";!function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,r,s,i){if("function"!=typeof r)throw new TypeError("The listener must be a function");var c=new o(r,s||e,i),u=n?n+t:t;return e._events[u]?e._events[u].fn?e._events[u]=[e._events[u],c]:e._events[u].push(c):(e._events[u]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function c(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,r,o=[];if(0===this._eventsCount)return o;for(r in e=this._events)t.call(e,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},c.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,s=r.length,i=new Array(s);o<s;o++)i[o]=r[o].fn;return i},c.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},c.prototype.emit=function(e,t,r,o,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var u,l,f=this._events[c],a=arguments.length;if(f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),a){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,t),!0;case 3:return f.fn.call(f.context,t,r),!0;case 4:return f.fn.call(f.context,t,r,o),!0;case 5:return f.fn.call(f.context,t,r,o,s),!0;case 6:return f.fn.call(f.context,t,r,o,s,i),!0}for(l=1,u=new Array(a-1);l<a;l++)u[l-1]=arguments[l];f.fn.apply(f.context,u)}else{var h,p=f.length;for(l=0;l<p;l++)switch(f[l].once&&this.removeListener(e,f[l].fn,void 0,!0),a){case 1:f[l].fn.call(f[l].context);break;case 2:f[l].fn.call(f[l].context,t);break;case 3:f[l].fn.call(f[l].context,t,r);break;case 4:f[l].fn.call(f[l].context,t,r,o);break;default:if(!u)for(h=1,u=new Array(a-1);h<a;h++)u[h-1]=arguments[h];f[l].fn.apply(f[l].context,u)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,r,o){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||o&&!c.once||r&&c.context!==r||i(this,s);else{for(var u=0,l=[],f=c.length;u<f;u++)(c[u].fn!==t||o&&!c[u].once||r&&c[u].context!==r)&&l.push(c[u]);l.length?this._events[s]=1===l.length?l[0]:l:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&i(this,t)):(this._events=new r,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c}({exports:{}});var t=function(e,t){return toString.call(e)==="[object ".concat(t,"]")},n=function(e){return"function"==typeof e},r=function(e){return null==e};function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}var s=function(e){var t=o(e);return null!==e&&"object"===t||"function"===t},i=function(e){return"object"==o(e)&&null!==e},c=function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=o(e);return n?"string"===r:"string"===r||t(e,"String")},u=function(e){return Array.isArray?Array.isArray(e):t(e,"Array")};function l(e){return null!=e?u(e)?e:[e]:[]}var f;try{"function"==typeof requestAnimationFrame&&"function"==typeof cancelAnimationFrame}catch(e){!1}(function(e){e[e.NONE=0]="NONE",e[e.BBOX1=1]="BBOX1",e[e.BBOX2=2]="BBOX2"})(f||(f={}));const a=(e,t,n)=>(e.fields=t||[],e.fname=n,e);function h(e){return r(e)?null:e.fields}const p=e=>t=>function(e,t,n){for(var r=c(t)?t.split("."):t,o=0;o<r.length;o++)e=e?e[r[o]]:void 0;return void 0===e?n:e}(t,e);function v(e,t,n){const r=[t].concat([].slice.call(n));console[e].apply(console,r)}var g;!function(e){e[e.None=0]="None",e[e.Error=1]="Error",e[e.Warn=2]="Warn",e[e.Info=3]="Info",e[e.Debug=4]="Debug"}(g||(g={}));class y{_level;_method;constructor(e=g.None,t){this._level=e,this._method=t}canLogInfo(){return this._level>=g.Info}canLogDebug(){return this._level>=g.Debug}canLogError(){return this._level>=g.Error}canLogWarn(){return this._level>=g.Error}level(e){return arguments.length?(this._level=+e,this):this._level}error(...e){return this._level>=g.Error&&v(this._method??"error","ERROR",e),this}warn(...e){return this._level>=g.Warn&&v(this._method||"warn","WARN",e),this}info(...e){return this._level>=g.Info&&v(this._method||"log","INFO",e),this}debug(...e){return this._level>=g.Debug&&v(this._method||"log","DEBUG",e),this}}let m=null;const b=(e,n)=>(m&&function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=o(e);return n?"number"===r:"number"===r||t(e,"Number")}(e)?m.level(e):m||(m=new y(e,n)),m),_=e=>{b().error(e)},d=e=>{const t=[],n=e.length;let r,o,s,i=null,c=0,u="";e+="";const l=()=>{t.push(u+e.substring(r,o)),u="",r=o+1};for(r=0,o=0;o<n;o+=1)if(s=e[o],"\\"===s)u+=e.substring(r,o),u+=e.substring(++o,++o),r=o;else if(s===i)l(),i=null,c=-1;else{if(i)continue;r===c&&'"'===s||r===c&&"'"===s?(r=o+1,i=s):"."!==s||c?"["===s?(o>r&&l(),r=o+1,c=r):"]"===s&&(c||_("Access path missing open bracket: "+e),c>0&&l(),c=0,r=o+1):o>r?l():r=o+1}return c&&_("Access path missing closing bracket: "+e),i&&_("Access path missing closing quote: "+e),o>r&&(o+=1,l()),t},N=(e,t,n={})=>{const r=d(e),o=1===r.length?r[0]:e;return a((n&&n.get||p)(r),[o],t||o)},O=N("id"),x=a((function(e){return e}),[],"identity"),E=a((function(){return 0}),[],"zero"),w=a((function(){return 1}),[],"one"),j=a((function(){return!0}),[],"true"),L=a((function(){return!1}),[],"false"),A=a((function(){return{}}),[],"emptyObject"),k=e=>"__proto__"!==e,S=(e,t,r,o)=>{if(k(t))if(!s(r)||u(r)||n(r))e[t]=r;else{s(e[t])||(e[t]={});const n=e[t];Object.keys(r).forEach((e=>{o&&(!0===o||o[e])?S(n,e,r[e]):k(e)&&(n[e]=r[e])}))}};const C=(e,t)=>{if((e<t||r(e))&&!r(t))return-1;if((e>t||r(t))&&!r(e))return 1;const n=t instanceof Date?+t:t,o=e instanceof Date?+e:e;return Number.isNaN(o)&&!Number.isNaN(n)?-1:Number.isNaN(n)&&!Number.isNaN(o)?1:0},B=(e,t)=>{return 1===e.length?(n=e[0],r=t[0],(e,t)=>C(n(e),n(t))*r):((e,t,n)=>(t.push(0),(r,o)=>{let s,i=0,c=-1;for(;0===i&&c+1<n;)c+=1,s=e[c],i=C(s(r),s(o));return i*t[c]}))(e,t,e.length);var n,r},D=(e,t,n,o=!0)=>{if(t===n)return!0;if(r(t)||r(n))return r(t)&&r(n);if(!i(t)&&!i(n))return t===n;const c=u(t)?t:t[e],l=u(n)?n:n[e];return c===l||!1!==o&&(u(l)?!(!u(c)||l.length!==c.length||!l.every(((e,t)=>e===c[t]))):!!s(l)&&!(!s(c)||Object.keys(l).length!==Object.keys(c).length||!Object.keys(l).every((e=>D(e,l,c)))))};var F=Object.freeze({__proto__:null,black:"#000",defaultColor:"#4c78a8",defaultFont:"sans-serif",defaultFontSize:11,defaultStrokeWidth:2,defaultSymbolSize:30,gray:"#888",lightGray:"#ddd"});function G(e,t,n,o){let s,i,c=-1;e.forEach((e=>{s=t(e),i=n(e),!r(s)&&(s=+s)>=s&&!r(i)&&(i=+i)>=i&&o(s,i,++c)}))}function I(e,t,n,r,o){let s=0,i=0;return G(e,t,n,((e,t)=>{const n=t-o(e),c=t-r;s+=n*n,i+=c*c})),1-s/i}e.Logger=y,e.accessor=a,e.accessorFields=h,e.accessorName=function(e){return r(e)?null:e.fname},e.ascending=C,e.clearLogger=()=>{m=null},e.compare=(e,t,o={})=>{const s=l(t)||[],i=[],c=[],u={},f=o.comparator||B;return l(e).forEach(((e,t)=>{if(r(e))return;i.push("desc"===s[t]?-1:1);const l=n(e)?e:N(e,null,o);c.push(l),(h(l)||[]).forEach((e=>{u[e]=1}))})),0===c.length?null:a(f(c,i),Object.keys(u))},e.emptyObject=A,e.error=_,e.extent=(e,t)=>{const o=n(t)?t:e=>e;let s,i;if(e&&e.length){const t=e.length;for(let n=0;n<t;n+=1){const t=o(e[n]);r(t)||Number.isNaN(t)||(r(s)?(s=t,i=t):(s=Math.min(s,t),i=Math.max(i,t)))}return[s,i]}return[s,i]},e.falsy=L,e.field=N,e.getLogger=b,e.getter=p,e.id=O,e.identity=x,e.isEqual=D,e.mergeConfig=(...e)=>e.reduce(((e,t)=>t?(Object.keys(t).forEach((n=>{if("signals"===n)e.signals=function(e,t){if(r(e))return t;const n={},o=[],s=e=>{n[e.name]||(n[e.name]=1,o.push(e))};return t.forEach(s),e.forEach(s),o}(e.signals,t.signals);else{const r="legend"===n?{layout:1}:"style"===n||null;S(e,n,t[n],r)}})),e):e),{}),e.one=w,e.regressionLinear=function(e,t,n){let r=0,o=0,s=0,i=0,c=0;G(e,t,n,((e,t)=>{++c,r+=(e-r)/c,o+=(t-o)/c,s+=(e*t-s)/c,i+=(e*e-i)/c}));const u=function(e,t,n,r){const o=r-e*e,s=Math.abs(o)<1e-24?0:(n-e*t)/o;return[t-s*e,s]}(r,o,s,i),l=e=>u[0]+u[1]*e;return{coef:u,predict:l,rSquared:I(e,t,n,o,l)}},e.setLogLevel=e=>{m?m.level(e):m=new y(e)},e.setLogger=e=>{m=e},e.splitAccessPath=d,e.toPercent=(e,t)=>r(e)?t:Math.min(c(e)?t*parseFloat(e)/100:e,t),e.truthy=j,e.vGrammarConstants=F,e.writeConfig=S,e.zero=E}));

@@ -0,4 +1,6 @@

import { getLogger } from "./logger";
export const error = message => {
if (__DEV__) throw Error(message);
getLogger().error(message);
};
//# sourceMappingURL=error.js.map

@@ -37,3 +37,3 @@ import { isNumber } from "@visactor/vutils";

var _a;
return (this._level >= LoggerLevel.Error || __DEV__) && log(null !== (_a = this._method) && void 0 !== _a ? _a : "error", "ERROR", args),
return this._level >= LoggerLevel.Error && log(null !== (_a = this._method) && void 0 !== _a ? _a : "error", "ERROR", args),
this;

@@ -40,0 +40,0 @@ }

{
"name": "@visactor/vgrammar-util",
"version": "0.2.1",
"version": "0.3.0",
"description": "The common utils functions of VGrammar",

@@ -27,3 +27,3 @@ "keywords": [

"dependencies": {
"@visactor/vutils": "0.9.0-alpha.2"
"@visactor/vutils": "~0.11.1"
},

@@ -30,0 +30,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc