@kanunilabs/pivotgrid-core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +55 -0
- package/README.md +48 -0
- package/dist/export.worker.cjs +24 -0
- package/dist/export.worker.d.cts +2 -0
- package/dist/export.worker.d.ts +2 -0
- package/dist/export.worker.js +24 -0
- package/dist/import.worker.cjs +3 -0
- package/dist/import.worker.d.cts +2 -0
- package/dist/import.worker.d.ts +2 -0
- package/dist/import.worker.js +3 -0
- package/dist/index.cjs +60 -0
- package/dist/index.d.cts +787 -0
- package/dist/index.d.ts +787 -0
- package/dist/index.js +60 -0
- package/dist/pivot.worker-DQFl4fMu.d.cts +1001 -0
- package/dist/pivot.worker-DQFl4fMu.d.ts +1001 -0
- package/dist/pivot.worker.cjs +1 -0
- package/dist/pivot.worker.d.cts +1 -0
- package/dist/pivot.worker.d.ts +1 -0
- package/dist/pivot.worker.js +1 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
KanuniLabs Community License
|
|
2
|
+
Version 1.0
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2024-present KanuniLabs. All rights reserved.
|
|
5
|
+
|
|
6
|
+
This package (the "Software") is made available free of charge, but it is
|
|
7
|
+
proprietary software and is NOT open source. By installing or using the
|
|
8
|
+
Software you agree to these terms.
|
|
9
|
+
|
|
10
|
+
1. LICENSE GRANT
|
|
11
|
+
KanuniLabs grants you a worldwide, royalty-free, non-exclusive license to:
|
|
12
|
+
(a) install and use the Software as a dependency of your applications,
|
|
13
|
+
including commercial applications; and
|
|
14
|
+
(b) reproduce and distribute the Software solely as an incorporated,
|
|
15
|
+
compiled part of such applications.
|
|
16
|
+
|
|
17
|
+
2. RESTRICTIONS
|
|
18
|
+
You may NOT:
|
|
19
|
+
(a) modify, adapt, translate, or create derivative works of the Software;
|
|
20
|
+
(b) decompile, disassemble, deobfuscate, or otherwise attempt to derive
|
|
21
|
+
the source code of the Software, except, and only to the extent,
|
|
22
|
+
applicable law expressly permits notwithstanding this limitation;
|
|
23
|
+
(c) distribute, publish, sublicense, sell, rent, or lease the Software on
|
|
24
|
+
its own, or as part of any toolkit, component, library, or product
|
|
25
|
+
that competes with KanuniLabs products;
|
|
26
|
+
(d) remove, obscure, or alter any copyright, trademark, or other
|
|
27
|
+
proprietary notice.
|
|
28
|
+
|
|
29
|
+
3. OWNERSHIP
|
|
30
|
+
The Software is licensed, not sold. KanuniLabs retains all right, title,
|
|
31
|
+
and interest in and to the Software, including all intellectual property
|
|
32
|
+
rights. No rights are granted except as expressly stated herein.
|
|
33
|
+
|
|
34
|
+
4. ENTERPRISE FEATURES
|
|
35
|
+
Certain features require a separate paid license
|
|
36
|
+
(@kanunilabs/pivotgrid-react-enterprise). This license grants no right to
|
|
37
|
+
those features.
|
|
38
|
+
|
|
39
|
+
5. NO WARRANTY
|
|
40
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
41
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
42
|
+
FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
|
|
43
|
+
|
|
44
|
+
6. LIMITATION OF LIABILITY
|
|
45
|
+
IN NO EVENT SHALL KANUNILABS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
|
|
46
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING
|
|
47
|
+
FROM OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
48
|
+
THE SOFTWARE.
|
|
49
|
+
|
|
50
|
+
7. TERMINATION
|
|
51
|
+
This license terminates automatically if you breach any term. Upon
|
|
52
|
+
termination you must cease all use and distribution of the Software.
|
|
53
|
+
|
|
54
|
+
For commercial licensing, source access, or other arrangements, contact
|
|
55
|
+
licensing@kanunilabs.com.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @kanunilabs/pivotgrid-core
|
|
2
|
+
|
|
3
|
+
Framework-agnostic PivotGrid engine with Web Worker computation, columnar storage, trie-based grouping, and headless controller.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Web Worker** — All aggregation runs off the main thread
|
|
8
|
+
- **Columnar Storage** — Dictionary-encoded Int32Array/Float64Array for memory efficiency
|
|
9
|
+
- **FastTrie** — Int32Array-based trie for hierarchical row/column grouping
|
|
10
|
+
- **Bitmask Filtering** — O(n) Uint8Array row mask applied inside the worker
|
|
11
|
+
- **Summary Display Modes** — Percent of Grand Total, Column, Row, Running Total, Rank, Index
|
|
12
|
+
- **CSP-Safe** — No `eval` or `new Function`; recursive-descent expression parser
|
|
13
|
+
- **12 Locales** — tr, en, de, fr, es, it, pt, ru, ar, zh-CN, ja, ko
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @kanunilabs/pivotgrid-core
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Peer dependencies (installed automatically by npm ≥ 7 and pnpm): `xlsx` (file import) and `file-saver` (file export).
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Most applications should use a framework wrapper such as
|
|
26
|
+
[`@kanunilabs/pivotgrid-react`](https://www.npmjs.com/package/@kanunilabs/pivotgrid-react)
|
|
27
|
+
instead of driving the engine directly. The headless controller:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { PivotController } from '@kanunilabs/pivotgrid-core';
|
|
31
|
+
|
|
32
|
+
const controller = new PivotController({
|
|
33
|
+
gridId: 'sales',
|
|
34
|
+
data: rows,
|
|
35
|
+
initialFields: [
|
|
36
|
+
{ id: 'region', dataField: 'region', caption: 'Region', dataType: 'string', area: 'row' },
|
|
37
|
+
{ id: 'product', dataField: 'product', caption: 'Product', dataType: 'string', area: 'column' },
|
|
38
|
+
{ id: 'amount', dataField: 'amount', caption: 'Amount', dataType: 'number', area: 'data', summaryType: 'sum' },
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
**KanuniLabs Community License v1.0** — free to use in commercial and
|
|
46
|
+
non-commercial applications; the source code is proprietary (no
|
|
47
|
+
redistribution/modification of the package itself). See [LICENSE](./LICENSE)
|
|
48
|
+
for the full terms.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';self.onmessage=async n=>{let{type:e,chunkId:c,chunk:s,fields:a,format:t,isFirstChunk:r,isLastChunk:o,locale:i}=n.data;if(e==="process_chunk")try{if(t==="csv"){let l=w(s,a,r,i);self.postMessage({type:"chunk_done",chunkId:c,format:"csv",payload:l});}else if(t==="excel-xml"){let l=T(s,a,r,o,i);self.postMessage({type:"chunk_done",chunkId:c,format:"excel-xml",payload:l});}}catch(l){self.postMessage({type:"error",chunkId:c,error:l instanceof Error?l.message:String(l)});}};var y=new Map,S=new Map;function h(n){if(!n||typeof n!="object")return false;let e=n;return "year"in e||"month"in e||"day"in e||"weekday"in e||"hour"in e||"minute"in e||"second"in e||"dateStyle"in e||"timeStyle"in e}var k={year:"numeric",month:"2-digit",day:"2-digit"};function x(n,e,c){let s=n instanceof Date?n:new Date(n);if(isNaN(s.getTime()))return String(n);try{let a=h(e?.format)?e.format:k,t=JSON.stringify(a)+"_"+c,r=S.get(t);return r||(r=new Intl.DateTimeFormat(c,a),S.set(t,r)),r.format(s)}catch{return String(n)}}function d(n,e,c="tr-TR"){if(n==null)return "";if(e?.dataType==="date"&&n!=="")return x(n,e,c);if(e&&e.format&&typeof n=="number")try{let s=e.format,a=JSON.stringify(s)+"_"+c,t=y.get(a);t||(t=new Intl.NumberFormat(c,s),y.set(a,t));let r=t.format(n);return s.isCustom&&(s.prefix||s.suffix)?`${s.prefix||""}${r}${s.suffix||""}`:r}catch{return String(n)}return String(n)}function w(n,e,c,s){let a="",t=e.map(r=>{let o=r.dataField||r.id;return typeof o=="string"?o:null});if(c){let r=e.map(o=>o.caption||o.id);a+=r.map(F).join(",")+`
|
|
2
|
+
`;}for(let r of n){let o=new Array(t.length);for(let i=0;i<t.length;i++){let l=t[i],f=l?r[l]??"":"",u=d(f,e[i],s);typeof f=="string"&&(u=D(u)),o[i]=u;}a+=o.map(F).join(",")+`
|
|
3
|
+
`;}return a}function D(n){return n.length>0&&/^[=+\-@\t\r]/.test(n)?"'"+n:n}function F(n){if(n==null)return "";let e=String(n);return e.includes(",")||e.includes('"')||e.includes(`
|
|
4
|
+
`)?`"${e.replace(/"/g,'""')}"`:e}function T(n,e,c,s,a){let t="",r=e.map(o=>{let i=o.dataField||o.id;return typeof i=="string"?i:null});c&&(t+=`<?xml version="1.0" encoding="UTF-8"?>
|
|
5
|
+
`,t+=`<?mso-application progid="Excel.Sheet"?>
|
|
6
|
+
`,t+=`<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
|
|
7
|
+
`,t+=` <Styles>
|
|
8
|
+
`,t+=` <Style ss:ID="HeaderStyle">
|
|
9
|
+
`,t+=` <Font ss:Bold="1" ss:Color="#FFFFFF"/>
|
|
10
|
+
`,t+=` <Interior ss:Color="#4F81BD" ss:Pattern="Solid"/>
|
|
11
|
+
`,t+=` </Style>
|
|
12
|
+
`,t+=` </Styles>
|
|
13
|
+
`,t+=` <Worksheet ss:Name="Data">
|
|
14
|
+
`,t+=` <Table>
|
|
15
|
+
`,t+=` <Row>
|
|
16
|
+
`,e.forEach(o=>{t+=` <Cell ss:StyleID="HeaderStyle"><Data ss:Type="String">${g(o.caption||o.id||"")}</Data></Cell>
|
|
17
|
+
`;}),t+=` </Row>
|
|
18
|
+
`);for(let o of n){t+=` <Row>
|
|
19
|
+
`;for(let i=0;i<r.length;i++){let l=r[i],f=l?o[l]:void 0,u=e[i],m="String",p="";if(f==null||f===""){t+=` <Cell></Cell>
|
|
20
|
+
`;continue}else u?.dataType==="date"?(m="String",p=g(d(f,u,a))):typeof f=="number"?u&&u.format?(p=g(d(f,u,a)),m="String"):(m="Number",p=String(f)):(m="String",p=g(String(f)));t+=` <Cell><Data ss:Type="${m}">${p}</Data></Cell>
|
|
21
|
+
`;}t+=` </Row>
|
|
22
|
+
`;}return s&&(t+=` </Table>
|
|
23
|
+
`,t+=` </Worksheet>
|
|
24
|
+
`,t+="</Workbook>"),t}function g(n){return n?n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"):""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
self.onmessage=async n=>{let{type:e,chunkId:c,chunk:s,fields:a,format:t,isFirstChunk:r,isLastChunk:o,locale:i}=n.data;if(e==="process_chunk")try{if(t==="csv"){let l=w(s,a,r,i);self.postMessage({type:"chunk_done",chunkId:c,format:"csv",payload:l});}else if(t==="excel-xml"){let l=T(s,a,r,o,i);self.postMessage({type:"chunk_done",chunkId:c,format:"excel-xml",payload:l});}}catch(l){self.postMessage({type:"error",chunkId:c,error:l instanceof Error?l.message:String(l)});}};var y=new Map,S=new Map;function h(n){if(!n||typeof n!="object")return false;let e=n;return "year"in e||"month"in e||"day"in e||"weekday"in e||"hour"in e||"minute"in e||"second"in e||"dateStyle"in e||"timeStyle"in e}var k={year:"numeric",month:"2-digit",day:"2-digit"};function x(n,e,c){let s=n instanceof Date?n:new Date(n);if(isNaN(s.getTime()))return String(n);try{let a=h(e?.format)?e.format:k,t=JSON.stringify(a)+"_"+c,r=S.get(t);return r||(r=new Intl.DateTimeFormat(c,a),S.set(t,r)),r.format(s)}catch{return String(n)}}function d(n,e,c="tr-TR"){if(n==null)return "";if(e?.dataType==="date"&&n!=="")return x(n,e,c);if(e&&e.format&&typeof n=="number")try{let s=e.format,a=JSON.stringify(s)+"_"+c,t=y.get(a);t||(t=new Intl.NumberFormat(c,s),y.set(a,t));let r=t.format(n);return s.isCustom&&(s.prefix||s.suffix)?`${s.prefix||""}${r}${s.suffix||""}`:r}catch{return String(n)}return String(n)}function w(n,e,c,s){let a="",t=e.map(r=>{let o=r.dataField||r.id;return typeof o=="string"?o:null});if(c){let r=e.map(o=>o.caption||o.id);a+=r.map(F).join(",")+`
|
|
2
|
+
`;}for(let r of n){let o=new Array(t.length);for(let i=0;i<t.length;i++){let l=t[i],f=l?r[l]??"":"",u=d(f,e[i],s);typeof f=="string"&&(u=D(u)),o[i]=u;}a+=o.map(F).join(",")+`
|
|
3
|
+
`;}return a}function D(n){return n.length>0&&/^[=+\-@\t\r]/.test(n)?"'"+n:n}function F(n){if(n==null)return "";let e=String(n);return e.includes(",")||e.includes('"')||e.includes(`
|
|
4
|
+
`)?`"${e.replace(/"/g,'""')}"`:e}function T(n,e,c,s,a){let t="",r=e.map(o=>{let i=o.dataField||o.id;return typeof i=="string"?i:null});c&&(t+=`<?xml version="1.0" encoding="UTF-8"?>
|
|
5
|
+
`,t+=`<?mso-application progid="Excel.Sheet"?>
|
|
6
|
+
`,t+=`<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
|
|
7
|
+
`,t+=` <Styles>
|
|
8
|
+
`,t+=` <Style ss:ID="HeaderStyle">
|
|
9
|
+
`,t+=` <Font ss:Bold="1" ss:Color="#FFFFFF"/>
|
|
10
|
+
`,t+=` <Interior ss:Color="#4F81BD" ss:Pattern="Solid"/>
|
|
11
|
+
`,t+=` </Style>
|
|
12
|
+
`,t+=` </Styles>
|
|
13
|
+
`,t+=` <Worksheet ss:Name="Data">
|
|
14
|
+
`,t+=` <Table>
|
|
15
|
+
`,t+=` <Row>
|
|
16
|
+
`,e.forEach(o=>{t+=` <Cell ss:StyleID="HeaderStyle"><Data ss:Type="String">${g(o.caption||o.id||"")}</Data></Cell>
|
|
17
|
+
`;}),t+=` </Row>
|
|
18
|
+
`);for(let o of n){t+=` <Row>
|
|
19
|
+
`;for(let i=0;i<r.length;i++){let l=r[i],f=l?o[l]:void 0,u=e[i],m="String",p="";if(f==null||f===""){t+=` <Cell></Cell>
|
|
20
|
+
`;continue}else u?.dataType==="date"?(m="String",p=g(d(f,u,a))):typeof f=="number"?u&&u.format?(p=g(d(f,u,a)),m="String"):(m="Number",p=String(f)):(m="String",p=g(String(f)));t+=` <Cell><Data ss:Type="${m}">${p}</Data></Cell>
|
|
21
|
+
`;}t+=` </Row>
|
|
22
|
+
`;}return s&&(t+=` </Table>
|
|
23
|
+
`,t+=` </Worksheet>
|
|
24
|
+
`,t+="</Workbook>"),t}function g(n){return n?n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"):""}
|
|
@@ -0,0 +1,3 @@
|
|
|
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=>W(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 W(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 L(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 B(e){let t=e.trim().toLowerCase();return A.has(t)||F.has(t)}function X(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 z(e){return /^0\d+$/.test(e)}var Y=/[₺$€£¥]/g,K=/[\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(K,"").replace(Y,"");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 H=/^\d{4}-\d{2}-\d{2}([ T]\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:?\d{2})?)?$/,Z=/^(\d{4})[/.](\d{1,2})[/.](\d{1,2})$/,U=/^(\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(H.test(t)){let i=new Date(t.replace(" ","T"));return isNaN(i.getTime())?null:i}let n=Z.exec(t);if(n){let i=new Date(+n[1],+n[2]-1,+n[3]);return R(i,+n[1],+n[2],+n[3])?i:null}let r=U.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 R(u,a,l,o)?u:null}return null}function R(e,t,n,r){return !isNaN(e.getTime())&&e.getFullYear()===t&&e.getMonth()===n-1&&e.getDate()===r}function V(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":B(t)?"boolean":z(t)?"string":D(t)?"date":_(t)!==null?"number":"string"}function y(e){let t={string:0,number:0,date:0,boolean:0};for(let i of e){let s=V(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 X(e);default:return e}}var Q=new Set(["__proto__","constructor","prototype"]);function x(e){return Q.has(e)?`${e}_`:e}var E=200,M=2e4;function G(e){let t=new Map;return e.map(n=>{let r=t.get(n)??0;return t.set(n,r+1),x(r===0?n:`${n}_${r+1}`)})}function O(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<E;u++){let c=e[u]?.[o];c!=null&&String(c).trim()!==""&&l.push(c);}s.set(o,y(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[x(c)]=d==null||d===""?null:v(d,s.get(c));}a[o]=u;}return a}function I(e,t){let n=T(e);if(!n.trim())return [];let r=N(n),i=L(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=G(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<E;g++){let p=o[g][d];p!==void 0&&p.trim()!==""&&f.push(p);}return y(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%M===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=q(t),i=tt(n).map(et).filter(s=>Object.keys(s).length>0);return O(i)}};function q(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}=J(o),d={tag:u,attrs:c,children:[],text:"",parent:n};n.children.push(d),l||(n=d),r=a+1;}return t}var P=/([^\s=/]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;function J(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(P.lastIndex=0;(s=P.exec(i))!==null;)r[s[1]]=C(s[2]??s[3]??"");}return {name:n,attrs:r}}function tt(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 et(e){let t={},n=new Map,r=(i,s)=>{let a=i||"value",o=n.get(a)??0;n.set(a,o+1),t[x(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,C(i));}else for(let i of e.children)r(i.tag,C($(i).trim()));return t}function $(e){if(e.children.length===0)return e.text;let t=e.text;for(let n of e.children)t+=$(n);return t}var nt=/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g,rt={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:"\xA0"};function C(e){return e.indexOf("&")===-1?e:e.replace(nt,(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 rt[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 y(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=I(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=h.extractFieldsFromData(a);w(n,{mode:"data",data:a,fields:o});}else w(n,{mode:"raw",value:a});return}j(n,`Desteklenmeyen i\xE7e aktarma t\xFCr\xFC: ${String(r)}`);}catch(s){j(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 j(e,t){k.postMessage({type:"error",jobId:e,message:t});}
|
|
@@ -0,0 +1,3 @@
|
|
|
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=>W(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 W(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 L(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 B(e){let t=e.trim().toLowerCase();return A.has(t)||F.has(t)}function X(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 z(e){return /^0\d+$/.test(e)}var Y=/[₺$€£¥]/g,K=/[\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(K,"").replace(Y,"");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 H=/^\d{4}-\d{2}-\d{2}([ T]\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:?\d{2})?)?$/,Z=/^(\d{4})[/.](\d{1,2})[/.](\d{1,2})$/,U=/^(\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(H.test(t)){let i=new Date(t.replace(" ","T"));return isNaN(i.getTime())?null:i}let n=Z.exec(t);if(n){let i=new Date(+n[1],+n[2]-1,+n[3]);return R(i,+n[1],+n[2],+n[3])?i:null}let r=U.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 R(u,a,l,o)?u:null}return null}function R(e,t,n,r){return !isNaN(e.getTime())&&e.getFullYear()===t&&e.getMonth()===n-1&&e.getDate()===r}function V(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":B(t)?"boolean":z(t)?"string":D(t)?"date":_(t)!==null?"number":"string"}function y(e){let t={string:0,number:0,date:0,boolean:0};for(let i of e){let s=V(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 X(e);default:return e}}var Q=new Set(["__proto__","constructor","prototype"]);function x(e){return Q.has(e)?`${e}_`:e}var E=200,M=2e4;function G(e){let t=new Map;return e.map(n=>{let r=t.get(n)??0;return t.set(n,r+1),x(r===0?n:`${n}_${r+1}`)})}function O(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<E;u++){let c=e[u]?.[o];c!=null&&String(c).trim()!==""&&l.push(c);}s.set(o,y(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[x(c)]=d==null||d===""?null:v(d,s.get(c));}a[o]=u;}return a}function I(e,t){let n=T(e);if(!n.trim())return [];let r=N(n),i=L(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=G(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<E;g++){let p=o[g][d];p!==void 0&&p.trim()!==""&&f.push(p);}return y(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%M===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=q(t),i=tt(n).map(et).filter(s=>Object.keys(s).length>0);return O(i)}};function q(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}=J(o),d={tag:u,attrs:c,children:[],text:"",parent:n};n.children.push(d),l||(n=d),r=a+1;}return t}var P=/([^\s=/]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;function J(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(P.lastIndex=0;(s=P.exec(i))!==null;)r[s[1]]=C(s[2]??s[3]??"");}return {name:n,attrs:r}}function tt(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 et(e){let t={},n=new Map,r=(i,s)=>{let a=i||"value",o=n.get(a)??0;n.set(a,o+1),t[x(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,C(i));}else for(let i of e.children)r(i.tag,C($(i).trim()));return t}function $(e){if(e.children.length===0)return e.text;let t=e.text;for(let n of e.children)t+=$(n);return t}var nt=/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g,rt={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:"\xA0"};function C(e){return e.indexOf("&")===-1?e:e.replace(nt,(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 rt[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 y(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=I(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=h.extractFieldsFromData(a);w(n,{mode:"data",data:a,fields:o});}else w(n,{mode:"raw",value:a});return}j(n,`Desteklenmeyen i\xE7e aktarma t\xFCr\xFC: ${String(r)}`);}catch(s){j(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 j(e,t){k.postMessage({type:"error",jobId:e,message:t});}
|