rowpine 0.0.0-stage → 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.md +18 -0
- package/README.md +89 -2
- package/dist/build-info.d.ts +2 -0
- package/dist/csv.d.ts +14 -0
- package/dist/download.d.ts +4 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/license.d.ts +32 -0
- package/dist/pdf/doc.d.ts +357 -0
- package/dist/pdf/index.d.ts +11 -0
- package/dist/pivot/designer.d.ts +90 -0
- package/dist/pivot/extent.d.ts +7 -0
- package/dist/pivot/pivot.d.ts +106 -0
- package/dist/pivot/tanstack.d.ts +65 -0
- package/dist/table-source.d.ts +147 -0
- package/dist/xlsx/index.d.ts +17 -0
- package/dist/xlsx/ooxml.d.ts +115 -0
- package/package.json +63 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
DRAFT - replace with the final license terms before the first npm release.
|
|
2
|
+
|
|
3
|
+
Rowpine commercial license
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2026 Rowpine. All rights reserved.
|
|
6
|
+
|
|
7
|
+
You may install Rowpine and use it without a license key to evaluate it.
|
|
8
|
+
Exports made without a key carry a notice line.
|
|
9
|
+
|
|
10
|
+
Using Rowpine in a product or service needs a license for each developer
|
|
11
|
+
who works on code that uses it. A license is a one-time payment and includes
|
|
12
|
+
one year of updates. You may keep using every version released during that
|
|
13
|
+
year without further payment.
|
|
14
|
+
|
|
15
|
+
You may not redistribute Rowpine as a standalone library or as part of a
|
|
16
|
+
component library, or share license keys outside the licensed developers.
|
|
17
|
+
|
|
18
|
+
CSV export (exportCsv, tableToCsv) may be used without a license.
|
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# rowpine
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Pivot tables, a pivot designer, and Excel and PDF export for TanStack Table and shadcn/ui data tables.** Works with TanStack Table v8 and v9.
|
|
4
|
+
|
|
5
|
+
[Website](https://rowpine.com) · [Demos](https://rowpine.com/examples/) · [Docs](https://rowpine.com/docs/) · [Pricing](https://rowpine.com/pricing.html)
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install rowpine
|
|
13
|
+
npx shadcn add https://rowpine.com/r/export-menu.json
|
|
14
|
+
npx shadcn add https://rowpine.com/r/pivot.json
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This package is the engine: the file writers, the pivot and the license check. The two `shadcn add` lines copy the export menu, the pivot table and the pivot designer into your project as source.
|
|
18
|
+
|
|
19
|
+
## Export
|
|
20
|
+
|
|
21
|
+
Pass the TanStack table you already render. The file matches the screen: visible columns in their order, every filtered row on every page, the current sort, pinned columns frozen, groups as Excel outline rows with `SUBTOTAL` formulas, typed numbers and dates.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { exportCsv, exportPdf, exportXlsx, setLicenseKey } from "rowpine"
|
|
25
|
+
|
|
26
|
+
setLicenseKey(import.meta.env.VITE_ROWPINE_KEY)
|
|
27
|
+
|
|
28
|
+
await exportXlsx(table, { fileName: "orders" })
|
|
29
|
+
await exportPdf(table, { fileName: "orders", title: "Orders" })
|
|
30
|
+
await exportCsv(table, { fileName: "orders" }) // free, no key needed
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
`rows: "all" | "page" | "selected"` picks the rows (default `"all"`: every filtered row on every page). `rowStyle` styles whole rows. `download: false` returns the Blob without saving it.
|
|
36
|
+
|
|
37
|
+
Per-column settings go in `meta.rowpine`:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
{
|
|
41
|
+
accessorKey: "amount",
|
|
42
|
+
header: "Amount",
|
|
43
|
+
aggregationFn: "sum",
|
|
44
|
+
meta: {
|
|
45
|
+
rowpine: {
|
|
46
|
+
numFmt: '"$"#,##0.00', // Excel number format
|
|
47
|
+
format: (v) => money.format(v as number), // PDF text
|
|
48
|
+
cellStyle: (v) => ((v as number) > 5000 ? { fill: "#dcfce7" } : undefined),
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Also: `header`, `width`, `align`, `exclude`.
|
|
55
|
+
|
|
56
|
+
## PDF
|
|
57
|
+
|
|
58
|
+
Page size and orientation, a title, headline numbers, a watermark, group rows with their totals, the header row on every page. Wide tables shrink and then split so every column prints.
|
|
59
|
+
|
|
60
|
+

|
|
61
|
+
|
|
62
|
+
## Pivot
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { createPivot, exportXlsx, pivotRowStyle } from "rowpine"
|
|
66
|
+
|
|
67
|
+
const pivot = createPivot(orders, {
|
|
68
|
+
rows: ["region", "country"],
|
|
69
|
+
cols: ["quarter"],
|
|
70
|
+
values: [{ field: "amount", agg: "sum", label: "Amount" }],
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
pivot.data // rows nested through subRows, for useTable / useReactTable
|
|
74
|
+
pivot.columns // column definitions with accessor functions
|
|
75
|
+
await exportXlsx(pivot.table, { rowStyle: pivotRowStyle })
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Aggregations: `sum`, `avg`, `min`, `max`, `count`, `countDistinct`, `first`, `last`, or a function. Subtotals and grand totals are on by default (`rowSubtotals`, `grandTotalRow`, `grandTotalCol`). The pivot designer's layout rules are exported too (`addToWell`, `setAggregatorAt`, `pivotFromLayout` and more), so you can drive a layout from your own UI.
|
|
79
|
+
|
|
80
|
+
## Demos
|
|
81
|
+
|
|
82
|
+
Ten demos play a short story on the live component and end with the exported file. [Open the demos](https://rowpine.com/examples/).
|
|
83
|
+
|
|
84
|
+
[](https://rowpine.com/examples/#/demo/orders-to-excel)
|
|
85
|
+
|
|
86
|
+
## License key
|
|
87
|
+
|
|
88
|
+
CSV export is free. Excel, PDF and pivots need a key; without one everything still runs, and Excel and PDF files carry one notice line. A key covers every version released during its year of updates, for good. Keys are checked in the browser, with no call to a server. [Pricing](https://rowpine.com/pricing.html).
|
|
89
|
+
|
|
90
|
+
Commercial license: see LICENSE.md.
|
package/dist/csv.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReadOptions, type TableLike } from './table-source';
|
|
2
|
+
export type CsvExportOptions = ReadOptions & {
|
|
3
|
+
fileName?: string;
|
|
4
|
+
/** Field separator. Default ','. */
|
|
5
|
+
delimiter?: string;
|
|
6
|
+
/** Start the file with a UTF-8 byte order mark so Excel reads accents. Default true. */
|
|
7
|
+
bom?: boolean;
|
|
8
|
+
/** Save the file in the browser. Default true. */
|
|
9
|
+
download?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/** The table as CSV text. */
|
|
12
|
+
export declare function tableToCsv(table: TableLike, opts?: CsvExportOptions): string;
|
|
13
|
+
/** Export the table to a CSV file. Returns the file as a Blob. */
|
|
14
|
+
export declare function exportCsv(table: TableLike, opts?: CsvExportOptions): Promise<Blob>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Save a Blob as a file in the browser. Does nothing outside one. */
|
|
2
|
+
export declare function saveBlob(blob: Blob, fileName: string): void;
|
|
3
|
+
/** `name` with `ext` added unless it already ends with it. */
|
|
4
|
+
export declare function withExt(name: string | undefined, ext: string): string;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { exportCsv, tableToCsv, type CsvExportOptions } from './csv';
|
|
2
|
+
export { exportXlsx, tableToXlsxModel, sheetToXlsxModel, type XlsxExportOptions } from './xlsx';
|
|
3
|
+
export { buildXlsxParts, type XlsxCell, type XlsxModel } from './xlsx/ooxml';
|
|
4
|
+
export { exportPdf, sheetToPdfParams, type PdfTableExportOptions } from './pdf';
|
|
5
|
+
export type { PdfExportOptions, PdfFont, PdfPageSize } from './pdf/doc';
|
|
6
|
+
export { readTable, type CellStyle, type ColumnLike, type RowLike, type RowScope, type RowpineColumnMeta, type Sheet, type SheetColumn, type SheetRow, type TableLike, } from './table-source';
|
|
7
|
+
export { createPivotModel, filterCollapsedPivotRows, pivotAggregators, type PivotAggregator, type PivotAggregatorId, type PivotColumn, type PivotConfig, type PivotResult, type PivotRow, type PivotRowKind, type PivotValueConfig, } from './pivot/pivot';
|
|
8
|
+
export { createPivot, pivotAsTable, pivotRowStyle, pivotToTree, toTanStackColumns, type PivotColumnDef, type PivotColumnMeta, type PivotTable, type PivotTreeRow, type ToColumnsOptions, } from './pivot/tanstack';
|
|
9
|
+
export { getLicenseStatus, setLicenseKey, type LicensePayload, type LicenseStatus } from './license';
|
|
10
|
+
export { saveBlob } from './download';
|
|
11
|
+
export { ALL_AGGREGATORS, AGG_LABEL, EMPTY_LAYOUT, KIND_WELLS, WELL_LABEL, addToWell, applyLayoutFilters, clearWell, defaultLayoutFor, defaultWellFor, distinctValues, isFieldInLayout, layoutToConfig, pivotFromLayout, removeFromWell, setAggregatorAt, setFilterAllowed, toggleField, type PivotField, type PivotFilterChip, type PivotLayout, type PivotPreset, type PivotValueChip, type Well, } from './pivot/designer';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function q(e,n){if(typeof document>"u"||typeof URL>"u"||!URL.createObjectURL)return;let t=URL.createObjectURL(e),o=document.createElement("a");o.href=t,o.download=n,o.rel="noopener",o.style.display="none",document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(t),1e3)}function ne(e,n){let t=(e??"").trim()||"export";return t.toLowerCase().endsWith(`.${n}`)?t:`${t}.${n}`}function $t(e){return(e.getState?.()??e.store?.state??e.state)?.grouping??[]}function _t(e){return(e.getSortedRowModel?.()??e.getGroupedRowModel?.()??e.getFilteredRowModel?.()??e.getCoreRowModel()).rows}var Ft=new Set(["sum","mean","min","max"]);function ye(e){return e.columnDef.meta?.rowpine??{}}function Mt(e){let n=ye(e).header??(typeof e.columnDef.header=="string"?e.columnDef.header:e.id),t=[];for(let o=e.parent;o;o=o.parent){let r=typeof o.columnDef.header=="string"?o.columnDef.header:"";r&&t.unshift(r)}return[...t,n].join(" / ")}function It(e){let n=e.getStartVisibleLeafColumns??e.getLeftVisibleLeafColumns,t=e.getEndVisibleLeafColumns??e.getRightVisibleLeafColumns;if(n&&t&&e.getCenterVisibleLeafColumns){let o=n.call(e);return{columns:[...o,...e.getCenterVisibleLeafColumns(),...t.call(e)],frozen:o.length}}return{columns:e.getVisibleLeafColumns?.()??e.getAllLeafColumns(),frozen:0}}function Z(e,n={}){let t=It(e),o=t.columns.filter(l=>!ye(l).exclude),r=t.columns.slice(0,t.frozen).filter(l=>!ye(l).exclude).length,i=o.map(l=>{let h=ye(l),P=l.columnDef.aggregationFn;return{id:l.id,header:Mt(l),width:h.width??l.getSize?.()??150,align:h.align,numFmt:h.numFmt,format:h.format,cellStyle:h.cellStyle,subtotal:typeof P=="string"&&(Ft.has(P)||P==="auto")?P:void 0}}),s=new Set($t(e)),u=[],c=(l,h)=>{let P=l.getIsGrouped?.()??!1,L=i.map(k=>l.getValue(k.id)),N=i.map(k=>s.has(k.id)&&(P?k.id!==l.groupingColumnId:h>0)),x={kind:P?"group":"data",depth:h,values:L,blank:N,descendants:0,hasChildren:l.subRows.length>0,original:l.original,style:n.rowStyle?.(l.original)};if(P){let k=String(l.groupingValue??l.getValue(l.groupingColumnId??"")??""),S=i.findIndex(y=>y.id===l.groupingColumnId);S<0&&(S=0),x.labelAt=S,x.label=k,L[S]=k,L.forEach((y,R)=>{R!==S&&typeof y!="number"&&(x.blank[R]=!0)})}return x},m=(l,h)=>{let P=c(l,h);u.push(P);let L=0;for(let N of l.subRows)L+=m(N,h+1);return P.descendants=L,L+1},d=n.rows??"all";if(d==="all")for(let l of _t(e))m(l,0);else{let l=d==="page"?e.getRowModel().rows:e.getSelectedRowModel?.().rows??[];for(let h of l){if(d==="selected"&&h.getIsGrouped?.())continue;let P=c(h,d==="page"?h.depth:0);d==="selected"&&(P.blank=P.blank.map(()=>!1)),u.push(P)}}return{columns:i,rows:u,freezeColumns:r}}function Ve(e,n,t){return n==null||n===""?"":e.format?e.format(n,t):typeof n=="number"?Number.isFinite(n)?n.toLocaleString(void 0,{maximumFractionDigits:2}):"":n instanceof Date?Number.isNaN(n.getTime())?"":n.toLocaleDateString():typeof n=="boolean"?n?"Yes":"No":String(n)}function Xe(e,n,t){return e.align?e.align:typeof n.rows.find(r=>r.kind==="data"&&r.values[t]!=null)?.values[t]=="number"?"right":"left"}var de=e=>String(e).padStart(2,"0");function Dt(e){if(e==null)return"";if(e instanceof Date){if(Number.isNaN(e.getTime()))return"";let n=`${e.getFullYear()}-${de(e.getMonth()+1)}-${de(e.getDate())}`;return e.getHours()||e.getMinutes()||e.getSeconds()?`${n} ${de(e.getHours())}:${de(e.getMinutes())}:${de(e.getSeconds())}`:n}return typeof e=="number"?Number.isFinite(e)?String(e):"":String(e)}function We(e,n){let t=/^[=+\-@\t\r]/.test(e)&&!/^-?\d/.test(e)?`'${e}`:e;return t.includes(n)||/["\r\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function je(e,n={}){let t=Z(e,n),o=n.delimiter??",",r=[t.columns.map(i=>We(i.header,o)).join(o)];for(let i of t.rows)i.kind!=="group"&&r.push(i.values.map(s=>We(Dt(s),o)).join(o));return r.join(`\r
|
|
2
|
+
`)+`\r
|
|
3
|
+
`}async function Ot(e,n={}){let t=je(e,n),o=new Blob([n.bom??!0?"\uFEFF"+t:t],{type:"text/csv;charset=utf-8"});return(n.download??!0)&&q(o,ne(n.fileName,"csv")),o}import{verifyAsync as Nt}from"@noble/ed25519";var Ue="2026-11-14";var Et="943b6a3625ce15fa7fd62ee65897491f1d4f55fa5430cb253b6db9d0634e6cad",be="Exported with an unlicensed copy of Rowpine. https://rowpine.com/",Ke=null,Le=null,Ae=!1;function zt(e){Ke=e?.trim()||null,Le=null,Ae=!1}function Ge(e){let n=e.replace(/-/g,"+").replace(/_/g,"/")+"=".repeat((4-e.length%4)%4),t=atob(n),o=new Uint8Array(t.length);for(let r=0;r<t.length;r++)o[r]=t.charCodeAt(r);return o}function Bt(e){let n=new Uint8Array(e.length/2);for(let t=0;t<n.length;t++)n[t]=parseInt(e.slice(t*2,t*2+2),16);return n}async function Vt(e,n,t){if(!e)return{licensed:!1,reason:"missing",buildDate:t};let o=e.split(".");if(o.length!==3||o[0]!=="RP1")return{licensed:!1,reason:"malformed",buildDate:t};let r;try{r=JSON.parse(new TextDecoder().decode(Ge(o[1])))}catch{return{licensed:!1,reason:"malformed",buildDate:t}}let i=!1;try{i=await Nt(Ge(o[2]),new TextEncoder().encode(o[1]),Bt(n))}catch{i=!1}return!i||r.v!==1?{licensed:!1,reason:"invalid",buildDate:t}:t<=r.upd?{licensed:!0,payload:r,buildDate:t}:{licensed:!1,reason:"updates-ended",payload:r,buildDate:t}}function He(){return Le??=Vt(Ke,Et,Ue),Le}function Xt(e,n){let t="Get a key at https://rowpine.com/#pricing and pass it to setLicenseKey().";switch(e.reason){case"missing":return`Rowpine: ${n} is running without a license key. It works, and files carry a one-line notice. ${t}`;case"malformed":case"invalid":return`Rowpine: the license key passed to setLicenseKey() is not valid. ${t}`;case"updates-ended":return`Rowpine: this version was built on ${e.buildDate}, after the updates on your key ended (${e.payload?.upd}). Keep the version you have, or renew updates at https://rowpine.com/#pricing.`}}async function oe(e){let n=await He();return n.licensed?!0:(Ae||(Ae=!0,console.warn(Xt(n,e))),!1)}var Wt={"&":"&","<":"<",">":">",'"':""","'":"'"},jt=/[\x00-\x08\x0B\x0C\x0E-\x1F]/g;function j(e){return e.replace(jt,"").replace(/[&<>"']/g,n=>Wt[n])}function Y(e){let n=e,t="";do t=String.fromCharCode(65+n%26)+t,n=Math.floor(n/26)-1;while(n>=0);return t}function we(e){if(!e)return null;let n=/^#?([0-9a-f]{6})$/i.exec(e.trim());return n?"FF"+n[1].toUpperCase():null}function Ut(e){return(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())-Date.UTC(1899,11,30))/864e5}function Gt(e){if(e instanceof Date)return e;let n=String(e).trim(),t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(n);return t?new Date(Number(t[1]),Number(t[2])-1,Number(t[3])):new Date(n)}var Ye=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
4
|
+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/></Types>`,Kt=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
5
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>`;function Ht(e){return e.replace(/[\\/?*[\]:]/g," ").trim().slice(0,31)||"Sheet1"}function Yt(e){return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
6
|
+
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><sheets><sheet name="${j(Ht(e))}" sheetId="1" r:id="rId1"/></sheets></workbook>`}var qt=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
7
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/></Relationships>`;function Zt(e,n){let t=new Map,o=164,r=x=>{if(!x)return 0;let k=t.get(x);if(k!=null)return k;let S=o++;return t.set(x,S),S},i=['<font><sz val="11"/><name val="Calibri"/></font>','<font><b/><sz val="11"/><name val="Calibri"/></font>'],s=new Map,u=(x,k)=>{let S=we(k);if(!x&&!S)return 0;let y=`${x?"b":""}|${S??""}`,R=s.get(y);if(R!=null)return R;let F=i.length;return i.push(`<font>${x?"<b/>":""}<sz val="11"/><name val="Calibri"/>${S?`<color rgb="${S}"/>`:""}</font>`),s.set(y,F),F},c=['<fill><patternFill patternType="none"/></fill>','<fill><patternFill patternType="gray125"/></fill>'],m=new Map,d=x=>{let k=we(x);if(!k)return 0;let S=m.get(k);if(S!=null)return S;let y=c.length;return c.push(`<fill><patternFill patternType="solid"><fgColor rgb="${k}"/><bgColor indexed="64"/></patternFill></fill>`),m.set(k,y),y},l=['<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>','<xf numFmtId="0" fontId="1" fillId="0" borderId="0" xfId="0" applyFont="1"/>'],h=new Map,P=(x,k,S,y)=>{let R=`${x}|${k}|${S}|${y??""}`,F=h.get(R);if(F!=null)return F;let $=l.length,D=y&&y!=="left"?`<alignment horizontal="${y}"/>`:"";return l.push(`<xf numFmtId="${x}" fontId="${k}" fillId="${S}" borderId="0" xfId="0"${x?' applyNumberFormat="1"':""}${k?' applyFont="1"':""}${S?' applyFill="1"':""}${D?' applyAlignment="1"':""}>${D}</xf>`),h.set(R,$),$},L=x=>{let k=r(x.numFmt),S=u(x.bold===!0,x.color),y=d(x.fill);return k===0&&S===0&&y===0&&(!x.align||x.align==="left")?0:P(k,S,y,x.align)};for(let x of n)for(let k of x)L(k);return{styleIndexOf:L,build:()=>`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
8
|
+
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">`+(t.size>0?`<numFmts count="${t.size}">${[...t.entries()].map(([k,S])=>`<numFmt numFmtId="${S}" formatCode="${j(k)}"/>`).join("")}</numFmts>`:"")+`<fonts count="${i.length}">${i.join("")}</fonts><fills count="${c.length}">${c.join("")}</fills><borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders><cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs><cellXfs count="${l.length}">${l.join("")}</cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles></styleSheet>`}}function $e(e){let{header:n,rows:t}=e,o=Zt(n,t),r=[],s=[`<row r="1">${n.map((y,R)=>`<c r="${Y(R)}1" s="1" t="inlineStr"><is><t xml:space="preserve">${j(y)}</t></is></c>`).join("")}</row>`];for(let y=0;y<t.length;y++){let R=y+2,F=t[y],$=[];for(let E=0;E<F.length;E++){let T=F[E],M=`${Y(E)}${R}`,J=o.styleIndexOf(T),I=J?` s="${J}"`:"";if(T.link&&r.push({ref:M,url:T.link,id:`rId${r.length+1}`}),T.formula){let V=T.value==null||T.value===""?"":T.t==="n"?`<v>${Number(T.value)}</v>`:"";$.push(`<c r="${M}"${I}><f>${j(T.formula)}</f>${V}</c>`)}else if(T.value==null||T.value==="")$.push(`<c r="${M}"${I}/>`);else if(T.t==="n")$.push(`<c r="${M}"${I}><v>${Number(T.value)}</v></c>`);else if(T.t==="d"){let V=Gt(T.value);$.push(`<c r="${M}"${I}><v>${Ut(V)}</v></c>`)}else T.t==="b"?$.push(`<c r="${M}"${I} t="b"><v>${T.value?1:0}</v></c>`):$.push(`<c r="${M}"${I} t="inlineStr"><is><t xml:space="preserve">${j(String(T.value))}</t></is></c>`)}let D=Math.max(0,Math.min(7,Math.floor(e.outline?.[y]??0)));s.push(`<row r="${R}"${D?` outlineLevel="${D}"`:""}>${$.join("")}</row>`)}let u=Math.max(0,...(e.outline??[]).map(y=>Math.min(7,Math.floor(y))));e.notes?.length&&!e.table&&e.notes.forEach((y,R)=>{let F=t.length+3+R;s.push(`<row r="${F}"><c r="A${F}" t="inlineStr"><is><t xml:space="preserve">${j(y)}</t></is></c></row>`)});let c=e.widths?`<cols>${e.widths.map((y,R)=>`<col min="${R+1}" max="${R+1}" width="${Math.max(4,Math.round(y/7*100)/100)}" customWidth="1"/>`).join("")}</cols>`:"",m=Math.max(0,Math.floor(e.freezeColumns??0)),d=e.freezeHeader?1:0,l='<sheetView workbookViewId="0"/>';if(d>0||m>0){let y=`${Y(m)}${d+1}`,R=m>0&&d>0?"bottomRight":m>0?"topRight":"bottomLeft";l=`<sheetView workbookViewId="0"><pane${m>0?` xSplit="${m}"`:""}${d>0?` ySplit="${d}"`:""} topLeftCell="${y}" activePane="${R}" state="frozen"/><selection pane="${R}" activeCell="${y}" sqref="${y}"/></sheetView>`}let h=t.length>0?(e.condFormats??[]).map((y,R)=>{let F=Y(y.colIdx),$=`${F}2:${F}${t.length+1}`;if(y.kind==="dataBar"){let M=we(y.color)??"FF638EC6";return`<conditionalFormatting sqref="${$}"><cfRule type="dataBar" priority="${R+1}"><dataBar><cfvo type="min"/><cfvo type="max"/><color rgb="${M}"/></dataBar></cfRule></conditionalFormatting>`}let D=y.colors.map(M=>we(M)??"FFFFFFFF"),E=D.length>=3?'<cfvo type="min"/><cfvo type="percentile" val="50"/><cfvo type="max"/>':'<cfvo type="min"/><cfvo type="max"/>',T=D.map(M=>`<color rgb="${M}"/>`).join("");return`<conditionalFormatting sqref="${$}"><cfRule type="colorScale" priority="${R+1}"><colorScale>${E}${T}</colorScale></cfRule></conditionalFormatting>`}).join(""):"",P=r.length?`<hyperlinks>${r.map(y=>`<hyperlink ref="${y.ref}" r:id="${y.id}"/>`).join("")}</hyperlinks>`:"",L="",N="",x="";if(e.table&&n.length>0){let y=e.table,R=new Set,F=n.map((I,V)=>{let O=(I??"").trim()||`Column${V+1}`,X=O,H=1;for(;R.has(X.toLowerCase());)X=`${O}${++H}`;return R.add(X.toLowerCase()),X}),$=Y(n.length-1),D=t.length+1,E=D+1,T=y.totalsRow&&t.length>0,M=y.totalsFns.findIndex(I=>!I);if(T){let I=n.map((V,O)=>{let X=`${Y(O)}${E}`,H=y.totalsFns[O];if(H){let U=0;for(let Q of t){let ae=Q[O];ae?.t==="n"&&typeof ae.value=="number"&&(U+=ae.value)}let se=t.find(Q=>Q[O]?.t==="n")?.[O]?.numFmt,W=o.styleIndexOf({t:"n",value:U,numFmt:se,bold:!0}),G=H==="average"?101:H==="count"?103:109,Pe=H==="count"?t.length:U;return`<c r="${X}"${W?` s="${W}"`:""}><f>SUBTOTAL(${G},${y.name}[${j(F[O])}])</f><v>${Pe}</v></c>`}if(O===M){let U=o.styleIndexOf({t:"s",value:"Total",bold:!0});return`<c r="${X}"${U?` s="${U}"`:""} t="inlineStr"><is><t>Total</t></is></c>`}return`<c r="${X}"/>`});s.push(`<row r="${E}">${I.join("")}</row>`)}let J=F.map((I,V)=>{let O=T?y.totalsFns[V]:void 0,X=T?O?` totalsRowFunction="${O}"`:V===M?' totalsRowLabel="Total"':"":"";return`<tableColumn id="${V+1}" name="${j(I)}"${X}/>`}).join("");L=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
9
|
+
<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" id="1" name="${j(y.name)}" displayName="${j(y.name)}" ref="A1:${$}${T?E:D}"${T?' totalsRowCount="1"':' totalsRowShown="0"'}><autoFilter ref="A1:${$}${D}"/><tableColumns count="${n.length}">${J}</tableColumns><tableStyleInfo name="${j(y.style??"TableStyleMedium2")}" showFirstColumn="0" showLastColumn="0" showRowStripes="1" showColumnStripes="0"/></table>`,x=`rId${r.length+1}`,N=`<tableParts count="1"><tablePart r:id="${x}"/></tableParts>`}let k=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
10
|
+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">`+(u>0?'<sheetPr><outlinePr summaryBelow="0"/></sheetPr>':"")+`<sheetViews>${l}</sheetViews><sheetFormatPr defaultRowHeight="15"${u>0?` outlineLevelRow="${u}"`:""}/>`+c+`<sheetData>${s.join("")}</sheetData>`+h+P+N+"</worksheet>",S={"[Content_Types].xml":L?Ye.replace("</Types>",'<Override PartName="/xl/tables/table1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"/></Types>'):Ye,"_rels/.rels":Kt,"xl/workbook.xml":Yt(e.sheetName),"xl/_rels/workbook.xml.rels":qt,"xl/styles.xml":o.build(),"xl/worksheets/sheet1.xml":k};if(L&&(S["xl/tables/table1.xml"]=L),r.length||x){let y=r.map(R=>`<Relationship Id="${R.id}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="${j(R.url)}" TargetMode="External"/>`);x&&y.push(`<Relationship Id="${x}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/table" Target="../tables/table1.xml"/>`),S["xl/worksheets/_rels/sheet1.xml.rels"]=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
11
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">`+y.join("")+"</Relationships>"}return S}async function qe(e,n){let t=new n;for(let[o,r]of Object.entries(e))t.file(o,r);return t.generateAsync({type:"blob",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})}var Jt={sum:9,mean:1,min:5,max:4};function Qt(e,n){return n==null||n===""?{t:"s",value:""}:typeof n=="number"?Number.isFinite(n)?{t:"n",value:n,numFmt:e.numFmt}:{t:"s",value:""}:n instanceof Date?Number.isNaN(n.getTime())?{t:"s",value:""}:{t:"d",value:n,numFmt:e.numFmt??"yyyy-mm-dd"}:typeof n=="boolean"?{t:"b",value:n}:{t:"s",value:String(n)}}function Ze(e,n={},t){let o=n.groupFill??"#eef2f0",r=e.rows.map((i,s)=>{let u=s+2;return e.columns.map((c,m)=>{if(i.blank[m])return{t:"s",value:"",fill:i.kind==="group"?o:void 0};let d=i.values[m],l=Qt(c,d);if(i.kind==="group"){l.bold=!0,l.fill=o;let h=c.subtotal==="auto"?typeof d=="number"?"sum":void 0:c.subtotal;if(h&&m!==i.labelAt&&typeof d=="number"&&i.descendants>0){let P=Y(m);l.formula=`SUBTOTAL(${Jt[h]},${P}${u+1}:${P}${u+i.descendants})`}}else{let h=c.cellStyle?.(d,i.original);h&&Object.assign(l,{fill:h.fill,color:h.color,bold:h.bold})}return i.style&&(i.style.bold&&(l.bold=!0),i.style.fill&&(l.fill=i.style.fill),i.style.color&&(l.color=i.style.color)),i.hasChildren&&i.kind==="data"&&(l.bold=!0),c.align&&c.align!=="left"&&(l.align=c.align),l})});return{sheetName:n.sheetName??"Sheet1",header:e.columns.map(i=>i.header),rows:r,widths:e.columns.map(i=>i.width),freezeHeader:!0,freezeColumns:e.freezeColumns,outline:e.rows.map(i=>i.depth),notes:t}}function Je(e,n={},t){return Ze(Z(e,n),n,t)}async function en(e,n={}){let t=await oe("Excel export"),o=Je(e,n,t?void 0:[be]),{default:r}=await import("jszip"),i=await qe($e(o),r);return(n.download??!0)&&q(i,ne(n.fileName,"xlsx")),i}function tn(e){let n=r=>!!r&&typeof r=="object"&&Object.keys(r).some(i=>/\.(ttf|otf)$/i.test(i))&&Object.values(r).every(i=>typeof i=="string"),t=new Set,o=r=>{if(!r||typeof r!="object"||t.has(r))return null;if(t.add(r),n(r))return r;let i=r;return o(i.pdfMake?.vfs)??o(i.vfs)??o(i.default)};return o(e)}function tt(e){return new Promise((n,t)=>{let o=e.getBlob(n);o&&typeof o.then=="function"&&o.then(n,t)})}function nt(e,n){let t=tn(n);return t?(typeof e.addVirtualFileSystem=="function"&&e.addVirtualFileSystem(t),e.vfs=t,!0):!1}var nn={normal:"Roboto-Regular.ttf",bold:"Roboto-Medium.ttf",italics:"Roboto-Italic.ttf",bolditalics:"Roboto-MediumItalic.ttf"};function ot(e,n){let t={},o=m=>/^(https?:|blob:|data:|\/|\.\.?\/)/i.test(m),r=(m,d)=>{if(!d)return;if(o(d))return d;let l=`rowpine-${n.name}-${m}.ttf`;return t[l]=d,l},i=r("normal",n.normal),s=r("bold",n.bold)??i,u={normal:i,bold:s,italics:r("italics",n.italics)??i,bolditalics:r("bolditalics",n.bolditalics)??s};if(Object.keys(t).length){let m={...e.vfs??{},...t};typeof e.addVirtualFileSystem=="function"&&e.addVirtualFileSystem(m),e.vfs=m}let c={Roboto:nn,...e.fonts??{},[n.name]:u};typeof e.addFonts=="function"&&e.addFonts(c),e.fonts=c}var on={A4:[595.28,841.89],A3:[841.89,1190.55],A5:[419.53,595.28],LETTER:[612,792],LEGAL:[612,1008]},_e="#dc2626",Qe="#d97706",rn="#eab308",Fe="#16a34a",re=(e,n)=>({type:"polyline",points:e,closePath:!0,lineWidth:.1,lineColor:n,color:n}),Me=e=>[{x:e/2,y:0},{x:e,y:e*.5},{x:e*.68,y:e*.5},{x:e*.68,y:e},{x:e*.32,y:e},{x:e*.32,y:e*.5},{x:0,y:e*.5}],et={"\u2191":e=>[re(Me(e),Fe)],"\u2193":e=>[re(Me(e).map(n=>({x:n.x,y:e-n.y})),_e)],"\u2192":e=>[re(Me(e).map(n=>({x:e-n.y,y:n.x})),Qe)],"\u25B2":e=>[re([{x:0,y:e},{x:e/2,y:0},{x:e,y:e}],Fe)],"\u25BC":e=>[re([{x:0,y:0},{x:e,y:0},{x:e/2,y:e}],_e)],"\u25C6":e=>[re([{x:e/2,y:0},{x:e,y:e/2},{x:e/2,y:e},{x:0,y:e/2}],Qe)],"\u{1F534}":e=>[{type:"ellipse",x:e/2,y:e/2,r1:e/2,r2:e/2,color:_e}],"\u{1F7E1}":e=>[{type:"ellipse",x:e/2,y:e/2,r1:e/2,r2:e/2,color:rn}],"\u{1F7E2}":e=>[{type:"ellipse",x:e/2,y:e/2,r1:e/2,r2:e/2,color:Fe}],"\u2713":e=>[{type:"polyline",points:[{x:0,y:e*.55},{x:e*.38,y:e*.92},{x:e,y:e*.08}],lineWidth:Math.max(1,e*.16),lineColor:"#334155"}]};function ln(e){let{columns:n}=e,t=e.opts??{},o=e.styles??{},r=e.theme??{},i=e.now??new Date(0),s=t.fontSize??8,u=t.headerColor??o.headerRow?.backgroundColor??r.headerColor??"#334155",c=t.headerTextColor??o.headerRow?.color??r.headerTextColor??"#ffffff",m=t.zebra??!0,d=t.zebraColor??o.rowAlternate?.backgroundColor??r.zebraColor??"#f1f5f9",l=t.groupColor??r.groupColor??"#e2e8f0",h=t.groupTextColor??r.groupTextColor??"#0f172a",P=t.subtotalColor??r.subtotalColor??"#f8fafc",L=t.textColor??o.rows?.color??r.textColor,N=t.borderColor??r.borderColor??"#e2e8f0",x=t.repeatHeader??!0,k=a=>a==="bold"||typeof a=="number"&&a>=600,S=a=>{if(a===void 0)return;let f=typeof a=="number"?a:parseFloat(a);return Number.isFinite(f)&&f>0?f:void 0},y=(a,f)=>{if(!f)return;f.backgroundColor&&(a.fillColor=f.backgroundColor),f.color&&(a.color=f.color),k(f.fontWeight)?a.bold=!0:f.fontWeight==="normal"&&(a.bold=!1),f.fontStyle==="italic"&&(a.italics=!0);let p=S(f.fontSize);p&&(a.fontSize=p),f.textAlign&&(a.alignment=f.textAlign)},R=new Map;for(let[a,f]of Object.entries(o.cells??{})){let p=/^([A-Z]+)(\d+)$/i.exec(a.trim());if(!p)continue;let g=0;for(let C of p[1].toUpperCase())g=g*26+(C.charCodeAt(0)-64);R.set(`${Number(p[2])-1}:${g-1}`,f)}let F=t.pageOrientation??(n.length>(t.autoLandscapeThreshold??8)?"landscape":"portrait"),$=t.margins??[28,34,28,34],[D,E]=on[t.pageSize??"A4"],T=(F==="landscape"?E:D)-$[0]-$[2],M=(F==="landscape"?D:E)-$[1]-$[3],J=n.map((a,f)=>{let p={text:a.header,bold:!0,alignment:a.align??"left",color:c,fillColor:u};return y(p,o.headerRow?{...o.headerRow,backgroundColor:void 0,color:void 0}:void 0),y(p,R.get(`0:${f}`)),p}),I=e.body??(e.rows??[]).map(a=>({kind:"data",cells:a})),V=e.dataCellStyle,O=e.dataCellLink,X=0,H=new Set,U=new Set,se=[],W=[J];if(I.forEach((a,f)=>{let p=f+1;if(a.kind==="group"){let g={text:a.label,bold:!0,color:h,fillColor:l,colSpan:n.length,margin:[(a.level??0)*12,2,0,2]},C=Array.from({length:Math.max(0,n.length-1)},()=>({text:""}));U.add(p),W.push([g,...C])}else if(a.kind==="subtotal")W.push(n.map((g,C)=>({text:a.cells[C]??"",bold:!0,alignment:g.align??"left",fillColor:P})));else{H.add(p);let g=X++;W.push(n.map((C,v)=>{let b={text:a.cells[v]??"",alignment:C.align??"left"};L&&(b.color=L),y(b,o.rows?{...o.rows,backgroundColor:void 0}:void 0),m&&g%2===1&&o.rowAlternate?.color&&(b.color=o.rowAlternate.color),y(b,R.get(`${g+1}:${v}`));let w=V?.(g,v);w&&(w.fill&&(b.fillColor=w.fill),w.color&&(b.color=w.color),w.bold&&(b.bold=!0),w.icon&&w.iconOnly&&(b.text=""),w.icon&&et[w.icon]?se.push([p,v,w.icon]):w.icon&&(b.text=w.iconOnly?w.icon:`${w.icon} ${b.text??""}`));let A=O?.(g,v);return A&&(b.link=A,b.decoration="underline",w?.color||(b.color="#2563eb")),b}))}}),e.merges?.length&&!e.body){let a=[...H].sort((f,p)=>f-p);for(let f of e.merges){let p=Math.max(1,Math.floor(f.rowSpan??1)),g=Math.max(1,Math.floor(f.colSpan??1));if(p===1&&g===1)continue;let C=a[f.row];if(C===void 0||f.col<0||f.col>=n.length)continue;let v=W[C]?.[f.col];if(v){p>1&&(v.rowSpan=Math.min(p,W.length-C)),g>1&&(v.colSpan=Math.min(g,n.length-f.col));for(let b=0;b<(v.rowSpan??1);b+=1)for(let w=0;w<(v.colSpan??1);w+=1){if(b===0&&w===0)continue;let A=W[C+b]?.[f.col+w];A&&(A.text="")}}}}let G=n.length,Pe=10.5,Q=a=>a?.62:.56,ae=new Set(se.map(([a,f])=>`${a}:${f}`)),fe=new Array(G).fill(0),ke=new Array(G).fill(0);W.forEach((a,f)=>{U.has(f)||a.forEach((p,g)=>{if((p.colSpan??1)>1||g>=G)return;let C=Q(p.bold)*(p.fontSize??s)/s,v=ae.has(`${f}:${g}`)?2:0,b=0,w=0;for(let A of(p.text??"").split(`
|
|
12
|
+
`)){w=Math.max(w,A.length);for(let _ of A.split(/\s+/))b=Math.max(b,_.length)}fe[g]=Math.max(fe[g],(Math.min(b,28)+v)*C),ke[g]=Math.max(ke[g],(w+v)*C)})});let ue=a=>T-a*Pe-2,Ce=(a,f)=>a.reduce((p,g)=>p+Math.max(fe[g]*f,f),0),ee=t.fit??"auto",te=Array.isArray(t.columnWidths)?t.columnWidths:null,pe=n.map((a,f)=>f),z=s,me=[pe];if(ee!=="none"&&!te&&G>0&&Ce(pe,s)>ue(G)){let a=ue(G),f=a>0?s*a/Ce(pe,s):0,p=ee==="shrink"?4:Math.max(5,s*.75);if(ee!=="split"&&f>=p)z=Math.floor(f*10)/10;else if(ee==="shrink")z=p;else{let g=Math.max(0,Math.min(t.repeatColumns??1,G-1)),C=pe.slice(0,g);me=[];let v=[];for(let b=g;b<G;b++)v.length&&Ce([...C,...v,b],s)>ue(C.length+v.length+1)&&(me.push([...C,...v]),v=[]),v.push(b);v.length&&me.push([...C,...v])}}let kt=a=>{if(te){let w=te.filter(_=>typeof _=="number").reduce((_,B)=>_+B,0),A=ue(te.length);return w>A&&ee!=="none"?te.map(_=>typeof _=="number"?Math.floor(_*A/w):_):te}if(ee==="none")return a.map(()=>t.columnWidths==="auto"?"auto":"*");let f=a.map(b=>Math.max(fe[b]*z,z)),p=a.map((b,w)=>Math.max(f[w],ke[b]*z)),g=ue(a.length),C=p.reduce((b,w)=>b+w,0),v;if(t.columnWidths==="auto"&&C<=g)v=p;else if(C<=g)v=p.map(b=>b+(g-C)/a.length);else{let b=f.reduce((_,B)=>_+B,0),w=Math.max(0,g-b),A=p.reduce((_,B,Te)=>_+(B-f[Te]),0);v=f.map((_,B)=>_+(A>0?w*(p[B]-_)/A:w/a.length))}return v.map(b=>Math.floor(b*100)/100)},Ct=z*1.25,ze=(a,f,p)=>{let g=0;return f.forEach((C,v)=>{let b=a[C],w=p[v];if(!b||(b.rowSpan??1)>1||typeof w!="number")return;let A=Q(b.bold)*(b.fontSize??z),_=0;for(let B of(b.text??"").split(`
|
|
13
|
+
`))_+=Math.max(1,Math.ceil(B.length*A/Math.max(w,1)));g=Math.max(g,_*Ct*((b.fontSize??z)/z))}),g+6};for(let[a,f,p]of se){let g=W[a]?.[f];if(!g)continue;let C=z*.8,{text:v,alignment:b,color:w,bold:A,italics:_,fontSize:B,link:Te,decoration:Lt}=g;delete g.text;let ge={width:C+3,canvas:et[p](C),margin:[0,z*.2,0,0]},he={width:"*",text:""};g.columns=v?[ge,{width:"*",text:v,alignment:b,color:w,bold:A,italics:_,fontSize:B,link:Te,decoration:Lt}]:b==="center"?[he,ge,he]:b==="right"?[he,ge]:[ge,he],g.columnGap=0;for(let At of["alignment","color","bold","italics","fontSize","link","decoration"])delete g[At]}let Rt=(a,f,p)=>p.length===G&&p.every((g,C)=>g===C)?a:U.has(f)?[{...a[0],colSpan:p.length},...p.slice(1).map(()=>({text:""}))]:p.map((g,C)=>{let v=a[g],b=v.colSpan??1;if(b<=1)return v;let w=1;for(;w<b&&p[C+w]===g+w;)w+=1;return{...v,colSpan:w}}),St={kind:"table",stripes:m?[...H].filter(a=>a>0&&a%2===0):[],zebraColor:d,lineColor:N},Tt=me.map((a,f)=>{let p=kt(a),g=W.map((w,A)=>Rt(w,A,a)),C=x?ze(g[0],a.map((w,A)=>A),p):0,v=M-C,b=g.some((w,A)=>A>0&&!U.has(A)&&ze(w,a.map((_,B)=>B),p)>v*.7);return{...f>0?{pageBreak:"before"}:{},...z!==s?{fontSize:z}:{},table:{headerRows:x?1:0,dontBreakRows:!b,widths:p,body:g},rpLayout:St}}),Be=(a,f)=>(a??[]).map(p=>{if("image"in p)return{image:p.image,...p.width?{width:p.width}:{},...p.height?{height:p.height}:{},margin:f};if("text"in p){let g={text:p.text};return y(g,p.style),{...g,margin:f}}return{columns:[{text:p.left??"",alignment:"left"},{text:p.center??"",alignment:"center"},{text:p.right??"",alignment:"right"}],margin:f}}),K=[];if(K.push(...Be(e.headerLines,[0,0,0,4])),t.logo&&K.push({image:t.logo,width:t.logoWidth??90,margin:[0,0,0,8]}),t.title&&K.push({text:t.title,fontSize:s+8,bold:!0,margin:[0,0,0,2]}),t.subtitle&&K.push({text:t.subtitle,fontSize:s+1,color:"#64748b",margin:[0,0,0,8]}),t.kpis?.length){let a=t.kpiColor??"#f8fafc";K.push({table:{widths:t.kpis.map(()=>"*"),body:[t.kpis.map(f=>({fillColor:a,margin:[8,6,8,6],stack:[{text:f.label,fontSize:s,color:"#64748b"},{text:f.value,fontSize:s+10,bold:!0,margin:[0,2,0,0]},...f.delta?[{text:f.delta,fontSize:s,color:f.color??"#64748b",margin:[0,2,0,0]}]:[]]}))]},rpLayout:{kind:"kpi"},margin:[0,0,0,10]})}let Re=(e.charts??(t.charts??[]).filter(a=>"image"in a)).map(a=>({stack:[...a.title?[{text:a.title,fontSize:s+3,bold:!0,margin:[0,0,0,4]}]:[],{image:a.image,width:Math.min(a.width??T,T)},...a.caption?[{text:a.caption,fontSize:s,color:"#64748b",margin:[0,3,0,0]}]:[]],margin:[0,0,0,12],unbreakable:!0}));t.chartsPosition!=="below"&&K.push(...Re),K.push(...Tt),t.chartsPosition==="below"&&(Re.length&&K.push({text:"",margin:[0,0,0,12]}),K.push(...Re)),K.push(...Be(e.footerLines,[0,4,0,0]));let Se={pageSize:t.pageSize??"A4",pageOrientation:F,pageMargins:$,defaultStyle:t.font?{fontSize:s,font:t.font.name}:{fontSize:s},content:K,info:{...t.title?{title:t.title}:{},...t.author?{author:t.author}:{},...t.subtitle?{subject:t.subtitle}:{},creator:"Rowpine",creationDate:i}};if(t.watermark){let a=typeof t.watermark=="string"?{text:t.watermark}:t.watermark;Se.watermark={text:a.text,color:a.color??"#94a3b8",opacity:a.opacity??.15,bold:!0}}if(t.showPageNumbers??!0){let a=g=>String(g).padStart(2,"0"),f=t.labels?.date?.(i)??`${i.getFullYear()}-${a(i.getMonth()+1)}-${a(i.getDate())}`,p="Page {page} of {pages}";if(t.labels?.page){let g=t.labels.page(Ie,De);g.includes(String(Ie))&&g.includes(String(De))&&(p=g.split(String(Ie)).join("{page}").split(String(De)).join("{pages}"))}Se.rpFooter={margin:[$[0],6,$[2],0],date:f,page:p}}return Se}var Ie=86421,De=97531;function rt(e){return sn(ln(e),{page:e.opts?.labels?.page})}function sn(e,n={}){let t=i=>{if(Array.isArray(i)){i.forEach(t);return}if(!i||typeof i!="object")return;let s=i;s.rpLayout&&(s.layout=an(s.rpLayout)),s.stack&&t(s.stack)};t(e.content);let o=e,r=e.rpFooter;if(r){let i=n.page??((s,u)=>r.page.split("{page}").join(String(s)).split("{pages}").join(String(u)));o.footer=(s,u)=>({margin:r.margin,columns:[{text:r.date,alignment:"left",fontSize:7,color:"#94a3b8"},{text:i(s,u),alignment:"right",fontSize:7,color:"#94a3b8"}]})}return o}function an(e){if(e.kind==="kpi")return{hLineWidth:()=>0,vLineWidth:()=>4,vLineColor:()=>"#ffffff",paddingLeft:()=>0,paddingRight:()=>0,paddingTop:()=>0,paddingBottom:()=>0};let n=new Set(e.stripes);return{fillColor:t=>n.has(t)?e.zebraColor:null,hLineWidth:()=>.5,vLineWidth:()=>.5,hLineColor:()=>e.lineColor,vLineColor:()=>e.lineColor,paddingTop:()=>3,paddingBottom:()=>3,paddingLeft:()=>5,paddingRight:()=>5}}function lt(e,n={},t,o=new Date){let r=e.columns.map((u,c)=>({header:u.header,align:Xe(u,e,c)})),i=[],s=[];for(let u of e.rows){let c=e.columns.map((m,d)=>{if(u.blank[d])return"";let l=u.kind==="group"&&d===u.labelAt?u.label??"":Ve(m,u.values[d],u.original);return d===0&&u.depth>0?`${" ".repeat(u.depth)}${l}`:l});u.kind==="group"||u.hasChildren||u.style?.bold?i.push({kind:"subtotal",cells:c}):(i.push({kind:"data",cells:c}),s.push(m=>{let d=e.columns[m].cellStyle?.(u.values[m],u.original);return d||u.style?{...u.style,...d}:void 0}))}return{columns:r,body:i,dataCellStyle:(u,c)=>s[u]?.(c),opts:{grandTotal:!1,...n},footerLines:t?.map(u=>({text:u,style:{color:"#64748b",fontSize:7}})),now:o}}var it=null;function un(){return it??=(async()=>{let e=await import("pdfmake/build/pdfmake"),n=await import("pdfmake/build/vfs_fonts"),t=e.default??e;if(!nt(t,n))throw new Error('rowpine: "pdfmake/build/vfs_fonts" did not contain a font map; this pdfmake version is not supported.');return t})(),it}async function dn(e,n={}){let t=await oe("PDF export"),o=lt(Z(e,n),n,t?void 0:[be]),r=await un();n.font&&ot(r,n.font);let i=await tt(r.createPdf(rt(o)));return(n.download??!0)&&q(i,ne(n.fileName,"pdf")),i}function st(e,n=-1/0){let t=n;for(let o of e){if(o!==o)return NaN;o>t&&(t=o)}return t}function at(e,n=1/0){let t=n;for(let o of e){if(o!==o)return NaN;o<t&&(t=o)}return t}var ie=e=>e.map(n=>typeof n=="number"?n:Number(n)).filter(n=>!Number.isNaN(n)),ct={sum:e=>ie(e).reduce((n,t)=>n+t,0),avg:e=>{let n=ie(e);return n.length===0?null:n.reduce((t,o)=>t+o,0)/n.length},min:e=>ie(e).length===0?null:at(ie(e)),max:e=>ie(e).length===0?null:st(ie(e)),count:e=>e.length,countDistinct:e=>new Set(e).size,first:e=>e[0]??null,last:e=>e[e.length-1]??null};function ut(e){if(typeof e=="function")return e;let n=ct[e];if(!n)throw new Error(`pivot: unknown aggregator '${String(e)}'`);return n}function cn(e,n){return e===n?0:e==null?-1:n==null?1:typeof e=="number"&&typeof n=="number"?e-n:String(e).localeCompare(String(n),void 0,{numeric:!0})}function dt(e,n,t){let o={level:0,value:null,path:[],pathKey:"__root",children:new Map,rows:e};for(let r of e){let i=o;for(let s=0;s<n.length;s+=1){let u=n[s],c=r[u],m=`${s}:${c===null?"__null":String(c)}`,d=i.children.get(m);d||(d={level:s+1,value:c,path:[...i.path,c],pathKey:i.pathKey==="__root"?m:`${i.pathKey}|${m}`,children:new Map,rows:[]},i.children.set(m,d)),d.rows.push(r),i=d}}return ft(o,t),o}function ft(e,n){let t=Array.from(e.children.entries());t.sort(([,o],[,r])=>(n??cn)(o.value,r.value,o.level-1)),e.children=new Map(t);for(let o of e.children.values())ft(o,n)}function le(e,n){return`pv__${e.length===0?"all":e.map(o=>fn(o)).join("__")}__m${n}`}function fn(e){return e==null?"null":String(e).replace(/[^a-zA-Z0-9_-]/g,"_")}function pn(e,n,t,o){let r={id:"__pivotRowHeader",header:o,width:240,isRowHeader:!0};function i(d){return d.children.size===0?n.map((l,h)=>{let P=le(d.path,h),L=l.label??`${l.field} (${typeof l.agg=="function"?"custom":l.agg})`;return{id:P,header:L,measure:h,format:l.format,width:130}}):Array.from(d.children.values()).map(l=>({id:`pv_group_${l.pathKey}`,header:String(l.value??"(blank)"),columns:i(l)}))}let s=(e.children.size===0,i(e));if(!(t.grandTotalCol!==!1&&e.children.size>0))return[r,...s];let m={id:"pv_group__grand_total",header:"Total",columns:n.map((d,l)=>{let h=le(["__total"],l),P=d.label??`${d.field} (${typeof d.agg=="function"?"custom":d.agg})`;return{id:h,header:P,measure:l,format:d.format,width:140,isTotal:!0}}),isTotal:!0};return[r,...s,m]}function pt(e,n){if(e.children.size===0){n.push(e.path);return}for(let t of e.children.values())pt(t,n)}function xe(e,n,t,o,r){let i={},s=new Map,u=c=>{let m=s.get(c.length);if(!m){m=new Map;for(let l of e){let h=m;for(let N=0;N<c.length-1;N+=1){let x=l[t[N]],k=h.get(x);k||h.set(x,k=new Map),h=k}let P=l[t[c.length-1]],L=h.get(P);L?L.push(l):h.set(P,[l])}s.set(c.length,m)}let d=m;for(let l of c)if(d=d.get(l),d===void 0)return[];return d};for(let c of n){let m=c.length===0?e:u(c);for(let d=0;d<o.length;d+=1){let l=o[d],h=ut(l.agg),P=le(c,d);i[P]=m.length===0?null:h(m.map(L=>L[l.field]))}}if(r)for(let c=0;c<o.length;c+=1){let m=o[c],d=ut(m.agg),l=le(["__total"],c);i[l]=d(e.map(h=>h[m.field]))}return i}function mn(e,n,t){let o={};for(let r of e)for(let i=0;i<n.length;i+=1)o[le(r,i)]=null;if(t)for(let r=0;r<n.length;r+=1)o[le(["__total"],r)]=null;return o}function mt(e,n,t,o,r,i,s,u){let c=i.grandTotalCol!==!1,m=i.rowSubtotals!==!1;if(e.children.size===0){n.push({__pivotId:`row__${e.pathKey}`,__pivotKind:"leaf",__pivotDepth:e.level,__pivotLabel:e.value===null?"(All)":String(e.value),__pivotParentId:u,__pivotExpandable:!1,...xe(e.rows,t,o,r,c)});return}let d=e.level>0&&e.level<s.length,l=u;if(d){let h=`group__${e.pathKey}`;n.push({__pivotId:h,__pivotKind:"group",__pivotDepth:e.level,__pivotLabel:String(e.value??"(All)"),__pivotParentId:u,__pivotExpandable:!0,...m?xe(e.rows,t,o,r,c):mn(t,r,c)}),l=h}for(let h of e.children.values())mt(h,n,t,o,r,i,s,l)}function Oe(e,n){if(n.values.length===0)throw new Error("pivot: at least one value config is required");let t=n.rows,o=n.cols,r=n.values,i=dt(e,t,n.rowSort),s=dt(e,o,n.colSort),u=[];pt(s,u);let c=[];t.length===0?c.push({__pivotId:"row__all",__pivotKind:"leaf",__pivotDepth:0,__pivotLabel:"(All)",__pivotParentId:null,__pivotExpandable:!1,...xe(e,u,o,r,n.grandTotalCol!==!1)}):mt(i,c,u,o,r,n,t,null),n.grandTotalRow!==!1&&c.push({__pivotId:"row__grand_total",__pivotKind:"grandTotal",__pivotDepth:0,__pivotLabel:"Grand total",__pivotParentId:null,__pivotExpandable:!1,...xe(e,u,o,r,n.grandTotalCol!==!1)});let m=pn(s,r,n,t.length>0?t.join(" / "):"");return{rows:c,columns:m}}var gn={...ct};function hn(e,n){if(n===!0)return e.slice();let t=n instanceof Set?n:new Set(n),o=new Map;for(let i of e)o.set(i.__pivotId,i.__pivotParentId);let r=[];for(let i of e){if(i.__pivotParentId===null){r.push(i);continue}let s=i.__pivotParentId,u=!0;for(;s!==null;){if(!t.has(s)){u=!1;break}s=o.get(s)??null}u&&r.push(i)}return r}function gt(e){let n=new Map,t=[];for(let o of e){let r={...o};n.set(o.__pivotId,r);let i=o.__pivotParentId?n.get(o.__pivotParentId):void 0;i?(i.subRows??=[]).push(r):t.push(r)}return t}var yn=e=>e==null||e===""?"":typeof e=="number"?e.toLocaleString(void 0,{maximumFractionDigits:2}):String(e);function Ne(e,n={}){return e.map(t=>{let o={isRowHeader:!!t.isRowHeader,isTotal:!!t.isTotal,measure:t.measure};if(t.columns)return{id:t.id,header:t.header,columns:Ne(t.columns,n),meta:{rowpine:{},pivot:o}};if(t.isRowHeader)return{id:t.id,header:t.header,accessorFn:i=>i.__pivotLabel,size:t.width,meta:{rowpine:{header:t.header||" "},pivot:o}};let r=t.format??yn;return{id:t.id,header:t.header,accessorFn:i=>i[t.id],size:t.width,meta:{rowpine:{numFmt:n.numFmt,format:i=>r(i),align:"right"},pivot:o}}})}function bn(e){let n=e?.__pivotKind;return n==="group"||n==="subtotal"||n==="grandTotal"?{bold:!0}:void 0}function ht(e,n){let t=[],o=(d,l)=>{for(let h of d){let P={id:h.id,columnDef:h,parent:l,getSize:()=>"size"in h&&h.size||130};"columns"in h?o(h.columns,P):t.push(P)}};o(n);let r=new Map,i=d=>{for(let l of d)"columns"in l?i(l.columns):r.set(l.id,l.accessorFn)};i(n);let s=(d,l)=>({id:d.__pivotId,depth:l,original:d,subRows:(d.subRows??[]).map(h=>s(h,l+1)),getValue:h=>r.get(h)?.(d),getIsGrouped:()=>!1}),u={rows:e.map(d=>s(d,0))},c=[],m=d=>d.forEach(l=>(c.push(l),m(l.subRows)));return m(u.rows),{getAllLeafColumns:()=>t,getCoreRowModel:()=>u,getRowModel:()=>({rows:c}),getState:()=>({grouping:[]})}}function Ee(e,n,t={}){oe("Pivot");let o=Oe(e,n),r=gt(o.rows),i=Ne(o.columns,t);return{data:r,columns:i,rows:o.rows,table:ht(r,i)}}var wn={rows:"Rows",cols:"Columns",values:"Values",filters:"Filters"},xn={dimension:["rows","cols","filters"],measure:["values","filters"]},vn=["sum","avg","min","max","count","countDistinct","first","last"],yt={sum:"Sum",avg:"Average",min:"Min",max:"Max",count:"Count",countDistinct:"Distinct count",first:"First",last:"Last"},Pn={rows:[],cols:[],values:[],filters:[]},ce=(e,n)=>e.find(t=>t.field===n),ve=(e,n,t)=>`${yt[t]} of ${ce(e,n)?.label??n}`;function kn(e){let n=e.find(r=>r.kind==="dimension"),t=e.find(r=>r.kind==="measure"),o=t?.defaultAgg??"sum";return{rows:n?[n.field]:[],cols:[],values:t?[{field:t.field,agg:o,label:ve(e,t.field,o)}]:[],filters:[]}}function bt(e){return e.kind==="measure"?"values":"rows"}function wt(e,n){return e.rows.includes(n)||e.cols.includes(n)||e.values.some(t=>t.field===n)||e.filters.some(t=>t.field===n)}function xt(e,n,t,o,r=1/0,i){let s=ce(n,t);if(!s)return e;let u={...e,rows:e.rows.filter(c=>c!==t),cols:e.cols.filter(c=>c!==t),values:i!==void 0?e.values.filter((c,m)=>m!==i):e.values.slice(),filters:e.filters.filter(c=>c.field!==t)};if(o==="rows"||o==="cols")u[o].splice(Math.min(u[o].length,r),0,t);else if(o==="values"){let m=(i!==void 0?e.values[i]:void 0)?.agg??s.defaultAgg??(s.kind==="measure"?"sum":"count");if(u.values.some(d=>d.field===t&&d.agg===m))return u;u.values.splice(Math.min(u.values.length,r),0,{field:t,agg:m,label:ve(n,t,m)})}else u.filters.splice(Math.min(u.filters.length,r),0,{field:t,allowed:null});return u}function Cn(e,n,t,o){return t==="rows"?{...e,rows:e.rows.filter(r=>r!==n)}:t==="cols"?{...e,cols:e.cols.filter(r=>r!==n)}:t==="filters"?{...e,filters:e.filters.filter(r=>r.field!==n)}:{...e,values:o!==void 0?e.values.filter((r,i)=>i!==o):e.values.filter(r=>r.field!==n)}}function Rn(e,n,t){let o=ce(n,t);return o?wt(e,t)?{...e,rows:e.rows.filter(r=>r!==t),cols:e.cols.filter(r=>r!==t),values:e.values.filter(r=>r.field!==t),filters:e.filters.filter(r=>r.field!==t)}:xt(e,n,t,bt(o)):e}function Sn(e,n,t,o){let r=e.values[t];if(!r)return e;let i=e.values.some((s,u)=>u!==t&&s.field===r.field&&s.agg===o);return{...e,values:i?e.values.filter((s,u)=>u!==t):e.values.map((s,u)=>u===t?{...s,agg:o,label:ve(n,r.field,o)}:s)}}function Tn(e,n,t){return{...e,filters:e.filters.map(o=>o.field===n?{...o,allowed:t}:o)}}function Ln(e,n){return{...e,[n]:[]}}function An(e,n){let t=new Set;for(let o of e)t.add(String(o[n]));return[...t].sort((o,r)=>o.localeCompare(r,void 0,{numeric:!0}))}function vt(e,n){let t=n.filters.filter(r=>r.allowed!==null);if(t.length===0)return e.slice();let o=t.map(r=>({field:r.field,allowed:new Set(r.allowed)}));return e.filter(r=>o.every(i=>i.allowed.has(String(r[i.field]))))}function Pt(e,n){return{rows:e.rows,cols:e.cols,values:e.values.map(t=>({field:t.field,agg:t.agg,label:t.label??ve(n,t.field,t.agg),format:t.agg==="count"||t.agg==="countDistinct"?void 0:ce(n,t.field)?.format})),grandTotalRow:!e.hideGrandTotals,grandTotalCol:!e.hideGrandTotals,rowSubtotals:!e.hideSubtotals}}function $n(e,n,t,o){if(n.values.length===0)return null;let r=Ee(vt(e,n),Pt(n,t),o),i=n.rows.map(u=>ce(t,u)?.label??u).join(" / "),s=r.columns[0];return s&&s.meta.pivot.isRowHeader&&(s.header=i,s.meta.rowpine.header=i||" "),r}export{yt as AGG_LABEL,vn as ALL_AGGREGATORS,Pn as EMPTY_LAYOUT,xn as KIND_WELLS,wn as WELL_LABEL,xt as addToWell,vt as applyLayoutFilters,$e as buildXlsxParts,Ln as clearWell,Ee as createPivot,Oe as createPivotModel,kn as defaultLayoutFor,bt as defaultWellFor,An as distinctValues,Ot as exportCsv,dn as exportPdf,en as exportXlsx,hn as filterCollapsedPivotRows,He as getLicenseStatus,wt as isFieldInLayout,Pt as layoutToConfig,gn as pivotAggregators,ht as pivotAsTable,$n as pivotFromLayout,bn as pivotRowStyle,gt as pivotToTree,Z as readTable,Cn as removeFromWell,q as saveBlob,Sn as setAggregatorAt,Tn as setFilterAllowed,zt as setLicenseKey,lt as sheetToPdfParams,Ze as sheetToXlsxModel,je as tableToCsv,Je as tableToXlsxModel,Ne as toTanStackColumns,Rn as toggleField};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const UNLICENSED_NOTE = "Exported with an unlicensed copy of Rowpine. https://rowpine.com/";
|
|
2
|
+
export type LicensePayload = {
|
|
3
|
+
v: 1;
|
|
4
|
+
/** Licensee name or company. */
|
|
5
|
+
sub: string;
|
|
6
|
+
plan: 'developer' | 'team';
|
|
7
|
+
seats: number;
|
|
8
|
+
/** Last day of the update period, YYYY-MM-DD. */
|
|
9
|
+
upd: string;
|
|
10
|
+
/** Issue date, YYYY-MM-DD. */
|
|
11
|
+
iat: string;
|
|
12
|
+
/** Order or license id. */
|
|
13
|
+
id: string;
|
|
14
|
+
};
|
|
15
|
+
export type LicenseStatus = {
|
|
16
|
+
licensed: true;
|
|
17
|
+
payload: LicensePayload;
|
|
18
|
+
buildDate: string;
|
|
19
|
+
} | {
|
|
20
|
+
licensed: false;
|
|
21
|
+
reason: 'missing' | 'malformed' | 'invalid' | 'updates-ended';
|
|
22
|
+
payload?: LicensePayload;
|
|
23
|
+
buildDate: string;
|
|
24
|
+
};
|
|
25
|
+
/** Set the license key. Call once, before the first export or pivot. */
|
|
26
|
+
export declare function setLicenseKey(value: string | null | undefined): void;
|
|
27
|
+
/** Check a key against a public key and a build date. Exported for tests. */
|
|
28
|
+
export declare function verifyLicenseKey(value: string | null, publicKeyHex: string, buildDate: string): Promise<LicenseStatus>;
|
|
29
|
+
/** The current license status. */
|
|
30
|
+
export declare function getLicenseStatus(): Promise<LicenseStatus>;
|
|
31
|
+
/** True when licensed. Otherwise logs the notice once and returns false. */
|
|
32
|
+
export declare function checkLicense(feature: string): Promise<boolean>;
|