@kanunilabs/pivotgrid-core 1.11.1 → 1.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +12 -14
- package/dist/index.d.cts +515 -424
- package/dist/index.d.ts +515 -424
- package/dist/index.js +12 -14
- package/dist/pivot.worker.cjs +1 -1
- package/dist/pivot.worker.js +1 -1
- package/package.json +2 -7
- package/dist/import.worker.cjs +0 -3
- package/dist/import.worker.js +0 -3
package/dist/pivot.worker.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var nt=class{size=1;nodeToParent;nodeToVal;nodeToDepth;nodeChildCount;childrenMap;constructor(t){this.nodeToParent=new Int32Array(t).fill(-1),this.nodeToVal=new Int32Array(t).fill(-1),this.nodeToDepth=new Int32Array(t).fill(0),this.nodeChildCount=new Int32Array(t).fill(0),this.childrenMap=new Map;}expandCapacity(){let t=this.nodeToParent.length*2,e=new Int32Array(t).fill(-1);e.set(this.nodeToParent),this.nodeToParent=e;let n=new Int32Array(t).fill(-1);n.set(this.nodeToVal),this.nodeToVal=n;let r=new Int32Array(t).fill(0);r.set(this.nodeToDepth),this.nodeToDepth=r;let i=new Int32Array(t).fill(0);i.set(this.nodeChildCount),this.nodeChildCount=i;}insert(t,e){let n=0;for(let r=0;r<e;r++){let i=t[r],s=this.childrenMap.get(n);s||(s=new Map,this.childrenMap.set(n,s));let c=s.get(i);c===void 0&&(this.size>=this.nodeToParent.length&&this.expandCapacity(),c=this.size++,this.nodeToParent[c]=n,this.nodeToVal[c]=i,this.nodeToDepth[c]=r+1,this.nodeChildCount[n]++,s.set(i,c)),n=c;}return n}};function X(z,t){if(z.length>=t)return z;let e=new z.constructor(Math.max(t,Math.ceil(z.length*1.5)));return e.set(z),e}function ct(z,t,e){let n=t[0];for(let r=0;r<t.length;r++){let i=t[r]+1,s=r+1<t.length?t[r+1]:e;z.copyWithin(n,i,s),n+=s-i;}}var lt=class{dictionary=[];rowFields=[];colFields=[];dataFields=[];storedColumns={};storedRowCount=0;lastMask=null;isBuilt=false;buildState=null;activeFilters=null;activePrefilter=null;tracking=false;groupRows=new Int32Array(0);groupMap=new Map;rowLive=null;colLive=null;rowTrie;colTrie;cardinalityMap={};rowPathStrs=[];colPathStrs=[];rowIndexMapCache={};columnIndexMapCache={};buildVersion=0;groupCount=0;leafGroupRowIds;leafGroupColIds;leafGroupMeasures;leafGroupCounts;leafGroupMins;leafGroupMaxes;leafGroupDistinctSets=new Map;rowGroupOf=null;init(t){this.dictionary=t.dictionary,this.rowFields=t.rowFields,this.colFields=t.colFields,this.dataFields=t.dataFields,t.workerBootstrap&&t.workerBootstrap.length>0&&console.warn("[PivotGrid Worker] workerBootstrap is deprecated for security reasons. All calculations are executed on the main thread."),this.storedRowCount=t.rowCount,this.storedColumns={};for(let[e,n]of Object.entries(t.columnarData))n.type==="int32"&&(this.storedColumns[e]={type:"int32",array:new Int32Array(n.buffer)}),n.type==="float64"&&(this.storedColumns[e]={type:"float64",array:new Float64Array(n.buffer)});this.lastMask=null,this.activeFilters=this.activePrefilter=null,t.deferBuild?this.isBuilt=false:this.buildFromMask(null);}reconfigure(t){if(this.rowFields=t.rowFields,this.colFields=t.colFields,this.dataFields=t.dataFields,this.appendDictionary(t.dictionaryAppend),t.newColumns)for(let[e,n]of Object.entries(t.newColumns))n.type==="int32"&&(this.storedColumns[e]={type:"int32",array:new Int32Array(n.buffer)}),n.type==="float64"&&(this.storedColumns[e]={type:"float64",array:new Float64Array(n.buffer)});this.buildFromMask(this.lastMask);}initStart(t){this.dictionary=t.dictionary,this.rowFields=t.rowFields,this.colFields=t.colFields,this.dataFields=t.dataFields,t.workerBootstrap&&t.workerBootstrap.length>0&&console.warn("[PivotGrid Worker] workerBootstrap is deprecated for security reasons. All calculations are executed on the main thread."),this.storedRowCount=t.rowCountTotal,this.storedColumns={};for(let[e,n]of Object.entries(t.columnTypes))n==="int32"?this.storedColumns[e]={type:"int32",array:new Int32Array(t.rowCountTotal)}:this.storedColumns[e]={type:"float64",array:new Float64Array(t.rowCountTotal)};this.setFilters((t.filters||[]).map(e=>({fieldId:e.fieldId,filterType:e.filterType,ids:new Set,pending:new Set(e.valueStrings)})),t.prefilter),this.resolveIncrementalFilterStrings(0),this.isBuilt=false,this.beginBuild();}initChunk(t){this.appendDictionary(t.dictionaryAppend)&&this.ensureCardCapacity();for(let[e,n]of Object.entries(t.columns)){let r=this.storedColumns[e];r&&(r.type==="int32"?r.array.set(new Int32Array(n),t.start):r.array.set(new Float64Array(n),t.start));}this.lastMask&&this.computeMaskRange(t.start,t.end),this.processRange(t.start,t.end,this.lastMask);}initEnd(){this.finalizeBuild();}appendDictionary(t){if(!t||t.length===0)return false;let e=this.dictionary.length;for(let n of t)this.dictionary.push(n);return this.resolveIncrementalFilterStrings(e),true}setFilters(t,e){this.activeFilters=t.length>0?t:null,this.activePrefilter=e&&e.conditions.length>0?e:null,this.lastMask=this.activeFilters||this.activePrefilter?new Uint8Array(this.storedRowCount):null;}resolveIncrementalFilterStrings(t){let e=this.activeFilters;if(!e)return;let n=0;for(let r of e)n+=r.pending.size;if(n!==0)for(let r=t;r<this.dictionary.length;r++){let i=this.dictionary[r];for(let s of e)s.pending.delete(i)&&s.ids.add(r);}}computeMaskRange(t,e){let n=this.lastMask;if(n.fill(1,t,e),this.activeFilters)for(let r of this.activeFilters){let i=this.storedColumns[r.fieldId];if(!i||i.type!=="int32")continue;let s=i.array,c=r.ids;if(r.filterType==="exclude")for(let a=t;a<e;a++)n[a]&&c.has(s[a])&&(n[a]=0);else for(let a=t;a<e;a++)n[a]&&!c.has(s[a])&&(n[a]=0);}if(this.activePrefilter)for(let r=t;r<e;r++)n[r]&&!this.evaluatePrefilterGroup(this.activePrefilter,r)&&(n[r]=0);}applyFilter(t){this.setFilters(t.filters.map(e=>({fieldId:e.fieldId,filterType:e.filterType,ids:new Set(e.dictIds),pending:new Set(e.valueStrings)})),t.prefilter),this.lastMask&&this.computeMaskRange(0,this.storedRowCount),this.buildFromMask(this.lastMask);}evaluatePrefilterGroup(t,e){if(!t.conditions||t.conditions.length===0)return true;if(t.logicalOperator==="and"){for(let n of t.conditions)if("logicalOperator"in n){if(!this.evaluatePrefilterGroup(n,e))return false}else if(!this.evaluatePrefilterCondition(n,e))return false;return true}else {for(let n of t.conditions)if("logicalOperator"in n){if(this.evaluatePrefilterGroup(n,e))return true}else if(this.evaluatePrefilterCondition(n,e))return true;return false}}evaluatePrefilterCondition(t,e){let n=this.storedColumns[t.fieldId];if(!n)return true;if(n.type==="float64"){let f=n.array[e],y=Number(t.value);switch(t.operator){case "=":return f===y;case "<>":return f!==y;case ">":return f>y;case ">=":return f>=y;case "<":return f<y;case "<=":return f<=y;case "isnull":return isNaN(f)||f===0;case "isnotnull":return !isNaN(f)&&f!==0;default:return true}}let r=n.array[e],i=this.dictionary[r]||"",s=String(t.value??""),c=Number(i),a=Number(s),d=i!==""&&s!==""&&!isNaN(c)&&!isNaN(a);switch(t.operator){case "=":return i===s;case "<>":return i!==s;case ">":return d?c>a:i>s;case ">=":return d?c>=a:i>=s;case "<":return d?c<a:i<s;case "<=":return d?c<=a:i<=s;case "contains":return i.toLowerCase().includes(s.toLowerCase());case "notcontains":return !i.toLowerCase().includes(s.toLowerCase());case "startswith":return i.toLowerCase().startsWith(s.toLowerCase());case "endswith":return i.toLowerCase().endsWith(s.toLowerCase());case "isnull":return i===""||i==="(Blank)";case "isnotnull":return i!==""&&i!=="(Blank)";case "in":return Array.isArray(t.value)?t.value.map(String).includes(i):true;case "notin":return Array.isArray(t.value)?!t.value.map(String).includes(i):true;default:return true}}buildFromMask(t){this.beginBuild(),this.processRange(0,this.storedRowCount,t),this.finalizeBuild();}beginBuild(){let t=this.storedRowCount,e=this.storedColumns,n=this.rowFields.length,r=this.colFields.length,i=new Array(n);for(let u=0;u<n;u++)i[u]=e[this.rowFields[u].id].array;let s=new Array(r);for(let u=0;u<r;u++)s[u]=e[this.colFields[u].id].array;let c=this.dictionary.length,a=this.rowFields.map(u=>{let v=e[u.id];return v&&v.type==="int32"?new Uint8Array(c):null}),d=this.colFields.map(u=>{let v=e[u.id];return v&&v.type==="int32"?new Uint8Array(c):null});this.rowTrie=new nt(2e5),this.colTrie=new nt(2e5);let f=this.dataFields.length,y=this.dataFields.map(u=>u.summaryType||"sum"),p=y.some(u=>u==="count"||u==="avg"),G=y.some(u=>u==="min"),C=y.some(u=>u==="max"),M=y.some(u=>u==="distinct"),T=new Array(f);for(let u=0;u<f;u++)T[u]=e[this.dataFields[u].id].array;let F=Math.min(t,2e5),l=G?new Float64Array(F*f):new Float64Array(0),w=C?new Float64Array(F*f):new Float64Array(0);this.leafGroupDistinctSets=M?new Map:new Map,G&&l.fill(1/0),C&&w.fill(-1/0),this.buildState={rPath:new Int32Array(n),cPath:new Int32Array(r),rowColArrays:i,colColArrays:s,dataColArrays:T,rowCardSeen:a,colCardSeen:d,rowCardCounts:new Int32Array(n),colCardCounts:new Int32Array(r),summaryTypes:y,allSums:y.every(u=>u==="sum"),needsCounts:p,needsMins:G,needsMaxes:C,groupMap:new Map,leafRowIds:new Int32Array(F),leafColIds:new Int32Array(F),leafMeasures:new Float64Array(F*f),leafCounts:p?new Float64Array(F*f):new Float64Array(0),leafMins:l,leafMaxes:w,rowGroupOf:this.tracking||y.includes("custom")?new Int32Array(t).fill(-1):null,gCount:0};}ensureCardCapacity(){let t=this.buildState;if(!t)return;let e=this.dictionary.length,n=r=>{if(r===null||r.length>=e)return r;let i=new Uint8Array(Math.max(e,r.length*2));return i.set(r),i};for(let r=0;r<t.rowCardSeen.length;r++)t.rowCardSeen[r]=n(t.rowCardSeen[r]);for(let r=0;r<t.colCardSeen.length;r++)t.colCardSeen[r]=n(t.colCardSeen[r]);}processRange(t,e,n){let r=this.buildState,{rPath:i,cPath:s,rowColArrays:c,colColArrays:a,dataColArrays:d,rowCardSeen:f,colCardSeen:y,rowCardCounts:p,colCardCounts:G,summaryTypes:C,allSums:M,needsCounts:T,needsMins:F,needsMaxes:l,groupMap:w,rowGroupOf:u}=r,v=c.length,m=a.length,b=d.length,D=this.rowTrie,E=this.colTrie,W=r.leafRowIds,J=r.leafColIds,_=r.leafMeasures,Q=r.leafCounts,Y=r.leafMins,Z=r.leafMaxes,K=r.gCount;for(let R=t;R<e;R++){if(n&&!n[R])continue;for(let h=0;h<v;h++){let A=c[h][R];i[h]=A;let g=f[h];g!==null&&g[A]===0&&(g[A]=1,p[h]++);}let $=D.insert(i,v);for(let h=0;h<m;h++){let A=a[h][R];s[h]=A;let g=y[h];g!==null&&g[A]===0&&(g[A]=1,G[h]++);}let rt=E.insert(s,m),it=$*67108864+rt,L=w.get(it);if(L===void 0){if(L=K++,w.set(it,L),L>=W.length){let h=L*2,A=new Int32Array(h);A.set(W),W=A;let g=new Int32Array(h);g.set(J),J=g;let H=new Float64Array(h*b);if(H.set(_),_=H,T){let o=new Float64Array(h*b);o.set(Q),Q=o;}if(F){let o=new Float64Array(h*b);o.fill(1/0),o.set(Y),Y=o;}if(l){let o=new Float64Array(h*b);o.fill(-1/0),o.set(Z),Z=o;}}W[L]=$,J[L]=rt;}u!==null&&(u[R]=L);let st=L*b;if(M)for(let h=0;h<b;h++)_[st+h]+=d[h][R];else for(let h=0;h<b;h++){let A=d[h][R],g=st+h;switch(C[h]){case "sum":_[g]+=A;break;case "count":Q[g]+=1;break;case "avg":_[g]+=A,Q[g]+=1;break;case "min":A<Y[g]&&(Y[g]=A);break;case "max":A>Z[g]&&(Z[g]=A);break;case "distinct":{if(A===0&&d[h]instanceof Int32Array)break;let H=this.leafGroupDistinctSets.get(g);H||(H=new Set,this.leafGroupDistinctSets.set(g,H)),H.add(A);break}default:_[g]+=A;break}}}r.leafRowIds=W,r.leafColIds=J,r.leafMeasures=_,r.leafCounts=Q,r.leafMins=Y,r.leafMaxes=Z,r.gCount=K;}finalizeBuild(){let t=this.buildState,{needsCounts:e,needsMins:n,needsMaxes:r,gCount:i}=t,s=t.dataColArrays.length,c=t.rowColArrays.length,a=t.colColArrays.length;this.groupCount=i,this.leafGroupRowIds=t.leafRowIds.slice(0,i),this.leafGroupColIds=t.leafColIds.slice(0,i),this.leafGroupMeasures=t.leafMeasures.slice(0,i*s),this.leafGroupCounts=e?t.leafCounts.slice(0,i*s):t.leafCounts,this.leafGroupMins=n?t.leafMins.slice(0,i*s):t.leafMins,this.leafGroupMaxes=r?t.leafMaxes.slice(0,i*s):t.leafMaxes,this.rowGroupOf=t.rowGroupOf,this.cardinalityMap={};for(let d=0;d<c;d++)t.rowCardSeen[d]!==null&&(this.cardinalityMap[this.rowFields[d].id]=t.rowCardCounts[d]);for(let d=0;d<a;d++)t.colCardSeen[d]!==null&&(this.cardinalityMap[this.colFields[d].id]=t.colCardCounts[d]);if(this.buildState=null,this.rowLive=this.colLive=null,this.tracking){this.groupMap=t.groupMap;let d=this.groupRows=new Int32Array(i),f=t.rowGroupOf;for(let y=0;y<this.storedRowCount;y++)f[y]>=0&&d[f[y]]++;}this.buildVersion++,this.isBuilt=true,this.rowPathStrs=this.buildPathStrs(this.rowTrie),this.colPathStrs=this.buildPathStrs(this.colTrie),this.rowIndexMapCache=this.buildIndexMap(this.rowPathStrs,null),this.columnIndexMapCache=this.buildIndexMap(this.colPathStrs,null);}buildPathStrs(t,e=[""]){let n=e;for(let r=e.length;r<t.size;r++){let i=t.nodeToParent[r],s=this.dictionary[t.nodeToVal[r]],c=n[i];n[r]=c?c+"|"+s:s;}return n}buildIndexMap(t,e){let n={};for(let r=0;r<t.length;r++)(!e||e[r])&&(n[t[r]]=r);return n}applyTransaction(t){this.tracking||(this.tracking=true,this.buildFromMask(this.lastMask)),this.appendDictionary(t.dictionaryAppend);let{update:e,remove:n}=t,r=e.length,i=this.storedRowCount,s=i+t.addCount,c=this.storedColumns,a=new Set,d=false,f=this.rowGroupOf,y=l=>{let w=f[l];w<0||(f[l]=-1,--this.groupRows[w]===0&&(d=true),a.add(w));};e.forEach(y),n.forEach(y);for(let l in c){let w=c[l],u=t.columns[l];if(!u)throw new Error("transaction: no values for column "+l);let v=w.type==="int32"?new Int32Array(u):new Float64Array(u),m=w.array=X(w.array,s);for(let b=0;b<r;b++)m[e[b]]=v[b];m.set(v.subarray(r),i);}f=this.rowGroupOf=X(f,s),f.fill(-1,i,s);let p=this.lastMask&&(this.lastMask=X(this.lastMask,s));p&&(e.forEach(l=>this.computeMaskRange(l,l+1)),this.computeMaskRange(i,s));let G=this.rowFields.map(l=>c[l.id].array),C=this.colFields.map(l=>c[l.id].array),M=new Int32Array(G.length),T=new Int32Array(C.length),F=l=>{if(p&&!p[l])return;G.forEach((b,D)=>{M[D]=b[l];}),C.forEach((b,D)=>{T[D]=b[l];});let w=this.rowTrie.insert(M,M.length),u=this.colTrie.insert(T,T.length),v=w*67108864+u,m=this.groupMap.get(v);m===void 0&&(this.groupMap.set(v,m=this.groupCount++),(this.leafGroupRowIds=X(this.leafGroupRowIds,m+1))[m]=w,(this.leafGroupColIds=X(this.leafGroupColIds,m+1))[m]=u,this.groupRows=X(this.groupRows,m+1)),this.groupRows[m]++===0&&(d=true),f[l]=m,a.add(m);};e.forEach(F);for(let l=i;l<s;l++)F(l);if(this.storedRowCount=s-n.length,n.length>0){for(let l in c)ct(c[l].array,n,s);ct(f,n,s),p&&ct(p,n,s);}if(this.resumGroups(a),d){let l=0;for(let w=0;w<this.groupCount;w++)this.groupRows[w]===0&&l++;l>4096&&l>this.groupCount-l?this.buildFromMask(this.lastMask):(this.cardinalityMap={},[this.rowLive,this.rowPathStrs,this.rowIndexMapCache]=this.relive(this.rowTrie,this.leafGroupRowIds,this.rowFields,this.rowPathStrs),[this.colLive,this.colPathStrs,this.columnIndexMapCache]=this.relive(this.colTrie,this.leafGroupColIds,this.colFields,this.colPathStrs),this.buildVersion++);}return this.storedRowCount}resumGroups(t){if(t.size===0)return;let e=this.dataFields.length,n=this.dataFields.map(C=>C.summaryType||"sum"),r=this.dataFields.map(C=>this.storedColumns[C.id].array),i=this.groupCount*e,s=this.leafGroupMeasures=X(this.leafGroupMeasures,i),c=n.some(C=>C==="count"||C==="avg")?this.leafGroupCounts=X(this.leafGroupCounts,i):null,a=n.includes("min")?this.leafGroupMins=X(this.leafGroupMins,i):null,d=n.includes("max")?this.leafGroupMaxes=X(this.leafGroupMaxes,i):null,f=this.leafGroupDistinctSets,y=new Uint8Array(this.groupCount),p=0;for(let C of t){y[C]=1,p+=this.groupRows[C];for(let M=C*e;M<(C+1)*e;M++)s[M]=0,c&&(c[M]=0),a&&(a[M]=1/0),d&&(d[M]=-1/0),f.delete(M);}let G=this.rowGroupOf;for(let C=0;p>0&&C<this.storedRowCount;C++){let M=G[C];if(!(M<0||!y[M])){p--;for(let T=0;T<e;T++){let F=r[T][C],l=M*e+T;switch(n[T]){case "count":c[l]++;break;case "avg":s[l]+=F,c[l]++;break;case "min":F<a[l]&&(a[l]=F);break;case "max":F>d[l]&&(d[l]=F);break;case "distinct":{if(F===0&&r[T]instanceof Int32Array)break;let w=f.get(l);w||f.set(l,w=new Set),w.add(F);break}default:s[l]+=F;}}}}}relive(t,e,n,r){let i=new Uint8Array(t.size);i[0]=1;for(let a=0;a<this.groupCount;a++)if(this.groupRows[a]!==0)for(let d=e[a];!i[d];d=t.nodeToParent[d])i[d]=1;let s=n.map(()=>new Set);t.nodeChildCount.fill(0,0,t.size);for(let a=1;a<t.size;a++)i[a]&&(t.nodeChildCount[t.nodeToParent[a]]++,s[t.nodeToDepth[a]-1]?.add(t.nodeToVal[a]));n.forEach((a,d)=>{this.cardinalityMap[a.id]=s[d].size;});let c=this.buildPathStrs(t,r);return [i,c,this.buildIndexMap(c,i)]}compute(t){this.isBuilt||this.buildFromMask(this.lastMask);let e=this.rowPathStrs,n=this.colPathStrs,r=new Uint8Array(this.rowTrie.size),i=new Set(t.expandedPaths),s=i.has(".*")||i.has("*");for(let o=0;o<this.rowTrie.size;o++)r[o]=s||i.has(e[o])?1:0;let c=new Uint8Array(this.colTrie.size),a=new Set(t.expandedColPaths),d=a.has(".*")||a.has("*");for(let o=0;o<this.colTrie.size;o++)c[o]=d||a.has(n[o])?1:0;let f=new Uint8Array(this.rowTrie.size);f[0]=1;for(let o=1;o<this.rowTrie.size;o++){let S=this.rowTrie.nodeToParent[o];(S===0||r[S])&&(!this.rowLive||this.rowLive[o])&&(f[o]=1);}let y=new Uint8Array(this.colTrie.size);y[0]=1;for(let o=1;o<this.colTrie.size;o++){let S=this.colTrie.nodeToParent[o];(S===0||c[S])&&(!this.colLive||this.colLive[o])&&(y[o]=1);}let p=this.dataFields.length,G=this.dataFields.map(o=>o.summaryType||"sum"),C=this.leafGroupMins.length>0,M=this.leafGroupMaxes.length>0,T=this.leafGroupCounts.length>0,F=this.leafGroupDistinctSets.size>0,l=new Map,w=0,u=1e4,v=new Float64Array(u),m=new Float64Array(u*p),b=new Int32Array(u*p),D=T?new Float64Array(u*p):null,E=C?new Float64Array(u*p):null,W=M?new Float64Array(u*p):null,J=F?new Map:new Map;E&&E.fill(1/0),W&&W.fill(-1/0);let _=new Int32Array(this.rowFields.length+1),Q=new Int32Array(this.colFields.length+1),Y=(o,S,I,O)=>{let tt=0,U=o;for(;U!==-1;)I[U]&&(O[tt++]=U),U=S.nodeToParent[U];return tt},Z=this.rowGroupOf!==null&&G.includes("custom"),K=Z?new Int32Array(this.groupCount+1):null,R=Z?new Int32Array(Math.max(16,this.groupCount*4)):null,$=0,rt=this.tracking?this.groupRows:null;for(let o=0;o<this.groupCount;o++){if(rt!==null&&rt[o]===0){K!==null&&(K[o+1]=$);continue}let S=this.leafGroupRowIds[o],I=this.leafGroupColIds[o],O=Y(S,this.rowTrie,f,_),tt=Y(I,this.colTrie,y,Q);for(let U=0;U<O;U++){let ot=_[U];for(let j=0;j<tt;j++){let at=Q[j],et=ot*67108864+at,P=l.get(et);if(P===void 0){if(P=w++,l.set(et,P),P>=v.length){let k=P*2,x=new Float64Array(k);x.set(v),v=x;let V=new Float64Array(k*p);V.set(m),m=V;let N=new Int32Array(k*p);if(N.set(b),b=N,D){let B=new Float64Array(k*p);B.set(D),D=B;}if(E){let B=new Float64Array(k*p);B.fill(1/0),B.set(E),E=B;}if(W){let B=new Float64Array(k*p);B.fill(-1/0),B.set(W),W=B;}}v[P]=et;}if(R!==null){if($>=R.length){let k=new Int32Array(R.length*2);k.set(R),R=k;}R[$++]=P;}for(let k=0;k<p;k++){let x=P*p+k,V=o*p+k;switch(G[k]){case "sum":m[x]+=this.leafGroupMeasures[V];break;case "count":m[x]+=this.leafGroupCounts[V];break;case "avg":m[x]+=this.leafGroupMeasures[V],D[x]+=this.leafGroupCounts[V];break;case "min":{let N=this.leafGroupMins[V];N<E[x]&&(E[x]=N);break}case "max":{let N=this.leafGroupMaxes[V];N>W[x]&&(W[x]=N);break}case "distinct":{let N=this.leafGroupDistinctSets.get(V);if(N){let B=J.get(x);B||(B=new Set,J.set(x,B));for(let ft of N)B.add(ft);}break}default:m[x]+=this.leafGroupMeasures[V];break}b[x]+=1;}}}K!==null&&(K[o+1]=$);}for(let o=0;o<w;o++)for(let S=0;S<p;S++){let I=o*p+S;switch(G[S]){case "avg":m[I]=D[I]>0?m[I]/D[I]:0;break;case "min":m[I]=E[I]!==1/0?E[I]:0;break;case "max":m[I]=W[I]!==-1/0?W[I]:0;break;case "distinct":{let O=J.get(I);m[I]=O?O.size:0;break}}}let it=v.slice(0,w),L=m.slice(0,w*p),st=b.slice(0,w*p),h=(o,S,I,O,tt)=>{let U=[];for(let j=0;j<O.length;j++)U[j]=O[j]?.id||"";let ot=j=>{let at=o.childrenMap.get(j);if(!at)return [];let et=[];for(let P of at.values())if(S[P]){let k=o.nodeToDepth[P]-1,x=I[P]===1;et.push({key:tt[P],value:this.dictionary[o.nodeToVal[P]],fieldId:U[k]||"",children:x?ot(P):[],isExpanded:x,isTotal:false,depth:k,hasChildren:o.nodeChildCount[P]>0});}return et};return ot(0)},A;if(this.rowGroupOf!==null&&K!==null&&R!==null){let o=this.storedRowCount,S={};for(let I=0;I<p;I++){if(G[I]!=="custom")continue;let O=this.dataFields[I].id;S[O]=this.storedColumns[O].array.slice(0,o);}A={rowGroupOf:this.rowGroupOf.slice(0,o),groupCellOffsets:K,groupCells:R.slice(0,$),values:S};}let g=h(this.rowTrie,f,r,this.rowFields,e),H=h(this.colTrie,y,c,this.colFields,n);return {id:t.id,rowTree:g,colTree:H,cellMatrix:{keys:it,sums:L,counts:st},customSummary:A,rowIndexMap:this.rowIndexMapCache,columnIndexMap:this.columnIndexMapCache,cardinalityMap:this.cardinalityMap,indexMapsVersion:this.buildVersion}}};var q=new lt,dt=-1;self.onmessage=z=>{let t=z.data;try{if(t.action==="init")q.init(t),self.postMessage({id:t.id,isInitComplete:!0});else if(t.action==="initStart")q.initStart(t);else if(t.action==="initChunk")q.initChunk(t);else if(t.action==="initEnd")q.initEnd(),self.postMessage({id:t.id,isInitComplete:!0});else if(t.action==="filter")q.applyFilter(t),self.postMessage({id:t.id,isFilterComplete:!0});else if(t.action==="reconfigure")q.reconfigure(t),self.postMessage({id:t.id,isReconfigureComplete:!0});else if(t.action==="transaction")self.postMessage({id:t.id,isTransactionComplete:!0,rowCount:q.applyTransaction(t)});else if(t.action==="compute"){let e=q.compute(t),n=[e.cellMatrix.keys.buffer,e.cellMatrix.sums.buffer,e.cellMatrix.counts.buffer];if(e.indexMapsVersion!==void 0&&e.indexMapsVersion===dt){let r={...e,rowIndexMap:void 0,columnIndexMap:void 0,cardinalityMap:void 0,indexMapsOmitted:!0};postMessage(r,n);}else e.indexMapsVersion!==void 0&&(dt=e.indexMapsVersion),postMessage(e,n);}}catch(e){self.postMessage({id:t.id,error:e instanceof Error?e.message:String(e)});}};
|
|
1
|
+
'use strict';var nt=class{size=1;nodeToParent;nodeToVal;nodeToDepth;nodeChildCount;childrenMap;constructor(t){this.nodeToParent=new Int32Array(t).fill(-1),this.nodeToVal=new Int32Array(t).fill(-1),this.nodeToDepth=new Int32Array(t).fill(0),this.nodeChildCount=new Int32Array(t).fill(0),this.childrenMap=new Map;}expandCapacity(){let t=this.nodeToParent.length*2,e=new Int32Array(t).fill(-1);e.set(this.nodeToParent),this.nodeToParent=e;let n=new Int32Array(t).fill(-1);n.set(this.nodeToVal),this.nodeToVal=n;let r=new Int32Array(t).fill(0);r.set(this.nodeToDepth),this.nodeToDepth=r;let i=new Int32Array(t).fill(0);i.set(this.nodeChildCount),this.nodeChildCount=i;}insert(t,e){let n=0;for(let r=0;r<e;r++){let i=t[r],s=this.childrenMap.get(n);s||(s=new Map,this.childrenMap.set(n,s));let c=s.get(i);c===void 0&&(this.size>=this.nodeToParent.length&&this.expandCapacity(),c=this.size++,this.nodeToParent[c]=n,this.nodeToVal[c]=i,this.nodeToDepth[c]=r+1,this.nodeChildCount[n]++,s.set(i,c)),n=c;}return n}};function X(z,t){if(z.length>=t)return z;let e=new z.constructor(Math.max(t,Math.ceil(z.length*1.5)));return e.set(z),e}function ct(z,t,e){let n=t[0];for(let r=0;r<t.length;r++){let i=t[r]+1,s=r+1<t.length?t[r+1]:e;z.copyWithin(n,i,s),n+=s-i;}}var lt=class{dictionary=[];rowFields=[];colFields=[];dataFields=[];storedColumns={};storedRowCount=0;lastMask=null;isBuilt=false;buildState=null;activeFilters=null;activePrefilter=null;tracking=false;groupRows=new Int32Array(0);groupMap=new Map;rowLive=null;colLive=null;rowTrie;colTrie;cardinalityMap={};rowPathStrs=[];colPathStrs=[];rowIndexMapCache={};columnIndexMapCache={};buildVersion=0;groupCount=0;leafGroupRowIds;leafGroupColIds;leafGroupMeasures;leafGroupCounts;leafGroupMins;leafGroupMaxes;leafGroupDistinctSets=new Map;rowGroupOf=null;init(t){this.dictionary=t.dictionary,this.rowFields=t.rowFields,this.colFields=t.colFields,this.dataFields=t.dataFields,t.workerBootstrap&&t.workerBootstrap.length>0&&console.warn("[PivotGrid Worker] workerBootstrap is deprecated for security reasons. All calculations are executed on the main thread."),this.storedRowCount=t.rowCount,this.storedColumns={};for(let[e,n]of Object.entries(t.columnarData))n.type==="int32"&&(this.storedColumns[e]={type:"int32",array:new Int32Array(n.buffer)}),n.type==="float64"&&(this.storedColumns[e]={type:"float64",array:new Float64Array(n.buffer)});this.lastMask=null,this.activeFilters=this.activePrefilter=null,t.deferBuild?this.isBuilt=false:this.buildFromMask(null);}reconfigure(t){if(this.rowFields=t.rowFields,this.colFields=t.colFields,this.dataFields=t.dataFields,this.appendDictionary(t.dictionaryAppend),t.newColumns)for(let[e,n]of Object.entries(t.newColumns))n.type==="int32"&&(this.storedColumns[e]={type:"int32",array:new Int32Array(n.buffer)}),n.type==="float64"&&(this.storedColumns[e]={type:"float64",array:new Float64Array(n.buffer)});this.buildFromMask(this.lastMask);}initStart(t){this.dictionary=t.dictionary,this.rowFields=t.rowFields,this.colFields=t.colFields,this.dataFields=t.dataFields,t.workerBootstrap&&t.workerBootstrap.length>0&&console.warn("[PivotGrid Worker] workerBootstrap is deprecated for security reasons. All calculations are executed on the main thread."),this.storedRowCount=t.rowCountTotal,this.storedColumns={};for(let[e,n]of Object.entries(t.columnTypes))n==="int32"?this.storedColumns[e]={type:"int32",array:new Int32Array(t.rowCountTotal)}:this.storedColumns[e]={type:"float64",array:new Float64Array(t.rowCountTotal)};this.setFilters((t.filters||[]).map(e=>({fieldId:e.fieldId,filterType:e.filterType,ids:new Set,pending:new Set(e.valueStrings)})),t.prefilter),this.resolveIncrementalFilterStrings(0),this.isBuilt=false,this.beginBuild();}initChunk(t){this.appendDictionary(t.dictionaryAppend)&&this.ensureCardCapacity();for(let[e,n]of Object.entries(t.columns)){let r=this.storedColumns[e];r&&(r.type==="int32"?r.array.set(new Int32Array(n),t.start):r.array.set(new Float64Array(n),t.start));}this.lastMask&&this.computeMaskRange(t.start,t.end),this.processRange(t.start,t.end,this.lastMask);}initEnd(){this.finalizeBuild();}appendDictionary(t){if(!t||t.length===0)return false;let e=this.dictionary.length;for(let n of t)this.dictionary.push(n);return this.resolveIncrementalFilterStrings(e),true}setFilters(t,e){this.activeFilters=t.length>0?t:null,this.activePrefilter=e&&e.conditions.length>0?e:null,this.lastMask=this.activeFilters||this.activePrefilter?new Uint8Array(this.storedRowCount):null;}resolveIncrementalFilterStrings(t){let e=this.activeFilters;if(!e)return;let n=0;for(let r of e)n+=r.pending.size;if(n!==0)for(let r=t;r<this.dictionary.length;r++){let i=this.dictionary[r];for(let s of e)s.pending.delete(i)&&s.ids.add(r);}}computeMaskRange(t,e){let n=this.lastMask;if(n.fill(1,t,e),this.activeFilters)for(let r of this.activeFilters){let i=this.storedColumns[r.fieldId];if(!i||i.type!=="int32")continue;let s=i.array,c=r.ids;if(r.filterType==="exclude")for(let a=t;a<e;a++)n[a]&&c.has(s[a])&&(n[a]=0);else for(let a=t;a<e;a++)n[a]&&!c.has(s[a])&&(n[a]=0);}if(this.activePrefilter)for(let r=t;r<e;r++)n[r]&&!this.evaluatePrefilterGroup(this.activePrefilter,r)&&(n[r]=0);}applyFilter(t){this.setFilters(t.filters.map(e=>({fieldId:e.fieldId,filterType:e.filterType,ids:new Set(e.dictIds),pending:new Set(e.valueStrings)})),t.prefilter),this.lastMask&&this.computeMaskRange(0,this.storedRowCount),this.buildFromMask(this.lastMask);}evaluatePrefilterGroup(t,e){if(!t.conditions||t.conditions.length===0)return true;if(t.logicalOperator==="and"){for(let n of t.conditions)if("logicalOperator"in n){if(!this.evaluatePrefilterGroup(n,e))return false}else if(!this.evaluatePrefilterCondition(n,e))return false;return true}else {for(let n of t.conditions)if("logicalOperator"in n){if(this.evaluatePrefilterGroup(n,e))return true}else if(this.evaluatePrefilterCondition(n,e))return true;return false}}evaluatePrefilterCondition(t,e){let n=this.storedColumns[t.fieldId];if(!n)return true;if(n.type==="float64"){let f=n.array[e],y=Number(t.value);switch(t.operator){case "=":return f===y;case "<>":return f!==y;case ">":return f>y;case ">=":return f>=y;case "<":return f<y;case "<=":return f<=y;case "isnull":return isNaN(f)||f===0;case "isnotnull":return !isNaN(f)&&f!==0;default:return true}}let r=n.array[e],i=this.dictionary[r]||"",s=String(t.value??""),c=Number(i),a=Number(s),d=i!==""&&s!==""&&!isNaN(c)&&!isNaN(a);switch(t.operator){case "=":return i===s;case "<>":return i!==s;case ">":return d?c>a:i>s;case ">=":return d?c>=a:i>=s;case "<":return d?c<a:i<s;case "<=":return d?c<=a:i<=s;case "contains":return i.toLowerCase().includes(s.toLowerCase());case "notcontains":return !i.toLowerCase().includes(s.toLowerCase());case "startswith":return i.toLowerCase().startsWith(s.toLowerCase());case "endswith":return i.toLowerCase().endsWith(s.toLowerCase());case "isnull":return i===""||i==="(Blank)";case "isnotnull":return i!==""&&i!=="(Blank)";case "in":return Array.isArray(t.value)?t.value.map(String).includes(i):true;case "notin":return Array.isArray(t.value)?!t.value.map(String).includes(i):true;default:return true}}buildFromMask(t){this.beginBuild(),this.processRange(0,this.storedRowCount,t),this.finalizeBuild();}beginBuild(){let t=this.storedRowCount,e=this.storedColumns,n=this.rowFields.length,r=this.colFields.length,i=new Array(n);for(let u=0;u<n;u++)i[u]=e[this.rowFields[u].id].array;let s=new Array(r);for(let u=0;u<r;u++)s[u]=e[this.colFields[u].id].array;let c=this.dictionary.length,a=this.rowFields.map(u=>{let v=e[u.id];return v&&v.type==="int32"?new Uint8Array(c):null}),d=this.colFields.map(u=>{let v=e[u.id];return v&&v.type==="int32"?new Uint8Array(c):null});this.rowTrie=new nt(2e5),this.colTrie=new nt(2e5);let f=this.dataFields.length,y=this.dataFields.map(u=>u.summaryType||"sum"),p=y.some(u=>u==="count"||u==="avg"),G=y.some(u=>u==="min"),C=y.some(u=>u==="max"),M=y.some(u=>u==="distinct"),T=new Array(f);for(let u=0;u<f;u++)T[u]=e[this.dataFields[u].id].array;let F=Math.min(t,2e5),l=G?new Float64Array(F*f):new Float64Array(0),w=C?new Float64Array(F*f):new Float64Array(0);this.leafGroupDistinctSets=M?new Map:new Map,G&&l.fill(1/0),C&&w.fill(-1/0),this.buildState={rPath:new Int32Array(n),cPath:new Int32Array(r),rowColArrays:i,colColArrays:s,dataColArrays:T,rowCardSeen:a,colCardSeen:d,rowCardCounts:new Int32Array(n),colCardCounts:new Int32Array(r),summaryTypes:y,allSums:y.every(u=>u==="sum"),needsCounts:p,needsMins:G,needsMaxes:C,groupMap:new Map,leafRowIds:new Int32Array(F),leafColIds:new Int32Array(F),leafMeasures:new Float64Array(F*f),leafCounts:p?new Float64Array(F*f):new Float64Array(0),leafMins:l,leafMaxes:w,rowGroupOf:this.tracking||y.includes("custom")?new Int32Array(t).fill(-1):null,gCount:0};}ensureCardCapacity(){let t=this.buildState;if(!t)return;let e=this.dictionary.length,n=r=>{if(r===null||r.length>=e)return r;let i=new Uint8Array(Math.max(e,r.length*2));return i.set(r),i};for(let r=0;r<t.rowCardSeen.length;r++)t.rowCardSeen[r]=n(t.rowCardSeen[r]);for(let r=0;r<t.colCardSeen.length;r++)t.colCardSeen[r]=n(t.colCardSeen[r]);}processRange(t,e,n){let r=this.buildState,{rPath:i,cPath:s,rowColArrays:c,colColArrays:a,dataColArrays:d,rowCardSeen:f,colCardSeen:y,rowCardCounts:p,colCardCounts:G,summaryTypes:C,allSums:M,needsCounts:T,needsMins:F,needsMaxes:l,groupMap:w,rowGroupOf:u}=r,v=c.length,m=a.length,b=d.length,D=this.rowTrie,E=this.colTrie,W=r.leafRowIds,J=r.leafColIds,_=r.leafMeasures,Q=r.leafCounts,Y=r.leafMins,Z=r.leafMaxes,K=r.gCount;for(let R=t;R<e;R++){if(n&&!n[R])continue;for(let h=0;h<v;h++){let A=c[h][R];i[h]=A;let g=f[h];g!==null&&g[A]===0&&(g[A]=1,p[h]++);}let $=D.insert(i,v);for(let h=0;h<m;h++){let A=a[h][R];s[h]=A;let g=y[h];g!==null&&g[A]===0&&(g[A]=1,G[h]++);}let rt=E.insert(s,m),it=$*67108864+rt,L=w.get(it);if(L===void 0){if(L=K++,w.set(it,L),L>=W.length){let h=L*2,A=new Int32Array(h);A.set(W),W=A;let g=new Int32Array(h);g.set(J),J=g;let H=new Float64Array(h*b);if(H.set(_),_=H,T){let o=new Float64Array(h*b);o.set(Q),Q=o;}if(F){let o=new Float64Array(h*b);o.fill(1/0),o.set(Y),Y=o;}if(l){let o=new Float64Array(h*b);o.fill(-1/0),o.set(Z),Z=o;}}W[L]=$,J[L]=rt;}u!==null&&(u[R]=L);let st=L*b;if(M)for(let h=0;h<b;h++)_[st+h]+=d[h][R];else for(let h=0;h<b;h++){let A=d[h][R],g=st+h;switch(C[h]){case "sum":_[g]+=A;break;case "count":Q[g]+=1;break;case "avg":_[g]+=A,Q[g]+=1;break;case "min":A<Y[g]&&(Y[g]=A);break;case "max":A>Z[g]&&(Z[g]=A);break;case "distinct":{if(A===0&&d[h]instanceof Int32Array)break;let H=this.leafGroupDistinctSets.get(g);H||(H=new Set,this.leafGroupDistinctSets.set(g,H)),H.add(A);break}default:_[g]+=A;break}}}r.leafRowIds=W,r.leafColIds=J,r.leafMeasures=_,r.leafCounts=Q,r.leafMins=Y,r.leafMaxes=Z,r.gCount=K;}finalizeBuild(){let t=this.buildState,{needsCounts:e,needsMins:n,needsMaxes:r,gCount:i}=t,s=t.dataColArrays.length,c=t.rowColArrays.length,a=t.colColArrays.length;this.groupCount=i,this.leafGroupRowIds=t.leafRowIds.slice(0,i),this.leafGroupColIds=t.leafColIds.slice(0,i),this.leafGroupMeasures=t.leafMeasures.slice(0,i*s),this.leafGroupCounts=e?t.leafCounts.slice(0,i*s):t.leafCounts,this.leafGroupMins=n?t.leafMins.slice(0,i*s):t.leafMins,this.leafGroupMaxes=r?t.leafMaxes.slice(0,i*s):t.leafMaxes,this.rowGroupOf=t.rowGroupOf,this.cardinalityMap={};for(let d=0;d<c;d++)t.rowCardSeen[d]!==null&&(this.cardinalityMap[this.rowFields[d].id]=t.rowCardCounts[d]);for(let d=0;d<a;d++)t.colCardSeen[d]!==null&&(this.cardinalityMap[this.colFields[d].id]=t.colCardCounts[d]);if(this.buildState=null,this.rowLive=this.colLive=null,this.tracking){this.groupMap=t.groupMap;let d=this.groupRows=new Int32Array(i),f=t.rowGroupOf;for(let y=0;y<this.storedRowCount;y++)f[y]>=0&&d[f[y]]++;}this.buildVersion++,this.isBuilt=true,this.rowPathStrs=this.buildPathStrs(this.rowTrie),this.colPathStrs=this.buildPathStrs(this.colTrie),this.rowIndexMapCache=this.buildIndexMap(this.rowPathStrs,null),this.columnIndexMapCache=this.buildIndexMap(this.colPathStrs,null);}buildPathStrs(t,e=[""]){let n=e;for(let r=e.length;r<t.size;r++){let i=t.nodeToParent[r],s=this.dictionary[t.nodeToVal[r]],c=n[i];n[r]=i===0?s===""?"|":s:c+"|"+s;}return n}buildIndexMap(t,e){let n={};for(let r=0;r<t.length;r++)(!e||e[r])&&(n[t[r]]=r);return n}applyTransaction(t){this.tracking||(this.tracking=true,this.buildFromMask(this.lastMask)),this.appendDictionary(t.dictionaryAppend);let{update:e,remove:n}=t,r=e.length,i=this.storedRowCount,s=i+t.addCount,c=this.storedColumns,a=new Set,d=false,f=this.rowGroupOf,y=l=>{let w=f[l];w<0||(f[l]=-1,--this.groupRows[w]===0&&(d=true),a.add(w));};e.forEach(y),n.forEach(y);for(let l in c){let w=c[l],u=t.columns[l];if(!u)throw new Error("transaction: no values for column "+l);let v=w.type==="int32"?new Int32Array(u):new Float64Array(u),m=w.array=X(w.array,s);for(let b=0;b<r;b++)m[e[b]]=v[b];m.set(v.subarray(r),i);}f=this.rowGroupOf=X(f,s),f.fill(-1,i,s);let p=this.lastMask&&(this.lastMask=X(this.lastMask,s));p&&(e.forEach(l=>this.computeMaskRange(l,l+1)),this.computeMaskRange(i,s));let G=this.rowFields.map(l=>c[l.id].array),C=this.colFields.map(l=>c[l.id].array),M=new Int32Array(G.length),T=new Int32Array(C.length),F=l=>{if(p&&!p[l])return;G.forEach((b,D)=>{M[D]=b[l];}),C.forEach((b,D)=>{T[D]=b[l];});let w=this.rowTrie.insert(M,M.length),u=this.colTrie.insert(T,T.length),v=w*67108864+u,m=this.groupMap.get(v);m===void 0&&(this.groupMap.set(v,m=this.groupCount++),(this.leafGroupRowIds=X(this.leafGroupRowIds,m+1))[m]=w,(this.leafGroupColIds=X(this.leafGroupColIds,m+1))[m]=u,this.groupRows=X(this.groupRows,m+1)),this.groupRows[m]++===0&&(d=true),f[l]=m,a.add(m);};e.forEach(F);for(let l=i;l<s;l++)F(l);if(this.storedRowCount=s-n.length,n.length>0){for(let l in c)ct(c[l].array,n,s);ct(f,n,s),p&&ct(p,n,s);}if(this.resumGroups(a),d){let l=0;for(let w=0;w<this.groupCount;w++)this.groupRows[w]===0&&l++;l>4096&&l>this.groupCount-l?this.buildFromMask(this.lastMask):(this.cardinalityMap={},[this.rowLive,this.rowPathStrs,this.rowIndexMapCache]=this.relive(this.rowTrie,this.leafGroupRowIds,this.rowFields,this.rowPathStrs),[this.colLive,this.colPathStrs,this.columnIndexMapCache]=this.relive(this.colTrie,this.leafGroupColIds,this.colFields,this.colPathStrs),this.buildVersion++);}return this.storedRowCount}resumGroups(t){if(t.size===0)return;let e=this.dataFields.length,n=this.dataFields.map(C=>C.summaryType||"sum"),r=this.dataFields.map(C=>this.storedColumns[C.id].array),i=this.groupCount*e,s=this.leafGroupMeasures=X(this.leafGroupMeasures,i),c=n.some(C=>C==="count"||C==="avg")?this.leafGroupCounts=X(this.leafGroupCounts,i):null,a=n.includes("min")?this.leafGroupMins=X(this.leafGroupMins,i):null,d=n.includes("max")?this.leafGroupMaxes=X(this.leafGroupMaxes,i):null,f=this.leafGroupDistinctSets,y=new Uint8Array(this.groupCount),p=0;for(let C of t){y[C]=1,p+=this.groupRows[C];for(let M=C*e;M<(C+1)*e;M++)s[M]=0,c&&(c[M]=0),a&&(a[M]=1/0),d&&(d[M]=-1/0),f.delete(M);}let G=this.rowGroupOf;for(let C=0;p>0&&C<this.storedRowCount;C++){let M=G[C];if(!(M<0||!y[M])){p--;for(let T=0;T<e;T++){let F=r[T][C],l=M*e+T;switch(n[T]){case "count":c[l]++;break;case "avg":s[l]+=F,c[l]++;break;case "min":F<a[l]&&(a[l]=F);break;case "max":F>d[l]&&(d[l]=F);break;case "distinct":{if(F===0&&r[T]instanceof Int32Array)break;let w=f.get(l);w||f.set(l,w=new Set),w.add(F);break}default:s[l]+=F;}}}}}relive(t,e,n,r){let i=new Uint8Array(t.size);i[0]=1;for(let a=0;a<this.groupCount;a++)if(this.groupRows[a]!==0)for(let d=e[a];!i[d];d=t.nodeToParent[d])i[d]=1;let s=n.map(()=>new Set);t.nodeChildCount.fill(0,0,t.size);for(let a=1;a<t.size;a++)i[a]&&(t.nodeChildCount[t.nodeToParent[a]]++,s[t.nodeToDepth[a]-1]?.add(t.nodeToVal[a]));n.forEach((a,d)=>{this.cardinalityMap[a.id]=s[d].size;});let c=this.buildPathStrs(t,r);return [i,c,this.buildIndexMap(c,i)]}compute(t){this.isBuilt||this.buildFromMask(this.lastMask);let e=this.rowPathStrs,n=this.colPathStrs,r=new Uint8Array(this.rowTrie.size),i=new Set(t.expandedPaths),s=i.has(".*")||i.has("*");for(let o=0;o<this.rowTrie.size;o++)r[o]=s||i.has(e[o])?1:0;let c=new Uint8Array(this.colTrie.size),a=new Set(t.expandedColPaths),d=a.has(".*")||a.has("*");for(let o=0;o<this.colTrie.size;o++)c[o]=d||a.has(n[o])?1:0;let f=new Uint8Array(this.rowTrie.size);f[0]=1;for(let o=1;o<this.rowTrie.size;o++){let S=this.rowTrie.nodeToParent[o];(S===0||r[S])&&(!this.rowLive||this.rowLive[o])&&(f[o]=1);}let y=new Uint8Array(this.colTrie.size);y[0]=1;for(let o=1;o<this.colTrie.size;o++){let S=this.colTrie.nodeToParent[o];(S===0||c[S])&&(!this.colLive||this.colLive[o])&&(y[o]=1);}let p=this.dataFields.length,G=this.dataFields.map(o=>o.summaryType||"sum"),C=this.leafGroupMins.length>0,M=this.leafGroupMaxes.length>0,T=this.leafGroupCounts.length>0,F=this.leafGroupDistinctSets.size>0,l=new Map,w=0,u=1e4,v=new Float64Array(u),m=new Float64Array(u*p),b=new Int32Array(u*p),D=T?new Float64Array(u*p):null,E=C?new Float64Array(u*p):null,W=M?new Float64Array(u*p):null,J=F?new Map:new Map;E&&E.fill(1/0),W&&W.fill(-1/0);let _=new Int32Array(this.rowFields.length+1),Q=new Int32Array(this.colFields.length+1),Y=(o,S,I,O)=>{let tt=0,U=o;for(;U!==-1;)I[U]&&(O[tt++]=U),U=S.nodeToParent[U];return tt},Z=this.rowGroupOf!==null&&G.includes("custom"),K=Z?new Int32Array(this.groupCount+1):null,R=Z?new Int32Array(Math.max(16,this.groupCount*4)):null,$=0,rt=this.tracking?this.groupRows:null;for(let o=0;o<this.groupCount;o++){if(rt!==null&&rt[o]===0){K!==null&&(K[o+1]=$);continue}let S=this.leafGroupRowIds[o],I=this.leafGroupColIds[o],O=Y(S,this.rowTrie,f,_),tt=Y(I,this.colTrie,y,Q);for(let U=0;U<O;U++){let ot=_[U];for(let j=0;j<tt;j++){let at=Q[j],et=ot*67108864+at,P=l.get(et);if(P===void 0){if(P=w++,l.set(et,P),P>=v.length){let k=P*2,x=new Float64Array(k);x.set(v),v=x;let V=new Float64Array(k*p);V.set(m),m=V;let N=new Int32Array(k*p);if(N.set(b),b=N,D){let B=new Float64Array(k*p);B.set(D),D=B;}if(E){let B=new Float64Array(k*p);B.fill(1/0),B.set(E),E=B;}if(W){let B=new Float64Array(k*p);B.fill(-1/0),B.set(W),W=B;}}v[P]=et;}if(R!==null){if($>=R.length){let k=new Int32Array(R.length*2);k.set(R),R=k;}R[$++]=P;}for(let k=0;k<p;k++){let x=P*p+k,V=o*p+k;switch(G[k]){case "sum":m[x]+=this.leafGroupMeasures[V];break;case "count":m[x]+=this.leafGroupCounts[V];break;case "avg":m[x]+=this.leafGroupMeasures[V],D[x]+=this.leafGroupCounts[V];break;case "min":{let N=this.leafGroupMins[V];N<E[x]&&(E[x]=N);break}case "max":{let N=this.leafGroupMaxes[V];N>W[x]&&(W[x]=N);break}case "distinct":{let N=this.leafGroupDistinctSets.get(V);if(N){let B=J.get(x);B||(B=new Set,J.set(x,B));for(let ft of N)B.add(ft);}break}default:m[x]+=this.leafGroupMeasures[V];break}b[x]+=1;}}}K!==null&&(K[o+1]=$);}for(let o=0;o<w;o++)for(let S=0;S<p;S++){let I=o*p+S;switch(G[S]){case "avg":m[I]=D[I]>0?m[I]/D[I]:0;break;case "min":m[I]=E[I]!==1/0?E[I]:0;break;case "max":m[I]=W[I]!==-1/0?W[I]:0;break;case "distinct":{let O=J.get(I);m[I]=O?O.size:0;break}}}let it=v.slice(0,w),L=m.slice(0,w*p),st=b.slice(0,w*p),h=(o,S,I,O,tt)=>{let U=[];for(let j=0;j<O.length;j++)U[j]=O[j]?.id||"";let ot=j=>{let at=o.childrenMap.get(j);if(!at)return [];let et=[];for(let P of at.values())if(S[P]){let k=o.nodeToDepth[P]-1,x=I[P]===1;et.push({key:tt[P],value:this.dictionary[o.nodeToVal[P]],fieldId:U[k]||"",children:x?ot(P):[],isExpanded:x,isTotal:false,depth:k,hasChildren:o.nodeChildCount[P]>0});}return et};return ot(0)},A;if(this.rowGroupOf!==null&&K!==null&&R!==null){let o=this.storedRowCount,S={};for(let I=0;I<p;I++){if(G[I]!=="custom")continue;let O=this.dataFields[I].id;S[O]=this.storedColumns[O].array.slice(0,o);}A={rowGroupOf:this.rowGroupOf.slice(0,o),groupCellOffsets:K,groupCells:R.slice(0,$),values:S};}let g=h(this.rowTrie,f,r,this.rowFields,e),H=h(this.colTrie,y,c,this.colFields,n);return {id:t.id,rowTree:g,colTree:H,cellMatrix:{keys:it,sums:L,counts:st},customSummary:A,rowIndexMap:this.rowIndexMapCache,columnIndexMap:this.columnIndexMapCache,cardinalityMap:this.cardinalityMap,indexMapsVersion:this.buildVersion}}};var q=new lt,dt=-1;self.onmessage=z=>{let t=z.data;try{if(t.action==="init")q.init(t),self.postMessage({id:t.id,isInitComplete:!0});else if(t.action==="initStart")q.initStart(t);else if(t.action==="initChunk")q.initChunk(t);else if(t.action==="initEnd")q.initEnd(),self.postMessage({id:t.id,isInitComplete:!0});else if(t.action==="filter")q.applyFilter(t),self.postMessage({id:t.id,isFilterComplete:!0});else if(t.action==="reconfigure")q.reconfigure(t),self.postMessage({id:t.id,isReconfigureComplete:!0});else if(t.action==="transaction")self.postMessage({id:t.id,isTransactionComplete:!0,rowCount:q.applyTransaction(t)});else if(t.action==="compute"){let e=q.compute(t),n=[e.cellMatrix.keys.buffer,e.cellMatrix.sums.buffer,e.cellMatrix.counts.buffer];if(e.indexMapsVersion!==void 0&&e.indexMapsVersion===dt){let r={...e,rowIndexMap:void 0,columnIndexMap:void 0,cardinalityMap:void 0,indexMapsOmitted:!0};postMessage(r,n);}else e.indexMapsVersion!==void 0&&(dt=e.indexMapsVersion),postMessage(e,n);}}catch(e){self.postMessage({id:t.id,error:e instanceof Error?e.message:String(e)});}};
|
package/dist/pivot.worker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var nt=class{size=1;nodeToParent;nodeToVal;nodeToDepth;nodeChildCount;childrenMap;constructor(t){this.nodeToParent=new Int32Array(t).fill(-1),this.nodeToVal=new Int32Array(t).fill(-1),this.nodeToDepth=new Int32Array(t).fill(0),this.nodeChildCount=new Int32Array(t).fill(0),this.childrenMap=new Map;}expandCapacity(){let t=this.nodeToParent.length*2,e=new Int32Array(t).fill(-1);e.set(this.nodeToParent),this.nodeToParent=e;let n=new Int32Array(t).fill(-1);n.set(this.nodeToVal),this.nodeToVal=n;let r=new Int32Array(t).fill(0);r.set(this.nodeToDepth),this.nodeToDepth=r;let i=new Int32Array(t).fill(0);i.set(this.nodeChildCount),this.nodeChildCount=i;}insert(t,e){let n=0;for(let r=0;r<e;r++){let i=t[r],s=this.childrenMap.get(n);s||(s=new Map,this.childrenMap.set(n,s));let c=s.get(i);c===void 0&&(this.size>=this.nodeToParent.length&&this.expandCapacity(),c=this.size++,this.nodeToParent[c]=n,this.nodeToVal[c]=i,this.nodeToDepth[c]=r+1,this.nodeChildCount[n]++,s.set(i,c)),n=c;}return n}};function X(z,t){if(z.length>=t)return z;let e=new z.constructor(Math.max(t,Math.ceil(z.length*1.5)));return e.set(z),e}function ct(z,t,e){let n=t[0];for(let r=0;r<t.length;r++){let i=t[r]+1,s=r+1<t.length?t[r+1]:e;z.copyWithin(n,i,s),n+=s-i;}}var lt=class{dictionary=[];rowFields=[];colFields=[];dataFields=[];storedColumns={};storedRowCount=0;lastMask=null;isBuilt=false;buildState=null;activeFilters=null;activePrefilter=null;tracking=false;groupRows=new Int32Array(0);groupMap=new Map;rowLive=null;colLive=null;rowTrie;colTrie;cardinalityMap={};rowPathStrs=[];colPathStrs=[];rowIndexMapCache={};columnIndexMapCache={};buildVersion=0;groupCount=0;leafGroupRowIds;leafGroupColIds;leafGroupMeasures;leafGroupCounts;leafGroupMins;leafGroupMaxes;leafGroupDistinctSets=new Map;rowGroupOf=null;init(t){this.dictionary=t.dictionary,this.rowFields=t.rowFields,this.colFields=t.colFields,this.dataFields=t.dataFields,t.workerBootstrap&&t.workerBootstrap.length>0&&console.warn("[PivotGrid Worker] workerBootstrap is deprecated for security reasons. All calculations are executed on the main thread."),this.storedRowCount=t.rowCount,this.storedColumns={};for(let[e,n]of Object.entries(t.columnarData))n.type==="int32"&&(this.storedColumns[e]={type:"int32",array:new Int32Array(n.buffer)}),n.type==="float64"&&(this.storedColumns[e]={type:"float64",array:new Float64Array(n.buffer)});this.lastMask=null,this.activeFilters=this.activePrefilter=null,t.deferBuild?this.isBuilt=false:this.buildFromMask(null);}reconfigure(t){if(this.rowFields=t.rowFields,this.colFields=t.colFields,this.dataFields=t.dataFields,this.appendDictionary(t.dictionaryAppend),t.newColumns)for(let[e,n]of Object.entries(t.newColumns))n.type==="int32"&&(this.storedColumns[e]={type:"int32",array:new Int32Array(n.buffer)}),n.type==="float64"&&(this.storedColumns[e]={type:"float64",array:new Float64Array(n.buffer)});this.buildFromMask(this.lastMask);}initStart(t){this.dictionary=t.dictionary,this.rowFields=t.rowFields,this.colFields=t.colFields,this.dataFields=t.dataFields,t.workerBootstrap&&t.workerBootstrap.length>0&&console.warn("[PivotGrid Worker] workerBootstrap is deprecated for security reasons. All calculations are executed on the main thread."),this.storedRowCount=t.rowCountTotal,this.storedColumns={};for(let[e,n]of Object.entries(t.columnTypes))n==="int32"?this.storedColumns[e]={type:"int32",array:new Int32Array(t.rowCountTotal)}:this.storedColumns[e]={type:"float64",array:new Float64Array(t.rowCountTotal)};this.setFilters((t.filters||[]).map(e=>({fieldId:e.fieldId,filterType:e.filterType,ids:new Set,pending:new Set(e.valueStrings)})),t.prefilter),this.resolveIncrementalFilterStrings(0),this.isBuilt=false,this.beginBuild();}initChunk(t){this.appendDictionary(t.dictionaryAppend)&&this.ensureCardCapacity();for(let[e,n]of Object.entries(t.columns)){let r=this.storedColumns[e];r&&(r.type==="int32"?r.array.set(new Int32Array(n),t.start):r.array.set(new Float64Array(n),t.start));}this.lastMask&&this.computeMaskRange(t.start,t.end),this.processRange(t.start,t.end,this.lastMask);}initEnd(){this.finalizeBuild();}appendDictionary(t){if(!t||t.length===0)return false;let e=this.dictionary.length;for(let n of t)this.dictionary.push(n);return this.resolveIncrementalFilterStrings(e),true}setFilters(t,e){this.activeFilters=t.length>0?t:null,this.activePrefilter=e&&e.conditions.length>0?e:null,this.lastMask=this.activeFilters||this.activePrefilter?new Uint8Array(this.storedRowCount):null;}resolveIncrementalFilterStrings(t){let e=this.activeFilters;if(!e)return;let n=0;for(let r of e)n+=r.pending.size;if(n!==0)for(let r=t;r<this.dictionary.length;r++){let i=this.dictionary[r];for(let s of e)s.pending.delete(i)&&s.ids.add(r);}}computeMaskRange(t,e){let n=this.lastMask;if(n.fill(1,t,e),this.activeFilters)for(let r of this.activeFilters){let i=this.storedColumns[r.fieldId];if(!i||i.type!=="int32")continue;let s=i.array,c=r.ids;if(r.filterType==="exclude")for(let a=t;a<e;a++)n[a]&&c.has(s[a])&&(n[a]=0);else for(let a=t;a<e;a++)n[a]&&!c.has(s[a])&&(n[a]=0);}if(this.activePrefilter)for(let r=t;r<e;r++)n[r]&&!this.evaluatePrefilterGroup(this.activePrefilter,r)&&(n[r]=0);}applyFilter(t){this.setFilters(t.filters.map(e=>({fieldId:e.fieldId,filterType:e.filterType,ids:new Set(e.dictIds),pending:new Set(e.valueStrings)})),t.prefilter),this.lastMask&&this.computeMaskRange(0,this.storedRowCount),this.buildFromMask(this.lastMask);}evaluatePrefilterGroup(t,e){if(!t.conditions||t.conditions.length===0)return true;if(t.logicalOperator==="and"){for(let n of t.conditions)if("logicalOperator"in n){if(!this.evaluatePrefilterGroup(n,e))return false}else if(!this.evaluatePrefilterCondition(n,e))return false;return true}else {for(let n of t.conditions)if("logicalOperator"in n){if(this.evaluatePrefilterGroup(n,e))return true}else if(this.evaluatePrefilterCondition(n,e))return true;return false}}evaluatePrefilterCondition(t,e){let n=this.storedColumns[t.fieldId];if(!n)return true;if(n.type==="float64"){let f=n.array[e],y=Number(t.value);switch(t.operator){case "=":return f===y;case "<>":return f!==y;case ">":return f>y;case ">=":return f>=y;case "<":return f<y;case "<=":return f<=y;case "isnull":return isNaN(f)||f===0;case "isnotnull":return !isNaN(f)&&f!==0;default:return true}}let r=n.array[e],i=this.dictionary[r]||"",s=String(t.value??""),c=Number(i),a=Number(s),d=i!==""&&s!==""&&!isNaN(c)&&!isNaN(a);switch(t.operator){case "=":return i===s;case "<>":return i!==s;case ">":return d?c>a:i>s;case ">=":return d?c>=a:i>=s;case "<":return d?c<a:i<s;case "<=":return d?c<=a:i<=s;case "contains":return i.toLowerCase().includes(s.toLowerCase());case "notcontains":return !i.toLowerCase().includes(s.toLowerCase());case "startswith":return i.toLowerCase().startsWith(s.toLowerCase());case "endswith":return i.toLowerCase().endsWith(s.toLowerCase());case "isnull":return i===""||i==="(Blank)";case "isnotnull":return i!==""&&i!=="(Blank)";case "in":return Array.isArray(t.value)?t.value.map(String).includes(i):true;case "notin":return Array.isArray(t.value)?!t.value.map(String).includes(i):true;default:return true}}buildFromMask(t){this.beginBuild(),this.processRange(0,this.storedRowCount,t),this.finalizeBuild();}beginBuild(){let t=this.storedRowCount,e=this.storedColumns,n=this.rowFields.length,r=this.colFields.length,i=new Array(n);for(let u=0;u<n;u++)i[u]=e[this.rowFields[u].id].array;let s=new Array(r);for(let u=0;u<r;u++)s[u]=e[this.colFields[u].id].array;let c=this.dictionary.length,a=this.rowFields.map(u=>{let v=e[u.id];return v&&v.type==="int32"?new Uint8Array(c):null}),d=this.colFields.map(u=>{let v=e[u.id];return v&&v.type==="int32"?new Uint8Array(c):null});this.rowTrie=new nt(2e5),this.colTrie=new nt(2e5);let f=this.dataFields.length,y=this.dataFields.map(u=>u.summaryType||"sum"),p=y.some(u=>u==="count"||u==="avg"),G=y.some(u=>u==="min"),C=y.some(u=>u==="max"),M=y.some(u=>u==="distinct"),T=new Array(f);for(let u=0;u<f;u++)T[u]=e[this.dataFields[u].id].array;let F=Math.min(t,2e5),l=G?new Float64Array(F*f):new Float64Array(0),w=C?new Float64Array(F*f):new Float64Array(0);this.leafGroupDistinctSets=M?new Map:new Map,G&&l.fill(1/0),C&&w.fill(-1/0),this.buildState={rPath:new Int32Array(n),cPath:new Int32Array(r),rowColArrays:i,colColArrays:s,dataColArrays:T,rowCardSeen:a,colCardSeen:d,rowCardCounts:new Int32Array(n),colCardCounts:new Int32Array(r),summaryTypes:y,allSums:y.every(u=>u==="sum"),needsCounts:p,needsMins:G,needsMaxes:C,groupMap:new Map,leafRowIds:new Int32Array(F),leafColIds:new Int32Array(F),leafMeasures:new Float64Array(F*f),leafCounts:p?new Float64Array(F*f):new Float64Array(0),leafMins:l,leafMaxes:w,rowGroupOf:this.tracking||y.includes("custom")?new Int32Array(t).fill(-1):null,gCount:0};}ensureCardCapacity(){let t=this.buildState;if(!t)return;let e=this.dictionary.length,n=r=>{if(r===null||r.length>=e)return r;let i=new Uint8Array(Math.max(e,r.length*2));return i.set(r),i};for(let r=0;r<t.rowCardSeen.length;r++)t.rowCardSeen[r]=n(t.rowCardSeen[r]);for(let r=0;r<t.colCardSeen.length;r++)t.colCardSeen[r]=n(t.colCardSeen[r]);}processRange(t,e,n){let r=this.buildState,{rPath:i,cPath:s,rowColArrays:c,colColArrays:a,dataColArrays:d,rowCardSeen:f,colCardSeen:y,rowCardCounts:p,colCardCounts:G,summaryTypes:C,allSums:M,needsCounts:T,needsMins:F,needsMaxes:l,groupMap:w,rowGroupOf:u}=r,v=c.length,m=a.length,b=d.length,D=this.rowTrie,E=this.colTrie,W=r.leafRowIds,J=r.leafColIds,_=r.leafMeasures,Q=r.leafCounts,Y=r.leafMins,Z=r.leafMaxes,K=r.gCount;for(let R=t;R<e;R++){if(n&&!n[R])continue;for(let h=0;h<v;h++){let A=c[h][R];i[h]=A;let g=f[h];g!==null&&g[A]===0&&(g[A]=1,p[h]++);}let $=D.insert(i,v);for(let h=0;h<m;h++){let A=a[h][R];s[h]=A;let g=y[h];g!==null&&g[A]===0&&(g[A]=1,G[h]++);}let rt=E.insert(s,m),it=$*67108864+rt,L=w.get(it);if(L===void 0){if(L=K++,w.set(it,L),L>=W.length){let h=L*2,A=new Int32Array(h);A.set(W),W=A;let g=new Int32Array(h);g.set(J),J=g;let H=new Float64Array(h*b);if(H.set(_),_=H,T){let o=new Float64Array(h*b);o.set(Q),Q=o;}if(F){let o=new Float64Array(h*b);o.fill(1/0),o.set(Y),Y=o;}if(l){let o=new Float64Array(h*b);o.fill(-1/0),o.set(Z),Z=o;}}W[L]=$,J[L]=rt;}u!==null&&(u[R]=L);let st=L*b;if(M)for(let h=0;h<b;h++)_[st+h]+=d[h][R];else for(let h=0;h<b;h++){let A=d[h][R],g=st+h;switch(C[h]){case "sum":_[g]+=A;break;case "count":Q[g]+=1;break;case "avg":_[g]+=A,Q[g]+=1;break;case "min":A<Y[g]&&(Y[g]=A);break;case "max":A>Z[g]&&(Z[g]=A);break;case "distinct":{if(A===0&&d[h]instanceof Int32Array)break;let H=this.leafGroupDistinctSets.get(g);H||(H=new Set,this.leafGroupDistinctSets.set(g,H)),H.add(A);break}default:_[g]+=A;break}}}r.leafRowIds=W,r.leafColIds=J,r.leafMeasures=_,r.leafCounts=Q,r.leafMins=Y,r.leafMaxes=Z,r.gCount=K;}finalizeBuild(){let t=this.buildState,{needsCounts:e,needsMins:n,needsMaxes:r,gCount:i}=t,s=t.dataColArrays.length,c=t.rowColArrays.length,a=t.colColArrays.length;this.groupCount=i,this.leafGroupRowIds=t.leafRowIds.slice(0,i),this.leafGroupColIds=t.leafColIds.slice(0,i),this.leafGroupMeasures=t.leafMeasures.slice(0,i*s),this.leafGroupCounts=e?t.leafCounts.slice(0,i*s):t.leafCounts,this.leafGroupMins=n?t.leafMins.slice(0,i*s):t.leafMins,this.leafGroupMaxes=r?t.leafMaxes.slice(0,i*s):t.leafMaxes,this.rowGroupOf=t.rowGroupOf,this.cardinalityMap={};for(let d=0;d<c;d++)t.rowCardSeen[d]!==null&&(this.cardinalityMap[this.rowFields[d].id]=t.rowCardCounts[d]);for(let d=0;d<a;d++)t.colCardSeen[d]!==null&&(this.cardinalityMap[this.colFields[d].id]=t.colCardCounts[d]);if(this.buildState=null,this.rowLive=this.colLive=null,this.tracking){this.groupMap=t.groupMap;let d=this.groupRows=new Int32Array(i),f=t.rowGroupOf;for(let y=0;y<this.storedRowCount;y++)f[y]>=0&&d[f[y]]++;}this.buildVersion++,this.isBuilt=true,this.rowPathStrs=this.buildPathStrs(this.rowTrie),this.colPathStrs=this.buildPathStrs(this.colTrie),this.rowIndexMapCache=this.buildIndexMap(this.rowPathStrs,null),this.columnIndexMapCache=this.buildIndexMap(this.colPathStrs,null);}buildPathStrs(t,e=[""]){let n=e;for(let r=e.length;r<t.size;r++){let i=t.nodeToParent[r],s=this.dictionary[t.nodeToVal[r]],c=n[i];n[r]=c?c+"|"+s:s;}return n}buildIndexMap(t,e){let n={};for(let r=0;r<t.length;r++)(!e||e[r])&&(n[t[r]]=r);return n}applyTransaction(t){this.tracking||(this.tracking=true,this.buildFromMask(this.lastMask)),this.appendDictionary(t.dictionaryAppend);let{update:e,remove:n}=t,r=e.length,i=this.storedRowCount,s=i+t.addCount,c=this.storedColumns,a=new Set,d=false,f=this.rowGroupOf,y=l=>{let w=f[l];w<0||(f[l]=-1,--this.groupRows[w]===0&&(d=true),a.add(w));};e.forEach(y),n.forEach(y);for(let l in c){let w=c[l],u=t.columns[l];if(!u)throw new Error("transaction: no values for column "+l);let v=w.type==="int32"?new Int32Array(u):new Float64Array(u),m=w.array=X(w.array,s);for(let b=0;b<r;b++)m[e[b]]=v[b];m.set(v.subarray(r),i);}f=this.rowGroupOf=X(f,s),f.fill(-1,i,s);let p=this.lastMask&&(this.lastMask=X(this.lastMask,s));p&&(e.forEach(l=>this.computeMaskRange(l,l+1)),this.computeMaskRange(i,s));let G=this.rowFields.map(l=>c[l.id].array),C=this.colFields.map(l=>c[l.id].array),M=new Int32Array(G.length),T=new Int32Array(C.length),F=l=>{if(p&&!p[l])return;G.forEach((b,D)=>{M[D]=b[l];}),C.forEach((b,D)=>{T[D]=b[l];});let w=this.rowTrie.insert(M,M.length),u=this.colTrie.insert(T,T.length),v=w*67108864+u,m=this.groupMap.get(v);m===void 0&&(this.groupMap.set(v,m=this.groupCount++),(this.leafGroupRowIds=X(this.leafGroupRowIds,m+1))[m]=w,(this.leafGroupColIds=X(this.leafGroupColIds,m+1))[m]=u,this.groupRows=X(this.groupRows,m+1)),this.groupRows[m]++===0&&(d=true),f[l]=m,a.add(m);};e.forEach(F);for(let l=i;l<s;l++)F(l);if(this.storedRowCount=s-n.length,n.length>0){for(let l in c)ct(c[l].array,n,s);ct(f,n,s),p&&ct(p,n,s);}if(this.resumGroups(a),d){let l=0;for(let w=0;w<this.groupCount;w++)this.groupRows[w]===0&&l++;l>4096&&l>this.groupCount-l?this.buildFromMask(this.lastMask):(this.cardinalityMap={},[this.rowLive,this.rowPathStrs,this.rowIndexMapCache]=this.relive(this.rowTrie,this.leafGroupRowIds,this.rowFields,this.rowPathStrs),[this.colLive,this.colPathStrs,this.columnIndexMapCache]=this.relive(this.colTrie,this.leafGroupColIds,this.colFields,this.colPathStrs),this.buildVersion++);}return this.storedRowCount}resumGroups(t){if(t.size===0)return;let e=this.dataFields.length,n=this.dataFields.map(C=>C.summaryType||"sum"),r=this.dataFields.map(C=>this.storedColumns[C.id].array),i=this.groupCount*e,s=this.leafGroupMeasures=X(this.leafGroupMeasures,i),c=n.some(C=>C==="count"||C==="avg")?this.leafGroupCounts=X(this.leafGroupCounts,i):null,a=n.includes("min")?this.leafGroupMins=X(this.leafGroupMins,i):null,d=n.includes("max")?this.leafGroupMaxes=X(this.leafGroupMaxes,i):null,f=this.leafGroupDistinctSets,y=new Uint8Array(this.groupCount),p=0;for(let C of t){y[C]=1,p+=this.groupRows[C];for(let M=C*e;M<(C+1)*e;M++)s[M]=0,c&&(c[M]=0),a&&(a[M]=1/0),d&&(d[M]=-1/0),f.delete(M);}let G=this.rowGroupOf;for(let C=0;p>0&&C<this.storedRowCount;C++){let M=G[C];if(!(M<0||!y[M])){p--;for(let T=0;T<e;T++){let F=r[T][C],l=M*e+T;switch(n[T]){case "count":c[l]++;break;case "avg":s[l]+=F,c[l]++;break;case "min":F<a[l]&&(a[l]=F);break;case "max":F>d[l]&&(d[l]=F);break;case "distinct":{if(F===0&&r[T]instanceof Int32Array)break;let w=f.get(l);w||f.set(l,w=new Set),w.add(F);break}default:s[l]+=F;}}}}}relive(t,e,n,r){let i=new Uint8Array(t.size);i[0]=1;for(let a=0;a<this.groupCount;a++)if(this.groupRows[a]!==0)for(let d=e[a];!i[d];d=t.nodeToParent[d])i[d]=1;let s=n.map(()=>new Set);t.nodeChildCount.fill(0,0,t.size);for(let a=1;a<t.size;a++)i[a]&&(t.nodeChildCount[t.nodeToParent[a]]++,s[t.nodeToDepth[a]-1]?.add(t.nodeToVal[a]));n.forEach((a,d)=>{this.cardinalityMap[a.id]=s[d].size;});let c=this.buildPathStrs(t,r);return [i,c,this.buildIndexMap(c,i)]}compute(t){this.isBuilt||this.buildFromMask(this.lastMask);let e=this.rowPathStrs,n=this.colPathStrs,r=new Uint8Array(this.rowTrie.size),i=new Set(t.expandedPaths),s=i.has(".*")||i.has("*");for(let o=0;o<this.rowTrie.size;o++)r[o]=s||i.has(e[o])?1:0;let c=new Uint8Array(this.colTrie.size),a=new Set(t.expandedColPaths),d=a.has(".*")||a.has("*");for(let o=0;o<this.colTrie.size;o++)c[o]=d||a.has(n[o])?1:0;let f=new Uint8Array(this.rowTrie.size);f[0]=1;for(let o=1;o<this.rowTrie.size;o++){let S=this.rowTrie.nodeToParent[o];(S===0||r[S])&&(!this.rowLive||this.rowLive[o])&&(f[o]=1);}let y=new Uint8Array(this.colTrie.size);y[0]=1;for(let o=1;o<this.colTrie.size;o++){let S=this.colTrie.nodeToParent[o];(S===0||c[S])&&(!this.colLive||this.colLive[o])&&(y[o]=1);}let p=this.dataFields.length,G=this.dataFields.map(o=>o.summaryType||"sum"),C=this.leafGroupMins.length>0,M=this.leafGroupMaxes.length>0,T=this.leafGroupCounts.length>0,F=this.leafGroupDistinctSets.size>0,l=new Map,w=0,u=1e4,v=new Float64Array(u),m=new Float64Array(u*p),b=new Int32Array(u*p),D=T?new Float64Array(u*p):null,E=C?new Float64Array(u*p):null,W=M?new Float64Array(u*p):null,J=F?new Map:new Map;E&&E.fill(1/0),W&&W.fill(-1/0);let _=new Int32Array(this.rowFields.length+1),Q=new Int32Array(this.colFields.length+1),Y=(o,S,I,O)=>{let tt=0,U=o;for(;U!==-1;)I[U]&&(O[tt++]=U),U=S.nodeToParent[U];return tt},Z=this.rowGroupOf!==null&&G.includes("custom"),K=Z?new Int32Array(this.groupCount+1):null,R=Z?new Int32Array(Math.max(16,this.groupCount*4)):null,$=0,rt=this.tracking?this.groupRows:null;for(let o=0;o<this.groupCount;o++){if(rt!==null&&rt[o]===0){K!==null&&(K[o+1]=$);continue}let S=this.leafGroupRowIds[o],I=this.leafGroupColIds[o],O=Y(S,this.rowTrie,f,_),tt=Y(I,this.colTrie,y,Q);for(let U=0;U<O;U++){let ot=_[U];for(let j=0;j<tt;j++){let at=Q[j],et=ot*67108864+at,P=l.get(et);if(P===void 0){if(P=w++,l.set(et,P),P>=v.length){let k=P*2,x=new Float64Array(k);x.set(v),v=x;let V=new Float64Array(k*p);V.set(m),m=V;let N=new Int32Array(k*p);if(N.set(b),b=N,D){let B=new Float64Array(k*p);B.set(D),D=B;}if(E){let B=new Float64Array(k*p);B.fill(1/0),B.set(E),E=B;}if(W){let B=new Float64Array(k*p);B.fill(-1/0),B.set(W),W=B;}}v[P]=et;}if(R!==null){if($>=R.length){let k=new Int32Array(R.length*2);k.set(R),R=k;}R[$++]=P;}for(let k=0;k<p;k++){let x=P*p+k,V=o*p+k;switch(G[k]){case "sum":m[x]+=this.leafGroupMeasures[V];break;case "count":m[x]+=this.leafGroupCounts[V];break;case "avg":m[x]+=this.leafGroupMeasures[V],D[x]+=this.leafGroupCounts[V];break;case "min":{let N=this.leafGroupMins[V];N<E[x]&&(E[x]=N);break}case "max":{let N=this.leafGroupMaxes[V];N>W[x]&&(W[x]=N);break}case "distinct":{let N=this.leafGroupDistinctSets.get(V);if(N){let B=J.get(x);B||(B=new Set,J.set(x,B));for(let ft of N)B.add(ft);}break}default:m[x]+=this.leafGroupMeasures[V];break}b[x]+=1;}}}K!==null&&(K[o+1]=$);}for(let o=0;o<w;o++)for(let S=0;S<p;S++){let I=o*p+S;switch(G[S]){case "avg":m[I]=D[I]>0?m[I]/D[I]:0;break;case "min":m[I]=E[I]!==1/0?E[I]:0;break;case "max":m[I]=W[I]!==-1/0?W[I]:0;break;case "distinct":{let O=J.get(I);m[I]=O?O.size:0;break}}}let it=v.slice(0,w),L=m.slice(0,w*p),st=b.slice(0,w*p),h=(o,S,I,O,tt)=>{let U=[];for(let j=0;j<O.length;j++)U[j]=O[j]?.id||"";let ot=j=>{let at=o.childrenMap.get(j);if(!at)return [];let et=[];for(let P of at.values())if(S[P]){let k=o.nodeToDepth[P]-1,x=I[P]===1;et.push({key:tt[P],value:this.dictionary[o.nodeToVal[P]],fieldId:U[k]||"",children:x?ot(P):[],isExpanded:x,isTotal:false,depth:k,hasChildren:o.nodeChildCount[P]>0});}return et};return ot(0)},A;if(this.rowGroupOf!==null&&K!==null&&R!==null){let o=this.storedRowCount,S={};for(let I=0;I<p;I++){if(G[I]!=="custom")continue;let O=this.dataFields[I].id;S[O]=this.storedColumns[O].array.slice(0,o);}A={rowGroupOf:this.rowGroupOf.slice(0,o),groupCellOffsets:K,groupCells:R.slice(0,$),values:S};}let g=h(this.rowTrie,f,r,this.rowFields,e),H=h(this.colTrie,y,c,this.colFields,n);return {id:t.id,rowTree:g,colTree:H,cellMatrix:{keys:it,sums:L,counts:st},customSummary:A,rowIndexMap:this.rowIndexMapCache,columnIndexMap:this.columnIndexMapCache,cardinalityMap:this.cardinalityMap,indexMapsVersion:this.buildVersion}}};var q=new lt,dt=-1;self.onmessage=z=>{let t=z.data;try{if(t.action==="init")q.init(t),self.postMessage({id:t.id,isInitComplete:!0});else if(t.action==="initStart")q.initStart(t);else if(t.action==="initChunk")q.initChunk(t);else if(t.action==="initEnd")q.initEnd(),self.postMessage({id:t.id,isInitComplete:!0});else if(t.action==="filter")q.applyFilter(t),self.postMessage({id:t.id,isFilterComplete:!0});else if(t.action==="reconfigure")q.reconfigure(t),self.postMessage({id:t.id,isReconfigureComplete:!0});else if(t.action==="transaction")self.postMessage({id:t.id,isTransactionComplete:!0,rowCount:q.applyTransaction(t)});else if(t.action==="compute"){let e=q.compute(t),n=[e.cellMatrix.keys.buffer,e.cellMatrix.sums.buffer,e.cellMatrix.counts.buffer];if(e.indexMapsVersion!==void 0&&e.indexMapsVersion===dt){let r={...e,rowIndexMap:void 0,columnIndexMap:void 0,cardinalityMap:void 0,indexMapsOmitted:!0};postMessage(r,n);}else e.indexMapsVersion!==void 0&&(dt=e.indexMapsVersion),postMessage(e,n);}}catch(e){self.postMessage({id:t.id,error:e instanceof Error?e.message:String(e)});}};
|
|
1
|
+
var nt=class{size=1;nodeToParent;nodeToVal;nodeToDepth;nodeChildCount;childrenMap;constructor(t){this.nodeToParent=new Int32Array(t).fill(-1),this.nodeToVal=new Int32Array(t).fill(-1),this.nodeToDepth=new Int32Array(t).fill(0),this.nodeChildCount=new Int32Array(t).fill(0),this.childrenMap=new Map;}expandCapacity(){let t=this.nodeToParent.length*2,e=new Int32Array(t).fill(-1);e.set(this.nodeToParent),this.nodeToParent=e;let n=new Int32Array(t).fill(-1);n.set(this.nodeToVal),this.nodeToVal=n;let r=new Int32Array(t).fill(0);r.set(this.nodeToDepth),this.nodeToDepth=r;let i=new Int32Array(t).fill(0);i.set(this.nodeChildCount),this.nodeChildCount=i;}insert(t,e){let n=0;for(let r=0;r<e;r++){let i=t[r],s=this.childrenMap.get(n);s||(s=new Map,this.childrenMap.set(n,s));let c=s.get(i);c===void 0&&(this.size>=this.nodeToParent.length&&this.expandCapacity(),c=this.size++,this.nodeToParent[c]=n,this.nodeToVal[c]=i,this.nodeToDepth[c]=r+1,this.nodeChildCount[n]++,s.set(i,c)),n=c;}return n}};function X(z,t){if(z.length>=t)return z;let e=new z.constructor(Math.max(t,Math.ceil(z.length*1.5)));return e.set(z),e}function ct(z,t,e){let n=t[0];for(let r=0;r<t.length;r++){let i=t[r]+1,s=r+1<t.length?t[r+1]:e;z.copyWithin(n,i,s),n+=s-i;}}var lt=class{dictionary=[];rowFields=[];colFields=[];dataFields=[];storedColumns={};storedRowCount=0;lastMask=null;isBuilt=false;buildState=null;activeFilters=null;activePrefilter=null;tracking=false;groupRows=new Int32Array(0);groupMap=new Map;rowLive=null;colLive=null;rowTrie;colTrie;cardinalityMap={};rowPathStrs=[];colPathStrs=[];rowIndexMapCache={};columnIndexMapCache={};buildVersion=0;groupCount=0;leafGroupRowIds;leafGroupColIds;leafGroupMeasures;leafGroupCounts;leafGroupMins;leafGroupMaxes;leafGroupDistinctSets=new Map;rowGroupOf=null;init(t){this.dictionary=t.dictionary,this.rowFields=t.rowFields,this.colFields=t.colFields,this.dataFields=t.dataFields,t.workerBootstrap&&t.workerBootstrap.length>0&&console.warn("[PivotGrid Worker] workerBootstrap is deprecated for security reasons. All calculations are executed on the main thread."),this.storedRowCount=t.rowCount,this.storedColumns={};for(let[e,n]of Object.entries(t.columnarData))n.type==="int32"&&(this.storedColumns[e]={type:"int32",array:new Int32Array(n.buffer)}),n.type==="float64"&&(this.storedColumns[e]={type:"float64",array:new Float64Array(n.buffer)});this.lastMask=null,this.activeFilters=this.activePrefilter=null,t.deferBuild?this.isBuilt=false:this.buildFromMask(null);}reconfigure(t){if(this.rowFields=t.rowFields,this.colFields=t.colFields,this.dataFields=t.dataFields,this.appendDictionary(t.dictionaryAppend),t.newColumns)for(let[e,n]of Object.entries(t.newColumns))n.type==="int32"&&(this.storedColumns[e]={type:"int32",array:new Int32Array(n.buffer)}),n.type==="float64"&&(this.storedColumns[e]={type:"float64",array:new Float64Array(n.buffer)});this.buildFromMask(this.lastMask);}initStart(t){this.dictionary=t.dictionary,this.rowFields=t.rowFields,this.colFields=t.colFields,this.dataFields=t.dataFields,t.workerBootstrap&&t.workerBootstrap.length>0&&console.warn("[PivotGrid Worker] workerBootstrap is deprecated for security reasons. All calculations are executed on the main thread."),this.storedRowCount=t.rowCountTotal,this.storedColumns={};for(let[e,n]of Object.entries(t.columnTypes))n==="int32"?this.storedColumns[e]={type:"int32",array:new Int32Array(t.rowCountTotal)}:this.storedColumns[e]={type:"float64",array:new Float64Array(t.rowCountTotal)};this.setFilters((t.filters||[]).map(e=>({fieldId:e.fieldId,filterType:e.filterType,ids:new Set,pending:new Set(e.valueStrings)})),t.prefilter),this.resolveIncrementalFilterStrings(0),this.isBuilt=false,this.beginBuild();}initChunk(t){this.appendDictionary(t.dictionaryAppend)&&this.ensureCardCapacity();for(let[e,n]of Object.entries(t.columns)){let r=this.storedColumns[e];r&&(r.type==="int32"?r.array.set(new Int32Array(n),t.start):r.array.set(new Float64Array(n),t.start));}this.lastMask&&this.computeMaskRange(t.start,t.end),this.processRange(t.start,t.end,this.lastMask);}initEnd(){this.finalizeBuild();}appendDictionary(t){if(!t||t.length===0)return false;let e=this.dictionary.length;for(let n of t)this.dictionary.push(n);return this.resolveIncrementalFilterStrings(e),true}setFilters(t,e){this.activeFilters=t.length>0?t:null,this.activePrefilter=e&&e.conditions.length>0?e:null,this.lastMask=this.activeFilters||this.activePrefilter?new Uint8Array(this.storedRowCount):null;}resolveIncrementalFilterStrings(t){let e=this.activeFilters;if(!e)return;let n=0;for(let r of e)n+=r.pending.size;if(n!==0)for(let r=t;r<this.dictionary.length;r++){let i=this.dictionary[r];for(let s of e)s.pending.delete(i)&&s.ids.add(r);}}computeMaskRange(t,e){let n=this.lastMask;if(n.fill(1,t,e),this.activeFilters)for(let r of this.activeFilters){let i=this.storedColumns[r.fieldId];if(!i||i.type!=="int32")continue;let s=i.array,c=r.ids;if(r.filterType==="exclude")for(let a=t;a<e;a++)n[a]&&c.has(s[a])&&(n[a]=0);else for(let a=t;a<e;a++)n[a]&&!c.has(s[a])&&(n[a]=0);}if(this.activePrefilter)for(let r=t;r<e;r++)n[r]&&!this.evaluatePrefilterGroup(this.activePrefilter,r)&&(n[r]=0);}applyFilter(t){this.setFilters(t.filters.map(e=>({fieldId:e.fieldId,filterType:e.filterType,ids:new Set(e.dictIds),pending:new Set(e.valueStrings)})),t.prefilter),this.lastMask&&this.computeMaskRange(0,this.storedRowCount),this.buildFromMask(this.lastMask);}evaluatePrefilterGroup(t,e){if(!t.conditions||t.conditions.length===0)return true;if(t.logicalOperator==="and"){for(let n of t.conditions)if("logicalOperator"in n){if(!this.evaluatePrefilterGroup(n,e))return false}else if(!this.evaluatePrefilterCondition(n,e))return false;return true}else {for(let n of t.conditions)if("logicalOperator"in n){if(this.evaluatePrefilterGroup(n,e))return true}else if(this.evaluatePrefilterCondition(n,e))return true;return false}}evaluatePrefilterCondition(t,e){let n=this.storedColumns[t.fieldId];if(!n)return true;if(n.type==="float64"){let f=n.array[e],y=Number(t.value);switch(t.operator){case "=":return f===y;case "<>":return f!==y;case ">":return f>y;case ">=":return f>=y;case "<":return f<y;case "<=":return f<=y;case "isnull":return isNaN(f)||f===0;case "isnotnull":return !isNaN(f)&&f!==0;default:return true}}let r=n.array[e],i=this.dictionary[r]||"",s=String(t.value??""),c=Number(i),a=Number(s),d=i!==""&&s!==""&&!isNaN(c)&&!isNaN(a);switch(t.operator){case "=":return i===s;case "<>":return i!==s;case ">":return d?c>a:i>s;case ">=":return d?c>=a:i>=s;case "<":return d?c<a:i<s;case "<=":return d?c<=a:i<=s;case "contains":return i.toLowerCase().includes(s.toLowerCase());case "notcontains":return !i.toLowerCase().includes(s.toLowerCase());case "startswith":return i.toLowerCase().startsWith(s.toLowerCase());case "endswith":return i.toLowerCase().endsWith(s.toLowerCase());case "isnull":return i===""||i==="(Blank)";case "isnotnull":return i!==""&&i!=="(Blank)";case "in":return Array.isArray(t.value)?t.value.map(String).includes(i):true;case "notin":return Array.isArray(t.value)?!t.value.map(String).includes(i):true;default:return true}}buildFromMask(t){this.beginBuild(),this.processRange(0,this.storedRowCount,t),this.finalizeBuild();}beginBuild(){let t=this.storedRowCount,e=this.storedColumns,n=this.rowFields.length,r=this.colFields.length,i=new Array(n);for(let u=0;u<n;u++)i[u]=e[this.rowFields[u].id].array;let s=new Array(r);for(let u=0;u<r;u++)s[u]=e[this.colFields[u].id].array;let c=this.dictionary.length,a=this.rowFields.map(u=>{let v=e[u.id];return v&&v.type==="int32"?new Uint8Array(c):null}),d=this.colFields.map(u=>{let v=e[u.id];return v&&v.type==="int32"?new Uint8Array(c):null});this.rowTrie=new nt(2e5),this.colTrie=new nt(2e5);let f=this.dataFields.length,y=this.dataFields.map(u=>u.summaryType||"sum"),p=y.some(u=>u==="count"||u==="avg"),G=y.some(u=>u==="min"),C=y.some(u=>u==="max"),M=y.some(u=>u==="distinct"),T=new Array(f);for(let u=0;u<f;u++)T[u]=e[this.dataFields[u].id].array;let F=Math.min(t,2e5),l=G?new Float64Array(F*f):new Float64Array(0),w=C?new Float64Array(F*f):new Float64Array(0);this.leafGroupDistinctSets=M?new Map:new Map,G&&l.fill(1/0),C&&w.fill(-1/0),this.buildState={rPath:new Int32Array(n),cPath:new Int32Array(r),rowColArrays:i,colColArrays:s,dataColArrays:T,rowCardSeen:a,colCardSeen:d,rowCardCounts:new Int32Array(n),colCardCounts:new Int32Array(r),summaryTypes:y,allSums:y.every(u=>u==="sum"),needsCounts:p,needsMins:G,needsMaxes:C,groupMap:new Map,leafRowIds:new Int32Array(F),leafColIds:new Int32Array(F),leafMeasures:new Float64Array(F*f),leafCounts:p?new Float64Array(F*f):new Float64Array(0),leafMins:l,leafMaxes:w,rowGroupOf:this.tracking||y.includes("custom")?new Int32Array(t).fill(-1):null,gCount:0};}ensureCardCapacity(){let t=this.buildState;if(!t)return;let e=this.dictionary.length,n=r=>{if(r===null||r.length>=e)return r;let i=new Uint8Array(Math.max(e,r.length*2));return i.set(r),i};for(let r=0;r<t.rowCardSeen.length;r++)t.rowCardSeen[r]=n(t.rowCardSeen[r]);for(let r=0;r<t.colCardSeen.length;r++)t.colCardSeen[r]=n(t.colCardSeen[r]);}processRange(t,e,n){let r=this.buildState,{rPath:i,cPath:s,rowColArrays:c,colColArrays:a,dataColArrays:d,rowCardSeen:f,colCardSeen:y,rowCardCounts:p,colCardCounts:G,summaryTypes:C,allSums:M,needsCounts:T,needsMins:F,needsMaxes:l,groupMap:w,rowGroupOf:u}=r,v=c.length,m=a.length,b=d.length,D=this.rowTrie,E=this.colTrie,W=r.leafRowIds,J=r.leafColIds,_=r.leafMeasures,Q=r.leafCounts,Y=r.leafMins,Z=r.leafMaxes,K=r.gCount;for(let R=t;R<e;R++){if(n&&!n[R])continue;for(let h=0;h<v;h++){let A=c[h][R];i[h]=A;let g=f[h];g!==null&&g[A]===0&&(g[A]=1,p[h]++);}let $=D.insert(i,v);for(let h=0;h<m;h++){let A=a[h][R];s[h]=A;let g=y[h];g!==null&&g[A]===0&&(g[A]=1,G[h]++);}let rt=E.insert(s,m),it=$*67108864+rt,L=w.get(it);if(L===void 0){if(L=K++,w.set(it,L),L>=W.length){let h=L*2,A=new Int32Array(h);A.set(W),W=A;let g=new Int32Array(h);g.set(J),J=g;let H=new Float64Array(h*b);if(H.set(_),_=H,T){let o=new Float64Array(h*b);o.set(Q),Q=o;}if(F){let o=new Float64Array(h*b);o.fill(1/0),o.set(Y),Y=o;}if(l){let o=new Float64Array(h*b);o.fill(-1/0),o.set(Z),Z=o;}}W[L]=$,J[L]=rt;}u!==null&&(u[R]=L);let st=L*b;if(M)for(let h=0;h<b;h++)_[st+h]+=d[h][R];else for(let h=0;h<b;h++){let A=d[h][R],g=st+h;switch(C[h]){case "sum":_[g]+=A;break;case "count":Q[g]+=1;break;case "avg":_[g]+=A,Q[g]+=1;break;case "min":A<Y[g]&&(Y[g]=A);break;case "max":A>Z[g]&&(Z[g]=A);break;case "distinct":{if(A===0&&d[h]instanceof Int32Array)break;let H=this.leafGroupDistinctSets.get(g);H||(H=new Set,this.leafGroupDistinctSets.set(g,H)),H.add(A);break}default:_[g]+=A;break}}}r.leafRowIds=W,r.leafColIds=J,r.leafMeasures=_,r.leafCounts=Q,r.leafMins=Y,r.leafMaxes=Z,r.gCount=K;}finalizeBuild(){let t=this.buildState,{needsCounts:e,needsMins:n,needsMaxes:r,gCount:i}=t,s=t.dataColArrays.length,c=t.rowColArrays.length,a=t.colColArrays.length;this.groupCount=i,this.leafGroupRowIds=t.leafRowIds.slice(0,i),this.leafGroupColIds=t.leafColIds.slice(0,i),this.leafGroupMeasures=t.leafMeasures.slice(0,i*s),this.leafGroupCounts=e?t.leafCounts.slice(0,i*s):t.leafCounts,this.leafGroupMins=n?t.leafMins.slice(0,i*s):t.leafMins,this.leafGroupMaxes=r?t.leafMaxes.slice(0,i*s):t.leafMaxes,this.rowGroupOf=t.rowGroupOf,this.cardinalityMap={};for(let d=0;d<c;d++)t.rowCardSeen[d]!==null&&(this.cardinalityMap[this.rowFields[d].id]=t.rowCardCounts[d]);for(let d=0;d<a;d++)t.colCardSeen[d]!==null&&(this.cardinalityMap[this.colFields[d].id]=t.colCardCounts[d]);if(this.buildState=null,this.rowLive=this.colLive=null,this.tracking){this.groupMap=t.groupMap;let d=this.groupRows=new Int32Array(i),f=t.rowGroupOf;for(let y=0;y<this.storedRowCount;y++)f[y]>=0&&d[f[y]]++;}this.buildVersion++,this.isBuilt=true,this.rowPathStrs=this.buildPathStrs(this.rowTrie),this.colPathStrs=this.buildPathStrs(this.colTrie),this.rowIndexMapCache=this.buildIndexMap(this.rowPathStrs,null),this.columnIndexMapCache=this.buildIndexMap(this.colPathStrs,null);}buildPathStrs(t,e=[""]){let n=e;for(let r=e.length;r<t.size;r++){let i=t.nodeToParent[r],s=this.dictionary[t.nodeToVal[r]],c=n[i];n[r]=i===0?s===""?"|":s:c+"|"+s;}return n}buildIndexMap(t,e){let n={};for(let r=0;r<t.length;r++)(!e||e[r])&&(n[t[r]]=r);return n}applyTransaction(t){this.tracking||(this.tracking=true,this.buildFromMask(this.lastMask)),this.appendDictionary(t.dictionaryAppend);let{update:e,remove:n}=t,r=e.length,i=this.storedRowCount,s=i+t.addCount,c=this.storedColumns,a=new Set,d=false,f=this.rowGroupOf,y=l=>{let w=f[l];w<0||(f[l]=-1,--this.groupRows[w]===0&&(d=true),a.add(w));};e.forEach(y),n.forEach(y);for(let l in c){let w=c[l],u=t.columns[l];if(!u)throw new Error("transaction: no values for column "+l);let v=w.type==="int32"?new Int32Array(u):new Float64Array(u),m=w.array=X(w.array,s);for(let b=0;b<r;b++)m[e[b]]=v[b];m.set(v.subarray(r),i);}f=this.rowGroupOf=X(f,s),f.fill(-1,i,s);let p=this.lastMask&&(this.lastMask=X(this.lastMask,s));p&&(e.forEach(l=>this.computeMaskRange(l,l+1)),this.computeMaskRange(i,s));let G=this.rowFields.map(l=>c[l.id].array),C=this.colFields.map(l=>c[l.id].array),M=new Int32Array(G.length),T=new Int32Array(C.length),F=l=>{if(p&&!p[l])return;G.forEach((b,D)=>{M[D]=b[l];}),C.forEach((b,D)=>{T[D]=b[l];});let w=this.rowTrie.insert(M,M.length),u=this.colTrie.insert(T,T.length),v=w*67108864+u,m=this.groupMap.get(v);m===void 0&&(this.groupMap.set(v,m=this.groupCount++),(this.leafGroupRowIds=X(this.leafGroupRowIds,m+1))[m]=w,(this.leafGroupColIds=X(this.leafGroupColIds,m+1))[m]=u,this.groupRows=X(this.groupRows,m+1)),this.groupRows[m]++===0&&(d=true),f[l]=m,a.add(m);};e.forEach(F);for(let l=i;l<s;l++)F(l);if(this.storedRowCount=s-n.length,n.length>0){for(let l in c)ct(c[l].array,n,s);ct(f,n,s),p&&ct(p,n,s);}if(this.resumGroups(a),d){let l=0;for(let w=0;w<this.groupCount;w++)this.groupRows[w]===0&&l++;l>4096&&l>this.groupCount-l?this.buildFromMask(this.lastMask):(this.cardinalityMap={},[this.rowLive,this.rowPathStrs,this.rowIndexMapCache]=this.relive(this.rowTrie,this.leafGroupRowIds,this.rowFields,this.rowPathStrs),[this.colLive,this.colPathStrs,this.columnIndexMapCache]=this.relive(this.colTrie,this.leafGroupColIds,this.colFields,this.colPathStrs),this.buildVersion++);}return this.storedRowCount}resumGroups(t){if(t.size===0)return;let e=this.dataFields.length,n=this.dataFields.map(C=>C.summaryType||"sum"),r=this.dataFields.map(C=>this.storedColumns[C.id].array),i=this.groupCount*e,s=this.leafGroupMeasures=X(this.leafGroupMeasures,i),c=n.some(C=>C==="count"||C==="avg")?this.leafGroupCounts=X(this.leafGroupCounts,i):null,a=n.includes("min")?this.leafGroupMins=X(this.leafGroupMins,i):null,d=n.includes("max")?this.leafGroupMaxes=X(this.leafGroupMaxes,i):null,f=this.leafGroupDistinctSets,y=new Uint8Array(this.groupCount),p=0;for(let C of t){y[C]=1,p+=this.groupRows[C];for(let M=C*e;M<(C+1)*e;M++)s[M]=0,c&&(c[M]=0),a&&(a[M]=1/0),d&&(d[M]=-1/0),f.delete(M);}let G=this.rowGroupOf;for(let C=0;p>0&&C<this.storedRowCount;C++){let M=G[C];if(!(M<0||!y[M])){p--;for(let T=0;T<e;T++){let F=r[T][C],l=M*e+T;switch(n[T]){case "count":c[l]++;break;case "avg":s[l]+=F,c[l]++;break;case "min":F<a[l]&&(a[l]=F);break;case "max":F>d[l]&&(d[l]=F);break;case "distinct":{if(F===0&&r[T]instanceof Int32Array)break;let w=f.get(l);w||f.set(l,w=new Set),w.add(F);break}default:s[l]+=F;}}}}}relive(t,e,n,r){let i=new Uint8Array(t.size);i[0]=1;for(let a=0;a<this.groupCount;a++)if(this.groupRows[a]!==0)for(let d=e[a];!i[d];d=t.nodeToParent[d])i[d]=1;let s=n.map(()=>new Set);t.nodeChildCount.fill(0,0,t.size);for(let a=1;a<t.size;a++)i[a]&&(t.nodeChildCount[t.nodeToParent[a]]++,s[t.nodeToDepth[a]-1]?.add(t.nodeToVal[a]));n.forEach((a,d)=>{this.cardinalityMap[a.id]=s[d].size;});let c=this.buildPathStrs(t,r);return [i,c,this.buildIndexMap(c,i)]}compute(t){this.isBuilt||this.buildFromMask(this.lastMask);let e=this.rowPathStrs,n=this.colPathStrs,r=new Uint8Array(this.rowTrie.size),i=new Set(t.expandedPaths),s=i.has(".*")||i.has("*");for(let o=0;o<this.rowTrie.size;o++)r[o]=s||i.has(e[o])?1:0;let c=new Uint8Array(this.colTrie.size),a=new Set(t.expandedColPaths),d=a.has(".*")||a.has("*");for(let o=0;o<this.colTrie.size;o++)c[o]=d||a.has(n[o])?1:0;let f=new Uint8Array(this.rowTrie.size);f[0]=1;for(let o=1;o<this.rowTrie.size;o++){let S=this.rowTrie.nodeToParent[o];(S===0||r[S])&&(!this.rowLive||this.rowLive[o])&&(f[o]=1);}let y=new Uint8Array(this.colTrie.size);y[0]=1;for(let o=1;o<this.colTrie.size;o++){let S=this.colTrie.nodeToParent[o];(S===0||c[S])&&(!this.colLive||this.colLive[o])&&(y[o]=1);}let p=this.dataFields.length,G=this.dataFields.map(o=>o.summaryType||"sum"),C=this.leafGroupMins.length>0,M=this.leafGroupMaxes.length>0,T=this.leafGroupCounts.length>0,F=this.leafGroupDistinctSets.size>0,l=new Map,w=0,u=1e4,v=new Float64Array(u),m=new Float64Array(u*p),b=new Int32Array(u*p),D=T?new Float64Array(u*p):null,E=C?new Float64Array(u*p):null,W=M?new Float64Array(u*p):null,J=F?new Map:new Map;E&&E.fill(1/0),W&&W.fill(-1/0);let _=new Int32Array(this.rowFields.length+1),Q=new Int32Array(this.colFields.length+1),Y=(o,S,I,O)=>{let tt=0,U=o;for(;U!==-1;)I[U]&&(O[tt++]=U),U=S.nodeToParent[U];return tt},Z=this.rowGroupOf!==null&&G.includes("custom"),K=Z?new Int32Array(this.groupCount+1):null,R=Z?new Int32Array(Math.max(16,this.groupCount*4)):null,$=0,rt=this.tracking?this.groupRows:null;for(let o=0;o<this.groupCount;o++){if(rt!==null&&rt[o]===0){K!==null&&(K[o+1]=$);continue}let S=this.leafGroupRowIds[o],I=this.leafGroupColIds[o],O=Y(S,this.rowTrie,f,_),tt=Y(I,this.colTrie,y,Q);for(let U=0;U<O;U++){let ot=_[U];for(let j=0;j<tt;j++){let at=Q[j],et=ot*67108864+at,P=l.get(et);if(P===void 0){if(P=w++,l.set(et,P),P>=v.length){let k=P*2,x=new Float64Array(k);x.set(v),v=x;let V=new Float64Array(k*p);V.set(m),m=V;let N=new Int32Array(k*p);if(N.set(b),b=N,D){let B=new Float64Array(k*p);B.set(D),D=B;}if(E){let B=new Float64Array(k*p);B.fill(1/0),B.set(E),E=B;}if(W){let B=new Float64Array(k*p);B.fill(-1/0),B.set(W),W=B;}}v[P]=et;}if(R!==null){if($>=R.length){let k=new Int32Array(R.length*2);k.set(R),R=k;}R[$++]=P;}for(let k=0;k<p;k++){let x=P*p+k,V=o*p+k;switch(G[k]){case "sum":m[x]+=this.leafGroupMeasures[V];break;case "count":m[x]+=this.leafGroupCounts[V];break;case "avg":m[x]+=this.leafGroupMeasures[V],D[x]+=this.leafGroupCounts[V];break;case "min":{let N=this.leafGroupMins[V];N<E[x]&&(E[x]=N);break}case "max":{let N=this.leafGroupMaxes[V];N>W[x]&&(W[x]=N);break}case "distinct":{let N=this.leafGroupDistinctSets.get(V);if(N){let B=J.get(x);B||(B=new Set,J.set(x,B));for(let ft of N)B.add(ft);}break}default:m[x]+=this.leafGroupMeasures[V];break}b[x]+=1;}}}K!==null&&(K[o+1]=$);}for(let o=0;o<w;o++)for(let S=0;S<p;S++){let I=o*p+S;switch(G[S]){case "avg":m[I]=D[I]>0?m[I]/D[I]:0;break;case "min":m[I]=E[I]!==1/0?E[I]:0;break;case "max":m[I]=W[I]!==-1/0?W[I]:0;break;case "distinct":{let O=J.get(I);m[I]=O?O.size:0;break}}}let it=v.slice(0,w),L=m.slice(0,w*p),st=b.slice(0,w*p),h=(o,S,I,O,tt)=>{let U=[];for(let j=0;j<O.length;j++)U[j]=O[j]?.id||"";let ot=j=>{let at=o.childrenMap.get(j);if(!at)return [];let et=[];for(let P of at.values())if(S[P]){let k=o.nodeToDepth[P]-1,x=I[P]===1;et.push({key:tt[P],value:this.dictionary[o.nodeToVal[P]],fieldId:U[k]||"",children:x?ot(P):[],isExpanded:x,isTotal:false,depth:k,hasChildren:o.nodeChildCount[P]>0});}return et};return ot(0)},A;if(this.rowGroupOf!==null&&K!==null&&R!==null){let o=this.storedRowCount,S={};for(let I=0;I<p;I++){if(G[I]!=="custom")continue;let O=this.dataFields[I].id;S[O]=this.storedColumns[O].array.slice(0,o);}A={rowGroupOf:this.rowGroupOf.slice(0,o),groupCellOffsets:K,groupCells:R.slice(0,$),values:S};}let g=h(this.rowTrie,f,r,this.rowFields,e),H=h(this.colTrie,y,c,this.colFields,n);return {id:t.id,rowTree:g,colTree:H,cellMatrix:{keys:it,sums:L,counts:st},customSummary:A,rowIndexMap:this.rowIndexMapCache,columnIndexMap:this.columnIndexMapCache,cardinalityMap:this.cardinalityMap,indexMapsVersion:this.buildVersion}}};var q=new lt,dt=-1;self.onmessage=z=>{let t=z.data;try{if(t.action==="init")q.init(t),self.postMessage({id:t.id,isInitComplete:!0});else if(t.action==="initStart")q.initStart(t);else if(t.action==="initChunk")q.initChunk(t);else if(t.action==="initEnd")q.initEnd(),self.postMessage({id:t.id,isInitComplete:!0});else if(t.action==="filter")q.applyFilter(t),self.postMessage({id:t.id,isFilterComplete:!0});else if(t.action==="reconfigure")q.reconfigure(t),self.postMessage({id:t.id,isReconfigureComplete:!0});else if(t.action==="transaction")self.postMessage({id:t.id,isTransactionComplete:!0,rowCount:q.applyTransaction(t)});else if(t.action==="compute"){let e=q.compute(t),n=[e.cellMatrix.keys.buffer,e.cellMatrix.sums.buffer,e.cellMatrix.counts.buffer];if(e.indexMapsVersion!==void 0&&e.indexMapsVersion===dt){let r={...e,rowIndexMap:void 0,columnIndexMap:void 0,cardinalityMap:void 0,indexMapsOmitted:!0};postMessage(r,n);}else e.indexMapsVersion!==void 0&&(dt=e.indexMapsVersion),postMessage(e,n);}}catch(e){self.postMessage({id:t.id,error:e instanceof Error?e.message:String(e)});}};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanunilabs/pivotgrid-core",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.3",
|
|
4
4
|
"description": "Framework-agnostic PivotGrid engine with Web Worker, columnar storage, trie-based grouping, and headless controller",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "KanuniLabs <hello@kanunilabs.com> (https://www.kanunilabs.com)",
|
|
@@ -32,10 +32,6 @@
|
|
|
32
32
|
"./dist/export.worker.js": {
|
|
33
33
|
"import": "./dist/export.worker.js",
|
|
34
34
|
"require": "./dist/export.worker.cjs"
|
|
35
|
-
},
|
|
36
|
-
"./dist/import.worker.js": {
|
|
37
|
-
"import": "./dist/import.worker.js",
|
|
38
|
-
"require": "./dist/import.worker.cjs"
|
|
39
35
|
}
|
|
40
36
|
},
|
|
41
37
|
"main": "./dist/index.cjs",
|
|
@@ -49,8 +45,7 @@
|
|
|
49
45
|
"access": "public"
|
|
50
46
|
},
|
|
51
47
|
"peerDependencies": {
|
|
52
|
-
"file-saver": ">=2.0.0"
|
|
53
|
-
"xlsx": ">=0.18.0"
|
|
48
|
+
"file-saver": ">=2.0.0"
|
|
54
49
|
},
|
|
55
50
|
"devDependencies": {
|
|
56
51
|
"@types/file-saver": "^2.0.7",
|
package/dist/import.worker.cjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
'use strict';function T(e){return e.charCodeAt(0)===65279?e.slice(1):e}function S(e){return typeof e.text=="function"?e.text():new Promise((t,n)=>{let r=new FileReader;r.onload=i=>t(i.target?.result??""),r.onerror=()=>n(new Error("Dosya okuma hatas\u0131.")),r.readAsText(e,"utf-8");})}function N(e){let t=[",",";"," ","|"],n=T(e).split(/\r\n|\r|\n/).filter(s=>s.length>0).slice(0,5);if(n.length===0)return ",";let r=",",i=-1;for(let s of t){let a=n.map(d=>B(d,s)),o=a.reduce((d,f)=>d+f,0);if(o===0)continue;let l=a[0],u=a.every(d=>d===l),c=o+(u?100:0)+l*10;c>i&&(i=c,r=s);}return r}function B(e,t){let n=0,r=false;for(let i=0;i<e.length;i++){let s=e[i];if(s==='"'){if(r&&e[i+1]==='"'){i++;continue}r=!r;}else !r&&s===t&&n++;}return n}function X(e,t,n){let r=T(e),i=t||N(r),s=[],a="",o=[],l=false,u=false,c=r.length,d=n?Math.max(1<<18,Math.ceil(c/100)):0,f=d;for(let g=0;g<r.length;g++){d&&g>=f&&(n(g/c),f+=d);let p=r[g];if(l){p==='"'?r[g+1]==='"'?(a+='"',g++):l=false:a+=p;continue}p==='"'?(l=true,u=true):p===i?(o.push(a),a="",u=true):p===`
|
|
2
|
-
`||p==="\r"?(p==="\r"&&r[g+1]===`
|
|
3
|
-
`&&g++,o.push(a),s.push(o),o=[],a="",u=false):(a+=p,u=true);}return (u||a.length>0||o.length>0)&&(o.push(a),s.push(o)),n&&n(1),s}var A=new Set(["true","yes","evet","do\u011Fru","dogru"]),F=new Set(["false","no","hay\u0131r","hayir","yanl\u0131\u015F","yanlis"]);function z(e){let t=e.trim().toLowerCase();return A.has(t)||F.has(t)}function Y(e){if(typeof e=="boolean")return e;let t=String(e).trim().toLowerCase();return A.has(t)||t==="1"||t==="y"||t==="on"?true:F.has(t)||t==="0"||t==="n"||t==="off"?false:null}function K(e){return /^0\d+$/.test(e)}var H=/[₺$€£¥]/g,Z=/[\s ]/g;function _(e){if(typeof e=="number")return isNaN(e)?null:e;let t=String(e).trim();if(!t)return null;t=t.replace(Z,"").replace(H,"");let n=false;t.endsWith("%")&&(n=true,t=t.slice(0,-1));let r=false;if(/^\(.*\)$/.test(t)&&(r=true,t=t.slice(1,-1)),!/^[+-]?[0-9.,]*[0-9][0-9.,]*$/.test(t))return null;let i=t.includes("."),s=t.includes(",");if(i&&s)t.lastIndexOf(",")>t.lastIndexOf(".")?t=t.replace(/\./g,"").replace(",","."):t=t.replace(/,/g,"");else if(s){let o=t.split(",");o.length===2&&o[1].length!==3?t=t.replace(",","."):t=t.replace(/,/g,"");}else i&&t.split(".").length>2&&(t=t.replace(/\./g,""));let a=Number(t);return isNaN(a)?null:(r&&(a=-a),n&&(a=a/100),a)}var U=/^\d{4}-\d{2}-\d{2}([ T]\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:?\d{2})?)?$/,V=/^(\d{4})[/.](\d{1,2})[/.](\d{1,2})$/,Q=/^(\d{1,2})[/.\-](\d{1,2})[/.\-](\d{4})$/;function D(e){if(e instanceof Date)return isNaN(e.getTime())?null:e;let t=String(e).trim();if(!t)return null;if(U.test(t)){let i=new Date(t.replace(" ","T"));return isNaN(i.getTime())?null:i}let n=V.exec(t);if(n){let i=new Date(+n[1],+n[2]-1,+n[3]);return C(i,+n[1],+n[2],+n[3])?i:null}let r=Q.exec(t);if(r){let i=+r[1],s=+r[2],a=+r[3],o,l;i>12&&s<=12?(o=i,l=s):s>12&&i<=12?(o=s,l=i):(o=i,l=s);let u=new Date(a,l-1,o);return C(u,a,l,o)?u:null}return null}function C(e,t,n,r){return !isNaN(e.getTime())&&e.getFullYear()===t&&e.getMonth()===n-1&&e.getDate()===r}function G(e){if(e==null||e==="")return "blank";if(typeof e=="boolean")return "boolean";if(typeof e=="number")return isNaN(e)?"blank":"number";if(e instanceof Date)return isNaN(e.getTime())?"blank":"date";let t=String(e).trim();return t===""?"blank":z(t)?"boolean":K(t)?"string":D(t)?"date":_(t)!==null?"number":"string"}function x(e){let t={string:0,number:0,date:0,boolean:0};for(let i of e){let s=G(i);s!=="blank"&&t[s]++;}let n="string",r=0;return Object.keys(t).forEach(i=>{t[i]>r&&(r=t[i],n=i);}),n}function v(e,t){if(e==null||e==="")return null;switch(t){case "number":return _(e);case "date":return D(e)??(e instanceof Date?e:null);case "boolean":return Y(e);default:return e}}var E=new Set(["__proto__","constructor","prototype"]);function y(e){return E.has(e)?`${e}_`:e}function M(e){let t=false;for(let n of e)if(!(!n||typeof n!="object")){for(let r of Object.keys(n))if(E.has(r)){t=true;break}if(t)break}return t?e.map(n=>{if(!n||typeof n!="object")return n;let r={};for(let i of Object.keys(n))r[y(i)]=n[i];return r}):e}var O=200,I=2e4;function q(e){let t=new Map;return e.map(n=>{let r=t.get(n)??0;return t.set(n,r+1),y(r===0?n:`${n}_${r+1}`)})}function P(e,t){if(e.length===0)return [];let n=[],r=new Set,i=Math.min(e.length,500);for(let o=0;o<i;o++){let l=e[o];if(!(!l||typeof l!="object"))for(let u of Object.keys(l))r.has(u)||(r.add(u),n.push(u));}let s=new Map;for(let o of n){let l=[];for(let u=0;u<e.length&&l.length<O;u++){let c=e[u]?.[o];c!=null&&String(c).trim()!==""&&l.push(c);}s.set(o,x(l));}let a=new Array(e.length);for(let o=0;o<e.length;o++){let l=e[o]||{},u={};for(let c of n){let d=l[c];u[y(c)]=d==null||d===""?null:v(d,s.get(c));}a[o]=u;}return a}function $(e,t){let n=T(e);if(!n.trim())return [];let r=N(n),i=X(n,r,t?c=>t({phase:"parsing",percent:Math.round(c*60)}):void 0);if(i.length===0)return [];let s=0;for(;s<i.length&&i[s].every(c=>c.trim()==="");)s++;if(s>=i.length)return [];let a=q(i[s].map((c,d)=>c.trim()||`Column${d+1}`)),o=i.slice(s+1).filter(c=>!(c.length===1&&c[0].trim()==="")),l=a.map((c,d)=>{let f=[];for(let g=0;g<o.length&&f.length<O;g++){let p=o[g][d];p!==void 0&&p.trim()!==""&&f.push(p);}return x(f)}),u=new Array(o.length);for(let c=0;c<o.length;c++){let d=o[c],f={};for(let g=0;g<a.length;g++){let p=d[g];f[a[g]]=p===void 0||p===""?null:v(p,l[g]);}u[c]=f,t&&c>0&&c%I===0&&t({phase:"typing",percent:60+Math.round(c/o.length*40)});}return t&&t({phase:"typing",percent:100}),u}var b=class e{supports(t){return t.name.split(".").pop()?.toLowerCase()==="xml"||t.type==="application/xml"||t.type==="text/xml"}async read(t){let n=await S(t);return e.parse(n)}static parse(t){if(!t||!t.trim())return [];let n=J(t),i=et(n).map(nt).filter(s=>Object.keys(s).length>0);return P(i)}};function J(e){let t={tag:"#root",attrs:{},children:[],text:"",parent:null},n=t,r=0,i=e.length;for(;r<i;){let s=e.indexOf("<",r);if(s===-1){n.text+=e.slice(r);break}if(s>r&&(n.text+=e.slice(r,s)),e.startsWith("<!--",s)){let f=e.indexOf("-->",s+4);r=f===-1?i:f+3;continue}if(e.startsWith("<![CDATA[",s)){let f=e.indexOf("]]>",s+9);n.text+=e.slice(s+9,f===-1?i:f),r=f===-1?i:f+3;continue}if(e.startsWith("<?",s)){let f=e.indexOf("?>",s+2);r=f===-1?i:f+2;continue}if(e.startsWith("<!",s)){let f=e.indexOf(">",s+2);r=f===-1?i:f+1;continue}let a=e.indexOf(">",s+1);if(a===-1)break;let o=e.slice(s+1,a).trim();if(o.startsWith("/")){let f=o.slice(1).trim(),g=n;for(;g&&g.tag!==f;)g=g.parent;g&&g.parent&&(n=g.parent),r=a+1;continue}let l=o.endsWith("/");l&&(o=o.slice(0,-1).trim());let{name:u,attrs:c}=tt(o),d={tag:u,attrs:c,children:[],text:"",parent:n};n.children.push(d),l||(n=d),r=a+1;}return t}var j=/([^\s=/]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;function tt(e){let t=e.search(/\s/),n=(t===-1?e:e.slice(0,t)).trim(),r={};if(t!==-1){let i=e.slice(t+1),s;for(j.lastIndex=0;(s=j.exec(i))!==null;)r[s[1]]=R(s[2]??s[3]??"");}return {name:n,attrs:r}}function et(e){let t=e.children[0];if(!t)return [];let n=t.children;return n.length===0?[]:n.some(i=>i.children.length>0||Object.keys(i.attrs).length>0)?n:[t]}function nt(e){let t={},n=new Map,r=(i,s)=>{let a=i||"value",o=n.get(a)??0;n.set(a,o+1),t[y(o===0?a:`${a}_${o+1}`)]=s;};for(let[i,s]of Object.entries(e.attrs))r(i,s);if(e.children.length===0){let i=e.text.trim();i&&r(e.tag,R(i));}else for(let i of e.children)r(i.tag,R(W(i).trim()));return t}function W(e){if(e.children.length===0)return e.text;let t=e.text;for(let n of e.children)t+=W(n);return t}var rt=/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g,it={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:"\xA0"};function R(e){return e.indexOf("&")===-1?e:e.replace(rt,(t,n)=>{if(n[0]==="#"){let r=n[1]==="x"||n[1]==="X"?parseInt(n.slice(2),16):parseInt(n.slice(1),10);return Number.isFinite(r)?String.fromCodePoint(r):t}return it[n]??t})}var h=class{static extractFieldsFromData(t,n=50){if(!t||t.length===0)return [];let r=[],i=Math.max(n,50),s=this.collectKeys(t,i),a=false,o=false;return s.forEach(l=>{let u=this.inferType(t,l,n),c="chooser";!a&&this.isAutoRowCandidate(t,l,u,i)?(c="row",a=true):!o&&this.isAutoDataCandidate(l,u)&&(c="data",o=true);let d={id:`f_${l}`,dataField:l,caption:this.formatCaption(l),dataType:u,area:c,areaIndex:0};u==="number"?d.summaryType="sum":u==="date"&&(d.groupInterval="month"),r.push(d);}),r}static buildFieldsFromPlan(t,n,r=50){let i=[],s=false,a=false,o=Math.max(r,50);for(let l of t){let u="chooser";!s&&this.isAutoRowCandidate(n,l.dataField,l.dataType,o)?(u="row",s=true):!a&&this.isAutoDataCandidate(l.dataField,l.dataType)&&(u="data",a=true);let c={id:`f_${l.dataField}`,dataField:l.dataField,caption:l.caption,dataType:l.dataType,area:u,areaIndex:0};l.dataType==="number"?c.summaryType="sum":l.dataType==="date"&&(c.groupInterval="month"),i.push(c);}return i}static isAutoRowCandidate(t,n,r,i){return !(n.startsWith("__EMPTY")||r!=="string"&&r!=="date"||this.isIdentifierLikeKey(n)||r==="string"&&t&&this.isHighCardinalityStringColumn(t,n,i))}static isAutoDataCandidate(t,n){return n==="number"&&!t.startsWith("__EMPTY")&&!this.isIdentifierLikeKey(t)}static isHighCardinalityStringColumn(t,n,r){let i=Math.min(t.length,r),s=new Set,a=0;for(let o=0;o<i;o++){let l=t[o]?.[n];l==null||l===""||(a++,s.add(String(l)));}return a<20?false:s.size/a>=.9}static isIdentifierLikeKey(t){let n=t.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase(),r=n.replace(/[^a-z0-9]/g,"");return r==="id"||r==="uuid"||r==="guid"||r==="key"?true:/(^|[\s_.-])(id|uuid|guid|key)($|[\s_.-])/.test(n)}static collectKeys(t,n){let r=[],i=new Set,s=Math.min(t.length,n);for(let a=0;a<s;a++){let o=t[a];if(!(!o||typeof o!="object"))for(let l of Object.keys(o))i.has(l)||(i.add(l),r.push(l));}return r}static inferType(t,n,r){let i=Math.min(t.length,r),s=new Array(i);for(let a=0;a<i;a++)s[a]=t[a]?.[n];return x(s)}static formatCaption(t){return t.replace(/([A-Z])/g," $1").replace(/_/g," ").replace(/^./,n=>n.toUpperCase()).trim()}};var k=self;k.onmessage=async e=>{let t=e.data;if(!t||t.type!=="parse")return;let{jobId:n,kind:r,file:i}=t;try{if(r==="csv"){m(n,"reading",3);let s=await i.text(),a=$(s,l=>{m(n,l.phase,5+Math.round(l.percent*.92));});m(n,"finalizing",98);let o=h.extractFieldsFromData(a);w(n,{mode:"data",data:a,fields:o});return}if(r==="xml"){m(n,"reading",10);let s=await i.text();m(n,"parsing",50);let a=b.parse(s);m(n,"finalizing",90);let o=h.extractFieldsFromData(a);w(n,{mode:"data",data:a,fields:o});return}if(r==="json"){m(n,"reading",10);let s=await i.text();m(n,"parsing",45);let a=JSON.parse(s);if(Array.isArray(a)){m(n,"finalizing",90);let o=M(a),l=h.extractFieldsFromData(o);w(n,{mode:"data",data:o,fields:l});}else w(n,{mode:"raw",value:a});return}L(n,`Desteklenmeyen i\xE7e aktarma t\xFCr\xFC: ${String(r)}`);}catch(s){L(n,s instanceof Error?s.message:String(s));}};function m(e,t,n){k.postMessage({type:"progress",jobId:e,phase:t,percent:n});}function w(e,t){k.postMessage({type:"done",jobId:e,payload:t});}function L(e,t){k.postMessage({type:"error",jobId:e,message:t});}
|
package/dist/import.worker.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
function T(e){return e.charCodeAt(0)===65279?e.slice(1):e}function S(e){return typeof e.text=="function"?e.text():new Promise((t,n)=>{let r=new FileReader;r.onload=i=>t(i.target?.result??""),r.onerror=()=>n(new Error("Dosya okuma hatas\u0131.")),r.readAsText(e,"utf-8");})}function N(e){let t=[",",";"," ","|"],n=T(e).split(/\r\n|\r|\n/).filter(s=>s.length>0).slice(0,5);if(n.length===0)return ",";let r=",",i=-1;for(let s of t){let a=n.map(d=>B(d,s)),o=a.reduce((d,f)=>d+f,0);if(o===0)continue;let l=a[0],u=a.every(d=>d===l),c=o+(u?100:0)+l*10;c>i&&(i=c,r=s);}return r}function B(e,t){let n=0,r=false;for(let i=0;i<e.length;i++){let s=e[i];if(s==='"'){if(r&&e[i+1]==='"'){i++;continue}r=!r;}else !r&&s===t&&n++;}return n}function X(e,t,n){let r=T(e),i=t||N(r),s=[],a="",o=[],l=false,u=false,c=r.length,d=n?Math.max(1<<18,Math.ceil(c/100)):0,f=d;for(let g=0;g<r.length;g++){d&&g>=f&&(n(g/c),f+=d);let p=r[g];if(l){p==='"'?r[g+1]==='"'?(a+='"',g++):l=false:a+=p;continue}p==='"'?(l=true,u=true):p===i?(o.push(a),a="",u=true):p===`
|
|
2
|
-
`||p==="\r"?(p==="\r"&&r[g+1]===`
|
|
3
|
-
`&&g++,o.push(a),s.push(o),o=[],a="",u=false):(a+=p,u=true);}return (u||a.length>0||o.length>0)&&(o.push(a),s.push(o)),n&&n(1),s}var A=new Set(["true","yes","evet","do\u011Fru","dogru"]),F=new Set(["false","no","hay\u0131r","hayir","yanl\u0131\u015F","yanlis"]);function z(e){let t=e.trim().toLowerCase();return A.has(t)||F.has(t)}function Y(e){if(typeof e=="boolean")return e;let t=String(e).trim().toLowerCase();return A.has(t)||t==="1"||t==="y"||t==="on"?true:F.has(t)||t==="0"||t==="n"||t==="off"?false:null}function K(e){return /^0\d+$/.test(e)}var H=/[₺$€£¥]/g,Z=/[\s ]/g;function _(e){if(typeof e=="number")return isNaN(e)?null:e;let t=String(e).trim();if(!t)return null;t=t.replace(Z,"").replace(H,"");let n=false;t.endsWith("%")&&(n=true,t=t.slice(0,-1));let r=false;if(/^\(.*\)$/.test(t)&&(r=true,t=t.slice(1,-1)),!/^[+-]?[0-9.,]*[0-9][0-9.,]*$/.test(t))return null;let i=t.includes("."),s=t.includes(",");if(i&&s)t.lastIndexOf(",")>t.lastIndexOf(".")?t=t.replace(/\./g,"").replace(",","."):t=t.replace(/,/g,"");else if(s){let o=t.split(",");o.length===2&&o[1].length!==3?t=t.replace(",","."):t=t.replace(/,/g,"");}else i&&t.split(".").length>2&&(t=t.replace(/\./g,""));let a=Number(t);return isNaN(a)?null:(r&&(a=-a),n&&(a=a/100),a)}var U=/^\d{4}-\d{2}-\d{2}([ T]\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:?\d{2})?)?$/,V=/^(\d{4})[/.](\d{1,2})[/.](\d{1,2})$/,Q=/^(\d{1,2})[/.\-](\d{1,2})[/.\-](\d{4})$/;function D(e){if(e instanceof Date)return isNaN(e.getTime())?null:e;let t=String(e).trim();if(!t)return null;if(U.test(t)){let i=new Date(t.replace(" ","T"));return isNaN(i.getTime())?null:i}let n=V.exec(t);if(n){let i=new Date(+n[1],+n[2]-1,+n[3]);return C(i,+n[1],+n[2],+n[3])?i:null}let r=Q.exec(t);if(r){let i=+r[1],s=+r[2],a=+r[3],o,l;i>12&&s<=12?(o=i,l=s):s>12&&i<=12?(o=s,l=i):(o=i,l=s);let u=new Date(a,l-1,o);return C(u,a,l,o)?u:null}return null}function C(e,t,n,r){return !isNaN(e.getTime())&&e.getFullYear()===t&&e.getMonth()===n-1&&e.getDate()===r}function G(e){if(e==null||e==="")return "blank";if(typeof e=="boolean")return "boolean";if(typeof e=="number")return isNaN(e)?"blank":"number";if(e instanceof Date)return isNaN(e.getTime())?"blank":"date";let t=String(e).trim();return t===""?"blank":z(t)?"boolean":K(t)?"string":D(t)?"date":_(t)!==null?"number":"string"}function x(e){let t={string:0,number:0,date:0,boolean:0};for(let i of e){let s=G(i);s!=="blank"&&t[s]++;}let n="string",r=0;return Object.keys(t).forEach(i=>{t[i]>r&&(r=t[i],n=i);}),n}function v(e,t){if(e==null||e==="")return null;switch(t){case "number":return _(e);case "date":return D(e)??(e instanceof Date?e:null);case "boolean":return Y(e);default:return e}}var E=new Set(["__proto__","constructor","prototype"]);function y(e){return E.has(e)?`${e}_`:e}function M(e){let t=false;for(let n of e)if(!(!n||typeof n!="object")){for(let r of Object.keys(n))if(E.has(r)){t=true;break}if(t)break}return t?e.map(n=>{if(!n||typeof n!="object")return n;let r={};for(let i of Object.keys(n))r[y(i)]=n[i];return r}):e}var O=200,I=2e4;function q(e){let t=new Map;return e.map(n=>{let r=t.get(n)??0;return t.set(n,r+1),y(r===0?n:`${n}_${r+1}`)})}function P(e,t){if(e.length===0)return [];let n=[],r=new Set,i=Math.min(e.length,500);for(let o=0;o<i;o++){let l=e[o];if(!(!l||typeof l!="object"))for(let u of Object.keys(l))r.has(u)||(r.add(u),n.push(u));}let s=new Map;for(let o of n){let l=[];for(let u=0;u<e.length&&l.length<O;u++){let c=e[u]?.[o];c!=null&&String(c).trim()!==""&&l.push(c);}s.set(o,x(l));}let a=new Array(e.length);for(let o=0;o<e.length;o++){let l=e[o]||{},u={};for(let c of n){let d=l[c];u[y(c)]=d==null||d===""?null:v(d,s.get(c));}a[o]=u;}return a}function $(e,t){let n=T(e);if(!n.trim())return [];let r=N(n),i=X(n,r,t?c=>t({phase:"parsing",percent:Math.round(c*60)}):void 0);if(i.length===0)return [];let s=0;for(;s<i.length&&i[s].every(c=>c.trim()==="");)s++;if(s>=i.length)return [];let a=q(i[s].map((c,d)=>c.trim()||`Column${d+1}`)),o=i.slice(s+1).filter(c=>!(c.length===1&&c[0].trim()==="")),l=a.map((c,d)=>{let f=[];for(let g=0;g<o.length&&f.length<O;g++){let p=o[g][d];p!==void 0&&p.trim()!==""&&f.push(p);}return x(f)}),u=new Array(o.length);for(let c=0;c<o.length;c++){let d=o[c],f={};for(let g=0;g<a.length;g++){let p=d[g];f[a[g]]=p===void 0||p===""?null:v(p,l[g]);}u[c]=f,t&&c>0&&c%I===0&&t({phase:"typing",percent:60+Math.round(c/o.length*40)});}return t&&t({phase:"typing",percent:100}),u}var b=class e{supports(t){return t.name.split(".").pop()?.toLowerCase()==="xml"||t.type==="application/xml"||t.type==="text/xml"}async read(t){let n=await S(t);return e.parse(n)}static parse(t){if(!t||!t.trim())return [];let n=J(t),i=et(n).map(nt).filter(s=>Object.keys(s).length>0);return P(i)}};function J(e){let t={tag:"#root",attrs:{},children:[],text:"",parent:null},n=t,r=0,i=e.length;for(;r<i;){let s=e.indexOf("<",r);if(s===-1){n.text+=e.slice(r);break}if(s>r&&(n.text+=e.slice(r,s)),e.startsWith("<!--",s)){let f=e.indexOf("-->",s+4);r=f===-1?i:f+3;continue}if(e.startsWith("<![CDATA[",s)){let f=e.indexOf("]]>",s+9);n.text+=e.slice(s+9,f===-1?i:f),r=f===-1?i:f+3;continue}if(e.startsWith("<?",s)){let f=e.indexOf("?>",s+2);r=f===-1?i:f+2;continue}if(e.startsWith("<!",s)){let f=e.indexOf(">",s+2);r=f===-1?i:f+1;continue}let a=e.indexOf(">",s+1);if(a===-1)break;let o=e.slice(s+1,a).trim();if(o.startsWith("/")){let f=o.slice(1).trim(),g=n;for(;g&&g.tag!==f;)g=g.parent;g&&g.parent&&(n=g.parent),r=a+1;continue}let l=o.endsWith("/");l&&(o=o.slice(0,-1).trim());let{name:u,attrs:c}=tt(o),d={tag:u,attrs:c,children:[],text:"",parent:n};n.children.push(d),l||(n=d),r=a+1;}return t}var j=/([^\s=/]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;function tt(e){let t=e.search(/\s/),n=(t===-1?e:e.slice(0,t)).trim(),r={};if(t!==-1){let i=e.slice(t+1),s;for(j.lastIndex=0;(s=j.exec(i))!==null;)r[s[1]]=R(s[2]??s[3]??"");}return {name:n,attrs:r}}function et(e){let t=e.children[0];if(!t)return [];let n=t.children;return n.length===0?[]:n.some(i=>i.children.length>0||Object.keys(i.attrs).length>0)?n:[t]}function nt(e){let t={},n=new Map,r=(i,s)=>{let a=i||"value",o=n.get(a)??0;n.set(a,o+1),t[y(o===0?a:`${a}_${o+1}`)]=s;};for(let[i,s]of Object.entries(e.attrs))r(i,s);if(e.children.length===0){let i=e.text.trim();i&&r(e.tag,R(i));}else for(let i of e.children)r(i.tag,R(W(i).trim()));return t}function W(e){if(e.children.length===0)return e.text;let t=e.text;for(let n of e.children)t+=W(n);return t}var rt=/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g,it={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:"\xA0"};function R(e){return e.indexOf("&")===-1?e:e.replace(rt,(t,n)=>{if(n[0]==="#"){let r=n[1]==="x"||n[1]==="X"?parseInt(n.slice(2),16):parseInt(n.slice(1),10);return Number.isFinite(r)?String.fromCodePoint(r):t}return it[n]??t})}var h=class{static extractFieldsFromData(t,n=50){if(!t||t.length===0)return [];let r=[],i=Math.max(n,50),s=this.collectKeys(t,i),a=false,o=false;return s.forEach(l=>{let u=this.inferType(t,l,n),c="chooser";!a&&this.isAutoRowCandidate(t,l,u,i)?(c="row",a=true):!o&&this.isAutoDataCandidate(l,u)&&(c="data",o=true);let d={id:`f_${l}`,dataField:l,caption:this.formatCaption(l),dataType:u,area:c,areaIndex:0};u==="number"?d.summaryType="sum":u==="date"&&(d.groupInterval="month"),r.push(d);}),r}static buildFieldsFromPlan(t,n,r=50){let i=[],s=false,a=false,o=Math.max(r,50);for(let l of t){let u="chooser";!s&&this.isAutoRowCandidate(n,l.dataField,l.dataType,o)?(u="row",s=true):!a&&this.isAutoDataCandidate(l.dataField,l.dataType)&&(u="data",a=true);let c={id:`f_${l.dataField}`,dataField:l.dataField,caption:l.caption,dataType:l.dataType,area:u,areaIndex:0};l.dataType==="number"?c.summaryType="sum":l.dataType==="date"&&(c.groupInterval="month"),i.push(c);}return i}static isAutoRowCandidate(t,n,r,i){return !(n.startsWith("__EMPTY")||r!=="string"&&r!=="date"||this.isIdentifierLikeKey(n)||r==="string"&&t&&this.isHighCardinalityStringColumn(t,n,i))}static isAutoDataCandidate(t,n){return n==="number"&&!t.startsWith("__EMPTY")&&!this.isIdentifierLikeKey(t)}static isHighCardinalityStringColumn(t,n,r){let i=Math.min(t.length,r),s=new Set,a=0;for(let o=0;o<i;o++){let l=t[o]?.[n];l==null||l===""||(a++,s.add(String(l)));}return a<20?false:s.size/a>=.9}static isIdentifierLikeKey(t){let n=t.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase(),r=n.replace(/[^a-z0-9]/g,"");return r==="id"||r==="uuid"||r==="guid"||r==="key"?true:/(^|[\s_.-])(id|uuid|guid|key)($|[\s_.-])/.test(n)}static collectKeys(t,n){let r=[],i=new Set,s=Math.min(t.length,n);for(let a=0;a<s;a++){let o=t[a];if(!(!o||typeof o!="object"))for(let l of Object.keys(o))i.has(l)||(i.add(l),r.push(l));}return r}static inferType(t,n,r){let i=Math.min(t.length,r),s=new Array(i);for(let a=0;a<i;a++)s[a]=t[a]?.[n];return x(s)}static formatCaption(t){return t.replace(/([A-Z])/g," $1").replace(/_/g," ").replace(/^./,n=>n.toUpperCase()).trim()}};var k=self;k.onmessage=async e=>{let t=e.data;if(!t||t.type!=="parse")return;let{jobId:n,kind:r,file:i}=t;try{if(r==="csv"){m(n,"reading",3);let s=await i.text(),a=$(s,l=>{m(n,l.phase,5+Math.round(l.percent*.92));});m(n,"finalizing",98);let o=h.extractFieldsFromData(a);w(n,{mode:"data",data:a,fields:o});return}if(r==="xml"){m(n,"reading",10);let s=await i.text();m(n,"parsing",50);let a=b.parse(s);m(n,"finalizing",90);let o=h.extractFieldsFromData(a);w(n,{mode:"data",data:a,fields:o});return}if(r==="json"){m(n,"reading",10);let s=await i.text();m(n,"parsing",45);let a=JSON.parse(s);if(Array.isArray(a)){m(n,"finalizing",90);let o=M(a),l=h.extractFieldsFromData(o);w(n,{mode:"data",data:o,fields:l});}else w(n,{mode:"raw",value:a});return}L(n,`Desteklenmeyen i\xE7e aktarma t\xFCr\xFC: ${String(r)}`);}catch(s){L(n,s instanceof Error?s.message:String(s));}};function m(e,t,n){k.postMessage({type:"progress",jobId:e,phase:t,percent:n});}function w(e,t){k.postMessage({type:"done",jobId:e,payload:t});}function L(e,t){k.postMessage({type:"error",jobId:e,message:t});}
|