@liasse/components 0.2.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Liasse
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,116 @@
1
+ import { ValueFormat, Align, Document, TableColumn } from '@liasse/core';
2
+
3
+ interface FinancialColumn {
4
+ key: string;
5
+ header: string;
6
+ format?: ValueFormat;
7
+ align?: Align;
8
+ width?: number;
9
+ }
10
+ interface FinancialTableInput {
11
+ /** Document + sheet title. */
12
+ title: string;
13
+ author?: string;
14
+ /** Optional intro line under the title. */
15
+ subtitle?: string;
16
+ columns: FinancialColumn[];
17
+ rows: Record<string, unknown>[];
18
+ /** Column keys to total with a `=SUM` summary row. */
19
+ totals?: string[];
20
+ /** Column key to colour by sign (green positive / red negative). */
21
+ deltaColumn?: string;
22
+ /** Keep the header visible while scrolling. Defaults to true. */
23
+ freezeHeader?: boolean;
24
+ }
25
+ /**
26
+ * `financial-table` — a styled financial table with summary subtotals, currency
27
+ * formatting and positive/negative conditional colouring. The flagship demo of
28
+ * the Liasse value proposition.
29
+ */
30
+ declare function financialTable(input: FinancialTableInput): Document;
31
+
32
+ interface InvoiceLine {
33
+ designation: string;
34
+ quantity: number;
35
+ unitPrice: number;
36
+ /** VAT rate as a ratio, e.g. 0.20 for 20 %. Falls back to `defaultVatRate`. */
37
+ vatRate?: number;
38
+ }
39
+ interface InvoiceParty {
40
+ name: string;
41
+ /** Free-form lines (address, SIREN, VAT number, …). */
42
+ details?: string[];
43
+ }
44
+ interface InvoiceInput {
45
+ number: string;
46
+ date?: string;
47
+ dueDate?: string;
48
+ issuer: InvoiceParty;
49
+ client?: InvoiceParty;
50
+ lines: InvoiceLine[];
51
+ /** Applied to lines without an explicit `vatRate`. Defaults to 0.20. */
52
+ defaultVatRate?: number;
53
+ }
54
+ /**
55
+ * `invoice` — a clean, presentational XLSX invoice: issuer/client header,
56
+ * line-items table and totals with a VAT breakdown by rate.
57
+ *
58
+ * This is **not** Factur-X; it is purely a presentational invoice for the MVP.
59
+ */
60
+ declare function invoice(input: InvoiceInput): Document;
61
+
62
+ interface DashboardKpi {
63
+ label: string;
64
+ value: string | number;
65
+ format?: ValueFormat;
66
+ }
67
+ interface DashboardTable {
68
+ title?: string;
69
+ columns: TableColumn[];
70
+ rows: Record<string, unknown>[];
71
+ totals?: string[];
72
+ deltaColumn?: string;
73
+ }
74
+ interface DashboardExportInput {
75
+ title: string;
76
+ author?: string;
77
+ kpis: DashboardKpi[];
78
+ /** One or two supporting tables, rendered under the KPIs. */
79
+ tables?: DashboardTable[];
80
+ }
81
+ /**
82
+ * `dashboard-export` — KPIs as key/value blocks followed by one or two tables.
83
+ * The "Export to Excel" feature a typical SaaS dashboard needs.
84
+ */
85
+ declare function dashboardExport(input: DashboardExportInput): Document;
86
+
87
+ interface ReportSection {
88
+ title: string;
89
+ columns: TableColumn[];
90
+ rows: Record<string, unknown>[];
91
+ /** Column keys to total within the section. */
92
+ totals?: string[];
93
+ deltaColumn?: string;
94
+ }
95
+ interface SummaryKpi {
96
+ label: string;
97
+ value: string | number;
98
+ format?: ValueFormat;
99
+ }
100
+ interface MultiSheetReportInput {
101
+ title: string;
102
+ author?: string;
103
+ /** Extra headline figures shown on the leading summary sheet. */
104
+ summaryKpis?: SummaryKpi[];
105
+ sections: ReportSection[];
106
+ /** Label/title for the leading summary sheet. Defaults to "Synthèse". */
107
+ summaryTitle?: string;
108
+ }
109
+ /**
110
+ * `multi-sheet-report` — multiple sections, each on its own sheet, preceded by a
111
+ * leading summary sheet that aggregates the key figure of every section into a
112
+ * single table (plus any headline KPIs).
113
+ */
114
+ declare function multiSheetReport(input: MultiSheetReportInput): Document;
115
+
116
+ export { type DashboardExportInput, type DashboardKpi, type DashboardTable, type FinancialColumn, type FinancialTableInput, type InvoiceInput, type InvoiceLine, type InvoiceParty, type MultiSheetReportInput, type ReportSection, type SummaryKpi, dashboardExport, financialTable, invoice, multiSheetReport };
package/dist/index.js ADDED
@@ -0,0 +1,208 @@
1
+ // src/financial-table.ts
2
+ import {
3
+ defineDocument,
4
+ heading,
5
+ paragraph,
6
+ table
7
+ } from "@liasse/core";
8
+ function financialTable(input) {
9
+ const columns = input.columns.map((c) => ({
10
+ key: c.key,
11
+ header: c.header,
12
+ ...c.format ? { format: c.format } : {},
13
+ ...c.align ? { align: c.align } : {},
14
+ ...c.width ? { width: c.width } : {}
15
+ }));
16
+ const summary = input.totals?.length ? Object.fromEntries(input.totals.map((key) => [key, "sum"])) : void 0;
17
+ return defineDocument({
18
+ meta: { title: input.title, ...input.author ? { author: input.author } : {} },
19
+ blocks: [
20
+ heading(input.title, { level: 1 }),
21
+ ...input.subtitle ? [paragraph(input.subtitle)] : [],
22
+ table({
23
+ columns,
24
+ rows: input.rows,
25
+ ...summary ? { summary } : {},
26
+ ...input.deltaColumn ? { conditional: { column: input.deltaColumn, rule: "positiveNegative" } } : {},
27
+ xlsx: { freezeHeader: input.freezeHeader ?? true }
28
+ })
29
+ ]
30
+ });
31
+ }
32
+
33
+ // src/invoice.ts
34
+ import {
35
+ defineDocument as defineDocument2,
36
+ heading as heading2,
37
+ keyValue,
38
+ kv,
39
+ spacer,
40
+ table as table2
41
+ } from "@liasse/core";
42
+ function formatRate(rate) {
43
+ const pct = rate * 100;
44
+ return `TVA ${Number.isInteger(pct) ? pct : pct.toFixed(1)} %`;
45
+ }
46
+ function invoice(input) {
47
+ const defaultRate = input.defaultVatRate ?? 0.2;
48
+ const rows = input.lines.map((line) => ({
49
+ designation: line.designation,
50
+ quantity: line.quantity,
51
+ unitPrice: line.unitPrice,
52
+ amount: line.quantity * line.unitPrice
53
+ }));
54
+ const byRate = /* @__PURE__ */ new Map();
55
+ let totalHT = 0;
56
+ for (const line of input.lines) {
57
+ const amount = line.quantity * line.unitPrice;
58
+ const rate = line.vatRate ?? defaultRate;
59
+ totalHT += amount;
60
+ byRate.set(rate, (byRate.get(rate) ?? 0) + amount * rate);
61
+ }
62
+ const totalVAT = [...byRate.values()].reduce((a, b) => a + b, 0);
63
+ const totalTTC = totalHT + totalVAT;
64
+ const issuerLines = [input.issuer.name, ...input.issuer.details ?? []].join("\n");
65
+ const meta = [
66
+ kv("Facture n\xB0", input.number, "text"),
67
+ ...input.date ? [kv("Date", input.date, "text")] : [],
68
+ ...input.dueDate ? [kv("\xC9ch\xE9ance", input.dueDate, "text")] : []
69
+ ];
70
+ const totalsItems = [
71
+ kv("Total HT", round2(totalHT), "currency"),
72
+ ...[...byRate.entries()].map(([rate, vat]) => kv(formatRate(rate), round2(vat), "currency")),
73
+ kv("Total TTC", round2(totalTTC), "currency")
74
+ ];
75
+ return defineDocument2({
76
+ meta: { title: `Facture ${input.number}`, author: input.issuer.name },
77
+ blocks: [
78
+ heading2("Facture", { level: 1 }),
79
+ keyValue(meta),
80
+ spacer(),
81
+ keyValue([
82
+ kv("\xC9metteur", issuerLines, "text"),
83
+ ...input.client ? [kv("Client", [input.client.name, ...input.client.details ?? []].join("\n"), "text")] : []
84
+ ]),
85
+ spacer(),
86
+ table2({
87
+ columns: [
88
+ { key: "designation", header: "D\xE9signation" },
89
+ { key: "quantity", header: "Qt\xE9", format: "number", align: "right" },
90
+ { key: "unitPrice", header: "PU", format: "currency", align: "right" },
91
+ { key: "amount", header: "Montant", format: "currency", align: "right" }
92
+ ],
93
+ rows,
94
+ summary: { amount: "sum" }
95
+ }),
96
+ spacer(),
97
+ keyValue(totalsItems)
98
+ ]
99
+ });
100
+ }
101
+ function round2(n) {
102
+ return Math.round((n + Number.EPSILON) * 100) / 100;
103
+ }
104
+
105
+ // src/dashboard-export.ts
106
+ import {
107
+ defineDocument as defineDocument3,
108
+ heading as heading3,
109
+ keyValue as keyValue2,
110
+ table as table3
111
+ } from "@liasse/core";
112
+ function dashboardExport(input) {
113
+ const kpiItems = input.kpis.map((k) => ({
114
+ label: k.label,
115
+ value: k.value,
116
+ ...k.format ? { format: k.format } : {}
117
+ }));
118
+ const tableBlocks = (input.tables ?? []).flatMap((t) => {
119
+ const summary = t.totals?.length ? Object.fromEntries(t.totals.map((key) => [key, "sum"])) : void 0;
120
+ return [
121
+ ...t.title ? [heading3(t.title, { level: 2 })] : [],
122
+ table3({
123
+ columns: t.columns,
124
+ rows: t.rows,
125
+ ...summary ? { summary } : {},
126
+ ...t.deltaColumn ? { conditional: { column: t.deltaColumn, rule: "positiveNegative" } } : {},
127
+ xlsx: { freezeHeader: true }
128
+ })
129
+ ];
130
+ });
131
+ return defineDocument3({
132
+ meta: { title: input.title, ...input.author ? { author: input.author } : {} },
133
+ blocks: [heading3(input.title, { level: 1 }), keyValue2(kpiItems), ...tableBlocks]
134
+ });
135
+ }
136
+
137
+ // src/multi-sheet-report.ts
138
+ import {
139
+ defineDocument as defineDocument4,
140
+ keyValue as keyValue3,
141
+ section,
142
+ table as table4
143
+ } from "@liasse/core";
144
+ function multiSheetReport(input) {
145
+ const summaryTitle = input.summaryTitle ?? "Synth\xE8se";
146
+ const aggregateRows = input.sections.map((s) => {
147
+ const totalKey = s.totals?.[0];
148
+ const total = totalKey ? s.rows.reduce((sum, row) => sum + toNumber(row[totalKey]), 0) : s.rows.length;
149
+ return { section: s.title, total };
150
+ });
151
+ const summaryKpiItems = (input.summaryKpis ?? []).map((k) => ({
152
+ label: k.label,
153
+ value: k.value,
154
+ ...k.format ? { format: k.format } : {}
155
+ }));
156
+ const hasTotals = input.sections.some((s) => s.totals?.length);
157
+ const summaryBlocks = [
158
+ ...summaryKpiItems.length ? [keyValue3(summaryKpiItems)] : [],
159
+ table4({
160
+ columns: [
161
+ { key: "section", header: "Section" },
162
+ {
163
+ key: "total",
164
+ header: hasTotals ? "Total" : "Lignes",
165
+ format: hasTotals ? "currency" : "number",
166
+ align: "right"
167
+ }
168
+ ],
169
+ rows: aggregateRows,
170
+ summary: { total: "sum" }
171
+ })
172
+ ];
173
+ const sectionSheets = input.sections.map((s) => {
174
+ const summary = s.totals?.length ? Object.fromEntries(s.totals.map((key) => [key, "sum"])) : void 0;
175
+ return section({
176
+ title: s.title,
177
+ sheet: true,
178
+ blocks: [
179
+ table4({
180
+ columns: s.columns,
181
+ rows: s.rows,
182
+ ...summary ? { summary } : {},
183
+ ...s.deltaColumn ? { conditional: { column: s.deltaColumn, rule: "positiveNegative" } } : {},
184
+ xlsx: { freezeHeader: true }
185
+ })
186
+ ]
187
+ });
188
+ });
189
+ return defineDocument4({
190
+ meta: { title: input.title, ...input.author ? { author: input.author } : {} },
191
+ blocks: [
192
+ section({ title: summaryTitle, sheet: true, blocks: summaryBlocks }),
193
+ ...sectionSheets
194
+ ]
195
+ });
196
+ }
197
+ function toNumber(value) {
198
+ if (typeof value === "number") return value;
199
+ const n = Number(value);
200
+ return Number.isNaN(n) ? 0 : n;
201
+ }
202
+ export {
203
+ dashboardExport,
204
+ financialTable,
205
+ invoice,
206
+ multiSheetReport
207
+ };
208
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/financial-table.ts","../src/invoice.ts","../src/dashboard-export.ts","../src/multi-sheet-report.ts"],"sourcesContent":["import {\n defineDocument,\n heading,\n paragraph,\n table,\n type Align,\n type Document,\n type TableColumn,\n type ValueFormat,\n} from \"@liasse/core\";\n\nexport interface FinancialColumn {\n key: string;\n header: string;\n format?: ValueFormat;\n align?: Align;\n width?: number;\n}\n\nexport interface FinancialTableInput {\n /** Document + sheet title. */\n title: string;\n author?: string;\n /** Optional intro line under the title. */\n subtitle?: string;\n columns: FinancialColumn[];\n rows: Record<string, unknown>[];\n /** Column keys to total with a `=SUM` summary row. */\n totals?: string[];\n /** Column key to colour by sign (green positive / red negative). */\n deltaColumn?: string;\n /** Keep the header visible while scrolling. Defaults to true. */\n freezeHeader?: boolean;\n}\n\n/**\n * `financial-table` — a styled financial table with summary subtotals, currency\n * formatting and positive/negative conditional colouring. The flagship demo of\n * the Liasse value proposition.\n */\nexport function financialTable(input: FinancialTableInput): Document {\n const columns: TableColumn[] = input.columns.map((c) => ({\n key: c.key,\n header: c.header,\n ...(c.format ? { format: c.format } : {}),\n ...(c.align ? { align: c.align } : {}),\n ...(c.width ? { width: c.width } : {}),\n }));\n\n const summary = input.totals?.length\n ? Object.fromEntries(input.totals.map((key) => [key, \"sum\" as const]))\n : undefined;\n\n return defineDocument({\n meta: { title: input.title, ...(input.author ? { author: input.author } : {}) },\n blocks: [\n heading(input.title, { level: 1 }),\n ...(input.subtitle ? [paragraph(input.subtitle)] : []),\n table({\n columns,\n rows: input.rows,\n ...(summary ? { summary } : {}),\n ...(input.deltaColumn\n ? { conditional: { column: input.deltaColumn, rule: \"positiveNegative\" as const } }\n : {}),\n xlsx: { freezeHeader: input.freezeHeader ?? true },\n }),\n ],\n });\n}\n","import {\n defineDocument,\n heading,\n keyValue,\n kv,\n spacer,\n table,\n type Document,\n} from \"@liasse/core\";\n\nexport interface InvoiceLine {\n designation: string;\n quantity: number;\n unitPrice: number;\n /** VAT rate as a ratio, e.g. 0.20 for 20 %. Falls back to `defaultVatRate`. */\n vatRate?: number;\n}\n\nexport interface InvoiceParty {\n name: string;\n /** Free-form lines (address, SIREN, VAT number, …). */\n details?: string[];\n}\n\nexport interface InvoiceInput {\n number: string;\n date?: string;\n dueDate?: string;\n issuer: InvoiceParty;\n client?: InvoiceParty;\n lines: InvoiceLine[];\n /** Applied to lines without an explicit `vatRate`. Defaults to 0.20. */\n defaultVatRate?: number;\n}\n\nfunction formatRate(rate: number): string {\n const pct = rate * 100;\n return `TVA ${Number.isInteger(pct) ? pct : pct.toFixed(1)} %`;\n}\n\n/**\n * `invoice` — a clean, presentational XLSX invoice: issuer/client header,\n * line-items table and totals with a VAT breakdown by rate.\n *\n * This is **not** Factur-X; it is purely a presentational invoice for the MVP.\n */\nexport function invoice(input: InvoiceInput): Document {\n const defaultRate = input.defaultVatRate ?? 0.2;\n\n const rows = input.lines.map((line) => ({\n designation: line.designation,\n quantity: line.quantity,\n unitPrice: line.unitPrice,\n amount: line.quantity * line.unitPrice,\n }));\n\n // VAT breakdown by rate, preserving first-seen order.\n const byRate = new Map<number, number>();\n let totalHT = 0;\n for (const line of input.lines) {\n const amount = line.quantity * line.unitPrice;\n const rate = line.vatRate ?? defaultRate;\n totalHT += amount;\n byRate.set(rate, (byRate.get(rate) ?? 0) + amount * rate);\n }\n const totalVAT = [...byRate.values()].reduce((a, b) => a + b, 0);\n const totalTTC = totalHT + totalVAT;\n\n const issuerLines = [input.issuer.name, ...(input.issuer.details ?? [])].join(\"\\n\");\n const meta = [\n kv(\"Facture n°\", input.number, \"text\"),\n ...(input.date ? [kv(\"Date\", input.date, \"text\")] : []),\n ...(input.dueDate ? [kv(\"Échéance\", input.dueDate, \"text\")] : []),\n ];\n\n const totalsItems = [\n kv(\"Total HT\", round2(totalHT), \"currency\"),\n ...[...byRate.entries()].map(([rate, vat]) => kv(formatRate(rate), round2(vat), \"currency\")),\n kv(\"Total TTC\", round2(totalTTC), \"currency\"),\n ];\n\n return defineDocument({\n meta: { title: `Facture ${input.number}`, author: input.issuer.name },\n blocks: [\n heading(\"Facture\", { level: 1 }),\n keyValue(meta),\n spacer(),\n keyValue([\n kv(\"Émetteur\", issuerLines, \"text\"),\n ...(input.client\n ? [kv(\"Client\", [input.client.name, ...(input.client.details ?? [])].join(\"\\n\"), \"text\")]\n : []),\n ]),\n spacer(),\n table({\n columns: [\n { key: \"designation\", header: \"Désignation\" },\n { key: \"quantity\", header: \"Qté\", format: \"number\", align: \"right\" },\n { key: \"unitPrice\", header: \"PU\", format: \"currency\", align: \"right\" },\n { key: \"amount\", header: \"Montant\", format: \"currency\", align: \"right\" },\n ],\n rows,\n summary: { amount: \"sum\" },\n }),\n spacer(),\n keyValue(totalsItems),\n ],\n });\n}\n\nfunction round2(n: number): number {\n return Math.round((n + Number.EPSILON) * 100) / 100;\n}\n","import {\n defineDocument,\n heading,\n keyValue,\n table,\n type Document,\n type KeyValueBlock,\n type TableColumn,\n type ValueFormat,\n} from \"@liasse/core\";\n\nexport interface DashboardKpi {\n label: string;\n value: string | number;\n format?: ValueFormat;\n}\n\nexport interface DashboardTable {\n title?: string;\n columns: TableColumn[];\n rows: Record<string, unknown>[];\n totals?: string[];\n deltaColumn?: string;\n}\n\nexport interface DashboardExportInput {\n title: string;\n author?: string;\n kpis: DashboardKpi[];\n /** One or two supporting tables, rendered under the KPIs. */\n tables?: DashboardTable[];\n}\n\n/**\n * `dashboard-export` — KPIs as key/value blocks followed by one or two tables.\n * The \"Export to Excel\" feature a typical SaaS dashboard needs.\n */\nexport function dashboardExport(input: DashboardExportInput): Document {\n const kpiItems: KeyValueBlock[\"items\"] = input.kpis.map((k) => ({\n label: k.label,\n value: k.value,\n ...(k.format ? { format: k.format } : {}),\n }));\n\n const tableBlocks = (input.tables ?? []).flatMap((t) => {\n const summary = t.totals?.length\n ? Object.fromEntries(t.totals.map((key) => [key, \"sum\" as const]))\n : undefined;\n return [\n ...(t.title ? [heading(t.title, { level: 2 })] : []),\n table({\n columns: t.columns,\n rows: t.rows,\n ...(summary ? { summary } : {}),\n ...(t.deltaColumn\n ? { conditional: { column: t.deltaColumn, rule: \"positiveNegative\" as const } }\n : {}),\n xlsx: { freezeHeader: true },\n }),\n ];\n });\n\n return defineDocument({\n meta: { title: input.title, ...(input.author ? { author: input.author } : {}) },\n blocks: [heading(input.title, { level: 1 }), keyValue(kpiItems), ...tableBlocks],\n });\n}\n","import {\n defineDocument,\n keyValue,\n section,\n table,\n type Block,\n type Document,\n type KeyValueBlock,\n type TableColumn,\n type ValueFormat,\n} from \"@liasse/core\";\n\nexport interface ReportSection {\n title: string;\n columns: TableColumn[];\n rows: Record<string, unknown>[];\n /** Column keys to total within the section. */\n totals?: string[];\n deltaColumn?: string;\n}\n\nexport interface SummaryKpi {\n label: string;\n value: string | number;\n format?: ValueFormat;\n}\n\nexport interface MultiSheetReportInput {\n title: string;\n author?: string;\n /** Extra headline figures shown on the leading summary sheet. */\n summaryKpis?: SummaryKpi[];\n sections: ReportSection[];\n /** Label/title for the leading summary sheet. Defaults to \"Synthèse\". */\n summaryTitle?: string;\n}\n\n/**\n * `multi-sheet-report` — multiple sections, each on its own sheet, preceded by a\n * leading summary sheet that aggregates the key figure of every section into a\n * single table (plus any headline KPIs).\n */\nexport function multiSheetReport(input: MultiSheetReportInput): Document {\n const summaryTitle = input.summaryTitle ?? \"Synthèse\";\n\n // Aggregate each section's first total column (or row count) for the summary.\n const aggregateRows = input.sections.map((s) => {\n const totalKey = s.totals?.[0];\n const total = totalKey\n ? s.rows.reduce((sum, row) => sum + toNumber(row[totalKey]), 0)\n : s.rows.length;\n return { section: s.title, total };\n });\n\n const summaryKpiItems: KeyValueBlock[\"items\"] = (input.summaryKpis ?? []).map((k) => ({\n label: k.label,\n value: k.value,\n ...(k.format ? { format: k.format } : {}),\n }));\n\n const hasTotals = input.sections.some((s) => s.totals?.length);\n\n const summaryBlocks: Block[] = [\n ...(summaryKpiItems.length ? [keyValue(summaryKpiItems)] : []),\n table({\n columns: [\n { key: \"section\", header: \"Section\" },\n {\n key: \"total\",\n header: hasTotals ? \"Total\" : \"Lignes\",\n format: hasTotals ? \"currency\" : \"number\",\n align: \"right\",\n },\n ],\n rows: aggregateRows,\n summary: { total: \"sum\" },\n }),\n ];\n\n const sectionSheets = input.sections.map((s) => {\n const summary = s.totals?.length\n ? Object.fromEntries(s.totals.map((key) => [key, \"sum\" as const]))\n : undefined;\n return section({\n title: s.title,\n sheet: true,\n blocks: [\n table({\n columns: s.columns,\n rows: s.rows,\n ...(summary ? { summary } : {}),\n ...(s.deltaColumn\n ? { conditional: { column: s.deltaColumn, rule: \"positiveNegative\" as const } }\n : {}),\n xlsx: { freezeHeader: true },\n }),\n ],\n });\n });\n\n return defineDocument({\n meta: { title: input.title, ...(input.author ? { author: input.author } : {}) },\n blocks: [\n section({ title: summaryTitle, sheet: true, blocks: summaryBlocks }),\n ...sectionSheets,\n ],\n });\n}\n\nfunction toNumber(value: unknown): number {\n if (typeof value === \"number\") return value;\n const n = Number(value);\n return Number.isNaN(n) ? 0 : n;\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AA+BA,SAAS,eAAe,OAAsC;AACnE,QAAM,UAAyB,MAAM,QAAQ,IAAI,CAAC,OAAO;AAAA,IACvD,KAAK,EAAE;AAAA,IACP,QAAQ,EAAE;AAAA,IACV,GAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,IAAI,CAAC;AAAA,IACvC,GAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAAA,IACpC,GAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAAA,EACtC,EAAE;AAEF,QAAM,UAAU,MAAM,QAAQ,SAC1B,OAAO,YAAY,MAAM,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,KAAc,CAAC,CAAC,IACnE;AAEJ,SAAO,e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B;","names":["defineDocument","heading","table","defineDocument","heading","keyValue","table","defineDocument","keyValue","table"]}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@liasse/components",
3
+ "version": "0.2.0",
4
+ "description": "Liasse free components — pure functions that produce themed document trees (financial-table, invoice, dashboard-export, multi-sheet-report).",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "@liasse/core": "0.2.0"
22
+ },
23
+ "devDependencies": {
24
+ "exceljs": "^4.4.0",
25
+ "tsup": "^8.3.5",
26
+ "typescript": "^5.7.2",
27
+ "vitest": "^2.1.8",
28
+ "@liasse/xlsx": "0.2.0"
29
+ },
30
+ "scripts": {
31
+ "build": "tsup",
32
+ "typecheck": "tsc --noEmit",
33
+ "test": "vitest run"
34
+ }
35
+ }