@akin2unde/flowui-core 0.1.0 → 0.1.1

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/index.cjs CHANGED
@@ -22,9 +22,13 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  createTheme: () => createTheme,
24
24
  defaultTheme: () => defaultTheme,
25
+ exportTableToExcel: () => exportTableToExcel,
26
+ exportTableToPdf: () => exportTableToPdf,
25
27
  flowClass: () => flowClass,
28
+ formatLocalDateTime: () => formatLocalDateTime,
26
29
  resolveFlowStyle: () => resolveFlowStyle,
27
30
  responsiveCSS: () => responsiveCSS,
31
+ setLocalDayBoundary: () => setLocalDayBoundary,
28
32
  themeToCSS: () => themeToCSS
29
33
  });
30
34
  module.exports = __toCommonJS(index_exports);
@@ -494,12 +498,118 @@ function flowClass(base, props, resolution, ...extra) {
494
498
  props.className
495
499
  ].filter(Boolean).join(" ");
496
500
  }
501
+
502
+ // src/datetime.ts
503
+ var pad = (value) => String(value).padStart(2, "0");
504
+ function formatLocalDateTime(value, mode = "datetime") {
505
+ const date = `${value.getFullYear()}-${pad(value.getMonth() + 1)}-${pad(value.getDate())}`;
506
+ const time = `${pad(value.getHours())}:${pad(value.getMinutes())}`;
507
+ if (mode === "date") return date;
508
+ if (mode === "time") return time;
509
+ return `${date}T${time}`;
510
+ }
511
+ function setLocalDayBoundary(value, boundary) {
512
+ const datePart = value?.split("T")[0] || formatLocalDateTime(/* @__PURE__ */ new Date(), "date");
513
+ return `${datePart}T${boundary === "start" ? "00:00" : "23:59"}`;
514
+ }
515
+
516
+ // src/table-export.ts
517
+ function cellText(row, column) {
518
+ const value = row[column.field];
519
+ return String(column.format ? column.format(value, row) : value ?? "");
520
+ }
521
+ function download(content, type, fileName) {
522
+ const url = URL.createObjectURL(new Blob([content], { type }));
523
+ const anchor = document.createElement("a");
524
+ anchor.href = url;
525
+ anchor.download = fileName;
526
+ anchor.click();
527
+ URL.revokeObjectURL(url);
528
+ }
529
+ function xml(value) {
530
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
531
+ }
532
+ function exportTableToExcel(data, columns, fileName = "table") {
533
+ const row = (values) => `<Row>${values.map((value) => `<Cell><Data ss:Type="String">${xml(value)}</Data></Cell>`).join("")}</Row>`;
534
+ const rows = [
535
+ row(columns.map((column) => column.header)),
536
+ ...data.map((item) => row(columns.map((column) => cellText(item, column))))
537
+ ].join("");
538
+ const workbook = `<?xml version="1.0"?><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"><Worksheet ss:Name="Data"><Table>${rows}</Table></Worksheet></Workbook>`;
539
+ download(workbook, "application/vnd.ms-excel", `${fileName}.xls`);
540
+ }
541
+ function pdfEscape(value) {
542
+ return value.replaceAll("\\", "\\\\").replaceAll("(", "\\(").replaceAll(")", "\\)").replace(/[^\x20-\x7e]/g, "?");
543
+ }
544
+ function exportTableToPdf(data, columns, fileName = "table") {
545
+ const lines = [
546
+ columns.map((column) => column.header).join(" | "),
547
+ ...data.map(
548
+ (item) => columns.map((column) => cellText(item, column)).join(" | ")
549
+ )
550
+ ];
551
+ const pages = Array.from(
552
+ { length: Math.max(1, Math.ceil(lines.length / 48)) },
553
+ (_, index) => lines.slice(index * 48, (index + 1) * 48)
554
+ );
555
+ const fontObject = 3 + pages.length * 2;
556
+ const pageObjects = pages.map((_, index) => 3 + index * 2);
557
+ const objects = [
558
+ "<< /Type /Catalog /Pages 2 0 R >>",
559
+ `<< /Type /Pages /Kids [${pageObjects.map((object) => `${object} 0 R`).join(" ")}] /Count ${pages.length} >>`
560
+ ];
561
+ pages.forEach((page, index) => {
562
+ const pageObject = 3 + index * 2;
563
+ const contentObject = pageObject + 1;
564
+ const commands = [
565
+ "BT /F1 10 Tf 40 800 Td",
566
+ ...page.flatMap((line, lineIndex) => [
567
+ lineIndex ? "0 -15 Td" : "",
568
+ `(${pdfEscape(line).slice(0, 115)}) Tj`
569
+ ]),
570
+ "ET"
571
+ ].filter(Boolean).join("\n");
572
+ objects.push(
573
+ `<< /Type /Page /Parent 2 0 R /MediaBox [0 0 595 842] /Resources << /Font << /F1 ${fontObject} 0 R >> >> /Contents ${contentObject} 0 R >>`,
574
+ `<< /Length ${commands.length} >>
575
+ stream
576
+ ${commands}
577
+ endstream`
578
+ );
579
+ });
580
+ objects.push("<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>");
581
+ let pdf = "%PDF-1.4\n";
582
+ const offsets = [0];
583
+ objects.forEach((object, index) => {
584
+ offsets.push(pdf.length);
585
+ pdf += `${index + 1} 0 obj
586
+ ${object}
587
+ endobj
588
+ `;
589
+ });
590
+ const xref = pdf.length;
591
+ pdf += `xref
592
+ 0 ${objects.length + 1}
593
+ 0000000000 65535 f
594
+ `;
595
+ pdf += offsets.slice(1).map((offset) => `${String(offset).padStart(10, "0")} 00000 n
596
+ `).join("");
597
+ pdf += `trailer << /Size ${objects.length + 1} /Root 1 0 R >>
598
+ startxref
599
+ ${xref}
600
+ %%EOF`;
601
+ download(pdf, "application/pdf", `${fileName}.pdf`);
602
+ }
497
603
  // Annotate the CommonJS export names for ESM import in node:
