highcharts
Version:
JavaScript charting framework
12 lines • 51.2 kB
JavaScript
/**
* Highcharts JS v13.0.1 (2026-08-17)
* @module highcharts/modules/data-tools
* @requires highcharts
*
* Highcharts
*
* (c) 2010-2026 Highsoft AS
*
* A commercial license may be required depending on use,
* see www.highcharts.com/license
*/import*as e from"../highcharts.js";let t={};t.n=e=>{let r=e&&e.__esModule?()=>e.default:()=>e;return t.d(r,{a:r}),r},t.d=(e,r)=>{if(Array.isArray(r))for(var s=0;s<r.length;){var i=r[s++],n=r[s++];t.o(e,i)?0===n&&s++:0===n?Object.defineProperty(e,i,{enumerable:!0,value:r[s++]}):Object.defineProperty(e,i,{enumerable:!0,get:n})}else for(var i in r)t.o(r,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},t.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let r=e.default;var s=t.n(r);class i{static registerType(e,t){return!!e&&!i.types[e]&&!!(i.types[e]=t)}benchmark(e,t){let s=[],i=this,n=()=>{i.modifyTable(e),i.emit({type:"afterBenchmarkIteration"})},{iterations:o}=(0,r.merge)({iterations:1},t);i.on("afterBenchmarkIteration",()=>{s.length===o?i.emit({type:"afterBenchmark",results:s}):n()});let l={startTime:0,endTime:0};return i.on("modify",()=>{l.startTime=window.performance.now()}),i.on("afterModify",()=>{l.endTime=window.performance.now(),s.push(l.endTime-l.startTime)}),n(),s}emit(e){(0,r.fireEvent)(this,e.type,e)}modify(e,t){let r=this;return new Promise((s,i)=>{e.modified||(e.modified=e.clone(!1,t));try{s(r.modifyTable(e,t))}catch(s){r.emit({type:"error",detail:t,table:e}),i(s instanceof Error?s:Error(""+s))}})}on(e,t){return(0,r.addEvent)(this,e,t)}}i.types={};let n=i,o={convertToNumber:function(e,t){switch(typeof e){case"boolean":return+!!e;case"number":return isNaN(e)&&!t?null:e;default:return isNaN(e=parseFloat(`${e??""}`))&&!t?null:e}},setLength:function(e,t,r){return Array.isArray(e)?(e.length=t,e):e[r?"subarray":"slice"](0,t)},splice:function(e,t,r,s,i=[]){if(Array.isArray(e))return Array.isArray(i)||(i=Array.from(i)),{removed:e.splice(t,r,...i),array:e};let n=Object.getPrototypeOf(e).constructor,o=e[s?"subarray":"slice"](t,t+r),l=new n(e.length-r+i.length);return l.set(e.subarray(0,t),0),l.set(i,t),l.set(e.subarray(t+r),t+i.length),{removed:o,array:l}}},{setLength:l,splice:a}=o,u=class{constructor(e={}){this.isDataTable=!0,this.autoId=!e.id,this.columns={},this.id=e.id||(0,r.uniqueKey)(),this.rowCount=0,this.versionTag=(0,r.uniqueKey)();let t=0;(0,r.objectEach)(e.columns||{},(e,r)=>{this.columns[r]=e.slice(),t=Math.max(t,e.length)}),this.applyRowCount(t)}applyRowCount(e){this.rowCount=e,(0,r.objectEach)(this.columns,(t,r)=>{t.length!==e&&(this.columns[r]=l(t,e))})}deleteRows(e,t=1){if(t>0&&e<this.rowCount){let s=0;(0,r.objectEach)(this.columns,(r,i)=>{this.columns[i]=a(r,e,t).array,s=r.length}),this.rowCount=s}(0,r.fireEvent)(this,"afterDeleteRows",{rowIndex:e,rowCount:t}),this.versionTag=(0,r.uniqueKey)()}getColumn(e,t){return this.columns[e]}getColumns(e,t){return(e||Object.keys(this.columns)).reduce((e,t)=>(e[t]=this.columns[t],e),{})}getRowObject(e,t){let r={},s=this.columns;for(let i of(t??(t=Object.keys(this.columns)),t))r[i]=s[i]?.[e];return r}setColumn(e,t=[],r=0,s){this.setColumns({[e]:t},r,s)}setColumns(e,t,s){let i=this.rowCount;(0,r.objectEach)(e,(e,t)=>{this.columns[t]=e.slice(),i=e.length}),this.applyRowCount(i),s?.silent||((0,r.fireEvent)(this,"afterSetColumns"),this.versionTag=(0,r.uniqueKey)())}setRow(e,t=this.rowCount,s,i){var n;let{columns:o}=this,l=s?this.rowCount+1:t+1,u=Object.keys(e);if(i?.addColumns!==!1)for(let e=0,t=u.length;e<t;e++)o[n=u[e]]||(o[n]=Array(this.rowCount));(0,r.objectEach)(o,(r,i)=>{r&&(s?r=a(r,t,0,!0,[e[i]]).array:r[t]=i in e?e[i]:r[t],o[i]=r)}),this.applyRowCount(Math.max(l,this.rowCount)),i?.silent||((0,r.fireEvent)(this,"afterSetRows",{rowIndex:t}),this.versionTag=(0,r.uniqueKey)())}getModified(){return this.modified||this}},{splice:h,setLength:c}=o;class d extends u{constructor(e={}){super(e),this.metadata=e.metadata}clone(e,t){let r={};this.emit({type:"cloneTable",detail:t}),e||(r.columns=this.columns),this.autoId||(r.id=this.id);let s=new d(r);return e||(s.versionTag=this.versionTag,s.originalRowIndexes=this.originalRowIndexes,s.localRowIndexes=this.localRowIndexes),s.metadata={...this.metadata},this.emit({type:"afterCloneTable",detail:t,tableClone:s}),s}deleteColumns(e,t){let r=this.columns,s={},i={},n=this.modifier,o=this.rowCount;if((e=e||Object.keys(r)).length){this.emit({type:"deleteColumns",columnIds:e,detail:t});for(let t=0,n=e.length,l,a;t<n;++t)(l=r[a=e[t]])&&(s[a]=l,i[a]=Array(o)),delete r[a];return Object.keys(r).length||(this.rowCount=0,this.deleteRowIndexReferences()),n&&n.modifyTable(this),this.emit({type:"afterDeleteColumns",columns:s,columnIds:e,detail:t}),s}}deleteRowIndexReferences(){delete this.originalRowIndexes,delete this.localRowIndexes}deleteRows(e,t=1,s){let i,n,{columns:o,modifier:l}=this,a=[];if((0,r.defined)(e)?Array.isArray(e)?n=(i=e.filter((e,t,r)=>e>=0&&e<this.rowCount&&r.indexOf(e)===t).sort((e,t)=>t-e)).length:(i=[e],n=t):(i=[0],n=this.rowCount),this.emit({type:"deleteRows",detail:s,rowCount:n,rowIndex:e??0}),n>0){let e=Object.keys(o);for(let t=0;t<e.length;++t){let r,s=e[t],l=o[s];if(1===i.length&&n>1){let e=h(l,i[0],n);r=e.removed,o[s]=e.array}else{for(let e of(r=[],i))r.push(l[e]),h(l,e,1);r.reverse()}t||(this.rowCount=l.length);for(let e=0,s=r.length;e<s;++e)a[e]=a[e]||[],a[e][t]=r[e]}}return l&&l.modifyTable(this),this.emit({type:"afterDeleteRows",detail:s,rowCount:n,rowIndex:e??0,rows:a}),a}emit(e){["afterDeleteColumns","afterDeleteRows","afterSetCell","afterSetColumns","afterSetRows"].includes(e.type)&&(this.versionTag=(0,r.uniqueKey)()),(0,r.fireEvent)(this,e.type,e)}getCell(e,t){let r=this.columns[e];if(r)return r[t]}getColumn(e,t){return this.getColumns([e],t)[e]}getColumnIds(){return Object.keys(this.columns)}getColumns(e,t,r){let s=this.columns,i={};e=e||Object.keys(s);for(let n=0,o=e.length,l,a;n<o;++n)(l=s[a=e[n]])&&(t?i[a]=l:r&&!Array.isArray(l)?i[a]=Array.from(l):i[a]=l.slice());return i}getLocalRowIndex(e){let{localRowIndexes:t}=this;return t?t[e]:e}getModifier(){return this.modifier}getOriginalRowIndex(e){let{originalRowIndexes:t}=this;return t?t[e]:e}getRow(e,t){return this.getRows(e,1,t)[0]}getRowCount(){return this.rowCount}getRowIndexBy(e,t,s){let i=this.columns[e];if(i){let e=-1;if(Array.isArray(i)?e=i.indexOf(t,s):(0,r.isNumber)(t)&&(e=i.indexOf(t,s)),-1!==e)return e}}getRowObject(e,t){return this.getRowObjects(e,1,t)[0]}getRowObjects(e=0,t=this.rowCount-e,r){let s=this.columns,i=Array(t);r=r||Object.keys(s);for(let n=e,o=0,l=Math.min(this.rowCount,e+t),a,u;n<l;++n,++o)for(let e of(u=i[o]={},r))a=s[e],u[e]=a?a[n]:void 0;return i}getRows(e=0,t=this.rowCount-e,r){let s=this.columns,i=Array(t);r=r||Object.keys(s);for(let n=e,o=0,l=Math.min(this.rowCount,e+t),a,u;n<l;++n,++o)for(let e of(u=i[o]=[],r))a=s[e],u.push(a?a[n]:void 0);return i}getVersionTag(){return this.versionTag}hasColumns(e){let t=this.columns;for(let r=0,s=e.length;r<s;++r)if(!t[e[r]])return!1;return!0}hasRowWith(e,t){let s=this.columns[e];return Array.isArray(s)?-1!==s.indexOf(t):!!((0,r.defined)(t)&&Number.isFinite(t))&&-1!==s.indexOf(+t)}on(e,t){return(0,r.addEvent)(this,e,t)}changeColumnId(e,t){let r=this.columns;return!!r[e]&&(e!==t&&(r[t]=r[e],delete r[e]),!0)}setCell(e,t,r,s){let i=this.columns,n=this.modifier,o=i[e];o&&o[t]===r||(this.emit({type:"setCell",cellValue:r,columnId:e,detail:s,rowIndex:t}),o||(o=i[e]=Array(this.rowCount)),t>=this.rowCount&&(this.rowCount=t+1),o[t]=r,n&&n.modifyTable(this),this.emit({type:"afterSetCell",cellValue:r,columnId:e,detail:s,rowIndex:t}))}setColumns(e,t,s,i){let n=this.columns,o=this.modifier,l=Object.keys(e),a=this.rowCount;if(this.emit({type:"setColumns",columns:e,columnIds:l,detail:s,rowIndex:t}),(0,r.defined)(t)||i){for(let r=0,s=l.length,o,u,h,c;r<s;++r){o=e[h=l[r]],c=Object.getPrototypeOf((u=n[h])&&i?u:o).constructor,u?c===Array?Array.isArray(u)||(u=Array.from(u)):u.length<a&&(u=new c(a)).set(n[h]):u=new c(a),n[h]=u;for(let e=t||0,r=o.length;e<r;++e)u[e]=o[e];a=Math.max(a,o.length)}this.applyRowCount(a)}else super.setColumns(e,t,(0,r.extend)(s,{silent:!0}));o&&o.modifyTable(this),this.emit({type:"afterSetColumns",columns:e,columnIds:l,detail:s,rowIndex:t})}setModifier(e,t){let r=this;return r.emit({type:"setModifier",detail:t,modifier:e,modified:r.getModified()}),r.modifier=e,(e?e.modify(r):Promise.resolve(r)).then(r=>(r.emit({type:"afterSetModifier",detail:t,modifier:e,modified:r.getModified()}),r)).catch(t=>{throw r.emit({type:"setModifierError",error:t,modifier:e,modified:r.getModified()}),t})}setOriginalRowIndexes(e,t=!1){if(this.originalRowIndexes=e,t)return;let s=this.localRowIndexes=[];for(let t=0,i=e.length,n;t<i;++t)n=e[t],(0,r.defined)(n)&&(s[n]=t)}setRow(e,t,r,s){this.setRows([e],t,r,s)}setRows(e,t=this.rowCount,r,s){let i=this.columns,n=Object.keys(i),o=this.modifier,l=e.length;this.emit({type:"setRows",detail:s,rowCount:l,rowIndex:t,rows:e});for(let s=0,o=t,a;s<l;++s,++o)if(0===Object.keys(a=e[s]).length)for(let e=0,t=n.length;e<t;++e){let t=i[n[e]];r?i[n[e]]=h(t,o,0,!0,[null]).array:t[o]=null}else if(Array.isArray(a))for(let e=0,t=n.length;e<t;++e)i[n[e]][o]=a[e];else super.setRow(a,o,r,{silent:!0});let a=r?l+e.length:t+l;if(a>this.rowCount){this.rowCount=a;for(let e=0,t=n.length;e<t;++e){let t=n[e];i[t]=c(i[t],a)}}o&&o.modifyTable(this),this.emit({type:"afterSetRows",detail:s,rowCount:l,rowIndex:t,rows:e})}}class f{static registerType(e,t){return!!e&&!f.types[e]&&!!(f.types[e]=t)}get polling(){return!!this._polling}constructor(e){this.dataTables={},this.loaded=!1,this.metadata=e.metadata||{columns:{}},this.options=e;let t=e?.dataTables,r=0;if(e.options&&console.error("The `DataConnectorOptions.options` property was removed in Dashboards v4.0.0. Check how to upgrade your connector to use the new options structure here: https://api.highcharts.com/dashboards/#interfaces/Data_DataTableOptions.DataTableOptions"),t&&t?.length>0)for(let e=0,s=t.length;e<s;++e){let s=t[e],i=s?.key;this.dataTables[i??r]=new d(s),!i&&r++}else this.dataTables[0]=new d({id:e.id})}getTable(e){return e?this.dataTables[e]:Object.values(this.dataTables)[0]}describeColumn(e,t){let s=this.metadata.columns;s[e]=(0,r.merge)(s[e]||{},t)}describeColumns(e){let t,r=Object.keys(e);for(;"string"==typeof(t=r.pop());)this.describeColumn(t,e[t])}getColumnOrder(){let e=this.metadata.columns,t=Object.keys(e||{});if(t.length)return t.sort((t,s)=>(0,r.pick)(e[t].index,0)-(0,r.pick)(e[s].index,0))}getSortedColumns(){return this.getTable().getColumns(this.getColumnOrder())}setColumnOrder(e){for(let t=0,r=e.length;t<r;++t)this.describeColumn(e[t],{index:t})}async update(e,t=!0){this.emit({type:"beforeUpdate"}),(0,r.merge)(!0,this.options,e);let{options:s}=this;("enablePolling"in e||"dataRefreshRate"in e)&&("enablePolling"in s&&s.enablePolling?(this.stopPolling(),this.startPolling("dataRefreshRate"in s&&"number"==typeof s.dataRefreshRate?1e3*Math.max(s.dataRefreshRate,1):1e3)):this.stopPolling()),t&&await this.load(),this.emit({type:"afterUpdate"})}load(){return this.emit({type:"afterLoad"}),Promise.resolve(this)}async applyTableModifiers(){let e=this.options?.dataTables;for(let[t,r]of Object.entries(this.dataTables)){let s=e?.find(e=>e.key===t)?.dataModifier??this.options?.dataModifier;if(!s)continue;let i=s&&n.types[s.type];await r.setModifier(i?new i(s):void 0)}return this}startPolling(e=1e3){let t=this;this.pollingController=new AbortController,window.clearTimeout(t._polling),t._polling=window.setTimeout(()=>t.load().catch(e=>t.emit({type:"loadError",error:e})).then(()=>{t._polling&&t.startPolling(e)}),e)}stopPolling(){this.polling&&(this?.pollingController?.abort(),window.clearTimeout(this._polling),delete this._polling)}emit(e){(0,r.fireEvent)(this,e.type,e)}on(e,t){return(0,r.addEvent)(this,e,t)}initConverters(e,t,r){let s=0;for(let[i,n]of Object.entries(this.dataTables)){let o=t(i),l=r(o,e);n.deleteColumns(),n.setColumns(l),0===s&&(this.converter=o),s++}}}f.types={};let p=f;function m(e,t){return"string"==typeof e&&(e=e.replace(/^\s+|\s+$/g,""),t&&/^[\d\s]+$/.test(e)&&(e=e.replace(/\s/g,""))),e}let g=function(e,t){let r;if("string"==typeof e)r=t.parseDate(e);else if("number"==typeof e)r=e;else{if(e instanceof Date)return e;r=t.parseDate(""+e)}return new Date(r)},y=function(e,t){if("number"==typeof e)return e;if("boolean"==typeof e)return+!!e;if("string"==typeof e){if(e.indexOf(" ")>-1&&(e=e.replace(/\s+/g,"")),t){if(!t.test(e))return NaN;e=e.replace(t,"$1.$2")}return parseFloat(e)}return e instanceof Date?e.getDate():e?e.getRowCount():NaN},b=function(e){return""+e},w=function(e=[],t){let r={};for(let s=0,i=Math.max(t.length,e.length);s<i;++s)r[t[s]||`${s}`]=e[s]?e[s].slice():[];return r},C=function(e,t){let s="string";if("string"==typeof e){let i=m(`${e}`),n=t.decimalRegExp,o=m(i,!0);n&&(o=n.test(o)?o.replace(n,"$1.$2"):"");let l=parseFloat(o);if(+o===l)e=l;else{let i=t.parseDate(e);s=(0,r.isNumber)(i)?"Date":"string"}}return"number"==typeof e&&(s=e>31536e6?"Date":"number"),s};class R{static registerType(e,t){return!!e&&!R.types[e]&&!!(R.types[e]=t)}constructor(e){this.dateFormats={"YYYY/mm/dd":{regex:/^(\d{4})([\-\.\/])(\d{1,2})\2(\d{1,2})$/,parser:function(e){return e?Date.UTC(+e[1],e[3]-1,+e[4]):NaN}},"dd/mm/YYYY":{regex:/^(\d{1,2})([\-\.\/])(\d{1,2})\2(\d{4})$/,parser:function(e){return e?Date.UTC(+e[4],e[3]-1,+e[1]):NaN},alternative:"mm/dd/YYYY"},"mm/dd/YYYY":{regex:/^(\d{1,2})([\-\.\/])(\d{1,2})\2(\d{4})$/,parser:function(e){return e?Date.UTC(+e[4],e[1]-1,+e[3]):NaN}},"dd/mm/YY":{regex:/^(\d{1,2})([\-\.\/])(\d{1,2})\2(\d{2})$/,parser:function(e){let t=new Date;if(!e)return NaN;let r=+e[4];return r>t.getFullYear()-2e3?r+=1900:r+=2e3,Date.UTC(r,e[3]-1,+e[1])},alternative:"mm/dd/YY"},"mm/dd/YY":{regex:/^(\d{1,2})([\-\.\/])(\d{1,2})\2(\d{2})$/,parser:function(e){return e?Date.UTC(+e[4]+2e3,e[1]-1,+e[3]):NaN}}};let t=(0,r.merge)(R.defaultOptions,e),s=t.decimalPoint;("."===s||","===s)&&(s="."===s?"\\.":",",this.decimalRegExp=RegExp("^(-?[0-9]+)"+s+"([0-9]+)$")),this.options=t}convertByType(e){let t=this;return({number:e=>y(e,t.decimalRegExp),Date:e=>g(e,t),string:b})[C(e,t)].call(t,e)}deduceDateFormat(e,t,r){let s=[],i=[],n="YYYY/mm/dd",o,l=[],a=0,u=!1,h,c;for((!t||t>e.length)&&(t=e.length);a<t;a++)if(void 0!==e[a]&&e[a]&&e[a].length)for(c=0,o=e[a].trim().replace(/[\-\.\/]/g," ").split(" "),l=["","",""];c<o.length;c++)c<l.length&&(h=parseInt(o[c],10))&&(i[c]=!i[c]||i[c]<h?h:i[c],void 0!==s[c]?s[c]!==h&&(s[c]=!1):s[c]=h,h>31?h<100?l[c]="YY":l[c]="YYYY":h>12&&h<=31?(l[c]="dd",u=!0):l[c].length||(l[c]="mm"));if(u){for(c=0;c<s.length;c++)!1!==s[c]?i[c]>12&&"YY"!==l[c]&&"YYYY"!==l[c]&&(l[c]="YY"):i[c]>12&&"mm"===l[c]&&(l[c]="dd");3===l.length&&"dd"===l[1]&&"dd"===l[2]&&(l[2]="YY"),n=l.join("/")}return r&&(this.options.dateFormat=n),n}emit(e){(0,r.fireEvent)(this,e.type,e)}on(e,t){return(0,r.addEvent)(this,e,t)}parseDate(e,t){let r=this.options,s=t||r.dateFormat,i=NaN,n,o=null;if(r.parseDate)i=r.parseDate(e);else{let t=this.dateFormats;if(s){let r=t[s];r||(r=t["YYYY/mm/dd"]),(o=e.match(r.regex))&&(i=r.parser(o))}else for(n in t){let r=t[n];if(o=e.match(r.regex)){s=n,i=r.parser(o);break}}if(!o){let t=Date.parse(e);!isNaN(t)&&(i=t-6e4*new Date(t).getTimezoneOffset(),e.includes("2001")||2001!==new Date(i).getFullYear()||(i=NaN))}}return i}}R.defaultOptions={dateFormat:"",firstRowAsNames:!0},R.types={};let N=R;function T(e,t){if("position"===e.type){for(let r,s=0,i=t.length;s<i;++s)if("position"===(r=t[s]).type&&r.state===e.state&&r.column===e.column&&r.row===e.row)return s}else{let r=JSON.stringify(e.columns);for(let s,i=0,n=t.length;i<n;++i)if("range"===(s=t[i]).type&&s.state===e.state&&s.firstRow===e.firstRow&&s.lastRow===e.lastRow&&JSON.stringify(s.columns)===r)return i}return -1}let O=class{constructor(e={}){this.emittingRegister=[],this.listenerMap={},this.stateMap=e}addListener(e,t,r){let s=this.listenerMap[e]=this.listenerMap[e]||{};return(s[t]=s[t]||[]).push(r),this}buildEmittingTag(e){return("position"===e.cursor.type?[e.table.id,e.cursor.column,e.cursor.row,e.cursor.state,e.cursor.type]:[e.table.id,e.cursor.columns,e.cursor.firstRow,e.cursor.lastRow,e.cursor.state,e.cursor.type]).join("\0")}emitCursor(e,t,r,s){let i=e.id,n=t.state,o=this.listenerMap[i]&&this.listenerMap[i][n];if(o){let n=this.stateMap[i]=this.stateMap[i]??{},l=n[t.state]||[];s&&(l.length||(n[t.state]=l),-1===T(t,l)&&l.push(t));let a={cursor:t,cursors:l,table:e};r&&(a.event=r);let u=this.emittingRegister,h=this.buildEmittingTag(a);if(u.indexOf(h)>=0)return this;try{this.emittingRegister.push(h);for(let e=0,t=o.length;e<t;++e)o[e].call(this,a)}finally{let e=this.emittingRegister.indexOf(h);e>=0&&this.emittingRegister.splice(e,1)}}return this}remitCursor(e,t){let r=this.stateMap[e]&&this.stateMap[e][t.state];if(r){let e=T(t,r);e>=0&&r.splice(e,1)}return this}removeListener(e,t,r){let s=this.listenerMap[e]&&this.listenerMap[e][t];if(s){let e=s.indexOf(r);e>=0&&s.splice(e,1)}return this}};class v{constructor(e){this.options=(0,r.merge)(v.defaultOptions,e),this.connectors={},this.waiting={}}emit(e){(0,r.fireEvent)(this,e.type,e)}getConnector(e){let t=this.connectors[e];if(t?.loaded)return Promise.resolve(t);let r=this.waiting[e];if(!r){r=this.waiting[e]=[];let t=this.getConnectorOptions(e);if(!t)throw Error(`Connector '${e}' not found.`);this.loadConnector(t).then(t=>{delete this.waiting[e];for(let e=0,s=r.length;e<s;++e)r[e][0](t)}).catch(t=>{delete this.waiting[e];for(let e=0,s=r.length;e<s;++e)r[e][1](t)})}return new Promise((e,t)=>{r.push([e,t])})}getConnectorIds(){let e=this.options.connectors,t=[];for(let r=0,s=e.length;r<s;++r)t.push(e[r].id);return t}getConnectorOptions(e){let t=this.options.connectors;for(let r=0,s=t.length;r<s;++r)if(t[r].id===e)return t[r]}isNewConnector(e){return!this.connectors[e]}loadConnector(e){return new Promise((t,r)=>{this.emit({type:"load",options:e});let s=p.types[e.type];if(!s)throw Error(`Connector type not found. (${e.type})`);let i=this.connectors[e.id]=new s(e);i.load().then(({converter:r})=>{i.converter=r,i.loaded=!0,this.emit({type:"afterLoad",options:e}),t(i)}).catch(r)})}cancelPendingRequests(){let{connectors:e}=this;for(let t of Object.keys(e))e[t].stopPolling()}on(e,t){return(0,r.addEvent)(this,e,t)}async setConnectorOptions(e,t){let r=this.options.connectors,s=this.connectors;this.emit({type:"setConnectorOptions",options:e});for(let t=0,s=r.length;t<s;++t)if(r[t].id===e.id){r.splice(t,1);break}let i=s[e.id];i&&(t?await i.update(e,!0):(i.stopPolling(),i=void 0,delete s[e.id])),i||r.push(e),this.emit({type:"afterSetConnectorOptions",options:e})}}v.defaultOptions={connectors:[]};let A=/^(?:FALSE|TRUE)/,M=/^[+\-]?\d+(?:\.\d+)?(?:e[+\-]\d+)?/,E=/^[+\-]?\d+(?:,\d+)?(?:e[+\-]\d+)?/,I=/^([A-Z][A-Z\d\.]*)\(/,x=/^(?:[+\-*\/^<=>]|<=|=>)/,F=/^(\$?[A-Z]+)(\$?\d+)\:(\$?[A-Z]+)(\$?\d+)/,D=/^R(\d*|\[\d+\])C(\d*|\[\d+\])\:R(\d*|\[\d+\])C(\d*|\[\d+\])/,P=/^(\$?[A-Z]+)(\$?\d+)(?![\:C])/,j=/^R(\d*|\[\d+\])C(\d*|\[\d+\])(?!\:)/;function k(e){let t=0;for(let r=0,s=e.length,i,n=1;r<s;++r){if("("===(i=e[r])){t||(n=r+1),++t;continue}if(")"===i&&!--t)return e.substring(n,r)}if(t>0){let e=Error("Incomplete parentheses.");throw e.name="FormulaParseError",e}return""}function L(e){let t=-1;for(let r=0,s=e.length,i,n=!1;r<s;++r){if("\\"===(i=e[r])){n=!n;continue}if(n){n=!1;continue}if('"'===i)if(!(t<0))return e.substring(t+1,r);else t=r}let r=Error("Incomplete string.");throw r.name="FormulaParseError",r}function Y(e,t){let r;if(r=e.match(D)){let e=""===r[2]||"["===r[2][0],t=""===r[1]||"["===r[1][0],s=""===r[4]||"["===r[4][0],i=""===r[3]||"["===r[3][0],n={type:"range",beginColumn:e?parseInt(r[2].substring(1,-1)||"0",10):parseInt(r[2],10)-1,beginRow:t?parseInt(r[1].substring(1,-1)||"0",10):parseInt(r[1],10)-1,endColumn:s?parseInt(r[4].substring(1,-1)||"0",10):parseInt(r[4],10)-1,endRow:i?parseInt(r[3].substring(1,-1)||"0",10):parseInt(r[3],10)-1};return e&&(n.beginColumnRelative=!0),t&&(n.beginRowRelative=!0),s&&(n.endColumnRelative=!0),i&&(n.endRowRelative=!0),n}if(r=e.match(F)){let e="$"!==r[1][0],t="$"!==r[2][0],s="$"!==r[3][0],i="$"!==r[4][0],n={type:"range",beginColumn:$(e?r[1]:r[1].substring(1))-1,beginRow:parseInt(t?r[2]:r[2].substring(1),10)-1,endColumn:$(s?r[3]:r[3].substring(1))-1,endRow:parseInt(i?r[4]:r[4].substring(1),10)-1};return e&&(n.beginColumnRelative=!0),t&&(n.beginRowRelative=!0),s&&(n.endColumnRelative=!0),i&&(n.endRowRelative=!0),n}let s=V(e,t);return 1===s.length&&"string"!=typeof s[0]?s[0]:s}function S(e){let t=e.length,s=e[t-2];return"-"===e[t-1]&&(0,r.isString)(s)&&!!s.match(/\*|\/|\^/)}function V(e,t){let r=t?E:M,s=[],i,n=("="===e[0]?e.substring(1):e).trim();for(;n;){if(i=n.match(j)){let e=""===i[2]||"["===i[2][0],t=""===i[1]||"["===i[1][0],r={type:"reference",column:e?parseInt(i[2].substring(1,-1)||"0",10):parseInt(i[2],10)-1,row:t?parseInt(i[1].substring(1,-1)||"0",10):parseInt(i[1],10)-1};e&&(r.columnRelative=!0),t&&(r.rowRelative=!0),S(s)&&(s.pop(),r.isNegative=!0),s.push(r),n=n.substring(i[0].length).trim();continue}if(i=n.match(P)){let e="$"!==i[1][0],t="$"!==i[2][0],r={type:"reference",column:$(e?i[1]:i[1].substring(1))-1,row:parseInt(t?i[2]:i[2].substring(1),10)-1};e&&(r.columnRelative=!0),t&&(r.rowRelative=!0),S(s)&&(s.pop(),r.isNegative=!0),s.push(r),n=n.substring(i[0].length).trim();continue}if(i=n.match(x)){s.push(i[0]),n=n.substring(i[0].length).trim();continue}if(i=n.match(A)){s.push("TRUE"===i[0]),n=n.substring(i[0].length).trim();continue}if(i=n.match(r)){let e=parseFloat(i[0]);S(s)&&(s.pop(),e=-e),s.push(e),n=n.substring(i[0].length).trim();continue}if('"'===n[0]){let e=L(n);s.push(e.substring(1,-1)),n=n.substring(e.length+2).trim();continue}if(i=n.match(I)){let e=k(n=n.substring(i[1].length).trim());s.push({type:"function",name:i[1],args:function(e,t){let r=[],s=t?";":",",i=0,n="";for(let o=0,l=e.length,a;o<l;++o)if((a=e[o])===s&&!i&&n)r.push(Y(n,t)),n="";else if('"'!==a||i||n)" "!==a&&(n+=a,"("===a?++i:")"===a&&--i);else{let t=L(e.substring(o));r.push(t),o+=t.length+1}return!i&&n&&r.push(Y(n,t)),r}(e,t)}),n=n.substring(e.length+2).trim();continue}if("("===n[0]){let e=k(n);if(e){s.push(V(e,t)),n=n.substring(e.length+2).trim();continue}}let o=e.length-n.length,l=Error("Unexpected character `"+e.substring(o,o+1)+"` at position "+(o+1)+". (`..."+e.substring(o-5,o+6)+"...`)");throw l.name="FormulaParseError",l}return s}function $(e){let t=0;for(let r=0,s=e.length,i,n=e.length-1;r<s;++r)(i=e.charCodeAt(r))>=65&&i<=90&&(t+=(i-64)*Math.pow(26,n)),--n;return t}let U={parseFormula:V},H=["+","-","*","/","^","=","<","<=",">",">="],_={isFormula:function(e){return Array.isArray(e)},isFunction:function(e){return"object"==typeof e&&!Array.isArray(e)&&"function"===e.type},isOperator:function(e){return"string"==typeof e&&H.indexOf(e)>=0},isRange:function(e){return"object"==typeof e&&!Array.isArray(e)&&"range"===e.type},isReference:function(e){return"object"==typeof e&&!Array.isArray(e)&&"reference"===e.type},isValue:function(e){return"boolean"==typeof e||"number"==typeof e||"string"==typeof e}},{isFormula:B,isFunction:Z,isOperator:K,isRange:X,isReference:q,isValue:G}=_,J=/ */,W=Number.MAX_VALUE/1.000000000001,z=Number.MAX_VALUE/1.000000000002,Q=Number.MAX_VALUE,ee={"^":3,"*":2,"/":2,"+":1,"-":1,"=":0,"<":0,"<=":0,">":0,">=":0},et={},er=/^[A-Z][A-Z\.]*$/;function es(e){switch(typeof e){case"boolean":return e?Q:W;case"string":return z;case"number":return e;default:return NaN}}function ei(e){return"string"==typeof e?e.toLowerCase().replace(J,"\0"):e}function en(e){switch(typeof e){case"boolean":return+!!e;case"string":return parseFloat(e.replace(",","."));case"number":return e;default:return NaN}}function eo(e,t){return G(e)?e:X(e)?t&&el(e,t)||[]:Z(e)?ec(e,t):eh(B(e)?e:[e],t)}function el(e,t){let r=t.getColumnIds().slice(e.beginColumn,e.endColumn+1),s=[];for(let i=0,n=r.length,o;i<n;++i){let n=t.getColumn(r[i],!0)||[];for(let l=e.beginRow,a=e.endRow+1;l<a;++l)"string"==typeof(o=n[l])&&"="===o[0]&&t!==t.getModified()&&(o=t.getModified().getCell(r[i],l)),s.push(G(o)?o:NaN)}return s}function ea(e,t){let r=t.getColumnIds()[e.column];if(r){let s=t.getCell(r,e.row);if("string"==typeof s&&"="===s[0]&&t!==t.getModified()){let s=t.getModified().getCell(r,e.row);return G(s)?s:NaN}if(G(s))return e.isNegative?-s:s}return NaN}function eu(e,t){(e.length<2||t.length<1)&&e.push(NaN);let s=e.pop(),i=e.pop(),n=t.pop();(0,r.defined)(s)&&(0,r.defined)(i)&&(0,r.defined)(n)?e.push(function(e,t,r){let s;switch(e){case"=":return ei(t)===ei(r);case"<":if(typeof t==typeof r)return ei(t)<ei(r);return es(t)<es(r);case"<=":if(typeof t==typeof r)return ei(t)<=ei(r);return es(t)<=es(r);case">":if(typeof t==typeof r)return ei(t)>ei(r);return es(t)>es(r);case">=":if(typeof t==typeof r)return ei(t)>=ei(r);return es(t)>=es(r)}switch(t=en(t),r=en(r),e){case"+":s=t+r;break;case"-":s=t-r;break;case"*":s=t*r;break;case"/":s=t/r;break;case"^":s=Math.pow(t,r);break;default:return NaN}return s%1?Math.round(1e9*s)/1e9:s}(n,i,s)):e.push(NaN)}function eh(e,t){let r=[],s=[],i=!0;for(let n=0,o=e.length;n<o;++n){let o,l=e[n];if(K(l)){if(i&&"-"===l)r.push(0),s.push("-"),i=!0;else{for(;s.length&&ee[s[s.length-1]]>=ee[l];)eu(r,s);s.push(l),i=!0}continue}if(G(l))o=l;else if(q(l))o=t?ea(l,t):NaN;else if(Z(l)){let e=ec(l,t);o=G(e)?e:NaN}else B(l)&&(o=eh(l,t));if(void 0===o)return NaN;r.push(o),i=!1}for(;s.length;)eu(r,s);return 1!==r.length?NaN:r[0]}function ec(e,t,r){let s=et[e.name];if(s)try{return s(e.args,t)}catch{return NaN}let i=Error(`Function "${e.name}" not found.`);throw i.name="FormulaProcessError",i}let ed={asNumber:en,getArgumentValue:eo,getArgumentsValues:function(e,t){let r=[];for(let s=0,i=e.length;s<i;++s)r.push(eo(e[s],t));return r},getRangeValues:el,getReferenceValue:ea,processFormula:eh,processorFunctions:et,registerProcessorFunction:function(e,t){return er.test(e)&&!et[e]&&!!(et[e]=t)},translateReferences:function e(t,r=0,s=0){for(let i=0,n=t.length,o;i<n;++i)Array.isArray(o=t[i])?e(o,r,s):Z(o)?e(o.args,r,s):X(o)?(o.beginColumnRelative&&(o.beginColumn+=r),o.beginRowRelative&&(o.beginRow+=s),o.endColumnRelative&&(o.endColumn+=r),o.endRowRelative&&(o.endRow+=s)):q(o)&&(o.columnRelative&&(o.column+=r),o.rowRelative&&(o.row+=s));return t}},{getArgumentValue:ef}=ed;ed.registerProcessorFunction("ABS",function(e,t){let r=ef(e[0],t);switch(typeof r){case"number":return Math.abs(r);case"object":{let e=[];for(let t=0,s=r.length,i;t<s;++t){if("number"!=typeof(i=r[t]))return NaN;e.push(Math.abs(i))}return e}default:return NaN}});let{getArgumentValue:ep}=ed;ed.registerProcessorFunction("AND",function e(t,r){for(let s=0,i=t.length,n;s<i;++s)if(!(n=ep(t[s],r))||"object"==typeof n&&!e(n,r))return!1;return!0});let{getArgumentsValues:em}=ed;ed.registerProcessorFunction("AVERAGE",function(e,t){let r=em(e,t),s=0,i=0;for(let e=0,t=r.length,n;e<t;++e)switch(typeof(n=r[e])){case"number":isNaN(n)||(++s,i+=n);break;case"object":for(let e=0,t=n.length,r;e<t;++e)"number"!=typeof(r=n[e])||isNaN(r)||(++s,i+=r)}return s?i/s:0});let{getArgumentValue:eg}=ed;ed.registerProcessorFunction("AVERAGEA",function(e,t){let r=0,s=0;for(let i=0,n=e.length,o;i<n;++i)switch(typeof(o=eg(e[i],t))){case"boolean":++r,s+=+!!o;continue;case"number":isNaN(o)||(++r,s+=o);continue;case"string":++r;continue;default:for(let e=0,t=o.length,i;e<t;++e)switch(typeof(i=o[e])){case"boolean":++r,s+=+!!i;continue;case"number":isNaN(i)||(++r,s+=i);continue;case"string":++r;continue}continue}return r?s/r:0}),ed.registerProcessorFunction("COUNT",function e(t,r){let s=ed.getArgumentsValues(t,r),i=0;for(let t=0,n=s.length,o;t<n;++t)switch(typeof(o=s[t])){case"number":!isNaN(o)&&++i;break;case"object":i+=e(o,r)}return i}),ed.registerProcessorFunction("COUNTA",function e(t,r){let s=ed.getArgumentsValues(t,r),i=0;for(let t=0,n=s.length,o;t<n;++t){switch(typeof(o=s[t])){case"number":if(isNaN(o))continue;break;case"object":i+=e(o,r);continue;case"string":if(!o)continue}++i}return i});let{getArgumentValue:ey}=ed;ed.registerProcessorFunction("IF",function(e,t){return ey(e[0],t)?ey(e[1],t):ey(e[2],t)});let{getArgumentValue:eb}=ed;ed.registerProcessorFunction("ISNA",function(e,t){let r=eb(e[0],t);return"number"!=typeof r||isNaN(r)});let{getArgumentsValues:ew}=ed;ed.registerProcessorFunction("MAX",function e(t,r){let s=ew(t,r),i=-1/0;for(let t=0,r=s.length,n;t<r;++t)switch(typeof(n=s[t])){case"number":n>i&&(i=n);break;case"object":(n=e(n))>i&&(i=n)}return isFinite(i)?i:0}),ed.registerProcessorFunction("MEDIAN",function(e,t){let r=[],s=ed.getArgumentsValues(e,t);for(let e=0,t=s.length,i;e<t;++e)switch(typeof(i=s[e])){case"number":isNaN(i)||r.push(i);break;case"object":for(let e=0,t=i.length,s;e<t;++e)"number"!=typeof(s=i[e])||isNaN(s)||r.push(s)}let i=r.length;if(!i)return NaN;let n=Math.floor(i/2);return i%2?r[n]:(r[n-1]+r[n])/2});let{getArgumentsValues:eC}=ed;ed.registerProcessorFunction("MIN",function e(t,r){let s=eC(t,r),i=1/0;for(let t=0,r=s.length,n;t<r;++t)switch(typeof(n=s[t])){case"number":n<i&&(i=n);break;case"object":(n=e(n))<i&&(i=n)}return isFinite(i)?i:0});let{getArgumentValue:eR}=ed;function eN(e,t){let r={},s=ed.getArgumentsValues(e,t);for(let e=0,t=s.length,i;e<t;++e)switch(typeof(i=s[e])){case"number":isNaN(i)||(r[i]=(r[i]||0)+1);break;case"object":for(let e=0,t=i.length,s;e<t;++e)"number"!=typeof(s=i[e])||isNaN(s)||(r[s]=(r[s]||0)+1)}return r}function eT(e,t){let r=eN(e,t),s=Object.keys(r);if(!s.length)return NaN;let i=parseFloat(s[0]),n=r[s[0]];for(let e=1,t=s.length,o,l,a;e<t;++e)n<(a=r[o=s[e]])?(i=parseFloat(o),n=a):n===a&&i>(l=parseFloat(o))&&(i=l,n=a);return n>1?i:NaN}ed.registerProcessorFunction("MOD",function(e,t){let r=eR(e[0],t),s=eR(e[1],t);return("object"==typeof r&&(r=r[0]),"object"==typeof s&&(s=s[0]),"number"!=typeof r||"number"!=typeof s||0===s)?NaN:r%s}),ed.registerProcessorFunction("MODE",eT),ed.registerProcessorFunction("MODE.MULT",function(e,t){let r=eN(e,t),s=Object.keys(r);if(!s.length)return NaN;let i=[parseFloat(s[0])],n=r[s[0]];for(let e=1,t=s.length,o,l;e<t;++e)n<(l=r[o=s[e]])?(i=[parseFloat(o)],n=l):n===l&&i.push(parseFloat(o));return n>1?i:NaN}),ed.registerProcessorFunction("MODE.SNGL",eT);let{getArgumentValue:eO}=ed;ed.registerProcessorFunction("NOT",function(e,t){let r=eO(e[0],t);switch("object"==typeof r&&(r=r[0]),typeof r){case"boolean":case"number":return!r}return NaN});let{getArgumentValue:ev}=ed;ed.registerProcessorFunction("OR",function e(t,r){for(let s=0,i=t.length,n;s<i;++s)if("object"==typeof(n=ev(t[s],r))){if(e(n,r))return!0}else if(n)return!0;return!1});let{getArgumentsValues:eA}=ed;ed.registerProcessorFunction("PRODUCT",function e(t,r){let s=eA(t,r),i=1,n=!1;for(let t=0,o=s.length,l;t<o;++t)switch(typeof(l=s[t])){case"number":isNaN(l)||(n=!0,i*=l);break;case"object":n=!0,i*=e(l,r)}return n?i:0}),ed.registerProcessorFunction("SUM",function e(t,r){let s=ed.getArgumentsValues(t,r),i=0;for(let t=0,n=s.length,o;t<n;++t)switch(typeof(o=s[t])){case"number":isNaN(o)||(i+=o);break;case"object":i+=e(o,r)}return i});let{getArgumentValue:eM}=ed;ed.registerProcessorFunction("XOR",function(e,t){for(let r=0,s=e.length,i,n;r<s;++r)switch(typeof(n=eM(e[r],t))){case"boolean":case"number":if(void 0===i)i=!!n;else if(!!n!==i)return!0;break;case"object":for(let e=0,t=n.length,r;e<t;++e)switch(typeof(r=n[e])){case"boolean":case"number":if(void 0===i)i=!!r;else if(!!r!==i)return!0}}return!1});let eE={...U,...ed,..._};class eI extends N{constructor(e){let t=(0,r.merge)(eI.defaultOptions,e);super(t),this.headers=[],this.dataTypes=[],this.options=t}parse(e,t){let s=this.dataTypes,i=(0,r.merge)(this.options,e),{beforeParse:n,lineDelimiter:o,firstRowAsNames:l,itemDelimiter:a}=i,u,h=0,{csv:c,startRow:d,endRow:f}=i,p,m=[];if(this.emit({type:"parse",columns:m,detail:t,headers:this.headers}),c&&n&&(c=n(c)),c){if(u=c.replace(/\r\n|\r/g,"\n").split(o||"\n"),(!d||d<0)&&(d=0),(!f||f>=u.length)&&(f=u.length-1),a||(this.guessedItemDelimiter=this.guessDelimiter(u)),l){let e=u[0].split(a||this.guessedItemDelimiter||",");for(let t=0;t<e.length;t++)e[t]=e[t].trim().replace(/^["']|["']$/g,"");this.headers=e,d++}let e=0;for(h=d;h<=f;h++)"#"===u[h][0]?e++:this.parseCSVRow(m,u[h],h-d-e);s.length&&s[0].length&&"date"===s[0][1]&&!this.options.dateFormat&&this.deduceDateFormat(m[0],null,!0);for(let e=0,t=m.length;e<t;++e){p=m[e];for(let t=0,r=p.length;t<r;++t)if(p[t]&&"string"==typeof p[t]){let r=this.convertByType(p[t]);r instanceof Date&&(r=r.getTime()),m[e][t]=r}}}return m.forEach(e=>{e.length=Math.max(...m.map(e=>e.length))}),this.emit({type:"afterParse",columns:m,detail:t,headers:this.headers}),w(m,this.headers)}parseCSVRow(e,t,r){let s=this,i=s.dataTypes,{startColumn:n,endColumn:o}=s.options,l=s.options.itemDelimiter||s.guessedItemDelimiter,{decimalPoint:a}=s.options;a&&a!==l||(a=s.guessedDecimalPoint||".");let u=0,h="",c="",d=0,f=0,p=e=>{h=t[e]},m=e=>{i.length<f+1&&i.push([e]),i[f][i[f].length-1]!==e&&i[f].push(e)},g=()=>{if(n>d||d>o){++d,c="";return}if("string"==typeof c){let e=parseFloat(c);!isNaN(e)&&isFinite(Number(c))?(c=e,m("number")):isNaN(Date.parse(c))?m("string"):(c=c.replace(/\//g,"-"),m("date"))}else m("number");if(e.length<f+1&&e.push([]),"number"!=typeof c&&"number"!==C(c,s)&&a){let e=c;"number"!==C(c=c.replace(a,"."),s)&&(c=e)}e[f][r]=c,c="",++f,++d};if(t.trim().length&&"#"!==t.trim()[0]){for(;u<t.length;u++){if(p(u),"#"===h&&!/^#[A-F\d]{3,3}|[A-F\d]{6,6}/i.test(t.substring(u)))return void g();if('"'===h)for(p(++u);u<t.length&&'"'!==h;)c+=h,p(++u);else h===l?g():c+=h}g()}}guessDelimiter(e){let t=0,r=0,s,i={",":0,";":0," ":0},n=e.length;for(let s=0;s<n;s++){let n=!1,o,l,a,u="";if(s>13)break;let h=e[s];for(let e=0;e<h.length&&(o=h[e],l=h[e+1],a=h[e-1],"#"!==o);e++){if('"'===o)if(n){if('"'!==a&&'"'!==l){for(;" "===l&&e<h.length;)l=h[++e];void 0!==i[l]&&i[l]++,n=!1}}else n=!0;else void 0!==i[o]?(isNaN(Date.parse(u=u.trim()))?(isNaN(Number(u))||!isFinite(Number(u)))&&i[o]++:i[o]++,u=""):u+=o;","===o&&r++,"."===o&&t++}}return i[";"]>i[","]?s=";":(i[","]>i[";"],s=","),t>r?this.guessedDecimalPoint=".":this.guessedDecimalPoint=",",s}}eI.defaultOptions={...N.defaultOptions,lineDelimiter:"\n",startColumn:0,endColumn:Number.MAX_VALUE,startRow:0,endRow:Number.MAX_VALUE},N.registerType("CSV",eI);class ex extends p{constructor(e){let t=(0,r.merge)(ex.defaultOptions,e);super(t),this.options=t,t.enablePolling&&this.startPolling(1e3*Math.max(t.dataRefreshRate||0,1))}emit(e){(0,r.fireEvent)(this,e.type,e)}load(e){let t=this,s=t.options,{csv:i,csvURL:n,dataTables:o,decimalPoint:l}=s;return t.emit({type:"load",csv:i}),Promise.resolve(n?fetch(n,{signal:t?.pollingController?.signal}).then(e=>e.text()):i||"").then(e=>(e&&this.initConverters(e,e=>{let{firstRowAsNames:t=s.firstRowAsNames,beforeParse:i=s.beforeParse}=o?.find(t=>t.key===e)||{};return new eI((0,r.merge)(s,{decimalPoint:l,firstRowAsNames:t,beforeParse:i}))},(e,t)=>e.parse({csv:t})),t.applyTableModifiers().then(()=>e))).then(r=>(t.emit({type:"afterLoad",detail:e,csv:r}),t)).catch(r=>{throw t.emit({type:"loadError",detail:e,error:r}),r})}}ex.defaultOptions={id:"csv-connector",type:"CSV",csv:"",csvURL:"",enablePolling:!1,dataRefreshRate:1,firstRowAsNames:!0},p.registerType("CSV",ex);class eF extends N{constructor(e){let t=(0,r.merge)(eF.defaultOptions,e);super(t),this.headerColumnIds=[],this.headers=[],this.options=t}parse(e,t){let{beforeParse:s,orientation:i,firstRowAsNames:n,columnIds:o}=e=(0,r.merge)(this.options,e),l=e.data;if(!l)return{};this.headers=[];let a=[];return this.emit({type:"parse",columns:a,detail:t,headers:this.headers}),s&&(l=s(l)),l=l.slice(),"columns"===i?this.parseColumnsOrientation(a,l,n,o):"rows"===i&&this.parseRowsOrientation(a,l,n,o),this.emit({type:"afterParse",columns:a,detail:t,headers:this.headers}),w(a,this.headers)}parseColumnsOrientation(e,t,s,i){for(let n=0,o=t.length;n<o;n++){let o=t[n];if(!Array.isArray(o))return;Array.isArray(this.headers)?(s?this.headers.push(`${o.shift()}`):i&&Array.isArray(i)&&this.headers.push(i[n]),e.push(o)):(0,r.error)("JSONConverter: Invalid `columnIds` option.",!1)}}parseRowsOrientation(e,t,s,i){s?this.headers=t.shift():i&&(this.headerColumnIds=i);for(let n=0,o=t.length;n<o;n++){let o=t[n];(0,r.isArray)(o)||(o=this.convertItemToRow(o,i));for(let t=0,i=o.length;t<i;t++)e.length<t+1&&e.push([]),e[t].push(o[t]),s||0!==n||(Array.isArray(this.headerColumnIds)?this.headers.push(this.headerColumnIds[t]||t.toString()):(0,r.error)("JSONConverter: Invalid `columnIds` option.",!1))}}convertItemToRow(e,t){let s=this;if(t&&!Array.isArray(t)){let i=[];return(0,r.objectEach)(t,(t,r)=>{i.push(t.reduce((e,t)=>e[t],e)),0>s.headers.indexOf(r)&&s.headers.push(r)}),i}return s.headerColumnIds=Object.keys(e),Object.values(e)}}eF.defaultOptions={...N.defaultOptions,orientation:"rows"},N.registerType("JSON",eF);class eD extends p{constructor(e){let t=(0,r.merge)(eD.defaultOptions,e);super(t),this.options=t,t.enablePolling&&this.startPolling(1e3*Math.max(t.dataRefreshRate||0,1))}emit(e){(0,r.fireEvent)(this,e.type,e)}load(e){let t=this,r=t.options,{data:s,dataUrl:i,dataTables:n}=r;return t.emit({type:"load",detail:e,data:s}),Promise.resolve(i?fetch(i,{signal:t?.pollingController?.signal}).then(e=>e.json()).catch(r=>{t.emit({type:"loadError",detail:e,error:r}),console.warn(`Unable to fetch data from ${i}.`)}):s||[]).then(async e=>(e&&this.initConverters(e,t=>{let{columnIds:s=r.columnIds,firstRowAsNames:i=r.firstRowAsNames,orientation:o=r.orientation,beforeParse:l=r.beforeParse}=n?.find(e=>e.key===t)||{};return new eF({data:e,columnIds:s,firstRowAsNames:i,orientation:o,beforeParse:l})},(e,t)=>e.parse({data:t})),t.applyTableModifiers().then(()=>e??[]))).then(r=>(t.emit({type:"afterLoad",detail:e,data:r}),t)).catch(r=>{throw t.emit({type:"loadError",detail:e,error:r}),r})}}eD.defaultOptions={type:"JSON",id:"json-connector",data:[],enablePolling:!1,dataRefreshRate:0,firstRowAsNames:!0,orientation:"rows"},p.registerType("JSON",eD);class eP extends N{constructor(e){let t=(0,r.merge)(eP.defaultOptions,e);super(t),this.header=[],this.options=t}parse(e,t){let s,i=(0,r.merge)(this.options,e),n=(i.json?.values||[]).map(e=>e.slice());if(0===n.length)return{};this.header=[],this.emit({type:"parse",columns:[],detail:t,headers:this.header});let{beforeParse:o,json:l}=i;o&&l&&(n=o(l.values));for(let e=0,t=n.length;e<t;e++){s=n[e],this.header[e]=i.firstRowAsNames?`${s.shift()}`:(0,r.uniqueKey)();for(let t=0,r=s.length;t<r;++t){var a;let r=s[t];a=r,"[object Date]"===Object.prototype.toString.call(a)&&(r=r.getTime()),n[e][t]=r}}return this.emit({type:"afterParse",columns:n,detail:t,headers:this.header}),w(n,this.header)}}eP.defaultOptions={...N.defaultOptions},N.registerType("GoogleSheets",eP);class ej extends p{constructor(e){let t=(0,r.merge)(ej.defaultOptions,e);super(t),this.options=t}emit(e){(0,r.fireEvent)(this,e.type,e)}load(e){let t=this,s=t.options,{dataRefreshRate:i,enablePolling:n,googleAPIKey:o,googleSpreadsheetKey:l,dataTables:a}=s,u=function(e,t,s={}){let i=new URL(`https://sheets.googleapis.com/v4/spreadsheets/${t}/values/`),n=s.onlyColumnIds?"A1:Z1":function(e={}){let{endColumn:t,endRow:s,googleSpreadsheetRange:i,startColumn:n,startRow:o}=e;return i||(ek[n||0]||"A")+(Math.max(o||0,0)+1)+":"+(ek[(0,r.pick)(t,25)]||"Z")+(s?Math.max(s,0):"Z")}(s);i.pathname+=n;let o=i.searchParams;return o.set("alt","json"),s.onlyColumnIds||(o.set("dateTimeRenderOption","FORMATTED_STRING"),o.set("majorDimension","COLUMNS"),o.set("valueRenderOption","UNFORMATTED_VALUE")),o.set("prettyPrint","false"),o.set("key",e),i.href}(o,l,s);if(t.emit({type:"load",detail:e,url:u}),!URL.canParse(u))throw Error("Invalid URL: "+u);return fetch(u,{signal:t?.pollingController?.signal}).then(e=>e.json()).then(e=>{if("object"==typeof e&&e&&"object"==typeof e.error&&e.error&&"number"==typeof e.error.code&&"string"==typeof e.error.message&&"string"==typeof e.error.status)throw Error(e.error.message);return this.initConverters(e,e=>{let{firstRowAsNames:t=s.firstRowAsNames,beforeParse:r=s.beforeParse}=a?.find(t=>t.key===e)||{};return new eP({firstRowAsNames:t,beforeParse:r})},(e,t)=>e.parse({json:t})),t.applyTableModifiers()}).then(()=>(t.emit({type:"afterLoad",detail:e,url:u}),n&&setTimeout(()=>t.load(),1e3*Math.max(i||0,1)),t)).catch(r=>{throw t.emit({type:"loadError",detail:e,error:r}),r})}}ej.defaultOptions={id:"google-sheets-connector",type:"GoogleSheets",googleAPIKey:"",googleSpreadsheetKey:"",enablePolling:!1,dataRefreshRate:2,firstRowAsNames:!0};let ek="ABCDEFGHIJKLMNOPQRSTUVWXYZ";p.registerType("GoogleSheets",ej);class eL extends N{constructor(e){let t=(0,r.merge)(eL.defaultOptions,e);super(t),this.headers=[],this.options=t,t.tableElement&&(this.tableElement=t.tableElement,this.tableElementID=t.tableElement.id)}export(e,t=this.options){let r=!1!==t.firstRowAsNames,s=t.useMultiLevelHeaders,i=e.getSortedColumns(),n=Object.keys(i),o=[],l=n.length,a=[],u="";if(r){let e=[];if(s){for(let t of n){let r=i[t];Array.isArray(r)||(r=Array.from(r));let s=(r.shift()||"").toString();i[t]=r,e.push(s)}u=this.getTableHeaderHTML(n,e,t)}else u=this.getTableHeaderHTML(void 0,n,t)}for(let e=0;e<l;e++){let t=i[n[e]],r=t.length;for(let s=0;s<r;s++){let r=t[s];a[s]||(a[s]=[]),"string"!=typeof r&&"number"!=typeof r&&void 0!==r&&(r=(r||"").toString()),a[s][e]=this.getCellHTMLFromValue(e?"td":"th",null,e?"":'scope="row"',r),e===l-1&&o.push("<tr>"+a[s].join("")+"</tr>")}}let h="";return t.tableCaption&&(h='<caption class="highcharts-table-caption">'+t.tableCaption+"</caption>"),"<table>"+h+u+"<tbody>"+o.join("")+"</tbody></table>"}getCellHTMLFromValue(e,t,r,s,i){let n=s,o="text"+(t?" "+t:"");return"number"==typeof n?(n=n.toString(),","===i&&(n=n.replace(".",i)),o="number"):s||(n="",o="empty"),"<"+e+(r?" "+r:"")+' class="'+o+'">'+n+"</"+e+">"}getTableHeaderHTML(e=[],t=[],r=this.options){let{useMultiLevelHeaders:s,useRowspanHeaders:i}=r,n="<thead>",o=0,l=t&&t.length,a,u=0,h;if(s&&e&&t&&!function(e,t){let r=e.length;if(t.length!==r)return!1;for(;--r;)if(e[r]!==t[r])return!1;return!0}(e,t)){for(n+="<tr>";o<l;++o)(a=e[o])===e[o+1]?++u:u?(n+=this.getCellHTMLFromValue("th","highcharts-table-topheading",'scope="col" colspan="'+(u+1)+'"',a),u=0):(a===t[o]?i?(h=2,t.splice(o,1)):(h=1,t[o]=""):h=1,n+=this.getCellHTMLFromValue("th","highcharts-table-topheading",'scope="col"'+(h>1?' valign="top" rowspan="'+h+'"':""),a));n+="</tr>"}if(t){for(n+="<tr>",o=0,l=t.length;o<l;++o)void 0!==t[o]&&(n+=this.getCellHTMLFromValue("th",null,'scope="col"',t[o]));n+="</tr>"}return n+"</thead>"}parse(e,t){let s=[],i=[],n=(0,r.merge)(this.options,e),{endRow:o,startColumn:l,endColumn:a,firstRowAsNames:u}=n,h=n.tableElement||this.tableElement;if(!(h instanceof HTMLElement))return this.emit({type:"parseError",columns:s,detail:t,headers:i,error:"Not a valid HTML Table"}),{};this.tableElement=h,this.tableElementID=h.id,this.emit({type:"parse",columns:s,detail:t,headers:this.headers});let c=h.getElementsByTagName("tr"),d=c.length,f=0,p,{startRow:m}=n;if(u&&d){let e=c[0].children,t=e.length;for(let r=l;r<t&&!(r>a);r++)("TD"===(p=e[r]).tagName||"TH"===p.tagName)&&i.push(p.innerHTML);m++}for(;f<d;){if(f>=m&&f<=o){let e=c[f].children,t=e.length,r=0;for(;r<t;){let t=r-l,i=s[t];if(("TD"===(p=e[r]).tagName||"TH"===p.tagName)&&r>=l&&r<=a){s[t]||(s[t]=[]);let e=this.convertByType(p.innerHTML);e instanceof Date&&(e=e.getTime()),s[t][f-m]=e;let r=1;for(;f-m>=r&&void 0===i[f-m-r];)i[f-m-r]=null,r++}r++}}f++}return this.headers=i,this.emit({type:"afterParse",columns:s,detail:t,headers:i}),w(s,this.headers)}}eL.defaultOptions={...N.defaultOptions,useRowspanHeaders:!0,useMultiLevelHeaders:!0,startColumn:0,endColumn:Number.MAX_VALUE,startRow:0,endRow:Number.MAX_VALUE},N.registerType("HTMLTable",eL);let{win:eY}=s();class eS extends p{constructor(e){let t=(0,r.merge)(eS.defaultOptions,e);super(t),this.options=t,this.converter=new eL(t)}async load(e){let t,s=this.options,i=this.converter,n=this.getTable(),o=s.htmlTable;if(this.emit({type:"load",detail:e}),"string"==typeof o?(this.tableID=o,t=eY.document.getElementById(o)):(t=o,this.tableID=t.id),this.tableElement=t||void 0,!this.tableElement){let t="HTML table not provided, or element with ID not found";return this.emit({type:"loadError",detail:e,error:t}),Promise.reject(Error(t))}let l=i.parse((0,r.merge)({tableElement:this.tableElement},s),e);return n.deleteColumns(),n.setColumns(l),await this.applyTableModifiers(),this.emit({type:"afterLoad",detail:e}),this}}eS.defaultOptions={id:"HTML-table-connector",type:"HTMLTable",htmlTable:""},p.registerType("HTMLTable",eS);class eV extends n{constructor(e,...t){super(),this.chain=t,this.options=(0,r.merge)(eV.defaultOptions,e);let s=this.options.chain||[];for(let e=0,r=s.length,i,o;e<r;++e)(i=s[e]).type&&(o=n.types[i.type])&&t.push(new o(i))}add(e,t){this.emit({type:"addModifier",detail:t,modifier:e}),this.chain.push(e),this.emit({type:"addModifier",detail:t,modifier:e})}clear(e){this.emit({type:"clearChain",detail:e}),this.chain.length=0,this.emit({type:"afterClearChain",detail:e})}async modify(e,t){let r=this.options.reverse?this.chain.slice().reverse():this.chain.slice();e.modified||(e.modified=e.clone(!1,t));let s=e;for(let i=0,n=r.length;i<n;++i){try{await r[i].modify(s,t)}catch(r){throw this.emit({type:"error",detail:t,table:e}),r}s=s.getModified()}return e.modified=s,e}modifyTable(e,t){this.emit({type:"modify",detail:t,table:e});let r=this.options.reverse?this.chain.reverse():this.chain.slice(),s=e.getModified();for(let e=0,i=r.length;e<i;++e)s=r[e].modifyTable(s,t).getModified();return e.modified=s,this.emit({type:"afterModify",detail:t,table:e}),e}remove(e,t){let r=this.chain;this.emit({type:"removeModifier",detail:t,modifier:e}),r.splice(r.indexOf(e),1),this.emit({type:"afterRemoveModifier",detail:t,modifier:e})}emit(e){(0,r.fireEvent)(this,e.type,e)}on(e,t){return(0,r.addEvent)(this,e,t)}}eV.defaultOptions={type:"Chain"},n.registerType("Chain",eV);class e$ extends n{constructor(e){super(),this.options=(0,r.merge)(e$.defaultOptions,e)}modifyTable(e,t){this.emit({type:"modify",detail:t,table:e});let r=e.getModified();if(e.hasColumns(["columnIds"])){let t=(e.deleteColumns(["columnIds"])||{}).columnIds||[],s={},i=[];for(let e=0,r=t.length;e<r;++e)i.push(""+t[e]);for(let t=0,r=e.getRowCount(),n;t<r;++t)(n=e.getRow(t))&&(s[i[t]]=n);r.deleteColumns(),r.setColumns(s)}else{let t={};for(let r=0,s=e.getRowCount(),i;r<s;++r)(i=e.getRow(r))&&(t[`${r}`]=i);t.columnIds=e.getColumnIds(),r.deleteColumns(),r.setColumns(t)}return this.emit({type:"afterModify",detail:t,table:e}),e}}e$.defaultOptions={type:"Invert"},n.registerType("Invert",e$);class eU extends n{constructor(e){super(),this.options={...eU.defaultOptions,...e}}modifyTable(e,t){this.emit({type:"modify",detail:t,table:e});let r=this.options.alternativeSeparators,s=this.options.formulaColumns||e.getColumnIds(),i=e.getModified();for(let t=0,r=s.length,n;t<r;++t)n=s[t],s.indexOf(n)>=0&&i.setColumn(n,this.processColumn(e,n));let n=this.options.columnFormulas||[];for(let t=0,s=n.length,o,l;t<s;++t)o=n[t],l=U.parseFormula(o.formula,r),i.setColumn(o.column,this.processColumnFormula(l,e,o.rowStart,o.rowEnd));return this.emit({type:"afterModify",detail:t,table:e}),e}processColumn(e,t,r=0){let s=this.options.alternativeSeparators,i=(e.getColumn(t,!0)||[]).slice(r>0?r:0);for(let t=0,r=i.length,n=[],o;t<r;++t)if("string"==typeof(o=i[t])&&"="===o[0])try{n=""===o?n:U.parseFormula(o.substring(1),s),i[t]=ed.processFormula(n,e)}catch{i[t]=NaN}return i}processColumnFormula(e,t,r=0,s=t.getRowCount()){r=r>=0?r:0,s=s>=0?s:t.getRowCount()+s;let i=[],n=t.getModified();for(let t=0,o=s-r;t<o;++t)try{i[t]=ed.processFormula(e,n)}catch{i[t]=NaN}finally{e=ed.translateReferences(e,0,1)}return i}}eU.defaultOptions={type:"Math",alternativeSeparators:!1},n.registerType("Math",eU);class eH extends n{constructor(e){super(),this.options=(0,r.merge)(eH.defaultOptions,e)}modifyTable(e,t){this.emit({type:"modify",detail:t,table:e});let{start:r,end:s}=this.options;r=Math.max(0,r||0);let i=Math.max((s=Math.min(s||1/0,e.getRowCount()))-r,0),n=e.getModified();return n.deleteRows(),n.setRows(e.getRows(r,i)),n.setOriginalRowIndexes(Array.from({length:i},(t,s)=>e.getOriginalRowIndex(r+s))),this.emit({type:"afterModify",detail:t,table:e}),e}}eH.defaultOptions={type:"Range",start:0,end:1/0},n.registerType("Range",eH);class e_ extends n{static ascending(e,t){return(e||0)<(t||0)?-1:+((e||0)>(t||0))}static descending(e,t){return(t||0)<(e||0)?-1:+((t||0)>(e||0))}static compareFactory(e,t){return t?"desc"===e?(e,r)=>-t(e,r):t:"asc"===e?e_.ascending:e_.descending}constructor(e){super(),this.options=(0,r.merge)(e_.defaultOptions,e)}getRowReferences(e){let t=e.getRows(),r=[];for(let e=0,s=t.length;e<s;++e)r.push({index:e,row:t[e]});return r}modifyTable(e,t){this.emit({type:"modify",detail:t,table:e});let r=e.getColumnIds(),s=e.getRowCount(),i=this.getRowReferences(e),{direction:n,orderInColumn:o,compare:l}=this.options,a=e.getModified(),u="columns"in this.options?this.options.columns:[this.options.orderByColumn],h=[];for(let e=0,t=u.length;e<t;++e){let t=u[e],s="string"==typeof t,i=s?t:t.column,o=r.indexOf(i);-1!==o&&h.push({columnIndex:o,compare:e_.compareFactory(s?n:t.direction||n,s?l:t.compare||l)})}if(h.length&&i.sort((e,t)=>{for(let r=0,s=h.length;r<s;++r){let{columnIndex:s,compare:i}=h[r],n=i(e.row[s],t.row[s]);if(n)return n}return e.index-t.index}),o){let e=[];for(let t=0;t<s;++t)e[i[t].index]=t;a.setColumns({[o]:e})}else{let t,r=[],n=[];for(let o=0;o<s;++o)t=i[o],r.push(e.getOriginalRowIndex(t.index)),n.push(t.row);a.setRows(n,0),a.setOriginalRowIndexes(r)}return this.emit({type:"afterModify",detail:t,table:e}),e}}e_.defaultOptions={type:"Sort",direction:"desc",orderByColumn:"y"},n.registerType("Sort",e_);class eB extends n{static compile(e){if((0,r.isFunction)(e))return e;let t=e.operator;switch(t){case"and":{let t=e.conditions.map(e=>this.compile(e));return(e,r,s)=>t.every(t=>t(e,r,s))}case"or":{let t=e.conditions.map(e=>this.compile(e));return(e,r,s)=>t.some(t=>t(e,r,s))}case"not":{let t=this.compile(e.condition);return(e,r,s)=>!t(e,r,s)}}let{columnId:s,value:i}=e;switch(t){case"==":return