@kashi-ui/persian 2.24.0 → 2.25.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 ADDED
@@ -0,0 +1,26 @@
1
+ /** نوع خدمت قبض، از رقم یکی‌مانده‌به‌آخر شناسهٔ قبض */
2
+ export type BillService = "water" | "electricity" | "gas" | "landline" | "mobile" | "municipality" | "tax" | "fine";
3
+ /** نام فارسی و انگلیسی نوع قبض */
4
+ export declare const BILL_SERVICE_NAMES: Record<BillService, string>;
5
+ export declare const BILL_SERVICE_NAMES_EN: Record<BillService, string>;
6
+ /** نوع قبض از روی شناسهٔ قبض؛ اگر شناسه معتبر نباشد null */
7
+ export declare function billService(billId: string): BillService | null;
8
+ /** شناسهٔ قبض: ۶ تا ۱۳ رقم، رقم آخر کنترل و رقم یکی‌مانده‌به‌آخر نوع خدمت است */
9
+ export declare function isValidBillId(billId: string): boolean;
10
+ export interface BillInfo {
11
+ service: BillService;
12
+ /** مبلغ به ریال (بخش اول شناسهٔ پرداخت × ۱۰۰۰) */
13
+ amount: number;
14
+ /** رقم آخر سال صدور، مثل 5 برای ۱۴۰۵ */
15
+ year: number;
16
+ /** شمارهٔ دوره (۱ تا ۹۹) */
17
+ period: number;
18
+ }
19
+ /**
20
+ * شناسهٔ پرداخت: ۶ تا ۱۳ رقم = مبلغ به هزار ریال + رقم سال + دو رقم دوره + دو رقم کنترل.
21
+ * کنترل اول روی خود شناسهٔ پرداخت و کنترل دوم روی «شناسهٔ قبض + شناسهٔ پرداخت» حساب می‌شود،
22
+ * پس شناسهٔ پرداخت فقط کنار شناسهٔ قبض خودش معتبر است.
23
+ */
24
+ export declare function isValidPaymentId(billId: string, paymentId: string): boolean;
25
+ /** اطلاعات قبض از روی شناسهٔ قبض و شناسهٔ پرداخت؛ اگر یکی نامعتبر باشد null */
26
+ export declare function parseBill(billId: string, paymentId: string): BillInfo | null;
package/dist/bill.js ADDED
@@ -0,0 +1,68 @@
1
+ import { onlyDigits } from "./digits.js";
2
+ const SERVICES = {
3
+ "1": "water", "2": "electricity", "3": "gas", "4": "landline",
4
+ "5": "mobile", "6": "municipality", "8": "tax", "9": "fine",
5
+ };
6
+ /** نام فارسی و انگلیسی نوع قبض */
7
+ export const BILL_SERVICE_NAMES = {
8
+ water: "آب", electricity: "برق", gas: "گاز", landline: "تلفن ثابت",
9
+ mobile: "تلفن همراه", municipality: "عوارض شهرداری", tax: "مالیات", fine: "جریمهٔ رانندگی",
10
+ };
11
+ export const BILL_SERVICE_NAMES_EN = {
12
+ water: "Water", electricity: "Electricity", gas: "Gas", landline: "Landline",
13
+ mobile: "Mobile", municipality: "Municipality", tax: "Tax", fine: "Traffic fine",
14
+ };
15
+ /**
16
+ * رقم کنترل استاندارد قبض‌ها (بانک مرکزی): ارقام از راست با وزن‌های ۲ تا ۷ (دوباره از ۲) ضرب و جمع می‌شوند؛
17
+ * باقی‌ماندهٔ تقسیم بر ۱۱ اگر ۰ یا ۱ باشد رقم کنترل ۰ است، وگرنه ۱۱ منهای آن.
18
+ */
19
+ function checkDigit(digits) {
20
+ let sum = 0;
21
+ let w = 2;
22
+ for (let i = digits.length - 1; i >= 0; i--) {
23
+ sum += Number(digits[i]) * w;
24
+ w = w === 7 ? 2 : w + 1;
25
+ }
26
+ const r = sum % 11;
27
+ return r < 2 ? 0 : 11 - r;
28
+ }
29
+ const clean = (v) => onlyDigits(v).replace(/^0+/, "");
30
+ /** نوع قبض از روی شناسهٔ قبض؛ اگر شناسه معتبر نباشد null */
31
+ export function billService(billId) {
32
+ const d = clean(billId);
33
+ if (d.length < 6 || d.length > 13)
34
+ return null;
35
+ return SERVICES[d[d.length - 2]] ?? null;
36
+ }
37
+ /** شناسهٔ قبض: ۶ تا ۱۳ رقم، رقم آخر کنترل و رقم یکی‌مانده‌به‌آخر نوع خدمت است */
38
+ export function isValidBillId(billId) {
39
+ const d = clean(billId);
40
+ if (!/^\d{6,13}$/.test(d) || !billService(d))
41
+ return false;
42
+ return checkDigit(d.slice(0, -1)) === Number(d[d.length - 1]);
43
+ }
44
+ /**
45
+ * شناسهٔ پرداخت: ۶ تا ۱۳ رقم = مبلغ به هزار ریال + رقم سال + دو رقم دوره + دو رقم کنترل.
46
+ * کنترل اول روی خود شناسهٔ پرداخت و کنترل دوم روی «شناسهٔ قبض + شناسهٔ پرداخت» حساب می‌شود،
47
+ * پس شناسهٔ پرداخت فقط کنار شناسهٔ قبض خودش معتبر است.
48
+ */
49
+ export function isValidPaymentId(billId, paymentId) {
50
+ return parseBill(billId, paymentId) !== null;
51
+ }
52
+ /** اطلاعات قبض از روی شناسهٔ قبض و شناسهٔ پرداخت؛ اگر یکی نامعتبر باشد null */
53
+ export function parseBill(billId, paymentId) {
54
+ const b = clean(billId);
55
+ const p = clean(paymentId);
56
+ if (!isValidBillId(b) || !/^\d{6,13}$/.test(p))
57
+ return null;
58
+ if (checkDigit(p.slice(0, -2)) !== Number(p[p.length - 2]))
59
+ return null;
60
+ if (checkDigit(b + p.slice(0, -1)) !== Number(p[p.length - 1]))
61
+ return null;
62
+ return {
63
+ service: billService(b),
64
+ amount: Number(p.slice(0, -5) || "0") * 1000,
65
+ year: Number(p[p.length - 5]),
66
+ period: Number(p.slice(-4, -2)),
67
+ };
68
+ }
@@ -0,0 +1,32 @@
1
+ /** بازهٔ تاریخ، هر دو سر شامل (نیمه‌شب به وقت محلی) */
2
+ export interface DateRange {
3
+ from: Date;
4
+ to: Date;
5
+ }
6
+ export type JalaliRangePresetId = "today" | "last-7" | "last-30" | "this-month" | "last-month" | "this-season" | "last-season" | "this-fiscal-year" | "last-fiscal-year";
7
+ export interface JalaliRangePreset extends DateRange {
8
+ id: JalaliRangePresetId;
9
+ }
10
+ /** فصل شمسی یک تاریخ: ۱ بهار، ۲ تابستان، ۳ پاییز، ۴ زمستان */
11
+ export declare function jalaliSeason(date: Date): {
12
+ jy: number;
13
+ season: 1 | 2 | 3 | 4;
14
+ };
15
+ /** بازهٔ یک فصل شمسی، مثلاً seasonRange(1405, 3) = ۱ مهر تا ۳۰ آذر ۱۴۰۵ */
16
+ export declare function seasonRange(jy: number, season: number): DateRange;
17
+ /** بازهٔ یک ماه شمسی */
18
+ export declare function jalaliMonthRange(jy: number, jm: number): DateRange;
19
+ /**
20
+ * سال مالی: از اول ماه startMonth سال jy تا روز پیش از همان تاریخ در سال بعد.
21
+ * پیش‌فرض ۱ (فروردین تا اسفند)، مثل بیشتر شرکت‌ها و سازمان امور مالیاتی.
22
+ */
23
+ export declare function fiscalYearRange(jy: number, startMonth?: number): DateRange;
24
+ /** سال مالی‌ای که این تاریخ در آن است (با سال شروعش نام‌گذاری می‌شود) */
25
+ export declare function fiscalYearOf(date: Date, startMonth?: number): number;
26
+ /**
27
+ * میان‌برهای آمادهٔ انتخاب بازه برای گزارش‌ها: امروز، ۷ و ۳۰ روز اخیر، ماه و فصل جاری و قبلی، سال مالی جاری و قبلی.
28
+ * برچسب‌ها در پیام‌های کاشی هستند (messages.dateRange.presets).
29
+ */
30
+ export declare function jalaliRangePresets(today?: Date, { fiscalStartMonth }?: {
31
+ fiscalStartMonth?: number;
32
+ }): JalaliRangePreset[];
package/dist/fiscal.js ADDED
@@ -0,0 +1,54 @@
1
+ import { jalaliMonthLength, toGregorian, toJalali } from "./jalali.js";
2
+ const day = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
3
+ const addDays = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
4
+ /** فصل شمسی یک تاریخ: ۱ بهار، ۲ تابستان، ۳ پاییز، ۴ زمستان */
5
+ export function jalaliSeason(date) {
6
+ const { jy, jm } = toJalali(date);
7
+ return { jy, season: Math.ceil(jm / 3) };
8
+ }
9
+ /** بازهٔ یک فصل شمسی، مثلاً seasonRange(1405, 3) = ۱ مهر تا ۳۰ آذر ۱۴۰۵ */
10
+ export function seasonRange(jy, season) {
11
+ const last = season * 3;
12
+ return { from: toGregorian(jy, last - 2, 1), to: toGregorian(jy, last, jalaliMonthLength(jy, last)) };
13
+ }
14
+ /** بازهٔ یک ماه شمسی */
15
+ export function jalaliMonthRange(jy, jm) {
16
+ return { from: toGregorian(jy, jm, 1), to: toGregorian(jy, jm, jalaliMonthLength(jy, jm)) };
17
+ }
18
+ /**
19
+ * سال مالی: از اول ماه startMonth سال jy تا روز پیش از همان تاریخ در سال بعد.
20
+ * پیش‌فرض ۱ (فروردین تا اسفند)، مثل بیشتر شرکت‌ها و سازمان امور مالیاتی.
21
+ */
22
+ export function fiscalYearRange(jy, startMonth = 1) {
23
+ const from = toGregorian(jy, startMonth, 1);
24
+ const to = addDays(toGregorian(jy + 1, startMonth, 1), -1);
25
+ return { from, to };
26
+ }
27
+ /** سال مالی‌ای که این تاریخ در آن است (با سال شروعش نام‌گذاری می‌شود) */
28
+ export function fiscalYearOf(date, startMonth = 1) {
29
+ const { jy, jm } = toJalali(date);
30
+ return jm >= startMonth ? jy : jy - 1;
31
+ }
32
+ /**
33
+ * میان‌برهای آمادهٔ انتخاب بازه برای گزارش‌ها: امروز، ۷ و ۳۰ روز اخیر، ماه و فصل جاری و قبلی، سال مالی جاری و قبلی.
34
+ * برچسب‌ها در پیام‌های کاشی هستند (messages.dateRange.presets).
35
+ */
36
+ export function jalaliRangePresets(today = new Date(), { fiscalStartMonth = 1 } = {}) {
37
+ const t = day(today);
38
+ const { jy, jm } = toJalali(t);
39
+ const { season } = jalaliSeason(t);
40
+ const prevMonth = jm === 1 ? { jy: jy - 1, jm: 12 } : { jy, jm: jm - 1 };
41
+ const prevSeason = season === 1 ? { jy: jy - 1, s: 4 } : { jy, s: season - 1 };
42
+ const fy = fiscalYearOf(t, fiscalStartMonth);
43
+ return [
44
+ { id: "today", from: t, to: t },
45
+ { id: "last-7", from: addDays(t, -6), to: t },
46
+ { id: "last-30", from: addDays(t, -29), to: t },
47
+ { id: "this-month", ...jalaliMonthRange(jy, jm) },
48
+ { id: "last-month", ...jalaliMonthRange(prevMonth.jy, prevMonth.jm) },
49
+ { id: "this-season", ...seasonRange(jy, season) },
50
+ { id: "last-season", ...seasonRange(prevSeason.jy, prevSeason.s) },
51
+ { id: "this-fiscal-year", ...fiscalYearRange(fy, fiscalStartMonth) },
52
+ { id: "last-fiscal-year", ...fiscalYearRange(fy - 1, fiscalStartMonth) },
53
+ ];
54
+ }
package/dist/index.d.ts CHANGED
@@ -36,5 +36,12 @@ export type { TimeRange, DayHours, WeekHours, SummarizeHoursOptions } from "./ho
36
36
  export { fixKeyboardLayout, looksLikeWrongLayout } from "./keyboard.js";
