coject 2.4.50 → 2.4.52

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 (75) hide show
  1. package/dist/cjs/Builder/Header/theme.d.ts +1 -1
  2. package/dist/cjs/Builder/Page/theme.d.ts +1 -1
  3. package/dist/cjs/Builder/Sidebar/theme.d.ts +1 -1
  4. package/dist/cjs/Components/Checkbox/theme.d.ts +1 -1
  5. package/dist/cjs/Components/CojectReport/PdfComponents/PdfBody.d.ts +11 -0
  6. package/dist/cjs/Components/CojectReport/PdfComponents/PdfBody.js +15 -0
  7. package/dist/cjs/Components/CojectReport/PdfComponents/PdfBody.js.map +1 -0
  8. package/dist/cjs/Components/CojectReport/PdfComponents/PdfFooter.d.ts +10 -0
  9. package/dist/cjs/Components/CojectReport/PdfComponents/PdfFooter.js +15 -0
  10. package/dist/cjs/Components/CojectReport/PdfComponents/PdfFooter.js.map +1 -0
  11. package/dist/cjs/Components/CojectReport/PdfComponents/PdfHeader.d.ts +10 -0
  12. package/dist/cjs/Components/CojectReport/PdfComponents/PdfHeader.js +15 -0
  13. package/dist/cjs/Components/CojectReport/PdfComponents/PdfHeader.js.map +1 -0
  14. package/dist/cjs/Components/CojectReport/PdfComponents/ProcessItem.d.ts +12 -0
  15. package/dist/cjs/Components/CojectReport/PdfComponents/ProcessItem.js +806 -0
  16. package/dist/cjs/Components/CojectReport/PdfComponents/ProcessItem.js.map +1 -0
  17. package/dist/cjs/Components/CojectReport/PdfContainer.d.ts +9 -0
  18. package/dist/cjs/Components/CojectReport/PdfContainer.js +206 -0
  19. package/dist/cjs/Components/CojectReport/PdfContainer.js.map +1 -0
  20. package/dist/cjs/Components/CojectReport/index.d.ts +14 -0
  21. package/dist/cjs/Components/CojectReport/index.js +27 -0
  22. package/dist/cjs/Components/CojectReport/index.js.map +1 -0
  23. package/dist/cjs/Components/DatePicker/theme.d.ts +1 -1
  24. package/dist/cjs/Components/Grid/index.js +15 -11
  25. package/dist/cjs/Components/Grid/index.js.map +1 -1
  26. package/dist/cjs/Components/Grid/theme.d.ts +1 -1
  27. package/dist/cjs/Components/Input/theme.d.ts +1 -1
  28. package/dist/cjs/Components/InputLabel/theme.d.ts +1 -1
  29. package/dist/cjs/Components/Modal/theme.d.ts +1 -1
  30. package/dist/cjs/Components/PDFGenerator/theme.d.ts +1 -1
  31. package/dist/cjs/Components/Scanner/theme.d.ts +1 -1
  32. package/dist/cjs/Components/Select/theme.d.ts +1 -1
  33. package/dist/cjs/Components/Switch/theme.d.ts +1 -1
  34. package/dist/cjs/Components/Upload/theme.d.ts +1 -1
  35. package/dist/cjs/Components/index.d.ts +1 -0
  36. package/dist/cjs/Components/index.js +4 -1
  37. package/dist/cjs/Components/index.js.map +1 -1
  38. package/dist/esm/Builder/Header/theme.d.ts +1 -1
  39. package/dist/esm/Builder/Page/theme.d.ts +1 -1
  40. package/dist/esm/Builder/Sidebar/theme.d.ts +1 -1
  41. package/dist/esm/Components/Checkbox/theme.d.ts +1 -1
  42. package/dist/esm/Components/CojectReport/PdfComponents/PdfBody.d.ts +11 -0
  43. package/dist/esm/Components/CojectReport/PdfComponents/PdfBody.js +10 -0
  44. package/dist/esm/Components/CojectReport/PdfComponents/PdfBody.js.map +1 -0
  45. package/dist/esm/Components/CojectReport/PdfComponents/PdfFooter.d.ts +10 -0
  46. package/dist/esm/Components/CojectReport/PdfComponents/PdfFooter.js +10 -0
  47. package/dist/esm/Components/CojectReport/PdfComponents/PdfFooter.js.map +1 -0
  48. package/dist/esm/Components/CojectReport/PdfComponents/PdfHeader.d.ts +10 -0
  49. package/dist/esm/Components/CojectReport/PdfComponents/PdfHeader.js +10 -0
  50. package/dist/esm/Components/CojectReport/PdfComponents/PdfHeader.js.map +1 -0
  51. package/dist/esm/Components/CojectReport/PdfComponents/ProcessItem.d.ts +12 -0
  52. package/dist/esm/Components/CojectReport/PdfComponents/ProcessItem.js +801 -0
  53. package/dist/esm/Components/CojectReport/PdfComponents/ProcessItem.js.map +1 -0
  54. package/dist/esm/Components/CojectReport/PdfContainer.d.ts +9 -0
  55. package/dist/esm/Components/CojectReport/PdfContainer.js +201 -0
  56. package/dist/esm/Components/CojectReport/PdfContainer.js.map +1 -0
  57. package/dist/esm/Components/CojectReport/index.d.ts +14 -0
  58. package/dist/esm/Components/CojectReport/index.js +20 -0
  59. package/dist/esm/Components/CojectReport/index.js.map +1 -0
  60. package/dist/esm/Components/DatePicker/theme.d.ts +1 -1
  61. package/dist/esm/Components/Grid/index.js +15 -11
  62. package/dist/esm/Components/Grid/index.js.map +1 -1
  63. package/dist/esm/Components/Grid/theme.d.ts +1 -1
  64. package/dist/esm/Components/Input/theme.d.ts +1 -1
  65. package/dist/esm/Components/InputLabel/theme.d.ts +1 -1
  66. package/dist/esm/Components/Modal/theme.d.ts +1 -1
  67. package/dist/esm/Components/PDFGenerator/theme.d.ts +1 -1
  68. package/dist/esm/Components/Scanner/theme.d.ts +1 -1
  69. package/dist/esm/Components/Select/theme.d.ts +1 -1
  70. package/dist/esm/Components/Switch/theme.d.ts +1 -1
  71. package/dist/esm/Components/Upload/theme.d.ts +1 -1
  72. package/dist/esm/Components/index.d.ts +1 -0
  73. package/dist/esm/Components/index.js +2 -0
  74. package/dist/esm/Components/index.js.map +1 -1
  75. package/package.json +4 -2
