@unlev/exeq 0.5.6 → 0.6.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.mjs CHANGED
@@ -1,192 +1,40 @@
1
+ import {
2
+ A4,
3
+ BUILTIN_TRANSFORMS,
4
+ DEFAULT_CALIBRATION,
5
+ DEFAULT_SIGNER_ROLES,
6
+ FIELD_DEFAULTS,
7
+ FONT_FAMILIES,
8
+ SIGNER_ROLE_COLORS,
9
+ US_LEGAL,
10
+ US_LETTER,
11
+ applyCalibration,
12
+ createField,
13
+ createPdfBuilder,
14
+ downloadPdf,
15
+ generateFilledPdf,
16
+ generateId,
17
+ getCssFontFamily,
18
+ getCssTextStyle,
19
+ getFieldValues,
20
+ getInputType,
21
+ getSignerColor,
22
+ isRedactField,
23
+ isSignatureField,
24
+ isTextLikeField,
25
+ parseDate,
26
+ postPdfToCallback,
27
+ preserveFieldValues,
28
+ resolveAllFormulas,
29
+ resolveFormula,
30
+ sortFieldsByPosition,
31
+ uniqueLabel
32
+ } from "./chunk-OLRWRBLO.mjs";
33
+
1
34
  // src/components/pdf-builder/DesignerView.tsx
2
35
  import { useState as useState5, useCallback as useCallback4, useEffect as useEffect2, useRef as useRef4 } from "react";
3
36
  import { createPortal } from "react-dom";
4
37
 
