@nxgt/material-core 0.1.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.
Files changed (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +335 -0
  3. package/dist/chunks/index-0xc5q9tp.js +81 -0
  4. package/dist/chunks/index-0xc5q9tp.js.map +10 -0
  5. package/dist/chunks/index-2gcgcmc0.js +36 -0
  6. package/dist/chunks/index-2gcgcmc0.js.map +10 -0
  7. package/dist/chunks/index-3ca6xe71.js +36 -0
  8. package/dist/chunks/index-3ca6xe71.js.map +10 -0
  9. package/dist/chunks/index-5r6rzp43.js +90 -0
  10. package/dist/chunks/index-5r6rzp43.js.map +10 -0
  11. package/dist/chunks/index-6tn0wjsb.js +13 -0
  12. package/dist/chunks/index-6tn0wjsb.js.map +10 -0
  13. package/dist/chunks/index-8gf9e2d4.js +76 -0
  14. package/dist/chunks/index-8gf9e2d4.js.map +11 -0
  15. package/dist/chunks/index-eh0e5ex7.js +61 -0
  16. package/dist/chunks/index-eh0e5ex7.js.map +10 -0
  17. package/dist/chunks/index-g7rh8fpv.js +57 -0
  18. package/dist/chunks/index-g7rh8fpv.js.map +10 -0
  19. package/dist/chunks/index-h3vjydz7.js +113 -0
  20. package/dist/chunks/index-h3vjydz7.js.map +10 -0
  21. package/dist/chunks/index-paaaedrm.js +37 -0
  22. package/dist/chunks/index-paaaedrm.js.map +10 -0
  23. package/dist/chunks/index-w3ajz57t.js +72 -0
  24. package/dist/chunks/index-w3ajz57t.js.map +10 -0
  25. package/dist/chunks/index-z3yjh0a8.js +642 -0
  26. package/dist/chunks/index-z3yjh0a8.js.map +18 -0
  27. package/dist/index.d.ts +21 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +133 -0
  30. package/dist/index.js.map +9 -0
  31. package/dist/lib/currency-digits.d.ts +8 -0
  32. package/dist/lib/currency-digits.d.ts.map +1 -0
  33. package/dist/lib/currency-digits.js +24 -0
  34. package/dist/lib/currency-digits.js.map +10 -0
  35. package/dist/lib/field-blur-layers.d.ts +35 -0
  36. package/dist/lib/field-blur-layers.d.ts.map +1 -0
  37. package/dist/lib/field-blur-layers.js +52 -0
  38. package/dist/lib/field-blur-layers.js.map +10 -0
  39. package/dist/lib/pdf-download.d.ts +36 -0
  40. package/dist/lib/pdf-download.d.ts.map +1 -0
  41. package/dist/lib/pdf-download.js +15 -0
  42. package/dist/lib/pdf-download.js.map +9 -0
  43. package/dist/lib/pdf-file-name.d.ts +10 -0
  44. package/dist/lib/pdf-file-name.d.ts.map +1 -0
  45. package/dist/lib/pdf-file-name.js +12 -0
  46. package/dist/lib/pdf-file-name.js.map +9 -0
  47. package/dist/lib/pdf-source.d.ts +58 -0
  48. package/dist/lib/pdf-source.d.ts.map +1 -0
  49. package/dist/lib/pdf-source.js +21 -0
  50. package/dist/lib/pdf-source.js.map +9 -0
  51. package/dist/lib/print-format.utils.d.ts +72 -0
  52. package/dist/lib/print-format.utils.d.ts.map +1 -0
  53. package/dist/lib/print-format.utils.js +14 -0
  54. package/dist/lib/print-format.utils.js.map +9 -0
  55. package/dist/lib/print-fraction-digits.d.ts +13 -0
  56. package/dist/lib/print-fraction-digits.d.ts.map +1 -0
  57. package/dist/lib/print-fraction-digits.js +11 -0
  58. package/dist/lib/print-fraction-digits.js.map +9 -0
  59. package/dist/lib/print-table.utils.d.ts +69 -0
  60. package/dist/lib/print-table.utils.d.ts.map +1 -0
  61. package/dist/lib/print-table.utils.js +15 -0
  62. package/dist/lib/print-table.utils.js.map +9 -0
  63. package/dist/lib/print-value.utils.d.ts +41 -0
  64. package/dist/lib/print-value.utils.d.ts.map +1 -0
  65. package/dist/lib/print-value.utils.js +13 -0
  66. package/dist/lib/print-value.utils.js.map +9 -0
  67. package/dist/pdf/file-loader.d.ts +19 -0
  68. package/dist/pdf/file-loader.d.ts.map +1 -0
  69. package/dist/pdf/file-loader.js +11 -0
  70. package/dist/pdf/file-loader.js.map +9 -0
  71. package/dist/pdf/http.d.ts +23 -0
  72. package/dist/pdf/http.d.ts.map +1 -0
  73. package/dist/pdf/http.js +13 -0
  74. package/dist/pdf/http.js.map +9 -0
  75. package/dist/pdf/index.d.ts +12 -0
  76. package/dist/pdf/index.d.ts.map +1 -0
  77. package/dist/pdf/index.js +99 -0
  78. package/dist/pdf/index.js.map +9 -0
  79. package/dist/pdf/model/builders.d.ts +59 -0
  80. package/dist/pdf/model/builders.d.ts.map +1 -0
  81. package/dist/pdf/model/data-table.d.ts +25 -0
  82. package/dist/pdf/model/data-table.d.ts.map +1 -0
  83. package/dist/pdf/model/index.d.ts +5 -0
  84. package/dist/pdf/model/index.d.ts.map +1 -0
  85. package/dist/pdf/model/index.js +60 -0
  86. package/dist/pdf/model/index.js.map +9 -0
  87. package/dist/pdf/model/nodes.d.ts +135 -0
  88. package/dist/pdf/model/nodes.d.ts.map +1 -0
  89. package/dist/pdf/model/theme.d.ts +17 -0
  90. package/dist/pdf/model/theme.d.ts.map +1 -0
  91. package/dist/pdf/model/types.d.ts +124 -0
  92. package/dist/pdf/model/types.d.ts.map +1 -0
  93. package/dist/pdf/render/context.d.ts +51 -0
  94. package/dist/pdf/render/context.d.ts.map +1 -0
  95. package/dist/pdf/render/document.d.ts +22 -0
  96. package/dist/pdf/render/document.d.ts.map +1 -0
  97. package/dist/pdf/render/index.d.ts +9 -0
  98. package/dist/pdf/render/index.d.ts.map +1 -0
  99. package/dist/pdf/render/index.js +44 -0
  100. package/dist/pdf/render/index.js.map +9 -0
  101. package/dist/pdf/render/nodes/blocks.d.ts +20 -0
  102. package/dist/pdf/render/nodes/blocks.d.ts.map +1 -0
  103. package/dist/pdf/render/nodes/header.d.ts +15 -0
  104. package/dist/pdf/render/nodes/header.d.ts.map +1 -0
  105. package/dist/pdf/render/nodes/layout.d.ts +45 -0
  106. package/dist/pdf/render/nodes/layout.d.ts.map +1 -0
  107. package/dist/pdf/render/nodes/table.d.ts +15 -0
  108. package/dist/pdf/render/nodes/table.d.ts.map +1 -0
  109. package/dist/pdf/render/page.d.ts +31 -0
  110. package/dist/pdf/render/page.d.ts.map +1 -0
  111. package/dist/pdf/render/render-node.d.ts +11 -0
  112. package/dist/pdf/render/render-node.d.ts.map +1 -0
  113. package/dist/pdf/render/styles.d.ts +304 -0
  114. package/dist/pdf/render/styles.d.ts.map +1 -0
  115. package/dist/pdf-viewer/index.d.ts +14 -0
  116. package/dist/pdf-viewer/index.d.ts.map +1 -0
  117. package/dist/pdf-viewer/index.js +380 -0
  118. package/dist/pdf-viewer/index.js.map +15 -0
  119. package/dist/pdf-viewer/pdf-document-search.d.ts +44 -0
  120. package/dist/pdf-viewer/pdf-document-search.d.ts.map +1 -0
  121. package/dist/pdf-viewer/pdf-escape.d.ts +7 -0
  122. package/dist/pdf-viewer/pdf-escape.d.ts.map +1 -0
  123. package/dist/pdf-viewer/pdf-page-geometry.d.ts +62 -0
  124. package/dist/pdf-viewer/pdf-page-geometry.d.ts.map +1 -0
  125. package/dist/pdf-viewer/pdf-page-sizes.d.ts +38 -0
  126. package/dist/pdf-viewer/pdf-page-sizes.d.ts.map +1 -0
  127. package/dist/pdf-viewer/pdf-scroll-spy.d.ts +43 -0
  128. package/dist/pdf-viewer/pdf-scroll-spy.d.ts.map +1 -0
  129. package/dist/pdf-viewer/pdf-text-search.d.ts +26 -0
  130. package/dist/pdf-viewer/pdf-text-search.d.ts.map +1 -0
  131. package/dist/vite/index.d.ts +81 -0
  132. package/dist/vite/index.d.ts.map +1 -0
  133. package/dist/vite/index.js +31 -0
  134. package/dist/vite/index.js.map +10 -0
  135. package/docs/README.md +9 -0
  136. package/docs/roadmap.md +35 -0
  137. package/docs/troubleshooting.md +105 -0
  138. package/package.json +187 -0
@@ -0,0 +1,642 @@
1
+ import {
2
+ isEmptyPrintValue2,
3
+ formatPrintValue2
4
+ } from "./index-eh0e5ex7.js";
5
+ import {
6
+ resolvePdfTheme2,
7
+ resolvePdfColor2
8
+ } from "./index-3ca6xe71.js";
9
+
10
+ // src/pdf/render/context.ts
11
+ import { IntlMessageFormat } from "intl-messageformat";
12
+
13
+ // src/pdf/render/styles.ts
14
+ function createPdfStyles2({ colors: c, fonts }) {
15
+ const pad = (y, x) => ({
16
+ paddingTop: y,
17
+ paddingBottom: y,
18
+ paddingLeft: x,
19
+ paddingRight: x
20
+ });
21
+ return {
22
+ page: {
23
+ fontFamily: fonts.sans,
24
+ fontSize: "9pt",
25
+ color: c.text,
26
+ ...pad(21, 24),
27
+ flexDirection: "column",
28
+ gap: 0
29
+ },
30
+ header: { flexDirection: "row", alignItems: "center", marginBottom: 12 },
31
+ headerTitle: {
32
+ fontSize: "18pt",
33
+ fontWeight: 700,
34
+ color: c.text,
35
+ letterSpacing: -0.3
36
+ },
37
+ headerRef: { fontSize: "10pt", color: c.secondary, marginTop: 1.5 },
38
+ divider: {
39
+ borderBottomWidth: 1,
40
+ borderColor: c.border,
41
+ marginBottom: 10.5
42
+ },
43
+ sectionTitle: {
44
+ fontSize: "9pt",
45
+ fontWeight: 700,
46
+ color: c.secondary,
47
+ marginBottom: 4.5,
48
+ textTransform: "uppercase",
49
+ letterSpacing: 0.3
50
+ },
51
+ infoGrid: { flexDirection: "row", gap: 12, marginBottom: 10.5 },
52
+ infoCol: { flex: "1 1 0%", flexDirection: "column", gap: 4.5 },
53
+ infoRow: { flexDirection: "row", gap: 3 },
54
+ infoLabel: { fontSize: "8pt", color: c.muted, fontWeight: 700, width: 96 },
55
+ infoValue: { fontSize: "9pt", color: c.text, flex: "1 1 0%" },
56
+ tableSection: { marginBottom: 10.5 },
57
+ tableHeader: {
58
+ flexDirection: "row",
59
+ backgroundColor: c.headerBg,
60
+ borderRadius: 2,
61
+ ...pad(4.5, 4.5),
62
+ gap: 4.5,
63
+ marginBottom: 1.5
64
+ },
65
+ tableHeaderCell: { fontSize: "8pt", fontWeight: 700, color: c.headerText },
66
+ tableRow: {
67
+ flexDirection: "row",
68
+ ...pad(4.5, 4.5),
69
+ gap: 4.5,
70
+ borderBottomWidth: 1,
71
+ borderColor: c.border
72
+ },
73
+ tableRowAlt: { backgroundColor: c.rowAlt },
74
+ tableCell: { fontSize: "8pt", color: c.text },
75
+ totalsSection: { alignItems: "flex-end", marginBottom: 10.5 },
76
+ totalsTable: {
77
+ width: "220pt",
78
+ borderWidth: 1,
79
+ borderColor: c.border,
80
+ borderRadius: 3
81
+ },
82
+ totalsRow: {
83
+ flexDirection: "row",
84
+ justifyContent: "space-between",
85
+ ...pad(3, 7.5),
86
+ borderBottomWidth: 1,
87
+ borderColor: c.border
88
+ },
89
+ totalsRowLast: {
90
+ flexDirection: "row",
91
+ justifyContent: "space-between",
92
+ ...pad(4.5, 7.5),
93
+ backgroundColor: c.headerBg,
94
+ borderRadius: 2
95
+ },
96
+ totalsLabel: { fontSize: "8pt", color: c.secondary },
97
+ totalsValue: { fontSize: "8pt", color: c.text, fontWeight: 700 },
98
+ totalsLabelBold: { fontSize: "9pt", color: c.headerText, fontWeight: 700 },
99
+ totalsValueBold: { fontSize: "9pt", color: c.headerText, fontWeight: 700 },
100
+ notesSection: {
101
+ borderWidth: 1,
102
+ borderColor: c.border,
103
+ borderRadius: 6,
104
+ padding: 7.5
105
+ },
106
+ notesText: { fontSize: "8pt", color: c.secondary, lineHeight: 1.5 },
107
+ badge: { borderRadius: 9, ...pad(4.5, 12), alignSelf: "flex-start" },
108
+ badgeText: { fontSize: "8pt", fontWeight: 700, color: c.headerText },
109
+ section: { marginBottom: 10.5 },
110
+ logoBox: {
111
+ width: "72pt",
112
+ height: "48pt",
113
+ borderRadius: 2,
114
+ justifyContent: "center",
115
+ alignItems: "center"
116
+ },
117
+ logoText: {
118
+ fontSize: "11pt",
119
+ fontWeight: 700,
120
+ color: c.secondary,
121
+ letterSpacing: 2,
122
+ textTransform: "uppercase"
123
+ },
124
+ headerCentre: {
125
+ flex: "1 1 0%",
126
+ flexDirection: "column",
127
+ alignItems: "center"
128
+ },
129
+ headerSubtitle: { fontSize: "10pt", color: c.muted, marginTop: 1.5 },
130
+ qrBox: { width: "60pt", height: "60pt", borderRadius: 2 },
131
+ heading1: {
132
+ fontSize: "16pt",
133
+ fontWeight: 700,
134
+ color: c.text,
135
+ marginBottom: 6
136
+ },
137
+ heading2: {
138
+ fontSize: "12pt",
139
+ fontWeight: 700,
140
+ color: c.text,
141
+ marginBottom: 4.5
142
+ },
143
+ heading3: {
144
+ fontSize: "10pt",
145
+ fontWeight: 700,
146
+ color: c.secondary,
147
+ marginBottom: 3
148
+ },
149
+ textBody: { fontSize: "9pt", color: c.text },
150
+ textMuted: { fontSize: "9pt", color: c.muted },
151
+ textCaption: { fontSize: "7pt", color: c.muted },
152
+ textLabel: {
153
+ fontSize: "7pt",
154
+ fontWeight: 700,
155
+ color: c.muted,
156
+ textTransform: "uppercase"
157
+ },
158
+ link: { color: c.secondary, textDecoration: "underline" },
159
+ tableEmpty: { fontSize: "8pt", color: c.muted, fontStyle: "italic" },
160
+ tableFooter: { flexDirection: "row", ...pad(4.5, 4.5), gap: 4.5 },
161
+ tableFooterCell: { fontSize: "8pt", fontWeight: 700, color: c.text },
162
+ metric: {
163
+ flex: "1 1 0%",
164
+ borderWidth: 1,
165
+ borderColor: c.border,
166
+ borderRadius: 3,
167
+ padding: 7.5,
168
+ gap: 3
169
+ },
170
+ metricValue: { fontSize: "14pt", fontWeight: 700, color: c.text },
171
+ deltaUp: { fontSize: "8pt", color: c.success },
172
+ deltaDown: { fontSize: "8pt", color: c.error },
173
+ pageNumber: { fontSize: "8pt", color: c.muted }
174
+ };
175
+ }
176
+
177
+ // src/pdf/render/context.ts
178
+ var DEFAULT_PDF_LANGUAGE2 = "en";
179
+ var NOT_IN_STANDARD_FONTS = /[\u202f\u2009\u2212]/g;
180
+ var REPLACEMENTS = {
181
+ " ": " ",
182
+ " ": " ",
183
+ "−": "-"
184
+ };
185
+ function toPdfText2(text) {
186
+ return text.replace(NOT_IN_STANDARD_FONTS, (c) => REPLACEMENTS[c] ?? c);
187
+ }
188
+ function formatEnglish(fallback, language, values) {
189
+ if (!values)
190
+ return fallback;
191
+ try {
192
+ return String(new IntlMessageFormat(fallback, language).format(values));
193
+ } catch {
194
+ return fallback;
195
+ }
196
+ }
197
+ function createPdfRenderContext2(options, renderNodes) {
198
+ const language = options.language || DEFAULT_PDF_LANGUAGE2;
199
+ const locale = options.locale ?? language;
200
+ const theme = resolvePdfTheme2(options.theme);
201
+ const context = {
202
+ language,
203
+ locale,
204
+ timeZone: options.timeZone,
205
+ theme,
206
+ styles: createPdfStyles2(theme),
207
+ t: (key, fallback, values) => toPdfText2(options.translate ? options.translate(key, fallback, values) : formatEnglish(fallback, language, values)),
208
+ format: (value, formatOptions) => toPdfText2(formatPrintValue2(value, {
209
+ locale,
210
+ timeZone: options.timeZone,
211
+ ...formatOptions
212
+ })),
213
+ renderNodes: (nodes) => renderNodes(nodes, context),
214
+ custom: options.custom ?? {}
215
+ };
216
+ return context;
217
+ }
218
+ // src/pdf/render/document.ts
219
+ import { Document } from "@react-pdf/renderer";
220
+ import { createElement as h6 } from "react";
221
+
222
+ // src/pdf/render/page.ts
223
+ import { Page, Text as Text2, View as View2 } from "@react-pdf/renderer";
224
+ import { createElement as h2 } from "react";
225
+
226
+ // src/pdf/render/nodes/blocks.ts
227
+ import { Text, View } from "@react-pdf/renderer";
228
+ import { createElement as h } from "react";
229
+ function renderKeyValue2(node, ctx) {
230
+ const { styles } = ctx;
231
+ const items = node.keepEmpty ? node.items : node.items.filter((item) => !isEmptyPrintValue2(item.value));
232
+ if (items.length === 0)
233
+ return null;
234
+ const pair = (item) => h(View, { style: styles.infoRow, wrap: false }, h(Text, { style: styles.infoLabel }, toPdfText2(item.label)), h(Text, { style: styles.infoValue }, ctx.format(item.value)));
235
+ if ((node.columns ?? 1) === 1) {
236
+ return h(View, { style: [styles.infoCol, { marginBottom: 10.5 }] }, ...items.map(pair));
237
+ }
238
+ const half = Math.ceil(items.length / 2);
239
+ return h(View, { style: styles.infoGrid }, h(View, { style: styles.infoCol }, ...items.slice(0, half).map(pair)), h(View, { style: styles.infoCol }, ...items.slice(half).map(pair)));
240
+ }
241
+ function renderTotals(node, ctx) {
242
+ const { styles } = ctx;
243
+ return h(View, { style: styles.totalsSection, wrap: false }, h(View, { style: styles.totalsTable }, ...node.rows.map((row) => h(View, { style: row.emphasis ? styles.totalsRowLast : styles.totalsRow }, h(Text, {
244
+ style: row.emphasis ? styles.totalsLabelBold : styles.totalsLabel
245
+ }, toPdfText2(row.label)), h(Text, {
246
+ style: row.emphasis ? styles.totalsValueBold : styles.totalsValue
247
+ }, ctx.format(row.value))))));
248
+ }
249
+ function formatDelta(delta, ctx) {
250
+ const text = ctx.format({
251
+ number: Math.abs(delta) / 100,
252
+ style: "percent",
253
+ fractionDigits: 1
254
+ });
255
+ return `${delta >= 0 ? "+" : "-"}${text}`;
256
+ }
257
+ function renderMetric2(node, ctx) {
258
+ const { styles } = ctx;
259
+ return h(View, { style: styles.metric, wrap: false }, h(Text, { style: styles.textLabel }, toPdfText2(node.label)), h(Text, { style: styles.metricValue }, ctx.format(node.value)), ...node.delta !== undefined ? [
260
+ h(Text, { style: node.delta >= 0 ? styles.deltaUp : styles.deltaDown }, formatDelta(node.delta, ctx))
261
+ ] : [], ...node.hint ? [h(Text, { style: styles.textCaption }, toPdfText2(node.hint))] : []);
262
+ }
263
+ function renderBadge(node, ctx) {
264
+ return h(View, {
265
+ style: [
266
+ ctx.styles.badge,
267
+ {
268
+ backgroundColor: resolvePdfColor2(node.color ?? "primary", ctx.theme)
269
+ }
270
+ ]
271
+ }, h(Text, { style: ctx.styles.badgeText }, toPdfText2(node.text)));
272
+ }
273
+ function renderPageNumber(node, ctx) {
274
+ const pageOf = node.format !== "page";
275
+ return h(Text, {
276
+ style: [ctx.styles.pageNumber, { textAlign: node.align ?? "center" }],
277
+ fixed: true,
278
+ render: ({
279
+ pageNumber,
280
+ totalPages
281
+ }) => pageOf ? ctx.t("material.print.page-of", "Page {page} of {pages}", {
282
+ page: pageNumber,
283
+ pages: totalPages
284
+ }) : ctx.t("material.print.page", "Page {page}", { page: pageNumber })
285
+ });
286
+ }
287
+
288
+ // src/pdf/render/page.ts
289
+ var DEFAULT_PDF_MARGINS2 = { top: 21, right: 24, bottom: 21, left: 24 };
290
+ var DEFAULT_FOOTER_HEIGHT2 = 24;
291
+ function resolvePdfMargins2(margins) {
292
+ if (typeof margins === "number") {
293
+ return { top: margins, right: margins, bottom: margins, left: margins };
294
+ }
295
+ const box = margins ?? {};
296
+ const d = DEFAULT_PDF_MARGINS2;
297
+ return {
298
+ top: box.top ?? box.y ?? d.top,
299
+ right: box.right ?? box.x ?? d.right,
300
+ bottom: box.bottom ?? box.y ?? d.bottom,
301
+ left: box.left ?? box.x ?? d.left
302
+ };
303
+ }
304
+ function renderWatermark(watermark, ctx) {
305
+ const mark = typeof watermark === "string" ? { text: watermark } : watermark;
306
+ return h2(View2, {
307
+ fixed: true,
308
+ style: {
309
+ position: "absolute",
310
+ top: 0,
311
+ right: 0,
312
+ bottom: 0,
313
+ left: 0,
314
+ justifyContent: "center",
315
+ alignItems: "center"
316
+ }
317
+ }, h2(Text2, {
318
+ style: {
319
+ fontSize: mark.fontSize ?? 72,
320
+ fontWeight: 700,
321
+ color: resolvePdfColor2(mark.color ?? "muted", ctx.theme),
322
+ opacity: mark.opacity ?? 0.08,
323
+ transform: `rotate(${-(mark.angle ?? 35)}deg)`
324
+ }
325
+ }, toPdfText2(mark.text)));
326
+ }
327
+ function renderFooterRow(footer, pageNumber, numberFirst, margins, height) {
328
+ const parts = [
329
+ ...footer ? [h2(View2, { key: "footer", style: { flex: 1 } }, footer)] : [],
330
+ ...pageNumber ? [
331
+ h2(View2, { key: "number", style: footer ? { marginLeft: 12 } : { flex: 1 } }, pageNumber)
332
+ ] : []
333
+ ];
334
+ if (numberFirst && footer && pageNumber) {
335
+ parts.reverse();
336
+ parts[0] = h2(View2, { key: "number", style: { marginRight: 12 } }, pageNumber);
337
+ }
338
+ return h2(View2, {
339
+ fixed: true,
340
+ style: {
341
+ position: "absolute",
342
+ left: margins.left,
343
+ right: margins.right,
344
+ bottom: margins.bottom,
345
+ height,
346
+ flexDirection: "row",
347
+ alignItems: "flex-end"
348
+ }
349
+ }, ...parts);
350
+ }
351
+ function renderPdfPage2(options, parts, ctx) {
352
+ const margins = resolvePdfMargins2(options.margins);
353
+ const numbers = options.pageNumbers;
354
+ const hasFooter = Boolean(parts.footer) || Boolean(numbers);
355
+ const footerHeight = options.footerHeight ?? DEFAULT_FOOTER_HEIGHT2;
356
+ const pageNumber = numbers && renderPageNumber({
357
+ type: "pageNumber",
358
+ ...typeof numbers === "object" ? numbers : {}
359
+ }, ctx);
360
+ const numberFirst = typeof numbers === "object" && numbers.align === "left";
361
+ return h2(Page, {
362
+ size: options.size ?? "A4",
363
+ orientation: options.orientation ?? "portrait",
364
+ wrap: true,
365
+ style: {
366
+ ...ctx.styles.page,
367
+ paddingTop: margins.top,
368
+ paddingRight: margins.right,
369
+ paddingLeft: margins.left,
370
+ paddingBottom: margins.bottom + (hasFooter ? footerHeight : 0)
371
+ }
372
+ }, ...options.watermark ? [renderWatermark(options.watermark, ctx)] : [], ...parts.header ? [h2(View2, { fixed: true }, parts.header)] : [], ...parts.body, ...hasFooter ? [
373
+ renderFooterRow(parts.footer, pageNumber, numberFirst, margins, footerHeight)
374
+ ] : []);
375
+ }
376
+
377
+ // src/pdf/render/render-node.ts
378
+ import { createElement, Fragment } from "react";
379
+
380
+ // src/pdf/render/nodes/header.ts
381
+ import { Image, Text as Text3, View as View3 } from "@react-pdf/renderer";
382
+ import { createElement as h3 } from "react";
383
+ var LOGO = { width: 72, height: 48 };
384
+ var QR = 60;
385
+ function logoBox(node, ctx) {
386
+ const { styles, theme } = ctx;
387
+ if (node.logo) {
388
+ const logo = typeof node.logo === "string" ? { src: node.logo } : node.logo;
389
+ const width = logo.width ?? LOGO.width;
390
+ const height = logo.height ?? LOGO.height;
391
+ return h3(Image, {
392
+ src: logo.src,
393
+ style: { width, height, objectFit: "contain", objectPosition: "left" }
394
+ });
395
+ }
396
+ if (node.logoText) {
397
+ return h3(View3, { style: [styles.logoBox, { backgroundColor: theme.colors.logoBg }] }, h3(Text3, { style: styles.logoText }, toPdfText2(node.logoText)));
398
+ }
399
+ return null;
400
+ }
401
+ function renderHeader2(node, ctx) {
402
+ const { styles } = ctx;
403
+ const logo = logoBox(node, ctx);
404
+ const qr = node.qrDataUrl ? h3(Image, { src: node.qrDataUrl, style: styles.qrBox }) : null;
405
+ const logoWidth = node.logo && typeof node.logo === "object" ? node.logo.width ?? LOGO.width : LOGO.width;
406
+ const side = Math.max(logo ? logoWidth : 0, qr ? QR : 0);
407
+ const spacer = h3(View3, { style: { width: side } });
408
+ const reference = node.reference ? toPdfText2(`${node.referencePrefix ?? "#"}${node.reference}`) : null;
409
+ return h3(View3, { style: styles.header }, ...side ? [h3(View3, { style: { width: side } }, logo ?? spacer)] : [], h3(View3, { style: styles.headerCentre }, h3(Text3, { style: styles.headerTitle }, toPdfText2(node.title)), ...node.subtitle ? [h3(Text3, { style: styles.headerSubtitle }, toPdfText2(node.subtitle))] : [], ...reference ? [h3(Text3, { style: styles.headerRef }, reference)] : []), ...side ? [
410
+ h3(View3, { style: { width: side, alignItems: "flex-end" } }, qr ?? spacer)
411
+ ] : []);
412
+ }
413
+
414
+ // src/pdf/render/nodes/layout.ts
415
+ import { Image as Image2, Link, Text as Text4, View as View4 } from "@react-pdf/renderer";
416
+ import { createElement as h4 } from "react";
417
+ function toStyle(style, ctx) {
418
+ if (!style)
419
+ return {};
420
+ const { color, backgroundColor, borderColor, fontFamily, ...rest } = style;
421
+ return {
422
+ ...rest,
423
+ ...fontFamily && Object.keys(ctx.theme.fonts).includes(fontFamily) && {
424
+ fontFamily: ctx.theme.fonts[fontFamily]
425
+ },
426
+ ...color && { color: resolvePdfColor2(color, ctx.theme) },
427
+ ...backgroundColor && {
428
+ backgroundColor: resolvePdfColor2(backgroundColor, ctx.theme)
429
+ },
430
+ ...borderColor && {
431
+ borderColor: resolvePdfColor2(borderColor, ctx.theme)
432
+ }
433
+ };
434
+ }
435
+ var ALIGN = {
436
+ start: "flex-start",
437
+ center: "center",
438
+ end: "flex-end",
439
+ stretch: "stretch"
440
+ };
441
+ var JUSTIFY = {
442
+ start: "flex-start",
443
+ center: "center",
444
+ end: "flex-end",
445
+ between: "space-between"
446
+ };
447
+ var renderStack = (node, ctx) => h4(View4, {
448
+ style: {
449
+ flexDirection: "column",
450
+ gap: node.gap ?? 0,
451
+ ...toStyle(node.style, ctx)
452
+ }
453
+ }, ...ctx.renderNodes(node.children));
454
+ var renderRow = (node, ctx) => h4(View4, {
455
+ style: {
456
+ flexDirection: "row",
457
+ gap: node.gap ?? 12,
458
+ ...node.align && { alignItems: ALIGN[node.align] },
459
+ ...node.justify && { justifyContent: JUSTIFY[node.justify] },
460
+ ...toStyle(node.style, ctx)
461
+ }
462
+ }, ...ctx.renderNodes(node.children));
463
+ function renderInline(inline, ctx) {
464
+ if (typeof inline === "string")
465
+ return toPdfText2(inline);
466
+ const style = {
467
+ ...inline.bold && { fontWeight: 700 },
468
+ ...inline.italic && { fontStyle: "italic" },
469
+ ...inline.color && { color: resolvePdfColor2(inline.color, ctx.theme) },
470
+ ...inline.href && ctx.styles.link
471
+ };
472
+ return inline.href ? h4(Link, { src: inline.href, style }, toPdfText2(inline.text)) : h4(Text4, { style }, toPdfText2(inline.text));
473
+ }
474
+ var TEXT_VARIANTS = {
475
+ body: "textBody",
476
+ muted: "textMuted",
477
+ caption: "textCaption",
478
+ label: "textLabel"
479
+ };
480
+ var renderText = (node, ctx) => h4(Text4, {
481
+ style: {
482
+ ...ctx.styles[TEXT_VARIANTS[node.variant ?? "body"]],
483
+ ...toStyle(node.style, ctx)
484
+ }
485
+ }, ...typeof node.content === "string" ? [toPdfText2(node.content)] : node.content.map((inline) => renderInline(inline, ctx)));
486
+ var renderHeading = (node, ctx) => h4(Text4, {
487
+ style: ctx.styles[`heading${node.level ?? 1}`],
488
+ minPresenceAhead: 24
489
+ }, toPdfText2(node.text));
490
+ var renderSection = (node, ctx) => h4(View4, { style: ctx.styles.section }, h4(Text4, { style: ctx.styles.sectionTitle, minPresenceAhead: 24 }, toPdfText2(node.title)), ...ctx.renderNodes(node.children));
491
+ var renderImage = (node) => h4(Image2, {
492
+ src: node.src,
493
+ style: {
494
+ ...node.width !== undefined && { width: node.width },
495
+ ...node.height !== undefined && { height: node.height },
496
+ objectFit: node.fit ?? "contain"
497
+ }
498
+ });
499
+ var renderLink = (node, ctx) => h4(Text4, null, h4(Link, { src: node.href, style: ctx.styles.link }, toPdfText2(node.text)));
500
+ var renderSpacer = (node) => h4(View4, { style: { height: node.size } });
501
+ var renderDivider = (_node, ctx) => h4(View4, { style: ctx.styles.divider });
502
+ var renderPageBreak = () => h4(View4, { break: true });
503
+
504
+ // src/pdf/render/nodes/table.ts
505
+ import { Text as Text5, View as View5 } from "@react-pdf/renderer";
506
+ import { createElement as h5 } from "react";
507
+ function columnBox(column) {
508
+ if (column.width !== undefined) {
509
+ return { width: column.width, flexGrow: 0, flexShrink: 0 };
510
+ }
511
+ return { flex: column.flex ?? 1 };
512
+ }
513
+ function cells(columns, values, cellStyle, ctx) {
514
+ return columns.map((column, index) => h5(Text5, {
515
+ style: [
516
+ cellStyle,
517
+ columnBox(column),
518
+ { textAlign: column.align ?? "left" }
519
+ ]
520
+ }, ctx.format(values[index])));
521
+ }
522
+ function renderFooter(node, ctx) {
523
+ const { footer = [], columns, labelTotals } = node;
524
+ if (footer.length === 0)
525
+ return [];
526
+ const total = ctx.t("material.print.table.total", "Total");
527
+ return [
528
+ h5(View5, { wrap: false }, ...footer.map(([first, ...rest]) => h5(View5, { style: ctx.styles.tableFooter }, ...cells(columns, [labelTotals && first == null ? total : first, ...rest], ctx.styles.tableFooterCell, ctx))))
529
+ ];
530
+ }
531
+ function renderTable2(node, ctx) {
532
+ const { styles } = ctx;
533
+ const {
534
+ columns,
535
+ rows,
536
+ striped = true,
537
+ repeatHeader = true,
538
+ keepRowsWhole = true
539
+ } = node;
540
+ if (rows.length === 0 && node.hideWhenEmpty)
541
+ return null;
542
+ const headerRow = h5(View5, { style: styles.tableHeader, fixed: repeatHeader, minPresenceAhead: 24 }, ...columns.map((column) => h5(Text5, {
543
+ style: [
544
+ styles.tableHeaderCell,
545
+ columnBox(column),
546
+ { textAlign: column.align ?? "left" }
547
+ ]
548
+ }, toPdfText2(column.label))));
549
+ const bodyRows = rows.length === 0 ? [
550
+ h5(View5, { style: styles.tableRow, wrap: false }, h5(Text5, { style: [styles.tableEmpty, { flex: 1 }] }, node.emptyText !== undefined ? toPdfText2(node.emptyText) : ctx.t("material.print.table.empty", "No rows")))
551
+ ] : rows.map((values, index) => h5(View5, {
552
+ style: [
553
+ styles.tableRow,
554
+ striped && index % 2 === 1 ? styles.tableRowAlt : {}
555
+ ],
556
+ wrap: !keepRowsWhole
557
+ }, ...cells(columns, values, styles.tableCell, ctx)));
558
+ const footerRows = renderFooter(node, ctx);
559
+ return h5(View5, { style: styles.tableSection }, headerRow, ...bodyRows, ...footerRows);
560
+ }
561
+
562
+ // src/pdf/render/render-node.ts
563
+ var own = (record, key) => Object.keys(record).includes(key);
564
+ var RENDERERS = {
565
+ stack: renderStack,
566
+ row: renderRow,
567
+ text: renderText,
568
+ heading: renderHeading,
569
+ section: renderSection,
570
+ image: renderImage,
571
+ link: renderLink,
572
+ spacer: renderSpacer,
573
+ divider: renderDivider,
574
+ pageBreak: renderPageBreak,
575
+ table: renderTable2,
576
+ keyValue: renderKeyValue2,
577
+ totals: renderTotals,
578
+ metric: renderMetric2,
579
+ badge: renderBadge,
580
+ header: renderHeader2,
581
+ pageNumber: renderPageNumber,
582
+ custom: (node, context) => {
583
+ const render = own(context.custom, node.name) ? context.custom[node.name] : undefined;
584
+ if (!render) {
585
+ throw new Error(`[pdf] No renderer for the custom node "${node.name}": pass it in \`custom\` when rendering.`);
586
+ }
587
+ return render(node.props ?? {}, context);
588
+ }
589
+ };
590
+ function renderPdfNode2(node, context) {
591
+ const render = own(RENDERERS, node.type) ? RENDERERS[node.type] : undefined;
592
+ if (!render) {
593
+ throw new Error(`[pdf] Unknown node type "${node.type}".`);
594
+ }
595
+ return render(node, context);
596
+ }
597
+ function renderPdfNodes2(nodes, context) {
598
+ return (nodes ?? []).map((node, index) => createElement(Fragment, { key: index }, renderPdfNode2(node, context)));
599
+ }
600
+
601
+ // src/pdf/render/document.ts
602
+ function createPdfContext2(options = {}) {
603
+ return createPdfRenderContext2(options, renderPdfNodes2);
604
+ }
605
+ function renderPdfDocumentShell2(options, pages) {
606
+ const { title, author, subject, keywords, creator, producer, language } = options;
607
+ return h6(Document, {
608
+ title,
609
+ author,
610
+ subject,
611
+ keywords,
612
+ creator,
613
+ producer: producer ?? creator,
614
+ language
615
+ }, ...pages);
616
+ }
617
+ function renderPdfElement2(doc, options = {}) {
618
+ if (doc.version !== 1) {
619
+ throw new Error(`[pdf] Unsupported document version ${String(doc.version)}: this version renders version 1.`);
620
+ }
621
+ const context = createPdfContext2({
622
+ language: doc.language,
623
+ locale: doc.locale,
624
+ timeZone: doc.timeZone,
625
+ theme: doc.theme,
626
+ ...options
627
+ });
628
+ const pages = doc.pages.map((page) => renderPdfPage2(page, {
629
+ header: page.header?.length ? context.renderNodes(page.header) : undefined,
630
+ footer: page.footer?.length ? context.renderNodes(page.footer) : undefined,
631
+ body: context.renderNodes(page.body)
632
+ }, context));
633
+ return renderPdfDocumentShell2({
634
+ ...doc.meta,
635
+ creator: doc.meta?.creator ?? options.defaultCreator,
636
+ language: doc.language
637
+ }, pages);
638
+ }
639
+ export { createPdfStyles2, DEFAULT_PDF_LANGUAGE2, toPdfText2, createPdfRenderContext2, renderKeyValue2, renderMetric2, DEFAULT_PDF_MARGINS2, DEFAULT_FOOTER_HEIGHT2, resolvePdfMargins2, renderPdfPage2, renderHeader2, renderTable2, renderPdfNode2, renderPdfNodes2, createPdfContext2, renderPdfDocumentShell2, renderPdfElement2 };
640
+
641
+ //# debugId=EA542ADA03C5516564756E2164756E21
642
+ //# sourceMappingURL=index-z3yjh0a8.js.map