@@ -0,0 +1,801 @@
1
+ import React from 'react';
2
+ // React Pdf
3
+ import { Text, View, Image } from '@react-pdf/renderer';
4
+ // QR Code
5
+ import QRCodeStyling from 'qr-code-styling';
6
+ // Function to get decimal value
7
+ const getDecimal = (value) => {
8
+ if (value === null || value === undefined)
9
+ return 0;
10
+ if (typeof value === "number")
11
+ return value;
12
+ const parsed = parseFloat(value);
13
+ return isNaN(parsed) ? 0 : parsed;
14
+ };
15
+ // Function to handle text wrapping
16
+ const ensureWrap = (val) => {
17
+ if (val === null || val === undefined)
18
+ return "";
19
+ const str = String(val);
20
+ if (/[\u0600-\u06FF]/.test(str))
21
+ return str;
22
+ return str.split(' ').map(word => {
23
+ if (word.length > 8) {
24
+ return word.split('').join('\u200B');
25
+ }
26
+ return word;
27
+ }).join(' ');
28
+ };
29
+ // Function to get common styles
30
+ const ProcessItemCommonStyles = (item, json) => {
31
+ const x = getDecimal(item?.x);
32
+ const y = getDecimal(item?.y);
33
+ const width = getDecimal(item?.width);
34
+ const height = getDecimal(item?.height);
35
+ const styles = {
36
+ position: 'absolute',
37
+ left: `${x / json.PxPerCmH}cm`,
38
+ top: `${y / json.PxPerCmV}cm`,
39
+ width: `${width / json.PxPerCmH}cm`,
40
+ height: `${height / json.PxPerCmV}cm`,
41
+ zIndex: 1
42
+ };
43
+ if (item?.fontFamily)
44
+ styles.fontFamily = item.fontFamily;
45
+ if (item?.fontSize)
46
+ styles.fontSize = `${item.fontSize}pt`;
47
+ if (item?.fontStyle) {
48
+ const stylesList = item.fontStyle.split(' ');
49
+ if (stylesList.includes('font-bold'))
50
+ styles.fontWeight = 'bold';
51
+ if (stylesList.includes('font-italic'))
52
+ styles.fontStyle = 'italic';
53
+ if (stylesList.includes('font-underline'))
54
+ styles.textDecoration = 'underline';
55
+ }
56
+ if (item?.color)
57
+ styles.color = item.color;
58
+ if (item?.textAlign)
59
+ styles.textAlign = item.textAlign;
60
+ if (item?.characterSpacing) {
61
+ const spacing = getDecimal(item.characterSpacing);
62
+ styles.characterSpacing = spacing.toString();
63
+ styles.letterSpacing = `${spacing / 1000}`;
64
+ styles.wordSpacing = `${spacing / 1000}em`;
65
+ }
66
+ if (item?.lineHeight) {
67
+ const newHeight = getDecimal(item.lineHeight);
68
+ styles.lineHeight = newHeight > 3 ? `${newHeight}pt` : newHeight.toString();
69
+ }
70
+ if (item?.border) {
71
+ switch (item.border) {
72
+ case "single":
73
+ styles.border = "1px solid black";
74
+ break;
75
+ case "double":
76
+ styles.border = "3px double black";
77
+ break;
78
+ case "dashed":
79
+ styles.border = "1px dashed black";
80
+ break;
81
+ case "dotted":
82
+ styles.border = "1px dotted black";
83
+ break;
84
+ case "dropShadow":
85
+ styles.boxShadow = "2px 2px 6px rgba(0, 0, 0, 0.4)";
86
+ break;
87
+ default:
88
+ break;
89
+ }
90
+ }
91
+ if (item?.backgroundColor)
92
+ styles.backgroundColor = item.backgroundColor;
93
+ if (item?.textRotation) {
94
+ const rotation = getDecimal(item.textRotation);
95
+ styles.transform = `rotate(${rotation}deg)`;
96
+ styles.transformOrigin = 'left top';
97
+ }
98
+ return styles;
99
+ };
100
+ const ProcessTextObjectItem = (item, json) => {
101
+ const styles = ProcessItemCommonStyles(item, json);
102
+ if (item?.hyperlink && item.hyperlink.trim() !== "") {
103
+ styles.textDecoration = "underline";
104
+ styles.color = "blue";
105
+ styles.hyperlink = item.hyperlink;
106
+ }
107
+ return styles;
108
+ };
109
+ const ProcessDatabaseFieldItem = (item, json) => {
110
+ return ProcessItemCommonStyles(item, json);
111
+ };
112
+ const ProcessPictureItem = (item, json) => {
113
+ const x = getDecimal(item?.x);
114
+ const y = getDecimal(item?.y);
115
+ const width = getDecimal(item?.width);
116
+ const height = getDecimal(item?.height);
117
+ const styles = {
118
+ position: 'absolute',
119
+ left: `${x / json.PxPerCmH}cm`,
120
+ top: `${y / json.PxPerCmV}cm`,
121
+ width: `${width / json.PxPerCmH}cm`,
122
+ height: `${height / json.PxPerCmV}cm`,
123
+ };
124
+ if (item?.rounded) {
125
+ styles.borderRadius = 50;
126
+ }
127
+ if (item?.layerPosition === "back") {
128
+ styles.zIndex = 2;
129
+ }
130
+ else {
131
+ styles.zIndex = 0;
132
+ }
133
+ if (item?.border) {
134
+ switch (item.border) {
135
+ case "single":
136
+ styles.border = "1px solid black";
137
+ break;
138
+ case "double":
139
+ styles.border = "3px double black";
140
+ break;
141
+ case "dashed":
142
+ styles.border = "1px dashed black";
143
+ break;
144
+ case "dotted":
145
+ styles.border = "1px dotted black";
146
+ break;
147
+ case "dropShadow":
148
+ styles.boxShadow = "2px 2px 6px rgba(0, 0, 0, 0.4)";
149
+ break;
150
+ default:
151
+ break;
152
+ }
153
+ }
154
+ return styles;
155
+ };
156
+ const ProcessSpecialFieldItem = (item, json) => {
157
+ return ProcessItemCommonStyles(item, json);
158
+ };
159
+ const ProcessTableObjectItem = (item, json) => {
160
+ const x = getDecimal(item?.x);
161
+ const y = getDecimal(item?.y);
162
+ const width = getDecimal(item?.width);
163
+ const styles = {
164
+ position: 'absolute',
165
+ left: `${x / json.PxPerCmH}cm`,
166
+ top: `${y / json.PxPerCmV}cm`,
167
+ width: `${width / json.PxPerCmH}cm`,
168
+ zIndex: 1
169
+ };
170
+ return styles;
171
+ };
172
+ const ProcessQrCodeObjectItem = (item, json) => {
173
+ const x = getDecimal(item?.x);
174
+ const y = getDecimal(item?.y);
175
+ const width = getDecimal(item?.width);
176
+ const height = getDecimal(item?.height);
177
+ const styles = {
178
+ position: 'absolute',
179
+ left: `${x / json.PxPerCmH}cm`,
180
+ top: `${y / json.PxPerCmV}cm`,
181
+ width: `${width / json.PxPerCmH}cm`,
182
+ height: `${height / json.PxPerCmV}cm`,
183
+ zIndex: 1
184
+ };
185
+ return styles;
186
+ };
187
+ const QrCodeGeneratedImage = ({ item, styles }) => {
188
+ const generateQrCode = async () => {
189
+ if (!item?.data)
190
+ return "";
191
+ const size = Math.max(getDecimal(item?.width) || 300, 300);
192
+ const qrContent = unescape(encodeURIComponent(item?.data || ""));
193
+ let base64Image = "";
194
+ if (item?.image && item.image.startsWith("http")) {
195
+ const proxiedUrl = `https://wsrv.nl/?url=${encodeURIComponent(item.image)}&w=150&h=150&fit=contain&output=png`;
196
+ try {
197
+ const res = await fetch(proxiedUrl);
198
+ const blob = await res.blob();
199
+ base64Image = await new Promise(resolve => {
200
+ const reader = new FileReader();
201
+ reader.onloadend = () => resolve(reader.result || "");
202
+ reader.readAsDataURL(blob);
203
+ });
204
+ }
205
+ catch (e) {
206
+ console.error("Failed to proxy image CORS", e);
207
+ base64Image = proxiedUrl;
208
+ }
209
+ }
210
+ else {
211
+ base64Image = item?.image || "";
212
+ }
213
+ const qrCode = new QRCodeStyling({
214
+ width: size,
215
+ height: size,
216
+ data: qrContent,
217
+ image: base64Image,
218
+ margin: getDecimal(item?.margin) || 0,
219
+ qrOptions: {
220
+ errorCorrectionLevel: item?.image ? "H" : (item?.errorCorrectionLevel || "M")
221
+ },
222
+ dotsOptions: {
223
+ type: item?.dotsOptionsType === "rounded" ? "rounded" : (item?.dotsOptionsType || "square"),
224
+ color: item?.dotsOptionsColor || "#000000"
225
+ },
226
+ cornersSquareOptions: {
227
+ type: item?.cornersSquareOptionsType === "rounded" ? "extra-rounded" : (item?.cornersSquareOptionsType || "square"),
228
+ color: item?.cornersSquareOptionsColor || "#000000"
229
+ },
230
+ cornersDotOptions: {
231
+ type: item?.cornersDotOptionsType === "rounded" ? "dot" : (item?.cornersDotOptionsType || "square"),
232
+ color: item?.cornersDotOptionsColor || "#000000"
233
+ },
234
+ backgroundOptions: {
235
+ color: item?.backgroundOptionsColor || "#ffffff"
236
+ },
237
+ imageOptions: {
238
+ crossOrigin: "anonymous",
239
+ margin: 2,
240
+ imageSize: 0.3
241
+ }
242
+ });
243
+ try {
244
+ const buffer = await qrCode.getRawData("png");
245
+ if (buffer) {
246
+ return new Promise((resolve) => {
247
+ const reader = new FileReader();
248
+ reader.onloadend = () => resolve(reader.result || "");
249
+ reader.readAsDataURL(buffer);
250
+ });
251
+ }
252
+ }
253
+ catch (error) {
254
+ console.error("Failed to generate QR Code locally:", error);
255
+ return `https://quickchart.io/qr?size=300&text=${encodeURIComponent(item?.data || "")}&centerImageUrl=${encodeURIComponent(item?.image || "")}&dark=${(item?.dotsOptionsColor || "#000000").replace("#", "")}&margin=${getDecimal(item?.margin) || 0}`;
256
+ }
257
+ };
258
+ return (React.createElement(View, { style: { ...styles } }, item?.data ? (React.createElement(Image, { src: generateQrCode(), style: { width: '100%', height: '100%', objectFit: 'contain' }, cache: false })) : null));
259
+ };
260
+ const processTableColumns = (item, json) => {
261
+ const columns = item?.columns;
262
+ if (!columns || typeof columns !== 'object')
263
+ return {};
264
+ const visibleKeys = Object.keys(columns).filter(key => !columns[key]?.hide);
265
+ visibleKeys.sort((a, b) => (columns[a]?.ordinal ?? 0) - (columns[b]?.ordinal ?? 0));
266
+ const firstColumnName = visibleKeys[0];
267
+ const lastColumnName = visibleKeys[visibleKeys.length - 1];
268
+ const tableTotalPx = getDecimal(item?.width) || 1064;
269
+ const pxPerCmH = json.PxPerCmH || 53.057;
270
+ let totalSizedWidthPx = 0;
271
+ const columnWidthsPx = {};
272
+ visibleKeys.forEach((key) => {
273
+ const col = columns[key];
274
+ if (col?.width) {
275
+ const widthPx = parseFloat(col.width);
276
+ if (!isNaN(widthPx)) {
277
+ columnWidthsPx[key] = widthPx;
278
+ totalSizedWidthPx += widthPx;
279
+ }
280
+ }
281
+ });
282
+ const flexColumnCount = visibleKeys.filter(k => !columnWidthsPx[k]).length;
283
+ const remainingPx = Math.max(0, tableTotalPx - totalSizedWidthPx);
284
+ const flexWidthPx = flexColumnCount > 0 ? remainingPx / flexColumnCount : 0;
285
+ const updatedColumns = {};
286
+ visibleKeys.forEach((key) => {
287
+ const col = columns[key];
288
+ const styleDict = {
289
+ fontSize: '12pt',
290
+ padding: '0.1cm 0.2cm',
291
+ minHeight: '1cm',
292
+ display: 'flex',
293
+ flexDirection: 'column',
294
+ justifyContent: 'center',
295
+ borderBottom: '1px solid #000',
296
+ borderRight: '1px solid #000',
297
+ zIndex: 1,
298
+ fontWeight: 'bold'
299
+ };
300
+ if (col?.fontSize)
301
+ styleDict.fontSize = `${col.fontSize}pt`;
302
+ if (col?.color)
303
+ styleDict.color = col.color;
304
+ if (col?.backgroundColor)
305
+ styleDict.backgroundColor = col.backgroundColor;
306
+ if (col?.textAlign)
307
+ styleDict.textAlign = col.textAlign;
308
+ if ((key === lastColumnName && json.Direction === 'rtl') ||
309
+ (key === firstColumnName && json.Direction === 'ltr')) {
310
+ styleDict.borderLeft = '1px solid #000';
311
+ }
312
+ if (columnWidthsPx[key]) {
313
+ styleDict.width = `${columnWidthsPx[key] / pxPerCmH}cm`;
314
+ }
315
+ else {
316
+ styleDict.width = `${flexWidthPx / pxPerCmH}cm`;
317
+ }
318
+ updatedColumns[key] = {
319
+ ordinal: col?.ordinal ?? 0,
320
+ text: col?.text ?? key,
321
+ isCustom: col?.isCustom ?? false,
322
+ valueSource: col?.valueSource ?? null,
323
+ staticValue: col?.staticValue ?? null,
324
+ parameter: col?.parameter ?? null,
325
+ Styles: styleDict,
326
+ merge: col?.merge,
327
+ colSpanLabel: col?.colSpanLabel,
328
+ };
329
+ });
330
+ return updatedColumns;
331
+ };
332
+ // Returns the value of a special field (like page number, date, etc.) based on the given key and context
333
+ const getSpecialFieldValue = (key, context) => {
334
+ switch (key) {
335
+ case 'pageNumber': return context.pageNumber || 1;
336
+ case 'totalPages': return context.totalPages || 1;
337
+ case 'pageXofY':
338
+ if (context?.dir === 'rtl') {
339
+ return `الصفحة ${context.pageNumber || 1} من ${context.totalPages || 1}`;
340
+ }
341
+ else {
342
+ return `Page ${context.pageNumber || 1} of ${context.totalPages || 1}`;
343
+ }
344
+ case 'currentDate': return formatDate(new Date(), context.format || "dd/MM/yyyy", context.dir);
345
+ case 'currentTime': return formatDate(new Date(), context.format || "HH:mm", context.dir);
346
+ case 'currentDateTime': return formatDate(new Date(), context.format || "dd/MM/yyyy HH:mm", context.dir);
347
+ case 'printedBy': return context.printedBy || "Unknown";
348
+ case 'printDate': return formatDate(context.printDate || new Date(), context.format || "dd/MM/yyyy HH:mm", context.dir);
349
+ default: return '';
350
+ }
351
+ };
352
+ // Formats a Date object into a string based on the provided format pattern
353
+ const formatDate = (date, format = "dd/MM/yyyy HH:mm", dir) => {
354
+ if (!(date instanceof Date))
355
+ date = new Date(date);
356
+ const lang = dir === 'rtl' ? 'ar' : 'en';
357
+ const days = {
358
+ ar: ["الأحد", "الإثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة", "السبت"],
359
+ en: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
360
+ };
361
+ const months = {
362
+ ar: [
363
+ "يناير", "فبراير", "مارس", "أبريل", "مايو", "يونيو",
364
+ "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر"
365
+ ],
366
+ en: [
367
+ "January", "February", "March", "April", "May", "June",
368
+ "July", "August", "September", "October", "November", "December"
369
+ ]
370
+ };
371
+ const pad = (n) => String(n).padStart(2, "0");
372
+ const map = {
373
+ dddd: days[lang][date.getDay()],
374
+ dd: pad(date.getDate()),
375
+ d: date.getDate(),
376
+ MMMM: months[lang][date.getMonth()],
377
+ MMM: months[lang][date.getMonth()].slice(0, 3),
378
+ MM: pad(date.getMonth() + 1),
379
+ M: date.getMonth() + 1,
380
+ yyyy: date.getFullYear(),
381
+ yy: String(date.getFullYear()).slice(-2),
382
+ HH: pad(date.getHours()),
383
+ hh: pad((date.getHours() % 12) || 12),
384
+ mm: pad(date.getMinutes()),
385
+ ss: pad(date.getSeconds()),
386
+ A: lang === "ar" ? (date.getHours() >= 12 ? "م" : "ص") : (date.getHours() >= 12 ? "PM" : "AM")
387
+ };
388
+ return format.replace(/dddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|HH|hh|mm|ss|A/g, m => map[m]);
389
+ };
390
+ // Currency symbol mapping
391
+ const currencySymbolMap = {
392
+ 'SAR': 'ر.س',
393
+ 'EGP': 'ج.م',
394
+ '$': '$',
395
+ '€': '€',
396
+ '£': '£'
397
+ };
398
+ // Formats a Number based on the provided format pattern
399
+ const formatNumber = (val, format) => {
400
+ if (val === null || val === undefined || val === '' || isNaN(val))
401
+ return '';
402
+ let num = Number(val);
403
+ let prefix = '';
404
+ let suffix = '';
405
+ let hasComma = false;
406
+ let decimalPlaces = 0;
407
+ let f = format || "";
408
+ if (f.includes("%")) {
409
+ suffix += "%";
410
+ f = f.replace("%", "");
411
+ }
412
+ // Replace known currency codes with Arabic symbols before parsing
413
+ for (const [code, symbol] of Object.entries(currencySymbolMap)) {
414
+ if (f.startsWith(code)) {
415
+ prefix = symbol + ' ';
416
+ f = f.slice(code.length);
417
+ break;
418
+ }
419
+ }
420
+ const match = f.match(/^([^\d#]*)([\d#,\.]+)([^\d#]*)$/);
421
+ if (match) {
422
+ if (!prefix)
423
+ prefix = match[1] || "";
424
+ let core = match[2];
425
+ suffix = (match[3] || "") + suffix;
426
+ hasComma = core.includes(",");
427
+ const dotIdx = core.indexOf(".");
428
+ if (dotIdx !== -1) {
429
+ decimalPlaces = core.length - dotIdx - 1;
430
+ }
431
+ }
432
+ let str = num.toFixed(decimalPlaces);
433
+ if (hasComma) {
434
+ let parts = str.split(".");
435
+ parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
436
+ str = parts.join(".");
437
+ }
438
+ return prefix + str + suffix;
439
+ };
440
+ const ProcessPanelItem = (item, json) => {
441
+ return ProcessItemCommonStyles(item, json);
442
+ };
443
+ const ProcessItem = ({ apiData, item, pageIndex, tableData, json, parameter, totalPages }) => {
444
+ if (item?.type === "text-object" && ((!item?.fixed && pageIndex == 0) || item?.fixed)) {
445
+ const itemStyles = ProcessTextObjectItem(item, json);
446
+ const { position, left, top, width, height, zIndex, border, boxShadow, backgroundColor, ...textStyles } = itemStyles;
447
+ const containerStyles = { position, left, top, width, height, zIndex, border, boxShadow, backgroundColor };
448
+ return (React.createElement(View, { style: containerStyles },
449
+ React.createElement(Text, { style: {
450
+ ...textStyles,
451
+ fontSize: textStyles.fontSize || '12pt',
452
+ hyphens: 'none'
453
+ } }, ensureWrap(item?.text))));
454
+ }
455
+ else if (item?.type === "database-field") {
456
+ let fieldValue = '';
457
+ const itemStyles = ProcessDatabaseFieldItem(item, json);
458
+ const sourceData = apiData?.[item?.dataSource];
459
+ if (Array.isArray(sourceData)) {
460
+ fieldValue = sourceData[0]?.[item?.field] ?? '';
461
+ }
462
+ else if (typeof sourceData === 'object') {
463
+ fieldValue = sourceData?.[item?.field] ?? '';
464
+ }
465
+ return (React.createElement(View, { style: { position: itemStyles.position, left: itemStyles.left, top: itemStyles.top, width: itemStyles.width, height: itemStyles.height, zIndex: itemStyles.zIndex, border: itemStyles.border, boxShadow: itemStyles.boxShadow, backgroundColor: itemStyles.backgroundColor } },
466
+ React.createElement(Text, { style: {
467
+ fontSize: itemStyles.fontSize || '12pt',
468
+ color: itemStyles.color || 'black',
469
+ fontFamily: itemStyles.fontFamily,
470
+ textAlign: itemStyles.textAlign,
471
+ fontWeight: itemStyles.fontWeight,
472
+ fontStyle: itemStyles.fontStyle,
473
+ textDecoration: itemStyles.textDecoration,
474
+ lineHeight: itemStyles.lineHeight,
475
+ letterSpacing: itemStyles.letterSpacing,
476
+ wordSpacing: itemStyles.wordSpacing,
477
+ transform: itemStyles.transform,
478
+ transformOrigin: itemStyles.transformOrigin,
479
+ hyphens: 'none'
480
+ } }, ensureWrap(fieldValue ?? ''))));
481
+ }
482
+ else if (item?.type === "picture") {
483
+ const itemStyles = ProcessPictureItem(item, json);
484
+ let source = item?.sourceType === "parameter" ? parameter[item?.parameter] : item?.source;
485
+ if (typeof source === 'string' && source.startsWith('http')) {
486
+ source = `https://wsrv.nl/?url=${encodeURIComponent(source)}&fit=contain&output=png&.png`;
487
+ }
488
+ else if (typeof source === 'string' && !source.startsWith('data:') && source.length > 100) {
489
+ source = `data:image/png;base64,${source}`;
490
+ }
491
+ return (React.createElement(View, { style: { ...itemStyles } }, source ? React.createElement(Image, { src: source, cache: false }) : null));
492
+ }
493
+ else if (item?.type === "special-field") {
494
+ const itemStyles = ProcessSpecialFieldItem(item, json);
495
+ const context = {
496
+ dir: json?.Direction,
497
+ pageNumber: (pageIndex ?? 0) + 1,
498
+ totalPages: totalPages || 1,
499
+ printedBy: "Coject User",
500
+ printDate: new Date(),
501
+ format: item?.format || (item?.fieldType == "currentTime" ? "HH:mm" : "dd/MM/yyyy HH:mm")
502
+ };
503
+ const value = getSpecialFieldValue(item.fieldType, context);
504
+ return (React.createElement(View, { style: { position: itemStyles.position, left: itemStyles.left, top: itemStyles.top, width: itemStyles.width, height: itemStyles.height, zIndex: itemStyles.zIndex, border: itemStyles.border, boxShadow: itemStyles.boxShadow, backgroundColor: itemStyles.backgroundColor } },
505
+ React.createElement(Text, { style: {
506
+ fontSize: itemStyles.fontSize || '12pt',
507
+ color: itemStyles.color || 'black',
508
+ fontFamily: itemStyles.fontFamily,
509
+ textAlign: itemStyles.textAlign,
510
+ fontWeight: itemStyles.fontWeight,
511
+ fontStyle: itemStyles.fontStyle,
512
+ textDecoration: itemStyles.textDecoration,
513
+ lineHeight: itemStyles.lineHeight,
514
+ letterSpacing: itemStyles.letterSpacing,
515
+ wordSpacing: itemStyles.wordSpacing,
516
+ transform: itemStyles.transform,
517
+ transformOrigin: itemStyles.transformOrigin,
518
+ hyphens: 'none'
519
+ } }, String(value))));
520
+ }
521
+ else if (item?.type === "table-object") {
522
+ const itemStyles = ProcessTableObjectItem(item, json);
523
+ const updatedColumns = processTableColumns(item, json);
524
+ const updatedColumnsEntries = Object.entries(updatedColumns);
525
+ const hasMerge = updatedColumnsEntries.some(([_, col]) => col.merge?.colSpan > 1);
526
+ const headerItems = [];
527
+ for (let i = 0; i < updatedColumnsEntries.length; i++) {
528
+ const [key, col] = updatedColumnsEntries[i];
529
+ const colSpan = col.merge?.colSpan || 1;
530
+ if (colSpan > 1) {
531
+ const subCols = updatedColumnsEntries.slice(i, i + colSpan);
532
+ headerItems.push({ type: 'merged', col, subCols });
533
+ i += (colSpan - 1);
534
+ }
535
+ else {
536
+ headerItems.push({ type: 'single', key, col });
537
+ }
538
+ }
539
+ // Grouping Logic
540
+ const tableRows = tableData[item?.id] || [];
541
+ const groupConfigs = item?.groups || [];
542
+ const footerConfigs = item?.footer || [];
543
+ const shouldRepeatHeader = groupConfigs.some((g) => g.showHeader);
544
+ const processedRows = [];
545
+ let lastGroupValues = {};
546
+ tableRows.forEach((row, rowIndex) => {
547
+ if (rowIndex > 0) {
548
+ footerConfigs.forEach((footer, fIdx) => {
549
+ const gc = footer.columns?.groupColumn;
550
+ if (gc && row[gc] !== tableRows[rowIndex - 1][gc]) {
551
+ const groupValue = tableRows[rowIndex - 1][gc];
552
+ const prevGroupRows = [];
553
+ for (let i = rowIndex - 1; i >= 0; i--) {
554
+ if (tableRows[i][gc] === groupValue) {
555
+ prevGroupRows.unshift(tableRows[i]);
556
+ }
557
+ else {
558
+ break;
559
+ }
560
+ }
561
+ processedRows.push({
562
+ type: 'footer-row',
563
+ dataRows: prevGroupRows,
564
+ footerIndex: fIdx,
565
+ key: `gf-${rowIndex}-${fIdx}`
566
+ });
567
+ }
568
+ });
569
+ }
570
+ let groupChanged = false;
571
+ groupConfigs.forEach((group, groupIndex) => {
572
+ const val = row[group.field];
573
+ if (groupChanged || rowIndex === 0 || val !== lastGroupValues[group.field]) {
574
+ groupChanged = true;
575
+ lastGroupValues[group.field] = val;
576
+ processedRows.push({
577
+ type: 'group-header',
578
+ text: (group.headerText || "").replace(/\{(\w+)\}/g, (_match, key) => row[key] ?? ""),
579
+ key: `gh-${rowIndex}-${groupIndex}`
580
+ });
581
+ }
582
+ });
583
+ if (shouldRepeatHeader) {
584
+ processedRows.push({
585
+ type: 'table-header',
586
+ key: `th-${rowIndex}`
587
+ });
588
+ }
589
+ processedRows.push({
590
+ type: 'data-row',
591
+ data: row,
592
+ index: rowIndex,
593
+ key: `dr-${rowIndex}`
594
+ });
595
+ });
596
+ footerConfigs.forEach((footer, fIdx) => {
597
+ const gc = footer.columns?.groupColumn;
598
+ if (gc && tableRows.length > 0) {
599
+ const groupValue = tableRows[tableRows.length - 1][gc];
600
+ const lastGroupRows = [];
601
+ for (let i = tableRows.length - 1; i >= 0; i--) {
602
+ if (tableRows[i][gc] === groupValue) {
603
+ lastGroupRows.unshift(tableRows[i]);
604
+ }
605
+ else {
606
+ break;
607
+ }
608
+ }
609
+ processedRows.push({
610
+ type: 'footer-row',
611
+ dataRows: lastGroupRows,
612
+ footerIndex: fIdx,
613
+ key: `gf-last-${fIdx}`
614
+ });
615
+ }
616
+ });
617
+ const renderTableHeader = (headerKey) => (React.createElement(View, { key: headerKey, style: { flexDirection: json?.Direction == 'rtl' ? 'row-reverse' : 'row' } }, headerItems.map((hItem, idx) => {
618
+ if (hItem.type === 'single') {
619
+ return (React.createElement(View, { key: idx, style: {
620
+ ...hItem.col.Styles,
621
+ minHeight: hasMerge ? '2cm' : '1cm',
622
+ justifyContent: 'center'
623
+ } },
624
+ React.createElement(Text, { wrap: true, style: { textAlign: hItem.col.Styles.textAlign || 'left', width: '100%', hyphens: 'none' } }, ensureWrap(hItem.col.text || hItem.key))));
625
+ }
626
+ else {
627
+ let totalWidthCm = 0;
628
+ hItem.subCols.forEach(([_, sc]) => totalWidthCm += parseFloat(sc.Styles.width));
629
+ return (React.createElement(View, { key: idx, style: { flexDirection: 'column', width: `${totalWidthCm}cm` } },
630
+ React.createElement(View, { style: {
631
+ ...hItem.col.Styles,
632
+ width: `${totalWidthCm}cm`,
633
+ minHeight: '1cm',
634
+ justifyContent: 'center',
635
+ alignItems: 'center'
636
+ } },
637
+ React.createElement(Text, { wrap: true, style: { textAlign: 'center', hyphens: 'none' } }, ensureWrap(hItem.col.colSpanLabel || ""))),
638
+ React.createElement(View, { style: { flexDirection: json?.Direction == 'rtl' ? 'row-reverse' : 'row' } }, hItem.subCols.map(([sk, sc], sidx) => (React.createElement(View, { key: sidx, style: { ...sc.Styles, minHeight: '1cm', justifyContent: 'center' } },
639
+ React.createElement(Text, { wrap: true, style: { textAlign: sc.Styles.textAlign || 'left', width: '100%', hyphens: 'none' } }, ensureWrap(sc.text || sk))))))));
640
+ }
641
+ })));
642
+ const renderTableFooters = (rows, specificFooterIndex) => {
643
+ if (!item?.footer || !Array.isArray(item.footer))
644
+ return null;
645
+ const footersToRender = specificFooterIndex !== undefined
646
+ ? [item.footer[specificFooterIndex]]
647
+ : item.footer;
648
+ return footersToRender.map((footerRow, fIdx) => {
649
+ const actualIdx = specificFooterIndex !== undefined ? specificFooterIndex : fIdx;
650
+ const fCols = footerRow?.columns || {};
651
+ const visibility = fCols.footerVisibility || "ALL";
652
+ const groupCol = fCols.groupColumn;
653
+ if (rows === undefined && groupCol)
654
+ return null;
655
+ if (rows !== undefined && !groupCol)
656
+ return null;
657
+ if (visibility === "LAST" && pageIndex !== (totalPages || 1) - 1) {
658
+ return null;
659
+ }
660
+ const colKeys = Object.keys(fCols)
661
+ .filter(k => !isNaN(parseInt(k)))
662
+ .sort((a, b) => parseInt(a) - parseInt(b));
663
+ let currentTableColIndex = 0;
664
+ return (React.createElement(View, { key: `footer-${actualIdx}`, style: { flexDirection: json?.Direction == 'rtl' ? 'row-reverse' : 'row' }, wrap: false }, colKeys.map((colKey, cIdx) => {
665
+ const fCol = fCols[colKey];
666
+ const colSpan = parseInt(fCol.colSpan) || 1;
667
+ let widthCm = 0;
668
+ for (let i = 0; i < colSpan; i++) {
669
+ if (currentTableColIndex + i < updatedColumnsEntries.length) {
670
+ const [, tableCol] = updatedColumnsEntries[currentTableColIndex + i];
671
+ widthCm += parseFloat(tableCol.Styles.width);
672
+ }
673
+ }
674
+ currentTableColIndex += colSpan;
675
+ let cellValue = '';
676
+ if (fCol.valueSource === 'staticValue') {
677
+ cellValue = fCol.staticValue || '';
678
+ }
679
+ else if (fCol.valueSource === 'parameter') {
680
+ cellValue = (parameter && fCol.parameter) ? (parameter[fCol.parameter] ?? '') : '';
681
+ }
682
+ else if (fCol.valueSource === 'field' && fCol.field) {
683
+ const fieldName = fCol.field;
684
+ const rowsToUse = rows || tableData[item?.id] || [];
685
+ let values = rowsToUse.map((r) => parseFloat(r[fieldName])).filter((v) => !isNaN(v));
686
+ if (fCol.aggregate === 'sum') {
687
+ cellValue = values.reduce((a, b) => a + b, 0);
688
+ }
689
+ else if (fCol.aggregate === 'count') {
690
+ cellValue = values.length;
691
+ }
692
+ else if (fCol.aggregate === 'avg') {
693
+ cellValue = values.length ? values.reduce((a, b) => a + b, 0) / values.length : 0;
694
+ }
695
+ else if (fCol.aggregate === 'min') {
696
+ cellValue = values.length ? Math.min(...values) : 0;
697
+ }
698
+ else if (fCol.aggregate === 'max') {
699
+ cellValue = values.length ? Math.max(...values) : 0;
700
+ }
701
+ if (fCol.format) {
702
+ cellValue = formatNumber(cellValue, fCol.format);
703
+ }
704
+ }
705
+ const cellStyle = {
706
+ width: `${widthCm}cm`,
707
+ minHeight: '1cm',
708
+ display: 'flex',
709
+ justifyContent: 'center',
710
+ flexDirection: 'column',
711
+ padding: '0.1cm 0.2cm',
712
+ borderRight: '1px solid #000',
713
+ borderBottom: '1px solid #000',
714
+ zIndex: 1,
715
+ fontWeight: 'bold'
716
+ };
717
+ if ((cIdx === colKeys.length - 1 && json?.Direction === 'rtl') ||
718
+ (cIdx === 0 && json?.Direction === 'ltr')) {
719
+ cellStyle.borderLeft = '1px solid #000';
720
+ }
721
+ if (fCol.fontSize)
722
+ cellStyle.fontSize = `${fCol.fontSize}pt`;
723
+ else
724
+ cellStyle.fontSize = '12pt';
725
+ if (fCol.color)
726
+ cellStyle.color = fCol.color;
727
+ if (fCol.backgroundColor)
728
+ cellStyle.backgroundColor = fCol.backgroundColor;
729
+ if (fCol.textAlign)
730
+ cellStyle.textAlign = fCol.textAlign;
731
+ return (React.createElement(View, { key: cIdx, style: { ...cellStyle } },
732
+ React.createElement(Text, { style: { textAlign: cellStyle.textAlign || 'left', width: '100%', hyphens: 'none' } }, ensureWrap(cellValue))));
733
+ })));
734
+ });
735
+ };
736
+ return ((tableData[item?.id]?.length || pageIndex == 0) ? (React.createElement(View, { style: { ...itemStyles, borderTop: '1px solid #000' }, wrap: true },
737
+ !shouldRepeatHeader && renderTableHeader('top-header'),
738
+ React.createElement(View, { style: { flexDirection: 'column' } },
739
+ processedRows.map((pRow) => {
740
+ if (pRow.type === 'group-header') {
741
+ return (React.createElement(View, { key: pRow.key, style: {
742
+ flexDirection: json?.Direction == 'rtl' ? 'row-reverse' : 'row',
743
+ backgroundColor: '#f0f0f0',
744
+ borderBottom: '1px solid #000',
745
+ borderLeft: '1px solid #000',
746
+ borderRight: '1px solid #000',
747
+ padding: '4pt',
748
+ zIndex: 1
749
+ } },
750
+ React.createElement(Text, { style: { fontWeight: 'bold', fontSize: '10pt', hyphens: 'none' } }, ensureWrap(pRow.text))));
751
+ }
752
+ if (pRow.type === 'table-header') {
753
+ return renderTableHeader(pRow.key);
754
+ }
755
+ if (pRow.type === 'footer-row') {
756
+ return renderTableFooters(pRow.dataRows, pRow.footerIndex);
757
+ }
758
+ const { data: row, index: idx } = pRow;
759
+ return (React.createElement(View, { key: pRow.key, style: { flexDirection: json?.Direction == 'rtl' ? 'row-reverse' : 'row' }, wrap: false }, updatedColumnsEntries.map(([key, col], i) => {
760
+ const { color, backgroundColor, fontWeight, ...filteredStyles } = col?.Styles || {};
761
+ let cellValue;
762
+ if (col?.isCustom && col?.valueSource) {
763
+ switch (col.valueSource) {
764
+ case 'rowNum':
765
+ cellValue = idx + 1;
766
+ break;
767
+ case 'staticValue':
768
+ cellValue = col?.staticValue ?? '';
769
+ break;
770
+ case 'parameter':
771
+ cellValue = parameter?.[col?.parameter] ?? '';
772
+ break;
773
+ default: cellValue = row[key] ?? '';
774
+ }
775
+ }
776
+ else {
777
+ cellValue = row[key] ?? '';
778
+ }
779
+ return (React.createElement(View, { key: i, style: { ...filteredStyles, backgroundColor: backgroundColor } },
780
+ React.createElement(Text, { style: {
781
+ width: '100%',
782
+ textAlign: filteredStyles.textAlign || (json?.Direction === 'rtl' ? 'right' : 'left'),
783
+ color: color || 'black',
784
+ hyphens: 'none'
785
+ } }, ensureWrap(cellValue))));
786
+ })));
787
+ }),
788
+ renderTableFooters()))) : null);
789
+ }
790
+ else if (item?.type === "qr-code-object") {
791
+ const itemStyles = ProcessQrCodeObjectItem(item, json);
792
+ return React.createElement(QrCodeGeneratedImage, { item: item, styles: itemStyles });
793
+ }
794
+ else if (item?.type === "panel") {
795
+ const itemStyles = ProcessPanelItem(item, json);
796
+ return (React.createElement(View, { style: { ...itemStyles } }, item?.body?.items?.map((childItem, index) => (React.createElement(ProcessItem, { key: index, apiData: apiData, item: childItem, json: json, pageIndex: pageIndex, tableData: tableData, parameter: parameter, totalPages: totalPages })))));
797
+ }
798
+ return null;
799
+ };
800
+ export default ProcessItem;
801
+ //# sourceMappingURL=ProcessItem.js.map