37
37
  export { formatMoney, rialToToman, tomanToRial } from "./money.js";
38
38
  export type { FormatMoneyOptions } from "./money.js";
39
+ export { isValidBillId, isValidPaymentId, billService, parseBill, BILL_SERVICE_NAMES, BILL_SERVICE_NAMES_EN } from "./bill.js";
40
+ export type { BillService, BillInfo } from "./bill.js";
41
+ export { jalaliSeason, seasonRange, jalaliMonthRange, fiscalYearRange, fiscalYearOf, jalaliRangePresets } from "./fiscal.js";
42
+ export type { DateRange, JalaliRangePreset, JalaliRangePresetId } from "./fiscal.js";
43
+ export { normalizeForSearch, searchSkeleton, persianMatch, persianFilter } from "./search.js";
44
+ export { toXlsx } from "./xlsx.js";
45
+ export type { XlsxCell, XlsxOptions } from "./xlsx.js";
39
46
  export { faMessages, enMessages, getMessages } from "./messages.js";
40
47
  export type { KashiMessages, KashiMessagesInput, KashiLocale } from "./messages.js";
package/dist/index.js CHANGED
@@ -21,4 +21,8 @@ export { economicCodeType, isValidEconomicCode, normalizeTaxId, isValidTaxId } f
21
21
  export { defaultWeekHours, invalidRanges, isOpenAt, summarizeHours } from "./hours.js";
