shareneus 1.7.4 → 1.7.6
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/README.md +1 -0
- package/dist/accounting/invoice/invoice-pdf/invoice-pdf.service.js +18 -45
- package/dist/accounting/invoice/reports/excel/analysis-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/category-wise-item-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/cust-wise-sales-details.js +17 -7
- package/dist/accounting/invoice/reports/excel/cust-wise-sales-summary-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/invoice-wise-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/item-wise-doctor-sale-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/items-wise-sales-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/manf-wise-sales-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/operator-wise-details.js +17 -7
- package/dist/accounting/invoice/reports/excel/operator-wise-summary.js +17 -7
- package/dist/accounting/invoice/reports/excel/sa-wise-labor-sales-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/sa-wise-part-sales-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/sale-summary-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/sales-by-service-summary-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/scheduled-drug-summary-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/scheduled-drugs-excel.service.js +17 -7
- package/dist/accounting/invoice/unified-invoice-pdf.service.d.ts +1 -1
- package/dist/accounting/payment-receive/reports/excel/cust-balance-excel.service.js +17 -7
- package/dist/accounting/payment-receive/reports/excel/payment-receive-excel.service.js +17 -7
- package/dist/common/reports/excel/product-without-owner-excel.service.js +17 -7
- package/dist/gst/excel/GSTR-RO-excel.service.js +17 -7
- package/dist/gst/excel/GSTR1-excel.service.js +17 -7
- package/dist/gst/excel/GSTR2-excel.service.js +17 -7
- package/dist/gst/excel/hsn-summary.js +17 -7
- package/dist/gst/excel/tally-sales-import.service.js +17 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/inventory/items/reports/excel/expiring-drugs-excel.service.js +17 -7
- package/dist/inventory/items/reports/excel/item-wise-mout-details.js +17 -7
- package/dist/inventory/items/reports/excel/item-wise-mout-summary.js +17 -7
- package/dist/inventory/items/reports/excel/spares-issue-excel.service.js +17 -7
- package/dist/inventory/items/reports/excel/stock-excel.service.js +17 -7
- package/dist/purchases/payment-made/reports/excel/payments-made-excel.service.js +17 -7
- package/dist/purchases/payment-made/reports/excel/ven-balance-excel.service.js +17 -7
- package/dist/services/reports/excel/insurance-expire-excel.service.js +17 -7
- package/dist/services/reports/excel/next-service-date-excel.service.js +17 -7
- package/dist/services/reports/excel/repair-orders-excel.service.js +17 -7
- package/dist/shared/table-section/pdf-table.header.d.ts +1 -1
- package/dist/shared/table-section/pdf-table.header.js +14 -2
- package/dist/shared/table-section/pdf-table.section.js +6 -13
- package/dist/{accounting/invoice/invoice-pdf.service.js → shared/transactions-pdf.service.js} +15 -15
- package/package.json +1 -1
- package/src/accounting/counter-sales/auto-sales-receipt-pdf.service.ts +569 -0
- package/src/accounting/counter-sales/pos-receipt-pdf.ts +577 -0
- package/src/accounting/counter-sales/sales-receipt-pdf.service.ts +628 -0
- package/src/accounting/counter-sales/sales-receipt-print.service.ts +506 -0
- package/src/accounting/credit-note/cn-print.service.ts +264 -0
- package/src/accounting/credit-note/credit-note-pdf.service.ts +602 -0
- package/src/accounting/credit-note/credit-note-totals.service.ts +424 -0
- package/src/accounting/debit-note/debit-note-pdf.service.ts +681 -0
- package/src/accounting/debit-note/debit-note-print.service.ts +276 -0
- package/src/accounting/debit-note/debit-note-totals.service.ts +361 -0
- package/src/accounting/invoice/hc-inv-pdf.service.ts +880 -0
- package/src/accounting/invoice/inv-pdf.service.ts +812 -0
- package/src/accounting/invoice/inv-print.service.ts +532 -0
- package/src/accounting/invoice/invoice-landscape-pdf.service.ts +947 -0
- package/src/accounting/invoice/invoice-letterhead-pdf.service.ts +813 -0
- package/src/accounting/invoice/invoice-pdf/invoice-pdf.service.ts +359 -0
- package/src/accounting/invoice/invoice-portrait-pdf.ts +972 -0
- package/src/accounting/invoice/invoice-print.service.ts +2906 -0
- package/src/accounting/invoice/invoice-total.service.ts +834 -0
- package/src/accounting/invoice/reports/excel/analysis-excel.service.ts +291 -0
- package/src/accounting/invoice/reports/excel/category-wise-item-excel.service.ts +267 -0
- package/src/accounting/invoice/reports/excel/cust-wise-sales-details.ts +321 -0
- package/src/accounting/invoice/reports/excel/cust-wise-sales-summary-excel.service.ts +300 -0
- package/src/accounting/invoice/reports/excel/invoice-wise-excel.service.ts +859 -0
- package/src/accounting/invoice/reports/excel/item-wise-doctor-sale-excel.service.ts +255 -0
- package/src/accounting/invoice/reports/excel/items-wise-sales-excel.service.ts +312 -0
- package/src/accounting/invoice/reports/excel/manf-wise-sales-excel.service.ts +273 -0
- package/src/accounting/invoice/reports/excel/operator-wise-details.ts +258 -0
- package/src/accounting/invoice/reports/excel/operator-wise-summary.ts +259 -0
- package/src/accounting/invoice/reports/excel/sa-wise-labor-sales-excel.service.ts +230 -0
- package/src/accounting/invoice/reports/excel/sa-wise-part-sales-excel.service.ts +231 -0
- package/src/accounting/invoice/reports/excel/sale-summary-excel.service.ts +326 -0
- package/src/accounting/invoice/reports/excel/sales-by-service-details-excel.service.ts +0 -0
- package/src/accounting/invoice/reports/excel/sales-by-service-summary-excel.service.ts +432 -0
- package/src/accounting/invoice/reports/excel/scheduled-drug-summary-excel.service.ts +373 -0
- package/src/accounting/invoice/reports/excel/scheduled-drugs-excel.service.ts +372 -0
- package/src/accounting/invoice/reports/pdf/analysis-pdf.service.ts +113 -0
- package/src/accounting/invoice/reports/pdf/category-wise-item-pdf.service.ts +107 -0
- package/src/accounting/invoice/reports/pdf/cust-wise-sales-details-pdf.service.ts +125 -0
- package/src/accounting/invoice/reports/pdf/cust-wise-sales-summary-pdf.service.ts +119 -0
- package/src/accounting/invoice/reports/pdf/item-wise-doctor-sale-pdf.service.ts +180 -0
- package/src/accounting/invoice/reports/pdf/item-wise-sales-pdf.service.ts +193 -0
- package/src/accounting/invoice/reports/pdf/manf-wise-sales-pdf.service.ts +188 -0
- package/src/accounting/invoice/reports/pdf/operator-wise-details-pdf.service.ts +118 -0
- package/src/accounting/invoice/reports/pdf/operator-wise-summary-pdf.ts +116 -0
- package/src/accounting/invoice/reports/pdf/sales-by-service-pdf.service.ts +132 -0
- package/src/accounting/invoice/reports/pdf/scheduled-drug-pdf.service.ts +191 -0
- package/src/accounting/invoice/reports/pdf/scheduled-drug-summary-pdf.service.ts +202 -0
- package/src/accounting/invoice/shared-inv-pdf.service.ts +787 -0
- package/src/accounting/invoice/unified-invoice-pdf.service.ts +937 -0
- package/src/accounting/payment-receive/payment-pdf.service.ts +410 -0
- package/src/accounting/payment-receive/payment-receipt-pdf/receipt-pdf.service.ts +470 -0
- package/src/accounting/payment-receive/receipt-print.service.ts +71 -0
- package/src/accounting/payment-receive/reports/excel/cust-balance-excel.service.ts +298 -0
- package/src/accounting/payment-receive/reports/excel/payment-receive-excel.service.ts +221 -0
- package/src/accounting/payment-receive/reports/pdf/customer-balances-pdf.service.ts +182 -0
- package/src/accounting/payment-receive/reports/pdf/payment-report-pdf.service.ts +116 -0
- package/src/aggregation/aggregation.ts +58 -0
- package/src/appointments/appointments/appointment-total.service.ts +298 -0
- package/src/appointments/consultations/consultation-fee-receipt.service.ts +407 -0
- package/src/appointments/consultations/consultation-full-pdf.service.ts +238 -0
- package/src/appointments/consultations/consultation-letterhead-pdf.service.ts +430 -0
- package/src/appointments/consultations/consultation-pdf.service.ts +417 -0
- package/src/common/reports/excel/product-without-owner-excel.service.ts +308 -0
- package/src/common/reports/pdf/product-without-owner-pdf.service.ts +146 -0
- package/src/enums/cache-enums.ts +33 -0
- package/src/enums/code-enums.ts +291 -0
- package/src/enums/country-enums.ts +9 -0
- package/src/enums/enums.ts +364 -0
- package/src/enums/industry-enums.ts +26 -0
- package/src/enums/treatment-enums.ts +9 -0
- package/src/gst/excel/GSTR-RO-excel.service.ts +926 -0
- package/src/gst/excel/GSTR1-excel.service.ts +313 -0
- package/src/gst/excel/GSTR2-excel.service.ts +314 -0
- package/src/gst/excel/hsn-summary.ts +314 -0
- package/src/gst/excel/tally-sales-import.service.ts +767 -0
- package/src/gst/pdf/hsn-summary-pdf.ts +176 -0
- package/src/index.ts +194 -0
- package/src/inventory/items/adjustment-pdf.service.ts +177 -0
- package/src/inventory/items/issue-parts-pdf.service.ts +795 -0
- package/src/inventory/items/item-bar-code-label-pdf.ts +194 -0
- package/src/inventory/items/item-detais-pdf.ts +141 -0
- package/src/inventory/items/item-price-for-pricelist.ts +368 -0
- package/src/inventory/items/reports/excel/expiring-drugs-excel.service.ts +290 -0
- package/src/inventory/items/reports/excel/item-wise-mout-details.ts +284 -0
- package/src/inventory/items/reports/excel/item-wise-mout-summary.ts +279 -0
- package/src/inventory/items/reports/excel/spares-issue-excel.service.ts +494 -0
- package/src/inventory/items/reports/excel/stock-excel.service.ts +319 -0
- package/src/inventory/items/reports/pdf/expiring-drugs-pdf.service.ts +172 -0
- package/src/inventory/items/reports/pdf/item-wise-mout-details-pdf.ts +122 -0
- package/src/inventory/items/reports/pdf/item-wise-mout-summary-pdf.ts +115 -0
- package/src/inventory/items/reports/pdf/reorder-point-pdf.service.ts +163 -0
- package/src/inventory/material-out/mout-pdf.service.ts +545 -0
- package/src/inventory/transfer-order/transfer-order-pdf.service.ts +154 -0
- package/src/purchases/bills/bill-pdf/bill-pdf.service.ts +211 -0
- package/src/purchases/bills/bill-pdf.service.ts +21 -0
- package/src/purchases/payment-made/reports/excel/payments-made-excel.service.ts +313 -0
- package/src/purchases/payment-made/reports/excel/ven-balance-excel.service.ts +307 -0
- package/src/purchases/payment-made/reports/pdf/vendor-balances-pdf.service.ts +114 -0
- package/src/purchases/purchase-order/po-totals.service.ts +343 -0
- package/src/purchases/purchase-order/purchase-order-pdf.service.ts +1016 -0
- package/src/purchases/purchase-order/purchase-order-print.service.ts +279 -0
- package/src/purchases/purchase-order/purchase-order-totals.service.ts +637 -0
- package/src/purchases/vendor-credit-note/vendor-credit-note-pdf.service.ts +1055 -0
- package/src/purchases/vendor-credit-note/vendor-credit-note-print.service.ts +145 -0
- package/src/purchases/vendor-credit-note/vendor-credit-note-totals.service.ts +399 -0
- package/src/purchases/vendor-debit-note/vendor-debit-note-pdf.service.ts +582 -0
- package/src/purchases/vendor-debit-note/vendor-debit-note-print.service.ts +295 -0
- package/src/purchases/vendor-debit-note/vendor-debit-note-totals.service.ts +377 -0
- package/src/sales/delivery-challan/dc-landscape-pdf.service.ts +922 -0
- package/src/sales/delivery-challan/dc-landscape-without-price-pdf.service.ts +869 -0
- package/src/sales/delivery-challan/dc-without-price-pdf.service.ts +505 -0
- package/src/sales/delivery-challan/delivery-challan-pdf.service.ts +461 -0
- package/src/sales/delivery-challan/delivery-challan-print.service.ts +229 -0
- package/src/sales/delivery-challan/delivery-challan-totals.ts +466 -0
- package/src/sales/sales/equipment-design-pdf.service.ts +153 -0
- package/src/sales/sales/pack-ship-pdf.service.ts +128 -0
- package/src/sales/sales/pack-ship-print.service.ts +198 -0
- package/src/sales/sales/sales-pdf.service.ts +658 -0
- package/src/sales/sales/sales-print.service.ts +376 -0
- package/src/sales/sales/sales-totals.service.ts +500 -0
- package/src/sales-receive/sales-receive-pdf.service.ts +602 -0
- package/src/sales-receive/sales-receive-print.service.ts +242 -0
- package/src/sales-receive/sales-receive-totals.service.ts +651 -0
- package/src/services/checklist-pdf.ts +151 -0
- package/src/services/checklists-pdf.ts +133 -0
- package/src/services/est.print-service.ts +1155 -0
- package/src/services/reports/excel/insurance-expire-excel.service.ts +292 -0
- package/src/services/reports/excel/next-service-date-excel.service.ts +317 -0
- package/src/services/reports/excel/repair-orders-excel.service.ts +249 -0
- package/src/services/reports/pdf/insurance-expire-pdf.service.ts +115 -0
- package/src/services/reports/pdf/next-service-date-pdf.service.ts +198 -0
- package/src/services/reports/pdf/repair-orders-pdf.service.ts +184 -0
- package/src/services/ro-pdf.service.ts +1917 -0
- package/src/services/ro-print-service.ts +881 -0
- package/src/services/ro-totals.service.ts +1314 -0
- package/src/services/separate-wo-print.service.ts +396 -0
- package/src/services/service-history-pdf.service.ts +145 -0
- package/src/services/service-price-for-pricelist.ts +649 -0
- package/src/services/technician-pdf.service.ts +234 -0
- package/src/services/technician-print.service.ts +95 -0
- package/src/shared/header-footer-section/pdf-header-footer.section.ts +519 -0
- package/src/shared/header-footer-section/pdf-shared.utils.ts +46 -0
- package/src/shared/math-operations.ts +208 -0
- package/src/shared/party-details-section/pdf-party-details.section.ts +602 -0
- package/src/shared/shared-pdf.service.ts +3042 -0
- package/src/shared/shared-print.service.ts +879 -0
- package/src/shared/table-section/pdf-table.config.ts +8 -0
- package/src/shared/table-section/pdf-table.header.ts +396 -0
- package/src/shared/table-section/pdf-table.row.ts +248 -0
- package/src/shared/table-section/pdf-table.section.ts +447 -0
- package/src/shared/totals-section/pdf-totals.section.ts +921 -0
- package/src/shared/transactions-pdf.service.ts +191 -0
- package/src/shared/util.ts +101 -0
- package/src/tasks/meetings/meeting-pdf.ts +410 -0
- package/src/tasks/tasks/task-pdf.service.ts +238 -0
- package/src/tasks/tasks/task-reports-pdf.service.ts +313 -0
- package/src/tax/index.ts +86 -0
- package/src/tax/tax-calculator.ts +1025 -0
- package/src/tax/tax.types.ts +535 -0
- package/src/transaction-calculations/discounts-distribution.ts +343 -0
- package/src/transaction-calculations/index.ts +3 -0
- package/src/transaction-calculations/total-calculation.ts +443 -0
- package/src/transaction-calculations/transaction-calculation-engine.ts +903 -0
- package/src/utils/my-date.ts +111 -0
- package/src/utils/tr-utils.ts +104 -0
- package/tsconfig.json +2 -2
- /package/dist/{accounting/invoice/invoice-pdf.service.d.ts → shared/transactions-pdf.service.d.ts} +0 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
import { asDataUrl, firstValue, normalizeColor, readPositiveNumber, toStr } from './pdf-shared.utils';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_PAGE_ORIENTATION: 'portrait' | 'landscape' = 'portrait';
|
|
4
|
+
const A4_WIDTH = 595.28;
|
|
5
|
+
const A4_HEIGHT = 841.89;
|
|
6
|
+
const HALF_A4_HEIGHT = A4_HEIGHT / 2;
|
|
7
|
+
const DEFAULT_ORG_NAME_FONT_SIZE = 16;
|
|
8
|
+
const DEFAULT_ORG_ADDRESS_FONT_SIZE = 9;
|
|
9
|
+
const DEFAULT_ORG_NAME_FONT_COLOR = '#111827';
|
|
10
|
+
const DEFAULT_ORG_ADDRESS_FONT_COLOR = '#111827';
|
|
11
|
+
const DEFAULT_PAGE_MARGINS: [number, number, number, number] = [20, 20, 20, 20];
|
|
12
|
+
const DEFAULT_HEADER_POSITION = 'Left';
|
|
13
|
+
const DEFAULT_LOGO_POSITION = 'Left';
|
|
14
|
+
|
|
15
|
+
export function resolvePageOrientation(value: any): 'portrait' | 'landscape' {
|
|
16
|
+
return value?.toLowerCase() === 'landscape' ? 'landscape' : DEFAULT_PAGE_ORIENTATION;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function resolvePageSize(
|
|
20
|
+
value: any,
|
|
21
|
+
orientation: 'portrait' | 'landscape' = DEFAULT_PAGE_ORIENTATION
|
|
22
|
+
): 'A4' | 'LETTER' | 'LEGAL' | { width: number; height: number } {
|
|
23
|
+
const raw = String(value ?? '').trim().toLowerCase();
|
|
24
|
+
const normalized = raw.replace(/[\s_-]/g, '');
|
|
25
|
+
if (normalized === 'halfa4') {
|
|
26
|
+
// return { width: A4_WIDTH, height: HALF_A4_HEIGHT };
|
|
27
|
+
return 'A4';
|
|
28
|
+
}
|
|
29
|
+
if (normalized === 'letter') {
|
|
30
|
+
return 'LETTER';
|
|
31
|
+
}
|
|
32
|
+
if (normalized === 'legal') {
|
|
33
|
+
return 'LEGAL';
|
|
34
|
+
}
|
|
35
|
+
return 'A4';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function deriveHeaderDataFromInvoice(PDFInvoiceData: any) {
|
|
39
|
+
const entity = PDFInvoiceData?.Entity || {};
|
|
40
|
+
return {
|
|
41
|
+
invoiceHeading: PDFInvoiceData?.Type ? `${PDFInvoiceData.Type} Invoice` : 'INVOICE',
|
|
42
|
+
organization: {
|
|
43
|
+
cName: entity?.CName || '',
|
|
44
|
+
address1: entity?.Adrs1 || entity?.Addr1 || '',
|
|
45
|
+
address2: entity?.Adrs2 || entity?.Addr2 || '',
|
|
46
|
+
city: entity?.City || '',
|
|
47
|
+
state: entity?.State || entity?.St || '',
|
|
48
|
+
pin: entity?.PIN || entity?.Pin || '',
|
|
49
|
+
gstin: entity?.GSTIN || entity?.GSTNo || '',
|
|
50
|
+
gst: entity?.GST || '',
|
|
51
|
+
cst: entity?.CST || '',
|
|
52
|
+
cin: entity?.CIN || '',
|
|
53
|
+
pan: entity?.PAN || '',
|
|
54
|
+
dlNo: entity?.DLNo || entity?.DLNO || '',
|
|
55
|
+
email: entity?.Email || entity?.EMail || '',
|
|
56
|
+
phone: entity?.Phone || entity?.Ph || '',
|
|
57
|
+
phone2: entity?.Phone2 || entity?.Ph2 || ''
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function normalizeHeaderData(headerData: any) {
|
|
63
|
+
const organization = headerData?.organization ?? {};
|
|
64
|
+
return {
|
|
65
|
+
logoDataUrl: asDataUrl(headerData?.logoDataUrl),
|
|
66
|
+
invoiceHeading: headerData?.invoiceHeading ? String(headerData.invoiceHeading) : 'INVOICE',
|
|
67
|
+
organization: {
|
|
68
|
+
cName: toStr(organization?.cName),
|
|
69
|
+
address1: toStr(organization?.address1),
|
|
70
|
+
address2: toStr(organization?.address2),
|
|
71
|
+
city: toStr(organization?.city),
|
|
72
|
+
state: toStr(organization?.state),
|
|
73
|
+
pin: toStr(organization?.pin),
|
|
74
|
+
gstin: toStr(organization?.gstin),
|
|
75
|
+
gst: toStr(organization?.gst),
|
|
76
|
+
cst: toStr(organization?.cst),
|
|
77
|
+
cin: toStr(organization?.cin),
|
|
78
|
+
pan: toStr(organization?.pan),
|
|
79
|
+
dlNo: toStr(organization?.dlNo),
|
|
80
|
+
email: toStr(organization?.email),
|
|
81
|
+
phone: toStr(organization?.phone),
|
|
82
|
+
phone2: toStr(organization?.phone2),
|
|
83
|
+
taxIds: normalizeTaxIds(organization?.taxIds)
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function normalizeHeaderStyle(headerStyles: any) {
|
|
89
|
+
return {
|
|
90
|
+
OrgNameFsize: readPositiveNumber(headerStyles?.orgNameFontSize ?? headerStyles?.OrgNameFsize, DEFAULT_ORG_NAME_FONT_SIZE),
|
|
91
|
+
OrgNameClr: normalizeColor(headerStyles?.orgNameFontColor ?? headerStyles?.OrgNameClr, DEFAULT_ORG_NAME_FONT_COLOR),
|
|
92
|
+
AdrsFsize: readPositiveNumber(headerStyles?.orgAddressFontSize ?? headerStyles?.AdrsFsize, DEFAULT_ORG_ADDRESS_FONT_SIZE),
|
|
93
|
+
AdrsClr: normalizeColor(headerStyles?.orgAddressFontColor ?? headerStyles?.AdrsClr, DEFAULT_ORG_ADDRESS_FONT_COLOR)
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function resolvePageMargins(value: any): [number, number, number, number] {
|
|
98
|
+
if (Array.isArray(value) && value.length === 4) {
|
|
99
|
+
return [
|
|
100
|
+
readPositiveNumber(value[0], DEFAULT_PAGE_MARGINS[0]),
|
|
101
|
+
readPositiveNumber(value[1], DEFAULT_PAGE_MARGINS[1]),
|
|
102
|
+
readPositiveNumber(value[2], DEFAULT_PAGE_MARGINS[2]),
|
|
103
|
+
readPositiveNumber(value[3], DEFAULT_PAGE_MARGINS[3])
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (value && typeof value === 'object') {
|
|
108
|
+
const left = readPositiveNumber(value?.Left ?? value?.left, DEFAULT_PAGE_MARGINS[0]);
|
|
109
|
+
const top = readPositiveNumber(value?.Top ?? value?.top, DEFAULT_PAGE_MARGINS[1]);
|
|
110
|
+
const right = readPositiveNumber(value?.Right ?? value?.right, DEFAULT_PAGE_MARGINS[2]);
|
|
111
|
+
const bottom = readPositiveNumber(value?.Bottom ?? value?.bottom, DEFAULT_PAGE_MARGINS[3]);
|
|
112
|
+
return [left, top, right, bottom];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return DEFAULT_PAGE_MARGINS;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function buildDocumentHeaderSection(PrintConfig: any, DocumentData: any = {}) {
|
|
119
|
+
const entity = DocumentData?.Entity ?? {};
|
|
120
|
+
const documentLogoDataUrl = resolveDocumentLogoDataUrl(DocumentData);
|
|
121
|
+
const headerData = normalizeHeaderData(PrintConfig?.headerData ?? {});
|
|
122
|
+
const mergedHeaderData = normalizeHeaderData({
|
|
123
|
+
...headerData,
|
|
124
|
+
logoDataUrl: firstValue(documentLogoDataUrl, headerData?.logoDataUrl),
|
|
125
|
+
organization: {
|
|
126
|
+
...(headerData?.organization ?? {}),
|
|
127
|
+
cName: firstValue(entity?.CName, headerData?.organization?.cName),
|
|
128
|
+
address1: firstValue(entity?.Adrs1, headerData?.organization?.address1),
|
|
129
|
+
address2: firstValue(entity?.Adrs2, headerData?.organization?.address2),
|
|
130
|
+
dlNo: firstValue(entity?.DLNo, entity?.DLNO, headerData?.organization?.dlNo),
|
|
131
|
+
gstin: firstValue(entity?.GSTIN, headerData?.organization?.gstin),
|
|
132
|
+
pan: firstValue(entity?.PAN, headerData?.organization?.pan),
|
|
133
|
+
taxIds: Array.isArray(entity?.TaxIds) ? entity.TaxIds : headerData?.organization?.taxIds,
|
|
134
|
+
city: firstValue(entity?.City, headerData?.organization?.city),
|
|
135
|
+
state: firstValue(entity?.State, headerData?.organization?.state),
|
|
136
|
+
pin: firstValue(entity?.PIN, entity?.Pin, headerData?.organization?.pin),
|
|
137
|
+
email: firstValue(entity?.Email, entity?.EMail, headerData?.organization?.email),
|
|
138
|
+
phone: firstValue(entity?.Phone, entity?.Ph, headerData?.organization?.phone),
|
|
139
|
+
phone2: firstValue(entity?.Phone2, entity?.Ph2, headerData?.organization?.phone2)
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const headerStyles = normalizeHeaderStyle(PrintConfig?.headerStyles ?? {
|
|
143
|
+
OrgNameFsize: PrintConfig?.OrgNameFsize,
|
|
144
|
+
OrgNameClr: PrintConfig?.OrgNameClr,
|
|
145
|
+
AdrsFsize: PrintConfig?.AdrsFsize,
|
|
146
|
+
AdrsClr: PrintConfig?.AdrsClr
|
|
147
|
+
});
|
|
148
|
+
const headerSettings:any = normalizeHeaderSettings(PrintConfig?.Header ?? PrintConfig?.Header ?? {});
|
|
149
|
+
|
|
150
|
+
if (!headerSettings.Show) {
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const hasPrintedTaxIds = !!buildPrintedTaxIdsText(mergedHeaderData.organization?.taxIds);
|
|
155
|
+
const hasOrganizationData = !!(mergedHeaderData.organization?.cName || mergedHeaderData.organization?.address1
|
|
156
|
+
|| mergedHeaderData.organization?.address2 || mergedHeaderData.organization?.city || mergedHeaderData.organization?.state
|
|
157
|
+
|| mergedHeaderData.organization?.pin || mergedHeaderData.organization?.gstin || mergedHeaderData.organization?.email
|
|
158
|
+
|| mergedHeaderData.organization?.phone || mergedHeaderData.organization?.phone2 || mergedHeaderData.organization?.dlNo
|
|
159
|
+
|| mergedHeaderData.organization?.cin || mergedHeaderData.organization?.pan || hasPrintedTaxIds);
|
|
160
|
+
const hasLogo = !!mergedHeaderData.logoDataUrl && headerSettings.ShowLogo;
|
|
161
|
+
if (!hasOrganizationData && !hasLogo) {
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const textAlignment = toPdfAlignment(headerSettings.Position);
|
|
166
|
+
const builtOrganizationStack = buildOrganizationStack(mergedHeaderData.organization, headerStyles, textAlignment);
|
|
167
|
+
const organizationStack = Array.isArray(builtOrganizationStack) ? builtOrganizationStack : [{ text: toStr(builtOrganizationStack) }];
|
|
168
|
+
const headerContent = buildHeaderContentWithLogo(mergedHeaderData.logoDataUrl, hasLogo, organizationStack, headerSettings.LogoPosition, textAlignment);
|
|
169
|
+
|
|
170
|
+
return [{
|
|
171
|
+
columns: [
|
|
172
|
+
{
|
|
173
|
+
width: '*',
|
|
174
|
+
...headerContent
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
columnGap: 10,
|
|
178
|
+
margin: [0, 0, 0, 10]
|
|
179
|
+
}];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function buildDocumentHeadingSection(PDFInvoiceData: any, PrintConfig: any, availableWidth: number) {
|
|
183
|
+
const headerData = normalizeHeaderData(PrintConfig?.headerData ?? {});
|
|
184
|
+
const headingText = PDFInvoiceData.HeaderName || 'INVOICE';
|
|
185
|
+
|
|
186
|
+
return [
|
|
187
|
+
{
|
|
188
|
+
text: headingText,
|
|
189
|
+
bold: true,
|
|
190
|
+
fontSize: 16,
|
|
191
|
+
alignment: 'center',
|
|
192
|
+
margin: [0, 0, 0, 4]
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
canvas: [
|
|
196
|
+
{ type: 'line', x1: 0, y1: 0, x2: Math.max(1, availableWidth), y2: 0, lineWidth: 1, lineColor: '#1f2937' }
|
|
197
|
+
],
|
|
198
|
+
margin: [0, 0, 0, 8]
|
|
199
|
+
}
|
|
200
|
+
];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function buildWatermark(PrintConfig: any, DocumentData: any = {}) {
|
|
204
|
+
const value = DocumentData?.IsProforma ? 'Not a final invoice' : firstValue(PrintConfig?.WatermarkText);
|
|
205
|
+
const isEnabled = !!(PrintConfig?.Watermark || PrintConfig?.WatermarkEnabled || value);
|
|
206
|
+
if (!isEnabled) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
if (!value) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
text: value,
|
|
214
|
+
color: '#9ca3af',
|
|
215
|
+
opacity: 0.25,
|
|
216
|
+
bold: true
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function buildLogoWatermarkBackground(PrintConfig: any, DocumentData: any = {}) {
|
|
221
|
+
const value = firstValue(PrintConfig?.WatermarkText);
|
|
222
|
+
const isEnabled = !!(PrintConfig?.Watermark || PrintConfig?.WatermarkEnabled || value);
|
|
223
|
+
if (!isEnabled || value) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const headerData = normalizeHeaderData(PrintConfig?.headerData ?? {});
|
|
228
|
+
const logoDataUrl = firstValue(resolveDocumentLogoDataUrl(DocumentData), headerData?.logoDataUrl);
|
|
229
|
+
if (!logoDataUrl) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return () => ({
|
|
234
|
+
image: logoDataUrl,
|
|
235
|
+
width: 220,
|
|
236
|
+
opacity: 0.08,
|
|
237
|
+
alignment: 'center',
|
|
238
|
+
margin: [0, 180, 0, 0]
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function resolveDocumentLogoDataUrl(DocumentData: any) {
|
|
243
|
+
const entity = DocumentData?.Entity ?? {};
|
|
244
|
+
return firstValue(
|
|
245
|
+
asDataUrl(DocumentData?.logoDataUrl),
|
|
246
|
+
asDataUrl(DocumentData?.LogoDataUrl),
|
|
247
|
+
asDataUrl(DocumentData?.Image),
|
|
248
|
+
asDataUrl(DocumentData?.Logo),
|
|
249
|
+
asDataUrl(entity?.Image),
|
|
250
|
+
asDataUrl(entity?.Logo),
|
|
251
|
+
asDataUrl(entity?.CLogo),
|
|
252
|
+
asDataUrl(entity?.LogoDataUrl)
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export function buildFooter(PrintConfig: any) {
|
|
257
|
+
const footerConfig = PrintConfig?.Footer ?? {};
|
|
258
|
+
const showFooter = footerConfig?.Show !== false;
|
|
259
|
+
if (!showFooter) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const value = firstValue(footerConfig?.Text ?? PrintConfig?.FooterText);
|
|
264
|
+
if (!value) {
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const textAlignment = normalizeFooterAlignment(footerConfig?.Position ?? footerConfig?.Position);
|
|
269
|
+
|
|
270
|
+
return () => ({
|
|
271
|
+
margin: [20, 0, 20, 6],
|
|
272
|
+
text: value,
|
|
273
|
+
alignment: textAlignment,
|
|
274
|
+
fontSize: 8,
|
|
275
|
+
color: '#4b5563'
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function buildPageNumberHeader(PrintConfig: any) {
|
|
280
|
+
// const showPageNumber = PrintConfig?.Header?.ShowPageNumber !== false;
|
|
281
|
+
// if (!showPageNumber) {
|
|
282
|
+
// return null;
|
|
283
|
+
// }
|
|
284
|
+
|
|
285
|
+
return (currentPage: number, pageCount: number) => ({
|
|
286
|
+
text: `Page ${currentPage}/${pageCount}`,
|
|
287
|
+
alignment: 'right',
|
|
288
|
+
margin: [20, 4, 20, 0],
|
|
289
|
+
fontSize: 8,
|
|
290
|
+
color: '#4b5563'
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function normalizeFooterAlignment(value: any): 'left' | 'center' | 'right' {
|
|
295
|
+
const raw = String(value ?? '').trim().toLowerCase();
|
|
296
|
+
if (raw === 'center') {
|
|
297
|
+
return 'center';
|
|
298
|
+
}
|
|
299
|
+
if (raw === 'right') {
|
|
300
|
+
return 'right';
|
|
301
|
+
}
|
|
302
|
+
return 'left';
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function buildOrganizationStack(organization: any, headerStyles: any, alignment: 'left' | 'center' | 'right') {
|
|
306
|
+
const stack: any[] = [];
|
|
307
|
+
const orgNameFontSize = readPositiveNumber(headerStyles?.OrgNameFsize, DEFAULT_ORG_NAME_FONT_SIZE);
|
|
308
|
+
const orgAddressFontSize = readPositiveNumber(headerStyles?.AdrsFsize, DEFAULT_ORG_ADDRESS_FONT_SIZE);
|
|
309
|
+
const orgNameFontColor = normalizeColor(headerStyles?.OrgNameClr, DEFAULT_ORG_NAME_FONT_COLOR);
|
|
310
|
+
const orgAddressFontColor = normalizeColor(headerStyles?.AdrsClr, DEFAULT_ORG_ADDRESS_FONT_COLOR);
|
|
311
|
+
|
|
312
|
+
if (organization?.cName) {
|
|
313
|
+
stack.push({ text: organization.cName, bold: true, fontSize: orgNameFontSize, color: orgNameFontColor, lineHeight: 1.1, alignment });
|
|
314
|
+
}
|
|
315
|
+
if (organization?.address1) {
|
|
316
|
+
stack.push({ text: organization.address1, fontSize: orgAddressFontSize, color: orgAddressFontColor, lineHeight: 1.05, alignment });
|
|
317
|
+
}
|
|
318
|
+
if (organization?.address2) {
|
|
319
|
+
stack.push({ text: organization.address2, fontSize: orgAddressFontSize, color: orgAddressFontColor, lineHeight: 1.05, alignment });
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const cityStatePin = [organization?.city, organization?.state, organization?.pin].filter((value: string) => !!value).join(', ');
|
|
323
|
+
if (cityStatePin) {
|
|
324
|
+
stack.push({ text: cityStatePin, fontSize: orgAddressFontSize, color: orgAddressFontColor, lineHeight: 1.05, alignment });
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const hasTaxIdsConfig = Array.isArray(organization?.taxIds) && organization.taxIds.length > 0;
|
|
328
|
+
const printedTaxIdsText = buildPrintedTaxIdsText(organization?.taxIds);
|
|
329
|
+
if (hasTaxIdsConfig) {
|
|
330
|
+
if (printedTaxIdsText) {
|
|
331
|
+
stack.push({ text: printedTaxIdsText, fontSize: orgAddressFontSize, color: orgAddressFontColor, lineHeight: 1.05, alignment });
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
if (organization?.gstin) {
|
|
335
|
+
stack.push({ text: `GSTIN: ${organization.gstin}`, fontSize: orgAddressFontSize, color: orgAddressFontColor, lineHeight: 1.05, alignment });
|
|
336
|
+
}
|
|
337
|
+
if (organization?.gst) {
|
|
338
|
+
stack.push({ text: `GST: ${organization.gst}`, fontSize: orgAddressFontSize, color: orgAddressFontColor, lineHeight: 1.05, alignment });
|
|
339
|
+
}
|
|
340
|
+
if (organization?.cst) {
|
|
341
|
+
stack.push({ text: `CST: ${organization.cst}`, fontSize: orgAddressFontSize, color: orgAddressFontColor, lineHeight: 1.05, alignment });
|
|
342
|
+
}
|
|
343
|
+
if (organization?.cin) {
|
|
344
|
+
stack.push({ text: `CIN: ${organization.cin}`, fontSize: orgAddressFontSize, color: orgAddressFontColor, lineHeight: 1.05, alignment });
|
|
345
|
+
}
|
|
346
|
+
if (organization?.pan) {
|
|
347
|
+
stack.push({ text: `PAN: ${organization.pan}`, fontSize: orgAddressFontSize, color: orgAddressFontColor, lineHeight: 1.05, alignment });
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (organization?.dlNo) {
|
|
351
|
+
stack.push({ text: `DLNo: ${organization.dlNo}`, fontSize: orgAddressFontSize, color: orgAddressFontColor, lineHeight: 1.05, alignment });
|
|
352
|
+
}
|
|
353
|
+
if (organization?.email) {
|
|
354
|
+
stack.push({ text: `Email: ${organization.email}`, fontSize: orgAddressFontSize, color: orgAddressFontColor, lineHeight: 1.05, alignment });
|
|
355
|
+
}
|
|
356
|
+
const phoneNumbers = [organization?.phone, organization?.phone2]
|
|
357
|
+
.filter((phone: string) => !!phone)
|
|
358
|
+
.join(', ');
|
|
359
|
+
if (phoneNumbers) {
|
|
360
|
+
stack.push({ text: `Phone: ${phoneNumbers}`, fontSize: orgAddressFontSize, color: orgAddressFontColor, lineHeight: 1.05, alignment });
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (stack.length === 0) {
|
|
364
|
+
stack.push({ text: '' });
|
|
365
|
+
}
|
|
366
|
+
return stack;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function normalizeTaxIds(value: any) {
|
|
370
|
+
if (!Array.isArray(value)) {
|
|
371
|
+
return [];
|
|
372
|
+
}
|
|
373
|
+
return value.map((taxId: any) => ({
|
|
374
|
+
Label: toStr(taxId?.Label ?? taxId?.label),
|
|
375
|
+
Value: toStr(taxId?.Value ?? taxId?.value),
|
|
376
|
+
Print: normalizeBooleanLike(taxId?.Print ?? taxId?.print),
|
|
377
|
+
Primary: normalizeBooleanLike(taxId?.Primary ?? taxId?.primary)
|
|
378
|
+
}));
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function buildPrintedTaxIdsText(value: any) {
|
|
382
|
+
const taxIds = normalizeTaxIds(value);
|
|
383
|
+
const primary: string[] = [];
|
|
384
|
+
const secondary: string[] = [];
|
|
385
|
+
|
|
386
|
+
for (const taxId of taxIds) {
|
|
387
|
+
if (!taxId?.Print || !taxId?.Value) {
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
const text = taxId?.Label ? `${taxId.Label}:${taxId.Value}` : taxId.Value;
|
|
391
|
+
if (taxId?.Primary) {
|
|
392
|
+
primary.push(text);
|
|
393
|
+
} else {
|
|
394
|
+
secondary.push(text);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return [...primary, ...secondary].join(', ');
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function normalizeBooleanLike(value: any) {
|
|
402
|
+
if (typeof value === 'boolean') {
|
|
403
|
+
return value;
|
|
404
|
+
}
|
|
405
|
+
if (typeof value === 'number') {
|
|
406
|
+
return value !== 0;
|
|
407
|
+
}
|
|
408
|
+
if (typeof value === 'string') {
|
|
409
|
+
const normalized = value.trim().toLowerCase();
|
|
410
|
+
return normalized === 'true' || normalized === '1' || normalized === 'yes' || normalized === 'y';
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function normalizeHeaderSettings(value: any) {
|
|
416
|
+
const Position = normalizePosition(value?.Position, DEFAULT_HEADER_POSITION);
|
|
417
|
+
const LogoPosition = normalizeLogoPosition(value?.LogoPosition, DEFAULT_LOGO_POSITION);
|
|
418
|
+
return {
|
|
419
|
+
Position,
|
|
420
|
+
LogoPosition,
|
|
421
|
+
Show: value?.Show !== false,
|
|
422
|
+
ShowLogo: value?.ShowLogo !== false
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function normalizePosition(value: any, fallback: string): 'Left' | 'Center' | 'Right' {
|
|
427
|
+
const raw = String(value ?? '').trim().toLowerCase();
|
|
428
|
+
if (raw === 'center') {
|
|
429
|
+
return 'Center';
|
|
430
|
+
}
|
|
431
|
+
if (raw === 'right') {
|
|
432
|
+
return 'Right';
|
|
433
|
+
}
|
|
434
|
+
if (raw === 'left') {
|
|
435
|
+
return 'Left';
|
|
436
|
+
}
|
|
437
|
+
return fallback as 'Left' | 'Center' | 'Right';
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function normalizeLogoPosition(value: any, fallback: string): 'Left' | 'Top' | 'Right' {
|
|
441
|
+
const raw = String(value ?? '').trim().toLowerCase();
|
|
442
|
+
if (raw === 'top') {
|
|
443
|
+
return 'Top';
|
|
444
|
+
}
|
|
445
|
+
if (raw === 'right') {
|
|
446
|
+
return 'Right';
|
|
447
|
+
}
|
|
448
|
+
if (raw === 'left') {
|
|
449
|
+
return 'Left';
|
|
450
|
+
}
|
|
451
|
+
return fallback as 'Left' | 'Top' | 'Right';
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function toPdfAlignment(position: 'Left' | 'Center' | 'Right'): 'left' | 'center' | 'right' {
|
|
455
|
+
if (position === 'Center') {
|
|
456
|
+
return 'center';
|
|
457
|
+
}
|
|
458
|
+
if (position === 'Right') {
|
|
459
|
+
return 'right';
|
|
460
|
+
}
|
|
461
|
+
return 'left';
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function buildHeaderContentWithLogo(
|
|
465
|
+
logoDataUrl: string | null,
|
|
466
|
+
hasLogo: boolean,
|
|
467
|
+
organizationStack: any[],
|
|
468
|
+
logoPosition: 'Left' | 'Top' | 'Right',
|
|
469
|
+
textAlignment: 'left' | 'center' | 'right'
|
|
470
|
+
) {
|
|
471
|
+
const safeOrganizationStack = Array.isArray(organizationStack) ? organizationStack : [{ text: toStr(organizationStack) }];
|
|
472
|
+
|
|
473
|
+
if (!hasLogo || !logoDataUrl) {
|
|
474
|
+
return { stack: safeOrganizationStack };
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const logoBlock = {
|
|
478
|
+
width: 80,
|
|
479
|
+
image: logoDataUrl,
|
|
480
|
+
fit: [72, 72],
|
|
481
|
+
margin: [0, 2, 6, 0]
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
if (logoPosition === 'Top') {
|
|
485
|
+
return {
|
|
486
|
+
stack: [
|
|
487
|
+
{ image: logoDataUrl, fit: [72, 72], alignment: textAlignment, margin: [0, 2, 0, 6] },
|
|
488
|
+
...safeOrganizationStack
|
|
489
|
+
]
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
if (logoPosition === 'Right') {
|
|
494
|
+
return {
|
|
495
|
+
columns: [
|
|
496
|
+
{
|
|
497
|
+
width: '*',
|
|
498
|
+
stack: safeOrganizationStack
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
...logoBlock,
|
|
502
|
+
margin: [6, 2, 0, 0]
|
|
503
|
+
}
|
|
504
|
+
],
|
|
505
|
+
columnGap: 8
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return {
|
|
510
|
+
columns: [
|
|
511
|
+
logoBlock,
|
|
512
|
+
{
|
|
513
|
+
width: '*',
|
|
514
|
+
stack: safeOrganizationStack
|
|
515
|
+
}
|
|
516
|
+
],
|
|
517
|
+
columnGap: 8
|
|
518
|
+
};
|
|
519
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export function asDataUrl(value: any) {
|
|
2
|
+
if (typeof value !== 'string') {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
return /^data:image\//.test(value) ? value : null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function toStr(value: any) {
|
|
9
|
+
if (value === undefined || value === null) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
return String(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function readPositiveNumber(value: any, fallback: number) {
|
|
16
|
+
const parsed = Number(value);
|
|
17
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
18
|
+
return fallback;
|
|
19
|
+
}
|
|
20
|
+
return parsed;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function normalizeColor(value: any, fallback: string) {
|
|
24
|
+
const normalized = firstValue(value);
|
|
25
|
+
if (!normalized) {
|
|
26
|
+
return fallback;
|
|
27
|
+
}
|
|
28
|
+
if (/^#[0-9a-fA-F]{6}$/.test(normalized) || /^#[0-9a-fA-F]{3}$/.test(normalized)) {
|
|
29
|
+
return normalized;
|
|
30
|
+
}
|
|
31
|
+
return fallback;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function firstValue(...values: any[]) {
|
|
35
|
+
for (const value of values) {
|
|
36
|
+
if (value === undefined || value === null) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const normalized = String(value).trim();
|
|
40
|
+
if (normalized) {
|
|
41
|
+
return normalized;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return '';
|
|
45
|
+
}
|
|
46
|
+
|