@geomak/ui 7.15.0 → 7.16.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/index.cjs CHANGED
@@ -11181,6 +11181,153 @@ function useJwt(token) {
11181
11181
  const isValid = decoded.payload != null && !isExpired;
11182
11182
  return { payload: decoded.payload, header: decoded.header, expiresAt, isExpired, isValid, raw: token ?? null };
11183
11183
  }
11184
+ var INVALID_WS_CHARS = /[:\\/?\*[\]]/g;
11185
+ function sanitizeName(name) {
11186
+ return name.replace(INVALID_WS_CHARS, "_").slice(0, 31) || "Sheet";
11187
+ }
11188
+ var xlsxPromise2 = null;
11189
+ var loadXlsx2 = () => xlsxPromise2 ??= import('xlsx');
11190
+ function useExcel() {
11191
+ const [isExporting, setIsExporting] = React36.useState(false);
11192
+ const exportSheets = React36.useCallback(async (sheets, options = {}) => {
11193
+ const { fileName = "export", onSave } = options;
11194
+ setIsExporting(true);
11195
+ try {
11196
+ const XLSX = await loadXlsx2();
11197
+ const wb = XLSX.utils.book_new();
11198
+ for (const sheet of sheets) {
11199
+ let headers;
11200
+ if (sheet.columns) {
11201
+ headers = sheet.columns;
11202
+ } else {
11203
+ const seen = /* @__PURE__ */ new Set();
11204
+ for (const row of sheet.rows) {
11205
+ if (!Array.isArray(row)) {
11206
+ for (const k of Object.keys(row)) seen.add(k);
11207
+ }
11208
+ }
11209
+ headers = Array.from(seen);
11210
+ }
11211
+ const aoa = [];
11212
+ if (headers.length > 0) aoa.push(headers);
11213
+ for (const row of sheet.rows) {
11214
+ if (Array.isArray(row)) {
11215
+ aoa.push(row);
11216
+ } else {
11217
+ aoa.push(headers.map((h) => row[h] ?? null));
11218
+ }
11219
+ }
11220
+ const ws = XLSX.utils.aoa_to_sheet(aoa);
11221
+ if (headers.length > 0) {
11222
+ for (let ci = 0; ci < headers.length; ci++) {
11223
+ const addr = XLSX.utils.encode_cell({ r: 0, c: ci });
11224
+ if (ws[addr]) ws[addr].s = { font: { bold: true } };
11225
+ }
11226
+ }
11227
+ const colWidths = headers.map((h) => Math.min(h.length, 40));
11228
+ for (const row of aoa.slice(1)) {
11229
+ row.forEach((cell, ci) => {
11230
+ const len = cell == null ? 0 : String(cell).length;
11231
+ if (len > (colWidths[ci] ?? 0)) colWidths[ci] = Math.min(len, 40);
11232
+ });
11233
+ }
11234
+ ws["!cols"] = colWidths.map((w) => ({ wch: w + 2 }));
11235
+ XLSX.utils.book_append_sheet(wb, ws, sanitizeName(sheet.name));
11236
+ }
11237
+ const out = XLSX.write(wb, { bookType: "xlsx", type: "array" });
11238
+ const blob = new Blob([out], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
11239
+ const name = `${fileName}.xlsx`;
11240
+ if (onSave) {
11241
+ await onSave(blob, name);
11242
+ } else {
11243
+ downloadBlob(blob, name);
11244
+ }
11245
+ } finally {
11246
+ setIsExporting(false);
11247
+ }
11248
+ }, []);
11249
+ const readWorkbook = React36.useCallback(async (source) => {
11250
+ const XLSX = await loadXlsx2();
11251
+ let bytes;
11252
+ if (source instanceof Uint8Array) {
11253
+ bytes = source;
11254
+ } else if (source instanceof ArrayBuffer) {
11255
+ bytes = new Uint8Array(source);
11256
+ } else {
11257
+ bytes = new Uint8Array(await source.arrayBuffer());
11258
+ }
11259
+ const wb = XLSX.read(bytes, { type: "array" });
11260
+ return wb.SheetNames.map((name) => {
11261
+ const ws = wb.Sheets[name];
11262
+ const aoa = XLSX.utils.sheet_to_json(ws, { header: 1, blankrows: false, defval: null });
11263
+ if (aoa.length === 0) return { name, rows: [] };
11264
+ const headerRow = aoa[0] ?? [];
11265
+ const headers = headerRow.map(
11266
+ (h, i) => h != null && String(h).length ? String(h) : `col_${i}`
11267
+ );
11268
+ const rows = aoa.slice(1).map((row) => {
11269
+ const rec = {};
11270
+ headers.forEach((h, i) => {
11271
+ rec[h] = row[i] ?? null;
11272
+ });
11273
+ return rec;
11274
+ });
11275
+ return { name, rows };
11276
+ });
11277
+ }, []);
11278
+ return { exportSheets, readWorkbook, isExporting };
11279
+ }
11280
+ var jspdfPromise2 = null;
11281
+ var loadJspdf2 = () => jspdfPromise2 ??= import('jspdf');
11282
+ function usePdf() {
11283
+ const [isExporting, setIsExporting] = React36.useState(false);
11284
+ const exportCanvases = React36.useCallback(async (pages, options = {}) => {
11285
+ const { fileName = "report", onSave, orientation = "landscape" } = options;
11286
+ const validPages = pages.filter((p) => p.canvas.width !== 0 && p.canvas.height !== 0);
11287
+ if (validPages.length === 0) return;
11288
+ setIsExporting(true);
11289
+ try {
11290
+ const { jsPDF } = await loadJspdf2();
11291
+ const pdf = new jsPDF({ orientation, unit: "px", compress: true });
11292
+ const pageW = pdf.internal.pageSize.getWidth();
11293
+ const pageH = pdf.internal.pageSize.getHeight();
11294
+ const TITLE_H = 28;
11295
+ for (let i = 0; i < validPages.length; i++) {
11296
+ const { canvas, title } = validPages[i];
11297
+ if (i > 0) pdf.addPage();
11298
+ let contentY = 0;
11299
+ const contentH = title ? pageH - TITLE_H : pageH;
11300
+ if (title) {
11301
+ pdf.setFontSize(12);
11302
+ pdf.setFont("helvetica", "bold");
11303
+ pdf.text(title, pageW / 2, TITLE_H / 2 + 6, { align: "center" });
11304
+ contentY = TITLE_H;
11305
+ }
11306
+ const scale = Math.min(pageW / canvas.width, contentH / canvas.height);
11307
+ const w = canvas.width * scale;
11308
+ const h = canvas.height * scale;
11309
+ const x = (pageW - w) / 2;
11310
+ const y = contentY + (contentH - h) / 2;
11311
+ pdf.addImage(canvas.toDataURL("image/png", 1), "PNG", x, y, w, h);
11312
+ }
11313
+ const blob = pdf.output("blob");
11314
+ const name = `${fileName}.pdf`;
11315
+ if (onSave) {
11316
+ await onSave(blob, name);
11317
+ } else {
11318
+ const url = URL.createObjectURL(blob);
11319
+ const a = document.createElement("a");
11320
+ a.href = url;
11321
+ a.download = name;
11322
+ a.click();
11323
+ URL.revokeObjectURL(url);
11324
+ }
11325
+ } finally {
11326
+ setIsExporting(false);
11327
+ }
11328
+ }, []);
11329
+ return { exportCanvases, isExporting };
11330
+ }
11184
11331
  var GRADIENT = "radial-gradient(ellipse 80% 60% at 50% 0%, color-mix(in oklab, var(--color-accent) 12%, transparent), transparent 70%)";
11185
11332
  function Jumbotron({
11186
11333
  eyebrow,
@@ -11868,6 +12015,7 @@ exports.runFieldRules = runFieldRules;
11868
12015
  exports.scorePassword = scorePassword;
11869
12016
  exports.useBreakpoint = useBreakpoint;
11870
12017
  exports.useCart = useCart;
12018
+ exports.useExcel = useExcel;
11871
12019
  exports.useFieldArray = useFieldArray;
11872
12020
  exports.useForm = useForm;
11873
12021
  exports.useFormField = useFormField;
@@ -11876,5 +12024,6 @@ exports.useJwt = useJwt;
11876
12024
  exports.useLocalStorage = useLocalStorage;
11877
12025
  exports.useMediaQuery = useMediaQuery;
11878
12026
  exports.useNotification = useNotification;
12027
+ exports.usePdf = usePdf;
11879
12028
  //# sourceMappingURL=index.cjs.map
11880
12029
  //# sourceMappingURL=index.cjs.map