22
22
  export { fixKeyboardLayout, looksLikeWrongLayout } from "./keyboard.js";
23
23
  export { formatMoney, rialToToman, tomanToRial } from "./money.js";
24
+ export { isValidBillId, isValidPaymentId, billService, parseBill, BILL_SERVICE_NAMES, BILL_SERVICE_NAMES_EN } from "./bill.js";
25
+ export { jalaliSeason, seasonRange, jalaliMonthRange, fiscalYearRange, fiscalYearOf, jalaliRangePresets } from "./fiscal.js";
26
+ export { normalizeForSearch, searchSkeleton, persianMatch, persianFilter } from "./search.js";
27
+ export { toXlsx } from "./xlsx.js";
24
28
  export { faMessages, enMessages, getMessages } from "./messages.js";
@@ -37,6 +37,8 @@ export declare const faMessages: {
37
37
  list: string;
38
38
  range: string;
39
39
  percent: (n: string) => string;
40
+ /** جداکنندهٔ فهرست در متن صفحه‌خوان */
41
+ comma: string;
40
42
  decimal: string;
41
43
  };
42
44
  money: {
@@ -166,6 +168,11 @@ export declare const faMessages: {
166
168
  left: string;
167
169
  };
168
170
  table: {
171
+ pinned: string;
172
+ edit: (col: string, row: string) => string;
173
+ editHint: string;
174
+ saved: string;
175
+ exportExcel: string;
169
176
  selectAll: string;
170
177
  selectRow: string;
171
178
  selectNamed: (row: string) => string;
@@ -188,6 +195,10 @@ export declare const faMessages: {
188
195
  last30: (n: string) => string;
189
196
  thisMonth: string;
190
197
  lastMonth: string;
198
+ today: string;
199
+ thisSeason: string;
200
+ lastSeason: string;
201
+ fiscalYear: (y: string) => string;
191
202
  };
192
203
  monthPicker: {
193
204
  label: string;
@@ -229,6 +240,8 @@ export declare const faMessages: {
229
240
  sayad: string;
230
241
  economicCode: string;
231
242
  taxId: string;
243
+ billId: string;
244
+ paymentId: string;
232
245
  mobile: string;
233
246
  landline: string;
234
247
  postal: string;
@@ -341,6 +354,8 @@ export declare const faMessages: {
341
354
  sayad: string;
342
355
  "economic-code": string;
343
356
  "tax-id": string;
357
+ "bill-id": string;
358
+ "payment-id": string;
344
359
  };
345
360
  taxCode: {
346
361
  person: string;
@@ -606,6 +621,102 @@ export declare const faMessages: {
606
621
  noEvents: string;
607
622
  slot: (day: string, time: string) => string;
608
623
  };
624
+ bill: {
625
+ service: {
626
+ water: string;
627
+ electricity: string;
628
+ gas: string;
629
+ landline: string;
630
+ mobile: string;
631
+ municipality: string;
632
+ tax: string;
633
+ fine: string;
634
+ };
635
+ amount: string;
636
+ period: (year: string, period: string) => string;
637
+ needBill: string;
638
+ };
639
+ invoice: {
640
+ official: string;
641
+ proforma: string;
642
+ number: string;
643
+ date: string;
644
+ validUntil: string;
645
+ seller: string;
646
+ buyer: string;
647
+ name: string;
648
+ economicCode: string;
649
+ nationalId: string;
650
+ postal: string;
651
+ phone: string;
652
+ address: string;
653
+ taxId: string;
654
+ row: string;
655
+ description: string;
656
+ quantity: string;
657
+ unit: string;
658
+ unitPrice: string;
659
+ discount: string;
660
+ lineTotal: string;
661
+ subtotal: string;
662
+ totalDiscount: string;
663
+ vat: (rate: string) => string;
664
+ payable: string;
665
+ inWords: (words: string, unit: string) => string;
666
+ rial: string;
667
+ toman: string;
668
+ notes: string;
669
+ sellerSign: string;
670
+ buyerSign: string;
671
+ print: string;
672
+ };
673
+ signature: {
674
+ label: string;
675
+ clear: string;
676
+ undo: string;
677
+ draw: string;
678
+ type: string;
679
+ hint: string;
680
+ typedLabel: string;
681
+ empty: string;
682
+ signed: string;
683
+ cleared: string;
684
+ area: string;
685
+ };
686
+ cropper: {
687
+ label: string;
688
+ zoom: string;
689
+ rotate: string;
690
+ reset: string;
691
+ apply: string;
692
+ area: string;
693
+ moved: (x: string, y: string) => string;
694
+ zoomed: (z: string) => string;
695
+ };
696
+ gantt: {
697
+ label: string;
698
+ task: string;
699
+ start: string;
700
+ end: string;
701
+ today: string;
702
+ days: (n: string) => string;
703
+ progress: (p: string) => string;
704
+ bar: (name: string, from: string, to: string, p: string) => string;
705
+ moved: (name: string, from: string, to: string) => string;
706
+ dependsOn: (name: string) => string;
707
+ hint: string;
708
+ };
709
+ infinite: {
710
+ loading: string;
711
+ end: string;
712
+ error: string;
713
+ retry: string;
714
+ loadMore: string;
715
+ loaded: (n: string) => string;
716
+ };
717
+ virtualList: {
718
+ label: (n: string) => string;
719
+ };
609
720
  };
610
721
  export type KashiMessages = typeof faMessages;
611
722
  export declare const enMessages: KashiMessages;
package/dist/messages.js CHANGED
@@ -36,6 +36,8 @@ export const faMessages = {
36
36
  list: "، ",
37
37
  range: " تا ",
38
38
  percent: (n) => `${n}٪`,
39
+ /** جداکنندهٔ فهرست در متن صفحه‌خوان */
40
+ comma: "، ",
39
41
  decimal: "٫",
40
42
  },
41
43
  money: { toman: "تومان", rial: "ریال", positive: "مثبت " },
@@ -68,11 +70,12 @@ export const faMessages = {
68
70
  contextMenu: { label: "گزینه‌ها", hint: "برای دیدن گزینه‌ها، دکمهٔ راست ماوس را بزنید، انگشت را روی آن نگه دارید یا ‎Shift+F10‎ را بزنید." },
69
71
  copy: { copy: "کپی", copied: "کپی شد", failed: "کپی نشد" },
70
72
  countdown: { days: "روز", hours: "ساعت", minutes: "دقیقه", seconds: "ثانیه", left: "مانده" },
71
- table: { selectAll: "انتخاب همهٔ ردیف‌ها", selectRow: "انتخاب ردیف", selectNamed: (row) => `انتخاب ${row}`, empty: "داده‌ای وجود ندارد.", sort: (col) => `مرتب‌سازی بر اساس ${col}`, search: "جستجو در جدول", rows: (n) => `${n} ردیف` },
73
+ table: { pinned: "ستون ثابت", edit: (col, row) => `ویرایش ${col} در ${row}`, editHint: "برای ویرایش Enter یا دوبار کلیک کنید؛ Esc برای انصراف.", saved: "ذخیره شد.", exportExcel: "خروجی اکسل", selectAll: "انتخاب همهٔ ردیف‌ها", selectRow: "انتخاب ردیف", selectNamed: (row) => `انتخاب ${row}`, empty: "داده‌ای وجود ندارد.", sort: (col) => `مرتب‌سازی بر اساس ${col}`, search: "جستجو در جدول", rows: (n) => `${n} ردیف` },
72
74
  datePicker: { label: "تاریخ", invalid: "این تاریخ معتبر نیست؛ آن را به شکل ۱۴۰۳/۰۵/۱۲ وارد کنید.", open: "انتخاب تاریخ از تقویم" },
73
75
  dateRange: {
74
76
  label: "بازهٔ تاریخ", placeholder: "انتخاب بازهٔ تاریخ", presets: "میان‌برها", pickEnd: "حالا تاریخ پایان را انتخاب کنید.",
75
77
  last7: (n) => `${n} روز اخیر`, last30: (n) => `${n} روز اخیر`, thisMonth: "این ماه", lastMonth: "ماه قبل",
78
+ today: "امروز", thisSeason: "فصل جاری", lastSeason: "فصل قبل", fiscalYear: (y) => `سال مالی ${y}`,
76
79
  },
77
80
  monthPicker: { label: "انتخاب ماه", prevYear: "سال قبل", nextYear: "سال بعد" },
78
81
  timePicker: { clock: "انتخاب ساعت", open: "انتخاب ساعت از روی ساعت", hour: "ساعت", minute: "دقیقه", now: "اکنون" },
@@ -88,6 +91,7 @@ export const faMessages = {
88
91
  card: "شماره کارت معتبر نیست.", iban: "شماره شبا معتبر نیست.", nationalId: "کد ملی معتبر نیست.", legalId: "شناسهٔ ملی معتبر نیست.",
89
92
  sayad: "شناسهٔ صیادی باید ۱۶ رقم باشد.", economicCode: "کد اقتصادی معتبر نیست؛ کد ملی، شناسهٔ ملی یا کد ۱۲ رقمی قدیمی را وارد کنید.",
90
93
  taxId: "شمارهٔ مالیاتی فاکتور باید ۲۲ نویسه از ارقام و حروف لاتین باشد.",
94
+ billId: "شناسهٔ قبض معتبر نیست؛ آن را از روی قبض دوباره بخوانید.", paymentId: "شناسهٔ پرداخت با این شناسهٔ قبض جور نیست.",
91
95
  mobile: "شماره موبایل معتبر نیست.", landline: "شمارهٔ تلفن ثابت معتبر نیست.", postal: "کد پستی معتبر نیست.", plate: "پلاک خودرو معتبر نیست.",
92
96
  time: "ساعت معتبر نیست؛ آن را به شکل ۰۹:۳۰ وارد کنید.", timeRange: (a, b) => `ساعت باید بین ${a} و ${b} باشد.`,
93
97
  priceMin: (n) => `مبلغ باید حداقل ${n} باشد.`, priceMax: (n) => `مبلغ باید حداکثر ${n} باشد.`,
@@ -129,7 +133,7 @@ export const faMessages = {
129
133
  persianInput: {
130
134
  text: "متن", "national-id": "کد ملی", "legal-id": "شناسهٔ ملی شرکت", mobile: "شمارهٔ موبایل", landline: "تلفن ثابت",
131
135
  card: "شمارهٔ کارت", iban: "شمارهٔ شبا", price: "مبلغ", postal: "کد پستی", time: "ساعت", plate: "پلاک خودرو",
132
- sayad: "شناسهٔ صیادی چک", "economic-code": "کد اقتصادی", "tax-id": "شمارهٔ مالیاتی فاکتور",
136
+ sayad: "شناسهٔ صیادی چک", "economic-code": "کد اقتصادی", "tax-id": "شمارهٔ مالیاتی فاکتور", "bill-id": "شناسهٔ قبض", "payment-id": "شناسهٔ پرداخت",
133
137
  },
134
138
  taxCode: { person: "شخص حقیقی", company: "شخص حقوقی", legacy: "کد قدیمی" },
135
139
  textFix: {
@@ -217,6 +221,40 @@ export const faMessages = {
217
221
  label: "برنامهٔ زمانی", week: "هفته", day: "روز", prevWeek: "هفتهٔ قبل", nextWeek: "هفتهٔ بعد", prevDay: "روز قبل", nextDay: "روز بعد",
218
222
  now: "اکنون", view: "نما", events: (n) => `${n} رویداد`, noEvents: "بدون رویداد", slot: (day, time) => `${day} ساعت ${time}، افزودن رویداد`,
219
223
  },
224
+ bill: {
225
+ service: { water: "آب", electricity: "برق", gas: "گاز", landline: "تلفن ثابت", mobile: "تلفن همراه", municipality: "عوارض شهرداری", tax: "مالیات", fine: "جریمهٔ رانندگی" },
226
+ amount: "مبلغ", period: (year, period) => `دورهٔ ${period}، سال …${year}`, needBill: "اول شناسهٔ قبض را وارد کنید.",
227
+ },
228
+ invoice: {
229
+ official: "صورتحساب فروش کالا و خدمات", proforma: "پیش‌فاکتور", number: "شماره", date: "تاریخ", validUntil: "اعتبار تا",
230
+ seller: "مشخصات فروشنده", buyer: "مشخصات خریدار", name: "نام", economicCode: "کد اقتصادی", nationalId: "شناسهٔ ملی / کد ملی",
231
+ postal: "کد پستی", phone: "تلفن", address: "نشانی", taxId: "شمارهٔ مالیاتی",
232
+ row: "ردیف", description: "شرح کالا یا خدمت", quantity: "تعداد", unit: "واحد", unitPrice: "مبلغ واحد", discount: "تخفیف",
233
+ lineTotal: "مبلغ کل", subtotal: "جمع کل", totalDiscount: "جمع تخفیف", vat: (rate) => `مالیات و عوارض ارزش افزوده (${rate}٪)`,
234
+ payable: "مبلغ قابل پرداخت", inWords: (words, unit) => `${words} ${unit}`, rial: "ریال", toman: "تومان",
235
+ notes: "توضیحات", sellerSign: "مهر و امضای فروشنده", buyerSign: "امضای خریدار", print: "چاپ یا ذخیرهٔ PDF",
236
+ },
237
+ signature: {
238
+ label: "امضا", clear: "پاک کردن", undo: "برگرداندن آخرین خط", draw: "رسم امضا", type: "تایپ امضا",
239
+ hint: "با ماوس، قلم یا انگشت داخل کادر امضا کنید.", typedLabel: "نام خود را برای امضا تایپ کنید", empty: "امضا خالی است.",
240
+ signed: "امضا ثبت شد.", cleared: "امضا پاک شد.", area: "کادر امضا",
241
+ },
242
+ cropper: {
243
+ label: "برش تصویر", zoom: "بزرگ‌نمایی", rotate: "چرخش ۹۰ درجه", reset: "بازنشانی", apply: "برش",
244
+ area: "کادر برش؛ با کلیدهای جهت جابه‌جا کنید و با + و − بزرگ و کوچک کنید.", moved: (x, y) => `کادر در ${x}٪ و ${y}٪`,
245
+ zoomed: (z) => `بزرگ‌نمایی ${z}٪`,
246
+ },
247
+ gantt: {
248
+ label: "نمودار گانت", task: "کار", start: "شروع", end: "پایان", today: "امروز", days: (n) => `${n} روز`,
249
+ progress: (p) => `${p}٪ انجام‌شده`, bar: (name, from, to, p) => `${name}، از ${from} تا ${to}، ${p}٪ انجام‌شده`,
250
+ moved: (name, from, to) => `${name} به ${from} تا ${to} منتقل شد.`, dependsOn: (name) => `وابسته به ${name}`,
251
+ hint: "با کلیدهای جهت جابه‌جا کنید و با Shift طول را تغییر دهید.",
252
+ },
253
+ infinite: {
254
+ loading: "در حال بارگذاری موارد بیشتر", end: "همهٔ موارد نمایش داده شد.", error: "موارد بیشتر بارگذاری نشد.", retry: "تلاش دوباره",
255
+ loadMore: "نمایش موارد بیشتر", loaded: (n) => `${n} مورد دیگر بارگذاری شد.`,
256
+ },
257
+ virtualList: { label: (n) => `فهرست ${n} موردی` },
220
258
  };
221
259
  export const enMessages = {
222
260
  common: {
@@ -251,6 +289,7 @@ export const enMessages = {
251
289
  list: ", ",
252
290
  range: " – ",
253
291
  percent: (n) => `${n}%`,
292
+ comma: ", ",
254
293
  decimal: ".",
255
294
  },
256
295
  money: { toman: "Toman", rial: "Rial", positive: "plus " },
@@ -283,11 +322,12 @@ export const enMessages = {
283
322
  contextMenu: { label: "Options", hint: "Right-click, long-press or press Shift+F10 for options." },
284
323
  copy: { copy: "Copy", copied: "Copied", failed: "Copy failed" },
285
324
  countdown: { days: "days", hours: "hours", minutes: "minutes", seconds: "seconds", left: "left" },
286
- table: { selectAll: "Select all rows", selectRow: "Select row", selectNamed: (row) => `Select ${row}`, empty: "No data.", sort: (col) => `Sort by ${col}`, search: "Search the table", rows: (n) => `${n} ${n === "1" ? "row" : "rows"}` },
325
+ table: { pinned: "Pinned column", edit: (col, row) => `Edit ${col} in ${row}`, editHint: "Press Enter or double-click to edit; Esc to cancel.", saved: "Saved.", exportExcel: "Export to Excel", selectAll: "Select all rows", selectRow: "Select row", selectNamed: (row) => `Select ${row}`, empty: "No data.", sort: (col) => `Sort by ${col}`, search: "Search the table", rows: (n) => `${n} ${n === "1" ? "row" : "rows"}` },
287
326
  datePicker: { label: "Date", invalid: "Invalid date; enter it like 1403/05/12.", open: "Choose a date from the calendar" },
288
327
  dateRange: {
289
328
  label: "Date range", placeholder: "Select a date range", presets: "Shortcuts", pickEnd: "Now choose the end date.",
290
329
  last7: (n) => `Last ${n} days`, last30: (n) => `Last ${n} days`, thisMonth: "This month", lastMonth: "Last month",
330
+ today: "Today", thisSeason: "This season", lastSeason: "Last season", fiscalYear: (y) => `Fiscal year ${y}`,
291
331
  },
292
332
  monthPicker: { label: "Choose a month", prevYear: "Previous year", nextYear: "Next year" },
293
333
  timePicker: { clock: "Choose a time", open: "Choose a time from the clock", hour: "Hour", minute: "Minute", now: "Now" },
@@ -303,6 +343,7 @@ export const enMessages = {
303
343
  card: "Invalid card number.", iban: "Invalid IBAN.", nationalId: "Invalid national ID.", legalId: "Invalid company ID.",
304
344
  sayad: "A Sayad ID has 16 digits.", economicCode: "Invalid economic code; enter a national ID, company ID or the old 12-digit code.",
305
345
  taxId: "An invoice tax ID has 22 Latin letters and digits.",
346
+ billId: "Invalid bill ID; read it from the bill again.", paymentId: "This payment ID doesn't match the bill ID.",
306
347
  mobile: "Invalid mobile number.", landline: "Invalid phone number.", postal: "Invalid postal code.", plate: "Invalid license plate.",
307
348
  time: "Invalid time; enter it like 09:30.", timeRange: (a, b) => `Time must be between ${a} and ${b}.`,
308
349
  priceMin: (n) => `Amount must be at least ${n}.`, priceMax: (n) => `Amount must be at most ${n}.`,
@@ -344,7 +385,7 @@ export const enMessages = {
344
385
  persianInput: {
345
386
  text: "Text", "national-id": "National ID", "legal-id": "Company ID", mobile: "Mobile number", landline: "Phone number",
346
387
  card: "Card number", iban: "IBAN", price: "Amount", postal: "Postal code", time: "Time", plate: "License plate",
347
- sayad: "Cheque Sayad ID", "economic-code": "Economic code", "tax-id": "Invoice tax ID",
388
+ sayad: "Cheque Sayad ID", "economic-code": "Economic code", "tax-id": "Invoice tax ID", "bill-id": "Bill ID", "payment-id": "Payment ID",
348
389
  },
349
390
  taxCode: { person: "Individual", company: "Company", legacy: "Old code" },
350
391
  textFix: {
@@ -432,6 +473,40 @@ export const enMessages = {
432
473
  label: "Schedule", week: "Week", day: "Day", prevWeek: "Previous week", nextWeek: "Next week", prevDay: "Previous day", nextDay: "Next day",
433
474
  now: "Now", view: "View", events: (n) => `${n} events`, noEvents: "No events", slot: (day, time) => `${day} at ${time}, add event`,
434
475
  },
476
+ bill: {
477
+ service: { water: "Water", electricity: "Electricity", gas: "Gas", landline: "Landline", mobile: "Mobile", municipality: "Municipality", tax: "Tax", fine: "Traffic fine" },
478
+ amount: "Amount", period: (year, period) => `Period ${period}, year …${year}`, needBill: "Enter the bill ID first.",
479
+ },
480
+ invoice: {
481
+ official: "Sales invoice", proforma: "Proforma invoice", number: "No.", date: "Date", validUntil: "Valid until",
482
+ seller: "Seller", buyer: "Buyer", name: "Name", economicCode: "Economic code", nationalId: "Company or national ID",
483
+ postal: "Postal code", phone: "Phone", address: "Address", taxId: "Tax ID",
484
+ row: "#", description: "Item or service", quantity: "Qty", unit: "Unit", unitPrice: "Unit price", discount: "Discount",
485
+ lineTotal: "Total", subtotal: "Subtotal", totalDiscount: "Total discount", vat: (rate) => `VAT (${rate}%)`,
486
+ payable: "Amount due", inWords: (words, unit) => `${words} ${unit}`, rial: "rials", toman: "tomans",
487
+ notes: "Notes", sellerSign: "Seller's stamp and signature", buyerSign: "Buyer's signature", print: "Print or save as PDF",
488
+ },
489
+ signature: {
490
+ label: "Signature", clear: "Clear", undo: "Undo last stroke", draw: "Draw", type: "Type",
491
+ hint: "Sign inside the box with a mouse, pen or finger.", typedLabel: "Type your name to sign", empty: "The signature is empty.",
492
+ signed: "Signature added.", cleared: "Signature cleared.", area: "Signature area",
493
+ },
494
+ cropper: {
495
+ label: "Crop image", zoom: "Zoom", rotate: "Rotate 90°", reset: "Reset", apply: "Crop",
496
+ area: "Crop area; move it with the arrow keys and zoom with + and −.", moved: (x, y) => `Crop at ${x}% and ${y}%`,
497
+ zoomed: (z) => `Zoom ${z}%`,
498
+ },
499
+ gantt: {
500
+ label: "Gantt chart", task: "Task", start: "Start", end: "End", today: "Today", days: (n) => `${n} ${n === "1" ? "day" : "days"}`,
501
+ progress: (p) => `${p}% done`, bar: (name, from, to, p) => `${name}, ${from} to ${to}, ${p}% done`,
502
+ moved: (name, from, to) => `${name} moved to ${from} – ${to}.`, dependsOn: (name) => `Depends on ${name}`,
503
+ hint: "Move with the arrow keys; hold Shift to change the length.",
504
+ },
505
+ infinite: {
506
+ loading: "Loading more items", end: "You've reached the end.", error: "Couldn't load more items.", retry: "Try again",
507
+ loadMore: "Show more", loaded: (n) => `${n} more ${n === "1" ? "item" : "items"} loaded.`,
508
+ },
509
+ virtualList: { label: (n) => `List of ${n} items` },
435
510
  };
436
511
  /** فرهنگ کامل: پایهٔ زبان (fa یا en) به‌اضافهٔ متن‌هایی که خودتان عوض کرده‌اید */
437
512
  export function getMessages(locale = "fa", overrides) {
@@ -0,0 +1,14 @@
1
+ /**
2
+ * یکدست‌سازی برای مقایسه (نه برای نمایش): حروف کوچک، ارقام لاتین، «ي/ى» ← «ی»، «ك» ← «ک»، «ة/ۀ» ← «ه»،
3
+ * «أ/إ/ٱ» ← «ا»، «ؤ» ← «و»، بدون اعراب و کشیده، و بدون نیم‌فاصله (پس «میخواهم» با «می‌خواهم» یکی است).
4
+ */
5
+ export declare function normalizeForSearch(text: string): string;
6
+ /** اسکلت صامت متن، واژه‌به‌واژه، برای پیدا کردن «ممد» با «mamad» یا «علی» با «ali» */
7
+ export declare function searchSkeleton(text: string): string[];
8
+ /**
9
+ * امتیاز تطبیق پرسش با متن (۰ یعنی نه). ترتیب: شروع متن ۴، شروع یک واژه ۳، هر جای متن ۲،
10
+ * بعد تطبیق آوایی فینگلیش و فارسی (۱٫۶ تا ۰٫۸). پرسشی که با چیدمان اشتباه صفحه‌کلید تایپ شده («hdvhk») هم پیدا می‌شود.
11
+ */
12
+ export declare function persianMatch(query: string, text: string): number;
13
+ /** فیلتر و مرتب‌سازی فهرست با persianMatch؛ بهترین‌ها اول، با حفظ ترتیب اصلی در امتیاز برابر */
14
+ export declare function persianFilter<T>(items: readonly T[], query: string, toText?: (item: T) => string): T[];
package/dist/search.js ADDED
@@ -0,0 +1,136 @@
1
+ import { toEnDigits } from "./digits.js";
2
+ import { fixKeyboardLayout, looksLikeWrongLayout } from "./keyboard.js";
3
+ /**
4
+ * یکدست‌سازی برای مقایسه (نه برای نمایش): حروف کوچک، ارقام لاتین، «ي/ى» ← «ی»، «ك» ← «ک»، «ة/ۀ» ← «ه»،
5
+ * «أ/إ/ٱ» ← «ا»، «ؤ» ← «و»، بدون اعراب و کشیده، و بدون نیم‌فاصله (پس «میخواهم» با «می‌خواهم» یکی است).
6
+ */
7
+ export function normalizeForSearch(text) {
8
+ return toEnDigits(text)
9
+ .toLowerCase()
10
+ .replace(/[يى]/g, "ی")
11
+ .replace(/ك/g, "ک")
12
+ .replace(/[ةۀ]/g, "ه")
13
+ .replace(/[أإٱ]/g, "ا")
14
+ .replace(/ؤ/g, "و")
15
+ .replace(/[ً-ٰٟـ]/g, "")
16
+ .replace(/[‌‍‎‏]/g, "")
17
+ .replace(/\s+/g, " ")
18
+ .trim();
19
+ }
20
+ // نگاشت حروف فارسی به صامت لاتین؛ حروف هم‌صدا (ث س ص، ذ ز ض ظ، ت ط، ح ه، غ ق) یکی می‌شوند
21
+ const FA = {
22
+ ب: "b", پ: "p", ت: "t", ث: "s", ج: "j", چ: "C", ح: "h", خ: "x", د: "d", ذ: "z", ر: "r", ز: "z", ژ: "J",
23
+ س: "s", ش: "S", ص: "s", ض: "z", ط: "t", ظ: "z", غ: "q", ف: "f", ق: "q", ک: "k", گ: "g", ل: "l", م: "m",
24
+ ن: "n", ه: "h", و: "v", ی: "y", ا: "", آ: "", ع: "", ء: "", ئ: "y",
25
+ };
26
+ /** اسکلت صامت یک واژهٔ فارسی: «محمد» ← mhmd، «ممد» ← mmd */
27
+ function faWord(w) {
28
+ let out = "";
29
+ for (let i = 0; i < w.length; i++) {
30
+ const c = w[i];
31
+ if (/[0-9]/.test(c)) {
32
+ out += c;
33
+ continue;
34
+ }
35
+ let m = FA[c];
36
+ if (m === undefined)
37
+ continue;
38
+ // «و» و «ی» وسط و آخر واژه بیشتر صدادارند (u/o/i) تا صامت؛ «ه» آخر واژه هم صدای e است
39
+ if ((c === "و" || c === "ی") && i > 0)
40
+ m = "";
41
+ if (c === "ه" && i === w.length - 1 && i > 0)
42
+ m = "";
43
+ out += m;
44
+ }
45
+ return out;
46
+ }
47
+ /** اسکلت صامت یک واژهٔ فینگلیش: «mamad» ← mmd، «khosro» ← xsr */
48
+ function latinWord(w) {
49
+ let s = w
50
+ .replace(/kh/g, "x").replace(/gh/g, "q").replace(/sh/g, "S").replace(/ch/g, "C").replace(/zh/g, "J")
51
+ .replace(/ph/g, "f").replace(/c/g, "k").replace(/w/g, "v").replace(/'/g, "")
52
+ .replace(/(?<=[aeiou])h$/, "");
53
+ let out = "";
54
+ for (let i = 0; i < s.length; i++) {
55
+ const c = s[i];
56
+ if ("aeiou".includes(c))
57
+ continue;
58
+ if ((c === "v" || c === "y") && i > 0)
59
+ continue;
60
+ if (/[a-zA-Z0-9]/.test(c))
61
+ out += c;
62
+ }
63
+ return out;
64
+ }
65
+ const collapse = (s) => s.replace(/(.)\1+/g, "$1");
66
+ /** اسکلت صامت متن، واژه‌به‌واژه، برای پیدا کردن «ممد» با «mamad» یا «علی» با «ali» */
67
+ export function searchSkeleton(text) {
68
+ return normalizeForSearch(text)
69
+ .split(/[\s\-_.,،]+/)
70
+ .filter(Boolean)
71
+ .map((w) => collapse(/[a-z]/.test(w) ? latinWord(w) : faWord(w)));
72
+ }
73
+ function textScore(q, t) {
74
+ if (!q)
75
+ return 1;
76
+ if (t.startsWith(q))
77
+ return 4;
78
+ if (t.includes(" " + q))
79
+ return 3;
80
+ if (t.includes(q))
81
+ return 2;
82
+ return 0;
83
+ }
84
+ function skeletonScore(q, t, typed) {
85
+ const qs = q.join("");
86
+ if (!qs)
87
+ return 0;
88
+ // پرسش کوتاه یک‌صامتی («t»، «sh») فقط با شروع متن جور می‌شود تا فهرست شلوغ نشود
89
+ if (qs.length === 1 && typed < 3)
90
+ return t[0]?.startsWith(qs) ? 1.2 : 0;
91
+ // واژه‌های پرسش به ترتیب، هرکدام پیشوند یکی از واژه‌های متن
92
+ let ti = 0;
93
+ let firstAt = -1;
94
+ for (const w of q) {
95
+ while (ti < t.length && !t[ti].startsWith(w))
96
+ ti++;
97
+ if (ti === t.length) {
98
+ // تطبیق داخل یک واژه، به شرط این‌که صامت اول هم یکی باشد («mamad» ← «محمد»، ولی نه «احمدی»)
99
+ return q.length === 1 && t.some((w) => w[0] === qs[0] && w.includes(qs)) ? 0.8 : 0;
100
+ }
101
+ if (firstAt < 0)
102
+ firstAt = ti;
103
+ ti++;
104
+ }
105
+ return firstAt === 0 ? 1.6 : 1.3;
106
+ }
107
+ /**
108
+ * امتیاز تطبیق پرسش با متن (۰ یعنی نه). ترتیب: شروع متن ۴، شروع یک واژه ۳، هر جای متن ۲،
109
+ * بعد تطبیق آوایی فینگلیش و فارسی (۱٫۶ تا ۰٫۸). پرسشی که با چیدمان اشتباه صفحه‌کلید تایپ شده («hdvhk») هم پیدا می‌شود.
110
+ */
111
+ export function persianMatch(query, text) {
112
+ const q = normalizeForSearch(query);
113
+ if (!q)
114
+ return 1;
115
+ const t = normalizeForSearch(text);
116
+ const direct = textScore(q, t);
117
+ if (direct)
118
+ return direct;
119
+ if (looksLikeWrongLayout(query)) {
120
+ const fixed = normalizeForSearch(fixKeyboardLayout(query, "fa"));
121
+ const s = textScore(fixed, t);
122
+ if (s)
123
+ return s - 0.1;
124
+ }
125
+ return skeletonScore(searchSkeleton(q), searchSkeleton(t), q.replace(/\s/g, "").length);
126
+ }
127
+ /** فیلتر و مرتب‌سازی فهرست با persianMatch؛ بهترین‌ها اول، با حفظ ترتیب اصلی در امتیاز برابر */
128
+ export function persianFilter(items, query, toText = String) {
129
+ if (!normalizeForSearch(query))
130
+ return items.slice();
131
+ return items
132
+ .map((item, i) => ({ item, i, s: persianMatch(query, toText(item)) }))
133
+ .filter((x) => x.s > 0)
134
+ .sort((a, b) => b.s - a.s || a.i - b.i)
135
+ .map((x) => x.item);
136
+ }
package/dist/xlsx.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ export type XlsxCell = string | number | boolean | Date | null | undefined;
2
+ export interface XlsxOptions {
3
+ /** نام برگه @default "Sheet1" */
4
+ sheetName?: string;
5
+ /** برگهٔ راست‌به‌چپ (ستون A در راست) @default true */
6
+ rtl?: boolean;
7
+ /** تاریخ‌ها به‌صورت متن شمسی مثل ۱۴۰۵/۰۹/۱۱ نوشته شوند @default true */
8
+ jalali?: boolean;
9
+ /** ارقام تاریخ شمسی @default "latin" (اکسل با ارقام لاتین بهتر مرتب می‌کند) */
10
+ digits?: "fa" | "latin";
11
+ }
12
+ /**
13
+ * ساخت فایل اکسل (xlsx) از ردیف‌ها، بدون وابستگی: سطر اول سرستون پررنگ، برگهٔ راست‌به‌چپ، و تاریخ‌ها شمسی.
14
+ * عددها عدد می‌مانند تا در اکسل جمع و مرتب شوند.
15
+ */
16
+ export declare function toXlsx(header: string[], rows: XlsxCell[][], { sheetName, rtl, jalali, digits }?: XlsxOptions): Uint8Array;
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) => ({ "<": "&lt;", ">": "&gt;", "&": "&amp;", '"': "&quot;" })[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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kashi-ui/persian",
3
- "version": "2.24.0",
3
+ "version": "2.25.0",
4
4
  "description": "ابزارهای فارسی کاشی: تاریخ شمسی، اعتبارسنجی کد ملی و شماره کارت، ارقام فارسی",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",