@kashi-ui/persian 2.24.1 → 2.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bill.d.ts +26 -0
- package/dist/bill.js +68 -0
- package/dist/fiscal.d.ts +32 -0
- package/dist/fiscal.js +54 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +6 -0
- package/dist/messages-fa.d.ts +712 -0
- package/dist/messages-fa.js +253 -0
- package/dist/messages.d.ts +110 -0
- package/dist/messages.js +118 -215
- package/dist/search.d.ts +14 -0
- package/dist/search.js +136 -0
- package/dist/xlsx.d.ts +16 -0
- package/dist/xlsx.js +105 -0
- package/package.json +1 -1
package/dist/xlsx.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { formatJalali } from "./jalali.js";
|
|
2
|
+
const enc = new TextEncoder();
|
|
3
|
+
const esc = (s) => s.replace(/[<>&"]/g, (c) => ({ "<": "<", ">": ">", "&": "&", '"': """ })[c]).replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g, "");
|
|
4
|
+
let CRC = null;
|
|
5
|
+
function crc32(b) {
|
|
6
|
+
if (!CRC) {
|
|
7
|
+
CRC = new Uint32Array(256);
|
|
8
|
+
for (let n = 0; n < 256; n++) {
|
|
9
|
+
let c = n;
|
|
10
|
+
for (let k = 0; k < 8; k++)
|
|
11
|
+
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
12
|
+
CRC[n] = c >>> 0;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
let c = 0xffffffff;
|
|
16
|
+
for (let i = 0; i < b.length; i++)
|
|
17
|
+
c = CRC[(c ^ b[i]) & 0xff] ^ (c >>> 8);
|
|
18
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
19
|
+
}
|
|
20
|
+
/** فایل zip بدون فشردهسازی (store)؛ برای xlsx کافی است و کد را کوچک نگه میدارد */
|
|
21
|
+
function zip(files) {
|
|
22
|
+
const parts = [];
|
|
23
|
+
const central = [];
|
|
24
|
+
let offset = 0;
|
|
25
|
+
for (const [name, text] of files) {
|
|
26
|
+
const nameB = enc.encode(name);
|
|
27
|
+
const data = enc.encode(text);
|
|
28
|
+
const crc = crc32(data);
|
|
29
|
+
const local = new Uint8Array(30 + nameB.length);
|
|
30
|
+
const v = new DataView(local.buffer);
|
|
31
|
+
v.setUint32(0, 0x04034b50, true);
|
|
32
|
+
v.setUint16(4, 20, true);
|
|
33
|
+
v.setUint16(6, 0x0800, true);
|
|
34
|
+
v.setUint32(14, crc, true);
|
|
35
|
+
v.setUint32(18, data.length, true);
|
|
36
|
+
v.setUint32(22, data.length, true);
|
|
37
|
+
v.setUint16(26, nameB.length, true);
|
|
38
|
+
local.set(nameB, 30);
|
|
39
|
+
const cen = new Uint8Array(46 + nameB.length);
|
|
40
|
+
const w = new DataView(cen.buffer);
|
|
41
|
+
w.setUint32(0, 0x02014b50, true);
|
|
42
|
+
w.setUint16(4, 20, true);
|
|
43
|
+
w.setUint16(6, 20, true);
|
|
44
|
+
w.setUint16(8, 0x0800, true);
|
|
45
|
+
w.setUint32(16, crc, true);
|
|
46
|
+
w.setUint32(20, data.length, true);
|
|
47
|
+
w.setUint32(24, data.length, true);
|
|
48
|
+
w.setUint16(28, nameB.length, true);
|
|
49
|
+
w.setUint32(42, offset, true);
|
|
50
|
+
cen.set(nameB, 46);
|
|
51
|
+
parts.push(local, data);
|
|
52
|
+
central.push(cen);
|
|
53
|
+
offset += local.length + data.length;
|
|
54
|
+
}
|
|
55
|
+
const cenSize = central.reduce((s, c) => s + c.length, 0);
|
|
56
|
+
const end = new Uint8Array(22);
|
|
57
|
+
const e = new DataView(end.buffer);
|
|
58
|
+
e.setUint32(0, 0x06054b50, true);
|
|
59
|
+
e.setUint16(8, files.length, true);
|
|
60
|
+
e.setUint16(10, files.length, true);
|
|
61
|
+
e.setUint32(12, cenSize, true);
|
|
62
|
+
e.setUint32(16, offset, true);
|
|
63
|
+
const all = [...parts, ...central, end];
|
|
64
|
+
const out = new Uint8Array(all.reduce((s, p) => s + p.length, 0));
|
|
65
|
+
let p = 0;
|
|
66
|
+
for (const a of all) {
|
|
67
|
+
out.set(a, p);
|
|
68
|
+
p += a.length;
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
const col = (i) => { let s = ""; for (i++; i > 0; i = Math.floor((i - 1) / 26))
|
|
73
|
+
s = String.fromCharCode(65 + ((i - 1) % 26)) + s; return s; };
|
|
74
|
+
/**
|
|
75
|
+
* ساخت فایل اکسل (xlsx) از ردیفها، بدون وابستگی: سطر اول سرستون پررنگ، برگهٔ راستبهچپ، و تاریخها شمسی.
|
|
76
|
+
* عددها عدد میمانند تا در اکسل جمع و مرتب شوند.
|
|
77
|
+
*/
|
|
78
|
+
export function toXlsx(header, rows, { sheetName = "Sheet1", rtl = true, jalali = true, digits = "latin" } = {}) {
|
|
79
|
+
const cell = (v, r, c, style = 0) => {
|
|
80
|
+
const ref = `${col(c)}${r + 1}`;
|
|
81
|
+
const s = style ? ` s="${style}"` : "";
|
|
82
|
+
if (v == null || v === "")
|
|
83
|
+
return "";
|
|
84
|
+
if (typeof v === "number" && Number.isFinite(v))
|
|
85
|
+
return `<c r="${ref}"${s}><v>${v}</v></c>`;
|
|
86
|
+
if (typeof v === "boolean")
|
|
87
|
+
return `<c r="${ref}" t="b"${s}><v>${v ? 1 : 0}</v></c>`;
|
|
88
|
+
const text = v instanceof Date ? (jalali ? formatJalali(v, { digits }) : v.toISOString().slice(0, 10)) : String(v);
|
|
89
|
+
return `<c r="${ref}" t="inlineStr"${s}><is><t xml:space="preserve">${esc(text)}</t></is></c>`;
|
|
90
|
+
};
|
|
91
|
+
const all = [header, ...rows];
|
|
92
|
+
const widths = header.map((_, c) => Math.min(60, Math.max(8, ...all.map((r) => String(r[c] instanceof Date ? "1400/00/00" : (r[c] ?? "")).length + 2))));
|
|
93
|
+
const sheet = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
94
|
+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetViews><sheetView workbookViewId="0"${rtl ? ' rightToLeft="1"' : ""}><pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen"/></sheetView></sheetViews><cols>${widths.map((w, i) => `<col min="${i + 1}" max="${i + 1}" width="${w}" customWidth="1"/>`).join("")}</cols><sheetData>${all
|
|
95
|
+
.map((r, ri) => `<row r="${ri + 1}">${r.map((v, ci) => cell(v, ri, ci, ri === 0 ? 1 : 0)).join("")}</row>`)
|
|
96
|
+
.join("")}</sheetData></worksheet>`;
|
|
97
|
+
return zip([
|
|
98
|
+
["[Content_Types].xml", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/></Types>`],
|
|
99
|
+
["_rels/.rels", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>`],
|
|
100
|
+
["xl/workbook.xml", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><sheets><sheet name="${esc(sheetName.slice(0, 31))}" sheetId="1" r:id="rId1"/></sheets></workbook>`],
|
|
101
|
+
["xl/_rels/workbook.xml.rels", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/></Relationships>`],
|
|
102
|
+
["xl/styles.xml", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fonts count="2"><font><sz val="11"/><name val="Tahoma"/></font><font><b/><sz val="11"/><name val="Tahoma"/></font></fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills><borders count="1"><border/></borders><cellStyleXfs count="1"><xf/></cellStyleXfs><cellXfs count="2"><xf/><xf fontId="1" applyFont="1"/></cellXfs></styleSheet>`],
|
|
103
|
+
["xl/worksheets/sheet1.xml", sheet],
|
|
104
|
+
]);
|
|
105
|
+
}
|