5
- // src/types/pdf-builder.ts
6
- function generateId() {
7
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
8
- return crypto.randomUUID();
9
- }
10
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
11
- const r = Math.random() * 16 | 0;
12
- const v = c === "x" ? r : r & 3 | 8;
13
- return v.toString(16);
14
- });
15
- }
16
- var DEFAULT_SIGNER_ROLES = ["Sender", "Signer 1"];
17
- var SIGNER_ROLE_COLORS = {
18
- "Sender": "#6366f1",
19
- "Signer 1": "#22c55e",
20
- "Signer 2": "#f59e0b",
21
- "Signer 3": "#ef4444",
22
- "Signer 4": "#06b6d4",
23
- "Signer 5": "#d946ef"
24
- };
25
- function getSignerColor(role) {
26
- return SIGNER_ROLE_COLORS[role] || "#888888";
27
- }
28
- function isRedactField(f) {
29
- return f.type === "blackout" || f.type === "whiteout";
30
- }
31
- function isSignatureField(f) {
32
- return f.type === "signature" || f.type === "initials";
33
- }
34
- function isTextLikeField(f) {
35
- return f.type === "text" || f.type === "dropdown" || f.type === "signed-date";
36
- }
37
- function getInputType(subtype) {
38
- switch (subtype) {
39
- case "email":
40
- return "email";
41
- case "number":
42
- return "number";
43
- case "phone":
44
- return "tel";
45
- case "date":
46
- return "date";
47
- default:
48
- return "text";
49
- }
50
- }
51
- var CSS_FONT_MAP = {
52
- Courier: '"Courier New", Courier, monospace',
53
- TimesRoman: '"Times New Roman", Times, serif',
54
- Helvetica: "Helvetica, Arial, sans-serif"
55
- };
56
- function getCssFontFamily(fontFamily) {
57
- return fontFamily ? CSS_FONT_MAP[fontFamily] : void 0;
58
- }
59
- function getCssTextStyle(field) {
60
- const decorations = [];
61
- if (field.underline) decorations.push("underline");
62
- if (field.strikethrough) decorations.push("line-through");
63
- const align = field.align ?? "left";
64
- return {
65
- fontFamily: getCssFontFamily(field.fontFamily),
66
- fontWeight: field.bold ? "bold" : void 0,
67
- fontStyle: field.italic ? "italic" : void 0,
68
- textDecorationLine: decorations.length ? decorations.join(" ") : void 0,
69
- textAlign: field.align,
70
- // Hug the alignment edge — no padding on the trailing side — so text reaches
71
- // the container edge (matches the PDF's 2pt offsets).
72
- paddingLeft: align === "right" ? "0px" : "2px",
73
- paddingRight: align === "left" ? "0px" : "2px"
74
- };
75
- }
76
- function sortFieldsByPosition(fields) {
77
- return [...fields].sort((a, b) => {
78
- if (a.page !== b.page) return a.page - b.page;
79
- const bandThreshold = 2;
80
- if (Math.abs(a.y - b.y) > bandThreshold) return a.y - b.y;
81
- return a.x - b.x;
82
- });
83
- }
84
- function preserveFieldValues(oldFields, newFields) {
85
- const valueMap = new Map(oldFields.filter((f) => f.value).map((f) => [f.id, f.value]));
86
- return newFields.map((f) => valueMap.has(f.id) ? { ...f, value: valueMap.get(f.id) } : f);
87
- }
88
- function getFieldValues(fields) {
89
- const values = {};
90
- fields.forEach((f) => {
91
- if (!isRedactField(f)) values[f.label] = f.value || "";
92
- });
93
- return values;
94
- }
95
- var FONT_FAMILIES = [
96
- { value: "Helvetica", label: "Helvetica" },
97
- { value: "Courier", label: "Courier New" },
98
- { value: "TimesRoman", label: "Times New Roman" }
99
- ];
100
- var FIELD_DEFAULTS = {
101
- text: {
102
- width: 20,
103
- height: 3,
104
- fontSize: 12,
105
- placeholder: "Enter text",
106
- textSubtype: "freeform"
107
- },
108
- dropdown: {
109
- width: 20,
110
- height: 3,
111
- fontSize: 12,
112
- placeholder: "Select..."
113
- },
114
- signature: {
115
- width: 20,
116
- height: 6,
117
- fontSize: 12,
118
- placeholder: "Sign here"
119
- },
120
- "signed-date": {
121
- width: 15,
122
- height: 3,
123
- fontSize: 12,
124
- placeholder: "Date"
125
- },
126
- checkbox: {
127
- width: 2.5,
128
- height: 2.5,
129
- fontSize: 12,
130
- placeholder: ""
131
- },
132
- initials: {
133
- width: 8,
134
- height: 5,
135
- fontSize: 12,
136
- placeholder: "Initials"
137
- },
138
- blackout: {
139
- width: 20,
140
- height: 3,
141
- fontSize: 12,
142
- placeholder: ""
143
- },
144
- whiteout: {
145
- width: 20,
146
- height: 3,
147
- fontSize: 12,
148
- placeholder: ""
149
- }
150
- };
151
- var TYPE_LABELS = {
152
- text: "Text Field",
153
- dropdown: "Dropdown",
154
- signature: "Signature",
155
- "signed-date": "Signed Date",
156
- checkbox: "Checkbox",
157
- initials: "Initials",
158
- blackout: "Blackout",
159
- whiteout: "Whiteout"
160
- };
161
- function uniqueLabel(desired, existingLabels) {
162
- const lower = desired.toLowerCase();
163
- if (!existingLabels.some((l) => l.toLowerCase() === lower)) return desired;
164
- let i = 2;
165
- while (existingLabels.some((l) => l.toLowerCase() === `${lower} ${i}`)) i++;
166
- return `${desired} ${i}`;
167
- }
168
- function createField(type, assignee, page, x, y, existingFields) {
169
- const defaults = FIELD_DEFAULTS[type];
170
- const baseLabel = TYPE_LABELS[type];
171
- const existingLabels = existingFields?.map((f) => f.label) ?? [];
172
- return {
173
- id: generateId(),
174
- type,
175
- label: uniqueLabel(baseLabel, existingLabels),
176
- placeholder: defaults.placeholder || "",
177
- required: type === "checkbox" || type === "blackout" || type === "whiteout" ? false : true,
178
- assignee,
179
- page,
180
- x,
181
- y,
182
- width: defaults.width || 20,
183
- height: defaults.height || 3,
184
- fontSize: defaults.fontSize || 12,
185
- value: "",
186
- ...type === "text" ? { textSubtype: defaults.textSubtype } : {}
187
- };
188
- }
189
-
190
38
  // src/utils/pdfRenderer.ts
191
39
  import * as pdfjsLib from "pdfjs-dist";
