@appcorp/fusion-storybook 0.5.40 → 0.6.2
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/attendance-register/documents/download.d.ts +2 -0
- package/attendance-register/documents/download.js +13 -0
- package/attendance-register/documents/image-text.d.ts +37 -0
- package/attendance-register/documents/image-text.js +103 -0
- package/attendance-register/documents/pdf.d.ts +40 -0
- package/attendance-register/documents/pdf.js +425 -0
- package/attendance-register/documents/zip-files.d.ts +2 -0
- package/attendance-register/documents/zip-files.js +5 -0
- package/attendance-register/documents/zip.d.ts +13 -0
- package/attendance-register/documents/zip.js +29 -0
- package/attendance-register/domain/calendar.d.ts +28 -0
- package/attendance-register/domain/calendar.js +150 -0
- package/attendance-register/domain/locale.d.ts +26 -0
- package/attendance-register/domain/locale.js +87 -0
- package/attendance-register/domain/register.d.ts +50 -0
- package/attendance-register/domain/register.js +116 -0
- package/attendance-register/domain/student-import.d.ts +51 -0
- package/attendance-register/domain/student-import.js +231 -0
- package/attendance-register/domain/week.d.ts +40 -0
- package/attendance-register/domain/week.js +90 -0
- package/attendance-register/index.d.ts +21 -0
- package/attendance-register/index.js +19 -0
- package/attendance-register/react/register-preview.d.ts +34 -0
- package/attendance-register/react/register-preview.js +88 -0
- package/attendance-register/react/use-attendance-register.d.ts +33 -0
- package/attendance-register/react/use-attendance-register.js +106 -0
- package/attendance-register/types.d.ts +90 -0
- package/attendance-register/types.js +22 -0
- package/base-modules/attendance/page.d.ts +2 -0
- package/base-modules/attendance/page.js +21 -1
- package/constants.d.ts +2 -3
- package/constants.js +2 -3
- package/package.json +3 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/communication.d.ts +3 -59
- package/types/communication.js +2 -2
- package/types/user-management.d.ts +0 -6
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AttendanceDay, WeekGroup, WeekStart } from "../types";
|
|
2
|
+
/** Advances one calendar month, rolling December into January of the next year. */
|
|
3
|
+
export declare function getNextMonth(month: string, year: number): {
|
|
4
|
+
month: string;
|
|
5
|
+
year: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function getDaysInMonth(month: string, year: number, weekendDays?: readonly number[], locale?: string): AttendanceDay[];
|
|
8
|
+
/**
|
|
9
|
+
* Groups a month into week rows. Weeks run Monday–Sunday or Sunday–Saturday,
|
|
10
|
+
* and slots outside the month are null so every week has exactly seven columns.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getWeekGroups(month: string, year: number, weekStartsOn: WeekStart, weekendDays?: readonly number[], locale?: string): WeekGroup[];
|
|
13
|
+
export interface ParsedNoSchoolDays {
|
|
14
|
+
days: number[];
|
|
15
|
+
invalid: string[];
|
|
16
|
+
/** ISO dates that belong to a different month and were ignored. */
|
|
17
|
+
outOfMonth: string[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Accepts day numbers ("5, 6, 15"), ranges ("5-7"), weekday rules ("friday" or
|
|
21
|
+
* "every friday") and ISO dates ("2026-11-26"). Weekday rules and out-of-month
|
|
22
|
+
* checks need the `context` (the register's month and year).
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseNoSchoolDays(input: string, daysInMonth: number, context?: {
|
|
25
|
+
monthIndex: number;
|
|
26
|
+
year: number;
|
|
27
|
+
}): ParsedNoSchoolDays;
|
|
28
|
+
export declare function getWorkingDays(days: AttendanceDay[], noSchoolDays: number[]): number;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { formatWeekdayShort } from "./locale";
|
|
2
|
+
import { DEFAULT_WEEKEND_DAYS, MONTHS, } from "../types";
|
|
3
|
+
/** Advances one calendar month, rolling December into January of the next year. */
|
|
4
|
+
export function getNextMonth(month, year) {
|
|
5
|
+
const index = MONTHS.indexOf(month);
|
|
6
|
+
if (index < 0)
|
|
7
|
+
return { month, year };
|
|
8
|
+
if (index === MONTHS.length - 1)
|
|
9
|
+
return { month: MONTHS[0], year: year + 1 };
|
|
10
|
+
return { month: MONTHS[index + 1], year };
|
|
11
|
+
}
|
|
12
|
+
export function getDaysInMonth(month, year, weekendDays = DEFAULT_WEEKEND_DAYS, locale = "en") {
|
|
13
|
+
const monthIndex = MONTHS.indexOf(month);
|
|
14
|
+
if (monthIndex < 0)
|
|
15
|
+
return [];
|
|
16
|
+
const daysInMonth = new Date(year, monthIndex + 1, 0).getDate();
|
|
17
|
+
const closed = new Set(weekendDays);
|
|
18
|
+
const days = [];
|
|
19
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
20
|
+
const date = new Date(year, monthIndex, day);
|
|
21
|
+
const weekday = formatWeekdayShort(date, locale);
|
|
22
|
+
const isWeekend = closed.has(date.getDay());
|
|
23
|
+
days.push({ day, weekday, isWeekend });
|
|
24
|
+
}
|
|
25
|
+
return days;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Groups a month into week rows. Weeks run Monday–Sunday or Sunday–Saturday,
|
|
29
|
+
* and slots outside the month are null so every week has exactly seven columns.
|
|
30
|
+
*/
|
|
31
|
+
export function getWeekGroups(month, year, weekStartsOn, weekendDays = DEFAULT_WEEKEND_DAYS, locale = "en") {
|
|
32
|
+
const days = getDaysInMonth(month, year, weekendDays, locale);
|
|
33
|
+
if (days.length === 0)
|
|
34
|
+
return [];
|
|
35
|
+
const monthIndex = MONTHS.indexOf(month);
|
|
36
|
+
const firstWeekday = new Date(year, monthIndex, 1).getDay();
|
|
37
|
+
const weekStartIndex = weekStartsOn === "monday" ? 1 : 0;
|
|
38
|
+
const offset = (firstWeekday - weekStartIndex + 7) % 7;
|
|
39
|
+
const weeks = [];
|
|
40
|
+
for (const day of days) {
|
|
41
|
+
const position = offset + day.day - 1;
|
|
42
|
+
const weekIndex = Math.floor(position / 7);
|
|
43
|
+
const slotIndex = position % 7;
|
|
44
|
+
if (!weeks[weekIndex]) {
|
|
45
|
+
weeks[weekIndex] = {
|
|
46
|
+
weekNumber: weekIndex + 1,
|
|
47
|
+
startDay: day.day,
|
|
48
|
+
endDay: day.day,
|
|
49
|
+
slots: Array.from({ length: 7 }, () => null),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
weeks[weekIndex].slots[slotIndex] = day;
|
|
53
|
+
weeks[weekIndex].endDay = day.day;
|
|
54
|
+
}
|
|
55
|
+
return weeks.filter(Boolean);
|
|
56
|
+
}
|
|
57
|
+
const WEEKDAY_TOKENS = {
|
|
58
|
+
sun: 0,
|
|
59
|
+
sunday: 0,
|
|
60
|
+
mon: 1,
|
|
61
|
+
monday: 1,
|
|
62
|
+
tue: 2,
|
|
63
|
+
tues: 2,
|
|
64
|
+
tuesday: 2,
|
|
65
|
+
wed: 3,
|
|
66
|
+
wednesday: 3,
|
|
67
|
+
thu: 4,
|
|
68
|
+
thur: 4,
|
|
69
|
+
thurs: 4,
|
|
70
|
+
thursday: 4,
|
|
71
|
+
fri: 5,
|
|
72
|
+
friday: 5,
|
|
73
|
+
sat: 6,
|
|
74
|
+
saturday: 6,
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Accepts day numbers ("5, 6, 15"), ranges ("5-7"), weekday rules ("friday" or
|
|
78
|
+
* "every friday") and ISO dates ("2026-11-26"). Weekday rules and out-of-month
|
|
79
|
+
* checks need the `context` (the register's month and year).
|
|
80
|
+
*/
|
|
81
|
+
export function parseNoSchoolDays(input, daysInMonth, context) {
|
|
82
|
+
const invalid = [];
|
|
83
|
+
const outOfMonth = [];
|
|
84
|
+
const days = new Set();
|
|
85
|
+
const normalized = input
|
|
86
|
+
.replace(/\bevery\s+(sun(?:day)?|mon(?:day)?|tue(?:s|sday)?|wed(?:nesday)?|thu(?:r|rs|rsday)?|fri(?:day)?|sat(?:urday)?)\b/gi, "$1")
|
|
87
|
+
.replace(/\s*[-–]\s*/g, "-");
|
|
88
|
+
const tokens = normalized
|
|
89
|
+
.split(/[\s,;]+/)
|
|
90
|
+
.map((token) => token.trim())
|
|
91
|
+
.filter(Boolean);
|
|
92
|
+
for (const token of tokens) {
|
|
93
|
+
const iso = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(token);
|
|
94
|
+
if (iso) {
|
|
95
|
+
const year = Number(iso[1]);
|
|
96
|
+
const monthIndex = Number(iso[2]) - 1;
|
|
97
|
+
const day = Number(iso[3]);
|
|
98
|
+
const validDate = monthIndex >= 0 &&
|
|
99
|
+
monthIndex <= 11 &&
|
|
100
|
+
day >= 1 &&
|
|
101
|
+
day <= new Date(year, monthIndex + 1, 0).getDate();
|
|
102
|
+
if (!validDate) {
|
|
103
|
+
invalid.push(token);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (context && (year !== context.year || monthIndex !== context.monthIndex)) {
|
|
107
|
+
outOfMonth.push(token);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
days.add(day);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const range = /^(\d{1,2})\s*[-–]\s*(\d{1,2})$/.exec(token);
|
|
114
|
+
if (range) {
|
|
115
|
+
const start = Number(range[1]);
|
|
116
|
+
const end = Number(range[2]);
|
|
117
|
+
if (start < 1 || end > daysInMonth || start > end) {
|
|
118
|
+
invalid.push(token);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
for (let day = start; day <= end; day++)
|
|
122
|
+
days.add(day);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (!/^\d{1,2}$/.test(token)) {
|
|
126
|
+
const weekday = WEEKDAY_TOKENS[token.toLowerCase()];
|
|
127
|
+
if (weekday !== undefined && context) {
|
|
128
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
129
|
+
if (new Date(context.year, context.monthIndex, day).getDay() === weekday) {
|
|
130
|
+
days.add(day);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
invalid.push(token);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const day = Number(token);
|
|
139
|
+
if (day < 1 || day > daysInMonth) {
|
|
140
|
+
invalid.push(token);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
days.add(day);
|
|
144
|
+
}
|
|
145
|
+
return { days: [...days].sort((a, b) => a - b), invalid, outOfMonth };
|
|
146
|
+
}
|
|
147
|
+
export function getWorkingDays(days, noSchoolDays) {
|
|
148
|
+
const noSchool = new Set(noSchoolDays);
|
|
149
|
+
return days.filter((day) => !day.isWeekend && !noSchool.has(day.day)).length;
|
|
150
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localisation for register labels.
|
|
3
|
+
*
|
|
4
|
+
* The tool stores the month as an English key (it is an identifier, not a
|
|
5
|
+
* label). Display text is derived with `Intl` so a Spanish or Portuguese
|
|
6
|
+
* school sees its own month and weekday names.
|
|
7
|
+
*
|
|
8
|
+
* Only Latin-script locales that the embedded PDF font can render are listed.
|
|
9
|
+
* Non-Latin scripts need the image-based PDF path and are added separately.
|
|
10
|
+
*/
|
|
11
|
+
export interface RegisterLocale {
|
|
12
|
+
code: string;
|
|
13
|
+
label: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const REGISTER_LOCALES: RegisterLocale[];
|
|
16
|
+
export declare function needsRasterLabels(locale: string): boolean;
|
|
17
|
+
export declare function isRtlLocale(locale: string): boolean;
|
|
18
|
+
export declare const DEFAULT_REGISTER_LOCALE = "en";
|
|
19
|
+
export declare function isSupportedLocale(code?: string): boolean;
|
|
20
|
+
/** Maps a browser locale such as "es-MX" to a supported base language. */
|
|
21
|
+
export declare function detectRegisterLocale(locale?: string): string;
|
|
22
|
+
/** Month name for a 0-based index, e.g. (0, "es") -> "enero". */
|
|
23
|
+
export declare function formatMonthName(monthIndex: number, locale: string): string;
|
|
24
|
+
export declare function formatMonthYear(monthIndex: number, year: number, locale: string): string;
|
|
25
|
+
/** Short weekday label, capitalised to match the printed register style. */
|
|
26
|
+
export declare function formatWeekdayShort(date: Date, locale: string): string;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export const REGISTER_LOCALES = [
|
|
2
|
+
{ code: "en", label: "English" },
|
|
3
|
+
{ code: "es", label: "Español" },
|
|
4
|
+
{ code: "fr", label: "Français" },
|
|
5
|
+
{ code: "pt", label: "Português" },
|
|
6
|
+
{ code: "de", label: "Deutsch" },
|
|
7
|
+
{ code: "it", label: "Italiano" },
|
|
8
|
+
{ code: "nl", label: "Nederlands" },
|
|
9
|
+
{ code: "id", label: "Bahasa Indonesia" },
|
|
10
|
+
{ code: "ms", label: "Bahasa Melayu" },
|
|
11
|
+
{ code: "sw", label: "Kiswahili" },
|
|
12
|
+
{ code: "fil", label: "Filipino" },
|
|
13
|
+
{ code: "ar", label: "العربية" },
|
|
14
|
+
{ code: "hi", label: "हिन्दी" },
|
|
15
|
+
{ code: "bn", label: "বাংলা" },
|
|
16
|
+
{ code: "ur", label: "اردو" },
|
|
17
|
+
{ code: "zh", label: "中文" },
|
|
18
|
+
{ code: "ru", label: "Русский" },
|
|
19
|
+
{ code: "fa", label: "فارسی" },
|
|
20
|
+
{ code: "ta", label: "தமிழ்" },
|
|
21
|
+
{ code: "th", label: "ไทย" },
|
|
22
|
+
{ code: "he", label: "עברית" },
|
|
23
|
+
{ code: "el", label: "Ελληνικά" },
|
|
24
|
+
{ code: "am", label: "አማርኛ" },
|
|
25
|
+
{ code: "ja", label: "日本語" },
|
|
26
|
+
{ code: "ko", label: "한국어" },
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Locales whose month/weekday labels cannot be drawn by jsPDF's text engine.
|
|
30
|
+
* Their labels are rendered by the browser and placed as an image instead.
|
|
31
|
+
*/
|
|
32
|
+
const RASTER_LABEL_LOCALES = new Set([
|
|
33
|
+
"ar",
|
|
34
|
+
"hi",
|
|
35
|
+
"bn",
|
|
36
|
+
"ur",
|
|
37
|
+
"zh",
|
|
38
|
+
"ru",
|
|
39
|
+
"fa",
|
|
40
|
+
"ta",
|
|
41
|
+
"th",
|
|
42
|
+
"he",
|
|
43
|
+
"el",
|
|
44
|
+
"am",
|
|
45
|
+
"ja",
|
|
46
|
+
"ko",
|
|
47
|
+
]);
|
|
48
|
+
export function needsRasterLabels(locale) {
|
|
49
|
+
return RASTER_LABEL_LOCALES.has(locale);
|
|
50
|
+
}
|
|
51
|
+
/** Locales that print the register grid right-to-left. */
|
|
52
|
+
const RTL_LOCALES = new Set(["ar", "ur", "fa", "he"]);
|
|
53
|
+
export function isRtlLocale(locale) {
|
|
54
|
+
return RTL_LOCALES.has(locale);
|
|
55
|
+
}
|
|
56
|
+
export const DEFAULT_REGISTER_LOCALE = "en";
|
|
57
|
+
const SUPPORTED = new Set(REGISTER_LOCALES.map((locale) => locale.code));
|
|
58
|
+
export function isSupportedLocale(code) {
|
|
59
|
+
return Boolean(code && SUPPORTED.has(code));
|
|
60
|
+
}
|
|
61
|
+
/** Maps a browser locale such as "es-MX" to a supported base language. */
|
|
62
|
+
export function detectRegisterLocale(locale) {
|
|
63
|
+
const base = (locale !== null && locale !== void 0 ? locale : "").trim().toLowerCase().split(/[-_]/)[0];
|
|
64
|
+
return SUPPORTED.has(base) ? base : DEFAULT_REGISTER_LOCALE;
|
|
65
|
+
}
|
|
66
|
+
function formatWithFallback(locale, options, date, fallback) {
|
|
67
|
+
try {
|
|
68
|
+
return new Intl.DateTimeFormat(isSupportedLocale(locale) ? locale : "en", options).format(date);
|
|
69
|
+
}
|
|
70
|
+
catch (_a) {
|
|
71
|
+
return fallback;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** Month name for a 0-based index, e.g. (0, "es") -> "enero". */
|
|
75
|
+
export function formatMonthName(monthIndex, locale) {
|
|
76
|
+
const date = new Date(2026, monthIndex, 1);
|
|
77
|
+
return formatWithFallback(locale, { month: "long" }, date, "January");
|
|
78
|
+
}
|
|
79
|
+
export function formatMonthYear(monthIndex, year, locale) {
|
|
80
|
+
const date = new Date(year, monthIndex, 1);
|
|
81
|
+
return formatWithFallback(locale, { month: "long", year: "numeric" }, date, `${formatMonthName(monthIndex, "en")} ${year}`);
|
|
82
|
+
}
|
|
83
|
+
/** Short weekday label, capitalised to match the printed register style. */
|
|
84
|
+
export function formatWeekdayShort(date, locale) {
|
|
85
|
+
const label = formatWithFallback(locale, { weekday: "short" }, date, "Mon");
|
|
86
|
+
return label.charAt(0).toUpperCase() + label.slice(1);
|
|
87
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AttendanceDay, AttendanceMark, PaperFormat, RegisterConfig, RegisterDensity, RegisterLayout, RegisterRoster, Student } from "../types";
|
|
2
|
+
export declare const PAGE_MARGIN = 12;
|
|
3
|
+
export declare const PDF_HEADER_HEIGHT = 24;
|
|
4
|
+
export declare const PDF_BOTTOM_BAND = 28;
|
|
5
|
+
export declare const PDF_ROW_HEIGHT = 6.5;
|
|
6
|
+
export declare const PDF_ROW_HEIGHT_COMPACT = 5.2;
|
|
7
|
+
export declare const PDF_HEADER_ROW_HEIGHT = 8;
|
|
8
|
+
export declare const PDF_WEEKDAY_ROW_HEIGHT = 4.5;
|
|
9
|
+
export interface PageDimensions {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function getRowHeight(density?: RegisterDensity): number;
|
|
14
|
+
export declare function getPageDimensions(format: PaperFormat, layout: RegisterLayout): PageDimensions;
|
|
15
|
+
export declare function getMaxStudentsPerPage(format: PaperFormat, layout: RegisterLayout, density?: RegisterDensity): number;
|
|
16
|
+
export declare function getStudentChunks(students: Student[], maxStudentsPerPage: number): Student[][];
|
|
17
|
+
export interface ColumnWidths {
|
|
18
|
+
serial: number;
|
|
19
|
+
name: number;
|
|
20
|
+
day: number;
|
|
21
|
+
total: number;
|
|
22
|
+
all: number[];
|
|
23
|
+
}
|
|
24
|
+
export declare function calculateColumnWidths(dayCount: number, totalWidth: number): ColumnWidths;
|
|
25
|
+
export declare function getNoSchoolSet(config: RegisterConfig): Set<number>;
|
|
26
|
+
export declare function isNonWorkingDay(day: AttendanceDay, noSchoolDays: Set<number>): boolean;
|
|
27
|
+
export interface RegisterSummary {
|
|
28
|
+
totalStudents: number;
|
|
29
|
+
totalDays: number;
|
|
30
|
+
workingDays: number;
|
|
31
|
+
weekends: number;
|
|
32
|
+
noSchoolDays: number;
|
|
33
|
+
pageCount: number;
|
|
34
|
+
}
|
|
35
|
+
export declare function getRegisterSummary(config: RegisterConfig): RegisterSummary;
|
|
36
|
+
export declare function formatClassLabel(config: RegisterConfig): string;
|
|
37
|
+
export declare function slugifyFilenamePart(value: string, fallback: string): string;
|
|
38
|
+
export declare function getRegisterFilename(config: RegisterConfig, extension: "pdf" | "xlsx" | "csv"): string;
|
|
39
|
+
export interface RegisterConfigBase {
|
|
40
|
+
month: string;
|
|
41
|
+
year: number;
|
|
42
|
+
noSchoolDays: number[];
|
|
43
|
+
schoolName: string;
|
|
44
|
+
attendance?: RegisterConfig["attendance"];
|
|
45
|
+
}
|
|
46
|
+
/** Combines a reusable roster with the month-specific register settings. */
|
|
47
|
+
export declare function buildRegisterConfig(roster: RegisterRoster, base: RegisterConfigBase): RegisterConfig;
|
|
48
|
+
export declare function buildRegisterConfigs(rosters: RegisterRoster[], base: RegisterConfigBase): RegisterConfig[];
|
|
49
|
+
export declare function getAttendanceMark(config: RegisterConfig, studentId: string, day: number): AttendanceMark | undefined;
|
|
50
|
+
export declare function getBatchFilename(month: string, year: number): string;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { getDaysInMonth, getWeekGroups, getWorkingDays } from "./calendar";
|
|
2
|
+
export const PAGE_MARGIN = 12;
|
|
3
|
+
export const PDF_HEADER_HEIGHT = 24;
|
|
4
|
+
export const PDF_BOTTOM_BAND = 28;
|
|
5
|
+
export const PDF_ROW_HEIGHT = 6.5;
|
|
6
|
+
export const PDF_ROW_HEIGHT_COMPACT = 5.2;
|
|
7
|
+
export const PDF_HEADER_ROW_HEIGHT = 8;
|
|
8
|
+
export const PDF_WEEKDAY_ROW_HEIGHT = 4.5;
|
|
9
|
+
/** Short and long edge in millimetres. */
|
|
10
|
+
const PAPER_DIMENSIONS = {
|
|
11
|
+
a4: [210, 297],
|
|
12
|
+
a3: [297, 420],
|
|
13
|
+
letter: [216, 279],
|
|
14
|
+
legal: [216, 356],
|
|
15
|
+
};
|
|
16
|
+
export function getRowHeight(density = "standard") {
|
|
17
|
+
return density === "compact" ? PDF_ROW_HEIGHT_COMPACT : PDF_ROW_HEIGHT;
|
|
18
|
+
}
|
|
19
|
+
export function getPageDimensions(format, layout) {
|
|
20
|
+
var _a;
|
|
21
|
+
const [shortSide, longSide] = (_a = PAPER_DIMENSIONS[format]) !== null && _a !== void 0 ? _a : PAPER_DIMENSIONS.a4;
|
|
22
|
+
return layout === "monthly"
|
|
23
|
+
? { width: longSide, height: shortSide }
|
|
24
|
+
: { width: shortSide, height: longSide };
|
|
25
|
+
}
|
|
26
|
+
export function getMaxStudentsPerPage(format, layout, density = "standard") {
|
|
27
|
+
const { height } = getPageDimensions(format, layout);
|
|
28
|
+
const usable = height -
|
|
29
|
+
PAGE_MARGIN * 2 -
|
|
30
|
+
PDF_HEADER_HEIGHT -
|
|
31
|
+
PDF_BOTTOM_BAND -
|
|
32
|
+
PDF_HEADER_ROW_HEIGHT -
|
|
33
|
+
PDF_WEEKDAY_ROW_HEIGHT;
|
|
34
|
+
return Math.max(1, Math.floor(usable / getRowHeight(density)));
|
|
35
|
+
}
|
|
36
|
+
export function getStudentChunks(students, maxStudentsPerPage) {
|
|
37
|
+
if (students.length === 0)
|
|
38
|
+
return [];
|
|
39
|
+
const chunks = [];
|
|
40
|
+
for (let index = 0; index < students.length; index += maxStudentsPerPage) {
|
|
41
|
+
chunks.push(students.slice(index, index + maxStudentsPerPage));
|
|
42
|
+
}
|
|
43
|
+
return chunks;
|
|
44
|
+
}
|
|
45
|
+
export function calculateColumnWidths(dayCount, totalWidth) {
|
|
46
|
+
const serial = 7;
|
|
47
|
+
const total = 12;
|
|
48
|
+
const name = Math.max(38, Math.min(48, totalWidth * 0.24));
|
|
49
|
+
const day = (totalWidth - serial - name - total) / Math.max(1, dayCount);
|
|
50
|
+
return {
|
|
51
|
+
serial,
|
|
52
|
+
name,
|
|
53
|
+
day,
|
|
54
|
+
total,
|
|
55
|
+
all: [serial, name, ...Array(dayCount).fill(day), total],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function getNoSchoolSet(config) {
|
|
59
|
+
return new Set(config.noSchoolDays);
|
|
60
|
+
}
|
|
61
|
+
export function isNonWorkingDay(day, noSchoolDays) {
|
|
62
|
+
return day.isWeekend || noSchoolDays.has(day.day);
|
|
63
|
+
}
|
|
64
|
+
export function getRegisterSummary(config) {
|
|
65
|
+
const days = getDaysInMonth(config.month, config.year, config.weekendDays);
|
|
66
|
+
const noSchool = getNoSchoolSet(config);
|
|
67
|
+
const weekends = days.filter((day) => day.isWeekend).length;
|
|
68
|
+
const noSchoolDays = days.filter((day) => !day.isWeekend && noSchool.has(day.day)).length;
|
|
69
|
+
const maxStudents = getMaxStudentsPerPage(config.format, config.layout, config.density);
|
|
70
|
+
const chunks = getStudentChunks(config.students, maxStudents);
|
|
71
|
+
const weekCount = config.layout === "weekly"
|
|
72
|
+
? getWeekGroups(config.month, config.year, config.weekStartsOn, config.weekendDays).length
|
|
73
|
+
: 1;
|
|
74
|
+
return {
|
|
75
|
+
totalStudents: config.students.length,
|
|
76
|
+
totalDays: days.length,
|
|
77
|
+
workingDays: getWorkingDays(days, config.noSchoolDays),
|
|
78
|
+
weekends,
|
|
79
|
+
noSchoolDays,
|
|
80
|
+
pageCount: chunks.length * weekCount,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export function formatClassLabel(config) {
|
|
84
|
+
return `${config.className}${config.section ? ` - ${config.section}` : ""}${config.grade ? ` | Grade: ${config.grade}` : ""}`;
|
|
85
|
+
}
|
|
86
|
+
export function slugifyFilenamePart(value, fallback) {
|
|
87
|
+
const slug = value
|
|
88
|
+
.normalize("NFKD")
|
|
89
|
+
// Strip combining accents so "Łódź" and "5º" stay readable in filenames.
|
|
90
|
+
.replace(/[\u0300-\u036f]/g, "")
|
|
91
|
+
.toLowerCase()
|
|
92
|
+
// Keep letters and numbers in any script; collapse everything else.
|
|
93
|
+
.replace(/[^\p{L}\p{N}]+/gu, "_")
|
|
94
|
+
.replace(/^_+|_+$/g, "");
|
|
95
|
+
return slug || fallback;
|
|
96
|
+
}
|
|
97
|
+
export function getRegisterFilename(config, extension) {
|
|
98
|
+
const classPart = slugifyFilenamePart(config.className, "class");
|
|
99
|
+
const sectionPart = config.section ? `_${slugifyFilenamePart(config.section, "section")}` : "";
|
|
100
|
+
const monthPart = slugifyFilenamePart(config.month, "month");
|
|
101
|
+
return `attendance_register_${classPart}${sectionPart}_${monthPart}_${config.year}_${config.layout}.${extension}`;
|
|
102
|
+
}
|
|
103
|
+
/** Combines a reusable roster with the month-specific register settings. */
|
|
104
|
+
export function buildRegisterConfig(roster, base) {
|
|
105
|
+
return Object.assign({ className: roster.className, section: roster.section, grade: roster.grade, month: base.month, year: base.year, format: roster.format, layout: roster.layout, density: roster.density, weekStartsOn: roster.weekStartsOn, weekendDays: roster.weekendDays, noSchoolDays: base.noSchoolDays, students: roster.students, schoolName: base.schoolName, locale: roster.locale }, (base.attendance ? { attendance: base.attendance } : {}));
|
|
106
|
+
}
|
|
107
|
+
export function buildRegisterConfigs(rosters, base) {
|
|
108
|
+
return rosters.map((roster) => buildRegisterConfig(roster, base));
|
|
109
|
+
}
|
|
110
|
+
export function getAttendanceMark(config, studentId, day) {
|
|
111
|
+
var _a, _b;
|
|
112
|
+
return (_b = (_a = config.attendance) === null || _a === void 0 ? void 0 : _a[studentId]) === null || _b === void 0 ? void 0 : _b[day];
|
|
113
|
+
}
|
|
114
|
+
export function getBatchFilename(month, year) {
|
|
115
|
+
return `attendance_registers_${slugifyFilenamePart(month, "month")}_${year}.zip`;
|
|
116
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Student } from "../types";
|
|
2
|
+
/** Browser-safe id generator shared by both apps. */
|
|
3
|
+
export declare function generateStudentId(): string;
|
|
4
|
+
export declare function normalizeStudentName(name: string): string;
|
|
5
|
+
export interface ImportedStudent {
|
|
6
|
+
name: string;
|
|
7
|
+
admissionNumber?: string;
|
|
8
|
+
rollNumber?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Extracts students from parsed CSV/XLSX rows.
|
|
12
|
+
*
|
|
13
|
+
* Handles a name column, combined first/last columns, headerless files and
|
|
14
|
+
* files where the first column is a roll number. Admission numbers are read
|
|
15
|
+
* when present and are the identity used to allow two students with the same
|
|
16
|
+
* name.
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractStudentRows(rows: unknown[][]): {
|
|
19
|
+
students: ImportedStudent[];
|
|
20
|
+
skipped: number;
|
|
21
|
+
};
|
|
22
|
+
/** Backwards-compatible name-only view of {@link extractStudentRows}. */
|
|
23
|
+
export declare function extractStudentNames(rows: unknown[][]): {
|
|
24
|
+
names: string[];
|
|
25
|
+
skipped: number;
|
|
26
|
+
};
|
|
27
|
+
export interface MergeStudentsResult {
|
|
28
|
+
students: Student[];
|
|
29
|
+
added: number;
|
|
30
|
+
duplicates: number;
|
|
31
|
+
/** Existing name-only records that gained an admission number. */
|
|
32
|
+
updated: number;
|
|
33
|
+
/** Names that were skipped because they already existed. */
|
|
34
|
+
duplicateNames: string[];
|
|
35
|
+
}
|
|
36
|
+
export type MergeInput = string | {
|
|
37
|
+
name: string;
|
|
38
|
+
admissionNumber?: string;
|
|
39
|
+
rollNumber?: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Merges new students into the current roster.
|
|
43
|
+
*
|
|
44
|
+
* Admission numbers are the identity when available, so two students can share
|
|
45
|
+
* a name. Name-only records still match by name to keep repeat imports from
|
|
46
|
+
* doubling the roster; pass `allowDuplicateNames` to override that.
|
|
47
|
+
*/
|
|
48
|
+
export declare function mergeStudents(existing: Student[], incoming: MergeInput[], options?: {
|
|
49
|
+
allowDuplicateNames?: boolean;
|
|
50
|
+
}): MergeStudentsResult;
|
|
51
|
+
export declare function reindexStudents(students: Student[]): Student[];
|