498
604
  0 && (module.exports = {
499
605
  createTheme,
500
606
  defaultTheme,
607
+ exportTableToExcel,
608
+ exportTableToPdf,
501
609
  flowClass,
610
+ formatLocalDateTime,
502
611
  resolveFlowStyle,
503
612
  responsiveCSS,
613
+ setLocalDayBoundary,
504
614
  themeToCSS
505
615
  });
package/dist/index.d.cts CHANGED
@@ -214,6 +214,8 @@ interface ButtonGroupProps extends BaseUIProps {
214
214
  orientation?: Orientation;
215
215
  attached?: boolean;
216
216
  align?: AlignValue;
217
+ selectable?: boolean;
218
+ value?: string | number;
217
219
  }
218
220
  interface InputProps extends BaseUIProps, TypographyProps, DisableableProps, ReadOnlyProps, RequiredProps, FocusableProps {
219
221
  name?: string;
@@ -268,6 +270,8 @@ interface SortState {
268
270
  interface TableColumn<T> {
269
271
  field: keyof T & string;
270
272
  header: string;
273
+ /** False hides this column until the user selects it. */
274
+ defaultVisible?: boolean;
271
275
  sortable?: boolean;
272
276
  width?: string | number;
273
277
  align?: "left" | "center" | "right";
@@ -304,5 +308,94 @@ interface TooltipProps extends BaseUIProps {
304
308
  location?: TooltipLocation;
305
309
  delay?: number;
306
310
  }
311
+ type DateTimeMode = "date" | "time" | "datetime";
312
+ interface DateTimeProps extends BaseUIProps, DisableableProps {
313
+ value?: string;
314
+ mode?: DateTimeMode;
315
+ name?: string;
316
+ min?: string;
317
+ max?: string;
318
+ showDayBoundaryButtons?: boolean;
319
+ }
320
+ interface AutocompleteProps extends BaseUIProps, DisableableProps {
321
+ options: DropdownModel[];
322
+ value?: string | number;
323
+ placeholder?: string;
324
+ minCharacters?: number;
325
+ }
326
+ interface RatingProps extends BaseUIProps, DisableableProps {
327
+ value?: number;
328
+ maximum?: number;
329
+ precision?: 1 | 0.5;
330
+ readOnly?: boolean;
331
+ }
332
+ interface ListboxProps extends BaseUIProps, DisableableProps {
333
+ options: DropdownModel[];
334
+ value?: string | number;
335
+ multiple?: boolean;
336
+ }
337
+ interface TimelineItem {
338
+ id: string | number;
339
+ title: string;
340
+ description?: string;
341
+ date?: string;
342
+ icon?: string;
343
+ image?: string;
344
+ other?: any;
345
+ }
346
+ interface TimelineProps extends BaseUIProps {
347
+ items: TimelineItem[];
348
+ orientation?: Orientation;
349
+ }
350
+ interface PopoverProps extends BaseUIProps {
351
+ open?: boolean;
352
+ placement?: TooltipLocation;
353
+ closeOnOutsideClick?: boolean;
354
+ }
355
+ interface FileUploadProps extends BaseUIProps, DisableableProps {
356
+ accept?: string;
357
+ multiple?: boolean;
358
+ preview?: boolean;
359
+ maxSize?: number;
360
+ }
361
+ interface CarouselProps extends BaseUIProps {
362
+ activeIndex?: number;
363
+ loop?: boolean;
364
+ showIndicators?: boolean;
365
+ showControls?: boolean;
366
+ }
367
+ interface BreadcrumbItem {
368
+ id: string | number;
369
+ text?: string;
370
+ image?: string;
371
+ icon?: string;
372
+ href?: string;
373
+ disabled?: boolean;
374
+ other?: any;
375
+ }
376
+ interface BreadcrumbProps extends BaseUIProps {
377
+ items: BreadcrumbItem[];
378
+ separatorIcon?: string;
379
+ }
380
+ type NotificationType = "success" | "error" | "warning" | "info";
381
+ type NotificationHorizontal = "left" | "center" | "right";
382
+ type NotificationVertical = "top" | "bottom";
383
+ interface NotificationProps extends BaseUIProps {
384
+ open?: boolean;
385
+ type?: NotificationType;
386
+ horizontal?: NotificationHorizontal;
387
+ vertical?: NotificationVertical;
388
+ duration?: number;
389
+ dismissible?: boolean;
390
+ }
391
+
392
+ /** Formats a Date for native date/time controls without converting it to UTC. */
393
+ declare function formatLocalDateTime(value: Date, mode?: DateTimeMode): string;
394
+ declare function setLocalDayBoundary(value: string | undefined, boundary: "start" | "end"): string;
395
+
396
+ /** Downloads an Excel-compatible SpreadsheetML workbook without a runtime dependency. */
397
+ declare function exportTableToExcel<T>(data: T[], columns: TableColumn<T>[], fileName?: string): void;
398
+ /** Downloads a compact PDF containing the currently visible table data. */
399
+ declare function exportTableToPdf<T>(data: T[], columns: TableColumn<T>[], fileName?: string): void;
307
400
 
308
- export { type AlignValue, type BadgeProps, type BaseUIProps, type BorderProps, type BreakpointName, type ButtonGroupProps, type ButtonProps, type CSSLength, type CSSVariableStyle, type CardProps, type ColorPalette, type ColorScale, type ColorShade, type ColorValue, type ComponentSize, type ComponentVariant, type DeepPartial, type DialogPosition, type DimensionValue, type DisableableProps, type DividerProps, type DropdownModel, type FlexContainerProps, type FlexDirection, type FlexItemProps, type FlexWrap, type FlowUIStyle, type FlowUITheme, type FocusableProps, type HStackProps, type IconProps, type ImageProps, type InputProps, type JustifyValue, type LabelProps, type LayoutProps, type LoadingProps, type MenuItem, type Orientation, type PaletteColor, type PasswordInputProps, type PositionProps, type PositionValue, type RadiusToken, type RadiusValue, type ReadOnlyProps, type RequiredProps, type ResolvedStyle, type ResponsiveObject, type ResponsiveValue, type SchemeColor, type SelectOption, type SliderProps, type SortDirection, type SortState, type SpacingProps, type SpacingToken, type SpacingValue, type StackProps, type StyleResolution, type SwitchProps, type TabItem, type TableColumn, type ThemeColorScheme, type ThemeMode, type TooltipLocation, type TooltipProps, type TreeModel, type TreeProps, type TypographyProps, type VStackProps, type VisualProps, createTheme, defaultTheme, flowClass, resolveFlowStyle, responsiveCSS, themeToCSS };
401
+ export { type AlignValue, type AutocompleteProps, type BadgeProps, type BaseUIProps, type BorderProps, type BreadcrumbItem, type BreadcrumbProps, type BreakpointName, type ButtonGroupProps, type ButtonProps, type CSSLength, type CSSVariableStyle, type CardProps, type CarouselProps, type ColorPalette, type ColorScale, type ColorShade, type ColorValue, type ComponentSize, type ComponentVariant, type DateTimeMode, type DateTimeProps, type DeepPartial, type DialogPosition, type DimensionValue, type DisableableProps, type DividerProps, type DropdownModel, type FileUploadProps, type FlexContainerProps, type FlexDirection, type FlexItemProps, type FlexWrap, type FlowUIStyle, type FlowUITheme, type FocusableProps, type HStackProps, type IconProps, type ImageProps, type InputProps, type JustifyValue, type LabelProps, type LayoutProps, type ListboxProps, type LoadingProps, type MenuItem, type NotificationHorizontal, type NotificationProps, type NotificationType, type NotificationVertical, type Orientation, type PaletteColor, type PasswordInputProps, type PopoverProps, type PositionProps, type PositionValue, type RadiusToken, type RadiusValue, type RatingProps, type ReadOnlyProps, type RequiredProps, type ResolvedStyle, type ResponsiveObject, type ResponsiveValue, type SchemeColor, type SelectOption, type SliderProps, type SortDirection, type SortState, type SpacingProps, type SpacingToken, type SpacingValue, type StackProps, type StyleResolution, type SwitchProps, type TabItem, type TableColumn, type ThemeColorScheme, type ThemeMode, type TimelineItem, type TimelineProps, type TooltipLocation, type TooltipProps, type TreeModel, type TreeProps, type TypographyProps, type VStackProps, type VisualProps, createTheme, defaultTheme, exportTableToExcel, exportTableToPdf, flowClass, formatLocalDateTime, resolveFlowStyle, responsiveCSS, setLocalDayBoundary, themeToCSS };
package/dist/index.d.ts CHANGED
@@ -214,6 +214,8 @@ interface ButtonGroupProps extends BaseUIProps {
214
214
  orientation?: Orientation;
215
215
  attached?: boolean;
216
216
  align?: AlignValue;
217
+ selectable?: boolean;
218
+ value?: string | number;
217
219
  }
218
220
  interface InputProps extends BaseUIProps, TypographyProps, DisableableProps, ReadOnlyProps, RequiredProps, FocusableProps {
219
221
  name?: string;
@@ -268,6 +270,8 @@ interface SortState {
268
270
  interface TableColumn<T> {
269
271
  field: keyof T & string;
270
272
  header: string;
273
+ /** False hides this column until the user selects it. */
274
+ defaultVisible?: boolean;
271
275
  sortable?: boolean;
272
276
  width?: string | number;
273
277
  align?: "left" | "center" | "right";
@@ -304,5 +308,94 @@ interface TooltipProps extends BaseUIProps {
304
308
  location?: TooltipLocation;
305
309
  delay?: number;
306
310
  }
311
+ type DateTimeMode = "date" | "time" | "datetime";
312
+ interface DateTimeProps extends BaseUIProps, DisableableProps {
313
+ value?: string;
314
+ mode?: DateTimeMode;
315
+ name?: string;
316
+ min?: string;
317
+ max?: string;
318
+ showDayBoundaryButtons?: boolean;
319
+ }
320
+ interface AutocompleteProps extends BaseUIProps, DisableableProps {
321
+ options: DropdownModel[];
322
+ value?: string | number;
323
+ placeholder?: string;
324
+ minCharacters?: number;
325
+ }
326
+ interface RatingProps extends BaseUIProps, DisableableProps {
327
+ value?: number;
328
+ maximum?: number;
329
+ precision?: 1 | 0.5;
330
+ readOnly?: boolean;
331
+ }
332
+ interface ListboxProps extends BaseUIProps, DisableableProps {
333
+ options: DropdownModel[];
334
+ value?: string | number;
335
+ multiple?: boolean;
336
+ }
337
+ interface TimelineItem {
338
+ id: string | number;
339
+ title: string;
340
+ description?: string;
341
+ date?: string;
342
+ icon?: string;
343
+ image?: string;
344
+ other?: any;
345
+ }
346
+ interface TimelineProps extends BaseUIProps {
347
+ items: TimelineItem[];
348
+ orientation?: Orientation;
349
+ }
350
+ interface PopoverProps extends BaseUIProps {
351
+ open?: boolean;
352
+ placement?: TooltipLocation;
353
+ closeOnOutsideClick?: boolean;
354
+ }
355
+ interface FileUploadProps extends BaseUIProps, DisableableProps {
356
+ accept?: string;
357
+ multiple?: boolean;
358
+ preview?: boolean;
359
+ maxSize?: number;
360
+ }
361
+ interface CarouselProps extends BaseUIProps {
362
+ activeIndex?: number;
363
+ loop?: boolean;
364
+ showIndicators?: boolean;
365
+ showControls?: boolean;
366
+ }
367
+ interface BreadcrumbItem {
368
+ id: string | number;
369
+ text?: string;
370
+ image?: string;
371
+ icon?: string;
372
+ href?: string;
373
+ disabled?: boolean;
374
+ other?: any;
375
+ }
376
+ interface BreadcrumbProps extends BaseUIProps {
377
+ items: BreadcrumbItem[];
378
+ separatorIcon?: string;
379
+ }
380
+ type NotificationType = "success" | "error" | "warning" | "info";
381
+ type NotificationHorizontal = "left" | "center" | "right";
382
+ type NotificationVertical = "top" | "bottom";
383
+ interface NotificationProps extends BaseUIProps {
384
+ open?: boolean;
385
+ type?: NotificationType;
386
+ horizontal?: NotificationHorizontal;
387
+ vertical?: NotificationVertical;
388
+ duration?: number;
389
+ dismissible?: boolean;
390
+ }
391
+
392
+ /** Formats a Date for native date/time controls without converting it to UTC. */
393
+ declare function formatLocalDateTime(value: Date, mode?: DateTimeMode): string;
394
+ declare function setLocalDayBoundary(value: string | undefined, boundary: "start" | "end"): string;
395
+
396
+ /** Downloads an Excel-compatible SpreadsheetML workbook without a runtime dependency. */
397
+ declare function exportTableToExcel<T>(data: T[], columns: TableColumn<T>[], fileName?: string): void;
398
+ /** Downloads a compact PDF containing the currently visible table data. */
399
+ declare function exportTableToPdf<T>(data: T[], columns: TableColumn<T>[], fileName?: string): void;
307
400
 
308
- export { type AlignValue, type BadgeProps, type BaseUIProps, type BorderProps, type BreakpointName, type ButtonGroupProps, type ButtonProps, type CSSLength, type CSSVariableStyle, type CardProps, type ColorPalette, type ColorScale, type ColorShade, type ColorValue, type ComponentSize, type ComponentVariant, type DeepPartial, type DialogPosition, type DimensionValue, type DisableableProps, type DividerProps, type DropdownModel, type FlexContainerProps, type FlexDirection, type FlexItemProps, type FlexWrap, type FlowUIStyle, type FlowUITheme, type FocusableProps, type HStackProps, type IconProps, type ImageProps, type InputProps, type JustifyValue, type LabelProps, type LayoutProps, type LoadingProps, type MenuItem, type Orientation, type PaletteColor, type PasswordInputProps, type PositionProps, type PositionValue, type RadiusToken, type RadiusValue, type ReadOnlyProps, type RequiredProps, type ResolvedStyle, type ResponsiveObject, type ResponsiveValue, type SchemeColor, type SelectOption, type SliderProps, type SortDirection, type SortState, type SpacingProps, type SpacingToken, type SpacingValue, type StackProps, type StyleResolution, type SwitchProps, type TabItem, type TableColumn, type ThemeColorScheme, type ThemeMode, type TooltipLocation, type TooltipProps, type TreeModel, type TreeProps, type TypographyProps, type VStackProps, type VisualProps, createTheme, defaultTheme, flowClass, resolveFlowStyle, responsiveCSS, themeToCSS };
401
+ export { type AlignValue, type AutocompleteProps, type BadgeProps, type BaseUIProps, type BorderProps, type BreadcrumbItem, type BreadcrumbProps, type BreakpointName, type ButtonGroupProps, type ButtonProps, type CSSLength, type CSSVariableStyle, type CardProps, type CarouselProps, type ColorPalette, type ColorScale, type ColorShade, type ColorValue, type ComponentSize, type ComponentVariant, type DateTimeMode, type DateTimeProps, type DeepPartial, type DialogPosition, type DimensionValue, type DisableableProps, type DividerProps, type DropdownModel, type FileUploadProps, type FlexContainerProps, type FlexDirection, type FlexItemProps, type FlexWrap, type FlowUIStyle, type FlowUITheme, type FocusableProps, type HStackProps, type IconProps, type ImageProps, type InputProps, type JustifyValue, type LabelProps, type LayoutProps, type ListboxProps, type LoadingProps, type MenuItem, type NotificationHorizontal, type NotificationProps, type NotificationType, type NotificationVertical, type Orientation, type PaletteColor, type PasswordInputProps, type PopoverProps, type PositionProps, type PositionValue, type RadiusToken, type RadiusValue, type RatingProps, type ReadOnlyProps, type RequiredProps, type ResolvedStyle, type ResponsiveObject, type ResponsiveValue, type SchemeColor, type SelectOption, type SliderProps, type SortDirection, type SortState, type SpacingProps, type SpacingToken, type SpacingValue, type StackProps, type StyleResolution, type SwitchProps, type TabItem, type TableColumn, type ThemeColorScheme, type ThemeMode, type TimelineItem, type TimelineProps, type TooltipLocation, type TooltipProps, type TreeModel, type TreeProps, type TypographyProps, type VStackProps, type VisualProps, createTheme, defaultTheme, exportTableToExcel, exportTableToPdf, flowClass, formatLocalDateTime, resolveFlowStyle, responsiveCSS, setLocalDayBoundary, themeToCSS };
package/dist/index.js CHANGED
@@ -463,11 +463,117 @@ function flowClass(base, props, resolution, ...extra) {
463
463
  props.className
464
464
  ].filter(Boolean).join(" ");
465
465
  }
466
+
467
+ // src/datetime.ts
468
+ var pad = (value) => String(value).padStart(2, "0");
469
+ function formatLocalDateTime(value, mode = "datetime") {
470
+ const date = `${value.getFullYear()}-${pad(value.getMonth() + 1)}-${pad(value.getDate())}`;
471
+ const time = `${pad(value.getHours())}:${pad(value.getMinutes())}`;
472
+ if (mode === "date") return date;
473
+ if (mode === "time") return time;
474
+ return `${date}T${time}`;
475
+ }
476
+ function setLocalDayBoundary(value, boundary) {
477
+ const datePart = value?.split("T")[0] || formatLocalDateTime(/* @__PURE__ */ new Date(), "date");
478
+ return `${datePart}T${boundary === "start" ? "00:00" : "23:59"}`;
479
+ }
480
+
481
+ // src/table-export.ts
482
+ function cellText(row, column) {
483
+ const value = row[column.field];
484
+ return String(column.format ? column.format(value, row) : value ?? "");
485
+ }
486
+ function download(content, type, fileName) {
487
+ const url = URL.createObjectURL(new Blob([content], { type }));
488
+ const anchor = document.createElement("a");
489
+ anchor.href = url;
490
+ anchor.download = fileName;
491
+ anchor.click();
492
+ URL.revokeObjectURL(url);
493
+ }
494
+ function xml(value) {
495
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
496
+ }
497
+ function exportTableToExcel(data, columns, fileName = "table") {
498
+ const row = (values) => `<Row>${values.map((value) => `<Cell><Data ss:Type="String">${xml(value)}</Data></Cell>`).join("")}</Row>`;
499
+ const rows = [
500
+ row(columns.map((column) => column.header)),
501
+ ...data.map((item) => row(columns.map((column) => cellText(item, column))))
502
+ ].join("");
503
+ const workbook = `<?xml version="1.0"?><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"><Worksheet ss:Name="Data"><Table>${rows}</Table></Worksheet></Workbook>`;
504
+ download(workbook, "application/vnd.ms-excel", `${fileName}.xls`);
505
+ }
506
+ function pdfEscape(value) {
507
+ return value.replaceAll("\\", "\\\\").replaceAll("(", "\\(").replaceAll(")", "\\)").replace(/[^\x20-\x7e]/g, "?");
508
+ }
509
+ function exportTableToPdf(data, columns, fileName = "table") {
510
+ const lines = [
511
+ columns.map((column) => column.header).join(" | "),
512
+ ...data.map(
513
+ (item) => columns.map((column) => cellText(item, column)).join(" | ")
514
+ )
515
+ ];
516
+ const pages = Array.from(
517
+ { length: Math.max(1, Math.ceil(lines.length / 48)) },
518
+ (_, index) => lines.slice(index * 48, (index + 1) * 48)
519
+ );
520
+ const fontObject = 3 + pages.length * 2;
521
+ const pageObjects = pages.map((_, index) => 3 + index * 2);
522
+ const objects = [
523
+ "<< /Type /Catalog /Pages 2 0 R >>",
524
+ `<< /Type /Pages /Kids [${pageObjects.map((object) => `${object} 0 R`).join(" ")}] /Count ${pages.length} >>`
525
+ ];
526
+ pages.forEach((page, index) => {
527
+ const pageObject = 3 + index * 2;
528
+ const contentObject = pageObject + 1;
529
+ const commands = [
530
+ "BT /F1 10 Tf 40 800 Td",
531
+ ...page.flatMap((line, lineIndex) => [
532
+ lineIndex ? "0 -15 Td" : "",
533
+ `(${pdfEscape(line).slice(0, 115)}) Tj`
534
+ ]),
535
+ "ET"
536
+ ].filter(Boolean).join("\n");
537
+ objects.push(
538
+ `<< /Type /Page /Parent 2 0 R /MediaBox [0 0 595 842] /Resources << /Font << /F1 ${fontObject} 0 R >> >> /Contents ${contentObject} 0 R >>`,
539
+ `<< /Length ${commands.length} >>
540
+ stream
541
+ ${commands}
542
+ endstream`
543
+ );
544
+ });
545
+ objects.push("<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>");
546
+ let pdf = "%PDF-1.4\n";
547
+ const offsets = [0];
548
+ objects.forEach((object, index) => {
549
+ offsets.push(pdf.length);
550
+ pdf += `${index + 1} 0 obj
551
+ ${object}
552
+ endobj
553
+ `;
554
+ });
555
+ const xref = pdf.length;
556
+ pdf += `xref
557
+ 0 ${objects.length + 1}
558
+ 0000000000 65535 f
559
+ `;
560
+ pdf += offsets.slice(1).map((offset) => `${String(offset).padStart(10, "0")} 00000 n
561
+ `).join("");
562
+ pdf += `trailer << /Size ${objects.length + 1} /Root 1 0 R >>
563
+ startxref
564
+ ${xref}
565
+ %%EOF`;
566
+ download(pdf, "application/pdf", `${fileName}.pdf`);
567
+ }
466
568
  export {
467
569
  createTheme,
468
570
  defaultTheme,
571
+ exportTableToExcel,
572
+ exportTableToPdf,
469
573
  flowClass,
574
+ formatLocalDateTime,
470
575
  resolveFlowStyle,
471
576
  responsiveCSS,
577
+ setLocalDayBoundary,
472
578
  themeToCSS
473
579
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akin2unde/flowui-core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Framework-independent contracts, themes and style resolution for FlowUI.",
5
5
  "author": "Akintunde Morakinyo",
6
6
  "repository": {