192
40
  if (typeof window !== "undefined") {
@@ -2116,411 +1964,6 @@ function DesignerView({
2116
1964
  // src/components/pdf-builder/SignerView.tsx
2117
1965
  import { useState as useState7, useCallback as useCallback5, useEffect as useEffect3, useRef as useRef5, useLayoutEffect } from "react";
2118
1966
 
2119
- // src/utils/pdfFiller.ts
2120
- import {
2121
- PDFDocument,
2122
- rgb,
2123
- StandardFonts
2124
- } from "pdf-lib";
2125
-
2126
- // src/utils/formulaResolver.ts
2127
- function parseDate(value) {
2128
- const s = value.trim();
2129
- if (!s) return null;
2130
- if (/^\d+(\.\d+)?$/.test(s)) {
2131
- const serial = parseFloat(s);
2132
- if (serial > 59) {
2133
- const utc = new Date(Math.round((serial - 25569) * 864e5));
2134
- if (!isNaN(utc.getTime())) {
2135
- return new Date(utc.getUTCFullYear(), utc.getUTCMonth(), utc.getUTCDate());
2136
- }
2137
- }
2138
- }
2139
- const iso = s.match(/^(\d{4})-(\d{2})-(\d{2})$/);
2140
- if (iso) return new Date(+iso[1], +iso[2] - 1, +iso[3]);
2141
- const d = new Date(s);
2142
- return isNaN(d.getTime()) ? null : d;
2143
- }
2144
- var BUILTIN_TRANSFORMS = {
2145
- // Date transforms (expects a parseable date string)
2146
- month: (v) => {
2147
- const d = parseDate(v);
2148
- return d ? String(d.getMonth() + 1) : "";
2149
- },
2150
- month2: (v) => {
2151
- const d = parseDate(v);
2152
- return d ? String(d.getMonth() + 1).padStart(2, "0") : "";
2153
- },
2154
- monthname: (v) => {
2155
- const d = parseDate(v);
2156
- return d ? d.toLocaleString("en", { month: "long" }) : "";
2157
- },
2158
- monthshort: (v) => {
2159
- const d = parseDate(v);
2160
- return d ? d.toLocaleString("en", { month: "short" }) : "";
2161
- },
2162
- day: (v) => {
2163
- const d = parseDate(v);
2164
- return d ? String(d.getDate()) : "";
2165
- },
2166
- day2: (v) => {
2167
- const d = parseDate(v);
2168
- return d ? String(d.getDate()).padStart(2, "0") : "";
2169
- },
2170
- year: (v) => {
2171
- const d = parseDate(v);
2172
- return d ? String(d.getFullYear()) : "";
2173
- },
2174
- year2: (v) => {
2175
- const d = parseDate(v);
2176
- return d ? String(d.getFullYear()).slice(-2) : "";
2177
- },
2178
- // String transforms
2179
- upper: (v) => v.toUpperCase(),
2180
- lower: (v) => v.toLowerCase(),
2181
- trim: (v) => v.trim(),
2182
- first: (v) => v.split(/\s+/)[0] || "",
2183
- last: (v) => {
2184
- const parts = v.split(/\s+/);
2185
- return parts[parts.length - 1] || "";
2186
- },
2187
- initials: (v) => v.split(/\s+/).map((w) => w[0] || "").join("").toUpperCase(),
2188
- // Numeric / substring
2189
- last4: (v) => v.slice(-4),
2190
- last2: (v) => v.slice(-2),
2191
- first4: (v) => v.slice(0, 4),
2192
- first2: (v) => v.slice(0, 2),
2193
- digits: (v) => v.replace(/\D/g, ""),
2194
- number: (v) => {
2195
- const n = parseFloat(v);
2196
- return isNaN(n) ? "" : String(n);
2197
- },
2198
- currency: (v) => {
2199
- const n = parseFloat(v.replace(/[^0-9.-]/g, ""));
2200
- return isNaN(n) ? "" : `$${n.toFixed(2)}`;
2201
- }
2202
- };
2203
- var FORMULA_RE = /\{\{(.+?)\}\}/g;
2204
- var PIPE_RE = /^(.+?)\s*\|\s*(.+)$/;
2205
- function todayIso() {
2206
- const d = /* @__PURE__ */ new Date();
2207
- return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
2208
- }
2209
- function resolveFormula(formula, fields, customTransforms, values) {
2210
- const transforms = { ...BUILTIN_TRANSFORMS, ...customTransforms };
2211
- return formula.replace(FORMULA_RE, (_match, expr) => {
2212
- const pipeMatch = expr.match(PIPE_RE);
2213
- const sourceLabel = (pipeMatch ? pipeMatch[1] : expr).trim();
2214
- const transformName = pipeMatch ? pipeMatch[2].trim() : null;
2215
- const lowerLabel = sourceLabel.toLowerCase();
2216
- const sourceField = fields.find((f) => f.label.toLowerCase() === lowerLabel) || fields.find((f) => f.id === sourceLabel);
2217
- let rawValue;
2218
- if (sourceField && sourceField.value) {
2219
- rawValue = sourceField.value;
2220
- }
2221
- if (rawValue === void 0 && values) {
2222
- const key = Object.keys(values).find((k) => k.toLowerCase() === lowerLabel);
2223
- if (key !== void 0) rawValue = values[key] || "";
2224
- }
2225
- if (rawValue === void 0 && sourceField) {
2226
- rawValue = sourceField.value || "";
2227
- }
2228
- if (rawValue === void 0 && (lowerLabel === "today" || lowerLabel === "now")) {
2229
- rawValue = todayIso();
2230
- }
2231
- if (rawValue === void 0) return "";
2232
- if (!transformName) return rawValue;
2233
- const fn = transforms[transformName];
2234
- if (!fn) return rawValue;
2235
- try {
2236
- return fn(rawValue);
2237
- } catch {
2238
- return rawValue;
2239
- }
2240
- });
2241
- }
2242
- function resolveAllFormulas(fields, customTransforms, values) {
2243
- return fields.map((f) => {
2244
- if (!f.formula) return f;
2245
- const computed = resolveFormula(f.formula, fields, customTransforms, values);
2246
- return computed !== f.value ? { ...f, value: computed } : f;
2247
- });
2248
- }
2249
-
2250
- // src/utils/fitText.ts
2251
- function fitFontSize(o) {
2252
- let size = o.autoShrink ? Math.min(o.fontSize, o.fieldHeightPt * 0.7) : o.fontSize;
2253
- if (o.autoShrink && o.value) {
2254
- const padding = 4;
2255
- while (size > 4) {
2256
- if (o.measure(o.value, size) <= o.fieldWidthPt - padding) break;
2257
- size -= 0.5;
2258
- }
2259
- }
2260
- return size;
2261
- }
2262
-
2263
- // src/utils/pdfFiller.ts
2264
- var FONT_VARIANTS = {
2265
- Helvetica: [StandardFonts.Helvetica, StandardFonts.HelveticaBold, StandardFonts.HelveticaOblique, StandardFonts.HelveticaBoldOblique],
2266
- Courier: [StandardFonts.Courier, StandardFonts.CourierBold, StandardFonts.CourierOblique, StandardFonts.CourierBoldOblique],
2267
- TimesRoman: [StandardFonts.TimesRoman, StandardFonts.TimesRomanBold, StandardFonts.TimesRomanItalic, StandardFonts.TimesRomanBoldItalic]
2268
- };
2269
- function resolveStandardFont(family, bold, italic) {
2270
- const variants = FONT_VARIANTS[family] || FONT_VARIANTS.Helvetica;
2271
- const idx = (bold ? 1 : 0) + (italic ? 2 : 0);
2272
- return variants[idx];
2273
- }
2274
- function fontKey(family, bold, italic) {
2275
- return `${family}|${bold ? "b" : ""}|${italic ? "i" : ""}`;
2276
- }
2277
- var US_LETTER = [612, 792];
2278
- var US_LEGAL = [612, 1008];
2279
- var A4 = [595.28, 841.89];
2280
- var DEFAULT_CALIBRATION = {
2281
- xOffset: 0,
2282
- yOffset: 0,
2283
- xScale: 1,
2284
- yScale: 1
2285
- };
2286
- function applyCalibration(fields, calibration, pageSize = US_LETTER) {
2287
- if (calibration.xOffset === 0 && calibration.yOffset === 0 && calibration.xScale === 1 && calibration.yScale === 1) {
2288
- return fields;
2289
- }
2290
- const xPctOff = calibration.xOffset / pageSize[0] * 100;
2291
- const yPctOff = calibration.yOffset / pageSize[1] * 100;
2292
- return fields.map((f) => ({
2293
- ...f,
2294
- x: f.x * calibration.xScale + xPctOff,
2295
- y: f.y * calibration.yScale + yPctOff,
2296
- width: f.width * calibration.xScale,
2297
- height: f.height * calibration.yScale
2298
- }));
2299
- }
2300
- function hexToRgb(hex) {
2301
- const r = parseInt(hex.slice(1, 3), 16) / 255;
2302
- const g = parseInt(hex.slice(3, 5), 16) / 255;
2303
- const b = parseInt(hex.slice(5, 7), 16) / 255;
2304
- return rgb(r, g, b);
2305
- }
2306
- async function renderFieldsOnPages(pages, fields, getFont, getSignature) {
2307
- for (const field of fields) {
2308
- const page = pages[field.page];
2309
- if (!page) continue;
2310
- const pageWidth = page.getWidth();
2311
- const pageHeight = page.getHeight();
2312
- const x = field.x / 100 * pageWidth;
2313
- const y = pageHeight - field.y / 100 * pageHeight - field.height / 100 * pageHeight;
2314
- const w = field.width / 100 * pageWidth;
2315
- const h = field.height / 100 * pageHeight;
2316
- if (isRedactField(field)) {
2317
- page.drawRectangle({
2318
- x,
2319
- y,
2320
- width: w,
2321
- height: h,
2322
- color: field.type === "blackout" ? rgb(0, 0, 0) : rgb(1, 1, 1)
2323
- });
2324
- continue;
2325
- }
2326
- if (!field.value) continue;
2327
- const inkColor = field.inkColor ? hexToRgb(field.inkColor) : rgb(0, 0, 0);
2328
- if (field.type === "checkbox") {
2329
- if (field.value === "true") {
2330
- const inset = Math.min(w, h) * 0.2;
2331
- const lineWidth = Math.min(w, h) * 0.08;
2332
- page.drawLine({
2333
- start: { x: x + inset, y: y + inset },
2334
- end: { x: x + w - inset, y: y + h - inset },
2335
- thickness: lineWidth,
2336
- color: inkColor
2337
- });
2338
- page.drawLine({
2339
- start: { x: x + w - inset, y: y + inset },
2340
- end: { x: x + inset, y: y + h - inset },
2341
- thickness: lineWidth,
2342
- color: inkColor
2343
- });
2344
- }
2345
- } else if (isSignatureField(field)) {
2346
- if (field.value.startsWith("data:image/png")) {
2347
- const img = await getSignature(field.value);
2348
- page.drawImage(img, { x, y, width: w, height: h });
2349
- }
2350
- } else {
2351
- const font = await getFont(field.fontFamily || "Helvetica", field.bold, field.italic);
2352
- const spacing = field.letterSpacing || 0;
2353
- const textWidthAtSize = (text, size) => font.widthOfTextAtSize(text, size) + spacing * (text.length - 1);
2354
- const fontSize = fitFontSize({
2355
- value: field.value,
2356
- fontSize: field.fontSize,
2357
- autoShrink: field.autoShrink,
2358
- fieldWidthPt: w,
2359
- fieldHeightPt: h,
2360
- measure: textWidthAtSize
2361
- });
2362
- const fullTextWidth = textWidthAtSize(field.value, fontSize);
2363
- const pad = 2;
2364
- const textX = field.align === "center" ? x + Math.max(pad, (w - fullTextWidth) / 2) : field.align === "right" ? x + Math.max(pad, w - fullTextWidth - pad) : x + pad;
2365
- const baselineY = y + h * 0.3;
2366
- if (spacing > 0) {
2367
- let cx = textX;
2368
- for (const char of field.value) {
2369
- page.drawText(char, {
2370
- x: cx,
2371
- y: baselineY,
2372
- size: fontSize,
2373
- font,
2374
- color: inkColor
2375
- });
2376
- cx += font.widthOfTextAtSize(char, fontSize) + spacing;
2377
- }
2378
- } else {
2379
- page.drawText(field.value, {
2380
- x: textX,
2381
- y: baselineY,
2382
- size: fontSize,
2383
- font,
2384
- color: inkColor
2385
- });
2386
- }
2387
- if (field.underline || field.strikethrough) {
2388
- const textWidth = textWidthAtSize(field.value, fontSize);
2389
- const lineThickness = Math.max(0.5, fontSize * 0.06);
2390
- if (field.underline) {
2391
- const uy = baselineY - fontSize * 0.12;
2392
- page.drawLine({
2393
- start: { x: textX, y: uy },
2394
- end: { x: textX + textWidth, y: uy },
2395
- thickness: lineThickness,
2396
- color: inkColor
2397
- });
2398
- }
2399
- if (field.strikethrough) {
2400
- const sy = baselineY + fontSize * 0.3;
2401
- page.drawLine({
2402
- start: { x: textX, y: sy },
2403
- end: { x: textX + textWidth, y: sy },
2404
- thickness: lineThickness,
2405
- color: inkColor
2406
- });
2407
- }
2408
- }
2409
- }
2410
- }
2411
- }
2412
- async function generateFilledPdf(opts) {
2413
- const builder = await createPdfBuilder({ pageSize: opts.pageSize });
2414
- await builder.addRecord(opts);
2415
- return builder.save();
2416
- }
2417
- async function createPdfBuilder(defaults = {}) {
2418
- const doc = await PDFDocument.create();
2419
- const fontCache = /* @__PURE__ */ new Map();
2420
- const embeddedPagesByUrl = /* @__PURE__ */ new Map();
2421
- const signatureCache = /* @__PURE__ */ new Map();
2422
- async function getFont(family, bold, italic) {
2423
- const key = fontKey(family, bold, italic);
2424
- let f = fontCache.get(key);
2425
- if (!f) {
2426
- f = await doc.embedFont(resolveStandardFont(family, bold, italic));
2427
- fontCache.set(key, f);
2428
- }
2429
- return f;
2430
- }
2431
- async function ensureFonts(fields) {
2432
- const keys = /* @__PURE__ */ new Map();
2433
- for (const f of fields) keys.set(fontKey(f.fontFamily || "Helvetica", f.bold, f.italic), f);
2434
- for (const f of keys.values()) await getFont(f.fontFamily || "Helvetica", f.bold, f.italic);
2435
- }
2436
- async function embedSource(source) {
2437
- if (typeof source === "string") {
2438
- let pages = embeddedPagesByUrl.get(source);
2439
- if (!pages) {
2440
- const res = await fetch(source);
2441
- const bytes = await res.arrayBuffer();
2442
- const srcDoc2 = await PDFDocument.load(bytes);
2443
- pages = await Promise.all(
2444
- srcDoc2.getPages().map((p) => doc.embedPage(p))
2445
- );
2446
- embeddedPagesByUrl.set(source, pages);
2447
- }
2448
- return pages;
2449
- }
2450
- const srcDoc = await PDFDocument.load(source);
2451
- return Promise.all(srcDoc.getPages().map((p) => doc.embedPage(p)));
2452
- }
2453
- async function getSignature(dataUrl) {
2454
- let img = signatureCache.get(dataUrl);
2455
- if (!img) {
2456
- const b64 = dataUrl.split(",")[1] ?? "";
2457
- const pngBytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
2458
- img = await doc.embedPng(pngBytes);
2459
- signatureCache.set(dataUrl, img);
2460
- }
2461
- return img;
2462
- }
2463
- return {
2464
- doc,
2465
- async addRecord(opts) {
2466
- const pageSize = opts.pageSize ?? defaults.pageSize;
2467
- let fields = opts.resolveFormulas ? resolveAllFormulas(opts.fields, opts.customTransforms, opts.formulaValues) : opts.fields;
2468
- if (opts.calibration) {
2469
- fields = applyCalibration(
2470
- fields,
2471
- opts.calibration,
2472
- pageSize ?? US_LETTER
2473
- );
2474
- }
2475
- await ensureFonts(fields);
2476
- let sourcePages = [];
2477
- let pageCount;
2478
- if (opts.pdfSource !== null) {
2479
- sourcePages = await embedSource(opts.pdfSource);
2480
- pageCount = sourcePages.length;
2481
- } else {
2482
- pageCount = opts.pageCount ?? 1;
2483
- }
2484
- const newPages = [];
2485
- for (let i = 0; i < pageCount; i++) {
2486
- const size = pageSize ? pageSize : sourcePages[i] ? [sourcePages[i].width, sourcePages[i].height] : US_LETTER;
2487
- const page = doc.addPage(size);
2488
- newPages.push(page);
2489
- if (sourcePages[i]) {
2490
- page.drawPage(sourcePages[i], {
2491
- x: 0,
2492
- y: 0,
2493
- width: size[0],
2494
- height: size[1]
2495
- });
2496
- }
2497
- }
2498
- await renderFieldsOnPages(newPages, fields, getFont, getSignature);
2499
- },
2500
- async save() {
2501
- return doc.save();
2502
- }
2503
- };
2504
- }
2505
- function downloadPdf(bytes, filename) {
2506
- const blob = new Blob([bytes.slice().buffer], { type: "application/pdf" });
2507
- const url = URL.createObjectURL(blob);
2508
- const a = document.createElement("a");
2509
- a.href = url;
2510
- a.download = filename;
2511
- a.click();
2512
- URL.revokeObjectURL(url);
2513
- }
2514
- async function postPdfToCallback(bytes, callbackUrl, filename) {
2515
- const blob = new Blob([bytes.slice().buffer], { type: "application/pdf" });
2516
- const formData = new FormData();
2517
- formData.append("file", blob, filename);
2518
- await fetch(callbackUrl, {
2519
- method: "POST",
2520
- body: formData
2521
- });
2522
- }
2523
-
2524
1967
  // src/components/pdf-builder/FieldNavigator.tsx
2525
1968
  import { useState as useState6 } from "react";
2526
1969
  import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
@@ -2869,20 +2312,20 @@ function SignerView({
2869
2312
  const finalFields = resolveAllFormulas(fields, transforms, initialValues);
2870
2313
  let pdfBytes;
2871
2314
  if (includeAuditTrail) {
2872
- const { PDFDocument: PDFDocument2, StandardFonts: StandardFonts2, rgb: rgb2 } = await import("pdf-lib");
2315
+ const { PDFDocument, StandardFonts, rgb } = await import("pdf-lib");
2873
2316
  const basePdf = await generateFilledPdf({ pdfSource, fields: finalFields });
2874
- const pdfDoc = await PDFDocument2.load(basePdf);
2875
- const font = await pdfDoc.embedFont(StandardFonts2.Helvetica);
2876
- const boldFont = await pdfDoc.embedFont(StandardFonts2.HelveticaBold);
2317
+ const pdfDoc = await PDFDocument.load(basePdf);
2318
+ const font = await pdfDoc.embedFont(StandardFonts.Helvetica);
2319
+ const boldFont = await pdfDoc.embedFont(StandardFonts.HelveticaBold);
2877
2320
  const auditPage = pdfDoc.addPage([612, 792]);
2878
2321
  let cy = 742;
2879
- auditPage.drawText("Signing Audit Trail", { x: 50, y: cy, size: 18, font: boldFont, color: rgb2(0, 0, 0) });
2322
+ auditPage.drawText("Signing Audit Trail", { x: 50, y: cy, size: 18, font: boldFont, color: rgb(0, 0, 0) });
2880
2323
  cy -= 30;
2881
- auditPage.drawText(`Document completed: ${(/* @__PURE__ */ new Date()).toLocaleString()}`, { x: 50, y: cy, size: 10, font, color: rgb2(0.4, 0.4, 0.4) });
2324
+ auditPage.drawText(`Document completed: ${(/* @__PURE__ */ new Date()).toLocaleString()}`, { x: 50, y: cy, size: 10, font, color: rgb(0.4, 0.4, 0.4) });
2882
2325
  cy -= 30;
2883
2326
  for (const entry of auditLogRef.current) {
2884
- auditPage.drawText(`${entry.signer}`, { x: 50, y: cy, size: 12, font: boldFont, color: rgb2(0, 0, 0) });
2885
- auditPage.drawText(`Completed: ${new Date(entry.completedAt).toLocaleString()}`, { x: 200, y: cy, size: 10, font, color: rgb2(0.3, 0.3, 0.3) });
2327
+ auditPage.drawText(`${entry.signer}`, { x: 50, y: cy, size: 12, font: boldFont, color: rgb(0, 0, 0) });
2328
+ auditPage.drawText(`Completed: ${new Date(entry.completedAt).toLocaleString()}`, { x: 200, y: cy, size: 10, font, color: rgb(0.3, 0.3, 0.3) });
2886
2329
  cy -= 22;
2887
2330
  }
2888
2331
  pdfBytes = await pdfDoc.save();
@@ -2921,8 +2364,13 @@ ${row.join(",")}`, "csv");
2921
2364
  if (isRedactField(field)) {
2922
2365
  return null;
2923
2366
  }
2367
+ const textStyle = {
2368
+ letterSpacing: field.letterSpacing ? `${field.letterSpacing}pt` : void 0,
2369
+ lineHeight: field.lineHeight ? `${field.lineHeight}` : void 0,
2370
+ ...getCssTextStyle(field)
2371
+ };
2924
2372
  if (field.formula) {
2925
- return /* @__PURE__ */ jsx6(FitText, { maxPt: field.fontSize, shrink: !!field.autoShrink, className: "field-overlay-value formula", style: getCssTextStyle(field), children: field.value || "" });
2373
+ return /* @__PURE__ */ jsx6(FitText, { maxPt: field.fontSize, shrink: !!field.autoShrink, className: "field-overlay-value formula", style: textStyle, children: field.value || "" });
2926
2374
  }
2927
2375
  const editable = field.assignee === signer;
2928
2376
  if (!editable) {
@@ -2932,7 +2380,7 @@ ${row.join(",")}`, "csv");
2932
2380
  if (field.type === "checkbox") {
2933
2381
  return /* @__PURE__ */ jsx6("div", { className: "field-checkbox-display readonly", children: field.value === "true" ? "\u2713" : "" });
2934
2382
  }
2935
- return /* @__PURE__ */ jsx6(FitText, { maxPt: field.fontSize, shrink: !!field.autoShrink, className: "field-overlay-placeholder readonly", style: getCssTextStyle(field), children: field.value || field.placeholder });
2383
+ return /* @__PURE__ */ jsx6(FitText, { maxPt: field.fontSize, shrink: !!field.autoShrink, className: "field-overlay-placeholder readonly", style: textStyle, children: field.value || field.placeholder });
2936
2384
  }
2937
2385
  if (isSignatureField(field)) {
2938
2386
  if (field.value) {
@@ -2954,13 +2402,8 @@ ${row.join(",")}`, "csv");
2954
2402
  );
2955
2403
  }
2956
2404
  if (field.type === "signed-date") {
2957
- return /* @__PURE__ */ jsx6(FitText, { maxPt: field.fontSize, shrink: !!field.autoShrink, className: "field-overlay-value", style: getCssTextStyle(field), children: field.value || (/* @__PURE__ */ new Date()).toLocaleDateString() });
2405
+ return /* @__PURE__ */ jsx6(FitText, { maxPt: field.fontSize, shrink: !!field.autoShrink, className: "field-overlay-value", style: textStyle, children: field.value || (/* @__PURE__ */ new Date()).toLocaleDateString() });
2958
2406
  }
2959
- const fontStyle = {
2960
- letterSpacing: field.letterSpacing ? `${field.letterSpacing}pt` : void 0,
2961
- lineHeight: field.lineHeight ? `${field.lineHeight}` : void 0,
2962
- ...getCssTextStyle(field)
2963
- };
2964
2407
  if (field.type === "dropdown" || field.options && field.options.length > 0) {
2965
2408
  return /* @__PURE__ */ jsxs6(
2966
2409
  "select",
@@ -2970,7 +2413,7 @@ ${row.join(",")}`, "csv");
2970
2413
  onChange: (e) => handleFieldUpdate(field.id, e.target.value),
2971
2414
  onFocus: () => setSelectedFieldId(field.id),
2972
2415
  onClick: (e) => e.stopPropagation(),
2973
- style: { fontSize: `${field.fontSize}pt`, ...fontStyle },
2416
+ style: { fontSize: `${field.fontSize}pt`, ...textStyle },
2974
2417
  children: [
2975
2418
  /* @__PURE__ */ jsx6("option", { value: "", children: field.placeholder || "Select..." }),
2976
2419
  (field.options || []).map((opt) => /* @__PURE__ */ jsx6("option", { value: opt, children: opt }, opt))
@@ -2991,7 +2434,7 @@ ${row.join(",")}`, "csv");
2991
2434
  onChange: (e) => handleFieldUpdate(field.id, e.target.value),
2992
2435
  onFocus: () => setSelectedFieldId(field.id),
2993
2436
  onClick: (e) => e.stopPropagation(),
2994
- style: fontStyle
2437
+ style: textStyle
2995
2438
  }
2996
2439
  );
2997
2440
  }, [signer, handleFieldUpdate, setSelectedFieldId]);